:root {
  --navy: #1f3a5f;
  --accent: #f38020;
  --accent-dark: #d96b0e;
  --bg: #f3f4f7;
  --card: #ffffff;
  --text: #1c2330;
  --muted: #667085;
  --line: #e4e7ec;
  --danger: #c4320a;
  --warn-bg: #fff4e5;
  --warn-text: #93370d;

  --s-draft: #667085;
  --s-submitted: #1570ef;
  --s-returned: #dc6803;
  --s-approved: #12b76a;
  --s-paid: #05603a;

  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --card: #182029;
    --text: #e6e9ee;
    --muted: #98a2b3;
    --line: #2a3441;
    --warn-bg: #3a2410;
    --warn-text: #fdb022;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--navy); color: #fff;
}
.brand { font-weight: 800; text-decoration: none; letter-spacing: .02em; }
.brand span { color: var(--accent); }
.switcher select {
  max-width: 210px; padding: 6px 10px; font-size: .85rem;
  border-radius: 999px; border: 1px solid rgba(255, 255, 255, .3);
  background: rgba(255, 255, 255, .12); color: #fff;
}
.switcher option { color: #000; }
.who { font-size: .85rem; opacity: .85; }

/* Layout */
main { max-width: 720px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.35rem; margin: 4px 0 14px; }
h2 { font-size: 1rem; margin: 22px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.back { display: inline-block; margin-bottom: 8px; color: var(--muted); text-decoration: none; font-size: .9rem; }

/* Cards */
.card {
  display: block; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--line);
  padding: 14px 16px; margin-bottom: 12px; text-decoration: none;
}
a.card { transition: transform .12s ease, border-color .12s ease; }
a.card:active { transform: scale(.99); }
a.card:hover { border-color: var(--accent); }
.card-title { font-weight: 700; font-size: 1.02rem; }
.amount { font-weight: 800; font-variant-numeric: tabular-nums; }
.big-total { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* Status badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700;
  color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent);
  white-space: nowrap; transition: background .2s ease, color .2s ease;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.draft { --c: var(--s-draft); }
.badge.submitted { --c: var(--s-submitted); }
.badge.returned { --c: var(--s-returned); }
.badge.approved { --c: var(--s-approved); }
.badge.paid { --c: var(--s-paid); }

.chip {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; background: var(--warn-bg); color: var(--warn-text);
}

/* Banners */
.banner { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; font-size: .95rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }
.banner.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.banner strong { display: block; margin-bottom: 2px; }

/* Category totals */
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 12px; }
.cat { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.cat .muted { font-size: .78rem; text-transform: capitalize; }

/* Expense list */
.expense { display: flex; align-items: center; gap: 12px; }
.thumb {
  flex: none; width: 48px; height: 48px; border-radius: 10px; object-fit: cover;
  background: var(--bg); display: grid; place-items: center; font-size: .65rem; text-align: center; color: var(--muted);
}
.expense .info { flex: 1; min-width: 0; }
.expense .vendor { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0 0 0 4px; }
.timeline li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--line); }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before {
  content: ""; position: absolute; left: -7px; top: 2px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--c, var(--s-draft)); border: 2px solid var(--card);
}
.timeline .comment { margin-top: 4px; padding: 8px 10px; border-radius: 10px; background: var(--bg); font-size: .9rem; }

/* Forms */
label { display: block; font-weight: 600; margin: 14px 0 4px; font-size: .95rem; }
input, select, textarea {
  width: 100%; padding: 12px; font-size: 1rem; font-family: inherit;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.camera {
  display: block; text-align: center; padding: 26px; margin: 0;
  border: 2px dashed var(--muted); border-radius: var(--radius); background: var(--card);
  font-size: 1.05rem; cursor: pointer;
}
#preview { max-width: 100%; max-height: 360px; border-radius: 10px; margin-top: 10px; display: none; }
#ocrStatus { margin: 8px 0; font-size: .9rem; color: var(--muted); text-align: center; min-height: 1.2em; }

/* Buttons */
.btn {
  display: block; width: 100%; padding: 15px; margin-top: 16px;
  font-size: 1.05rem; font-weight: 700; font-family: inherit; text-align: center; text-decoration: none;
  color: #fff; background: var(--accent); border: 0; border-radius: 12px; cursor: pointer;
}
.btn:hover { background: var(--accent-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn.success { background: var(--s-approved); }
.btn.navy { background: var(--navy); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.btn.inline { display: inline-block; width: auto; padding: 8px 14px; margin: 0; font-size: .9rem; }

/* Empty states */
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty p { margin: 4px 0; }

/* Bottom tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; max-width: 180px; position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 16px 4px; text-decoration: none; font-size: .85rem; font-weight: 600; color: var(--muted);
}
.tabbar a.active { color: var(--accent); }
.tabbar .count {
  position: absolute; top: 6px; right: 8px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: .7rem; line-height: 18px; text-align: center;
}

.loading { text-align: center; padding: 40px; color: var(--muted); }
