:root {
  --ink: #1c2430;
  --muted: #5e6872;
  --paper: #f3efe6;
  --card: #fffdf8;
  --line: #e3d9c6;
  --indigo: #1d2b4f;
  --indigo-2: #31457a;
  --teal: #0f766e;
  --teal-d: #0c5f59;
  --red: #9f2d2d;
  --warn-bg: #fff4d6;
  --warn-ink: #7a4b00;
  --danger-bg: #fdeceb;
  --danger-ink: #8d2a2a;
  --shadow: 0 10px 28px rgba(29, 43, 79, 0.08);
  --radius: 18px;
  --tab-h: 64px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --max: 480px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 400px at 50% -10%, #d9e4ea 0%, transparent 55%),
    var(--paper);
  color: var(--ink);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { touch-action: manipulation; }

.app-shell {
  width: min(100%, var(--max));
  min-height: 100dvh;
  margin: 0 auto;
  background: linear-gradient(#f7f4ee, #f3efe6 180px);
  position: relative;
  box-shadow: 0 0 0 1px rgba(29, 43, 79, 0.04);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(12px + var(--safe-t)) 16px 14px;
  background: var(--indigo);
  color: #f7f4ee;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: 0.08em; font-weight: 700; }
.brand p { margin: 0; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.75; }

.seal {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #f4efe4;
  color: var(--red);
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: inset 0 0 0 2px rgba(159, 45, 45, 0.35);
}

.banner {
  margin: 12px 16px 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  border: 1px solid #f0dd9a;
  font-size: 14px;
}
.banner strong { display: block; font-size: 15px; margin-bottom: 2px; }

main {
  padding: 8px 16px calc(var(--tab-h) + var(--safe-b) + 28px);
}

.screen-title { margin: 14px 0 4px; font-size: 20px; }
.screen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.lede, .hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.lede { font-size: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.card-label { font-size: 13px; font-weight: 700; margin-bottom: 8px; }

.photo-empty {
  border: 1.5px dashed #cabb9e;
  border-radius: 14px;
  min-height: 140px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 16px;
  background: #fbf8f2;
  margin-bottom: 12px;
}
.photo-empty p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.photo-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--indigo);
  color: #fff;
  font-weight: 700;
}

.photo-preview img {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: 12px;
  background: #ece6da;
}
.photo-preview .btn { margin-top: 8px; }

.photo-actions, .settings-card .btn, .form-card + .form-error { }

.photo-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
  font-weight: 700;
  width: 100%;
  margin-top: 8px;
}
.btn.compact { width: auto; min-height: 44px; margin: 0; padding: 8px 12px; font-size: 14px; }
.btn.primary { background: var(--teal); color: white; }
.btn.primary:active { background: var(--teal-d); }
.btn.secondary { background: #e7eef0; color: var(--indigo); border-color: #d3e0e4; }
.btn.ghost { background: transparent; color: var(--indigo); border-color: var(--line); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.submit { margin-top: 4px; letter-spacing: 0.06em; }

.file-btn { overflow: hidden; margin-top: 0; }
.file-btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  font-size: 16px;
}

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #d9d0bf;
  background: #fff;
  font-size: 16px;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 3px solid rgba(15, 118, 110, 0.25);
  border-color: var(--teal);
}

.money { display: flex; align-items: center; gap: 8px; }
.money span {
  font-weight: 800;
  color: var(--red);
  min-width: 48px;
}
.money input { flex: 1; }

.form-error {
  background: var(--danger-bg);
  color: var(--danger-ink);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  margin: 0 0 10px;
}
.progress {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--teal-d);
}

.total-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--indigo);
  color: #f7f4ee;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.total-label { display: block; font-size: 12px; letter-spacing: 0.08em; opacity: 0.75; }
.total-card strong { font-size: 28px; font-variant-numeric: tabular-nums; }
.pill {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
}

.table-wrap { overflow-x: auto; border-radius: 14px; border: 1px solid var(--line); background: var(--card); }
.ledger { width: 100%; border-collapse: collapse; min-width: 340px; }
.ledger th, .ledger td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  vertical-align: middle;
}
.ledger th {
  font-size: 12px;
  color: var(--muted);
  background: #f7f3ea;
  position: sticky;
  top: 0;
}
.ledger tr:last-child td { border-bottom: 0; }
.ledger .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--red); font-weight: 700; white-space: nowrap; }
.ledger .shop { max-width: 92px; word-break: break-word; }
.nature-pill {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 999px;
  background: #e7f3f1;
  color: var(--teal-d);
  font-size: 12px;
  white-space: nowrap;
}
.linkish {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #d3e0e4;
  background: #e7eef0;
  color: var(--indigo);
  font-weight: 700;
  font-size: 13px;
}
.linkish:disabled { opacity: 0.45; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
  border: 1px dashed #cabb9e;
  border-radius: 14px;
  background: #fbf8f2;
}

.facts { margin: 0; }
.facts > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.facts > div:last-child { border-bottom: 0; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; font-weight: 700; text-align: right; word-break: break-all; }

.about-card h3 { margin: 0 0 8px; font-size: 16px; }
.about-card p { margin: 0 0 8px; }

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(100%, var(--max));
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: #fffdf8;
  border-top: 1px solid var(--line);
  z-index: 30;
}
.tab {
  border: 0;
  background: transparent;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.tab svg { width: 22px; height: 22px; }
.tab.is-active { color: var(--teal-d); }

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tab-h) + var(--safe-b) + 12px);
  width: min(calc(100% - 32px), 448px);
  background: var(--indigo);
  color: white;
  border-radius: 14px;
  padding: 12px 14px;
  z-index: 40;
  box-shadow: var(--shadow);
  font-size: 14px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

.ocr-status {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  background: #f0f7f6;
  color: var(--teal-d);
}
.ocr-status[data-kind="pending"] {
  background: #f5f1e8;
  color: var(--muted);
}
.ocr-status[data-kind="ok"] {
  background: #e7f5f2;
  color: var(--teal-d);
}
.ocr-status[data-kind="fail"] {
  background: var(--danger-bg);
  color: var(--danger-ink);
}
