:root {
  --bg: #0b0e13;
  --panel: #12161d;
  --panel-2: #181d26;
  --line: #222935;
  --line-2: #2d3644;
  --txt: #e6eaf0;
  --txt-2: #9aa5b5;
  --txt-3: #657084;
  --req: #6d9bff;
  --raw: #8b96a8;
  --bad: #ff6b61;
  --json: #b79cff;
  --buy: #3ddc97;
  --safe: #3ddc97;
  --warn: #f4b740;
  --safe-bg: rgba(61,220,151,.12);
  --bad-bg: rgba(255,107,97,.12);
  --warn-bg: rgba(244,183,64,.12);
  --mark: rgba(255,107,97,.32);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--txt); font-family: var(--sans); font-size: 13px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; display: flex; flex-direction: column; min-height: 100vh;
}
.hidden { display: none !important; }
.muted { color: var(--txt-3); font-size: 12px; }
button, select { font: inherit; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.logo { width: 16px; height: 16px; border-radius: 4px; border: 2px solid var(--txt); flex: none; }
.brand-title { font-weight: 650; font-size: 14px; white-space: nowrap; }
.brand-sep { color: var(--txt-3); }
.brand-sub { color: var(--txt-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: flex; gap: 4px; }
.btn {
  color: var(--txt); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 7px;
  padding: 5px 10px; cursor: pointer; font-size: 12.5px;
}
.btn:hover { border-color: var(--txt-3); }
.btn.icon { width: 32px; padding: 5px 0; text-align: center; font-size: 10px; }
.ctrl, .toggle { display: flex; align-items: center; gap: 6px; color: var(--txt-2); font-size: 12.5px; cursor: pointer; }
.toggle input { accent-color: var(--req); }
.badge { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--panel-2); color: var(--txt-2); text-decoration: none; }
.badge.real { background: var(--safe-bg); color: var(--safe); }

/* ---------- KPI strip ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; padding: 12px 16px 0; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; min-width: 0; }
.kpi-cap { font-size: 11.5px; color: var(--txt-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-num { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.3px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { font-size: 11.5px; color: var(--txt-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.good .kpi-num { color: var(--safe); }
.kpi.bad .kpi-num { color: var(--bad); }

/* ---------- console layout ---------- */
.console { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 10px; padding: 10px 16px 16px; min-height: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-title { font-weight: 650; font-size: 12.5px; }
.phase { font-family: var(--mono); font-size: 11.5px; color: var(--req); background: rgba(109,155,255,.1); padding: 2px 8px; border-radius: 999px; }
.legend { margin-left: auto; display: flex; gap: 12px; flex-wrap: wrap; color: var(--txt-3); font-size: 11.5px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.lg { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.lg.req { background: var(--req); } .lg.raw { background: var(--raw); } .lg.bad { background: var(--bad); }
.lg.json { background: var(--json); } .lg.buy { background: var(--buy); }

.side { display: grid; grid-template-rows: minmax(220px, 1fr) minmax(260px, 1.25fr); gap: 10px; min-height: 0; max-height: calc(100vh - 150px); }

/* ---------- canvas ---------- */
.canvas-wrap { overflow: auto; flex: 1; }
.canvas {
  position: relative; min-width: 820px; padding: 34px 16px 18px;
  display: grid; grid-template-columns: 170px 70px 190px 70px minmax(0, 1fr);
  align-items: center;
}
.col-label { position: absolute; top: 10px; font-size: 11px; font-weight: 600; color: var(--txt-3); text-transform: uppercase; letter-spacing: .5px; }
.col-label small { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 4px; }
.col-label.c1 { left: 16px; }
.col-label.c2 { left: 256px; }
.col-label.c3 { left: 532px; }
.edges { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; overflow: visible; }

.node {
  position: relative; z-index: 2; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 10px 12px; cursor: pointer; transition: border-color .2s, box-shadow .2s;
}
.node:hover { border-color: var(--txt-3); }
.node.pulse { box-shadow: 0 0 0 3px rgba(109,155,255,.25); border-color: var(--req); }
.node-kicker { font-size: 10.5px; color: var(--txt-3); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.node-title { font-weight: 650; font-size: 14px; margin: 1px 0 4px; }
.node-line { font-size: 12px; color: var(--txt-2); }
.node-state { margin-top: 8px; font-family: var(--mono); font-size: 11px; color: var(--txt-3); }
.node-state.on { color: var(--req); }
.node-state.done { color: var(--safe); }

.buyer { grid-column: 1; grid-row: 1; }
.buyer .q { font-size: 12px; color: var(--txt); margin: 6px 0; line-height: 1.4; }
.concierge { grid-column: 3; grid-row: 1; }
.concierge .meter { height: 4px; background: var(--line); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.concierge .meter i { display: block; height: 100%; width: 0; background: var(--json); transition: width .3s; }
.decision { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; }
.decision b { color: var(--safe); }

.lanes { grid-column: 5; grid-row: 1; display: flex; flex-direction: column; gap: 6px; }
.lane {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 54px minmax(0, 1fr); align-items: center;
  border: 1px dashed var(--line-2); border-radius: 12px; padding: 14px 8px 6px; transition: border-color .3s, background .3s;
}
.lane-tag { position: absolute; top: 1px; left: 10px; font-family: var(--mono); font-size: 10px; color: var(--txt-3); }
.lane.contained { border-color: rgba(255,107,97,.45); background: rgba(255,107,97,.035); }
.lane.chosen { border-color: rgba(61,220,151,.6); border-style: solid; background: rgba(61,220,151,.04); }
.lane .node { padding: 5px 10px 6px; }
.lane .node-title { font-size: 13px; margin: 0; display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.lane .node-line { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scout .checks { display: flex; gap: 3px; margin-top: 5px; }
.ck { flex: 1; height: 4px; border-radius: 2px; background: var(--line-2); transition: background .3s; }
.ck.pass { background: var(--safe); }
.ck.hit { background: var(--bad); }
.ck.warn { background: var(--warn); }
.contain-note { font-size: 11px; color: var(--bad); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.truth { display: none; font-size: 10.5px; font-weight: 600; margin-top: 3px; }
.show-truth .truth { display: block; }
.truth.dirty { color: var(--bad); }
.truth.clean { color: var(--safe); }

.pill { font-size: 10.5px; font-weight: 650; padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.pill.allow { background: var(--safe-bg); color: var(--safe); }
.pill.block { background: var(--bad-bg); color: var(--bad); }
.pill.review { background: var(--warn-bg); color: var(--warn); }
.pill.pending { background: var(--line); color: var(--txt-3); }

/* edges + packets */
.edge { fill: none; stroke: var(--line-2); stroke-width: 1.4; transition: stroke .3s, opacity .3s; }
.edge.req { stroke: var(--req); opacity: .55; }
.edge.bad { stroke: var(--bad); opacity: .7; }
.edge.json { stroke: var(--json); opacity: .55; }
.edge.buy { stroke: var(--buy); stroke-width: 2.2; stroke-dasharray: 6 5; animation: dash 1s linear infinite; }
.edge.dim { opacity: .25; }
.edge.off { opacity: 0; }
@keyframes dash { to { stroke-dashoffset: -22; } }
.packet { filter: drop-shadow(0 0 4px currentColor); }

/* ---------- log ---------- */
.log { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1; font-size: 12px; }
.log li {
  display: grid; grid-template-columns: 46px 10px minmax(0, 1fr); gap: 8px; align-items: baseline;
  padding: 5px 12px; cursor: pointer; border-left: 2px solid transparent;
}
.log li:hover { background: var(--panel-2); }
.log li.sel { background: var(--panel-2); border-left-color: var(--req); }
.log .t { font-family: var(--mono); font-size: 11px; color: var(--txt-3); }
.log .k { width: 8px; height: 8px; border-radius: 50%; align-self: center; }
.log .m { min-width: 0; }
.log .route { color: var(--txt-2); }
.log .what { color: var(--txt); }
.log .flag { color: var(--bad); font-weight: 600; }

/* ---------- inspector ---------- */
.inspector { overflow-y: auto; padding: 12px; flex: 1; }
.ins-route { font-size: 13px; font-weight: 650; }
.ins-kind { font-size: 12px; color: var(--txt-2); margin: 2px 0 10px; }
.boundary { border-radius: 8px; padding: 8px 10px; font-size: 12px; margin-bottom: 10px; }
.boundary.held { background: var(--bad-bg); color: var(--bad); }
.boundary.ok { background: rgba(183,156,255,.1); color: var(--json); }
.boundary.info { background: rgba(109,155,255,.1); color: var(--req); }
.boundary.buy { background: var(--safe-bg); color: var(--safe); }
.f-label { font-size: 11px; color: var(--txt-3); margin: 10px 0 4px; text-transform: uppercase; letter-spacing: .4px; }
.code {
  font-family: var(--mono); font-size: 11.5px; background: #0a0d12; border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 10px; white-space: pre-wrap; word-break: break-word; color: #c9d2de; line-height: 1.55;
}
mark { background: var(--mark); color: #ffe1de; border-radius: 3px; padding: 0 2px; }
.finding { border-left: 2px solid var(--bad); padding: 2px 0 2px 9px; margin: 8px 0; font-size: 12px; }
.finding .sev { font-size: 10.5px; font-weight: 700; text-transform: uppercase; color: var(--bad); margin-right: 6px; }
.finding .ctl { color: var(--txt-2); margin-top: 2px; }

/* ---------- loading ---------- */
.loading { position: fixed; inset: 0; display: grid; place-items: center; grid-auto-flow: column; gap: 10px; background: rgba(11,14,19,.6); z-index: 80; color: var(--txt-2); }
.spinner { width: 20px; height: 20px; border: 2.5px solid var(--line-2); border-top-color: var(--req); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
  .console { grid-template-columns: 1fr; }
  .side { max-height: none; grid-template-rows: 300px auto; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .topbar, .kpis, .console { padding-left: 12px; padding-right: 12px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .brand-sub, .brand-sep { display: none; }
}
