/*!
 * Wirebench theme.css
 * Design system: .agents/rules/design.md ("Precision Technical Instrument").
 * Single shared stylesheet. Zero framework, zero build step.
 *
 * Contents
 *  1. Tokens
 *  2. Base and typography
 *  3. Layout primitives
 *  4. Top bar, segmented control, buttons
 *  5. Forms
 *  6. Panels and notes
 *  7. Readout, lamp, gauge
 *  8. Workbench and reference layout
 *  9. Tables
 * 10. Directory (tool cards)
 * 11. Ad slots
 * 12. Mobile result bar
 * 13. Footer
 * 14. Utilities
 * 15. Print
 */

/* ==========================================================================
   1. Tokens
   ========================================================================== */
:root {
  color-scheme: light;

  --font-ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  /* Brand values (fixed) */
  --paper: #F8F8F6;
  --panel: #FFFFFF;
  --ink: #111827;
  --amber: #D97706;
  --pass: #15803D;
  --fail: #B91C1C;

  /* Derived (contrast and state helpers) */
  --ink-2: #4B5563;
  --ink-3: #6B7280;
  --line: #D4D4D8;
  --line-strong: #A1A1AA;
  --field-ro: #F4F4F2;
  --on-amber: #111827;
  --amber-ink: #92400E;
  --amber-wash: #FFF4DF;
  --pass-text: #15803D;
  --fail-text: #B91C1C;
  --idle: #6B7280;

  /* Geometry */
  --radius: 4px;
  --bw: 1px;
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;
  --topbar-h: 52px;
  --control-h: 40px;
  --wrap-max: 1280px;
  --wrap-pad: 16px;
  --ease: 120ms ease-out;
}

html[data-theme="dark"] {
  color-scheme: dark;

  --paper: #0A0A0B;
  --panel: #131315;
  --ink: #ECECEE;
  --ink-2: #A1A1AA;
  --ink-3: #8B8B94;
  --line: #27272A;
  --line-strong: #3F3F46;
  --field-ro: #0F0F11;
  --amber-ink: #FBBF24;
  --amber-wash: #2A1D08;
  --pass-text: #4ADE80;
  --fail-text: #F87171;
  --idle: #52525B;
}

@media (min-width: 900px) {
  :root { --wrap-pad: 24px; }
}

@media (max-width: 899px) {
  :root { --control-h: 44px; }
}

/* ==========================================================================
   2. Base and typography
   ========================================================================== */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--topbar-h) + var(--s-4));
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 24px;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  margin: 0;
  font-family: var(--font-ui);
  font-weight: 600;
  color: var(--ink);
}
h1 { font-size: 24px; line-height: 32px; }
h2 { font-size: 18px; line-height: 28px; }
h3 { font-size: 16px; line-height: 24px; }
h4 { font-size: 14px; line-height: 20px; }

@media (min-width: 900px) {
  h1 { font-size: 28px; line-height: 36px; }
}

p { margin: 0 0 var(--s-3); max-width: 68ch; }
p:last-child { margin-bottom: 0; }

a {
  color: var(--amber-ink);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
a:hover { text-decoration-thickness: 2px; }

ul, ol { margin: 0 0 var(--s-3); padding-left: 1.25em; max-width: 68ch; }
li + li { margin-top: var(--s-1); }

img, svg { display: block; max-width: 100%; }

hr { border: 0; border-top: var(--bw) solid var(--line); margin: var(--s-5) 0; }

code, kbd, samp, pre, .mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
code { font-size: 0.9em; }

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

::selection { background: var(--amber); color: var(--on-amber); }

.small { font-size: 13px; line-height: 20px; }
.muted { color: var(--ink-2); }
.caption { font-size: 12px; line-height: 16px; color: var(--ink-3); }

/* Everything numeric is monospace with aligned digits */
.num, .formula {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.formula {
  display: block;
  padding: var(--s-3) var(--s-4);
  background: var(--field-ro);
  border: var(--bw) solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 24px;
  overflow-x: auto;
}

/* ==========================================================================
   3. Layout primitives
   ========================================================================== */
.wrap {
  width: 100%;
  max-width: var(--wrap-max);
  margin: 0 auto;
  padding-inline: var(--wrap-pad);
}

.pagehead {
  padding-block: var(--s-5) var(--s-4);
}
.pagehead p {
  margin-top: var(--s-1);
  font-size: 14px;
  line-height: 20px;
  color: var(--ink-2);
}

.section { margin-top: var(--s-6); }
.stack > * + * { margin-top: var(--s-4); }
.row { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }

/* ==========================================================================
   4. Top bar, segmented control, buttons
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  background: var(--panel);
  border-bottom: var(--bw) solid var(--line);
}
.topbar__inner {
  height: 100%;
  max-width: var(--wrap-max);
  margin: 0 auto;
  padding-inline: var(--wrap-pad);
  display: flex;
  align-items: center;
  gap: var(--s-4);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--ink);
  font-weight: 600;
  font-size: 16px;
  text-decoration: none;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand__mark { width: 24px; height: 24px; flex: none; }
.brand__mark rect { fill: var(--amber); }
.brand__mark path { stroke: var(--on-amber); }

.topbar__nav {
  display: none;
  gap: var(--s-1);
  margin-left: var(--s-2);
}
.topbar__nav a {
  padding: 6px 10px;
  border-radius: var(--radius);
  color: var(--ink-2);
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  text-decoration: none;
}
.topbar__nav a:hover { color: var(--ink); background: var(--field-ro); }
.topbar__nav a[aria-current="page"] { color: var(--ink); background: var(--amber-wash); }

.topbar__tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.topbar__hint {
  display: none;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 16px;
  color: var(--ink-3);
  white-space: nowrap;
}

@media (min-width: 900px) {
  .topbar__nav { display: flex; }
}
@media (min-width: 1100px) {
  .topbar__hint { display: block; }
}

/* Top-bar controls are compact; elsewhere controls are 40/44px */
.topbar .seg button,
.topbar .btn {
  min-height: 32px;
  padding-block: 4px;
}

/* Segmented control */
.seg {
  display: inline-flex;
  border: var(--bw) solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}
.seg button {
  appearance: none;
  min-height: var(--control-h);
  padding: 0 var(--s-3);
  border: 0;
  border-left: var(--bw) solid var(--line);
  background: transparent;
  color: var(--ink-2);
  font: 500 14px/20px var(--font-ui);
  cursor: pointer;
  transition: background-color var(--ease), color var(--ease);
}
.seg button:first-child { border-left: 0; }
.seg button:hover { color: var(--ink); background: var(--field-ro); }
.seg button[aria-pressed="true"] {
  background: var(--amber);
  color: var(--on-amber);
  font-weight: 600;
}
.seg button:focus-visible { outline-offset: -2px; }
.seg--fill { display: flex; width: 100%; }
.seg--fill button { flex: 1 1 0; }

/* Buttons */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--control-h);
  padding: 0 var(--s-4);
  border: var(--bw) solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  font: 500 14px/20px var(--font-ui);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color var(--ease), background-color var(--ease);
}
.btn:hover { border-color: var(--ink); text-decoration: none; }
.btn--primary {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--on-amber);
  font-weight: 600;
}
.btn--primary:hover { background: #C96F05; border-color: #C96F05; }
.btn--quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn--quiet:hover { color: var(--ink); background: var(--field-ro); border-color: transparent; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

/* Theme toggle icon follows state */
.theme-icon { width: 16px; height: 16px; flex: none; }
.theme-icon * { fill: none; stroke: currentColor; stroke-width: 1.5; }
.theme-icon .to-dark { display: block; }
.theme-icon .to-light { display: none; }
html[data-theme="dark"] .theme-icon .to-dark { display: none; }
html[data-theme="dark"] .theme-icon .to-light { display: block; }
.theme-label-dark { display: inline; }
.theme-label-light { display: none; }
html[data-theme="dark"] .theme-label-dark { display: none; }
html[data-theme="dark"] .theme-label-light { display: inline; }
@media (max-width: 599px) {
  .theme-label-dark, .theme-label-light { display: none !important; }
  .topbar .btn { padding-inline: var(--s-2); }
}

/* Unit-dependent static text */
html[data-units="us"] .u-iec { display: none !important; }
html[data-units="iec"] .u-us { display: none !important; }

/* ==========================================================================
   5. Forms
   ========================================================================== */
.field { display: grid; gap: var(--s-1); min-width: 0; }
.field__label {
  font-size: 13px;
  line-height: 20px;
  font-weight: 500;
  color: var(--ink);
}
.field__hint {
  font-size: 12px;
  line-height: 16px;
  color: var(--ink-3);
}
.field [aria-invalid="true"] { border-color: var(--fail); }
.field__hint.is-error { color: var(--fail-text); }

.form-grid { display: grid; gap: var(--s-4); }
.form-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 479px) {
  .form-grid--2 { grid-template-columns: minmax(0, 1fr); }
}

.input {
  width: 100%;
  min-height: var(--control-h);
  padding: 0 var(--s-3);
  border: var(--bw) solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 20px;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--ease);
}
.input:hover { border-color: var(--line-strong); }
.input:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; border-color: var(--ink); }
.input[readonly] { background: var(--field-ro); }
.input::placeholder { color: var(--ink-3); }
input[type="number"].input { -moz-appearance: textfield; appearance: textfield; }
input[type="number"].input::-webkit-outer-spin-button,
input[type="number"].input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.input-group {
  display: flex;
  align-items: stretch;
  border: var(--bw) solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  transition: border-color var(--ease);
}
.input-group:hover { border-color: var(--line-strong); }
.input-group:focus-within { outline: 2px solid var(--amber); outline-offset: 1px; border-color: var(--ink); }
.input-group .input {
  border: 0;
  border-radius: 0;
  background: transparent;
  outline: none;
  min-width: 0;
}
.input-group__unit {
  display: flex;
  align-items: center;
  padding: 0 var(--s-3);
  border-left: var(--bw) solid var(--line);
  background: var(--field-ro);
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
}

.select { position: relative; }
.select select.input { appearance: none; -webkit-appearance: none; padding-right: 36px; cursor: pointer; }
.select::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--ink-2);
  border-bottom: 2px solid var(--ink-2);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }

/* ==========================================================================
   6. Panels and notes
   ========================================================================== */
.panel {
  background: var(--panel);
  border: var(--bw) solid var(--line);
  border-radius: var(--radius);
}
.panel__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2) var(--s-3);
  min-height: 44px;
  padding: var(--s-2) var(--s-4);
  border-bottom: var(--bw) solid var(--line);
}
.panel__head h2,
.panel__head h3 { font-size: 14px; line-height: 20px; }
.panel__body { padding: var(--s-4); }

.note {
  padding: var(--s-3) var(--s-4);
  border: var(--bw) solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 13px;
  line-height: 20px;
  color: var(--ink-2);
  max-width: 68ch;
}
.note strong { color: var(--ink); font-weight: 600; }

/* ==========================================================================
   7. Readout, lamp, gauge (the signature object)
   ========================================================================== */
.readout {
  background: var(--panel);
  border: var(--bw) solid var(--line);
  border-radius: var(--radius);
}
.readout--pin {
  position: static;
}
.readout__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2) var(--s-3);
  min-height: 44px;
  padding: var(--s-2) var(--s-4);
  border-bottom: var(--bw) solid var(--line);
}
.readout__title { font-size: 14px; line-height: 20px; font-weight: 600; }
.readout__body { padding: var(--s-4); }
.readout__primary {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--s-2);
}
.readout__value {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: clamp(40px, 6vw, 56px);
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  min-width: 4ch;
}
.readout__unit {
  font-family: var(--font-mono);
  font-size: 18px;
  line-height: 24px;
  color: var(--ink-2);
}
.readout__sub {
  margin-top: var(--s-2);
  font-size: 13px;
  line-height: 20px;
  color: var(--ink-2);
  min-height: 20px;
}
.readout__empty { color: var(--ink-3); font-size: 14px; line-height: 20px; }
.readout.is-pass .readout__value { color: var(--pass-text); }
.readout.is-fail .readout__value { color: var(--fail-text); }

.readout__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--bw);
  background: var(--line);
  border-top: var(--bw) solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}
.metric {
  margin: 0;
  padding: var(--s-3) var(--s-4);
  background: var(--panel);
  min-width: 0;
}
.metric dt {
  font-size: 12px;
  line-height: 16px;
  color: var(--ink-2);
}
.metric dd {
  margin: var(--s-1) 0 0;
  font-family: var(--font-mono);
  font-size: 18px;
  line-height: 24px;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.metric dd small {
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-3);
  margin-left: 2px;
}
.metric.is-pass dd { color: var(--pass-text); }
.metric.is-fail dd { color: var(--fail-text); }

/* Lamp: status as a solid indicator plus words */
.lamp {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: var(--radius);
  background: var(--idle);
  color: #FFFFFF;
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
  white-space: nowrap;
}
.lamp::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 1px;
  background: currentColor;
  opacity: 0.9;
}
.lamp--pass { background: var(--pass); }
.lamp--fail { background: var(--fail); }
.lamp--warn { background: var(--amber); color: var(--on-amber); }

/* Gauge: a calibrated scale like a meter face.
   --v  needle position (percent of full scale)
   --t1 first limit tick (percent of scale)
   --t2 second limit tick (percent of scale) */
.gauge { --v: 0%; --t1: 50%; --t2: 83.333%; margin-top: var(--s-4); }
.gauge__track {
  position: relative;
  height: 12px;
  border: var(--bw) solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--field-ro);
}
.gauge__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--v);
  max-width: 100%;
  background: var(--pass);
  border-radius: 2px;
  transition: width var(--ease), background-color var(--ease);
}
.gauge.is-warn .gauge__fill { background: var(--amber); }
.gauge.is-fail .gauge__fill { background: var(--fail); }
.gauge__tick {
  position: absolute;
  top: -5px;
  bottom: -5px;
  width: 2px;
  margin-left: -1px;
  background: var(--ink);
}
.gauge__tick--1 { left: var(--t1); }
.gauge__tick--2 { left: var(--t2); }
.gauge__needle {
  position: absolute;
  top: -7px;
  bottom: -7px;
  left: min(var(--v), 100%);
  width: 3px;
  margin-left: -1px;
  background: var(--amber);
  border: 1px solid var(--ink);
  border-radius: 1px;
  transition: left var(--ease);
}
.gauge__rule {
  position: relative;
  height: 8px;
  margin-top: 6px;
  border-right: var(--bw) solid var(--ink-3);
  background-image: repeating-linear-gradient(90deg, var(--ink-3) 0 1px, transparent 1px calc(100% / 12));
  background-size: 100% 6px;
  background-repeat: no-repeat;
}
.gauge__labels {
  position: relative;
  height: 20px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 16px;
  color: var(--ink-2);
}
.gauge__labels span { position: absolute; top: 2px; transform: translateX(-50%); white-space: nowrap; }
.gauge__labels span:first-child { transform: none; }
.gauge__labels span:last-child { transform: translateX(-100%); }

/* ==========================================================================
   8. Workbench and reference layout
   ========================================================================== */
.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s-4);
  align-items: start;
  height: auto;
  overflow: visible;
}
.workbench__params,
.workbench__main,
.workbench__main > .panel,
.workbench__main > .readout {
  position: static;
  min-width: 0;
  max-width: 100%;
  height: auto;
  max-height: none;
  overflow: visible;
}
.workbench__params .panel__body { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-4); min-width: 0; }
.workbench__main { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-4); min-width: 0; }
.workbench__main .panel__body { min-width: 0; }

@media (min-width: 901px) {
  .workbench { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .workbench {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    overflow: visible;
  }
  .workbench__params,
  .workbench__main {
    position: static;
    height: auto;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 600px) {
  .workbench {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    overflow: visible;
  }
  .workbench__params,
  .workbench__main {
    position: static;
    height: auto;
    max-height: none;
    overflow: visible;
  }
}

.action-row {
  position: static;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-top: var(--s-4);
}
@media (max-width: 600px) {
  .action-row > .btn {
    flex: 1 1 100%;
    text-align: center;
  }
}

.ref-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s-5);
  margin-top: var(--s-6);
}
.ref-layout__aside { min-width: 0; }
.ref-layout__main { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-6); }
.ref-section { min-width: 0; }
.ref-section > h2 { margin-bottom: var(--s-3); padding-bottom: var(--s-2); border-bottom: var(--bw) solid var(--line); }
@media (min-width: 1100px) {
  .ref-layout { grid-template-columns: minmax(0, 1fr) 300px; }
  .ref-layout__aside > .ad { position: sticky; top: calc(var(--topbar-h) + var(--s-4)); }
}

/* Index quick-check: parameters and readout side by side */
.quick {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}
.quick__inputs {
  display: grid;
  gap: var(--s-4);
  padding: var(--s-4);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
}
.quick__inputs .field--wide { grid-column: 1 / -1; }
.quick__out { border-top: var(--bw) solid var(--line); min-width: 0; }
.quick__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4) var(--s-4);
}
.quick .readout { border: 0; border-radius: 0; }
.quick .readout__head { border-top: 0; }
@media (min-width: 640px) {
  .quick__inputs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1000px) {
  .quick { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
  .quick__out { border-top: 0; border-left: var(--bw) solid var(--line); }
}

/* ==========================================================================
   9. Tables (NEC data: mono, aligned, scannable)
   ========================================================================== */
.table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  border: var(--bw) solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.nec-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 20px;
  font-variant-numeric: tabular-nums;
}
.nec-table caption {
  padding: var(--s-2) var(--s-3);
  text-align: left;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  caption-side: top;
}
.nec-table th,
.nec-table td {
  padding: 6px var(--s-3);
  text-align: right;
  white-space: nowrap;
  border-bottom: var(--bw) solid var(--line);
}
.nec-table th:first-child,
.nec-table td:first-child { text-align: left; }
.nec-table thead th {
  position: static;
  background: var(--panel);
  border-bottom: var(--bw) solid var(--line-strong);
  font-family: var(--font-ui);
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
  color: var(--ink-2);
  vertical-align: bottom;
}
.nec-table tbody th {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--ink);
  background: var(--panel);
}
.nec-table tbody tr:last-child th,
.nec-table tbody tr:last-child td { border-bottom: 0; }
.nec-table tbody tr:hover > * { background: var(--field-ro); }
.nec-table tr.is-hit > * { background: var(--amber-wash); font-weight: 700; }
.nec-table td.is-na { color: var(--ink-3); }
.nec-table .col-group { text-align: center; border-left: var(--bw) solid var(--line); }
.nec-table .sep { border-left: var(--bw) solid var(--line); }
.nec-table th.is-left,
.nec-table td.is-left { text-align: left; }
.nec-table tbody tr.is-clickable { cursor: pointer; }
.nec-table tbody tr.is-clickable:hover > *,
.nec-table tbody tr.is-clickable:focus-within > * { background: var(--amber-wash); }
.nec-table .row-link {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.nec-table .row-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
}

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2) var(--s-3);
  margin-bottom: var(--s-3);
}
.table-toolbar__filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  flex: 1 1 auto;
  min-width: 0;
}
.table-toolbar__search { width: min(320px, 100%); }
.table-toolbar__search .input { min-height: 36px; font-family: var(--font-ui); font-size: 14px; }
.table-toolbar__meta {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

/* ==========================================================================
   10. Directory (tool cards)
   ========================================================================== */
.dir { margin-top: var(--s-6); }
.dir__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-2) var(--s-4);
  margin-bottom: var(--s-3);
  padding-bottom: var(--s-2);
  border-bottom: var(--bw) solid var(--line);
}
.dir__head h2 { font-size: 18px; line-height: 28px; }
.dir__count {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 16px;
  color: var(--ink-3);
}
.dir__tools { display: flex; align-items: center; gap: var(--s-3); }
.dir__filter { width: min(260px, 100%); }
.dir__filter .input { min-height: 32px; font-family: var(--font-ui); font-size: 14px; }

.tool-grid {
  display: grid;
  gap: var(--s-3);
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 640px) { .tool-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 900px) { .tool-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.tool {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: var(--s-1);
  padding: var(--s-3) var(--s-4);
  background: var(--panel);
  border: var(--bw) solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
  transition: border-color var(--ease);
}
.tool:hover { border-color: var(--ink); text-decoration: none; }
.tool__name { font-size: 16px; line-height: 24px; font-weight: 600; }
.tool__desc { font-size: 13px; line-height: 20px; color: var(--ink-2); }
.tool__ref {
  margin-top: var(--s-1);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 16px;
  color: var(--ink-3);
}
.tool[hidden] { display: none; }

.ref-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  max-width: none;
  border: var(--bw) solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  grid-template-columns: minmax(0, 1fr);
}
.ref-list li { margin: 0; border-bottom: var(--bw) solid var(--line); }
.ref-list li:last-child { border-bottom: 0; }
.ref-list a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s-3);
  min-height: 44px;
  padding: var(--s-3) var(--s-4);
  color: var(--ink);
  font-weight: 500;
  text-decoration: none;
}
.ref-list a:hover { background: var(--field-ro); }
.ref-list .tool__ref { margin: 0; }
@media (min-width: 900px) {
  .ref-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ref-list li { border-right: var(--bw) solid var(--line); }
  .ref-list li:nth-child(3n) { border-right: 0; }
  .ref-list li:nth-last-child(-n + 3) { border-bottom: 0; }
}

.empty {
  padding: var(--s-4);
  border: var(--bw) solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink-2);
  font-size: 14px;
}

/* ==========================================================================
   11. Ad slots (fixed size, zero layout shift)
   ========================================================================== */
.ad {
  --ad-w: 728px;
  --ad-h: 90px;
  display: block;
  width: var(--ad-w);
  max-width: 100%;
  margin-inline: auto;
}
.ad--leaderboard { --ad-w: 728px; --ad-h: 90px; }
.ad--rect { --ad-w: 300px; --ad-h: 250px; }
@media (max-width: 767px) {
  .ad--leaderboard { --ad-w: 320px; --ad-h: 100px; }
}
.ad__label {
  display: block;
  height: 16px;
  font-size: 12px;
  line-height: 16px;
  color: var(--ink-3);
}
.ad__box {
  display: grid;
  place-items: center;
  width: 100%;
  height: var(--ad-h);
  border: var(--bw) solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  overflow: hidden;
  contain: size layout paint;
}
.ad__box.is-placeholder::after {
  content: attr(data-size);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-3);
}
.ad-row {
  display: flex;
  justify-content: center;
  margin-block: var(--s-6) 0;
  /* label 16px + box height, reserved before any ad loads */
  min-height: calc(16px + 90px);
}
@media (max-width: 767px) {
  .ad-row { min-height: calc(16px + 100px); }
}

/* ==========================================================================
   12. Mobile result bar
   ========================================================================== */
.result-bar { display: none; }

@media (max-width: 900px) {
  .has-result-bar .result-bar {
    position: static;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s-3);
    min-height: 60px;
    padding: var(--s-2) var(--wrap-pad);
    background: var(--panel);
    border-top: var(--bw) solid var(--line);
  }
  .result-bar__label {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12px;
    line-height: 16px;
    color: var(--ink-2);
  }
  .result-bar__value {
    display: block;
    font-family: var(--font-mono);
    font-size: 20px;
    line-height: 26px;
    font-weight: 500;
    color: var(--ink);
    overflow-wrap: anywhere;
  }
  .result-bar.is-pass .result-bar__value { color: var(--pass-text); }
  .result-bar.is-fail .result-bar__value { color: var(--fail-text); }
  .result-bar .btn { min-height: 40px; }
}

/* ==========================================================================
   13. Footer
   ========================================================================== */
.site-footer {
  margin-top: var(--s-7);
  padding-block: var(--s-5) var(--s-6);
  border-top: var(--bw) solid var(--line);
  font-size: 13px;
  line-height: 20px;
  color: var(--ink-2);
}
.site-footer p { max-width: 80ch; }
.site-footer__links { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); margin-top: var(--s-3); }

/* ==========================================================================
   14. Utilities
   ========================================================================== */
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  left: var(--s-2);
  top: -48px;
  z-index: 100;
  padding: var(--s-2) var(--s-3);
  background: var(--amber);
  color: var(--on-amber);
  font-weight: 600;
  border-radius: var(--radius);
}
.skip-link:focus { top: var(--s-2); }
.print-only { display: none; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   15. Print
   ========================================================================== */
@media print {
  @page { margin: 14mm; }

  /* Always print on white with black ink, even from dark mode */
  :root,
  html[data-theme="dark"] {
    color-scheme: light;
    --paper: #FFFFFF;
    --panel: #FFFFFF;
    --ink: #000000;
    --ink-2: #222222;
    --ink-3: #444444;
    --line: #888888;
    --line-strong: #444444;
    --field-ro: #FFFFFF;
    --amber-ink: #000000;
    --amber-wash: #EEEEEE;
    --pass-text: #000000;
    --fail-text: #000000;
  }

  body {
    background: #FFFFFF;
    color: #000000;
    font-size: 11pt;
    line-height: 1.4;
  }

  .topbar,
  .ad,
  .ad-row,
  .result-bar,
  .seg,
  .btn,
  .quick__links,
  .dir__filter,
  .table-toolbar,
  .col-actions,
  .skip-link,
  .readout__empty-hint,
  [data-noprint] { display: none !important; }

  .print-only { display: block; }
  .print-header {
    display: block;
    margin-bottom: 8mm;
    padding-bottom: 3mm;
    border-bottom: 1px solid #000;
    font-size: 10pt;
  }
  .print-header .mono { font-size: 9pt; overflow-wrap: anywhere; }

  .wrap { max-width: none; padding-inline: 0; }
  .workbench { display: block; }
  .workbench__params { position: static; max-height: none; overflow: visible; margin-bottom: 6mm; }
  .readout--pin { position: static; }
  .ref-layout { display: block; }
  .ref-layout__aside { display: none; }

  .panel,
  .readout,
  .note,
  .tool,
  .metric { break-inside: avoid; }

  .table-scroll { overflow: visible; border-color: #888; }
  .nec-table thead { display: table-header-group; }
  .nec-table thead th { position: static; }
  .nec-table tr { break-inside: avoid; }
  .nec-table tr.is-hit > * { background: #EEEEEE; font-weight: 700; text-decoration: underline; }

  .gauge__fill { background: #444444 !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .lamp { background: #FFFFFF !important; color: #000000 !important; border: 1px solid #000; }
  .lamp::before { background: #000; }

  .tool-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  a { color: #000000; text-decoration: none; }
  .site-footer { border-top: 1px solid #000; margin-top: 8mm; }
}
