/* ===========================================================================
   BRIDGE AI — reset, typography, and the application shell
   ---------------------------------------------------------------------------
   Layout contract:
     >= 960px   fixed left rail (nav + system health) + scrolling content
     <  960px   sticky brand bar on top, fixed 4-item tab bar on the bottom
   The mobile layout is designed for 390px, not merely tolerated there: the
   tab bar is thumb-reachable, every table becomes a stack of labelled rows,
   and no screen scrolls horizontally.
   =========================================================================== */

/* ------------------------------------------------------------------ reset */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--ink-950);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--t-base);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  /* A faint ruled ground: the page reads as instrument paper, not a void. */
  background-image:
    radial-gradient(90% 60% at 100% 0%, rgba(255, 214, 77, .045), transparent 62%),
    radial-gradient(70% 50% at 0% 100%, rgba(61, 220, 132, .04), transparent 60%),
    repeating-linear-gradient(90deg,
      rgba(190, 240, 190, .022) 0 1px, transparent 1px 96px);
  background-attachment: fixed;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: var(--lh-tight); }
p, ul, ol, dl, figure, pre, table { margin: 0; }
ul, ol { padding: 0; list-style: none; }

a { color: inherit; text-decoration: none; }
a:focus-visible,
button:focus-visible,
summary:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

img, svg { max-width: 100%; display: block; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s5) 0; }
::selection { background: var(--green); color: var(--ink-1000); }

/* ------------------------------------------------------------- typography */
.display {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: var(--track-tight);
  line-height: var(--lh-tight);
}
h1.display { font-size: clamp(var(--t-xl), 5vw, var(--t-2xl)); }
h2.display { font-size: var(--t-lg); }

.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: var(--track-wide);
  text-transform: uppercase;
  color: var(--text-3);
}
.eyebrow--yellow { color: var(--yellow); }
.eyebrow--green  { color: var(--green); }

.lede {
  font-size: var(--t-md);
  color: var(--text-2);
  max-width: 62ch;
  text-wrap: pretty;
}
.muted   { color: var(--text-2); }
.dim     { color: var(--text-3); }
.small   { font-size: var(--t-sm); }
.tiny    { font-size: var(--t-xs); }
.mono    { font-family: var(--font-mono); }
.num     { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.nowrap  { white-space: nowrap; }
.strong  { font-weight: 600; color: var(--text); }
.measure { max-width: var(--wrap-narrow); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Long opaque strings (fingerprints, URLs) must wrap, never widen the page. */
.break { overflow-wrap: anywhere; word-break: break-word; }

/* ------------------------------------------------------------------ shell */
.shell { min-height: 100vh; }

.rail {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--rail);
  display: flex;
  flex-direction: column;
  gap: var(--s5);
  padding: var(--s5) var(--s4);
  background: var(--ink-900);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  z-index: 30;
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 0;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--t-md);
  letter-spacing: var(--track-tight);
}
.brand .ai {
  background: linear-gradient(94deg, var(--yellow), var(--green));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand .dot { color: var(--green); }
.brand-sub {
  display: block;
  margin-top: var(--s1);
  font-family: var(--font-mono);
  font-size: var(--t-2xs);
  letter-spacing: var(--track-wide);
  text-transform: uppercase;
  color: var(--text-3);
}

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  border-radius: var(--r-md);
  font-size: var(--t-base);
  color: var(--text-2);
  border: 1px solid transparent;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.nav a:hover { background: var(--ink-800); color: var(--text); }
.nav a[aria-current="page"] {
  background: var(--ink-800);
  border-color: var(--line-2);
  color: var(--text);
  font-weight: 600;
}
.nav a[aria-current="page"] .nav-mark { background: var(--yellow); }
.nav-mark {
  width: 3px;
  height: 18px;
  border-radius: var(--r-pill);
  background: var(--line-2);
  flex: none;
}
.nav-count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--t-xs);
  color: var(--text-3);
}

.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--s3); }
.rail-note {
  font-size: var(--t-xs);
  line-height: 1.5;
  color: var(--text-3);
  border-top: 1px solid var(--line);
  padding-top: var(--s3);
}
.rail-note b { color: var(--text-2); font-weight: 600; }

.content {
  margin-left: var(--rail);
  padding: var(--s6) var(--s6) var(--s9);
}
.wrap { max-width: var(--wrap); margin: 0 auto; }
.wrap--narrow { max-width: var(--wrap-narrow); margin: 0 auto; }

/* Mobile chrome — hidden on desktop, load-bearing below 960px. */
.topbar, .tabbar { display: none; }

.page-head { margin-bottom: var(--s6); }
.page-head h1 { margin-top: var(--s2); }
.page-head .lede { margin-top: var(--s3); }

.section { margin-top: var(--s7); }
.section > header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
  margin-bottom: var(--s4);
  padding-bottom: var(--s3);
  border-bottom: 1px solid var(--line);
}
.section > header h2 { font-family: var(--font-mono); font-size: var(--t-md); letter-spacing: var(--track-tight); }
.section > header .hint { font-size: var(--t-sm); color: var(--text-3); }

.stack   { display: flex; flex-direction: column; gap: var(--s4); }
.stack-2 { display: flex; flex-direction: column; gap: var(--s2); }
.row     { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.row--end { justify-content: flex-end; }
.spacer  { flex: 1 1 auto; }

.grid-2 { display: grid; gap: var(--s4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: var(--s4); grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: var(--s3); grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* --------------------------------------------------------- staggered load */
/* One orchestrated reveal per page load beats a dozen scattered fidgets. */
.rise { animation: rise var(--slow) var(--ease) both; }
.rise:nth-child(1) { animation-delay: 0ms; }
.rise:nth-child(2) { animation-delay: 40ms; }
.rise:nth-child(3) { animation-delay: 80ms; }
.rise:nth-child(4) { animation-delay: 120ms; }
.rise:nth-child(5) { animation-delay: 160ms; }
.rise:nth-child(6) { animation-delay: 200ms; }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .rise { animation: none; }
}

/* ------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 960px) {
  .rail { display: none; }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s3);
    position: sticky;
    top: 0;
    z-index: 30;
    padding: var(--s3) var(--gutter);
    background: rgba(8, 20, 8, .86);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
  }

  .tabbar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    position: fixed;
    inset: auto 0 0 0;
    z-index: 30;
    background: rgba(8, 20, 8, .94);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--line-2);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: var(--s2) var(--s1) var(--s3);
    font-family: var(--font-mono);
    font-size: var(--t-2xs);
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-3);
    border-top: 2px solid transparent;
  }
  .tabbar a[aria-current="page"] { color: var(--yellow); border-top-color: var(--yellow); }
  .tabbar .tab-glyph { font-size: 1rem; line-height: 1; }

  .content {
    margin-left: 0;
    padding: var(--s5) var(--gutter) calc(var(--s9) + 40px);
  }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section { margin-top: var(--s6); }
}

/* NOTE: `.grid-4` stays TWO-UP at phone width (the one-up rule that used to
   live here is gone). Stacked, the archive's four counters took four
   full-width blocks and pushed the first archive row — the thing the screen is
   for — below the worker banner, the lede and a screen of chrome. The tighter
   tile padding that buys the second column is in components.css, beside the
   `.kpi` rule it has to override. */
