/* Generato dal know-how di Fulvio Drago - info@drago.solutions */

:root {
  --bg: #0B0F14;
  --bg-elev: #111821;
  --bg-elev-2: #1A2330;
  --bg-input: #243042;

  --text: #E6EDF3;
  --text-dim: #8B98A9;
  --text-mute: #5A6675;

  --accent: #00E5FF;
  --ok: #3DD68C;
  --warn: #F5C518;
  --err: #FF5A5F;

  --alt-low: #F5C518;
  --alt-mid: #3DD68C;
  --alt-high: #4DA8FF;

  --border: #1F2A38;
  --border-strong: #2C3A4D;

  --map-bg: #0B0F14;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-rows: 56px 1fr 28px;
  grid-template-areas: "hdr" "main" "ftr";
}

/* --- Header --- */
.hdr {
  grid-area: hdr;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 600;
}
.hdr__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
}
.hdr__brand h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
}
.hdr__stats {
  display: flex;
  gap: 8px;
}
.hdr__filter {
  display: flex;
  gap: 2px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  margin-left: 6px;
}
.hdr__filter-btn {
  background: transparent;
  color: var(--text-dim);
  border: 0;
  padding: 3px 12px;
  border-radius: 999px;
  font: 600 11px/1 'Inter', system-ui, -apple-system, sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.hdr__filter-btn:hover {
  color: var(--text);
}
.hdr__filter-btn.is-active {
  background: var(--accent);
  color: #0a0d12;
}
/* TRACKS: switch indipendente dai filtri tipo. Accento cyan/azzurro
   con glow quando attivo, per distinguerlo da Tutti/Aerei/Helicopter. */
#tracks-toggle {
  margin-left: 4px;
  border: 1px solid transparent;
}
#tracks-toggle.is-active {
  background: #4DA8FF;
  color: #0a0d12;
  border-color: #4DA8FF;
}
#tracks-toggle:not(.is-active) {
  color: #4DA8FF;
  border-color: rgba(77, 168, 255, 0.45);
}
#tracks-toggle:not(.is-active):hover {
  background: rgba(77, 168, 255, 0.12);
  color: #4DA8FF;
}
.chip {
  background: var(--bg-elev-2);
  color: var(--text);
  padding: 5px 12px;
  border-radius: 999px;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* --- Main --- */
.main {
  grid-area: main;
  display: grid;
  /* Sidebar 285px = 380px * 0.75 (-25%). Adjust here if the user wants
     a different width: 1fr = map, sidebar = flight list panel. */
  grid-template-columns: 1fr 285px;
  min-height: 0;
}
.map-wrap {
  position: relative;
  background: var(--map-bg);
  min-width: 0;
}
/* Bussola: fissa top-right dentro .map-wrap. Il bearing-number è
   separato dal SVG così il numero resta dritto quando l'ago ruota. */
.map-compass {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 6px 6px;
  border-radius: 8px;
  background: rgba(20, 24, 32, 0.55);
  color: var(--fg);
  cursor: pointer;
  user-select: none;
  line-height: 1;
  transition: background 0.15s ease;
}
.map-compass:hover,
.map-compass:focus-visible {
  background: rgba(20, 24, 32, 0.85);
  outline: none;
}
.map-compass:focus-visible {
  box-shadow: 0 0 0 2px var(--accent, #5aa9ff);
}
/* L'ago ruota in senso opposto alla mappa. Quando la mappa ha bearing
   45°, la "N" deve restare in alto: l'ago SVG va quindi ruotato di -bearing. */
.map-compass__rose {
  display: block;
  transform: rotate(0deg);
  transition: transform 0.15s ease;
}
.map-compass__bearing {
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: var(--fg-dim, #9aa3b2);
  letter-spacing: 0.5px;
}
@media (max-width: 768px) {
  /* Su mobile la bussola occupa spazio: tienila più compatta ma visibile */
  .map-compass { top: 8px; right: 8px; padding: 3px 4px 4px; }
  .map-compass__rose { width: 32px; height: 32px; }
}
#map {
  position: absolute;
  inset: 0;
  background: var(--map-bg);
}

/* --- Sidebar --- */
.sidebar {
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.sidebar__search {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  z-index: 2;
}
#search {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 4px;
  font: inherit;
  outline: none;
  transition: border-color 120ms;
}
#search:focus {
  border-color: var(--accent);
}
.flight-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.flight-list li {
  display: grid;
  grid-template-columns: 90px 60px 60px 1fr;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 12px;
  transition: background 100ms, border-color 100ms;
}
.flight-list li:hover {
  background: var(--bg-elev-2);
}
.flight-list li.selected {
  background: var(--bg-elev-2);
  border-left-color: var(--accent);
}
.flight-list .col-callsign {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.flight-list .col-alt,
.flight-list .col-spd {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  color: var(--text-dim);
}
.flight-list .col-trend {
  text-align: right;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
}
.trend-up { color: var(--ok); }
.trend-dn { color: var(--err); }
.trend-fl { color: var(--text-mute); }

.sidebar__empty {
  padding: 16px;
  color: var(--text-mute);
  text-align: center;
  font-style: italic;
}
.sidebar__legend {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* --- Footer --- */
.ftr {
  grid-area: ftr;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 12px;
  font-size: 11px;
  color: var(--text-dim);
  z-index: 600;
}
.ftr__poll { flex: 1; text-align: center; }
.ftr__meta { text-align: right; font-family: 'JetBrains Mono', ui-monospace, monospace; }

/* --- Status dot --- */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  background: var(--text-mute);
}
.dot--ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot--warn { background: var(--warn); box-shadow: 0 0 6px var(--warn); }
.dot--err { background: var(--err); box-shadow: 0 0 6px var(--err); }
.dot--low { background: var(--alt-low); }
.dot--mid { background: var(--alt-mid); }
.dot--high { background: var(--alt-high); }

/* --- Detail panel --- */
.detail {
  position: fixed;
  right: 0;
  top: 56px;
  bottom: 28px;
  width: 320px;
  background: var(--bg-elev-2);
  border-left: 1px solid var(--border-strong);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.5);
  transform: translateX(100%);
  transition: transform 200ms ease;
  z-index: 800;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.detail.open {
  transform: translateX(0);
}
.detail__hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.detail__hdr h2 {
  margin: 0;
  font-size: 16px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  color: var(--accent);
}
#detail-close {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
#detail-close:hover { color: var(--text); background: var(--bg-input); }
.detail__body {
  margin: 0;
  padding: 8px 14px 14px;
  flex: 1;
  overflow-y: auto;
  font-size: 12px;
}
/* Ogni riga è un dl.row: dt (etichetta) + dd (valore) affiancati
   con un bordo inferiore sottile per separare visivamente le righe. */
.detail__body .row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 12px;
  padding: 9px 6px;
  border-bottom: 1px solid var(--border);
  margin: 0;
}
.detail__body .row:last-child { border-bottom: 0; }
.detail__body .row:hover { background: var(--bg-input); }
.detail__body dt {
  margin: 0;
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
}
.detail__body dd {
  margin: 0;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  word-break: break-word;
}
.detail__links {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
}
.detail__links a {
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  display: inline-block;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
}
.detail__links a:hover {
  background: var(--bg-input);
}

/* --- Leaflet marker --- */
.leaflet-container { background: var(--map-bg); font: inherit; }
.leaflet-control-attribution {
  background: rgba(11, 15, 20, 0.7) !important;
  color: var(--text-mute) !important;
  font-size: 10px;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.leaflet-control-zoom a {
  background: var(--bg-elev-2) !important;
  color: var(--text) !important;
  border-color: var(--border-strong) !important;
}
/* Bottone "centra su Schio" — è un <a> dentro lo stesso wrapper
   .leaflet-control-zoom dei tasti +/-, quindi eredita naturalmente
   dimensioni, padding, border-radius e separatori. Serve solo
   colorarlo coerente col tema dark. */
.leaflet-control-zoom a.leaflet-control-schio-btn {
  background: var(--bg-elev-2) !important;
  color: var(--text) !important;
  border-bottom-color: var(--border-strong) !important;
  text-decoration: none;
  font: bold 18px 'Lucida Console', Monaco, monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.leaflet-control-zoom a.leaflet-control-schio-btn:hover {
  background: var(--bg-elev-3, #1f2a36) !important;
  color: var(--accent, #00E5FF) !important;
}
.leaflet-control-schio-btn svg { display: block; }
.leaflet-control-zoom a.leaflet-control-schio-btn:last-child {
  border-bottom: none;
}

.ac-marker {
  /* No fixed width/height: marker size is driven by the inner SVG
     (22 / 25 / 29 px depending on altitude band). A fixed 22x22 box
     would clip larger icons and shift their visual center away from
     the latlng, breaking polyline alignment. */
  display: inline-block;
  line-height: 0;
  transform-origin: 50% 50%;
  will-change: transform;
}
/* Outer rotation wrapper: the heading rotate is applied here so it
   doesn't conflict with the centering rule on .ac-marker below. */
.ac-marker-rot {
  display: inline-block;
  line-height: 0;
  transform-origin: 50% 50%;
  will-change: transform;
}
/* Leaflet's iconSize box may be larger than the inner .ac-marker
   (altitude-band scaling: 22/25/29). Two-stage centering:
   .ac-marker-rot (heading-rotation wrapper) fills the Leaflet box
   exactly via inset:0; .ac-marker inside it shrinks to the SVG
   content and is centered within .ac-marker-rot. Together they
   keep the cyan selection halo concentric with the EMS red ring
   regardless of iconSize. */
.leaflet-marker-icon > .ac-marker-rot {
  position: absolute;
  inset: 0;
  display: block;
}
.ac-marker-rot > .ac-marker {
  position: absolute;
  display: block;
  inset: 0;
  margin: auto;
  width: max-content;
  height: max-content;
}
.ac-marker svg { display: block; overflow: visible; }
/* Selection ring: cyan halo behind the aircraft icon.
   Drawn as a pseudo-element so it does not affect the iconAnchor
   geometry (polyline alignment stays correct). The ring is centered
   on the 22x22 marker box; overflow:visible on .ac-marker svg lets
   it spill outside without clipping. */
.ac-marker.selected {
  position: relative;
}
.ac-marker.selected::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.45),
    0 0 8px rgba(0, 229, 255, 0.55);
  pointer-events: none;
  animation: ac-select-pulse 1.6s ease-in-out infinite;
}
.ac-marker.selected svg path,
.ac-marker.selected svg polygon,
.ac-marker.selected svg rect {
  stroke: var(--accent);
  stroke-width: 1.2;
}
@keyframes ac-select-pulse {
  0%, 100% { transform: scale(1);    opacity: 0.85; }
  50%      { transform: scale(1.15); opacity: 1; }
}
.ac-trail {
  stroke-opacity: 0.45;
  stroke-width: 2;
  fill: none;
}

/* --- Marker wrapper: allows the EMS red ring to be larger than the
   inner aircraft icon. Icon is centered inside the wrap. --- */
.ac-marker-wrap {
  position: relative;
  width: 22px;
  height: 22px;
}
.ac-marker-wrap--ems {
  width: 38px;
  height: 38px;
}
.ac-marker-wrap--ems > .ac-marker {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -11px 0 0 -11px;
}
.ac-marker-ems {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px;
  border: 2.5px solid #ff2d2d;
  border-radius: 50%;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.5),
    0 0 10px rgba(255, 45, 45, 0.6);
  pointer-events: none;
  animation: ems-pulse 1.4s ease-in-out infinite;
}
@keyframes ems-pulse {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50%      { transform: scale(1.12); opacity: 1; }
}

/* --- Mobile --- */
@media (max-width: 768px) {
  body {
    grid-template-rows: 56px 1fr 28px;
  }
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 200px;
  }
  .sidebar {
    border-left: 0;
    border-top: 1px solid var(--border);
  }
  .detail {
    width: 100%;
  }
}

/* --- Spinner (caricamento) --- */
.spinner {
  display: inline-flex;
  align-items: center;
  margin-left: 10px;
  color: var(--accent);
  vertical-align: middle;
}
.spinner[hidden] { display: none; }
.spinner svg { animation: spin 1s linear infinite; }
.spinner--err { color: #ff6b6b; }
.spinner--err svg { animation: none; }
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Chip button (header Alerts toggle) --- */
.chip--btn {
  cursor: pointer;
  font: 600 12px/1 'JetBrains Mono', ui-monospace, monospace;
  color: var(--text);
  transition: background 120ms, color 120ms, border-color 120ms;
}
.chip--btn:hover {
  background: var(--bg-input);
  border-color: var(--border-strong);
}
.chip--btn[aria-expanded="true"] {
  background: var(--accent);
  color: #0a0d12;
  border-color: var(--accent);
}

/* --- Modal --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}
.modal__dialog {
  position: relative;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
  width: min(520px, 100%);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal__hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.modal__hdr h2 {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.modal__close {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.modal__close:hover { color: var(--text); background: var(--bg-input); }
.modal__body {
  padding: 16px;
  overflow-y: auto;
}
.modal__lead {
  margin: 0 0 12px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
}
.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

/* --- Banner (in-modal status) --- */
.banner {
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
}
.banner--warn { border-color: var(--warn); color: var(--warn); }
.banner--info { color: var(--text-dim); }

/* --- Alerts form --- */
.alerts-form { display: flex; flex-direction: column; gap: 12px; }
.alerts-form__row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 12px;
  align-items: start;
}
.alerts-form__row--info { display: block; }
.alerts-form__row label {
  padding-top: 8px;
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
}
.alerts-form__field { display: flex; flex-direction: column; gap: 4px; }
.alerts-form__field input,
.alerts-form__field textarea {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 4px;
  font: 12px/1.4 'JetBrains Mono', ui-monospace, monospace;
  outline: none;
  transition: border-color 120ms;
}
.alerts-form__field input:focus,
.alerts-form__field textarea:focus {
  border-color: var(--accent);
}
.alerts-form__field textarea { resize: vertical; min-height: 110px; }
.alerts-form__field small { color: var(--text-mute); font-size: 11px; }
.alerts-form__field code {
  background: var(--bg-input);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 10px;
  color: var(--accent);
  margin: 0 1px;
}
.alerts-form__hint {
  font-size: 12px;
  padding: 6px 0;
}
.alerts-form__hint--ok { color: var(--ok); }
.alerts-form__hint--warn { color: var(--warn); }
.alerts-form__counter {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
}
.alerts-form__counter strong { color: var(--text); }

/* --- Buttons --- */
.btn {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 7px 14px;
  border-radius: 4px;
  font: 600 12px/1 inherit;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.btn:hover { background: var(--bg-input); }
.btn--primary {
  background: var(--accent);
  color: #0a0d12;
  border-color: var(--accent);
}
.btn--primary:hover { background: #66ecff; border-color: #66ecff; }
.btn--ghost { background: transparent; }

/* --- Toasts --- */
.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 44px;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
  pointer-events: none;
}
.toast {
  position: relative;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 10px 36px 10px 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  color: var(--text);
  font-size: 12px;
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}
.toast--err { border-left-color: var(--err); }
.toast--leaving { animation: toast-out 0.2s ease-in forwards; }
.toast__title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 4px;
}
.toast__body {
  margin: 0;
  font: 11px/1.4 'JetBrains Mono', ui-monospace, monospace;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 160px;
  overflow: hidden;
}
.toast__close {
  position: absolute;
  top: 6px;
  right: 6px;
  background: transparent;
  border: 0;
  color: var(--text-mute);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
}
.toast__close:hover { color: var(--text); background: var(--bg-input); }
@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes toast-out {
  to { transform: translateX(20px); opacity: 0; }
}
}
