:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --ink: #111c29;
  --muted: #66778b;
  --line: #e6ebf1;
  --brand: #0f6fb5;
  --brand-dark: #0a558c;
  --navy: #0f2c40;
  --green: #17864f;
  --green-bg: #e6f5ec;
  --red: #c0392b;
  --red-bg: #fbeaea;
  --orange: #c97a12;
  --orange-bg: #fdf3e2;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 48, .04), 0 10px 30px rgba(16, 32, 48, .07);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.petit { font-size: 12.5px; }
.spacer { flex: 1; }
a { color: var(--brand); }

.bandeau-essai {
  background: var(--red); color: #fff; text-align: center; font-weight: 700;
  font-size: 13px; padding: 6px 12px; position: sticky; top: 0; z-index: 60;
}

/* ---------- Boutons, champs ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: var(--radius-sm); padding: 9px 14px; font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #cdd6e0; }
.btn-principal { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-principal:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-vert { background: var(--green); border-color: var(--green); color: #fff; }
.btn-danger { color: var(--red); }
.btn-petit { padding: 6px 10px; font-size: 13px; }
.btn-bloc { width: 100%; white-space: normal; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.lien { background: none; border: 0; color: var(--brand); font: inherit; cursor: pointer; padding: 0; }

.champ { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.champ > span { font-size: 13px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 111, 181, .25); border-color: var(--brand); }
textarea { min-height: 80px; resize: vertical; }
.grille2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grille3 { display: grid; grid-template-columns: 2fr 1fr 2fr; gap: 0 12px; }
.erreur { color: var(--red); font-weight: 600; margin: 10px 0 0; }
.cases { display: flex; flex-wrap: wrap; gap: 6px; }
.case { display: flex; align-items: center; gap: 7px; border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer; font-size: 14px; color: var(--ink); }
.case input { width: auto; margin: 0; accent-color: var(--brand); }
.case:has(input:checked) { border-color: var(--brand); background: #e8f1fa; color: var(--brand-dark); font-weight: 700; }

/* ---------- Connexion ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(160deg, var(--navy), #164a6c); }
.login-card { background: #fff; border-radius: 18px; box-shadow: var(--shadow); padding: 28px; width: 100%; max-width: 380px; }
.login-logo { height: 46px; display: block; margin-bottom: 18px; }
.login-card h1 { margin-bottom: 2px; }
.login-card p.muted { margin: 0 0 18px; }

/* ---------- Mise en page ---------- */
#app { display: flex; min-height: 100vh; }
.sidebar {
  --side-bg: #0f2c40;
  --side-carte: #173a52;
  --side-ligne: rgba(255, 255, 255, .09);
  --side-texte: #e7eef5;
  --side-gris: #8aa3b8;
  width: 260px; flex: none;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--side-bg); color: var(--side-texte);
  display: flex; flex-direction: column; z-index: 30;
}
.side-marque { display: flex; justify-content: center; padding: 20px 20px 18px; border-bottom: 1px solid var(--side-ligne); }
.side-marque img { height: 76px; width: auto; display: block; }
.side-hello { padding: 22px 18px 6px; }
.side-hello-titre { font-size: 22px; font-weight: 700; color: #fff; }
.side-hello-titre span:not(:empty)::before { content: ", "; }
.side-hello-sous { opacity: .85; font-size: 14px; margin-top: 2px; }
.side-nav { padding: 0 18px 18px; flex: 1; display: block; }
.side-label { font-size: 12px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--side-gris); margin: 20px 0 8px 14px; }
.side-groupe { background: var(--side-carte); border: 1px solid var(--side-ligne); border-radius: 16px; padding: 6px; }
.side-nav button, .side-deconnexion {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: none; border: 0; cursor: pointer; text-align: left;
  font: inherit; font-size: 15px; font-weight: 600; color: var(--side-texte);
  padding: 12px 14px; border-radius: 11px; transition: background .15s, color .15s;
}
.side-nav svg, .side-deconnexion svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; opacity: .9; }
.side-nav button:hover, .side-deconnexion:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.side-nav button.actif { background: var(--brand); color: #fff; box-shadow: 0 6px 14px rgba(0, 0, 0, .18); }
.pastille { margin-left: auto; background: var(--orange); color: #fff; font-style: normal; font-size: 12px; font-weight: 700; border-radius: 99px; padding: 1px 8px; }
.side-pied { border-top: 1px solid var(--side-ligne); }
.side-deconnexion { padding: 20px 32px; border-radius: 0; }
.side-version { border-top: 1px solid var(--side-ligne); text-align: center; color: var(--side-gris); font-size: 13px; padding: 14px; }
.side-voile { display: none; }
.btn-menu { display: none; font: inherit; font-size: 20px; line-height: 1; border: 1px solid var(--line); background: #fff; color: var(--ink); width: 40px; height: 40px; border-radius: 10px; cursor: pointer; flex: none; }

/* Téléphone / petite tablette : le menu glisse depuis la gauche (comme le CRM entretien) */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; height: auto; transform: translateX(-100%); transition: transform .2s ease; padding-top: env(safe-area-inset-top); }
  body.menu-ouvert .sidebar { transform: none; box-shadow: 10px 0 30px rgba(0, 0, 0, .25); }
  body.menu-ouvert .side-voile { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(10, 25, 40, .45); }
  .btn-menu { display: inline-flex; align-items: center; justify-content: center; }
}

.contenu { flex: 1; min-width: 0; padding: 22px 26px 40px; }
.entete { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }

/* ---------- Cartes ---------- */
.carte { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 26px; line-height: 1.1; margin-top: 4px; }
.stat span { color: var(--muted); font-size: 13px; font-weight: 600; }
.deux-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.liste-ligne {
  display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.liste-ligne:last-child { border-bottom: 0; }
.liste-ligne:hover { background: #f9fbfd; }
.liste-ligne .qui { flex: 1; min-width: 0; }
.liste-ligne .qui b { display: block; }
.liste-ligne .qui small { color: var(--muted); }
.vide { color: var(--muted); padding: 18px 4px; text-align: center; }

.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.badge.eligible { background: var(--green-bg); color: var(--green); }
.badge.a_revoir { background: var(--orange-bg); color: var(--orange); }
.badge.non_eligible { background: var(--red-bg); color: var(--red); }
.badge.attente { background: #eef2f7; color: var(--muted); }
.badge.etape { background: #e8f1fa; color: var(--brand-dark); }

/* ---------- Filtres ---------- */
.barre { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.barre input[type=search] { max-width: 280px; }
.puces { display: flex; gap: 6px; flex-wrap: wrap; }
.puce { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 6px 12px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink); }
.puce.on { background: var(--navy); border-color: var(--navy); color: #fff; }

/* ---------- Chantiers (colonnes) ---------- */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.colonne { background: #eef2f6; border-radius: var(--radius); padding: 10px; width: 250px; flex-shrink: 0; }
.colonne h3 { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 4px 8px; color: #3b4b5d; }
.carte-chantier { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.carte-chantier:hover { border-color: #b9c8d8; }
.carte-chantier b { display: block; font-size: 14px; }
.carte-chantier small { color: var(--muted); display: block; }
.carte-chantier .prod { font-size: 12px; margin-top: 4px; color: var(--brand-dark); font-weight: 600; }

/* ---------- Fenêtre ---------- */
.modale { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 30px 16px; overflow-y: auto; }
.modale-fond { position: fixed; inset: 0; background: rgba(10, 25, 40, .45); }
.modale-boite { position: relative; background: #fff; border-radius: 18px; width: 100%; max-width: 760px; padding: 24px; box-shadow: var(--shadow); }
.modale-boite.large { max-width: 980px; }
.modale-x { position: absolute; top: 10px; right: 12px; background: none; border: 0; font-size: 28px; line-height: 1; cursor: pointer; color: var(--muted); }
.modale h2 { font-size: 19px; margin-bottom: 4px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }

/* ---------- QCM ---------- */
.qcm { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.qcm-groupe { margin-bottom: 18px; }
.qcm-groupe > h3 { text-transform: uppercase; letter-spacing: .04em; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.qcm-q { margin: 10px 0 14px; }
.qcm-q > div:first-child { font-weight: 600; margin-bottom: 6px; }
.qcm-q.manque > div:first-child::after { content: " •"; color: var(--orange); }
.choix { display: flex; flex-wrap: wrap; gap: 6px; }
.choix button { border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 12px; font: inherit; font-size: 14px; cursor: pointer; color: var(--ink); }
.choix button:hover { border-color: #b9c8d8; }
.choix button.on { border-color: var(--brand); background: #e8f1fa; color: var(--brand-dark); font-weight: 700; }
.resultat { position: sticky; top: 10px; border-radius: var(--radius); padding: 16px; border: 1px solid var(--line); background: #f9fbfd; }
.resultat .jauge { height: 10px; background: #e5eaf0; border-radius: 99px; overflow: hidden; margin: 8px 0 12px; }
.resultat .jauge i { display: block; height: 100%; border-radius: 99px; transition: width .25s; }
.resultat .note { font-size: 32px; font-weight: 800; }
.resultat ul { margin: 6px 0 12px; padding-left: 18px; font-size: 13.5px; }
.resultat li { margin-bottom: 5px; }
.resultat.eligible { border-color: #b6dfc6; background: var(--green-bg); }
.resultat.a_revoir { border-color: #f0d6a8; background: var(--orange-bg); }
.resultat.non_eligible { border-color: #efc1bc; background: var(--red-bg); }

/* ---------- Fiche dossier ---------- */
.fiche-tete { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 14px; padding-right: 30px; }
.fiche-tete .infos { flex: 1; min-width: 200px; }
.fiche-tete .infos a { text-decoration: none; font-weight: 600; }
.frise { display: flex; gap: 4px; overflow-x: auto; margin: 6px 0 18px; padding-bottom: 4px; }
.frise button { flex: 1; min-width: 92px; border: 0; background: #eef2f6; color: var(--muted); border-radius: 8px; padding: 8px 6px; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; }
.frise button.fait { background: #d6e8f6; color: var(--brand-dark); }
.frise button.courant { background: var(--brand); color: #fff; }
.bloc { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.bloc-alerte { border-color: #f0d6a8; background: var(--orange-bg); }
.histo { list-style: none; padding: 0; margin: 0; font-size: 13px; max-height: 220px; overflow-y: auto; }
.histo li { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.histo time { color: var(--muted); margin-right: 6px; }
.reponses { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; font-size: 13.5px; }
.reponses span { color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 80; font-weight: 600; box-shadow: var(--shadow); }

/* ---------- Téléphone ---------- */
@media (max-width: 860px) {
  .qcm { grid-template-columns: 1fr; }
  .resultat { position: static; }
  .deux-col { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  #app { flex-direction: column; }
  .contenu { padding: 16px 16px 40px; }
  .entete h1 { font-size: 19px; }
  .grille2, .grille3, .reponses { grid-template-columns: 1fr; }
  .modale { padding: 0; }
  .modale-boite { border-radius: 0; min-height: 100vh; padding: 18px 16px 40px; }
  .barre input[type=search] { max-width: none; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat b { font-size: 21px; }
  .toast { bottom: calc(24px + env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 32px); }
  .entete .btn { padding: 8px 12px; }
}

/* ---------- Dossiers CEE ---------- */
.cee-barre { height: 7px; background: #e5eaf0; border-radius: 99px; overflow: hidden; margin: 6px 0 3px; max-width: 360px; }
.cee-barre i { display: block; height: 100%; border-radius: 99px; }
.bloc-rouge { border-color: #efc1bc; background: var(--red-bg); }
.bloc-rouge .petit, .bloc-alerte .petit { margin: 2px 0; }
.guide-cee summary { cursor: pointer; }
.guide-cee h3 { margin-top: 16px; }
.guide-cee ul { padding-left: 18px; }
.guide-phase { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--brand-dark); margin-top: 12px; }
.guide-etapes li { margin-bottom: 8px; }
.cee-etape { border-top: 1px solid var(--line); padding: 10px 0; }
.cee-etape:first-of-type { border-top: 0; }
.cee-etape.fait .cee-coche b { color: var(--green); }
.cee-ligne { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cee-coche { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 220px; cursor: pointer; }
.cee-coche input { width: 20px; height: 20px; margin: 0; accent-color: var(--green); flex-shrink: 0; }
.cee-date { width: auto; padding: 6px 8px; font-size: 13px; }
.cee-aide { margin: 4px 0 0 28px; color: var(--muted); }
.cee-aide summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.mentions { margin: 8px 0 0 28px; padding: 8px 10px; background: #f9fbfd; border-radius: 8px; }
.mention { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; padding: 2px 0; cursor: pointer; }
.mention input { width: auto; margin: 3px 0 0; accent-color: var(--green); }
.cee-pieces { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0 0 28px; }
.piece { display: inline-flex; align-items: center; gap: 4px; background: #eef2f6; border-radius: 8px; padding: 4px 8px; font-size: 13px; max-width: 100%; }
.piece a { text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.piece .lien { font-size: 18px; line-height: 1; color: var(--red); }
.ajout-piece { font-weight: 600; color: var(--brand); }
@media (max-width: 720px) {
  .cee-aide, .mentions, .cee-pieces { margin-left: 0; }
}
.liste-ligne .qui small b { display: inline; }
.dim-calc { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 6px; }
.dim-calc span { display: block; font-size: 12px; color: var(--muted); }
.dim-calc b { font-size: 18px; }
@media (max-width: 720px) { .dim-calc { grid-template-columns: 1fr 1fr; } }
.bloc-ia { border-color: #d9ccf5; background: #f7f3ff; }
.bloc-ia textarea { min-height: 70px; background: #fff; }
.ia-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.ia-retour { margin-top: 10px; font-size: 13.5px; background: #fff; border-radius: 10px; padding: 10px 12px; border: 1px solid #d9ccf5; }
.ia-retour ul { margin: 6px 0 0; padding-left: 18px; }
.rempli-ia { border-color: #8b5cf6 !important; background: #f7f3ff !important; }
.sig-dim { margin: 10px 0 0 28px; padding: 10px 12px; border: 1px solid #c9dcef; background: #f4f9fe; border-radius: 10px; font-size: 14px; }
.sig-dim.signe { border-color: #b6dfc6; background: var(--green-bg); }
.sig-ligne { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; font-size: 13.5px; }
.pad-signature { display: block; width: 100%; height: 190px; border: 2px dashed #cbd5e1; border-radius: 12px; background: #fff; touch-action: none; user-select: none; margin: 6px 0; }
@media (max-width: 720px) { .sig-dim { margin-left: 0; } }
