/* Apex Delta web workspace: the tablet's dark palette, map beside telemetry when wide. */
:root {
  color-scheme: dark;
  --bg: rgb(12, 12, 12);
  --panel: rgb(16, 20, 22);
  --panel-2: rgb(20, 24, 27);
  --line: rgb(42, 49, 53);
  --line-2: rgb(55, 62, 64);
  --text: rgb(232, 238, 240);
  --muted: rgb(151, 163, 169);
  --dim: rgb(100, 117, 126);
  --selected: rgb(64, 174, 255);
  --reference: rgb(235, 72, 72);
  --accent: rgb(45, 160, 255);
  --line-mark: rgb(190, 225, 145);
  --good: rgb(43, 215, 125);
  --bad: rgb(255, 118, 126);
  --radius: 10px;
  --gutter: 16px;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); display: flex; flex-direction: column; overflow: hidden; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
kbd { font: 12px/1 ui-monospace, monospace; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 2px 5px; color: var(--text); background: var(--panel-2); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bar { display: flex; align-items: center; gap: 12px; padding: 8px var(--gutter); min-height: 52px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 650; letter-spacing: .02em; white-space: nowrap; }
.bar-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title .sub { color: var(--muted); font-weight: 400; margin-left: 8px; }
.bar-actions { display: flex; align-items: center; gap: 12px; }
.who { color: var(--muted); max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.text-button { white-space: nowrap; background: none; border: 0; color: var(--muted); padding: 6px 4px; cursor: pointer; border-radius: 6px; }
.text-button:hover { color: var(--text); }
.icon-button { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer; font-size: 18px; line-height: 1; }
.icon-button:hover { border-color: var(--dim); }
.icon-button svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; fill: none; }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 10px 16px; font-weight: 600; cursor: pointer; }
.primary:disabled { opacity: .55; cursor: default; }

main { flex: 1; min-height: 0; display: flex; }

/* sign-in */
.gate { flex: 1; display: flex; overflow: auto; padding: clamp(24px, 5vw, 88px); }
.gate-layout { margin: auto; width: min(100%, 1190px); display: grid; grid-template-columns: minmax(270px, .72fr) minmax(0, 1.28fr); align-items: center; gap: clamp(40px, 7vw, 108px); }
.gate-card { width: min(100%, 370px); display: flex; flex-direction: column; gap: 18px; justify-self: center; }
.gate-card h1 { margin: 0; font-size: clamp(2.2rem, 3.7vw, 3.7rem); line-height: 1.08; letter-spacing: -.045em; }
.gate-card p { margin: 0; }
.gate-card #gate-intro { font-size: 1.08rem; line-height: 1.55; }
.gate-card form { display: flex; flex-direction: column; gap: 9px; margin-top: 8px; }
.gate-card label { color: var(--text); font-size: .97rem; }
.gate-card input { width: 100%; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 12px 14px; font-size: max(16px, 1.06rem); }
.gate-card .primary { min-height: 44px; margin-top: 5px; background: var(--line-mark); border-color: var(--line-mark); color: #17200f; font-weight: 650; }
.gate-card .primary:hover { background: #cef1a3; }
.gate-card :focus-visible { outline-color: var(--line-mark); }
.gate-preview { margin: 0; min-width: 0; border: 1px solid var(--line-2); border-radius: 12px; background: var(--panel); overflow: hidden; }
.gate-preview figcaption { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 14px 18px; font-weight: 650; border-bottom: 1px solid var(--line); }
.gate-key { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .9rem; font-weight: 450; }
.gate-key i { width: 17px; height: 3px; border-radius: 2px; background: var(--selected); }
.gate-key i + i { margin-left: 8px; background: var(--reference); }
.gate-preview img { width: 100%; height: auto; display: block; }
.gate-preview p { margin: 0; padding: 12px 18px 15px; border-top: 1px solid var(--line); color: var(--muted); font-size: .94rem; line-height: 1.6; }
.gate-preview kbd { white-space: nowrap; }
@media (max-width: 740px) {
  .gate { padding: 26px 20px; }
  .gate-layout { width: min(100%, 430px); grid-template-columns: minmax(0,1fr); gap: 30px; }
  .gate-card { width: 100%; gap: 13px; }
  .gate-preview figcaption, .gate-preview p { padding-inline: 12px; }
}
#code { letter-spacing: .3em; font-variant-numeric: tabular-nums; font-size: 20px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.message { min-height: 1.4em; color: var(--bad); }
.message.ok { color: var(--muted); }

/* workspace */
.workspace { flex: 1; min-width: 0; display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 0; }
.workspace.rail-hidden { grid-template-columns: 0 minmax(0, 1fr); }
.workspace.rail-hidden .rail { visibility: hidden; }
.rail { border-right: 1px solid var(--line); background: var(--panel); min-height: 0; display: flex; flex-direction: column; }
.rail-scroll { overflow: auto; padding: 8px 0 24px; }
.group-title { position: sticky; top: 0; z-index: 1; background: var(--panel); padding: 10px var(--gutter) 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.day-title { padding: 8px var(--gutter) 2px; font-size: 13px; color: var(--dim); }
.entry { display: flex; flex-direction: column; width: 100%; text-align: left; background: none; border: 0; border-left: 3px solid transparent; padding: 7px var(--gutter) 7px calc(var(--gutter) - 3px); cursor: pointer; }
.entry:hover { background: var(--panel-2); }
.entry[aria-current="true"] { background: var(--panel-2); border-left-color: var(--selected); }
.entry .primary-line { display: flex; justify-content: space-between; gap: 8px; }
.entry .secondary-line { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .time { font-variant-numeric: tabular-nums; color: var(--muted); }
.entry.unsupported .primary-line { color: var(--muted); }
.more { margin: 8px var(--gutter); }

.stage { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.state { margin: auto; max-width: 46ch; text-align: center; color: var(--muted); padding: var(--gutter); }
.state:empty { display: none; }
.state.error { color: var(--bad); }
/* The comparison screen follows the tablet: map on the left, lap controls above the charts. */
.stage-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "map pickers" "map channels" "map note";
  gap: 0 6px;
  padding: 0 6px 4px;
  background: #000;
}
.laps-bar { grid-area: pickers; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.picker { --lap-color: var(--selected); position: relative; min-width: 0; background: #080f13; }
.picker[data-kind="reference"] { --lap-color: var(--reference); background: #100e10; }
.picker + .picker { border-left: 1px solid var(--line); }
.picker-label {
  position: absolute;
  left: 14px;
  top: 8px;
  pointer-events: none;
  color: var(--muted);
  font: 650 11px/1.15 Roboto, system-ui, sans-serif;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.picker-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1px 10px;
  align-content: start;
  position: relative;
  width: 100%;
  min-height: 82px;
  padding: 25px 32px 8px 14px;
  text-align: left;
  border: 0;
  border-bottom: 2px solid var(--lap-color);
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}
.picker-button:hover, .picker-button[aria-expanded="true"] { background: rgb(255 255 255 / 6%); }
.picker-title, .picker-sub { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.picker-title { font-weight: 650; font-size: clamp(13px, 1vw, 16px); }
.picker-time, .picker-row-time { color: var(--lap-color); font-variant-numeric: tabular-nums; white-space: nowrap; }
.picker-time { font-size: clamp(16px, 1.35vw, 21px); line-height: 1.2; font-weight: 650; }
.picker-sub { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
.picker-caret { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text); }
.picker-panel {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  width: max(100%, min(400px, 90vw));
  max-height: min(68dvh, 620px);
  background: #11171a;
  border: 1px solid var(--line-2);
  border-top-color: var(--lap-color);
  border-radius: 0 0 7px 7px;
  box-shadow: 0 8px 24px #000a;
  overflow: hidden;
}
.picker[data-kind="reference"] .picker-panel { right: 0; left: auto; }
.picker-scroll { min-height: 0; overflow: auto; overscroll-behavior: contain; }
.picker-heading { padding: 9px 12px 5px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.picker-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-content: center;
  gap: 1px 12px;
  width: 100%;
  min-height: 44px;
  background: transparent;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 0;
  color: var(--text);
  padding: 6px 14px 6px 9px;
  text-align: left;
  cursor: pointer;
}
.picker-row-title { font-weight: 550; }
.picker-row-sub, .picker-status { font-size: 12px; color: var(--muted); }
.picker-row-sub { grid-column: 1 / -1; overflow-wrap: anywhere; }
.picker-row[aria-selected="true"] { background: #1b2328; border-left-color: var(--lap-color); }
.picker-row:hover:not([aria-disabled="true"]), .picker-row:focus-visible { background: #263138; }
.picker-row:focus-visible { outline-offset: -2px; }
.picker-row[aria-disabled="true"] { color: var(--muted); cursor: default; }
.picker-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; padding: 5px 10px; border-top: 1px solid var(--line); }
.picker-foot:empty { display: none; }
.picker-foot .text-button { color: var(--text); white-space: normal; text-align: left; min-height: 36px; }
select { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 8px; max-width: 100%; }
.note { margin: 0; color: var(--muted); font-size: 13px; min-height: 1.3em; }
.note.warn { color: rgb(255, 158, 42); }

.panes { display: contents; }
.stage-body .pane { border: 0; border-radius: 0; background: #000; }
.stage-body .map-pane {
  grid-area: map;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto auto;
  grid-template-areas: "track track" "tools legend" "hint hint";
  border-right: 1px solid #262a2d;
}
.stage-body .chart-pane { grid-area: channels; }
.stage-body .note { grid-area: note; padding: 3px 10px; font-size: 12px; }
.stage-body .note:empty { display: none; }
.pane { position: relative; margin: 0; min-height: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.pane canvas { flex: 1; min-height: 0; width: 100%; display: block; touch-action: none; cursor: crosshair; }
.map-pane canvas {
  grid-area: track;
  height: 100%;
  cursor: grab;
  --grid-line: transparent calc(50% - .5px), #161a1c calc(50% - .5px) calc(50% + .5px), transparent calc(50% + .5px);
  background-image: linear-gradient(to right, var(--grid-line)), linear-gradient(to bottom, var(--grid-line));
  background-size: 20% 20%;
}
.map-pane canvas.dragging { cursor: grabbing; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; padding: 8px 12px 0; font-size: 13px; color: var(--muted); }
.swatch { display: inline-block; width: 18px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.map-tools { grid-area: tools; display: flex; gap: 3px; align-self: center; margin: 4px 6px; }
.map-tools .icon-button { background: #11161af0; }
.map-gesture-hint { grid-area: hint; margin: 0; padding: 2px 8px 6px; color: var(--muted); font-size: 12px; }
.map-pane .legend {
  grid-area: legend;
  align-self: center;
  align-content: center;
  justify-content: flex-end;
  min-height: 45px;
  padding: 4px 8px;
  gap: 2px 10px;
  text-align: right;
  font-size: 12px;
}
.gl-legend { display: inline-flex; flex-wrap: wrap; gap: 2px 7px; }
.gl-total { font-weight: 650; font-variant-numeric: tabular-nums; }
.gl-total.is-gain { color: #ff706f; }
.gl-total.is-loss { color: #50b4ff; }
.swatch.gain, .swatch.even, .swatch.loss { width: 8px; height: 8px; border-radius: 50%; margin: 0 4px 1px; }
.swatch.gain { background: rgb(255,25,45); }
.swatch.even { background: #fff; }
.swatch.loss { background: rgb(0,110,255); }

.charts-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.charts-scroll canvas { height: 100%; }
.charts-scroll canvas.pointer-focus { outline: none; }
.charts-scroll.is-scrolling canvas { touch-action: pan-y; }
.chart-tools { flex: none; position: relative; padding: 4px 8px; border-top: 1px solid var(--line); background: var(--panel); }
.channel-picker summary {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  padding: 4px 8px;
  border-radius: 5px;
  cursor: pointer;
  list-style: none;
}
.channel-picker summary::-webkit-details-marker { display: none; }
.channel-picker summary::after { content: "▴"; color: var(--muted); }
.channel-picker[open] summary::after { content: "▾"; }
.channel-picker summary:hover, .channel-picker[open] summary { background: var(--panel-2); }
.channel-summary-title { font-weight: 650; }
.channel-count, .channel-unit, .channel-note, .channel-status { color: var(--muted); font-size: 12px; }
.channel-panel {
  position: absolute;
  z-index: 3;
  bottom: 100%;
  left: 8px;
  width: min(400px, calc(100% - 16px));
  max-height: min(38dvh, 350px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #11171a;
  border: 1px solid var(--line-2);
  border-radius: 7px 7px 0 0;
  box-shadow: 0 -6px 18px #0008;
}
.channel-options-scroll { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.channel-options { margin: 0; border: 0; padding: 4px 0; min-width: 0; }
.channel-option { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 7px 12px; min-height: 40px; cursor: pointer; }
.channel-option:hover, .channel-option:focus-within { background: var(--panel-2); }
.channel-option input { margin: 0; accent-color: var(--selected); }
.channel-note { margin-left: auto; }
.channel-actions { flex: none; padding: 2px 10px; border-top: 1px solid var(--line); }
.channel-actions button { color: var(--text); }
.channel-status { margin: 3px 12px 6px; }
.channel-status:empty { display: none; }
.readout { display: flex; flex-wrap: wrap; gap: 2px 16px; padding: 4px 12px 0; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--text); min-height: 1.4em; }
.chart-pane .readout { max-height: 5em; overflow-y: auto; }
.readout > span { white-space: nowrap; }
.readout b { font-weight: 500; color: var(--muted); }
.readout .ref-value { color: var(--reference); }
.readout .value.behind { color: #50b4ff; }
.readout .value.ahead { color: #ff706f; }
.entry.pending .primary-line { color: var(--muted); }
.state .primary { margin-top: 12px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 20px; max-width: min(480px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0 0 16px; }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }

/* narrow: the list becomes a drawer; map and charts stack and scroll */
@media (max-width: 899px) {
  .workspace, .workspace.rail-hidden { grid-template-columns: minmax(0, 1fr); }
  .rail { position: fixed; inset: var(--bar-height, 52px) auto 0 0; width: min(320px, 88vw); z-index: 5; box-shadow: 8px 0 24px rgba(0, 0, 0, .5); }
  .workspace.rail-hidden .rail { display: none; }
  .who { max-width: 17ch; }
  .bar { flex-wrap: wrap; row-gap: 4px; padding-block: 6px; }
  .bar-title { order: 3; flex-basis: 100%; font-size: 14px; }
  .bar-actions { margin-left: auto; }

}
@media (max-width: 899px) and (orientation: portrait), (max-width: 650px) {
  .stage { overflow: auto; }
  .stage-body {
    flex: none;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas: "pickers" "map" "channels" "note";
    gap: 0;
    padding: 0 4px 6px;
  }
  .stage-body .map-pane { height: clamp(270px, 48dvh, 570px); border-right: 0; border-bottom: 1px solid var(--line); }
  .stage-body .chart-pane { height: max(360px, 58dvh); }
  .picker-panel { max-width: calc(100vw - 10px); }
}
@media (max-width: 520px), (min-width: 651px) and (max-width: 1080px) and (orientation: landscape) {
  .picker-button { grid-template-columns: minmax(0, 1fr); padding-right: 24px; padding-left: 9px; }
  .picker-label { left: 9px; }
  .picker-time { grid-row: 2; }
  .picker-sub { display: none; }
  .picker-caret { right: 8px; }
}
/* sections (only the catalogue administrator sees them) */
.tabs { display: flex; gap: 4px; }
.tab { background: none; border: 1px solid transparent; border-radius: 8px; color: var(--muted); padding: 6px 12px; cursor: pointer; }
.tab[aria-pressed="true"] { color: var(--text); border-color: var(--line-2); background: var(--panel-2); }

/* the Tracks tab */
.admin { flex: 1; min-width: 0; display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 0; }
.admin-list { border-right: 1px solid var(--line); background: var(--panel); min-height: 0; display: flex; flex-direction: column; }
.admin-tools { display: flex; gap: 8px; align-items: center; padding: 10px var(--gutter); }
.admin-list .rail-scroll { flex: 1; }
.snapshot { display: block; padding: 10px var(--gutter); text-decoration: none; border-top: 1px solid var(--line); }
.admin-detail { min-width: 0; min-height: 0; display: flex; flex-direction: column; padding: 10px var(--gutter) var(--gutter); }
.admin-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 12px; }
.admin-map-pane canvas { cursor: crosshair; }
.admin-form { display: flex; flex-direction: column; gap: 8px; }
.admin-form label { color: var(--muted); font-size: 13px; }
.admin-form input { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 9px 11px; }
.admin-form p { margin: 0; }
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 999px; padding: 3px 10px; cursor: pointer; font-size: 13px; }
.swatch.outline { background: var(--selected); }
.swatch.line { background: var(--line-mark); }
.swatch.candidate { background: rgb(255, 158, 42); }
@media (max-width: 899px) {
  .admin { grid-template-columns: minmax(0, 1fr); overflow: auto; }
  .admin-list { border-right: 0; max-height: 40vh; }
  .admin-body { grid-template-columns: minmax(0, 1fr); }
  .admin-map-pane { height: min(60vh, 92vw); }
}
