/* Dyna3D Live — habillage RaceCarnet, repris de DynaViewer (DynaFramework : tokens.rs, palette.rs).
   Deux thèmes : Nuit (défaut) et Papier. Les couleurs des courbes sont lues par app.js dans --curve-1..8. */

@font-face { font-family: "Geist"; src: url("fonts/Geist-Regular.ttf"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Geist"; src: url("fonts/Geist-Medium.ttf"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Geist"; src: url("fonts/Geist-SemiBold.ttf"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Geist Mono"; src: url("fonts/GeistMono-Regular.ttf"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Geist Mono"; src: url("fonts/GeistMono-Medium.ttf"); font-weight: 500; font-display: swap; }

:root[data-theme="night"] {
  --bg: #0C0E14; --bar: #12141C; --inset: #10121A; --hover: #171923; --pressed: #262A36;
  --line: #1E212B; --line-strong: #3A3F4E;
  --text: #F1F3F7; --text-2: #C9CEDA; --text-3: #7D8394;
  --accent: #5B84E8; --accent-soft: #16203A; --on-accent: #0C0E14;
  --critical: #E85147; --ok: #3FB07C; --warn: #E5A93B;
  --plot-text: #A4AAB8; --cursor: #DA4C43; --grid: #1A1D27; --grid-strong: #3A3F4E;
  --curve-1: #6CA8FF; --curve-2: #53E08A; --curve-3: #F5C242; --curve-4: #5AD6E8;
  --curve-5: #FF8A82; --curve-6: #B99BF5; --curve-7: #C6CEE0; --curve-8: #FFA55A;
  --gap: rgba(232, 81, 71, 0.16);
  color-scheme: dark;
}
:root[data-theme="paper"] {
  --bg: #FDFCFA; --bar: #F7F5F0; --inset: #F6F7FA; --hover: #F1F3F7; --pressed: #E9ECF2;
  --line: #DDE1EB; --line-strong: #A4AAB8;
  --text: #0C0E14; --text-2: #3A3F4E; --text-3: #5A6072;
  --accent: #1E3A8A; --accent-soft: #EDF1FA; --on-accent: #FDFCFA;
  --critical: #C8322A; --ok: #137A4E; --warn: #C98A00;
  --plot-text: #5A6072; --cursor: #C8322A; --grid: #E9ECF2; --grid-strong: #C9CEDA;
  --curve-1: #1E3A8A; --curve-2: #137A4E; --curve-3: #C98A00; --curve-4: #3B62C4;
  --curve-5: #9E2820; --curve-6: #3E8860; --curve-7: #3A3F4E; --curve-8: #6C8BDA;
  --gap: rgba(200, 50, 42, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 400 13px/1.45 "Geist", system-ui, sans-serif; }
[hidden] { display: none !important; }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; }
h2 { font-size: 11px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); margin: 16px 0 6px; }
button, select, input { font: inherit; color: inherit; }
button, select {
  background: var(--bar); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer;
}
button:hover, select:hover { background: var(--hover); }
button:active { background: var(--pressed); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 500; }
button.quiet { border-color: transparent; background: transparent; color: var(--text-3); padding: 2px 6px; }
button.quiet:hover { color: var(--text); background: var(--hover); }
input[type="password"], input[type="search"] {
  background: var(--inset); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; width: 100%;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.error { color: var(--critical); min-height: 1.4em; margin: 6px 0; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.spacer { flex: 1; }

/* Connexion */
#login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
#login .card { width: min(360px, 100%); background: var(--bar); border: 1px solid var(--line); border-radius: 10px; padding: 24px; }
#login label { display: block; margin: 16px 0 6px; color: var(--text-2); }
#login button { width: 100%; padding: 9px; }

/* Barre du haut */
#app { height: 100%; display: flex; flex-direction: column; }
header {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--bar); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { font-weight: 500; letter-spacing: 0.02em; }
.brand b { color: var(--critical); font-weight: 600; }
.title { color: var(--text-2); font-family: "Geist Mono", monospace; font-size: 12px; }
.badge {
  font: 500 11px "Geist Mono", monospace; letter-spacing: 0.06em; padding: 3px 8px; border-radius: 4px;
  border: 1px solid var(--line-strong); color: var(--text-3);
}
.badge.live { border-color: var(--critical); color: var(--critical); }
.badge.live::before { content: "● "; animation: pulse 1.4s ease-in-out infinite; }
.badge.done { border-color: var(--ok); color: var(--ok); }
.badge.warn { border-color: var(--warn); color: var(--warn); }
@keyframes pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .badge.live::before { animation: none; } }

/* Corps : liste | carte | courbes */
main { flex: 1; min-height: 0; display: grid; grid-template-columns: 230px minmax(280px, 2fr) minmax(360px, 3fr); }
#side { border-right: 1px solid var(--line); padding: 4px 10px 12px; overflow-y: auto; background: var(--bar); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 7px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.list li:hover { background: var(--hover); }
.list li.selected { background: var(--accent-soft); border-color: var(--accent); }
.list .name { font-weight: 500; display: flex; justify-content: space-between; gap: 6px; }
.list .sub { color: var(--text-3); font: 11px "Geist Mono", monospace; }
.dot { color: var(--critical); }
#side .check { margin-top: 8px; white-space: normal; font-size: 12px; }

#map-pane { position: relative; min-height: 0; border-right: 1px solid var(--line); }
#map { position: absolute; inset: 0; background: var(--inset); }
.map-tools {
  position: absolute; top: 10px; right: 10px; z-index: 500; display: flex; gap: 6px; align-items: center;
  background: var(--bar); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px;
}
.scale {
  position: absolute; left: 10px; bottom: 22px; z-index: 500; background: var(--bar); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 8px; font: 11px "Geist Mono", monospace; color: var(--text-2);
}
.scale .ramp { height: 6px; width: 150px; border-radius: 3px; margin: 3px 0;
  background: linear-gradient(90deg, rgb(38,96,255), rgb(36,200,232), rgb(58,200,96), rgb(245,200,50), rgb(232,62,52)); }
.scale .ends { display: flex; justify-content: space-between; }
.car { width: 26px; height: 26px; }
.car svg { width: 26px; height: 26px; filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.7)); }
.leaflet-container { font: inherit; background: var(--inset); }
/* Plan assombri en thème Nuit (le satellite reste tel quel) : la trace doit rester ce qu on voit en premier. */
:root[data-theme="night"] .leaflet-layer.dim { filter: brightness(0.62) contrast(1.1) saturate(0.7); }

#plots-pane { min-height: 0; overflow-y: auto; padding: 10px 12px 24px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.tile { background: var(--bar); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.tile .k { font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-3); }
.tile .v { font: 500 20px "Geist Mono", monospace; }
.tile .u { font-size: 11px; color: var(--text-3); margin-left: 3px; }
.info { margin: 8px 0 2px; color: var(--text-3); font-size: 12px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.info .lost { color: var(--critical); }
.info a { color: var(--accent); }
.panel { margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.panel-head { display: flex; align-items: center; gap: 6px; padding: 4px 6px 0 10px; color: var(--text-3); font-size: 11px; }
.panel-head .names { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-body { padding: 0 2px 2px; }
#add-panel { margin-top: 10px; }
.empty { color: var(--text-3); padding: 24px 4px; }

/* uPlot : légende et axes aux couleurs du thème */
.uplot, .u-legend { font-family: "Geist Mono", monospace; font-size: 11px; color: var(--plot-text); }
.u-legend { text-align: left; padding: 0 8px 4px; }
.u-legend .u-series > * { padding: 1px 4px; }
.u-legend .u-marker { width: 9px; height: 3px; border-radius: 1px; }
.u-select { background: var(--accent-soft); opacity: 0.6; }
.u-cursor-x { border-right: 1px solid var(--cursor) !important; }
.u-cursor-y { display: none; }

/* Choix des canaux */
dialog { background: var(--bar); color: var(--text); border: 1px solid var(--line-strong); border-radius: 10px; padding: 16px; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog h2 { margin-top: 0; }
.picker-list { max-height: 50vh; overflow-y: auto; margin: 10px 0; display: grid; gap: 2px; }
.picker-list label { display: flex; gap: 8px; padding: 4px 6px; border-radius: 4px; cursor: pointer; }
.picker-list label:hover { background: var(--hover); }
.picker-list .tech { color: var(--text-3); font: 11px "Geist Mono", monospace; margin-left: auto; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; }

/* Téléphone : tout s'empile, la carte garde une hauteur utile */
@media (max-width: 900px) {
  main { display: block; overflow-y: auto; }
  #side { border-right: 0; border-bottom: 1px solid var(--line); max-height: 34vh; }
  #map-pane { height: 46vh; border-right: 0; border-bottom: 1px solid var(--line); }
  #plots-pane { overflow: visible; }
  header { gap: 8px; }
  .title { display: none; }
}
