:root {
  color-scheme: light;
  --page:        #f5f6f3;
  --surface:     #fcfcfb;
  --surface-2:   #eef0eb;
  --border:      rgba(17,20,18,0.11);
  --border-strong: rgba(17,20,18,0.20);
  --text:        #12140f;
  --text-2:      #52564d;
  --muted:       #8a8d82;
  --accent:      #2a78d6;
  --accent-ink:  #ffffff;
  --accent-soft: rgba(42,120,214,0.12);
  --good:        #0ca30c;
  --bad:         #e34948;
  --warn-bg:     #fff4e0;
  --warn-ink:    #7a5400;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --shadow: 0 1px 2px rgba(17,20,18,0.06), 0 8px 24px -12px rgba(17,20,18,0.18);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:        #101210;
    --surface:     #171915;
    --surface-2:   #1f221c;
    --border:      rgba(255,255,255,0.10);
    --border-strong: rgba(255,255,255,0.18);
    --text:        #f4f5f1;
    --text-2:      #c3c5ba;
    --muted:       #8d9086;
    --accent:      #5b9ce8;
    --accent-ink:  #0b1420;
    --accent-soft: rgba(91,156,232,0.16);
    --good:        #3fc23f;
    --bad:         #ef7d7c;
    --warn-bg:     #2c2408;
    --warn-ink:    #f0c975;
    --s1: #5b9ce8; --s2: #f08a5c; --s3: #34c795; --s4: #f0b93a;
    --s5: #f0a0c0; --s6: #4bbf4b; --s7: #9085e9; --s8: #ef7d7c;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -12px rgba(0,0,0,0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:        #101210;
  --surface:     #171915;
  --surface-2:   #1f221c;
  --border:      rgba(255,255,255,0.10);
  --border-strong: rgba(255,255,255,0.18);
  --text:        #f4f5f1;
  --text-2:      #c3c5ba;
  --muted:       #8d9086;
  --accent:      #5b9ce8;
  --accent-ink:  #0b1420;
  --accent-soft: rgba(91,156,232,0.16);
  --good:        #3fc23f;
  --bad:         #ef7d7c;
  --warn-bg:     #2c2408;
  --warn-ink:    #f0c975;
  --s1: #5b9ce8; --s2: #f08a5c; --s3: #34c795; --s4: #f0b93a;
  --s5: #f0a0c0; --s6: #4bbf4b; --s7: #9085e9; --s8: #ef7d7c;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -12px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--text);
  font-family: Manrope, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
}
.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }
h1,h2,h3 { font-weight: 800; letter-spacing: -0.01em; text-wrap: balance; margin: 0; }
a { color: var(--accent); }

.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 24px 80px; }

.topbar { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; }
.topbar .sub { color: var(--text-2); font-size: 13px; }
.brand { display:flex; align-items:center; gap:10px; }
.brand .mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(155deg, var(--s1), var(--s3)); flex: none; display:flex; align-items:center; justify-content:center; box-shadow: var(--shadow); }
.brand .mark svg { width: 16px; height: 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.pad { padding: 20px; }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { padding: 16px 18px; }
.stat .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.stat .value.good { color: var(--good); }
.stat .value.bad { color: var(--bad); }
.good { color: var(--good); }
.bad { color: var(--bad); }

.grid { display: grid; grid-template-columns: 1.55fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 880px) { .grid { grid-template-columns: 1fr; } .stat-row { grid-template-columns: repeat(2,1fr); } }

.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-2); margin-bottom: 12px; display:flex; align-items:center; justify-content:space-between; gap: 8px;}

.btn { font-family: inherit; font-size: 13.5px; font-weight: 600; border-radius: 9px; padding: 9px 14px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; transition: filter .12s ease; }
.btn:hover { filter: brightness(0.97); }
:root:not([data-theme="light"]) .btn:hover { filter: brightness(1.12); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.wide { width: 100%; }

.dropzone { border: 1.5px dashed var(--border-strong); border-radius: 12px; padding: 26px 20px; text-align: center; color: var(--text-2); cursor: pointer; transition: border-color .12s, background .12s; }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .big { color: var(--text); font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.dropzone .hint { font-size: 12.5px; margin-top: 6px; }
input[type=file] { display: none; }

select, input[type=date], input[type=text], input[type=email], input[type=password] {
  font-family: inherit; font-size: 13.5px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 6px 9px;
}
select:focus, input:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; overflow: hidden; }
tr:last-child td { border-bottom: none; }
.amt { text-align: right; white-space: nowrap; }
.desc-cell { max-width: 0; }
.desc-cell .merchant { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.desc-cell .raw { color: var(--muted); font-size: 11.5px; display: block; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ledger-table, .review-table { table-layout: fixed; }
.ledger-table th:nth-child(1), .ledger-table td:nth-child(1) { width: 92px; }
.ledger-table th:nth-child(2), .ledger-table td:nth-child(2) { width: auto; }
.ledger-table th:nth-child(3), .ledger-table td:nth-child(3) { width: 220px; }
.ledger-table th:nth-child(4), .ledger-table td:nth-child(4) { width: 108px; }
.review-table th:nth-child(1), .review-table td:nth-child(1) { width: 92px; }
.review-table th:nth-child(2), .review-table td:nth-child(2) { width: auto; }
.review-table th:nth-child(3), .review-table td:nth-child(3) { width: 96px; }
.review-table th:nth-child(4), .review-table td:nth-child(4) { width: 220px; }
select.ledgerSelect, select.reviewSelect { max-width: 100%; box-sizing: border-box; }

.table-scroll { max-height: min(82vh, 1400px); overflow-y: auto; overflow-x: hidden; border-radius: 10px; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.pill.uncategorized { background: var(--warn-bg); color: var(--warn-ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.range-row { display:flex; align-items:center; gap:8px; flex-wrap: wrap; }
.range-row .to { color: var(--muted); font-size: 12.5px; }

.cat-filter-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.cat-filter-row select { max-width: 240px; }
.cat-filter-row input[type="search"] {
  flex: 1 1 180px; min-width: 140px; max-width: 260px;
  padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
.cat-filter-row input[type="search"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.cat-filter-summary { font-size: 12.5px; color: var(--text-2); }
.cat-filter-summary b { color: var(--text); font-weight: 700; }

.empty { color: var(--muted); text-align: center; padding: 32px 12px; font-size: 13.5px; }

.review-row { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.review-row:last-child { border-bottom: none; }

.banner { display:flex; align-items:center; gap:10px; padding: 10px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 14px; }
.banner.ok { background: color-mix(in oklab, var(--good) 14%, var(--surface)); color: var(--text); }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner.bad { background: color-mix(in oklab, var(--bad) 16%, var(--surface)); color: var(--text); }

.legend { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 3px 6px; margin: 0 -6px; border-radius: 7px; }
.legend-row .name { flex: 1; color: var(--text-2); }
.legend-row .val { font-weight: 600; }
.legend-row .pct { color: var(--muted); width: 38px; text-align: right; }
.legend-row.clickable { cursor: pointer; }
.legend-row.clickable:hover { background: var(--surface-2); }
.legend-row.active { background: var(--accent-soft); }
.legend-row.active .name { color: var(--text); font-weight: 700; }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 9px; }
.tabs button { border: none; background: transparent; font-family: inherit; font-size: 12.5px; font-weight: 600; color: var(--text-2); padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

footer { margin-top: 30px; color: var(--muted); font-size: 12px; text-align: center; }

.modal-overlay { position: fixed; inset: 0; background: rgba(10,12,9,0.45); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 20px; }
.modal { width: 100%; max-width: 640px; max-height: 85vh; display: flex; flex-direction: column; padding: 0; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-body { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; padding: 18px 20px; overflow-y: auto; }
@media (max-width: 560px) { .modal-body { grid-template-columns: 1fr; } }
.cat-col .section-title { margin-bottom: 10px; }
.cat-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.cat-row input[type=text] { flex: 1; min-width: 0; }
.cat-row .catCount { font-size: 11px; color: var(--muted); white-space: nowrap; padding: 0 2px; }
.cat-row .delCat { flex: none; width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); cursor: pointer; font-size: 14px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.cat-row .delCat:hover { color: var(--bad); border-color: var(--bad); }
.cat-add-row { display: flex; gap: 6px; margin-top: 10px; }
.cat-add-row input { flex: 1; min-width: 0; }
.modal-hint { padding: 12px 20px 16px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); display: inline-block; margin-right: 5px; }
.sync-dot.off { background: var(--muted); }

/* ---- Auth pages (login/register) ---- */
.auth-wrap { max-width: 380px; margin: 12vh auto 0; padding: 0 20px; }
.auth-card { padding: 28px 26px; }
.auth-card h1 { font-size: 20px; margin-bottom: 4px; }
.auth-card .sub { color: var(--text-2); font-size: 13px; margin-bottom: 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.field input { width: 100%; padding: 9px 10px; }
.auth-error { color: var(--bad); font-size: 13px; margin-bottom: 12px; min-height: 0; }
.auth-switch { margin-top: 16px; font-size: 13px; color: var(--text-2); text-align: center; }
.user-chip { display:flex; align-items:center; gap: 10px; font-size: 12.5px; color: var(--text-2); }
