/* ExpenseTrack — shelf-tag design system
   Palette: pine ink, cool paper, shelf yellow, fresh green, over red */

:root {
  --ink: #10262c;
  --ink-2: #1b3a41;
  --paper: #f2f5f1;
  --surface: #ffffff;
  --surface-2: #e9efe9;
  --line: #d3ddd6;
  --slate: #63797e;
  --shelf: #ffd23f;
  --shelf-deep: #e3ae00;
  --fresh: #128a63;
  --fresh-soft: #dff2ea;
  --over: #c4453f;
  --over-soft: #fbe4e2;
  --radius: 14px;
  --radius-sm: 9px;
  --tap: 44px;
  --pad: 16px;
  --shadow: 0 1px 2px rgba(16, 38, 44, .07), 0 8px 24px -16px rgba(16, 38, 44, .35);
  --font-ui: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-tag: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --ink: #eaf2ee;
  --ink-2: #b9cbc7;
  --paper: #0c1a1e;
  --surface: #142a2f;
  --surface-2: #1b3a41;
  --line: #24454c;
  --slate: #8ba5a8;
  --fresh-soft: #10352b;
  --over-soft: #3a1e1e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 26px -18px rgba(0, 0, 0, .9);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  font-feature-settings: "tnum" 1;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(66px + var(--safe-b)); }

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0 0 .6em; }
a { color: inherit; }

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 12px var(--pad) 10px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.appbar h1 {
  font-family: var(--font-tag);
  font-size: 27px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  line-height: 1;
}
.appbar .sub { color: var(--slate); font-size: 12px; margin-left: auto; text-align: right; }
.appbar .back {
  background: none; border: 0; color: var(--ink); font-size: 22px;
  width: 32px; height: 32px; margin-left: -6px; cursor: pointer;
}

main { padding: 14px var(--pad) 28px; max-width: 720px; margin: 0 auto; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card > h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--slate); font-weight: 700; margin-bottom: 10px;
}
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 18px 2px 8px;
}
.section-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--slate); }

/* ---------- Shelf tag (signature) ---------- */
.tag {
  display: inline-flex; align-items: stretch;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  overflow: hidden;
  background: var(--shelf);
  color: #10262c;
  font-family: var(--font-tag);
  line-height: 1;
  box-shadow: 2px 2px 0 rgba(16, 38, 44, .18);
}
.tag .rate { padding: 4px 7px 3px; font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.tag .per {
  padding: 4px 6px 3px;
  background: var(--ink); color: var(--shelf);
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em;
  display: flex; align-items: center;
}
.tag.sm .rate { font-size: 15px; padding: 3px 6px 2px; }
.tag.sm .per { font-size: 10px; }
.tag.flat { background: var(--surface-2); color: var(--ink); border-color: var(--line); box-shadow: none; }
.tag.flat .per { background: var(--slate); color: var(--surface); }

.delta {
  display: inline-block; font-family: var(--font-tag); font-size: 13px;
  padding: 2px 6px; border-radius: 4px; letter-spacing: .02em; white-space: nowrap;
}
.delta.down { background: var(--fresh-soft); color: var(--fresh); }
.delta.up { background: var(--over-soft); color: var(--over); }
.delta.same { background: var(--surface-2); color: var(--slate); }

/* ---------- Cadence rail ---------- */
.cadence { margin-top: 8px; }
.cadence .rail {
  position: relative; height: 6px; border-radius: 3px;
  background: var(--surface-2); overflow: hidden;
}
.cadence .fill { position: absolute; inset: 0 auto 0 0; background: var(--fresh); border-radius: 3px; }
.cadence .fill.due { background: var(--shelf-deep); }
.cadence .fill.over { background: var(--over); }
.cadence .cap {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 11px; color: var(--slate); margin-top: 4px;
}

/* ---------- Rows ---------- */
.row {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.row .meta { font-size: 12.5px; color: var(--slate); margin-top: 2px; }
.row .amt {
  font-family: var(--font-tag); font-size: 21px; font-weight: 700;
  white-space: nowrap; text-align: right;
}
.rowlink { cursor: pointer; }
.rowlink:active { background: var(--surface-2); }

.daygroup { margin-bottom: 6px; }
.daygroup .dayhead {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 2px 4px; font-size: 12px; color: var(--slate);
  text-transform: uppercase; letter-spacing: .08em; font-weight: 700;
}

/* ---------- Forms ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span {
  display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--slate); font-weight: 700; margin-bottom: 5px;
}
input, select, textarea, button { font-family: inherit; font-size: 16px; color: var(--ink); }
input, select, textarea {
  width: 100%; padding: 11px 12px; min-height: var(--tap);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--ink);
}
textarea { min-height: 76px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--shelf-deep); outline-offset: 1px;
}
input[type="number"] { font-family: var(--font-tag); font-size: 20px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; }
.inline { display: flex; gap: 8px; align-items: center; }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.check input { width: 22px; height: 22px; min-height: 0; flex: none; }
.check span { font-size: 14px; }

button {
  cursor: pointer; border: 0; border-radius: var(--radius-sm);
  min-height: var(--tap); padding: 0 16px; font-weight: 600;
  background: var(--surface-2); color: var(--ink);
}
button.primary { background: var(--ink); color: var(--paper); }
[data-theme="dark"] button.primary { background: var(--shelf); color: #10262c; }
button.tag-btn {
  background: var(--shelf); color: #10262c; border: 1.5px solid var(--ink);
  font-family: var(--font-tag); font-size: 17px; text-transform: uppercase; letter-spacing: .04em;
}
button.ghost { background: transparent; border: 1px solid var(--line); }
button.danger { background: var(--over-soft); color: var(--over); }
button.link { background: none; min-height: 0; padding: 0; color: var(--slate); font-size: 13px; text-decoration: underline; }
button.sm { min-height: 34px; padding: 0 11px; font-size: 13.5px; }
.actions { display: flex; gap: 10px; margin-top: 4px; }
.actions button { flex: 1; }

/* combo box */
.combo { position: relative; }
.combo .list {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); max-height: 236px; overflow: auto;
}
.combo .list div { padding: 11px 12px; border-bottom: 1px solid var(--line); font-size: 15px; }
.combo .list div:last-child { border-bottom: 0; }
.combo .list div .hint { color: var(--slate); font-size: 12px; }
.combo .list div[aria-selected="true"] { background: var(--surface-2); }

/* chips */
.chips { display: flex; gap: 7px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 12px; border-radius: 999px; font-size: 13.5px;
  background: var(--surface); border: 1px solid var(--line); color: var(--slate);
  min-height: 36px; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
[data-theme="dark"] .chip[aria-pressed="true"] { background: var(--shelf); color: #10262c; border-color: var(--shelf); }

/* ---------- Budget meter ---------- */
.meter { margin-top: 10px; }
.meter .bar { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.meter .bar span { display: block; height: 100%; background: var(--fresh); }
.meter .bar span.warn { background: var(--shelf-deep); }
.meter .bar span.over { background: var(--over); }
.meter .cap { display: flex; justify-content: space-between; font-size: 12px; color: var(--slate); margin-top: 5px; }

.bignum { font-family: var(--font-tag); font-size: 42px; font-weight: 700; line-height: 1; }
.bignum small { font-size: 15px; font-weight: 600; color: var(--slate); margin-left: 6px; }

/* ---------- Tabs / nav ---------- */
.tabbar {
  position: fixed; z-index: 40; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar button {
  background: none; border-radius: 0; min-height: 62px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--slate); font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; padding: 0 2px;
}
.tabbar button svg { width: 21px; height: 21px; stroke-width: 1.9; }
.tabbar button[aria-current="page"] { color: var(--ink); }
.tabbar button[aria-current="page"] svg { stroke-width: 2.6; }
[data-theme="dark"] .tabbar button[aria-current="page"] { color: var(--shelf); }

/* ---------- Sheet / dialog ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 60; display: none;
  background: rgba(16, 38, 44, .45);
  align-items: flex-end; justify-content: center;
}
.sheet[open] { display: flex; }
.sheet .panel {
  background: var(--paper); width: 100%; max-width: 720px;
  max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0;
  padding: 16px var(--pad) calc(20px + var(--safe-b));
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(18px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .sheet .panel { animation: none; } }
.sheet .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet .head h2 { font-family: var(--font-tag); font-size: 24px; text-transform: uppercase; letter-spacing: .04em; }
.sheet .head button { background: none; font-size: 22px; min-height: 36px; padding: 0 6px; color: var(--slate); }

/* ---------- Misc ---------- */
.empty { text-align: center; color: var(--slate); padding: 34px 18px; }
.empty .big { font-family: var(--font-tag); font-size: 22px; color: var(--ink); text-transform: uppercase; letter-spacing: .04em; }
.empty p { font-size: 14px; margin-top: 6px; }
.muted { color: var(--slate); font-size: 13px; }
.err { color: var(--over); font-size: 13.5px; margin: 6px 0; }
.ok { color: var(--fresh); font-size: 13.5px; margin: 6px 0; }
canvas { max-width: 100%; }
.chartbox { position: relative; height: 220px; }
.scanbox { border-radius: var(--radius); overflow: hidden; background: #000; min-height: 240px; }
.scanbox video, .scanbox img { width: 100%; display: block; }
table.mini { width: 100%; border-collapse: collapse; font-size: 14px; }
table.mini th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--slate); padding: 6px 4px; }
table.mini td { padding: 5px 4px; border-top: 1px solid var(--line); }
table.mini td input { padding: 7px 8px; min-height: 36px; font-size: 14px; }
table.mini td input[type="number"] { font-size: 15px; }

.toast {
  position: fixed; z-index: 80; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + var(--safe-b));
  background: var(--ink); color: var(--paper);
  padding: 11px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); max-width: 90vw;
}
[data-theme="dark"] .toast { background: var(--shelf); color: #10262c; }

.updatebar {
  position: fixed; z-index: 70; left: 10px; right: 10px;
  bottom: calc(72px + var(--safe-b));
  display: flex; align-items: center; gap: 12px;
  background: var(--shelf); color: #10262c;
  border: 1.5px solid var(--ink); border-radius: var(--radius);
  padding: 10px 12px; font-size: 14px; font-weight: 600;
  box-shadow: 3px 3px 0 rgba(16, 38, 44, .22);
}
.updatebar button {
  margin-left: auto; flex: none;
  background: var(--ink); color: var(--shelf);
  font-family: var(--font-tag); font-size: 15px;
  text-transform: uppercase; letter-spacing: .05em;
}
