/* SmartScan — Rose 設計規範 v2 */
:root {
  --gold-deep: #7a6a42;
  --gold-bg: #f0e9d8;
  --amber: #b8860b;
  --amber-bg: #fef3d5;
  --red: #c0392b;
  --red-bg: #fde8e5;
  --brown-warm: #8b7355;
  --brown-bg: #f5efe5;
  --text: #2c2416;
  --text2: #5a4d3a;
  --text3: #9a8b72;
  --bg: #faf8f4;
  --card: #ffffff;
  --border: #e8e0d0;
  --border-lt: #f0ece4;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; }
body {
  font-family: 'Noto Sans TC', -apple-system, sans-serif;
  font-size: 15px; line-height: 1.6;
  color: var(--text); background: var(--bg);
  min-height: 100%; -webkit-font-smoothing: antialiased;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ── Header ── */
.header {
  position: sticky; top: 0; z-index: 100;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex; align-items: center; gap: 12px;
}
.header h1 { font-size: 18px; font-weight: 700; flex: 1; }
.header .back-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: none; background: none;
  cursor: pointer; border-radius: 8px;
}
.header .back-btn:active { background: var(--border-lt); }
.header .back-btn svg {
  width: 20px; height: 20px;
  stroke: var(--text); fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ── Page container ── */
.page { padding: 20px; max-width: 480px; margin: 0 auto; }

/* ── Alert banner ── */
.alert {
  padding: 14px 16px; border-radius: 12px;
  margin-bottom: 16px; font-size: 14px; line-height: 1.5;
}
.alert.pending {
  background: var(--amber-bg); border: 1px solid var(--amber);
  color: var(--amber);
}
.alert.pending .count {
  font-size: 28px; font-weight: 900; color: var(--text);
  display: block; margin-bottom: 2px;
}
.alert.success { background: var(--gold-bg); color: var(--gold-deep); }
.alert.error { background: var(--red-bg); color: var(--red); }

/* ── Action cards ── */
.action-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px 18px;
  margin-bottom: 12px; text-decoration: none;
  color: inherit; cursor: pointer; transition: border-color 0.15s;
}
.action-card:active { border-color: var(--amber); }
.action-icon {
  width: 48px; height: 48px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.action-icon.primary { background: var(--amber); }
.action-icon.secondary { background: var(--gold-bg); }
.action-icon svg {
  width: 24px; height: 24px; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.action-icon.primary svg { stroke: #fff; }
.action-icon.secondary svg { stroke: var(--gold-deep); }
.action-text h3 { font-size: 16px; font-weight: 700; }
.action-text p { font-size: 13px; color: var(--text3); }

/* ── Buttons ── */
.btn {
  display: block; width: 100%; padding: 14px;
  border: none; border-radius: 12px;
  font-family: inherit; font-size: 15px; font-weight: 700;
  text-align: center; cursor: pointer;
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.8; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--amber); color: #fff; }
.btn-secondary { background: var(--gold-bg); color: var(--gold-deep); }
.btn-outline {
  background: transparent; color: var(--text2);
  border: 1px solid var(--border);
}

/* ── Review cards ── */
.voucher-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; margin-bottom: 12px;
  overflow: hidden;
}
.voucher-card.confirmed {
  border-color: var(--gold-deep);
  background: linear-gradient(180deg, var(--gold-bg) 0%, var(--card) 30%);
}
.voucher-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0; font-size: 14px;
}
.voucher-row .label { color: var(--text3); font-size: 13px; }
.voucher-row .value { font-weight: 600; }
.voucher-row .value.amount { color: var(--amber); font-weight: 700; }
.voucher-thumb {
  width: 100%; height: 120px; object-fit: cover;
  border-radius: 8px; margin-bottom: 12px;
  background: var(--border-lt);
}
.voucher-badge {
  display: inline-block; padding: 3px 10px; border-radius: 6px;
  font-size: 12px; font-weight: 600;
  background: var(--amber-bg); color: var(--amber);
}
.voucher-actions {
  display: flex; gap: 8px; margin-top: 12px;
}
.voucher-actions .btn { flex: 1; padding: 10px; font-size: 14px; }

/* ── Upload progress ── */
.progress-item {
  padding: 12px 0; border-bottom: 1px solid var(--border-lt);
}
.progress-item:last-child { border-bottom: none; }
.progress-label {
  display: flex; justify-content: space-between;
  font-size: 14px; margin-bottom: 6px;
}
.progress-status { font-weight: 600; }
.progress-status.done { color: var(--gold-deep); }
.progress-status.active { color: var(--amber); }
.progress-status.error { color: var(--red); }
.progress-bar {
  height: 5px; background: var(--border); border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 3px;
  transition: width 0.4s ease;
}
.progress-fill.done { background: var(--gold-deep); }
.progress-fill.active { background: var(--amber); animation: pulse 1.5s infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ── Scanner ── */
.scanner-container {
  position: fixed; inset: 0; background: #000; z-index: 200;
  display: flex; flex-direction: column;
}
.scanner-video {
  flex: 1; width: 100%; object-fit: cover;
}
.scanner-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
}
.scanner-hud {
  position: absolute; top: 0; left: 0; right: 0;
  padding: 16px 20px; display: flex; justify-content: space-between;
  align-items: center; z-index: 10;
}
.scanner-count {
  background: var(--amber); color: #fff;
  font-size: 14px; font-weight: 700;
  padding: 4px 14px; border-radius: 100px;
}
.scanner-close {
  width: 36px; height: 36px; border: none;
  background: rgba(0,0,0,0.4); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.scanner-close svg {
  width: 20px; height: 20px;
  stroke: #fff; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.scanner-bottom {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  display: flex; justify-content: center; align-items: center;
  gap: 40px; z-index: 10;
}
.shutter {
  width: 72px; height: 72px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.4);
  background: rgba(255,255,255,0.1);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: transform 0.1s;
}
.shutter:active { transform: scale(0.92); }
.shutter-inner {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--amber);
  transition: background 0.15s;
}
.shutter:active .shutter-inner { background: #d4a017; }
.done-btn {
  background: rgba(255,255,255,0.15); color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 12px; padding: 10px 24px;
  font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.scanner-hint {
  position: absolute; bottom: 130px; left: 0; right: 0;
  text-align: center; color: var(--amber);
  font-size: 13px; font-weight: 500; z-index: 10;
}
/* Edge detection canvas overlay */
.scanner-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 5;
}

/* ── File upload zone ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 14px; padding: 40px 20px;
  text-align: center; cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 16px;
}
.upload-zone.dragover {
  border-color: var(--amber);
  background: var(--amber-bg);
}
.upload-zone svg {
  width: 40px; height: 40px;
  stroke: var(--text3); fill: none;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
  margin-bottom: 12px;
}
.upload-zone p { font-size: 14px; color: var(--text2); }
.upload-zone small { font-size: 12px; color: var(--text3); }

/* ── Recurring list ── */
.recurring-item {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px; margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: center;
}
.recurring-item .info h4 { font-size: 15px; font-weight: 700; }
.recurring-item .info p { font-size: 13px; color: var(--text3); }
.recurring-item .amount { font-size: 16px; font-weight: 700; color: var(--amber); }

/* ── Edit modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 300; display: flex; align-items: flex-end;
  justify-content: center;
}
.modal {
  background: var(--card); border-radius: 20px 20px 0 0;
  width: 100%; max-width: 480px;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  max-height: 85vh; overflow-y: auto;
}
.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--text3); margin-bottom: 4px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  font-family: inherit; font-size: 15px; color: var(--text);
  background: var(--bg); outline: none;
}
.field input:focus, .field select:focus {
  border-color: var(--amber);
}

/* ── Toast ── */
.toast {
  position: fixed; bottom: calc(20px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff;
  padding: 10px 24px; border-radius: 12px;
  font-size: 14px; font-weight: 500;
  z-index: 500; opacity: 0; transition: opacity 0.3s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ── Loading ── */
.loading {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 60px 20px; gap: 16px;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading p { font-size: 14px; color: var(--text3); }

/* ── Hide/show ── */
.hidden { display: none !important; }
