/* RALLi Rebuild Telemetry — "Drafting Table / Mission Telemetry"
   Implements design.md. Dark blueprint surface, IBM Plex Sans + Mono,
   hairline instrument panels, semantic status system, wafer matrices. */

:root {
  --canvas: #0A0E1A;
  --canvas-grid: #12182B;
  --surface-1: #0F1525;
  --surface-2: #141C30;
  --surface-3: #1B2540;
  --hairline: #22304F;
  --hairline-strong: #34466E;
  --ink: #EAF0FF;
  --ink-muted: #A7B2CC;
  --ink-subtle: #6B779A;
  --accent: #46B6FF;
  --accent-dim: #2C6E9E;

  --st-done: #34D399;
  --st-progress: #FBBF24;
  --st-planned: #5B6678;
  --st-drift: #FB7185;
  --st-done-bg: rgba(52, 211, 153, .12);
  --st-progress-bg: rgba(251, 191, 36, .12);
  --st-planned-bg: rgba(91, 102, 120, .14);
  --st-drift-bg: rgba(251, 113, 133, .12);

  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --r: 8px;
  --rail-w: 232px;
  --pad: clamp(16px, 2.4vw, 28px);
  --maxw: 1320px;
  --ease: cubic-bezier(.22, .61, .36, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  background-color: var(--canvas);
  /* blueprint drafting grid */
  background-image:
    linear-gradient(var(--canvas-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--canvas-grid) 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: -1px -1px;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
body::before { /* faint vignette so the grid recedes at edges */
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: radial-gradient(120% 90% at 50% 0%, transparent 55%, rgba(5, 8, 16, .65) 100%);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #7fccff; }
::selection { background: rgba(70, 182, 255, .28); }

.skip-link {
  position: absolute; left: -999px; top: 8px; z-index: 100;
  background: var(--surface-3); color: var(--ink); padding: 8px 14px; border-radius: 6px;
}
.skip-link:focus { left: 8px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- shell ---------- */
.app { position: relative; z-index: 1; display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100dvh; }

.rail {
  position: sticky; top: 0; align-self: start; height: 100dvh;
  display: flex; flex-direction: column; gap: 8px;
  padding: 22px 16px; border-right: 1px solid var(--hairline);
  background: linear-gradient(180deg, rgba(15, 21, 37, .92), rgba(10, 14, 26, .92));
  backdrop-filter: blur(4px);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.brand-mark { color: var(--accent); font-size: 18px; letter-spacing: -2px; }
.brand-text { font-weight: 700; font-size: 17px; letter-spacing: .02em; display: flex; flex-direction: column; line-height: 1.1; }
.brand-sub { font-family: var(--mono); font-size: 10px; font-weight: 500; color: var(--ink-subtle); letter-spacing: .14em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 7px; color: var(--ink-muted);
  font-size: 14px; font-weight: 500; border: 1px solid transparent;
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--surface-3); color: var(--ink); border-color: var(--hairline-strong); }
.nav-item.active .nav-glyph { color: var(--accent); }
.nav-glyph { font-size: 14px; color: var(--ink-subtle); width: 16px; text-align: center; }

.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 14px; border-top: 1px solid var(--hairline); }
.refresh {
  font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  background: var(--surface-2); color: var(--ink-muted); border: 1px solid var(--hairline);
  padding: 8px 10px; border-radius: 6px; cursor: pointer; transition: all .15s var(--ease);
}
.refresh:hover { color: var(--ink); border-color: var(--accent-dim); }
.refresh.spin { color: var(--accent); }
.scan-meta { font-family: var(--mono); font-size: 10px; color: var(--ink-subtle); line-height: 1.5; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 14px;
  padding: 14px var(--pad); border-bottom: 1px solid var(--hairline);
  background: rgba(10, 14, 26, .82); backdrop-filter: blur(8px);
}
.menu-btn { display: none; background: none; border: 1px solid var(--hairline); color: var(--ink); border-radius: 6px; width: 38px; height: 38px; font-size: 18px; cursor: pointer; }
.topbar-title { font-weight: 600; font-size: 15px; letter-spacing: .01em; }
.topbar-pill { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--ink-muted); display: flex; align-items: center; gap: 8px; }

.view { padding: var(--pad); max-width: var(--maxw); width: 100%; margin: 0 auto; }
.loading { font-family: var(--mono); color: var(--ink-subtle); padding: 60px 0; text-align: center; }

/* ---------- instrument panel ---------- */
.panel {
  background: var(--surface-1); border: 1px solid var(--hairline); border-radius: var(--r);
  padding: 20px 22px; position: relative;
}
.eyebrow {
  font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-subtle); display: flex; align-items: center; gap: 8px; margin: 0 0 14px;
}
.eyebrow .tick { color: var(--accent); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head .eyebrow { margin: 0; }
.panel-stat { font-family: var(--mono); font-size: 12px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }

.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }

h1.view-title { font-size: 22px; font-weight: 700; letter-spacing: -.01em; margin: 0 0 4px; }
.view-sub { color: var(--ink-muted); font-size: 14px; margin: 0 0 22px; }

/* mono numerics everywhere */
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- status chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono);
  font-size: 11px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 5px; border: 1px solid transparent; white-space: nowrap;
}
.chip .g { font-size: 11px; }
.chip.done     { color: var(--st-done);     background: var(--st-done-bg);     border-color: rgba(52,211,153,.3); }
.chip.in-progress { color: var(--st-progress); background: var(--st-progress-bg); border-color: rgba(251,191,36,.3); }
.chip.planned  { color: #97a2bd;             background: var(--st-planned-bg);  border-color: rgba(91,102,120,.35); }
.chip.drift    { color: var(--st-drift);     background: var(--st-drift-bg);    border-color: rgba(251,113,133,.4); }
.chip.unknown  { color: var(--ink-subtle);   background: rgba(107,119,154,.1);  border-color: var(--hairline); }

/* ---------- overview: gauge ring + stats ---------- */
.overview-top { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: stretch; }
.gauge-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.gauge { position: relative; width: 220px; height: 220px; }
.gauge svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge .track { fill: none; stroke: var(--surface-3); stroke-width: 14; }
.gauge .fill { fill: none; stroke: var(--accent); stroke-width: 14; stroke-linecap: round;
  transition: stroke-dashoffset .7s var(--ease); filter: drop-shadow(0 0 6px rgba(70,182,255,.35)); }
.gauge .ticks line { stroke: var(--hairline-strong); stroke-width: 1.5; }
.gauge-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.gauge-pct { font-family: var(--mono); font-size: 44px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.gauge-pct small { font-size: 18px; color: var(--ink-subtle); }
.gauge-label { font-family: var(--mono); font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-subtle); }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat {
  background: var(--surface-1); border: 1px solid var(--hairline); border-radius: var(--r);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 4px;
}
.stat .k { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-subtle); }
.stat .v { font-family: var(--mono); font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .v .sep { color: var(--ink-subtle); font-weight: 400; }
.stat .bar { margin-top: 8px; }

.bar { height: 6px; border-radius: 4px; background: var(--surface-3); overflow: hidden; position: relative; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--st-done); transition: width .6s var(--ease); }
.bar.accent > i { background: var(--accent); }

/* segmented phase gauge (one cell per task) */
.segbar { display: flex; gap: 3px; margin-top: 4px; }
.seg { flex: 1; height: 8px; border-radius: 2px; background: var(--st-planned); min-width: 4px; transition: background .3s var(--ease); }
.seg.done { background: var(--st-done); }
.seg.in-progress { background: var(--st-progress); }
.seg.planned { background: var(--surface-3); }
.seg.drift { box-shadow: 0 0 0 1.5px var(--st-drift); }

/* ---------- phases ---------- */
.phase { margin-bottom: 14px; }
.phase-head {
  width: 100%; text-align: left; cursor: pointer; background: var(--surface-1);
  border: 1px solid var(--hairline); border-radius: var(--r); padding: 16px 18px;
  display: grid; grid-template-columns: 54px 1fr auto; gap: 16px; align-items: center;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.phase-head:hover { border-color: var(--hairline-strong); }
.phase.open .phase-head { border-color: var(--accent-dim); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.phase-n { font-family: var(--mono); font-size: 22px; font-weight: 600; color: var(--ink-subtle); text-align: center; }
.phase.open .phase-n, .phase-head:hover .phase-n { color: var(--accent); }
.phase-title { font-weight: 600; font-size: 16px; }
.phase-summary { color: var(--ink-muted); font-size: 13px; margin-top: 2px; line-height: 1.45; }
.phase-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; min-width: 150px; }
.phase-prog { font-family: var(--mono); font-size: 12px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.phase-meta-bar { width: 150px; }

.phase-body { border: 1px solid var(--accent-dim); border-top: none; border-radius: 0 0 var(--r) var(--r); background: var(--surface-1); padding: 6px; display: none; }
.phase.open .phase-body { display: block; }

.task { border: 1px solid var(--hairline); border-radius: 6px; margin: 6px; background: var(--canvas); overflow: hidden; }
.task-head { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; cursor: pointer; }
.task-head:hover { background: var(--surface-2); }
.task-id { font-family: var(--mono); font-size: 12px; color: var(--accent); font-weight: 500; }
.task-title { font-size: 14px; font-weight: 500; }
.task-chips { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.task-body { display: none; padding: 4px 14px 16px; border-top: 1px dashed var(--hairline); }
.task.open .task-body { display: block; }
.task-grid { display: grid; grid-template-columns: 130px 1fr; gap: 6px 14px; margin-top: 12px; font-size: 13px; }
.task-grid dt { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-subtle); padding-top: 3px; }
.task-grid dd { margin: 0; color: var(--ink-muted); }
.task-grid code, .mono-ref { font-family: var(--mono); font-size: 12px; color: var(--ink); background: var(--surface-2); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--hairline); display: inline-block; margin: 2px 4px 2px 0; }
.task-note { border-left: 2px solid var(--accent-dim); padding: 6px 0 6px 12px; margin: 4px 0; color: var(--ink-muted); font-size: 13px; }
.task-note.issue { border-color: var(--st-drift); }
.task-note .lbl { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-subtle); display: block; margin-bottom: 2px; }
.drift-banner { display: flex; gap: 8px; align-items: center; background: var(--st-drift-bg); border: 1px solid rgba(251,113,133,.3); border-radius: 6px; padding: 8px 12px; margin-top: 10px; font-size: 12px; color: #ffc4cd; font-family: var(--mono); }

/* ---------- coverage matrices ---------- */
.matrix-wrap { overflow-x: auto; }
.matrix { display: flex; flex-wrap: wrap; gap: 6px; }
.cell {
  font-family: var(--mono); font-size: 11px; padding: 7px 9px; border-radius: 5px;
  border: 1px solid var(--hairline); background: var(--surface-2); color: var(--ink-muted);
  display: flex; align-items: center; gap: 6px; cursor: default; transition: transform .12s var(--ease);
}
.cell:hover { transform: translateY(-1px); border-color: var(--hairline-strong); color: var(--ink); }
.cell .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--st-planned); flex: none; }
.cell.done { border-color: rgba(52,211,153,.35); color: #c7f5e4; }
.cell.done .dot { background: var(--st-done); box-shadow: 0 0 5px rgba(52,211,153,.6); }
.cell.in-progress .dot { background: var(--st-progress); }
.cell.planned { opacity: .82; }
.cell.drift { box-shadow: 0 0 0 1.5px var(--st-drift); }
.cell .sub { color: var(--ink-subtle); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-family: var(--mono); font-size: 11px; color: var(--ink-subtle); margin-top: 14px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 8px; height: 8px; border-radius: 50%; }

/* endpoint rows */
.ep-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ep-table th { text-align: left; font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-subtle); padding: 8px 10px; border-bottom: 1px solid var(--hairline); position: sticky; top: 0; background: var(--surface-1); }
.ep-table td { padding: 8px 10px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
.ep-table tr:hover td { background: var(--surface-2); }
.method { font-family: var(--mono); font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 4px; border: 1px solid var(--hairline); }
.method.GET { color: #7fccff; } .method.POST { color: var(--st-done); } .method.PATCH, .method.PUT { color: var(--st-progress); } .method.DELETE { color: var(--st-drift); }
.ep-path { font-family: var(--mono); font-size: 12.5px; color: var(--ink); }

/* ---------- flows (schematics) ---------- */
.flow { margin-bottom: 26px; }
.flow-steps { display: flex; flex-wrap: wrap; gap: 0; align-items: stretch; }
.fstep { position: relative; background: var(--surface-1); border: 1px solid var(--hairline); border-radius: 7px; padding: 12px 14px; min-width: 200px; max-width: 260px; flex: 1; margin: 0 26px 18px 0; }
.fstep::after { content: "→"; position: absolute; right: -22px; top: 50%; transform: translateY(-50%); color: var(--accent-dim); font-size: 18px; font-family: var(--mono); }
.fstep:last-child::after, .fstep.last::after { content: ""; }
.fstep .fn { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; color: var(--ink-subtle); text-transform: uppercase; }
.fstep .fa { font-size: 13.5px; font-weight: 600; margin: 4px 0; }
.fstep .fd { font-size: 12.5px; color: var(--ink-muted); line-height: 1.45; }
.fstep .fmeta { font-family: var(--mono); font-size: 11px; color: var(--accent); margin-top: 6px; word-break: break-word; }
.actor-tag { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; padding: 2px 7px; border-radius: 4px; border: 1px solid var(--hairline); color: var(--ink-subtle); }
.actor-applicant { color: #7fccff; border-color: rgba(70,182,255,.35); }
.actor-employer { color: var(--st-progress); border-color: rgba(251,191,36,.35); }
.actor-system { color: var(--st-done); border-color: rgba(52,211,153,.35); }

/* ---------- guide browser ---------- */
.guide-layout { display: grid; grid-template-columns: 256px 1fr; gap: 16px; align-items: start; }
.guide-toc { position: sticky; top: 84px; background: var(--surface-1); border: 1px solid var(--hairline); border-radius: var(--r); padding: 10px; max-height: calc(100dvh - 110px); overflow: auto; }
.toc-group { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-subtle); margin: 12px 8px 4px; }
.toc-link { display: block; padding: 7px 10px; border-radius: 6px; font-size: 13px; color: var(--ink-muted); }
.toc-link:hover { background: var(--surface-2); color: var(--ink); }
.toc-link.active { background: var(--surface-3); color: var(--ink); }
.doc { background: var(--surface-1); border: 1px solid var(--hairline); border-radius: var(--r); padding: 28px clamp(20px, 3vw, 40px); }
.doc h1, .doc h2, .doc h3 { font-weight: 700; letter-spacing: -.01em; line-height: 1.25; margin: 1.6em 0 .5em; }
.doc h1 { font-size: 26px; margin-top: 0; } .doc h2 { font-size: 20px; padding-bottom: 6px; border-bottom: 1px solid var(--hairline); } .doc h3 { font-size: 16px; }
.doc p, .doc li { color: var(--ink-muted); }
.doc a { text-decoration: underline; text-underline-offset: 2px; }
.doc code { font-family: var(--mono); font-size: 13px; background: var(--surface-2); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--hairline); color: var(--ink); }
.doc pre { background: var(--canvas); border: 1px solid var(--hairline); border-radius: 8px; padding: 16px; overflow: auto; }
.doc pre code { background: none; border: none; padding: 0; font-size: 12.5px; }
.doc table { width: 100%; border-collapse: collapse; margin: 1em 0; font-size: 13.5px; }
.doc th, .doc td { border: 1px solid var(--hairline); padding: 7px 10px; text-align: left; }
.doc th { background: var(--surface-2); font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-subtle); }
.doc blockquote { border-left: 3px solid var(--accent-dim); margin: 1em 0; padding: 4px 0 4px 16px; color: var(--ink-subtle); }
.doc ul, .doc ol { padding-left: 22px; }

.empty { font-family: var(--mono); color: var(--ink-subtle); border: 1px dashed var(--hairline); border-radius: var(--r); padding: 30px; text-align: center; }

/* ---------- entrance motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.stagger > * { animation: rise .4s var(--ease) both; }
.stagger > *:nth-child(2){animation-delay:.04s}.stagger > *:nth-child(3){animation-delay:.08s}
.stagger > *:nth-child(4){animation-delay:.12s}.stagger > *:nth-child(5){animation-delay:.16s}
.stagger > *:nth-child(6){animation-delay:.2s}.stagger > *:nth-child(n+7){animation-delay:.24s}

/* ---------- responsive ---------- */
@media (max-width: 1024px) {
  .overview-top { grid-template-columns: 1fr; }
  .gauge-panel { padding-bottom: 8px; }
  .cols-4 { grid-template-columns: repeat(2, 1fr); }
  .guide-layout { grid-template-columns: 1fr; }
  .guide-toc { position: static; max-height: none; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .rail {
    position: fixed; left: 0; top: 0; width: 280px; z-index: 40; transform: translateX(-102%);
    transition: transform .22s var(--ease);
  }
  .rail.open { transform: none; box-shadow: 0 0 0 100vmax rgba(5,8,16,.5); }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
}
@media (max-width: 640px) {
  .cols-2, .cols-3, .cols-4, .stat-grid, .overview-top { grid-template-columns: 1fr; }
  .phase-head { grid-template-columns: 40px 1fr; }
  .phase-right { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; }
  .phase-meta-bar { width: 100%; }
  .task-head { grid-template-columns: 1fr; gap: 6px; }
  .task-chips { justify-content: flex-start; }
  .topbar-pill { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .gauge .fill { transition: none; }
}
