/* ---------------------------------------------------------------------------
   Friedman Financial

   Navy, gold and cream, sampled from design/friedman financial.png rather than
   eyeballed: the wordmark navy is #0a2740, the rule under FINANCIAL is #b78c47,
   and the ground it all sits on is #f7efe5.

   The two chart series are the brand's own colours, stepped for legibility on
   a light surface: navy to #2a5f8a and gold to #b3862f. That pair clears the
   dataviz lightness band and 3:1 contrast, and separates far better than the
   palette it replaced - normal-vision dE 27.0 and CVD dE 22.9, against 20.9
   before. It sits fractionally under the chroma floor at 0.09, which is
   inherent to blue; the required relief ships with it, since the legend is
   always present and the tooltip names each series in text.

   The bucket and spending ramps are a sequential single-hue navy scale, judged
   on lightness monotonicity rather than the categorical rules. Gold is kept for
   accents and the active nav so it stays a highlight rather than a third series.
--------------------------------------------------------------------------- */
:root {
  --bg: #f3ebe0;
  --surface: #fffdf9;
  --surface-2: #faf4ea;
  --line: #e6dccb;
  --line-soft: #efe7db;

  --ink: #0a2740;
  --ink-2: #4b5a6b;
  --ink-3: #8a8578;

  /* brand navy, dark -> pale */
  --navy-900: #0a2740;
  --navy-700: #1e4a72;
  --navy-500: #2a5f8a;
  --navy-300: #7ba0c0;
  --navy-100: #e4ecf3;

  /* chart series: the two brand colours, stepped for a light surface.
     Two categorical series must be two hues, not two steps of one. */
  --series-in: #b3862f;
  --series-out: #2a5f8a;

  /* brand gold */
  --gold-600: #9c7f45;
  --gold-500: #b78c47;
  --gold-100: #f4e8d2;

  --primary: #1e4a72;
  --primary-ink: #ffffff;
  --dark: #0a2740;

  --good: #2f7d55;   --good-bg: #e5f2e9;
  --warn: #9a6410;   --warn-bg: #fbf0dc;
  --bad:  #b03050;   --bad-bg:  #fbe9ec;

  --r-card: 16px;
  --r-ctl: 10px;
  --r-pill: 999px;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s7: 32px;
  --shadow: 0 1px 2px rgba(16, 24, 32, .04);
  --shadow-pop: 0 8px 28px rgba(16, 24, 32, .16);

  --sidebar-w: 236px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.spacer { margin-left: auto; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.num, th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- busy bar ------------------------------------------------------------ */
#busy-bar {
  position: fixed; top: 0; left: 0; height: 2px; width: 100%;
  background: var(--primary); transform: scaleX(0); transform-origin: 0 50%;
  transition: transform .25s ease, opacity .3s ease; opacity: 0; z-index: 60;
}
body.busy #busy-bar { transform: scaleX(.7); opacity: 1; }

/* --- shell --------------------------------------------------------------- */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  border-right: 1px solid var(--line);
  padding: var(--s5) var(--s3);
  display: flex; flex-direction: column; gap: var(--s2);
  position: sticky; top: 0; height: 100vh;
}
/* The mark and lockup have their cream ground keyed out, so they sit on any
   surface without a visible crop rectangle. */
.brand { display: flex; align-items: center; gap: 10px; padding: 0 var(--s2) var(--s5); }
.brand .mark { width: 26px; height: auto; flex-shrink: 0; }
.brand h1 {
  font-size: 13px; margin: 0; font-weight: 600; color: var(--navy-900);
  letter-spacing: .1em; text-transform: uppercase; line-height: 1.25;
  font-family: ui-serif, Georgia, "Times New Roman", serif;
}
.brand h1 span {
  display: block; font-size: 9.5px; letter-spacing: .22em;
  color: var(--gold-600); font-weight: 500;
}

.nav-group { margin-top: var(--s3); }
.nav-group > .nav-label {
  font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-3); padding: 0 var(--s2) var(--s2); font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: transparent; border: 0; cursor: pointer;
  padding: 8px var(--s2); border-radius: var(--r-ctl);
  font-size: 13.5px; color: var(--ink-2); text-align: left;
  transition: background .14s ease, color .14s ease;
}
.nav-item:hover { background: var(--surface); color: var(--ink); }
.nav-item.active { background: var(--gold-100); color: var(--navy-900); font-weight: 600; }
.nav-item .ico { width: 16px; height: 16px; flex-shrink: 0; opacity: .8; }
.nav-item.active .ico { opacity: 1; }
.nav-item .count {
  margin-left: auto; font-size: 11px; color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--s2); }
.ledger-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-ctl); padding: 10px;
}
.ledger-card .nav-label { padding: 0 0 6px; }

/* --- main ---------------------------------------------------------------- */
.main { flex: 1; min-width: 0; padding: var(--s5) var(--s6) var(--s7); }

.topbar { display: flex; align-items: flex-start; gap: var(--s3); margin-bottom: var(--s5); flex-wrap: wrap; }
.topbar h2 { font-size: 21px; margin: 0; font-weight: 650; letter-spacing: -0.02em; }
.topbar .sub { color: var(--ink-3); font-size: 12px; margin-top: 3px; display: flex; align-items: center; gap: 6px; }
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--good); display: inline-block; }
.topbar-actions { display: flex; align-items: center; gap: var(--s2); margin-left: auto; flex-wrap: wrap; }

.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* --- controls ------------------------------------------------------------ */
button {
  background: var(--primary); color: var(--primary-ink); border: 0;
  padding: 8px 14px; border-radius: var(--r-ctl);
  font-size: 13px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: filter .14s ease, background .14s ease;
}
button:hover:not(:disabled) { filter: brightness(1.07); }
button:disabled { opacity: .5; cursor: default; }
button.dark { background: var(--dark); }
button.ghost { background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); }
button.ghost:hover:not(:disabled) { background: var(--surface-2); filter: none; color: var(--ink); }

.seg {
  display: flex; gap: 2px; background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 2px;
}
.seg button { background: transparent; color: var(--ink-3); padding: 4px 11px; border-radius: 7px; font-size: 12px; }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }

input, select {
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  padding: 7px 10px; border-radius: var(--r-ctl); font-size: 13px; font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--navy-500); }
input.limit { width: 96px; text-align: right; font-variant-numeric: tabular-nums; }
select.mini { padding: 5px 8px; font-size: 12px; }
select.full { width: 100%; }
.checkbox { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.checkbox input { width: auto; }

.link-btn {
  background: none; border: 0; color: var(--ink-3); cursor: pointer;
  font-size: 12px; padding: 2px 4px; text-decoration: underline; font-family: inherit;
}
.link-btn:hover { color: var(--ink); filter: none; }
.link-more {
  background: none; border: 0; color: var(--navy-700); cursor: pointer;
  font-size: 12px; font-weight: 600; padding: 0; font-family: inherit;
}
.link-more:hover { filter: none; text-decoration: underline; }

/* --- pills / badges ------------------------------------------------------ */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: var(--r-pill);
  background: var(--bg); color: var(--ink-2); white-space: nowrap;
}
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad  { background: var(--bad-bg);  color: var(--bad); }
.pill.teal { background: var(--navy-100); color: var(--navy-700); }
.pill.gold { background: var(--gold-100); color: var(--gold-600); }
.badge {
  font-size: 10px; letter-spacing: .06em; padding: 3px 7px; border-radius: var(--r-pill);
  background: var(--warn-bg); color: var(--warn); font-weight: 700;
}

/* --- cards --------------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); padding: var(--s4);
  box-shadow: var(--shadow);
}
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: var(--s3); }

/* Anything that drills through to the rows behind a figure. */
.drill { cursor: pointer; transition: border-color .14s ease, box-shadow .14s ease, background .14s ease; }
.card.drill:hover { border-color: var(--navy-500); box-shadow: 0 2px 10px rgba(16, 24, 32, .07); }
.drill:focus-visible { outline: 2px solid var(--navy-500); outline-offset: 2px; }
.card.drill .stat-label::after {
  content: '›'; margin-left: auto; color: var(--ink-3);
  font-size: 15px; line-height: 1; opacity: 0; transition: opacity .14s ease;
}
.card.drill:hover .stat-label::after { opacity: 1; }
/* The balance card already puts a count in that slot, so no chevron there. */
.card.drill .stat-label:has(.spacer)::after { content: none; }
.card-head { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s3); }
.card-head h3 {
  font-size: 13px; margin: 0; font-weight: 600; color: var(--ink);
  display: flex; align-items: center; gap: 7px;
}
.card-head .ico { width: 15px; height: 15px; color: var(--ink-3); }
.card-head .note { color: var(--ink-3); font-size: 12px; }

.grid { display: grid; gap: var(--s3); }
.grid-3 { grid-template-columns: 1.35fr 1fr 1fr; }
.grid-4 { grid-template-columns: 1.45fr 1fr 1fr 1fr; }
.grid-2 { grid-template-columns: 1.6fr 1fr; }
@media (max-width: 1400px) { .grid-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 1100px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .grid-4 { grid-template-columns: 1fr; } }

/* --- hero numbers -------------------------------------------------------- */
.stat-label { color: var(--ink-2); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 7px; }
.stat-value { font-size: 30px; font-weight: 650; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat-value .cents { font-size: .55em; color: var(--ink-3); font-weight: 500; letter-spacing: 0; }
.stat-value.mid { font-size: 24px; }
.stat-row { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s2); flex-wrap: wrap; }
.stat-note { color: var(--ink-3); font-size: 12px; }
.stat-actions { display: flex; gap: var(--s2); margin-top: var(--s4); flex-wrap: wrap; }

.substats { display: flex; gap: var(--s5); margin-top: var(--s3); padding-top: var(--s3); border-top: 1px solid var(--line-soft); }
.substats .k { color: var(--ink-3); font-size: 11.5px; }
.substats .v { font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* --- daily-spend dot grid (sequential single hue) ------------------------ */
.dotgrid { display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; gap: 3px; }
.dotgrid i { width: 9px; height: 9px; border-radius: 2px; background: var(--navy-100); display: block; }

/* --- composition bar (top buckets inside a stat card) -------------------- */
.compbar { display: flex; gap: 2px; margin-top: var(--s3); }
.compbar > span { height: 8px; border-radius: 3px; }
.complegend { display: flex; gap: var(--s3); margin-top: var(--s2); flex-wrap: wrap; }
.complegend span { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--ink-2); }

/* --- insights ------------------------------------------------------------ */
.insights { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
@media (max-width: 900px) { .insights { grid-template-columns: 1fr; } }
.insight { padding: 0 var(--s4); border-left: 1px solid var(--line-soft); }
.insight:first-child { padding-left: 0; border-left: 0; }
.insight .k {
  font-size: 10px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 700; margin-bottom: 6px;
}
.insight p { margin: 0; font-size: 13px; color: var(--ink-2); line-height: 1.45; }

/* --- chart --------------------------------------------------------------- */
.chart-wrap { position: relative; margin-top: var(--s4); }
.chart-grid { position: absolute; inset: 0 0 24px 0; pointer-events: none; }
.chart-grid .gridline { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--line); }
.chart-grid .gridline span {
  position: absolute; right: 0; top: -8px; font-size: 10px;
  color: var(--ink-3); background: var(--surface); padding-left: 6px;
}
.chart { display: flex; align-items: flex-end; gap: 6px; height: 190px; overflow-x: auto; }
/* An empty chart should not reserve its full plot height. */
.chart.is-empty, .stack.is-empty { height: auto; align-items: flex-start; }
.month { display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 44px; flex: 1; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; }
.bar { width: 14px; border-radius: 4px; transition: filter .12s ease; }
.bar.income { background: var(--series-in); }
.bar.spend { background: var(--series-out); }
.month:hover .bar { filter: brightness(1.15); }
.month .lbl { font-size: 11px; color: var(--ink-3); }
.legend { display: flex; gap: var(--s3); font-size: 11.5px; color: var(--ink-2); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 40;
  background: var(--dark); color: #fff;
  border-radius: var(--r-ctl); padding: 9px 11px; font-size: 12px;
  box-shadow: var(--shadow-pop); white-space: nowrap;
}
.tooltip .t-month { color: #9aa3ad; margin-bottom: 5px; font-size: 11px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.tooltip .t-row .v { margin-left: auto; font-weight: 600; }

/* --- spending stack (sequential ramp) ------------------------------------ */
.stack { display: flex; gap: var(--s2); align-items: flex-end; height: 190px; margin-top: var(--s4); }
.stack .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 0; }
.stack .cap { height: 4px; border-radius: 3px; margin-bottom: 6px; }
.stack .track { flex: 1; background: var(--navy-100); border-radius: 10px; position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; }
.stack .fill { border-radius: 10px; padding: 9px 10px; color: #fff; display: flex; flex-direction: column; justify-content: flex-end; min-height: 34px; }
.stack .fill .p { font-size: 17px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; }
.stack .fill .p sup { font-size: .6em; font-weight: 500; margin-left: 1px; }
/* Name and amount sit under the track rather than inside the fill: our bucket
   shares are far more skewed than the reference's, so a small fill cannot hold
   three lines without clipping. Keeping them outside preserves the encoding. */
.stack .meta { margin-top: var(--s2); min-width: 0; }
.stack .meta .n { font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack .meta .a { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* --- upcoming strip ------------------------------------------------------ */
.upcoming { display: flex; gap: 0; overflow-x: auto; }
.up-item { display: flex; align-items: center; gap: 10px; padding: 0 var(--s4); border-left: 1px solid var(--line-soft); flex-shrink: 0; }
.up-item:first-child { padding-left: 0; border-left: 0; }
.up-date {
  background: var(--bg); border-radius: 8px; padding: 4px 7px; text-align: center;
  font-size: 10px; color: var(--ink-2); font-weight: 600; line-height: 1.25; white-space: nowrap;
}
.up-name { font-size: 12.5px; font-weight: 500; }
.up-amt { font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* --- tables -------------------------------------------------------------- */
.table-scroll { overflow-x: auto; margin: 0 calc(var(--s4) * -1); padding: 0 var(--s4); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; color: var(--ink-3); font-weight: 500;
  border-bottom: 1px solid var(--line); padding: 8px 8px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .05em; white-space: nowrap;
}
td { padding: 10px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td, table tr:last-child td { border-bottom: 0; }
tr.excluded td { opacity: .5; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  background: var(--navy-100); color: var(--navy-700);
  display: grid; place-items: center; font-size: 10.5px; font-weight: 700; letter-spacing: .02em;
}
.who { display: flex; align-items: center; gap: 10px; }
.who .nm { font-weight: 500; }
.who .sb { color: var(--ink-3); font-size: 11px; text-transform: capitalize; }

/* --- balances owed ------------------------------------------------------- */
.owed-row {
  display: flex; align-items: center; gap: var(--s3);
  padding: 11px 8px; border-bottom: 1px solid var(--line-soft);
}
.owed-row:last-child { border-bottom: 0; }
.owed-row .nm { font-weight: 500; }
.owed-row .sb { color: var(--ink-3); font-size: 11px; text-transform: capitalize; }
.owed-row .util { flex: 1; max-width: 260px; min-width: 90px; }
.owed-row .amt { font-variant-numeric: tabular-nums; font-weight: 600; width: 110px; text-align: right; }

/* --- P&L matrix ---------------------------------------------------------- */
.pnl { font-size: 12.5px; border-collapse: separate; border-spacing: 0; }
.pnl th, .pnl td { white-space: nowrap; }
.pnl th.m, .pnl td.m { text-align: right; font-variant-numeric: tabular-nums; min-width: 78px; }
.pnl .rowname {
  position: sticky; left: 0; background: var(--surface);
  text-align: left; min-width: 150px; z-index: 1;
  box-shadow: 8px 0 8px -8px rgba(16, 24, 32, .1);
}
/* Row headers are <th> for semantics, but they are labels not column headings -
   the uppercase/small treatment that suits the month row reads as shouting. */
.pnl tbody th.rowname {
  text-transform: none; letter-spacing: 0; font-size: 12.5px;
  color: var(--ink); font-weight: 500;
}
.pnl thead th { position: sticky; top: 0; background: var(--surface); z-index: 2; }
.pnl thead th.rowname { z-index: 3; }
.pnl td.zero { color: var(--ink-3); }
.pnl tr.total td, .pnl tr.total th { border-top: 1px solid var(--line); font-weight: 600; }
.pnl tr.income td, .pnl tr.income th { color: var(--good); }
.pnl tr.net td, .pnl tr.net th { font-weight: 700; }
.pnl td.neg { color: var(--bad); }
.pnl td.tot, .pnl th.tot {
  border-left: 1px solid var(--line); font-weight: 600;
  position: sticky; right: 0; background: var(--surface);
  box-shadow: -8px 0 8px -8px rgba(16, 24, 32, .1);
}
/* Heat behind each cell: one hue, opacity carrying magnitude - a sequential
   ramp, so it is judged on monotonicity rather than the categorical rules. */
.pnl td.m span.cell { display: block; padding: 3px 6px; border-radius: 5px; }

/* --- manual entry form --------------------------------------------------- */
.entry-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--s3); margin-bottom: var(--s3);
}
.entry-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--ink-2); }
.entry-grid label.wide { grid-column: span 2; }
.entry-grid label.checkbox.inline { flex-direction: row; align-items: center; align-self: end; padding-bottom: 8px; }

/* --- tax ledger ---------------------------------------------------------- */
.ledger-line {
  display: flex; align-items: center; gap: var(--s3);
  padding: 9px 8px; border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.ledger-line:last-child { border-bottom: 0; }
.ledger-line .k { flex: 1; min-width: 0; }
.ledger-line .k .sb { color: var(--ink-3); font-size: 11px; }
.ledger-line .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.ledger-line.sum { border-top: 1px solid var(--line); border-bottom: 0; margin-top: 4px; font-weight: 600; }
.src {
  font-size: 10px; padding: 2px 6px; border-radius: var(--r-pill);
  background: var(--bg); color: var(--ink-3); white-space: nowrap;
}
.src.manual { background: var(--warn-bg); color: var(--warn); }
.src.feed { background: var(--navy-100); color: var(--navy-700); }

.flag {
  background: none; border: 1px solid var(--line); color: var(--ink-3);
  padding: 3px 7px; border-radius: var(--r-pill); font-size: 11px; cursor: pointer;
}
.flag.on { background: var(--good-bg); border-color: transparent; color: var(--good); font-weight: 600; }
.flag:hover { filter: none; }
input.memo { width: 150px; font-size: 12px; padding: 5px 8px; }

/* --- chat widget --------------------------------------------------------- */
#chat-widget {
  position: fixed; right: var(--s6); bottom: var(--s6); z-index: 45;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
}
.chat-launcher {
  background: var(--navy-900); color: #fff;
  padding: 11px 18px 11px 15px; border-radius: var(--r-pill);
  box-shadow: 0 6px 20px rgba(10, 39, 64, .28);
  font-size: 13.5px; font-weight: 500;
}
.chat-launcher:hover { filter: brightness(1.15); }
.chat-panel {
  width: 400px; max-width: calc(100vw - var(--s6) * 2);
  height: 560px; max-height: calc(100vh - 140px);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); box-shadow: 0 16px 48px rgba(10, 39, 64, .22);
  display: flex; flex-direction: column; overflow: hidden;
  animation: pop .16s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2);
}
.chat-head img { width: 22px; height: auto; }
.chat-head .t { font-size: 13px; font-weight: 600; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.chat-head .s { font-size: 10.5px; color: var(--ink-3); }
.icon-btn {
  background: transparent; color: var(--ink-3); padding: 5px;
  border-radius: 7px; line-height: 0;
}
.icon-btn:hover { background: var(--bg); color: var(--ink); filter: none; }

/* --- assistant ----------------------------------------------------------- */
#chat-log { flex: 1; overflow-y: auto; padding: var(--s3) var(--s4); }
.msg { display: flex; gap: 10px; padding: 10px 0; }
.msg .who-i {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-size: 10px; font-weight: 700;
}
.msg.you .who-i { background: var(--navy-100); color: var(--navy-700); }
.msg.ff .who-i { background: var(--gold-100); color: var(--gold-600); }
.msg .body { flex: 1; min-width: 0; font-size: 13.5px; line-height: 1.55; }
.msg .body p { margin: 0 0 8px; }
.msg .body p:last-child { margin-bottom: 0; }
.msg .body strong { font-weight: 650; }
.msg .body ul { margin: 0 0 8px; padding-left: 18px; }
.msg .body li { margin-bottom: 4px; }
.tool-trace {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px;
}
.tool-trace span {
  font-size: 10.5px; padding: 2px 7px; border-radius: var(--r-pill);
  background: var(--bg); color: var(--ink-3); font-family: ui-monospace, monospace;
}
.chat-suggest { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 var(--s4) var(--s2); }
.chat-suggest button {
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-2);
  font-size: 11.5px; padding: 5px 10px; border-radius: var(--r-pill); font-weight: 400;
  text-align: left;
}
.chat-suggest button:hover { background: var(--surface-2); filter: none; color: var(--ink); }
.chat-input {
  display: flex; gap: var(--s2); padding: var(--s3) var(--s4);
  border-top: 1px solid var(--line-soft);
}
.chat-input input { flex: 1; min-width: 0; }
.chat-input button { padding: 8px 11px; line-height: 0; }

.model-picker { display: flex; align-items: flex-end; gap: var(--s3); flex-wrap: wrap; }
.model-picker label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--ink-2); }
.model-picker select { min-width: 190px; }

/* --- archive ------------------------------------------------------------- */
.convo-row {
  display: flex; align-items: center; gap: var(--s3);
  padding: 10px 8px; border-bottom: 1px solid var(--line-soft);
  cursor: pointer; border-radius: 8px;
}
.convo-row:last-child { border-bottom: 0; }
.convo-row:hover { background: var(--surface-2); }
.convo-row.active { background: var(--gold-100); }
.convo-row .t { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-row .s { font-size: 11px; color: var(--ink-3); }
#archive-transcript { max-height: 62vh; overflow-y: auto; }
.chat-cost { font-size: 10.5px; color: var(--ink-3); margin-top: 6px; font-variant-numeric: tabular-nums; }
.blink::after {
  content: '▍'; margin-left: 1px; animation: blink 1s steps(2) infinite; color: var(--gold-600);
}
@keyframes blink { 50% { opacity: 0; } }

/* --- documents ----------------------------------------------------------- */
.upload-btn { position: relative; overflow: hidden; display: inline-flex; }
.upload-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.upload-btn span {
  background: var(--primary); color: #fff; padding: 8px 14px;
  border-radius: var(--r-ctl); font-size: 13px; font-weight: 500; cursor: pointer;
}
.upload-btn:hover span { filter: brightness(1.07); }
.doc-row {
  display: flex; align-items: center; gap: var(--s3);
  padding: 10px 8px; border-bottom: 1px solid var(--line-soft);
}
.doc-row:last-child { border-bottom: 0; }
.doc-row .nm { font-weight: 500; word-break: break-all; }
.doc-row .sb { color: var(--ink-3); font-size: 11px; }
.doc-icon {
  width: 30px; height: 30px; border-radius: 7px; flex-shrink: 0;
  background: var(--navy-100); color: var(--navy-700);
  display: grid; place-items: center; font-size: 9px; font-weight: 700;
}

/* --- split editor -------------------------------------------------------- */
.split-host td { background: var(--surface-2); padding: 0; }
.split-editor { padding: var(--s3) var(--s2); }
.split-head { display: flex; align-items: center; gap: var(--s2); font-size: 12.5px; font-weight: 500; margin-bottom: var(--s2); }
.split-part { display: flex; align-items: center; gap: var(--s2); padding: 5px 0; flex-wrap: wrap; }
.split-part .memo { flex: 1; min-width: 140px; }
.split-actions { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s3); flex-wrap: wrap; }
.split-editor .err { margin: var(--s2) 0 0; }

/* --- filter bar ---------------------------------------------------------- */
.filters {
  display: flex; align-items: center; gap: var(--s2);
  padding-bottom: var(--s3); margin-bottom: var(--s1); flex-wrap: wrap;
}
.search { position: relative; flex: 1 1 240px; min-width: 180px; }
.search .ico {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--ink-3); pointer-events: none;
}
.search input { width: 100%; padding-left: 30px; }
.search input::-webkit-search-cancel-button { cursor: pointer; }

/* --- line chart (net worth / cash over time) ----------------------------- */
.line-wrap { position: relative; margin-top: var(--s4); }
#line-chart { width: 100%; height: 150px; display: block; overflow: visible; }
#line-chart .grid { stroke: var(--line); stroke-dasharray: 3 3; stroke-width: 1; vector-effect: non-scaling-stroke; }
#line-chart .area { fill: url(#lineFade); }
#line-chart .line { fill: none; stroke: var(--navy-700); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
#line-chart .cursor { stroke: var(--ink-3); stroke-width: 1; vector-effect: non-scaling-stroke; }
#line-chart .knob { fill: var(--surface); stroke: var(--navy-700); stroke-width: 2; vector-effect: non-scaling-stroke; }
.line-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--ink-3); margin-top: 6px; }
.line-y {
  position: absolute; right: 0; font-size: 10px; color: var(--ink-3);
  background: var(--surface); padding-left: 6px;
}

/* --- price changes ------------------------------------------------------- */
.price-row {
  display: flex; align-items: center; gap: var(--s3);
  padding: 12px 8px; border-bottom: 1px solid var(--line-soft);
}
.price-row:last-child { border-bottom: 0; }
.price-row .nm { font-weight: 500; }
.price-row .from-to { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 13px; }
.price-row .from-to s { color: var(--ink-3); text-decoration-thickness: 1px; }
.price-row .spark { width: 108px; height: 26px; flex-shrink: 0; }
.price-row .spark path { fill: none; stroke: var(--navy-500); stroke-width: 1.5; vector-effect: non-scaling-stroke; }

/* --- progress meters ----------------------------------------------------- */
.progress { height: 7px; border-radius: 4px; background: var(--navy-100); overflow: hidden; }
.progress > div { height: 100%; border-radius: 4px; background: var(--navy-500); transition: width .3s ease; }
.progress > div.over { background: var(--bad); }
.progress > div.close { background: var(--warn); }

/* --- bucket rows --------------------------------------------------------- */
.bucket-row {
  display: flex; align-items: center; gap: var(--s3);
  padding: 11px 8px; border-bottom: 1px solid var(--line-soft); cursor: pointer;
  border-radius: 8px;
}
.bucket-row:hover { background: var(--surface-2); }
.bucket-row:last-of-type { border-bottom: 0; }
.bucket-row .name { width: 190px; flex-shrink: 0; display: flex; align-items: center; font-weight: 500; }
.bucket-row .amount { width: 100px; text-align: right; font-variant-numeric: tabular-nums; }
.bucket-row .pct { width: 42px; text-align: right; color: var(--ink-3); font-size: 12px; }
.bucket-row .track { flex: 1; min-width: 60px; }
.bucket-detail { padding: 2px 0 12px 210px; }
.bucket-detail table { font-size: 12.5px; }
.bucket-detail td { border-bottom: 0; padding: 4px 8px; }
@media (max-width: 800px) {
  .bucket-row .name { width: 120px; }
  .bucket-detail { padding-left: 8px; }
}

/* Drawn rather than a glyph - the character renders as a dot at this size. */
.caret {
  display: inline-block; width: 0; height: 0;
  border-left: 5px solid var(--ink-3);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  margin-right: 9px; flex-shrink: 0;
  transition: transform .15s ease;
}
.bucket-row.open .caret { transform: rotate(90deg); }

/* --- alert / misc -------------------------------------------------------- */
.alert {
  display: flex; align-items: center; gap: var(--s2);
  background: var(--bad-bg); color: var(--bad);
  border-radius: var(--r-ctl); padding: 10px var(--s3); font-size: 12.5px;
  margin-bottom: var(--s3);
}
.alert .spacer { margin-left: auto; }
.err { color: var(--bad); font-size: 12.5px; min-height: 17px; margin: 0 0 var(--s2); }
.empty { color: var(--ink-3); padding: var(--s3) 0; font-size: 13px; }

#login {
  max-width: 380px; margin: 12vh auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-card); padding: var(--s6);
  box-shadow: var(--shadow);
}
.login-logo { display: block; width: 100%; height: auto; margin-bottom: var(--s5); }
#login h2 {
  margin: 0 0 var(--s4); font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .12em; color: var(--ink-3);
}
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 10px 14px; border-radius: var(--r-ctl);
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font-size: 13.5px; font-weight: 500;
  text-decoration: none; transition: background .14s ease, border-color .14s ease;
}
.google-btn:hover { background: var(--surface-2); border-color: var(--navy-300); }
.or {
  display: flex; align-items: center; gap: var(--s3);
  margin: var(--s4) 0; color: var(--ink-3); font-size: 11px;
  text-transform: uppercase; letter-spacing: .1em;
}
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
#login input { width: 100%; margin-bottom: var(--s2); }

/* Which books to open. Below the password rather than above it: the password is
   what people came to type, and a chooser above it reads as a step to complete
   first. */
.mode-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2);
  margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--line-soft);
}
.mode-option {
  display: flex; flex-direction: column; gap: 2px; align-items: flex-start;
  padding: 9px 12px; border-radius: var(--r-ctl); cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); text-align: left;
  transition: border-color .14s ease, background .14s ease;
}
.mode-option:hover { background: var(--surface-2); }
.mode-option[aria-checked="true"] {
  border-color: var(--navy-500); background: var(--navy-100);
}
/* Selected state is carried by the label as well as the border, so it does not
   rest on colour alone. */
.mode-option[aria-checked="true"] .mode-name { color: var(--navy-700); }
.mode-option[aria-checked="true"] .mode-name::after { content: ' ✓'; }
.mode-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.mode-note { font-size: 11.5px; color: var(--ink-3); }

/* Demo banner. Fixed, so it stays true wherever you have scrolled to - the
   point is that you cannot be in demo mode and forget it. */
#demo-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center; gap: var(--s3);
  padding: 6px var(--s4);
  background: var(--gold-100); color: var(--gold-600);
  border-bottom: 1px solid var(--gold-500);
  font-size: 12px; font-weight: 600; letter-spacing: .04em;
}
#demo-banner button {
  padding: 2px 10px; font-size: 11.5px; font-weight: 600;
  border: 1px solid var(--gold-500); background: transparent; color: var(--gold-600);
  border-radius: var(--r-ctl); cursor: pointer;
}
#demo-banner button:hover { background: var(--surface); }
body.demo #app { padding-top: 30px; }

@media (max-width: 860px) {
  #app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static;
    border-right: 0; border-bottom: 1px solid var(--line);
    flex-direction: row; align-items: center; gap: var(--s3);
    overflow-x: auto; padding: var(--s3) var(--s4);
  }
  .brand, .sidebar-foot { padding: 0; margin: 0; flex-direction: row; }
  .nav-group { margin: 0; display: flex; align-items: center; gap: 2px; }
  .nav-group > .nav-label { display: none; }
  .main { padding: var(--s4); }
}

/* Direction of an amount, in the transaction tables.
   Colour is reinforcement, not the encoding: Intl already renders an outflow
   with a leading minus, so the sign carries the meaning for anyone who cannot
   separate these two hues - which, red and green being the pair they are, is a
   material number of people. The steps are the existing status tokens rather
   than pure red and green, which keeps them legible on this surface. */
td.num.amt-out { color: var(--bad); }
td.num.amt-in  { color: var(--good); font-weight: 600; }
