:root {
  color-scheme: dark;
  --bg: #0d0f15;
  --surface: #161924;
  --surface-2: #1f2433;
  --surface-3: #2a3043;
  --border: #2c3144;
  --text: #ecedf2;
  --text-dim: #98a0b3;
  --accent: #2a8df0;
  --accent-2: #36b37e;
  --warn: #efa133;
  --danger: #ff5d73;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

body { display: flex; flex-direction: column; min-height: 100vh; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* -------------------- Nav -------------------- */
.sw-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: relative; z-index: 1500;
  box-shadow: var(--shadow);
}
.sw-brand { display: flex; align-items: center; gap: 10px; color: inherit; }
.sw-brand:hover { text-decoration: none; }
.sw-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #0d4587);
  font-size: 18px; color: #fff;
}
.sw-brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.sw-brand-text strong { font-size: 16px; letter-spacing: 0.4px; }
.sw-brand-text small { color: var(--text-dim); font-size: 11px; }
.sw-nav-links { display: flex; gap: 16px; font-size: 13px; }
.sw-nav-links a { color: var(--text-dim); }
.sw-nav-links a:hover { color: var(--text); }

/* -------------------- App layout -------------------- */
.sw-app {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  min-height: 0;
}
.sw-map-area { position: relative; min-height: 480px; }
.sw-map { position: absolute; inset: 0; background: #0a0c14; }
.sw-side {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0;
}

@media (max-width: 960px) {
  .sw-app { grid-template-columns: 1fr; grid-template-rows: 55vh 1fr; }
  .sw-side { border-left: 0; border-top: 1px solid var(--border); }
}

/* -------------------- Overlay -------------------- */
.sw-map-overlay {
  position: absolute; top: 14px; left: 14px;
  display: flex; flex-direction: column; gap: 8px; z-index: 800;
}
.sw-status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; background: rgba(15,18,28,0.85);
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 12px; backdrop-filter: blur(8px);
}
.sw-pill-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--text-dim);
}
.sw-pill-dot.ok { background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); }
.sw-pill-dot.warn { background: var(--warn); }
.sw-pill-dot.err { background: var(--danger); }
.sw-stats-row {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.sw-stat {
  background: rgba(15,18,28,0.85);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.sw-stat strong { color: var(--text); margin-right: 4px; }

/* -------------------- Alerts stack -------------------- */
.sw-alert-stack {
  position: absolute; top: 14px; right: 14px; z-index: 1100;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 320px;
}
.sw-toast {
  background: rgba(20, 24, 34, 0.95);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  font-size: 12px;
  animation: sw-pop 220ms ease;
}
.sw-toast.warn { border-left-color: var(--warn); }
.sw-toast.danger { border-left-color: var(--danger); }
.sw-toast strong { display: block; font-size: 13px; margin-bottom: 4px; }
.sw-toast small { color: var(--text-dim); }
.sw-toast button {
  margin-top: 6px; font-size: 11px; color: var(--text-dim); background: none;
  border: 0; cursor: pointer;
}

@keyframes sw-pop { from { transform: translateY(-6px); opacity: 0; } to { opacity: 1; } }

/* -------------------- Tabs / panels -------------------- */
.sw-tabs {
  display: flex; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  overflow-x: auto;
}
.sw-tab {
  background: transparent; border: 0; padding: 12px 16px; color: var(--text-dim);
  font-size: 13px; cursor: pointer; border-bottom: 2px solid transparent;
  flex-shrink: 0;
}
.sw-tab:hover { color: var(--text); }
.sw-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.sw-panel { display: none; padding: 14px; overflow-y: auto; flex: 1; min-height: 0; }
.sw-panel.active { display: flex; flex-direction: column; gap: 10px; }
.sw-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.sw-panel-head h2 { font-size: 15px; margin: 0; }
.sw-panel-actions { display: flex; gap: 6px; }

.sw-hint {
  color: var(--text-dim); font-size: 12px; margin: 0;
}
.sw-limit-note { font-style: italic; }
.sw-subhead { margin: 10px 0 4px; font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.8px; }

/* -------------------- Forms -------------------- */
.sw-form { display: flex; flex-direction: column; gap: 8px; }
.sw-form-row { display: flex; gap: 8px; align-items: flex-end; }
.sw-form-row .grow { flex: 1; }
label { display: flex; flex-direction: column; font-size: 12px; color: var(--text-dim); gap: 3px; }
input, select, textarea {
  font-family: inherit; font-size: 13px; padding: 7px 9px;
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }

/* -------------------- Buttons -------------------- */
.sw-btn {
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  padding: 7px 12px; border-radius: 6px; cursor: pointer; font-size: 12px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.sw-btn:hover { background: var(--surface-2); border-color: var(--accent); }
.sw-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.sw-btn.primary:hover { background: #1c79d6; border-color: #1c79d6; }
.sw-btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.sw-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.sw-icon-btn {
  background: transparent; border: 0; color: var(--text-dim); cursor: pointer;
  width: 28px; height: 28px; border-radius: 4px; font-size: 14px;
}
.sw-icon-btn:hover { background: var(--surface-3); color: var(--text); }
.sw-icon-btn.danger:hover { color: var(--danger); }

/* -------------------- Lists -------------------- */
.sw-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.sw-list-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--surface-2); border-radius: 6px; border: 1px solid var(--border);
}
.sw-list-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.sw-list-text strong { font-size: 13px; }
.sw-list-text small { color: var(--text-dim); font-size: 11px; }
.sw-list-actions { display: flex; gap: 2px; }
.sw-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.watch-kind {
  font-size: 10px; padding: 2px 6px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-dim); text-transform: uppercase;
}

.sw-list.rank { counter-reset: rank; }
.sw-list.rank li { counter-increment: rank; }
.sw-list.rank li::before { content: counter(rank) ". "; color: var(--text-dim); margin-right: 6px; }

/* -------------------- Aircraft table -------------------- */
.sw-table-wrap { overflow: auto; max-height: 60vh; border: 1px solid var(--border); border-radius: 6px; }
.sw-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.sw-table th, .sw-table td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); }
.sw-table th {
  position: sticky; top: 0; background: var(--surface-2); color: var(--text-dim);
  cursor: pointer; user-select: none; font-weight: 600;
}
.sw-table tbody tr:hover { background: var(--surface-2); }
.sw-table tbody tr.selected { background: rgba(42,141,240,0.2); }

/* -------------------- Stats -------------------- */
.sw-stats-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.sw-stat-card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px; display: flex; flex-direction: column; gap: 4px;
}
.sw-stat-card span { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; }
.sw-stat-card strong { font-size: 20px; }
.sw-bars {
  display: flex; align-items: flex-end; gap: 3px; height: 110px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px; overflow-x: auto;
}
.sw-bar {
  flex: 0 0 18px; background: var(--accent); border-radius: 2px;
  min-height: 4px; position: relative;
}
.sw-bar:hover::after {
  content: attr(data-tip);
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--surface-3); padding: 3px 6px; font-size: 11px; border-radius: 4px;
  white-space: nowrap;
}

/* -------------------- Playback -------------------- */
.sw-playback-controls {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px;
}
.sw-slider { width: 100%; margin-top: 6px; }

/* -------------------- Switch -------------------- */
.sw-switch {
  display: inline-flex; flex-direction: row; align-items: center; gap: 6px;
  color: var(--text-dim); font-size: 12px;
}
.sw-switch input { width: 14px; height: 14px; }

/* -------------------- Dialog -------------------- */
.sw-dialog {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px; width: min(420px, 90vw); box-shadow: var(--shadow);
}
.sw-dialog::backdrop { background: rgba(8, 9, 13, 0.7); backdrop-filter: blur(2px); }
.sw-dialog h3 { margin-top: 0; }
.sw-dialog form { display: flex; flex-direction: column; gap: 10px; }
.sw-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 6px 0 0; }

/* -------------------- Doc pages -------------------- */
.sw-doc { flex: 1; display: flex; justify-content: center; padding: 28px 18px; background: var(--bg); }
.sw-doc article { max-width: 760px; width: 100%; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 28px; }
.sw-doc h1 { margin-top: 0; font-size: 26px; }
.sw-doc h2 { margin-top: 24px; font-size: 18px; }
.sw-doc .sw-lead { color: var(--text-dim); font-size: 15px; }

/* -------------------- Leaflet override -------------------- */
.leaflet-container { background: #0a0c14; }
.leaflet-control-attribution {
  background: rgba(15,18,28,0.7) !important;
  color: var(--text-dim) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--text) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--surface) !important; color: var(--text) !important;
  border: 1px solid var(--border) !important;
}
.leaflet-popup-content { font-size: 12px; line-height: 1.4; }
.leaflet-popup-content b { color: var(--accent); }

.sw-aircraft-marker {
  font-size: 18px; color: var(--accent); font-weight: bold;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6); transform-origin: center;
}
.sw-aircraft-marker.matched { color: var(--danger); }
.sw-aircraft-marker.inside { color: var(--warn); }
