:root {
  --or: #b8892c;
  --or-clair: #f5ecd9;
  --gris-entete: #7f7f7f;
  --gris-ligne: #f2f2f2;
  --bordure: #c8c8c8;
  --texte: #1d1d1d;
  --vert: #2e7d32;
  --rouge: #b3261e;
  --orange: #c77700;
  --fond: #eceae6;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --serif: Garamond, 'EB Garamond', 'Times New Roman', serif;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--sans); color: var(--texte); background: var(--fond); font-size: 15px; }
main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }
a { color: #1a4f8b; }
h1, h2 { margin: 0 0 12px; }
h2 { font-size: 1.1rem; }

/* ---------- Barre supérieure ---------- */
.topbar { display: flex; align-items: center; gap: 24px; padding: 8px 24px; background: #fff; border-bottom: 3px solid var(--or); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; font-weight: 600; }
.brand img { height: 40px; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { padding: 8px 14px; border-radius: 6px; text-decoration: none; color: #444; }
.topbar nav a:hover { background: var(--gris-ligne); }
.topbar nav a.actif { background: var(--or-clair); color: #6b4c10; font-weight: 600; }
.session { display: flex; align-items: center; gap: 12px; color: #555; font-size: .9rem; }
.session form { margin: 0; }

/* ---------- Composants ---------- */
.bouton { display: inline-block; padding: 8px 14px; border: 1px solid var(--or); border-radius: 6px; background: #fff;
  color: #6b4c10; font: inherit; text-decoration: none; cursor: pointer; }
.bouton:hover { background: var(--or-clair); }
.bouton.plein { background: var(--or); color: #fff; }
.bouton.plein:hover { background: #9e7424; }
.bouton.petit { padding: 4px 10px; font-size: .85rem; }
.bouton.danger { border-color: var(--rouge); color: var(--rouge); }
.bouton.danger:hover { background: #fbeaea; }
button.lien { background: none; border: 0; color: #1a4f8b; cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }
a.lien { font-size: .9rem; }

.carte { background: #fff; border-radius: 10px; padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.centre { text-align: center; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }
.flash-succes { background: #e8f5e9; color: var(--vert); border: 1px solid #a5d6a7; }
.flash-erreur { background: #fbeaea; color: var(--rouge); border: 1px solid #f1b0ab; }

.progression { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; color: #555; }
.jauge { display: inline-block; width: 140px; height: 8px; background: #e0e0e0; border-radius: 4px; overflow: hidden; }
.jauge span { display: block; height: 100%; background: var(--vert); }

.statut { font-size: 1.25rem; line-height: 1; }
.statut-obtenu { color: var(--vert); }
.statut-incomplet { color: var(--orange); }
.statut-manquant { color: #555; }

/* ---------- Connexion ---------- */
.login { max-width: 380px; margin: 60px auto; background: #fff; padding: 32px; border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.08); text-align: center; }
.login-logo { width: 130px; }
.login h1 { font-size: 1.3rem; margin-top: 12px; }
.sous-titre { color: #777; margin-top: -6px; }
.login form { display: flex; flex-direction: column; gap: 14px; text-align: left; margin-top: 20px; }

/* ---------- Formulaires ---------- */
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; font-weight: 500; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--bordure); border-radius: 6px; font-weight: 400; }
input[type=file] { padding: 6px; }
.form-pile { display: flex; flex-direction: column; gap: 14px; }
.form-pile button { align-self: flex-start; }
.form-ligne { display: flex; gap: 6px; margin: 0; }
.form-ligne input { flex: 1; min-width: 0; padding: 4px 8px; }
.aide { font-size: .82rem; color: #666; margin: 0; }
.choix-statut { border: 0; padding: 0; margin: 0; display: flex; gap: 18px; }
.choix-statut label { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }

/* ---------- Récépissé (fidèle au document) ---------- */
.barre-outils { display: flex; justify-content: space-between; align-items: center; max-width: 900px; margin: 0 auto 12px; }
.feuille { max-width: 900px; margin: 0 auto; background: #fff; padding: 40px 48px 28px; font-family: var(--serif);
  font-size: 15.5px; box-shadow: 0 2px 10px rgba(0,0,0,.12); }
.logo-doc { width: 155px; display: block; }
.cadre-titre { margin: 18px 0 28px; border: 6px solid #000; padding: 3px; }
.cadre-titre h1 { border: 1.5px solid #000; padding: 12px 18px; font-size: 1.3rem; line-height: 1.35; text-align: justify; }
.feuille p { margin: 0 0 12px; line-height: 1.45; }
.feuille .retrait { margin: 18px 0 18px 40px; }

.tableau-doc { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.tableau-doc th { background: var(--gris-entete); color: #fff; padding: 8px 6px; text-align: center; font-weight: 700;
  border: 1px solid #fff; border-bottom: 0; }
.tableau-doc td { border: 1px solid var(--bordure); padding: 4px 8px; vertical-align: middle; line-height: 1.3; }
.tableau-doc tbody tr:nth-child(odd) { background: var(--gris-ligne); }
.tableau-doc .c-num { width: 34px; text-align: center; }
.tableau-doc .c-statut { width: 82px; text-align: center; }
.tableau-doc .c-obs { width: 150px; font-size: 13.5px; }
.tableau-doc.avec-ref .c-ref { width: 170px; text-align: center; }
.tableau-doc.avec-ref .c-obs { width: 140px; }
.tableau-doc .c-num { font-weight: 400; }
.tableau-doc.avec-ref td.c-num { font-weight: 700; }
.puces { margin: 2px 0; padding-left: 20px; list-style: '-   '; }
.puces li { padding-left: 4px; }

.bouton-piece { display: table; margin: 6px 0 4px; padding: 3px 10px; border-radius: 4px; font-family: var(--sans);
  font-size: 12.5px; text-decoration: none; background: var(--or); color: #fff; }
.bouton-piece:hover { background: #9e7424; }
.bouton-piece.vide { background: transparent; color: #777; border: 1px dashed #aaa; }
.bouton-piece.vide:hover { background: #fff; color: #444; }

.pied-doc { margin-top: 40px; padding-top: 6px; border-top: 1px dotted #888; text-align: center; font-family: Cambria, Georgia, serif;
  font-size: 13px; line-height: 1.4; }
.pied-doc a { font-weight: 700; color: #0563c1; }

/* ---------- Sous-page d'un élément ---------- */
.fil { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.nav-voisins { display: flex; gap: 14px; align-items: center; }
.element-entete { display: flex; gap: 18px; align-items: flex-start; }
.pastille-num { flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--or); color: #fff; display: grid;
  place-items: center; font-weight: 700; font-size: 1.1rem; }
.element-texte { flex: 1; font-family: var(--serif); font-size: 16px; line-height: 1.45; }
.element-etat { flex: none; width: 230px; font-size: .9rem; border-left: 1px solid #eee; padding-left: 16px; }
.observations { margin: 8px 0 0; color: #444; }
.reference { font-style: italic; color: #666; margin: 6px 0 0; }
.surtitre { text-transform: uppercase; font-family: var(--sans); font-size: .75rem; letter-spacing: .06em; color: var(--or); margin: 0 0 4px; }
.vide-etat { color: #777; text-align: center; }

.pieces { display: grid; grid-template-columns: 300px 1fr; gap: 16px; }
.liste-pieces { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.liste-pieces li { background: #fff; border-radius: 8px; padding: 12px; border: 2px solid transparent; display: flex; flex-direction: column; gap: 4px; }
.liste-pieces li.actif { border-color: var(--or); }
.piece-titre { font-weight: 600; text-decoration: none; color: var(--texte); }
.meta { font-size: .8rem; color: #777; word-break: break-all; }
.lien-dl { font-size: .85rem; }
.apercu { background: #fff; border-radius: 8px; min-height: 75vh; overflow: hidden; }
.apercu iframe { width: 100%; height: 75vh; border: 0; display: block; }
.sans-apercu { height: 100%; min-height: 300px; display: grid; place-content: center; text-align: center; gap: 12px; color: #666; }

/* ---------- Backoffice ---------- */
.titre-page, .titre-section { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.titre-page h1, .titre-section h2 { margin: 0; flex: 1; }
.grille-admin { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grille-admin > .carte { margin-bottom: 20px; }
.tableau-admin { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tableau-admin th { text-align: left; background: var(--gris-ligne); padding: 8px; font-weight: 600; }
.tableau-admin td { padding: 8px; border-bottom: 1px solid #eee; vertical-align: middle; }
.tableau-admin td.tronque { max-width: 380px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tableau-admin form { margin: 0; }

@media (max-width: 860px) {
  .grille-admin, .pieces { grid-template-columns: 1fr; }
  .element-entete { flex-direction: column; }
  .element-etat { width: auto; border: 0; padding: 0; }
  .feuille { padding: 20px; }
  .topbar { flex-wrap: wrap; }
}

/* ---------- Impression : rendu identique au récépissé papier ---------- */
@media print {
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .no-print { display: none !important; }
  .feuille { box-shadow: none; padding: 0; max-width: none; }
  .tableau-doc tr { break-inside: avoid; }
  .tableau-doc th, .tableau-doc tbody tr:nth-child(odd) { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { size: A4; margin: 14mm 16mm; }
}

/* ---------- Utilisateurs, profils et droits ---------- */
.flash-info { background: #e8f0fb; color: #1a4f8b; border: 1px solid #b6cdee; }
.session a { color: #444; text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.session a:hover, .session a.actif { background: var(--gris-ligne); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: .75rem; font-weight: 600; background: #eee; color: #555; vertical-align: middle; }
.badge-ok { background: #e8f5e9; color: var(--vert); }
.badge-off { background: #fbeaea; color: var(--rouge); }
.badge-attente { background: #fff4e0; color: var(--orange); }
.tableau-admin tr.inactif td { color: #999; }
label.case { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.form-grille { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: end; }
.form-grille label.case { grid-column: span 2; }
.matrice { border-collapse: collapse; margin: 6px 0; font-size: .9rem; }
.matrice th, .matrice td { padding: 6px 14px; border-bottom: 1px solid #eee; text-align: left; }
.matrice th { background: var(--gris-ligne); font-weight: 600; cursor: help; }
.matrice th:not(:first-child) { text-align: center; }
.matrice input[type=checkbox] { width: 18px; height: 18px; }
.droit.oui { color: var(--vert); font-weight: 700; }
.droit.non { color: #bbb; }
.droit-global { margin: 10px 0 0; font-size: .9rem; }
.grille-profils { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 20px; }
.infos { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 20px; }
.infos dt { color: #777; }
.infos dd { margin: 0; }
.zone-danger { color: var(--rouge); margin-top: 24px; }
.intro { margin: -4px 0 18px; }
@media (max-width: 860px) { .form-grille { grid-template-columns: 1fr; } .form-grille label.case { grid-column: auto; } }

/* ---------- Code de connexion ---------- */
.champ-code { font-size: 1.6rem; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.liens-code { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; font-size: .9rem; }

/* ---------- Clause de confidentialité ---------- */
.clause { max-width: 860px; margin: 0 auto; }
.clause h1 { font-size: 1.35rem; margin-top: 14px; }
.clause-texte { max-height: 52vh; overflow-y: auto; border: 1px solid var(--bordure); border-radius: 8px; padding: 18px 22px;
  margin: 14px 0 8px; background: #fcfbf8; font-family: var(--serif); line-height: 1.5; }
.clause-texte:focus { outline: 2px solid var(--or); }
.clause-texte h2 { font-family: var(--sans); font-size: 1rem; margin: 18px 0 6px; }
.clause-texte h2:first-child { margin-top: 0; }
.clause-texte p { margin: 0 0 8px; text-align: justify; }
.clause-fin { text-align: center !important; color: #888; font-style: italic; margin-top: 18px !important; }
.clause-apercu { max-height: none; }
.clause-indication { margin-bottom: 14px; color: var(--orange); font-weight: 600; }
.clause-indication.ok { color: var(--vert); }
.clause label.case { align-items: flex-start; line-height: 1.4; }
.clause label.case input { margin-top: 3px; }
.clause button:disabled { opacity: .45; cursor: not-allowed; }
.clause form + form { margin-top: 12px; }

/* ---------- Journal d'audit ---------- */
.raccourcis { font-size: .9rem; margin: -4px 0 14px; }
.filtres-audit { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.filtres-actions { display: flex; gap: 12px; align-items: center; }
.defilement-x { overflow-x: auto; }
.tableau-audit td { vertical-align: top; }
.nowrap { white-space: nowrap; }
tr.audit-alerte td { background: #fff6f5; }
.pagination { display: flex; gap: 14px; justify-content: center; align-items: center; margin-top: 14px; }
.form-grille-large { grid-column: 1 / -1; }
