/* ============================================================
   Layout + map + adaptations.
   Component chrome (panels, controls, stats, legend, years) lives in
   crash-density-ui.css. This file keeps the app-shell layout, the map
   surface (left untouched), the floating widget positions, the road-search
   dropdown, the interactive time-of-day dial, and the road shields.
   ============================================================ */

:root {
  color-scheme: light;
  --paper: #dce2dc;            /* sidebar backdrop behind the cards */
  --glass: rgba(244, 246, 240, 0.88);
  --rail: 420px;               /* sidebar width; floating widgets offset by it */
}

html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--paper);
}
h1 { margin: 0; }
button, input, select { font: inherit; }

/* ---------- App shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: 1fr;
  height: 100vh;
  min-height: 620px;
}

/* Sidebar overlays the full-bleed map (transparent so the map shows through). */
.sidebar {
  grid-column: 1;
  grid-row: 1;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: var(--rail);
  min-width: 0;
  min-height: 0;             /* allow the grid item to shrink to the row */
  padding: 16px;
  overflow: hidden;          /* the panel scrolls internally; the rail does not */
  background: transparent;
  transition: width 0.28s ease, padding 0.28s ease;
}
.app-shell.panel-hidden .sidebar { width: 0; padding-left: 0; padding-right: 0; }

/* The main panel scrolls internally when its contents exceed the rail height;
   the legend stays fixed at the foot so it is always visible. */
.sidebar > .panel { min-height: 0; overflow-y: auto; }
.sidebar > .legend { flex-shrink: 0; margin-top: auto; }

/* ---------- Controls (inside panel body) ---------- */
#controls { display: flex; flex-direction: column; gap: 16px; }
.label--inline { margin-bottom: 0; }
.group__head .label { margin-bottom: 0; }

/* ---------- Road search dropdown ---------- */
.road-search-wrap { position: relative; }
.road-search-list {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 600;
  margin: 0; padding: 5px 0; list-style: none;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-height: 280px; overflow-y: auto;
}
.road-search-group {
  padding: 7px 14px 4px;
  font-size: 10px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); pointer-events: none;
}
.road-search-group:not(:first-child) { border-top: 1px solid var(--hairline-2); margin-top: 4px; padding-top: 9px; }
.road-search-item {
  display: block; width: 100%; padding: 8px 14px;
  border: 0; background: transparent;
  color: var(--ink); font-size: 14px; font-weight: 600;
  text-align: left; cursor: pointer;
}
.road-search-item:hover, .road-search-item:focus { background: var(--accent-tint); outline: none; }
.road-search-item.interstate { color: #1d5790; }
.road-search-item.usroute { color: var(--accent-2-dark); }

/* ---------- Map surface (full-bleed, behind the sidebar) ---------- */
.map-wrap { grid-column: 1 / -1; grid-row: 1; position: relative; overflow: hidden; min-width: 0; height: 100vh; min-height: 620px; }
#map { position: absolute; inset: 0; width: 100%; height: auto; background: #dce4df; }
#chartOverlay {
  position: absolute; inset: 0; z-index: 450;
  width: 100%; height: 100%; overflow: visible; pointer-events: none;
}

/* ---------- Floating buttons ---------- */
/* Left-anchored widgets are pushed clear of the sidebar (372px + 16px gap)
   and slide back to the edge when the panel is hidden. */
.panel-toggle { position: absolute; top: 16px; left: calc(var(--rail) + 16px); z-index: 500; transition: left 0.28s ease; }
.view-toggle { position: absolute; top: 16px; left: calc(var(--rail) + 70px); z-index: 500; transition: left 0.28s ease; }
.view-toggle.active { background: var(--accent); border-color: rgba(174,74,50,.34); }
.app-shell.panel-hidden .panel-toggle { left: 16px; }
.app-shell.panel-hidden .view-toggle { left: 70px; }

/* ---------- Years card (floating) ---------- */
.years {
  position: absolute; top: 16px; right: 16px; z-index: 500;
  width: 208px;
}
/* Now a holder for the route shield rather than a coloured text pill. */
.year-road-name { display: inline-flex; align-items: center; }
.year-road-name[hidden] { display: none; }

/* Year rows are built in JS as <button>s — reset button chrome and let the
   design-system .year flex layout from crash-density-ui.css do the rest. */
.year {
  width: 100%; border: 0; font: inherit; color: inherit; background: transparent;
}
.year__dot { background: var(--accent-2); }
.year:not(.is-selected) .year__dot { background: var(--muted); }

/* ---------- Time-of-day dial card (floating) ---------- */
.dial-card {
  position: absolute; bottom: 16px; left: calc(var(--rail) + 16px); z-index: 500;
  padding: 12px 14px 8px;
  transition: left 0.28s ease;
}
.app-shell.panel-hidden .dial-card { left: 16px; }
.dial-card__title { margin-bottom: 6px; }
#timeDial { display: flex; justify-content: center; }
.dial-svg { width: 132px; height: 132px; touch-action: none; }
.dial-track { fill: none; stroke: rgba(45, 62, 55, .12); stroke-width: 6; }
.dial-arc { fill: none; stroke: var(--accent-2); stroke-width: 6; stroke-linecap: round; }
.dial-tick { stroke: rgba(45, 62, 55, .30); stroke-width: 1; }
.dial-tick.major { stroke: var(--ink-2); stroke-width: 1.6; }
.dial-hour { fill: var(--muted); font-size: 9px; font-weight: 700; text-anchor: middle; dominant-baseline: middle; }
.dial-handle { fill: var(--field); stroke: var(--accent-2); stroke-width: 2.5; cursor: grab; }
.dial-value { fill: var(--ink); font-family: var(--font-display); font-size: 17px; font-weight: 600; text-anchor: middle; }
.dial-value-sub { fill: var(--muted); font-size: 11px; font-weight: 600; text-anchor: middle; }

/* ---------- Road info pill + source ---------- */
.road-info-overlay {
  position: absolute; bottom: 46px; left: 50%; transform: translateX(-50%);
  z-index: 500; padding: 8px 12px; border-radius: 12px;
  display: flex; align-items: center; line-height: 0;
  background: var(--glass); box-shadow: var(--shadow-sm);
  border: 1px solid var(--hairline);
  pointer-events: none; white-space: nowrap;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.road-info-overlay #roadInfoName { display: inline-flex; }
.road-info-overlay .road-shield-inline { filter: drop-shadow(0 1px 2px rgba(20, 30, 40, .28)); }
.source {
  position: absolute; right: 14px; bottom: 14px; z-index: 500;
  max-width: min(520px, calc(100% - 28px)); padding: 7px 11px; border-radius: var(--radius-sm);
  color: var(--ink-2); background: var(--glass);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-sm); font-size: 12px;
}
.source a { color: var(--accent-2); }

/* ---------- US road shields (map markers — unchanged) ---------- */
.road-marker-shell { z-index: 460; }
.road-badge {
  position: relative;
  display: grid; place-items: center;
  width: 48px; height: 56px; padding: 0; border: 0;
  color: #fff;
  font-family: var(--font-ui);
  font-weight: 900; line-height: 1; cursor: pointer; background: transparent;
  filter: drop-shadow(0 2px 5px rgba(20, 30, 40, 0.34));
  transition: transform 0.08s ease, filter 0.08s ease;
}
.road-badge:hover { transform: scale(1.12); filter: drop-shadow(0 3px 7px rgba(20, 30, 40, 0.4)); }
.road-badge svg { display: block; width: 100%; height: 100%; }
.road-badge text { font-family: var(--font-ui); font-weight: 900; pointer-events: none; }
.road-badge .shield-route { letter-spacing: 0.2px; }
.road-badge.usroute { width: 46px; height: 52px; color: #111; }
.road-badge.usroute .shield-route { letter-spacing: 0.3px; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(420px, 1fr); height: auto; min-height: 100vh; }
  .sidebar { width: auto; overflow: visible; grid-row: 1; }
  .map-wrap { grid-row: 2; height: 68vh; min-height: 420px; }
  /* Stacked layout: map sits below the panel, so drop the desktop sidebar offsets. */
  .panel-toggle { left: 16px; }
  .view-toggle { left: 70px; }
  .dial-card { left: 16px; }
}
