/* Browser Crawl Engine — shared design system.
 *
 * One file, three surfaces: the marketing site, the customer portal and the
 * operator control panel. They had drifted into separate stylesheets before,
 * and the project has paid for duplicated constants enough times (thirteen
 * copies of a page size, two copies of a routing rule, two copies of a systemd
 * unit) that the tokens live here exactly once.
 *
 * Every page that uses this is served under `style-src 'self'`, so there is no
 * inline style anywhere and no webfont from a third-party origin. The type
 * stack is the system one: it renders on first paint with no network request,
 * which is both the fastest option and the one search ranking rewards.
 */

/* The browser's own [hidden] rule is weaker than any class that sets display,
 * so without this a hidden panel stays visible. Learned the hard way: the login
 * form rendered on top of the dashboard after a successful sign-in. */
[hidden] { display: none !important; }

:root {
  color-scheme: light dark;

  /* Surfaces, from furthest back to nearest front. */
  --bg: #f6f7f9;
  --bg-soft: #eef0f4;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --line: #e2e6eb;
  --line-soft: #eef0f3;

  /* Text, in descending prominence. --ink-3 is for things that must be
   * available but must not compete: timestamps, units, row counts. */
  --ink: #15181d;
  --ink-2: #555f6b;
  --ink-3: #8a94a0;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-ink: #ffffff;
  --accent-soft: #eef0fe;
  --accent-line: #c7cbfa;

  /* Status colours. Reserved for state. A data series never borrows one of
   * these: a reader takes green to mean "good", not "this is the memory line". */
  --ok: #0f8a5f;
  --ok-soft: #e6f5ee;
  --warn: #a86a00;
  --warn-soft: #fdf3e0;
  --bad: #c0362c;
  --bad-soft: #fdeceb;
  --info: #0b6bcb;
  --info-soft: #e7f1fd;

  /* Data series, checked with the dataviz palette validator on this page's own
   * card surfaces (#ffffff light, #171b22 dark, all-pairs mode).
   * Light: CVD separation ΔE 23.1 · normal vision 24.0.
   * Dark:  19.6 · 20.9, both ≥ 3:1 against the surface. */
  --series-1: #2a78d6;
  --series-2: #1baf7a;

  /* One spacing scale. Numbers outside it are a smell: they are usually
   * someone nudging a single element instead of fixing the rhythm. */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px -12px rgba(16, 24, 40, .18);
  --shadow-lg: 0 2px 4px rgba(16, 24, 40, .04), 0 24px 48px -16px rgba(16, 24, 40, .22);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  /* Tap targets. 44px is the smallest reliably hittable control on a phone;
   * anything smaller is a desktop control that happens to render on mobile. */
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1016;
    --bg-soft: #11151c;
    --panel: #171b22;
    --panel-2: #1c212a;
    --line: #272d38;
    --line-soft: #1f242d;
    --ink: #e9ecf1;
    --ink-2: #9ba5b3;
    --ink-3: #6c7784;
    --accent: #7c74ff;
    --accent-hover: #918bff;
    --accent-ink: #0d1016;
    --accent-soft: #1f2240;
    --accent-line: #3b3b7a;
    --ok: #3ddc97;
    --ok-soft: #10281f;
    --warn: #e8b04b;
    --warn-soft: #2a2113;
    --bad: #ff6b5e;
    --bad-soft: #2c1614;
    --info: #63aef7;
    --info-soft: #11243a;
    --series-1: #3987e5;
    --series-2: #2fc48c;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .7);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, .3), 0 24px 48px -16px rgba(0, 0, 0, .75);
  }
}

:root[data-theme="dark"] {
  --bg: #0d1016;
  --bg-soft: #11151c;
  --panel: #171b22;
  --panel-2: #1c212a;
  --line: #272d38;
  --line-soft: #1f242d;
  --ink: #e9ecf1;
  --ink-2: #9ba5b3;
  --ink-3: #6c7784;
  --accent: #7c74ff;
  --accent-hover: #918bff;
  --accent-ink: #0d1016;
  --accent-soft: #1f2240;
  --accent-line: #3b3b7a;
  --ok: #3ddc97;
  --ok-soft: #10281f;
  --warn: #e8b04b;
  --warn-soft: #2a2113;
  --bad: #ff6b5e;
  --bad-soft: #2c1614;
  --info: #63aef7;
  --info-soft: #11243a;
  --series-1: #3987e5;
  --series-2: #2fc48c;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.6 var(--sans);
  /* Without this the page can scroll sideways on a phone the moment any one
   * element overflows, and the reader cannot tell which one did it. */
  overflow-x: hidden;
}

h1, h2, h3, h4 { margin: 0 0 var(--s3); line-height: 1.25; font-weight: 650; letter-spacing: -.011em; }
h1 { font-size: clamp(28px, 5vw, 44px); letter-spacing: -.022em; }
h2 { font-size: clamp(22px, 3.4vw, 30px); letter-spacing: -.018em; }
h3 { font-size: clamp(18px, 2.4vw, 21px); }
h4 { font-size: 16px; }
p  { margin: 0 0 var(--s4); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, kbd, pre, samp { font-family: var(--mono); font-size: .92em; }
code {
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: .12em .38em;
}
pre {
  margin: 0 0 var(--s4);
  padding: var(--s4);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  line-height: 1.55;
}
pre code { background: none; border: 0; padding: 0; }

hr { border: 0; border-top: 1px solid var(--line); margin: var(--s6) 0; }

/* Keyboard focus must be visible on every interactive element. Removing the
 * outline without replacing it makes the whole page unusable without a mouse. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- layout ---------- */

.container {
  width: 100%;
  max-width: 1120px;
  margin-inline: auto;
  /* 16px of gutter on a phone. Text touching the screen edge is the single
   * most common mobile layout defect. */
  padding-inline: var(--s4);
}
.container-narrow { max-width: 760px; }
.container-wide { max-width: 1320px; }

.stack > * + * { margin-top: var(--s4); }
.stack-lg > * + * { margin-top: var(--s6); }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  align-items: center;
}
.row-between { justify-content: space-between; }
.row-end { justify-content: flex-end; }
.grow { flex: 1 1 auto; min-width: 0; }

.grid { display: grid; gap: var(--s4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.section { padding-block: clamp(var(--s6), 7vw, var(--s8)); }

/* ---------- surfaces ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s5);
  box-shadow: var(--shadow-sm);
}
.card-flat { box-shadow: none; }
.card-pad-sm { padding: var(--s4); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  align-items: center;
  justify-content: space-between;
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.panel-head h2, .panel-head h3 { margin: 0; font-size: 17px; }
.panel-body { padding: var(--s5); }

/* A number and what it means. The label goes UNDER the number: the eye lands
 * on the figure first and the label answers the question it just raised. */
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s4) var(--s5);
}
.stat-value {
  display: block;
  font-size: clamp(24px, 3.6vw, 30px);
  font-weight: 650;
  line-height: 1.15;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  display: block;
  margin-top: var(--s1);
  font-size: 13px;
  color: var(--ink-2);
}
.stat-note { display: block; margin-top: var(--s2); font-size: 12px; color: var(--ink-3); }

/* ---------- controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: var(--tap);
  padding: 0 var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--ink);
  font: 600 14px/1 var(--sans);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color .14s ease, border-color .14s ease, transform .06s ease;
}
.btn:hover { background: var(--bg-soft); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--bg-soft); color: var(--ink); }

.btn.danger { border-color: var(--bad); color: var(--bad); background: var(--panel); }
.btn.danger:hover { background: var(--bad-soft); }

.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 var(--s3); font-size: 13px; }
.btn.lg { min-height: 52px; padding: 0 var(--s5); font-size: 16px; }

label, .label {
  display: block;
  margin-bottom: var(--s2);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="search"], input[type="url"],
select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--ink);
  /* 16px exactly: iOS Safari zooms the whole page in when a focused field has
   * a smaller font, and the reader then has to pinch back out. */
  font: 400 16px/1.5 var(--sans);
}
textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
input:disabled, select:disabled, textarea:disabled {
  background: var(--bg-soft); color: var(--ink-3); cursor: not-allowed;
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }

.field { margin-bottom: var(--s4); }
.field-hint { margin: var(--s2) 0 0; font-size: 13px; color: var(--ink-3); }
.field-error { margin: var(--s2) 0 0; font-size: 13px; color: var(--bad); }

.checkline { display: flex; gap: var(--s3); align-items: flex-start; }
.checkline input[type="checkbox"] {
  width: 20px; height: 20px; min-height: 0; margin: 2px 0 0; flex: none;
  accent-color: var(--accent);
}
.checkline label { margin: 0; font-weight: 400; color: var(--ink); }

/* ---------- badges and notices ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  padding: 3px var(--s2);
  border-radius: var(--radius-pill);
  background: var(--bg-soft);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.ok   { background: var(--ok-soft);   color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad  { background: var(--bad-soft);  color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.notice {
  padding: var(--s4);
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  font-size: 14px;
}
.notice.ok   { border-left-color: var(--ok);   background: var(--ok-soft); }
.notice.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.notice.bad  { border-left-color: var(--bad);  background: var(--bad-soft); }
.notice.info { border-left-color: var(--info); background: var(--info-soft); }
.notice :last-child { margin-bottom: 0; }

/* ---------- tables ---------- */

/* The wrapper scrolls, not the page. A wide table inside a page that scrolls
 * sideways drags the navigation off-screen with it. */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  padding: var(--s3) var(--s4);
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
th {
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-3);
  background: var(--panel-2);
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono { font-family: var(--mono); font-size: 13px; }

.table-empty { padding: var(--s7) var(--s4); text-align: center; color: var(--ink-3); }

/* Below 640px a wide table becomes a stack of labelled rows. Horizontal
 * scrolling works, but on a phone it hides columns the reader does not know
 * exist; `data-label` puts the header back beside each value. */
@media (max-width: 640px) {
  table.stacked, table.stacked tbody, table.stacked tr, table.stacked td {
    display: block;
    width: 100%;
  }
  table.stacked thead { display: none; }
  table.stacked tr {
    margin-bottom: var(--s3);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel);
    padding: var(--s2) 0;
  }
  table.stacked td {
    display: flex;
    justify-content: space-between;
    gap: var(--s4);
    border: 0;
    padding: var(--s2) var(--s4);
    text-align: right;
  }
  table.stacked td::before {
    content: attr(data-label);
    font-size: 12px;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ink-3);
    text-align: left;
    flex: none;
  }
}

/* ---------- pagination ---------- */

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  align-items: center;
  justify-content: space-between;
  padding: var(--s3) var(--s4);
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 13px;
  color: var(--ink-2);
}
.pager-controls { display: flex; gap: var(--s2); align-items: center; }

/* ---------- utilities ---------- */

.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.mt2 { margin-top: var(--s2); }  .mt3 { margin-top: var(--s3); }
.mt4 { margin-top: var(--s4); }  .mt5 { margin-top: var(--s5); }
.mt6 { margin-top: var(--s6); }
.mb3 { margin-bottom: var(--s3); } .mb4 { margin-bottom: var(--s4); }
.mb5 { margin-bottom: var(--s5); }

.lede { font-size: clamp(17px, 2.2vw, 20px); line-height: 1.6; color: var(--ink-2); }

/* Visible to a screen reader, not to the eye. Used for headings that give a
 * region a name the layout already makes obvious visually. */
.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;
}

/* The first thing a keyboard user tabs to on every page. */
.skip-link {
  position: absolute;
  left: var(--s4);
  top: -60px;
  z-index: 100;
  padding: var(--s3) var(--s4);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: top .15s ease;
}
.skip-link:focus { top: var(--s4); text-decoration: none; }

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Respect the system setting. Vestibular disorders are a real accessibility
 * requirement, not a preference. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  body { background: #fff; color: #000; }
  .no-print { display: none !important; }
}
