:root {
  --fond: #f1f4f8;
  --carte: #ffffff;
  --texte: #1d2733;
  --gris: #6b7785;
  --bord: #dde3ea;
  --marine: #16324f;
  --bleu: #1c7ed6;
  --vert: #2f9e44;
  --orange: #f08c00;
  --rouge: #e03131;
  --rayon: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fond); color: var(--texte); font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}
#app { min-height: 100%; display: flex; flex-direction: column; }
main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
h1, h2, h3 { margin: 0 0 10px; }
h3 { font-size: 15px; margin-top: 14px; }
.centre { text-align: center; padding: 40px 16px; color: var(--gris); }
.aide { color: var(--gris); font-size: 13px; margin: 6px 0; }

/* ---------- Boutons et champs ---------- */
button, .btn {
  font: inherit; font-weight: 600; border: 1px solid var(--bord); background: var(--carte); color: var(--texte);
  border-radius: 10px; padding: 9px 13px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
button:disabled { opacity: .4; cursor: default; }
button.vert, .btn.vert { background: var(--vert); border-color: var(--vert); color: #fff; }
button.rouge { background: var(--rouge); border-color: var(--rouge); color: #fff; }
button.orange, .btn.orange { background: var(--orange); border-color: var(--orange); color: #fff; }
button.actif { background: var(--marine); border-color: var(--marine); color: #fff; }
button.gros { width: 100%; padding: 16px; font-size: 17px; border-radius: var(--rayon); border: none; }
button.mini { padding: 4px 9px; }
button.lien { background: transparent; border: none; color: #fff; padding: 6px 8px; font-weight: 500; }
input, select, textarea {
  font: inherit; padding: 9px 10px; border: 1px solid var(--bord); border-radius: 10px; background: #fff; width: 100%;
  color: var(--texte);
}
label { display: block; font-size: 13px; color: var(--gris); margin-top: 8px; }
label > input, label > select, label > textarea { margin-top: 4px; }
label.case { display: flex; align-items: center; gap: 8px; color: var(--texte); }
label.case input { width: auto; margin: 0; }
.rangee { display: flex; gap: 8px; align-items: flex-end; margin-top: 8px; }
.rangee > label { flex: 1; margin-top: 0; }
.rangee > input[type=search] { flex: 1; }
.rangee.wrap { flex-wrap: wrap; }
.grandit { flex: 1; min-width: 0; }

/* ---------- En-tête ---------- */
.entete {
  background: var(--marine); color: #fff; display: flex; align-items: center; gap: 6px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  position: sticky; top: 0; z-index: 1000;
}
.entete .logo { font-weight: 800; font-size: 17px; }
.entete .qui { flex: 1; text-align: right; opacity: .8; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Connexion ---------- */
.connexion { max-width: 380px; margin: auto; padding: 40px 20px; text-align: center; width: 100%; }
.connexion .logo-grand { font-size: 64px; }
.connexion form { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.connexion input { padding: 14px; font-size: 16px; }

/* ---------- Carte ---------- */
.carte { min-height: 300px; border-radius: var(--rayon); overflow: hidden; background: #dfe6ee; }
.pin {
  width: 28px; height: 28px; border-radius: 50%; border: 3px solid #fff; color: #fff; font-weight: 800; font-size: 12px;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 5px rgba(0,0,0,.45);
}
.pin.gros { width: 36px; height: 36px; font-size: 15px; box-shadow: 0 0 0 4px rgba(28,126,214,.35), 0 1px 5px rgba(0,0,0,.45); }

/* ---------- Vue Terrain (téléphone) ---------- */
.op { max-width: 640px; margin: 0 auto; width: 100%; padding: 12px; padding-bottom: max(24px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.op .rangee { margin-top: 0; align-items: center; }
.op select { flex: 1; font-size: 16px; padding: 12px; font-weight: 600; }
.compteur { font-weight: 700; color: var(--marine); white-space: nowrap; }
.etat { font-size: 13px; color: var(--gris); text-align: center; }
.carte-op { height: 38vh; min-height: 220px; }
.liste { display: flex; flex-direction: column; gap: 10px; }
.arret { background: var(--carte); border-radius: var(--rayon); padding: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); border-left: 5px solid var(--gris); }
.arret.encours { border-left-color: var(--orange); }
.arret.fait { border-left-color: var(--vert); opacity: .65; }
.arret.prochain { box-shadow: 0 0 0 2px var(--bleu), 0 4px 14px rgba(28,126,214,.2); }
.arret-tete { display: flex; gap: 10px; align-items: flex-start; }
.arret-info { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.arret-info b { font-size: 16px; }
.arret-info small { color: var(--gris); }
.arret-info .note { color: #8a5a00; }
.num { min-width: 30px; height: 30px; border-radius: 50%; color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 20px; background: #eef1f4; color: var(--gris); white-space: nowrap; }
.badge.encours { background: #fff1db; color: #a65f00; }
.badge.fait { background: #e3f6e7; color: #1f7a33; }
.arret-actions { display: flex; gap: 6px; margin-top: 10px; }
.arret-actions > * { flex: 1; padding: 11px 6px; }
.arret.fait .arret-actions .btn:not(:last-child) { display: none; }

/* ---------- Vue Bureau (ordinateur) ---------- */
.onglets { display: flex; gap: 4px; padding: 8px 12px 0; background: var(--marine); overflow-x: auto; }
.onglets button { border: none; border-radius: 10px 10px 0 0; background: rgba(255,255,255,.12); color: #fff; }
.onglets button.actif { background: var(--fond); color: var(--texte); }
.panneau { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.split { flex: 1; display: grid; grid-template-columns: 1fr 400px; gap: 12px; padding: 12px; min-height: 0; height: calc(100vh - 110px); }
.split .carte { height: 100%; }
.cote { background: var(--carte); border-radius: var(--rayon); padding: 14px; overflow-y: auto; }
.formulaire { background: #f7f9fb; border: 1px solid var(--bord); border-radius: 12px; padding: 12px; margin: 10px 0; }
.formulaire:empty { display: none; }
.liste-bureau { display: flex; flex-direction: column; }
.ligne { display: flex; flex-direction: column; gap: 2px; padding: 9px 4px; border-bottom: 1px solid var(--bord); cursor: pointer; }
.ligne:hover { background: #f5f8fb; }
.ligne small { color: var(--gris); }
.ligne.inactif { opacity: .5; }
.ligne.arret-route { flex-direction: row; align-items: center; gap: 8px; cursor: default; }
.barre-prog { height: 12px; background: #e9edf1; border-radius: 6px; overflow: hidden; display: flex; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; text-align: center; }
.stats div { background: #f5f8fb; border-radius: 10px; padding: 10px; display: flex; flex-direction: column; }
.stats b { font-size: 24px; }
.stats small { color: var(--gris); }
.page { padding: 16px; max-width: 1200px; width: 100%; margin: 0 auto; }
.filtres label { flex: 0 1 200px; }
.tableau-wrap { overflow-x: auto; background: var(--carte); border-radius: var(--rayon); margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--bord); white-space: nowrap; }
th { background: #f5f8fb; font-size: 12px; text-transform: uppercase; color: var(--gris); }
td input, td select { min-width: 160px; }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; height: auto; }
  .split .carte { height: 50vh; }
}

/* ---------- Assistant IA ---------- */
.ia { display: flex; flex-direction: column; height: calc(100vh - 110px); }
.ia .rangee label { flex: 0 1 260px; }
.ia-fil { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 12px 0; }
.ia-bulle { max-width: 80%; padding: 10px 14px; border-radius: 14px; line-height: 1.45; }
.ia-bulle.moi { align-self: flex-end; background: var(--marine); color: #fff; white-space: pre-wrap; }
.ia-bulle.ia { align-self: flex-start; background: var(--carte); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.ia-bulle.erreur { background: #fff0f0; color: var(--rouge); }
.ia-texte p, .ia-texte li { margin: 0 0 6px; }
.ia-texte li { margin-left: 18px; }
.ia-texte .titre { font-weight: 700; margin-top: 8px; }
.ia-accueil button.mini { white-space: normal; text-align: left; padding: 8px 10px; font-weight: 500; }
.ia-saisie { display: flex; gap: 8px; align-items: flex-end; }
.ia-saisie textarea { flex: 1; resize: vertical; }

/* ---------- Indicateur réseau (terrain) ---------- */
.reseau { font-size: 13px; font-weight: 600; text-align: center; padding: 8px 10px; border-radius: 10px; }
.reseau.ok { background: #e3f6e7; color: #1f7a33; }
.reseau.attente { background: #fff1db; color: #a65f00; }
.reseau.horsligne { background: #ffe3e3; color: #b42318; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #1d2733; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; z-index: 5000;
  opacity: 0; pointer-events: none; transition: .25s; max-width: 90vw; text-align: center;
}
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.connexion button.oubli { background: none; border: none; color: #2563eb; margin-top: 14px; font-size: 14px; text-decoration: underline; }
