/* Finance v2 — tokens from the validated dataviz palette; components from design/v2 mockups. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good-text: #006300;
  --bad-text: #d03b3b;
  --accent: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --good-text: #0ca30c;
    --bad-text: #e66767;
    --accent: #3987e5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --good-text: #0ca30c;
  --bad-text: #e66767;
  --accent: #3987e5;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.4;
}

.app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--page);
  padding-bottom: 84px;
  position: relative;
}
.app.no-tabbar { padding-bottom: 24px; }

.pad { padding: 0 20px; }
.hidden { display: none !important; }
.error { color: var(--bad-text); }
.good { color: var(--good-text); }
.empty { color: var(--muted); font-size: 0.9rem; }
.bad { color: var(--bad-text); }

/* ---------- top area ---------- */
.screen-head {
  padding: 18px 20px 6px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.screen-head h1 { font-size: 1.15rem; margin: 0; letter-spacing: -0.01em; }
.head-btn {
  background: none; border: none; color: var(--accent); font: inherit;
  font-size: 0.95rem; padding: 6px 0; cursor: pointer; text-decoration: none;
}

.banner {
  margin: 10px 20px; padding: 10px 14px;
  background: color-mix(in srgb, var(--series-2) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--series-2) 30%, transparent);
  border-radius: 10px; font-size: 0.85rem; color: var(--ink-2);
}
.banner a { color: var(--accent); }

/* ---------- hero ---------- */
.hero { padding: 10px 20px 4px; }
.hero-label { color: var(--muted); font-size: 0.8rem; }
.hero-value { font-size: 2.35rem; font-weight: 750; letter-spacing: -0.02em; margin: 2px 0 8px; }
.hero-value.debt { color: var(--bad-text); }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 0.78rem; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px; white-space: nowrap;
}
.chip b { color: var(--ink); font-weight: 600; }

/* ---------- sections & lists ---------- */
.section { margin-top: 22px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 20px 6px; }
.section-head h2 {
  font-size: 0.8rem; margin: 0; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 650;
}
.section-head a { color: var(--accent); font-size: 0.85rem; text-decoration: none; }
.panel-sub { color: var(--muted); font-size: 0.85rem; margin: 2px 0 8px; }

.list { border-top: 1px solid var(--grid); }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--grid);
  text-decoration: none; color: inherit; min-height: 56px;
}
a.row:active { background: var(--surface); }
.row-icon {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center; font-size: 1.05rem;
  background: var(--surface); border: 1px solid var(--border); flex: none;
}
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { display: block; color: var(--muted); font-size: 0.8rem; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-end { text-align: right; flex: none; }
.row-amount { display: block; font-weight: 600; font-variant-numeric: tabular-nums; }
.row-amount.pos { color: var(--good-text); }
.row-amount.neg { color: var(--ink); }
.row-amount.debt { color: var(--bad-text); }
.row-when { display: block; color: var(--muted); font-size: 0.78rem; margin-top: 1px; }
.badge-ccy {
  font-size: 0.68rem; font-weight: 650; color: var(--ink-2);
  border: 1px solid var(--baseline); border-radius: 5px; padding: 1px 4px;
  vertical-align: 1px; margin-left: 5px;
}
.day-head {
  padding: 14px 20px 4px; color: var(--muted); font-size: 0.78rem;
  display: flex; justify-content: space-between; font-variant-numeric: tabular-nums;
}
.due {
  font-size: 0.7rem; font-weight: 650; border-radius: 999px; padding: 2px 8px;
  background: var(--surface); color: var(--muted); border: 1px solid var(--border);
}
.due.late { background: color-mix(in srgb, var(--bad-text) 12%, transparent); color: var(--bad-text); border: none; }
.due.ok { background: color-mix(in srgb, var(--good-text) 12%, transparent); color: var(--good-text); border: none; }

/* ---------- category bars ---------- */
.cat { padding: 6px 20px; }
.cat-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 10px; align-items: center; padding: 5px 0; }
.cat-name { font-size: 0.85rem; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-track { display: block; height: 10px; border-radius: 5px; background: var(--surface); border: 1px solid var(--border); overflow: hidden; }
.cat-fill { display: block; height: 100%; border-radius: 4px 0 0 4px; background: var(--series-1); }
.cat-amt { font-size: 0.83rem; font-variant-numeric: tabular-nums; }

/* ---------- tiles (payoff) ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 8px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tile-label { color: var(--ink-2); font-size: 0.78rem; }
.tile-value { font-size: 1.35rem; font-weight: 700; margin-top: 2px; }
.tile-note { color: var(--muted); font-size: 0.75rem; margin-top: 2px; }
.tile-bad .tile-value { color: var(--bad-text); }
.tile-good .tile-value { color: var(--good-text); }

/* ---------- bottom tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 430px;
  background: var(--surface); border-top: 1px solid var(--border);
  display: grid; grid-template-columns: 1fr 1fr 72px 1fr 1fr; align-items: center;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 10;
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.66rem; padding: 4px 0;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--ink); }
.tab-add {
  width: 54px; height: 54px; margin: -22px auto 0; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-size: 1.7rem; font-weight: 300; line-height: 1;
  text-decoration: none; border: none;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 45%, transparent);
}

/* ---------- forms ---------- */
input, select, button, textarea { font: inherit; color: var(--ink); }
input:not([type="checkbox"]), select {
  background: var(--surface); border: 1px solid var(--baseline); border-radius: 8px;
  padding: 8px 10px; min-width: 0; max-width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }

.seg {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 4px; margin: 8px 20px 0;
}
.seg button {
  border: none; background: none; color: var(--muted);
  font: inherit; font-size: 0.9rem; font-weight: 550;
  padding: 8px 0; border-radius: 9px; cursor: pointer;
}
.seg button.on { background: var(--page); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }

.amount-wrap { text-align: center; padding: 26px 20px 10px; }
.amount-input {
  font-size: 2.6rem; font-weight: 700; letter-spacing: -0.02em;
  border: none !important; background: none !important; color: var(--ink);
  width: 100%; text-align: center; outline: none !important;
  font-variant-numeric: tabular-nums;
}
.amount-input::placeholder { color: var(--baseline); }
.amount-ccy {
  font-size: 0.85rem; color: var(--accent); font-weight: 600;
  border: 1px solid var(--border); border-radius: 999px; padding: 3px 12px;
}

.field-list { margin: 8px 0 0; border-top: 1px solid var(--grid); }
.field { display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--grid); }
.field-label { color: var(--muted); font-size: 0.9rem; width: 84px; flex: none; }
.field-value { flex: 1; display: flex; align-items: center; gap: 8px; justify-content: flex-end; text-align: right; font-weight: 500; }
.field-value input, .field-value select { border: none; background: none; text-align: right; width: 100%; outline: none; padding: 6px 0; }

.cat-chips { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px 20px 4px; }
.cat-chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 7px 14px; font-size: 0.85rem; cursor: pointer;
}
.cat-chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.receipt-zone {
  margin: 16px 20px 0; border: 1.5px dashed var(--baseline); border-radius: 14px;
  padding: 16px; text-align: center; color: var(--muted); font-size: 0.9rem;
  background: var(--surface); display: block; cursor: pointer;
}
.receipt-zone .big { font-size: 1.5rem; display: block; margin-bottom: 4px; }
.receipt-zone.busy { opacity: 0.6; }
.receipt-done {
  margin: 16px 20px 0; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); padding: 12px 14px;
  display: flex; gap: 12px; align-items: center;
}
.receipt-thumb {
  width: 44px; height: 56px; border-radius: 8px; flex: none;
  background: repeating-linear-gradient(0deg, var(--grid), var(--grid) 3px, var(--surface) 3px, var(--surface) 8px);
  border: 1px solid var(--border); display: block;
}
.ocr-note { font-size: 0.82rem; color: var(--ink-2); }
.ocr-note b { color: var(--ink); }
.from-receipt {
  font-size: 0.68rem; font-weight: 650; color: var(--series-2);
  background: color-mix(in srgb, var(--series-2) 12%, transparent);
  border-radius: 5px; padding: 2px 6px; white-space: nowrap;
}

.cta {
  display: block; width: calc(100% - 40px); margin: 22px 20px 12px;
  background: var(--accent); color: #fff; text-align: center;
  border: none; border-radius: 13px; padding: 15px;
  font-size: 1.02rem; font-weight: 650; cursor: pointer; text-decoration: none;
}
.cta.small { width: auto; display: inline-block; margin: 0; padding: 9px 18px; font-size: 0.92rem; border-radius: 10px; }
.cta[disabled] { opacity: 0.45; }

.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--ink-2); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-row { display: flex; gap: 12px; align-items: center; }
.check { flex-direction: row !important; align-items: center; gap: 8px !important; }
.panel-lite { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin: 8px 0; }
.edit-row { background: var(--surface); }
.inline { display: inline; }
.link-btn { background: none; border: none; color: inherit; cursor: pointer; padding: 0; font-size: inherit; }

.net-line { display: flex; justify-content: space-between; padding: 14px 20px; font-weight: 650; }
.net-line .sub { color: var(--muted); font-weight: 400; font-size: 0.8rem; }

/* ---------- filter chips ---------- */
.filters { display: flex; gap: 8px; padding: 10px 20px; overflow-x: auto; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.f-chip, select.f-chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 6px 13px; font-size: 0.83rem;
  white-space: nowrap; cursor: pointer; flex: none; text-decoration: none;
  appearance: none; -webkit-appearance: none;
}
.f-chip.on { background: var(--ink); border-color: var(--ink); color: var(--page); }

/* ---------- inline form (payoff) ---------- */
.inline-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin: 6px 0 12px; }
.inline-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--ink-2); }

/* ---------- data tables (legacy archive) ---------- */
.table-scroll { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
table.data th, table.data td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--grid); }
table.data th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.section td { font-weight: 700; background: var(--surface); padding-top: 12px; }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--baseline); border-bottom: none; }
table.data a { color: var(--accent); text-decoration: none; }

/* ---------- today view ---------- */
.big-log {
  padding: 22px; font-size: 1.2rem; border-radius: 16px; margin-top: 18px;
}
.streak-chip {
  display: inline-block; font-size: 0.82rem; font-weight: 650;
  background: color-mix(in srgb, var(--series-2) 12%, transparent);
  color: var(--series-2); border-radius: 999px; padding: 5px 12px; margin-top: 4px;
}
.today-card {
  margin: 18px 20px 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px;
}
.today-card-title { font-weight: 650; }
.today-card-sub { color: var(--ink-2); font-size: 0.9rem; margin: 4px 0 12px; }
.today-card .btn-row { gap: 16px; }
.muted-btn { color: var(--muted); }
.recap-lines { list-style: none; padding: 0; margin: 4px 0 12px; color: var(--ink-2); }
.recap-lines li { padding: 3px 0; }
.recap-lines li.good { color: var(--good-text); }
.nothing { text-align: center; color: var(--muted); padding: 34px 20px; }
.see-numbers {
  display: block; text-align: center; color: var(--muted); text-decoration: none;
  font-size: 0.88rem; padding: 18px;
}
.see-numbers:hover { color: var(--accent); }
.progress-line {
  padding: 12px 20px 0; font-weight: 650; color: var(--ink-2);
}
.progress-line.good { color: var(--good-text); }

.celebrate {
  position: fixed; inset: 0; display: grid; place-items: center;
  pointer-events: none; z-index: 50;
  animation: celebrate-fade 1.8s ease forwards;
}
.celebrate-inner {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 26px 34px; text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
  animation: celebrate-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.celebrate-check {
  width: 54px; height: 54px; margin: 0 auto 8px; border-radius: 50%;
  background: var(--good-text); color: #fff;
  display: grid; place-items: center; font-size: 1.7rem; font-weight: 700;
}
.celebrate-text { font-weight: 650; }
@keyframes celebrate-pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes celebrate-fade { 0%, 65% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }
@media (prefers-reduced-motion: reduce) {
  .celebrate { animation: celebrate-fade 1.8s ease forwards; }
  .celebrate-inner { animation: none; }
}

/* ---------- welcome wizard ---------- */
.wiz { max-width: 420px; margin: 0 auto; padding: 40px 24px; text-align: center; }
.wiz-dots { display: flex; gap: 7px; justify-content: center; margin-bottom: 30px; }
.wiz-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--baseline); }
.wiz-dot.on { background: var(--accent); }
.wiz-q { font-size: 1.35rem; letter-spacing: -0.01em; margin: 0 0 6px; }
.wiz-sub { color: var(--muted); font-size: 0.9rem; margin: 0 0 22px; }
.wiz-form { display: flex; flex-direction: column; gap: 14px; }
.wiz-input { display: flex; flex-direction: column; gap: 4px; }
.wiz-input-label { color: var(--ink-2); font-size: 0.85rem; text-align: left; }
.wiz-amount { display: flex; align-items: baseline; gap: 8px; justify-content: center; }
.wiz-amount input {
  font-size: 1.9rem; font-weight: 700; text-align: center; width: 100%;
  border: none; border-bottom: 2px solid var(--baseline); border-radius: 0;
  background: none; outline: none; font-variant-numeric: tabular-nums;
}
.wiz-amount input:focus { border-color: var(--accent); outline: none; }
.wiz-ccy { color: var(--muted); font-weight: 650; }
.wiz-checks { display: flex; flex-direction: column; gap: 2px; text-align: left; }
.wiz-check {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.wiz-skip { background: none; border: none; color: var(--muted); font: inherit; font-size: 0.88rem; margin-top: 16px; cursor: pointer; }
.wiz-skip:hover { color: var(--ink-2); }
.wiz-done { font-size: 2.6rem; margin-bottom: 6px; }
.wiz .cta { width: 100%; margin: 8px 0 0; }

/* ---------- collapsed account rows ---------- */
details.more-rows summary {
  list-style: none; cursor: pointer; color: var(--muted); font-size: 0.85rem;
  padding: 12px 20px; border-bottom: 1px solid var(--grid);
}
details.more-rows summary::-webkit-details-marker { display: none; }
details.more-rows summary::before { content: '▸ '; }
details.more-rows[open] summary::before { content: '▾ '; }

/* ---------- auth ---------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; margin: 0; background: var(--page); font-family: system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; width: min(92vw, 360px); }
.auth-card h1 { margin-top: 0; }
.auth-card form { display: flex; flex-direction: column; gap: 10px; }
.auth-card button { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 9px; cursor: pointer; }

/* ---------- desktop (≥900px): sidebar replaces tab bar ---------- */
.sidenav { display: none; }
@media (min-width: 900px) {
  body { display: flex; }
  .sidenav {
    display: flex; flex-direction: column; gap: 2px;
    position: sticky; top: 0; align-self: flex-start;
    width: 220px; flex: none; min-height: 100vh;
    padding: 22px 14px;
    border-right: 1px solid var(--grid);
    background: var(--surface);
  }
  .sidenav .brand { font-weight: 750; font-size: 1.05rem; padding: 0 10px 16px; letter-spacing: -0.01em; }
  .side-link {
    display: flex; align-items: center; gap: 10px;
    color: var(--ink-2); text-decoration: none;
    padding: 9px 10px; border-radius: 9px; font-size: 0.93rem;
  }
  .side-link svg { width: 19px; height: 19px; }
  .side-link:hover { background: var(--page); }
  .side-link.active { background: var(--page); color: var(--ink); font-weight: 600; }
  .side-add {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    margin: 14px 4px 0;
    background: var(--accent); color: #fff; text-decoration: none;
    border-radius: 10px; padding: 10px; font-weight: 650; font-size: 0.93rem;
  }
  .side-foot { margin-top: auto; padding: 10px; color: var(--muted); font-size: 0.78rem; }
  .side-foot a { color: var(--muted); }

  .app { max-width: none; flex: 1; padding: 0 max(28px, calc((100% - 920px) / 2)) 40px; }
  .tabbar { display: none; }
  .screen-head { padding-top: 26px; }
  .screen-head h1 { font-size: 1.35rem; }
  .hero-value { font-size: 2.8rem; }

  .list, .field-list { border: 1px solid var(--grid); border-radius: 12px; overflow: hidden; margin: 0 20px; }
  .list .row:last-child, .field-list .field:last-child { border-bottom: none; }

  .cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; align-items: start; }
  .cols-2 > .section { min-width: 0; }

  #tx-form, .seg, .amount-wrap { max-width: 560px; margin-left: auto; margin-right: auto; }
  .seg { margin-top: 8px; }
}
