html, body { margin: 0; padding: 0; height: 100%;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #e5e7eb;
  background: #0f172a;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
#map { position: absolute; top: 0; left: 0; right: 320px; bottom: 0; }

/* ---------- sidebar (desktop default) ---------- */
#sidebar {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 320px;
  background: #1e293b;
  display: flex; flex-direction: column;
  border-left: 1px solid #334155;
  box-shadow: -2px 0 8px rgba(0,0,0,0.4);
  z-index: 1000;
  transition: transform 0.25s ease;
}
#sidebar header {
  padding: 10px 12px;
  border-bottom: 1px solid #334155;
  background: #0f172a;
}
#sidebar h1 {
  margin: 0; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
#sidebar .badge {
  background: #334155;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  color: #cbd5e1;
  font-variant-numeric: tabular-nums;
}
#sidebar h1 #sidebar-close {
  margin-left: auto;
  background: none; color: #94a3b8; border: none;
  font-size: 24px; line-height: 1; cursor: pointer; padding: 0 4px;
  display: none;  /* hidden on desktop */
}
#sidebar h1 #sidebar-close:hover { color: #e5e7eb; }
#sidebar .controls {
  margin-top: 8px;
  display: flex; gap: 12px; align-items: center;
  font-size: 12px; color: #94a3b8;
}
#sidebar .controls label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
#sidebar .controls input { margin: 0; transform: scale(1.05); }
#sidebar .controls button {
  background: #334155; color: #e5e7eb; border: none;
  padding: 4px 12px; border-radius: 4px;
  font-size: 12px; cursor: pointer;
  min-height: 28px;
}
#sidebar .controls button:hover { background: #475569; }
#sidebar .sort {
  margin-top: 8px;
  font-size: 12px; color: #94a3b8;
  display: flex; align-items: center; gap: 6px;
}
#sidebar .sort select {
  background: #334155; color: #e5e7eb; border: none;
  padding: 4px 8px; border-radius: 3px; font-size: 12px;
  min-height: 28px;
}

#aircraft-list {
  list-style: none; margin: 0; padding: 0;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
#aircraft-list li {
  padding: 10px 12px;
  border-bottom: 1px solid #273345;
  cursor: pointer;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 6px;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  transition: background 0.1s;
}
#aircraft-list li:hover { background: #273345; }
#aircraft-list li:active { background: #1e3a8a; }
#aircraft-list li.pinned { background: #1e3a8a; }
#aircraft-list li.no-pos { opacity: 0.55; }
#aircraft-list li.stale { opacity: 0.55; }
#aircraft-list li .cs {
  font-weight: 600; color: #93c5fd;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
#aircraft-list li .icao {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px; color: #94a3b8;
}
#aircraft-list li .alt {
  text-align: right; color: #cbd5e1;
}
#aircraft-list li .meta {
  grid-column: 1 / 3;
  font-size: 11px; color: #94a3b8;
  display: flex; gap: 8px; flex-wrap: wrap;
}

/* ---------- sidebar toggle (mobile only) ---------- */
#sidebar-toggle {
  position: absolute;
  top: env(safe-area-inset-top, 8px); /* notch-aware */
  right: 8px;
  z-index: 1001;
  background: rgba(15, 23, 42, 0.92);
  color: #e5e7eb;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 8px 10px;
  display: none;  /* shown only at mobile breakpoint */
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 500;
  min-height: 40px;
  min-width: 40px;
  -webkit-tap-highlight-color: transparent;
}
#sidebar-toggle .badge {
  background: #334155;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
}
#sidebar-toggle:active { background: #1e293b; }

/* ---------- status bar ---------- */
#status {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 8px) + 8px);
  left: 8px; z-index: 1000;
  background: rgba(15, 23, 42, 0.92);
  color: #e5e7eb;
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 4px;
  display: flex; align-items: center; gap: 6px;
  font-variant-numeric: tabular-nums;
  border: 1px solid #334155;
  max-width: calc(100% - 16px);
}
#status .sep { opacity: 0.5; }
#status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
}
#status .dot.live    { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
#status .dot.dim     { background: #888; }
#status .dot.error   { background: #ef4444; }

/* ---------- markers ---------- */
.receiver-icon {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #2563eb;
  border: 2px solid #fff;
  box-shadow: 0 0 6px rgba(37, 99, 235, 0.8);
}
.aircraft-icon {
  width: 18px; height: 18px;
  position: relative;
}
.aircraft-icon::before {
  content: '';
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 14px solid #fbbf24;
  filter: drop-shadow(0 0 2px rgba(0,0,0,0.6));
}
.aircraft-icon.no-track::before { border-bottom-color: #94a3b8; }
.aircraft-icon.stale::before    { opacity: 0.45; }
.aircraft-icon.pinned::before   { border-bottom-color: #60a5fa; }
.aircraft-track { stroke-opacity: 0.45; }
/* (.range-ring is now drawn as a MapLibre line layer; the old .range-ring
   class no longer applies. Keep the rule in case any debug overlay reuses it.)
*/
.range-ring { stroke: #475569; stroke-width: 1; fill: none; stroke-dasharray: 4 4; pointer-events: none; }

/* ---------- density-heatmap status indicator (in sidebar header) ---------- */
.heatmap-status {
  font-size: 11px;
  color: #94a3b8;
  margin: 4px 0 0 2px;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}
.heatmap-status.hide { display: none; }
.heatmap-status.loading { color: #fbbf24; }
.heatmap-status.error { color: #ef4444; }

/* ---------- MapLibre popup theme ---------- */
.maplibregl-popup-content {
  background: #1e293b !important;
  color: #e5e7eb;
  border-radius: 6px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  padding: 8px 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.maplibregl-popup-tip { border-top-color: #1e293b !important; border-bottom-color: #1e293b !important; }
.maplibregl-popup-content .icao {
  font-weight: 600; font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.maplibregl-popup-content .callsign { font-weight: 600; color: #93c5fd; }
.maplibregl-popup-content .row { display: flex; justify-content: space-between; gap: 12px; }
.maplibregl-popup-content .label { color: #94a3b8; }

/* ---------- MapLibre controls (dark) ---------- */
.maplibregl-ctrl-group {
  background: #334155 !important;
  border: 1px solid #475569 !important;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.maplibregl-ctrl-group button {
  background-color: transparent !important;
}
.maplibregl-ctrl-group button:hover {
  background-color: #475569 !important;
}
.maplibregl-ctrl-group button + button {
  border-top: 1px solid #475569 !important;
}
.maplibregl-ctrl-zoom-in .maplibregl-ctrl-icon,
.maplibregl-ctrl-zoom-out .maplibregl-ctrl-icon,
.maplibregl-ctrl-compass .maplibregl-ctrl-icon {
  filter: invert(0.9);
}
.maplibregl-ctrl-attrib {
  background: rgba(15, 23, 42, 0.8) !important;
  color: #94a3b8 !important;
}
.maplibregl-ctrl-attrib a { color: #cbd5e1 !important; }
.maplibregl-ctrl-scale {
  background: rgba(15, 23, 42, 0.75) !important;
  border: 1px solid #475569 !important;
  border-top: none !important;
  color: #cbd5e1 !important;
}

/* ---------- log pane (collapsible bottom drawer) ---------- */
#log-pane {
  position: absolute;
  left: 0; right: 0;
  bottom: env(safe-area-inset-bottom, 0);
  background: rgba(15, 23, 42, 0.96);
  color: #e5e7eb;
  border-top: 1px solid #334155;
  z-index: 1100;  /* above status bar (1000) */
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  height: 30px;
  transition: height 0.2s ease;
  box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.4);
}
#log-pane.expanded { height: 45vh; }
@media (min-width: 769px) { #log-pane.expanded { height: 320px; } }

#log-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  height: 30px;
  flex-shrink: 0;
  background: #0f172a;
  border-bottom: 1px solid #334155;
  font-variant-numeric: tabular-nums;
}
#log-pane.collapsed #log-header { border-bottom: none; }
#log-header .log-latest {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #cbd5e1;
}
#log-header .badge {
  background: #334155;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  color: #cbd5e1;
}
#log-header button {
  background: #334155;
  color: #e5e7eb;
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  min-height: 24px;
  font-family: inherit;
}
#log-header button:active { background: #1e293b; }

#log-list {
  list-style: none;
  margin: 0;
  padding: 4px 8px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
#log-pane.collapsed #log-list { display: none; }
#log-list li {
  padding: 2px 0;
  border-bottom: 1px solid #1e293b;
  word-wrap: break-word;
  word-break: break-word;
  line-height: 1.45;
}
#log-list li .ts { color: #64748b; margin-right: 6px; }
#log-list li .lvl {
  display: inline-block;
  min-width: 38px;
  margin-right: 4px;
  text-transform: uppercase;
  font-size: 10px;
  opacity: 0.8;
}
#log-list li .lvl.info  { color: #94a3b8; }
#log-list li .lvl.warn  { color: #fbbf24; }
#log-list li .lvl.error { color: #ef4444; }
#log-list li .lvl.debug { color: #64748b; }
#log-list li .lvl.recv  { color: #60a5fa; }   /* inbound WS frames */
#log-list li .lvl.send  { color: #a78bfa; }   /* outbound WS frames */

/* Status bar lifts above the log pane when collapsed */
#status { bottom: calc(env(safe-area-inset-bottom, 8px) + 38px); }

/* ---------- mobile breakpoint ---------- */
@media (max-width: 768px) {
  #map { right: 0; }  /* full-width map */
  #sidebar {
    /* Slide-in drawer from the right; default off-screen */
    width: min(360px, 88vw);
    transform: translateX(100%);
    box-shadow: -4px 0 16px rgba(0,0,0,0.5);
    padding-top: env(safe-area-inset-top, 0);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar h1 #sidebar-close { display: inline-block; }
  #sidebar-toggle { display: flex; }
  #status { font-size: 10px; padding: 5px 8px; }
  .hide-narrow { display: none; }

  /* slightly bigger touch targets in the list */
  #aircraft-list li { padding: 12px 14px; font-size: 13px; }
  #aircraft-list li .meta { font-size: 12px; }

  /* fewer hover effects on touch */
  #aircraft-list li:hover { background: transparent; }
  #aircraft-list li.pinned { background: #1e3a8a; }

  .maplibregl-ctrl-top-right { margin-top: 56px !important; }  /* clear of toggle button */
}

@media (max-width: 380px) {
  /* squish the controls onto one line on small phones */
  #sidebar .controls { gap: 8px; font-size: 11px; }
  #sidebar .controls button { padding: 4px 8px; }
}
