/* VD-1: design tokens live in :root. Everything below references these
 * tokens — no raw pixel literals for font-size / padding / gap / margin
 * / border-radius outside of :root. Layout-specific constants (grid
 * minmax breakpoints, hairline 1px borders, sr-only clip offsets) stay
 * literal because they are not part of a reusable scale. */
:root {
  /* Colors — GitHub-dark palette, unchanged from pre-VD-1. */
  --bg: #0d1117; --surface: #161b22; --border: #30363d;
  --text: #e6edf3; --muted: #8b949e; --accent: #58a6ff;
  --green: #3fb950; --yellow: #d29922; --red: #f85149; --purple: #bc8cff;

  /* Typography scale — every inline font-size in the pre-VD-1 CSS
   * mapped to one of these. xs=pills/badges, sm=labels/meta/mono,
   * base=body/tables, md=mobile h2, lg=section h2 + mobile h1,
   * xl=desktop h1, 2xl=mobile card value, 3xl=desktop card value. */
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-base: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --fs-2xl: 22px;
  --fs-3xl: 28px;

  /* Font weights — only the three actually used. */
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* Font families. */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;

  /* Spacing scale — Tailwind-ish 4px-base with half-steps where the
   * existing design needed them (2px pill padding, 6px button padding,
   * 10px/14px dead-letter rows). Not every step is used in every
   * breakpoint; that is fine — a scale is a contract, not a quota. */
  --space-px: 1px;
  --space-0-5: 2px;
  --space-1: 4px;
  --space-1-5: 6px;
  --space-2: 8px;
  --space-2-5: 10px;
  --space-3: 12px;
  --space-3-5: 14px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Corner radii — sm=small chips, md=buttons/cards-inner, lg=cards,
   * pill=inline status pills, badge=header badge. */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-pill: 10px;
  --radius-badge: 12px;

  /* Line height — only the body uses a non-default value today,
   * exposed as a token so future overrides share a source of truth. */
  --lh-base: 1.5;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: var(--font-sans);
  background: var(--bg); color: var(--text); line-height: var(--lh-base);
}
.container { max-width: 1200px; margin: 0 auto; padding: var(--space-6); }
header {
  display: flex; align-items: center; gap: var(--space-4); margin-bottom: var(--space-8);
  border-bottom: 1px solid var(--border); padding-bottom: var(--space-4); flex-wrap: wrap;
}
header h1 { font-size: var(--fs-xl); font-weight: var(--fw-semibold); }
header .badge {
  font-size: var(--fs-sm); padding: var(--space-0-5) var(--space-2); border-radius: var(--radius-badge);
  background: var(--green); color: #000; font-weight: var(--fw-semibold);
}
.header-actions { margin-left: auto; display: flex; gap: var(--space-2); }
/* Scope banner — UX-4 closeout. Subtle, non-blocking note that sits below
 * the header and tells an operator arriving at the dashboard what it is
 * (read-only) and where to go for control (HTTP API). Uses only existing
 * tokens so it stays part of the design system. */
.scope-note {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  color: var(--muted); font-size: var(--fs-sm);
  padding: var(--space-2) var(--space-3); margin-bottom: var(--space-6);
}
.scope-note a { color: var(--accent); text-decoration: none; }
.scope-note a:hover, .scope-note a:focus-visible { text-decoration: underline; outline: none; }
.scope-note code {
  font-family: var(--font-mono); font-size: var(--fs-xs);
  background: rgba(88,166,255,0.10); color: var(--accent);
  padding: var(--space-px) var(--space-1); border-radius: var(--radius-sm);
}
.btn {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); padding: var(--space-1-5) var(--space-3); border-radius: var(--radius-md);
  cursor: pointer; font-size: var(--fs-base); font-family: inherit;
}
.btn:hover, .btn:focus-visible { color: var(--text); border-color: var(--accent); outline: none; }
.btn:focus-visible { box-shadow: 0 0 0 2px rgba(88,166,255,0.4); }
.btn[aria-pressed="true"] { color: var(--yellow); border-color: var(--yellow); }
.cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4); margin-bottom: var(--space-8);
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-4);
}
.card .label {
  font-size: var(--fs-sm); color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: var(--space-1);
}
.card .value { font-size: var(--fs-3xl); font-weight: var(--fw-bold); }
.card .sub { font-size: var(--fs-sm); color: var(--muted); margin-top: var(--space-1); }
.pill {
  display: inline-block; padding: var(--space-px) var(--space-2); border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); text-transform: uppercase;
}
.pill-ok { background: rgba(63,185,80,0.15); color: var(--green); }
.pill-run { background: rgba(88,166,255,0.15); color: var(--accent); }
.pill-err { background: rgba(248,81,73,0.15); color: var(--red); }
.pill-warn { background: rgba(210,153,34,0.15); color: var(--yellow); }
.pill-mute { background: rgba(139,148,158,0.15); color: var(--muted); }
section { margin-bottom: var(--space-8); }
section h2 {
  font-size: var(--fs-lg); font-weight: var(--fw-semibold); margin-bottom: var(--space-3);
  padding-bottom: var(--space-2); border-bottom: 1px solid var(--border);
}
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); min-width: 600px; }
thead th {
  text-align: left; padding: var(--space-2) var(--space-3); color: var(--muted); font-weight: var(--fw-medium);
  border-bottom: 1px solid var(--border); font-size: var(--fs-sm); text-transform: uppercase;
  position: sticky; top: 0; background: var(--bg);
}
tbody td { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); }
tbody tr:hover { background: rgba(88,166,255,0.04); }
.mono { font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--muted); }
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--space-3); }
.metric-row {
  display: flex; justify-content: space-between; padding: var(--space-1-5) 0;
  border-bottom: 1px solid rgba(48,54,61,0.5); font-size: var(--fs-base);
}
.metric-row .key { color: var(--muted); }
.metric-row .val { font-family: var(--font-mono); }
.loading { color: var(--muted); font-style: italic; padding: var(--space-5); text-align: center; }
.error-msg {
  color: var(--red); padding: var(--space-3); background: rgba(248,81,73,0.1);
  border-radius: var(--radius-md); margin: var(--space-2) 0;
}

/* CC-2 + CQ-7: structured error panel (first-fetch failure, no cache). */
.error-panel {
  padding: var(--space-4); background: rgba(248,81,73,0.08);
  border: 1px solid rgba(248,81,73,0.25); border-left: 3px solid var(--red);
  border-radius: var(--radius-md); margin: var(--space-2) 0;
}
.error-panel .error-title { color: var(--red); font-weight: var(--fw-semibold); margin-bottom: var(--space-1); }
.error-panel .error-hint { color: var(--muted); font-size: var(--fs-base); margin-bottom: var(--space-2); }

/* Stale banner — shown when a refresh failed but last-good data is
 * still visible. Amber left-border separates "partially working" from
 * "fully broken" so operators don't conflate the two. */
.panel-stale { position: relative; border-left: 3px solid var(--yellow); padding-left: var(--space-3); }
.stale-banner {
  background: rgba(210,153,34,0.12); border: 1px solid rgba(210,153,34,0.35);
  color: var(--yellow); border-radius: var(--radius-md); padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-2); font-size: var(--fs-base);
}

/* Collapsed technical-details block. Defaults closed so operators
 * see the plain-English message; click to expose the raw exception. */
.error-detail { margin-top: var(--space-2); }
.error-detail summary {
  cursor: pointer; color: var(--muted); font-size: var(--fs-sm);
  padding: var(--space-1) 0; user-select: none;
}
.error-detail summary:hover, .error-detail summary:focus-visible {
  color: var(--text); outline: none;
}
.error-detail pre {
  margin-top: var(--space-1-5); padding: var(--space-2) var(--space-2-5);
  background: rgba(13,17,23,0.6); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-family: var(--font-mono);
  font-size: var(--fs-sm); color: var(--muted); white-space: pre-wrap;
  word-break: break-word; max-height: 160px; overflow-y: auto;
}
.dl-item {
  background: rgba(248,81,73,0.06); border: 1px solid rgba(248,81,73,0.2);
  border-radius: var(--radius-md); padding: var(--space-2-5) var(--space-3-5); margin-bottom: var(--space-2); font-size: var(--fs-base);
}
.empty { color: var(--muted); font-style: italic; padding: var(--space-4); text-align: center; }
.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;
}

/* Mobile (UX-1) */
@media (max-width: 640px) {
  .container { padding: var(--space-3); }
  header { gap: var(--space-2); margin-bottom: var(--space-5); }
  header h1 { font-size: var(--fs-lg); }
  .header-actions { margin-left: 0; width: 100%; }
  .btn { flex: 1; padding: var(--space-2) var(--space-2-5); }
  .cards { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-2-5); }
  .card { padding: var(--space-3); }
  .card .value { font-size: var(--fs-2xl); }
  section h2 { font-size: var(--fs-md); }
  table { font-size: var(--fs-sm); }
  thead th, tbody td { padding: var(--space-1-5) var(--space-2); }
}

/* Reduced motion (UX-2) */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
