/* Feuille de style commune — formulaire et tableau de bord.
   Pour changer les couleurs, modifier uniquement les variables ci-dessous. */
:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --ink: #121643;  /* bleu marine du logo OSF */
  --muted: #55627a;
  --line: #d5dce8;
  --accent: #0b4ea2;  /* bleu OSF (approché) : remplacer par la valeur officielle si besoin */
  --accent-ink: #ffffff;
  --accent-soft: #e6eefa;
  --focus: #3d7fd9;
  --ok: #17703f;
  --ok-soft: #e3f3ea;
  --warn: #a35200;
  --warn-soft: #fdf0dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--font); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .9em; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.wrap { max-width: 780px; margin: 0 auto; padding: 0 16px 64px; }
.wrap.wide { max-width: 1120px; }

/* En-tête */
.top { background: var(--surface); border-bottom: 1px solid var(--line); }
.top .wrap { padding-bottom: 0; display: flex; align-items: center; gap: 16px; min-height: 76px; }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 0; }
/* Logo officiel (logo.avif, fichier non modifié) : le cadre n'affiche que la zone dessinée,
   sans les marges blanches de l'image (repères mesurés sur l'image de 1200 × 578 px). */
.logo-frame { display: block; width: 200px; max-width: 100%; aspect-ratio: 964 / 141; overflow: hidden; }
.logo-frame img { display: block; width: 124.48%; max-width: none; height: auto; margin: -22.72% 0 0 -12.24%; }
.brand small { font-size: .72rem; color: var(--muted); letter-spacing: .02em; }
.top .spacer { flex: 1; }
.top .title { font-weight: 600; color: var(--muted); font-size: .9rem; text-align: right; }

/* Cartes & boutons */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-top: 20px; }
.card > :last-child { margin-bottom: 0; }
.note { background: var(--accent-soft); border-left: 4px solid var(--accent); padding: 12px 14px; border-radius: 6px; font-size: .95rem; }
.note.warn { background: var(--warn-soft); border-left-color: var(--warn); }
.note.bad { background: var(--bad-soft); border-left-color: var(--bad); }
.muted { color: var(--muted); }
.small { font-size: .88rem; }

.btn { font: inherit; font-weight: 600; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); padding: 11px 20px; border-radius: 8px; cursor: pointer; min-height: 44px; }
.btn:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: var(--bad); border-color: var(--bad); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.actions { display: flex; gap: 12px; justify-content: space-between; margin-top: 24px; flex-wrap: wrap; }

/* Progression */
.progress { margin-top: 20px; }
.progress .meta { display: flex; justify-content: space-between; font-size: .88rem; color: var(--muted); margin-bottom: 6px; }
.bar { height: 8px; background: #e1e7f1; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .25s; }

/* Questions */
fieldset.q { border: 0; padding: 18px 0; margin: 0; border-bottom: 1px solid var(--line); min-width: 0; }
fieldset.q:last-of-type { border-bottom: 0; }
fieldset.q legend { padding: 0; font-weight: 600; margin-bottom: 10px; display: block; width: 100%; }
.qn { display: inline-block; min-width: 2em; color: var(--accent); font-variant-numeric: tabular-nums; }
.choices { display: grid; gap: 8px; }
.choices.c5 { grid-template-columns: repeat(5, 1fr); }
.choices.c11 { grid-template-columns: repeat(11, 1fr); gap: 6px; }
.chip { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 2px; padding: 9px 4px; border: 1.5px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; font-size: .8rem; line-height: 1.2; min-height: 54px; user-select: none; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.chip .num { font-weight: 700; font-size: 1.05rem; }
.chip:hover { border-color: var(--accent); }
.chip.sel { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.scale-ends { display: flex; justify-content: space-between; font-size: .82rem; color: var(--muted); margin-top: 6px; gap: 12px; }
.choices.stack { grid-template-columns: 1fr; }
.choices.stack .chip { flex-direction: row; justify-content: flex-start; padding: 10px 14px; min-height: 44px; font-size: .95rem; text-align: left; }
.choices.row5 { grid-template-columns: repeat(5, 1fr); }
fieldset.q.invalid { background: var(--bad-soft); border-radius: 8px; padding-left: 12px; padding-right: 12px; }
.errmsg { color: var(--bad); font-weight: 600; font-size: .9rem; margin-top: 8px; }
.sub { color: var(--muted); margin: 0 0 4px; font-size: .95rem; }

textarea, input[type=text], input[type=password], input[type=number], input[type=datetime-local], select { font: inherit; width: 100%; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 8px; background: #fff; color: inherit; }
textarea { min-height: 110px; resize: vertical; }
label.field { display: block; font-weight: 600; margin-bottom: 14px; }
label.field > span { display: block; margin-bottom: 4px; }
.counter { text-align: right; font-size: .8rem; color: var(--muted); }

@media (max-width: 640px) {
  .choices.c5, .choices.row5 { grid-template-columns: 1fr; }
  .choices.c5 .chip, .choices.row5 .chip { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 14px; min-height: 44px; font-size: .95rem; text-align: left; }
  .choices.c5 .chip .num { min-width: 1.2em; }
  .choices.c11 { grid-template-columns: repeat(6, 1fr); }
  .card { padding: 16px; }
  h1 { font-size: 1.35rem; }
  .top .title { display: none; }
}

/* ---------- Tableau de bord ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 20px; border-bottom: 2px solid var(--line); }
.tab { font: inherit; font-weight: 600; background: none; border: 0; padding: 10px 16px; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tab[aria-selected=true] { color: var(--accent); border-bottom-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }
.kpi { font-size: 2.2rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-weight: 600; color: var(--muted); font-size: .82rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tablewrap { overflow-x: auto; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; font-weight: 700; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.badge.favorable { background: var(--ok-soft); color: var(--ok); }
.badge.surveiller { background: var(--warn-soft); color: var(--warn); }
.badge.vigilance { background: var(--bad-soft); color: var(--bad); }
.track { position: relative; height: 14px; background: #e6ebf3; border-radius: 99px; min-width: 140px; }
.track > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; }
.track > i.favorable { background: var(--ok); }
.track > i.surveiller { background: #c77a12; }
.track > i.vigilance { background: var(--bad); }
.track > u { position: absolute; top: -2px; bottom: -2px; width: 2px; background: #14213d; opacity: .35; }
.hist { display: flex; align-items: flex-end; gap: 4px; height: 110px; }
.hist > div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: .72rem; color: var(--muted); }
.hist > div > i { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 1px; }
.stack100 { display: flex; height: 22px; border-radius: 6px; overflow: hidden; background: #e6ebf3; }
.stack100 > i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .78rem; color: var(--muted); margin-top: 6px; }
.legend b { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.masked { color: var(--muted); font-style: italic; font-size: .85rem; }
details.th { border-top: 1px solid var(--line); padding: 4px 0; }
details.th summary { cursor: pointer; padding: 10px 0; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
details.th summary::-webkit-details-marker { display: none; }
details.th summary::before { content: "▸"; color: var(--muted); }
details.th[open] summary::before { content: "▾"; }
.comment { border-left: 3px solid var(--line); padding: 6px 12px; margin: 0 0 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment cite { display: block; font-size: .78rem; color: var(--muted); font-style: normal; }
.delta.up { color: var(--ok); font-weight: 600; }
.delta.down { color: var(--bad); font-weight: 600; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar select { width: auto; }
.codebox { font-family: ui-monospace, Menlo, Consolas, monospace; background: #eef2f8; border: 1px solid var(--line); padding: 10px 12px; border-radius: 8px; font-size: .88rem; overflow-x: auto; white-space: pre-wrap; }

@media print {
  body { background: #fff; }
  .top, .tabs, .toolbar, .noprint, .btn { display: none !important; }
  .card { border: 0; padding: 0; break-inside: avoid; }
  [data-panel] { display: block !important; }
  details.th { break-inside: avoid; }
  details.th > * { display: block; }
}

/* Profil : précision « Autre » */
.sub-field { margin: 10px 0 0; font-weight: 400; }
.sub-field input { width: 100%; }
.sub-field .muted { display: block; margin-top: 4px; }
/* Récapitulatif avant envoi */
.recap { border-top: 1px solid var(--line); padding-block: 14px 4px; }
.recap-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.recap-head h2 { margin: 0; font-size: 1.05rem; }
.recap dl { margin: 8px 0 0; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 6px 16px; }
.recap dt { color: var(--muted); font-size: .92rem; min-width: 0; }
.recap dd { margin: 0; font-weight: 600; font-size: .92rem; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 600px) { .recap dl { grid-template-columns: minmax(0, 1fr); gap: 2px; } .recap dd { margin-bottom: 8px; } }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: .9rem; }

/* Lien d'action discret (ex. « Mot de passe oublié ? ») */
.linkbtn { font: inherit; font-size: .92rem; background: none; border: 0; padding: 6px 0; color: var(--accent); text-decoration: underline; cursor: pointer; }
input[type=email] { font: inherit; width: 100%; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 8px; background: #fff; color: inherit; }

/* Légende placée juste sous un titre de carte */
.legend-under { margin: -4px 0 14px; }

/* Croisements de segments */
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 700px) { .grid3 { grid-template-columns: minmax(0, 1fr); gap: 0; } }
table.cross th[scope=row] { text-align: left; font-weight: 600; }
table.cross td.total { background: var(--accent-soft); }

/* Exemples sous une option (ex. fonctions du profil) */
.chip .hint { display: block; font-size: .8rem; color: var(--muted); margin-top: 2px; }
.chip.sel .hint { color: inherit; opacity: .85; }
