:root {
  --bg-0: #060912;
  --bg-1: #0a0e1a;
  --bg-2: #0f1729;
  --bg-3: #162136;
  --line: #1f2d4a;
  --text: #e6edf7;
  --muted: #7f8ea8;
  --cyan: #22d3ee;
  --cyan-soft: rgba(34, 211, 238, 0.16);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.16);
  --green: #34d399;
  --red: #f87171;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --radius: 10px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(34, 211, 238, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(251, 191, 36, 0.06), transparent 60%),
    var(--bg-0);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); background: var(--bg-2); padding: 1px 6px; border-radius: 4px; }

/* TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  font-family: var(--mono);
  font-size: 22px;
  color: var(--cyan);
  letter-spacing: -2px;
}
.brand h1 {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.5px;
}
.brand .accent { color: var(--cyan); font-weight: 500; }
.subtitle { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.status-cluster { display: flex; align-items: center; gap: 12px; }
.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 0 rgba(0,0,0,0);
}
.status-dot[data-state="live"] { background: var(--green); animation: pulse 2s infinite; }
.status-dot[data-state="stale"] { background: var(--amber); }
.status-dot[data-state="error"] { background: var(--red); }
.status-dot[data-state="loading"] { background: var(--cyan); animation: pulse 1.2s infinite; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6); }
  70% { box-shadow: 0 0 0 12px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

.status-text { display: flex; flex-direction: column; line-height: 1.2; font-family: var(--mono); font-size: 12px; }
.status-text .muted { font-size: 11px; }
.muted { color: var(--muted); }
.center { text-align: center; }

.btn-refresh {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-3);
  color: var(--cyan);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-refresh:hover { border-color: var(--cyan); background: var(--cyan-soft); }
.btn-refresh:disabled { opacity: 0.4; cursor: wait; }

/* KPI STRIP */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  padding: 18px 28px;
}
.kpi {
  background: linear-gradient(160deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--cyan);
  opacity: 0.6;
}
.kpi.highlight::before { background: var(--amber); }
.kpi-label {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
}
.kpi-value {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  transition: color 0.4s ease;
}
.kpi.highlight .kpi-value { color: var(--amber); }
.kpi:not(.highlight) .kpi-value { color: var(--cyan); }
.kpi-value.flash { animation: flash 0.6s ease; }
@keyframes flash {
  0% { background: var(--cyan-soft); }
  100% { background: transparent; }
}
.kpi-sub { font-size: 11px; color: var(--muted); font-family: var(--mono); }

/* DASHBOARD GRID */
.dashboard {
  display: grid;
  grid-template-columns: 2fr 1fr;
  grid-template-rows: minmax(420px, 56vh) auto;
  gap: 14px;
  padding: 0 28px 24px;
}
.map-card { grid-row: 1 / span 2; }
.chart-card { min-height: 280px; }
.table-card { grid-column: 1 / -1; }

.card {
  background: linear-gradient(160deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.card-head h2 {
  font-family: var(--mono);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin: 0;
  color: var(--text);
}
.card-head .muted { font-size: 11px; font-family: var(--mono); }

/* MAP */
#map {
  flex: 1;
  min-height: 420px;
  background: var(--bg-0);
}
.legend {
  display: flex;
  gap: 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}
.legend .dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.dot-low { background: var(--green); }
.dot-mid { background: var(--cyan); }
.dot-high { background: var(--amber); }

/* Leaflet overrides */
.leaflet-container {
  background: #050813;
  font-family: var(--sans);
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.leaflet-popup-content {
  margin: 10px 14px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
}
.leaflet-popup-content strong { color: var(--cyan); }
.leaflet-control-attribution {
  background: rgba(10, 14, 26, 0.7) !important;
  color: var(--muted) !important;
}
.leaflet-control-attribution a { color: var(--cyan) !important; }
.leaflet-control-zoom a {
  background: var(--bg-2) !important;
  color: var(--cyan) !important;
  border-color: var(--line) !important;
}

.plane-icon { transition: transform 0.2s linear; }
.plane-icon svg { display: block; filter: drop-shadow(0 0 3px rgba(34, 211, 238, 0.6)); }
.plane-low svg { color: var(--green); }
.plane-mid svg { color: var(--cyan); }
.plane-high svg { color: var(--amber); }

.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background: rgba(34, 211, 238, 0.18) !important;
}
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background: rgba(34, 211, 238, 0.55) !important;
  color: #06121a !important;
  font-family: var(--mono);
  font-weight: 700;
}

/* CHARTS */
.chart-wrap {
  flex: 1;
  padding: 12px 14px 16px;
  min-height: 220px;
  position: relative;
}
.chart-wrap.donut { display: flex; align-items: center; justify-content: center; }

/* TABLE */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12.5px; }
thead th {
  text-align: left;
  padding: 10px 14px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  font-size: 10.5px;
}
thead th.num, tbody td.num { text-align: right; }
tbody td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
}
tbody tr:hover { background: var(--cyan-soft); }
tbody td:first-child { color: var(--cyan); font-weight: 600; }

/* FOOTER */
.footer {
  padding: 16px 28px 28px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  text-align: center;
}

/* RESPONSIVE */
@media (max-width: 1024px) {
  .kpi-strip { grid-template-columns: repeat(3, 1fr); }
  .dashboard {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  .map-card { grid-row: auto; }
  #map { min-height: 380px; }
}
@media (max-width: 768px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px 16px; }
  .kpi-strip { grid-template-columns: repeat(2, 1fr); padding: 14px 16px; gap: 8px; }
  .kpi-value { font-size: 22px; }
  .dashboard { padding: 0 16px 20px; gap: 10px; }
  .card-head h2 { font-size: 12px; }
  .legend { display: none; }
}

/* SKELETON */
.skeleton { background: linear-gradient(90deg, var(--bg-2) 0%, var(--bg-3) 50%, var(--bg-2) 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 4px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
