/* =========================================================================
   Net Worth Tracker
   Chart colours are the validated categorical slots 1–3 (blue, orange, aqua),
   stepped per mode and checked against these exact surfaces.
   System font stack on purpose: no webfont means no third-party request.
   ========================================================================= */

:root {
  color-scheme: dark;

  --page:        #101215;
  --surface-1:   #191c21;   /* chart + card surface — validator surface */
  --surface-2:   #1f232a;
  --ink:         #f2f3f5;
  --ink-2:       #aab0b9;
  --muted:       #7c838d;
  --line:        rgba(255,255,255,.10);
  --line-2:      rgba(255,255,255,.06);

  --accent:      #3987e5;
  --accent-ink:  #ffffff;

  --series-1:    #3987e5;   /* net worth  */
  --series-2:    #d95926;   /* assets     */
  --series-3:    #199e70;   /* liabilities*/

  --good:        #0ca30c;
  --bad:         #e66767;

  --grid:        rgba(255,255,255,.07);
  --axis:        #898781;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 10px 28px rgba(0,0,0,.22);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease: cubic-bezier(.22,.61,.36,1);
}

:root[data-theme="light"] {
  color-scheme: light;

  --page:        #f7f7f5;
  --surface-1:   #ffffff;
  --surface-2:   #f2f2ef;
  --ink:         #14161a;
  --ink-2:       #52514e;
  --muted:       #6b7079;
  --line:        rgba(0,0,0,.12);
  --line-2:      rgba(0,0,0,.06);

  --accent:      #2a78d6;

  --series-1:    #2a78d6;
  --series-2:    #eb6834;
  --series-3:    #1baf7a;

  --good:        #006300;
  --bad:         #d03b3b;

  --grid:        rgba(0,0,0,.07);
  --axis:        #898781;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 10px 28px rgba(0,0,0,.06);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0; background: var(--page); color: var(--ink);
  font-family: var(--font); font-size: 16px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
svg { display: block; }

.shell { width: min(100% - 2rem, 1160px); margin-inline: auto; }

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: .5rem; top: .5rem; z-index: 99; background: var(--accent); color: #fff; padding: .6rem 1rem; border-radius: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- top bar ---------- */
.topbar { border-bottom: 1px solid var(--line); background: var(--surface-1); position: sticky; top: 0; z-index: 20; }
.topbar__inner { display: flex; align-items: center; gap: 1rem; height: 62px; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 650; letter-spacing: -.01em; }
.brand__mark { width: 24px; height: 24px; color: var(--accent); }
.topbar__actions { display: flex; align-items: center; gap: .4rem; margin-left: auto; }

.privacy-badge {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .78rem; color: var(--ink-2);
  border: 1px solid var(--line); border-radius: 100px; padding: .28rem .7rem;
}
.privacy-badge__icon { width: 14px; height: 14px; color: var(--good); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid transparent; border-radius: 9px; padding: .55rem 1rem;
  font-size: .9rem; font-weight: 550; cursor: pointer; background: none;
  transition: background-color .2s var(--ease), border-color .2s var(--ease), color .2s var(--ease);
}
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--ghost { border-color: var(--line); }
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn--quiet { color: var(--ink-2); }
.btn--quiet:hover { background: var(--line-2); color: var(--ink); }
.btn--danger { border-color: var(--line); color: var(--bad); }
.btn--danger:hover { background: color-mix(in srgb, var(--bad) 12%, transparent); }

.iconbtn {
  width: 34px; height: 34px; padding: 7px; border: 0; border-radius: 8px;
  background: none; color: var(--ink-2); cursor: pointer;
}
.iconbtn:hover { background: var(--line-2); color: var(--ink); }
.iconbtn svg { width: 100%; height: 100%; fill: currentColor; }
.icon-sun { display: none; }
:root[data-theme="light"] .icon-sun { display: block; }
:root[data-theme="light"] .icon-moon { display: none; }

.linkbtn { background: none; border: 0; color: var(--muted); font-size: .8rem; cursor: pointer; padding: .2rem .3rem; }
.linkbtn:hover { color: var(--bad); text-decoration: underline; }

/* ---------- first run ---------- */
.empty { max-width: 640px; margin: clamp(3rem, 12vh, 7rem) auto; text-align: center; }
.empty__title { font-size: clamp(1.7rem, 4vw, 2.5rem); letter-spacing: -.02em; margin-bottom: 1rem; }
.empty__lead { color: var(--ink-2); margin-bottom: 2rem; }
.empty__actions { display: flex; gap: .7rem; justify-content: center; flex-wrap: wrap; }
.empty__note { color: var(--muted); font-size: .82rem; margin-top: 1.4rem; }

/* ---------- kpis ---------- */
.kpis { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: 1rem; margin: 1.6rem 0; }
.kpi { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; }
.kpi--flat { background: none; border: 0; padding: 0; }
.kpi__label { font-size: .74rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-bottom: .35rem; }
.kpi__value { font-size: clamp(1.8rem, 4vw, 2.6rem); font-weight: 600; letter-spacing: -.02em; }
.kpi__value--sm { font-size: 1.45rem; }
.kpi__sub, .kpi__since { color: var(--muted); font-size: .78rem; font-weight: 400; }
.kpi__delta { font-size: .85rem; color: var(--muted); margin-top: .3rem; }
.kpi__delta.is-up { color: var(--good); }
.kpi__delta.is-down { color: var(--bad); }
@media (max-width: 860px) { .kpis { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .kpis { grid-template-columns: 1fr; } }

/* ---------- panels ---------- */
.panel {
  background: var(--surface-1); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.3rem; margin-bottom: 1.2rem;
}
.panel--quiet { background: none; }
.panel__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.panel__title { font-size: 1.12rem; font-weight: 600; }
.panel__sub { color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.controls { display: flex; gap: .5rem; flex-wrap: wrap; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg {
  border: 0; background: none; color: var(--ink-2);
  padding: .4rem .75rem; font-size: .82rem; cursor: pointer;
  border-right: 1px solid var(--line);
}
.seg:last-child { border-right: 0; }
.seg:hover { background: var(--line-2); color: var(--ink); }
.seg.is-on { background: var(--accent); color: var(--accent-ink); }

/* series legend — always present for >= 2 series, doubles as the toggle */
.serieskeys { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.skey {
  display: inline-flex; align-items: center; gap: .45rem;
  border: 1px solid var(--line); background: none; color: var(--muted);
  border-radius: 100px; padding: .3rem .75rem; font-size: .82rem; cursor: pointer;
}
.skey.is-on { color: var(--ink); border-color: var(--line); background: var(--surface-2); }
.skey__swatch { width: 10px; height: 10px; border-radius: 3px; opacity: .35; }
.skey.is-on .skey__swatch { opacity: 1; }

/* ---------- chart chrome ---------- */
.figure { margin: 0; position: relative; }
.figure__cap { color: var(--muted); font-size: .78rem; margin-top: .5rem; }
.chart { position: relative; width: 100%; min-height: 60px; }
.chart__empty { color: var(--muted); font-size: .88rem; padding: 2.5rem 0; text-align: center; }

.c-grid { stroke: var(--grid); stroke-width: 1; }
.c-zero { stroke: var(--axis); stroke-width: 1; }
.c-axis { fill: var(--axis); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.c-cross { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }

.tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 9px; padding: .55rem .7rem; box-shadow: var(--shadow);
  font-size: .8rem; white-space: nowrap;
}
.tip__date { color: var(--muted); font-size: .72rem; margin-bottom: .3rem; }
.tip__row { display: flex; align-items: center; gap: .45rem; }
.tip__key { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tip__label { color: var(--ink-2); }
.tip__val { margin-left: auto; padding-left: 1rem; font-variant-numeric: tabular-nums; }

/* ---------- horizontal bars ---------- */
.bars { display: grid; gap: .5rem; }
.bars__row {
  display: grid; grid-template-columns: minmax(90px, 150px) 1fr auto 40px;
  align-items: center; gap: .75rem;
}
.bars__label { font-size: .87rem; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars__track { height: 22px; background: var(--line-2); border-radius: 5px; overflow: hidden; }
.bars__fill { display: block; height: 100%; border-radius: 5px; transition: width .4s var(--ease); }
.bars__value { font-size: .87rem; font-variant-numeric: tabular-nums; }
.bars__share { font-size: .78rem; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) {
  .bars__row { grid-template-columns: 1fr auto; grid-template-areas: "label value" "track track"; }
  .bars__label { grid-area: label; } .bars__value { grid-area: value; }
  .bars__track { grid-area: track; } .bars__share { display: none; }
}

/* ---------- accounts ---------- */
.accounts { margin-bottom: 1rem; }
.accounts__head { font-size: .74rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-bottom: .5rem; }
.acct {
  display: grid; grid-template-columns: 1fr 140px auto; gap: .7rem; align-items: center;
  padding: .5rem 0; border-bottom: 1px solid var(--line-2);
}
.acct__name { font-size: .93rem; display: flex; flex-direction: column; }
.acct__cat { font-size: .74rem; color: var(--muted); }

.input {
  background: var(--page); border: 1px solid var(--line); border-radius: 8px;
  padding: .5rem .65rem; font-size: .9rem; width: 100%;
}
.input--num { text-align: right; font-variant-numeric: tabular-nums; }
.input:focus { border-color: var(--accent); outline: none; }

.addrow { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.addrow .input { width: auto; flex: 1 1 130px; }
.addrow .input--num { flex: 0 1 120px; }
@media (max-width: 560px) { .acct { grid-template-columns: 1fr auto; } .acct__input { grid-column: 1 / -1; } }

/* ---------- switch ---------- */
.switch { display: inline-flex; align-items: center; gap: .55rem; cursor: pointer; font-size: .85rem; color: var(--ink-2); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track { width: 38px; height: 22px; border-radius: 100px; background: var(--surface-2); border: 1px solid var(--line); position: relative; transition: background-color .2s var(--ease); }
.switch__thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform .2s var(--ease), background-color .2s var(--ease); }
.switch input:checked + .switch__track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch__track .switch__thumb { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- tables ---------- */
.tableview { margin-top: .9rem; }
.tableview summary { cursor: pointer; color: var(--muted); font-size: .82rem; }
.tableview summary:hover { color: var(--ink); }
.tablewrap { overflow-x: auto; margin-top: .7rem; }
.dt { width: 100%; border-collapse: collapse; font-size: .85rem; }
.dt th, .dt td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.dt th { color: var(--muted); font-weight: 550; font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; }
.dt td { font-variant-numeric: tabular-nums; }

.exp-summary { display: flex; gap: 2.5rem; margin-bottom: 1.2rem; }
.datarow { display: flex; gap: .6rem; margin-top: 1rem; flex-wrap: wrap; }

/* ---------- footer / toast ---------- */
.footer { border-top: 1px solid var(--line); margin-top: 2rem; padding: 1.6rem 0; }
.footer__inner { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; color: var(--muted); font-size: .82rem; }
.footer a { color: var(--ink-2); text-decoration: none; }
.footer a:hover { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; padding: .7rem 1.1rem; box-shadow: var(--shadow);
  font-size: .87rem; z-index: 60; max-width: calc(100% - 2rem);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
