/* ============================================================
   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: 400px;
  /* 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 fills the rail; its body scrolls internally when needed. */
.sidebar>.panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar>.panel>.panel__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ---------- Controls (inside panel body) ---------- */
#controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.search-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100%;
}

.search-panel[hidden] {
  display: none;
}

.search-panel>.legend {
  margin-top: auto;
  padding: 14px 0 0;
  border: 0;
  border-top: 1px solid var(--hairline-2);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.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;
}

/* The map + chart + map-only overlays. Fills the map-wrap on desktop; becomes a
   fixed-height hero block at the top of the column on mobile. */
.map-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

#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 (--rail + 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;
}

/* ---------- Date/time controller (inside left panel) ---------- */
.temporal-controller {
  background: rgba(255, 253, 248, .70);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.temporal-controller__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 15px;
  border-bottom: 1px solid var(--hairline-2);
  background: linear-gradient(90deg, rgba(31, 111, 100, .07), transparent 62%);
}

.temporal-controller__body {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 132px;
  gap: 12px;
  align-items: center;
  padding: 12px 13px 13px;
}

.temporal-controller__section {
  min-width: 0;
}

.temporal-controller__section>.label {
  margin: 0 0 7px;
}

.temporal-controller__section--dial {
  text-align: center;
}

/* 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. */
.temporal-controller .years__list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 0;
}

.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);
}

#timeDial {
  display: flex;
  justify-content: center;
}

.dial-svg {
  width: 120px;
  height: 120px;
  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 {
    height: 100svh;
    min-height: 0;
    overflow: hidden;
  }

  .map-wrap {
    grid-column: 1 / -1;
    grid-row: 1;
    height: 100svh;
    min-height: 0;
    overflow: hidden;
  }

  .map-stage {
    position: absolute;
    inset: 0;
    overflow: hidden;
  }

  .sidebar {
    grid-column: 1;
    grid-row: 1;
    width: min(var(--rail), calc(100vw - 72px));
    height: 100svh;
    padding: 12px;
    gap: 10px;
    overflow: hidden;
  }

  .app-shell.panel-hidden .sidebar {
    width: 0;
    padding: 0;
  }

  .sidebar>.panel {
    overflow-y: auto;
  }

  .panel-toggle {
    display: inline-flex;
    top: 12px;
    right: 12px;
    left: auto;
    z-index: 700;
  }

  .app-shell.panel-hidden .panel-toggle {
    right: 12px;
    left: auto;
  }

  .view-toggle {
    top: 64px;
    right: 12px;
    left: auto;
    z-index: 700;
  }

  .app-shell.panel-hidden .view-toggle {
    right: 12px;
    left: auto;
  }

  .temporal-controller__head {
    padding: 10px 12px;
  }

  .temporal-controller__body {
    grid-template-columns: minmax(0, 1fr) 104px;
    gap: 10px;
    padding: 10px;
  }

  .temporal-controller .years__list {
    gap: 2px;
  }

  .temporal-controller .year {
    gap: 8px;
    padding: 6px 7px;
  }

  .temporal-controller .year__label {
    font-size: 12.5px;
  }

  .temporal-controller .year__count {
    font-size: 11.5px;
  }

  .temporal-controller .dial-svg {
    width: 104px;
    height: 104px;
  }

  .temporal-controller .dial-hour {
    font-size: 8px;
  }

  .temporal-controller .dial-value {
    font-size: 15px;
  }

  .temporal-controller .dial-value-sub {
    font-size: 10px;
  }

  .map-stage .source {
    right: 10px;
    left: auto;
    bottom: 10px;
    max-width: calc(100% - 24px);
    font-size: 10.5px;
    line-height: 1.35;
  }
}
