/* ============ Thèmes ============ */
:root, [data-theme="clair"] {
  --fond: #f4f4f2; --surface: #ffffff; --surface2: #f0efec; --texte: #1d1f23; --texte2: #5f6368; --bord: #dedcd6;
  --accent: #b71c1c; --accent-texte: #ffffff; --ombre: 0 2px 10px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --vert: #1e8e3e; --rouge: #d93025; --orange: #f29900; --gris: #8a8f98; --bleu: #1565c0;
}
[data-theme="sombre"] {
  --fond: #121316; --surface: #1d1f24; --surface2: #262830; --texte: #ececec; --texte2: #a4a8b0; --bord: #33363e;
  --accent: #ef5350; --accent-texte: #ffffff; --ombre: 0 2px 12px rgba(0,0,0,.5);
}
[data-theme="sombre"] .maplibregl-canvas { filter: brightness(.82) contrast(1.05); }

* { 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; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: .2em 0 .4em; } h2 { font-size: 1.15rem; margin: 1.4em 0 .6em; } h3 { font-size: 1rem; margin: .2em 0 .6em; }
.sous-titre { color: var(--texte2); margin: -.2em 0 1em; }
.aide { color: var(--texte2); font-size: .88rem; }
.vide { color: var(--texte2); font-style: italic; }
small { color: var(--texte2); }
.chargement { display: grid; place-items: center; height: 100vh; color: var(--texte2); }

/* ============ Boutons & formulaires ============ */
.btn { font: inherit; border: 1px solid var(--bord); background: var(--surface); color: var(--texte); padding: .6em 1em; border-radius: 10px;
  cursor: pointer; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4em; min-height: 42px; }
.btn:hover { filter: brightness(.97); } .btn:disabled { opacity: .5; cursor: default; }
.btn.primaire { background: var(--accent); color: var(--accent-texte); border-color: transparent; }
.btn.danger { color: var(--rouge); border-color: color-mix(in srgb, var(--rouge) 40%, transparent); }
.btn.danger:not(.petit) { background: var(--rouge); color: #fff; }
.btn.vendu { background: var(--vert); color: #fff; border-color: transparent; width: 100%; min-height: 50px; font-size: 1.05rem; }
.btn.statut { border: 2px solid var(--c); color: var(--c); background: color-mix(in srgb, var(--c) 8%, var(--surface)); flex: 1; min-height: 48px; }
.btn.petit { padding: .3em .7em; min-height: 32px; font-size: .85rem; border-radius: 8px; }
.btn.large { width: 100%; min-height: 50px; margin: .5em 0; }
.btn.rond { border-radius: 999px; box-shadow: var(--ombre); }
.lien { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; margin-top: 1em; }
label { display: block; margin: .6em 0; font-size: .9rem; color: var(--texte2); }
input, select, textarea { display: block; width: 100%; font: inherit; font-size: 16px; padding: .6em .7em; margin-top: .25em; border: 1px solid var(--bord);
  border-radius: 10px; background: var(--surface); color: var(--texte); }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }
label.check { display: flex; align-items: center; gap: .5em; color: var(--texte); }
label.check input { width: auto; margin: 0; }
fieldset { border: 1px solid var(--bord); border-radius: 10px; margin: .6em 0; padding: .4em .8em .6em; }
legend { color: var(--texte2); font-size: .9rem; padding: 0 .3em; }
.ligne2 { display: flex; gap: .7em; } .ligne2 > label { flex: 1; } .ligne2 > label.grand { flex: 2.5; }
.ligne-form { display: flex; flex-wrap: wrap; gap: .7em; align-items: flex-end; }
.ligne-form label { margin: 0; } .ligne-form input, .ligne-form select { width: auto; }
.actions { display: flex; gap: .6em; justify-content: flex-end; margin-top: 1em; }
.modes { display: flex; gap: .5em; flex-wrap: wrap; }
.mode { flex: 1; margin: 0; } .mode input { position: absolute; opacity: 0; pointer-events: none; }
.mode span { display: block; text-align: center; padding: .8em .4em; border: 2px solid var(--bord); border-radius: 10px; font-weight: 700; color: var(--texte); cursor: pointer; }
.mode input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); color: var(--accent); }
.mode input:focus-visible + span { outline: 2px solid var(--accent); }
details { margin: .6em 0; } summary { cursor: pointer; color: var(--texte2); padding: .3em 0; }
.filtre { max-width: 340px; }

/* ============ Mise en page ============ */
#app { min-height: 100vh; }
.entete { position: fixed; top: 0; left: 0; right: 0; height: 56px; display: flex; align-items: center; gap: .6em; padding: 0 .8em;
  padding-top: env(safe-area-inset-top); background: var(--accent); color: #fff; z-index: 30; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.marque { display: flex; align-items: center; gap: .5em; color: #fff; text-decoration: none; font-weight: 700; flex: 1; min-width: 0; }
.marque img { width: 34px; height: 34px; border-radius: 8px; background: #fff; }
.marque span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .marque small { color: rgba(255,255,255,.8); font-weight: 400; }
.entete .btn.rond { background: rgba(255,255,255,.15); color: #fff; border-color: transparent; box-shadow: none; min-height: 38px; }
.sync-badge { display: flex; align-items: center; gap: .4em; border: 0; border-radius: 999px; padding: .35em .8em; background: rgba(255,255,255,.15);
  color: #fff; font: inherit; font-size: .8rem; cursor: pointer; white-space: nowrap; }
.sync-badge i { width: 10px; height: 10px; border-radius: 50%; background: #9e9e9e; }
.sync-badge.ok i { background: #69f0ae; } .sync-badge.encours i { background: #ffd740; animation: pulse 1s infinite; }
.sync-badge.hors i { background: #bdbdbd; } .sync-badge.erreur i { background: #ff5252; }
@keyframes pulse { 50% { opacity: .3; } }
.nav { position: fixed; z-index: 30; background: var(--surface); }
main { padding-top: 56px; }
.page { padding: 1em; max-width: 1000px; margin: 0 auto; } .page.etroit { max-width: 560px; }

@media (max-width: 999px) {
  .nav { bottom: 0; left: 0; right: 0; display: flex; border-top: 1px solid var(--bord); padding-bottom: env(safe-area-inset-bottom); }
  .nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: .45em 0; color: var(--texte2); text-decoration: none; font-size: .72rem; }
  .nav a .ico { font-size: 1.3rem; } .nav a.actif { color: var(--accent); font-weight: 700; }
  .seulement-ordi { display: none !important; }
  main { padding-bottom: calc(62px + env(safe-area-inset-bottom)); }
  .sync-badge span { display: none; } .marque small { display: none; }
}
@media (min-width: 1000px) {
  .nav { top: 56px; bottom: 0; left: 0; width: 220px; border-right: 1px solid var(--bord); padding: .8em .5em; display: flex; flex-direction: column; gap: 2px; }
  .nav a { display: flex; gap: .7em; align-items: center; padding: .65em .8em; border-radius: 10px; color: var(--texte); text-decoration: none; }
  .nav a.actif { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); font-weight: 700; }
  .nav-moi { margin-top: auto; padding: .8em; font-size: .85rem; border-top: 1px solid var(--bord); }
  main { padding-left: 220px; }
}

/* ============ Connexion ============ */
.ecran-connexion { min-height: 100vh; display: grid; place-items: center; padding: 1em;
  background: linear-gradient(160deg, var(--accent), #6d0f0f); }
.ecran-connexion .boite { background: var(--surface); padding: 2em 1.6em; border-radius: 18px; width: 100%; max-width: 400px; box-shadow: 0 10px 40px rgba(0,0,0,.3); text-align: center; }
.ecran-connexion form { text-align: left; }
.logo-grand img { width: 84px; height: 84px; border-radius: 20px; }

/* ============ Carte ============ */
.vue-carte { height: 100vh; }
.carte-page { position: relative; height: calc(100vh - 56px); }
@media (max-width: 999px) { .carte-page { height: calc(100vh - 56px - 62px - env(safe-area-inset-bottom)); } }
#map, #smap { position: absolute; inset: 0; }
.carte-haut { position: absolute; top: .7em; left: .7em; right: .7em; display: flex; gap: .5em; z-index: 5; }
.recherche-carte { flex: 1; position: relative; max-width: 460px; }
.recherche-carte input { margin: 0; box-shadow: var(--ombre); border-radius: 999px; padding-left: 1em; }
.rc-res { position: absolute; top: 110%; left: 0; right: 0; background: var(--surface); border-radius: 12px; box-shadow: var(--ombre); overflow: hidden; }
.rc-res:empty { display: none; }
.rc-res button { display: flex; gap: .5em; align-items: center; width: 100%; text-align: left; border: 0; background: none; color: var(--texte); padding: .7em .9em; font: inherit; cursor: pointer; border-bottom: 1px solid var(--bord); }
.rc-res button i, .pastille { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.rc-res .vide { padding: .7em; }
.legende { position: absolute; left: .7em; bottom: .7em; z-index: 4; background: color-mix(in srgb, var(--surface) 94%, transparent); border-radius: 14px;
  box-shadow: var(--ombre); padding: .5em .6em; max-width: 270px; font-size: .85rem; }
.leg { display: flex; align-items: center; gap: .45em; border: 0; background: none; color: var(--texte); font: inherit; padding: .2em .1em; cursor: pointer; width: 100%; text-align: left; }
.leg i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.2); flex: none; }
.leg.off { opacity: .35; text-decoration: line-through; }
.leg-total { display: flex; gap: .7em; flex-wrap: wrap; margin-top: .3em; padding-top: .3em; border-top: 1px solid var(--bord); color: var(--texte2); font-size: .8rem; }
.leg-total b { color: var(--texte); }
.progression { position: relative; height: 18px; background: var(--surface2); border-radius: 9px; margin-top: .4em; overflow: hidden; }
.progression span { position: absolute; inset: 0 auto 0 0; background: var(--vert); opacity: .8; }
.progression em { position: relative; font-style: normal; font-size: .75rem; padding-left: .5em; line-height: 18px; font-weight: 600; }
.leg-alerte { margin-top: .4em; color: var(--rouge); font-size: .8rem; }
.carte-actions { position: absolute; right: .7em; top: 3.9em; z-index: 4; }
.carte-actions .btn { box-shadow: var(--ombre); }
.bandeau-mode { position: absolute; top: 3.9em; left: 50%; transform: translateX(-50%); z-index: 6; background: var(--bleu); color: #fff; padding: .5em .8em;
  border-radius: 12px; display: flex; gap: .7em; align-items: center; box-shadow: var(--ombre); font-weight: 600; width: max-content; max-width: 92%; }
.bandeau-mode[hidden] { display: none; }
.fiche { position: absolute; z-index: 8; background: var(--surface); box-shadow: 0 -4px 24px rgba(0,0,0,.2); padding: 1em; overflow-y: auto;
  left: 0; right: 0; bottom: 0; max-height: 72%; border-radius: 18px 18px 0 0; }
@media (min-width: 700px) { .fiche { left: auto; right: .8em; top: .8em; bottom: auto; width: 380px; max-height: calc(100% - 1.6em); border-radius: 16px; } }
.fiche[hidden] { display: none; }
.fiche-tete { display: flex; justify-content: space-between; gap: .5em; } .fiche-tete h3 { margin: 0; font-size: 1.1rem; }
.fiche-statut { margin: .5em 0; display: flex; gap: .6em; align-items: center; }
.attente { color: var(--orange); font-size: .8rem; font-weight: 600; }
.fiche-infos { display: grid; grid-template-columns: auto 1fr; gap: .25em .8em; margin: .6em 0; font-size: .92rem; }
.fiche-infos dt { color: var(--texte2); } .fiche-infos dd { margin: 0; font-weight: 600; }
.fiche-form label { margin: .3em 0; }
.boutons-statut { display: flex; gap: .4em; margin: .6em 0; }
.fiche-pied { display: flex; gap: .4em; flex-wrap: wrap; margin-top: .8em; padding-top: .6em; border-top: 1px solid var(--bord); }
.fiche-pied:empty { display: none; }
.maplibregl-ctrl-bottom-right { bottom: 0; }
@media (max-width: 699px) { .legende { bottom: .7em; max-width: 60%; } }

/* ============ Éléments ============ */
.badge { display: inline-flex; align-items: center; gap: .35em; padding: .2em .65em; border-radius: 999px; font-size: .8rem; font-weight: 700;
  color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); white-space: nowrap; }
.badge::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.etiq { display: inline-block; padding: .15em .55em; border-radius: 6px; font-size: .78rem; background: var(--surface2); color: var(--texte2); margin: .15em .3em .15em 0; }
.etiq.rouge { background: color-mix(in srgb, var(--rouge) 15%, transparent); color: var(--rouge); }
.etiq.orange { background: color-mix(in srgb, var(--orange) 18%, transparent); color: #a86a00; }
.etiq.vert { background: color-mix(in srgb, var(--vert) 15%, transparent); color: var(--vert); }
.carte-info { background: var(--surface); border: 1px solid var(--bord); border-radius: 14px; padding: .9em 1em; margin: .8em 0; }
.carte-info.alerte { border-color: color-mix(in srgb, var(--orange) 50%, transparent); background: color-mix(in srgb, var(--orange) 8%, var(--surface)); }
.carte-info.sync { display: flex; justify-content: space-between; align-items: center; gap: 1em; }
.carte-info.sync.erreur { border-color: var(--rouge); } .err { color: var(--rouge); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6em; }
.kpi { background: var(--surface); border: 1px solid var(--bord); border-left: 4px solid var(--c, var(--accent)); border-radius: 12px; padding: .7em .8em; }
.kpi b { display: block; font-size: 1.35rem; } .kpi span { color: var(--texte2); font-size: .82rem; }
.tableau { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 12px; overflow: hidden; font-size: .88rem; margin: .4em 0 1em; }
.tableau th, .tableau td { padding: .55em .6em; border-bottom: 1px solid var(--bord); text-align: left; vertical-align: top; }
.tableau th { background: var(--surface2); font-weight: 600; color: var(--texte2); font-size: .8rem; }
.tableau .num { text-align: right; white-space: nowrap; } .tableau .total td { font-weight: 700; } .droite { text-align: right; white-space: nowrap; }
.tableau.compact { max-width: 420px; }
.barre-texte td { text-decoration: line-through; color: var(--texte2); }
.barre { height: 10px; background: var(--surface2); border-radius: 5px; overflow: hidden; min-width: 80px; }
.barre span { display: block; height: 100%; border-radius: 5px; }
.col-barre { width: 160px; }
.barre-ligne { display: grid; grid-template-columns: 80px 1fr 100px; gap: .6em; align-items: center; margin: .4em 0; } .barre-ligne b { text-align: right; }
.multi { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--surface2); margin: .3em 0; }
.multi.grand { height: 22px; }
.progress-ligne { background: var(--surface); border: 1px solid var(--bord); border-radius: 12px; padding: .6em .8em; margin: .5em 0; }
.pl-tete { display: flex; justify-content: space-between; }
.liste-ventes { display: grid; gap: .6em; }
.vente { background: var(--surface); border: 1px solid var(--bord); border-radius: 12px; padding: .7em .9em; }
.vente.annulee { opacity: .6; } .v-tete { font-size: 1.05rem; } .v-actions { display: flex; gap: .4em; flex-wrap: wrap; margin-top: .4em; }
.choix-theme { display: flex; gap: .6em; }
.citation { border-left: 3px solid var(--bord); padding-left: .7em; margin: .4em 0; }
.rues { line-height: 1.7; }

/* ============ Administration ============ */
.admin { display: flex; min-height: calc(100vh - 56px); }
.admin-nav { width: 220px; flex: none; border-right: 1px solid var(--bord); padding: .8em .5em; background: var(--surface); }
.admin-nav a { display: block; padding: .55em .8em; border-radius: 8px; color: var(--texte); text-decoration: none; font-size: .92rem; }
.admin-nav a.actif { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); font-weight: 700; }
.compteur { color: #fff; background: var(--rouge); border-radius: 999px; font-size: .72rem; padding: 0 .45em; margin-left: .4em; }
.compteur:empty { display: none; }
.admin-contenu { flex: 1; padding: 1em 1.4em; min-width: 0; }
.titre-ligne { display: flex; align-items: center; justify-content: space-between; gap: 1em; }
.titre-ligne select { width: auto; }
.grille2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1em; }
.secteurs-grille { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1em; height: calc(100vh - 150px); }
.secteurs-carte { position: relative; border-radius: 14px; overflow: hidden; border: 1px solid var(--bord); }
.secteurs-listes { overflow-y: auto; }
.dessin-barre { position: absolute; top: .7em; left: .7em; right: .7em; z-index: 3; display: flex; gap: .5em; align-items: center; flex-wrap: wrap;
  background: var(--surface); padding: .5em; border-radius: 12px; box-shadow: var(--ombre); }
.dessin-barre span { flex: 1; font-size: .88rem; }
.item-gestion { display: flex; justify-content: space-between; gap: .8em; padding: .6em 0; border-bottom: 1px solid var(--bord); }
.item-gestion .boutons { display: flex; gap: .3em; flex-wrap: wrap; justify-content: flex-end; align-content: flex-start; }
.cases { max-height: 50vh; overflow-y: auto; }
.version { background: var(--surface2); border-radius: 10px; padding: .7em; }
.version h4 { margin: 0 0 .2em; }

/* ============ Modales & messages ============ */
.modal-fond { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: grid; place-items: center; padding: 1em; }
.modal { position: relative; background: var(--surface); border-radius: 16px; padding: 1.3em 1.2em 1em; width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.modal.large { max-width: 920px; }
.modal h2 { margin-top: 0; padding-right: 1.5em; }
.modal-x { position: absolute; top: .4em; right: .5em; border: 0; background: none; font-size: 1.7rem; line-height: 1; color: var(--texte2); cursor: pointer; padding: .2em; }
.fiche .modal-x { position: static; }
.confirm-texte { font-size: 1.02rem; }
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 200; display: grid; gap: .4em; width: max-content; max-width: 92vw; }
.toast { background: #323232; color: #fff; padding: .7em 1em; border-radius: 10px; box-shadow: var(--ombre); transition: opacity .4s, transform .4s; }
.toast.ok { background: var(--vert); } .toast.erreur { background: var(--rouge); } .toast.avert { background: #b26a00; }
.toast.out { opacity: 0; transform: translateY(10px); }
.rg-res h3 { margin: 1em 0 .3em; color: var(--texte2); font-size: .85rem; text-transform: uppercase; }
.rg-item { display: block; width: 100%; text-align: left; border: 0; background: none; color: var(--texte); font: inherit; padding: .5em .3em; border-bottom: 1px solid var(--bord); cursor: default; }
button.rg-item { cursor: pointer; } button.rg-item:hover { background: var(--surface2); }
.maplibregl-popup-content { color: #222; }
.admin-contenu .tableau { display: block; overflow-x: auto; }
