/* SpendPilot — light, audit-grade visual language.
 * Benchmark: Linear's app shell (standing side rail, internal scrolling,
 * hairline borders) + Stripe Dashboard's number density. Icons: Lucide.
 * Radius system: 4 (badges) / 6 (controls) / 8 (cards) / 10 (bubbles). */

:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --rail: #fbfbfa;
  --line: #e4e4e7;
  --line-strong: #d4d4d8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --ok: #15803d;   --ok-soft: #f0fdf4;
  --warn: #b45309; --warn-soft: #fffbeb;
  --over: #b91c1c; --over-soft: #fef2f2;
  --text: #18181b;
  --muted: #57606a;
}

* {
  box-sizing: border-box; margin: 0; padding: 0;
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #b6b6bd; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
}

.app {
  max-width: 1240px; margin: 0 auto; height: 100vh; min-height: 560px;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  background: var(--panel);
}

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; border-bottom: 1px solid var(--line); flex: none;
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand-mark { width: 28px; height: 28px; color: var(--accent); flex: none; }
.brand h1 { font-size: 17px; letter-spacing: -0.2px; }
.tagline { color: var(--muted); font-size: 12px; }

.ghost-btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; font-size: 13px;
  transition: border-color 120ms ease, color 120ms ease;
}
.ghost-btn:hover { color: var(--text); border-color: var(--line-strong); }

/* --- two-column app shell --- */
.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) 320px;
}
.main-col { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.main-col .chat { flex: 1; overflow-y: auto; }
.side-col {
  overflow-y: auto; background: var(--rail);
  padding: 16px; display: flex; flex-direction: column; gap: 14px;
}

/* scenario chips — one quiet row above the conversation */
.chips { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 20px 2px; flex: none; }
.chip {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 6px 11px; font-size: 12.5px; cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease;
}
.chip:hover { border-color: var(--line-strong); background: var(--accent-soft); }

.chat { padding: 12px 20px 20px; display: flex; flex-direction: column; gap: 14px; }

.msg { max-width: 85%; padding: 11px 15px; border-radius: 10px; line-height: 1.55; font-size: 14.5px; }
.msg.agent { background: var(--panel); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 3px; }
.msg.user { background: #e8edf5; align-self: flex-end; border-bottom-right-radius: 3px; }

.carousel { display: flex; gap: 12px; overflow-x: auto; padding: 4px 2px 10px; scroll-snap-type: x mandatory; align-self: stretch; }

.card {
  min-width: 300px; max-width: 340px; scroll-snap-align: start;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 13px 15px; font-size: 14px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.card h3 { font-size: 14px; margin-bottom: 8px; }
.card .meta { color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.card .amount { font-size: 19px; font-weight: 650; margin: 6px 0; font-variant-numeric: tabular-nums; }
.card .badge {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 4px;
  margin: 0 4px 8px 0; font-weight: 600;
}
.badge.high, .badge.over { background: var(--over-soft); color: var(--over); }
.badge.medium, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.low { background: #f4f4f5; color: var(--muted); }
.badge.keep, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.conf { background: var(--accent-soft); color: var(--accent); }

.evidence {
  margin: 8px 0 0; padding: 8px 10px; background: #f8fafc;
  border-left: 2px solid var(--accent); border-radius: 4px;
  font-size: 12px; color: var(--muted); line-height: 1.6;
}
.evidence b { color: var(--text); font-weight: 600; }
.evidence .src { opacity: 0.75; font-size: 11px; }

.saving-flow { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.saving-flow .before { color: var(--over); text-decoration: line-through; }
.saving-flow .after { color: var(--ok); }
.saving-flow .arrow { color: var(--muted); font-weight: 400; }
.card ul { margin: 8px 0 0 16px; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.card .note { margin-top: 8px; font-size: 11.5px; color: var(--muted); font-style: italic; }
.proof-hint { color: var(--accent); }

.card.mandate { border-color: #bbe7c9; }
.card.receipt { border-color: #c3d7f8; }
.card .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-style: normal; }
.card .action-hint { font-style: normal; color: var(--ok); }
.card .action-hint b, .card .note b { color: var(--text); }

.bar { height: 8px; background: #f1f1f0; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--ok); }
.bar.warn > span { background: var(--warn); }
.bar.over > span { background: var(--over); }

.spark { display: flex; align-items: flex-end; gap: 4px; height: 34px; margin: 8px 0 4px; }
.spark > span { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; opacity: 0.85; min-height: 3px; }
.spark > span.hot { background: var(--over); }

.composer {
  display: flex; gap: 10px; padding: 12px 20px 16px;
  border-top: 1px solid var(--line); flex: none;
}
.composer input {
  flex: 1; background: var(--panel); border: 1px solid var(--line-strong); color: var(--text);
  border-radius: 6px; padding: 11px 14px; font-size: 14.5px; outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.composer input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.send-btn { border: none; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600; background: var(--accent); color: white; padding: 0 20px; transition: background-color 120ms ease; }
.send-btn:hover { background: var(--accent-hover); }

/* --- side rail --- */
.side-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 13px 14px; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.side-card h2 { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.side-note { color: var(--muted); font-size: 11.5px; line-height: 1.5; }

/* action loop: vertical steps, joined by a hairline */
.pipeline { list-style: none; }
.pipeline li {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 6px 0; color: var(--muted); font-size: 13px;
}
.pipeline li .dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  border: 2px solid var(--line-strong); background: var(--panel);
}
.pipeline li:not(:last-child)::after {
  content: ""; position: absolute; left: 4px; top: 22px; bottom: -6px;
  width: 1px; background: var(--line);
}
.pipeline li.reached { color: var(--text); }
.pipeline li.reached .dot { border-color: var(--accent); background: var(--accent); }
.pipeline li.reached:not(:last-child)::after { background: var(--accent); opacity: 0.35; }
.pipeline li.current { color: var(--accent); font-weight: 600; }
.pipeline li.current .dot { box-shadow: 0 0 0 3px var(--accent-soft); }

.stat-rows div {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 6px 0; border-top: 1px solid var(--line);
}
.stat-rows div:first-child { border-top: none; padding-top: 0; }
.stat-rows dt { color: var(--muted); font-size: 12px; }
.stat-rows dt em { font-style: normal; opacity: 0.8; }
.stat-value { font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.accent-warn { color: var(--warn); }
.accent-ok { color: var(--ok); }

.ledger-body { max-height: 240px; overflow-y: auto; }
.ledger-entry {
  display: grid; grid-template-columns: 72px 1fr; gap: 8px;
  padding: 6px 0; border-top: 1px solid var(--line); font-size: 12px;
}
.ledger-entry:first-child { border-top: none; }
.ledger-entry .kind { font-weight: 700; text-transform: uppercase; font-size: 10px; letter-spacing: 0.4px; }
.kind.alert { color: var(--over); }
.kind.suppress, .kind.hold { color: var(--warn); }
.kind.budget, .kind.propose { color: var(--accent); }
.kind.challenge, .kind.refuse { color: var(--ok); }
.ledger-entry .why { color: var(--muted); line-height: 1.5; }
.ledger-entry .why b { color: var(--text); font-weight: 600; }

/* narrow screens: fall back to a single scrolling column */
@media (max-width: 960px) {
  .app { height: auto; min-height: 100vh; border: none; }
  .layout { grid-template-columns: 1fr; }
  .main-col { border-right: none; }
  .chat { max-height: none; }
  .composer { position: sticky; bottom: 0; background: var(--panel); }
  .side-col { border-top: 1px solid var(--line); }
}
