:root {
  --gris-fond:    #e8e9ec;
  --gris-fond-2:  #dfe1e5;
  --carte:        #ffffff;
  --carte-bord:   #d2d5db;
  --texte:        #1f2733;
  --texte-doux:   #5b6573;
  --bleu:         #1d4e89;
  --bleu-clair:   #2f6fb8;
  --bleu-pale:    #eef4fb;
  --or:           #c8961e;
  --vert:         #2e7d4f;
  --vert-pale:    #e7f3ec;
  --rouge:        #b3261e;
  --rouge-pale:   #fbeceb;
  --rouge-accent: #c0272d;   /* rouge d'habillage (logo, titres, actifs) */
  --ombre:        0 1px 2px rgba(20,30,45,.06), 0 4px 14px rgba(20,30,45,.06);
  --rayon:        10px;
}

/* ------------------------------------------------ Thème sombre (fond noir) */
html[data-theme="sombre"] {
  --gris-fond:    #15171c;
  --gris-fond-2:  #21252c;
  --carte:        #1e222a;
  --carte-bord:   #363c47;
  --texte:        #e7eaef;
  --texte-doux:   #9aa4b2;
  --bleu:         #3d7cc4;
  --bleu-clair:   #6ea6de;
  --bleu-pale:    #1d2b3d;
  --or:           #d4a72c;
  --vert:         #4f9d72;
  --vert-pale:    #1e3128;
  --rouge:        #e0655c;
  --rouge-pale:   #3b211f;
  --rouge-accent: #e05a52;
  --ombre:        0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.35);
}
html[data-theme="sombre"] .input,
html[data-theme="sombre"] select.input {
  background: #262b34; color: var(--texte); border-color: var(--carte-bord);
}
html[data-theme="sombre"] .dropzone { background: #232830; }
html[data-theme="sombre"] .dropzone:hover,
html[data-theme="sombre"] .dropzone.survol { background: var(--bleu-pale); }
html[data-theme="sombre"] .fichier { background: var(--vert-pale); border-color: #3a5c49; }
html[data-theme="sombre"] .fichier .mini { background: #262b34; border-color: #3a5c49; }
html[data-theme="sombre"] .alerte-attention { background: #33270f; border-color: #6b5416; color: #e8c568; }
html[data-theme="sombre"] .alerte-info      { background: var(--bleu-pale); border-color: #2b466b; color: #a9c8ea; }
html[data-theme="sombre"] .alerte-ok        { background: var(--vert-pale); border-color: #35604a; color: #9fd4b6; }
html[data-theme="sombre"] .alerte-err       { background: var(--rouge-pale); border-color: #6b3330; color: #eda49e; }
html[data-theme="sombre"] .btn-sec { background: #262b34; color: var(--bleu-clair); }
html[data-theme="sombre"] .btn-sec:hover { background: var(--gris-fond-2); }
html[data-theme="sombre"] .pwd-box { background: var(--bleu-pale); color: var(--bleu-clair); }
html[data-theme="sombre"] .marque .plaque { border-color: var(--bleu); }
html[data-theme="sombre"] .dropzone.analyse { background: #2e2712; }

/* Bouton flottant de bascule clair/sombre */
#btnTheme {
  display: inline-flex; align-items: center; justify-content: center;
  vertical-align: middle; margin-left: 12px;
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--carte-bord);
  background: var(--carte); color: var(--texte);
  font-size: 16px; cursor: pointer;
  box-shadow: var(--ombre);
  transition: transform .12s;
}
/* Position de secours si une page n'a pas de titre */
#btnTheme.flottant { position: fixed; bottom: 18px; right: 18px; z-index: 60; }
#btnTheme:hover { transform: scale(1.08); }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* FOND DU SITE — image CERFY, posée UNE fois, fixe au défilement.
     Un voile clair est superposé pour que texte et cartes restent
     parfaitement lisibles ; le thème sombre a le sien, plus dense.
     La couleur unie reste en secours si l'image ne charge pas. */
  background: var(--gris-fond) url('../img/fond-cerfy.jpg') center / cover no-repeat fixed;
  color: var(--texte);
  line-height: 1.5;
  font-size: 15px;
}

/* Voile de lisibilité au-dessus du fond : les pages restent claires. */
body::after{
  content:'';position:fixed;inset:0;z-index:-1;pointer-events:none;
  /* Voile LÉGER : l'image reste visible, le texte hors carte reste lisible.
     Les cartes ayant leur propre fond opaque, un voile discret suffit. */
  background:linear-gradient(180deg, rgba(255,255,255,.34), rgba(238,242,248,.46));
}
html[data-theme="sombre"] body::after{
  background:linear-gradient(180deg, rgba(10,13,18,.55), rgba(8,10,14,.66));
}
/* Sur petits écrans, le fond fixe coûte cher en défilement : il devient normal. */
@media (max-width: 820px){ body{ background-attachment: scroll; } }


a { color: var(--bleu-clair); }

/* ----------------------------------------------------------- En-tête */
.entete {
  background: var(--carte);
  border-bottom: 1px solid var(--carte-bord);
}
.entete-inner {
  max-width: 1060px;
  margin: 0 auto;
  padding: 7px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.marque {
  display: flex; align-items: center; gap: 12px;
  text-decoration: none; color: var(--texte);
  flex-shrink: 0;               /* le bloc de marque ne se replie jamais */
}
.marque .plaque {
  font-weight: 700; letter-spacing: .5px;
  background: var(--bleu); color: #fff;
  border-radius: 6px; padding: 6px 10px; font-size: 14px;
  border: 2px solid var(--bleu);
}
.marque .plaque .ue { color: var(--or); }
.marque .nom { font-weight: 700; font-size: 16px; line-height: 1.15; white-space: nowrap; }
.marque .sous { font-size: 12px; color: var(--texte-doux); white-space: nowrap; }

.nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; margin-left: auto; flex-shrink: 0; }
@media (min-width: 641px) { .nav { flex-wrap: nowrap; } }
.nav a {
  text-decoration: none; color: var(--texte-doux);
  padding: 6px 12px; border-radius: 7px; font-weight: 600; font-size: 14px;
  line-height: 1.2;
}
.nav a:hover { background: var(--gris-fond-2); color: var(--texte); }
.nav a.actif { background: var(--bleu-pale); color: var(--bleu); }
.nav .deco { color: var(--rouge); }

/* ----------------------------------------------------------- Layout */
.page { max-width: 1060px; margin: 0 auto; padding: 28px 22px 60px; }
.centre { max-width: 440px; margin: 7vh auto 0; }

.carte {
  background: var(--carte);
  border: 1px solid var(--carte-bord);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 26px;
}

h1 { font-size: 24px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0 0 12px; }
.lead { color: var(--texte-doux); margin: 0 0 22px; }

/* ----------------------------------------------------------- Bienvenue */
.bienvenue {
  margin-bottom: 22px;
  padding: 18px 22px;
  border-left: 4px solid var(--bleu);
  border-radius: 0 var(--rayon) var(--rayon) 0;
}
.bonjour { font-size: 19px; }
.bonjour b { color: var(--bleu); }
.coordonnees {
  margin-top: 6px; font-size: 13px; color: var(--texte-doux);
  display: flex; flex-wrap: wrap; gap: 6px 18px;
}
.entete .partenaire-nom {
  font-size: 12.5px; color: var(--texte-doux);
  padding: 4px 10px; background: var(--gris-fond);
  border-radius: 7px; white-space: nowrap;
  /* Un nom d'entreprise long se tronque au lieu de pousser la navigation
     à la ligne ; le nom complet reste lisible au survol (attribut title). */
  max-width: 30ch; overflow: hidden; text-overflow: ellipsis;
  flex: 0 1 auto; min-width: 0;
}
@media (max-width: 900px) {
  .marque .sous { display: none; }          /* le sous-titre s'efface avant de casser */
  .entete .partenaire-nom { max-width: 18ch; }
}

/* ----------------------------------------------------------- Alerte */
.alerte {
  border-radius: 8px; padding: 12px 14px; font-size: 14px;
  display: flex; gap: 10px; align-items: flex-start;
}
.alerte .ico { font-size: 18px; line-height: 1.3; }
.alerte-attention { background: #fdf3e3; border: 1px solid #f0d9a8; color: #7a5410; }
.alerte-info      { background: var(--bleu-pale); border: 1px solid #cfe0f3; color: var(--bleu); }
.alerte-ok        { background: var(--vert-pale); border: 1px solid #bfe0cc; color: var(--vert); }
.alerte-err       { background: var(--rouge-pale); border: 1px solid #f0c5c2; color: var(--rouge); }

/* ----------------------------------------------------------- Formulaire */
label.champ { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
.input {
  width: 100%; padding: 11px 13px; font-size: 15px;
  border: 1px solid var(--carte-bord); border-radius: 8px;
  background: #fff; color: var(--texte);
}
.input:focus { outline: none; border-color: var(--bleu-clair); box-shadow: 0 0 0 3px var(--bleu-pale); }
textarea.input { resize: vertical; min-height: 90px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--bleu); color: #fff; border: none; cursor: pointer;
  padding: 12px 18px; border-radius: 8px; font-size: 15px; font-weight: 600;
  text-decoration: none; transition: background .15s;
}
.btn:hover { background: var(--bleu-clair); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-bloc { width: 100%; }
.btn-sec { background: #fff; color: var(--bleu); border: 1px solid var(--carte-bord); }
.btn-sec:hover { background: var(--gris-fond-2); }
.btn-danger { background: var(--rouge); }
.btn-danger:hover { background: #8f1d17; }

.lien-discret {
  background: none; border: none; color: var(--bleu-clair);
  cursor: pointer; font-size: 14px; padding: 0; text-decoration: underline;
}

/* ----------------------------------------------------------- Grille documents */
.bandeau-avert {
  margin-bottom: 20px;
}
.grille-docs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}
.doc {
  background: var(--carte);
  border: 1px solid var(--carte-bord);
  border-radius: 10px;
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.doc-titre { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 7px; }
.doc-titre .num { color: var(--texte-doux); font-weight: 600; font-size: 12px; }

.dropzone {
  border: 2px dashed var(--carte-bord);
  border-radius: 8px;
  padding: 16px 10px;
  text-align: center;
  color: var(--texte-doux);
  font-size: 13px;
  cursor: pointer;
  background: #fafbfc;
  transition: border-color .15s, background .15s;
}
.dropzone:hover { border-color: var(--bleu-clair); background: var(--bleu-pale); }
.dropzone.survol { border-color: var(--bleu); background: var(--bleu-pale); }
.dropzone.analyse { border-color: var(--or); background: #fdf8ec; cursor: wait; }
.dropzone.analyse::after { content: " Analyse du document…"; display:block; color: var(--or); font-weight:600; margin-top:4px; }
.dropzone .plus { font-size: 22px; display: block; margin-bottom: 2px; color: var(--bleu-clair); }

.doc.rempli { border-color: var(--vert); }
.doc.erreur { border-color: var(--rouge); }
.doc.conseillee { border-left: 4px solid var(--bleu); }
.doc.conseillee .doc-titre::after {
  content: "conseillée"; font-size: 10px; font-weight: 700;
  color: var(--bleu); background: var(--bleu-pale);
  padding: 2px 7px; border-radius: 10px; margin-left: auto;
}

.fichier {
  display: none;
  align-items: center; gap: 8px;
  background: var(--vert-pale); border: 1px solid #bfe0cc;
  border-radius: 8px; padding: 9px 11px; font-size: 13px;
}
.fichier.actif { display: flex; }
.fichier .nom { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.fichier .nom:hover { text-decoration: underline; }
.fichier .mini {
  width: 34px; height: 44px; object-fit: cover; object-position: top;
  border: 1px solid #bfe0cc; border-radius: 4px; background: #fff;
  cursor: zoom-in; flex-shrink: 0;
}
.fichier .mini:hover { border-color: var(--bleu-clair); box-shadow: 0 0 0 2px var(--bleu-pale); }
.fichier .retirer { background: none; border: none; color: var(--rouge); cursor: pointer; font-size: 16px; }

/* Modale aperçu */
.modale-apercu { max-width: 680px; max-height: 88vh; display: flex; flex-direction: column; }
.apercu-entete { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.apercu-pages { overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.apercu-page img {
  width: 100%; height: auto; display: block;
  border: 1px solid var(--carte-bord); border-radius: 6px;
  box-shadow: 0 2px 10px rgba(20,30,45,.08);
}
.apercu-legende { font-size: 12px; color: var(--texte-doux); margin-bottom: 4px; font-weight: 600; }
.msg-erreur { display: none; color: var(--rouge); font-size: 12px; }
.msg-erreur.actif { display: block; }

.barre-envoi {
  position: sticky; bottom: 0;
  margin-top: 22px; padding: 16px 0 0;
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
}
.compteur { font-size: 14px; color: var(--texte-doux); }
.compteur b { color: var(--texte); }

/* ----------------------------------------------------------- Modale */
.modale-fond {
  display: none; position: fixed; inset: 0;
  background: rgba(20,28,40,.45); z-index: 50;
  align-items: center; justify-content: center; padding: 20px;
}
.modale-fond.actif { display: flex; }
.modale {
  background: #fff; border-radius: 12px; max-width: 420px; width: 100%;
  padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

/* ----------------------------------------------------------- Admin */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--carte-bord); }
.table th { color: var(--texte-doux); font-weight: 600; background: var(--gris-fond); }
.pwd-box {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 20px; letter-spacing: 2px; font-weight: 700;
  background: var(--bleu-pale); color: var(--bleu);
  padding: 12px 16px; border-radius: 8px; text-align: center;
}
.pied { text-align: center; color: var(--texte-doux); font-size: 12px; margin-top: 36px; }

@media (max-width: 560px) {
  .entete-inner { flex-direction: column; align-items: flex-start; gap: 10px; }
  .nav { flex-wrap: wrap; }
}


/* ===================== Habillage bleu / gris / rouge ===================== */
/* Liseré rouge en haut du site */
.entete { border-top: 3px solid var(--rouge-accent); }

/* Logo : plaque bordée de rouge, point rouge */
.marque .plaque { border-color: var(--rouge-accent); }
.marque .plaque .ue { color: var(--rouge-accent); }

/* Titres de page : barre d'accent rouge */
h1 { border-left: 4px solid var(--rouge-accent); padding-left: 12px; }
.carte h2 { border-left: 3px solid var(--rouge-accent); padding-left: 10px; }

/* Lien actif de la navigation souligné de rouge */
.nav a.actif { color: var(--rouge-accent); box-shadow: inset 0 -2px 0 var(--rouge-accent); }

/* Déconnexion en rouge */
.nav a.deco { color: var(--rouge-accent); }

/* Compteur de pièces : chiffre en rouge */
.compteur b { color: var(--rouge-accent); font-size: 17px; }

/* Numéro des cases de pièces en rouge */
.doc .doc-titre .num { color: var(--rouge-accent); }

/* Bouton principal : bleu, passage au rouge sombre au survol */
.btn:hover { background: #8f1d22; }

/* Pied de page : rappel du liseré */
.pied { border-top: 2px solid var(--rouge-accent); padding-top: 12px; }

/* Badge conseillée inchangé (bleu) — le rouge reste réservé à l'identité et aux erreurs */


/* Logo image dans l'en-tête */
.marque .logo-img { height: 40px; width: auto; display: block; }
@media (max-width: 640px) { .marque .logo-img { height: 34px; } }
/* Lisibilité du logo sur fond sombre */
html[data-theme="sombre"] .marque .logo-img { filter: drop-shadow(0 0 3px rgba(255,255,255,.45)); }


/* Logo complet sur la page d'accueil */
.logo-accueil { text-align: center; margin: 6px 0 18px; }
.logo-accueil img { height: 170px; width: auto; }
@media (max-width: 640px) { .logo-accueil img { height: 130px; } }
html[data-theme="sombre"] .logo-accueil img { filter: drop-shadow(0 0 4px rgba(255,255,255,.45)); }

/* ===================== Mode assisté IA ===================== */
.ia-carte { border-left: 4px solid var(--bleu); }
.ia-entete { display:flex; justify-content:space-between; gap:16px; align-items:flex-start; }
.ia-badge { flex:0 0 auto; font-size:12px; font-weight:700; border-radius:999px; padding:5px 10px; }
.ia-badge.ok { color:var(--vert); background:var(--vert-pale); border:1px solid #bfe0cc; }
.ia-badge.off { color:#7a5410; background:#fdf3e3; border:1px solid #f0d9a8; }
.ia-dropzone { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px; margin-top:16px; min-height:118px; border:2px dashed var(--bleu-clair); border-radius:10px; background:var(--bleu-pale); color:var(--texte); cursor:pointer; text-align:center; padding:18px; }
.ia-dropzone.survol { outline:3px solid rgba(47,111,184,.16); }
.ia-dropzone span:last-child { color:var(--texte-doux); font-size:12px; }
.ia-plus { font-size:27px; color:var(--bleu); line-height:1; }
.ia-fichiers { display:grid; gap:6px; margin-top:10px; }
.ia-fichier { display:flex; justify-content:space-between; gap:10px; align-items:center; border:1px solid var(--carte-bord); background:var(--carte); border-radius:7px; padding:7px 10px; font-size:12.5px; }
.ia-x { border:0; background:transparent; color:var(--rouge); cursor:pointer; font-weight:700; }
.ia-actions { display:flex; gap:10px; flex-wrap:wrap; margin-top:12px; }
.ia-progress { height:8px; background:var(--gris-fond-2); overflow:hidden; border-radius:99px; margin-top:12px; }
.ia-progress > div { width:0%; height:100%; background:var(--bleu); transition:width .2s ease; }
.ia-table-wrap { overflow-x:auto; }
.ia-table td:nth-child(1) { max-width:220px; overflow:hidden; text-overflow:ellipsis; }
.ia-etat { font-size:12px; font-weight:600; }
.ia-etat.good { color:var(--vert); }.ia-etat.warn { color:#a06500; }.ia-etat.bad { color:var(--rouge); }.ia-etat.info { color:var(--bleu); }
.ia-controles { display:grid; gap:8px; margin-top:12px; }
.ia-confidentialite { margin-top:14px; color:var(--texte-doux); font-size:11.5px; }
.ia-confidentialite code { font-size:11px; }
html[data-theme="sombre"] .ia-badge.ok { border-color:#35604a; }
html[data-theme="sombre"] .ia-badge.off { background:#33270f; border-color:#6b5416; color:#e8c568; }
@media (max-width:640px){ .ia-entete{flex-direction:column}.ia-badge{align-self:flex-start}.ia-fichier{align-items:flex-start;flex-direction:column} }

/* IMPRESSION — le fond ne doit jamais partir sur le papier : ni image, ni
   voile. Les Cerfa, attestations et listes s'impriment sur fond blanc. */
@media print{
  body{ background:#fff !important; }
  body::after, body::before{ display:none !important; }
}
