/* MyRadar — dark operations-console aesthetic */
:root {
  --bg: #0a1118;
  --bg-raised: #0f1922;
  --bg-panel: rgba(13, 22, 31, 0.94);
  --line: #1d2f3f;
  --text: #cfe3ee;
  --text-dim: #6d8698;
  --accent: #58f0c0;          /* radar green  */
  --plane: #ffc247;           /* amber        */
  --cargo: #4cd97b;
  --tanker: #ff5d5d;
  --pax: #59b7ff;
  --fish: #ff9e3d;
  --other: #93a7b5;
  --font-display: 'Chakra Petch', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  overflow: hidden;
}

/* ---- top bar ---- */
#topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 1100;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: linear-gradient(180deg, rgba(10, 17, 24, 0.97), rgba(10, 17, 24, 0.88));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}

.brand { display: flex; align-items: baseline; gap: 10px; }

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.22em;
  color: var(--accent);
  text-shadow: 0 0 14px rgba(88, 240, 192, 0.35);
}

.brand-sub {
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--text-dim);
}

.radar-dot {
  align-self: center;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(88, 240, 192, 0.6);
  animation: ping 2.2s infinite;
}
@keyframes ping {
  0%   { box-shadow: 0 0 0 0 rgba(88, 240, 192, 0.55); }
  70%  { box-shadow: 0 0 0 12px rgba(88, 240, 192, 0); }
  100% { box-shadow: 0 0 0 0 rgba(88, 240, 192, 0); }
}

.status-group { display: flex; align-items: center; gap: 10px; }

.layer-toggle input { display: none; }
.layer-toggle { cursor: pointer; user-select: none; }

.chip {
  display: inline-block;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  transition: all 0.15s;
}
.chip .count { font-weight: 600; color: var(--text); }
.layer-toggle input:checked + .chip-plane { border-color: var(--plane); color: var(--plane); }
.layer-toggle input:checked + .chip-plane .count { color: var(--plane); }
.layer-toggle input:checked + .chip-ship { border-color: var(--accent); color: var(--accent); }
.layer-toggle input:checked + .chip-ship .count { color: var(--accent); }
.layer-toggle input:not(:checked) + .chip { opacity: 0.45; text-decoration: line-through; }

.conn {
  font-size: 10px;
  letter-spacing: 0.2em;
  padding: 4px 10px;
  border-radius: 3px;
  border: 1px solid var(--line);
}
.conn[data-state="connected"]  { color: var(--accent); border-color: var(--accent); }
.conn[data-state="connecting"] { color: var(--plane); border-color: var(--plane); animation: blink 1.2s infinite; }
.conn[data-state="offline"]    { color: var(--tanker); border-color: var(--tanker); }
@keyframes blink { 50% { opacity: 0.35; } }

/* ---- map ---- */
#map {
  position: fixed;
  inset: 52px 0 0 0;
  background: var(--bg);
}
.leaflet-container { font-family: var(--font-mono); background: var(--bg); }
.leaflet-control-attribution {
  background: rgba(10, 17, 24, 0.8) !important;
  color: var(--text-dim) !important;
  font-size: 10px;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.leaflet-bar a {
  background: var(--bg-raised) !important;
  color: var(--text) !important;
  border-bottom-color: var(--line) !important;
}
.locate-btn {
  font-size: 17px;
  color: var(--accent) !important;
}
.leaflet-control-layers {
  background: var(--bg-panel) !important;
  color: var(--text) !important;
  border: 1px solid var(--line) !important;
}

/* ---- vehicle markers ---- */
.vehicle-icon { background: none; border: none; }
.vehicle-icon svg { display: block; overflow: visible; }
.vehicle-icon svg path,
.vehicle-icon svg circle { transition: filter 0.15s; }
.vehicle-icon.selected svg { filter: drop-shadow(0 0 6px #fff); }

/* ---- info panel ---- */
#panel {
  position: fixed;
  top: 64px;
  right: 12px;
  bottom: 12px;
  width: 340px;
  max-width: calc(100vw - 24px);
  z-index: 1200;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(0);
  transition: transform 0.22s ease, opacity 0.22s ease;
}
#panel.hidden { transform: translateX(110%); opacity: 0; pointer-events: none; }

#panel-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#panel-close {
  position: absolute;
  top: 8px; right: 8px;
  z-index: 4;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: rgba(10, 17, 24, 0.65);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
#panel-close:hover { background: rgba(10, 17, 24, 0.9); color: #fff; }

/* drag handle - only shown in bottom-sheet mode on small screens */
#panel-handle {
  display: none;
  flex: 0 0 auto;
  padding: 8px 0 6px;
  background: var(--bg-panel);
  touch-action: none;
}
#panel-handle span {
  display: block;
  width: 42px;
  height: 4px;
  margin: 0 auto;
  border-radius: 2px;
  background: var(--text-dim);
  opacity: 0.6;
}

/* compact title strip shown only while the sheet is minimized */
#panel-mini {
  display: none;
  padding: 2px 44px 10px 16px;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
#panel-mini::before {
  content: '▲ ';
  font-size: 10px;
  color: var(--text-dim);
}

.panel-photo {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  background: var(--bg-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.panel-photo img { width: 100%; height: 100%; object-fit: cover; }
.panel-photo .silhouette { width: 65%; opacity: 0.9; }
.panel-photo .photo-note {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 3px 8px;
  font-size: 9px;
  color: #ddd;
  background: rgba(0, 0, 0, 0.55);
}
.panel-photo .photo-note a { color: #fff; }

.panel-head { padding: 12px 16px 4px; }
.panel-head .title {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text);
}
.panel-head .subtitle {
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}
.tag {
  display: inline-block;
  margin-top: 6px;
  font-size: 10px;
  letter-spacing: 0.15em;
  padding: 2px 8px;
  border-radius: 2px;
  border: 1px solid currentColor;
}

.route-line {
  margin: 12px 16px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.route-line .code { font-weight: 600; font-size: 15px; color: var(--text); }
.route-line .apt { color: var(--text-dim); font-size: 10px; display: block; }
.route-line .arrow { color: var(--accent); flex: 0 0 auto; }
.route-line .ep { flex: 1; min-width: 0; }
.route-line .ep .apt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.route-note { margin: 4px 16px 0; font-size: 9px; color: var(--text-dim); }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  background: var(--line);
}
.stat {
  background: var(--bg-raised);
  padding: 8px 10px;
}
.stat .k {
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  text-transform: uppercase;
}
.stat .v { margin-top: 2px; font-size: 14px; font-weight: 500; }
.stat .v small { font-size: 10px; color: var(--text-dim); }
.stat.wide { grid-column: 1 / -1; }

.hist-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 4px 16px 16px;
}
.hist-controls select {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 6px;
}
.btn {
  flex: 1;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 3px;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { background: rgba(88, 240, 192, 0.12); }
.btn.active { background: var(--accent); color: var(--bg); }
.btn:disabled { opacity: 0.4; cursor: default; }

.ext-links { margin: 0 16px 16px; font-size: 11px; }
.ext-links a { color: var(--pax); text-decoration: none; }
.ext-links a:hover { text-decoration: underline; }

.hist-empty { margin: 0 16px 12px; font-size: 11px; color: var(--plane); }

/* altitude color scale for aircraft tracks */
.alt-scale {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px 14px;
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}
.alt-scale .bar {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg,
    rgb(245,210,75), rgb(143,217,76) 10%, rgb(76,217,176) 30%,
    rgb(77,179,230) 50%, rgb(89,133,255) 75%, rgb(176,109,240));
}

/* ---- legend ---- */
#legend {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 1100;
  display: flex;
  gap: 10px;
  padding: 6px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.lg::before {
  content: '';
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 5px;
}
.lg-svg::before { display: none; }
.lg-svg svg { vertical-align: -2px; margin-right: 4px; }
.lg-cargo::before  { background: var(--cargo); }
.lg-tanker::before { background: var(--tanker); }
.lg-pax::before    { background: var(--pax); }
.lg-fish::before   { background: var(--fish); }
.lg-other::before  { background: var(--other); }
.lg-anchor::before { background: var(--other); width: 5px; height: 5px; }

/* ---- toast ---- */
#toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1300;
  padding: 10px 18px;
  background: var(--bg-panel);
  border: 1px solid var(--plane);
  color: var(--plane);
  border-radius: 4px;
  font-size: 12px;
  transition: opacity 0.3s;
}
#toast.hidden { opacity: 0; pointer-events: none; }

/* bigger tap targets for markers on touch screens */
@media (pointer: coarse) {
  .vehicle-icon::after {
    content: '';
    position: absolute;
    inset: -10px;
  }
}

/* small screens: info panel becomes a bottom sheet so the map stays visible */
@media (max-width: 640px) {
  .brand-sub, #legend { display: none; }

  #panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    max-height: 52vh;
    border-radius: 14px 14px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    transform: translateY(0);
  }
  #panel.hidden { transform: translateY(110%); }

  /* minimized: only handle + title strip peek above the bottom edge */
  #panel.minimized { transform: translateY(calc(100% - 54px)); }
  #panel.minimized #panel-mini { display: block; }
  #panel.minimized #panel-body { visibility: hidden; }

  #panel-handle { display: block; }

  .panel-photo {
    aspect-ratio: auto;
    height: 130px;
  }
  .panel-photo .silhouette { width: 40%; }

  .panel-head .title { font-size: 16px; }
  .stat-grid { margin: 10px 12px; }
  .route-line { margin: 10px 12px 0; }
  .hist-controls { margin: 4px 12px 12px; }
}
