/* 77 Rapid Restore — Service Distribution Map
   Custom layer on top of Tailwind: map chrome, markers, popups, motion. */

:root {
  --brand: #e8541e;
  --ring: rgba(232, 84, 30, 0.28);
}

html, body { -webkit-tap-highlight-color: transparent; }
* { scrollbar-width: thin; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(100, 116, 139, .32); border-radius: 999px; }

.chip-rail::-webkit-scrollbar { height: 0; }

/* ── Map surface ─────────────────────────────────────── */
#map { background: #eef1f4; z-index: 0; }
.dark #map { background: #10151c; }

.leaflet-container { font: inherit; }
.leaflet-tile-pane { filter: saturate(.72) contrast(.98); }
.dark .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.84) contrast(.92) saturate(.3); }

.leaflet-bar,
.leaflet-control-attribution {
  border: 1px solid rgba(15, 23, 42, .08) !important;
  border-radius: 8px !important;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .06) !important;
  overflow: hidden;
}
.leaflet-control-attribution { font-size: 10px; padding: 2px 6px; }
.leaflet-bar a { color: #475569 !important; }

/* ── Markers ─────────────────────────────────────────── */
.pin { position: relative; }
.pin-dot {
  position: absolute; inset: 0;
  border-radius: 999px;
  border: 2.5px solid #fff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, .28);
  transition: transform .16s cubic-bezier(.2,.8,.3,1);
}
.pin-count {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 900; color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.45);
  pointer-events: none;
}
/* Extended service area (outside the 20-mile primary radius) */
.pin-ext { opacity: .85; }
.pin-ext .pin-dot {
  border-style: dashed;
  border-width: 2.5px;
  border-color: #fff;
  box-shadow: 0 0 0 1.5px rgba(100,116,139,.55), 0 2px 6px rgba(15,23,42,.28);
}
.pin-badge {
  position: absolute;
  top: -7px; right: -12px;
  padding: 0 3px;
  border-radius: 4px;
  background: #475569;
  border: 1.5px dashed #fff;
  color: #fff;
  font-size: 7.5px;
  font-weight: 900;
  letter-spacing: .06em;
  line-height: 1.5;
  pointer-events: none;
}
.dark .pin-badge { background: #64748b; border-color: #0e1116; }

/* Tier badges (sidebar + popup) */
.badge-ext, .badge-pri {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .07em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-ext { background: #e2e8f0; color: #475569; border: 1px dashed #94a3b8; }
.dark .badge-ext { background: #2c3542; color: #cbd5e1; border-color: #64748b; }
.badge-pri { background: #fef3ec; color: #c2410c; border: 1px solid rgba(232,84,30,.28); }
.dark .badge-pri { background: rgba(232,84,30,.14); color: #fdba74; }

.pin:hover .pin-dot,
.pin.is-active .pin-dot { transform: scale(1.18); }
.pin.is-active .pin-dot { box-shadow: 0 0 0 6px var(--ring), 0 2px 8px rgba(15,23,42,.3); }

.pin-hq {
  position: relative;
  display: grid; place-items: center;
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--brand);
  border: 3px solid #fff;
  box-shadow: 0 6px 18px rgba(232, 84, 30, .38);
  animation: hqpulse 3.2s ease-in-out infinite;
}
@keyframes hqpulse {
  0%, 100% { box-shadow: 0 6px 18px rgba(232,84,30,.38), 0 0 0 0 rgba(232,84,30,.34); }
  70%      { box-shadow: 0 6px 18px rgba(232,84,30,.38), 0 0 0 16px rgba(232,84,30,0); }
}
@media (prefers-reduced-motion: reduce) { .pin-hq { animation: none; } }

.pin-label {
  position: absolute;
  left: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .01em;
  color: #334155;
  text-shadow: 0 1px 0 #fff, 0 0 4px #fff, 0 0 8px #fff;
  pointer-events: none;
}
.dark .pin-label { color: #e2e8f0; text-shadow: 0 1px 0 #0e1116, 0 0 5px #0e1116, 0 0 10px #0e1116; }
.pin-label-hq {
  left: 50%;
  top: calc(100% + 5px);
  bottom: auto;
  transform: translateX(-50%);
  font-size: 11.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #C2410C;
}
.dark .pin-label-hq { color: #FDBA74; }
@media (max-width: 640px) { .pin-label { display: none; } }
#map.labels-off .pin-label { display: none; }

/* ── Popups ──────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 12px 36px -10px rgba(16, 24, 40, .3);
  background: #fff; color: #0e1116;
}
.dark .leaflet-popup-content-wrapper { background: #161b22; color: #e2e8f0; }
.dark .leaflet-popup-tip { background: #161b22; }
.leaflet-popup-content { margin: 0; width: 300px !important; font-size: 13px; line-height: 1.45; }
.leaflet-popup-close-button { top: 8px !important; right: 8px !important; color: #94a3b8 !important; }

/* ── City list rows ──────────────────────────────────── */
.city-row summary { list-style: none; cursor: pointer; }
.city-row summary::-webkit-details-marker { display: none; }
.city-row[open] .chev { transform: rotate(90deg); }
.chev { transition: transform .18s ease; }

.fade-in { animation: fade .22s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

@media (max-width: 640px) {
  #stats > div { padding: 8px 12px; }
  #stats .text-2xl { font-size: 19px; }
  #stats .stat-sub { display: none; }
  #legend { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  #legend::-webkit-scrollbar { height: 0; }
  #legend > span { flex: 0 0 auto; }
}

/* ── Mobile bottom sheet ─────────────────────────────── */
@media (max-width: 1023px) {
  #sidebar {
    position: relative;
    border-top-left-radius: 18px;
    border-top-right-radius: 18px;
    margin-top: -18px;
    box-shadow: 0 -10px 30px -16px rgba(16, 24, 40, .35);
    transition: flex-basis .25s ease;
  }
  #sidebar.collapsed #stats,
  #sidebar.collapsed #city-list,
  #sidebar.collapsed .sheet-body { display: none; }
  #sidebar.collapsed { flex: 0 0 auto; }
  #sidebar { min-height: 0; }
  body.sheet-collapsed #map-pane { height: auto; flex: 1 1 auto; }
  #map-pane { height: 31vh; min-height: 230px; }
  #stats > div { padding: 10px 12px; }
  #stats .text-2xl { font-size: 20px; }
  #sidebar.collapsed #stats-note { display: none; }
}
