:root {
  --fond: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --texte: #17212b;
  --texte-doux: #5b6b7a;
  --bordure: #d6dde3;
  --accent: #0b6e69;
  --accent-fort: #08524e;
  --accent-clair: #dff1ef;
  --danger: #b42318;
  --ok: #1a7f37;
  --attention: #9a6700;
  --ombre: 0 8px 28px rgba(15, 30, 45, .14);
  --rayon: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #11161b; --surface: #1a2128; --surface-2: #222b33; --texte: #e6edf3; --texte-doux: #98a6b3;
    --bordure: #33404b; --accent: #2fb3a8; --accent-fort: #5fd0c6; --accent-clair: #12302e; --ombre: 0 8px 28px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Open Sans", sans-serif; color: var(--texte); background: var(--fond); }
h1 { font-size: 1.35rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .8rem; }
h3 { font-size: 1rem; margin: .2rem 0 .6rem; }
h4 { font-size: .9rem; margin: 1.2rem 0 .4rem; color: var(--texte-doux); text-transform: uppercase; letter-spacing: .04em; }
code { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .85em; }
a { color: var(--accent); }
.aide { color: var(--texte-doux); font-size: .85rem; }
.erreur { background: #fdecea; color: var(--danger); padding: .6rem .8rem; border-radius: 6px; }

/* Boutons et champs */
.bouton { border: 1px solid var(--bordure); background: var(--surface); color: var(--texte); border-radius: 6px; padding: .45rem .8rem; font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap; }
.bouton:hover { border-color: var(--accent); }
.bouton.principal { background: var(--accent); color: #fff; border-color: var(--accent); }
.bouton.principal:hover { background: var(--accent-fort); }
.bouton.discret { border-color: transparent; background: transparent; padding: .3rem .5rem; }
.bouton.icone { font-size: 1.1rem; padding: .25rem .6rem; }
.bouton:disabled { opacity: .55; cursor: progress; }
input, select, textarea { font: inherit; color: var(--texte); background: var(--surface); border: 1px solid var(--bordure); border-radius: 6px; padding: .45rem .6rem; width: 100%; }
textarea { font-family: ui-monospace, Consolas, monospace; font-size: .82rem; resize: vertical; }
label { display: block; font-size: .85rem; color: var(--texte-doux); margin-bottom: .7rem; }
label > input, label > select { margin-top: .25rem; }
label.case { display: flex; gap: .5rem; align-items: center; color: var(--texte); }
label.case input { width: auto; margin: 0; }
.actions { display: flex; gap: .5rem; justify-content: flex-end; align-items: center; margin-top: .8rem; flex-wrap: wrap; }
.actions input { flex: 1; min-width: 120px; }

/* Connexion */
.page-connexion { display: grid; place-items: center; min-height: 100vh; padding: 16px; background: linear-gradient(160deg, var(--accent-clair), var(--fond)); }
.carte-connexion { background: var(--surface); padding: 2rem; border-radius: 12px; box-shadow: var(--ombre); width: min(420px, 100%); }
.marque { display: flex; gap: .6rem; align-items: center; }
.marque small { display: block; color: var(--texte-doux); font-size: .75rem; }
.logo-pastille { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 700; font-size: .8rem; letter-spacing: .03em; }

/* Application */
.page-appli { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.barre { display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--bordure); z-index: 5; }
.barre .recherche { flex: 1; max-width: 560px; position: relative; }
.utilisateur { margin-left: auto; display: flex; align-items: center; gap: .5rem; color: var(--texte-doux); }
.corps { flex: 1; display: flex; min-height: 0; }
.panneau { width: 360px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--bordure); display: flex; flex-direction: column; min-height: 0; }
.panneau.masque { display: none; }
.onglets { display: flex; border-bottom: 1px solid var(--bordure); }
.onglet { flex: 1; border: 0; background: none; padding: .7rem .3rem; font: inherit; color: var(--texte-doux); cursor: pointer; border-bottom: 2px solid transparent; }
.onglet.actif { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.vue { display: none; padding: .8rem; overflow: auto; flex: 1; }
.vue.active { display: block; }
.badge { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 .4rem; font-size: .7rem; }
.outils-liste { display: flex; gap: .3rem; margin-bottom: .6rem; }

.catalogue details { border-bottom: 1px solid var(--surface-2); }
.catalogue summary { cursor: pointer; padding: .45rem .2rem; font-weight: 600; color: var(--texte-doux); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.couche { display: flex; align-items: center; gap: .45rem; padding: .3rem .2rem; border-radius: 6px; }
.couche:hover { background: var(--surface-2); }
.couche input { width: auto; }
.couche .nom { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.couche .compte { color: var(--texte-doux); font-size: .75rem; }
.type-geom { font-size: .7rem; color: var(--texte-doux); width: 1.1rem; text-align: center; }
.actives:not(:empty) { border: 1px solid var(--bordure); border-radius: var(--rayon); padding: .4rem; margin-bottom: .8rem; background: var(--surface-2); }
.couche-active { display: flex; align-items: center; gap: .35rem; padding: .25rem; }
.couche-active .pastille { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; border: 1px solid rgba(0,0,0,.2); }
.couche-active .nom { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }
.couche-active .filtre-actif { color: var(--attention); font-size: .7rem; }
.couche-active button { padding: .1rem .35rem; font-size: .8rem; }

.zone-carte { flex: 1; position: relative; min-width: 0; }
#carte { position: absolute; inset: 0; }
.outils-carte { position: absolute; top: 10px; right: 52px; display: flex; gap: .4rem; align-items: center; background: var(--surface); padding: .35rem; border-radius: var(--rayon); box-shadow: var(--ombre); flex-wrap: wrap; }
.outils-carte select { width: auto; }
.outils-carte .case { margin: 0 .3rem; }
.coordonnees { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); background: color-mix(in srgb, var(--surface) 85%, transparent); padding: .15rem .6rem; border-radius: 6px; font: .75rem ui-monospace, monospace; color: var(--texte-doux); }

.liste-deroulante { position: absolute; top: 100%; left: 0; right: 0; background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon); box-shadow: var(--ombre); list-style: none; margin: .3rem 0 0; padding: .3rem; max-height: 60vh; overflow: auto; z-index: 20; }
.liste-deroulante li { padding: .45rem .5rem; border-radius: 6px; cursor: pointer; }
.liste-deroulante li:hover, .liste-deroulante li.survol { background: var(--accent-clair); }
.liste-deroulante small { color: var(--texte-doux); display: block; }

.table-attributs { position: absolute; left: 0; right: 0; bottom: 0; height: 38%; background: var(--surface); border-top: 1px solid var(--bordure); display: flex; flex-direction: column; box-shadow: 0 -6px 18px rgba(0,0,0,.08); }
.table-attributs header { display: flex; align-items: center; gap: .5rem; padding: .4rem .6rem; border-bottom: 1px solid var(--bordure); }
.table-attributs header input { max-width: 320px; margin-left: auto; padding: .3rem .5rem; }
.table-defilante { overflow: auto; flex: 1; }
table { border-collapse: collapse; width: 100%; font-size: .8rem; }
th, td { padding: .3rem .5rem; border-bottom: 1px solid var(--surface-2); text-align: left; white-space: nowrap; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; }
tbody tr:hover { background: var(--accent-clair); cursor: pointer; }

.travaux .travail { border: 1px solid var(--bordure); border-radius: var(--rayon); padding: .6rem; margin-bottom: .6rem; background: var(--surface); }
.travail .entete { display: flex; justify-content: space-between; gap: .5rem; }
.travail .titre { font-weight: 600; overflow-wrap: anywhere; }
.travail .meta { color: var(--texte-doux); font-size: .75rem; }
.travail img { width: 100%; border-radius: 6px; margin-top: .4rem; border: 1px solid var(--bordure); background: #fff; }
.travail .fichiers { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
.travail .fichiers a { font-size: .8rem; padding: .15rem .5rem; border: 1px solid var(--bordure); border-radius: 12px; text-decoration: none; }
.travail .samba { font-size: .75rem; color: var(--texte-doux); overflow-wrap: anywhere; margin-top: .3rem; }
.etat { font-size: .72rem; padding: .1rem .45rem; border-radius: 10px; white-space: nowrap; height: fit-content; }
.etat.termine { background: #dcf3e3; color: var(--ok); }
.etat.erreur { background: #fdecea; color: var(--danger); }
.etat.en_cours, .etat.en_attente { background: #fff4d6; color: var(--attention); }
.progression { height: 4px; background: var(--surface-2); border-radius: 2px; margin-top: .4rem; overflow: hidden; }
.progression span { display: block; height: 100%; background: var(--accent); transition: width .4s; }

.copie { display: flex; align-items: center; gap: .3rem; background: var(--surface-2); border-radius: 6px; padding: .4rem .5rem; margin: .4rem 0; }
.copie code { flex: 1; overflow-wrap: anywhere; }

.dialogue { border: 0; border-radius: 12px; padding: 1.4rem; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--texte); box-shadow: var(--ombre); }
.dialogue.large { width: min(760px, calc(100vw - 32px)); }
.dialogue::backdrop { background: rgba(10, 20, 30, .45); }
.grille-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.liste-cases { max-height: 160px; overflow: auto; border: 1px solid var(--bordure); border-radius: 6px; padding: .4rem; margin-bottom: .8rem; }
.apercu img { max-width: 100%; max-height: 46vh; display: block; margin: .5rem auto; border: 1px solid var(--bordure); border-radius: 6px; background: #fff; }

.notification { position: fixed; bottom: 18px; right: 18px; background: var(--texte); color: var(--surface); padding: .7rem 1rem; border-radius: var(--rayon); box-shadow: var(--ombre); z-index: 50; max-width: 420px; }
.maplibregl-popup-content { background: var(--surface); color: var(--texte); max-height: 320px; overflow: auto; font-size: .8rem; padding: .7rem .8rem; }
.maplibregl-popup-content table td { max-width: 220px; white-space: normal; }

/* Onglet Terrain */
.bloc { border: 1px solid var(--bordure); border-radius: var(--rayon); padding: .2rem .7rem .7rem; margin-bottom: .7rem; background: var(--surface); }
.bloc > summary { cursor: pointer; font-weight: 600; padding: .5rem 0; }
.liste-externes h5 { margin: .6rem 0 .2rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--texte-doux); }
.couche-externe { display: grid; grid-template-columns: auto 1fr 70px; gap: .45rem; align-items: center; padding: .15rem 0; font-size: .85rem; }
.couche-externe input[type=range] { width: 70px; padding: 0; }
.couche-externe input[type=checkbox] { width: auto; margin: 0; }
.ligne-champs { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; }
.ligne-champs .champ-court { width: 110px; margin: 0; }
.actions.gauche { justify-content: flex-start; }
.resultat-externe table { margin-top: .4rem; }
.resultat-externe img, #photo-resultat img, .photo-fiche img { width: 100%; border-radius: 6px; border: 1px solid var(--bordure); margin-top: .4rem; background: #fff; }
.photo-fiche dl { display: grid; grid-template-columns: auto 1fr; gap: .15rem .6rem; font-size: .8rem; margin: .4rem 0; }
.photo-fiche dt { color: var(--texte-doux); }
.photo-fiche dd { margin: 0; overflow-wrap: anywhere; }
.alertes { margin: .4rem 0; padding-left: 1.1rem; font-size: .82rem; }
.alertes li { margin-bottom: .2rem; }
.confiance { display: inline-block; padding: .05rem .5rem; border-radius: 10px; font-size: .75rem; font-weight: 600; }
.confiance.elevee { background: #dcf3e3; color: var(--ok); }
.confiance.moyenne { background: #fff4d6; color: var(--attention); }
.confiance.faible, .confiance.echec { background: #fdecea; color: var(--danger); }
.maplibregl-popup-content img.vignette-terrain { width: 240px; max-width: 100%; display: block; border-radius: 4px; margin-top: .3rem; }
.mode-choix #carte canvas { cursor: crosshair !important; }

@media (max-width: 760px) {
  .barre { flex-wrap: wrap; gap: .5rem; padding: .5rem 16px; }
  .barre .recherche { order: 3; flex-basis: 100%; max-width: none; }
  .barre .marque small, .utilisateur span { display: none; }
  .panneau { position: absolute; z-index: 10; top: 0; bottom: 0; width: min(92vw, 360px); box-shadow: var(--ombre); }
  .corps { position: relative; }
  .outils-carte { right: 10px; left: 10px; top: auto; bottom: 34px; justify-content: center; }
  .grille-2 { grid-template-columns: 1fr; }
  .onglet { font-size: .78rem; padding: .65rem .1rem; }
}
