:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #16191d;
  --muted: #6b7480;
  --line: #dde1e6;
  --accent: #1a35e3;
  --header-h: 52px;
  --panel-w: 380px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --panel: #1c2024;
    --text: #e8eaed;
    --muted: #98a1ac;
    --line: #2c3238;
    --accent: #7f93ff;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

/* ── En-tête ─────────────────────────────────────────── */

header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.count { color: var(--text); font-variant-numeric: tabular-nums; }
.status { color: var(--muted); font-size: 13px; margin-left: auto; }

header button {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

header button:active { background: var(--line); }

/* Indicateur de suivi : un clic dessus arrête le suivi. */
header button.follow {
  min-height: 32px;
  padding: 0 10px;
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 45vw;
}

#toggle-list { display: none; }

.error {
  margin: 0;
  padding: 8px 12px;
  background: #b3261e;
  color: #fff;
  font-size: 13px;
}

/* ── Disposition ─────────────────────────────────────── */

main {
  position: relative;
  display: flex;
  height: calc(100% - var(--header-h));
}

#map {
  flex: 1;
  min-width: 0;
  background: var(--bg);
}

.panel {
  width: var(--panel-w);
  flex: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel);
  border-left: 1px solid var(--line);
}

/* ── Tableau ─────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; }

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 6px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: right;
}

thead th:first-child { text-align: left; }

tbody td {
  padding: 9px 6px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Courbe d'altitude dépliée sous un pilote suivi. */
tbody tr.detail { cursor: default; background: color-mix(in srgb, var(--accent) 6%, transparent); }
tbody tr.detail:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
tbody tr.detail td { padding: 4px 8px 10px; border-bottom: 1px solid var(--line); }
canvas.chart { display: block; width: 100%; height: 76px; }

tbody tr { cursor: pointer; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
tbody tr.selected { background: color-mix(in srgb, var(--accent) 16%, transparent); }
tbody tr.selected td.name { font-weight: 700; }
tbody tr.selected td { border-bottom: none; }
tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

td.name {
  text-align: left;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Hauteur imposée, largeur libre : les épingles n'ont pas toutes le même
   rapport (20×26, 32×41, 48×60). */
.etat-ico { height: 22px; width: auto; flex: none; }

.dot {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
}

td.alt { font-weight: 600; }
td.age { color: var(--muted); font-size: 13px; }

tbody tr.stale { color: var(--muted); opacity: 0.6; }
tbody tr.stale td.alt { font-weight: 400; }

/* ── Marqueurs ───────────────────────────────────────── */

/* L'épingle est ancrée par sa pointe : le conteneur ne doit pas la décaler,
   d'où l'alignement en haut et l'étiquette positionnée à part. */
.pilot-marker { display: flex; align-items: flex-start; white-space: nowrap; }

.marker-pin {
  flex: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}

.pilot-marker.etat-off { opacity: 0.55; }

.marker-label {
  align-self: center;
  margin-left: 3px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.85);
  color: #16191d;
  font-size: 12px;
  font-weight: 600;
}

.popup-table { border-collapse: collapse; margin-top: 6px; }
.popup-table th { padding-right: 10px; color: #6b7480; font-weight: 500; text-align: left; }
.popup-table td { font-variant-numeric: tabular-nums; }

/* ── Mobile : la liste devient une feuille escamotable ─ */

@media (max-width: 760px) {
  #toggle-list { display: inline-block; }
  .status { display: none; }

  .panel {
    position: absolute;
    inset: auto 0 0 0;
    width: auto;
    max-height: 55%;
    border-left: none;
    border-top: 1px solid var(--line);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.18);
    transform: translateY(100%);
    transition: transform 0.2s ease;
    z-index: 500; /* au-dessus des tuiles Leaflet */
  }

  .panel.open { transform: none; }
}
