:root {
  --bg: #12121f;
  --panel: #1A1A2E;
  --panel-2: #22223a;
  --line: #2f2f4a;
  --text: #eef0f6;
  --muted: #9a9cb5;
  --flame: #E85D24;
  --green: #22c55e;
  --yellow: #facc15;
  --red: #ef4444;
  --blue: #3b82f6;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); min-height: 1.2em; margin: 6px 0 0; font-size: 14px; }

button { background: var(--flame); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; }
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.danger { color: var(--red); border-color: #5a2a33; }
.small-btn { padding: 6px 10px; font-size: 13px; }
input { width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; font: inherit; margin-top: 4px; }
input:focus { outline: 2px solid var(--flame); border-color: transparent; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h3 { margin: 0; font-size: 16px; }

.brand { font-weight: 800; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; font-size: 18px; }
.brand.big { font-size: 26px; justify-content: center; }
.logo-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--flame);
  box-shadow: 0 0 0 4px rgba(232, 93, 36, .25); }

.screen { min-height: 100vh; }
#login { display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; text-align: center; display: grid; gap: 12px; padding: 28px; }
.login-card p { margin: 0; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(18, 18, 31, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.top-actions { display: flex; gap: 8px; }
main { max-width: 980px; margin: 0 auto; padding: 16px; }

.tabs { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; }
.tab { background: var(--panel); border: 1px solid var(--line); color: var(--text); white-space: nowrap;
  display: flex; align-items: center; gap: 8px; font-weight: 500; }
.tab.active { border-color: var(--flame); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.l0 { background: var(--green); } .dot.l1 { background: var(--yellow); }
.dot.l2 { background: var(--red); } .dot.off { background: #555; }

.status-row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 14px; }
.status-row .card { margin-bottom: 14px; }
.status-card { display: flex; flex-direction: column; justify-content: center; align-items: center;
  text-align: center; min-height: 150px; transition: background .3s, border-color .3s; }
.status-label { font-size: 30px; font-weight: 800; letter-spacing: .5px; }
.status-sub { color: var(--muted); margin-top: 4px; }
.level-0 { background: linear-gradient(160deg, rgba(34,197,94,.22), var(--panel)); border-color: rgba(34,197,94,.5); }
.level-0 .status-label { color: var(--green); }
.level-1 { background: linear-gradient(160deg, rgba(250,204,21,.22), var(--panel)); border-color: rgba(250,204,21,.6); }
.level-1 .status-label { color: var(--yellow); }
.level-2 { background: linear-gradient(160deg, rgba(239,68,68,.32), var(--panel)); border-color: var(--red);
  animation: pulse 1s infinite; }
.level-2 .status-label { color: #fff; }
.level-off .status-label { color: var(--muted); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(239,68,68,.25); } }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.stats > div { display: flex; flex-direction: column; }
.stat-num { font-size: 22px; font-weight: 700; }
.stat-cap { font-size: 12px; color: var(--muted); }
.blue-on { color: var(--blue); }

canvas { width: 100%; display: block; }
.legend { display: flex; gap: 16px; margin-top: 8px; }
.sw { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 6px; }
.sw-y { background: var(--yellow); } .sw-r { background: var(--red); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
.pill { padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.pill.l1 { background: rgba(250,204,21,.18); color: var(--yellow); }
.pill.l2 { background: rgba(239,68,68,.2); color: var(--red); }

.device-info dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.device-info dt { color: var(--muted); }
.device-info dd { margin: 0; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0; width: min(440px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog-body { padding: 20px; }
.dialog-body h3 { margin-top: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
pre { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  white-space: pre-wrap; word-break: break-all; font-size: 13px; }

/* ---------- Map ---------- */
.map-row { display: grid; grid-template-columns: 1.5fr 1fr; gap: 14px; }
.map-row .card { margin-bottom: 14px; }
#map { height: 320px; border-radius: 10px; overflow: hidden; background: #0d0d18; }
.map-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.pick-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px;
  padding: 8px 10px; background: var(--panel-2); border-radius: 10px; }
.pick-bar > div { display: flex; gap: 6px; }
#mapNote { margin: 8px 0 0; }
.leaflet-container { font: inherit; background: #1b1b2b; }
/* Dark map look from the normal OSM tiles */
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9) saturate(.6); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-popup-content a { color: var(--flame); }

.qp-pin { --c: var(--green); width: 22px; height: 22px; border-radius: 50%; background: var(--c);
  border: 3px solid #fff; box-shadow: 0 0 8px rgba(0,0,0,.6); position: relative; }
.qp-pin::before, .qp-pin::after { content: ''; position: absolute; inset: -3px; border-radius: 50%;
  border: 3px solid var(--c); opacity: 0; }
.qp-pin.l0 { --c: var(--green); }
.qp-pin.l0::before { animation: ping 3s infinite; }
.qp-pin.l1 { --c: var(--yellow); }
.qp-pin.l1::before { animation: ping 1.4s infinite; }
.qp-pin.l2 { --c: var(--red); animation: blink .5s steps(2) infinite; }
.qp-pin.l2::before { animation: ping .8s infinite; }
.qp-pin.l2::after { animation: ping .8s .4s infinite; }
.qp-pin.off { --c: #666; }
@keyframes ping { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(4.5); opacity: 0; } }
@keyframes blink { 50% { background: #fff; } }

.st-pin { width: 22px; height: 22px; border-radius: 6px; background: #b91c1c; color: #fff; font-size: 13px;
  display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 0 6px rgba(0,0,0,.5); }

/* ---------- Emergency card ---------- */
.emergency-card h4.sub-head { margin: 16px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.hotline { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; }
.hotline.primary { border-color: var(--red); background: rgba(239,68,68,.12); }
.hotline .num { font-size: 22px; font-weight: 800; }
.hotline.primary .num { color: #ff8a8a; }
.call-btn { background: var(--red); color: #fff; border-radius: 10px; padding: 8px 14px; font-weight: 700;
  text-decoration: none; white-space: nowrap; }
.call-btn.alt { background: transparent; border: 1px solid var(--line); color: var(--text); }
.station { padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--text); }
.station:last-child { border-bottom: 0; }
.station-top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.station-links { display: flex; gap: 12px; margin-top: 4px; font-size: 13px; }
.station-links a { color: var(--flame); text-decoration: none; }

/* ---------- RED alert overlay ---------- */
.alert-overlay { position: fixed; inset: 0; z-index: 2000; background: rgba(60, 0, 0, .88);
  display: grid; place-items: center; padding: 16px; animation: flash 1s infinite; }
@keyframes flash { 50% { background: rgba(120, 0, 0, .92); } }
.alert-box { background: var(--panel); border: 2px solid var(--red); border-radius: 18px; padding: 20px;
  width: min(520px, 100%); text-align: center; display: grid; gap: 12px; }
.alert-title { font-size: 26px; font-weight: 900; color: #ff6b6b; letter-spacing: .5px; }
.alert-where { font-size: 16px; }
.alert-advice { font-size: 14px; color: var(--muted); }
#alertMap { height: 200px; border-radius: 10px; overflow: hidden; }
.alert-call { display: block; background: var(--red); color: #fff; font-size: 24px; font-weight: 900;
  padding: 16px; border-radius: 14px; text-decoration: none; }
.alert-station { font-size: 14px; }
.alert-station a { color: var(--flame); }

@media (max-width: 680px) {
  .map-row { grid-template-columns: 1fr; gap: 0; }
  #map { height: 260px; }
  .status-row { grid-template-columns: 1fr; gap: 0; }
  .status-label { font-size: 26px; }
}
