/* Layout: green signage header, one working column, receipt-like cards, bottom tab bar for thumb reach. System fonts only so the app renders identically offline. */
:root {
  --bg: #f2f4ee;
  --surface: #ffffff;
  --ink: #16241b;
  --muted: #5b6a60;
  --line: #dbe2d6;
  --brand: #1c4f30;
  --brand-ink: #ffffff;
  --accent: #f4b400;
  --accent-ink: #2a1f00;
  --good: #1d7a44;
  --bad: #b8322a;
  --soft: #eef3ea;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1612; --surface: #17211b; --ink: #e6eee7; --muted: #98a99d; --line: #2a372f;
    --brand: #143522; --brand-ink: #f2f6f2; --accent: #f6c32e; --accent-ink: #231a00;
    --good: #57c785; --bad: #ff8172; --soft: #132019;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45;
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
}
.num, input.num { font-variant-numeric: tabular-nums; }
.wrap { max-width: 720px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
[hidden] { display: none !important; }

/* header */
.top { background: var(--brand); color: var(--brand-ink); padding-top: env(safe-area-inset-top, 0px); }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 12px; }
h1 { margin: 0; font-size: 1.25rem; font-weight: 800; letter-spacing: -0.01em; }
.badge { font-size: 0.75rem; font-weight: 700; background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 3px 10px; }
.update { background: var(--accent); color: var(--accent-ink); }
.update-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 8px; font-weight: 600; }

main { display: grid; gap: 16px; padding-block: 16px 24px; }
h2 { margin: 0; font-size: 1.1rem; font-weight: 800; text-wrap: balance; }
h3 { margin: 0; font-size: 0.95rem; font-weight: 700; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.eyebrow { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

/* controls */
button, .btn {
  font: inherit; font-weight: 650; cursor: pointer; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); padding: 8px 14px; min-height: 42px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.go { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--bad); }
button.danger.armed { background: var(--bad); color: #fff; border-color: var(--bad); }
button.ghost { background: transparent; }
button.small { min-height: 34px; padding: 4px 10px; font-size: 0.85rem; }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, input:focus-visible, a:focus-visible, summary:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input, select {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; min-height: 42px; width: 100%; min-width: 0;
}
label.field { display: grid; gap: 4px; min-width: 0; }
label.field > span { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.row-btns > * { flex: 1 1 auto; }

/* segmented mode switch */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; min-height: 38px; background: transparent; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }

/* summary card */
.summary { background: var(--brand); color: var(--brand-ink); border-radius: 16px; padding: 14px; display: grid; gap: 12px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; }
.stat .k { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.8; }
.stat .v { font-size: 1.3rem; font-weight: 800; line-height: 1.15; overflow-wrap: anywhere; }
.stat .v small { font-size: 0.68rem; font-weight: 500; opacity: 0.75; margin-left: 3px; }
.stat.hl .v { color: var(--accent); }
.track { height: 8px; border-radius: 99px; background: rgba(255,255,255,0.2); overflow: hidden; }
.fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.25s ease; }
.meta { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 0.8rem; }
.var-good { color: #8ff0b4; font-weight: 700; }
.var-bad { color: #ffb3a8; font-weight: 700; }

.meta-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }

/* lines */
.lines { display: grid; gap: 8px; }
.line { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; gap: 10px; }
.line.bought { background: var(--soft); border-color: color-mix(in srgb, var(--good) 35%, var(--line)); }
.line-head { display: flex; align-items: flex-start; gap: 10px; }
.line-head .grow { flex: 1; min-width: 0; display: grid; gap: 2px; }
.line-name { font-weight: 750; font-size: 1.02rem; overflow-wrap: anywhere; }
.line-name-input { font-weight: 750; padding: 6px 8px; min-height: 38px; }
.line-total { font-weight: 800; white-space: nowrap; text-align: right; }
.line-total small { display: block; font-weight: 500; font-size: 0.72rem; color: var(--muted); }
.tick { width: 34px; height: 34px; min-height: 0; padding: 0; border-radius: 10px; border: 2px solid var(--muted); background: transparent; flex: none; }
.tick svg { width: 20px; height: 20px; stroke: #fff; fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.line.bought .tick { background: var(--good); border-color: var(--good); }
.line.bought .tick svg { opacity: 1; }
.grid3 { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 0.8fr) minmax(0, 1.3fr); gap: 8px; align-items: end; }
.grid2 { display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); gap: 8px; align-items: end; }
.unit-in { text-transform: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 0.78rem; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 0.75rem; padding: 2px 8px; border-radius: 99px; background: var(--soft); color: var(--muted); }
.chip.up { color: var(--bad); background: color-mix(in srgb, var(--bad) 13%, transparent); }
.chip.down { color: var(--good); background: color-mix(in srgb, var(--good) 15%, transparent); }
.chip.tag { color: var(--accent-ink); background: var(--accent); }

.add { background: var(--surface); border: 1px dashed var(--muted); border-radius: 14px; padding: 12px; display: grid; gap: 10px; }
.add .grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 0.8fr) minmax(0, 1.2fr); gap: 8px; }
@media (max-width: 520px) {
  .add .grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .add .grid .wide { grid-column: 1 / -1; }
}
.err { color: var(--bad); font-size: 0.85rem; font-weight: 600; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: grid; gap: 12px; }
.panel.callout { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 0.92rem; }
.check input { width: 20px; height: 20px; min-height: 0; flex: none; margin-top: 1px; accent-color: var(--brand); }

.empty { text-align: center; padding: 26px 16px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; display: grid; gap: 6px; }

/* records */
details.rec { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
details.rec > summary { list-style: none; cursor: pointer; padding: 12px 14px; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
details.rec > summary::-webkit-details-marker { display: none; }
.rec-left { min-width: 0; display: grid; gap: 2px; }
.rec-right { text-align: right; white-space: nowrap; font-weight: 800; }
.rec-body { padding: 0 14px 14px; display: grid; gap: 12px; }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 6px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; white-space: normal; min-width: 72px; }
th { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); background: var(--soft); }
tr:last-child td { border-bottom: 0; }
tr.skipped td { color: var(--muted); }
tfoot td { font-weight: 800; background: var(--soft); }

/* insights */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; gap: 2px; min-width: 0; }
.kpi .v { font-size: 1.2rem; font-weight: 800; overflow-wrap: anywhere; }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 0.85rem; }
.bar { height: 14px; background: var(--soft); border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 6px; }
@media (prefers-color-scheme: dark) { .bar > i { background: var(--good); } }
.item-cards { display: grid; gap: 8px; }
.item-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; gap: 8px; }
.item-card .head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 10px; font-size: 0.82rem; }
.facts b { display: block; font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.spark { width: 100%; height: 36px; display: block; }
.spark path.l { fill: none; stroke: var(--brand); stroke-width: 2; }
.spark circle { fill: var(--accent); stroke: var(--brand); stroke-width: 1.5; }
@media (prefers-color-scheme: dark) { .spark path.l { stroke: var(--good); } }
select.sort { width: auto; }

/* bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
}
.tabs a { display: grid; justify-items: center; gap: 2px; padding: 8px 4px 10px; color: var(--muted); text-decoration: none; font-size: 0.72rem; font-weight: 700; }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current="page"] { color: var(--brand); }
@media (prefers-color-scheme: dark) { .tabs a[aria-current="page"] { color: var(--accent); } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom, 0px)); z-index: 30;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 0.9rem;
  max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,0.25);
}
@media (prefers-reduced-motion: reduce) { .fill { transition: none; } }
