/* Road-viz applet — light mode only (basemap is a light raster). Palette tokens
   from the dataviz reference instance. */
:root {
  --surface-1: #fcfcfb;
  --page: #f4f4f1;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hair: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #256abf;
  --panel-w: 300px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { color: var(--ink); background: var(--page); font-size: 14px; }

#app {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  height: 100vh;
}

.muted { color: var(--muted); font-size: 12px; }

/* ---- Left control panel ---- */
#controls {
  overflow-y: auto;
  padding: 16px 16px 24px;
  background: var(--surface-1);
  border-right: 1px solid var(--hair);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#title-block h1 { font-size: 18px; margin: 0 0 2px; }
#scenario-name { font-size: 12px; }

.ctl { display: flex; flex-direction: column; gap: 5px; }
.ctl-label { font-weight: 600; font-size: 12px; color: var(--ink-2); }
select, input[type="range"] { width: 100%; }
select {
  font-size: 14px; padding: 7px 8px; border: 1px solid var(--border);
  border-radius: 7px; background: #fff; color: var(--ink);
}
input[type="range"] { accent-color: var(--accent); }

.ctl-group { border: 1px solid var(--hair); border-radius: 8px; padding: 10px 12px; }
.ctl-group > summary { font-weight: 600; cursor: pointer; font-size: 13px; }
.ctl-group > .ctl { margin-top: 12px; }

.ctl-overlays.hidden { display: none; }
#fc-checks { display: flex; flex-direction: column; gap: 4px; }
.fc-check { font-size: 13px; display: flex; align-items: center; gap: 6px; text-transform: capitalize; }

#drawer-toggle {
  text-align: left; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 7px; background: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
}
#drawer-toggle:hover { background: #f6f6f4; }
#scenario-picker-placeholder { margin-top: -6px; }

/* ---- Map ---- */
#map-wrap { position: relative; }
#map { position: absolute; inset: 0; }

/* ---- Legend (bottom-left) ---- */
#legend {
  position: absolute; left: 14px; bottom: 22px; z-index: 2;
  background: rgba(252, 252, 251, 0.94); border: 1px solid var(--border);
  border-radius: 9px; padding: 10px 12px; max-width: 280px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08); font-size: 12px;
}
.lg-title { font-weight: 600; margin-bottom: 7px; }
.lg-ramp-wrap { position: relative; height: 12px; }
.lg-ramp { height: 12px; border-radius: 3px; border: 1px solid var(--border); }
.lg-pivot {
  position: absolute; top: -2px; width: 2px; height: 16px; background: var(--ink);
  transform: translateX(-1px);
}
.lg-pivot::after {
  content: attr(data-pivot); position: absolute; top: -13px; left: 50%; transform: translateX(-50%);
  font-size: 9px; color: var(--ink-2); white-space: nowrap;
}
.lg-ends { display: flex; justify-content: space-between; margin-top: 3px; color: var(--ink-2); }
.lg-clamp { margin-top: 3px; font-size: 10px; }
.lg-cats { display: flex; flex-wrap: wrap; gap: 5px 10px; }
.lg-chip { display: inline-flex; align-items: center; gap: 5px; text-transform: capitalize; }
.lg-chip i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }

/* ---- Mobile chrome (hidden on desktop) ---- */
#mobile-bar { display: none; }
.sheet-handle { display: none; }
#controls-close { display: none; }

/* ---- Link inspector (right) ---- */
#inspector {
  position: absolute; top: 0; right: 0; height: 100vh; width: 320px; z-index: 5;
  background: var(--surface-1); border-left: 1px solid var(--hair);
  box-shadow: -3px 0 14px rgba(0, 0, 0, 0.10); overflow-y: auto; padding: 16px 18px 28px;
}
#inspector.hidden, #drawer.hidden { display: none; }
#inspector-close, #drawer-close {
  position: absolute; top: 10px; right: 12px; border: none; background: none;
  font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted);
}
.ins-head { margin-bottom: 12px; padding-right: 20px; }
.ins-name { font-size: 16px; font-weight: 600; }
.ins-id { margin-top: 2px; }
.ins-group { margin-top: 14px; }
.ins-group-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--accent); border-bottom: 1px solid var(--hair); padding-bottom: 3px; margin-bottom: 5px;
}
.ins-table { width: 100%; border-collapse: collapse; }
.ins-table td { padding: 2px 0; vertical-align: top; font-size: 13px; }
.ins-table td:first-child { color: var(--ink-2); padding-right: 10px; }
.ins-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ins-jump {
  margin-top: 8px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; font-size: 12px; cursor: pointer; width: 100%;
}
.ins-jump:hover { background: #f6f6f4; }

.ins-vot { margin-bottom: 6px; }
.vot-bar {
  display: flex; height: 14px; border-radius: 4px; overflow: hidden; margin: 4px 0;
  border: 1px solid var(--border);
}
.vot-seg { display: block; height: 100%; }
.vot-key { display: flex; gap: 12px; }
.vot-key span { display: inline-flex; align-items: center; gap: 4px; }
.vot-key i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

/* ---- Diagnostics drawer ---- */
#drawer {
  position: absolute; top: 0; right: 0; height: 100vh; width: 360px; z-index: 6;
  background: var(--surface-1); border-left: 1px solid var(--hair);
  box-shadow: -3px 0 14px rgba(0, 0, 0, 0.12); overflow-y: auto; padding: 16px 20px 30px;
}
#drawer h2 { font-size: 17px; margin: 0 0 10px; }
.dr-sec { margin-top: 16px; }
.dr-sec h3 { font-size: 13px; margin: 0 0 6px; color: var(--accent); }
.dr-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.dr-table td { padding: 3px 6px 3px 0; border-bottom: 1px solid var(--hair); }
.dr-table td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.dr-th td { font-weight: 600; color: var(--ink-2); }
.dr-flag { color: #d03b3b; font-weight: 700; }
.dr-note { margin: -2px 0 4px; }

/* Gateway / s71 inspector flags. These call out a defect (a gateway that seeds
   nothing, a fired symmetry guard, a gateway sitting on the analysis outline
   rather than at the extract cut), so they are deliberately louder than a table
   row — the whole point is that these were previously invisible. */
.gw-flag { padding: 6px 8px; margin-bottom: 6px; border-radius: 4px;
           font-size: 12px; line-height: 1.35; border-left: 3px solid; }
.gw-bad  { background: #fdecea; border-color: #d03b3b; color: #7d1f1f; }
.gw-warn { background: #fff6e5; border-color: #d08a1e; color: #7a4d06; }
.gw-ok   { background: #eaf4ec; border-color: #2f6f4f; color: #1e4a34; }
.gw-flag code { font-size: 11px; }
.gw-caveat { font-size: 11px; color: var(--muted); font-style: italic;
             margin-top: 4px; }
.ins-table td.sub { padding-left: 10px; color: var(--muted); }
.s71-warn { font-size: 11px; font-style: italic; margin-top: 4px; }

/* modeled-vs-observed scatter */
.sc-svg { width: 100%; height: auto; margin-top: 8px; }
.sc-grid { stroke: var(--hair); stroke-width: 1; }
.sc-frame { fill: none; stroke: var(--border); stroke-width: 1; }
.sc-band30 { fill: #256abf; opacity: 0.08; }
.sc-band10 { fill: #256abf; opacity: 0.12; }
.sc-diag { stroke: #52514e; stroke-width: 1.2; stroke-dasharray: 4 3; }
.sc-tick { fill: var(--muted); font-size: 9px; }
.sc-axis { fill: var(--ink-2); font-size: 10px; }
.sc-pt { cursor: pointer; }
.sc-pt:hover { stroke-width: 1.8; }
.sc-pt:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ==== Mobile (≤720px): map-first + bottom sheets ==========================
   The map owns the viewport; a fixed bottom bar toggles the control sheet and
   the diagnostics sheet. Tapping a link raises the inspector as a half-height
   sheet so the map stays visible above it. Tapping a sheet's handle toggles
   tall (near-full-screen) mode. Desktop layout above is untouched. */
@media (max-width: 720px) {
  :root { --bar-h: calc(52px + env(safe-area-inset-bottom, 0px)); }

  #app { display: block; height: 100vh; height: 100dvh; }
  #map-wrap { position: absolute; inset: 0 0 var(--bar-h) 0; }

  #mobile-bar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0;
    height: var(--bar-h); z-index: 10; gap: 10px;
    padding: 7px 10px calc(7px + env(safe-area-inset-bottom, 0px));
    background: var(--surface-1); border-top: 1px solid var(--hair);
  }
  #mobile-bar button {
    flex: 1; font-size: 14px; font-weight: 600; border: 1px solid var(--border);
    border-radius: 8px; background: #fff; color: var(--ink); cursor: pointer;
  }
  #mobile-bar button[aria-expanded="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

  /* All three panels become bottom sheets docked above the bar. */
  #controls, #inspector, #drawer {
    position: fixed; left: 0; right: 0; bottom: var(--bar-h); top: auto;
    width: auto; height: auto; border: none; border-top: 1px solid var(--hair);
    border-radius: 14px 14px 0 0; box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.16);
    padding-top: 4px; overflow-y: auto;
  }
  #controls {
    z-index: 8; max-height: 70vh;
    transform: translateY(105%); transition: transform 0.18s ease-out;
  }
  #controls.open { transform: none; }
  #inspector { z-index: 5; height: 48vh; }
  #drawer { z-index: 6; height: 56vh; }
  #inspector.tall, #drawer.tall {
    height: calc(100vh - var(--bar-h) - 24px);
    height: calc(100dvh - var(--bar-h) - 24px);
  }

  .sheet-handle {
    display: flex; justify-content: center; padding: 8px 0 4px; cursor: pointer;
  }
  .sheet-handle span { width: 38px; height: 4px; border-radius: 2px; background: var(--hair); }

  /* The bar's buttons replace the in-panel diagnostics toggle. */
  #drawer-toggle { display: none; }
  #controls-close {
    display: block; position: absolute; top: 6px; right: 10px; border: none;
    background: none; font-size: 26px; line-height: 1; padding: 6px; color: var(--muted); cursor: pointer;
  }

  /* Legend moves top-left so sheets don't cover it, and collapses to its
     title chip (tap toggles — wired in app.js). */
  #legend { top: 10px; left: 10px; bottom: auto; max-width: min(62vw, 240px); padding: 8px 10px; cursor: pointer; }
  #legend.collapsed .lg-sec:not(:first-child) { display: none; }
  #legend.collapsed .lg-sec > *:not(.lg-title) { display: none; }
  #legend.collapsed .lg-title { margin-bottom: 0; }
  #legend.collapsed .lg-title::after { content: " ▸"; color: var(--muted); }

  /* Touch targets. 16px select font also stops iOS zoom-on-focus. */
  select { font-size: 16px; padding: 10px; }
  .fc-check { font-size: 15px; padding: 3px 0; }
  .fc-check input, #toggle-counts { width: 18px; height: 18px; }
  input[type="range"] { height: 28px; }
  .ins-jump { padding: 11px 10px; font-size: 13px; }
  #inspector-close, #drawer-close { font-size: 26px; padding: 6px; top: 6px; }
}
