/* Spendfuse console - dark theme, system fonts only. */
:root {
  --bg: #0b0e14;
  --panel: #121722;
  --panel-2: #171d2b;
  --line: #232b3d;
  --text: #e3e8f2;
  --muted: #8a94a8;
  --accent: #6ea8ff;
  --good: #3ddc84;
  --good-bg: rgba(61, 220, 132, 0.12);
  --warn: #ffb547;
  --warn-bg: rgba(255, 181, 71, 0.12);
  --bad: #ff5c6c;
  --bad-bg: rgba(255, 92, 108, 0.13);
  --trip: #ff4fd8;
  --trip-bg: rgba(255, 79, 216, 0.16);
  --info: #8fb3ff;
  --info-bg: rgba(143, 179, 255, 0.1);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}
body.busy { cursor: progress; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; margin: 0; color: var(--muted); font-weight: 600; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.invalid { color: var(--bad); }
[hidden] { display: none !important; }

/* ---------- header */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px;
  padding: 14px 24px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #10141d, var(--bg));
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: conic-gradient(from 210deg, var(--bad), var(--warn), var(--good), var(--accent), var(--bad));
  box-shadow: 0 0 0 2px #0b0e14 inset, 0 0 18px rgba(255, 92, 108, 0.35);
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: 0.02em; }
.brand-sub { color: var(--muted); font-size: 11.5px; }
.vault { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.vault a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-group { display: flex; align-items: center; gap: 8px; }

.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11.5px;
  font-weight: 700; letter-spacing: 0.06em; border: 1px solid transparent; white-space: nowrap;
}
.pill-active { color: var(--good); background: var(--good-bg); border-color: rgba(61, 220, 132, 0.35); }
.pill-paused { color: var(--warn); background: var(--warn-bg); border-color: rgba(255, 181, 71, 0.4); }
.pill-frozen { color: #fff; background: var(--bad); border-color: var(--bad); }
.pill-unknown { color: var(--muted); background: var(--panel-2); border-color: var(--line); }
#vault-pill { font-size: 13px; padding: 4px 14px; }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 11.5px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.tag-armed { color: var(--warn); border-color: rgba(255, 181, 71, 0.45); }
.tag-bad { color: var(--bad); border-color: rgba(255, 92, 108, 0.45); }
.tag-warn { color: var(--warn); border-color: rgba(255, 181, 71, 0.45); }

.live { font-size: 12px; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.live::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live-on { color: var(--good); }
.live-on::before { background: var(--good); box-shadow: 0 0 8px var(--good); animation: pulse 2s infinite; }
.live-warn { color: var(--warn); }
.live-warn::before { background: var(--warn); }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- banner + tabs */
.banner {
  margin: 12px 24px 0; padding: 10px 14px; border-radius: var(--radius); display: flex; gap: 12px;
  align-items: center; border: 1px solid var(--line); background: var(--panel);
}
.banner span { flex: 1; overflow-wrap: anywhere; }
.banner-ok { border-color: rgba(61, 220, 132, 0.4); background: var(--good-bg); }
.banner-err { border-color: rgba(255, 92, 108, 0.45); background: var(--bad-bg); }
.banner-warn { border-color: rgba(255, 181, 71, 0.4); background: var(--warn-bg); }
.tabs { display: flex; gap: 4px; padding: 12px 24px 0; border-bottom: 1px solid var(--line); }
.tab {
  background: none; border: none; color: var(--muted); padding: 8px 14px; font: inherit; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text); }

main { padding: 16px 24px 32px; max-width: 1500px; margin: 0 auto; }

/* ---------- stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; }
.stat.good .stat-value { color: var(--good); }
.stat.warn .stat-value { color: var(--warn); }
.stat.bad .stat-value { color: var(--bad); }
.stat.trip .stat-value { color: var(--trip); }
.vault-actions { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }

/* ---------- cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.count { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 9px; font-size: 12px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid2 > .card { margin-bottom: 14px; }
.empty { color: var(--muted); padding: 14px 4px; list-style: none; }

/* ---------- buttons */
.btn {
  font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn.small { font-size: 12px; padding: 3px 10px; }
.btn-ok { color: var(--good); border-color: rgba(61, 220, 132, 0.45); }
.btn-ok:hover { background: var(--good-bg); border-color: var(--good); }
.btn-danger { color: var(--bad); border-color: rgba(255, 92, 108, 0.45); }
.btn-danger:hover { background: var(--bad-bg); border-color: var(--bad); }
.btn-ghost { background: transparent; }
body.busy .btn { opacity: 0.5; pointer-events: none; }

/* ---------- agents table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }
.row-frozen { background: rgba(255, 92, 108, 0.05); }
.row-frozen td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.reason { color: var(--bad); margin-top: 4px; max-width: 260px; overflow-wrap: anywhere; }
.spend { min-width: 190px; }
.bar { height: 6px; background: var(--panel-2); border-radius: 4px; overflow: hidden; margin-top: 5px; border: 1px solid var(--line); }
.bar-fill { display: block; height: 100%; width: 0; background: var(--good); transition: width 0.4s; }
.bar-warm .bar-fill { background: var(--warn); }
.bar-hot .bar-fill { background: var(--bad); }
.counters { display: flex; flex-wrap: wrap; gap: 4px 8px; }
.c-good { color: var(--good); }
.c-warn { color: var(--warn); }
.c-bad { color: var(--bad); }
.c-trip { color: var(--trip); font-weight: 700; }
.row-actions { text-align: right; white-space: nowrap; }

/* ---------- lists */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.item-main { flex: 1; min-width: 0; overflow-wrap: anywhere; display: flex; flex-direction: column; gap: 3px; }
.item-actions { display: flex; flex-direction: column; gap: 6px; }
.item.pending { border-left: 3px solid var(--warn); }
.amount { font-variant-numeric: tabular-nums; }
.arrow { color: var(--muted); }
.reason-chip { display: inline-block; font-family: var(--mono); font-size: 11px; padding: 0 6px; margin: 2px 4px 0 0; border-radius: 4px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); color: var(--muted); }
.memo { background: rgba(255, 181, 71, 0.06); border: 1px dashed rgba(255, 181, 71, 0.35); padding: 4px 8px; border-radius: 6px; white-space: pre-wrap; }
.note { color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- feed */
.legend { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.feed { list-style: none; margin: 0; padding: 0; max-height: 520px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.feed-item { padding: 8px 10px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); border-left-width: 3px; overflow-wrap: anywhere; }
.feed-line { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: baseline; }
.feed-item.fresh { animation: flash 2.4s ease-out; }
@keyframes flash { from { background: rgba(110, 168, 255, 0.22); } }
.ev { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 1px 7px; border-radius: 4px; }
.ev-paid { color: var(--good); background: var(--good-bg); }
.ev-escalated { color: var(--warn); background: var(--warn-bg); }
.ev-blocked { color: var(--bad); background: var(--bad-bg); }
.ev-frozen { color: #fff; background: var(--bad); font-weight: 800; }
.ev-tripped { color: #fff; background: var(--trip); font-weight: 800; box-shadow: 0 0 10px rgba(255, 79, 216, 0.6); }
.ev-info { color: var(--info); background: var(--info-bg); }
.ev-muted { color: var(--muted); background: rgba(255, 255, 255, 0.05); }
.ev-paid-row { border-left-color: var(--good); }
.ev-escalated-row { border-left-color: var(--warn); }
.ev-blocked-row { border-left-color: var(--bad); }
.ev-frozen-row { border-left-color: var(--bad); background: rgba(255, 92, 108, 0.08); }
.ev-frozen-row .feed-line { font-weight: 700; }
.ev-tripped-row { border-left-color: var(--trip); background: var(--trip-bg); box-shadow: 0 0 0 1px rgba(255, 79, 216, 0.35); }
.ev-info-row { border-left-color: var(--info); }
.ev-muted-row { border-left-color: var(--line); }
#feed-more { margin-top: 8px; width: 100%; }

/* ---------- proof */
.proof { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; background: var(--panel-2); }
.proof-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.keys { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.key { border-top: 1px solid var(--line); padding-top: 6px; overflow-wrap: anywhere; }
.key-full { background: var(--bad-bg); border-radius: 6px; padding: 6px; }
.key-pk { color: var(--muted); }
.method { font-size: 11.5px; background: rgba(110, 168, 255, 0.1); color: var(--info); padding: 0 6px; border-radius: 4px; margin: 2px 4px 0 0; display: inline-block; }

/* ---------- key/value */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; min-width: 0; }
.pre { white-space: pre-wrap; margin: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; max-height: 260px; overflow: auto; }

/* ---------- runs */
.runs { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: 14px; align-items: start; }
.run-item { padding: 0; }
.run-item.active { border-color: var(--accent); }
.run-btn { all: unset; display: block; width: 100%; padding: 10px 12px; cursor: pointer; overflow-wrap: anywhere; box-sizing: border-box; }
.run-btn:focus-visible { outline: 2px solid var(--accent); border-radius: 8px; }
#run-meta { margin-bottom: 14px; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.tl-item { position: relative; padding: 8px 12px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); border-left-width: 3px; }
.tl-dot { position: absolute; left: -23px; top: 13px; width: 12px; height: 12px; border-radius: 50%; background: var(--panel); border: 2px solid var(--muted); }
.ev-paid-row .tl-dot { border-color: var(--good); }
.ev-escalated-row .tl-dot { border-color: var(--warn); }
.ev-blocked-row .tl-dot, .ev-frozen-row .tl-dot { border-color: var(--bad); background: var(--bad); }
.ev-tripped-row .tl-dot { border-color: var(--trip); background: var(--trip); }
.tl-head { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin-bottom: 4px; }
.tl-title { overflow-wrap: anywhere; }
.tl-body .kv { margin-top: 6px; }

/* ---------- footer */
.foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 12px 24px 24px; border-top: 1px solid var(--line); }

/* ---------- responsive */
@media (max-width: 980px) {
  .grid2, .runs { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .topbar, main, .tabs, .foot { padding-left: 16px; padding-right: 16px; }
  .banner { margin-left: 16px; margin-right: 16px; }
  .vault { flex-basis: 100%; order: 3; }
  .stat-value { font-size: 17px; }
  .item { flex-direction: column; }
  .item-actions { flex-direction: row; }
}
