:root {
  --bleu: #085292;
  --bleu-clair: #0B6BB8;
  --bleu-fonce: #06467E;
  --fond: #f4f7fb;
  --carte: #ffffff;
  --texte: #1b2430;
  --texte-doux: #4a5868;
  --bord: #d5dee9;
  --rouge: #c62828;
  --rouge-fond: #fde8e8;
  --patron: #7f1010;
  --patron-fond: #f3c9c9;
  --orange: #9a4a00;
  --orange-fond: #ffe7c7;
  --vert: #1d6b35;
  --vert-fond: #e3f4e8;
  --rayon: 10px;
  --ombre: 0 1px 2px rgba(10, 30, 60, .06), 0 4px 14px rgba(10, 30, 60, .06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fond); color: var(--texte);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.saut { position: absolute; left: -999px; top: 0; background: #fff; padding: 8px; z-index: 10; }
.saut:focus { left: 8px; }
.enveloppe { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { line-height: 1.25; color: var(--bleu-fonce); }
h1 { margin: .2em 0 .3em; font-size: 1.8rem; color: #fff; }
h2 { font-size: 1.3rem; margin: 0; }
h3 { font-size: 1.05rem; margin: 1.4em 0 .5em; }
code { font-size: .9em; background: #eef3f9; padding: 0 4px; border-radius: 4px; overflow-wrap: anywhere; }

.entete { background: linear-gradient(135deg, var(--bleu-fonce), var(--bleu) 55%, var(--bleu-clair)); color: #fff; padding: 22px 0 18px; }
.surtitre { margin: 0; font-size: .82rem; opacity: .9; text-transform: uppercase; letter-spacing: .04em; }
.intro { margin: 0 0 12px; max-width: 760px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.bandeau-exemple { margin: 12px 0 0; background: #fff4d6; color: #5a3b00; padding: 8px 12px; border-radius: 8px; font-weight: 600; }

.btn {
  font: inherit; font-size: .92rem; cursor: pointer; border-radius: 8px; padding: 8px 14px; min-height: 40px;
  border: 1px solid var(--bleu); background: #fff; color: var(--bleu); text-decoration: none; display: inline-flex; align-items: center;
}
.btn:hover { background: #eaf2fb; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [role=tab]:focus-visible, .defile:focus-visible {
  outline: 3px solid #f2a900; outline-offset: 2px;
}
.btn-primaire { background: var(--bleu); color: #fff; }
.btn-primaire:hover { background: var(--bleu-fonce); }
.btn-clair { background: #fff; color: var(--bleu-fonce); border-color: #fff; font-weight: 600; }
.btn-fantome { background: transparent; border-color: currentColor; }
.entete .btn-fantome { color: #fff; }
.entete .btn-fantome:hover { background: rgba(255, 255, 255, .12); }
.btn-mini { min-height: 28px; padding: 2px 8px; font-size: .8rem; }

.onglets { display: flex; gap: 4px; margin-top: 14px; overflow-x: auto; }
.onglets [role=tab] {
  font: inherit; font-weight: 600; border: 1px solid var(--bord); border-bottom: none; background: #e8eef6; color: var(--bleu-fonce);
  padding: 10px 14px; border-radius: 10px 10px 0 0; cursor: pointer; white-space: nowrap;
}
.onglets [role=tab][aria-selected=true] { background: var(--carte); color: var(--bleu); box-shadow: inset 0 3px 0 var(--bleu); }

.panneau { background: var(--carte); border: 1px solid var(--bord); border-radius: 0 var(--rayon) var(--rayon) var(--rayon); padding: 16px; box-shadow: var(--ombre); }
.tete-panneau { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.aide { color: var(--texte-doux); font-size: .9rem; }
.note { color: var(--texte-doux); font-size: .84rem; margin: 6px 0; }
.attention { background: #fff4d6; color: #5a3b00; padding: 6px 10px; border-radius: 6px; }
.pastille { display: inline-block; padding: 0 6px; border-radius: 4px; font-weight: 600; font-size: .85em; }
.pastille.rouge { background: var(--rouge); color: #fff; }
.pastille.patron { background: var(--patron); color: #fff; }
.pastille.orange { background: var(--orange-fond); color: var(--orange); border: 1px solid #e0a35a; }
.barre-outils { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

.score { display: flex; align-items: baseline; gap: 4px; background: var(--vert-fond); color: var(--vert); padding: 6px 12px; border-radius: 10px; }
.score.moyen { background: var(--orange-fond); color: var(--orange); }
.score.faible { background: var(--rouge-fond); color: var(--rouge); }
.score-val { font-size: 1.7rem; font-weight: 700; }
.score-lib { margin-left: 6px; font-size: .85rem; }

.defile { overflow-x: auto; max-width: 100%; border: 1px solid var(--bord); border-radius: 8px; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; }
.matrice { font-size: .82rem; min-width: 100%; }
.matrice th, .matrice td { border: 1px solid var(--bord); padding: 4px; vertical-align: top; }
.matrice thead th { background: #eef3f9; min-width: 104px; max-width: 130px; font-weight: 600; }
.matrice thead th.col-emp { position: sticky; left: 0; z-index: 2; min-width: 170px; }
.matrice tbody th { position: sticky; left: 0; background: #fff; z-index: 1; text-align: left; min-width: 170px; font-weight: 400; }
.matrice thead th.st-rouge { background: var(--rouge); color: #fff; }
.matrice thead th.st-patron { background: var(--patron); color: #fff; }
.matrice thead th.st-ok { background: var(--vert-fond); color: var(--vert); }
.matrice td.st-rouge { background: var(--rouge-fond); }
.matrice td.st-patron { background: var(--patron-fond); }
.matrice td.al-echu, .matrice td.al-bientot { background: var(--orange-fond); box-shadow: inset 0 0 0 2px #e08a1e; }
.matrice input[type=text], .matrice input[type=date], .matrice select { font: inherit; font-size: .8rem; width: 100%; padding: 3px; border: 1px solid var(--bord); border-radius: 4px; background: #fff; color: var(--texte); }
.matrice .etat { display: block; font-size: .72rem; margin-top: 2px; }
.matrice .cell-al { display: block; font-size: .7rem; color: var(--orange); font-weight: 600; }
.matrice .lig-emp { display: grid; gap: 3px; }
.matrice .lig-emp .case { font-size: .75rem; }
.niv-0 { color: #777; } .niv-2, .niv-3 { font-weight: 700; color: var(--vert); }

.alertes { margin-top: 12px; display: grid; gap: 6px; }
.alerte { padding: 8px 12px; border-radius: 8px; border-left: 5px solid; font-size: .9rem; }
.alerte.rouge { background: var(--rouge-fond); border-color: var(--rouge); }
.alerte.patron { background: var(--patron-fond); border-color: var(--patron); }
.alerte.orange { background: var(--orange-fond); border-color: #e08a1e; }
.alerte.ok { background: var(--vert-fond); border-color: var(--vert); }

form fieldset { border: 1px solid var(--bord); border-radius: 8px; margin: 0; padding: 10px 12px; min-width: 0; }
legend { font-weight: 700; color: var(--bleu-fonce); padding: 0 4px; }
label { display: block; font-size: .87rem; margin: 6px 0; color: var(--texte); }
label input:not([type=checkbox]), label select, label textarea {
  display: block; width: 100%; margin-top: 3px; font: inherit; padding: 7px 8px; border: 1px solid #b7c4d4; border-radius: 6px; background: #fff; color: var(--texte);
}
label.case { display: flex; gap: 6px; align-items: center; }
.grille-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.grille-form .large, .plan .large { grid-column: 1 / -1; }
.ligne-taux { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0 10px; }
label.court { max-width: 320px; }
.plan { display: grid; gap: 12px; }

.treso { font-size: .8rem; font-variant-numeric: tabular-nums; width: 100%; }
.treso th, .treso td { border-bottom: 1px solid var(--bord); padding: 4px 6px; text-align: right; white-space: nowrap; }
.treso th:first-child, .treso td:first-child { text-align: left; position: sticky; left: 0; background: #fff; z-index: 1; min-width: 150px; white-space: normal; }
.treso thead th { background: #eef3f9; }
.treso thead th:first-child { background: #eef3f9; }
.treso input { width: 88px; font: inherit; padding: 3px 4px; text-align: right; border: 1px solid #b7c4d4; border-radius: 4px; }
.treso tr.total td { font-weight: 700; border-top: 2px solid var(--bleu); }
.treso tr.solde td { font-weight: 700; background: #eef3f9; }
.treso tr.provision td { color: var(--texte-doux); font-style: italic; }
.treso td.crit { background: var(--rouge); color: #fff; }
.treso td.neg { color: var(--rouge); }
.treso tr.section td { background: #f7f9fc; font-weight: 700; color: var(--bleu-fonce); text-align: left; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 8px 0; }
.kpi { border: 1px solid var(--bord); border-radius: 10px; padding: 10px 12px; background: #fff; }
.kpi b { display: block; font-size: 1.25rem; color: var(--bleu-fonce); font-variant-numeric: tabular-nums; }
.kpi.alerte-kpi { background: var(--rouge-fond); border-color: var(--rouge); }
.kpi.alerte-kpi b { color: var(--rouge); }
.kpi span { font-size: .8rem; color: var(--texte-doux); }
.graphe { margin: 8px 0; }
.graphe svg { width: 100%; height: auto; display: block; }
.graphe figcaption { font-size: .8rem; color: var(--texte-doux); }

.prio { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; align-items: end; border-bottom: 1px dashed var(--bord); padding-bottom: 6px; }
.chiffre { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }

.passerelle { margin: 20px 0; background: #eaf2fb; border: 1px solid #b9d3ee; border-radius: var(--rayon); padding: 16px; }
.passerelle h2 { font-size: 1.1rem; }
.passerelle ul { padding-left: 1.2em; }
.pied { background: #0d2238; color: #d8e3ef; font-size: .82rem; padding: 16px 0; margin-top: 20px; }

@media (max-width: 640px) {
  h1 { font-size: 1.45rem; }
  .panneau { padding: 12px; }
  .prio, .chiffre { grid-template-columns: 1fr; }
  .matrice tbody th, .matrice thead th.col-emp { min-width: 130px; }
  .treso th:first-child, .treso td:first-child { min-width: 118px; }
}

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 10pt; }
  .entete, .onglets, .barre-outils, .actions, .passerelle, .saut, form .note.attention, #btn-ajout-prio, .btn { display: none !important; }
  .panneau { border: none; box-shadow: none; padding: 0; }
  .defile { overflow: visible; border: none; }
  .matrice, .treso { font-size: 7pt; }
  .treso input { border: none; width: auto; }
  .pied { background: #fff; color: #333; border-top: 1px solid #999; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body::after { content: "Version gratuite – art-construction.ch"; position: fixed; bottom: 2mm; right: 2mm; color: #aaa; font-size: 8pt; }
}
