:root {
  --fond: #f4f5f7;
  --carte: #ffffff;
  --texte: #1c2330;
  --doux: #5d6675;
  --bord: #dde1e7;
  --accent: #1d4f91;
  --accent-fonce: #163d71;
  --accent-clair: #e8eff9;
  --vert: #1d7a46;
  --vert-clair: #e5f4ec;
  --orange: #a35a00;
  --orange-clair: #fdf1e1;
  --rouge: #b42318;
  --rouge-clair: #fdecea;
  --rayon: 12px;
  --nav-h: 64px;
  font-size: 17px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--fond); color: var(--texte); line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.discret { color: var(--doux); font-size: .9rem; }

/* ---------- En-tête et navigation ---------- */
.entete {
  position: sticky; top: 0; z-index: 20; background: var(--carte); border-bottom: 1px solid var(--bord);
  display: flex; align-items: center; gap: 1rem; padding: .6rem 1.25rem; padding-top: max(.6rem, env(safe-area-inset-top));
}
.marque { font-weight: 700; color: var(--texte); text-decoration: none; white-space: nowrap; }
.badge-mode { font-size: .75rem; font-weight: 600; padding: .2rem .55rem; border-radius: 99px; white-space: nowrap; }
.badge-mode.ia { background: var(--vert-clair); color: var(--vert); }
.badge-mode.demo { background: var(--orange-clair); color: var(--orange); }
.onglets { display: flex; gap: .25rem; margin-left: auto; }
.onglets a, .lien-donnees {
  text-decoration: none; color: var(--doux); font-weight: 600; padding: .55rem .9rem; border-radius: 10px; position: relative;
}
.onglets a.actif, .lien-donnees.actif { background: var(--accent-clair); color: var(--accent); }
.lien-donnees { font-size: .9rem; }
.pastille { display: inline-block; min-width: 1.3rem; padding: 0 .35rem; border-radius: 99px; background: var(--rouge); color: #fff; font-size: .75rem; text-align: center; line-height: 1.3rem; }

main { max-width: 860px; margin: 0 auto; padding: 1.25rem 1rem 3rem; outline: none; }

@media (max-width: 760px) {
  :root { font-size: 16px; }
  .entete { padding: .5rem 1rem; padding-top: max(.5rem, env(safe-area-inset-top)); }
  .onglets {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0; background: var(--carte);
    border-top: 1px solid var(--bord); padding: .35rem .35rem max(.35rem, env(safe-area-inset-bottom));
    display: grid; grid-template-columns: repeat(3, 1fr); gap: .35rem;
  }
  .onglets a { text-align: center; padding: .8rem .25rem; font-size: .95rem; }
  .lien-donnees { margin-left: auto; }
  main { padding: 1rem .75rem calc(var(--nav-h) + 2.5rem + env(safe-area-inset-bottom)); }
}

/* ---------- Cartes et formulaires ---------- */
.carte { background: var(--carte); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 1.1rem; margin-bottom: 1rem; }
.titre-vue { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.grille { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem 1rem; }
.grille .plein { grid-column: 1 / -1; }
@media (max-width: 560px) { .grille { grid-template-columns: 1fr; } }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
label .req { color: var(--rouge); }
input, select, textarea {
  width: 100%; font: inherit; font-size: 1rem; color: var(--texte); background: #fff;
  border: 1px solid #c9ced6; border-radius: 10px; padding: .7rem .8rem; min-height: 48px;
}
input:focus, select:focus, textarea:focus { outline: 3px solid var(--accent-clair); border-color: var(--accent); }
input:disabled, textarea:disabled, select:disabled { background: #f3f4f6; color: var(--doux); }
textarea { resize: vertical; line-height: 1.5; }
textarea.notes { min-height: 260px; }
.invalide { border-color: var(--rouge) !important; }

.choix { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.choix button { min-height: 48px; }
.choix button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

.ligne-interl { display: grid; grid-template-columns: 1fr 1fr auto; gap: .5rem; margin-bottom: .5rem; }
@media (max-width: 560px) { .ligne-interl { grid-template-columns: 1fr 1fr 48px; } }

/* ---------- Boutons ---------- */
button, .bouton {
  font: inherit; font-weight: 600; font-size: 1rem; border-radius: 10px; border: 1px solid #c9ced6;
  background: #fff; color: var(--texte); padding: .75rem 1.1rem; min-height: 50px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
button:hover, .bouton:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: not-allowed; }
.principal { background: var(--accent); border-color: var(--accent); color: #fff; }
.principal:hover { background: var(--accent-fonce); }
.succes { background: var(--vert); border-color: var(--vert); color: #fff; }
.danger { color: var(--rouge); }
.grand { width: 100%; min-height: 58px; font-size: 1.08rem; }
.petit { min-height: 40px; padding: .4rem .75rem; font-size: .9rem; }
.icone { width: 48px; min-width: 48px; padding: 0; }
.barre-boutons { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.barre-boutons > * { flex: 1 1 180px; }
.collant {
  position: sticky; bottom: 0; background: linear-gradient(to top, var(--fond) 75%, transparent);
  padding: 1rem 0 .5rem; margin: 0; z-index: 5;
}
@media (max-width: 760px) { .collant { bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); } }

.dictee.active { background: var(--rouge); border-color: var(--rouge); color: #fff; }
.indice { font-size: .85rem; color: var(--doux); margin-top: .4rem; }
.etat-sauvegarde { font-size: .85rem; color: var(--doux); min-height: 1.2em; }

/* ---------- Badges ---------- */
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: .2rem .55rem; border-radius: 99px; white-space: nowrap; vertical-align: middle; }
.b-brouillon { background: #eef0f3; color: var(--doux); }
.b-a_relire { background: var(--orange-clair); color: var(--orange); }
.b-valide { background: var(--vert-clair); color: var(--vert); }
.b-fictive { background: #f1e8fb; color: #6b3fa0; }
.b-retard { background: var(--rouge-clair); color: var(--rouge); }
.b-en_cours { background: var(--accent-clair); color: var(--accent); }
.b-a_faire { background: #eef0f3; color: var(--texte); }
.b-terminee { background: var(--vert-clair); color: var(--vert); }

.bandeau { border-radius: 10px; padding: .75rem .9rem; margin-bottom: 1rem; font-size: .95rem; }
.bandeau.demo { background: var(--orange-clair); color: #6d3c00; }
.bandeau.info { background: var(--accent-clair); color: var(--accent-fonce); }
.bandeau.ok { background: var(--vert-clair); color: #135533; }
.bandeau.erreur { background: var(--rouge-clair); color: var(--rouge); }

/* ---------- Éditeur de rapport ---------- */
.bloc-section { border: 1px solid var(--bord); border-radius: 10px; padding: .75rem; margin-bottom: .75rem; background: #fcfcfd; }
.bloc-section .entete-bloc { display: flex; gap: .5rem; margin-bottom: .5rem; }
.bloc-section textarea { min-height: 140px; }
.action-edit { border: 1px solid var(--bord); border-radius: 10px; padding: .75rem; margin-bottom: .75rem; background: #fcfcfd; }
.action-edit .grille { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 560px) { .action-edit .grille { grid-template-columns: 1fr 1fr; } .action-edit .grille .resp { grid-column: 1 / -1; } }

/* ---------- Listes ---------- */
.liste { display: flex; flex-direction: column; gap: .65rem; }
.item {
  display: block; background: var(--carte); border: 1px solid var(--bord); border-radius: var(--rayon);
  padding: .9rem 1rem; color: inherit; text-decoration: none;
}
a.item:hover { border-color: var(--accent); }
.item .haut { display: flex; justify-content: space-between; gap: .75rem; align-items: baseline; }
.item .ent { font-weight: 700; }
.item .meta { color: var(--doux); font-size: .9rem; margin-top: .15rem; }
.item .resume { margin-top: .35rem; font-size: .95rem; color: #39414e; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.filtres { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; margin-top: .75rem; }
@media (max-width: 760px) { .filtres { grid-template-columns: 1fr 1fr; } }
.puces { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .25rem; margin-bottom: 1rem; -webkit-overflow-scrolling: touch; }
.puces button { flex: 0 0 auto; min-height: 44px; border-radius: 99px; }
.puces button[aria-pressed="true"] { background: var(--texte); color: #fff; border-color: var(--texte); }

.action-carte .champs { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: .5rem; margin-top: .65rem; }
@media (max-width: 560px) { .action-carte .champs { grid-template-columns: 1fr 1fr; } .action-carte .champs .resp { grid-column: 1 / -1; } }
.action-carte .champs label { font-size: .78rem; color: var(--doux); margin-bottom: .15rem; }
.action-carte.retard { border-left: 4px solid var(--rouge); }

.vide { text-align: center; color: var(--doux); padding: 2rem 1rem; }

/* ---------- Rapport rendu ---------- */
.rapport { background: #fff; }
.rapport h1 { font-size: 1.35rem; margin-bottom: .75rem; }
.rapport h2 { font-size: 1.05rem; margin: 1.4rem 0 .5rem; padding-bottom: .3rem; border-bottom: 1px solid var(--bord); }
.rapport h3 { font-size: .98rem; margin: 1rem 0 .35rem; }
.rapport p { margin: 0 0 .6rem; }
.rapport table.ent { border-collapse: collapse; width: 100%; font-size: .95rem; }
.rapport table.ent th { text-align: left; color: var(--doux); font-weight: 600; width: 34%; padding: .3rem .6rem .3rem 0; vertical-align: top; }
.rapport table.ent td { padding: .3rem 0; }
.rapport .apreciser { color: var(--orange); font-style: italic; }
.rapport ol { padding-left: 1.4rem; margin: .25rem 0 .75rem; }
.rapport li { margin-bottom: .45rem; }
.rapport .meta-action { color: var(--doux); font-size: .9rem; }
.rapport .pied { margin-top: 1.5rem; font-size: .85rem; color: var(--doux); }

details { margin-top: .75rem; }
summary { cursor: pointer; font-weight: 600; padding: .5rem 0; }
pre.notes-origine { white-space: pre-wrap; font-family: inherit; background: #f7f8fa; border: 1px solid var(--bord); border-radius: 10px; padding: .75rem; margin: .25rem 0 0; font-size: .95rem; }

/* ---------- Modale et toast ---------- */
.modale { position: fixed; inset: 0; z-index: 50; background: rgba(20, 25, 35, .45); display: flex; align-items: flex-start; justify-content: center; padding: max(1rem, env(safe-area-inset-top)) .75rem 1rem; overflow-y: auto; }
.modale[hidden] { display: none; }
.modale .panneau { background: #fff; border-radius: 14px; width: 100%; max-width: 820px; padding: 1.25rem; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modale .barre-boutons { position: sticky; bottom: 0; background: #fff; padding-top: .75rem; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 1.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--texte); color: #fff; padding: .7rem 1.1rem; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: 90vw; text-align: center; }
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (min-width: 761px) { .toast { bottom: 2rem; } }

.chargement { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: tourne .8s linear infinite; }
@keyframes tourne { to { transform: rotate(360deg); } }

/* ---------- Impression / PDF ---------- */
#impression { display: none; }
@media print-desactive {
  @page { margin: 16mm 15mm; }
  body { background: #fff; font-size: 11pt; }
  body > *:not(#impression) { display: none !important; }
  #impression { display: block !important; }
  .rapport h2 { break-after: avoid; }
  .rapport li, .rapport p { break-inside: avoid; }
}
.pastille[hidden] { display: none; }

.retour { min-height: 44px; padding: .4rem .2rem; border: none; background: none; color: var(--accent); margin-bottom: .25rem; }
.petit-panneau { max-width: 460px; margin-top: 18vh; }
.danger-plein { background: var(--rouge); border-color: var(--rouge); color: #fff; }
.texte-copie { min-height: 60vh; font-size: .95rem; }
#dialogue { z-index: 70; }
.barre-boutons.colonne { flex-direction: column; }
.barre-boutons.colonne > * { flex: 1 1 auto; width: 100%; }
.badge-mode.horsligne { background: #e9ebef; color: #39414e; }
.onglets a, .lien-donnees { cursor: pointer; }
.entete { min-width: 0; }
.marque, .badge-mode { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.lien-donnees { flex-shrink: 0; }
html, body { max-width: 100%; overflow-x: clip; }
.maj { position: fixed; top: max(.5rem, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 80; background: var(--texte); color: #fff; border-radius: 10px; padding: .4rem .5rem .4rem 1rem; display: flex; gap: .75rem; align-items: center; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.maj[hidden] { display: none; }
.maj button { min-height: 40px; }
@media (display-mode: standalone) { .entete { padding-top: max(.6rem, env(safe-area-inset-top)); } }
