/* Desktop analysis dashboard — phone vs R2 trip comparison. */

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, system-ui, "Segoe UI", sans-serif;
  color: #1c1c28;
  background: #fff;
}
/* Full-window column layout; the stage grows to fill leftover height. */
body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
header, #tabs, #controls, .hint { flex: 0 0 auto; }
#stage { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#chart { flex: 1 1 0; min-height: 0; position: relative; }
/* Map fills the bottom half on the speed tab; hidden on the trajectory tab. */
#map { flex: 1 1 0; min-height: 0; position: relative; display: none; }
body.show-map #map { display: block; }
header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 20px 8px;
}
h1 { font-size: 18px; margin: 0; }
#trip-select { font: inherit; font-size: 14px; padding: 5px 8px; border: 1px solid #bbb; border-radius: 6px; }
.trip-meta { font-size: 13px; color: #666; }
#global-controls { margin-left: auto; font-size: 13px; display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }

#tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid #ddd; }
#tabs button {
  font: inherit; font-size: 14px;
  border: 1px solid #ddd; border-bottom: none;
  background: #f3f3f6; color: #444;
  padding: 8px 16px; border-radius: 8px 8px 0 0; cursor: pointer;
  position: relative; top: 1px;
}
#tabs button.active { background: #fff; color: #111; font-weight: 600; border-color: #ddd; }

#controls {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 20px; font-size: 13px; background: #fafafb; border-bottom: 1px solid #eee;
}
.ctrl-group { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ctrl-group label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.ctrl-group .sep { margin-left: 8px; padding-left: 12px; border-left: 1px solid #ddd; color: #888; }
.ctrl-group .seg { display: inline-flex; align-items: center; gap: 6px; }
.ctrl-group .grouplbl { color: #888; }
.legend { font-weight: 700; padding-left: 16px; position: relative; }
.legend::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 12px; height: 3px; border-radius: 2px;
}
.legend.phone { color: #52c41a; }
.legend.phone::before { background: #52c41a; }
.legend.r2 { color: #c026d3; }
.legend.r2::before { background: #c026d3; }
#reset-zoom { margin-left: auto; font: inherit; font-size: 13px; padding: 5px 12px; border: 1px solid #bbb; border-radius: 6px; background: #fff; cursor: pointer; }
.hidden { display: none !important; }

/* padding 0 so the JS-sized svg (clientWidth/clientHeight) fills exactly */
svg { display: block; }
.axis text { font-size: 11px; fill: #555; }
.axis path, .axis line { stroke: #ccc; }
.grid line { stroke: #eee; }
.curve { fill: none; stroke-width: 2; }
.curve.phone { stroke: #52c41a; }
.curve.r2 { stroke: #c026d3; }
.raw.phone { fill: #52c41a; }
.raw.r2 { fill: #c026d3; }
.stopline { stroke: #e3e3ea; stroke-dasharray: 2 3; }
.rowlabel { font-size: 11px; font-weight: 700; fill: #888; }
.delaybar { stroke: rgba(0,0,0,0.15); stroke-width: 0.5; cursor: pointer; }
.delaytext { font-size: 10px; fill: #fff; pointer-events: none; font-weight: 600; }
.rowsep { stroke: #eee; }

.hint { font-size: 12px; color: #888; padding: 4px 20px 20px; }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: #1c1c28; color: #fff; font-size: 12px; line-height: 1.4;
  padding: 6px 9px; border-radius: 6px; max-width: 260px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* speed-chart vertical cursor (mirrors the map bus icon) */
.chart-cursor { stroke: #111; stroke-width: 1; stroke-dasharray: 3 2; pointer-events: none; }
.threshold-line { stroke: #c0392b; stroke-width: 1; stroke-dasharray: 4 3; opacity: 0.75; pointer-events: none; }
.threshold-label { font-size: 10px; fill: #c0392b; }

/* ============ ported map / cursor / legend / street-view styles ========= */
.maplibregl-ctrl-attrib { font-size: 9px; }

.map-legend .legend-toggle {
  display: flex; align-items: center; gap: 6px; padding-bottom: 4px;
  margin-bottom: 4px; border-bottom: 1px solid #e0e0e0; color: #222; font-size: 11px;
}
.map-legend .legend-toggle input[type="radio"] { margin: 0; cursor: pointer; }
.map-legend .legend-toggle-label { margin-right: 2px; }
.map-legend .legend-radio { display: inline-flex; align-items: center; gap: 3px; }
.legend-shortcut { color: #888; font-size: 10px; margin-left: 2px; }
.map-legend {
  position: absolute; bottom: 30px; left: 10px;
  background: rgba(255, 255, 255, 0.92); border: 1px solid #ddd; border-radius: 4px;
  padding: 6px 8px; font-size: 11px; line-height: 1.6; z-index: 5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.map-legend .legend-row { display: flex; align-items: center; gap: 8px; color: #222; }
.map-legend .dot { display: inline-block; border-radius: 50%; border: 1px solid #111; flex-shrink: 0; }

.cursor-bus { pointer-events: none; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4)); }
/* opacity on the inner svg — MapLibre sets inline opacity on the marker element */
.cursor-bus svg { opacity: 0.75; }
.cursor-bus-ghost { opacity: 0.55; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25)) saturate(0.6); }

.streetview-popup {
  position: fixed; width: 480px; height: 360px; background: #fff;
  border: 1px solid #888; border-radius: 5px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  z-index: 9999; overflow: hidden; display: flex; flex-direction: column;
}
.streetview-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 4px 6px 4px 10px; background: #ececec; border-bottom: 1px solid #ccc;
  cursor: move; user-select: none; font-size: 11.5px; color: #333; flex: 0 0 auto;
}
.streetview-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.streetview-close {
  background: none; border: none; cursor: pointer; font-size: 18px; line-height: 1;
  padding: 0 6px; color: #555; flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px;
}
.streetview-close:hover { color: #000; }
.streetview-close-hint { font-size: 10px; color: #888; vertical-align: middle; }
.streetview-iframe { flex: 1 1 auto; width: 100%; border: 0; }
.streetview-drag-overlay { position: absolute; inset: 32px 0 0 0; display: none; }
body.streetview-dragging .streetview-drag-overlay { display: block; cursor: move; }

/* Rich/Lite mode switch */
#modes { display: inline-flex; gap: 2px; margin: 0 6px; }
#modes button { font-size: 12px; padding: 2px 9px; border: 1px solid #ccc; background: #f5f5f7; cursor: pointer; border-radius: 4px; }
#modes button.active { background: #2b6cb0; color: #fff; border-color: #2b6cb0; }

/* Two-level tabs: main (Single trip / Network) + sub-tabs */
#main-tabs { display: inline-flex; gap: 4px; margin: 0 10px; }
#main-tabs button { font-size: 13px; font-weight: 600; padding: 4px 12px; border: 1px solid #bbb; background: #eef1f5; cursor: pointer; border-radius: 5px; }
#main-tabs button.active { background: #1a365d; color: #fff; border-color: #1a365d; }
.mainbar { display: inline-flex; align-items: center; gap: 8px; }
.mainbar.hidden, .subtabs.hidden, #controls.hidden { display: none; }
.stub { padding: 2rem; color: #555; max-width: 42rem; font-size: 14px; line-height: 1.5; }

/* Band tooltip + map cursor dot (single-trip map cursor) */
.band-tooltip {
  position: absolute; z-index: 50; pointer-events: none;
  background: #1c1c28; color: #fff; font-size: 12px; line-height: 1.4;
  padding: 6px 9px; border-radius: 6px; max-width: 260px; box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.band-tooltip .ttl-cat { font-weight: 600; margin-bottom: 2px; }
.band-tooltip .ttl-where { color: #cbd5e1; margin-bottom: 1px; }
.band-tooltip .ttl-dur { color: #9aa5b1; }
.map-cursor-dot {
  width: 13px; height: 13px; border-radius: 50%; background: #1a73e8;
  border: 2px solid #fff; box-shadow: 0 0 4px rgba(0,0,0,0.55); pointer-events: none;
}

/* Profile color key — sits top-right over the chart */
.profile-legend {
  position: absolute; top: 8px; right: 12px; z-index: 5;
  background: rgba(255,255,255,0.92); border: 1px solid #ddd; border-radius: 4px;
  padding: 6px 8px; font-size: 10.5px; line-height: 1.5; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.profile-legend .legend-row { display: flex; align-items: center; gap: 6px; color: #333; }
.profile-legend svg { flex-shrink: 0; }
.profile-legend .legend-toggle {
  display: flex; align-items: center; gap: 6px; padding-bottom: 4px; margin-bottom: 4px;
  border-bottom: 1px solid #e0e0e0; color: #222; font-size: 11px;
}
.profile-legend .legend-toggle input { margin: 0; cursor: pointer; }
.profile-legend .legend-toggle label { cursor: pointer; user-select: none; }
.profile-legend .legend-toggle-label { margin-right: 2px; }
.profile-legend .legend-radio { display: inline-flex; align-items: center; gap: 3px; }
.profile-legend .legend-section { margin-top: 2px; }

/* ---- Network tab -------------------------------------------------------- */
body.network-mode #stage { position: relative; flex-direction: row; }  /* side-by-side + anchor overlays */
body.network-mode #chart { display: none; }
body.network-mode.network-areas #chart {
  display: block; flex: 0 0 46%; max-width: 46%; overflow: hidden;
  border-right: 1px solid #e2e2e2;
}
body.network-mode #map { display: block; flex: 1 1 auto; }

/* Segmented-control subtabs for the network tab */
#ntabs { display: inline-flex; background: #ececf0; border-radius: 9px; padding: 3px; gap: 2px;
  margin: 6px 10px; border-bottom: none; }
#ntabs button { border: none; background: transparent; padding: 5px 18px; border-radius: 7px;
  font: inherit; font-weight: 500; color: #555; cursor: pointer; transition: all .12s; }
#ntabs button:hover { color: #111; }
#ntabs button.active { background: #fff; color: #111; font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.18); }
#ntabs.hidden { display: none; }

/* Filter panel */
.nw-panel {
  position: absolute; top: 10px; left: 10px; z-index: 5; width: 252px;
  background: rgba(255,255,255,.96); border: 1px solid #ddd; border-radius: 10px;
  padding: 10px 12px; font-size: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.14);
  max-height: calc(100% - 90px); overflow-y: auto; box-sizing: border-box;
}
body.network-areas .nw-panel { left: calc(46% + 10px); }
.nw-panel * { box-sizing: border-box; }
.nw-group { margin: 0 0 9px; }
.nw-group:last-child { margin-bottom: 0; }
.nw-group > b { display: block; font-weight: 600; color: #333; margin-bottom: 3px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.nw-group select, .nw-group input[type="number"], .nw-group input[type="text"],
.nw-group input:not([type="checkbox"]) { width: 100%; font-size: 12px; padding: 3px 4px;
  border: 1px solid #ccc; border-radius: 5px; background: #fff; }
.nw-group select[multiple] { padding: 2px; }
.nw-inline { display: flex; gap: 6px; }
.nw-inline > * { flex: 1 1 0; min-width: 0; }
.nw-checks { display: grid; grid-template-columns: 1fr 1fr; gap: 1px 8px; }
.nw-checks label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nw-minirow { display: flex; gap: 6px; align-items: center; }
.nw-minirow input { flex: 0 0 64px; }
.nw-minirow input.nw-search { flex: 1 1 auto; min-width: 0; }
.nw-smallbtn:disabled { opacity: .45; cursor: default; }
.nw-clear { flex: 0 0 auto; border: 1px solid #ccc; background: #fff; border-radius: 5px;
  cursor: pointer; padding: 2px 7px; }
.nw-note { color: #888; font-size: 11px; }
.nw-hintkey { display: inline-block; border: 1px solid #bbb; border-bottom-width: 2px;
  border-radius: 4px; padding: 0 5px; font-family: ui-monospace, monospace; font-size: 11px;
  background: #f7f7f7; }

/* Detail panel */
.nw-detail {
  /* 2026-08-11: half-window, left-aligned, opaque — deliberately covers
     the filters sidebar; the map auto-frames the segment on the right. */
  position: absolute; top: 10px; left: 10px; z-index: 50;
  width: calc(60vw - 20px); min-width: 0; max-width: none;
  max-height: calc(100% - 20px); overflow-y: auto;
  background: #fff; border: 1px solid #ddd; border-radius: 10px;
  padding: 10px 12px; font-size: 12px; box-shadow: 0 2px 12px rgba(0,0,0,.22);
}
.nw-detail .dist-svg { width: 100%; height: auto; }
.nw-detail h3 { margin: 0 16px 8px 0; font-size: 16px; font-weight: 700; line-height: 1.35; }
.nw-detail .nw-close { position: absolute; top: 4px; right: 6px; border: none;
  background: none; font-size: 15px; cursor: pointer; color: #666; }
.nw-chips { margin: 4px 0; }
.chip { display: inline-block; background: #eef3fa; border: 1px solid #cdd9ea;
  border-radius: 10px; padding: 0 7px; margin: 1px 2px; font-size: 11px; }
.chip-segment { background: #eef3fa; border-color: #cdd9ea; }
.chip-corridor { background: #f3eefa; border-color: #d9cdea; }
.chip-route { background: #eefaf0; border-color: #cdeacd; }
.nw-facts { color: #555; margin: 4px 0 8px; line-height: 1.5; }
.nw-ptable { border-collapse: collapse; width: 100%; max-width: 380px; font-variant-numeric: tabular-nums; }
.nw-ptable th, .nw-ptable td { text-align: right; padding: 2px 6px; border-bottom: 1px solid #eee; }
.nw-ptable td:first-child, .nw-ptable th:first-child { text-align: left; }

.nw-tooltip {
  position: fixed; z-index: 30; pointer-events: none;
  background: rgba(20,20,20,.88); color: #fff; border-radius: 5px;
  padding: 5px 8px; font-size: 11px; line-height: 1.45; max-width: 280px;
}
.nw-tooltip .tt-cor { color: #d9c8f2; }

.nw-legend {
  position: absolute; bottom: 22px; left: 10px; z-index: 5; min-width: 180px;
  background: rgba(255,255,255,.95); border: 1px solid #ddd; border-radius: 8px;
  padding: 6px 10px; box-shadow: 0 1px 5px rgba(0,0,0,.14);
}
body.network-areas .nw-legend { left: calc(46% + 10px); }
.nw-legend-title { font-weight: 600; font-size: 11px; margin-bottom: 3px; }
.nw-legend-bar { height: 10px; border-radius: 3px; border: 1px solid #ccc; }
.nw-legend-ticks { display: flex; justify-content: space-between; font-size: 10px; color: #444; }
.nw-legend-note { font-size: 10px; color: #888; margin-top: 2px; }

/* Areas of interest pane */
.nw-areas { display: flex; flex-direction: column; height: 100%; background: #fafbfc; }
.nw-areas-bar { padding: 10px 12px 8px; border-bottom: 1px solid #e2e2e2; background: #fff; }
.nw-areas-bar .row1 { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.nw-areas-bar select { flex: 1 1 auto; min-width: 0; font-size: 12px; padding: 4px 5px;
  border: 1px solid #ccc; border-radius: 6px; background: #fff; }
.nw-areas-bar .row2 { display: flex; gap: 14px; align-items: center; font-size: 11.5px;
  color: #555; flex-wrap: wrap; }
.nw-areas-scroll { overflow-y: auto; flex: 1 1 auto; }
.nw-atable { border-collapse: collapse; width: 100%; font-size: 12px;
  font-variant-numeric: tabular-nums; }
.nw-atable th { position: sticky; top: 0; background: #f2f4f6; text-align: right;
  padding: 6px 8px; border-bottom: 1px solid #ddd; font-size: 11px; color: #444;
  text-transform: uppercase; letter-spacing: .02em; z-index: 1; }
.nw-atable td { text-align: right; padding: 5px 8px; border-bottom: 1px solid #eef0f2; }
.nw-atable td.nw-aname, .nw-atable th.nw-aname { text-align: left; max-width: 300px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nw-atable td.nw-rank { color: #999; width: 26px; }
.nw-atable tbody tr { cursor: pointer; background: #fff; }
.nw-atable tbody tr:hover { background: #f2f7ff; }
.nw-atable tbody tr.sel { background: #e3eefe; }
.nw-atable td.worse { color: #b3261e; font-weight: 600; }
.nw-atable td.better { color: #1e7b34; font-weight: 600; }
.kbadge { display: inline-block; width: 18px; height: 18px; line-height: 18px;
  border-radius: 5px; text-align: center; font-size: 10px; font-weight: 700; color: #fff; }
.kbadge-segment { background: #4a7fd6; }
.kbadge-corridor { background: #8a5fc0; }
.kbadge-route { background: #3d9e57; }
.nw-empty { padding: 24px; color: #666; font-size: 13px; }

/* metric/stat controls in the panel */
.nw-radios { display: grid; grid-template-columns: auto auto auto; justify-content: start;
  gap: 2px 12px; margin-top: 5px; }
.nw-radios label { white-space: nowrap; display: inline-flex; align-items: center;
  gap: 4px; justify-self: start; }
.nw-radios label input { margin: 0; }
.nw-radios label:nth-child(5) { grid-column: span 2; }
.nw-toggle { display: flex; gap: 5px; align-items: flex-start; margin-top: 5px; }
.nw-toggle input { flex: 0 0 auto; margin: 2px 0 0; }
.nw-quick { display: inline-flex; gap: 4px; margin-bottom: 4px; }
.nw-quick button, .nw-smallbtn {
  border: 1px solid #ccc; background: #fff; border-radius: 5px; cursor: pointer;
  padding: 1px 8px; font-size: 11px;
}
.nw-quick button:hover, .nw-smallbtn:hover { background: #f0f4fa; }
.nw-quick button:disabled { opacity: .45; cursor: default; }
/* routes checkbox list */
.nw-routelist {
  border: 1px solid #ccc; border-radius: 5px; background: #fff;
  max-height: 132px; overflow-y: auto;
}
.nw-routerow {
  display: flex; justify-content: space-between; align-items: center;
  padding: 2px 8px; cursor: pointer; border-bottom: 1px solid #f2f2f2;
}
.nw-routerow:hover { background: #f2f7ff; }
.nw-routerow.active { background: #e3eefe; font-weight: 600; }
.nw-routerow input { cursor: pointer; }

/* map/satellite toggle (network map, bottom-right) */
.nw-basemap {
  position: absolute; bottom: 22px; right: 10px; z-index: 5;
  background: rgba(255,255,255,.95); border: 1px solid #ddd; border-radius: 7px;
  padding: 2px; box-shadow: 0 1px 5px rgba(0,0,0,.14); display: inline-flex; gap: 2px;
}
.nw-basemap button {
  border: none; background: transparent; border-radius: 5px; padding: 3px 10px;
  font: inherit; font-size: 11.5px; cursor: pointer; color: #555;
}
.nw-basemap button.active { background: #2d4a75; color: #fff; }

/* inline direction buttons inside the single-selected route row */
.nw-dirbtns { display: inline-flex; gap: 2px; margin: 0 6px; flex: 1 1 auto; justify-content: flex-end; }
.nw-dirbtns button {
  border: 1px solid #bcd; background: #fff; border-radius: 4px; cursor: pointer;
  font-size: 10px; padding: 0 6px; color: #345; line-height: 16px;
}
.nw-dirbtns button.on { background: #2d4a75; border-color: #2d4a75; color: #fff; font-weight: 600; }

/* delay-location distribution */
.dist-rule { border: none; border-top: 1px solid #e2e2e2; margin: 12px 0 10px; }
.dist-head { font-weight: 600; font-size: 14px; color: #223; margin: 0 0 6px; }
.dist-svg { display: block; }
.dist-tick { font-size: 12px; fill: #666; }
.dist-legend { display: flex; gap: 16px; font-size: 12px; color: #444; margin-top: 4px; }
.dist-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  margin-right: 4px; vertical-align: -1px; }

.dist-toggle { display: inline-flex; gap: 2px; margin-left: 8px; vertical-align: 1px; }
.dist-toggle button { border: 1px solid #ccc; background: #fff; border-radius: 4px;
  font-size: 10px; padding: 0 7px; cursor: pointer; color: #555; }
.dist-toggle button.on { background: #2d4a75; border-color: #2d4a75; color: #fff; }

/* Network city switcher (Chicago | Boston) — right of the sub-tab pills */
#ntabs .ntab-city {
  margin-left: 18px;
  padding-left: 16px;
  border-left: 1px solid #c9ced6;
  display: inline-flex;
  gap: 6px;
}

/* ---- Explore (DuckDB-WASM fact-table querying) --------------------------- */
#explore-panel { padding: 14px 18px 40px; overflow-y: auto; max-height: calc(100vh - 120px); }
#explore-panel.hidden { display: none; }
.xp-controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center;
  padding: 10px 12px; background: #f6f7f9; border: 1px solid #e2e5ea; border-radius: 6px; }
.xp-controls label { font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
.xp-group { font-size: 12px; display: inline-flex; align-items: center; gap: 6px;
  padding-left: 10px; border-left: 1px solid #d8dce2; }
.xp-group label { gap: 2px; }
.xp-run { padding: 5px 14px; font-size: 12px; font-weight: 600; cursor: pointer;
  background: #2f6fd6; color: #fff; border: none; border-radius: 4px; }
.xp-status { font-size: 12px; color: #666; margin: 8px 2px; min-height: 16px; }
.xp-trend { margin: 6px 0 14px; }
.xp-trend h4 { font-size: 12px; font-weight: 600; margin: 0 0 2px; color: #444; }
.xp-table { border-collapse: collapse; font-size: 12px; width: 100%; max-width: 1000px; }
.xp-table th { text-align: left; border-bottom: 1.5px solid #ccc; padding: 4px 8px; color: #555; }
.xp-table td { padding: 3px 8px; border-bottom: 1px solid #eee; }
.xp-table tr:hover td { background: #f2f6fd; }
