:root {
  --bg: #07090d;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #12203a 0%, transparent 60%), radial-gradient(900px 500px at 110% 10%, #1a1230 0%, transparent 55%);
  --surface: rgba(17, 22, 30, .72);
  --surface-2: #151b24;
  --surface-3: #1b2330;
  --border: rgba(255, 255, 255, .07);
  --border-strong: rgba(255, 255, 255, .14);
  --text: #e8edf4;
  --muted: #8592a3;
  --accent: #5b8cff;
  --l0: #22c55e; --l1: #eab308; --l2: #f97316; --l3: #ef4444; --na: #64748b;
  --radius: 14px;
  --shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 10px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f5f9;
    --bg-grad: radial-gradient(1200px 600px at 10% -10%, #dfe8ff 0%, transparent 60%), radial-gradient(900px 500px at 110% 10%, #efe6ff 0%, transparent 55%);
    --surface: rgba(255,255,255,.82); --surface-2: #ffffff; --surface-3: #eef1f6;
    --border: rgba(15, 23, 42, .08); --border-strong: rgba(15, 23, 42, .16);
    --text: #0f172a; --muted: #5b6678; --shadow: 0 1px 2px rgba(15,23,42,.05), 0 8px 24px rgba(15,23,42,.06);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg-grad), var(--bg); background-attachment: fixed; color: var(--text); font: 14px/1.5 Inter, "Segoe UI", system-ui, sans-serif; -webkit-font-smoothing: antialiased; min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
svg[viewBox="0 0 24 24"] { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.mono { font-family: "JetBrains Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 900; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 14px 28px; background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--accent), #8b5cf6); box-shadow: 0 6px 18px rgba(91,140,255,.35); transition: background .4s; }
.logo svg { width: 20px; height: 20px; }
.logo.l1 { background: linear-gradient(135deg, #eab308, #ca8a04); box-shadow: 0 6px 18px rgba(234,179,8,.35); }
.logo.l2 { background: linear-gradient(135deg, #f97316, #ea580c); box-shadow: 0 6px 18px rgba(249,115,22,.4); }
.logo.l3 { background: linear-gradient(135deg, #ef4444, #b91c1c); box-shadow: 0 6px 22px rgba(239,68,68,.5); animation: throb 1.4s ease-in-out infinite; }
.brand-title { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-sub { color: var(--muted); font-size: 12px; }
.top-right { display: flex; align-items: center; gap: 8px; }
.status-pill { display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12.5px; color: var(--muted); }
.status-pill .sep { width: 1px; height: 12px; background: var(--border-strong); }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--na); }
.live.on { background: var(--l0); box-shadow: 0 0 0 0 rgba(34,197,94,.6); animation: ping 2s infinite; }
.live.busy { background: var(--accent); animation: ping 1s infinite; }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.5); } 70% { box-shadow: 0 0 0 8px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }
@keyframes throb { 50% { transform: scale(1.06); } }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; transition: border-color .15s, background .15s; }
.icon-btn:hover { border-color: var(--border-strong); background: var(--surface-3); }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.spin svg { animation: spin .9s linear infinite; }
.icon-btn.active { color: var(--l0); border-color: color-mix(in srgb, var(--l0) 40%, transparent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-weight: 600; transition: filter .15s, border-color .15s; }
.btn:hover { border-color: var(--border-strong); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.full { width: 100%; }
.text-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px 0; font-size: 12.5px; }
.text-btn:hover { color: var(--text); }

/* ---------- place tabs ---------- */
.places { display: flex; gap: 8px; padding: 18px 28px 0; flex-wrap: wrap; max-width: 1440px; margin: 0 auto; }
.place { display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; transition: border-color .15s, background .15s; }
.place:hover { border-color: var(--border-strong); }
.place.active { background: var(--surface-3); border-color: var(--border-strong); box-shadow: 0 0 0 1px var(--border-strong) inset; }
.place .pdot { width: 8px; height: 8px; border-radius: 50%; }
.place .plvl { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; color: var(--muted); }
.place .x { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 6px; color: var(--muted); opacity: 0; transition: opacity .15s; }
.place:hover .x { opacity: 1; }
.place .x:hover { background: var(--surface-2); color: var(--text); }
.place .x svg { width: 14px; height: 14px; }
.place.add { color: var(--muted); border-style: dashed; padding-right: 14px; }
.place.add svg { width: 15px; height: 15px; }

/* ---------- layout ---------- */
.wrap { max-width: 1440px; margin: 0 auto; padding: 16px 28px 40px; }
.hero { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 28px 2px 12px; }
.section-head.inner { margin: 0 0 14px; }
.section-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.section-head p { margin: 4px 0 0; font-size: 13px; }

/* ---------- verdict ---------- */
.verdict { position: relative; overflow: hidden; padding: 26px 28px; display: flex; flex-direction: column; min-height: 400px; --lc: var(--na); }
.verdict::before { content: ""; position: absolute; inset: 0; background: radial-gradient(600px 300px at 0% 0%, color-mix(in srgb, var(--lc) 26%, transparent), transparent 70%); pointer-events: none; transition: background .4s; }
.verdict::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--lc); }
.verdict.lvl0 { --lc: var(--l0); } .verdict.lvl1 { --lc: var(--l1); } .verdict.lvl2 { --lc: var(--l2); } .verdict.lvl3 { --lc: var(--l3); }
.verdict.lvl3::before { animation: glow 1.6s ease-in-out infinite; }
@keyframes glow { 50% { opacity: .55; } }
.verdict > * { position: relative; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.eyebrow svg { width: 14px; height: 14px; }
.vlevel { font-size: clamp(38px, 5vw, 56px); font-weight: 800; letter-spacing: -.03em; line-height: 1.05; margin: 10px 0 20px; color: var(--lc); }
.verdict.lvlna .vlevel { color: var(--muted); }
.scale { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg i { display: block; height: 6px; border-radius: 3px; background: var(--surface-3); transition: background .3s, box-shadow .3s; }
.seg span { display: block; font-size: 11px; font-weight: 600; color: var(--muted); margin-top: 7px; letter-spacing: .02em; }
.seg.on i { background: var(--sc); }
.seg.cur i { box-shadow: 0 0 12px var(--sc); }
.seg.cur span { color: var(--text); }
.seg[data-l="0"] { --sc: var(--l0); } .seg[data-l="1"] { --sc: var(--l1); } .seg[data-l="2"] { --sc: var(--l2); } .seg[data-l="3"] { --sc: var(--l3); }
.vtext { font-size: 16px; font-weight: 500; margin: 22px 0 14px; line-height: 1.5; }
.drivers { list-style: none; margin: auto 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.drivers li { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; }
.drivers li.warn { color: var(--muted); }
.drivers .lv { width: 6px; align-self: stretch; border-radius: 3px; flex: none; }
.drivers:empty { display: none; }
.vmeta { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.drivers:not(:empty) + .vmeta { margin-top: 16px; }
.vmeta:empty { display: none; }
.vmeta div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.vmeta span { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.vmeta b { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- map ---------- */
.mapcard { position: relative; overflow: hidden; min-height: 400px; display: flex; flex-direction: column; }
#map { flex: 1; min-height: 360px; background: var(--surface-2); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; padding: 10px 14px; font-size: 12px; border-top: 1px solid var(--border); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.lg.l0 { background: var(--l0); } .lg.l1 { background: var(--l1); } .lg.l2 { background: var(--l2); } .lg.l3 { background: var(--l3); }
.map-off { display: grid; place-items: center; height: 100%; min-height: 360px; color: var(--muted); font-size: 13px; text-align: center; padding: 20px; }
.leaflet-container { font: inherit; background: var(--surface-2); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 10px 14px; font-size: 12.5px; }
.leaflet-popup-content b { display: block; margin-bottom: 2px; }
.leaflet-control-zoom a { background: var(--surface-2) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface-2) 80%, transparent) !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted) !important; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.kpi { padding: 14px 16px; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; background: var(--kc, var(--na)); }
.kpi .k-label { display: flex; align-items: center; gap: 7px; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi .k-label svg { width: 14px; height: 14px; }
.kpi .k-value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 6px 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .k-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- source cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 14px; }
.src { padding: 18px 18px 8px; display: flex; flex-direction: column; min-width: 0; }
.src-head { display: flex; align-items: center; gap: 12px; }
.src-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in srgb, var(--sc, var(--na)) 16%, transparent); color: var(--sc, var(--muted)); flex: none; }
.src-title { font-weight: 650; font-size: 14px; line-height: 1.3; }
.src-title a { text-decoration: none; }
.src-title a:hover { text-decoration: underline; }
.src-sub { font-size: 12px; color: var(--muted); }
.src-head .badge { margin-left: auto; }
.src.l0 { --sc: var(--l0); } .src.l1 { --sc: var(--l1); } .src.l2 { --sc: var(--l2); } .src.l3 { --sc: var(--l3); }
.src.l2, .src.l3 { border-color: color-mix(in srgb, var(--sc) 40%, transparent); }
.src-summary { font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.items { list-style: none; padding: 0; margin: 0 -18px; max-height: 360px; overflow: auto; }
.items li { padding: 11px 18px; border-top: 1px solid var(--border); display: grid; grid-template-columns: 4px 1fr; gap: 12px; }
.items li .bar { border-radius: 4px; background: var(--ic); }
.items li.l0 { --ic: var(--surface-3); } .items li.l1 { --ic: var(--l1); } .items li.l2 { --ic: var(--l2); } .items li.l3 { --ic: var(--l3); }
.items .t { font-weight: 600; font-size: 13.5px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.items .t a { text-decoration: none; }
.items .t a:hover { text-decoration: underline; }
.items .d { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.items details summary { cursor: pointer; color: var(--accent); font-size: 12px; margin-top: 6px; list-style: none; }
.items details summary::-webkit-details-marker { display: none; }
.items pre { white-space: pre-wrap; font: 12px/1.55 "JetBrains Mono", Consolas, monospace; background: var(--surface-2); border: 1px solid var(--border); padding: 10px 12px; border-radius: 8px; max-height: 260px; overflow: auto; margin: 8px 0 2px; }
.empty { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; padding: 6px 0 12px; }
.empty svg { width: 15px; height: 15px; color: var(--l0); }
.empty.err svg { color: var(--na); }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .07em; padding: 4px 9px; border-radius: 999px; white-space: nowrap; text-transform: uppercase; color: var(--bc); background: color-mix(in srgb, var(--bc) 14%, transparent); border: 1px solid color-mix(in srgb, var(--bc) 30%, transparent); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.l0 { --bc: var(--l0); } .badge.l1 { --bc: var(--l1); } .badge.l2 { --bc: var(--l2); } .badge.l3 { --bc: var(--l3); } .badge.na { --bc: var(--na); }
.action { font-size: 10px; font-weight: 800; letter-spacing: .08em; padding: 2px 7px; border-radius: 5px; background: var(--l3); color: #fff; }

/* ---------- checklist ---------- */
.checklist-card { padding: 22px 24px; margin-top: 28px; }
.progress-wrap { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.progress { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.progress div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--l0)); transition: width .3s; }
.checklist { list-style: none; padding: 0; margin: 0 0 8px; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 8px; }
.checklist label { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-size: 13px; transition: border-color .15s; }
.checklist label:hover { border-color: var(--border-strong); }
.checklist input { appearance: none; width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--border-strong); margin: 0; flex: none; display: grid; place-items: center; cursor: pointer; }
.checklist input:checked { background: var(--l0); border-color: var(--l0); }
.checklist input:checked::after { content: ""; width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.checklist input:checked + span { color: var(--muted); text-decoration: line-through; }

.foot { margin-top: 28px; font-size: 12.5px; color: var(--muted); }
.foot strong { color: var(--text); }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 1000; background: rgba(3, 6, 10, .55); backdrop-filter: blur(4px); display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 520px; padding: 22px; background: var(--surface-2); }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal p { margin: 6px 0 16px; font-size: 13px; }
.search { display: flex; align-items: center; gap: 8px; padding: 5px 5px 5px 12px; border-radius: 12px; border: 1px solid var(--border-strong); background: var(--surface-3); margin-bottom: 10px; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.search svg { color: var(--muted); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; padding: 6px 0; }
.results { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 6px; }
.results li { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); cursor: pointer; display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; }
.results li:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.results li .muted { font-size: 12px; }
#settings { justify-content: flex-end; align-items: stretch; padding: 0; }
.drawer { width: 100%; max-width: 380px; border-radius: 0; padding: 22px; background: var(--surface-2); display: flex; flex-direction: column; gap: 14px; animation: slide .2s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field select { padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface-3); color: var(--text); font-weight: 500; }
.toggle { display: flex; align-items: center; gap: 12px; cursor: pointer; font-size: 13.5px; }
.toggle input { display: none; }
.toggle i { width: 36px; height: 20px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border-strong); position: relative; flex: none; transition: background .2s; }
.toggle i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle input:checked + i { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + i::after { transform: translateX(16px); }

.toast { position: fixed; bottom: 22px; right: 22px; z-index: 1100; max-width: 400px; padding: 14px 16px 14px 18px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border-strong); border-left: 4px solid var(--tc, var(--l3)); box-shadow: 0 20px 40px rgba(0,0,0,.45); cursor: pointer; white-space: pre-line; font-size: 13px; animation: slide .2s; }
.toast b { display: block; font-size: 14px; margin-bottom: 4px; }

/* ---------- responsive ---------- */
@media (max-width: 1200px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 980px) { .hero { grid-template-columns: 1fr; } .verdict { min-height: 0; } .drivers { margin-top: 8px; } }
@media (max-width: 640px) {
  .topbar, .places, .wrap { padding-left: 16px; padding-right: 16px; }
  .brand-sub, .status-pill .sep, #countdown { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid, .checklist { grid-template-columns: 1fr; }
  .section-head.inner { flex-direction: column; align-items: stretch; }
}
