/* Base reset (the preview page got this from its host) */
:root { color-scheme: light; }
body { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* Layout: one summary band on top, entry form beside the 6-month chart and category breakdown, full-width ledger underneath. Phone: form first. */
:root {
  --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f4f6fb;
  --line: #dce1ec;
  --fg: #111a33;
  --muted: #5b6682;
  --accent: #3446e8;
  --accent-fg: #ffffff;
  --accent-soft: #e4e8ff;
  --inc: #0e7c59;
  --inc-soft: #ddf3ea;
  --exp: #c7452f;
  --exp-soft: #fbe6e1;
  --warn: #8a5a00;
  --warn-soft: #fff1cc;
  --hero-bg: #2b3cd9;
  --hero-fg: #ffffff;
  --hero-muted: #cdd3ff;
  --hero-line: #5a6af0;
  --hero-inc: #a8f5d3;
  --hero-exp: #ffc7ba;
  --hero-pend: #ffe38f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1020;
    --surface: #141a30;
    --surface-2: #1a2140;
    --line: #272f4f;
    --fg: #e8ecfa;
    --muted: #9aa5c6;
    --accent: #8d9bff;
    --accent-fg: #0c1020;
    --accent-soft: #232c5e;
    --inc: #46d39a;
    --inc-soft: #12352b;
    --exp: #ff8a73;
    --exp-soft: #3d1f1b;
    --warn: #f2c14e;
    --warn-soft: #3a2e10;
    --hero-bg: #1b2466;
    --hero-fg: #eef0ff;
    --hero-muted: #aab5f0;
    --hero-line: #3a46a0;
    --hero-inc: #7be3b4;
    --hero-exp: #ffa391;
    --hero-pend: #f6cf6a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c1020;
  --surface: #141a30;
  --surface-2: #1a2140;
  --line: #272f4f;
  --fg: #e8ecfa;
  --muted: #9aa5c6;
  --accent: #8d9bff;
  --accent-fg: #0c1020;
  --accent-soft: #232c5e;
  --inc: #46d39a;
  --inc-soft: #12352b;
  --exp: #ff8a73;
  --exp-soft: #3d1f1b;
  --warn: #f2c14e;
  --warn-soft: #3a2e10;
  --hero-bg: #1b2466;
  --hero-fg: #eef0ff;
  --hero-muted: #aab5f0;
  --hero-line: #3a46a0;
  --hero-inc: #7be3b4;
  --hero-exp: #ffa391;
  --hero-pend: #f6cf6a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  padding-block: 20px 40px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.wrap { max-width: 1120px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.tnum { font-variant-numeric: tabular-nums; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; text-wrap: balance; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* header */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark { width: 38px; height: 38px; flex: none; }
.mark path { fill: var(--accent); }
.mark .snow { fill: var(--bg); }
.brand h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.1; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 0.82rem; }
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 0.75rem; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); display: block; }
.pill.ok i { background: var(--inc); }
.pill.ok { color: var(--inc); }
.pill.warn i { background: var(--warn); }
.pill.warn { color: var(--warn); }
.pill.bad i { background: var(--exp); }
.pill.bad { color: var(--exp); }
select, input[type="text"], input[type="number"], input[type="date"], input[type="search"], input[type="password"] {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; min-width: 0; width: 100%;
}
.tools select { width: auto; font-weight: 500; }
a.btn { display: inline-block; text-decoration: none; color: var(--fg); }
.btn { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 14px; cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn[disabled] { opacity: 0.6; cursor: default; }

/* hero */
.hero { position: relative; overflow: hidden; background: var(--hero-bg); color: var(--hero-fg); border-radius: 12px; padding: 22px 22px 18px; display: flex; flex-direction: column; gap: 22px; }
.hero > * { position: relative; z-index: 1; }
.ridge { position: absolute !important; z-index: 0 !important; right: 0; top: 0; width: min(46%, 340px); height: auto; opacity: 0.5; }
.ridge polygon { fill: var(--hero-line); }
.eyebrow { margin: 0; font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--hero-muted); font-weight: 600; }
.net { margin: 4px 0 0; font-family: var(--font-display); font-weight: 700; font-size: clamp(2.2rem, 7vw, 3.6rem); line-height: 1.05; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.net.neg { color: var(--hero-exp); }
.net-note { margin: 6px 0 0; color: var(--hero-muted); font-size: 0.9rem; min-height: 1.35em; }
.stats { margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; border-top: 1px solid var(--hero-line); padding-top: 14px; }
.stats > div { padding-right: 12px; min-width: 0; }
.stats > div + div { padding-left: 14px; border-left: 1px solid var(--hero-line); }
.stats dt { font-size: 0.74rem; color: var(--hero-muted); letter-spacing: 0.04em; text-transform: uppercase; font-weight: 600; }
.stats dd { margin: 2px 0 0; font-family: var(--font-display); font-weight: 600; font-size: clamp(1rem, 3.6vw, 1.5rem); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.stats small { color: var(--hero-muted); font-size: 0.72rem; }
.stats .i { color: var(--hero-inc); }
.stats .e { color: var(--hero-exp); }
.stats .p { color: var(--hero-pend); }

/* banners */
.note { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 14px; font-size: 0.9rem; }
.note button { background: none; border: 0; padding: 4px 0; color: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; }

/* cards */
.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); align-items: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; min-width: 0; }
.card h2 { font-size: 1.05rem; font-weight: 600; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 14px; margin-bottom: 14px; }
.legend { display: flex; gap: 14px; font-size: 0.8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: block; }
.legend .li { background: var(--inc); }
.legend .le { background: var(--exp); }
@media (min-width: 960px) {
  .grid { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); grid-template-areas: "chart form" "break form" "list list"; }
  #sec-chart { grid-area: chart; }
  #sec-break { grid-area: break; }
  #entry { grid-area: form; }
  #sec-list { grid-area: list; }
}
@media (max-width: 560px) {
  .hero { padding: 18px 16px 14px; }
  .stats > div { padding-right: 8px; }
  .stats > div + div { padding-left: 10px; }
  .card { padding: 16px; }
}

/* chart */
#chart svg { display: block; width: 100%; height: auto; }
#chart .grid-line { stroke: var(--line); stroke-width: 1; }
#chart .tick { fill: var(--muted); font-size: 11px; font-family: var(--font-body); }
#chart .tick.on { fill: var(--fg); font-weight: 600; }
#chart .hl { fill: var(--accent-soft); }
#chart .bar-inc { fill: var(--inc); }
#chart .bar-exp { fill: var(--exp); }
.empty { color: var(--muted); margin: 8px 0; }

/* breakdown */
.cats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.cats li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; font-size: 0.9rem; }
.cats .amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.cats .share { color: var(--muted); font-weight: 400; margin-left: 6px; }
.cats .track { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.cats .fill { display: block; height: 100%; background: var(--exp); border-radius: 3px; }

/* form */
form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label, .field .lab { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.money { position: relative; }
.money span { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 0.85rem; pointer-events: none; }
.money input { padding-left: 34px; }
.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; gap: 2px; }
.seg.full { display: grid; grid-template-columns: 1fr 1fr; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label, .seg button { text-align: center; padding: 7px 14px; border-radius: 7px; cursor: pointer; font-size: 0.88rem; font-weight: 600; color: var(--muted); background: none; border: 0; }
.seg input:checked + label.li { background: var(--inc-soft); color: var(--inc); }
.seg input:checked + label.le { background: var(--exp-soft); color: var(--exp); }
.seg input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 0 0 1px var(--line); }
.err { color: var(--exp); font-size: 0.85rem; margin: 0; min-height: 1.2em; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* ledger */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 8px; }
.filters .search { flex: 1 1 200px; min-width: 0; }
.row { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 4px 12px; padding: 13px 0; border-top: 1px solid var(--line); }
.date { text-align: center; line-height: 1.15; }
.date b { display: block; font-family: var(--font-display); font-size: 1.15rem; }
.date span { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.main { min-width: 0; }
.title { font-weight: 600; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: 0.84rem; overflow-wrap: anywhere; }
.amt-col { text-align: right; font-family: var(--font-display); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt-col.i { color: var(--inc); }
.amt-col.e { color: var(--exp); }
.chip { display: inline-block; font-size: 0.7rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 1px; font-family: var(--font-body); }
.chip.pend { background: var(--warn-soft); color: var(--warn); }
.chip.smp { background: var(--accent-soft); color: var(--accent); }
.acts { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: 4px; }
.acts button { background: none; border: 0; padding: 4px 0; color: var(--accent); font-size: 0.84rem; font-weight: 500; cursor: pointer; }
.acts button.danger { color: var(--exp); }
.acts button:hover { text-decoration: underline; }
.empty-box { padding: 22px 4px 6px; color: var(--muted); display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); max-width: calc(100vw - 32px); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 9px; font-size: 0.9rem; z-index: 20; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); }
@media (prefers-reduced-motion: no-preference) {
  .btn, .cats .fill { transition: filter 0.15s, border-color 0.15s, width 0.3s; }
}

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding-block: 24px; }
.login { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 18px; }
.login .brand { justify-content: center; }
.login form { gap: 12px; }

a.btn.primary { color: var(--accent-fg); }
