/* T-168 — UI v2 top bar, floating controls (hideHeader) and the v2 skin of the
   replay transport. Epic T-166; design: docs/UI-V2-DESIGN-HANDOFF.md.
   Every selector is scoped under html[data-ui="v2"], so ui=classic matches
   nothing here and renders exactly as before. Colours/sizes come from the
   tokens in ui-v2-tokens.css (T-167). Frame modes come from frame-mode.js
   via html[data-frame]. html[data-header="hidden"] is set by app.js for
   hideHeader=true. */

html[data-ui="v2"] body { background: var(--v2-workspace); }

/* ---- layout: the bar sits above the map; hideHeader gives the map the whole frame ---- */
html[data-ui="v2"]:not([data-header="hidden"]) #map-container {
  position: absolute;
  top: var(--v2-topbar-height);
  left: 0;
  right: 0;
  bottom: 0;
  width: auto;
  height: auto;
}

html[data-ui="v2"] .v2-chrome { font-family: var(--v2-font); color: var(--v2-text); }
html[data-ui="v2"]:not([data-header="hidden"]) .v2-chrome {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--v2-topbar-height);
  z-index: 300;
  box-sizing: border-box;
  background: var(--v2-surface);
  border-bottom: 1px solid var(--v2-border-subtle);
}
html[data-ui="v2"] .v2-bar {
  display: flex;
  align-items: center;
  gap: var(--v2-space-4);
  height: 100%;
  padding: 0 var(--v2-space-4);
  box-sizing: border-box;
  min-width: 0;
}
html[data-ui="v2"] .v2-title-block { min-width: 0; flex: 0 1 auto; }
html[data-ui="v2"] .v2-title {
  margin: 0;
  font: 600 var(--v2-text-section) var(--v2-font);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
html[data-ui="v2"] .v2-subtitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html[data-ui="v2"] .v2-metrics { display: flex; gap: var(--v2-space-4); min-width: 0; flex: 1 1 auto; }
html[data-ui="v2"] .v2-metric { display: flex; flex-direction: column; min-width: 0; white-space: nowrap; }
html[data-ui="v2"] .v2-metric[hidden] { display: none; }
html[data-ui="v2"] .v2-metric-value { font: 600 var(--v2-text-control) var(--v2-font); }
html[data-ui="v2"] .v2-left,
html[data-ui="v2"] .v2-right { display: flex; align-items: center; gap: var(--v2-space-2); flex: 0 0 auto; }
html[data-ui="v2"] .v2-right { margin-left: auto; position: relative; }

/* Segmented controls (Trip | Daily view, EN | ES, ...). */
html[data-ui="v2"] .v2-seg {
  display: inline-flex;
  border: 1px solid var(--v2-border);
  border-radius: var(--v2-radius-control-lg);
  overflow: hidden;
  background: var(--v2-surface);
}
html[data-ui="v2"] .v2-seg-btn {
  min-height: calc(var(--v2-hit) - 2px);
  padding: 0 var(--v2-space-3);
  border: 0;
  background: transparent;
  color: var(--v2-text);
  font: 500 var(--v2-text-control) var(--v2-font);
  cursor: pointer;
  white-space: nowrap;
}
html[data-ui="v2"] .v2-seg-btn + .v2-seg-btn { border-left: 1px solid var(--v2-border); }
html[data-ui="v2"] .v2-seg-btn[aria-pressed="true"] { background: var(--v2-action); color: var(--v2-action-text); }

html[data-ui="v2"] .v2-hbtn { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
html[data-ui="v2"] .v2-hbtn[hidden] { display: none; }
html[data-ui="v2"] .v2-hbtn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Daily date: prev / picker / next. */
html[data-ui="v2"] .v2-date { display: inline-flex; align-items: center; gap: var(--v2-space-1); }
html[data-ui="v2"] .v2-date-step { display: inline-flex; align-items: center; justify-content: center; }
html[data-ui="v2"] .v2-date-field { display: inline-flex; align-items: center; gap: 6px; position: relative; }
html[data-ui="v2"] .v2-date-input {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  min-width: 0;
}

/* Settings popover. */
html[data-ui="v2"] .v2-settings {
  position: absolute;
  top: calc(var(--v2-topbar-height) - 4px);
  right: var(--v2-space-4);
  width: 280px;
  max-width: calc(100vw - 2 * var(--v2-space-4));
  box-sizing: border-box;
  padding: var(--v2-space-3);
  display: flex;
  flex-direction: column;
  gap: var(--v2-space-3);
  z-index: 310;
}
html[data-ui="v2"] .v2-settings[hidden] { display: none; }
html[data-ui="v2"] .v2-settings-row { display: flex; flex-direction: column; align-items: flex-start; gap: var(--v2-space-1); }

/* ---- hideHeader: the same controls float over the map ---- */
html[data-ui="v2"][data-header="hidden"] .v2-chrome {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 300;
}
html[data-ui="v2"][data-header="hidden"] .v2-bar { display: block; padding: 0; }
html[data-ui="v2"][data-header="hidden"] .v2-title-block,
html[data-ui="v2"][data-header="hidden"] .v2-metrics { display: none; }
html[data-ui="v2"][data-header="hidden"] .v2-left {
  position: absolute;
  top: var(--v2-space-3);
  left: var(--v2-space-3);
  flex-direction: column;
  align-items: flex-start;
  pointer-events: auto;
}
/* T-201: Google's RIGHT_TOP column (fullscreen, and the v2 base-map icon pushed by
   basemap-control-v2.js; 40 px wide, 10 px from the edge) is always there, but its vertical
   place depends on whether Google draws a fullscreen button (not in an iframe without
   allow="fullscreen"). The floating buttons therefore sit to the left of that column
   instead of sharing its corner. */
html[data-ui="v2"][data-header="hidden"] .v2-right {
  position: absolute;
  top: var(--v2-space-3);
  right: calc(var(--v2-space-3) + var(--v2-map-control-column));
  margin: 0;
  pointer-events: auto;
}
/* Floating buttons are labelled icons (aria-label + title carry the name). */
html[data-ui="v2"][data-header="hidden"] .v2-hbtn { min-width: var(--v2-hit); justify-content: center; padding: 0; box-shadow: var(--v2-shadow-raised); }
html[data-ui="v2"][data-header="hidden"] .v2-hbtn .v2-hbtn-label { display: none; }
html[data-ui="v2"][data-header="hidden"] .v2-view-switch,
html[data-ui="v2"][data-header="hidden"] .v2-date { box-shadow: var(--v2-shadow-raised); }
html[data-ui="v2"][data-header="hidden"] .v2-date { background: var(--v2-surface); border-radius: var(--v2-radius-control-lg); }
/* Panels that float at top-right in classic drop below the floating buttons. */
html[data-ui="v2"][data-header="hidden"] #layers-panel { top: 56px; right: var(--v2-space-3); }
html[data-ui="v2"][data-header="hidden"] #day-view-panel { top: 96px; }

/* ---- narrow frames: icon-only date and buttons, title yields ---- */
html[data-ui="v2"]:is([data-frame="narrow"], [data-frame="square"]) .v2-bar { gap: var(--v2-space-2); padding: 0 var(--v2-space-2); }
html[data-ui="v2"]:is([data-frame="narrow"], [data-frame="square"]) .v2-metrics { display: none; }
html[data-ui="v2"]:is([data-frame="narrow"], [data-frame="square"]) .v2-subtitle { display: none; }
html[data-ui="v2"]:is([data-frame="narrow"], [data-frame="square"]) .v2-title-block { display: none; }
html[data-ui="v2"]:is([data-frame="narrow"], [data-frame="square"]) .v2-hbtn { min-width: var(--v2-hit); justify-content: center; padding: 0; }
html[data-ui="v2"]:is([data-frame="narrow"], [data-frame="square"]) .v2-hbtn .v2-hbtn-label { display: none; }
html[data-ui="v2"]:is([data-frame="narrow"], [data-frame="square"]) .v2-date-field { width: var(--v2-hit); padding: 0; justify-content: center; overflow: hidden; }
html[data-ui="v2"]:is([data-frame="narrow"], [data-frame="square"]) .v2-date-input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
html[data-ui="v2"][data-frame="short"] .v2-metrics { display: none; }
/* T-199: the statistics block does not fit next to Trip / Daily in frames up to 820 px that are not
   "narrow" (about 500 px: the label clips and collides with the Trip button). One rule for .v2-metrics
   only; frame-mode.js classification and every other layout are unchanged. */
@media (max-width: 820px) {
  html[data-ui="v2"] .v2-metrics { display: none; }
}

/* ---- classic controls that the bar replaces ----
   Some of them get an inline display from map-day-view.js, which a stylesheet cannot beat without
   a forced override, so they are taken out of layout and the accessibility tree another way. */
html[data-ui="v2"] :is(#day-view-entry-btn, #day-view-exit-btn, #day-view-nav-header, #day-view-tz-toggle) {
  visibility: hidden;
  position: absolute;
  width: 0;
  height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  pointer-events: none;
}
/* The Layers button in the bar opens/closes the panel, so its collapsed pill is not shown. */
html[data-ui="v2"] #layers-panel.collapsed { display: none; }

/* Charts toggle: the panel stays mounted (state kept), only hidden. */
html[data-ui="v2"] body.v2-charts-closed #trip-charts-panel { display: none; }

/* ---- states: the chrome stays; Layers / replay stay usable under a load error (index.html scopes
   the classic hiding rule to html:not([data-ui="v2"])) ---- */
html[data-ui="v2"] #map-loading { color: var(--v2-text-muted); font: 500 var(--v2-text-section) var(--v2-font); }

/* ---- replay: map-adjacent bottom-centre transport (same element and logic as classic) ---- */
html[data-ui="v2"] #replay-bar {
  background: var(--v2-surface);
  border-top: 1px solid var(--v2-border-subtle);
  box-shadow: var(--v2-shadow-sheet);
  align-items: center;
  color: var(--v2-text);
}
/* T-186: the transport spans the full width of the frame (it was a 720px centred block). */
html[data-ui="v2"] #replay-slider-row,
html[data-ui="v2"] #replay-info-panel { width: 100%; box-sizing: border-box; }
/* T-186: hidden from the top-bar Replay toggle (the bar keeps its state and playback position). */
html[data-ui="v2"] body.v2-replay-closed #replay-bar { display: none; }
html[data-ui="v2"] #replay-play-btn { background: var(--v2-primary); box-shadow: none; }
html[data-ui="v2"] #replay-slider { background: var(--v2-border-subtle); }
html[data-ui="v2"] #replay-slider::-webkit-slider-thumb { background: var(--v2-primary); }
html[data-ui="v2"] #replay-slider::-moz-range-thumb { background: var(--v2-primary); }
html[data-ui="v2"] #replay-time-labels { color: var(--v2-text-muted); }
html[data-ui="v2"] #replay-speed-btn {
  background: var(--v2-surface);
  color: var(--v2-text);
  border-color: var(--v2-border);
  min-height: var(--v2-hit);
}
html[data-ui="v2"] #replay-info-panel { color: var(--v2-text); border-top-color: var(--v2-border-subtle); }
/* T-180: narrow and square frames keep the scrubber (operator, UAT 1.4.0: scrubbing must stay
   available; this deviates from the design handoff, which hid it). The end time goes, the
   current time stays under the slider. */
html[data-ui="v2"]:is([data-frame="narrow"], [data-frame="square"]) #replay-time-end { display: none; }
html[data-ui="v2"]:is([data-frame="narrow"], [data-frame="square"]) #replay-slider-wrap { flex: 1; align-items: stretch; }
html[data-ui="v2"][data-frame="short"] .v2-title-block { display: none; }

/* ---- T-188/T-189: route source switch (Processed | Raw | Both) ----
   On the map, top-left: the corner Google's Map | Satellite bar used to take (10 px in from the
   map edge, below the bar). With hideHeader it sits in the floating top-left column instead. */
html[data-ui="v2"] .v2-route-switch { flex: 0 0 auto; box-shadow: var(--v2-shadow-raised); }
html[data-ui="v2"] .v2-route-switch .v2-seg-btn:disabled { opacity: 0.45; cursor: not-allowed; }
html[data-ui="v2"] .v2-route-switch .v2-seg-btn:focus-visible { outline: 2px solid var(--v2-action); outline-offset: -2px; }
html[data-ui="v2"]:not([data-header="hidden"]) .v2-route-switch {
  position: fixed;
  top: calc(var(--v2-topbar-height) + 10px);
  left: 10px;
  z-index: 300;
  max-width: calc(100vw - 80px); /* clear of the right-edge map controls */
}
html[data-ui="v2"] .v2-route-switch[hidden] { display: none; }
/* Small frames: shorter buttons so the switch stays a small strip over the corner. */
html[data-ui="v2"]:is([data-frame="narrow"], [data-frame="square"], [data-frame="short"]) .v2-route-switch .v2-seg-btn {
  min-height: 32px;
  padding: 0 var(--v2-space-2);
  font-size: 13px;
}
