/* ────────────────────────────────────────────────────────────── */
/* DESIGN TOKENS                                                   */
/* ────────────────────────────────────────────────────────────── */
:root {
  /* Type stack */
  --font-display: "Fraunces", "Iowan Old Style", "Source Serif Pro", Georgia, serif;
  --font-body:    "DM Sans", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  --font-mono:    "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;

  /* Palette — warm paper / ink */
  --paper:        #f3eddf;
  --cream:        #faf6ec;
  --surface:      #ffffff;
  --ink:          #1c1814;
  --ink-soft:     #4a4540;
  --muted:        #857d72;
  --rule:         #e0d6c1;
  --rule-strong:  #b9ac93;

  --accent:       #1f3d63;
  --accent-hover: #294f80;
  --accent-soft:  #e8edf3;

  --danger:       #a13a2c;
  --danger-soft:  #f7ebe8;

  --ok:           #3a6a3a;

  /* Spatial */
  --r-sm: 4px;
  --r-md: 6px;
  --r-pill: 999px;

  --shadow-soft: 0 1px 0 rgba(28,24,20,0.04), 0 8px 24px -12px rgba(28,24,20,0.10);
}

/* ────────────────────────────────────────────────────────────── */
/* RESET & BASE                                                    */
/* ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  background-color: var(--paper);
  /* Subtle SVG noise overlay — adds organic warmth without visual weight */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='320' height='320'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' seed='5'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.05 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  color: var(--ink);
  font-family: var(--font-body);
  font-feature-settings: "ss01", "cv01";
  line-height: 1.5;
  min-height: 100vh;
}

/* Quietly styled scrollbars — present, but never the protagonist */
* { scrollbar-width: thin; scrollbar-color: var(--rule) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--rule);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--rule-strong); background-clip: padding-box; }

button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }

::selection { background: var(--accent); color: var(--surface); }

/* Custom focus ring */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: 2px;
}

/* ────────────────────────────────────────────────────────────── */
/* TOP BAR                                                         */
/* ────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 32px;
  background: var(--cream);
  border-bottom: 1px solid var(--rule);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  color: var(--accent);
  flex-shrink: 0;
  transform: translateY(1px);
}
.brand-name {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
/* Byline button — visually identical to the prior <span>, but focusable
   and hosting the contact popover. */
.brand-meta {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.01em;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  transition: color .12s ease;
}
.brand-meta:hover { color: var(--ink); }
.brand-meta:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
.brand-meta[aria-expanded="true"] { color: var(--ink); }
.brand-version {
  display: inline-block;
  font-family: var(--font-mono);
  font-style: normal;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--ink);
  background: var(--accent-soft);
  padding: 2px 6px;
  border-radius: 3px;
  margin-right: 6px;
  transform: translateY(-1px);
}

.topbar-right {
  display: flex;
  align-items: baseline;
  gap: 18px;
  position: relative;  /* anchor for .contact-popover */
}

/* Contact popover — appears below the byline button on click. */
.contact-popover {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  min-width: 280px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 14px 16px 16px;
  z-index: 80;
  box-shadow: 0 10px 28px -10px rgba(28,24,20,0.22);
  animation: contact-pop .22s cubic-bezier(.2,.8,.2,1);
}
@keyframes contact-pop {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.contact-popover-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 6px;
}
.contact-popover-email {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  margin: 0 0 10px;
  word-break: break-all;
  user-select: all;
}
.contact-popover-actions {
  display: flex;
  gap: 8px;
}
.contact-popover-btn,
.contact-popover-link {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  text-decoration: none;
  transition: background-color .12s ease, color .12s ease, border-color .12s ease;
}
.contact-popover-btn {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--rule);
}
.contact-popover-btn:hover { border-color: var(--rule-strong); background: var(--cream); }
.contact-popover-btn.is-copied {
  background: var(--ok);
  color: var(--surface);
  border-color: var(--ok);
}
.contact-popover-link {
  background: var(--accent);
  color: var(--surface);
  border: 1px solid var(--accent);
}
.contact-popover-link:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }

.locale-picker {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  padding: 4px 6px 4px 8px;
  cursor: pointer;
}
.locale-picker:hover { border-color: var(--rule-strong); }
.locale-picker:focus-visible { outline: 2px solid var(--accent); }

/* ────────────────────────────────────────────────────────────── */
/* PAGE CONTAINER                                                  */
/* ────────────────────────────────────────────────────────────── */
#root { padding: 32px; max-width: 1600px; margin: 0 auto; }

.error { color: var(--danger); padding: 24px 0; }

/* ────────────────────────────────────────────────────────────── */
/* LANDING                                                         */
/* ────────────────────────────────────────────────────────────── */
#root > h2,
.landing-head {
  font-family: var(--font-display);
  font-weight: 500;
  font-style: italic;
  font-size: clamp(28px, 4vw, 38px);
  line-height: 1.1;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}
#root > p {
  color: var(--muted);
  font-size: 15px;
  max-width: 56ch;
  margin: 0 0 32px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.preset-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 22px 24px 24px 26px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
  position: relative;
  overflow: hidden;
  transition: border-color .25s ease, transform .25s ease;
}
.preset-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--accent);
  transform: scaleY(0);
  transform-origin: top center;
  transition: transform .35s cubic-bezier(.2,.8,.2,1);
}
.preset-card::after {
  content: "→";
  position: absolute;
  top: 22px; right: 22px;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--muted);
  transition: transform .25s ease, color .25s ease;
}
.preset-card:hover {
  border-color: var(--rule-strong);
  transform: translateY(-1px);
}
.preset-card:hover::before { transform: scaleY(1); }
.preset-card:hover::after { color: var(--accent); transform: translateX(3px); }
.preset-card h3 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 19px;
  letter-spacing: -0.005em;
}
.preset-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  padding-right: 24px;
}

.open-by-url { margin-top: 48px; max-width: 540px; }
.open-by-url h2 {
  margin: 0 0 10px;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.open-by-url .row { gap: 8px; }
.open-by-url input { flex: 1; }

/* ────────────────────────────────────────────────────────────── */
/* SCENARIO SCREEN — DESKTOP                                       */
/* ────────────────────────────────────────────────────────────── */
.scenario-screen {
  display: grid;
  /* User-resizable rail: --rail-w drives column 1; column 2 is the drag
     handle; column 3 fills the remainder. */
  grid-template-columns: var(--rail-w, 380px) 14px 1fr;
  gap: 0;
  align-items: stretch;
  /* Lock to the viewport height (minus topbar + page padding) so both
     columns are the same height and each scrolls its own content. */
  height: calc(100dvh - 110px);
}

/* Drag handle between the two columns. Visually a thin centred grip;
   active hit area is the full 14px column width so the cursor latches
   easily. */
.rail-resizer {
  position: relative;
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
}
.rail-resizer-grip {
  width: 2px;
  height: 36px;
  border-radius: 999px;
  background: var(--rule);
  transition: background-color .15s ease, height .2s ease;
}
.rail-resizer:hover .rail-resizer-grip,
.rail-resizer.dragging .rail-resizer-grip,
.rail-resizer:focus-visible .rail-resizer-grip {
  background: var(--accent);
  height: 60px;
}
.rail-resizer:focus-visible { outline: none; }
/* Apply user-select: none to the body while actively dragging
   (set by JS) so text selection doesn't trigger mid-drag. */
body.is-resizing { cursor: col-resize; user-select: none; }
body.is-resizing * { user-select: none !important; }

.left-rail, .right-pane {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 24px;
  min-width: 0;  /* allow grid children to shrink below content min-content */
  min-height: 0; /* allow internal scroll under fixed grid height */
  overflow-y: auto;
}

.right-pane { display: flex; flex-direction: column; gap: 20px; }
.right-pane > * { min-width: 0; }

/* Page-load entrance — opacity-only so descendants can use position: fixed */
.left-rail  { animation: fade-in 360ms cubic-bezier(.2,.8,.2,1) both; }
.right-pane { animation: fade-in 360ms cubic-bezier(.2,.8,.2,1) 80ms both; }
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Scenario-head: name + actions */
.scenario-head { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
#scenario-name {
  width: 100%;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 24px;
  line-height: 1.2;
  border: none;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  padding: 6px 0 8px;
  background: transparent;
  letter-spacing: -0.005em;
}
#scenario-name:focus { outline: none; border-bottom-color: var(--accent); }

.scenario-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Editor tab nav (mobile only) */
.editor-tabs { display: none; }
.editor-tabs button {
  flex: 1;
  background: transparent;
  border: 1px solid var(--rule);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: var(--r-sm);
  color: var(--muted);
}
.editor-tabs button.active {
  background: var(--ink);
  color: var(--cream);
  border-color: var(--ink);
}

/* ────────────────────────────────────────────────────────────── */
/* EDITOR SECTIONS — magazine-style numbered headings              */
/* ────────────────────────────────────────────────────────────── */
#editors .section { margin-bottom: 28px; }
#editors .section:last-child { margin-bottom: 0; }

/* Section head is a button so it's natively focusable + keyboard-accessible */
#editors .section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 0 0 12px;
  padding: 0 0 10px;
  border: none;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  border-radius: 0;
  transition: border-color .12s ease;
}
#editors .section-head:hover { border-bottom-color: var(--rule-strong); }
#editors .section-head:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
#editors .section-head h3 {
  flex: 1;
  margin: 0; padding: 0; border: none;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--ink);
}
#editors .collapse-marker {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
  display: inline-block;
  transition: transform .15s ease;
}
#editors .section[data-collapsed] .collapse-marker { transform: rotate(-90deg); }
#editors .section[data-collapsed] .section-head { margin-bottom: 0; }
#editors .section[data-collapsed] .section-body { display: none; }
#editors .section-body {
  animation: section-expand .18s ease-out;
}
@keyframes section-expand {
  from { opacity: 0; }
  to { opacity: 1; }
}
.section-num {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 7px;
  border-radius: 2px;
  flex-shrink: 0;
}
#editors .section .count {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
  flex-shrink: 0;
}

.row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.row:last-child { margin-bottom: 0; }

/* Step type rows */
#step-types .row { gap: 6px; }
#step-types .row input { flex: 1; }

/* Machine cards */
.machine-row {
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 10px 12px 12px;
  margin-bottom: 8px;
  background: var(--cream);
}
.machine-row > .row { margin-bottom: 8px; }

/* Mono pill (display_id) — code-tag aesthetic */
input.mono-pill {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-soft);
  text-align: center;
  padding: 6px 8px;
  width: 96px;
  flex-shrink: 0;
  border-radius: var(--r-sm);
  transition: background-color .12s ease, border-color .12s ease;
}
input.mono-pill:focus {
  background: var(--surface);
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(31,61,99,0.10);
}

/* Step-type checkboxes inside machine card */
.step-type-checks {
  display: flex;
  flex-wrap: wrap;
  column-gap: 14px;
  row-gap: 5px;
  font-size: 12px;
  color: var(--ink-soft);
  padding-top: 4px;
  border-top: 1px dashed var(--rule);
  margin-top: 2px;
}
.step-type-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.step-type-check input { margin: 0; accent-color: var(--accent); }

/* Job cards */
.job-card {
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 14px;
  margin-bottom: 10px;
  background: var(--cream);
}
.job-card > .row:first-child { margin-bottom: 6px; }
.job-card .steps {
  margin: 10px 0;
  padding-top: 8px;
  border-top: 1px dashed var(--rule);
}
.job-card label {
  font-size: 12px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Step-row inside a job */
.step-row-wrap {
  border-left: 2px solid var(--rule);
  padding-left: 8px;
  margin-bottom: 8px;
}
.step-row-wrap.orphan {
  border-left-color: var(--danger);
  background: var(--danger-soft);
  padding: 4px 6px 4px 8px;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.step-row { gap: 6px; }
.step-row > input[type="text"] { flex: 1; min-width: 0; }
.step-row > input[type="number"] { width: 60px; flex-shrink: 0; }
.step-row > select { min-width: 90px; }

.elig-picker {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  font-size: 12px;
}
.elig-picker label { gap: 6px; padding: 2px 0; }
.elig-picker input { accent-color: var(--accent); }

/* ────────────────────────────────────────────────────────────── */
/* RIGHT PANE — RUN CONTROLS                                       */
/* ────────────────────────────────────────────────────────────── */
.run-controls {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  padding: 16px 0 4px;
  border-bottom: 1px solid var(--rule);
}
.control-group { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.control-group:nth-child(2) { flex: 1; min-width: 220px; }
.control-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.control-label .readout {
  display: inline-block;
  margin-left: 6px;
  color: var(--ink);
  font-feature-settings: "tnum";
}

.advanced { font-size: 13px; }
.advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 6px 0;
}
.advanced summary:hover { color: var(--ink); }
.advanced .row { padding-top: 8px; }

/* ────────────────────────────────────────────────────────────── */
/* RIGHT PANE — KPIs                                               */
/* ────────────────────────────────────────────────────────────── */
.summary-row, .kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.summary-row .kpi, .kpi-grid .kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 24px 20px 18px;
  border-right: 1px solid var(--rule);
  position: relative;
}
.summary-row .kpi:last-child, .kpi-grid .kpi:last-child { border-right: none; }
/* Editorial accent rule above each KPI — magazine stat-block flourish */
.summary-row .kpi::before {
  content: "";
  position: absolute;
  top: 14px; left: 20px;
  width: 16px; height: 2px;
  background: var(--accent);
}
.summary-row .kpi {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.summary-row .kpi b {
  display: block;
  font-family: var(--font-display);
  font-weight: 600;
  font-style: normal;
  font-size: 30px;
  line-height: 1.05;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin-top: 4px;
  font-feature-settings: "tnum";
}

/* ────────────────────────────────────────────────────────────── */
/* RIGHT PANE — GANTT                                              */
/* ────────────────────────────────────────────────────────────── */
.gantt-card {
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 14px;
  background: var(--surface);
}
.gantt-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.gantt-head h3 {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 16px;
  margin: 0;
}
.gantt-controls {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.gantt-head .axis-mark {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* Segmented control — tight mono-caps toggle for Y-axis grouping. */
.seg-control {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.seg-control button {
  border: none;
  background: transparent;
  padding: 5px 11px;
  color: var(--muted);
  cursor: pointer;
  border-radius: 0;
  transition: background-color .12s ease, color .12s ease;
}
.seg-control button + button { border-left: 1px solid var(--rule); }
.seg-control button:hover:not(.active) { background: var(--cream); color: var(--ink); }
.seg-control button.active {
  background: var(--ink);
  color: var(--cream);
}
.seg-control button:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
.gantt {
  width: 100%;
  height: 480px;
  min-height: 320px;
}
.gantt-scroll { overflow: hidden; }

/* ────────────────────────────────────────────────────────────── */
/* INPUTS                                                          */
/* ────────────────────────────────────────────────────────────── */
input[type="text"],
input[type="number"],
input[type="search"],
select {
  font-size: 13px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  color: var(--ink);
  transition: border-color .12s ease, background-color .12s ease;
}
input[type="text"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
input[type="text"]::placeholder { color: var(--muted); }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; min-width: 120px;
  height: 22px; background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 2px; background: var(--rule); border-radius: 999px;
}
input[type="range"]::-moz-range-track {
  height: 2px; background: var(--rule); border-radius: 999px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
  margin-top: -6px;
  box-shadow: 0 0 0 1px var(--accent);
  transition: transform .12s ease;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.1); }

input[type="checkbox"] { accent-color: var(--accent); }

/* ────────────────────────────────────────────────────────────── */
/* BUTTONS                                                         */
/* ────────────────────────────────────────────────────────────── */
button {
  cursor: pointer;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 12px;
  transition: border-color .12s ease, background .12s ease, transform .06s ease;
  letter-spacing: 0.005em;
}
button:hover { border-color: var(--rule-strong); background: var(--cream); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button.primary, #run {
  background: var(--accent);
  color: var(--surface);
  border-color: var(--accent);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding: 12px 30px;
  align-self: stretch;
  transition: background-color .15s ease, transform .12s ease, box-shadow .25s ease;
}
#run:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 8px 18px -8px rgba(31, 61, 99, 0.45);
}
#run:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 6px -3px rgba(31, 61, 99, 0.40);
}
#run:disabled { opacity: 0.55; cursor: not-allowed; }

/* small × delete buttons */
button[data-del] {
  width: 28px; height: 28px;
  padding: 0;
  font-size: 16px;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
  flex-shrink: 0;
}
button[data-del]:hover { color: var(--danger); background: var(--danger-soft); border-color: transparent; }

/* + Add buttons */
button[data-add], button[data-add-step] {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--rule-strong);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  padding: 8px;
  margin-top: 6px;
}
button[data-add]:hover:not(:disabled),
button[data-add-step]:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

button:disabled,
select:disabled,
input:disabled { opacity: 0.5; cursor: not-allowed; }

/* eligibility small buttons */
button[data-elig], button[data-elig-clear] {
  font-size: 11px;
  padding: 4px 8px;
  background: transparent;
  border-color: var(--rule);
}

/* ────────────────────────────────────────────────────────────── */
/* VALIDATION BANNER                                               */
/* ────────────────────────────────────────────────────────────── */
#validation-banner {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-left-width: 3px;
  border-radius: var(--r-sm);
  padding: 12px 16px 12px 14px;
  font-size: 13px;
  font-weight: 500;
  animation: slide-down 220ms cubic-bezier(.2,.8,.2,1);
}
@keyframes slide-down {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ────────────────────────────────────────────────────────────── */
/* MUTED                                                           */
/* ────────────────────────────────────────────────────────────── */
.muted { color: var(--muted); }
em.muted { font-style: italic; font-family: var(--font-display); }

/* ────────────────────────────────────────────────────────────── */
/* TABLET HORIZONTAL  (900–1199px)                                 */
/* ────────────────────────────────────────────────────────────── */
@media (max-width: 1199px) {
  .topbar { padding: 14px 24px; }
  #root { padding: 24px; }

  /* Keep the three-track resizable grid; tighten the rail's default width
     so the right pane has more breathing room at this size. */
  .scenario-screen { grid-template-columns: var(--rail-w, 320px) 14px 1fr; }
  .left-rail, .right-pane { padding: 18px; }

  #scenario-name { font-size: 21px; }
  #editors .section h3 { font-size: 16px; }

  .summary-row, .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .summary-row .kpi { padding: 20px 14px 14px; }
  .summary-row .kpi::before { top: 12px; left: 14px; width: 14px; }
  .summary-row .kpi b { font-size: 25px; }

  .gantt { height: 420px; }
}

/* ────────────────────────────────────────────────────────────── */
/* MOBILE / VERTICAL TABLET  (≤ 899px)                             */
/* ────────────────────────────────────────────────────────────── */
@media (max-width: 899px) {
  html { font-size: 14px; }
  .topbar { padding: 12px 16px; }
  #root { padding: 16px; padding-bottom: 96px; /* room for sticky run */ }

  .scenario-screen {
    grid-template-columns: 1fr;
    gap: 14px;
    height: auto;       /* unlock viewport-height clamp on mobile */
    max-height: none;
  }
  .rail-resizer { display: none; }  /* single column on mobile — no drag */
  .left-rail, .right-pane {
    padding: 16px;
    border-radius: var(--r-md);
    overflow: visible;  /* restore page-scroll behaviour on mobile */
  }
  .right-pane { min-height: 0; }

  #scenario-name { font-size: 22px; }
  .scenario-actions button { flex: 1; min-width: 0; }

  /* Editor tabs become visible & functional */
  .editor-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
  #editors[data-active-tab="step-types"] [data-tab]:not([data-tab="step-types"]),
  #editors[data-active-tab="machines"]  [data-tab]:not([data-tab="machines"]),
  #editors[data-active-tab="jobs"]      [data-tab]:not([data-tab="jobs"]) {
    display: none;
  }
  /* On mobile, the tab system handles one-section-at-a-time; collapse is
     redundant. Hide marker, keep content visible regardless. */
  #editors .collapse-marker { display: none; }
  #editors .section-head { cursor: default; pointer-events: none; }
  #editors .section[data-collapsed] .section-body { display: block; }

  /* Run controls: stack tighter */
  .run-controls { gap: 12px; padding: 12px 0 4px; }
  #run {
    position: fixed;
    left: 16px; right: 16px; bottom: 16px;
    z-index: 50;
    padding: 14px;
    box-shadow: 0 6px 24px -8px rgba(28,24,20,0.30);
    align-self: auto;
    width: auto;
  }

  .summary-row, .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .summary-row .kpi { border-right: 1px solid var(--rule); padding: 20px 14px 14px; }
  .summary-row .kpi::before { top: 12px; left: 14px; width: 14px; }
  .summary-row .kpi:nth-child(2n) { border-right: none; }
  .summary-row .kpi:nth-child(-n+2) { border-bottom: 1px solid var(--rule); }
  .summary-row .kpi b { font-size: 24px; }

  /* Gantt scrolls horizontally on mobile */
  .gantt-card { padding: 10px; }
  .gantt { height: 380px; min-width: 600px; }
  .gantt-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Step-type checkboxes wrap tighter */
  .step-type-checks { font-size: 11px; column-gap: 10px; }

  /* Step-row stacks display_id pill above name */
  .step-row { flex-wrap: wrap; }
  .step-row > input[type="text"] { flex: 1 1 100%; }

  /* Open by URL: stack input + button */
  .open-by-url .row { flex-wrap: wrap; }
  .open-by-url input { flex: 1 1 100%; max-width: none; }
  .open-by-url button { flex: 1; }
}

/* ────────────────────────────────────────────────────────────── */
/* BI DASHBOARD (Phase 4)                                          */
/* ────────────────────────────────────────────────────────────── */
.bi-screen {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 1600px;
  margin: 0 auto;
}

.bi-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}
.bi-head-left { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.bi-back {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.bi-back:hover { color: var(--ink); text-decoration: none; }
.bi-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(22px, 3vw, 32px);
  letter-spacing: -0.01em;
  margin: 0;
  display: inline-flex;
  align-items: baseline;
  gap: 12px;
}
.bi-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-style: normal;
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--surface);
  background: var(--danger);
  padding: 3px 8px;
  border-radius: 999px;
  position: relative;
  top: -3px;
}
.bi-tag::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--surface);
  margin-right: 5px;
  animation: bi-pulse 1.4s ease-in-out infinite;
}
@keyframes bi-pulse {
  0%,100% { opacity: 0.4; }
  50%     { opacity: 1; }
}

/* Controls bar — play, pause, reset, speed segments */
.bi-controls {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.bi-btn-primary, .bi-btn-secondary {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 8px 18px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background-color .15s ease, transform .12s ease;
}
.bi-btn-primary {
  background: var(--accent);
  color: var(--surface);
  border: 1px solid var(--accent);
}
.bi-btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); transform: translateY(-1px); }
.bi-btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.bi-btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--rule);
  padding: 8px 12px;
}
.bi-btn-secondary:hover:not(:disabled) { border-color: var(--rule-strong); }
.bi-btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }

/* KPI strip */
.bi-kpis {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  overflow: hidden;
}
.bi-kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 22px 18px 16px;
  border-right: 1px solid var(--rule);
  position: relative;
}
.bi-kpi:last-child { border-right: none; }
.bi-kpi::before {
  content: '';
  position: absolute;
  top: 14px; left: 18px;
  width: 14px; height: 2px;
  background: var(--accent);
}
.bi-kpi--danger::before { background: var(--danger); }
.bi-kpi--ok::before     { background: var(--ok); }
.bi-kpi-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.bi-kpi-value {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: -0.01em;
  font-feature-settings: "tnum";
  color: var(--ink);
  margin-top: 2px;
  line-height: 1.05;
}
.bi-kpi--danger .bi-kpi-value { color: var(--danger); }
.bi-kpi--ok     .bi-kpi-value { color: var(--ok); }
.bi-kpi-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  margin-top: 1px;
}

/* Gantt card */
.bi-gantt-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 14px;
}
.bi-gantt-card .gantt {
  width: 100%;
  height: 420px;
  min-height: 280px;
}

/* Bottom: jobs + telemetry */
.bi-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.bi-jobs-card, .bi-telemetry-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 18px;
  min-height: 240px;
}
.bi-section-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 16px;
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
}

/* Per-job rows */
.bi-jobs { display: flex; flex-direction: column; gap: 6px; }
.bi-job-row {
  display: grid;
  grid-template-columns: 80px 1fr 1.2fr 70px 100px;
  gap: 10px;
  align-items: center;
  padding: 8px 4px;
  border-bottom: 1px dashed var(--rule);
  font-size: 13px;
}
.bi-job-row:last-child { border-bottom: none; }
.bi-job-code {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 6px;
  border-radius: var(--r-sm);
  text-align: center;
}
.bi-job-name { color: var(--ink); font-weight: 500; }
.bi-job-step { color: var(--ink-soft); font-size: 12px; }
.bi-job-machine {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-transform: uppercase;
}
.bi-job-status {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 999px;
  text-align: center;
}
.bi-status--pending     { color: var(--muted);  background: var(--cream); }
.bi-status--in_progress { color: var(--surface); background: var(--accent); }
.bi-status--done        { color: var(--surface); background: var(--ok); }
.bi-status--late        { color: var(--surface); background: var(--danger); }

/* Telemetry log */
.bi-telemetry {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 280px;
  overflow-y: auto;
}
.bi-tel-row {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 6px 4px;
  border-bottom: 1px dashed var(--rule);
  font-size: 12px;
  animation: bi-tel-in .25s ease-out;
}
@keyframes bi-tel-in {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: 1; transform: none; }
}
.bi-tel-row:last-child { border-bottom: none; }
.bi-tel-time {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-feature-settings: "tnum";
}
.bi-tel-msg b {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.04em;
}
.bi-tel-row[data-kind="step_started"]  .bi-tel-msg::before { content: '▸ '; color: var(--accent); }
.bi-tel-row[data-kind="step_finished"] .bi-tel-msg::before { content: '✓ '; color: var(--ok); }
.bi-tel-dev {
  font-family: var(--font-mono);
  font-size: 10px;
  margin-left: 4px;
  color: var(--muted);
}
.bi-tel-dev--late { color: var(--danger); font-weight: 600; }
.bi-tel-bd {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--danger);
  background: var(--danger-soft);
  padding: 1px 5px;
  border-radius: 2px;
  margin-left: 4px;
}

/* Tablet horizontal — KPI grid wraps */
@media (max-width: 1199px) {
  .bi-kpis { grid-template-columns: repeat(3, 1fr); }
  .bi-kpi:nth-child(3n) { border-right: none; }
  .bi-kpi:nth-child(-n+3) { border-bottom: 1px solid var(--rule); }
  .bi-bottom { grid-template-columns: 1fr; }
}

/* Mobile — single column, compact controls */
@media (max-width: 899px) {
  .bi-kpis { grid-template-columns: repeat(2, 1fr); }
  .bi-kpi:nth-child(n) { border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
  .bi-kpi:nth-child(2n) { border-right: none; }
  .bi-kpi:nth-last-child(-n+2) { border-bottom: none; }
  .bi-job-row { grid-template-columns: 60px 1fr 90px; gap: 8px; font-size: 12px; }
  .bi-job-row .bi-job-step,
  .bi-job-row .bi-job-machine { display: none; }
  .bi-controls { width: 100%; }
}

/* Inline BI link in the scenario top bar */
.bi-link {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--surface);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  padding: 7px 12px;
  text-decoration: none;
  transition: background-color .15s ease, transform .12s ease;
}
.bi-link:hover { background: var(--accent-hover); border-color: var(--accent-hover); transform: translateY(-1px); text-decoration: none; }

/* ────────────────────────────────────────────────────────────── */
/* HOME PAGE (`/`) — slim editorial entry                          */
/* ────────────────────────────────────────────────────────────── */
.home {
  display: flex;
  flex-direction: column;
  gap: 56px;
  padding: 48px 0 32px;
  max-width: 1100px;
  margin: 0 auto;
}

.home-hero { display: flex; flex-direction: column; gap: 16px; }
.home-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(56px, 9vw, 110px);
  line-height: 0.95;
  letter-spacing: -0.025em;
  margin: 0;
  color: var(--ink);
}
.home-tagline {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(20px, 2.4vw, 28px);
  line-height: 1.3;
  margin: 4px 0 0;
  max-width: 28ch;
  color: var(--ink-soft);
}
.home-sub {
  font-size: 16px;
  line-height: 1.55;
  max-width: 60ch;
  color: var(--muted);
  margin: 12px 0 0;
}
.home-actions {
  margin-top: 8px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.home-cta {
  display: inline-block;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  background: var(--accent);
  color: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  padding: 14px 28px;
  text-decoration: none;
  transition: background-color .15s ease, transform .12s ease, box-shadow .25s ease;
}
.home-cta:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 8px 18px -8px rgba(31, 61, 99, 0.45);
  text-decoration: none;
}

/* Three magazine pillars */
.home-pillars {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.home-pillar {
  padding: 28px 24px 28px;
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.home-pillar:last-child { border-right: none; }
.home-pillar-num {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 7px;
  border-radius: 2px;
  align-self: flex-start;
  margin-bottom: 4px;
}
.home-pillar-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 22px;
  letter-spacing: -0.005em;
  margin: 0;
  color: var(--ink);
}
.home-pillar p {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-soft);
  margin: 0;
}

.home-open { margin-top: 0; }

/* Tablet horizontal */
@media (max-width: 1199px) {
  .home { padding: 40px 0 24px; gap: 44px; }
  .home-pillars { grid-template-columns: 1fr; }
  .home-pillar {
    border-right: none;
    border-bottom: 1px solid var(--rule);
    padding: 22px 0;
  }
  .home-pillar:last-child { border-bottom: none; }
}

/* Mobile */
@media (max-width: 899px) {
  .home { padding: 24px 0; gap: 32px; }
  .home-title { font-size: clamp(44px, 14vw, 80px); }
  .home-tagline { font-size: 19px; }
  .home-cta { padding: 13px 22px; font-size: 12px; letter-spacing: 0.18em; }
  .contact-popover { right: 0; min-width: 240px; }
}

/* ────────────────────────────────────────────────────────────── */
/* BI SECTION (Phase 4) — top-level shell with Overview / Live    */
/* ────────────────────────────────────────────────────────────── */
.bi-section {
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 1600px;
  margin: 0 auto;
}
.bi-section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}
.bi-section-head-left { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.bi-section-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(22px, 3vw, 32px);
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
}

.bi-tabs {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface);
}
.bi-tab {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 9px 18px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color .12s ease, color .12s ease;
}
.bi-tab + .bi-tab { border-left: 1px solid var(--rule); }
.bi-tab:hover:not(.active) { background: var(--cream); color: var(--ink); }
.bi-tab.active {
  background: var(--ink);
  color: var(--cream);
}
.bi-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.bi-view { display: contents; }

/* ────────────────────────────────────────────────────────────── */
/* BI OVERVIEW VIEW                                                */
/* ────────────────────────────────────────────────────────────── */
.biov {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* Hint affordance. The tooltip itself is portalled to <body> by tooltip.js
   (so it can escape `overflow: hidden` ancestors) — these rules just mark
   the trigger element. */
.biov-hint {
  cursor: help;
}
.biov-card-title.biov-hint {
  text-decoration: underline dotted rgba(28, 24, 20, 0.28);
  text-underline-offset: 4px;
}
.biov-health-eyebrow.biov-hint {
  text-decoration: underline dotted rgba(28, 24, 20, 0.28);
  text-underline-offset: 3px;
}
.biov-health-factor.biov-hint:hover {
  background: rgba(28, 24, 20, 0.03);
  border-radius: 6px;
}

/* Portal tooltip — rendered at <body> level by tooltip.js. Fixed position
   bypasses overflow:hidden on ancestors. The arrow is a rotated square
   poking out of the bubble; tooltip.js sets its left offset so it tracks
   the trigger's centre. */
.app-tip {
  position: fixed;
  z-index: 1200;
  pointer-events: none;
  background: var(--ink, #1c1814);
  color: var(--cream, #faf6ec);
  padding: 10px 13px;
  border-radius: 8px;
  font: 12.5px/1.5 var(--font-body, "DM Sans", system-ui, sans-serif);
  letter-spacing: 0.005em;
  max-width: 300px;
  box-shadow:
    0 16px 40px rgba(0, 0, 0, 0.24),
    0 2px 6px rgba(0, 0, 0, 0.14),
    inset 0 0 0 1px rgba(250, 246, 236, 0.04);
  opacity: 0;
  transform: translateY(6px) scale(0.97);
  transform-origin: top center;
  transition:
    opacity 0.14s ease,
    transform 0.18s cubic-bezier(0.2, 0.7, 0.2, 1);
  white-space: normal;
  text-align: left;
  display: none;
}
.app-tip[data-placement="bottom"] {
  transform-origin: bottom center;
}
.app-tip.is-visible { display: block; }
.app-tip.is-visible:not(.is-measuring) {
  opacity: 1;
  transform: translateY(0) scale(1);
}
/* During measurement, reset transform so getBoundingClientRect returns the
   natural box (no scale, no offset) — otherwise the height comes back ~3%
   short and the flip math gets fuzzy near the viewport top. */
.app-tip.is-measuring {
  opacity: 0;
  pointer-events: none;
  transform: none !important;
  transition: none !important;
}
.app-tip-arrow {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--ink, #1c1814);
  transform: rotate(45deg);
}
.app-tip[data-placement="top"]    .app-tip-arrow { bottom: -4px; }
.app-tip[data-placement="bottom"] .app-tip-arrow { top:    -4px; }
.app-tip-text { display: block; }

/* Schedule Health composite — banner card sitting above the hero strip */
.biov-health {
  position: relative;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto;
  align-items: center;
  gap: 32px;
  padding: 22px 26px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  overflow: hidden;
}
.biov-health::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: var(--rule-strong);
}
.biov-health--strong::before  { background: var(--ok); }
.biov-health--steady::before  { background: #1f3d63; }
.biov-health--fragile::before { background: #b88a1a; }
.biov-health--atRisk::before  { background: var(--danger); }
.biov-health-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.biov-health-eyebrow {
  font: 11px/1.4 var(--font-mono, "JetBrains Mono", monospace);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mute, #857d72);
}
.biov-health-score {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-top: 2px;
}
.biov-health-num {
  font: 700 48px/1 var(--font-display, "Fraunces", serif);
  letter-spacing: -0.02em;
  color: var(--ink, #1c1814);
}
.biov-health-unit {
  font-size: 22px;
  color: var(--ink-mute, #857d72);
  font-weight: 500;
  margin-left: 4px;
}
.biov-health-tone {
  font: 600 13px/1 var(--font-body, "DM Sans", system-ui, sans-serif);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(28, 24, 20, 0.06);
  color: var(--ink, #1c1814);
}
.biov-health--strong  .biov-health-tone { background: rgba(58, 167, 87, 0.16); color: #2c6b3f; }
.biov-health--steady  .biov-health-tone { background: rgba(31, 61, 99, 0.12);  color: #1f3d63; }
.biov-health--fragile .biov-health-tone { background: rgba(184, 138, 26, 0.16); color: #8a6314; }
.biov-health--atRisk  .biov-health-tone { background: rgba(161, 58, 44, 0.14);  color: #a13a2c; }
.biov-health-sub {
  font: 13px/1.5 var(--font-body, "DM Sans", system-ui, sans-serif);
  color: var(--ink-mute, #857d72);
  margin-top: 4px;
}
.biov-health-factors {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 14px 22px;
  border-left: 1px solid var(--rule);
  padding-left: 26px;
}
.biov-health-factor {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.biov-health-factor-label {
  font: 11px/1.3 var(--font-mono, "JetBrains Mono", monospace);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute, #857d72);
}
.biov-health-factor-value {
  font: 700 22px/1 var(--font-display, "Fraunces", serif);
  letter-spacing: -0.01em;
  color: var(--ink, #1c1814);
}
.biov-health-factor-weight {
  font: 11px/1.3 var(--font-mono, "JetBrains Mono", monospace);
  color: var(--ink-mute, #857d72);
}
.biov-health-factor--na .biov-health-factor-value { color: var(--ink-mute, #857d72); }

@media (max-width: 899px) {
  .biov-health {
    grid-template-columns: 1fr;
    gap: 18px;
  }
  .biov-health-factors {
    border-left: none;
    border-top: 1px solid var(--rule);
    padding-left: 0;
    padding-top: 16px;
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Hero KPI strip — four pillar cards */
.biov-hero {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  overflow: hidden;
}
.biov-hero-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 28px 22px 22px;
  border-right: 1px solid var(--rule);
  position: relative;
  cursor: help;
}
.biov-hero-card:last-child { border-right: none; }
.biov-hero-card::before {
  content: '';
  position: absolute;
  top: 16px; left: 22px;
  width: 18px; height: 2px;
  background: var(--accent);
}
.biov-hero-card--ok::before     { background: var(--ok); }
.biov-hero-card--danger::before { background: var(--danger); }
.biov-hero-card--muted::before  { background: var(--rule-strong); }
.biov-hero-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.biov-hero-value {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 36px;
  line-height: 1.0;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-top: 6px;
  font-feature-settings: "tnum";
}
.biov-hero-card--ok     .biov-hero-value { color: var(--ok); }
.biov-hero-card--danger .biov-hero-value { color: var(--danger); }
.biov-hero-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 6px;
}

/* Charts row */
.biov-row {
  display: grid;
  gap: 18px;
}
.biov-row--charts {
  grid-template-columns: 1fr 1fr;
}

.biov-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 18px 18px 16px;
}
.biov-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
}
.biov-card-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 17px;
  margin: 0;
  color: var(--ink);
}
.biov-card-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.biov-chart { width: 100%; min-height: 220px; }

/* Tables */
.biov-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.biov-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.biov-table thead th {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-align: left;
  color: var(--muted);
  padding: 10px 10px 8px;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
.biov-table tbody td {
  padding: 10px 10px;
  border-bottom: 1px dashed var(--rule);
  vertical-align: middle;
}
.biov-table tbody tr:last-child td { border-bottom: none; }
.biov-table tbody tr:hover td { background: var(--cream); }
.biov-cell-name { font-weight: 500; color: var(--ink); }
.biov-cell-num {
  font-family: var(--font-mono);
  font-feature-settings: "tnum";
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
}
.biov-cell--ok      { color: var(--ok);     font-weight: 600; }
.biov-cell--warn    { color: #b88a1a;       font-weight: 600; }
.biov-cell--danger  { color: var(--danger); font-weight: 600; }

.biov-pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: var(--r-sm);
  white-space: nowrap;
}
.biov-pill--muted { color: var(--muted); background: var(--cream); }

.biov-cell-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 140px;
}
.biov-bar {
  flex: 1;
  height: 6px;
  background: var(--cream);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--rule);
}
.biov-bar-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, rgba(31,61,99,0.85), rgba(31,61,99,1));
  border-radius: 999px;
}
.biov-bar-num {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
  min-width: 38px;
  text-align: right;
  font-feature-settings: "tnum";
}

/* Tablet horizontal */
@media (max-width: 1199px) {
  .biov-hero { grid-template-columns: repeat(2, 1fr); }
  .biov-hero-card:nth-child(2n) { border-right: none; }
  .biov-hero-card:nth-child(-n+2) { border-bottom: 1px solid var(--rule); }
  .biov-row--charts { grid-template-columns: 1fr; }
}

/* Mobile */
@media (max-width: 899px) {
  .biov-hero { grid-template-columns: 1fr; }
  .biov-hero-card { border-right: none; border-bottom: 1px solid var(--rule); }
  .biov-hero-card:last-child { border-bottom: none; }
  .biov-hero-value { font-size: 30px; }
  .biov-card { padding: 14px; }
  .bi-tabs { width: 100%; }
  .bi-tab { flex: 1; }
}

/* Secondary KPI strip — smaller cards, supporting metrics under the hero */
.biov-secondary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  overflow: hidden;
}
.biov-sec-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px 14px;
  border-right: 1px solid var(--rule);
  position: relative;
}
.biov-sec-card:last-child { border-right: none; }
.biov-sec-card::before {
  content: '';
  position: absolute;
  top: 12px; left: 18px;
  width: 12px; height: 1.5px;
  background: var(--rule-strong);
}
.biov-sec-card--ok::before     { background: var(--ok); }
.biov-sec-card--danger::before { background: var(--danger); }
.biov-sec-label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 4px;
}
.biov-sec-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.005em;
  color: var(--ink);
  font-feature-settings: "tnum";
  margin-top: 2px;
}
.biov-sec-card--ok     .biov-sec-value { color: var(--ok); }
.biov-sec-card--danger .biov-sec-value { color: var(--danger); }
.biov-sec-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

/* Embedded plan-Gantt card in BI overview */
.biov-card--gantt .gantt {
  width: 100%;
  height: 460px;
  min-height: 320px;
}
.biov-gantt-controls {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.biov-card--gantt .seg-control { font-size: 10px; }

/* Mix donut + slack histogram cards */
.biov-card--mix .biov-chart,
.biov-card--slack .biov-chart {
  min-height: 280px;
}

@media (max-width: 1199px) {
  .biov-secondary { grid-template-columns: repeat(2, 1fr); }
  .biov-sec-card:nth-child(2n) { border-right: none; }
  .biov-sec-card:nth-child(-n+2) { border-bottom: 1px solid var(--rule); }
}
@media (max-width: 899px) {
  .biov-secondary { grid-template-columns: 1fr; }
  .biov-sec-card { border-right: none; border-bottom: 1px solid var(--rule); }
  .biov-sec-card:last-child { border-bottom: none; }
}

/* Goal comparison panel */
.biov-card--compare .biov-compare-loading,
.biov-card--compare .biov-compare-error {
  padding: 22px 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-align: center;
}
.biov-card--compare .biov-compare-error { color: var(--danger); }
.biov-table--compare tbody tr.biov-row--active {
  background: var(--accent-soft);
}
.biov-table--compare tbody tr.biov-row--active:hover td { background: var(--accent-soft); }
.biov-table--compare tbody tr.biov-row--active td:first-child {
  border-left: 3px solid var(--accent);
  padding-left: 7px;
}
.biov-table--compare .biov-active-pill {
  display: inline-block;
  margin-left: 8px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--surface);
  background: var(--accent);
  padding: 2px 7px;
  border-radius: 999px;
  vertical-align: 1px;
}
.biov-table--compare .biov-cell--best {
  color: var(--ok);
  font-weight: 700;
}
.biov-row--loading td { color: var(--muted); }
.biov-cell--skeleton {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.biov-skeleton-pulse {
  display: inline-block;
  animation: biov-skel-pulse 1.1s ease-in-out infinite;
}
@keyframes biov-skel-pulse {
  0%, 100% { opacity: 0.35; }
  50%      { opacity: 0.85; }
}
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.biov-compare-hint {
  margin: 10px 4px 0;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* SSR fallback inside #root: visible only between page load and SPA hydration
   (the SPA wipes #root.innerHTML on first render). Crawlers and link-preview
   bots see this; humans rarely. Kept minimal so the brief flash is graceful. */
.ssr-fallback {
  max-width: 720px;
  margin: 96px auto 0;
  padding: 0 24px;
  text-align: center;
}
.ssr-fallback h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0 0 24px;
}
.ssr-fallback p {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 1.125rem;
  line-height: 1.5;
  color: var(--muted);
  margin: 0;
}

/* ────────────────────────────────────────────────────────────── */
/* INBOX — pending orders + archive (Phase 5b)                     */
/* ────────────────────────────────────────────────────────────── */

.inbox-section {
  margin: 16px 0;
}
.inbox-section-empty .inbox-head { padding-bottom: 6px; }

.inbox-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
}
.inbox-accent {
  display: inline-block;
  font-family: var(--font-mono);
  color: var(--rule-strong);
  font-size: 14px;
  line-height: 1;
}
.inbox-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 18px;
  color: var(--ink);
  margin: 0;
}
.inbox-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0;
}
.inbox-link {
  margin-left: auto;
  background: none;
  border: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--accent);
  cursor: pointer;
  padding: 4px 0;
}
.inbox-link:hover { color: var(--accent-hover); }
.inbox-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

.inbox-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.inbox-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.inbox-card-accent {
  display: block;
  font-family: var(--font-mono);
  color: var(--rule-strong);
  font-size: 12px;
  line-height: 1;
  margin-bottom: 8px;
}
.inbox-card-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.inbox-card-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 18px;
  color: var(--ink);
  margin: 0 0 6px;
  line-height: 1.2;
  /* clamp to 2 lines, ellipsis on overflow */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.inbox-card-figure {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  margin: 0 0 12px;
}
.inbox-card-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--rule);
}

.inbox-btn {
  flex: 1;
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.inbox-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.inbox-btn[disabled] { cursor: progress; opacity: 0.6; }

.inbox-btn-reject {
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  color: var(--ink-soft);
}
.inbox-btn-reject:hover:not([disabled]) {
  border-color: var(--danger);
  color: var(--danger);
}

.inbox-btn-accept {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: var(--surface);
}
.inbox-btn-accept:hover:not([disabled]) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.inbox-card-archived {
  opacity: 0.7;
  background: transparent;
}
.inbox-card-archived .inbox-card-title { color: var(--ink-soft); }

@media (max-width: 1100px) {
  .inbox-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 599px) {
  .inbox-grid { grid-template-columns: 1fr; }
  .inbox-head { flex-wrap: wrap; }
  .inbox-link { margin-left: 0; }
}

/* ────────────────────────────────────────────────────────────── */
/* BI staleness banner — appears when the persisted plan changed   */
/* (e.g. visitor accepted an order in another tab) while BI is open*/
/* ────────────────────────────────────────────────────────────── */
.bi-stale-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0 0 16px;
  padding: 12px 16px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--r-md);
}
.bi-stale-msg {
  flex: 1;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 13px;
  color: var(--ink);
}
.bi-stale-btn {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: var(--surface);
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: var(--r-md);
  cursor: pointer;
}
.bi-stale-btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.bi-stale-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Cookie consent banner ---------- */
.cookie-banner {
  position: fixed;
  bottom: 18px;
  right: 18px;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  box-shadow: 0 12px 32px -10px rgba(28, 24, 20, 0.25);
  padding: 18px 20px;
  z-index: 90;
  font-family: var(--font-body);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.cookie-banner--show {
  opacity: 1;
  transform: translateY(0);
}
.cookie-banner-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 6px 0;
}
.cookie-banner-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
  margin: 0 0 14px 0;
}
.cookie-banner-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.cookie-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 7px 14px;
  border-radius: var(--r-md);
  cursor: pointer;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  color: var(--ink);
}
.cookie-btn:hover { background: var(--cream); }
.cookie-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface);
}
.cookie-btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
@media (max-width: 600px) {
  .cookie-banner { left: 12px; right: 12px; max-width: none; bottom: 12px; }
}

/* ---------- Admin dashboard ---------- */
.admin-page {
  background: var(--paper);
  min-height: 100vh;
  padding: 24px 32px 64px;
  font-family: var(--font-body);
  color: var(--ink);
}
.admin-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}
.admin-title {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 600;
  margin: 0;
  color: var(--ink);
}
.admin-controls { display: flex; gap: 8px; align-items: center; }
.admin-range-tabs { display: flex; border: 1px solid var(--rule-strong); border-radius: var(--r-pill); overflow: hidden; }
.admin-range-tab {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 14px;
  background: var(--surface);
  border: none;
  border-right: 1px solid var(--rule);
  color: var(--ink-soft);
  cursor: pointer;
}
.admin-range-tab:last-child { border-right: none; }
.admin-range-tab.active { background: var(--accent); color: var(--surface); }
.admin-logout {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 14px;
  background: transparent;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-pill);
  color: var(--ink-soft);
  cursor: pointer;
}
.admin-logout:hover { background: var(--cream); }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 18px 20px;
}
.kpi-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px 0;
}
.kpi-value {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
  line-height: 1.1;
}
.kpi-sub {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 6px 0 0 0;
}

.admin-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 18px;
  margin-bottom: 24px;
}
@media (max-width: 900px) { .admin-grid { grid-template-columns: 1fr; } }
.admin-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 18px 20px;
}
.admin-card-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 14px 0;
}
.admin-chart { width: 100%; min-height: 280px; }

.online-list { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow-y: auto; }
.online-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 13px;
}
.online-item:last-child { border-bottom: none; }
.online-flag { font-size: 18px; }
.online-meta { color: var(--ink-soft); }
.online-meta strong { color: var(--ink); font-weight: 600; }
.online-path {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  background: var(--cream);
  padding: 2px 6px;
  border-radius: var(--r-sm);
}

.sessions-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sessions-table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 8px;
  border-bottom: 1px solid var(--rule-strong);
}
.sessions-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
.sessions-trail {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  word-break: break-all;
}

.admin-login-page {
  background: var(--paper);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
}
.admin-login-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 32px 36px;
  width: 360px;
  max-width: 90vw;
  box-shadow: 0 12px 32px -10px rgba(28, 24, 20, 0.15);
}
.admin-login-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  margin: 0 0 4px 0;
}
.admin-login-sub {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 24px 0;
}
.admin-login-field { margin-bottom: 18px; }
.admin-login-field label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.admin-login-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: 14px;
  background: var(--cream);
}
.admin-login-field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.admin-login-error {
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-soft);
  padding: 8px 10px;
  border-radius: var(--r-sm);
  margin: 0 0 14px 0;
}
.admin-login-submit {
  width: 100%;
  padding: 11px 16px;
  background: var(--accent);
  color: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}
.admin-login-submit:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ---------- Scenarios by visitor ---------- */
.admin-card-sub {
  font-size: 12px;
  color: var(--ink-soft);
  margin: -8px 0 16px 0;
  line-height: 1.5;
}
.admin-empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 0;
  margin: 0;
  font-size: 13px;
}
.visitor-row {
  border-bottom: 1px solid var(--rule);
  padding: 8px 0;
}
.visitor-row:last-child { border-bottom: none; }
.visitor-row summary {
  cursor: pointer;
  list-style: none;
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 6px 0;
  font-size: 13px;
}
.visitor-row summary::-webkit-details-marker { display: none; }
.visitor-row summary::before {
  content: '▸';
  color: var(--muted);
  font-size: 11px;
  transition: transform 0.15s ease;
  margin-right: -6px;
}
.visitor-row[open] > summary::before { transform: rotate(90deg); }
.visitor-flag { font-size: 18px; }
.visitor-id {
  background: var(--cream);
  padding: 2px 6px;
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink);
}
.visitor-meta { color: var(--ink-soft); }
.visitor-stats { color: var(--ink); }
.visitor-stats strong { font-weight: 600; }
.visitor-when {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}
.visitor-scen-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 12px;
}
.visitor-scen-table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 6px 8px;
  border-bottom: 1px solid var(--rule);
}
.visitor-scen-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-soft);
}
.visitor-scen-table td:first-child { color: var(--ink); }
.visitor-scen-table a { color: var(--accent); text-decoration: none; }
.visitor-scen-table a:hover { text-decoration: underline; }
@media (max-width: 700px) {
  .visitor-row summary {
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "flag id when" "meta meta meta" "stats stats stats";
  }
  .visitor-flag { grid-area: flag; }
  .visitor-id { grid-area: id; }
  .visitor-when { grid-area: when; }
  .visitor-meta { grid-area: meta; }
  .visitor-stats { grid-area: stats; }
}

.admin-wipe { color: var(--danger); border-color: var(--danger); }
.admin-wipe:hover { background: var(--danger-soft); }
