/* One stylesheet for the whole app, custom properties for theming.
   Dark by default: capture happens in shops and the viewfinder dominates,
   and the view screens inherit the same night-friendly palette.

   Clean neutral dark, Vercel/Next.js-style: flat near-black surfaces, grey
   hairlines, no tint anywhere. White is the primary action colour; one calm
   blue marks interactive accents; green and red appear only when they mean
   something (savings, overspend, failures). */
:root {
  --bg: #0a0a0a;
  --card: #111111;
  --card-2: #161616;
  --line: #262626;
  --line-strong: #333333;
  --ink: #ededed;
  --muted: #a1a1a1;
  --accent: #52a9ff;
  --accent-soft: #52a9ff24;
  --accent-ink: #0a0a0a;
  --action: #ededed;
  --action-ink: #0a0a0a;
  --ok: #45de85;
  --ok-strong: #45de85;
  --ok-bg: #111111;
  --ok-line: #1e3a2a;
  --bad: #ff6b66;
  --bad-bg: #1c1010;
  --warn: #f5b944;
  --field: #000000;
  --pad: 14px;
  --radius: 10px;
  --radius-s: 8px;
  --nav-h: 58px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); /* flat, no gradient - the content is the interest */
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  /* Safe areas so the viewfinder can reach the edges on a notched phone. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
h1, h2, h3, h4 { margin: 0 0 .3em; font-weight: 600; }
h3 { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
h4 { font-size: .85rem; color: var(--muted); }
p { margin: .3em 0; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.error { color: var(--bad); }
.pad { padding: var(--pad); }
.banner { padding: var(--pad); background: var(--bad-bg); border-radius: var(--radius); }
.banner.note { background: var(--card-2); color: var(--muted); font-size: .88rem; }
code { background: var(--field); padding: 1px 4px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; }

button {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: 12px 14px; cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
/* The Vercel signature: the primary action is white, not coloured. */
button.primary { background: var(--action); color: var(--action-ink); border-color: var(--action); font-weight: 600; }
button.primary:active { background: #cccccc; border-color: #cccccc; }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 6px; }
button.linky {
  background: none; border: none; padding: 0; color: var(--ink);
  text-align: left; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
button:disabled { opacity: .55; cursor: default; }
input {
  font: inherit; color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: 12px; width: 100%;
}
input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label { display: block; margin: .6em 0; color: var(--muted); font-size: .88rem; }
label input { margin-top: 4px; color: var(--ink); font-size: 1rem; }

/* --- shell ------------------------------------------------------------- */
.app { display: flex; flex-direction: column; min-height: 100vh; }
header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px var(--pad); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: #0a0a0aee; backdrop-filter: blur(8px); z-index: 5;
}
.apptitle { font-weight: 650; font-size: 1.05rem; letter-spacing: .01em; }
/* Queue depth is always visible. It is the one number that tells you whether
   the PC run is worth doing. */
.depth {
  margin-left: auto; min-width: 30px; text-align: center;
  background: var(--action); color: var(--action-ink);
  border-radius: 999px; padding: 3px 10px;
  font-variant-numeric: tabular-nums; font-weight: 600; font-size: .85rem;
}
.signout { text-decoration: none; font-size: .82rem; }
main {
  flex: 1; padding: var(--pad);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + var(--pad));
  animation: screen-in .18s ease;
}
@keyframes screen-in { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) {
  main { animation: none; }
  * { transition: none !important; }
}

/* Bottom tab bar: four ways in, thumb-reachable. */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #0a0a0ae8; backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  position: relative; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px;
  background: none; border: none; border-radius: 0;
  color: var(--muted); font-size: .68rem; padding: 6px 0;
}
/* Active = white, like Vercel's nav; colour is reserved for meaning. */
.tabbar button.on { color: var(--ink); }
.tabbar svg { width: 22px; height: 22px; }
.tabbar .badge {
  position: absolute; top: 4px; left: calc(50% + 8px);
  background: var(--action); color: var(--action-ink);
  border-radius: 999px; min-width: 17px; padding: 1px 5px;
  font-size: .68rem; font-weight: 700; font-variant-numeric: tabular-nums;
}

/* --- cards, login ------------------------------------------------------ */
.card { background: var(--card); border: 1px solid var(--line);
        border-radius: var(--radius); padding: var(--pad); margin-bottom: var(--pad); }
.card.sub { background: var(--card-2); margin-bottom: 8px; }
.login { max-width: 380px; margin: 12vh auto; }

/* Show/hide sits inside the field rather than under it, so it cannot be
   mistaken for the submit button on a narrow screen. */
.reveal { position: relative; display: block; margin-top: 4px; }
.reveal input { padding-right: 68px; margin-top: 0; }
.reveal button {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  padding: 8px 10px; text-decoration: none; color: var(--accent);
}

/* --- capture ----------------------------------------------------------- */
.viewfinder {
  position: relative;
  background: #000; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 3 / 4; display: grid; place-items: center;
}
.viewfinder video { width: 100%; height: 100%; object-fit: cover; }
.camera-fallback { padding: var(--pad); text-align: center; max-width: 34em; }
.camera-fallback .small { color: var(--muted); margin-bottom: 12px; }
.fallback-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.filepick { display: inline-block; background: var(--card); border: 1px solid var(--line);
            border-radius: var(--radius-s); padding: 12px; cursor: pointer; }
.filepick input { display: none; }

/* Attach an existing photo. Overlaid on the viewfinder rather than placed in
   the button row: the camera stays the default and this stays out of the way of
   the two saves, which are the thumb targets that matter. 44px is the smallest
   reliable one-handed tap. */
.attach {
  position: absolute; right: 10px; bottom: 10px;
  display: grid; place-items: center; width: 44px; height: 44px;
  background: #000000b0; border: 1px solid var(--line); border-radius: 999px;
  color: var(--ink); cursor: pointer;
}
.attach input { display: none; }
.attach svg { width: 22px; height: 22px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* An attached photo covers the live feed. `contain`, not `cover` - a cropped
   preview of a receipt hides exactly the end of it you need to check. */
.shot-preview { position: absolute; inset: 0; background: #000; display: grid; place-items: center; }
.shot-preview img { width: 100%; height: 100%; object-fit: contain; }
.shot-preview .discard {
  position: absolute; top: 8px; right: 8px;
  width: 36px; height: 36px; padding: 0; line-height: 1; font-size: 1.3rem;
  border-radius: 999px; background: #000000b0;
}

/* The resting state after "Save & done". */
.capture .done { text-align: center; }
.capture .done button { margin-top: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: var(--pad) 0; }
.chip { padding: 8px 14px; border-radius: 999px; }
.chip.on { background: var(--action); color: var(--action-ink); border-color: var(--action); font-weight: 600; }
.total input { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 8px; margin-top: var(--pad); }
.actions button { flex: 1; }

/* --- queue ------------------------------------------------------------- */
.queue { list-style: none; padding: 0; margin: var(--pad) 0 0; }
.queue li {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px; border-bottom: 1px solid var(--line);
}
.queue .store { font-weight: 600; }
.queue .state { font-size: .8rem; color: var(--muted); }
.queue .code { font-size: .75rem; color: var(--bad); }
.queue li.failed { background: var(--bad-bg); border-radius: var(--radius-s); }
.queue .repair { margin-left: auto; display: flex; gap: 6px; }
.queue .repair button { padding: 6px 10px; font-size: .82rem; }

/* --- glance ------------------------------------------------------------ */
.glance section { margin-bottom: 18px; }
.glance .hero { margin-bottom: 10px; }
/* Savings owns green. It is the payoff of the whole app, so it does not look
   like just another card. */
.glance .hero.savings { background: var(--ok-bg); border-color: var(--ok-line); }
.glance .hero.savings h3 { color: var(--ok); }
.glance .hero.savings .big { color: var(--ok-strong); }
.big { font-size: 2.8rem; font-weight: 650; font-variant-numeric: tabular-nums;
       margin: 0; letter-spacing: -.02em; }
.up { color: var(--bad); }     /* spending more is not good news */
.down { color: var(--ok); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.grid > div { background: var(--card); border: 1px solid var(--line);
              border-radius: var(--radius); padding: 12px; }
.grid > div p { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; margin: 0; }
.grid > div p.muted { font-size: .82rem; font-weight: 400; }
.glance.empty { text-align: center; padding-top: 12vh; }

/* Shared horizontal bars (glance lists, category splits). */
.bars { list-style: none; padding: 0; margin: 0; }
.bars li { display: grid; grid-template-columns: minmax(90px, 1fr) 2fr auto;
           align-items: center; gap: 8px; padding: 5px 0; }
.bars .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.bars .value { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; text-align: right; }
.bar-track { display: block; height: 8px; background: var(--field); border-radius: 4px; overflow: hidden; }
.bar-track.wide { width: 100%; }
.bar { display: block; height: 100%; background: var(--accent); border-radius: 4px;
       min-width: 2px; transition: width .25s ease; }

/* --- export ------------------------------------------------------------ */
.export { margin-top: 4px; }
.exportbtns { display: flex; gap: 8px; flex-wrap: wrap; }
.exportbtns button { font-size: .88rem; }

/* --- browse ------------------------------------------------------------ */
.seg {
  display: flex; gap: 4px; padding: 4px; margin-bottom: var(--pad);
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  overflow-x: auto; scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: 1 0 auto; border: none; background: none; color: var(--muted);
  padding: 8px 12px; border-radius: 999px; font-size: .88rem; white-space: nowrap;
}
.seg button.on { background: var(--action); color: var(--action-ink); font-weight: 600; }

.rows { list-style: none; padding: 0; margin: 0; }
.rows .row { border-bottom: 1px solid var(--line); }
.rows.tight .row { border-bottom-color: var(--card-2); }
.rowmain {
  display: grid; width: 100%; text-align: left;
  grid-template-columns: 1fr auto; grid-template-areas:
    "title amount"
    "sub   comparison";
  gap: 2px 10px; align-items: baseline;
  background: none; border: none; border-radius: 0; padding: 12px 2px;
}
.rowmain:active { background: var(--accent-soft); }
.rowmain.static { cursor: default; }
.rowmain .title { grid-area: title; font-weight: 600; display: inline-flex; align-items: center; gap: 7px; min-width: 0; }
.rowmain .sub { grid-area: sub; color: var(--muted); font-size: .8rem; }
.rowmain .amount { grid-area: amount; font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.rowmain .delta, .rowmain .share { grid-area: comparison; }
.rowmain .share { display: flex; align-items: center; gap: 8px; min-width: 140px; justify-self: end; }
.rowmain .share .bar-track { width: 90px; }
.delta { font-size: .8rem; font-variant-numeric: tabular-nums; text-align: right; }
.delta.up { color: var(--bad); }
.delta.down { color: var(--ok); }
.delta.flat { color: var(--muted); }
.delta .pct { color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.flag { color: var(--warn); margin-left: 6px; font-weight: 700; }
.quickfilter { margin-bottom: 10px; }

.row.open { background: var(--card); border-radius: var(--radius); border-bottom: none; margin-bottom: 8px; }
.row.open .rowmain { padding-left: 10px; padding-right: 10px; }
.rowdetail { padding: 4px 10px 12px; animation: screen-in .15s ease; }
.rowdetail h4 { margin-top: 14px; }

/* Category split rows (used in expanded months, receipt & store detail). */
.catsplit .catrow {
  display: grid; grid-template-columns: 12px minmax(80px, 1fr) 2fr auto;
  align-items: center; gap: 8px; padding: 4px 0;
}
.catsplit .label { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catsplit .value { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.catsplit .pctv { color: var(--ink); }

/* --- search ------------------------------------------------------------ */
.searchbox { font-size: 1.05rem; margin-bottom: 10px; }
.search .kind {
  grid-area: comparison; justify-self: end;
  font-size: .68rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); border: 1px solid var(--line); border-radius: 999px;
  padding: 1px 8px;
}

/* --- detail ------------------------------------------------------------ */
.detail .back { margin-bottom: 10px; padding: 8px 14px; border-radius: 999px; }
.detailhead { margin-bottom: var(--pad); }
.detailhead h2 { display: flex; align-items: center; gap: 8px; }
.kv div { display: flex; justify-content: space-between; padding: 4px 0; gap: 12px; }
.kv div span:last-child { font-variant-numeric: tabular-nums; }
.recon.ok { border-color: var(--ok-line); }
.recon.bad { border-color: #3a2222; background: var(--bad-bg); }
.items { width: 100%; border-collapse: collapse; }
.items td { padding: 7px 4px; border-bottom: 1px solid var(--card-2); vertical-align: top; }
.items tr:last-child td { border-bottom: none; }
.items .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dealtag {
  display: inline-block; margin-left: 6px; padding: 0 6px;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; font-size: .72rem; white-space: nowrap;
}
.receiptphoto { width: 100%; border-radius: var(--radius-s); }
.notes { font-style: italic; }

.stats { margin-bottom: var(--pad); }

/* --- price chart ------------------------------------------------------- */
.chart { position: relative; margin: 4px 0 10px; touch-action: pan-y; }
.chart svg { display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 4; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .axis.end { text-anchor: end; }
.chart .pt { fill: var(--bg); stroke: var(--accent); stroke-width: 2; }
.chart .pt.on { fill: var(--accent); }
.chart .guide { stroke: var(--line-strong); stroke-width: 1; }
.chart .tip {
  position: absolute; top: -4px; transform: translateX(-50%);
  display: flex; gap: 8px; align-items: baseline; white-space: nowrap;
  background: var(--card-2); border: 1px solid var(--line-strong);
  border-radius: var(--radius-s); padding: 4px 10px;
  font-size: .82rem; pointer-events: none;
}
.chart .tip .num { font-weight: 600; }
.history { list-style: none; padding: 0; margin: 0; }
.history li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px;
  padding: 6px 0; border-bottom: 1px solid var(--card-2); font-size: .9rem;
  align-items: baseline;
}
.history li:last-child { border-bottom: none; }
.pricecards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
              gap: 10px; margin-bottom: var(--pad); }
.pricepoint { background: var(--card); border: 1px solid var(--line);
              border-radius: var(--radius); padding: 12px; }
.pricepoint .price { font-size: 1.25rem; font-weight: 650; font-variant-numeric: tabular-nums; margin: 0; }
.alts { list-style: none; padding: 0; margin: 0; }

/* --- held, misc -------------------------------------------------------- */
.held form { display: flex; gap: 8px; margin: 8px 0; }
.held form button { flex: 0 0 auto; }
.empty-state { text-align: center; padding-top: 12vh; }

.update-toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  background: var(--action); color: var(--action-ink); border: none;
  border-radius: 999px; padding: 12px 20px; box-shadow: 0 4px 16px #0008;
  font-weight: 600; z-index: 10;
}
