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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  overflow: hidden;
  height: 100dvh;
}

/* ── Map ── */
#map {
  position: absolute;
  inset: 0;
  top: 40px; /* below banner */
}

/* ── Banner ── */
#banner {
  position: relative;
  z-index: 10;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  font-size: 14px;
  gap: 8px;
}

#banner-icon { display: flex; align-items: center; }
#banner-icon svg { width: 18px; height: 18px; }
#banner-text { color: #cbd5e1; }
#banner-stats { color: #64748b; font-size: 12px; }

#banner.banner-sun     { border-bottom-color: #92400e; }
#banner.banner-partial { border-bottom-color: #78350f; }
#banner.banner-cloud   { border-bottom-color: #334155; }
#banner.banner-night   { border-bottom-color: #1e293b; }

/* ── Search bar ── */
#search-bar {
  position: absolute;
  top: 52px;
  left: 12px;
  z-index: 10;
  display: flex;
  gap: 4px;
}

#search-input {
  width: 240px;
  padding: 8px 12px;
  border: 1px solid #475569;
  border-radius: 6px;
  background: #1e293bee;
  color: #f1f5f9;
  font-size: 14px;
  backdrop-filter: blur(8px);
}

#search-input::placeholder { color: #64748b; }
#search-input:focus { outline: none; border-color: #f59e0b; }

#search-btn, #locate-btn, #refresh-btn, #about-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid #475569;
  border-radius: 6px;
  background: #1e293bee;
  color: #cbd5e1;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

#search-btn:hover, #locate-btn:hover, #refresh-btn:hover, #about-btn:hover {
  background: #334155;
  border-color: #f59e0b;
  color: #f59e0b;
}

/* ── Zoom hint ── */
#zoom-hint {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  padding: 8px 16px;
  border-radius: 20px;
  background: #1e293bee;
  border: 1px solid #475569;
  font-size: 13px;
  color: #94a3b8;
  backdrop-filter: blur(8px);
  pointer-events: none;
  transition: opacity 0.3s;
}

#zoom-hint.hidden { opacity: 0; }

/* ── Search results dropdown ── */
#search-results {
  position: absolute;
  top: 92px; /* below search bar */
  left: 12px;
  z-index: 20;
  width: 284px;
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

#search-results.hidden { display: none; }

.search-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px solid #334155;
  gap: 8px;
}

.search-result:last-child { border-bottom: none; }

.search-result:hover { background: #334155; }

.search-result-name {
  font-size: 13px;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── No data overlay ── */
#no-data {
  position: absolute;
  inset: 0;
  top: 40px;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15,23,42,0.75);
  backdrop-filter: blur(4px);
}

#no-data.hidden { display: none; }

#no-data-inner {
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 10px;
  padding: 24px 28px;
  text-align: center;
  max-width: 320px;
}

#no-data-inner p {
  color: #94a3b8;
  font-size: 14px;
  margin-bottom: 8px;
}

#no-data-inner p:first-child {
  color: #e2e8f0;
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 10px;
}

#no-data-refresh {
  margin-top: 12px;
  padding: 8px 20px;
  background: #334155;
  border: 1px solid #475569;
  border-radius: 6px;
  color: #e2e8f0;
  font-size: 13px;
  cursor: pointer;
}

#no-data-refresh:hover { background: #475569; }

/* ── Popup ── */
.maplibregl-popup-content {
  background: #1e293b !important;
  border: 1px solid #475569 !important;
  border-radius: 10px !important;
  padding: 0 !important;
  color: #e2e8f0 !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4) !important;
  min-width: 240px;
  max-width: 300px;
}

.maplibregl-popup-tip {
  border-top-color: #475569 !important;
}

.maplibregl-popup-close-button {
  color: #94a3b8 !important;
  font-size: 18px !important;
  padding: 4px 8px !important;
}

.maplibregl-popup-close-button:hover {
  color: #f1f5f9 !important;
  background: transparent !important;
}

.pub-popup {
  padding: 14px;
}

.pub-popup h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
  color: #f8fafc;
  line-height: 1.3;
}

.pub-popup .score-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.pub-popup .score-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
}

.pub-popup .score-badge.sun      { background: #422006; color: #fbbf24; }
.pub-popup .score-badge.partial  { background: #431407; color: #fb923c; }
.pub-popup .score-badge.shadow   { background: #1e293b; color: #94a3b8; border: 1px solid #334155; }
.pub-popup .score-badge.night    { background: #0f172a; color: #64748b; border: 1px solid #1e293b; }

.pub-popup .score-pct {
  font-size: 20px;
  font-weight: 700;
}

.pub-popup .score-pct.sun     { color: #fbbf24; }
.pub-popup .score-pct.partial { color: #fb923c; }
.pub-popup .score-pct.shadow  { color: #94a3b8; }
.pub-popup .score-pct.night   { color: #64748b; }

.pub-popup .detail-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  font-size: 12px;
}

.pub-popup .detail-label {
  color: #64748b;
  white-space: nowrap;
}

.pub-popup .detail-value {
  color: #cbd5e1;
}

/* ── Marker ── */
.pub-marker {
  cursor: pointer;
  transition: transform 0.15s;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pub-marker:hover { transform: scale(1.3); }

/* Circle backgrounds per state */
.pub-marker--sun     { background: #f59e0b; box-shadow: 0 2px 6px rgba(245,158,11,0.55); }
.pub-marker--partial { background: #f97316; box-shadow: 0 2px 6px rgba(249,115,22,0.45); }
.pub-marker--shadow  { background: #334155; border: 1px solid #475569; }
.pub-marker--rain    { background: #2563eb; box-shadow: 0 2px 4px rgba(37,99,235,0.4); }
.pub-marker--moon    { background: #1e293b; border: 1px solid #334155; }

/* ── Cluster marker ── */
.cluster-marker {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #1e293b;
  border: 2px solid #475569;
  color: #f1f5f9;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.cluster-marker:hover {
  border-color: #f59e0b;
  color: #f59e0b;
}

/* ── Detail panel ── */
#detail-panel {
  position: absolute;
  top: 40px;
  right: 0;
  bottom: 0;
  width: 360px;
  max-width: 100vw;
  z-index: 20;
  background: #1e293b;
  border-left: 1px solid #334155;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

#detail-panel.visible {
  transform: translateX(0);
}

#detail-panel.hidden {
  pointer-events: none;
}

#detail-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 24px;
  cursor: pointer;
  z-index: 1;
}
#detail-close:hover { color: #f1f5f9; }

#detail-content {
  padding: 16px;
}

#detail-name {
  font-size: 17px;
  font-weight: 700;
  color: #f8fafc;
  margin-bottom: 2px;
  padding-right: 28px;
  line-height: 1.3;
}

.detail-sub {
  font-size: 12px;
  color: #64748b;
  margin-bottom: 12px;
}

#detail-panel .score-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.sun-window {
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  display: inline-block;
  margin-bottom: 14px;
}

.sun-window--until {
  background: #422006;
  color: #fbbf24;
}

.sun-window--from {
  background: #0f2238;
  color: #7dd3fc;
}

.detail-section {
  margin-bottom: 18px;
}

.detail-section h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  margin-bottom: 8px;
  font-weight: 600;
}

#detail-panel .detail-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 13px;
}

#detail-panel .detail-label { color: #64748b; }
#detail-panel .detail-value { color: #cbd5e1; }

/* Compass rose */
#compass-container {
  display: flex;
  justify-content: center;
  padding: 4px 0;
}

/* Pavement table */
#pavement-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

#pavement-table th {
  text-align: left;
  color: #64748b;
  font-weight: 500;
  padding: 4px 6px;
  border-bottom: 1px solid #334155;
}

#pavement-table td {
  padding: 4px 6px;
  color: #cbd5e1;
  border-bottom: 1px solid #1e293b;
}

#pavement-table .verdict-good     { color: #4ade80; }
#pavement-table .verdict-possible { color: #fbbf24; }
#pavement-table .verdict-marginal { color: #fb923c; }

#detail-links a {
  color: #94a3b8;
  font-size: 12px;
  text-decoration: none;
}
#detail-links a:hover { color: #f59e0b; }

/* "More details" link in popup */
.pub-popup .more-link {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  color: #94a3b8;
  cursor: pointer;
  text-align: right;
}
.pub-popup .more-link:hover { color: #f59e0b; }

/* ── Best spots button + panel ── */
#best-spots-btn {
  position: absolute;
  bottom: 68px;
  left: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid #475569;
  border-radius: 20px;
  background: #1e293bee;
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: border-color 0.15s, color 0.15s;
}
#best-spots-btn:hover {
  border-color: #f59e0b;
  color: #f59e0b;
}

#best-spots-panel {
  position: absolute;
  bottom: 108px;
  left: 12px;
  z-index: 15;
  width: 280px;
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
#best-spots-panel.hidden { display: none; }

#best-spots-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid #334155;
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#best-spots-close {
  background: none;
  border: none;
  color: #64748b;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
}
#best-spots-close:hover { color: #f1f5f9; }

.best-spots-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px solid #1e293b;
  transition: background 0.1s;
}
.best-spots-row:last-child { border-bottom: none; }
.best-spots-row:hover { background: #334155; }

.best-spots-name {
  font-size: 13px;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.best-spots-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.best-spots-empty {
  padding: 14px 12px;
  font-size: 13px;
  color: #64748b;
}

/* Score badges (shared) */
.score-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
}
.score-badge.sun     { background: #422006; color: #fbbf24; }
.score-badge.partial { background: #431407; color: #fb923c; }
.score-badge.shadow  { background: #1e293b; color: #94a3b8; border: 1px solid #334155; }
.score-badge.night   { background: #0f172a; color: #64748b; border: 1px solid #1e293b; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 12px;
  padding: 24px;
  max-width: 480px;
  width: 100%;
  max-height: 85dvh;
  overflow-y: auto;
  position: relative;
}

.modal-box h2 {
  font-size: 18px;
  font-weight: 700;
  color: #f8fafc;
  margin-bottom: 12px;
  padding-right: 28px;
}

.modal-box h3 {
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 18px;
  margin-bottom: 6px;
}

.modal-box p {
  font-size: 13px;
  color: #cbd5e1;
  line-height: 1.65;
  margin-bottom: 6px;
}

.modal-box ol, .modal-box ul {
  padding-left: 18px;
  margin-bottom: 6px;
}

.modal-box li {
  font-size: 13px;
  color: #cbd5e1;
  line-height: 1.6;
  margin-bottom: 3px;
}

.modal-box code {
  background: #0f172a;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
  color: #7dd3fc;
}

.modal-box a { color: #94a3b8; text-decoration: none; }
.modal-box a:hover { color: #f59e0b; }

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: #64748b;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: #f1f5f9; }

.modal-footer {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid #334155;
  font-size: 12px !important;
  color: #64748b !important;
}

/* ── Attribution ── */
.maplibregl-ctrl-attrib {
  background: #1e293bee !important;
  color: #64748b !important;
  font-size: 11px !important;
}

.maplibregl-ctrl-attrib a { color: #94a3b8 !important; }

/* ── Mobile ── */
@media (max-width: 640px) {
  /* Search bar full width */
  #search-bar {
    left: 8px;
    right: 8px;
  }

  #search-input {
    flex: 1;
    width: auto;
    min-width: 0;
  }

  /* Larger tap targets for markers */
  .pub-marker {
    width: 34px;
    height: 34px;
  }

  /* Detail panel as bottom sheet */
  #detail-panel {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: 100vw;
    max-height: 70dvh;
    border-left: none;
    border-top: 1px solid #334155;
    border-radius: 12px 12px 0 0;
    transform: translateY(100%);
  }

  #detail-panel.visible {
    transform: translateY(0);
  }

  /* Drag handle hint */
  #detail-content::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    background: #475569;
    border-radius: 2px;
    margin: 0 auto 12px;
  }

  /* Popup narrower on mobile */
  .maplibregl-popup-content {
    min-width: 200px;
    max-width: 260px !important;
  }

  /* Banner: hide stats to save space */
  #banner-stats { display: none; }

  /* Best spots button */
  #best-spots-btn { bottom: 76px; }
  #best-spots-panel { bottom: 118px; left: 8px; right: 8px; width: auto; }

  /* Compass rose smaller */
  #compass-container svg {
    width: 140px;
    height: 140px;
  }
}
