/* Layout: app shell — a sticky header, a summary rail beside the ledger on desktop, one column with a bottom scan bar on phones. */
:root {
  --bg: #EDF2F0;
  --surface: #FFFFFF;
  --surface-2: #F5F8F7;
  --ink: #12201D;
  --muted: #5A6B66;
  --line: #D6E0DC;
  --brand: #0E6B5C;
  --brand-ink: #FFFFFF;
  --brand-soft: #DCEEE9;
  --gold: #F0B23A;
  --gold-ink: #3A2905;
  --danger: #B3261E;
  --danger-soft: #FBE7E5;
  --scrim: rgba(8, 22, 19, .45);
  --shadow: 0 1px 2px rgba(10, 40, 34, .06), 0 8px 24px rgba(10, 40, 34, .08);
  --c-food: #D2602A; --c-groceries: #4C8A2C; --c-transport: #2F6FD0; --c-shopping: #B4407A;
  --c-bills: #7A5BC7; --c-health: #C23B4B; --c-fun: #B57C0C; --c-travel: #13809E; --c-other: #6B7773;
  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "Figtree", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1412; --surface: #12201C; --surface-2: #172925; --ink: #E4EEEB; --muted: #94A7A2; --line: #233832;
    --brand: #3CC0A3; --brand-ink: #03201A; --brand-soft: #16362F; --gold: #F4C25C; --gold-ink: #2E2004;
    --danger: #F2867D; --danger-soft: #3A1714; --scrim: rgba(0, 0, 0, .6);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
    --c-food: #F08A55; --c-groceries: #86C064; --c-transport: #74A3F2; --c-shopping: #E37DB0;
    --c-bills: #A88FEC; --c-health: #F07583; --c-fun: #E8B44A; --c-travel: #4CC0DD; --c-other: #9AA8A4;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0B1412; --surface: #12201C; --surface-2: #172925; --ink: #E4EEEB; --muted: #94A7A2; --line: #233832;
  --brand: #3CC0A3; --brand-ink: #03201A; --brand-soft: #16362F; --gold: #F4C25C; --gold-ink: #2E2004;
  --danger: #F2867D; --danger-soft: #3A1714; --scrim: rgba(0, 0, 0, .6);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
  --c-food: #F08A55; --c-groceries: #86C064; --c-transport: #74A3F2; --c-shopping: #E37DB0;
  --c-bills: #A88FEC; --c-health: #F07583; --c-fun: #E8B44A; --c-travel: #4CC0DD; --c-other: #9AA8A4;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
:root { padding-top: env(safe-area-inset-top, 0px); }
img { max-width: 100%; }
[hidden] { display: none !important; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--f-body);
  -webkit-font-smoothing: antialiased;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--surface); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.gutter { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.wrap { max-width: 1180px; margin: 0 auto; }

/* Header */
.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.top .wrap { display: flex; align-items: center; gap: 12px; padding-block: 10px; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
.brand svg { width: 36px; height: 36px; flex: none; }
.brand b { font: 800 22px/1 var(--f-display); letter-spacing: -.02em; }
.brand .ver { display: inline-block; vertical-align: 3px; margin-left: 4px; padding: 1px 7px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font: 600 11px/1.5 var(--f-mono); letter-spacing: 0; }
.brand small { display: block; font-size: 12px; color: var(--muted); line-height: 1.2; }
.sync { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync[data-state="cloud"] i { background: var(--brand); }
.sync[data-state="local"] i, .sync[data-state="signedout"] i, .sync[data-state="offline"] i { background: var(--gold); }
.sync[data-state="synced"] i { background: var(--brand); }
.sync[data-state="error"] i { background: var(--danger); }
.sync[data-state="syncing"] i { background: var(--brand); animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .3; } to { opacity: 1; } }
button.sync { border: 0; background: transparent; padding: 6px 4px; cursor: pointer; font: inherit; font-size: 12px; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 10px; font-weight: 600; font-size: 14px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.gold { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: var(--surface); border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { padding: 8px; }
.btn[disabled] { opacity: .55; cursor: default; }
.desk-actions { display: flex; gap: 8px; }

/* Main grid */
main .wrap { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 20px; align-items: start; padding-block: 20px 120px; }
.rail { display: grid; gap: 16px; position: sticky; top: calc(env(safe-area-inset-top, 0px) + 76px); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }

.month { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 14px 0; }
.month h2 { font: 600 17px/1.2 var(--f-display); margin: 0; }
.hero { padding: 6px 18px 18px; }
.label { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.total { font: 600 clamp(30px, 6vw, 40px)/1.1 var(--f-mono); letter-spacing: -.02em; margin-top: 4px; overflow-wrap: anywhere; }
.delta { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.pill.up { background: var(--danger-soft); color: var(--danger); }
.pill.down { background: var(--brand-soft); color: var(--brand); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.stats div { padding: 12px 14px; }
.stats div + div { border-left: 1px solid var(--line); }
.stats b { display: block; font: 600 16px/1.3 var(--f-mono); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.other-cur { padding: 0 18px 14px; font-size: 12px; color: var(--muted); }

.chart { padding: 16px 16px 12px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--muted); font: 10px var(--f-body); }
.cats { padding: 16px; display: grid; gap: 12px; }
.stack { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.stack span { display: block; height: 100%; }
.cat-row { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; align-items: center; gap: 10px; font-size: 14px; }
.cat-row .dot { width: 10px; height: 10px; border-radius: 3px; }
.cat-row .pct { color: var(--muted); font-size: 12px; width: 36px; text-align: right; }
.panel h3 { font: 600 15px/1.2 var(--f-display); margin: 0; }

/* Ledger */
.ledger { min-width: 0; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font-weight: 600; font-size: 14px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--brand-soft); color: var(--brand); }
.search { flex: 1 1 200px; min-width: 0; position: relative; }
.search input { width: 100%; padding: 9px 12px 9px 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--muted); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.chip i { width: 8px; height: 8px; border-radius: 50%; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }

.day { margin-top: 18px; }
.day:first-child { margin-top: 0; }
.day-h { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 6px; }
.day-h span:last-child { font-family: var(--f-mono); font-size: 13px; color: var(--muted); }
.rows { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 11px 14px; border: 0; background: transparent; }
.row + .row { border-top: 1px solid var(--line); }
.row:hover { background: var(--surface-2); }
.avatar { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; font: 700 15px var(--f-display); color: #fff; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.row .who { min-width: 0; }
.row .who b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .who small { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; }
.row .amt small.fx { display: block; font: 500 12px/1.3 var(--f-body); color: var(--muted); }
.row .amt { font-family: var(--f-mono); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 5px; background: var(--brand-soft); color: var(--brand); }
.tag svg { width: 11px; height: 11px; }

.receipts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.rcard { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; overflow: hidden; padding: 0; text-align: left; }
.rcard .ph { aspect-ratio: 3/4; max-width: 100%; background: var(--surface-2); display: block; width: 100%; object-fit: cover; }
.rcard div { padding: 8px 10px; }
.rcard b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rcard small { color: var(--muted); font-size: 12px; font-family: var(--f-mono); }

.empty { padding: 28px 20px; text-align: center; display: grid; justify-items: center; gap: 10px; }
.empty h3 { font: 700 20px/1.2 var(--f-display); margin: 0; text-wrap: balance; }
.empty p { margin: 0; color: var(--muted); max-width: 40ch; }
.empty .acts { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.examples { margin-top: 16px; opacity: .62; position: relative; }
.examples::after { content: "Example"; position: absolute; top: -9px; right: 12px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; background: var(--gold); color: var(--gold-ink); padding: 1px 8px; border-radius: 6px; }
.examples .row { cursor: default; }
.drop-hint { margin-top: 14px; font-size: 13px; color: var(--muted); }

/* Phone bottom bar */
.dock { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--surface); border-top: 1px solid var(--line);
  padding-top: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
.dock .wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dock .btn { padding: 13px; font-size: 15px; border-radius: 12px; }

/* Sheet */
.scrim { position: fixed; inset: 0; z-index: 40; background: var(--scrim); display: grid; place-items: center; padding: 20px; padding-top: calc(20px + env(safe-area-inset-top, 0px)); padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
.sheet { background: var(--surface); border-radius: 18px; width: min(560px, 100%); max-height: 100%; overflow: auto; box-shadow: var(--shadow); }
.sheet-h { display: flex; align-items: center; gap: 10px; padding: 16px 18px 6px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.sheet-h h2 { font: 700 19px/1.2 var(--f-display); margin: 0 auto 0 0; }
.sheet-b { padding: 8px 18px 18px; display: grid; gap: 14px; }
.sheet-f { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 12px 18px 18px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface); }
.sheet-f .spacer { margin-right: auto; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); min-width: 0; }
.field input.big { font: 600 24px var(--f-mono); }
.amount-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 8px; }
.err { color: var(--danger); font-size: 13px; }
.note { padding: 10px 12px; border-radius: 10px; font-size: 13.5px; background: var(--brand-soft); color: var(--ink); display: flex; gap: 8px; align-items: flex-start; }
.note.warn { background: var(--danger-soft); }
.note svg { width: 18px; height: 18px; flex: none; color: var(--brand); margin-top: 1px; }
.note.warn svg { color: var(--danger); }

.scan-view { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 16px; align-items: start; }
.scan-img { position: relative; border-radius: 10px; overflow: hidden; background: var(--surface-2); aspect-ratio: 3/4; max-width: 100%; }
.scan-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-img .beam { position: absolute; left: 0; right: 0; height: 30%; background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--brand) 45%, transparent), transparent); animation: beam 1.6s ease-in-out infinite alternate; }
@keyframes beam { from { top: -30%; } to { top: 100%; } }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.steps li { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.steps li i { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; }
.steps li[data-s="run"] { color: var(--ink); font-weight: 600; }
.steps li[data-s="run"] i { border-color: var(--brand); border-right-color: transparent; animation: spin .8s linear infinite; }
.steps li[data-s="done"] { color: var(--ink); }
.steps li[data-s="done"] i { background: var(--brand); border-color: var(--brand); }
.steps li[data-s="done"] i::after { content: ""; width: 5px; height: 9px; border: solid var(--brand-ink); border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.steps li[data-s="fail"] i { border-color: var(--danger); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Detail: a paper receipt */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.detail.no-img { grid-template-columns: minmax(0, 1fr); }
.photo { border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--surface-2); padding: 0; display: block; width: 100%; }
.photo img { display: block; width: 100%; height: auto; }
.paper { background: var(--surface-2); padding: 16px 16px 26px; font-family: var(--f-mono); font-size: 13px;
  -webkit-mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / 14px 100%;
  mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / 14px 100%; }
.paper h4 { font: 700 17px/1.2 var(--f-display); margin: 0 0 2px; text-align: center; overflow-wrap: anywhere; }
.paper .meta { text-align: center; color: var(--muted); font-size: 12px; }
.paper hr { border: 0; border-top: 1px dashed var(--muted); margin: 12px 0; opacity: .6; }
.paper .ln { display: flex; justify-content: space-between; gap: 12px; }
.paper .ln span:first-child { min-width: 0; overflow-wrap: anywhere; }
.paper .ln.tot { font-weight: 600; font-size: 16px; }
.big-photo .sheet { width: min(900px, 100%); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 60; background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500; box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center; max-width: calc(100% - 32px); }
.toast button { background: none; border: 0; color: var(--gold); font-weight: 700; padding: 0; }
.dragging main .ledger { outline: 2px dashed var(--brand); outline-offset: 6px; border-radius: 14px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 860px) {
  main .wrap { grid-template-columns: minmax(0, 1fr); padding-block: 14px 120px; }
  .rail { display: contents; }
  .rail > :first-child { order: 1; }
  .ledger { order: 2; }
  .rail > .chart { order: 3; }
  .rail > .cats { order: 4; }
  .desk-actions { display: none; }
  .dock { display: block; }
  .toast { bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }
  .brand small { display: none; }
}
@media (max-width: 560px) {
  .scrim { padding: 0; place-items: end stretch; padding-top: env(safe-area-inset-top, 0px); }
  .sheet { width: 100%; border-radius: 18px 18px 0 0; max-height: 92%; }
  .sheet-f { padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px)); }
  .detail, .scan-view { grid-template-columns: minmax(0, 1fr); }
  .scan-img { max-width: 200px; margin: 0 auto; width: 100%; }
  .fields { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .scan-img .beam, .steps li[data-s="run"] i { animation: none; }
}

/* Installable-app additions */
.progress { height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.install-steps { margin: 0; padding-left: 20px; display: grid; gap: 10px; }
.install-steps b { font-weight: 700; }
.ios-share { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; color: var(--brand); }
.set-row { display: flex; gap: 8px; flex-wrap: wrap; }
.set-sec { display: grid; gap: 8px; }
.set-sec h3 { font: 600 15px/1.2 var(--f-display); margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
@media (display-mode: standalone) { .install-only { display: none !important; } }
