:root {
  /* Warm off-black system, cream on charcoal. Reads like a handmade
     household tool, not a corporate dashboard. */
  --bg: #14110d;
  --surface: #1c1815;
  --surface-2: #23201d;
  --text: #ede4d3;
  --muted: #9a938a;
  --border: #2e2823;
  --accent: #a5c092;        /* muted moss/sage, replaces cold blue */
  --accent-strong: #cfe0b8;
  --good: #7ba76a;          /* forest — above the line */
  --near: #d69e5a;          /* warm amber — near the line */
  --bad:  #cc6151;          /* coral — below the line */
  --total: #d4b56a;         /* warm champagne — the "answer" bar in the waterfall */
  --radius: 14px;
  --font-display: "Fraunces", ui-serif, Georgia, "Times New Roman", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    /* Cream on paper for the light scheme — same warm family, inverted. */
    --bg: #f6f1e6; --surface: #fbf6ea; --surface-2: #efe8d8;
    --text: #24211c; --muted: #6b6558; --border: #ded3ba;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
/* Serif on the pieces that carry the app's identity — headers, brand,
   the balance number, card titles. Everything else stays humanist sans
   so table rows and dense forms don't look precious. */
h1, .card-title, .brand {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.005em;
}
a { color: var(--accent); text-decoration: none; }
.wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px 64px; }
/* Widen on desktop so table-heavy pages (activity, rules admin) don't
   force horizontal scroll on a monitor that has plenty of room. */
@media (min-width: 900px)  { .wrap { max-width: 960px; padding: 20px 24px 80px; } }
@media (min-width: 1200px) { .wrap { max-width: 1120px; } }

/* Nav */
.topnav {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.navlinks { display: flex; gap: 14px; align-items: center; margin-left: auto; font-size: 14px; }
.navlinks a { color: var(--muted); }
.badge {
  background: var(--accent); color: #fff; border-radius: 999px;
  padding: 0 7px; font-size: 12px; font-weight: 700;
}
.linklike { background: none; border: none; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.inline { display: inline; margin: 0; }

/* Cards */
.card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin: 14px 0;
}
.card-title {
  font-family: var(--font-body); /* small caps look sharper in sans */
  font-size: 12px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted); margin-bottom: 12px; font-weight: 600;
}
.muted { color: var(--muted); }
.error { color: var(--bad); }
h1 { font-size: 26px; margin: 8px 0 6px; letter-spacing: -0.01em; }

/* Gauge — the hero card. Serif number, mood word, warm tinted glow. */
.gauge {
  text-align: center; border-radius: 20px; padding: 32px 20px 26px;
  margin: 14px 0; border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  position: relative;
}
.gauge-comfortable { box-shadow: inset 0 0 0 9999px rgba(123,167,106,.06); border-color: rgba(123,167,106,.35); }
.gauge-near        { box-shadow: inset 0 0 0 9999px rgba(214,158,90,.07); border-color: rgba(214,158,90,.35); }
.gauge-below       { box-shadow: inset 0 0 0 9999px rgba(204,97,81,.08); border-color: rgba(204,97,81,.4); }
.gauge-headline {
  font-family: var(--font-display);
  font-size: clamp(18px, 3.4vw, 24px);
  font-weight: 500; line-height: 1.2;
  margin: 0 auto 14px;
  max-width: 34ch;
  color: var(--text);
}
.gauge-comfortable .gauge-headline { color: var(--good); }
.gauge-near        .gauge-headline { color: var(--near); }
.gauge-below       .gauge-headline { color: var(--bad); }
.gauge-label {
  color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: .12em; font-weight: 600;
}
.gauge-balance {
  font-family: var(--font-display);
  font-size: clamp(48px, 10vw, 68px);
  font-weight: 500; letter-spacing: -.02em; margin: 8px 0 4px;
  font-variant-numeric: tabular-nums;
}
.gauge-mood {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 20px; margin: 2px 0 8px;
  color: var(--muted);
}
.gauge-comfortable .gauge-mood { color: var(--good); }
.gauge-near        .gauge-mood { color: var(--near); }
.gauge-below       .gauge-mood { color: var(--bad); }
.gauge-status { font-size: 17px; font-weight: 600; }
.gauge-detail { color: var(--muted); font-size: 14px; margin-top: 6px; }
.gauge-delta { font-size: 14px; color: var(--muted); margin-top: 2px; }
.delta-num { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.delta-num.up { color: var(--good); }
.delta-num.down { color: var(--bad); }
.gauge-asof {
  color: var(--muted); font-size: 12px; margin-top: 14px;
  letter-spacing: .04em;
}

/* Combined "How it adds up" — meter beside/atop the waterfall.
   Mobile: column, meter above (centered). Desktop: row, meter left. */
.fviz-body { display: flex; flex-direction: column; gap: 18px; align-items: center; }
@media (min-width: 720px) {
  .fviz-body { flex-direction: row; align-items: stretch; gap: 28px; }
}
.fviz-meter {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  flex: 0 0 auto;
}
.fviz-waterfall { flex: 1 1 auto; min-width: 0; align-self: stretch; }
.fviz-cap {
  font-family: var(--font-body); font-size: 12px; color: var(--muted);
  letter-spacing: .04em; font-variant-numeric: tabular-nums;
}
.fviz-linelabel {
  font-family: var(--font-display); font-style: italic;
  font-size: 14px; margin-top: 8px;
}

/* Vertical float meter */
.meter { display: block; }
.meter-below { fill: rgba(204,97,81,.22); }
.meter-above { fill: rgba(123,167,106,.22); }
.meter-line { stroke: var(--text); stroke-width: 1.5; opacity: .8; stroke-dasharray: 4 3; }
.meter-pointer {
  fill: var(--accent-strong); stroke: var(--surface);
  stroke-width: 1.5;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.35));
}
.fviz-meter.gauge-below       .meter-pointer { fill: var(--bad); }
.fviz-meter.gauge-near        .meter-pointer { fill: var(--near); }
.fviz-meter.gauge-comfortable .meter-pointer { fill: var(--good); }

/* Waterfall */
.waterfall { display: block; width: 100%; height: auto; }
.wf-add { fill: var(--good); }
.wf-subtract { fill: var(--bad); }
.wf-total { fill: var(--total); }
.wf-zero { stroke: var(--border); stroke-width: 1; }
.wf-bar { cursor: pointer; outline: none; }
.wf-hit { fill: transparent; }
.wf-bar:hover .wf-add, .wf-bar.active .wf-add,
.wf-bar:hover .wf-subtract, .wf-bar.active .wf-subtract,
.wf-bar:hover .wf-total, .wf-bar.active .wf-total { opacity: 0.75; }
.wf-detail { text-align: center; margin-top: 8px; font-size: 13px; font-variant-numeric: tabular-nums; min-height: 1.2em; }

/* Savings FYI */
.savings-row { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.savings-row + .savings-row { border-top: 1px solid var(--border); }

/* Trend chart */
.spark { display: block; width: 100%; height: auto; }
.spark-path { stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; fill: none; }
.spark-line { stroke: var(--muted); stroke-width: 1; opacity: .85; vector-effect: non-scaling-stroke; }
.spark-forecast { stroke: var(--muted); stroke-width: 2; opacity: 0.9; vector-effect: non-scaling-stroke; }
.spark-forecast-dot { fill: var(--muted); }
.spark-forecast-value { fill: var(--text); font-size: 12px; font-variant-numeric: tabular-nums; font-weight: 600; }
.spark-grid { stroke: var(--border); stroke-width: 1; opacity: .35; vector-effect: non-scaling-stroke; }
.spark-axis-line { stroke: var(--border); stroke-width: 1; opacity: .7; vector-effect: non-scaling-stroke; }
.spark-y-label { fill: var(--muted); font-size: 12px; text-anchor: end; font-variant-numeric: tabular-nums; }
.spark-x-label { fill: var(--muted); font-size: 12px; }
.spark-line-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.spark-legend { margin-top: 8px; font-size: 12px; }
.spark-wrap { position: relative; }
.spark-crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; opacity: .7; vector-effect: non-scaling-stroke; }
.spark-hover-dot { fill: var(--accent-strong); stroke: var(--surface); stroke-width: 1.5; }
.spark-tip-bg { fill: var(--surface-2); stroke: var(--border); stroke-width: 1; opacity: .96; }
.spark-tip-text { fill: var(--text); font-size: 12px; font-variant-numeric: tabular-nums; font-weight: 600; }
.spark-line { stroke: var(--muted); stroke-width: 1; opacity: .8; vector-effect: non-scaling-stroke; }
.spark-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 4px; }

/* Pills */
.pills { display: flex; gap: 10px; }
.pill { flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; text-align: center; }
.pill-link { color: var(--text); }
.pill-num { font-size: 24px; font-weight: 700; }
.pill-cap { font-size: 12px; color: var(--muted); }

/* Stale banner */
.stale-banner {
  background: var(--bad); color: #fff; padding: 12px 14px;
  border-radius: 12px; font-weight: 600; margin: 4px 0 12px;
}

/* Review */
.review-item { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; }
.ri-head { display: flex; justify-content: space-between; gap: 10px; font-weight: 600; }
.ri-meta { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.ri-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ri-amount.out { color: var(--bad); }
.ri-amount.in { color: var(--good); }
.ri-single-only { display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  padding: 6px 8px; cursor: pointer; user-select: none; }
.ri-single-only input[type="checkbox"] { margin: 0; }
.ri-badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px;
  font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; vertical-align: middle; }
.ri-badge-ai { background: rgba(79,140,255,.18); color: var(--accent); border: 1px solid rgba(79,140,255,.35); }
.ri-badge-rule { background: rgba(255,255,255,.05); color: var(--muted); border: 1px solid var(--border); }
.ri-badge-audit { background: rgba(255,180,0,.15); color: #ffb400; border: 1px solid rgba(255,180,0,.35); }
.ri-confidence { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.review-stats { font-size: 12px; margin: 4px 0 14px; }
.review-stats b { color: var(--text); font-variant-numeric: tabular-nums; }

/* Forms */
button, select, input {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
button { cursor: pointer; }
button.primary, button.confirm { background: var(--accent); color: #fff; border-color: transparent; font-weight: 600; }

/* Sync-now button: htmx-indicator swap. Static "Sync now" label swaps to a
   spinner + "Syncing…" label while the request is in flight. hx-disabled-elt
   tells htmx to also apply the disabled attribute on the button so it can't
   be double-clicked. */
.sync-btn { display: inline-flex; align-items: center; gap: 8px; position: relative; }
.sync-btn .sync-spinner, .sync-btn .sync-label-busy { display: none; }
.sync-btn.htmx-request .sync-label { display: none; }
.sync-btn.htmx-request .sync-spinner,
.sync-btn.htmx-request .sync-label-busy { display: inline-flex; }
.sync-btn[disabled] { opacity: .8; cursor: progress; }
.sync-spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: sync-spin 0.7s linear infinite;
}
@keyframes sync-spin { to { transform: rotate(360deg); } }
button.confirm { flex: 1; }
select { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label, fieldset label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.stack input, .stack select, fieldset input { color: var(--text); }
fieldset { border: 1px solid var(--border); border-radius: 12px; display: flex; flex-direction: column; gap: 10px; }
legend { color: var(--muted); font-size: 13px; padding: 0 6px; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.filters { display: flex; gap: 8px; margin-bottom: 10px; }

/* Login */
.login-card { max-width: 340px; margin: 12vh auto 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; text-align: center; }
.login-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

/* Tables */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.out { color: var(--bad); }
td.in { color: var(--good); }
td.detail { white-space: normal; color: var(--muted); font-size: 12px; }

/* Chips */
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.chip.transfer { border-color: var(--accent); color: var(--accent); }

/* Status */
.status { padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.status-success { background: rgba(47,191,113,.16); color: var(--good); }
.status-error { background: rgba(229,72,77,.16); color: var(--bad); }
.status-running { background: rgba(79,140,255,.16); color: var(--accent); }
.drift-narrative { font-size: 16px; }

/* Account overrides table */
.accounts-form { display: flex; flex-direction: column; gap: 12px; }
.acct-group { border: 1px solid var(--border); border-radius: 12px; padding: 4px 12px; }
.acct-group summary { cursor: pointer; padding: 8px 0; font-weight: 600; }
.acct-table th, .acct-table td { padding: 6px 6px; vertical-align: top; }
.acct-table input[type="text"] { width: 100%; padding: 6px 8px; font-size: 13px; }
.acct-table .acct-key { font-size: 11px; margin-top: 3px; font-family: ui-monospace, monospace; }
.acct-table .acct-active, .acct-table th.acct-active { text-align: center; width: 60px; }
.acct-table .acct-delete, .acct-table th.acct-delete { text-align: right; width: 60px; }
.acct-table input[type="checkbox"] { transform: scale(1.2); }
.danger-link { background: transparent; border: 1px solid transparent; color: var(--bad);
  padding: 4px 8px; font-size: 12px; font-weight: 600; }
.danger-link:hover { border-color: var(--bad); }
.err { background: rgba(229,72,77,.14); border: 1px solid var(--bad); color: var(--bad);
  padding: 10px 12px; border-radius: 10px; margin: 4px 0 10px; font-size: 13px; }
