:root {
  --bg: #0b0f14;
  --panel: #121921;
  --panel2: #0e141b;
  --border: #1f2a36;
  --text: #e6edf3;
  --muted: #8596a6;
  --accent: #2dd4bf;
  --accent2: #38bdf8;
  --danger: #f87171;
  --shadow: 0 12px 36px rgba(0,0,0,.5);
  --radius: 12px;
}

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

html, body { height: 100%; }
body {
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); overflow: hidden;
}

/* ---------- top bar ---------- */
header#topbar {
  position: relative; z-index: 1200;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 16px;
  background: linear-gradient(180deg, #10161d, #0d1218);
  border-bottom: 1px solid var(--border);
  height: 58px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 230px; }
.logo { font-size: 24px; filter: drop-shadow(0 0 8px rgba(45,212,191,.5)); }
.title h1 { font-size: 17px; letter-spacing: .3px; }
.title p { font-size: 11px; color: var(--muted); margin-top: -2px; }

.stats { display: flex; gap: 22px; }
.stat { display: flex; flex-direction: column; line-height: 1.15; }
.stat b { font-size: 17px; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat span { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }

.search { position: relative; margin-left: auto; width: 300px; }
.search input {
  width: 100%; padding: 8px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  font-size: 13px; outline: none; transition: border .15s;
}
.search input:focus { border-color: var(--accent); }
.results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 1300;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  max-height: 320px; overflow-y: auto; box-shadow: var(--shadow);
}
.results .res {
  padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.results .res:last-child { border-bottom: none; }
.results .res:hover { background: var(--panel2); }
.results .res b { display: block; font-size: 12.5px; }
.results .res span { font-size: 11px; color: var(--muted); word-break: break-all; }

/* ---------- layout ---------- */
main { position: relative; height: calc(100% - 58px - 24px); }
#map { position: absolute; inset: 0; background: var(--bg); z-index: 1; }

/* leaflet dark theming */
.leaflet-container { background: #0b0f14; }
.leaflet-control-attribution { background: rgba(11,15,20,.7) !important; color: #5a6a7a; font-size: 9.5px; }
.leaflet-control-attribution a { color: #7d8ea0 !important; }
.leaflet-bar a { background: var(--panel); color: var(--text); border-color: var(--border); }
.leaflet-bar a:hover { background: var(--panel2); }

/* markers */
.wcm { display: flex; align-items: center; justify-content: center; }
.wcm::before {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4ade80, #059669 70%);
  box-shadow: 0 0 0 3px rgba(5,150,105,.25), 0 2px 8px rgba(0,0,0,.6);
  transition: transform .12s;
}
.wcm:hover::before { transform: scale(1.25); }

.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div {
  background: rgba(14,116,144,.25);
  border: 1.5px solid var(--accent2);
  color: #cdeffd !important;
  box-shadow: 0 2px 10px rgba(0,0,0,.5);
}

/* popup */
.leaflet-popup-content-wrapper {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--panel); border: 1px solid var(--border); }
.leaflet-popup-content { margin: 10px 12px; font-size: 12.5px; }
.leaflet-popup-content b { display: block; font-size: 13.5px; margin-bottom: 2px; }
.leaflet-popup-content .who { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.leaflet-popup-content button, .panel-actions button, .ghost {
  background: var(--accent); color: #05201b; border: none; border-radius: 8px;
  padding: 6px 13px; font-size: 12px; font-weight: 600; cursor: pointer; transition: filter .15s;
}
.leaflet-popup-content button:hover, .panel-actions button:hover { filter: brightness(1.1); }
.ghost { background: transparent; color: var(--accent2); border: 1px solid #234a63; font-weight: 500; padding: 4px 10px; }

/* ---------- detail panel ---------- */
#panel {
  position: absolute; top: 14px; right: 14px; bottom: 14px; z-index: 1100;
  width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
  animation: slideIn .18s ease-out;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } }
#panel.hidden { display: none; }
#panelClose {
  position: absolute; top: 10px; right: 10px; z-index: 5;
  background: rgba(255,255,255,.06); border: none; color: var(--text);
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 13px;
}
#panelClose:hover { background: rgba(255,255,255,.14); }
#panelBody { padding: 18px; overflow-y: auto; }

.cam-title { font-size: 16px; font-weight: 700; padding-right: 26px; }
.cam-meta { margin: 4px 0 12px; font-size: 12px; color: var(--muted); }
.cam-meta .tag {
  display: inline-block; background: rgba(56,189,248,.12); color: var(--accent2);
  border: 1px solid #234a63; border-radius: 20px; padding: 1px 9px; margin: 2px 4px 2px 0;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px;
}

.livebox {
  position: relative; background: #000; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border); margin-bottom: 12px;
}
.livebox img, .livebox video, .livebox iframe { width: 100%; display: block; min-height: 170px; background: #000; border: 0; }
.livebox .ph {
  display: flex; align-items: center; justify-content: center; height: 190px;
  color: var(--muted); background: repeating-linear-gradient(45deg,#0c1118,#0c1118 12px,#0e141b 12px,#0e141b 24px);
  flex-direction: column; gap: 8px; font-size: 12.5px;
}
.livebox .ph .big { font-size: 30px; }
.liveflag {
  position: absolute; top: 10px; left: 10px; z-index: 2;
  background: rgba(5,150,105,.9); color: #06251c; border-radius: 20px;
  padding: 2px 10px; font-size: 10.5px; font-weight: 700; letter-spacing: .5px;
  display: flex; align-items: center; gap: 5px;
}
.liveflag .dot { width: 7px; height: 7px; border-radius: 50%; background: #a7f3d0; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.liveflag.stale { background: rgba(234,88,12,.85); color: #fff; }

.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-actions a { text-decoration: none; }
.panel-actions .ghost-link {
  background: transparent; color: var(--accent2); border: 1px solid #234a63; border-radius: 8px;
  padding: 6px 13px; font-size: 12px; cursor: pointer; display: inline-block; text-decoration: none;
}
.panel-actions .ghost-link:hover { background: rgba(56,189,248,.08); }

.details { font-size: 12px; color: var(--muted); }
.details table { width: 100%; border-collapse: collapse; }
.details td { padding: 5px 0; border-bottom: 1px solid rgba(31,42,54,.6); vertical-align: top; }
.details td:first-child { width: 92px; color: var(--text); font-weight: 600; }
.details code { color: var(--accent2); word-break: break-all; font-size: 11px; }

/* ---------- list card ---------- */
#listcard {
  position: absolute; left: 14px; bottom: 14px; z-index: 1100;
  width: 300px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); overflow: hidden;
}
.listhead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 12.5px;
}
#listBody { max-height: 0; overflow-y: auto; transition: max-height .2s; }
#listcard.expanded #listBody { max-height: 300px; }
.listitem {
  display: flex; gap: 10px; align-items: center; padding: 8px 12px; cursor: pointer;
  border-bottom: 1px solid rgba(31,42,54,.5);
}
.listitem:last-child { border-bottom: none; }
.listitem:hover { background: var(--panel2); }
.listitem .thumb {
  width: 44px; height: 32px; border-radius: 6px; object-fit: cover; background: #0a0f14; flex-shrink: 0;
}
.listitem .li-name { font-size: 12px; font-weight: 600; line-height: 1.25; }
.listitem .li-sub { font-size: 10.5px; color: var(--muted); }

/* ---------- footer, toast ---------- */
#credit {
  position: relative; z-index: 1200; height: 24px; display: flex; align-items: center;
  padding: 0 14px; font-size: 10.5px; color: #51616f; background: #0c1117;
  border-top: 1px solid var(--border);
}
#credit a { color: #7d8fa0; }

#toast {
  position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); z-index: 2000;
  background: #1c2835; border: 1px solid var(--border); color: var(--text);
  padding: 9px 18px; border-radius: 10px; font-size: 12.5px; box-shadow: var(--shadow);
}
#toast.hidden { display: none; }

.hidden { display: none !important; }

/* responsive */
@media (max-width: 760px) {
  header#topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; }
  .stats { gap: 14px; }
  .search { width: 100%; order: 5; margin-left: 0; }
  main { height: calc(100vh - 150px - 24px); }
  #panel { width: calc(100% - 28px); }
  #listcard { width: calc(100% - 28px); }
}