/* ─────────────────────────────────────────────────────────────
   Risk Assessment Matrix — feuille de style unique
   Thème : un tableau de bord de comité des risques. Fond neutre, encre
   anthracite ; les couleurs des NIVEAUX viennent de la méthode du registre
   (appliquées par le script, avec un texte au contraste calculé) et sont
   toujours doublées du libellé. Polices système : aucune requête externe.
   ───────────────────────────────────────────────────────────── */

/* 1. Jetons — thème clair par défaut */
:root {
  --paper: #f4f3ef;
  --surface: #ffffff;
  --ink: #16171b;
  --muted: #565a64;
  --rule: #d9d7cf;
  --alert: #b3261e;
  --alert-bg: #fbe3df;
  --accent: #1f4fbf;
  --focus: #1f4fbf;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16171b;
    --surface: #1f2127;
    --ink: #e8e8ec;
    --muted: #a7aab3;
    --rule: #383b44;
    --alert: #ff8f85;
    --alert-bg: #3a1d1d;
    --accent: #8fb0ff;
    --focus: #8fb0ff;
    color-scheme: dark;
  }
}

/* 2. Base */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .75rem; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.skip { position: absolute; left: -999px; top: .5rem; background: var(--surface); padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: .5rem; }

/* 3. En-tête et pied */
.top {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .75rem max(1rem, calc((100% - 72rem) / 2)); background: var(--surface); border-bottom: 1px solid var(--rule);
}
.brand { font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.brand-mark {
  width: 1.1rem; height: 1.1rem; border-radius: 3px;
  background: linear-gradient(135deg, #2e7d4f 0 33%, #b85300 33% 66%, #b3261e 66%);
}
.langs { display: flex; gap: .25rem; }
.foot { max-width: 72rem; margin: 2rem auto; padding: 0 1rem; color: var(--muted); font-size: .9rem; }

/* 4. Mise en page */
main { max-width: 72rem; margin: 0 auto; padding: 1rem; }
.intro { color: var(--muted); max-width: 48rem; }
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1rem 1.25rem; margin: 1rem 0; }
.muted { color: var(--muted); font-size: .92rem; }
.scroll { overflow-x: auto; }

/* 5. Boutons et champs */
button, .file-button, select, input[type="search"] {
  font: inherit; color: inherit; background: var(--surface);
  border: 1px solid var(--rule); border-radius: 6px; padding: .4rem .75rem; min-height: 2.25rem;
}
button, .file-button { cursor: pointer; }
button:hover, .file-button:hover { border-color: var(--accent); }
button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.file-button { display: inline-flex; align-items: center; position: relative; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-button:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.load-actions, .toggle { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
button.link { border: 0; background: none; padding: 0; min-height: 0; color: var(--accent); text-align: left; text-decoration: underline; }
.check { display: flex; gap: .5rem; align-items: center; }

#status.error { color: var(--alert); background: var(--alert-bg); padding: .5rem .75rem; border-radius: 6px; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: .5rem 0 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

/* 6. Synthèse */
.cards { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .75rem; }
.card { border: 1px solid var(--rule); border-radius: var(--radius); padding: .75rem; display: flex; flex-direction: column; }
.card strong { font-size: 1.6rem; }
.card.alert { border-color: var(--alert); background: var(--alert-bg); }

/* 7. Cartographie : couleurs posées par le script (niveaux de la méthode) */
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid var(--rule); padding: .4rem .5rem; text-align: left; vertical-align: top; }
.heat td { padding: 0; }
.heat .cell {
  width: 100%; min-height: 4rem; border: 0; border-radius: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: .15rem; padding: .35rem;
}
.heat .cell:hover { filter: brightness(1.1); }
.heat .cell.selected { outline: 4px solid var(--ink); outline-offset: -4px; }
.cell-level { font-size: .78rem; opacity: .95; }
.cell-ids { font-weight: 700; }
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .85rem; font-weight: 600; white-space: nowrap; }

/* 8. Filtres, liste, détail */
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; margin-bottom: .75rem; }
.filters label { display: flex; flex-direction: column; gap: .2rem; font-size: .9rem; }
/* Un nom de responsable très long ne doit pas élargir la page sur mobile */
.filters label { min-width: 0; max-width: 100%; }
.filters select { max-width: 100%; text-overflow: ellipsis; }
.filters .grow { flex: 1 1 14rem; }
.chip { display: inline-block; background: var(--paper); border: 1px solid var(--rule); border-radius: 999px; padding: .2rem .75rem; }
tr.selected td { background: var(--paper); }
.late { color: var(--alert); font-weight: 700; }
.date { white-space: nowrap; }
.detail { border-top: 3px solid var(--ink); margin-top: 1rem; padding-top: 1rem; }
.fields { display: grid; grid-template-columns: minmax(9rem, max-content) 1fr; gap: .4rem 1rem; margin: 0; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; }
.fields ul { margin: 0; padding-left: 1.1rem; }
caption { text-align: left; color: var(--muted); padding: .25rem 0; }

@media (max-width: 40rem) {
  .fields, .meta { grid-template-columns: 1fr; }
  .heat .cell { min-height: 3rem; }
}

@media print {
  .top .langs, .load-actions, .filters, .settings, .toggle, .skip { display: none !important; }
  .panel { break-inside: avoid; border: 0; padding: 0; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
