/* BlurredBox AGD — components */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 5px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-base);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 2px 8px; font-size: var(--fs-sm); }

/* Segmented control (range picker, filters) */
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.seg button {
  border: none; background: transparent; color: var(--text-dim);
  font: inherit; font-size: var(--fs-sm); padding: 4px 10px; cursor: pointer;
  border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: none; }
.seg button:hover { color: var(--text); background: var(--surface-2); }
.seg button[aria-pressed="true"] { background: var(--accent-dim); color: var(--accent-hi); font-weight: 600; }
.seg button:focus-visible { outline: none; box-shadow: inset var(--focus-ring); }

/* ---------- Inputs ---------- */
.input, select.input, textarea.input {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-base);
  padding: 5px 9px;
}
.input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.input.mono { font-family: var(--font-mono); }
.input[readonly], .input:disabled { color: var(--text-dim); background: var(--surface-2); }
label.field { display: flex; flex-direction: column; gap: var(--sp-1); font-size: var(--fs-sm); color: var(--text-dim); }
.field-err { color: var(--danger); font-size: var(--fs-sm); }
.input.invalid { border-color: var(--danger); }

/* Toggle switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; font-size: var(--fs-base); }
.switch input { position: absolute; opacity: 0; }
.switch .track {
  width: 30px; height: 17px; border-radius: 9px; flex: none;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  transition: background 0.15s;
}
.switch .track::after {
  content: ""; position: absolute; width: 11px; height: 11px; border-radius: 50%;
  background: var(--text-dim); top: 50%; transform: translateY(-50%); left: 3px;
  transition: left 0.15s, background 0.15s;
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { left: 16px; background: #fff; }
.switch input:focus-visible + .track { box-shadow: var(--focus-ring); }
.switch input:disabled + .track { opacity: 0.45; }

/* ---------- Cards / panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
}
.panel-title {
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 0 0 var(--sp-4);
  display: flex; align-items: center; gap: var(--sp-3);
}
.panel-title .right { margin-left: auto; text-transform: none; letter-spacing: 0; }

/* KPI tile */
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
}
.kpi .kpi-label { font-size: var(--fs-sm); color: var(--text-dim); margin-bottom: var(--sp-2); }
.kpi .kpi-value { font-size: var(--fs-kpi); font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1.1; }
.kpi .kpi-value .unit { font-size: var(--fs-md); color: var(--text-dim); font-weight: 500; margin-left: 2px; }
.kpi .kpi-sub { font-size: var(--fs-xs); color: var(--text-faint); margin-top: var(--sp-1); }
.kpi .kpi-value.null { color: var(--text-faint); font-size: var(--fs-lg); }

/* Model card */
.model-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4) var(--sp-5);
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: var(--sp-4);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  position: relative;
}
.model-card:hover { border-color: var(--border-strong); background: var(--surface-2); }
.model-card:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.model-card.crit {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger), 0 0 18px rgba(229, 72, 77, 0.25);
}
.model-card.crit::before {
  content: ""; position: absolute; inset: 0; border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(229,72,77,0.07), transparent 45%);
  pointer-events: none;
}
.model-card .mc-name { font-weight: 600; font-size: var(--fs-md); display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.model-card .mc-name .slug { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-card .mc-meta { display: flex; align-items: center; gap: var(--sp-3); margin-top: 3px; flex-wrap: wrap; }
.model-card .mc-last { margin-top: var(--sp-3); font-size: var(--fs-sm); color: var(--text-dim); display: flex; gap: var(--sp-2); align-items: center; min-width: 0; }
.model-card .mc-last .reason { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); font-size: var(--fs-xs); }

/* ---------- Chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px; border-radius: 999px;
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.03em;
  border: 1px solid; white-space: nowrap;
  font-family: var(--font-mono);
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

/* status chips */
.chip.st-HEALTHY            { color: var(--s-healthy);   border-color: var(--s-healthy);   background: var(--ok-dim); }
.chip.st-DEGRADING          { color: var(--s-degrading); border-color: var(--s-degrading); background: var(--warn-dim); }
.chip.st-AUTO_KILL_IMMINENT { color: var(--s-imminent);  border-color: var(--s-imminent);  background: rgba(224, 118, 58, 0.13); }
.chip.st-HARD_BLOCKED       { color: var(--s-blocked);   border-color: var(--s-blocked);   background: var(--danger-dim); }

/* outcome chips — text always present, color never sole signal */
.chip.oc { border-color: color-mix(in srgb, var(--oc) 55%, transparent); color: var(--oc-fg); background: color-mix(in srgb, var(--oc) 14%, transparent); }
.chip.oc .dot { background: var(--oc); }
.oc-allow      { --oc: var(--o-allow);      --oc-fg: var(--o-allow-fg); }
.oc-alert      { --oc: var(--o-alert);      --oc-fg: var(--o-alert-fg); }
.oc-throttle   { --oc: var(--o-throttle);   --oc-fg: var(--o-throttle-fg); }
.oc-restart    { --oc: var(--o-restart);    --oc-fg: var(--o-restart-fg); }
.oc-restrict   { --oc: var(--o-restrict);   --oc-fg: var(--o-restrict-fg); }
.oc-rollback   { --oc: var(--o-rollback);   --oc-fg: var(--o-rollback-fg); }
.oc-hard_block { --oc: var(--o-hard-block); --oc-fg: var(--o-hard-block-fg); font-weight: 700; }
.oc-start_new  { --oc: var(--o-start-new);  --oc-fg: var(--o-start-new-fg); }
.oc-kill_old   { --oc: var(--o-kill-old);   --oc-fg: var(--o-kill-old-fg); }

/* misc chips */
.chip.neutral { color: var(--text-dim); border-color: var(--border-strong); background: var(--surface-2); }
.chip.tier { color: var(--accent-hi); border-color: var(--accent); background: var(--accent-dim); }
.chip.readonly { color: var(--warn); border-color: var(--warn); background: var(--warn-dim); }

/* Heartbeat dot */
.hb { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.hb.live { background: var(--ok); box-shadow: 0 0 6px rgba(42, 194, 142, 0.7); }
.hb.silent { background: transparent; border: 1.5px solid var(--danger); position: relative; }
.hb.silent::after { content: ""; position: absolute; left: -3px; right: -3px; top: 50%; height: 1.5px; background: var(--danger); transform: rotate(-40deg); }

/* WS state */
.ws-state { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-dim); font-family: var(--font-mono); }
.ws-state .hb.connecting { background: var(--warn); animation: pulse 1s infinite; box-shadow: none; }
.ws-state .hb.off { background: var(--text-faint); box-shadow: none; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- Tables ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.tbl th {
  text-align: left; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-faint); font-weight: 600; padding: 6px var(--sp-3);
  border-bottom: 1px solid var(--border-strong); position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.tbl td { padding: 0 var(--sp-3); height: var(--row-h); border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr.row { cursor: pointer; }
.tbl tr.row:hover td { background: var(--surface-2); }
.tbl tr.row:focus-visible { outline: none; }
.tbl tr.row:focus-visible td { background: var(--accent-dim); box-shadow: inset 2px 0 0 var(--accent); }
.tbl tr.expand-row td { height: auto; padding: var(--sp-4); background: var(--bg); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }

.mono { font-family: var(--font-mono); font-size: var(--fs-sm); }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.nums { font-variant-numeric: tabular-nums; }

time[title] { text-decoration: underline dotted var(--text-faint); text-underline-offset: 2px; cursor: help; }

/* Copyable id */
.copy-id { display: inline-flex; align-items: center; gap: 4px; font-family: var(--font-mono); font-size: var(--fs-sm); }
.copy-id button {
  border: none; background: none; color: var(--text-faint); cursor: pointer; padding: 2px;
  display: inline-flex; border-radius: 3px;
}
.copy-id button:hover { color: var(--accent-hi); background: var(--surface-3); }
.copy-id button:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.copy-id button.copied { color: var(--ok); }

/* ---------- Detail (expanded decision) ---------- */
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 4px var(--sp-4); font-size: var(--fs-sm); }
.kv dt { color: var(--text-faint); }
.kv dd { margin: 0; font-family: var(--font-mono); word-break: break-all; }

/* ---------- Gauges ---------- */
.gauge-wrap { display: flex; flex-direction: column; align-items: center; gap: var(--sp-1); }
.gauge-label { font-size: var(--fs-xs); color: var(--text-faint); }

/* ---------- Charts ---------- */
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--sp-4); }
.chart-card h3 { margin: 0 0 var(--sp-2); font-size: var(--fs-sm); font-weight: 600; color: var(--text-dim); display: flex; gap: var(--sp-2); align-items: baseline; }
.chart-card h3 .cur { margin-left: auto; font-family: var(--font-mono); color: var(--text); font-variant-numeric: tabular-nums; }
.chart-card canvas { width: 100%; display: block; }
.chart-legend { display: flex; gap: var(--sp-4); font-size: var(--fs-xs); color: var(--text-faint); margin-top: var(--sp-2); flex-wrap: wrap; }
.chart-legend .li { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend .sw { width: 14px; height: 3px; border-radius: 2px; }
.chart-legend .sw.dashed { background: repeating-linear-gradient(90deg, currentColor 0 3px, transparent 3px 6px); height: 2px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-5); }
.tabs button {
  border: none; background: none; color: var(--text-dim); font: inherit; font-size: var(--fs-base);
  padding: var(--sp-3) var(--sp-4); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--accent-hi); border-bottom-color: var(--accent); font-weight: 600; }
.tabs button:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
.tabs button .lock { opacity: 0.7; margin-left: 4px; }

/* ---------- Skeletons ---------- */
.skel { border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; color: transparent !important; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } .hb.connecting { animation: none; } }

/* ---------- Empty / locked states ---------- */
.empty {
  text-align: center; padding: var(--sp-7) var(--sp-6); color: var(--text-dim);
  border: 1px dashed var(--border-strong); border-radius: var(--radius-lg);
}
.empty h3 { color: var(--text); font-size: var(--fs-lg); margin: 0 0 var(--sp-2); }
.empty pre {
  text-align: left; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--sp-4); font-family: var(--font-mono); font-size: var(--fs-sm); overflow-x: auto;
  max-width: 560px; margin: var(--sp-4) auto 0; position: relative;
}

.locked-panel { position: relative; overflow: hidden; border-radius: var(--radius-lg); }
.locked-panel .blurred { filter: blur(7px) saturate(0.8); opacity: 0.55; pointer-events: none; user-select: none; }
.locked-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-3); text-align: center; padding: var(--sp-6); z-index: 3;
}
.locked-overlay .lock-glyph { font-size: 26px; }
.locked-overlay h3 { margin: 0; font-size: var(--fs-lg); }
.locked-overlay p { margin: 0; color: var(--text-dim); max-width: 420px; }

/* stale badge */
.stale-badge { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--warn); border: 1px solid var(--warn); border-radius: 999px; padding: 0 7px; background: var(--warn-dim); font-family: var(--font-mono); }

/* ---------- Live stream terminal ---------- */
.term {
  background: #070A10;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  height: calc(100vh - 250px);
  min-height: 320px;
  overflow-y: auto;
  padding: var(--sp-3) 0;
}
[data-theme="light"] .term { background: #10151F; color: #C9D4E8; }
.term-line { padding: 1px var(--sp-4); display: flex; gap: var(--sp-3); align-items: baseline; white-space: nowrap; }
.term-line .t { color: var(--text-faint); flex: none; }
.term-line .tag { flex: none; width: 92px; font-weight: 700; }
.term-line .msg { overflow: hidden; text-overflow: ellipsis; color: var(--text-dim); }
.term-card {
  margin: var(--sp-2) var(--sp-4); padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius); border: 1px solid; display: flex; flex-direction: column; gap: 3px;
}
.term-card .row1 { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.term-paused { position: sticky; bottom: 0; text-align: center; font-size: var(--fs-xs); color: var(--warn); background: var(--warn-dim); padding: 2px; }

/* ---------- Policy studio ---------- */
.editor-wrap {
  display: grid; grid-template-columns: 48px 1fr; background: var(--bg);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  font-family: var(--font-mono); font-size: var(--fs-base); line-height: 20px;
  max-height: 60vh; overflow: auto; position: relative;
}
.editor-gutter { text-align: right; padding: var(--sp-3) 8px; color: var(--text-faint); user-select: none; white-space: pre; font-variant-numeric: tabular-nums; border-right: 1px solid var(--border); position: sticky; left: 0; background: var(--bg); }
.editor-gutter .ln.err { color: var(--danger); font-weight: 700; }
.editor-ta {
  border: none; background: transparent; color: var(--text); resize: none; outline: none;
  font: inherit; line-height: inherit; padding: var(--sp-3) var(--sp-4); min-height: 300px; white-space: pre; overflow: hidden;
}
.lint-msg { display: flex; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); border-radius: var(--radius); font-family: var(--font-mono); font-size: var(--fs-sm); align-items: baseline; }
.lint-msg.err { background: var(--danger-dim); color: var(--danger); }
.lint-msg.ok { background: var(--ok-dim); color: var(--ok); }
.lint-msg.warn { background: var(--warn-dim); color: var(--warn); }
.lint-msg .ln-ref { flex: none; font-weight: 700; }
.lint-msg code { color: var(--text-dim); }

.ref-panel h4 { font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); margin: var(--sp-4) 0 var(--sp-2); }
.ref-panel code, .kbd { font-family: var(--font-mono); font-size: var(--fs-sm); background: var(--surface-2); border: 1px solid var(--border); border-radius: 3px; padding: 0 4px; }
.ref-panel pre { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-3); font-size: var(--fs-sm); overflow-x: auto; }

/* ---------- Progress ---------- */
.progress { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 3px; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(4, 6, 10, 0.6); display: grid; place-items: center; z-index: 100; }
.modal { background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); width: 440px; max-width: 92vw; padding: var(--sp-5); }
.modal h3 { margin: 0 0 var(--sp-3); font-size: var(--fs-lg); }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-3); margin-top: var(--sp-5); }
.diff-row { display: flex; gap: var(--sp-3); align-items: center; font-family: var(--font-mono); font-size: var(--fs-sm); padding: 3px 0; }
.diff-row .old { color: var(--danger); text-decoration: line-through; }
.diff-row .new { color: var(--ok); font-weight: 700; }

/* ---------- Toast ---------- */
.toast-host { position: fixed; bottom: var(--sp-5); right: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); z-index: 200; }
.toast { background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: var(--sp-3) var(--sp-4); font-size: var(--fs-sm); box-shadow: var(--shadow); }
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--danger); }

/* ---------- Feature matrix ---------- */
.matrix td, .matrix th { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }
.matrix .yes { color: var(--ok); font-weight: 700; }
.matrix .no { color: var(--text-faint); }
.matrix th.cur-tier { color: var(--accent-hi); }
.matrix td.cur-tier { background: var(--accent-dim); }

/* virtual list spacer rows */
.vspacer td { border: none; padding: 0; }

/* utility */
.row-flex { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.mt { margin-top: var(--sp-5); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Demo build banner ---------- */
.demo-banner {
  height: 24px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--text-dim); background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  user-select: none;
}
.demo-banner .sep { width: 3px; height: 3px; border-radius: 50%; background: var(--text-faint); }
body.demo #app { height: calc(100vh - 24px); }
body.demo .login-wrap { height: calc(100vh - 24px); }
