:root {
  --bg: #eef1f6;
  --panel: #ffffff;
  --ink: #16202e;
  --muted: #64748b;
  --line: #dde3ec;
  --accent: #1d4ed8;
  --accent-soft: #e8efff;
  --danger: #b91c1c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 35, 59, .06), 0 8px 24px rgba(16, 35, 59, .07);
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font: 14px/1.45 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3 { margin: 0; font-weight: 650; }

.app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- Barre supérieure ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar__title { display: flex; align-items: center; gap: 12px; }

.topbar__dept {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  letter-spacing: .5px;
}

.topbar h1 { font-size: 16px; }
.topbar p { margin: 1px 0 0; font-size: 12px; color: var(--muted); }

.topbar__actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Boutons et champs ---------- */

.btn {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #f4f7fb; border-color: #c6d0de; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: #1740b8; border-color: #1740b8; }
.btn--danger { color: var(--danger); border-color: #f0d2d2; }
.btn--danger:hover { background: #fdf2f2; }
.btn--ghost { background: transparent; }
.btn--sm { padding: 5px 10px; font-size: 12px; }

.input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
}
.input:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.input--sm { padding: 4px 6px; font-size: 12px; }

.label { display: block; margin-bottom: 4px; font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

kbd {
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #f7f9fc;
  font-family: inherit;
  font-size: 11px;
}

/* ---------- Mise en page ---------- */

.layout { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 360px;
  flex: none;
  padding: 14px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.panel__head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }

.hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- Liste des départements ---------- */

.panel__actions { display: flex; gap: 6px; }

.departements {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  max-height: 420px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.departement {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 6px;
  border-radius: 7px;
}
.departement:hover { background: #f1f5fb; }

.departement__label {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.departement__nom {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.departement__nom strong { color: var(--accent); font-variant-numeric: tabular-nums; }

.departement__compte {
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.depstat {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--muted);
}

.region { margin-top: 6px; }
.region:first-child { margin-top: 0; }

.region__btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: #f4f7fb;
  font: inherit;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}
.region__btn:hover { border-color: #c6d0de; color: var(--ink); }
.region__btn.is-complete { background: var(--accent-soft); color: var(--accent); }
.region__btn.is-partiel { background: #f4f7fb; color: var(--ink); }
.region__nom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.region__compte { font-variant-numeric: tabular-nums; letter-spacing: 0; }

/* ---------- Liste des commerciaux ---------- */

.secteurs { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.secteur {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
}
.secteur:hover { border-color: #c6d0de; background: #fafbfe; }
.secteur.is-active { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }

.secteur__color {
  width: 26px; height: 26px;
  flex: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}
.secteur__color::-webkit-color-swatch-wrapper { padding: 2px; }
.secteur__color::-webkit-color-swatch { border: none; border-radius: 4px; }

.secteur__main { flex: 1; min-width: 0; }

.secteur__name {
  width: 100%;
  padding: 1px 2px;
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  border-radius: 4px;
}
.secteur__name:focus { outline: none; background: #fff; box-shadow: 0 0 0 1px var(--accent); }

.secteur__meta { font-size: 11.5px; color: var(--muted); }

.secteur__actions { display: flex; gap: 2px; }

.iconbtn {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}
.iconbtn:hover { background: #eef2f8; color: var(--ink); }
.iconbtn--danger:hover { background: #fdf0f0; color: var(--danger); }

.eraser {
  width: 100%;
  margin-top: 8px;
  padding: 7px 10px;
  display: flex; align-items: center; gap: 8px;
  border: 1px dashed var(--line);
  border-radius: 9px;
  background: #fff;
  font: inherit;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
}
.eraser:hover { border-color: #c6d0de; color: var(--ink); }
.eraser.is-active { border-style: solid; border-color: var(--danger); color: var(--danger); background: #fdf3f3; }
.eraser__icon {
  display: grid; place-items: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: currentColor;
  color: #fff;
  font-size: 12px;
  line-height: 1;
}
.eraser.is-active .eraser__icon { color: #fdf3f3; }

.empty { padding: 8px; font-size: 12px; color: var(--muted); list-style: none; }

/* ---------- Recherche ---------- */

.results { list-style: none; margin: 8px 0 0; padding: 0; max-height: 240px; overflow-y: auto; }

.result {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 6px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
}
.result:hover { background: #f1f5fb; }
.result__dot { width: 10px; height: 10px; flex: none; border: 1px solid #b7c0cc; border-radius: 50%; }
.result__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result__cp { font-size: 11.5px; color: var(--muted); }

/* ---------- Couverture ---------- */

.coverage { display: flex; flex-direction: column; gap: 12px; }
.coverage__head { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.coverage__head strong { color: var(--ink); }
.coverage__bar { margin-top: 5px; height: 7px; border-radius: 4px; background: #e8edf5; overflow: hidden; }
.coverage__bar span { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .25s; }
.coverage__pct { margin-top: 3px; font-size: 11px; color: var(--muted); text-align: right; }

/* ---------- Carte ---------- */

.mapwrap { position: relative; flex: 1; min-width: 0; }
.map { position: absolute; inset: 0; background: #f6f8fb; }

.mapbar {
  position: absolute;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .95);
  box-shadow: var(--shadow);
  font-size: 12px;
}
.toggle { display: flex; align-items: center; gap: 5px; white-space: nowrap; cursor: pointer; }

.infobox {
  position: absolute;
  top: 10px; right: 10px;
  z-index: 500;
  min-width: 190px; max-width: 250px;
  display: flex; flex-direction: column; gap: 2px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow);
  pointer-events: none;
}
.infobox__line { font-size: 11.5px; color: var(--muted); }
.infobox__secteur {
  margin-top: 5px;
  padding: 2px 7px;
  align-self: flex-start;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
}

.legend {
  position: absolute;
  left: 10px; bottom: 22px;
  z-index: 500;
  max-height: 45%;
  overflow-y: auto;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow);
}
.legend h3 { margin-bottom: 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.legend__row { display: flex; align-items: center; gap: 7px; font-size: 12.5px; padding: 1px 0; }
.legend__dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend__name { flex: 1; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend__count { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Fond de carte atténué : les couleurs des secteurs priment sur le fond. */
.fond-attenue { filter: grayscale(.85) brightness(1.08) opacity(.55); }

.select-box {
  position: absolute;
  z-index: 800;
  border: 1.5px dashed var(--accent);
  background: rgba(29, 78, 216, .12);
  pointer-events: none;
}

.commune-label {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  color: #16202e;
  font-size: 10.5px;
  font-weight: 600;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
}
.commune-label::before { display: none; }

.toast {
  position: absolute;
  bottom: 18px; left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(22, 32, 46, .92);
  color: #fff;
  font-size: 12.5px;
  box-shadow: var(--shadow);
}

.leaflet-container { font: inherit; }

.chargement {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .97);
  box-shadow: var(--shadow);
  font-size: 13px;
}

.chargement__spin {
  width: 15px; height: 15px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: tourne .8s linear infinite;
}

@keyframes tourne { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .chargement__spin { animation-duration: 2.4s; }
}

/* ---------- Écrans étroits ---------- */

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; max-height: 45vh; border-right: none; border-bottom: 1px solid var(--line); }
  .mapwrap { min-height: 55vh; }
  .topbar { padding: 10px 12px; }
  .mapbar {
    left: 8px; right: 8px;
    transform: none;
    justify-content: center;
    border-radius: var(--radius);
    font-size: 11px; gap: 8px;
  }
  .infobox {
    top: auto; bottom: 8px; left: 8px; right: 8px;
    max-width: none;
    flex-flow: row wrap;
    align-items: baseline;
    gap: 3px 8px;
  }
  .infobox__secteur { margin-top: 0; }
  .legend { display: none; }
}

/* ---------- Impression ---------- */

@media print {
  .topbar, .sidebar, .mapbar, .infobox, .toast, .leaflet-control-zoom { display: none !important; }
  .app, .layout { height: auto; display: block; }
  .mapwrap { position: relative; height: 96vh; }
  .legend { box-shadow: none; }
}

/* ---------- Pages de connexion et d'installation ---------- */

.page-auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px 16px;
  background: linear-gradient(160deg, #eef1f6 0%, #e3e9f4 100%);
}

.carte-auth {
  width: 100%;
  max-width: 420px;
  padding: 26px 26px 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.carte-auth__marque { margin-bottom: 14px; }
.carte-auth h1 { font-size: 19px; }
.carte-auth__intro { margin: 6px 0 18px; font-size: 13px; color: var(--muted); }
.carte-auth__pied { margin: 14px 0 0; font-size: 12px; color: var(--muted); }

.formulaire { display: flex; flex-direction: column; }
.formulaire .label { margin-top: 12px; }
.formulaire .hint { margin: 4px 0 0; }
.formulaire .btn--bloc { margin-top: 18px; }

.btn--bloc { width: 100%; padding: 10px; font-size: 14px; }

.onglets {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
  padding: 3px;
  border-radius: 9px;
  background: #eef2f8;
}
.onglet {
  flex: 1;
  padding: 7px;
  border: none;
  border-radius: 7px;
  background: transparent;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.onglet.is-actif { background: #fff; color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

.message {
  margin: 14px 0 0;
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 13px;
}
.message--erreur { background: #fdf2f2; border: 1px solid #f0d2d2; color: var(--danger); }
.message--succes { background: #eefaf1; border: 1px solid #c9e9d3; color: #14663a; }

/* ---------- Utilisateur connecté ---------- */

.utilisateur { display: flex; align-items: center; gap: 7px; margin-right: 4px; }
.utilisateur__nom { font-size: 13px; font-weight: 600; }

.etiquette {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .2px;
}
.etiquette--admin { background: var(--accent-soft); color: var(--accent); }
.etiquette--user { background: #eef2f8; color: var(--muted); }
.etiquette--off { background: #f1f1f1; color: #6b6b6b; }
.etiquette--alerte { background: #fef3e2; color: #a35a00; }

/* ---------- Page des comptes ---------- */

.page-comptes { background: var(--bg); }
.comptes { max-width: 860px; margin: 0 auto; padding: 20px 16px 48px; }
.comptes__intro { margin: 0 0 16px; font-size: 13px; }

.bandeau {
  margin: 0 0 14px;
  padding: 10px 13px;
  border: 1px solid #f3dfc0;
  border-radius: var(--radius);
  background: #fef8ee;
  font-size: 13px;
  color: #8a5a10;
}

.compte {
  margin-bottom: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.compte--inactif { opacity: .7; }

.compte__tete { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.compte__identite { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.compte__login { font-size: 12.5px; color: var(--muted); }
.compte__etiquettes { display: flex; gap: 6px; flex-wrap: wrap; }
.compte__meta { margin: 4px 0 10px; font-size: 11.5px; color: var(--muted); }

.acces {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 2px 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.acces__case { display: flex; align-items: center; gap: 7px; padding: 3px 0; font-size: 13px; cursor: pointer; }

.compte__actions { display: flex; gap: 6px; flex-wrap: wrap; padding-top: 10px; border-top: 1px solid var(--line); }

@media (max-width: 600px) {
  .compte__actions .btn { flex: 1; }
}
