:root {
  --bg: #080d13;
  --bg-2: #0d141c;
  --panel: #111b25;
  --panel-2: #16222e;
  --ink: #ffffff;
  --muted: #94a3b8;
  --faint: #64748b;
  --line: #1e2c3a;
  --line-2: #2a3b4c;
  --accent: #38bdf8;

  --confirmed: #f2555a;
  --probable: #f5a524;
  --signal: #7f92a5;
  --resolved: #2fb37a;
  --warning: #4b8ff5;
  --rescue: #2fb37a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }

/* ---------- header ---------- */
header {
  padding: 12px 20px 0;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-bottom: 1px solid var(--line);
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -.01em;
  white-space: nowrap;
}
.brand .live {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--resolved);
}
.brand .live::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--resolved); box-shadow: 0 0 0 0 rgba(47, 179, 122, .55);
  animation: pulse 2.4s infinite;
}
@keyframes pulse {
  70% { box-shadow: 0 0 0 7px rgba(47, 179, 122, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 179, 122, 0); }
}
@media (prefers-reduced-motion: reduce) { .brand .live::before { animation: none; } }

.ctrl { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.ctrl select, .ctrl button, .ctrl a.btn {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: border-color .15s, background .15s;
}
.ctrl select:hover, .ctrl button:hover, .ctrl a.btn:hover { border-color: var(--accent); background: var(--panel-2); }
.ctrl select:focus-visible, .ctrl button:focus-visible, .ctrl a.btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

header .tag { margin: 8px 0 0; color: var(--muted); max-width: 78ch; font-size: 13px; }

/* ---------- KPI strip ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(126px, 1fr));
  gap: 10px;
  margin: 12px 0;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
}
.kpi .k-val {
  font-size: 22px; font-weight: 650; line-height: 1.15;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.kpi .k-lab {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin-top: 2px;
}
.kpi.is-confirmed .k-val { color: var(--confirmed); }
.kpi.is-warning   .k-val { color: var(--warning); }
.kpi.is-ok        .k-val { color: var(--resolved); }
.kpi.is-degraded  .k-val { color: var(--probable); }

#stale {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: #3c1618;
  color: #ffb9bb;
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid #6d2427;
}

/* ---------- layout ---------- */
main { flex: 1; display: flex; min-height: 0; }
#map { flex: 1; min-width: 0; background: #060a0f; }
.leaflet-container { background: #060a0f; }
.leaflet-control-attribution {
  background: rgba(8, 13, 19, .82) !important;
  color: var(--faint) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--muted) !important; }

#side {
  width: 360px;
  border-left: 1px solid var(--line);
  background: var(--bg-2);
  overflow-y: auto;
  padding: 14px 16px 18px;
}
#side h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted); margin: 16px 0 9px; font-weight: 650;
}

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 11.5px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.s-confirmed { background: var(--confirmed); }
.s-probable  { background: var(--probable); }
.s-signal    { background: var(--signal); }
.s-resolved  { background: var(--resolved); }
.s-warning   { background: var(--warning); }

/* ---------- timeline ---------- */
#timeline { list-style: none; margin: 0; padding: 0; }
#timeline li {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--signal);
  border-radius: 9px;
  padding: 9px 11px 9px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .12s;
}
#timeline li:hover { background: var(--panel-2); border-color: var(--line-2); transform: translateX(1px); }
#timeline li.confirmed { border-left-color: var(--confirmed); }
#timeline li.probable  { border-left-color: var(--probable); }
#timeline li.resolved  { border-left-color: var(--resolved); }
#timeline li.warning   { border-left-color: var(--warning); }
#timeline li.rescue    { border-left-color: var(--rescue); }

#timeline .t-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#timeline .t-type { font-weight: 620; display: flex; align-items: center; gap: 7px; min-width: 0; }
#timeline .t-type .t-ico { font-size: 15px; flex: none; }
#timeline .t-type .t-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#timeline .t-badge {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 7px; border-radius: 999px;
  background: #1d2a37; color: var(--muted); white-space: nowrap; flex: none;
}
#timeline li.confirmed .t-badge { background: #3a1d1f; color: #ff9fa2; }
#timeline li.probable  .t-badge { background: #3a2c14; color: #fbc76a; }
#timeline li.resolved  .t-badge { background: #16302a; color: #6fd6ab; }
#timeline .t-badge:empty { display: none; }
#timeline .t-area { color: var(--muted); font-size: 12px; margin-top: 3px; }
#timeline .t-area .t-when { color: var(--faint); }
#timeline .t-src { font-size: 12px; margin-top: 5px; color: var(--muted); }
#timeline .t-src a { color: var(--accent); text-decoration: none; }
#timeline .t-src a:hover { text-decoration: underline; }

.empty {
  border: 1px dashed var(--line-2);
  border-radius: 9px;
  padding: 22px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.empty b { display: block; color: var(--ink); font-size: 14px; margin-bottom: 3px; }

/* ---------- popups ---------- */
.leaflet-popup-content-wrapper {
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.leaflet-popup-tip { background: var(--panel); border: 1px solid var(--line-2); }
.leaflet-popup-content { margin: 11px 13px; font-size: 13px; }
.leaflet-popup-close-button { color: var(--muted) !important; }
.popup-title { font-weight: 650; margin-bottom: 4px; }
.popup-meta { color: var(--muted); font-size: 12px; }
.popup-meta a, .leaflet-popup-content a { color: var(--accent); }
.badge-unverified {
  display: inline-block; margin: 3px 0;
  font-size: 11px; font-weight: 650;
  padding: 2px 7px; border-radius: 999px;
  background: #3a2c14; color: #fbc76a;
}
.popup-track {
  display: inline-block; margin: 4px 0 2px;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
  background: rgba(245, 165, 36, 0.15);
  color: #f5a524;
  border: 1px solid rgba(245, 165, 36, 0.3);
}

/* ---------- offline banner ---------- */
.offline-bar {
  background: #7f1d1d;
  color: #fecaca;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 16px;
  text-align: center;
  border-bottom: 1px solid #b91c1c;
}

/* ---------- safety strip ticker ---------- */
.safety-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}
.safety-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 12px;
  white-space: nowrap;
  flex: none;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.safety-card:hover { background: var(--panel-2); border-color: var(--line-2); }
.safety-card .sc-title { font-weight: 650; color: var(--ink); }

/* ---------- today outlook panel ---------- */
.outlook-panel {
  margin: 4px 0 8px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.outlook-panel .ol-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 8px;
}
.outlook-panel .ol-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
  margin-right: 4px;
}
.outlook-panel .ol-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: #0e7490;
  color: #ecfeff;
}
.outlook-panel select {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--ink);
  max-width: 100%;
}
.outlook-timeline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.outlook-seg {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  border: 1px solid var(--line);
  min-width: 7.5rem;
}
.outlook-seg.ok { background: rgba(34, 197, 94, 0.12); border-color: rgba(34, 197, 94, 0.35); }
.outlook-seg.watch { background: rgba(234, 179, 8, 0.14); border-color: rgba(234, 179, 8, 0.4); }
.outlook-seg.danger { background: rgba(239, 68, 68, 0.14); border-color: rgba(239, 68, 68, 0.4); }
.outlook-seg .ol-hours { font-weight: 700; font-variant-numeric: tabular-nums; }
.outlook-seg .ol-level { font-size: 11px; opacity: 0.9; }
.outlook-return {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}
.outlook-now {
  margin-top: 6px;
  font-size: 11px;
  opacity: 0.85;
  color: var(--muted, #94a3b8);
}
.outlook-status {
  font-size: 12px;
  opacity: 0.9;
  padding: 4px 0;
}
.outlook-skel {
  display: inline-block;
  height: 36px;
  width: 96px;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--panel-2), var(--line), var(--panel-2));
  background-size: 200% 100%;
  opacity: 0.6;
}
@media (max-width: 640px) {
  .outlook-panel .ol-head { flex-direction: column; align-items: stretch; }
  .outlook-panel select { width: 100%; }
}

.safety-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
}
.safety-badge.good { background: rgba(47, 179, 122, 0.18); color: #4ade80; border: 1px solid rgba(74, 222, 128, 0.3); }
.safety-badge.caution { background: rgba(245, 165, 36, 0.18); color: #fbbf24; border: 1px solid rgba(251, 191, 36, 0.3); }
.safety-badge.danger, .safety-badge.suspended { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(248, 113, 113, 0.35); }
.safety-card .sc-meta { color: var(--muted); font-size: 11px; }

/* ---------- search & filter chips ---------- */
.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 10px;
  flex-wrap: wrap;
}
.search-box {
  position: relative;
  flex: 1;
  min-width: 220px;
  max-width: 380px;
}
.search-box .search-ico {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  opacity: 0.6;
  pointer-events: none;
}
.search-box input[type="search"] {
  width: 100%;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 6px 12px 6px 30px;
  font: inherit;
  font-size: 12.5px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-box input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25);
}
.search-box.shake {
  animation: shake 0.3s ease-in-out;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.chip-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.chip {
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 550;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover {
  background: var(--panel-2);
  color: var(--ink);
  border-color: var(--line-2);
}
.chip.is-active {
  background: #0284c7;
  color: #ffffff;
  border-color: #38bdf8;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.35);
}

.btn-emergency {
  background: #3a1d1f !important;
  color: #ff9fa2 !important;
  border-color: #7f1d1d !important;
  font-weight: 600 !important;
}
.btn-emergency:hover {
  background: #4c1d24 !important;
  border-color: #ef4444 !important;
}
.btn-playback {
  background: #162a45 !important;
  color: #38bdf8 !important;
  border-color: #1e4976 !important;
}

/* ---------- map wrapper & playback ---------- */
.map-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.playback-bar {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(17, 27, 37, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 8px 16px;
  color: var(--ink);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  min-width: 360px;
  max-width: 90vw;
}
.play-btn {
  background: var(--accent);
  color: #080d13;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .12s;
}
.play-btn:hover { transform: scale(1.08); }
.play-label { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.play-time { font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--accent); white-space: nowrap; }
.playback-bar input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}
.play-speeds { display: flex; gap: 4px; }
.speed-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 10px;
  cursor: pointer;
}
.speed-btn.is-active {
  background: var(--accent);
  color: #080d13;
  font-weight: 700;
}
.play-close {
  background: transparent;
  color: var(--muted);
  border: none;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

/* ---------- modal ---------- */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal[hidden] { display: none !important; }
.modal-backdrop {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(4, 7, 11, 0.78);
  backdrop-filter: blur(6px);
}
.modal-card {
  position: relative;
  z-index: 2001;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  width: 100%;
  max-width: 580px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 650; color: var(--ink); }
.modal-close {
  background: transparent; border: none; font-size: 20px; color: var(--muted); cursor: pointer;
}
.modal-body { padding: 18px; max-height: 80vh; overflow-y: auto; }
.emergency-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.em-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
}
.em-card.em-primary {
  border-color: #ef4444;
  background: linear-gradient(180deg, #2b1114, var(--bg-2));
}
.em-num { font-size: 18px; font-weight: 700; color: #f87171; }
.em-primary .em-num { color: #fca5a5; font-size: 20px; }
.em-title { font-size: 12px; font-weight: 600; color: var(--ink); margin: 3px 0; }
.em-desc { font-size: 11px; color: var(--muted); line-height: 1.4; flex: 1; }
.btn-copy {
  margin-top: 10px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  align-self: flex-start;
  transition: background .15s;
}
.btn-copy:hover { background: var(--panel-2); border-color: var(--accent); }

/* ---------- toast container ---------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: rgba(17, 27, 37, 0.95);
  backdrop-filter: blur(10px);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12.5px;
  font-weight: 550;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: slideInUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}
@keyframes slideInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- highlights ---------- */
mark.highlight {
  background: #facc15;
  color: #000;
  padding: 1px 3px;
  border-radius: 3px;
  font-weight: 600;
}

/* ---------- weather overlay marker & sparkline ---------- */
.weather-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
  cursor: pointer;
}
.weather-arrow {
  width: 22px;
  height: 22px;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.8));
  transition: transform 0.2s ease-out;
}
.weather-pill {
  background: rgba(10, 16, 29, 0.85);
  backdrop-filter: blur(4px);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  padding: 1px 5px;
  font-size: 10px;
  font-weight: 650;
  color: var(--ink);
  white-space: nowrap;
  margin-top: -2px;
}
.sparkline-box {
  margin: 8px 0 4px;
  padding: 6px 8px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.sparkline-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 2px;
}
svg.sparkline {
  display: block;
  overflow: visible;
}

.btn-share {
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--panel-2);
  color: var(--accent);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn-share:hover { border-color: var(--accent); }

/* ---------- footer ---------- */
footer {
  border-top: 1px solid var(--line);
  padding: 9px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  color: var(--faint);
  font-size: 11px;
  background: var(--bg-2);
}
footer a { color: var(--muted); }
footer strong { color: var(--muted); }

@media (max-width: 820px) {
  main { flex-direction: column; }
  #map { min-height: 44vh; }
  #side { width: auto; border-left: 0; border-top: 1px solid var(--line); max-height: none; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); }
  .emergency-grid { grid-template-columns: 1fr; }
  .playback-bar { width: 94vw; min-width: unset; bottom: 12px; padding: 6px 12px; }
  header .tag { display: none; }
}
