/* Reset + base */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background:#0b1020;
  color:#e9ecff;
}

/* Right panel */
#panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 360px;
  background: radial-gradient(1200px 800px at 100% 0%, #141a3c 0%, #0f1530 45%, #0b1020 100%);
  border-left: 1px solid #20285a;
  padding: 14px 14px 64px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.03);
  overflow: auto; z-index: 500;
}

/* Map fills space left of the panel (desktop) */
#map {
  position: absolute; top: 0; left: 0; bottom: 0; right: 360px;
  min-height: 520px;
  background: #0b1020;
}

/* On-map info box */
.info-box {
  position: absolute; left: 12px; bottom: 12px; z-index: 600;
  border: 1px solid #2b3262; border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
  background: rgba(15,21,48,0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  color: #e9ecff;
  max-width: 320px;
}
.info-box__inner { padding: 10px 12px; font-size: 12.5px; line-height: 1.45; }
.info-box__header { display:flex; justify-content:space-between; gap:10px; align-items:baseline; }
.info-box__title { margin:0; font-size:13.5px; color:#e9ecff; }
.info-box__updated { font-size:11.5px; opacity:.85; white-space: nowrap; }
.info-box p { margin:6px 0; }
.info-box__meta { opacity:.9; }

/* Panel header with sticky dropdown (desktop) */
.panel-header {
  position: sticky; top: 0; z-index: 2;
  display: flex; justify-content: flex-end; align-items: center;
  padding-bottom: 6px; margin-bottom: 6px;
  background: linear-gradient(180deg, rgba(10,15,32,.9), rgba(10,15,32,0));
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
#metricSelect {
  background: #0f1530; color: #e9ecff;
  border: 1px solid #2b3262; border-radius: 10px;
  padding: 10px 12px; min-width: 210px; font-size: 0.95rem;
}

/* Metric chip (used in mobile toolbar) */
.metric-chip {
  display: none;
  background: #0f1530;
  color: #e9ecff;
  border: 1px solid #2b3262;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Cards */
.stats-card, .chart-card {
  border: 1px solid #2b3262; border-radius: 12px; background:#0e1330;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.stats-card { padding: 10px 12px; }
.stats-row {
  display:flex; justify-content: space-between; margin: 6px 0; font-size: .95rem;
}
.stats-row span { opacity: .85; }

.chart-card {
  padding: 10px 12px; min-height: 260px; display:flex; flex-direction: column;
}

/* Footer credit */
.credit {
  position: absolute; right: 14px; bottom: 10px;
  opacity: .85; font-size: .9rem;
}

/* Leaflet niceties */
.leaflet-interactive { transition: all 180ms ease; }
.leaflet-container { background: transparent !important; }

/* ---------- Mobile toolbar (hidden on desktop) ---------- */

.mobile-toolbar {
  display: none; /* shown only on mobile */
  position: sticky; top: 0; z-index: 1000;
  padding: 8px 10px;
  background: linear-gradient(180deg, rgba(10,15,32,.97), rgba(10,15,32,.85));
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid #20285a;
}
.mobile-toolbar .metric-chip { display: block; }

/* ---------- Responsive tweaks (desktop unchanged) ---------- */

/* Tablet & small laptop */
@media (max-width: 1024px) {
  #panel { width: 340px; }
  #map { right: 340px; }
}

/* Phone layout */
@media (max-width: 980px) {
  /* Show top toolbar and hide the panel header */
  .mobile-toolbar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
  }
  #metricSelectMobile {
    background: #0f1530; color: #e9ecff;
    border: 1px solid #2b3262; border-radius: 10px;
    padding: 12px 14px; font-size: 1rem; min-width: 0; width: 100%;
  }
  .panel-header { display: none; } /* hide desktop header on phones */

  #panel {
    position: static;
    width: auto;
    border-left: none;
    border-top: 1px solid #20285a;
    padding: 14px 14px 90px;
  }
  #map {
    position: relative;
    right: 0;
    height: 70vh;
    min-height: 380px;
  }

  /* Centered, smaller info box WITH smaller text */
  .info-box {
    left: 50%;
    transform: translateX(-50%);
    bottom: 8px;
    max-width: min(88vw, 360px);
    border-radius: 8px;
    box-shadow: 0 4px 14px rgba(0,0,0,.28);
  }
  .info-box__inner { padding: 8px 10px; }
  .info-box__title { font-size: 12.5px; }
  .info-box__updated { font-size: 11px; }
  .info-box p { font-size: 12px; line-height: 1.35; margin: 4px 0; }
  /* keep .info-box__meta visible (do NOT hide) */

  /* Hide bar chart on phones */
  .chart-card { display: none; }

  /* Spacing */
  #panel > .stats-card { margin-top: 14px; }
  .stats-card, .chart-card { border-radius: 10px; }

  /* Credit flows below content */
  .credit { position: static; text-align: right; margin-top: 10px; }
}

/* Extra-small phones: slightly tighter info box */
@media (max-width: 420px) {
  .info-box { max-width: 90vw; bottom: 6px; }
}
