/* 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; overflow-wrap: anywhere; }
.msg.agent { background: var(--panel); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 3px; max-width: 100%; }
.msg.user { background: #e8edf5; align-self: flex-end; border-bottom-right-radius: 3px; max-width: 70%; }

.card-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px; align-self: stretch;
}

.card {
  min-width: 0;
  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);
  overflow-wrap: anywhere;
}
.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; }

/* --- the approval artifact: the signature interaction -------------------- */
.card.approval { border-color: #bbe7c9; padding-top: 0; overflow: hidden; }
.approval-head {
  margin: 0 -15px 10px; padding: 7px 15px;
  background: var(--ok-soft); color: var(--ok);
  font-size: 11px; font-weight: 700; letter-spacing: 1.5px;
}
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin: 8px 0; }
.kv > div { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.kv span { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.4px; }
.kv b { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kv .ok-text { color: var(--ok); }
.check-line { font-size: 12px; color: var(--muted); line-height: 1.7; }
.check-line::before { content: "✓  "; color: var(--ok); font-weight: 700; }
.auth-block {
  margin: 10px -15px -13px; padding: 10px 15px 13px;
  background: #f8fafc; border-top: 1px solid var(--line);
}
.auth-title { font-size: 10px; font-weight: 700; letter-spacing: 1.2px; color: var(--muted); margin-bottom: 6px; }
.auth-block .kv b.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 11.5px; }
.proof-detail { margin-bottom: 8px; }
.card.receipt { border-color: #c3d7f8; }

/* --- the denial case card: the approval artifact's dark twin ------------- */
.card.denied { border-color: #3f3f46; padding-top: 0; overflow: hidden;
  background: #1c1c1f; }
.card.denied h3 { color: #fafafa; }
.card.denied .kv b { color: #fafafa; }
.card.denied .kv span { color: #a1a1aa; }
.denied-head {
  margin: 0 -15px 10px; padding: 7px 15px;
  background: var(--over); color: #fff;
  font-size: 11px; font-weight: 700; letter-spacing: 1.5px;
}
.card.denied .denied-block { background: #26262b; border-top: 1px solid #3f3f46; }
.card.denied .denied-block .meta { color: #a1a1aa; }
.card.denied .auth-title { color: #d4d4d8; }
.deny-line { font-size: 12px; color: #fca5a5; line-height: 1.7; }
.deny-line::before { content: "✗  "; color: #f87171; font-weight: 700; }
.card.denied .note { color: #a1a1aa; }
.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); }

.sparkline { width: 100%; height: auto; display: block; }
.unit-chart { position: relative; padding-top: 16px; }
.spark-val {
  position: absolute; top: 0;
  font-size: 11.5px; font-weight: 650; font-variant-numeric: tabular-nums;
}
.spark-first { left: 2px; color: var(--muted); font-weight: 500; }
.spark-last { right: 2px; }
.spark-axis {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums;
  margin: 2px 0 2px;
}
.unit-drift { font-size: 11.5px; font-weight: 700; }
.unit-row { padding: 10px 0; border-top: 1px solid var(--line); }
.unit-row:first-of-type { border-top: none; padding-top: 2px; }
.unit-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.unit-canary .unit-head b { color: var(--over); }

.compare-bars { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 8px; }
.cb-row { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center; }
.cb-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
.cb-track { height: 14px; background: #f1f1f0; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.cb-fill { height: 100%; }
.cb-before { background: var(--line-strong); }
.cb-after { background: var(--accent); }
.cb-val { font-size: 12.5px; font-variant-numeric: tabular-nums; }

.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); }
.round-btn {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); transition: border-color 120ms ease, color 120ms ease;
}
.round-btn .i { width: 18px; height: 18px; }
.round-btn:hover { border-color: var(--accent); color: var(--accent); }
.round-btn.listening {
  border-color: var(--over); color: var(--over);
  animation: mic-pulse 1.6s ease-out infinite;
  transform: scale(calc(1 + var(--level, 0.2) * 0.18));
}
@keyframes mic-pulse {
  0% { box-shadow: 0 0 0 0 rgba(165, 39, 31, 0.35); }
  100% { box-shadow: 0 0 0 12px rgba(165, 39, 31, 0); }
}
input.mic-error { border-color: var(--over); }
input.mic-error::placeholder { color: var(--over); }
input.listening-input { border-color: var(--accent); }
input.listening-input::placeholder { color: var(--accent); }
.round-btn.speaking-ready .i-on { display: block; }
.round-btn.speaking-ready .i-off { display: none; }
.round-btn:not(.speaking-ready) .i-on { display: none; }
.round-btn:not(.speaking-ready) .i-off { display: block; }
.send-btn {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  border: none; background: var(--accent); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: filter 120ms ease;
}
.send-btn:hover { filter: brightness(1.08); }
.send-btn .i { width: 17px; height: 17px; } 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-head-row { display: flex; justify-content: space-between; align-items: center; }
.count-pill {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--line-strong); background: var(--panel);
  color: var(--text); font-size: 13px; font-weight: 700;
  font-variant-numeric: tabular-nums; cursor: pointer; flex: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.count-pill:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* --- audit trail modal --------------------------------------------------- */
.audit-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 18, 24, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.audit-overlay[hidden] { display: none; }
.audit-modal {
  width: min(760px, 100%); max-height: 84vh;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 24px 60px rgba(16, 24, 40, 0.25);
  display: flex; flex-direction: column; overflow: hidden;
}
.audit-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 16px 20px 12px; border-bottom: 1px solid var(--line);
}
.audit-head h2 { font-size: 16px; }
.chain-line { color: var(--muted); font-size: 12px; margin-top: 3px; }
.chain-ok { color: var(--ok); font-weight: 600; }
.chain-bad { color: var(--over); font-weight: 600; }
.audit-filters {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
}
.audit-chip {
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 4px 12px; font-size: 12px; cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease;
}
.audit-chip.active, .audit-chip:hover { color: var(--text); border-color: var(--line-strong); }
.audit-list { overflow-y: auto; padding: 8px 20px 16px; }
.audit-entry { padding: 10px 0; border-top: 1px solid var(--line); }
.audit-entry:first-child { border-top: none; }
.audit-meta { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 3px; }
.audit-ts { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.audit-subject { font-size: 13px; }
.audit-reason { color: var(--muted); font-size: 12.5px; line-height: 1.55; margin-top: 2px; }
.audit-hash { color: var(--line-strong); font-size: 10.5px; margin-top: 4px; }

.legend { padding: 4px 0 8px; border-bottom: 1px solid var(--line); }
.legend-row { display: flex; gap: 12px; align-items: flex-start; padding: 7px 0; }
.legend-row .badge { flex: none; margin: 0; min-width: 74px; text-align: center; }
.legend-row p { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.legend-row p b { color: var(--text); }

.audit-promise {
  padding: 10px 20px; border-top: 1px solid var(--line);
  background: #f8fafc; color: var(--muted); font-size: 12px;
}
.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); }
}
