:root {
  --bg: #070b10;
  --panel: rgba(10, 16, 22, 0.88);
  --ink: #e7eef5;
  --muted: #7f93a8;
  --line: rgba(125, 160, 190, 0.18);
  --teal: #3dd6c6;
  --sky: #7ec8ff;
  --quake: #ff6b4a;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --font-display: "Syne", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: var(--font-mono);
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(61, 214, 198, 0.14), transparent 55%),
    radial-gradient(900px 500px at 90% 0%, rgba(126, 200, 255, 0.1), transparent 50%),
    linear-gradient(180deg, #0a1118 0%, #070b10 45%, #05080c 100%);
}

#app { position: relative; height: 100%; min-height: 100dvh; }

.top {
  position: absolute; inset: 0 0 auto 0; z-index: 4;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 18px;
  pointer-events: none;
}
.top > * { pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 {
  margin: 0; font-family: var(--font-display); font-weight: 800;
  letter-spacing: 0.04em; font-size: 22px; line-height: 1;
}
.tag { margin: 3px 0 0; color: var(--muted); font-size: 11px; letter-spacing: 0.02em; }

.mark {
  width: 34px; height: 34px; border-radius: 10px;
  background:
    radial-gradient(circle at 50% 50%, var(--quake) 0 3px, transparent 4px),
    conic-gradient(from 210deg, transparent 0 60%, rgba(61,214,198,.35) 0 100%),
    linear-gradient(145deg, #12202c, #0a121a);
  border: 1px solid rgba(61, 214, 198, 0.45);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04), 0 0 24px rgba(61,214,198,0.18);
  position: relative;
  animation: pulse-ring 3.2s ease-in-out infinite;
}
.mark::after {
  content: ""; position: absolute; inset: 7px;
  border: 1.5px solid rgba(126, 200, 255, 0.55); border-radius: 50%;
}

@keyframes pulse-ring {
  0%, 100% { box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04), 0 0 18px rgba(61,214,198,0.14); }
  50% { box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04), 0 0 28px rgba(61,214,198,0.32); }
}

.hud { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill, .stat {
  font-size: 11px; padding: 6px 10px; border-radius: 999px;
  background: rgba(8, 14, 20, 0.72); border: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.pill[data-state="ok"] { color: var(--ok); border-color: rgba(74, 222, 128, 0.35); }
.pill[data-state="degraded"] { color: var(--warn); border-color: rgba(251, 191, 36, 0.35); }
.pill[data-state="error"], .pill[data-state="starting"] { color: var(--err); border-color: rgba(248, 113, 113, 0.35); }
.stat { color: var(--muted); }

.panel {
  position: absolute; z-index: 3; top: 72px; left: 16px; bottom: 16px;
  width: min(320px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--line);
  box-shadow: var(--shadow); backdrop-filter: blur(16px);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
}
.panel-head h2, .panel-head.sub h2 {
  margin: 0; font-family: var(--font-display); font-size: 13px;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.panel-head.sub { margin-top: 4px; }
.panel-head .hint {
  font-size: 10px; color: var(--muted); max-width: 55%; text-align: right;
}
.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--sky);
  border-radius: 8px; width: 30px; height: 30px; cursor: pointer;
}
.ghost:hover { border-color: var(--teal); color: var(--teal); }

.layers { display: grid; gap: 6px; }
.layer {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px;
  border: 1px solid transparent; background: rgba(255,255,255,0.02);
  cursor: pointer; user-select: none;
}
.layer.active { border-color: color-mix(in srgb, var(--lc, var(--teal)) 45%, transparent); background: color-mix(in srgb, var(--lc, var(--teal)) 12%, transparent); }
.layer .swatch {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--lc, var(--teal)); box-shadow: 0 0 10px var(--lc, var(--teal));
}
.layer .name { flex: 1; font-size: 12px; }
.layer .count { color: var(--muted); font-size: 11px; }

.station-list {
  flex: 1; overflow: auto; display: grid; gap: 8px;
  padding-right: 2px; scrollbar-width: thin;
}
.station {
  padding: 10px 11px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(0,0,0,0.22);
  cursor: pointer; transition: border-color .15s, transform .15s;
  text-align: left; color: inherit; font: inherit; width: 100%;
}
.station:hover { border-color: color-mix(in srgb, var(--lc, var(--teal)) 55%, transparent); transform: translateY(-1px); }
.station .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.station .id { color: var(--lc, var(--teal)); font-weight: 600; font-size: 12px; }
.station .headline { color: var(--ink); font-size: 12px; }
.station .meta { margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.station.off { opacity: 0.55; }
.station .badge {
  font-size: 9px; padding: 2px 6px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
.station .badge.live { color: var(--teal); border-color: rgba(61,214,198,.35); }
.station .badge.sim { color: #e8b86d; border-color: rgba(232,184,109,.4); }

.panel-foot {
  display: flex; gap: 12px; padding-top: 8px; border-top: 1px solid var(--line);
}
.panel-foot a {
  color: var(--sky); text-decoration: none; font-size: 11px;
}
.panel-foot a:hover { color: var(--teal); }

.detail {
  position: absolute; z-index: 5; top: 72px; right: 16px; bottom: 16px;
  width: min(360px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--line);
  box-shadow: var(--shadow); backdrop-filter: blur(18px);
  overflow: auto;
  animation: detail-in .22s ease-out;
}
.detail[hidden] { display: none !important; }
@keyframes detail-in {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}
.detail-head {
  display: flex; gap: 12px; align-items: flex-start;
}
.detail-head h2 {
  margin: 0; font-family: var(--font-display); font-size: 18px; letter-spacing: 0.02em;
}
.detail-sub { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.detail-status {
  margin: 0; font-size: 11px; color: var(--teal);
  padding: 8px 10px; border-radius: 10px;
  background: rgba(61,214,198,0.08); border: 1px solid rgba(61,214,198,0.22);
}
.detail-summary {
  margin: 0; font-size: 12px; line-height: 1.55; color: var(--ink);
}
.detail-metrics { display: grid; gap: 8px; }
.metric {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px;
  padding: 10px 12px; border-radius: 12px;
  background: rgba(0,0,0,0.28); border: 1px solid var(--line);
}
.metric .label { font-size: 11px; color: var(--sky); }
.metric .value { font-size: 14px; font-weight: 600; text-align: right; }
.metric .hint { grid-column: 1 / -1; font-size: 10px; color: var(--muted); }
.detail-meta {
  margin-top: auto; font-size: 10px; color: var(--muted); line-height: 1.5;
  border-top: 1px solid var(--line); padding-top: 10px;
}
.detail.loading .detail-summary::after {
  content: " Loading live reading…";
  color: var(--muted);
}

#map {
  position: absolute; inset: 0;
  border-radius: 0;
}
.maplibregl-popup-content {
  background: #0d151d !important; color: var(--ink) !important;
  border: 1px solid var(--line); border-radius: 12px !important;
  box-shadow: var(--shadow); font-family: var(--font-mono); font-size: 11px;
  padding: 10px 12px !important;
}
.maplibregl-popup-tip { border-top-color: #0d151d !important; }
.maplibregl-ctrl-attrib { font-size: 9px; opacity: 0.7; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 12px; border-radius: 10px;
  background: rgba(61, 214, 198, 0.16); color: var(--teal);
  border: 1px solid rgba(61, 214, 198, 0.45);
  text-decoration: none; font-size: 11px; font-family: var(--font-mono);
  backdrop-filter: blur(10px); box-shadow: var(--shadow);
}
.btn:hover { background: rgba(61, 214, 198, 0.26); }

.toast {
  position: absolute; z-index: 6; left: 50%; bottom: 18px; transform: translateX(-50%);
  padding: 8px 14px; border-radius: 999px;
  background: rgba(8,14,20,0.9); border: 1px solid var(--line);
  color: var(--muted); font-size: 11px;
}

/* ── ATLAS Analyst ─────────────────────────────────────────────── */
.ai-root { position: fixed; z-index: 20; inset: 0; pointer-events: none; }
.ai-fab, .ai-panel { pointer-events: auto; }
.ai-fab {
  position: absolute; right: 18px; bottom: 18px;
  width: 52px; height: 52px; border-radius: 16px;
  border: 1px solid rgba(61,214,198,0.45);
  background: linear-gradient(145deg, rgba(61,214,198,0.22), rgba(10,18,26,0.92));
  color: var(--teal); font-family: var(--font-display); font-weight: 800;
  font-size: 14px; letter-spacing: 0.04em; cursor: pointer;
  box-shadow: var(--shadow);
}
.ai-fab:hover { filter: brightness(1.08); }
.ai-panel {
  position: absolute; right: 18px; bottom: 80px;
  width: min(400px, calc(100vw - 24px)); height: min(560px, calc(100dvh - 100px));
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--line);
  box-shadow: var(--shadow); backdrop-filter: blur(18px);
}
.ai-panel[hidden] { display: none !important; }
.ai-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.ai-head strong { font-family: var(--font-display); font-size: 15px; }
.ai-sub { color: var(--muted); font-size: 10px; margin-top: 2px; }
.ai-meta { display: flex; gap: 6px; }
.ai-meta select {
  flex: 1; background: rgba(0,0,0,0.35); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
  font-family: var(--font-mono); font-size: 11px;
}
.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-chip {
  border: 1px solid var(--line); background: rgba(126,200,255,0.08);
  color: var(--sky); border-radius: 999px; padding: 4px 10px;
  font-size: 10px; cursor: pointer; font-family: var(--font-mono);
}
.ai-chip:hover { border-color: var(--teal); color: var(--teal); }
.ai-messages {
  flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 8px;
  padding: 4px 2px; scrollbar-width: thin;
}
.ai-msg {
  padding: 10px 12px; border-radius: 12px; font-size: 12px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.ai-user {
  align-self: flex-end; max-width: 92%;
  background: rgba(61,214,198,0.14); border: 1px solid rgba(61,214,198,0.3);
  color: var(--ink);
}
.ai-assistant {
  align-self: stretch;
  background: rgba(0,0,0,0.28); border: 1px solid var(--line);
  color: var(--ink);
}
.ai-pending { color: var(--muted); font-style: italic; }
.ai-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.ai-input {
  resize: none; width: 100%;
  background: rgba(0,0,0,0.35); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  font-family: var(--font-mono); font-size: 12px;
}
.ai-send {
  border: 1px solid rgba(61,214,198,0.45); background: rgba(61,214,198,0.18);
  color: var(--teal); border-radius: 10px; padding: 10px 14px;
  font-family: var(--font-mono); font-size: 12px; cursor: pointer; height: 42px;
}
.ai-send:hover { background: rgba(61,214,198,0.28); }

@media (max-width: 820px) {
  .panel {
    top: auto; left: 10px; right: 10px; bottom: 10px; width: auto; height: 34%;
  }
  .detail {
    top: auto; left: 10px; right: 10px; bottom: calc(34% + 18px); height: 42%;
    width: auto;
  }
  .top { padding: 10px 12px; }
  .brand h1 { font-size: 18px; }
  .ai-panel { right: 10px; left: 10px; width: auto; bottom: 72px; height: min(50dvh, 480px); }
  .ai-fab { right: 12px; bottom: 12px; }
}
