/* ============================================================================
   AlterEgo Design System — spec/designs/design-system.css
   Normative implementation of designs/design-language.md. Import in every page:
   <link rel="stylesheet" href="design-system.css">
   ========================================================================== */

:root {
  --bg-0: #0B0E12; --bg-1: #10141B; --bg-2: #161B25; --bg-3: #1C2330;
  --line-1: rgba(148,163,184,0.10); --line-2: rgba(148,163,184,0.18);
  --text-1: #E8EDF4; --text-2: #A8B4C4; --text-3: #6B7787;
  --accent: #22D3EE; --accent-soft: rgba(34,211,238,0.14);
  --good: #3DDC97; --warn: #F5C044; --bad: #F2555A;
  --info: #8B9DF9; --violet: #B38CF9;
  --stale: #7A6C5D; --missing: rgba(148,163,184,0.28);
  --sans: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, monospace;
  --r-panel: 12px; --r-ctl: 8px; --r-pill: 999px;
  --gap: 16px; --pad-page: 24px;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0; background: var(--bg-0); color: var(--text-1);
  font: 0.875rem/1.5 var(--sans); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dim { color: var(--text-3); } .dim2 { color: var(--text-2); }
.label {
  font-size: 0.6875rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-3); font-weight: 600;
}
h1, h2, h3 { font-weight: 650; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.125rem; } h3 { font-size: 1rem; }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: 240px minmax(0,1fr); min-height: 100vh; }
.sidenav {
  border-right: 1px solid var(--line-1); background: var(--bg-1);
  padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidenav .mark { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.sidenav .mark svg { flex: none; }
.sidenav .mark b { font-size: 0.95rem; letter-spacing: -0.01em; }
.sidenav .mark span { display: block; font-size: 0.6875rem; color: var(--text-3); }
.nav-group { margin: 14px 0 4px; padding: 0 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-ctl);
  color: var(--text-2); font-size: 0.875rem; border: 1px solid transparent;
}
.nav-item svg { opacity: 0.72; flex: none; }
.nav-item:hover { background: var(--bg-2); color: var(--text-1); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); border-color: rgba(34,211,238,0.25); }
.nav-item .count { margin-left: auto; font-size: 0.6875rem; color: var(--text-3); font-family: var(--mono); }
.nav-item .count.warn { color: var(--warn); } .nav-item .count.bad { color: var(--bad); }

.main { padding: var(--pad-page); max-width: 1680px; width: 100%; margin: 0 auto; min-width: 0; }
.main > * { min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap;
}
.topbar .crumb { color: var(--text-3); font-size: 0.8125rem; }
.topbar .crumb b { color: var(--text-1); font-weight: 600; }
.topbar .spacer { flex: 1; }
.tz-chip, .health-chip, .freshness {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.6875rem;
  font-family: var(--mono); color: var(--text-3);
  border: 1px solid var(--line-1); border-radius: var(--r-pill); padding: 3px 10px;
}
.pulse { width: 6px; height: 6px; border-radius: 50%; background: var(--good); animation: pulse 2s ease-in-out infinite; }
.pulse.warn { background: var(--warn); } .pulse.bad { background: var(--bad); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ---------- state line (v2: the answer, accent-edged) ---------- */
.state-line {
  display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap;
  background: var(--bg-1); border: 1px solid var(--line-1); border-radius: var(--r-panel);
  border-left: 2px solid var(--accent);
  padding: 14px 18px; margin-bottom: var(--gap);
}
.state-line p { margin: 0; font-size: 0.9375rem; color: var(--text-1); max-width: 1100px; }
.state-line .stamp { font-family: var(--mono); font-size: 0.6875rem; color: var(--text-3); white-space: nowrap; }

/* ---------- scorecards (v2: compact uniform strip — wraps, never clips) ---------- */
.scorecards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: var(--gap); }
.scorecard {
  background: var(--bg-1); border: 1px solid var(--line-1); border-radius: var(--r-panel);
  padding: 10px 12px 8px; display: flex; flex-direction: column; gap: 4px; position: relative;
  min-width: 0; max-height: 128px; overflow: hidden;
}
.scorecard:hover { background: var(--bg-2); }
.scorecard .k {
  font-size: 0.625rem; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-3);
  font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.scorecard .v { font-family: var(--mono); font-size: 1.375rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; }
.scorecard .d { font-family: var(--mono); font-size: 0.625rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scorecard .d.up { color: var(--good); } .scorecard .d.down { color: var(--bad); } .scorecard .d.flat { color: var(--text-3); }
.scorecard .go { position: absolute; top: 10px; right: 10px; color: var(--text-3); }
.scorecard:hover .go { color: var(--accent); }
.scorecard .sparkline { height: 26px; }
.sparkline { width: 100%; height: 40px; display: block; margin-top: auto; }

/* ---------- hero tiles (v2 T2: the few numbers that prove the answer) ---------- */
.hero-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--gap); margin-bottom: var(--gap); }
.hero-tile {
  background: var(--bg-1); border: 1px solid var(--line-1); border-radius: var(--r-panel);
  padding: 16px 18px 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; position: relative;
}
.hero-tile:hover { background: var(--bg-2); }
.hero-tile .kh { display: flex; align-items: center; justify-content: space-between; gap: 6px 10px; flex-wrap: wrap; }
.hero-tile .k { font-size: 0.6875rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.hero-tile .verdict { flex: none; }
.hero-tile .v { font-family: var(--mono); font-size: 2rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; }
.hero-tile .v small { font-size: 1rem; color: var(--text-3); letter-spacing: 0; }
.hero-tile .ctx { color: var(--text-2); font-size: 0.75rem; }
.hero-tile .sparkline { height: 30px; }

/* ---------- scope bar (v2: game/instance pivot) ---------- */
.scopebar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin: -4px 0 var(--gap); padding: 8px 10px;
  background: var(--bg-1); border: 1px solid var(--line-1); border-radius: var(--r-panel);
}
.scopebar .scope {
  display: inline-flex; align-items: center; gap: 7px;
  font: 600 0.75rem var(--sans); color: var(--text-2);
  padding: 5px 12px; border-radius: var(--r-pill); border: 1px solid transparent;
  background: transparent; cursor: pointer; white-space: nowrap;
}
.scopebar .scope:hover { color: var(--text-1); background: var(--bg-2); }
.scopebar .scope.on { color: var(--accent); background: var(--accent-soft); border-color: rgba(34,211,238,0.28); }
.scopebar .scope .cnt { font-family: var(--mono); font-size: 0.625rem; color: var(--text-3); }
.scopebar .scope.on .cnt { color: var(--accent); }
.scopebar .scope .dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.scopebar .divider { width: 1px; align-self: stretch; margin: 2px 4px; background: var(--line-2); }
.scopebar .inst-picker {
  margin-left: auto; display: inline-flex; align-items: center; gap: 7px;
  font: 600 0.6875rem var(--mono); color: var(--text-2);
  border: 1px solid var(--line-2); border-radius: var(--r-pill); padding: 5px 12px; background: var(--bg-0); cursor: pointer;
}
.scopebar .inst-picker:hover { color: var(--text-1); border-color: var(--accent); }
.scopebar .inst-picker .caret { color: var(--text-3); }

/* ---------- disclosure blocks (v2 T3) ---------- */
details.disc {
  background: var(--bg-1); border: 1px solid var(--line-1); border-radius: var(--r-panel);
  margin-bottom: var(--gap); overflow: hidden;
}
details.disc > summary {
  list-style: none; display: flex; align-items: center; gap: 12px;
  padding: 13px 18px; cursor: pointer; user-select: none; flex-wrap: wrap;
}
details.disc > summary::-webkit-details-marker { display: none; }
details.disc > summary::before {
  content: "▸"; color: var(--text-3); font-size: 0.75rem; flex: none;
  transition: transform 140ms ease;
}
details.disc[open] > summary::before { transform: rotate(90deg); }
details.disc > summary:hover { background: var(--bg-2); }
details.disc > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
details.disc > summary .t { font-weight: 650; font-size: 0.9375rem; color: var(--text-1); }
details.disc > summary .glance { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
details.disc > summary .gchip {
  font: 600 0.625rem var(--mono); color: var(--text-2);
  border: 1px solid var(--line-1); border-radius: var(--r-pill); padding: 2px 8px; background: var(--bg-0);
}
details.disc > summary .gchip.good { color: var(--good); border-color: rgba(61,220,151,0.3); }
details.disc > summary .gchip.warn { color: var(--warn); border-color: rgba(245,192,68,0.3); }
details.disc > summary .gchip.bad { color: var(--bad); border-color: rgba(242,85,90,0.3); }
details.disc > summary .arw { margin-left: auto; color: var(--text-3); font-size: 0.6875rem; font-family: var(--mono); }
details.disc > summary:hover .arw { color: var(--accent); }
details.disc .disc-body { padding: 4px 18px 18px; border-top: 1px solid var(--line-1); animation: discIn 160ms ease; }
@keyframes discIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---------- show-all affordance (v2: row cap) ---------- */
.more {
  display: inline-flex; align-items: center; gap: 6px; font: 600 0.75rem var(--sans); color: var(--accent);
  padding: 8px 0 0;
}
.more:hover { text-decoration: underline; }
.rowcap { color: var(--text-3); font-size: 0.6875rem; font-family: var(--mono); }

/* ---------- tier helpers (v2) ---------- */
.hero-zone { display: grid; grid-template-columns: 2fr 1fr; gap: var(--gap); margin-bottom: var(--gap); align-items: start; }
.hero-zone > * { min-width: 0; }
@media (max-width: 1080px) { .hero-zone { grid-template-columns: 1fr; } }
.hero-panel { position: relative; }
.hero-panel .panel-head h2 { font-size: 1.0625rem; }

/* ---------- panels ---------- */
.panel {
  background: var(--bg-1); border: 1px solid var(--line-1); border-radius: var(--r-panel);
  padding: 16px 18px; margin-bottom: var(--gap); position: relative;
}
.panel-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { font-size: 1rem; }
.panel-head .q { color: var(--text-3); font-size: 0.75rem; }
.panel-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.panel-foot { display: flex; gap: 14px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.legend { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.legend .lg { display: inline-flex; align-items: center; gap: 6px; font-size: 0.6875rem; color: var(--text-2); font-family: var(--mono); }
.legend .sw { width: 16px; height: 2px; border-radius: 2px; flex: none; }
.legend .sw.dash { background: repeating-linear-gradient(90deg, currentColor 0 5px, transparent 5px 8px); height: 0; border-top: 2px solid currentColor; }
.legend .sw.dot { background: repeating-linear-gradient(90deg, currentColor 0 2px, transparent 2px 6px); height: 0; border-top: 2px solid currentColor; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: var(--gap); }
.grid-1-2 { display: grid; grid-template-columns: 1fr 2fr; gap: var(--gap); }
@media (max-width: 1080px) { .grid2, .grid3, .grid-2-1, .grid-1-2 { grid-template-columns: 1fr; } }

.horizon { display: inline-flex; border: 1px solid var(--line-1); border-radius: var(--r-pill); overflow: hidden; }
.horizon button {
  background: transparent; border: 0; color: var(--text-3); font: 0.6875rem var(--mono);
  padding: 4px 10px; cursor: pointer;
}
.horizon button.active { background: var(--accent-soft); color: var(--accent); }
.horizon button:hover { color: var(--text-1); }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.6875rem; font-weight: 600;
  font-family: var(--mono); padding: 3px 10px; border-radius: var(--r-pill);
  border: 1px solid var(--line-2); color: var(--text-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--good { color: var(--good); border-color: rgba(61,220,151,0.35); background: rgba(61,220,151,0.08); }
.badge--warn { color: var(--warn); border-color: rgba(245,192,68,0.35); background: rgba(245,192,68,0.08); }
.badge--bad { color: var(--bad); border-color: rgba(242,85,90,0.35); background: rgba(242,85,90,0.08); }
.badge--info { color: var(--info); border-color: rgba(139,157,249,0.35); background: rgba(139,157,249,0.10); }
.badge--violet { color: var(--violet); border-color: rgba(179,140,249,0.35); background: rgba(179,140,249,0.10); }
.badge--stale { color: var(--stale); border-color: rgba(122,108,93,0.45); background: rgba(122,108,93,0.12); }

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.tooltip {
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: var(--r-ctl);
  padding: 8px 12px; font-family: var(--mono); font-size: 0.6875rem; color: var(--text-2);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4); pointer-events: none; position: absolute; z-index: 30;
}
.tooltip b { color: var(--text-1); }
.missing-pattern {
  background-image: repeating-linear-gradient(135deg, var(--missing) 0 1px, transparent 1px 7px);
  border-radius: var(--r-ctl);
}
.empty { border: 1px dashed var(--line-2); border-radius: var(--r-panel); padding: 32px; text-align: center; color: var(--text-3); }

/* ---------- stream frames & cards ---------- */
.stream-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: var(--gap); margin-bottom: var(--gap); }
.stream-card {
  background: var(--bg-1); border: 1px solid var(--line-1); border-radius: var(--r-panel);
  overflow: hidden; display: flex; flex-direction: column;
}
.stream-card:hover { border-color: var(--line-2); }
.stream-frame { position: relative; aspect-ratio: 16/9; background: var(--bg-0); }
.stream-frame .rec {
  position: absolute; top: 10px; left: 10px; display: inline-flex; align-items: center; gap: 6px;
  font: 0.6875rem var(--mono); color: var(--text-1); background: rgba(11,14,18,0.65);
  border-radius: var(--r-pill); padding: 3px 10px; backdrop-filter: blur(4px);
}
.stream-frame .session-tag {
  position: absolute; bottom: 10px; left: 10px; font: 0.6875rem var(--mono); color: var(--text-2);
  background: rgba(11,14,18,0.65); border-radius: var(--r-pill); padding: 3px 10px; backdrop-filter: blur(4px);
}
.stream-body { padding: 12px 16px 14px; display: flex; flex-direction: column; gap: 8px; }
.stream-body .row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.stream-body .name { font-weight: 650; font-size: 0.9375rem; }
.stream-body .state { color: var(--text-2); font-size: 0.8125rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 0.75rem; }
.kv b { color: var(--text-3); font-weight: 600; }
.kv span { color: var(--text-1); font-family: var(--mono); }
.spark-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; border-top: 1px solid var(--line-1); padding-top: 10px; }
.spark-cell { display: flex; flex-direction: column; gap: 2px; }
.spark-cell .k { font-size: 0.625rem; color: var(--text-3); letter-spacing: 0.06em; text-transform: uppercase; }
.spark-cell svg { height: 26px; width: 100%; }
.layer-chips { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.layer-chip {
  font: 600 0.625rem var(--mono); letter-spacing: 0.04em; color: var(--text-3);
  background: rgba(11,14,18,0.65); border: 1px solid var(--line-1);
  border-radius: var(--r-pill); padding: 3px 8px; cursor: pointer; backdrop-filter: blur(4px);
}
.layer-chip.on { color: var(--accent); border-color: rgba(34,211,238,0.4); }
.layer-chip:hover { color: var(--text-1); }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.table th {
  text-align: left; font-size: 0.6875rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-3); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--line-2);
  position: sticky; top: 0; background: var(--bg-1);
}
.table td { padding: 9px 12px; border-bottom: 1px solid var(--line-1); color: var(--text-2); }
.table td.num, .table td .mono { font-family: var(--mono); color: var(--text-1); }
.table tbody tr:hover { background: var(--bg-2); }
.table .drill { color: var(--text-3); text-align: right; }
.table tbody tr:hover .drill { color: var(--accent); }

/* ---------- attention rows ---------- */
.attention-row {
  display: grid; grid-template-columns: 20px 1fr auto; gap: 12px; align-items: start;
  padding: 12px 14px; border: 1px solid var(--line-1); border-radius: var(--r-panel);
  background: var(--bg-1); margin-bottom: 10px;
}
.attention-row:hover { background: var(--bg-2); }
.attention-row .sev { font-size: 1rem; line-height: 1.4; }
.attention-row .what { font-weight: 600; color: var(--text-1); }
.attention-row .why { color: var(--text-2); font-size: 0.8125rem; margin-top: 2px; }
.attention-row .meta { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: var(--gap); }
.filters .f-chip {
  font: 600 0.6875rem var(--mono); color: var(--text-2); background: var(--bg-1);
  border: 1px solid var(--line-1); border-radius: var(--r-pill); padding: 4px 12px; cursor: pointer;
}
.filters .f-chip:hover { border-color: var(--line-2); color: var(--text-1); }
.filters .f-chip.on { background: var(--accent-soft); color: var(--accent); border-color: rgba(34,211,238,0.3); }
.filters .f-group { display: inline-flex; gap: 4px; align-items: center; color: var(--text-3); font-size: 0.6875rem; }

/* ---------- timeline ---------- */
.timeline { position: relative; }
.timeline .lane { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: center; margin-bottom: 6px; }
.timeline .lane .lane-k { font-size: 0.6875rem; color: var(--text-3); text-align: right; font-weight: 600; }
.timeline .lane .track { position: relative; height: 26px; background: var(--bg-0); border-radius: 6px; border: 1px solid var(--line-1); }
.timeline .seg { position: absolute; top: 4px; height: 18px; border-radius: 4px; }
.timeline .seg.pred { border: 1px dashed currentColor; background: transparent; }
.timeline .seg.exec { background: currentColor; opacity: 0.85; }
.timeline .seg.cancel { background: currentColor; opacity: 0.3; text-decoration: line-through; }
.timeline .seg.expire { border: 1px solid var(--stale); background: transparent; }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; width: min(560px, 92vw); height: 100vh; z-index: 40;
  background: var(--bg-2); border-left: 1px solid var(--line-2); padding: 20px; overflow-y: auto;
  box-shadow: -24px 0 48px rgba(0,0,0,0.35);
}
.drawer .close { position: sticky; top: 0; float: right; }

/* ---------- CLI ---------- */
.cli-bar {
  display: flex; align-items: center; gap: 10px; background: var(--bg-0);
  border: 1px solid var(--line-2); border-radius: var(--r-ctl); padding: 10px 14px;
  font-family: var(--mono); font-size: 0.8125rem;
}
.cli-bar .prompt { color: var(--good); }
.cli-bar input { background: transparent; border: 0; outline: none; color: var(--text-1); font: inherit; flex: 1; }

/* ---------- donut ---------- */
.donut { position: relative; width: 96px; height: 96px; }
.donut .val { position: absolute; inset: 0; display: grid; place-items: center; font: 650 1.125rem var(--mono); }

/* ---------- misc ---------- */
.causal-chain { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.causal-chain .node {
  font: 600 0.6875rem var(--mono); padding: 5px 10px; background: var(--bg-0);
  border: 1px solid var(--line-2); border-radius: var(--r-pill); color: var(--text-2);
}
.causal-chain .node.on { color: var(--accent); border-color: rgba(34,211,238,0.4); }
.causal-chain .arr { color: var(--text-3); }
.term { border-bottom: 1px dotted var(--text-3); cursor: help; }
hr.sep { border: 0; border-top: 1px solid var(--line-1); margin: 18px 0; }
.footer-note { color: var(--text-3); font-size: 0.75rem; margin-top: 28px; }
