:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #f1ece3;
  --ink: #26211d;
  --muted: #6b625a;
  --line: #e2dbcf;
  --accent: #7a1f3d;
  --accent-ink: #ffffff;
  --accent-soft: #f3e3e8;
  --leaf: #5f7a3a;
  --leaf-soft: #e8eedd;
  --warn: #9a3412;
  --warn-soft: #fdecdf;
  --focus: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(38, 33, 29, .06), 0 4px 16px rgba(38, 33, 29, .05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1715; --surface: #24201d; --surface-2: #2d2824; --ink: #efe9e2; --muted: #b0a69c;
    --line: #3d3631; --accent: #d1728f; --accent-ink: #1a1715; --accent-soft: #3e2530;
    --leaf: #9fbd73; --leaf-soft: #2d3524; --warn: #f4a36b; --warn-soft: #3d2a1c; --focus: #7aa7ff;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #1a1715; --surface: #24201d; --surface-2: #2d2824; --ink: #efe9e2; --muted: #b0a69c;
  --line: #3d3631; --accent: #d1728f; --accent-ink: #1a1715; --accent-soft: #3e2530;
  --leaf: #9fbd73; --leaf-soft: #2d3524; --warn: #f4a36b; --warn-soft: #3d2a1c; --focus: #7aa7ff;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .9em; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------- en-tête ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { flex: none; display: block; line-height: 0; }
.brand-logo img { height: 56px; width: auto; }
.brand-logo + div { border-left: 1px solid var(--line); padding-left: 14px; }
.brand-kicker { font-size: .75rem; color: var(--muted); letter-spacing: .02em; }
.brand-title { font-weight: 650; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-actions form { margin: 0; }
.save-status { font-size: .85rem; color: var(--muted); }
.save-status.ok { color: var(--leaf); }
.save-status.err { color: var(--warn); }

.footer { margin-top: auto; padding: 20px 16px; text-align: center; font-size: .8rem; color: var(--muted); }

/* ---------- pages ---------- */
.page { width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px 16px; }
.page-narrow { max-width: 720px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.intro h1 { font-size: 1.6rem; }
.callout { background: var(--leaf-soft); border-left: 4px solid var(--leaf); padding: 12px 14px; border-radius: 8px; }
.facts { list-style: none; padding: 0; margin: 16px 0 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.facts li { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.facts span { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.alert { background: var(--warn-soft); color: var(--warn); padding: 10px 14px; border-radius: 8px; font-weight: 500; }
.check { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 50%; background: var(--leaf-soft); color: var(--leaf); font-size: 2rem; display: grid; place-items: center; }

/* ---------- formulaires ---------- */
label { font-weight: 550; }
input[type=text], input:not([type]), input[type=email], input[type=password], input[type=number], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; width: 100%; max-width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.stack { display: grid; gap: 14px; }
.stack label { display: grid; gap: 6px; }
.code-form label { display: block; margin-bottom: 6px; }
.code-row { display: flex; gap: 10px; flex-wrap: wrap; }
.code-row input { flex: 1 1 220px; font-size: 1.25rem; letter-spacing: .12em; text-transform: uppercase; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

.btn {
  font: inherit; font-weight: 600; border-radius: 999px; padding: 10px 20px; cursor: pointer;
  border: 1px solid transparent; background: var(--surface-2); color: var(--ink); text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-small { padding: 6px 14px; font-size: .88rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- questionnaire ---------- */
.survey-layout {
  width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px 16px;
  display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 28px; align-items: start;
}
.steps { position: sticky; top: 16px; display: grid; gap: 2px; }
.steps button {
  font: inherit; text-align: left; background: none; border: 0; border-radius: 8px; padding: 8px 10px;
  color: var(--muted); cursor: pointer; display: flex; align-items: center; gap: 10px;
}
.steps button:hover { background: var(--surface-2); color: var(--ink); }
.steps button[aria-current="step"] { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.steps .dot { width: 22px; height: 22px; flex: none; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: .7rem; font-weight: 700; }
.steps .done .dot { background: var(--leaf); border-color: var(--leaf); color: var(--bg); }
.steps .skipped { opacity: .55; }
.steps .skipped .dot { border-style: dashed; }
.steps .req { font-size: .7rem; color: var(--accent); margin-left: auto; }

.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 20px; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

.step-head { margin-bottom: 18px; }
.step-head .kicker { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.step-head h1 { margin: 4px 0 8px; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); vertical-align: middle; margin-left: 6px; letter-spacing: .02em; }

.q {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.q.has-error { border-color: var(--warn); box-shadow: 0 0 0 2px var(--warn-soft); }
.q-num { font-weight: 750; color: var(--accent); margin-right: 6px; }
.q-text { font-weight: 550; margin: 0 0 12px; }
.q-help { font-size: .88rem; color: var(--muted); margin: -6px 0 12px; }
.q-err { color: var(--warn); font-size: .88rem; font-weight: 600; margin: 10px 0 0; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }

.choices { display: grid; gap: 8px; }
.choices.inline { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.choice {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; cursor: pointer; font-weight: 450; background: var(--surface);
}
.choice:hover { border-color: var(--accent); }
.choice input { margin: 3px 0 0; accent-color: var(--accent); width: 18px; height: 18px; flex: none; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.other-input { margin-top: 8px; }
.group-label { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 10px 0 6px; }

/* échelle d'accord */
.likert { display: grid; grid-template-columns: repeat(4, 1fr) auto; gap: 6px; }
.likert.no-nsa { grid-template-columns: repeat(4, 1fr); }
.likert label {
  position: relative; display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 10px 6px; border: 1px solid var(--line); border-radius: 10px; font-size: .85rem; font-weight: 500;
  cursor: pointer; min-height: 52px; background: var(--surface);
}
.likert input { position: absolute; opacity: 0; pointer-events: none; }
.likert label:hover { border-color: var(--accent); }
.likert label:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.likert label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.likert label.nsa { color: var(--muted); font-size: .8rem; max-width: 150px; }
.likert label.nsa:has(input:checked) { background: var(--muted); border-color: var(--muted); color: var(--bg); }

/* série */
.series-toggle {
  display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: var(--surface-2); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px;
}
.series-toggle label { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.series-toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.series-hint { font-size: .85rem; color: var(--muted); }
.series-off .q { opacity: .45; pointer-events: none; }

/* matrice B.1 */
.task { border-top: 1px solid var(--line); padding: 14px 0 6px; }
.task:first-of-type { border-top: 0; }
.task-title { font-weight: 650; margin-bottom: 10px; }
.task-row { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 10px; align-items: center; margin-bottom: 8px; }
.task-row .lbl { font-size: .85rem; color: var(--muted); }
.mini { display: flex; flex-wrap: wrap; gap: 6px; }
.mini label { position: relative; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: .82rem; font-weight: 500; cursor: pointer; background: var(--surface); }
.mini input { position: absolute; opacity: 0; pointer-events: none; }
.mini label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.mini label:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.legend-scale { font-size: .8rem; color: var(--muted); background: var(--surface-2); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; }

/* points */
.points-row { display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: 12px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.points-row:first-child { border-top: 0; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 36px; height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); font: inherit; font-weight: 700; cursor: pointer; }
.stepper input { text-align: center; padding: 8px 4px; }
.points-total { display: flex; align-items: center; gap: 12px; margin-top: 12px; font-weight: 650; }
.points-meter { flex: 1; height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.points-meter div { height: 100%; background: var(--leaf); transition: width .2s; }
.points-total.over .points-meter div { background: var(--warn); }
.points-total.over { color: var(--warn); }

.note { font-size: .88rem; color: var(--muted); }

/* récapitulatif */
.recap { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 8px; }
.recap li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.recap .ok { color: var(--leaf); font-weight: 600; }
.recap .ko { color: var(--warn); font-weight: 600; }
.recap .na { color: var(--muted); }
.recap button { font: inherit; background: none; border: 0; color: var(--accent); cursor: pointer; text-decoration: underline; padding: 0; }

.step-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 20px; }

@media (max-width: 860px) {
  .survey-layout { grid-template-columns: 1fr; padding-top: 12px; }
  .steps { position: static; display: flex; overflow-x: auto; gap: 4px; padding-bottom: 6px; scrollbar-width: thin; }
  .steps button { white-space: nowrap; flex: none; padding: 6px 10px; }
  .steps .req { display: none; }
}
@media (max-width: 600px) {
  .card { padding: 18px; }
  .q { padding: 16px; }
  .likert, .likert.no-nsa { grid-template-columns: 1fr 1fr; }
  .likert label.nsa { grid-column: 1 / -1; max-width: none; }
  .task-row { grid-template-columns: 1fr; gap: 4px; }
  .points-row { grid-template-columns: 1fr; }
  .brand-kicker { display: none; }
  .brand-logo img { height: 40px; }
  .step-nav .btn { flex: 1; justify-content: center; }
}

/* ---------- administration ---------- */
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kpi .v { font-size: 1.9rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .85rem; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.inline-form label { display: grid; gap: 4px; font-size: .85rem; }
.inline-form input, .inline-form select { width: auto; min-width: 140px; }
.bar { display: grid; grid-template-columns: minmax(0, 1fr) 190px 64px; gap: 10px; align-items: center; padding: 4px 0; font-size: .88rem; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); }
.bar-fill.leaf { background: var(--leaf); }
.stack-bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--surface-2); min-width: 120px; }
.s1 { background: #b45a6f; } .s2 { background: #e0b3be; } .s3 { background: #a9c282; } .s4 { background: #5f7a3a; } .s0 { background: var(--line); }
.agg-q { padding: 14px 0; border-top: 1px solid var(--line); }
.agg-q:first-child { border-top: 0; }
.agg-meta { font-size: .8rem; color: var(--muted); }
.legend-row { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-bottom: 10px; }
.legend-row i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.texts { margin: 0; padding-left: 18px; font-size: .9rem; }
.admin-actions { display: flex; gap: 10px; flex-wrap: wrap; }
@media (max-width: 600px) { .bar { grid-template-columns: 1fr 90px 48px; } }
.bar-svg .track { fill: var(--surface-2); }
.bar-svg .fill { fill: var(--accent); }
.bar-svg .fill.leaf { fill: var(--leaf); }
.stack-svg { display: block; border-radius: 999px; overflow: hidden; margin-bottom: 6px; }
.stack-svg .s1 { fill: #b45a6f; } .stack-svg .s2 { fill: #e0b3be; } .stack-svg .s3 { fill: #a9c282; } .stack-svg .s4 { fill: #5f7a3a; } .stack-svg .s0 { fill: var(--line); }
/* La légende d'un fieldset se place sur la bordure : on la remet dans le flux. */
.q > legend { float: left; width: 100%; }
.q > legend + * { clear: both; }
details.agg-section { border-top: 1px solid var(--line); padding: 10px 0; }
details.agg-section > summary { cursor: pointer; font-weight: 650; font-size: 1.05rem; padding: 4px 0; }
[hidden] { display: none !important; }
