/* Living Ocean V1 — floating left rail (plan §5.3).
   Reuses the page tokens (--glass, --line, --cyan, --text, --muted, --dim, --amber, --top-h, --radius).
   Colour carries meaning: cyan = intelligence, amber = risk. No green anywhere in this file.
   Evidence chip classes (.ev, .ev-*) are owned by the page and provenance.css, not here. */

:root {
  --rail-w: 280px;
  --rail-w-collapsed: 64px;
  --rail-w-phone: 56px;
  --rail-top: calc(env(safe-area-inset-top, 0px) + var(--top-h, 54px) + 14px);
  --rail-left: 16px;
  --rail-gap: 10px;
  --rail-fly-w: 300px;
  --rail-ease: cubic-bezier(.32, .72, .28, 1);
  /* Bottom chrome the rail and flyout must stay clear of (the page sets --time-h / --obs-h / --notices-h). */
  --rail-bottom-clear: calc(var(--bottom-base, env(safe-area-inset-bottom, 0px)) + var(--time-h, 120px) + var(--obs-h, 44px) + 48px);
  /* Phone sheet: sits above the obs row AND the Mapbox control stack the page parks there (compass + zoom ≈ 96 px + 44 px offset). */
  --rail-sheet-bottom: calc(var(--bottom-base, env(safe-area-inset-bottom, 0px)) + var(--time-h, 170px) + var(--obs-h, 44px) + var(--notices-h, 0px) + 44px + 96px + 10px);
}

/* ── Skip link: first tab stop, visible only when focused ─────────────────── */
.rail-skip {
  position: fixed; z-index: 100; left: 16px; top: calc(env(safe-area-inset-top, 0px) + 8px);
  transform: translateY(-200%); padding: 10px 14px; border-radius: 10px;
  background: var(--glass, rgba(10, 20, 32, .9)); border: 1px solid var(--cyan, #35c7ff);
  color: var(--text, #eaf7fd); font-weight: 800; font-size: 13px; text-decoration: none;
}
.rail-skip:focus-visible { transform: none; outline: 2px solid var(--cyan, #35c7ff); outline-offset: 2px; }

/* ── Rail shell ───────────────────────────────────────────────────────────── */
.rail {
  /* The outer nav is a plain fixed column with NO filter or transform, so the
     fixed flyout inside it stays anchored to the viewport. The glass is on .rail-panel. */
  position: fixed; z-index: 40; left: var(--rail-left); top: var(--rail-top);
  width: var(--rail-w); max-height: calc(100vh - var(--rail-top) - var(--rail-bottom-clear));
  display: flex; flex-direction: column;
  color: var(--text, #eaf7fd); font-size: 13.5px; line-height: 1.35;
  transition: width 220ms var(--rail-ease);
}
.rail[data-open="false"] { width: var(--rail-w-collapsed); }
.rail-panel {
  display: flex; flex-direction: column; overflow: hidden; width: 100%; max-height: inherit;
  background: var(--glass, rgba(10, 20, 32, .9)); border: 1px solid var(--line, rgba(226, 249, 255, .12)); border-radius: var(--radius, 16px);
  box-shadow: inset 0 1px 0 rgba(226, 249, 255, .14), 0 18px 50px rgba(2, 8, 14, .55);
  -webkit-backdrop-filter: blur(16px) saturate(1.15); backdrop-filter: blur(16px) saturate(1.15);
}
.rail *, .rail *::before, .rail *::after { box-sizing: border-box; }
.rail button { font: inherit; color: inherit; }
.rail :focus-visible { outline: 2px solid var(--cyan, #35c7ff); outline-offset: 2px; border-radius: 8px; }
.rail [hidden] { display: none !important; }

/* Head */
.rail-head { display: flex; align-items: center; justify-content: space-between; height: 44px; padding: 0 8px 0 14px; border-bottom: 1px solid var(--line, rgba(226, 249, 255, .12)); flex: none; }
.rail-title { font-weight: 800; font-size: 14px; letter-spacing: .02em; white-space: nowrap; }
.rail[data-open="false"] .rail-title { display: none; }
.rail[data-open="false"] .rail-head { justify-content: center; padding: 0; }
.rail-collapse { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line, rgba(226, 249, 255, .12)); background: rgba(226, 249, 255, .06); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.rail-collapse:hover { background: rgba(226, 249, 255, .12); }
.rail-chev { width: 8px; height: 8px; border-left: 2px solid var(--muted, #9fc0d2); border-bottom: 2px solid var(--muted, #9fc0d2); transform: rotate(45deg) translate(1px, -1px); transition: transform 220ms var(--rail-ease); }
.rail[data-open="false"] .rail-chev { transform: rotate(-135deg) translate(1px, -1px); }

/* Rows */
.rail-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; overflow-x: hidden; flex: 1 1 auto; }
.rail-item { position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; border-radius: 12px; }
.rail-item:hover { background: rgba(226, 249, 255, .05); }
.rail-item[data-selected="true"] { background: rgba(53, 199, 255, .10); }
.rail-item[data-selected="true"]::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--cyan, #35c7ff); }
.rail-row {
  display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: center; min-height: 60px; width: 100%;
  padding: 8px 6px 8px 10px; background: none; border: 0; text-align: left; cursor: pointer; border-radius: 12px; min-width: 0;
}
.rail-row[aria-disabled="true"] { cursor: default; }
.rail-row[aria-disabled="true"] .rail-rowtitle { color: var(--dim, #70889a); }
.rail-row[aria-disabled="true"] .rail-thumb { opacity: .55; filter: saturate(.4); }
.rail-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.rail-titleline { display: flex; align-items: center; gap: 6px; min-width: 0; }
.rail-rowtitle { font-weight: 700; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-subtitle { font-size: 10.5px; color: var(--dim, #70889a); line-height: 1.3; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; }
.rail-chip { flex: none; display: inline-flex; }
.rail-subtext { flex: 1 1 auto; min-width: 0; }
.rail-reason { flex-basis: 100%; }
.rail-reason { color: var(--amber, #ffb020); }
.rail[data-open="false"] .rail-text, .rail[data-open="false"] .rail-list .rail-sw { display: none; }
.rail[data-open="false"] .rail-row { grid-template-columns: 40px; justify-content: center; padding: 8px 0; justify-items: center; }
.rail[data-open="false"] .rail-item { grid-template-columns: 1fr; }

/* Thumbnail: a static picture of the layer's look, ringed by its state (on = cyan, off = line, none = no ring) */
.rail-thumb { width: 40px; height: 40px; border-radius: 50%; overflow: hidden; display: inline-flex; flex: none; border: 2px solid var(--line, rgba(226, 249, 255, .12)); background: #0b2238; }
.rail-thumb svg { width: 100%; height: 100%; display: block; }
.rail-thumb[data-on="true"] { border-color: var(--cyan, #35c7ff); box-shadow: 0 0 0 2px rgba(53, 199, 255, .22); }
.rail-thumb[data-on="false"] { border-color: rgba(226, 249, 255, .22); }
.rail-thumb-lg { width: 44px; height: 44px; }
.rail-thumb .t-cyan { stroke: var(--cyan, #35c7ff); }
.rail-thumb .t-cyan-fill { fill: var(--cyan, #35c7ff); }
.rail-thumb .t-text { stroke: var(--text, #eaf7fd); }
.rail-thumb .t-text-fill { fill: var(--text, #eaf7fd); }
.rail-thumb .t-dim { stroke: var(--dim, #70889a); }

/* Switch (role=switch checkbox). Separate hit target from the row body. */
.rail-sw { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; margin-right: 4px; cursor: pointer; flex: none; }
.rail-sw input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: pointer; }
.rail-sw i { position: relative; display: block; width: 38px; height: 22px; border-radius: 999px; background: rgba(226, 249, 255, .14); border: 1px solid var(--line, rgba(226, 249, 255, .12)); transition: background 160ms, border-color 160ms; pointer-events: none; }
.rail-sw i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #c9dbe6; transition: transform 160ms var(--rail-ease), background 160ms; }
.rail-sw input:checked + i { background: rgba(53, 199, 255, .55); border-color: rgba(53, 199, 255, .6); }
.rail-sw input:checked + i::after { transform: translateX(16px); background: #fff; }
.rail-sw input:disabled { cursor: not-allowed; }
.rail-sw input:disabled + i { opacity: .4; }
.rail-sw input:focus-visible + i { outline: 2px solid var(--cyan, #35c7ff); outline-offset: 2px; }

/* ── Flyout (desktop) ─────────────────────────────────────────────────────── */
.rail-flyout {
  position: fixed; z-index: 41; top: var(--rail-top); left: calc(var(--rail-left) + var(--rail-w) + var(--rail-gap));
  width: var(--rail-fly-w); max-height: calc(100vh - var(--rail-top) - var(--rail-bottom-clear)); overflow-y: auto;
  background: var(--glass, rgba(10, 20, 32, .9)); border: 1px solid var(--line, rgba(226, 249, 255, .12)); border-radius: var(--radius, 16px);
  box-shadow: inset 0 1px 0 rgba(226, 249, 255, .14), 0 18px 50px rgba(2, 8, 14, .55);
  -webkit-backdrop-filter: blur(16px) saturate(1.15); backdrop-filter: blur(16px) saturate(1.15);
  color: var(--text, #eaf7fd); font-size: 13px; transition: left 220ms var(--rail-ease);
}
.rail[data-open="false"] .rail-flyout { left: calc(var(--rail-left) + var(--rail-w-collapsed) + var(--rail-gap)); }
.rail-fly-head { display: grid; grid-template-columns: 44px 1fr 44px; gap: 10px; align-items: center; padding: 12px 8px 10px 14px; border-bottom: 1px solid var(--line, rgba(226, 249, 255, .12)); }
.rail-fly-text { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; }
.rail-fly-title { font-weight: 800; font-size: 15px; }
.rail-fly-sub { font-size: 11px; color: var(--muted, #9fc0d2); }
.rail-close { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line, rgba(226, 249, 255, .12)); background: rgba(226, 249, 255, .06); cursor: pointer; font-size: 20px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; color: var(--muted, #9fc0d2); }
.rail-close:hover { background: rgba(226, 249, 255, .12); color: var(--text, #eaf7fd); }
.rail-fly-body { padding: 6px 14px 12px; }
.rail-fly-note { margin: 10px 0; font-size: 12px; color: var(--muted, #9fc0d2); }

/* Controls */
.rail-ctl { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px; min-height: 44px; padding: 6px 0; border-top: 1px solid var(--line, rgba(226, 249, 255, .12)); }
.rail-ctl:first-child, .rail-ctl-vis + .rail-ctl { border-top-color: transparent; }
.rail-ctl-vis { border-top: 0; }
.rail-ctl-lab { font-weight: 600; font-size: 12.5px; display: flex; flex-direction: column; gap: 1px; cursor: pointer; }
.rail-ctl-note { font-weight: 500; font-size: 10.5px; color: var(--dim, #70889a); line-height: 1.3; }
.rail-ctl-reason { font-weight: 600; font-size: 10.5px; color: var(--amber, #ffb020); line-height: 1.3; }
.rail-ctl-switch .rail-sw { margin-right: -6px; }
.rail-ctl-range { grid-template-columns: 1fr auto; }
.rail-ctl-range input[type="range"] { grid-column: 1 / -1; width: 100%; margin: 2px 0 4px; accent-color: var(--cyan, #35c7ff); height: 28px; cursor: pointer; }
.rail-ctl-range input[type="range"]:disabled { opacity: .4; cursor: not-allowed; }
.rail-ctl-val { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted, #9fc0d2); font-weight: 700; }
.rail-ctl-seg { margin: 0; padding: 6px 0; border: 0; border-top: 1px solid var(--line, rgba(226, 249, 255, .12)); display: grid; grid-template-columns: 1fr auto; align-items: center; }
.rail-ctl-seg legend { padding: 0; float: left; }
.rail-seg { display: inline-flex; border: 1px solid var(--line, rgba(226, 249, 255, .12)); border-radius: 10px; overflow: hidden; background: rgba(226, 249, 255, .04); }
.rail-seg input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.rail-seg label { padding: 0 12px; min-width: 44px; height: 36px; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--muted, #9fc0d2); cursor: pointer; border-left: 1px solid var(--line, rgba(226, 249, 255, .12)); }
.rail-seg label:first-of-type { border-left: 0; }
.rail-seg input:checked + label { background: rgba(53, 199, 255, .22); color: var(--cyan, #35c7ff); }
.rail-seg input:focus-visible + label { outline: 2px solid var(--cyan, #35c7ff); outline-offset: -2px; }
.rail-ctl-button { grid-template-columns: 1fr; }
.rail-btn { width: 100%; min-height: 44px; border-radius: 10px; border: 1px solid rgba(53, 199, 255, .4); background: rgba(53, 199, 255, .12); color: var(--text, #eaf7fd); font-weight: 700; cursor: pointer; }
.rail-btn:hover { background: rgba(53, 199, 255, .2); }

/* ── Phone (<900 px): 56 px icon column + sheet in the band above the bottom chrome ── */
@media (max-width: 899px) {
  .rail, .rail[data-open="false"], .rail[data-open="true"] { width: var(--rail-w-phone); max-height: calc(100vh - var(--rail-top) - var(--rail-sheet-bottom)); }
  .rail-head { display: none; }
  .rail-list { padding: 4px; }
  .rail-item, .rail[data-open="true"] .rail-item { grid-template-columns: 1fr; }
  .rail-row, .rail[data-open="true"] .rail-row { grid-template-columns: 40px; justify-items: center; min-height: 56px; min-width: 48px; padding: 8px 0; }
  .rail-text, .rail-list .rail-sw, .rail[data-open="true"] .rail-text, .rail[data-open="true"] .rail-list .rail-sw { display: none; }
  .rail-item[data-selected="true"]::before { left: -2px; }
  .rail-flyout, .rail[data-open="false"] .rail-flyout {
    top: auto; left: calc(var(--rail-left) + var(--rail-w-phone) + 8px); right: 16px; width: auto;
    bottom: var(--rail-sheet-bottom);
    max-height: calc(100vh - var(--rail-top) - var(--rail-sheet-bottom));
    transition: none;
  }
  .rail-fly-head { padding: 10px 6px 8px 12px; }
  .rail-fly-body { padding: 4px 12px 10px; }
}

/* ── Reduced motion: no transitions, from the media query or the store ─────── */
@media (prefers-reduced-motion: reduce) {
  .rail, .rail *, .rail *::before, .rail *::after { transition: none !important; animation: none !important; }
}
.rail[data-reduced="true"], .rail[data-reduced="true"] *, .rail[data-reduced="true"] *::before, .rail[data-reduced="true"] *::after { transition: none !important; animation: none !important; }
