/* Calibration page — layout and chart styles.
   Shares scenario_results.css for the sidebar-title / nav idiom; everything
   here is page-specific. Light mode only, matching the host applet. */

.calib-page {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, sans-serif;
  font-size: 14px;
}

/* Series and scale roles (validated palette — see dataviz notes in LOG):
   modeled = blue, target = orange; diverging ASC wash blue↔red over a
   neutral midpoint; status colors reserved for flags, always icon+label. */
.calib-page {
  --series-modeled: #2a78d6;
  --series-target:  #eb6834;
  --div-pos: #2a78d6;
  --div-neg: #e34948;
  --div-mid: #f0efec;
  --status-warning: #fab219;
  --ink-secondary: #52514e;
  --ink-muted: #898781;
  --hairline: #e1e0d9;
  --surface: #fcfcfb;
}

/* Calibration-page tokens (rung 1): page-specific values, inheriting :root above. */
.calib-page {
  --ink: #0b0b0b;
  --heading: #0d3266;
  --page: #f9f9f7;
  --th-bg: #f2f5fa;
  --seghead-bg: #f7f9fc;
  --tt-muted: #b9c2d0;
  --axis: #c3c2b7;
  --ok-bg: #e2f2e2;
  --ok-text: #006300;
  --bad-bg: #fdf0d5;
  --kink-bicycle: #1baf7a;
  --tooltip-bg: rgba(20, 26, 36, 0.94);
  --on-dark: #fff;
}

.calib-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--n-ff); border-bottom: 1px solid var(--n-dd);
}
.calib-header #panel-title { border-bottom: none; max-width: 1080px; margin: 0 auto; }
.calib-header .applet-nav { max-width: 280px; }

.calib-main {
  /* `width: 100%` is load-bearing: body is a column flexbox (shared
     sheet) and `margin: 0 auto` makes main a fit-content flex item, so a
     table wider than the screen would widen main instead of scrolling. */
  width: 100%; max-width: 1080px;
  margin: 0 auto;
  padding: 18px 24px 64px;
}
.calib-main h1 { font-size: 20px; font-weight: 700; margin: 8px 0 4px; }
.calib-main h2 { font-size: 15px; font-weight: 700; color: var(--heading); margin: 28px 0 6px; }
.calib-main h3 { font-size: 13px; font-weight: 600; color: var(--accent-deep); margin: 14px 0 4px; }
.calib-intro, .calib-note { font-size: 12.5px; color: var(--ink-secondary); max-width: 72ch; }
.calib-loading { color: var(--ink-muted); font-size: 12px; }
.calib-unavailable { color: var(--ink-muted); font-size: 12px; font-style: italic; }

/* ---- Convergence ---- */
.conv-headline { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.conv-pill {
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
}
.conv-pill.ok  { background: var(--ok-bg); color: var(--ok-text); }
.conv-pill.bad { background: var(--bad-bg); color: var(--warn-text); }
.conv-facts { font-size: 12.5px; color: var(--ink-secondary); }
.conv-spark { display: block; max-width: 440px; height: auto; }
.conv-spark .spark-line { fill: none; stroke: var(--series-modeled); stroke-width: 2; }
.conv-spark .spark-tol  { stroke: var(--ink-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.conv-spark .spark-dot  { fill: var(--series-modeled); }
.conv-spark .spark-hit  { fill: transparent; cursor: default; }
.conv-spark text { font-size: 10px; fill: var(--ink-muted); }
details.conv-history { margin-top: 8px; font-size: 12px; }
details.conv-history summary { cursor: pointer; color: var(--accent-deep); font-weight: 600; }

/* ---- Tables (ASC + iteration history) ---- */
.calib-table {
  border-collapse: collapse; margin-top: 8px; font-size: 12px;
  background: var(--surface);
}
.calib-table th, .calib-table td {
  border: 1px solid var(--hairline); padding: 4px 8px; text-align: right;
  font-variant-numeric: tabular-nums;
}
.calib-table th { background: var(--th-bg); color: var(--accent-deep); font-weight: 600; }
.calib-table td.rowhead, .calib-table th.rowhead { text-align: left; font-weight: 600; color: var(--n-33); }
.calib-table td.seghead {
  text-align: left; font-weight: 700; color: var(--heading); background: var(--seghead-bg);
  vertical-align: top;
}
.calib-table td.absent { color: var(--n-bb); text-align: center; }
.calib-table td.anchor { color: var(--ink-muted); }
.asc-cell { position: relative; cursor: default; }
.asc-cell .asc-badges { font-size: 10px; margin-left: 3px; }
.asc-flag-icon { color: var(--warn-text); }
.asc-bundle-tag {
  font-size: 9.5px; font-weight: 700; color: var(--n-55);
  background: var(--n-ee); border-radius: 3px; padding: 0 3px; margin-left: 3px;
}
.asc-legend { font-size: 11.5px; color: var(--ink-secondary); margin-top: 6px; max-width: 80ch; }
.asc-legend .asc-bundle-tag { font-size: 9.5px; }

/* ---- Mode-share dumbbells ---- */
.share-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 10px;
}
@media (max-width: 900px) { .share-grid { grid-template-columns: 1fr; } }
.share-panel {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 6px; padding: 8px 10px 10px;
}
.share-panel h3 { margin: 0 0 6px; }
.share-row { margin: 6px 0; }
.share-row .row-top { display: flex; align-items: center; gap: 8px; }
.share-row .mode-name { font-size: 11px; font-weight: 600; color: var(--n-33); flex: none; white-space: nowrap; }
.share-row .mode-asc { font-weight: 600; color: var(--ink-secondary); font-variant-numeric: tabular-nums; }
.share-row .row-top .share-track { flex: 1; min-width: 40px; }
.share-row .share-nums { display: block; font-size: 10.5px; color: var(--ink-secondary); margin-top: 1px; white-space: nowrap; }
.share-row .thin-badge { color: var(--warn-text); font-size: 10px; }
.share-track { display: block; }
.share-track .track-base { stroke: var(--hairline); stroke-width: 1; }
.share-track .db-conn { stroke: var(--ink-muted); stroke-width: 2; }
.share-track .db-target { fill: var(--series-target); }
.share-track .db-modeled { fill: var(--series-modeled); }
.chart-legend { display: flex; gap: 16px; font-size: 11.5px; color: var(--ink-secondary); margin: 8px 0 0; }
.chart-legend .swatch {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-right: 5px; vertical-align: baseline;
}

/* ---- TLFD bars ---- */
.tlfd-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 10px; }
@media (max-width: 900px) { .tlfd-grid { grid-template-columns: 1fr; } }
.tlfd-panel {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 6px; padding: 8px 10px 4px;
}
.tlfd-panel h3 { margin: 0 0 4px; }
.tlfd-svg .bar-target { fill: var(--series-target); }
.tlfd-svg .bar-modeled { fill: var(--series-modeled); }
.tlfd-svg .axis-line { stroke: var(--axis); stroke-width: 1; }
.tlfd-svg .gridline { stroke: var(--hairline); stroke-width: 1; }
.tlfd-svg text, .kink-svg text { font-size: 9.5px; fill: var(--ink-muted); }
.tlfd-svg .lane-label, .kink-svg .lane-label { font-size: 8.5px; fill: var(--ink-muted); }
.tlfd-svg .bar-hit { fill: transparent; }
.tlfd-svg .band-excluded { opacity: 0.35; }
.tlfd-svg .band-excluded .bar-target,
.tlfd-svg .band-excluded .bar-modeled { fill: var(--ink-muted); }
.tlfd-svg .argmax-wash { fill: var(--bad-bg); }
.tlfd-svg .resid-pos { stroke: var(--div-pos); stroke-width: 4; stroke-linecap: round; }
.tlfd-svg .resid-neg { stroke: var(--div-neg); stroke-width: 4; stroke-linecap: round; }
.tlfd-svg .k-stem { stroke: var(--ink-muted); stroke-width: 1.5; }
.tlfd-svg .k-pos { fill: var(--div-pos); }
.tlfd-svg .k-neg { fill: var(--div-neg); }
.tlfd-svg .k-anchor { fill: var(--surface); stroke: var(--ink-muted); stroke-width: 1.5; }
.tlfd-svg .k-lbl { font-size: 9px; fill: var(--ink-secondary); font-weight: 600; font-variant-numeric: tabular-nums; }
.tlfd-argmax-note { font-size: 10.5px; color: var(--warn-text); margin-top: 2px; }
.tlfd-svg .zc-tick { stroke: var(--ink-secondary); stroke-width: 2; }
.chart-legend .swatch-tick { background: none; border-top: 2px solid var(--ink-secondary); height: 0; width: 12px; border-radius: 0; vertical-align: middle; }
.tlfd-diag-note { font-size: 10.5px; color: var(--ink-secondary); font-weight: 600; margin-top: 2px; cursor: default; }

/* ---- Kink curves ---- */
.kink-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.kink-wrap .kink-svg { max-width: 360px; flex: 1 1 280px; }
.kink-svg .kink-identity { stroke: var(--ink-muted); stroke-width: 1; stroke-dasharray: 4 3; }
.kink-svg .kink-line { fill: none; stroke-width: 2; }
.kink-svg .kink-line.kink-walk, .kink-svg .kink-knee.kink-walk { stroke: var(--series-modeled); }
.kink-svg .kink-knee { fill: var(--surface); stroke-width: 2; }
.kink-svg .kink-line.kink-bicycle, .kink-svg .kink-knee.kink-bicycle { stroke: var(--kink-bicycle); }
.kink-svg text.kink-tag { font-size: 9.5px; fill: var(--ink-secondary); font-weight: 600; }
.kink-facts { font-size: 12px; color: var(--ink-secondary); flex: 1 1 260px; }
.kink-facts > div { margin: 4px 0; }
.kink-facts .kink-status { color: var(--ink-muted); font-size: 11px; }
.kink-swatch { display: inline-block; width: 14px; height: 3px; margin-right: 6px; vertical-align: middle; }
.kink-swatch.kink-walk { background: var(--series-modeled); }
.kink-swatch.kink-bicycle { background: var(--kink-bicycle); }

/* ---- Tooltip ---- */
#calib-tooltip {
  position: fixed; z-index: 100; pointer-events: none;
  background: var(--tooltip-bg); color: var(--on-dark);
  font-size: 11.5px; line-height: 1.45;
  padding: 6px 9px; border-radius: 5px; max-width: 320px;
}
#calib-tooltip .tt-title { font-weight: 700; }
#calib-tooltip .tt-muted { color: var(--tt-muted); }

/* ==== Phone (≤760px) ======================================================
   The same width term as the map applet's phone sheet (scenario_results.
   mobile.css / LAYOUT_MQ), so the nav strip changes shape at the same width
   on every page; the map's max-height term is a landscape-map concern and
   does not apply to a scrolling document. This page reuses the map's
   `#panel-title` markup, so the header rules below mirror S9's sheet header
   (12px title, full-width nav, subtitle · © on one line) rather than load
   scenario_results.mobile.css, whose other rules are about the map frame.
   Desktop rules above are untouched. */
@media (max-width: 760px) {
  /* Static, not sticky: a sticky header costs ~90px of every phone screen
     on a ~4800px document; the nav is one scroll-to-top away (Taylor,
     2026-09-11). */
  .calib-header { position: static; }
  .calib-header #panel-title {
    display: flex; flex-wrap: wrap; align-items: center; padding: 8px 12px 6px;
  }
  .calib-header #panel-title h2 {
    flex: 0 0 100%; font-size: 12px; font-weight: 600; color: var(--n-55); line-height: 18px;
  }
  .calib-header .applet-nav { flex: 0 0 100%; max-width: none; margin-top: 4px; border-radius: 6px; }
  .calib-header .applet-nav a { padding: 7px 8px; font-size: 12px; }
  .calib-header #panel-title .subtitle { flex: 0 1 auto; margin: 5px 6px 0 0; font-size: 11px; color: var(--n-55); }
  .calib-header #panel-title .subtitle:empty { display: none; }
  .calib-header #panel-title .copyright { flex: 1 1 auto; margin: 5px 0 0; font-size: 11px; color: var(--n-6b); }
  .calib-header #panel-title .subtitle:not(:empty) + .copyright::before { content: "\00b7\00a0"; }

  .calib-main { padding: 6px 12px 40px; }
  .calib-main h1 { font-size: 18px; margin: 10px 0 4px; }
  .calib-main h2 { margin: 22px 0 6px; }
  .calib-intro, .calib-note { font-size: 13px; }

  /* Tables wider than the phone scroll inside their own box (ruling D3, the
     same treatment as the dock's tables). The ASC table is ~720px at 12px;
     11.5px and tighter cells bring it to ~620, still two screens wide. The
     table's own box becomes the scroller, so no wrapper markup is needed. */
  .calib-table {
    display: block; overflow-x: auto; max-width: 100%;
    -webkit-overflow-scrolling: touch; font-size: 11.5px;
  }
  .calib-table th, .calib-table td { padding: 4px 6px; white-space: nowrap; }
  .calib-table td.seghead { white-space: normal; }

  .conv-spark text { font-size: 12px; }   /* scaled ≈0.8 by the viewBox at 390 */
  /* Legend entries wrap as units (swatch + label), the note on its own line. */
  .chart-legend { flex-wrap: wrap; gap: 4px 14px; }
  .chart-legend > span { white-space: nowrap; }
  .chart-legend > .tt-like { flex: 0 0 100%; white-space: normal; }
  .share-grid, .tlfd-grid { gap: 10px; }
  .kink-wrap { gap: 10px; }
  .kink-wrap .kink-svg { max-width: none; }

  /* Tap, not hover: mobile browsers synthesize mouseenter on tap, so the
     tooltip already opens; it just must not run off a 320px screen. */
  #calib-tooltip { max-width: calc(100vw - 16px); }
}
