/* Kitty — "ledger ink" design system.
   A household ledger by lamplight: deep green-ink surfaces (old ledger covers),
   aged-paper text, one interactive accent (rand-note brass), and ink-stamp status
   colours. Young Serif is reserved for the wordmark and hero money figures —
   everything else is quiet system sans with tabular numerals. */

@font-face {
  font-family: "Young Serif";
  src: url("/assets/young-serif-fea48221.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0f1411;          /* deep green ink */
  --panel: #171f19;       /* raised ledger board */
  --well: #0b0f0c;        /* inset wells: charts, inputs */
  --line: #263129;        /* hairline rules */
  --text: #e9e4d4;        /* aged paper */
  --muted: #94a094;       /* sage */
  --accent: #d2b160;      /* rand brass — the only interactive colour */
  --accent-bright: #e0c47a;
  --accent-ink: #241c08;  /* text on brass */
  --ok: #6cc394;          /* leaf stamp */
  --bad: #e26a52;         /* madder stamp */
  --warn: #dd9c3f;        /* ochre stamp */
  --ring: rgba(210, 177, 96, .25);
  --display: "Young Serif", "Iowan Old Style", Georgia, serif;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums lining-nums;
  -webkit-font-smoothing: antialiased;
}
::selection { background: rgba(210, 177, 96, .32); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px; background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: inset 0 -1px 0 rgba(210, 177, 96, .12); /* faint gilt edge under the rule */
}
.brand {
  color: var(--text); text-decoration: none;
  font-family: var(--display); font-size: 19px; letter-spacing: .01em;
}
.nav { display: flex; gap: 18px; margin-left: auto; margin-right: 22px; }
.nav a {
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px;
  padding: 3px 1px; border-bottom: 2px solid transparent; transition: color .12s;
}
.nav a:hover { color: var(--text); }
.nav a.active { color: var(--text); border-bottom-color: var(--accent); }

.container { max-width: 1040px; margin: 0 auto; padding: 22px 20px 48px; }
.section { margin: 34px 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Section headers as ledger eyebrows: small caps with a brass tick. */
h2 {
  display: flex; align-items: center; gap: 9px;
  font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted); margin: 0 0 12px;
}
h2::before { content: ""; width: 14px; height: 2px; background: var(--accent); flex: none; }
h2 .badge { letter-spacing: .05em; }

/* ---- Tables: the ledger ---- */
table.grid {
  width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
.grid th, .grid td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.grid th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 700; background: rgba(233, 228, 212, .02);
}
.grid tr:last-child td { border-bottom: 0; }
.grid tbody tr { transition: background .1s; }
.grid tbody tr:hover td { background: rgba(233, 228, 212, .025); }
.grid .num { text-align: right; white-space: nowrap; }
.row-bad td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.row-ok td:first-child { box-shadow: inset 3px 0 0 var(--ok); }

.muted { color: var(--muted); } .small { font-size: 12px; }
.pos { color: var(--ok); } .neg { color: var(--bad); }
.warn-text { color: var(--warn); } .bad-text { color: var(--bad); }

/* Hero money is set in the display serif — the one loud thing on the page. */
.headline {
  font-family: var(--display); font-weight: 400;
  font-size: 32px; margin: 0 0 10px; letter-spacing: .005em;
}

/* ---- Filters (Insights) ---- */
.filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.filters select, .filters summary {
  background: var(--well); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 7px 10px; font: inherit;
}
.field-cap { display: block; font-size: 13px; color: var(--muted); line-height: 1.2; }
/* One row, one height: every control sits under a caption row (real or spacer).
   Scoped to .field so inline forms that borrow .filters keep natural sizing. */
.filters .field select, .filters .field summary, .filters .field .btn { height: 40px; box-sizing: border-box; width: 100%; }
.filters .field summary, .filters .field .btn { display: inline-flex; align-items: center; justify-content: center; }
.filters summary { display: inline-flex; align-items: center; justify-content: flex-start; gap: 5px; }
.filters .field select { padding: 0 10px; }
.accounts-filter { position: relative; }
.accounts-filter summary { cursor: pointer; list-style: none; }
.account-list {
  position: absolute; z-index: 10; margin-top: 4px; max-height: 320px; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px;
  min-width: 240px; box-shadow: 0 10px 32px rgba(0, 0, 0, .45);
}
.check { display: flex; gap: 8px; align-items: center; color: var(--text); padding: 6px 8px; font-size: 14px; border: 1px solid transparent; border-radius: 8px; }
.check:has(:checked) { background: rgba(210, 177, 96, .09); border-color: rgba(210, 177, 96, .38); }
.check span { color: var(--text); }
.grid.cats tbody tr:has(input:checked) td { background: rgba(210, 177, 96, .06); }
.grid.cats tbody tr:has(input:checked) td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

.fi-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.fi-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.fi-card .headline { font-size: 22px; margin: 4px 0; }
.assumptions, .account-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.assumptions input { background: var(--well); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 7px 9px; font: inherit; }
.spend-input { width: 110px; background: var(--well); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 4px 7px; text-align: right; font: inherit; }
.group-row td {
  background: rgba(210, 177, 96, .06); font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text); font-weight: 700; padding-top: 12px; padding-bottom: 8px;
  box-shadow: inset 3px 0 0 var(--accent);
}

.table-scroll { overflow-x: auto; }
.grid.sched { min-width: 720px; }
.grid.sched td { vertical-align: middle; }
.grid.sched select.input { padding: 8px 9px; }
.grid.sched .center { text-align: center; }
.grid.sched .sched-new .input { opacity: .75; }
.grid.sched .sched-new:focus-within .input { opacity: 1; }
.sched-add { margin-top: 10px; }

.barcol { width: 32%; }
.bars { display: flex; flex-direction: column; gap: 2px; }
.bar { height: 7px; border-radius: 3px; min-width: 1px; }
.bar-in { background: var(--ok); }
.bar-out { background: var(--bad); }

/* ---- Background activity (Operations) + mirror status ---- */
.ops-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ops-list li { display: flex; gap: 10px; align-items: baseline; font-size: 14px; flex-wrap: wrap; }
.ops-list .badge { flex: none; }
.mirror-status { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.mirror-status form { margin: 0; }

/* ---- Badges as ink stamps ---- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  border: 1px solid;
}
.badge-ok { color: var(--ok); border-color: rgba(108, 195, 148, .45); background: rgba(108, 195, 148, .07); }
.badge-bad { color: var(--bad); border-color: rgba(226, 106, 82, .5); background: rgba(226, 106, 82, .08); }
.badge-warn { color: var(--warn); border-color: rgba(221, 156, 63, .45); background: rgba(221, 156, 63, .07); }
.badge-muted { color: var(--muted); border-color: rgba(148, 160, 148, .35); background: rgba(148, 160, 148, .06); }

/* ---- Buttons ---- */
.btn, .linkish { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid transparent; transition: background .12s, color .12s, border-color .12s, opacity .12s; }
.btn {
  background: var(--accent); color: var(--accent-ink);
  padding: 7px 14px; font-weight: 700;
}
a.btn { text-decoration: none; display: inline-block; }
.btn:hover { background: var(--accent-bright); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: progress; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: transparent; border-color: var(--accent); color: var(--accent-bright); }
.btn-sm { padding: 3px 11px; font-size: 13px; }
.actions { display: flex; gap: 8px; align-items: center; }
.uploader { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.uploader input[type=file] { color: var(--muted); font: inherit; }
.uploader input[type=file]::file-selector-button {
  font: inherit; font-size: 14px; cursor: pointer; margin-right: 10px;
  background: transparent; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 12px;
}
.uploader input[type=file]::file-selector-button:hover { border-color: var(--accent); color: var(--accent-bright); }
.linkish { background: transparent; color: var(--muted); padding: 2px 4px; }
.linkish:hover { color: var(--accent-bright); }
form { display: inline; }

.flash { max-width: 1040px; margin: 12px auto 0; padding: 10px 14px; border-radius: 8px; border-left: 3px solid; font-size: 14px; }
.flash-notice { background: rgba(210, 177, 96, .09); border-color: var(--accent); color: var(--accent-bright); }
.flash-alert { background: rgba(226, 106, 82, .1); border-color: var(--bad); color: var(--bad); }

/* ---- Auth ---- */
.auth { max-width: 360px; margin: 72px auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 26px 24px; box-shadow: inset 0 2px 0 rgba(210, 177, 96, .18); }
.auth h1, .auth h2 { font-family: var(--display); font-size: 22px; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text); display: block; }
.auth h1::before, .auth h2::before { display: none; }
.auth input:not([type="submit"]) { width: 100%; padding: 10px; margin: 6px 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--well); color: var(--text); font: inherit; }
.auth input:not([type="submit"]):focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.auth .btn { width: 100%; }

/* ---- Retirement: hero plate ---- */
.fi-hero {
  background: linear-gradient(165deg, #1b2519, #131a15 62%);
  border: 1px solid var(--line); border-radius: 14px; padding: 24px 26px;
  box-shadow: inset 0 2px 0 rgba(210, 177, 96, .22); /* gilt top edge */
}
.fi-hero-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 700; }
.fi-hero-date { font-family: var(--display); font-weight: 400; font-size: 38px; margin: 8px 0 4px; letter-spacing: .002em; }
.fi-hero-age { font-size: 21px; color: var(--muted); letter-spacing: 0; }
.fi-hero-sub { color: var(--text); opacity: .85; }
.fi-hero-range { margin-top: 6px; color: var(--muted); font-size: 13px; }
.fi-hero-range strong { color: var(--text); font-weight: 600; }
.fi-hero-warn { margin-top: 10px; padding: 8px 12px; border-radius: 8px; background: rgba(221, 156, 63, .09); border: 1px solid rgba(221, 156, 63, .3); color: var(--warn); font-size: 13px; }
.fi-hero-warn strong { color: var(--text); font-weight: 700; }
.fi-hero-bar { height: 8px; background: rgba(233, 228, 212, .07); border-radius: 999px; margin: 18px 0 14px; overflow: hidden; }
.fi-hero-bar span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #b8964a, #e0c476); }
.fi-hero-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.fi-hero-stats strong { font-family: var(--display); font-weight: 400; font-size: 18px; }

/* ---- Charts (shared) ---- */
.legend { display: flex; gap: 14px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dot-portfolio { background: var(--ok); } .dot-fi { background: var(--accent); } .dot-band { background: var(--ok); opacity: .3; }
.chart-wrap { position: relative; background: var(--well); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; }
.chart-capture { cursor: crosshair; pointer-events: all; }
.chart-cursor { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; opacity: 0; pointer-events: none; }
.chart-cursor-dot { fill: var(--ok); stroke: var(--well); stroke-width: 2; opacity: 0; pointer-events: none; }
.chart-active .chart-cursor, .chart-active .chart-cursor-dot { opacity: 1; }
.chart-tip { position: absolute; transform: translate(-50%, calc(-100% - 12px)); background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 5px 9px; font-size: 12px; line-height: 1.35; white-space: nowrap; pointer-events: none; z-index: 3; box-shadow: 0 6px 20px rgba(0, 0, 0, .5); }
.chart-tip strong { display: block; color: var(--text); font-size: 13px; }
.chart-tip span { display: block; color: var(--muted); }
.chart { width: 100%; height: auto; display: block; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-band { fill: var(--ok); opacity: .1; stroke: none; }
.chart-milestone { stroke: rgba(233, 228, 212, .14); stroke-width: 1; stroke-dasharray: 4 4; }
.chart-fi { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 3; opacity: .8; }
.chart-line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; }
.line-portfolio { stroke: var(--ok); }
.chart-zero { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; opacity: .5; }
.nw-line { stroke: var(--accent); }
.nw-area { fill: var(--accent); opacity: .1; stroke: none; }
.nw-chart .chart-cursor-dot { fill: var(--accent); }
.dot-in { background: var(--ok); } .dot-out { background: var(--bad); }
.cf-bar-in { fill: var(--ok); } .cf-bar-out { fill: var(--bad); }
.cf-highlight { fill: rgba(233, 228, 212, .05); opacity: 0; pointer-events: none; }
.cf-active .cf-highlight { opacity: 1; }
.cf-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 4px 0 12px; }
.cf-summary strong { font-family: var(--display); font-weight: 400; font-size: 19px; }
.cf-tip { transform: translateX(-50%); top: 8px; }
.cf-tip .pos { color: var(--ok); } .cf-tip .neg { color: var(--bad); }
.chart-caption { margin: 2px 2px 14px; line-height: 1.5; }
.chart-caption strong { color: var(--text); font-weight: 600; }
.info { border-bottom: 1px dotted currentColor; cursor: help; }
.chart-axis { fill: var(--muted); font-size: 11px; }
.chart-mlabel { fill: var(--muted); font-size: 10px; opacity: .8; }
.ladder td div.small { margin-top: 2px; }

/* ---- Collapsible panels ---- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; margin: 14px 0; overflow: hidden; }
.panel > summary { cursor: pointer; list-style: none; padding: 14px 16px; font-weight: 600; display: flex; align-items: center; gap: 10px; transition: background .12s; }
.panel > summary:hover { background: rgba(233, 228, 212, .02); }
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::before { content: "▸"; color: var(--accent); transition: transform .15s; }
.panel[open] > summary::before { transform: rotate(90deg); }
.summary-count { margin-left: auto; font-weight: 400; font-size: 13px; color: var(--muted); }
.panel-body { padding: 4px 16px 18px; border-top: 1px solid var(--line); }
.howto-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 8px 28px; margin-top: 10px; }
.howto-head { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 8px 0 6px; font-weight: 700; }
.howto-list { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.6; }
.howto-list li { margin-bottom: 6px; }
.howto-list code, .panel-body code { background: rgba(210, 177, 96, .1); color: var(--accent-bright); border-radius: 4px; padding: 1px 5px; font-size: 12px; }

/* ---- Forms ---- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-top: 12px; }
.field-lg { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.hint { font-weight: 400; font-size: 12px; color: var(--muted); }
.input { background: var(--well); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 9px 11px; font: inherit; width: 100%; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.input-prefix, .input-suffix { display: flex; align-items: center; background: var(--well); border: 1px solid var(--line); border-radius: 8px; }
.input-prefix span, .input-suffix span { color: var(--muted); padding: 0 4px 0 11px; }
.input-suffix span { padding: 0 11px 0 4px; }
.input-prefix .input, .input-suffix .input { border: 0; background: transparent; padding-left: 4px; }
.input-prefix .input:focus, .input-suffix .input:focus { box-shadow: none; }
.input-prefix:focus-within, .input-suffix:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.input-sm { padding: 6px 8px; font-size: 13px; }
.input-sm { max-width: 130px; margin-left: auto; }
.input-sm .input { text-align: right; padding: 5px 4px; }

/* ---- Motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation: none !important; }
}

/* ---- Mobile ---- */
/* Never let a stray-wide element scroll the whole page (tables opt into their own
   horizontal scroll via .table-scroll, which is unaffected by this). */
body { overflow-x: hidden; }

@media (max-width: 640px) {
  /* iOS zooms in when you focus an input under 16px and never zooms back. 16px on
     touch form controls stops it. */
  input, select, textarea { font-size: 16px !important; }

  .container { padding: 14px 14px 40px; }
  .topbar { padding: 10px 14px; flex-wrap: wrap; gap: 8px 12px; }
  .nav { margin-right: 0; gap: 14px; }

  .fi-hero { padding: 18px 16px; }
  .fi-hero-date { font-size: 28px; }
  .fi-hero-stats { grid-template-columns: repeat(2, 1fr); }
  .headline { font-size: 26px; }

  /* Stack the chart title and its legend instead of squeezing them onto one row. */
  .section-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .legend { flex-wrap: wrap; gap: 10px 14px; }

  /* One column so form fields get full width rather than being crushed. */
  .settings-grid, .assumptions, .account-grid { grid-template-columns: 1fr; }

  /* Tighter tables so nowrap amounts + bars fit a phone. */
  .grid th, .grid td { padding: 8px 8px; }
  .barcol { width: 24%; }

  /* Tables that opt in with .stack become one card per row: the header is dropped
     and every cell carries its own label, so a wide row reads top-to-bottom
     instead of forcing the sideways scroll a phone can't discover. */
  .grid.stack { border: 0; border-radius: 0; background: none; }
  .grid.stack thead { display: none; }
  .grid.stack, .grid.stack tbody, .grid.stack tr, .grid.stack td { display: block; width: 100%; }
  .grid.stack tr {
    background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
    margin-bottom: 10px; padding: 6px 2px;
  }
  .grid.stack tbody tr:hover td { background: none; }
  .grid.stack td { border-bottom: 0; padding: 5px 12px; text-align: left; }
  .grid.stack td.num { text-align: left; white-space: normal; }
  .grid.stack td[data-label]::before {
    content: attr(data-label);
    display: block; margin-bottom: 2px;
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
    color: var(--muted); font-weight: 700;
  }
  /* An action cell carries buttons and no label; keep them on one line. */
  .grid.stack td:not([data-label]) { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding-top: 8px; }
  .grid.stack .input-sm { max-width: 100%; margin-left: 0; }
  .grid.stack .fi-hero-bar { max-width: 100% !important; }
  /* The stacked card is already full width — nothing left to scroll. */
  .table-scroll:has(.grid.stack) { overflow-x: visible; }

  /* Full-width controls in wrapped filter/entry forms; 130px is a desktop-row size. */
  .filters .field .input, .filters .field select { max-width: none; }

  /* The insights charts scale down to fit the screen, shrinking their SVG-unit text
     to a few px. Bump it (in viewBox units) so it reads at the mobile scale. */
  .insights-chart .chart-axis { font-size: 26px; }

  /* Widen the chart so the accumulation-up-to-FI fills the screen; scroll for the
     rest. Only the chart scrolls, inside its own box — not the page. */
  .chart-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .chart { width: calc(var(--chart-scale, 1) * 100%); }
  .chart-scroll-hint { display: block; }
}

.chart-scroll-hint { display: none; margin: -8px 2px 14px; }

/* ---- Inline row editor (loans "Paid off by") ----
   The date saves on pick, so the button is only a fallback for when the change
   event doesn't fire (re-picking the same date). Revealed on focus so the column
   stays a quiet date, not a button per row. */
.target-on { max-width: 150px; }
.set-date { display: none; }
td:focus-within .set-date { display: inline-flex; }
