:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  --navy-950: #07172b;
  --navy-900: #0a213d;
  --navy-850: #0e294a;
  --navy-800: #12345a;
  --blue-600: #1479d1;
  --blue-500: #2494e8;
  --blue-300: #8bc8f4;
  --blue-100: #d8edfc;
  --line: #295276;
  --text: #f6faff;
  --muted: #a9c3dc;
  --map-shell: #b9d5ea;
  --risk-low: #2563eb;
  --risk-medium: #f59e0b;
  --risk-high: #dc2626;
  --risk-unknown: #6b7280;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--navy-950);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.map-view:focus-visible {
  outline: 3px solid var(--blue-300);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.app {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  height: 100vh;
}

.sidebar {
  position: relative;
  z-index: 20;
  min-width: 0;
  overflow-y: auto;
  padding: 24px 20px;
  border-right: 1px solid #1d4569;
  background: var(--navy-900);
  scrollbar-color: #35668f transparent;
  scrollbar-width: thin;
}

.sidebar-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brand-copy {
  min-width: 0;
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--blue-300);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.sidebar-heading h1 {
  max-width: 250px;
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.14;
}

.icon-button,
.map-control {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--navy-850);
  color: var(--blue-100);
  font-size: 1.05rem;
}

.icon-button:hover,
.map-control:hover:not(:disabled) {
  border-color: var(--blue-500);
  background: var(--navy-800);
  color: #ffffff;
}

.panel {
  margin: 0 0 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--navy-850);
}

.panel h2 {
  margin: 0 0 15px;
  color: #ffffff;
  font-size: 0.92rem;
  line-height: 1.25;
}

.field-wrap {
  position: relative;
  margin-top: 14px;
}

.field-wrap:first-of-type {
  margin-top: 0;
}

label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 7px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #3b6386;
  border-radius: 7px;
  background: #091c34;
  color: var(--text);
}

input {
  padding: 9px 11px;
}

select {
  padding: 9px 34px 9px 11px;
}

.period-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 7px;
  margin-bottom: 2px;
}

.period-fields[hidden] {
  display: none;
}

.period-fields label {
  margin-top: 0;
  font-size: 0.68rem;
}

.period-fields input {
  width: 100%;
  color-scheme: dark;
}

input::placeholder {
  color: #7897b3;
}

input:hover,
select:hover {
  border-color: #5683a8;
}

input:focus,
select:focus {
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(36, 148, 232, 0.18);
  outline: 0;
}

.clear-input {
  width: 40px;
  min-height: 42px;
  margin: 0;
  padding: 0;
  border: 1px solid #3b6386;
  border-radius: 7px;
  background: #173a5e;
  color: var(--blue-100);
  font-size: 1.1rem;
}

.clear-input:hover {
  border-color: var(--blue-500);
  background: #204d77;
}

.route-builder > label {
  margin-top: 16px;
}

.suggestion-list {
  position: absolute;
  z-index: 40;
  top: calc(100% + 5px);
  right: 47px;
  left: 0;
  max-height: 230px;
  overflow-y: auto;
  border: 1px solid #41739d;
  border-radius: 7px;
  background: #071a31;
  box-shadow: 0 14px 30px rgba(1, 10, 23, 0.48);
}

.suggestion-list[hidden],
.route-options[hidden] {
  display: none;
}

.suggestion-heading,
.suggestion-message {
  padding: 9px 11px;
  color: #8eabc5;
  font-size: 0.7rem;
}

.suggestion-heading {
  border-bottom: 1px solid #244866;
  font-weight: 700;
  text-transform: uppercase;
}

.suggestion-item {
  width: 100%;
  margin: 0;
  padding: 10px 11px;
  border: 0;
  border-bottom: 1px solid #173752;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.suggestion-item:last-child {
  border-bottom: 0;
}

.suggestion-item:hover {
  background: #123b63;
}

.suggestion-item small {
  display: block;
  margin-top: 3px;
  color: #8eabc5;
  font-size: 0.7rem;
}

.route-actions {
  display: grid;
  grid-template-columns: 94px minmax(0, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.route-actions button,
.route-options-toggle {
  min-height: 42px;
  margin: 0;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--blue-600);
  color: #ffffff;
  font-weight: 700;
}

.route-actions button:hover:not(:disabled),
.route-options-toggle:hover:not(:disabled) {
  background: #0f68b4;
}

.route-actions .secondary-button {
  border-color: #3a668b;
  background: transparent;
  color: var(--blue-100);
}

.route-actions .secondary-button:hover:not(:disabled) {
  border-color: var(--blue-500);
  background: #173c61;
}

.summary-panel {
  border-color: #244c70;
}

.status {
  color: var(--blue-100);
  font-size: 0.84rem;
  line-height: 1.45;
}

.threshold-notice {
  margin-top: 12px;
  padding: 10px 11px;
  border: 1px solid #b87921;
  border-radius: 7px;
  background: #3b2b16;
  color: #ffe1a8;
  font-size: 0.75rem;
  line-height: 1.45;
}

.threshold-notice[hidden] {
  display: none;
}

.threshold-notice--alternative {
  border-color: #2e8a62;
  background: #113c32;
  color: #c9f7e3;
}

.threshold-notice--unavailable {
  border-color: #b55a64;
  background: #45232a;
  color: #ffd2d7;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 14px;
  border-top: 1px solid #2c5679;
  border-left: 1px solid #2c5679;
}

.summary-grid[hidden] {
  display: none;
}

.summary-metric {
  min-width: 0;
  padding: 11px 9px;
  border-right: 1px solid #2c5679;
  border-bottom: 1px solid #2c5679;
}

.summary-metric small,
.route-option small {
  display: block;
  color: #8eabc5;
  font-size: 0.68rem;
}

.summary-metric strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  color: #ffffff;
  font-size: 0.85rem;
}

.options-panel {
  padding: 0;
  border: 0;
  background: transparent;
}

.panel-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-heading-row h2 {
  margin-bottom: 0;
}

.corridor-route-name {
  color: var(--blue-300);
  font-size: 0.72rem;
  font-weight: 800;
}

.corridor-alert {
  margin-top: 12px;
  padding: 9px 10px;
  border: 1px solid #3d6689;
  border-radius: 6px;
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.4;
}

.corridor-alert--high {
  border-color: #b95059;
  background: #4d1c25;
  color: #ffd6da;
}

.corridor-alert--clear {
  border-color: #3979a9;
  background: #113b62;
  color: #d6ebff;
}

.corridor-alert--unavailable {
  background: #26394b;
  color: #d7e4ee;
}

.corridor-counts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 9px;
}

.corridor-count {
  padding: 6px 8px;
  border-left: 4px solid var(--risk-unknown);
  border-radius: 4px;
  background: #0a233e;
  color: #dceaf6;
  font-size: 0.7rem;
  font-weight: 700;
}

.corridor-count--low { border-left-color: var(--risk-low); }
.corridor-count--medium { border-left-color: var(--risk-medium); }
.corridor-count--high { border-left-color: var(--risk-high); }
.corridor-count--unknown { border-left-color: var(--risk-unknown); }

.corridor-period-status {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.4;
}

.route-options-toggle {
  width: 100%;
  border-color: #3c79a7;
  background: #123c62;
}

.route-options {
  display: grid;
  gap: 8px;
  margin-top: 9px;
}

.route-option {
  width: 100%;
  margin: 0;
  padding: 12px;
  border: 1px solid #315c7e;
  border-left: 4px solid var(--route-color, var(--blue-500));
  border-radius: 7px;
  background: #0b2745;
  color: var(--text);
  text-align: left;
}

.route-option:hover {
  background: #103455;
  border-color: #4f7da2;
  border-left-color: var(--route-color, var(--blue-500));
}

.route-option[aria-pressed="true"] {
  border-color: var(--route-color, var(--blue-500));
  background: #133d62;
}

.route-option-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.route-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.recommended-badge {
  padding: 3px 6px;
  border-radius: 4px;
  background: #14532d;
  color: #c8f7d7;
  font-size: 0.62rem;
  font-weight: 700;
}

.risk-badge {
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 0.62rem;
  font-weight: 700;
}

.risk-badge--low {
  background: #123f7a;
  color: #c8ddff;
}

.risk-badge--medium {
  background: #5a3b0c;
  color: #ffe4a3;
}

.risk-badge--high {
  background: #651f26;
  color: #ffd0d7;
}

.risk-badge--unknown {
  background: #3f4650;
  color: #deebf5;
}

.route-option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 10px;
  font-size: 0.76rem;
}

.route-option-grid strong {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
  font-size: 0.76rem;
}

.map {
  position: relative;
  min-width: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--map-shell);
}

.map-card {
  position: absolute;
  inset: 14px;
  overflow: hidden;
  border: 1px solid #759bbb;
  border-radius: 8px;
  background: #dce8dc;
  box-shadow: 0 14px 36px rgba(7, 23, 43, 0.2);
}

.map-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #dce8dc;
}

.tile-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #dce8dc;
}

.tile-layer img {
  position: absolute;
  max-width: none;
  opacity: 0.82;
  filter: saturate(0.62) contrast(0.94) brightness(1.05);
  user-select: none;
}

.map-view {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

.map-view.is-panning {
  cursor: grabbing;
}

.route-map-path {
  cursor: default;
  pointer-events: stroke;
  vector-effect: non-scaling-stroke;
}

.route-map-path:hover {
  opacity: 1;
  filter: drop-shadow(0 0 4px rgba(8, 38, 65, 0.55));
}

.corridor-risk-segment {
  cursor: default;
  pointer-events: stroke;
  vector-effect: non-scaling-stroke;
}

.corridor-risk-segment:hover {
  filter: drop-shadow(0 0 5px rgba(7, 23, 43, 0.72));
}

.corridor-risk-segment--high {
  filter: drop-shadow(0 0 3px rgba(220, 38, 38, 0.5));
}

.route-hover-label {
  position: absolute;
  z-index: 12;
  width: min(330px, calc(100% - 16px));
  padding: 10px 11px;
  border: 1px solid #6c91ad;
  border-radius: 7px;
  background: rgba(7, 28, 52, 0.96);
  box-shadow: 0 10px 24px rgba(8, 31, 50, 0.3);
  color: #f7fbff;
  font-size: 0.72rem;
  line-height: 1.4;
  pointer-events: none;
}

.route-hover-label[hidden] {
  display: none;
}

.route-hover-label strong,
.route-hover-label span {
  display: block;
}

.route-hover-label strong {
  margin-bottom: 6px;
  font-size: 0.78rem;
}

.route-hover-risk {
  font-weight: 800;
  text-transform: capitalize;
}

.route-hover-risk-line {
  display: flex !important;
  align-items: center;
  gap: 7px;
  margin-bottom: 4px;
}

.route-hover-risk-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border: 1px solid rgba(255, 255, 255, 0.76);
  border-radius: 50%;
  background: var(--risk-unknown);
}

.route-hover-risk-dot--low { background: var(--risk-low); }
.route-hover-risk-dot--medium { background: var(--risk-medium); }
.route-hover-risk-dot--high { background: var(--risk-high); }
.route-hover-risk-dot--unknown { background: var(--risk-unknown); }

.route-hover-metrics,
.route-hover-detail {
  color: #c1d7e9;
}

.route-hover-metrics {
  margin: 0 0 5px 16px;
  font-size: 0.68rem;
}

.route-hover-detail {
  font-size: 0.69rem;
}

.route-hover-divider {
  height: 1px;
  margin: 8px 0;
  background: #365d7c;
}

.route-hover-risk--low {
  color: #8bb8ff;
}

.route-hover-risk--medium {
  color: #ffd27a;
}

.route-hover-risk--high {
  color: #ff9292;
}

.route-hover-risk--unknown {
  color: #c2d6e7;
}

.map-boundary {
  fill: rgba(30, 88, 137, 0.06);
  stroke: #245b88;
  stroke-width: 1.6;
  stroke-dasharray: 8 7;
}

.map-label {
  fill: #102a44;
  font-size: 12px;
  font-weight: 700;
  paint-order: stroke;
  pointer-events: none;
  stroke: #ffffff;
  stroke-width: 4px;
}

.map-legend {
  position: absolute;
  z-index: 9;
  top: 14px;
  left: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 9px 11px;
  border: 1px solid rgba(40, 86, 124, 0.24);
  border-radius: 7px;
  background: rgba(248, 252, 255, 0.92);
  box-shadow: 0 8px 20px rgba(21, 56, 83, 0.14);
  color: #173b5d;
  font-size: 0.76rem;
  font-weight: 700;
}

.legend-label {
  color: #52718a;
  font-size: 0.66rem;
  text-transform: uppercase;
}

.legend-key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-line {
  width: 24px;
  border-top: 3px solid var(--blue-500);
}

.legend-line--low {
  border-color: var(--risk-low);
}

.legend-line--medium {
  border-color: var(--risk-medium);
}

.legend-line--high {
  border-color: var(--risk-high);
}

.legend-line--unknown {
  border-color: var(--risk-unknown);
}

.map-attribution {
  position: absolute;
  z-index: 8;
  bottom: 7px;
  left: 8px;
  padding: 2px 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.84);
  color: #39566d;
  font-size: 0.62rem;
}

.map-controls {
  position: absolute;
  z-index: 10;
  right: 12px;
  bottom: 12px;
  display: grid;
  grid-template-columns: repeat(3, 40px);
  gap: 6px;
}

.map-control {
  border-color: #7d9db8;
  background: rgba(248, 252, 255, 0.94);
  color: #123d62;
  box-shadow: 0 5px 14px rgba(20, 53, 78, 0.16);
  font-size: 1.1rem;
  font-weight: 800;
}

.map-control:hover:not(:disabled) {
  border-color: var(--blue-600);
  background: #ffffff;
  color: #0c68b4;
}

body.high-contrast {
  --navy-950: #000000;
  --navy-900: #020b16;
  --navy-850: #071523;
  --navy-800: #0c2741;
  --line: #81bde8;
  --muted: #d8eafb;
  --map-shell: #bcd3e3;
  color: #ffffff;
}

body.high-contrast .tile-layer img {
  opacity: 0.78;
  filter: grayscale(0.35) contrast(1.18);
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    overflow: visible;
    padding: 20px 16px;
    border-right: 0;
    border-bottom: 1px solid #285175;
  }

  .sidebar-heading h1 {
    max-width: none;
  }

  .map {
    min-height: 68vh;
  }

  .map-card {
    inset: 10px;
  }
}

@media (max-width: 440px) {
  .sidebar {
    padding: 17px 12px;
  }

  .summary-grid,
  .route-option-grid {
    grid-template-columns: 1fr;
  }

  .map-legend {
    right: 12px;
    gap: 8px;
  }

  .map-controls {
    grid-template-columns: repeat(3, 38px);
  }

  .map-control {
    width: 38px;
    height: 38px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
