:root {
  --paper: #eef0ee;
  --surface: #ffffff;
  --ink: #14181d;
  --muted: #6a7480;
  --rule: #d8dcd8;
  --in: #1f6b4f;
  --out: #a33a2c;
  --mark: #2b3a67;
  --mark-ink: #ffffff;
  --pending: #8a6d23;
  --radius: 12px;
  --tabs-h: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #101317;
    --surface: #171b21;
    --ink: #e7eae7;
    --muted: #8b95a1;
    --rule: #272d35;
    --in: #5bbd92;
    --out: #e7836f;
    --mark: #9db2ef;
    --mark-ink: #101317;
    --pending: #d0ab55;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
}
h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin: 4px 0 0; }
h2 { font-size: 15px; font-weight: 600; margin: 24px 0 10px; }
.card h2 { margin-top: 0; }
a { color: var(--mark); }
.note { color: var(--muted); font-size: 14px; }

/* --- formulieren --- */
input, select, button, .button {
  font: inherit; /* 16px: voorkomt dat iOS inzoomt bij focus */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
button, .button { cursor: pointer; font-weight: 550; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
button.primary, .button.primary { background: var(--mark); color: var(--mark-ink); border-color: var(--mark); }
button:disabled { opacity: 0.6; }
button.link { background: none; border: 0; color: var(--muted); text-decoration: underline; }
.button.wide { display: flex; width: 100%; margin-top: 12px; }
:focus-visible { outline: 2px solid var(--mark); outline-offset: 2px; }
.stack { display: grid; gap: 12px; }
.stack label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.stack label input, .stack label select { color: var(--ink); width: 100%; }
.file input { width: 100%; padding: 9px; }

/* --- kop --- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.totals { display: flex; gap: 18px; flex-wrap: wrap; }
.figure { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
.figure.in { color: var(--in); }
.figure small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }

/* --- filters --- */
.filters { display: grid; gap: 10px; margin-bottom: 14px; }
.search input { width: 100%; }
.chips {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px; padding: 0 16px 2px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border-radius: 999px; min-height: 36px; padding: 6px 14px;
  font-size: 14px; display: inline-flex; align-items: center; gap: 6px;
  color: var(--ink); text-decoration: none; background: var(--surface);
  border: 1px solid var(--rule);
}
select.chip { padding-right: 28px; }
.chip.on { border-color: var(--mark); color: var(--mark); }
.chip.toggle { position: relative; }
.chip.toggle input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }

/* --- transactielijst --- */
.txlist { list-style: none; margin: 0; padding: 0; }
.day {
  font-size: 13px; font-weight: 600; color: var(--muted);
  padding: 16px 4px 6px; position: sticky; top: 0; background: var(--paper); z-index: 1;
}
.tx {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  background: var(--surface); padding: 12px 14px; border: 1px solid var(--rule); border-bottom-width: 0;
}
.day + .tx { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.tx:has(+ .day), .tx:last-child { border-bottom-width: 1px; border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.tx-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tx-amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.tx-amount.in { color: var(--in); }
.cur { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 3px; }
.tx-meta { color: var(--muted); font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending { color: var(--pending); }
.tx-cat {
  justify-self: end; max-width: 60vw; min-height: 32px; padding: 4px 26px 4px 10px;
  font-size: 13px; border-radius: 999px; background-color: var(--paper); border-color: transparent;
}
.tx-cat.unset { color: var(--mark); border: 1px dashed var(--mark); background-color: transparent; }
.tx-cat.manual { color: var(--mark); }
.saved { animation: flash 900ms ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--in) 22%, var(--surface)); } }
@media (prefers-reduced-motion: reduce) { .saved { animation: none; } }
.empty { padding: 48px 12px; text-align: center; color: var(--muted); display: grid; gap: 12px; justify-items: center; }

/* --- overzicht --- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 8px; }
.stat { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px; min-width: 0; }
.stat span { display: block; font-size: 12px; color: var(--muted); }
.stat strong { display: block; font-size: 18px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.stat .in { color: var(--in); }
.stat .out { color: var(--out); }
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.bars a { display: block; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 14px; color: inherit; text-decoration: none; }
.bar-top { display: flex; justify-content: space-between; gap: 12px; font-weight: 550; }
.bar-amount { font-variant-numeric: tabular-nums; }
.bar-track { height: 6px; background: var(--paper); border-radius: 3px; margin: 8px 0 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--mark); border-radius: 3px; }
.bar-meta { font-size: 12px; color: var(--muted); }
.bars a.uncat { border-style: dashed; }
.bars a.uncat .bar-fill { background: var(--muted); }

/* --- beheer --- */
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card .note { margin-top: 0; }
.plain { list-style: none; padding: 0; margin: 0 0 12px; }
.plain li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
details summary { cursor: pointer; color: var(--mark); font-weight: 550; padding: 8px 0; }
details form { margin-top: 8px; }
.flash { border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; }
.flash.ok { background: color-mix(in srgb, var(--in) 14%, var(--surface)); color: var(--in); }
.flash.error { background: color-mix(in srgb, var(--out) 14%, var(--surface)); color: var(--out); }
.logout { text-align: center; margin-top: 8px; }

/* --- tabbalk --- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; height: var(--tabs-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; color: var(--muted); text-decoration: none;
}
.tabs a[aria-current=page] { color: var(--mark); font-weight: 600; }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* --- melding onderin --- */
.toast {
  position: fixed; left: 12px; right: 12px; z-index: 20;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px);
  max-width: 480px; margin: 0 auto;
  background: var(--ink); color: var(--paper); border-radius: var(--radius);
  padding: 10px 10px 10px 14px; display: flex; align-items: center; gap: 12px;
  font-size: 14px; box-shadow: 0 6px 24px rgb(0 0 0 / 0.18);
}
.toast[hidden] { display: none; }
.toast span { flex: 1; }
.toast button { background: var(--paper); color: var(--ink); border: 0; min-height: 36px; padding: 6px 16px; }

/* --- inloggen --- */
.login-page { padding-bottom: 0; }
.login { max-width: 360px; margin: 12vh auto 0; display: grid; gap: 16px; }
.login img { border-radius: 14px; }
.login h1 { margin: 0 0 8px; }

@media (min-width: 720px) {
  .tx-cat { max-width: 220px; }
  .stat strong { font-size: 22px; }
}

/* --- bankkoppeling --- */
.link-card { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.link-card > span:last-child { color: var(--mark); font-size: 20px; }
.banner { display: block; text-decoration: none; }
.steps { padding-left: 20px; margin: 0; display: grid; gap: 8px; }
.steps code { overflow-wrap: anywhere; }

/* --- maanden vergelijken ---
   Uitgaven oranje, inkomsten groen. Gevalideerd (ook voor kleurenblindheid):
   licht #eb6834 + #006300, donker #d95926 + #199e70. Het fellere #008300 valt
   voor rood-groenblinden samen met oranje, dus niet gebruiken. */
:root { --series-out: #eb6834; --series-in: #006300; }
@media (prefers-color-scheme: dark) { :root { --series-out: #d95926; --series-in: #199e70; } }
.range-total { display: grid; gap: 6px; margin: 4px 0 12px; }
.range-total strong { font-size: 16px; }
.table-view tfoot td { font-weight: 600; border-bottom: 0; }
.compare { margin-top: 28px; }
.forecast { display: grid; gap: 10px; }
.fc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.fc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.fc-grid > div { display: grid; gap: 2px; min-width: 0; }
.fc-grid strong { font-size: 18px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.fc-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.forecast > .note { margin: 0; font-size: 13px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.key-out { background: var(--series-out); }
.key-in { background: var(--series-in); }
.key-fc-out { background: color-mix(in srgb, var(--series-out) 35%, transparent); }
.key-fc-in { background: color-mix(in srgb, var(--series-in) 35%, transparent); }
.key-fc { background: linear-gradient(90deg, color-mix(in srgb, var(--series-out) 35%, transparent) 50%, color-mix(in srgb, var(--series-in) 35%, transparent) 50%); }
.range-bar { display: grid; gap: 10px; margin: 16px 0 10px; }
.range { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.range label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); flex: 1 1 130px; }
.range input { width: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-wrap { position: relative; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 8px 4px 4px; }
.chart-scroll { overflow-x: auto; scrollbar-width: thin; }
.viz { display: block; width: 100%; height: auto; font: 11px ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif; }
.viz .grid { stroke: var(--rule); stroke-width: 1; shape-rendering: crispEdges; }
.viz .axis { stroke: var(--muted); stroke-opacity: 0.5; stroke-width: 1; shape-rendering: crispEdges; }
.viz .tick, .viz .month { fill: var(--muted); font-variant-numeric: tabular-nums; }
.viz .current .month { fill: var(--ink); font-weight: 600; }
.viz .col-out, .viz .fc-out { fill: var(--series-out); }
.viz .col-in, .viz .fc-in { fill: var(--series-in); }
.viz .fc { fill-opacity: 0.35; }
.viz .hit { fill: transparent; }
.viz .grp { cursor: pointer; outline: none; }
.viz .grp.active .hit, .viz .grp:focus-visible .hit { fill: var(--ink); fill-opacity: 0.05; }
.tooltip {
  position: absolute; top: 8px; z-index: 5; min-width: 180px; pointer-events: none;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 10px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.14); padding: 8px 10px; font-size: 13px;
}
.tt-title { font-weight: 600; margin-bottom: 4px; }
.tt-sub { color: var(--muted); font-size: 12px; margin-top: 6px; }
.tt-row { display: flex; align-items: center; gap: 6px; }
.tt-row span { flex: 1; color: var(--muted); }
.tt-row b { font-variant-numeric: tabular-nums; font-weight: 600; }
.table-view { margin-top: 10px; }
.table-view summary { cursor: pointer; color: var(--mark); font-size: 14px; padding: 6px 0; }
.table-view table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.table-view th { text-align: right; font-size: 12px; font-weight: 500; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--rule); }
.table-view td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--rule); font-variant-numeric: tabular-nums; }
.table-view th:first-child, .table-view td:first-child { text-align: left; }

/* --- inzichten --- */
.hero-card { display: grid; gap: 8px; color: inherit; text-decoration: none; }
.hero { font-size: 44px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.meter { height: 8px; border-radius: 4px; background: color-mix(in srgb, var(--mark) 18%, var(--surface)); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 4px; background: var(--mark); }
.meter-fill.over { background: var(--out); }
.pill { justify-self: start; font-size: 13px; padding: 3px 10px; border-radius: 999px; background: color-mix(in srgb, var(--mark) 14%, var(--surface)); color: var(--mark); font-weight: 600; }
.stats.two { grid-template-columns: repeat(2, 1fr); }
.fall { width: 100%; border-collapse: collapse; margin: 16px 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; font-variant-numeric: tabular-nums; }
.fall th { font-size: 12px; font-weight: 500; color: var(--muted); text-align: right; padding: 8px 12px; border-bottom: 1px solid var(--rule); }
.fall td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--rule); }
.fall td:first-child, .fall th:first-child { text-align: left; }
.fall tr.minus td { color: var(--muted); }
.fall tr.sum td { font-weight: 650; }
.fall tr.aside td { font-size: 13px; color: var(--muted); border-bottom: 0; }
li.decide { align-items: center; }
.actions { display: flex; gap: 6px; }
.actions button { min-height: 36px; padding: 6px 12px; }
.sublist { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.sublist .card { margin: 0; padding: 12px 14px; }
.sub-top { display: flex; justify-content: space-between; gap: 12px; }
.sub-amount { font-weight: 650; font-variant-numeric: tabular-nums; }
.sublist .flash { margin: 8px 0 4px; font-size: 14px; }
table.merchants { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; font-size: 14px; font-variant-numeric: tabular-nums; }
table.merchants th { font-size: 11px; font-weight: 500; color: var(--muted); text-align: right; padding: 8px 6px; border-bottom: 1px solid var(--rule); }
table.merchants td { padding: 9px 6px; text-align: right; border-bottom: 1px solid var(--rule); }
table.merchants th:first-child, table.merchants td:first-child { text-align: left; padding-left: 12px; }
table.merchants td:last-child, table.merchants th:last-child { padding-right: 12px; }
table.merchants td a { color: inherit; text-decoration: none; font-weight: 550; }
table.merchants tr { cursor: pointer; }
table.merchants td.up::before { content: "▲ "; font-size: 9px; color: var(--muted); }
table.merchants td.down::before { content: "▼ "; font-size: 9px; color: var(--muted); }
.risers { display: grid; gap: 4px; }
.riser { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; color: inherit; text-decoration: none; border-bottom: 1px solid var(--rule); }
.riser:last-child { border-bottom: 0; }
.tx.excluded .tx-name, .tx.excluded .tx-amount { color: var(--muted); text-decoration: line-through; }
.linked { color: var(--muted); }
.linked a, .linked .link { color: var(--mark); font-size: 13px; padding: 0; min-height: 0; }
.viz.balance .line-actual, .viz.balance .line-forecast { fill: none; stroke: var(--mark); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz.balance .line-forecast { stroke-dasharray: 5 4; }
.viz.balance .floor { stroke: var(--out); stroke-width: 1; shape-rendering: crispEdges; }
.viz.balance .today { stroke: var(--muted); stroke-opacity: 0.5; stroke-width: 1; }
.viz.balance .dot { fill: var(--mark); stroke: var(--surface); stroke-width: 2; pointer-events: none; }
.viz.balance .hit { fill: transparent; cursor: crosshair; }
.line-key { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--mark); }
.line-key.dashed { border-top-style: dashed; }
.line-key.floor { border-top: 1px solid var(--out); }

/* --- betaald / terug / eigen deel (bijv. huur met Etienne) --- */
.split { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; margin: 4px 0 6px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.split dt, .split dd { margin: 0; }
.split dd { text-align: right; }
.split .own { color: var(--ink); font-weight: 600; }
