/* ========================================================================== */
/* Base + Theme Tokens                                                        */
/* ========================================================================== */

* { box-sizing: border-box; }

:root {
  /* Light theme (default) */
  --bg: #f7f7f7;
  --card: #ffffff;
  --ink: #222222;
  --muted: #6b7280;
  --muted-ink: #374151;
  --line: #e5e7eb;
  --line-soft: #f0f0f0;
  --brand: #e74b2e;
  --accent: #0e7afe;

  --pos: #047857;   /* positive amounts */
  --neg: #b91c1c;   /* negative amounts */

  --chip-bg: #fafafa;
  --chip-border: #e5e7eb;

  --shadow: 0 1px 0 var(--line);
  --focus: 0 0 0 3px rgba(14,122,254,.25);

  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;

  --input-bg: #ffffff;
  --input-ink: var(--ink);
  --input-border: #d1d5db;
  --input-border-hover: #9ca3af;

  --table-head: #fafafa;
}

html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Dark theme tokens (manual override) */
html[data-theme="dark"] {
  --bg: #0f1115;
  --card: #151922;
  --ink: #e6e8eb;
  --muted: #9aa4b2;
  --muted-ink: #b8c0cc;
  --line: #232834;
  --line-soft: #1b2030;
  --brand: #ff633b;         /* a touch brighter on dark */
  --accent: #6aa8ff;

  --pos: #4ade80;
  --neg: #f87171;

  --chip-bg: #1b2130;
  --chip-border: #2a3244;

  --shadow: 0 1px 0 rgba(0,0,0,.35);
  --focus: 0 0 0 3px rgba(106,168,255,.35);

  --input-bg: #111520;
  --input-ink: #e6e8eb;
  --input-border: #2a3244;
  --input-border-hover: #3a465c;

  --table-head: #1a1f2b;
}

/* Dark theme tokens (auto, if no manual override) */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #0f1115;
    --card: #151922;
    --ink: #e6e8eb;
    --muted: #9aa4b2;
    --muted-ink: #b8c0cc;
    --line: #232834;
    --line-soft: #1b2030;
    --brand: #ff633b;
    --accent: #6aa8ff;

    --pos: #4ade80;
    --neg: #f87171;

    --chip-bg: #1b2130;
    --chip-border: #2a3244;

    --shadow: 0 1px 0 rgba(0,0,0,.35);
    --focus: 0 0 0 3px rgba(106,168,255,.35);

    --input-bg: #111520;
    --input-ink: #e6e8eb;
    --input-border: #2a3244;
    --input-border-hover: #3a465c;

    --table-head: #1a1f2b;
  }
}

/* ========================================================================== */
/* Top bar + Actions                                                          */
/* ========================================================================== */

.topbar {
  display:flex; align-items:center; justify-content:space-between;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.topbar h1 { margin:0; font-size: 18px; color: var(--ink); }
.actions { display:flex; gap:8px; }

.btn {
  appearance:none; border:1px solid var(--input-border); background: var(--input-bg);
  color: var(--ink); padding:8px 12px; border-radius: var(--radius-sm); cursor:pointer;
  transition: border-color .15s ease, background-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.btn:hover { border-color: var(--input-border-hover); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn-primary { background: var(--accent); color:#fff; border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.06); }

/* ========================================================================== */
/* Dropzone                                                                   */
/* ========================================================================== */

.dropzone { margin:16px; border:2px dashed var(--input-border); border-radius: var(--radius); background: var(--card); }
.dropzone.dragover { border-color: var(--accent); background: color-mix(in oklab, var(--accent) 9%, var(--card)); }
.dz-inner { padding: 26px; text-align:center; color: var(--muted); }
.dz-inner strong { color: var(--ink); }

/* ========================================================================== */
/* Tabs                                                                       */
/* ========================================================================== */

.tabs { display:flex; gap:8px; align-items:center; padding: 0 16px; margin-top:6px; }
.tab {
  border:none; background:transparent; padding:10px 12px; border-bottom:2px solid transparent; cursor:pointer;
  color: var(--ink);
}
.tab:hover { color: var(--brand); }
.tab.active { border-color: var(--brand); color: var(--brand); font-weight:600; }
.tabs .spacer { flex:1; }
.tabs input[type="search"] {
  padding:8px 10px; border:1px solid var(--input-border); border-radius: var(--radius-sm);
  min-width: 240px; background: var(--input-bg); color: var(--input-ink);
}
.tabs input[type="search"]::placeholder { color: var(--muted); }
.tabs input[type="search"]:focus-visible { outline: none; box-shadow: var(--focus); }

/* ========================================================================== */
/* Views                                                                       */
/* ========================================================================== */

main { padding: 16px; }
.tabview { display:none; }
.tabview.active { display:block; }

/* ========================================================================== */
/* Tables                                                                      */
/* ========================================================================== */

.tx-table { width:100%; border-collapse: collapse; background: var(--card);
  border-radius: var(--radius); overflow:hidden; box-shadow: var(--shadow); color: var(--ink);
}
.tx-table th, .tx-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top;
}
.tx-table th { text-align:left; background: var(--table-head); font-weight:600; color: var(--ink); }
.tx-table .num { text-align:right; font-variant-numeric: tabular-nums; }

.tx-table td .cat, .tx-table td .subcat,
select.cat, select.subcat {
  width: 100%; padding:6px 8px; border:1px solid var(--input-border); border-radius: var(--radius-xs);
  background: var(--input-bg); color: var(--input-ink);
}
.tx-table td .cat:focus-visible, .tx-table td .subcat:focus-visible { outline: none; box-shadow: var(--focus); }

.badge {
  display:inline-block; padding:2px 6px; border-radius: var(--radius-xs);
  background: var(--chip-bg); border: 1px solid var(--chip-border);
  font-size:12px; color: var(--muted-ink);
}

/* Amount colouring */
.positive { color: var(--pos); }
.negative { color: var(--neg); }

/* ========================================================================== */
/* Breakdown                                                                   */
/* ========================================================================== */

.card { background: var(--card); border:1px solid var(--line); border-radius: var(--radius); padding:12px; color: var(--ink); }
.grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap:12px; }
.card h3 { margin:0 0 6px; font-size:14px; color: var(--ink); }
.small { color: var(--muted); font-size: 12px; }
.tot { font-weight:700; }
.subrow { display:flex; justify-content:space-between; padding:2px 0; }
.subrow .label { color: var(--muted-ink); }
.subrow .amt { font-variant-numeric: tabular-nums; }

/* ========================================================================== */
/* Insights / Recurring                                                        */
/* ========================================================================== */

.insights { display:flex; justify-content:flex-end; padding: 0 16px; margin: 8px 0; }
.insight-card { background: var(--card); border:1px solid var(--line); border-radius: var(--radius); padding:10px 12px; max-width: 720px; }
.insight-head { font-weight:600; margin-bottom:6px; color: var(--ink); }
.chiplist { display:flex; flex-wrap:wrap; gap:6px; }
.chip {
  border:1px solid var(--chip-border); border-radius:999px; padding:6px 10px; background: var(--chip-bg);
  color: var(--muted-ink);
}
.chip .m { font-weight:600; margin-right:6px; color: var(--ink); }
.chip .a { font-variant-numeric: tabular-nums; }
.chip.small { font-size:12px; }

/* Active chip (filter ON) */
.chip.active {
  background: color-mix(in oklab, var(--accent) 18%, var(--chip-bg));
  border-color: var(--accent);
  color: var(--ink);
}

/* ========================================================================== */
/* Utilities                                                                   */
/* ========================================================================== */

a { color: var(--accent); }
a:hover { filter: brightness(1.08); }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }

/* Subtle scrollbars on dark mode (WebKit) */
@media (prefers-color-scheme: dark) {
  *::-webkit-scrollbar { height: 10px; width: 10px; }
  *::-webkit-scrollbar-track { background: transparent; }
  *::-webkit-scrollbar-thumb { background: #2a3244; border-radius: 999px; }
  *::-webkit-scrollbar-thumb:hover { background: #3a465c; }
}
