/* ───────────────────── Reset & Base ───────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; }
body { display: flex; overflow: hidden; background: #0d1b2a; color: #e0e0e0; }

/* ───────────────────── Hamburger button ──────────────── */
#sidebar-toggle {
  display: none;
  position: fixed; top: 12px; left: 12px; z-index: 1300;
  width: 42px; height: 42px;
  background: #1b2a4a; border: 1px solid #233d6b; border-radius: 8px;
  cursor: pointer; padding: 9px 7px;
  flex-direction: column; justify-content: space-between;
  box-shadow: 0 2px 10px rgba(0,0,0,.4);
  transition: background .2s;
}
#sidebar-toggle span {
  display: block; height: 3px; width: 100%; background: #4fc3f7;
  border-radius: 2px; transition: transform .25s, opacity .2s;
}
#sidebar-toggle.open span:nth-child(1) { transform: translateY(9.5px) rotate(45deg); }
#sidebar-toggle.open span:nth-child(2) { opacity: 0; }
#sidebar-toggle.open span:nth-child(3) { transform: translateY(-9.5px) rotate(-45deg); }

/* ───────────────────── Sidebar overlay (mobile) ──────── */
#sidebar-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 1050;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
  opacity: 0; transition: opacity .25s;
}
#sidebar-overlay.visible { display: block; opacity: 1; }

/* ───────────────────── Sidebar ────────────────────────── */
#sidebar {
  width: 320px; min-width: 320px;
  background: #1b2a4a;
  padding: 20px;
  display: flex; flex-direction: column; gap: 16px;
  overflow-y: auto;
  z-index: 1000;
  border-right: 2px solid #233d6b;
}
h1 { font-size: 1.25rem; color: #4fc3f7; letter-spacing: .5px; }
.subtitle { font-size: .82rem; color: #90a4ae; margin-top: -8px; }

/* ── Search ── */
.search-box { position: relative; }
#search {
  width: 100%; padding: 8px 12px;
  border: 1px solid #233d6b; border-radius: 6px;
  background: #0d1b2a; color: #e0e0e0;
  font-size: .9rem; outline: none;
  transition: border-color .2s;
}
#search:focus { border-color: #4fc3f7; }
#search-results {
  list-style: none; position: absolute; top: 100%; left: 0; right: 0;
  background: #1b2a4a; border: 1px solid #233d6b; border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 200px; overflow-y: auto;
  display: none; z-index: 2000;
}
#search-results.visible { display: block; }
#search-results li {
  padding: 6px 12px; cursor: pointer; font-size: .85rem;
}
#search-results li:hover, #search-results li.active {
  background: #233d6b; color: #fff;
}

/* ── Mode & style buttons ── */
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: 1px; color: #90a4ae; }
.mode-group { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.mode-btn, .style-btn {
  padding: 7px 10px; border: 1px solid #233d6b; border-radius: 5px;
  background: transparent; color: #c0c0d0; cursor: pointer;
  font-size: .82rem; text-align: left; transition: all .15s;
}
.mode-btn:hover, .style-btn:hover { background: #233d6b; color: #fff; }
.mode-btn.active { background: #0288d1; border-color: #0288d1; color: #fff; font-weight: 600; }
.style-btn.active { background: #233d6b; border-color: #4fc3f7; color: #fff; font-weight: 600; }

/* ── Legend ── */
#legend { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.legend-title { font-size: .78rem; text-transform: uppercase; letter-spacing: 1px; color: #90a4ae; margin-bottom: 2px; }
.legend-tiles { display: flex; flex-wrap: wrap; gap: 6px; }
.legend-tile {
  display: flex; align-items: center; gap: 5px;
  font-size: .75rem; color: #c0c0d0;
  background: rgba(255,255,255,.06); border-radius: 4px;
  padding: 3px 8px;
}
.legend-tile span { white-space: nowrap; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: .8rem; min-width: 0; }
.legend-row span { white-space: normal; word-break: break-word; }
.legend-swatch { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; border: 1px solid rgba(255,255,255,.15); }
.legend-gradient-bar {
  width: 100%; height: 16px; border-radius: 4px;
  border: 1px solid rgba(255,255,255,.15);
  min-width: 0;
  overflow: hidden;
  background-color: #004d40;
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
.legend-labels { display: flex; justify-content: space-between; font-size: .72rem; color: #90a4ae; padding: 0 2px; }

/* ── Mode info ── */
.mode-info { font-size: .78rem; color: #90a4ae; line-height: 1.5; }

/* ── Old-calc toggle ── */
.toggle-row {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; font-size: .82rem; color: #c0c0d0;
}
.toggle-row input[type="checkbox"] {
  accent-color: #4fc3f7; width: 16px; height: 16px; cursor: pointer;
}
.toggle-info { font-size: .72rem; color: #90a4ae; line-height: 1.4; margin-top: 2px; }

/* ── Stats ── */
.stats { font-size: .78rem; color: #90a4ae; line-height: 1.6; }
.stats strong { color: #c0c0d0; }

/* ───────────────────── Map ───────────────────────────── */
#map { flex: 1; background: #0d1b2a; }

/* ───────────────────── Detail panel ──────────────────── */
#detail-panel {
  position: fixed; top: 60px; right: 20px;
  width: 360px; max-height: calc(100vh - 100px);
  background: #1b2a4a; border: 1px solid #233d6b;
  border-radius: 10px; padding: 20px;
  overflow-y: auto; z-index: 1100;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  transition: opacity .2s, transform .2s;
}
#detail-panel.hidden { opacity: 0; pointer-events: none; transform: translateX(20px); }
#detail-close {
  position: absolute; top: 10px; right: 14px;
  background: none; border: none; color: #4fc3f7;
  font-size: 1.2rem; cursor: pointer;
}
#detail-content h2 { font-size: 1.1rem; color: #4fc3f7; margin-bottom: 8px; }
#detail-content table { width: 100%; border-collapse: collapse; font-size: .82rem; }
#detail-content td { padding: 4px 0; vertical-align: top; }
#detail-content td:first-child { color: #90a4ae; width: 130px; }
#detail-content td:last-child { color: #e0e0e0; }
#detail-content .route-section { margin-top: 10px; }
#detail-content .route-step {
  font-size: .78rem; padding: 3px 0; border-left: 2px solid #233d6b;
  padding-left: 10px; margin: 2px 0; color: #c0c0d0;
}

/* ───────────────────── Leaflet overrides ─────────────── */
.leaflet-popup-content-wrapper { background: #1b2a4a !important; color: #e0e0e0 !important; border-radius: 8px !important; }
.leaflet-popup-tip { background: #1b2a4a !important; }
.leaflet-popup-content { font-size: .85rem; }
.leaflet-control-zoom a { background: #1b2a4a !important; color: #e0e0e0 !important; border-color: #233d6b !important; }

/* ─────────────────────── Custom tooltip ────────────── */
#custom-tooltip {
  display: none;
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  background: #fff;
  color: #222;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: .82rem;
  font-family: 'Segoe UI', system-ui, sans-serif;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
  white-space: nowrap;
  transform: translateX(-50%);
}

/* ═════════════════════ Responsive / Mobile ═══════════════ */
@media (max-width: 768px) {
  body { flex-direction: column; }

  /* Hamburger visible */
  #sidebar-toggle { display: flex; }

  /* Sidebar as slide-over drawer */
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 85vw; max-width: 340px; min-width: 0;
    transform: translateX(-100%);
    transition: transform .3s ease;
    z-index: 1100;
    border-right: 2px solid #233d6b;
    padding-top: 60px;          /* room for hamburger */
  }
  #sidebar.open { transform: translateX(0); }

  /* Map fills viewport */
  #map { position: fixed; inset: 0; width: 100%; height: 100%; }

  /* Detail panel: bottom sheet on mobile */
  #detail-panel {
    position: fixed;
    top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; max-width: 100%;
    max-height: 55vh;
    border-radius: 14px 14px 0 0;
    padding: 16px 16px 24px;
    transform: translateY(0);
  }
  #detail-panel.hidden { transform: translateY(100%); opacity: 0; }

  /* Leaflet zoom controls – move out of hamburger area */
  .leaflet-top.leaflet-left { top: 60px !important; }

  /* Legend tiles wrap a bit tighter */
  .legend-tiles { gap: 4px; }
  .legend-tile { font-size: .7rem; padding: 2px 6px; }
}

@media (max-width: 420px) {
  #sidebar { width: 100vw; max-width: 100vw; }
  #detail-panel { max-height: 60vh; }
  h1 { font-size: 1.1rem; }
}
