/* Expense Tracker — modern fintech look, dense where it counts.
   Dark by default, light via [data-theme="light"]. All color via tokens. */

:root,
[data-theme="dark"] {
  --bg: #0a0e17;
  --surface: #121a2b;
  --surface-2: #182236;
  --surface-hover: #1b2740;
  --track: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.08);
  --border-2: rgba(255, 255, 255, 0.14);
  --text: #eef2f9;
  --muted: #93a1b8;
  --faint: #5e6b82;
  --green: #34d399;
  --red: #fb7185;
  /* accent is driven by a single hue so the whole theme color is swappable */
  --accent-h: 245;
  --accent: hsl(var(--accent-h), 85%, 72%);
  --accent-2: hsl(calc(var(--accent-h) + 28), 80%, 70%);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03), 0 10px 30px -16px rgba(0, 0, 0, 0.7);
  --hero-grad: linear-gradient(140deg, hsl(var(--accent-h), 70%, 56%), hsl(calc(var(--accent-h) + 28), 68%, 54%), hsl(calc(var(--accent-h) + 52), 66%, 52%));
}

[data-theme="light"] {
  --bg: #eef1f7;
  --surface: #ffffff;
  --surface-2: #f5f7fc;
  --surface-hover: #eef2fb;
  --track: rgba(15, 23, 42, 0.08);
  --border: rgba(15, 23, 42, 0.09);
  --border-2: rgba(15, 23, 42, 0.16);
  --text: #0f172a;
  --muted: #5b6678;
  --faint: #94a3b8;
  --green: #059669;
  --red: #e11d48;
  --accent: hsl(var(--accent-h), 74%, 52%);
  --accent-2: hsl(calc(var(--accent-h) + 28), 70%, 52%);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 12px 28px -18px rgba(16, 24, 40, 0.25);
  --hero-grad: linear-gradient(140deg, hsl(var(--accent-h), 72%, 55%), hsl(calc(var(--accent-h) + 28), 68%, 53%), hsl(calc(var(--accent-h) + 52), 66%, 51%));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* the hidden attribute must always hide */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  transition: background 0.2s ease, color 0.2s ease;
}
a { color: inherit; text-decoration: none; }
h2 { margin: 0; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.right { text-align: right; }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* ── top bar ───────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 11px 20px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; letter-spacing: -0.01em; font-size: 15px; }
.brand .dot { color: var(--accent); }
.tabs { display: flex; gap: 3px; flex-wrap: wrap; }
.tab {
  padding: 7px 13px; border-radius: 9px; color: var(--muted); font-weight: 600;
  font-size: 13px; border: 1px solid transparent; transition: all 0.15s;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); border-color: var(--border-2); box-shadow: var(--shadow); }
.tab .pill {
  display: inline-block; min-width: 18px; text-align: center; margin-left: 6px;
  padding: 0 6px; border-radius: 999px; background: var(--red); color: #fff;
  font-size: 11px; font-weight: 800;
}
.spacer { flex: 1; }
.monthnav { display: flex; align-items: center; gap: 6px; }
.monthnav a, .btn, .iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text);
  border-radius: 9px; padding: 7px 11px; font-weight: 600; font-size: 13px; cursor: pointer;
  transition: all 0.15s; box-shadow: var(--shadow);
}
.monthnav a:hover, .btn:hover, .iconbtn:hover { border-color: var(--accent); transform: translateY(-1px); }
.monthnav .label { min-width: 134px; text-align: center; font-weight: 700; box-shadow: none; border: none; background: none; }
.iconbtn { width: 36px; height: 34px; padding: 0; font-size: 15px; }
.btn-accent { background: var(--hero-grad); color: #fff; border-color: transparent; }

/* accent color picker */
.palette { position: relative; display: inline-flex; }
.palette-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent);
  display: inline-block; box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.swatch-pop { position: absolute; top: 44px; right: 0; z-index: 45; background: var(--surface);
  border: 1px solid var(--border-2); box-shadow: var(--shadow); border-radius: 14px; padding: 12px;
  display: grid; grid-template-columns: repeat(4, 28px); gap: 9px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer;
  padding: 0; background: hsl(var(--sh), 75%, 58%); box-shadow: none; transition: transform 0.12s; }
.swatch:hover { border-color: var(--text); transform: scale(1.1); }
.hue-slider { grid-column: 1 / -1; width: 100%; margin-top: 4px; height: 12px; border-radius: 7px;
  cursor: pointer; -webkit-appearance: none; appearance: none;
  background: linear-gradient(to right, hsl(0,80%,55%), hsl(60,80%,55%), hsl(120,80%,55%),
    hsl(180,80%,55%), hsl(240,80%,55%), hsl(300,80%,55%), hsl(360,80%,55%)); }
.hue-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 2px solid rgba(0, 0, 0, 0.35); cursor: pointer; }
.hue-slider::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: #fff;
  border: 2px solid rgba(0, 0, 0, 0.35); cursor: pointer; }
.btn-sm { padding: 5px 9px; font-size: 12px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 22px 20px 60px; }

/* ── hero stat cards ───────────────────────────────────────────────────── */
.hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(186px, 1fr)); gap: 14px; align-items: start; }
.hcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 18px 18px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.hcard .label { font-size: 11.5px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.hcard .value { font-size: 29px; font-weight: 800; margin-top: 7px; letter-spacing: -0.02em; }
.hcard .sub { font-size: 12px; color: var(--faint); margin-top: 5px; }
.hcard.net { background: var(--hero-grad); border-color: transparent; color: #fff; }
.hcard.net .label { color: rgba(255, 255, 255, 0.82); }
.hcard.net .sub { color: rgba(255, 255, 255, 0.78); }
.hcard.income .value { color: var(--green); }
.hcard.expense .value { color: var(--red); }

/* total balance card with an account dropdown */
.hcard.balance { position: relative; overflow: visible; }
details.hcard.balance > summary { list-style: none; cursor: pointer; }
details.hcard.balance > summary::-webkit-details-marker { display: none; }
details.hcard.balance[open] { z-index: 20; }
.acct-list { position: absolute; top: calc(100% - 6px); left: 0; right: 0; z-index: 25;
  background: var(--surface); border: 1px solid var(--border-2); box-shadow: var(--shadow);
  border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.acct-row { display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.acct-row:hover { background: var(--surface-2); }
.acct-row .an { font-weight: 600; }
.acct-row .ab { font-weight: 800; }

/* ── panels ────────────────────────────────────────────────────────────── */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 18px 20px; box-shadow: var(--shadow); margin-top: 16px;
}
.panel-h { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.panel-h h2 { font-size: 15px; font-weight: 700; }
.section-h { display: flex; align-items: baseline; gap: 10px; margin: 24px 2px 12px; }
.section-h h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }

/* ── donut + legend ────────────────────────────────────────────────────── */
.breakdown { display: grid; grid-template-columns: 200px 1fr; gap: 26px; align-items: center; }
.donut { position: relative; width: 200px; height: 200px; }
.donut svg { width: 100%; height: 100%; transform: rotate(0deg); }
.donut-track { stroke: var(--track); }
.donut svg circle { transition: stroke-width 0.15s; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.donut-center .dc-amt { font-size: 23px; font-weight: 800; letter-spacing: -0.02em; }
.donut-center .dc-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-top: 2px; }
.legend { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
.legend-row { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 10px; transition: background 0.12s; }
.legend-row:hover { background: var(--surface-2); }
.legend-row .dot { width: 11px; height: 11px; border-radius: 4px; flex: none; }
.legend-row .nm { flex: 1; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-row .amt { font-weight: 800; font-size: 13.5px; }
.legend-row .pct { color: var(--muted); width: 46px; text-align: right; font-size: 12px; }

/* ── horizontal category bars ──────────────────────────────────────────── */
.dot { width: 11px; height: 11px; border-radius: 4px; flex: none; display: inline-block; }
.bars { display: flex; flex-direction: column; gap: 11px; }
.bar-row { display: grid; grid-template-columns: 168px 1fr 132px; gap: 14px; align-items: center; padding: 5px 7px; border-radius: 9px; transition: background 0.12s; }
.bar-row:hover { background: var(--surface-2); }
.bar-label { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 10px; border-radius: 6px; background: var(--track); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; min-width: 3px; }
.bar-amt { text-align: right; font-weight: 800; font-size: 13px; }
.bar-amt .muted { font-weight: 600; font-size: 11.5px; margin-left: 4px; }

/* ── daily spend chart (y-axis gridlines + hover tooltips) ─────────────── */
.chartwrap { display: flex; }
.yaxis { position: relative; width: 50px; height: 150px; flex: none; }
.ytick { position: absolute; right: 9px; transform: translateY(50%); font-size: 11px;
  color: var(--faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.plot { position: relative; flex: 1; height: 150px; }
.gridline { position: absolute; left: 0; right: 0; height: 1px; background: var(--track); }
.daychart { position: relative; display: flex; align-items: flex-end; gap: 3px; height: 100%; }
.daycol { position: relative; flex: 1; height: 100%; display: flex; align-items: flex-end; }
.daybar { width: 100%; min-height: 2px; border-radius: 3px 3px 0 0;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 45%, transparent)); transition: opacity 0.12s; }
.daycol:hover .daybar { opacity: 0.6; }
.daytip { position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); z-index: 40;
  background: var(--surface); border: 1px solid var(--border-2); box-shadow: var(--shadow);
  border-radius: 10px; padding: 9px 11px; min-width: 184px; max-width: 260px; display: none; }
.daycol:hover .daytip { display: block; }
.daytip-h { font-weight: 700; font-size: 12px; margin-bottom: 6px; }
.daytip-row { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 2px 0; }
.daytip-row .m { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.daytip-row .a { font-weight: 700; }
.daychart-axis { display: flex; justify-content: space-between; margin: 7px 0 0 50px; font-size: 11px; color: var(--faint); }
.daycol { cursor: pointer; text-decoration: none; }

/* ── monthly budget gauge ──────────────────────────────────────────────── */
.budget-wrap { display: flex; gap: 26px; align-items: center; }
.gauge { position: relative; width: 188px; height: 188px; flex: none; }
.gauge-svg { width: 100%; height: 100%; }
.gauge-track { stroke: var(--track); }
.gauge-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.gc-spent { font-size: 25px; font-weight: 800; letter-spacing: -0.02em; }
.gc-of { font-size: 12px; color: var(--muted); margin-top: 1px; }
.gc-status { font-size: 13px; font-weight: 800; margin-top: 7px; }
.budget-side { flex: 1; min-width: 0; }
.brow { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.brow:last-of-type { border-bottom: none; }
@media (max-width: 600px) { .budget-wrap { flex-direction: column; } .budget-side { width: 100%; } }

/* day anchor jump: clear the sticky bar + briefly highlight the landing day */
.day { scroll-margin-top: 74px; }
.day:target { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 32%, transparent); }

/* legacy chips (kept for any view that still uses them) */
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.chip { --c: #64748b; display: block; border: 1px solid var(--border-2); border-left: 4px solid var(--c);
  background: color-mix(in srgb, var(--c) 12%, var(--surface)); border-radius: 12px; padding: 11px 13px; box-shadow: var(--shadow); }
.chip:hover { border-color: var(--c); }
.chip .n { font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 7px; }
.chip .swatch { width: 9px; height: 9px; border-radius: 3px; background: var(--c); flex: none; }
.chip .row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 6px; }
.chip .amt { font-size: 18px; font-weight: 800; }
.chip .cnt { color: var(--muted); font-size: 12px; }

/* ── daily breakdown ───────────────────────────────────────────────────── */
.day { border: 1px solid var(--border); border-radius: 14px; margin-bottom: 9px; background: var(--surface); overflow: hidden; box-shadow: var(--shadow); }
.day.empty { background: transparent; border-style: dashed; box-shadow: none; opacity: 0.5; }
.day > summary { list-style: none; cursor: pointer; padding: 11px 15px; display: flex; align-items: center; gap: 13px; }
.day > summary::-webkit-details-marker { display: none; }
.day > summary:hover { background: var(--surface-hover); }
.day .dnum { font-weight: 700; font-size: 12px; min-width: 58px; color: var(--muted); line-height: 1.25; }
.day .dnum b { color: var(--text); font-size: 16px; }
.day .dtotal { font-weight: 800; min-width: 92px; }
.daychips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.tchip { --c: #64748b; display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid color-mix(in srgb, var(--c) 40%, var(--border-2));
  background: color-mix(in srgb, var(--c) 15%, var(--surface)); border-radius: 8px; padding: 3px 9px; font-size: 12px; max-width: 100%; }
.tchip .m { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.tchip .a { font-weight: 800; }
.tchip.review { border-style: dashed; }
.day .detail { border-top: 1px solid var(--border); padding: 8px 15px 14px; }

/* ── tables ────────────────────────────────────────────────────────────── */
table.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { text-align: left; padding: 9px 11px; border-bottom: 1px solid var(--border); font-size: 13px; }
.grid th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.grid tr:last-child td { border-bottom: none; }
.grid tr:hover td { background: var(--surface-2); }

/* fixed daily-detail columns so Category + Amount line up across every day,
   while long merchant names wrap instead of shoving things sideways */
.daily-detail { table-layout: fixed; }
.daily-detail .col-note { width: 34px; text-align: center; }
.daily-detail .col-cat { width: 210px; }
.daily-detail .col-amt { width: 118px; }
.daily-detail .col-merch { white-space: normal; word-break: break-word; }
.daily-detail .cat-select { width: 100%; }
.note-tag { color: var(--faint); font-style: italic; font-size: 12px; }

/* slim, near-invisible note affordance */
.note-btn { background: none; border: none; box-shadow: none; cursor: pointer; color: var(--faint);
  opacity: 0.28; font-size: 13px; padding: 2px 4px; line-height: 1; }
.daily-detail tr:hover .note-btn { opacity: 0.7; }
.note-btn.has-note { color: var(--accent); opacity: 1; }
.note-row > td { padding-top: 0; padding-bottom: 9px; }
.note-edit { width: 100%; background: var(--surface-2); border: 1px solid var(--border-2);
  border-radius: 8px; padding: 7px 10px; font-size: 13px; color: var(--text); }
.note-edit:focus { outline: none; border-color: var(--accent); }
.tag { --c: #64748b; display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); background: color-mix(in srgb, var(--c) 15%, var(--surface)); }
.tag .swatch { width: 8px; height: 8px; border-radius: 2px; background: var(--c); }
.statusdot { font-size: 11px; color: var(--faint); }
.pending { color: #f59e0b; font-size: 11px; font-weight: 700; }

/* ── forms ─────────────────────────────────────────────────────────────── */
select, input[type="text"], input[type="date"], input[type="number"] {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border-2);
  border-radius: 8px; padding: 6px 9px; font-size: 13px; font-family: inherit;
}
select:focus, input:focus { outline: none; border-color: var(--accent); }
.addform label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 13px; }
.addform input, .addform select { width: 100%; margin-top: 5px; padding: 9px 11px; font-size: 14px; }
.addform .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .addform .row2 { grid-template-columns: 1fr; } }
.inline-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
label.chk { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 28px 26px; width: 100%; max-width: 340px; }
.login-brand { font-weight: 800; font-size: 20px; margin-bottom: 4px; }
.login-brand .dot { color: var(--accent); }
.login-card input[type="password"] { width: 100%; padding: 11px 12px; font-size: 15px; }
.login-err { color: var(--red); font-size: 13px; margin-top: 10px; font-weight: 600; }

.empty-state { text-align: center; padding: 54px 20px; color: var(--muted); }
.empty-state .big { font-size: 18px; font-weight: 700; color: var(--text); }

.flash { background: color-mix(in srgb, var(--green) 15%, var(--surface)); border: 1px solid var(--green); color: var(--text); padding: 10px 14px; border-radius: 12px; margin-bottom: 14px; }
.flash.sweep { display: flex; align-items: center; gap: 11px; flex-wrap: wrap; background: color-mix(in srgb, var(--accent) 15%, var(--surface)); border-color: var(--accent); }
.flash.sweep form { display: inline; margin: 0; }

/* in-place save: toast + row flash (no page reload, no scroll jump) */
.toast-wrap { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 60;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; background: var(--surface); border: 1px solid var(--border-2);
  box-shadow: var(--shadow); border-radius: 12px; padding: 10px 14px; display: flex; align-items: center;
  gap: 12px; font-size: 13px; font-weight: 600; transition: opacity 0.3s; max-width: 92vw; }
@keyframes rowflash { from { background: color-mix(in srgb, var(--green) 26%, transparent); } to { background: transparent; } }
.row-flash > td { animation: rowflash 1s ease; }
.cat-select { max-width: 100%; }

/* theme toggle glyph swap */
[data-theme="dark"] .t-light { display: none; }
[data-theme="light"] .t-dark { display: none; }

@media (max-width: 860px) {
  .hero { grid-template-columns: repeat(2, 1fr); }
  .breakdown { grid-template-columns: 1fr; justify-items: center; }
  .legend { width: 100%; }
}
@media (max-width: 760px) {
  .day > summary { flex-wrap: wrap; }
  .tchip .m { max-width: 130px; }
  .hide-sm { display: none; }
}
