* { box-sizing: border-box; margin: 0; }
body { font-family: system-ui, sans-serif; display: flex; height: 100vh; height: 100dvh; }
#map { flex: 1; }
#sidebar {
  width: 320px; display: flex; flex-direction: column;
  border-left: 1px solid #ddd; background: #fafafa;
}
#sidebar-header, #sidebar-header-school { padding: 16px 16px 12px; }
#sidebar-header h2, #sidebar-header-school h2 { font-size: 18px; margin-bottom: 4px; }

/* Panel toggling */
#landing-panel { display: flex; flex-direction: column; flex: 1; overflow-y: auto; }
#school-panel { display: flex; flex-direction: column; flex: 1; overflow: hidden; }

/* Intro text */
.intro-text { font-size: 13px; color: #6b7280; margin-bottom: 12px; line-height: 1.4; }

/* Back link */
#back-link {
  display: inline-block; font-size: 13px; color: #6b7280;
  text-decoration: none; margin-bottom: 8px; cursor: pointer;
}
#back-link:hover { color: #2563eb; }

/* School name header */
#school-name { font-size: 20px; font-weight: 600; margin-bottom: 4px; }

/* Feeder info */
#feeder-info {
  font-size: 12px; color: #6b7280; margin-bottom: 10px; line-height: 1.5;
}
#feeder-info a {
  color: #2563eb; text-decoration: none; cursor: pointer;
}
#feeder-info a:hover { text-decoration: underline; }

/* Address counts */
#address-counts { margin-bottom: 10px; }
.address-headline { font-size: 16px; font-weight: 600; color: #374151; }
.address-headline span { color: #2563eb; }
.address-breakdown { font-size: 12px; color: #9ca3af; margin-top: 2px; }

/* Quick stats */
.quick-stats { font-size: 12px; color: #9ca3af; margin-bottom: 8px; }

/* Legend */
.legend { padding: 8px 16px; display: flex; gap: 14px; align-items: center; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 12px; color: #6b7280; }
.legend-dot {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block; border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
}

/* Data nerd section */
.data-nerd-section { padding: 12px 16px; }
.data-cta { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.data-nerd-links { display: flex; gap: 8px; align-items: center; }

/* Download & about links */
.download-link {
  font-size: 11px; color: #374151; text-decoration: none;
  background: #f3f4f6; border: 1px solid #d1d5db; border-radius: 4px;
  padding: 2px 8px; white-space: nowrap;
}
.download-link:hover { background: #e5e7eb; }
.about-link { font-size: 11px; color: #6b7280; text-decoration: none; }
.about-link:hover { color: #2563eb; text-decoration: underline; }
.school-geojson { padding: 12px 16px 16px; border-top: 1px solid #eee; }
.geojson-links { padding: 8px 16px; }

/* About Data modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-card {
  background: #fff; border-radius: 10px; padding: 24px 28px;
  max-width: 520px; width: 100%; max-height: 85vh; overflow-y: auto;
  position: relative; box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal-card h2 { font-size: 18px; margin-bottom: 16px; }
.modal-card h3 { font-size: 14px; font-weight: 600; margin: 14px 0 6px; color: #374151; }
.modal-card ul { padding-left: 18px; margin: 0; }
.modal-card li { font-size: 13px; line-height: 1.5; margin-bottom: 4px; color: #4b5563; }
.modal-card code { font-size: 12px; background: #f3f4f6; padding: 1px 5px; border-radius: 3px; }
.modal-card a { color: #2563eb; text-decoration: none; }
.modal-card a:hover { text-decoration: underline; }
.modal-close-btn {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; font-size: 22px; cursor: pointer;
  color: #9ca3af; line-height: 1; padding: 4px;
}
.modal-close-btn:hover { color: #374151; }

/* School autocomplete */
#school-search-wrap { position: relative; margin-bottom: 8px; }
#school-search {
  width: 100%; padding: 8px 10px; font-size: 14px;
  border: 1px solid #d1d5db; border-radius: 6px;
  outline: none; font-family: inherit;
}
#school-search:focus { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,0.15); }
#school-dropdown {
  display: none; position: absolute; top: 100%; left: 0; right: 0;
  background: #fff; border: 1px solid #d1d5db; border-top: none;
  border-radius: 0 0 6px 6px; list-style: none; padding: 0; margin: 0;
  max-height: 300px; overflow-y: auto; z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
#school-dropdown.open { display: block; }
#school-dropdown li {
  padding: 8px 12px; font-size: 13px; cursor: pointer;
}
#school-dropdown li:hover, #school-dropdown li.active {
  background: #eff6ff;
}
#school-dropdown li.disabled {
  color: #9ca3af; cursor: default;
}
#school-dropdown li.disabled:hover, #school-dropdown li.disabled.active {
  background: #f9fafb;
}
#school-dropdown li .coming-soon {
  font-size: 11px; color: #9ca3af; margin-left: 4px;
}

#sidebar-header .count, #sidebar-header-school .count {
  color: #2563eb; font-size: 14px; display: flex; align-items: center; justify-content: space-between;
}
.csv-link {
  font-size: 11px; color: #374151; text-decoration: none;
  background: #f3f4f6; border: 1px solid #d1d5db; border-radius: 4px;
  padding: 2px 8px; white-space: nowrap;
}
.csv-link:hover { background: #e5e7eb; }
#street-table-wrap { flex: 1; overflow-y: auto; padding: 0 16px 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 6px 4px; border-bottom: 2px solid #ccc; font-size: 12px; color: #666; position: sticky; top: 0; background: #fafafa; }
td { padding: 6px 4px; border-bottom: 1px solid #eee; }
td.range { color: #555; font-variant-numeric: tabular-nums; }
tr.street-row { cursor: pointer; }
tr.street-row:hover { background: #f0f0f0; }
tr.street-row.selected { background: #fff7ed; }
tr.street-row.selected td { color: #ea580c; font-weight: 600; }
#selected-info {
  padding: 8px 0 4px; font-size: 13px; color: #666; min-height: 28px;
}
#selected-info.active { color: #ea580c; font-weight: 500; }
#reset-btn {
  background: #f3f4f6; border: 1px solid #d1d5db; border-radius: 4px;
  padding: 4px 10px; font-size: 12px; cursor: pointer; color: #374151;
}
#reset-btn:hover { background: #e5e7eb; }
.header-row { display: flex; justify-content: space-between; align-items: center; }
#search-wrap { padding: 0 16px 8px; }
#street-search {
  width: 100%; padding: 6px 10px; font-size: 13px;
  border: 1px solid #d1d5db; border-radius: 4px;
  outline: none; font-family: inherit;
}
#street-search:focus { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,0.15); }
tr.street-row.hidden { display: none; }

/* MapLibre popup overrides */
.maplibregl-popup-content {
  font-family: system-ui, sans-serif;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.4;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
.maplibregl-popup-content strong { font-size: 14px; }
.popup-level { font-size: 12px; color: #6b7280; font-weight: normal; }
.popup-stats { font-size: 12px; color: #6b7280; margin: 4px 0; }
.popup-feeder { font-size: 11px; color: #6b7280; margin: 4px 0; line-height: 1.4; }
.popup-feeder a { color: #2563eb; text-decoration: none; cursor: pointer; }
.popup-feeder a:hover { text-decoration: underline; }
.popup-action { margin-top: 6px; }
.popup-action a {
  color: #2563eb; text-decoration: none; font-size: 13px; font-weight: 500;
}
.popup-action a:hover { text-decoration: underline; }

/* Drag handle - hidden on desktop */
#sidebar-handle { display: none; }

/* Mobile: sidebar becomes a bottom sheet */
@media (max-width: 640px) {
  body { flex-direction: column; }
  #map { flex: 1; min-height: 0; }
  #sidebar {
    width: 100%; border-left: none; border-top: 1px solid #ddd;
    position: fixed; bottom: 0; left: 0; right: 0;
    height: 40dvh;
    max-height: 85dvh;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    transition: height 0.3s ease;
    z-index: 10;
  }
  #sidebar.collapsed { height: 56px; }
  #sidebar.expanded { height: 85dvh; }
  #sidebar-handle {
    display: flex; justify-content: center; align-items: center;
    padding: 8px 0 4px; cursor: grab; touch-action: none;
  }
  #sidebar-handle .handle-bar {
    width: 36px; height: 4px; border-radius: 2px; background: #cbd5e1;
  }
  #sidebar-header, #sidebar-header-school { padding: 8px 16px 8px; }
  #sidebar-header h2, #sidebar-header-school h2 { font-size: 16px; }
  #school-search { font-size: 16px; /* prevent iOS zoom on focus */ }
  /* Reserve space at the bottom so the fixed sidebar doesn't cover the map */
  #map { padding-bottom: 56px; }
  /* Info bar adjustments on mobile */
  #selected-info { font-size: 12px; min-height: unset; }
}
