/* Chit Tracker — one stylesheet, tokens on :root, dark mode chosen (not flipped). */
:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --line: #e3e2de;
  --grid: #ebeae6;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-soft: #e6f0fc;
  --s1: #2a78d6;      /* own money */
  --s2: #eb6834;      /* FD money */
  --s3: #1baf7a;      /* suspense */
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-soft: #fdecec;
  --warning-soft: #fff6e0;
  --good-soft: #e7f6e7;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #2f2f2c; --grid: #2a2a28;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5; --accent-soft: #1b2a3d;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --good-text: #5fd35f;
    --critical-soft: #3a1d1d; --warning-soft: #3a2f14; --good-soft: #17301a;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #2f2f2c; --grid: #2a2a28;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5; --accent-soft: #1b2a3d;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --good-text: #5fd35f;
  --critical-soft: #3a1d1d; --warning-soft: #3a2f14; --good-soft: #17301a;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.t2 { color: var(--text-2); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

/* ── shell ── */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 20px 14px; border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; padding: 4px 10px 18px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 19px; height: 19px; flex: none; }
.nav-group { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 18px 12px 4px; }
.nav a.minor { padding: 6px 12px; font-size: 13.5px; }
.nav a.minor svg { width: 16px; height: 16px; }
.nav a.mobile-only { display: none; }
tfoot td { border-bottom: 0; border-top: 1px solid var(--line); font-weight: 550; }
.plan-seg button { padding: 4px 10px; font-size: 13px; }
.plan-seg button.on[data-p="attend"] { color: var(--good-text); }
.plan-seg button.on[data-p="proxy"] { color: var(--accent); }
.side-foot { margin-top: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.main { min-width: 0; padding: 26px 32px 80px; max-width: 1240px; width: 100%; }
.top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.top h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; font-weight: 650; }
.top .sub { color: var(--muted); font-size: 14px; }
.spacer { flex: 1; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; z-index: 20; flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); }
  .brand, .side-foot { display: none; }
  .nav { display: flex; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; text-align: center; }
  .nav a.minor, .nav-group { display: none; }
  .nav a.mobile-only { display: flex; }
  .main { padding: 18px 16px 100px; }
  .top h1 { font-size: 21px; }
}

/* ── controls ── */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--text-2); font-size: 14px; font-weight: 500; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.input { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 12px; min-width: 0; }
.input:focus, .seg button:focus-visible, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 7px 13px; border-radius: 10px; cursor: pointer; font-weight: 500; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }

/* ── cards & tiles ── */
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .g2, .g3 { grid-template-columns: 1fr; } .g4 { grid-template-columns: 1fr 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 15px; margin: 0 0 4px; font-weight: 600; }
.card .hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.card-head { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head > div:first-child { flex: 1; min-width: 180px; }
.card-head .hint { margin: 0; }
.tile .label { color: var(--text-2); font-size: 13px; font-weight: 500; }
.tile .value { font-size: 24px; font-weight: 650; letter-spacing: -.01em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .foot { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.hero { display: flex; gap: 24px; align-items: flex-end; flex-wrap: wrap; }
.hero .value { font-size: 52px; font-weight: 650; letter-spacing: -.02em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.hero .label { color: var(--text-2); font-weight: 500; }
.section { margin-top: 24px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 26px 0 10px; }

/* ── status ── */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 550; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill svg { width: 13px; height: 13px; }
.pill.prized { background: var(--accent-soft); color: var(--accent); }
.pill.crit { background: var(--critical-soft); color: var(--critical); }
.pill.warn { background: var(--warning-soft); color: #9a6400; }
:root[data-theme="dark"] .pill.warn { color: var(--warning); }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .pill.warn { color: var(--warning); } }
.pill.good { background: var(--good-soft); color: var(--good-text); }
.banner { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-radius: 12px; background: var(--critical-soft); color: var(--text); margin-bottom: 18px; flex-wrap: wrap; }
.banner svg { color: var(--critical); flex: none; }
.banner.ok { background: var(--good-soft); }
.banner.ok svg { color: var(--good); }

/* ── lists ── */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--line); min-width: 0; }
.row:last-child { border-bottom: 0; }
a.row:hover { background: var(--surface-2); border-radius: 8px; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--muted); font-size: 13px; }
.row .amt { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.daygroup { font-size: 12.5px; font-weight: 600; color: var(--text-2); padding: 14px 4px 4px; display: flex; gap: 8px; }
.empty { color: var(--muted); padding: 22px 4px; text-align: center; }
.when { width: 54px; flex: none; text-align: center; border-radius: 10px; background: var(--surface-2); padding: 5px 0; line-height: 1.1; }
.when b { display: block; font-size: 18px; }
.when span { font-size: 11px; color: var(--muted); text-transform: uppercase; }

/* chittal cards */
.ch-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.ch { display: flex; flex-direction: column; gap: 10px; padding: 15px 16px; }
.ch:hover { border-color: var(--accent); }
.ch-top { display: flex; align-items: center; gap: 8px; }
.ch-no { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ch-top .pill { flex: none; }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; display: flex; gap: 2px; }
.bar i { display: block; height: 100%; background: var(--s1); border-radius: 99px; }
.kv { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--text-2); }
.kv b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 550; color: var(--muted); font-size: 12.5px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
td.r, th.r { text-align: right; }
tr.over td { background: var(--critical-soft); }
tr.future td { color: var(--muted); }
tbody tr:hover td { background: var(--surface-2); }
.chip { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 12px; background: var(--surface-2); color: var(--text-2); margin-right: 3px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; }

/* charts */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridl { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--line); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + g rect, .chart .colg:hover rect { opacity: .82; }
.chart .dlabel { fill: var(--text-2); font-size: 11px; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--text-2); margin: 0 0 10px; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0,0,0,.14); border-radius: 10px; padding: 9px 11px; font-size: 13px; min-width: 150px; max-width: 280px; }
.tip .th { font-weight: 600; margin-bottom: 4px; }
.tip .tr { display: flex; justify-content: space-between; gap: 14px; font-variant-numeric: tabular-nums; }
.tip .tr span:first-child { color: var(--text-2); }

/* split bar (where money went) */
.split { display: flex; height: 10px; border-radius: 99px; overflow: hidden; gap: 2px; background: var(--surface-2); }
.split i { display: block; height: 100%; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; grid-column: 1 / -1; }
.login form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0 0 6px; font-size: 24px; }
.err { color: var(--critical); font-size: 14px; min-height: 20px; }

/* skeleton */
.skel { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 10px; height: 90px; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }
@media (forced-colors: active) { .bar i, .split i, .key { forced-color-adjust: none; } }

/* grid: spreadsheet-like tables (app.js grid) */
.gq { margin-bottom: 8px; max-width: 240px; padding: 5px 10px; }
table.gt th.gs { cursor: pointer; user-select: none; }
table.gt th.gs:hover { color: var(--text); }
table.gt th.gs .arrow { color: var(--accent); }
table.gt .gsel { width: 30px; padding-right: 0; }
table.gt tbody tr { cursor: default; }
table.gt tbody tr.on td { background: var(--accent-soft); }
table.gt tfoot tr.on td { color: var(--accent); }
.gsum { margin-top: 10px; }
.gsum:empty { display: none; }
