/* PlotLab — page-specific layout and components (Build Pass 1c: three-zone workbench) */

/* Wider work surface for the workbench (scoped to PlotLab's <main>) */
.site-inner--wide {
  max-width: 1440px;
}

/* The header wordmark + theme toggle live in site.css (shared chrome). */
.site-header__theme {
  flex-shrink: 0;
}

/* ---------- The instrument: one full-bleed 4-zone grid ----------
   left rail · stage · inspector panel · right rail. Flush to the viewport
   edges (no outer card, no page-grey gutters); zones divided by hairlines. */
.plot45-main {
  padding: 0;
}

.plot45-app {
  display: grid;
  /* Wider rails (64px) so the longer inspector labels ("Examples", "Export")
     don't crowd the edges; the extra width comes from the stage, the inspector
     panel stays at 290px. Both rails match — the mirrored bookend is the point. */
  grid-template-columns: 64px minmax(0, 1fr) 290px 64px;
  height: calc(100vh - var(--nav-height));
  background: var(--panel);
}

.plot45-app > * {
  min-width: 0;
  min-height: 0;
}

/* ---------- Stage (zone 2): results bar + swappable body ---------- */
.plotlab-stage {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.plotlab-stagebody {
  position: relative;
  flex: 1;
  min-height: 0;
}

.plotlab-pane {
  position: absolute;
  inset: 0;
}

.plotlab-pane[hidden] {
  display: none;
}

/* Data pane — room to breathe (no more 264px squeeze). */
.plotlab-pane--data {
  display: flex;
  flex-direction: column;
}

.plotlab-data-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 14px 22px;
}

.plotlab-data-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 22px 22px;
}

/* The sheet itself breathes inside the wide stage. */
.plotlab-data-sheet {
  max-width: 640px;
}

/* Generous cells in the Data pane (the Split pane uses .plotlab-table--compact).
   Header padding now lives on .plotlab-colhead__h, so the th override is gone. */
.plotlab-pane--data input.plotlab-cell {
  padding: 10px 14px;
}

/* Graph pane — big, calm paper. */
.plotlab-pane--graph {
  padding: 18px;
}

.plotlab-graphframe {
  position: relative;
  width: 100%;
  height: 100%;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

/* Split pane — preserves at-a-glance data <-> graph. */
.plotlab-pane--split {
  display: grid;
  grid-template-columns: 300px 1fr;
}

.plotlab-split-data {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
}

.plotlab-split-data__head {
  flex-shrink: 0;
  padding: 11px 16px;
  font-size: var(--fs-title);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.plotlab-split-data__scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 6px 12px;
}

.plotlab-split-graph {
  min-width: 0;
  padding: 16px;
}

.plotlab-split-graph .plotlab-graphframe {
  border: none;
}

.plotlab-data-head h2 {
  margin: 0;
  font-size: var(--fs-title);
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* Reset = a quiet circular-arrow icon button filling the otherwise-empty
   top-left corner cell (the row-number column header). A rare, destructive
   action behind a confirm dialog, so it stays understated until hovered.
   The corner th is position:sticky, so it's the containing block for the
   absolutely-positioned button that fills it. */
.plotlab-table__reset {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 0;
  -webkit-tap-highlight-color: transparent;
}

.plotlab-table__reset:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.plotlab-table__reset:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.plotlab-table__reset svg {
  width: 15px;
  height: 15px;
}

.plotlab-table--compact .plotlab-table__reset svg {
  width: 13px;
  height: 13px;
}

/* Per-row delete lives in the row-number gutter (mirrors the uncertainty-column
   header trash): hovering the row number cross-fades it out for a full-cell red
   trash zone, pinned to the left edge however many columns scroll off. */
.plotlab-rownum {
  transition: opacity 0.14s ease;
}

.plotlab-row-del {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--danger-soft);
  color: var(--danger);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.14s ease;
  -webkit-tap-highlight-color: transparent;
}

.plotlab-table__index:hover .plotlab-row-del,
.plotlab-row-del:focus-visible {
  opacity: 1;
  visibility: visible;
}

.plotlab-table__index:hover .plotlab-rownum {
  opacity: 0;
}

.plotlab-row-del:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--danger);
}

.plotlab-row-del svg {
  width: 14px;
  height: 14px;
}

/* Hidden at the row floor (MIN_ROWS) — the button is also disabled in JS. */
.plotlab-row-del[disabled] {
  display: none;
}

/* Saved-session status line — quiet, only present when it has something to say. */
.plotlab-saved-status {
  margin: 6px 0 0;
  font-size: var(--fs-caption);
  color: var(--muted);
}

.plotlab-saved-status:empty {
  margin: 0;
}

/* No box-in-a-box: the scroll + chrome belong to the stage panes now, so the
   wrap is a plain container and the sheet reads as one clean surface. */
.plotlab-table-wrap {
  overflow: visible;
}

/* ----- Direction A "Ledger": a full hairline grid, jeweled two-line header,
   value+Δ grouping, a Sheets-grade selection crosshair, and a built-in add-row.
   The cell stays an editable input.plotlab-cell — the selection engine's DOM. */
.plotlab-table {
  /* Shrink-wrap to content: the table is the sum of its column floors, so it
     stays narrow with few columns and grows ~one column at a time as variables
     are added. The scroll container (.plotlab-data-scroll / split scroll, both
     overflow:auto) shows a horizontal scrollbar once it outgrows the viewport. */
  width: auto;
  border-collapse: collapse;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  font-size: var(--fs-data);
}

/* Full grid — light rules, so it reads as a calm ledger, not heavy Excel chrome. */
.plotlab-table th,
.plotlab-table td {
  border-right: 1px solid var(--line);
}

.plotlab-table tbody td {
  border-bottom: 1px solid var(--line);
}

/* Data columns keep a readable minimum width; the index gutter stays compact. */
.plotlab-table th:not(.plotlab-table__index) {
  min-width: 84px;
}

/* Header th = the jewel: symbol over unit, right-aligned and bottom-set. */
.plotlab-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--line-strong);
  text-align: right;
  vertical-align: bottom;
  white-space: nowrap;
}

.plotlab-colhead__h {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  padding: 10px 12px 9px;
  transition: opacity 0.14s ease;
}

.plotlab-colhead__row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
}

.plotlab-colhead__sym {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.015em;
  color: var(--text);
}

.plotlab-colhead__unit {
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Role marks — achromatic squares: x ink-filled, y ink-outline, ± quiet. */
.plotlab-colhead__tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  border-radius: var(--radius);
  font-size: 0.6rem;
  font-weight: 700;
  font-style: normal;
  line-height: 1;
}

.plotlab-colhead__tag--x { background: var(--accent); color: var(--panel); }
.plotlab-colhead__tag--y {
  background: transparent;
  color: var(--accent-2);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.plotlab-colhead__tag--unc {
  background: transparent;
  color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--line);
}

.plotlab-table td {
  padding: 0;
}

/* Row-number gutter + select-all corner. */
.plotlab-table__index {
  width: 44px;
  text-align: center;
  background: var(--bg-subtle);
  color: var(--muted);
  font-size: var(--fs-caption);
  font-variant-numeric: tabular-nums;
  user-select: none;
}

td.plotlab-table__index {
  position: relative;
  overflow: hidden;
  padding: 0;
}

input.plotlab-cell {
  width: 100%;
  min-width: 84px; /* readable floor; columns scroll rather than squeeze */
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 10px 12px;
  font-size: var(--fs-data);
  font-variant-numeric: tabular-nums;
  text-align: right;
  caret-color: transparent; /* select mode shows no caret; edit mode restores it */
}

/* Empty cells show a quiet resting dot (the input placeholder) so a clean slate
   reads as a grid ready for input, not a void. */
input.plotlab-cell::placeholder {
  color: color-mix(in srgb, var(--muted) 40%, transparent);
}

/* Range of a multi-cell selection: a soft fill, no caret. */
input.plotlab-cell.is-selected {
  background: var(--accent-soft);
}

/* The active cell (single click, arrow target, or range corner): ringed. Shown
   whether or not it currently holds focus, so the selection persists visually. */
input.plotlab-cell.is-active,
input.plotlab-cell:focus {
  outline: none;
  border-color: transparent;
  box-shadow: inset 0 0 0 2px var(--accent);
  background: var(--accent-soft);
}

/* Edit mode: live caret. */
input.plotlab-cell.is-editing {
  caret-color: var(--accent);
}

/* Invalid: a red fill (the danger token, matching row-delete) with NO ring, so it
   never reads as the active cell — and it beats the active ring when both apply. */
input.plotlab-cell--invalid,
input.plotlab-cell--invalid.is-active,
input.plotlab-cell--invalid.is-selected,
input.plotlab-cell--invalid:focus {
  box-shadow: none;
  background: var(--danger-soft);
  color: var(--danger);
}

/* Sheets-grade crosshair: the active cell's column header + row number light up. */
.plotlab-table th.is-colactive {
  background: var(--accent-soft);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.plotlab-table th.is-colactive .plotlab-colhead__sym {
  color: var(--text);
}

td.plotlab-table__index.is-rowactive {
  color: var(--text);
  font-weight: 700;
  background: var(--accent-soft);
  box-shadow: inset 2px 0 0 var(--accent);
}

/* Value + Δ grouping: a faint tint band binds a variable to its uncertainty
   column; a stronger seam closes the group (the within-group seam stays light). */
.plotlab-table .is-grp {
  background: color-mix(in srgb, var(--accent) 3%, var(--panel));
}

.plotlab-table th.is-grp {
  background: color-mix(in srgb, var(--accent) 5%, var(--bg-subtle));
}

.plotlab-table .is-grpend {
  border-right: 1px solid var(--line-strong);
}

/* Built-in add-row fused to the foot of the grid; the plus sits in the gutter
   width, so it lands where the next row number will appear. */
.plotlab-table__add td {
  padding: 0;
  border-top: 1px solid var(--line);
  border-right: 0;
}

.plotlab-row-add {
  width: 100%;
  display: flex;
  align-items: stretch;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: var(--fs-caption);
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.plotlab-row-add__plus {
  flex: 0 0 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 0;
}

.plotlab-row-add__label {
  display: inline-flex;
  align-items: center;
  padding: 9px 0;
}

.plotlab-row-add:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.plotlab-row-add svg {
  width: 13px;
  height: 13px;
}

/* Compact density — the Split (~300px) variant; same look, tighter metrics. */
.plotlab-table--compact { font-size: 0.8rem; }
.plotlab-table--compact .plotlab-table__index { width: 30px; }
.plotlab-table--compact .plotlab-colhead__h { padding: 7px 9px 6px; gap: 2px; }
.plotlab-table--compact .plotlab-colhead__sym { font-size: 0.82rem; }
.plotlab-table--compact .plotlab-colhead__unit { font-size: 0.64rem; }
.plotlab-table--compact th:not(.plotlab-table__index) { min-width: 60px; }
.plotlab-table--compact input.plotlab-cell { padding: 7px 9px; min-width: 60px; font-size: 0.8rem; }
.plotlab-table--compact .plotlab-row-add__plus { flex-basis: 30px; }
.plotlab-table--compact .plotlab-row-del svg { width: 12px; height: 12px; }

/* Honor reduced motion for the new gutter / header cross-fades. */
@media (prefers-reduced-motion: reduce) {
  .plotlab-rownum,
  .plotlab-row-del,
  .plotlab-colhead__h {
    transition: none;
  }
}

.plotlab-data-note {
  min-height: 0;
  margin: 8px 0 0;
  font-size: var(--fs-caption);
  color: var(--warning);
}

.plotlab-data-note:empty {
  margin: 0;
}

.plotlab-pane--data .plotlab-hint {
  margin-top: 8px;
}

/* ---------- Results bar: a persistent fit readout atop the stage ----------
   Always visible in every stage view; min-height + tint + line-strong baseline
   are shared with the inspector header so the band runs unbroken across the
   stage -> inspector seam. */
.plotlab-fitslab {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  flex-shrink: 0;
  min-height: 48px;
  padding: 8px 18px;
  background: color-mix(in srgb, var(--accent) 3.5%, var(--panel));
  border-bottom: 1px solid var(--line-strong);
  font-variant-numeric: tabular-nums;
}

.plotlab-fitslab__eyebrow {
  font-size: var(--fs-eyebrow);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.plotlab-fitslab__eyebrow[hidden] {
  display: none;
}

/* Per-series fit chips: m and R², each pair coloured to its best-fit line.
   They flow left-aligned and wrap to 2–3 rows on narrow screens. */
.plotlab-fitslab__chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  min-width: 0;
}

.plotlab-chipgroup {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.plotlab-chips__sep {
  color: var(--muted);
  opacity: 0.5;
  font-weight: 400;
  user-select: none;
}

.plotlab-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3em;
  padding: 4px 10px;
  border: none;
  border-radius: var(--radius);
  /* Soft fill tinted to the series colour (set inline via --chip-color); mixes
     with the panel so it reads on both light and dark chrome. */
  background: color-mix(in srgb, var(--chip-color, var(--accent)) 16%, var(--panel));
  color: var(--text);
  font-size: var(--fs-chip);
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* The key (m, R²) carries the series colour; the value stays in --text. */
.plotlab-chip var {
  font-style: italic;
  font-weight: 700;
  color: var(--chip-color, var(--accent-2));
}

/* Lone (black-lined) fit: a theme-neutral pill, legible in light and dark.
   Placed after the rules above so it wins at equal specificity. */
.plotlab-chip--neutral {
  background: color-mix(in srgb, var(--text) 8%, var(--panel));
}

.plotlab-chip--neutral var {
  color: var(--text);
}

/* Dark mode: the line colours read low-contrast as small key text on dark chrome,
   so a tinted chip's key + fill use a brighter variant (inline --chip-color-dark). */
[data-theme="dark"] .plotlab-chip--tinted {
  background: color-mix(in srgb, var(--chip-color-dark, var(--chip-color)) 20%, var(--panel));
}

[data-theme="dark"] .plotlab-chip--tinted var {
  color: var(--chip-color-dark, var(--chip-color));
}

/* Warning pill: soft orange fill + a ⚠ glyph; same shape as the metric chips. */
.plotlab-chip--warn {
  background: color-mix(in srgb, var(--warning) 18%, var(--panel));
  color: var(--text);
  font-weight: 500;
  cursor: help;
}

.plotlab-chip--warn::before {
  content: "⚠";
  margin-right: 0.4em;
  color: var(--warning);
  font-weight: 700;
}

/* R² status dot — neutral until known, then red/amber/green by threshold. */
.plotlab-chip__dot {
  align-self: center;
  width: 0.6em;
  height: 0.6em;
  margin-left: 0.3em;
  border-radius: var(--radius-full);
  background: var(--muted);
}

.plotlab-chip__dot--weak { background: var(--danger); }
.plotlab-chip__dot--moderate { background: var(--warning); }
.plotlab-chip__dot--strong { background: var(--success); }

/* Outlier marker on the m chip: a small superscript asterisk; the excluded
   rows live in its title tooltip. */
.plotlab-chip__flag {
  margin-left: 0.1em;
  font-size: 0.85em;
  font-weight: 700;
  vertical-align: super;
  line-height: 0;
  cursor: help;
  color: var(--warning);
}

.plotlab-metric__unit {
  font-weight: 500;
  color: var(--muted);
  margin-left: 0.22em;
}

.plotlab-sup {
  font-size: 0.66em;
  vertical-align: super;
  line-height: 0;
  font-weight: 600;
  font-style: normal;
}

/* status note — full-width row when present */
.plotlab-fitslab__note {
  flex: 1 1 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 0;
  padding: 0 4px 2px;
  font-size: var(--fs-caption);
  color: var(--muted);
}

.plotlab-fitslab__note:empty {
  display: none;
  padding: 0;
}

/* Graph: fills its graphframe (reparented between the Graph and Split panes). */

.plotlab-svg-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  background: #ffffff;
  line-height: 0;
}

/* On-canvas equation labels (SVG <text>). Halo comes from paint-order:stroke
   set per element; dragging is wired up in label-drag.js. */
.plotlab-eqlabel {
  cursor: move;
  user-select: none;
  touch-action: none;  /* let pointer drags work on touch without scrolling */
}

/* Fullscreen control — attached to the graph frame, not the fit slab */

.plotlab-graph-fs {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  margin: 0;
  border: 1px solid color-mix(in srgb, var(--accent) 12%, var(--line-strong));
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  box-shadow: none;
  cursor: pointer;
  line-height: 0;
  transition: color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.plotlab-graph-fs:hover {
  color: var(--accent-2);
  background: #ffffff;
  box-shadow: none;
}

.plotlab-graph-fs:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.plotlab-graph-fs svg {
  width: 16px;
  height: 16px;
}

.plotlab-graph-fs[hidden] {
  display: none;
}

#plotSvg {
  display: block;
  width: 100%;
  height: 100%;
  background: #ffffff;
  font-family: var(--font);
}

/* Fullscreen graph view */

.plotlab-svg-wrap:fullscreen {
  background: #ffffff;
  border: none;
  border-radius: 0;
  height: 100%;
}

.plotlab-fs-exit {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  min-height: 44px;
  line-height: 1.2;
}

.plotlab-fs-exit[hidden] {
  display: none;
}

/* ---------- Tab rails (zones 1 & 4): mirrored bookends ----------
   Identical grammar both sides — that symmetry is the point. Vertical icon
   tablists at the two outer edges; the active tab carries a 2px accent marker
   on its OUTER edge (mirror image left vs right). */
.plotlab-rail {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 0;
  background: var(--bg-subtle);
}

/* Left rail sits against the stage; right rail flanks the inspector panel. */
.plotlab-rail--stage {
  border-right: 1px solid var(--line);
}

.plotlab-rail--inspector {
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.plotlab-rail__tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 100%;
  min-height: 52px;
  padding: 8px 2px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  cursor: pointer;
}

.plotlab-rail__icon {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
}

.plotlab-rail__label {
  font-size: 0.69rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.plotlab-rail__tab:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.plotlab-rail__tab:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  z-index: 1;
}

/* Active tab: lifts onto the panel fill + accent ink, with a 2px outer-edge
   marker (left rail → left edge, right rail → right edge). */
.plotlab-rail__tab[aria-selected="true"] {
  background: var(--panel);
  color: var(--accent-2);
}

.plotlab-rail__tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--accent-2);
}

.plotlab-rail--stage .plotlab-rail__tab[aria-selected="true"]::after {
  left: 0;
}

.plotlab-rail--inspector .plotlab-rail__tab[aria-selected="true"]::after {
  right: 0;
}

/* ---------- Inspector panel (zone 3) ----------
   Anchored full-height to the right of the stage, divided from it by the one
   deliberate rule (--line-strong, matching the results-bar baseline weight). */
.plotlab-inspector {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-left: 1px solid var(--line-strong);
}

.plotlab-railpanel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}

/* Header sits on the exact 48px results-bar baseline, same tint + strong rule,
   so the tinted band + hairline run unbroken across the stage->inspector seam. */
.plotlab-railpanel__head {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
  height: 48px;
  min-height: 48px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--accent) 3.5%, var(--panel));
  border-bottom: 1px solid var(--line-strong);
  font-size: var(--fs-title);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.plotlab-railpanel__head-icon {
  display: inline-flex;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--accent-2);
}

.plotlab-railpanel__head-icon svg {
  width: 16px;
  height: 16px;
}

/* The ONLY scroll region in the inspector — vertical only. */
.plotlab-railpanel__body {
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 12px 14px;
}

/* The rail narrows the panel, so let long labels (e.g. the "Gradient
   uncertainty Next pass" row) wrap their badge instead of forcing a
   horizontal scrollbar. */
.plotlab-inspector .plotlab-inline__label {
  flex-wrap: wrap;
}

.plotlab-tabpanel[hidden] {
  display: none;
}

.plotlab-section__body {
  display: grid;
  gap: 10px;
}

/* Make enabled inspector fields read as fillable (white), and disabled
   "Next pass" fields clearly inert (lavender + dimmed). Scoped to the
   inspector so the transparent data-table cells stay untouched. */
.plotlab-inspector input,
.plotlab-inspector select {
  background: var(--panel);
  border: 1px solid var(--line-strong);
}

.plotlab-inspector input:focus,
.plotlab-inspector select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.plotlab-inspector :disabled,
.plotlab-inspector .plotlab-planned input,
.plotlab-inspector .plotlab-planned select {
  background: var(--bg-subtle);
  opacity: 0.55;
  cursor: not-allowed;
}

.plotlab-section__row {
  display: grid;
  gap: 6px;
}

.plotlab-range {
  display: flex;
  align-items: center;
  gap: 6px;
}

.plotlab-range input {
  flex: 1;
  min-width: 0;
}

/* Axis-label row: a title + unit pair that fills the panel width (the title
   gets the larger share). Overrides the fixed .plotlab-input-sm width. */
.plotlab-axislabel {
  display: flex;
  gap: 6px;
}

.plotlab-axislabel input.plotlab-input-sm,
.plotlab-section__body .plotlab-axislabel input.plotlab-input-sm {
  min-width: 0;
  flex: 1;
}

.plotlab-axislabel input.plotlab-input-sm:first-child,
.plotlab-section__body .plotlab-axislabel input.plotlab-input-sm:first-child {
  flex: 2;
}

.plotlab-section__btnrow {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

/* ---------- Shared control styles ---------- */

.plotlab-inline__label {
  font-size: var(--fs-body);
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.plotlab-inline__dash {
  color: var(--muted);
}

.plotlab-input-sm,
.plotlab-section__body input.plotlab-input-sm {
  width: 74px;
  padding: 7px 9px;
  font-size: var(--fs-body);
}

.plotlab-input-text,
.plotlab-section__body input.plotlab-input-text {
  width: 100%;
  padding: 7px 9px;
  font-size: var(--fs-body);
}

.plotlab-select,
.plotlab-section__body select.plotlab-select {
  width: 100%;
  padding: 7px 9px;
  font-size: var(--fs-body);
}

/* Variable metadata: title + name on the first row, symbol/unit below */

.plotlab-vargroup {
  display: grid;
  grid-template-columns: 22px 1fr 1fr;
  gap: 6px 8px;
  align-items: center;
}

.plotlab-vargroup input {
  width: 100%;
  min-width: 0;
  padding: 7px 9px;
  font-size: var(--fs-body);
}

.plotlab-vargroup__title {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 0.8rem;
  font-weight: 700;
  font-style: italic;
  grid-row: 1;
  grid-column: 1;
}

.plotlab-vargroup__name {
  grid-row: 1;
  grid-column: 2 / 4;
}

.plotlab-vargroup__sym {
  grid-row: 2;
  grid-column: 2;
}

.plotlab-vargroup__unit {
  grid-row: 2;
  grid-column: 3;
}

.plotlab-vargroup__pm {
  grid-row: 3;
  grid-column: 1;
  justify-self: center;
}

.plotlab-vargroup__delta {
  grid-row: 3;
  grid-column: 2 / 4;
}

/* ---------- Graph tab: x/y plot-pair selectors ---------- */

.plotlab-plotpair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.plotlab-plotpair__field {
  display: grid;
  gap: 4px;
  margin: 0;
}

/* ---------- Variable card: metadata + uncertainty controls
   (shared by the x-var and y-var cards; class names keep the historic
   `colcard`/`series` prefixes the JS still emits) ---------- */

.plotlab-col-del {
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
}

.plotlab-col-del:hover:enabled,
.plotlab-col-del:focus-visible {
  background: var(--danger-soft);
  color: var(--danger);
}

.plotlab-col-del:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.plotlab-colcard__meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.plotlab-colcard__meta input {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  font-size: var(--fs-body);
}

.plotlab-colcard__name {
  grid-column: 1 / 3;
}

.plotlab-colcard__unc {
  display: grid;
  gap: 6px;
}

.plotlab-colcard__uncrow {
  display: flex;
  align-items: center;
  gap: 6px;
}

.plotlab-colcard__uncrow .plotlab-select {
  flex: 1;
  min-width: 0;
}

.plotlab-colcard__unc input {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  font-size: var(--fs-body);
}

/* ---------- Variable card: Appearance / Fit sections ---------- */

/* Eyebrow: the one section-label treatment (PLOT, AXIS LABELS, Appearance, Fit…).
   .plotlab-series__subhead is the historic name the JS still emits. */
.plotlab-eyebrow,
.plotlab-series__subhead {
  font-size: var(--fs-eyebrow);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Tighten the gap above the Fit heading so the two groups read as sections. */
.plotlab-series__subhead + * { margin-top: -2px; }

.plotlab-series__fitrow {
  display: flex;
  align-items: center;
  gap: 8px;
}

.plotlab-series__fitrow .plotlab-select {
  flex: 1;
  min-width: 0;
}

.plotlab-series__styles {
  display: grid;
  gap: 6px;
}

.plotlab-series__styles .plotlab-select {
  width: 100%;
  min-width: 0;
}

/* ---------- y-var: horizontal variable tabs + active card ---------- */

.plotlab-vartabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 12px;
}

.plotlab-vartab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-body);
  font-weight: 600;
  cursor: pointer;
}

.plotlab-vartab:hover { background: var(--bg-subtle); }

.plotlab-vartab.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-2);
}

.plotlab-vartab.is-off .plotlab-vartab__label {
  text-decoration: line-through;
  opacity: 0.6;
}

.plotlab-vartab__glyph {
  font-size: 0.95rem;
  line-height: 1;
  color: var(--glyph-color, inherit);
}

/* Dark mode: a brighter tint + a hairline stroke so the deeper blue/green and
   the thin outline shapes (○ △ □) read clearly on the dark chrome. */
[data-theme="dark"] .plotlab-vartab__glyph {
  color: var(--glyph-color-dark, var(--glyph-color, inherit));
  -webkit-text-stroke: 0.5px currentColor;
}

.plotlab-vartab__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plotlab-vartab--add {
  font-weight: 700;
  color: var(--muted);
  padding-inline: 11px;
}

/* The active y-variable's settings card. */
.plotlab-varcard {
  display: grid;
  min-width: 0;
  gap: 8px;
}

.plotlab-varcard__head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.plotlab-varcard__head .plotlab-col-del { margin-left: auto; }

/* Section headings + wrapping checkboxes (shared with the old series body). */
.plotlab-varcard .plotlab-series__subhead:not(:first-child) { margin-top: 4px; }
.plotlab-varcard .plotlab-check {
  white-space: normal;
  align-items: flex-start;
}

/* The header's own checkbox/radio (plot toggle, "use as x-axis") stays on one
   tidy line — only the Fit-section checkboxes wrap. Extra specificity so it
   beats the wrapping rule above regardless of source order. */
.plotlab-varcard .plotlab-varcard__head .plotlab-check {
  white-space: nowrap;
  align-items: center;
}

/* Uncertainty column header doubles as its delete control: hovering (or focusing
   the button) cross-fades the two-line header (.plotlab-colhead__h, which carries
   the opacity transition) out and reveals a full-cell red trash zone — a big,
   unmissable target with no layout shift. The header th is already position:sticky,
   the containing block for the inset:0 button. */
.plotlab-colhead--unc:hover .plotlab-colhead__h,
.plotlab-colhead--unc:focus-within .plotlab-colhead__h {
  opacity: 0;
}

.plotlab-colhead__del {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  border: 0;
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--danger-soft);
  color: var(--danger);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.14s ease;
  -webkit-tap-highlight-color: transparent;
}

.plotlab-colhead--unc:hover .plotlab-colhead__del,
.plotlab-colhead__del:focus-visible {
  opacity: 1;
  visibility: visible;
}

.plotlab-colhead__del:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--danger);
}

.plotlab-colhead__del svg {
  width: 15px;
  height: 15px;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.plotlab-colhead__del:hover svg {
  transform: scale(1.06);
}

/* Springy mechanical "press" on click — quick squash, gentle overshoot, settle. */
.plotlab-colhead__del.is-pressed svg {
  animation: plotlab-trash-press 0.34s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes plotlab-trash-press {
  0%   { transform: scale(1); }
  32%  { transform: scale(0.74); }
  66%  { transform: scale(1.14); }
  100% { transform: scale(1.06); }
}

@media (prefers-reduced-motion: reduce) {
  .plotlab-colhead__del svg { transition: none; }
  .plotlab-colhead__del:hover svg { transform: none; }
  .plotlab-colhead__del.is-pressed svg { animation: none; }
}

.plotlab-btn-sm {
  padding: 7px 12px;
  font-size: var(--fs-body);
}

/* ---------- Planned ("Next pass") controls ---------- */

.plotlab-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
  vertical-align: middle;
}

.plotlab-planned,
.plotlab-planned label,
.plotlab-planned .plotlab-check {
  color: var(--muted);
  cursor: not-allowed;
}

.plotlab-planned input,
.plotlab-planned select,
.plotlab-planned button {
  cursor: not-allowed;
}

.plotlab-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 500;
  font-size: var(--fs-body);
  margin: 0;
  cursor: pointer;
  white-space: nowrap;
}

.plotlab-check input[type="checkbox"],
.plotlab-check input[type="radio"] {
  flex: none;
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--accent);
}

.plotlab-hint {
  margin: 0;
  font-size: var(--fs-caption);
  color: var(--muted);
  line-height: 1.4;
}

/* ---------- Utilities ---------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.tablenum {
  font-variant-numeric: tabular-nums;
}

/* ---------- Responsive ---------- */

/* Desktop: lock the workbench to the viewport so the page never scrolls the
   three panels. The data table and the inspector body scroll internally; the
   graph stays fixed. (The single-column stack below keeps normal page scroll.) */
/* Desktop: lock the instrument to the viewport; nothing outside it scrolls. */
@media (min-width: 1101px) {
  .site {
    height: 100vh;
    overflow: hidden;
  }
  /* Footer belongs to the page flow, not the locked app surface. */
  .site-footer {
    display: none;
  }
}

/* ---------- Narrow / vertical (<= 1100px): collapse to one column ----------
   Rails become horizontal top strips; the inspector panel drops below the
   stage; Split is dropped (two columns can't earn their keep without width).
   Placed near the end so these overrides win over the desktop base rules. */
@media (max-width: 1100px) {
  .plot45-app {
    display: flex;
    flex-direction: column;
    height: auto;
  }

  /* Reorder: stage tabs · stage · inspector tabs · inspector panel. */
  .plotlab-rail--stage { order: 1; }
  .plotlab-stage { order: 2; }
  .plotlab-rail--inspector { order: 3; }
  .plotlab-inspector { order: 4; border-left: none; }

  /* Rails fold into horizontal strips; drop the active edge-marker. */
  .plotlab-rail {
    flex-direction: row;
    overflow-x: auto;
  }
  .plotlab-rail--stage {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .plotlab-rail--inspector {
    border-left: none;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }
  .plotlab-rail__tab {
    flex-direction: row;
    gap: 7px;
    width: auto;
    min-height: 46px;
    padding: 9px 14px;
  }
  .plotlab-rail__tab[aria-selected="true"]::after {
    display: none;
  }

  /* Split is desktop-only. */
  #stageTab-split,
  .plotlab-pane--split {
    display: none !important;
  }

  /* Panes stack in normal flow; the graph gets an explicit height. */
  .plotlab-stagebody,
  .plotlab-pane {
    position: static;
  }
  .plotlab-pane[hidden] {
    display: none;
  }
  .plotlab-pane--data {
    height: auto;
  }
  .plotlab-data-scroll {
    overflow: visible;
  }
  .plotlab-pane--graph {
    height: 58vh;
  }

  .plotlab-railpanel__head {
    height: auto;
    min-height: 46px;
    padding: 12px 16px;
  }
  .plotlab-railpanel__body {
    max-height: 60vh;
  }
}

/* ---------- Print: show only the graph (PlotLab.Export.print) ----------
   A beforeprint hook reparents the single graph node into the Graph pane, so
   forcing that pane visible prints correctly from any stage view. */
@media print {
  .site-header,
  .site-footer,
  .plotlab-rail,
  .plotlab-inspector,
  .plotlab-fitslab,
  .plotlab-graph-fs,
  .plotlab-fs-exit {
    display: none !important;
  }

  body,
  .site-main,
  .plot45-app,
  .plotlab-stage,
  .plotlab-stagebody {
    display: block !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    overflow: visible !important;
  }

  .plotlab-pane {
    position: static !important;
    display: none !important;
  }

  .plotlab-pane--graph {
    display: block !important;
    height: auto !important;
    padding: 0 !important;
  }

  .plotlab-graphframe {
    border: none !important;
    height: auto !important;
  }

  .plotlab-svg-wrap {
    height: auto !important;
    min-height: 0 !important;
  }

  #plotSvg {
    width: 100%;
    height: auto;
    max-height: 96vh;
  }
}

/* ---------- Confirmation dialog (PlotLab.Dialog) ---------- */
.plotlab-dialog {
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--text);
  max-width: 30rem;
  width: calc(100vw - 2rem);
  box-shadow: none;
}

.plotlab-dialog::backdrop {
  background: rgba(20, 24, 28, 0.34);
}

.plotlab-dialog__form {
  margin: 0;
  padding: 1rem 1.125rem 0.875rem;
  display: grid;
  gap: 0.625rem;
}

.plotlab-dialog__title {
  margin: 0;
  font-size: var(--fs-title);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.plotlab-dialog__message {
  margin: 0;
  font-size: var(--fs-body);
  line-height: 1.45;
  color: var(--muted);
}

.plotlab-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
