*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: #f5f5f5;
}

/* ── Sidebar ─────────────────────────────── */
#sidebar {
  width: 360px;
  min-width: 300px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: 2px 0 12px rgba(0,0,0,0.12);
  z-index: 1000;
  overflow: hidden;
}

.sidebar-header {
  background: linear-gradient(135deg, #1a237e 0%, #283593 100%);
  color: #fff;
  padding: 18px 16px 14px;
  flex-shrink: 0;
}
.sidebar-header h1 { font-size: 17px; font-weight: 700; margin-bottom: 3px; }
.sidebar-header p  { font-size: 12px; opacity: 0.8; line-height: 1.4; }

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* ── Controls ────────────────────────────── */
.controls {
  padding: 14px 14px 12px;
  border-bottom: 1px solid #e8e8e8;
}

.field-label {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.field-label.mt-12 {
  margin-top: 12px;
  color: #777;
  margin-bottom: 5px;
}

.input-wrap {
  position: relative;
  margin-bottom: 11px;
}

.input-wrap input,
.input-wrap select {
  width: 100%;
  padding: 9px 36px 9px 11px;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  font-size: 13.5px;
  outline: none;
  background: #fafafa;
  transition: border-color 0.18s, background 0.18s;
  color: #222;
}
.input-wrap input:focus,
.input-wrap select:focus {
  border-color: #3949ab;
  background: #fff;
}
.input-wrap input::placeholder { color: #aaa; }

.field-icon {
  position: absolute;
  right: 10px; top: 50%;
  transform: translateY(-50%);
  font-size: 15px;
  pointer-events: none;
  opacity: 0.5;
}

/* Autocomplete dropdown */
.ac-list {
  position: absolute;
  top: calc(100% + 2px);
  left: 0; right: 0;
  background: #fff;
  border: 1.5px solid #c5cae9;
  border-radius: 8px;
  max-height: 190px;
  overflow-y: auto;
  z-index: 9999;
  box-shadow: 0 6px 18px rgba(0,0,0,0.14);
  display: none;
}
.ac-list.open { display: block; }
.ac-item {
  padding: 8px 11px;
  cursor: pointer;
  font-size: 12.5px;
  line-height: 1.35;
  border-bottom: 1px solid #f0f0f0;
  color: #333;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: #e8eaf6; }

/* Map-click hint */
.map-hint {
  font-size: 11px;
  color: #999;
  margin-top: 4px;
}
.map-hint a { color: #3949ab; text-decoration: none; }
.map-hint a:hover { text-decoration: underline; }

/* Buttons */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 11px;
  background: #1a237e;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, transform 0.1s;
}
.btn-primary:hover:not(:disabled)  { background: #283593; }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }
.btn-primary:disabled { background: #b0bec5; cursor: not-allowed; }

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px;
  background: transparent;
  color: #777;
  border: 1.5px solid #e0e0e0;
  border-radius: 8px;
  font-size: 12.5px;
  cursor: pointer;
  margin-top: 8px;
  transition: all 0.18s;
}
.btn-secondary:hover { border-color: #ef5350; color: #c62828; }

/* ── Route Summary ───────────────────────── */
#route-info {
  padding: 13px 14px;
  background: #e8eaf6;
  border-bottom: 1px solid #c5cae9;
  display: none;
}
#route-info.show { display: block; }

.route-stats {
  display: flex;
  gap: 12px;
  align-items: stretch;
  margin-bottom: 10px;
}
.route-stat {
  flex: 1;
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.route-stat .big   { font-size: 22px; font-weight: 700; color: #1a237e; line-height: 1; }
.route-stat .small { font-size: 11px; color: #888; margin-top: 2px; }

.route-destination {
  font-size: 12.5px;
  color: #444;
  background: #fff;
  border-radius: 7px;
  padding: 7px 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.route-destination strong { color: #1a237e; }

/* Hazard warning banner */
.hazard-banner {
  display: none;
  margin-top: 8px;
  border-radius: 0 7px 7px 0;
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1.4;
  border-left: 3px solid;
}
.hazard-banner.show { display: block; }
.hazard-banner.green {
  background: #e8f5e9;
  border-left-color: #4caf50;
  color: #1b5e20;
}
.hazard-banner.yellow {
  background: #fff9c4;
  border-left-color: #fbc02d;
  color: #f57f17;
}

/* ── Directions Panel (not currently used) ──────────────────────────── */
#directions-panel {
  padding: 12px 14px;
  border-bottom: 1px solid #e8e8e8;
}
.dir-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #888;
  margin-bottom: 8px;
}
.step {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 7px 0;
  border-bottom: 1px solid #f3f3f3;
  font-size: 12.5px;
  color: #333;
}
.step:last-child { border-bottom: none; }
.step-icon  { font-size: 15px; width: 22px; text-align: center; flex-shrink: 0; padding-top: 1px; }
.step-body  { flex: 1; line-height: 1.45; }
.step-dist  { font-size: 11px; color: #aaa; flex-shrink: 0; padding-top: 2px; }
.step.hazard-step { background: #fff8f0; border-radius: 6px; padding: 7px 6px; margin: 1px -6px; }
.hazard-tag { font-size: 10.5px; color: #e65100; display: block; margin-top: 2px; }

/* ── Legend ──────────────────────────────── */
.legend {
  padding: 12px 14px 16px;
  background: #fafafa;
}
.legend-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #888;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}
.legend-title .chevron { transition: transform 0.2s; }
.legend-title.collapsed .chevron { transform: rotate(-90deg); }
.legend-body { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; }
.legend-body.hidden { display: none; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: #555;
}
.li-swatch {
  width: 18px; height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1.5px solid rgba(0,0,0,0.15);
}
.li-swatch.dawes { background: #0288D1; }
.li-swatch.dewey { background: #FFD600; }
.li-swatch.foster { background: #880E4F; }
.li-swatch.lincoln { background: #0097A7; }
.li-swatch.lincolnwood { background: #F9A825; }
.li-swatch.oakton { background: #F57C00; }
.li-swatch.orrington { background: #FF5252; }
.li-swatch.walker { background: #795548; }
.li-swatch.washington { background: #0F9D58; }
.li-swatch.willard { background: #673AB7; }
.li-line {
  width: 18px; height: 4px;
  border-radius: 2px;
  flex-shrink: 0;
}
.li-line.hazard { background: #C62828; height: 5px; }
.li-line.route { background: #1565C0; height: 4px; }
.legend-item.footer {
  grid-column: 1 / -1;
  font-size: 10.5px;
  color: #aaa;
}
#btn-clear.hidden { display: none; }
.legend-divider {
  grid-column: 1 / -1;
  height: 1px;
  background: #eee;
  margin: 3px 0;
}

/* ── Map ─────────────────────────────────── */
#map { flex: 1; height: 100vh; }

/* Leaflet tweaks */
.leaflet-popup-content-wrapper { border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,0.18); }
.leaflet-popup-content { margin: 10px 14px; font-size: 13px; }

/* Spinner */
.spinner {
  display: inline-block;
  width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Map-click mode cursor */
.cursor-crosshair { cursor: crosshair !important; }

/* ── Leaflet Marker Styles ───────────────── */
.marker-school {
  background: #1a237e;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
.marker-school-emoji {
  transform: rotate(45deg);
  font-size: 14px;
}
.marker-start {
  background: #2E7D32;
  color: #fff;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  font-size: 14px;
}
.marker-dest {
  background: #C62828;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2.5px solid #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
.marker-dest-emoji {
  transform: rotate(45deg);
  font-size: 16px;
}
.popup-route-btn {
  margin-top: 7px;
  padding: 5px 12px;
  background: #1a237e;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}

/* ── Mobile ──────────────────────────────── */
@media (max-width: 700px) {
  body { flex-direction: column; }
  #sidebar { width: 100%; height: 48vh; min-width: unset; box-shadow: 0 2px 10px rgba(0,0,0,0.14); }
  #map { height: 52vh; }
}
