/* Où est le bus ? — feuille de style
 * Le tableau reprend le registre des tableaux de départ suisses : fond bleu nuit,
 * texte blanc, retards en jaune notés +3'. La carte reste sobre (fond gris swisstopo)
 * pour que les véhicules ressortent. */

@font-face {
  font-family: 'Atkinson Hyperlegible Next';
  src: url('polices/atkinson-hyperlegible-next-latin-400-normal.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Atkinson Hyperlegible Next';
  src: url('polices/atkinson-hyperlegible-next-latin-700-normal.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Atkinson Hyperlegible Next';
  src: url('polices/atkinson-hyperlegible-next-latin-ext-400-normal.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+20A0-20AB, U+20AD-20C0, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Atkinson Hyperlegible Next';
  src: url('polices/atkinson-hyperlegible-next-latin-ext-700-normal.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+20A0-20AB, U+20AD-20C0, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --nuit: #1c2d5a;          /* fond du tableau */
  --nuit-clair: #2a3f7a;    /* survol et éléments actifs */
  --blanc: #ffffff;
  --doux: #b9c3df;          /* texte secondaire sur fond nuit */
  --filet: rgba(255, 255, 255, 0.16);
  --jaune: #ffd84d;         /* retards */
  --rouge-clair: #ff9c94;   /* suppressions, alertes */
  --gris-carte: #e6e8eb;
  --bas: 0px;               /* hauteur du tableau sur téléphone (réglée par app.js) */
  --police: 'Atkinson Hyperlegible Next', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--police);
  font-size: 16px;
  line-height: 1.45;
  background: var(--gris-carte);
  color: #17203a;
}

#carte { position: fixed; inset: 0; background: var(--gris-carte); }
.leaflet-container { font-family: var(--police); }
.leaflet-bottom { bottom: var(--bas); }

/* ---- Tableau ---------------------------------------------------------- */

.tableau {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 1000;
  width: 352px;
  max-height: calc(100% - 32px);
  display: flex;
  flex-direction: column;
  background: var(--nuit);
  color: var(--blanc);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(16, 26, 56, 0.38);
  overflow: hidden;
}

.tableau-tete {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
}

h1 {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.lieu { margin: 4px 0 0; color: var(--doux); font-size: 0.95rem; }

.tableau-corps {
  overflow-y: auto;
  padding: 0 20px 16px;
  overscroll-behavior: contain;
}

.tableau.replie .tableau-corps { display: none; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid var(--jaune);
  outline-offset: 2px;
}

.replier,
.retour {
  background: transparent;
  border: 1px solid var(--filet);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.85rem;
  color: var(--doux);
  white-space: nowrap;
}
.replier:hover, .retour:hover { background: var(--nuit-clair); color: var(--blanc); }

.retour { margin: 2px 0 14px; }

.compte {
  margin: 0;
  padding-top: 14px;
  border-top: 1px solid var(--filet);
  font-size: 1.15rem;
  font-weight: 700;
}

.statut { margin: 2px 0 16px; color: var(--doux); font-size: 0.9rem; min-height: 1.3em; }
.statut.alerte { color: var(--rouge-clair); }

.filtres { display: flex; gap: 8px; margin-bottom: 12px; }

.filtre {
  flex: 1;
  padding: 7px 0;
  border-radius: 8px;
  border: 1px solid var(--filet);
  background: transparent;
  color: var(--doux);
  font-weight: 700;
}
.filtre[aria-pressed="true"] { background: var(--blanc); color: var(--nuit); border-color: var(--blanc); }

.choix-ligne {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  color: var(--doux);
  font-size: 0.9rem;
}
.choix-ligne select {
  flex: 1;
  font: inherit;
  font-size: 1rem;
  color: var(--blanc);
  background: var(--nuit-clair);
  border: 1px solid var(--filet);
  border-radius: 8px;
  padding: 6px 8px;
}

.legende {
  list-style: none;
  margin: 0 0 12px;
  padding: 12px 0 0;
  border-top: 1px solid var(--filet);
  display: grid;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--doux);
}
.legende li { display: grid; grid-template-columns: 3.4rem 1fr; align-items: center; }
.legende .pastille, .legende .badge-retard { justify-self: start; }

.curseur input[type="range"] { flex: 1; accent-color: var(--jaune); min-width: 0; }
.curseur output { min-width: 3.2rem; text-align: right; color: var(--blanc); font-variant-numeric: tabular-nums; }

.aide a, .operateur a { color: var(--blanc); }

.aide, .note { color: var(--doux); font-size: 0.85rem; margin: 0 0 10px; }
.note { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--filet); }

/* ---- Pastilles de ligne (carte et tableau) ---------------------------- */

.pastille {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-width: 2rem;
  height: 1.5rem;
  padding: 0 0.4rem;
  border-radius: 0.5rem;
  border: 2px solid var(--blanc);
  background: var(--c);
  color: var(--t, var(--blanc));
  font-weight: 700;
  font-size: 0.8rem;
  line-height: 1;
  white-space: nowrap;
}
.pastille.cat-train { border-radius: 0.15rem; }       /* rectangle des catégories de train */
/* Horaire seul : fond blanc, contour pointillé à la couleur de la ligne (lisible même en jaune) */
.pastille.theorique {
  background: var(--blanc);
  color: #17203a;
  border: 3px dashed var(--c);
}

.badge-retard {
  display: inline-block;
  padding: 0.1rem 0.3rem;
  border-radius: 0.3rem;
  background: var(--jaune);
  color: var(--nuit);
  font-weight: 700;
  font-size: 0.78rem;
  line-height: 1.2;
  white-space: nowrap;
}

/* Marqueurs sur la carte : la pastille est centrée sur la position */
.vehicule { width: 0; height: 0; }
.vehicule .pastille {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 4px rgba(16, 26, 56, 0.45);
}
.vehicule .badge-retard {
  position: absolute;
  top: -0.85rem;
  right: -1rem;
  font-size: 0.7rem;
  box-shadow: 0 1px 3px rgba(16, 26, 56, 0.35);
}
.vehicule:focus { outline: none; }
.vehicule:focus-visible .pastille { outline: 3px solid var(--jaune); outline-offset: 2px; }

.mise-en-avant .vehicule:not(.choisi) { opacity: 0.32; }
.vehicule.choisi .pastille {
  transform: translate(-50%, -50%) scale(1.2);
  box-shadow: 0 0 0 3px var(--nuit), 0 2px 8px rgba(16, 26, 56, 0.5);
}

/* ---- Détail : course ou arrêt ----------------------------------------- */

.titre-detail {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 1.3rem;
  line-height: 1.2;
}
.titre-detail .pastille { flex: none; font-size: 0.9rem; height: 1.7rem; }

.operateur { margin: 4px 0 0; color: var(--doux); font-size: 0.9rem; }
.etat-course { margin: 8px 0 12px; font-weight: 700; }
.etat-course:empty { display: none; }

.liste-arrets {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}
.liste-arrets li {
  display: grid;
  grid-template-columns: 3.2rem 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 8px 0 8px 10px;
  border-top: 1px solid var(--filet);
  border-left: 3px solid transparent;
}
.liste-arrets .heure { font-weight: 700; font-variant-numeric: tabular-nums; }
.liste-arrets .nom { min-width: 0; overflow-wrap: anywhere; }
.liste-arrets .nom .pastille { margin-right: 4px; font-size: 0.75rem; height: 1.35rem; min-width: 1.8rem; vertical-align: 0.1em; }
.liste-arrets li.passe { color: var(--doux); opacity: 0.55; }
.liste-arrets li.actuel { border-left-color: var(--jaune); background: rgba(255, 255, 255, 0.06); }
.liste-arrets li.annule .heure, .liste-arrets li.annule .nom { text-decoration: line-through; color: var(--doux); }
.supprime { color: var(--rouge-clair); font-weight: 700; font-size: 0.85rem; }
.quai { display: inline-block; margin-left: 6px; color: var(--doux); font-size: 0.82rem; white-space: nowrap; }

.intertitre { margin: 20px 0 0; font-size: 1rem; font-weight: 700; }
.resume { margin: 4px 0 0; color: var(--doux); font-size: 0.9rem; }

/* Statistiques du jour par ligne et direction */
.stats { width: 100%; margin-top: 8px; border-collapse: collapse; font-size: 0.88rem; }
.stats th { text-align: left; font-weight: 400; color: var(--doux); padding: 4px 6px 6px 0; }
.stats td { padding: 6px 6px 6px 0; border-top: 1px solid var(--filet); vertical-align: baseline; }
.stats .nombre { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats td:last-child, .stats th:last-child { padding-right: 0; }
.stats .pastille { font-size: 0.72rem; height: 1.3rem; min-width: 1.8rem; }

/* Histogramme des départs par heure : une série, barres fines arrondies en haut */
.histogramme { margin: 16px 0 0; }
.histogramme figcaption { color: var(--doux); font-size: 0.85rem; margin-bottom: 6px; }
.barres { display: flex; align-items: flex-end; gap: 2px; height: 72px; border-bottom: 1px solid var(--filet); }
.barre { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.barre span { display: block; width: 100%; background: var(--doux); border-radius: 3px 3px 0 0; }
.barre.en-cours span { background: var(--jaune); }
.barre:hover span { background: var(--blanc); }
.reperes { display: flex; gap: 2px; margin-top: 4px; font-size: 0.7rem; color: var(--doux); }
.reperes span { flex: 1; white-space: nowrap; overflow: visible; }
.vide { color: var(--doux); margin: 12px 0 0; }

/* ---- Contrôles Leaflet accordés au tableau ---------------------------- */

.leaflet-control-zoom a,
.leaflet-control-layers-toggle { border-radius: 8px; }
.leaflet-bar { border: none; box-shadow: 0 2px 8px rgba(16, 26, 56, 0.3); border-radius: 8px; }
.leaflet-control-layers { border: none; box-shadow: 0 2px 8px rgba(16, 26, 56, 0.3); border-radius: 8px; font-size: 0.95rem; }
.leaflet-tooltip { font-family: var(--police); font-weight: 700; color: var(--nuit); }
path.leaflet-interactive:focus:not(:focus-visible) { outline: none; }

/* ---- Téléphone : le tableau devient un panneau en bas de l'écran ------ */

@media (max-width: 640px) {
  .tableau {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 55%;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tableau-tete { padding: 14px 16px 10px; }
  h1 { font-size: 1.45rem; }
  .tableau-corps { padding: 0 16px 12px; }
  .legende, .aide, .note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
