:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2330;
  --border: #2d333b;
  --text: #e6edf3;
  --text-dim: #9198a1;
  --evac: #f85149;
  --alert: #f0883e;
  --advice: #d29922;
  --sat: #a371f7;
  --safe: #3fb950;
  --radius: 14px;
  --sheet-h: 42vh;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}

/* ---------- Top bar ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: linear-gradient(to bottom, rgba(13,17,23,.96), rgba(13,17,23,.82));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.brand-flame { color: var(--evac); align-self: center; flex: none; }
.brand h1 { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.brand-sub { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.topbar-actions { display: flex; gap: 8px; flex: none; }

.chip-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.chip-btn:active { background: var(--panel-2); }
.lang-btn { min-width: 42px; }

/* ---------- Map ---------- */
#map { position: fixed; inset: 0; }
.maplibregl-ctrl-attrib { font-size: 10px; background: rgba(13,17,23,.7) !important; }
.maplibregl-ctrl-attrib a { color: var(--text-dim) !important; }

/* ---------- Legend ---------- */
.legend {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 58px);
  left: 10px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: rgba(22,27,34,.88);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 11px;
  color: var(--text-dim);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot-evac { background: var(--evac); }
.dot-alert { background: var(--alert); }
.dot-advice { background: var(--advice); }
.dot-sat { background: var(--sat); }

/* ---------- Incident markers ---------- */
.marker {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.55);
}
.marker-evacuation { background: var(--evac); animation: pulse 1.6s ease-out infinite; }
.marker-alert { background: var(--alert); }
.marker-advice { background: var(--advice); }
.marker-contained { background: var(--safe); opacity: .8; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(248,81,73,.55); }
  70% { box-shadow: 0 0 0 16px rgba(248,81,73,0); }
  100% { box-shadow: 0 0 0 0 rgba(248,81,73,0); }
}

/* ---------- Bottom sheet ---------- */
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  max-height: var(--sheet-h);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -8px 30px rgba(0,0,0,.5);
  transition: transform .25s ease;
}
.sheet.collapsed { transform: translateY(calc(100% - 92px)); }
.sheet-handle {
  padding: 8px 0 2px;
  display: flex;
  justify-content: center;
  cursor: grab;
}
.sheet-handle span {
  width: 42px; height: 4px;
  border-radius: 2px;
  background: var(--border);
}
.sheet-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 16px 8px;
}
.sheet-header h2 { font-size: 15px; font-weight: 700; }
.data-stamp { font-size: 11px; color: var(--text-dim); }

.incident-list {
  list-style: none;
  overflow-y: auto;
  padding: 0 10px;
  -webkit-overflow-scrolling: touch;
}
.incident-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 10px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
}
.incident-card:hover, .incident-card:active { background: var(--panel-2); border-color: var(--border); }
.status-pill {
  flex: none;
  width: 12px; height: 12px;
  border-radius: 50%;
}
.incident-card .info { min-width: 0; flex: 1; }
.incident-card .name { font-size: 14px; font-weight: 650; }
.incident-card .meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.incident-card .status-label {
  flex: none;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 4px 8px;
  border-radius: 6px;
}
.sl-evacuation { color: #fff; background: var(--evac); }
.sl-alert { color: #1a1005; background: var(--alert); }
.sl-advice { color: #1a1005; background: var(--advice); }
.sl-contained { color: #04150a; background: var(--safe); }

.disclaimer {
  font-size: 11px;
  color: var(--text-dim);
  padding: 8px 16px 4px;
  border-top: 1px solid var(--border);
}
.support-line {
  padding: 0 16px calc(env(safe-area-inset-bottom) + 10px);
  font-size: 11px;
}
.support-line a { color: #d29922; text-decoration: none; }

/* ---------- Detail & risk panels ---------- */
.detail, .risk-panel {
  position: fixed;
  z-index: 50;
  inset: auto 0 0 0;
  max-height: 78vh;
  overflow-y: auto;
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -12px 40px rgba(0,0,0,.6);
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px);
  -webkit-overflow-scrolling: touch;
}
.detail-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.detail h2 { font-size: 19px; padding-right: 40px; }
.detail .d-meta { font-size: 12.5px; color: var(--text-dim); margin: 4px 0 12px; }
.d-status-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.d-chip {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.d-chip.hot { border-color: var(--evac); color: var(--evac); }

.forces {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 8px;
  margin: 12px 0 16px;
}
.force {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 6px;
  text-align: center;
}
.force b { display: block; font-size: 18px; }
.force span { font-size: 10.5px; color: var(--text-dim); }

.section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  margin: 16px 0 8px;
}

.timeline { list-style: none; position: relative; padding-left: 18px; }
.timeline::before {
  content: "";
  position: absolute;
  left: 5px; top: 6px; bottom: 6px;
  width: 2px;
  background: var(--border);
}
.timeline li { position: relative; padding: 0 0 14px 8px; }
.timeline li::before {
  content: "";
  position: absolute;
  left: -18px; top: 5px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
  border: 2px solid var(--panel);
}
.timeline li.tl-112::before { background: var(--evac); }
.timeline .tl-time { font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.timeline .tl-text { font-size: 13.5px; margin-top: 2px; line-height: 1.45; }
.tl-112 .tl-text { color: #ffb3ae; }
.tl-badge {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 800;
  background: var(--evac);
  color: #fff;
  border-radius: 4px;
  padding: 2px 5px;
  margin-right: 6px;
  vertical-align: 1px;
}

.wind-box {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
}
.wind-arrow { font-size: 22px; display: inline-block; transition: transform .4s; }

/* ---------- Risk panel ---------- */
.risk-panel h2 { font-size: 17px; padding-right: 40px; }
.risk-note { font-size: 12px; color: var(--text-dim); margin: 6px 0 12px; }
.risk-list { list-style: none; }
.risk-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.risk-cat {
  font-size: 11px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  color: #0d1117;
}
.cat-1 { background: #3fb950; }
.cat-2 { background: #9ece6a; }
.cat-3 { background: #d29922; }
.cat-4 { background: #f0883e; }
.cat-5 { background: #f85149; color: #fff; animation: pulse 1.6s infinite; }

.ext-link {
  display: inline-block;
  margin-top: 14px;
  color: #58a6ff;
  font-size: 13px;
  text-decoration: none;
}

/* ---------- 112 FAB ---------- */
.emergency-fab {
  position: fixed;
  right: 12px;
  bottom: calc(var(--sheet-h) + 14px);
  z-index: 35;
}
.emergency-fab a {
  display: inline-block;
  background: var(--evac);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 999px;
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(248,81,73,.4);
}

@media (min-width: 760px) {
  .sheet, .detail, .risk-panel {
    left: 14px; right: auto;
    width: 400px;
    bottom: 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
  }
  .sheet { max-height: 46vh; }
  .sheet.collapsed { transform: none; }
  .emergency-fab { bottom: 20px; }
  .legend { top: auto; bottom: 20px; left: auto; right: 12px; flex-direction: row; gap: 12px; }
}
