:root {
  --fond: #f4f6f6;
  --carte: #ffffff;
  --encre: #0e1419;
  --encre-2: #4a5557;
  --encre-3: #6f7b7e;
  --trait: #dfe5e6;
  --accent: #007490;
  --sur-accent: #ffffff;
  --relance: #9a5800;
  --relance-fond: #fff3e0;
  --porte-fond: #e3f3f6;
  --ok: #1d7a46;
  --ok-fond: #e2f4e9;
  --chaud: #b3261e;
  --chaud-fond: #fde8e6;
  --neutre-fond: #eceff0;
  --attente: #8a6d00;
  --attente-fond: #fff6cc;
  --ombre: 0 1px 2px rgba(14, 20, 25, .06), 0 2px 8px rgba(14, 20, 25, .05);
  --rayon: 14px;
  --haut: env(safe-area-inset-top, 0px);
  --bas: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #0b1013;
    --carte: #141c21;
    --encre: #eef3f4;
    --encre-2: #b3bfc3;
    --encre-3: #84939a;
    --trait: #26323a;
    --accent: #3ccfea;
    --sur-accent: #06212a;
    --relance: #ffb547;
    --relance-fond: #2e2210;
    --porte-fond: #0f2a31;
    --ok: #6fd99a;
    --ok-fond: #12301f;
    --chaud: #ff8a80;
    --chaud-fond: #3a1714;
    --neutre-fond: #1d272d;
    --attente: #ffd75e;
    --attente-fond: #2f2a10;
    --ombre: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --fond: #0b1013;
  --carte: #141c21;
  --encre: #eef3f4;
  --encre-2: #b3bfc3;
  --encre-3: #84939a;
  --trait: #26323a;
  --accent: #3ccfea;
  --sur-accent: #06212a;
  --relance: #ffb547;
  --relance-fond: #2e2210;
  --porte-fond: #0f2a31;
  --ok: #6fd99a;
  --ok-fond: #12301f;
  --chaud: #ff8a80;
  --chaud-fond: #3a1714;
  --neutre-fond: #1d272d;
  --attente: #ffd75e;
  --attente-fond: #2f2a10;
  --ombre: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--fond);
  color: var(--encre);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: clip;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muet { color: var(--encre-3); }
.petit { font-size: 13px; }

/* ── Barre du haut ─────────────────────────────────────────── */
.barre {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--haut)) 12px 10px;
  background: var(--encre); color: #fff;
}
:root[data-theme="dark"] .barre { background: #050809; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .barre { background: #050809; } }
.barre h1 { font-size: 17px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barre .sous { display: block; font-size: 12px; font-weight: 400; opacity: .7; }
.btn-barre {
  min-width: 40px; height: 40px; padding: 0 10px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.18); background: transparent; color: #fff;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 14px;
}
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; opacity: .9; }
.sync i { width: 9px; height: 9px; border-radius: 50%; background: #6fd99a; display: inline-block; }
.sync.attente i { background: #ffd75e; }
.sync.horsligne i { background: #ff8a80; }

main { padding: 12px 12px calc(96px + var(--bas)); max-width: 720px; margin: 0 auto; }

/* ── Compteurs ─────────────────────────────────────────────── */
.compteurs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.compteur { background: var(--carte); border-radius: 12px; padding: 8px 6px; text-align: center; box-shadow: var(--ombre); border: 1px solid var(--trait); }
.compteur b { display: block; font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.compteur span { font-size: 11px; color: var(--encre-3); }

.filtres { display: flex; gap: 6px; margin: 4px 0 10px; overflow-x: auto; scrollbar-width: none; }
.puce {
  flex: none; border: 1px solid var(--trait); background: var(--carte); border-radius: 999px;
  padding: 6px 12px; font-size: 14px;
}
.puce[aria-pressed="true"] { background: var(--encre); color: var(--fond); border-color: var(--encre); }

details.consignes { background: var(--carte); border: 1px solid var(--trait); border-radius: var(--rayon); padding: 10px 12px; margin-bottom: 12px; }
details.consignes summary { font-weight: 600; cursor: pointer; }
details.consignes div { margin-top: 8px; color: var(--encre-2); font-size: 14px; white-space: pre-line; }

/* ── Blocs et arrêts ───────────────────────────────────────── */
.bloc { margin: 18px 0 8px; }
.bloc h2 { font-size: 15px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.bloc h2 small { font-weight: 500; color: var(--encre-3); font-size: 13px; white-space: nowrap; }
.bloc p { margin: 2px 0 0; font-size: 13px; color: var(--encre-3); }

.arret {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: start;
  width: 100%; text-align: left; background: var(--carte); border: 1px solid var(--trait);
  border-radius: var(--rayon); padding: 10px; margin-top: 8px; box-shadow: var(--ombre);
}
.arret.fait { opacity: .62; }
.arret .num {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 14px; background: var(--porte-fond); color: var(--accent);
}
.arret.relance .num { background: var(--relance-fond); color: var(--relance); }
.arret.reserve .num { background: var(--neutre-fond); color: var(--encre-3); }
.arret .nom { font-weight: 650; line-height: 1.25; }
.arret .meta { font-size: 13px; color: var(--encre-3); margin-top: 1px; }
.arret .obj { font-size: 13.5px; color: var(--encre-2); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.arret .droite { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.arret .heure { font-size: 12px; color: var(--encre-3); font-variant-numeric: tabular-nums; }
.etiquette { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .02em; padding: 2px 7px; border-radius: 999px; background: var(--neutre-fond); color: var(--encre-2); white-space: nowrap; }
.etiquette.relance { background: var(--relance-fond); color: var(--relance); }
.etiquette.porte { background: var(--porte-fond); color: var(--accent); }

.statut { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.st-a_faire { background: var(--neutre-fond); color: var(--encre-3); }
.st-interesse, .st-rdv, .st-accord { background: var(--ok-fond); color: var(--ok); }
.st-repasser, .st-absent { background: var(--attente-fond); color: var(--attente); }
.st-ferme { background: var(--neutre-fond); color: var(--encre-2); }
.st-non { background: var(--chaud-fond); color: var(--chaud); }

/* ── Bouton flottant ───────────────────────────────────────── */
.fab {
  position: fixed; right: 16px; bottom: calc(16px + var(--bas)); z-index: 30;
  height: 54px; padding: 0 20px; border-radius: 27px; border: 0;
  background: var(--accent); color: var(--sur-accent); font-weight: 700; font-size: 16px;
  box-shadow: 0 6px 18px rgba(0, 116, 144, .35);
}

/* ── Fiche ─────────────────────────────────────────────────── */
.entete-fiche { margin: 4px 0 12px; }
.entete-fiche h2 { font-size: 22px; }
.entete-fiche .meta { color: var(--encre-3); font-size: 14px; margin-top: 4px; }

.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; margin-bottom: 12px; }
.action {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 56px; padding: 8px; border-radius: 12px; text-decoration: none;
  background: var(--carte); border: 1px solid var(--trait); color: var(--encre); font-size: 13px; font-weight: 600;
}
.action span { font-size: 18px; line-height: 1; }

.statuts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px; }
.statuts button {
  min-height: 48px; padding: 6px 4px; border-radius: 12px; border: 1px solid var(--trait);
  background: var(--carte); font-size: 13px; font-weight: 600; line-height: 1.15;
}
.statuts button[aria-pressed="true"].v { background: var(--ok); border-color: var(--ok); color: #fff; }
.statuts button[aria-pressed="true"].o { background: var(--attente); border-color: var(--attente); color: #fff; }
.statuts button[aria-pressed="true"].r { background: var(--chaud); border-color: var(--chaud); color: #fff; }
.statuts button[aria-pressed="true"].g { background: var(--encre-2); border-color: var(--encre-2); color: var(--fond); }

.encart { background: var(--carte); border: 1px solid var(--trait); border-radius: var(--rayon); padding: 12px; margin-bottom: 12px; box-shadow: var(--ombre); }
.encart h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--encre-3); margin-bottom: 6px; }
.encart.objectif { border-left: 4px solid var(--accent); }
.encart.objectif.relance { border-left-color: var(--relance); }
.encart p { margin: 0 0 6px; }
.encart p:last-child { margin-bottom: 0; }
dl.infos { margin: 0; display: grid; grid-template-columns: 112px 1fr; gap: 6px 10px; font-size: 14.5px; }
dl.infos dt { color: var(--encre-3); }
dl.infos dd { margin: 0; overflow-wrap: anywhere; }
ul.offres { margin: 0; padding-left: 18px; font-size: 14.5px; }
ul.offres li { margin-bottom: 4px; }

/* ── Notes ─────────────────────────────────────────────────── */
.saisie textarea {
  width: 100%; min-height: 84px; resize: vertical; border-radius: 12px; border: 1px solid var(--trait);
  background: var(--fond); padding: 10px; font-size: 16px;
}
.saisie .rangee { display: flex; gap: 8px; margin-top: 8px; }
.btn {
  min-height: 48px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--trait);
  background: var(--carte); font-weight: 650; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.plein { background: var(--accent); border-color: var(--accent); color: var(--sur-accent); }
.btn.large { flex: 1; }
.btn.micro { background: var(--encre); color: var(--fond); border-color: var(--encre); flex: 1.3; }
.btn.micro.enregistre { background: var(--chaud); border-color: var(--chaud); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(179, 38, 30, .18); } }

.note { border-top: 1px solid var(--trait); padding: 10px 0; }
.note:first-of-type { border-top: 0; }
.note .qui { font-size: 12.5px; color: var(--encre-3); display: flex; justify-content: space-between; gap: 8px; }
.note .corps { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.note audio { width: 100%; height: 40px; margin-top: 6px; }
.note .trans { margin-top: 6px; padding: 8px 10px; border-radius: 10px; background: var(--fond); font-size: 14.5px; white-space: pre-wrap; }
.note .outils { display: flex; gap: 12px; margin-top: 6px; }
.note .outils button { border: 0; background: none; padding: 4px 0; color: var(--encre-3); font-size: 13px; text-decoration: underline; }
.note .compte { font-weight: 650; color: var(--encre); }

/* ── Formulaires ───────────────────────────────────────────── */
.champ { display: block; margin-bottom: 12px; }
.champ span { display: block; font-size: 13px; font-weight: 600; color: var(--encre-2); margin-bottom: 4px; }
.champ input, .champ select {
  width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--trait);
  background: var(--carte); padding: 0 12px; font-size: 16px;
}
.connexion { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; }
.connexion h1 { font-size: 26px; margin-bottom: 4px; }
.connexion p { color: var(--encre-3); margin: 0 0 20px; }
.erreur { color: var(--chaud); font-size: 14px; min-height: 20px; }

details.corriger summary { cursor: pointer; color: var(--encre-3); font-size: 14px; }

/* ── Carte ─────────────────────────────────────────────────── */
#carte { position: fixed; left: 0; right: 0; bottom: 0; top: calc(60px + var(--haut)); z-index: 5; background: var(--neutre-fond); }
.repere {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font: 700 12px/1 system-ui, sans-serif; color: #fff; background: #007490; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.repere.relance { background: #9a5800; }
.repere.reserve { background: #6f7b7e; }
.repere.fait { background: #1d7a46; }
.repere.refus { background: #b3261e; }
.moi-point { width: 16px; height: 16px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(26,115,232,.2); }
.leaflet-popup-content { font: 14px/1.4 system-ui, sans-serif; }
.leaflet-popup-content button { margin-top: 6px; }

/* ── Menu ──────────────────────────────────────────────────── */
.voile { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.menu {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--carte);
  border-radius: 18px 18px 0 0; padding: 12px 12px calc(16px + var(--bas)); max-width: 720px; margin: 0 auto;
}
.menu button, .menu a {
  display: block; width: 100%; text-align: left; padding: 14px 12px; border: 0; background: none;
  border-radius: 10px; font-size: 16px; color: var(--encre); text-decoration: none;
}
.menu button:active, .menu a:active { background: var(--neutre-fond); }
.menu hr { border: 0; border-top: 1px solid var(--trait); margin: 6px 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--bas)); transform: translateX(-50%) translateY(20px);
  background: var(--encre); color: var(--fond); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100% - 32px);
}
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.vide { text-align: center; color: var(--encre-3); padding: 32px 12px; }

/* ── Impression : la feuille de route sur papier ───────────── */
@media print {
  .barre, .fab, .filtres, .compteurs, #toast { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  main { padding: 0; max-width: none; }
  details.consignes { border: 0; padding: 0; }
  details.consignes > div { display: block !important; }
  .arret { box-shadow: none; border: 0; border-bottom: 1px solid #bbb; border-radius: 0; break-inside: avoid; padding: 6px 0; }
  .arret .obj { -webkit-line-clamp: unset; display: block; }
  .arret::after { content: "Résultat : ☐ intéressé ☐ RDV ☐ repasser ☐ absent ☐ non   Notes : ________________________"; grid-column: 2 / 4; font-size: 9pt; color: #555; }
}
.saisie .btn { white-space: nowrap; padding: 0 12px; }

/* ── État d'une transcription ──────────────────────────────── */
.etat-trans { display: flex; align-items: center; gap: 8px; margin-top: 6px; padding: 8px 10px; border-radius: 10px; font-size: 14px; }
.etat-trans.actif, .etat-trans.attente { background: var(--porte-fond); color: var(--accent); }
.etat-trans.eteinte { background: var(--neutre-fond); color: var(--encre-2); }
.etat-trans.echec { background: var(--chaud-fond); color: var(--chaud); flex-wrap: wrap; }
.etat-trans.echec .btn { min-height: 36px; }
.etat-trans .rond { flex: none; width: 12px; height: 12px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: tourne .9s linear infinite; }
.etat-trans.attente .rond { animation-duration: 2.4s; opacity: .7; }
@keyframes tourne { to { transform: rotate(360deg); } }
.tour-etat { float: right; font-size: 12px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--encre-3); }
.tour-etat.on { color: var(--ok); }
