:root {
  --fond: #040b15;
  --verre: rgba(7, 22, 40, 0.78);
  --verre-fort: rgba(9, 28, 50, 0.94);
  --trait: rgba(120, 200, 255, 0.16);
  --trait-fort: rgba(120, 200, 255, 0.34);
  --texte: #e8f2fb;
  --gris: #8ea6bc;
  --menthe: #2fe6a3;
  --cyan: #38c6ff;
  --rouge: #ff5a6a;
  --ambre: #ffb547;
  --arret: #8fa3b8;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 "Plus Jakarta Sans", system-ui, sans-serif;
  color: var(--texte);
  background: var(--fond);
}
h1, h2, .product, nav button { font-family: Montserrat, system-ui, sans-serif; }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--texte); letter-spacing: 0.02em; }

button, input, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--trait-fort);
  background: rgba(56, 198, 255, 0.07);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
button:hover { border-color: var(--cyan); background: rgba(56, 198, 255, 0.16); }
button.primary {
  background: var(--menthe); border-color: var(--menthe); color: #03241a; font-weight: 600;
  box-shadow: 0 0 18px rgba(47, 230, 163, 0.35);
}
button.primary:hover { background: #5ff0bb; }
button.link { border: 0; background: none; padding: 2px 4px; color: var(--cyan); text-decoration: underline; }
button.danger { color: var(--rouge); }
input, select {
  border: 1px solid var(--trait-fort);
  border-radius: 8px;
  padding: 6px 8px;
  background: rgba(4, 14, 26, 0.7);
  min-width: 0;
  color-scheme: dark;
}
input[type="range"] { padding: 0; accent-color: var(--menthe); }
:focus-visible { outline: 2px solid var(--menthe); outline-offset: 2px; }
.muted { color: var(--gris); }
.mono { font-family: var(--mono); }
.error { color: var(--rouge); margin: 0; min-height: 1.4em; }
.spacer { flex: 1; }
.badge {
  background: rgba(255, 181, 71, 0.12); color: var(--ambre); border: 1px solid rgba(255, 181, 71, 0.4);
  border-radius: 999px; padding: 2px 12px; font-size: 12px; font-weight: 600;
}

/* Connexion */
body:has(#login:not([hidden])) {
  background:
    radial-gradient(circle at 20% 15%, rgba(56, 198, 255, 0.16), transparent 45%),
    radial-gradient(circle at 80% 85%, rgba(47, 230, 163, 0.14), transparent 45%),
    var(--fond);
}
#login {
  width: min(380px, calc(100% - 32px));
  margin: 8vh auto 0;
  background: var(--verre-fort);
  border: 1px solid var(--trait-fort);
  border-radius: 18px;
  padding: 28px;
  display: grid;
  gap: 14px;
  box-shadow: 0 0 60px rgba(56, 198, 255, 0.12);
}
#login img { width: 190px; justify-self: center; border-radius: 12px; }
#login h1 { font-size: 20px; margin: 0; text-align: center; letter-spacing: 0.04em; }
#login label { display: grid; gap: 4px; font-weight: 500; color: var(--gris); }
#login .muted { text-align: center; font-size: 12px; margin: 0; }

/* Cadre */
#app { height: 100%; display: flex; flex-direction: column; }
header {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 14px; background: var(--verre-fort); border-bottom: 1px solid var(--trait);
}
header > * { white-space: nowrap; }
header img { height: 36px; border-radius: 8px; }
.product { font-weight: 700; font-size: 15px; letter-spacing: 0.06em; text-transform: uppercase; }
nav {
  display: flex; gap: 4px; background: var(--fond); padding: 6px 10px; overflow-x: auto;
  scrollbar-width: none; border-bottom: 1px solid var(--trait);
}
nav button {
  border: 1px solid transparent; border-radius: 999px; background: none; color: var(--gris);
  padding: 6px 14px; font-weight: 600; font-size: 13px; white-space: nowrap;
}
nav button:hover { color: var(--texte); background: rgba(56, 198, 255, 0.1); border-color: transparent; }
nav button[aria-current] {
  color: #03241a; background: var(--menthe); box-shadow: 0 0 16px rgba(47, 230, 163, 0.45);
}
nav .count { background: var(--rouge); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 4px; }
main { flex: 1; position: relative; min-height: 0; display: flex; }
#map { position: absolute; inset: 0; background: var(--fond); }
#panel {
  position: absolute; z-index: 500; top: 12px; left: 12px; bottom: 12px; width: 340px; display: flex; flex-direction: column;
  background: var(--verre); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--trait-fort); border-radius: 16px; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}
#panel-body { flex: 1; overflow-y: auto; padding: 12px; }
.handle { display: none; }
#page { flex: 1; overflow: auto; padding: 18px; }
.scroll { overflow-x: auto; border: 1px solid var(--trait); border-radius: 12px; }
footer {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  padding: 5px 14px; background: var(--verre-fort); border-top: 1px solid var(--trait);
  font-size: 12px; color: var(--gris);
}
footer #coords, footer #clock { font-family: var(--mono); }
.moving { color: var(--menthe); } .stopped { color: var(--arret); }
.offline { color: var(--ambre); } .alert { color: var(--rouge); }

/* Compteurs vivants au-dessus de la carte */
#hud { position: absolute; z-index: 500; top: 12px; right: 12px; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  display: grid; justify-items: start; gap: 0; min-width: 92px; padding: 8px 12px; border-radius: 14px;
  background: var(--verre); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--trait-fort); text-align: left;
}
.chip b { font: 500 24px/1.1 var(--mono); }
.chip em { font-style: normal; }
.chip span { font-size: 11px; color: var(--gris); text-transform: uppercase; letter-spacing: 0.08em; }
.chip.moving b { color: var(--menthe); } .chip.stopped b { color: var(--arret); }
.chip.offline b { color: var(--ambre); } .chip.alerts b { color: var(--rouge); }
.chip.on { border-color: var(--menthe); box-shadow: 0 0 18px rgba(47, 230, 163, 0.4); background: rgba(47, 230, 163, 0.14); }
.chip.tick b { animation: tick 0.6s ease-out; }
@keyframes tick { from { transform: scale(1.35); filter: brightness(1.8); } to { transform: none; filter: none; } }

/* Liste des unités */
.units { margin: 10px -12px; border-top: 1px solid var(--trait); }
.unit {
  display: grid; grid-template-columns: 16px 20px minmax(0, 1fr) 56px 20px 20px 20px 22px 22px; gap: 4px;
  align-items: center; padding: 3px 10px; border-bottom: 1px solid var(--trait); min-height: 32px;
  transition: background 0.15s;
}
.unit:not(.head):hover { background: rgba(56, 198, 255, 0.08); }
.unit.head { color: var(--gris); font-size: 12px; background: rgba(4, 14, 26, 0.5); }
.unit.on { background: rgba(47, 230, 163, 0.14); box-shadow: inset 3px 0 0 var(--menthe); }
.unit input { margin: 0; accent-color: var(--menthe); }
.unit .ti { font-size: 17px; }
.unit .name {
  border: 0; background: none; padding: 2px 0; text-align: left; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; box-shadow: none;
}
.unit .name:hover { color: var(--menthe); background: none; }
.unit .speed { text-align: right; font: 12px var(--mono); color: var(--gris); }
.unit .speed.alert { color: var(--rouge); font-weight: 500; }
.unit .tool { border: 0; background: none; padding: 2px; color: var(--gris); line-height: 1; }
.unit .tool:hover { color: var(--texte); background: none; }
.unit .tool.danger:hover { color: var(--rouge); }
.card { border: 1px solid var(--trait); border-radius: 12px; padding: 10px; margin-top: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.row > input, .row > select { flex: 1; }

/* Carte de nuit : les tuiles OpenStreetMap sont assombries par le navigateur. */
#map:not(.carte-sombre) .leaflet-tile-pane { filter: invert(1) hue-rotate(195deg) brightness(0.82) contrast(0.92) saturate(0.55); }
.leaflet-container { background: var(--fond); font: inherit; }
.leaflet-bar, .leaflet-bar a {
  background: var(--verre-fort); color: var(--texte); border-color: var(--trait-fort);
}
.leaflet-bar { border: 1px solid var(--trait-fort) !important; border-radius: 10px; overflow: hidden; }
.leaflet-bar a:hover { background: rgba(56, 198, 255, 0.2); color: var(--texte); }
.leaflet-control-attribution { background: rgba(4, 11, 21, 0.75) !important; color: var(--gris); }
.leaflet-control-attribution a { color: var(--cyan); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--verre-fort); color: var(--texte); border: 1px solid var(--trait-fort);
  box-shadow: 0 0 30px rgba(56, 198, 255, 0.25);
}
.leaflet-popup-content-wrapper { border-radius: 14px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--gris); }
.leaflet-tooltip { background: var(--verre-fort); color: var(--texte); border: 1px solid var(--trait-fort); box-shadow: none; }
.leaflet-tooltip::before { display: none; }
path.glow { filter: drop-shadow(0 0 5px rgba(56, 198, 255, 0.9)); }
path.glow-menthe { filter: drop-shadow(0 0 6px rgba(47, 230, 163, 0.95)); }

/* Véhicules sur la carte : ils glissent d'une position à la suivante. */
#map:not(.leaflet-zoom-anim):not(.nomove) .veh-wrap,
#map:not(.leaflet-zoom-anim):not(.nomove) .leaflet-popup { transition: transform 5s linear; }
.veh { position: relative; width: 30px; height: 30px; --c: var(--arret); transition: opacity 0.3s; }
.veh.moving { --c: var(--menthe); } .veh.offline { --c: var(--ambre); } .veh.alert { --c: var(--rouge); }
.veh.dim { opacity: 0.25; }
.veh .core {
  position: absolute; inset: 0; border-radius: 50%; display: grid; place-items: center;
  background: #061423; border: 2px solid var(--c); color: var(--c); font-size: 16px;
  box-shadow: 0 0 12px var(--c), inset 0 0 8px rgba(0, 0, 0, 0.6);
}
.veh.moving::before, .veh.alert::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--c);
}
.veh .dir { position: absolute; inset: -9px; pointer-events: none; }
.veh .dir::after {
  content: ""; position: absolute; top: 0; left: 50%; margin-left: -5px;
  border: 5px solid transparent; border-top-width: 0; border-bottom: 8px solid var(--c);
  filter: drop-shadow(0 0 3px var(--c));
}
.veh.sel .core { background: var(--c); color: #061423; box-shadow: 0 0 22px var(--c); }
.veh .name {
  position: absolute; top: 34px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  font: 500 11px var(--mono); color: var(--texte); background: rgba(4, 11, 21, 0.78);
  border: 1px solid var(--trait); border-radius: 6px; padding: 0 5px;
}
.veh.sel .name { border-color: var(--c); color: var(--c); }
#map.nonames .veh .name { display: none; }
.ghost {
  width: 18px; height: 18px; border-radius: 50%; background: var(--menthe); border: 3px solid #061423;
  box-shadow: 0 0 0 2px var(--menthe), 0 0 20px var(--menthe);
}
@media (prefers-reduced-motion: no-preference) {
  .veh.moving::before { animation: onde 2s ease-out infinite; }
  .veh.alert::before { animation: onde 0.9s ease-out infinite; }
}
@keyframes onde { from { transform: scale(1); opacity: 0.9; } to { transform: scale(2.3); opacity: 0; } }
.tools a { display: grid; place-items: center; font-size: 17px; }
.tools a.off { color: #4d6176; }
.pop { font: 13px/1.5 "Plus Jakarta Sans", sans-serif; }
.pop b { display: block; font-size: 14px; color: var(--menthe); }

/* Relecture d'un trajet */
.player { border: 1px solid var(--trait-fort); border-radius: 12px; padding: 10px; margin: 10px 0; background: rgba(4, 14, 26, 0.5); }
.player .row { margin-bottom: 6px; }
.player input[type="range"] { width: 100%; }
.player .row > select { flex: 0 0 104px; }
.player .mono { flex-basis: 100%; color: var(--menthe); }

/* Chiffres et tableaux */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 10px 0; }
.figures div { background: rgba(56, 198, 255, 0.07); border: 1px solid var(--trait); border-radius: 12px; padding: 8px 10px; }
.figures span { display: block; font-size: 11px; color: var(--gris); text-transform: uppercase; letter-spacing: 0.06em; }
.figures b { font: 500 17px var(--mono); color: var(--cyan); }
table { border-collapse: collapse; width: 100%; background: var(--verre); }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--trait); }
th { font-size: 11px; color: var(--gris); font-weight: 600; background: rgba(4, 14, 26, 0.6); text-transform: uppercase; letter-spacing: 0.06em; }
tbody tr { transition: background 0.15s; }
tbody tr:hover { background: rgba(56, 198, 255, 0.08); }
td.num, th.num { text-align: right; font-family: var(--mono); }
tfoot td { font-weight: 600; color: var(--menthe); }
.list button { width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--trait); border-radius: 0; background: none; }
.list button:hover { background: rgba(56, 198, 255, 0.12); color: var(--cyan); }

/* Fenêtre de saisie */
dialog {
  border: 1px solid var(--trait-fort); border-radius: 16px; padding: 22px; width: min(390px, calc(100% - 32px));
  background: var(--verre-fort); color: var(--texte); box-shadow: 0 0 60px rgba(56, 198, 255, 0.2);
}
dialog::backdrop { background: rgba(2, 6, 12, 0.7); backdrop-filter: blur(3px); }
dialog form { display: grid; gap: 10px; }
dialog label { display: grid; gap: 4px; font-weight: 500; color: var(--gris); }
dialog .row { justify-content: flex-end; margin: 6px 0 0; }

@media print {
  header, nav, footer, #panel, #map, #hud, dialog, .noprint { display: none !important; }
  html, body, #app { height: auto; background: #fff; color: #000; }
  main { display: block; }
  #page { overflow: visible; padding: 0; }
  h2, td, th, tfoot td { color: #000; }
  table, th { background: #fff; }
  th, td { border-bottom: 1px solid #999; }
}

/* iPhone et téléphones à encoche : l'application installée occupe tout l'écran,
   on laisse la place à l'encoche, aux coins arrondis et à la barre du bas. */
:root {
  --haut: env(safe-area-inset-top, 0px);
  --bas: env(safe-area-inset-bottom, 0px);
  --gauche: env(safe-area-inset-left, 0px);
  --droite: env(safe-area-inset-right, 0px);
}
html, body { overscroll-behavior: none; }
#app { height: 100vh; height: 100dvh; }
header { padding-top: calc(6px + var(--haut)); padding-left: calc(14px + var(--gauche)); padding-right: calc(14px + var(--droite)); }
nav { padding-left: calc(10px + var(--gauche)); padding-right: calc(10px + var(--droite)); }
footer { padding-bottom: calc(5px + var(--bas)); padding-left: calc(14px + var(--gauche)); padding-right: calc(14px + var(--droite)); }
#login { margin-top: calc(8vh + var(--haut)); }
#map { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
button, nav button, .chip { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

@media (max-width: 760px) {
  body { overflow-x: hidden; }
  /* Safari zoome sur un champ dont le texte fait moins de 16 px : on l'évite. */
  input, select, textarea { font-size: 16px; }
  header { gap: 8px; padding: calc(6px + var(--haut)) calc(10px + var(--droite)) 6px calc(10px + var(--gauche)); }
  header img { height: 32px; }
  header .product, #user, #logout span { display: none; }
  #demo { font-size: 0; padding: 2px 10px; }
  #demo::after { content: "Démo"; font-size: 12px; }
  #client { min-width: 0; flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; }
  #client select { max-width: 100%; }
  nav { padding: 6px; }
  nav button { padding: 8px 12px; }

  #hud { left: calc(8px + var(--gauche)); right: calc(8px + var(--droite)); top: 8px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .chip { min-width: 0; padding: 6px 8px; border-radius: 12px; }
  .chip b { font-size: 19px; }
  .chip span { letter-spacing: 0; text-transform: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .chip em { display: none; }

  /* Le panneau devient une feuille en bas de l'écran, repliable. */
  #panel { top: auto; left: calc(8px + var(--gauche)); right: calc(8px + var(--droite)); bottom: 8px; width: auto; max-height: 45%; }
  .handle {
    display: block; width: 100%; border: 0; border-bottom: 1px solid var(--trait); border-radius: 0;
    background: rgba(4, 14, 26, 0.6); color: var(--gris); padding: 9px; font-size: 13px;
  }
  #panel.closed #panel-body { display: none; }
  #panel.closed .handle { border-bottom: 0; }
  .unit { min-height: 42px; }
  .unit .tool { padding: 6px 2px; }

  /* Les boutons de la carte restent au-dessus de la feuille. */
  .leaflet-control-zoom { display: none; }
  .leaflet-bottom { bottom: 47%; }
  main:has(#panel.closed) .leaflet-bottom, main:has(#panel[hidden]) .leaflet-bottom { bottom: 56px; }

  #page { padding: 10px calc(10px + var(--droite)) 10px calc(10px + var(--gauche)); }
  .scroll th, .scroll td { white-space: nowrap; }
  dialog { padding: 16px; }
}
