:root {
  --fond: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --encre: #1c2430;
  --encre-2: #4a5462;
  --encre-3: #7b8491;
  --bord: #e4e0d8;
  --accent: #a8322a;          /* rouge laque */
  --accent-doux: #f6e7e4;
  --bleu: #2f5d8a;
  --ambre: #c27c1a;
  --vert: #1f7a4d;
  --vert-doux: #e3f2ea;
  --rouge: #b42318;
  --rouge-doux: #fdecea;
  --ambre-doux: #fbf0dc;
  --bleu-doux: #e6eef6;
  --rayon: 14px;
  --ombre: 0 1px 2px rgba(28, 36, 48, .06), 0 4px 16px rgba(28, 36, 48, .05);
  --nav-l: 248px;
  --sab: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--encre);
  background: var(--fond);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- Structure ---------- */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }

.nav {
  position: fixed; inset: 0 auto 0 0; width: var(--nav-l);
  background: var(--encre); color: #e9ecf1;
  display: flex; flex-direction: column; gap: 4px;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 12px 18px;
  z-index: 20;
}
.nav-marque { display: flex; align-items: center; gap: 12px; padding: 4px 10px 22px; }
.nav-marque strong { display: block; font-size: 16px; letter-spacing: .2px; }
.nav-marque span { font-size: 12px; color: #9aa4b2; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px;
  border-radius: 10px; text-decoration: none; font-weight: 500; font-size: 15px; color: #c8cfd9;
}
.nav a svg { width: 22px; height: 22px; fill: currentColor; flex: none; }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.actif { background: rgba(255, 255, 255, .12); color: #fff; }

.vue {
  flex: 1; min-width: 0; margin-left: var(--nav-l);
  padding: calc(24px + env(safe-area-inset-top, 0px)) 32px 48px;
  outline: none;
}

@media (max-width: 899px) {
  .nav {
    inset: auto 0 0 0; width: auto; height: calc(62px + var(--sab));
    flex-direction: row; justify-content: space-around; gap: 0;
    padding: 6px 4px calc(6px + var(--sab));
    background: rgba(255, 255, 255, .94); color: var(--encre-2);
    backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
    border-top: 1px solid var(--bord);
  }
  .nav-marque { display: none; }
  .nav a {
    flex: 1; flex-direction: column; gap: 3px; padding: 6px 2px; font-size: 10.5px;
    color: var(--encre-3); border-radius: 10px; text-align: center; line-height: 1.1;
  }
  .nav a span { max-width: 80px; }
  .nav a:hover { background: none; color: var(--encre-2); }
  .nav a.actif { background: none; color: var(--accent); }
  .vue { margin-left: 0; padding: calc(16px + env(safe-area-inset-top, 0px)) 16px calc(96px + var(--sab)); }
}

/* ---------- En-têtes ---------- */
.entete { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.entete h1 { margin: 0; font-size: 28px; letter-spacing: -.4px; }
.entete p { margin: 4px 0 0; color: var(--encre-3); font-size: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 11px;
  border: 1px solid var(--bord); background: var(--surface); color: var(--encre);
  font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primaire { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primaire:hover { background: #932a23; }
.btn.danger { color: var(--rouge); border-color: #f1c6c1; }
.btn.petit { min-height: 34px; padding: 0 11px; font-size: 13.5px; border-radius: 9px; }
.btn.lien { border: 0; background: none; color: var(--bleu); padding: 0 6px; }
.btn svg { width: 18px; height: 18px; fill: currentColor; }

.fab {
  position: fixed; right: 20px; bottom: calc(80px + var(--sab)); z-index: 15;
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 6px 20px rgba(168, 50, 42, .35); cursor: pointer;
}
@media (min-width: 900px) { .fab { display: none; } }

/* ---------- Cartes & indicateurs ---------- */
.carte { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 18px; }
.grille { display: grid; gap: 14px; }
.grille-kpi { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.grille-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpi { padding: 16px 18px; }
.kpi .libelle { font-size: 13px; color: var(--encre-3); font-weight: 500; }
.kpi .valeur { font-size: 26px; font-weight: 700; letter-spacing: -.5px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .detail { font-size: 12.5px; color: var(--encre-3); margin-top: 4px; }
.kpi.fort { background: var(--encre); color: #fff; border-color: var(--encre); }
.kpi.fort .libelle, .kpi.fort .detail { color: #b9c2ce; }
.positif { color: var(--vert); }
.negatif { color: var(--rouge); }
.kpi.fort .positif { color: #7fe0a9; }
.kpi.fort .negatif { color: #ff9b91; }

.section { margin-top: 22px; }
.formule { font-size: 13px; color: var(--encre-3); line-height: 1.6; }
.formule b { color: var(--encre-2); }

/* ---------- Sélecteur de période ---------- */
.periode { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.segment { display: inline-flex; background: #e9e5dd; border-radius: 11px; padding: 3px; }
.segment button {
  border: 0; background: none; padding: 8px 14px; border-radius: 9px; font-weight: 600; font-size: 14px;
  color: var(--encre-2); cursor: pointer; min-height: 38px;
}
.segment button.actif { background: var(--surface); color: var(--encre); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.nav-periode { display: inline-flex; align-items: center; gap: 4px; }
.nav-periode strong { min-width: 150px; text-align: center; font-size: 15px; }
.rond { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--bord); background: var(--surface); cursor: pointer; font-size: 18px; }

/* ---------- Recherche & filtres ---------- */
.barre-recherche {
  position: sticky; top: 0; z-index: 10; background: var(--fond);
  padding: 8px 0 12px; margin-top: -8px;
}
.champ-recherche { position: relative; }
.champ-recherche svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; fill: var(--encre-3); }
.champ-recherche input {
  width: 100%; height: 52px; padding: 0 44px 0 46px; font-size: 17px;
  border: 1.5px solid var(--bord); border-radius: 14px; background: var(--surface); box-shadow: var(--ombre);
  -webkit-appearance: none; appearance: none;
}
.champ-recherche input:focus { outline: none; border-color: var(--bleu); box-shadow: 0 0 0 4px rgba(47, 93, 138, .15); }
.champ-recherche .effacer { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border: 0; background: none; font-size: 22px; color: var(--encre-3); width: 36px; height: 36px; cursor: pointer; }
.filtres { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.filtres select, .filtres input {
  height: 40px; border: 1px solid var(--bord); border-radius: 10px; background: var(--surface); padding: 0 10px; font-size: 14px; max-width: 100%;
}
.filtres input[type=number] { width: 110px; }
.compteur { font-size: 13px; color: var(--encre-3); margin: 4px 2px 10px; }
.onglets { display: flex; gap: 6px; margin-bottom: 14px; }

/* ---------- Tableaux (deviennent des cartes sur téléphone) ---------- */
.tableau-wrap { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); box-shadow: var(--ombre); overflow: hidden; }
table.liste { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.liste th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--encre-3); font-weight: 600; padding: 12px 14px; background: var(--surface-2); border-bottom: 1px solid var(--bord); white-space: nowrap; }
.liste td { padding: 12px 14px; border-bottom: 1px solid #efece6; vertical-align: middle; }
.liste tr:last-child td { border-bottom: 0; }
.liste tbody tr { cursor: pointer; }
.liste tbody tr:hover { background: #fbfaf7; }
.liste .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.liste .principal { font-weight: 600; }
.liste .secondaire { font-size: 12.5px; color: var(--encre-3); margin-top: 2px; }
.liste .act { text-align: right; white-space: nowrap; }
mark { background: #fff1b8; color: inherit; border-radius: 3px; padding: 0 1px; }

@media (max-width: 699px) {
  .tableau-wrap { background: none; border: 0; box-shadow: none; overflow: visible; }
  table.liste, .liste tbody, .liste tr, .liste td { display: block; width: 100%; }
  .liste thead { display: none; }
  .liste tr { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); box-shadow: var(--ombre); margin-bottom: 10px; padding: 8px 4px; }
  .liste td { border: 0; padding: 5px 12px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .liste td::before { content: attr(data-l); color: var(--encre-3); font-size: 13px; text-align: left; flex: none; }
  .liste td.titre { display: block; text-align: left; padding-top: 8px; }
  .liste td.titre::before { display: none; }
  .liste td.act { justify-content: flex-end; }
  .liste td.act::before { display: none; }
  .liste td:empty { display: none; }
}

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #eceae5; color: var(--encre-2); }
.badge.vert { background: var(--vert-doux); color: var(--vert); }
.badge.rouge { background: var(--rouge-doux); color: var(--rouge); }
.badge.ambre { background: var(--ambre-doux); color: #8a5a10; }
.badge.bleu { background: var(--bleu-doux); color: var(--bleu); }
.wechat { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; color: #237a3a; }

/* ---------- Vide ---------- */
.vide { text-align: center; padding: 48px 20px; color: var(--encre-3); }
.vide strong { display: block; color: var(--encre); font-size: 17px; margin-bottom: 6px; }
.vide .actions { justify-content: center; margin-top: 16px; }

/* ---------- Modale / formulaires ---------- */
.modale {
  border: 0; padding: 0; border-radius: 18px; width: min(680px, calc(100vw - 24px));
  max-height: calc(100dvh - 40px); background: var(--surface); color: var(--encre);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.modale::backdrop { background: rgba(20, 26, 34, .45); }
.modale form { display: flex; flex-direction: column; max-height: calc(100dvh - 40px); }
.modale-tete { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--bord); }
.modale-tete h2 { margin: 0; font-size: 18px; }
.modale-corps { padding: 18px 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modale-pied { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px calc(14px + var(--sab)); border-top: 1px solid var(--bord); background: var(--surface-2); flex-wrap: wrap; }
.modale-pied .gauche { margin-right: auto; }
@media (max-width: 699px) {
  .modale { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 94dvh; }
  .modale form { max-height: 94dvh; }
}

.champs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.champs .large { grid-column: 1 / -1; }
@media (max-width: 520px) { .champs { grid-template-columns: 1fr; } }
.champ label { display: block; font-size: 13px; font-weight: 600; color: var(--encre-2); margin-bottom: 5px; }
.champ input, .champ select, .champ textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; font-size: 16px; /* 16px évite le zoom iOS */
  border: 1px solid #d9d4ca; border-radius: 11px; background: #fff;
  -webkit-appearance: none; appearance: none;
}
.champ select { background-image: linear-gradient(45deg, transparent 50%, var(--encre-3) 50%), linear-gradient(135deg, var(--encre-3) 50%, transparent 50%); background-position: calc(100% - 18px) 20px, calc(100% - 13px) 20px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.champ textarea { min-height: 80px; resize: vertical; }
.champ input:focus, .champ select:focus, .champ textarea:focus { outline: none; border-color: var(--bleu); box-shadow: 0 0 0 3px rgba(47, 93, 138, .15); }
.champ .aide { font-size: 12px; color: var(--encre-3); margin-top: 4px; }
.avec-unite { position: relative; }
.avec-unite input { padding-right: 34px; }
.avec-unite span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--encre-3); font-weight: 600; pointer-events: none; }
.separateur { grid-column: 1 / -1; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--encre-3); font-weight: 700; margin-top: 8px; padding-top: 10px; border-top: 1px dashed var(--bord); }

.recap { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; background: var(--surface-2); border: 1px solid var(--bord); border-radius: 12px; padding: 12px; }
.recap div { font-size: 12px; color: var(--encre-3); }
.recap b { display: block; font-size: 17px; color: var(--encre); margin-top: 2px; font-variant-numeric: tabular-nums; }
@media (max-width: 520px) { .recap { grid-template-columns: repeat(2, 1fr); } }

.puces { display: flex; flex-wrap: wrap; gap: 8px; }
.puces button { border: 1px solid var(--bord); background: #fff; border-radius: 999px; padding: 9px 14px; font-weight: 600; font-size: 14px; cursor: pointer; min-height: 40px; }
.puces button.actif { background: var(--encre); color: #fff; border-color: var(--encre); }

/* ---------- Graphiques ---------- */
.barres-h { display: grid; gap: 10px; }
.barre-h { display: grid; grid-template-columns: 110px 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.barre-h .piste { height: 10px; background: #efece6; border-radius: 5px; overflow: hidden; }
.barre-h .rempli { height: 100%; background: var(--bleu); border-radius: 5px; }
.barre-h .val { font-variant-numeric: tabular-nums; font-weight: 600; }
.graph { width: 100%; height: auto; display: block; }
.graph text { font-size: 11px; fill: var(--encre-3); }
.legende { display: flex; gap: 16px; font-size: 13px; color: var(--encre-2); margin-bottom: 8px; flex-wrap: wrap; }
.legende i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.infobulle { position: fixed; pointer-events: none; background: var(--encre); color: #fff; font-size: 12.5px; padding: 8px 10px; border-radius: 8px; z-index: 50; line-height: 1.5; white-space: nowrap; }

/* ---------- Listes simples ---------- */
.mini-liste { list-style: none; margin: 0; padding: 0; }
.mini-liste li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid #efece6; font-size: 14px; cursor: pointer; }
.mini-liste li:last-child { border-bottom: 0; }
.jour-titre { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; color: var(--encre-2); margin: 18px 4px 8px; text-transform: capitalize; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--sab)); transform: translateX(-50%) translateY(20px);
  background: var(--encre); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 500; font-size: 14.5px;
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 100; max-width: calc(100vw - 32px);
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.alerte { border-radius: 12px; padding: 12px 14px; font-size: 14px; background: var(--ambre-doux); color: #6b4710; border: 1px solid #f0d9a8; }
.alerte.info { background: var(--bleu-doux); color: #1f4466; border-color: #c9d9ea; }
.apercu-import { max-height: 260px; overflow: auto; border: 1px solid var(--bord); border-radius: 10px; font-size: 13px; }
.apercu-import table { border-collapse: collapse; width: 100%; }
.apercu-import td, .apercu-import th { padding: 6px 8px; border-bottom: 1px solid #efece6; white-space: nowrap; text-align: left; }
.correspondance { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; align-items: center; font-size: 14px; }
.correspondance select { min-height: 40px; border: 1px solid var(--bord); border-radius: 9px; padding: 0 8px; background: #fff; }
.case { display: flex; gap: 10px; align-items: center; font-size: 14.5px; margin-top: 10px; }
.case input { width: 20px; height: 20px; }

@media (max-width: 699px) {
  .filtres { display: grid; grid-template-columns: 1fr 1fr; }
  .filtres select, .filtres input, .filtres input[type=number] { width: 100%; }
  .filtres .segment { grid-column: 1 / -1; }
  .entete h1 { font-size: 24px; }
}

/* ---------- Compte, connexion et synchronisation (v2) ---------- */
body.sans-nav .nav, body.sans-nav .pastille-sync { display: none !important; }
body.sans-nav .vue { margin-left: 0; }
.auth { max-width: 460px; margin: 0 auto; padding: 4vh 0 40px; }
.auth-marque { display: flex; align-items: center; gap: 12px; margin: 0 4px 18px; }
.auth-marque strong { display: block; font-size: 20px; }
.auth-marque span { color: var(--encre-3); font-size: 13px; }
.auth-carte { display: flex; flex-direction: column; gap: 14px; padding: 22px; }
.auth-carte h1 { margin: 0; font-size: 24px; letter-spacing: -.3px; }
.auth-carte h2 { margin: 0; font-size: 16px; }
.auth-message:empty { display: none; }
.auth-message { border-radius: 10px; padding: 10px 12px; font-size: 14px; line-height: 1.4; }
.auth-message.erreur { background: var(--rouge-doux); color: var(--rouge); border: 1px solid #f1c6c1; }
.auth-message.info { background: var(--vert-doux); color: var(--vert); border: 1px solid #bfe0cd; }
.auth-liens { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.btn.large { width: 100%; min-height: 48px; font-size: 16px; }
.btn:disabled { opacity: .55; pointer-events: none; }
.champ-simple { flex: 1; min-width: 180px; min-height: 44px; padding: 8px 12px; font-size: 16px; border: 1px solid #d9d4ca; border-radius: 11px; background: #fff; }
.champ-simple:focus { outline: none; border-color: var(--bleu); box-shadow: 0 0 0 3px rgba(47, 93, 138, .15); }
.liste-espaces { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.liste-espaces li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border: 1px solid var(--bord); border-radius: 12px; background: var(--surface-2); flex-wrap: wrap; }
.liste-espaces li[role=button] { cursor: pointer; }
.liste-espaces li[role=button]:hover { border-color: var(--bleu); }
.liste-espaces strong { display: block; }
.liste-espaces span { font-size: 13px; color: var(--encre-3); }
.sous-titre { font-size: 14px; margin: 16px 0 4px; color: var(--encre-2); }
.etat-sync { display: block; margin-top: 4px; font-size: 11.5px; color: #9aa4b2; }
.etat-sync[data-statut=synchronise] { color: #8fd1ad; }
.etat-sync[data-statut=erreur] { color: #f3a39b; }
.etat-sync-carte { font-size: 14px; font-weight: 600; color: var(--encre-2); background: var(--surface-2); border: 1px solid var(--bord); border-radius: 10px; padding: 8px 12px; margin-top: 10px; }
.pastille-sync { position: fixed; top: calc(8px + env(safe-area-inset-top, 0px)); right: 12px; z-index: 30; background: var(--ambre-doux); color: #6b4710; border: 1px solid #f0d9a8; border-radius: 999px; padding: 5px 12px; font-size: 12.5px; font-weight: 600; text-decoration: none; box-shadow: var(--ombre); }
.pastille-sync[data-statut=erreur] { background: var(--rouge-doux); color: var(--rouge); border-color: #f1c6c1; }
#resultats-securite li { cursor: default; }
