:root {
  --bg: #f4efe6;
  --bg-2: #ebe4d6;
  --paper: #fffbf5;
  --ink: #1c1917;
  --ink-soft: #57534e;
  --muted: #8a837a;
  --line: #e4dcd0;
  --jade: #0f6e56;
  --jade-dark: #0b5744;
  --jade-mid: #1a8669;
  --jade-soft: #e5f3ed;
  --stamp: #c45c26;
  --stamp-soft: #f8e6db;
  --danger: #b42318;
  --danger-soft: #fce8e6;
  --warn: #9a6700;
  --warn-soft: #fbf1d9;
  --shadow: 0 10px 28px rgba(28, 25, 23, 0.08);
  --shadow-sm: 0 2px 8px rgba(28, 25, 23, 0.06);
  --radius: 20px;
  --radius-sm: 14px;
  --tab-h: 72px;
  --font: "PingFang HK", "PingFang TC", "Noto Sans HK", "Noto Sans TC",
    "Hiragino Sans CNS", "Hiragino Sans GB", "Microsoft JhengHei", system-ui,
    sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(15, 110, 86, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(196, 92, 38, 0.06), transparent 55%),
    var(--bg);
  color: var(--ink);
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }
a { color: var(--jade-dark); }

button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }

#app { min-height: 100dvh; }

/* ---------- Shared ---------- */
.page {
  min-height: 100dvh;
  padding: calc(16px + var(--safe-top)) 18px calc(28px + var(--safe-bot));
}
.page.with-tab {
  padding-bottom: calc(var(--tab-h) + 20px + var(--safe-bot));
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 12px;
}
.chop {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--jade);
  color: #f6f1e8;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 22px;
  box-shadow: inset 0 0 0 2px rgba(246, 241, 232, 0.35);
  flex-shrink: 0;
}
.chop.lg {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  font-size: 36px;
  box-shadow: inset 0 0 0 3px rgba(246, 241, 232, 0.4);
}
.wordmark h1, .brand-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}
.icon-btn {
  appearance: none;
  border: 0;
  background: var(--paper);
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
  color: var(--ink);
}
.icon-btn:active { transform: scale(0.97); }
.ghost-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--jade-dark);
  font-weight: 600;
  padding: 10px 8px;
  min-height: 44px;
}

.card {
  background: var(--paper);
  border: 1px solid rgba(228, 220, 208, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 16px;
  min-height: 52px;
  padding: 0 18px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--jade); color: #fff; }
.btn-primary:hover { background: var(--jade-mid); }
.btn-secondary {
  background: var(--jade-soft);
  color: var(--jade-dark);
}
.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.field input, .field select, .field textarea {
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 10px 14px;
  font-size: 16px; /* avoid iOS zoom */
  width: 100%;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--jade);
  box-shadow: 0 0 0 3px rgba(15, 110, 86, 0.15);
}
.field input[type="date"] { min-height: 48px; }
.money {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  letter-spacing: -0.02em;
}

.banner {
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 16px;
}
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.info { background: var(--jade-soft); color: var(--jade-dark); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner.error-text { white-space: pre-wrap; }

.muted { color: var(--muted); }
.center { text-align: center; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  border: 0;
}

/* ---------- Login ---------- */
.login-page {
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 420px;
  margin: 0 auto;
  min-height: 100dvh;
}
.login-hero { text-align: center; margin-bottom: 28px; }
.login-hero .chop { margin: 0 auto 16px; }
.login-hero h1 { font-size: 28px; margin: 0 0 6px; }
.login-card { padding: 22px; }
.login-card .btn { margin-top: 16px; }
.hint { margin-top: 18px; font-size: 13px; color: var(--muted); text-align: center; }

/* ---------- Home ---------- */
.period-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.period {
  padding: 14px 10px 16px;
  text-align: center;
}
.period .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.period .amt {
  margin-top: 8px;
  font-size: clamp(15px, 4.4vw, 20px);
  font-weight: 750;
  color: var(--ink);
}
.period.is-today .amt { color: var(--jade-dark); }

.cta-card {
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
  text-decoration: none;
  color: inherit;
  border: 0;
  width: 100%;
  text-align: left;
}
.cta-card .orb {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: var(--jade);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.cta-card h2 { margin: 0; font-size: 18px; }
.cta-card p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.cta-card.report .orb { background: var(--stamp); }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 22px 2px 10px;
}
.section-head h3 { margin: 0; font-size: 15px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.expense {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 12px 14px;
  align-items: center;
}
.expense .store { font-weight: 650; }
.expense .meta { font-size: 12px; color: var(--muted); }
.expense .amt { font-weight: 700; font-size: 16px; }
.expense .actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.expense button.linkish {
  appearance: none;
  border: 0;
  background: none;
  color: var(--stamp);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 0;
  min-height: 36px;
}

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + var(--safe-bot));
  padding: 8px 18px var(--safe-bot);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: start;
  z-index: 20;
}
.tab {
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 650;
  padding-top: 6px;
  min-height: 56px;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--jade-dark); }
.tab.capture {
  color: #fff;
  margin-top: -22px;
}
.tab.capture .orb {
  width: 58px;
  height: 58px;
  border-radius: 22px;
  background: var(--jade);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 18px rgba(15, 110, 86, 0.35);
  border: 3px solid var(--bg);
}
.tab.capture span { color: var(--jade-dark); margin-top: 2px; }

/* ---------- Capture ---------- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 8px 0 16px;
}
.photo-tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 16px;
  overflow: hidden;
  background: var(--bg-2);
  border: 1px dashed var(--line);
}
.photo-tile img { width: 100%; height: 100%; object-fit: cover; }
.photo-tile .del {
  position: absolute;
  top: 6px; right: 6px;
  width: 32px; height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(28, 25, 23, 0.72);
  color: #fff;
  font-size: 18px;
  line-height: 1;
}
.add-tile {
  appearance: none;
  border: 1.5px dashed var(--jade);
  background: var(--jade-soft);
  color: var(--jade-dark);
  border-radius: 16px;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 700;
  font-size: 13px;
}

/* ---------- Confirm ---------- */
.confirm-list { display: flex; flex-direction: column; gap: 14px; }
.receipt-card { padding: 14px; }
.receipt-card.has-error { border-color: #e8b4ae; box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.08); }
.receipt-head {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}
.thumb {
  width: 72px;
  height: 72px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-2);
  border: 0;
  padding: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
}
.receipt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.receipt-grid .span-2 { grid-column: 1 / -1; }
.remove-row { margin-top: 8px; }

/* ---------- Report ---------- */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}
.month-nav h2 { margin: 0; font-size: 20px; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.filters .span-2 { grid-column: 1 / -1; }
.total-hero {
  padding: 20px 18px;
  margin: 8px 0 16px;
  text-align: center;
}
.total-hero .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.total-hero .amt { font-size: 36px; font-weight: 750; margin-top: 4px; color: var(--jade-dark); }
.total-hero .count { color: var(--muted); font-size: 13px; margin-top: 4px; }

.bars { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.bar-row .meta { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.bar-track { height: 8px; background: var(--bg-2); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--jade); border-radius: 99px; min-width: 0; }

/* ---------- Overlay / modal / lightbox ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.45);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 40;
}
.modal {
  background: var(--paper);
  border-radius: 20px;
  padding: 20px;
  width: min(100%, 400px);
  box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(12, 10, 9, 0.92);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: calc(12px + var(--safe-top)) 12px calc(16px + var(--safe-bot));
}
.lightbox img {
  flex: 1;
  object-fit: contain;
  width: 100%;
  height: 100%;
}
.lightbox button {
  align-self: flex-end;
  background: #fff;
  color: var(--ink);
  border: 0;
  border-radius: 14px;
  min-height: 44px;
  padding: 0 16px;
  font-weight: 700;
  margin-bottom: 8px;
}

.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
.btn-secondary .spinner, .busy-dark .spinner {
  border-color: rgba(15, 110, 86, 0.25);
  border-top-color: var(--jade);
}
@keyframes spin { to { transform: rotate(360deg); } }

.busy-screen {
  position: fixed;
  inset: 0;
  background: rgba(244, 239, 230, 0.78);
  display: grid;
  place-items: center;
  z-index: 30;
  text-align: center;
  padding: 24px;
}
.busy-screen .orb {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--jade);
  display: grid; place-items: center;
  margin: 0 auto 12px;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + 16px + var(--safe-bot));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 60;
  max-width: calc(100% - 32px);
  box-shadow: var(--shadow);
}

@media (min-width: 720px) {
  .page, .login-page { max-width: 560px; margin-left: auto; margin-right: auto; }
  .period .amt { font-size: 22px; }
}
