:root {
  --bg: #0b1220;
  --panel: rgba(13, 21, 36, 0.94);
  --panel-solid: #0e1626;
  --raised: #16223a;
  --line: #22314d;
  --text: #e6edf7;
  --muted: #8b9ab3;
  --accent: #5cc8ff;
  --accent-ink: #04121f;
  --warn: #ffb74d;
  --danger: #ff5d5d;
  --topbar-h: 52px;
  --sheet-peek: 136px;
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--font);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
svg { stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }

/* --- Barre du haut --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  background: var(--panel-solid);
  border-bottom: 1px solid var(--line);
  z-index: 1200;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: .02em; margin-right: auto; }
.brand img { border-radius: 7px; }
.chip {
  max-width: 50vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--raised);
  font-size: 13px;
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--raised);
  flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }

/* --- Vues --- */
.views { position: relative; overflow: hidden; }
.view { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; background: #0a0f1a; }
#map.picking { cursor: crosshair; }
.top-overlay {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1050;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  pointer-events: none;
}
.status {
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.status.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.alt-legend { width: 150px; padding: 6px 8px 4px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }
.alt-bar { height: 5px; border-radius: 3px; }
.alt-ticks { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin-top: 3px; }

/* Contrôles propres à une vue, en haut à droite */
.view-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1050;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  max-width: 55%;
}
.pill, .pill-btn {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.pill-btn { color: var(--accent); }
.pill-btn.accent { background: var(--accent); color: var(--accent-ink); font-weight: 700; border-color: var(--accent); }

/* Radar */
.radar-view { background: radial-gradient(circle at 50% 40%, #0f1b30, var(--bg) 70%); }
#radar-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: manipulation; }

/* AR */
.ar-view { background: #000; }
#ar-video, #ar-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#ar-video { object-fit: cover; }
#ar-canvas { touch-action: manipulation; }
body[data-view="ar"] .alt-legend { display: none; }
.ar-start {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 50%;
  transform: translateY(-60%);
  z-index: 1060;
  max-width: 420px;
  margin: 0 auto;
  padding: 20px 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  text-align: center;
}
.ar-start h2 { margin: 0 0 6px; font-size: 18px; }
.ar-start p { margin: 0 0 16px; font-size: 14px; }
.ar-msg {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 96px;
  z-index: 1055;
  margin: 0 auto;
  max-width: 460px;
  padding: 9px 12px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--warn) 22%, var(--panel-solid));
  color: #ffe2b8;
  font-size: 13.5px;
}
.ar-aim {
  position: absolute;
  left: 50%;
  bottom: calc(var(--sheet-peek) + 14px);
  transform: translateX(-50%);
  z-index: 1055;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 24px);
  padding: 9px 14px;
  border-radius: 14px;
  border: 1px solid var(--accent);
  background: var(--panel);
  text-align: left;
}
.ar-aim > span:nth-child(2) { display: flex; flex-direction: column; min-width: 0; }
.ar-aim small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ar-aim em { font-style: normal; color: var(--accent); font-size: 12.5px; white-space: nowrap; }
.ar-calib {
  position: absolute;
  top: 92px;
  right: 10px;
  z-index: 1060;
  width: min(330px, calc(100% - 20px));
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  display: grid;
  gap: 10px;
}
.ar-calib p { margin: 0; font-size: 13px; }
.ar-calib label { display: grid; gap: 4px; font-size: 13px; }
.ar-calib output { color: var(--accent); font-variant-numeric: tabular-nums; }
.ar-calib input[type="range"] { width: 100%; accent-color: var(--accent); }
.ar-calib .link-btn { margin-top: 0; }
.ar-recal-msg { min-height: 1em; color: var(--accent); }
.ar-calib .primary-btn { font-size: 14px; padding: 10px; }

.fab {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1050;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--accent);
}
.fab svg { width: 22px; height: 22px; }

/* --- Leaflet --- */
.leaflet-container { font-family: var(--font); }
.leaflet-control-attribution { background: rgba(11, 18, 32, .75) !important; color: var(--muted); font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted); }
.leaflet-bottom { bottom: var(--sheet-peek); }

.user-dot span {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 0 0 0 rgba(92, 200, 255, .6);
  animation: pulse 2.4s infinite;
}
@keyframes pulse { 70% { box-shadow: 0 0 0 16px rgba(92, 200, 255, 0); } 100% { box-shadow: 0 0 0 0 rgba(92, 200, 255, 0); } }
.radius-circle { stroke: var(--accent); stroke-opacity: .45; stroke-width: 1.5; stroke-dasharray: 6 6; fill: var(--accent); fill-opacity: .04; }

.plane-icon { background: none; border: none; transition: transform 1s linear; }
.leaflet-zoom-anim .plane-icon, .leaflet-dragging .plane-icon { transition: none; }
.plane { position: relative; width: 34px; height: 34px; }
.plane-rot { width: 100%; height: 100%; transition: transform .6s ease; }
.plane svg { width: 100%; height: 100%; fill: var(--c); stroke: #06101d; stroke-width: .9; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .7)); }
.tiles-dark { filter: invert(1) hue-rotate(185deg) brightness(.85) contrast(.85) saturate(.5); }
.plane-label {
  display: none;
  position: absolute;
  top: 31px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10.5px;
  font-weight: 650;
  white-space: nowrap;
  color: var(--text);
  text-shadow: 0 0 3px #000, 0 0 2px #000;
  pointer-events: none;
}
.plane.on-ground { transform: scale(.65); opacity: .75; }
.plane.selected::before {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 12px rgba(255, 255, 255, .5);
}
.show-labels .plane-label, .plane.selected .plane-label { display: block; }
.plane.selected .plane-label { color: #fff; font-size: 12px; }
.plane.emergency svg { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { fill: var(--danger); } }

.route-done { stroke: var(--accent); stroke-opacity: .55; stroke-width: 2; fill: none; }
.route-todo { stroke: #fff; stroke-opacity: .7; stroke-width: 2; stroke-dasharray: 5 7; fill: none; }
.airport-icon { background: none; border: none; }
.airport-icon span {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 6px;
  background: #fff;
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
}

/* --- Panneau (bottom sheet mobile, colonne à droite sur grand écran) --- */
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  height: var(--sheet-peek);
  background: var(--panel);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, .35);
  transition: height .25s ease;
}
.sheet[data-state="half"] { height: 58%; }
.sheet[data-state="full"] { height: calc(100% - 8px); }
.sheet-handle { flex: none; display: grid; place-items: center; height: 22px; border: none; background: none; touch-action: none; }
.sheet-handle span { width: 42px; height: 5px; border-radius: 3px; background: var(--line); }
.sheet-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0 14px 16px; }
.sheet-drag { touch-action: none; }

.list-head h2 { margin: 0; font-size: 16px; }
.list-head h2 .muted { font-weight: 400; font-size: 13px; }
.list-head p { margin: 2px 0 8px; font-size: 12.5px; }
.empty { color: var(--muted); font-size: 14px; }

.ac-list { list-style: none; margin: 0; padding: 0; }
.ac-row {
  display: grid;
  grid-template-columns: 12px 1fr auto auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 4px;
  border: none;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
}
.ac-row:active { background: var(--raised); }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.ac-main, .ac-sky { display: flex; flex-direction: column; min-width: 0; }
.ac-main strong { font-size: 15px; }
.ac-main small, .ac-sky small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-sky { align-items: flex-end; font-variant-numeric: tabular-nums; }
.ac-alt { min-width: 74px; text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }

/* Fiche avion */
.d-head { display: flex; align-items: center; gap: 10px; padding-bottom: 8px; }
.d-title { flex: 1; min-width: 0; }
.d-title h2 { margin: 0; font-size: 20px; }
.d-title h2 small { font-size: 13px; font-weight: 500; color: var(--muted); }
.d-title p { margin: 0; color: var(--muted); font-size: 14px; }
.d-lost, .d-emergency { margin: 0 0 10px; padding: 6px 10px; border-radius: 8px; font-size: 13px; }
.d-lost { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.d-emergency { background: color-mix(in srgb, var(--danger) 22%, transparent); color: #ffd0d0; font-weight: 600; }

.d-route {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--raised);
}
.d-route .ap { display: flex; flex-direction: column; min-width: 0; }
.d-route .ap:last-child { text-align: right; }
.d-route .ap strong { font-size: 22px; letter-spacing: .03em; }
.d-route .ap span { font-size: 13px; }
.d-route .ap small { font-size: 11.5px; color: var(--muted); }
.route-arrow { color: var(--accent); font-size: 18px; }
.route-note { margin: 4px 2px 10px; font-size: 12px; }

.d-sky { margin: 4px 0 10px; font-size: 14px; }
.d-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 0 0 12px; border-radius: 12px; overflow: hidden; background: var(--line); }
.d-grid > div { padding: 8px 10px; background: var(--panel-solid); }
.d-grid dt { font-size: 11.5px; color: var(--muted); }
.d-grid dd { margin: 0; font-size: 15px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.d-grid dd small { color: var(--muted); font-size: 12px; }

.d-photo { margin: 0 0 12px; }
.d-photo img { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 12px; background: var(--raised); }
.d-photo figcaption { margin-top: 4px; font-size: 11.5px; color: var(--muted); }
.d-photo a { color: inherit; }

/* --- Onglets --- */
.tabbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--panel-solid);
  border-top: 1px solid var(--line);
  z-index: 1200;
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; border: none; background: none; color: var(--muted); font-size: 12px; }
.tab svg { width: 22px; height: 22px; }
.tab[aria-selected="true"] { color: var(--accent); }
.tab:disabled { opacity: .45; cursor: default; }
.tab em { font-style: normal; font-size: 10px; }

/* --- Réglages, bandeau, dialogue --- */
.popover {
  position: fixed;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 6px);
  right: 12px;
  z-index: 1500;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.popover fieldset { border: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.popover legend { font-weight: 600; margin-bottom: 6px; }
.popover label { display: flex; align-items: center; gap: 8px; }
.popover small { color: var(--muted); font-weight: 400; }
.popover fieldset + fieldset { margin-top: 12px; }
.popover select { padding: 7px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: 14px; }

.pick-banner {
  position: fixed;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 10px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1500;
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 14px;
}
.pick-banner .link-btn { color: var(--accent-ink); }

.dialog-backdrop { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 16px; background: rgba(3, 7, 14, .7); }
.dialog {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 22px 18px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
}
.dialog h2 { margin: 0 0 4px; }
.dialog > .muted { margin: 0 0 14px; font-size: 14px; }
.dialog-close { position: absolute; top: 12px; right: 12px; }
.dialog-msg { margin: 0 0 12px; padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); font-size: 13.5px; }
.primary-btn { width: 100%; padding: 13px; border: none; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 16px; }
.primary-btn:disabled { opacity: .7; }
.secondary-btn { padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--raised); }
.link-btn { display: block; margin: 12px auto 0; border: none; background: none; color: var(--accent); text-decoration: underline; font-size: 14px; }
.or { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.search { display: flex; gap: 8px; }
.search input {
  flex: 1;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* évite le zoom automatique d'iOS */
}
.results { list-style: none; margin: 8px 0 0; padding: 0; }
.results li.muted { padding: 8px 2px; font-size: 14px; }
.results button { display: flex; flex-direction: column; width: 100%; padding: 9px 4px; border: none; border-bottom: 1px solid var(--line); background: none; text-align: left; }
.results button span { color: var(--muted); font-size: 12.5px; }

/* --- Grand écran : panneau en colonne à droite --- */
@media (min-width: 900px) {
  :root { --sheet-peek: 0px; }
  .sheet, .sheet[data-state] {
    top: 12px;
    right: 12px;
    bottom: 12px;
    left: auto;
    width: 380px;
    height: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .sheet-handle { display: none; }
  .sheet-body { padding-top: 14px; }
  .fab, .view-controls, .ar-calib { right: 404px; }
  .ar-aim { left: calc((100% - 392px) / 2); }
  .ar-msg { right: 404px; }
}
