/* Quiz SFCB — thème clair / sombre, bleu #00529b, rouge #c10435, blanc, noir */
:root {
  --blue: #00529b;
  --blue-strong: #003f78;
  --red: #c10435;
  --red-strong: #9a032a;
  --black: #0b0d12;
  --white: #ffffff;

  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #eaf0f7;
  --text: #0b0d12;
  --muted: #4a5466;
  --border: #cfd7e3;
  --link: #00529b;
  --primary: #00529b;
  --primary-hover: #003f78;
  --on-primary: #ffffff;
  --danger: #c10435;
  --danger-text: #b0032f;
  --success: #17703f;
  --success-bg: #e6f4ec;
  --error-bg: #fbe8ed;
  --warn-bg: #fff4dc;
  --warn-text: #7a4b00;
  --focus: #c10435;
  --shadow: 0 1px 2px rgba(11, 13, 18, 0.06), 0 6px 20px rgba(0, 40, 90, 0.07);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #07090d;
    --surface: #12161e;
    --surface-2: #1b2130;
    --text: #f1f4f9;
    --muted: #a7b1c2;
    --border: #2b3445;
    --link: #8cc2ff;
    --primary: #0a62b5;
    --primary-hover: #1773c9;
    --danger-text: #ff7d9b;
    --success: #5fd394;
    --success-bg: #10291c;
    --error-bg: #34111c;
    --warn-bg: #2f2410;
    --warn-text: #ffcf7a;
    --focus: #ff7d9b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #07090d;
  --surface: #12161e;
  --surface-2: #1b2130;
  --text: #f1f4f9;
  --muted: #a7b1c2;
  --border: #2b3445;
  --link: #8cc2ff;
  --primary: #0a62b5;
  --primary-hover: #1773c9;
  --danger-text: #ff7d9b;
  --success: #5fd394;
  --success-bg: #10291c;
  --error-bg: #34111c;
  --warn-bg: #2f2410;
  --warn-text: #ffcf7a;
  --focus: #ff7d9b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
}
img { max-width: 100%; }
a { color: var(--link); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75em; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 1000;
  background: var(--primary); color: var(--on-primary); padding: 10px 16px; border-radius: 8px;
}
.skip-link:focus { top: 8px; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ── En-tête ─────────────────────────────────────────────────────────── */
.tricolore { height: 5px; background: linear-gradient(90deg, var(--blue) 0 33.3%, var(--white) 33.3% 66.6%, var(--red) 66.6%); }
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.site-header .inner {
  max-width: 1180px; margin: 0 auto; padding: 8px 16px;
  display: flex; align-items: center; gap: 12px; min-height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 800; font-size: 1.05rem; min-width: 0; }
.brand img { width: 28px; height: 37px; flex: none; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.main-nav { display: flex; gap: 4px; }
.main-nav a {
  text-decoration: none; color: var(--text); padding: 10px 12px; border-radius: 10px; font-weight: 600; font-size: 0.95rem;
  min-height: 44px; display: inline-flex; align-items: center;
}
.main-nav a:hover { background: var(--surface-2); }
.main-nav a[aria-current='page'] { background: var(--primary); color: var(--on-primary); }

.container { max-width: 1180px; margin: 0 auto; padding: 20px 16px 96px; }
.container.narrow { max-width: 720px; }

/* ── Boutons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: 0.95rem; line-height: 1.2;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: var(--red-strong); border-color: var(--red-strong); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-ghost.danger { color: var(--danger-text); }
.btn-lg { min-height: 54px; padding: 14px 22px; font-size: 1.05rem; border-radius: var(--radius); }
.btn-block { width: 100%; }
.btn-icon { width: 44px; padding: 0; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ── Cartes, sections ───────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-title { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-title h2 { margin: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 18px; }
.page-head h1 { margin: 0; flex: 1 1 auto; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.mono { font-family: var(--mono); }
.stack > * + * { margin-top: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }

/* ── Formulaires ─────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-weight: 600; font-size: 0.92rem; }
.hint { font-size: 0.84rem; color: var(--muted); }
input[type='text'], input[type='password'], input[type='url'], input[type='number'], input[type='search'], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  font: inherit; font-size: 1rem; color: var(--text);
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius-sm);
}
textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: 2px solid transparent; box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent); }
input[type='color'] { width: 52px; height: 44px; padding: 2px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }
input[type='range'] { width: 100%; accent-color: var(--primary); min-height: 32px; }
input[type='checkbox'], input[type='radio'] { accent-color: var(--primary); width: 20px; height: 20px; }
.field-error { color: var(--danger-text); font-size: 0.88rem; font-weight: 600; }

/* Interrupteur accessible (checkbox native) */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 48px; height: 28px; border-radius: 28px; background: var(--border); position: relative; flex: none; cursor: pointer; transition: background 0.2s; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { left: 23px; }

/* Choix segmentés */
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.segmented span {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; min-width: 44px; padding: 8px 12px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-weight: 600; font-size: 0.9rem; background: var(--surface);
}
.segmented input:checked + span { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, var(--surface)); color: var(--text); box-shadow: inset 0 0 0 1px var(--primary); }
.segmented input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ── Étiquettes ─────────────────────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 0.8rem; font-weight: 700; color: var(--tag-text, #fff); background: var(--tag, var(--blue)); line-height: 1.5;
}
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-filter { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-filter button {
  min-height: 40px; padding: 6px 14px; border-radius: 999px; font: inherit; font-weight: 700; font-size: 0.88rem; cursor: pointer;
  border: 2px solid var(--tag, var(--blue)); background: transparent; color: var(--text);
}
.tag-filter button[aria-pressed='true'] { background: var(--tag, var(--blue)); color: var(--tag-text, #fff); }
.tag-filter button .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--tag); margin-right: 6px; }
.tag-filter button[aria-pressed='true'] .dot { background: var(--tag-text, #fff); }
.tag-remove { border: 0; background: rgba(127, 127, 127, 0.35); color: inherit; width: 22px; height: 22px; border-radius: 50%; cursor: pointer; font-size: 0.9rem; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }

.code-badge {
  font-family: var(--mono); font-weight: 700; letter-spacing: 0.12em; padding: 3px 9px; border-radius: 8px;
  background: var(--black); color: #fff; font-size: 0.88rem;
}
:root[data-theme='dark'] .code-badge { background: #fff; color: var(--black); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .code-badge { background: #fff; color: var(--black); } }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; font-weight: 700; }
.status::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status.on::before { background: var(--success); }
.status.on { color: var(--success); }

/* ── Messages ───────────────────────────────────────────────────────── */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid transparent; font-size: 0.95rem; }
.alert-warn { background: var(--warn-bg); color: var(--warn-text); border-color: color-mix(in srgb, var(--warn-text) 30%, transparent); }
.alert-error { background: var(--error-bg); color: var(--danger-text); border-color: color-mix(in srgb, var(--danger-text) 30%, transparent); }
.alert-ok { background: var(--success-bg); color: var(--success); border-color: color-mix(in srgb, var(--success) 30%, transparent); }

#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 460px); pointer-events: none; }
.toast { background: var(--black); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35); font-weight: 600; animation: rise 0.25s ease; border-left: 5px solid var(--blue); }
.toast.error { border-left-color: var(--red); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ── Dialogues ──────────────────────────────────────────────────────── */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text);
  width: min(94vw, 560px); max-height: 90vh; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
dialog::backdrop { background: rgba(5, 10, 20, 0.6); }
dialog .dlg-body { padding: 20px; overflow: auto; max-height: calc(90vh - 80px); }
dialog .dlg-actions { padding: 12px 20px 20px; display: flex; flex-direction: row-reverse; gap: 8px; justify-content: flex-start; flex-wrap: wrap; }

/* ── Tableaux ───────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
@media (max-width: 640px) {
  table.responsive thead { display: none; }
  table.responsive tr { display: block; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 10px; padding: 6px 10px; }
  table.responsive td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 6px 0; }
  table.responsive td::before { content: attr(data-label); font-weight: 700; color: var(--muted); }
}

/* ── Barres ─────────────────────────────────────────────────────────── */
.progress { height: 10px; border-radius: 10px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--blue), var(--red)); border-radius: 10px; transition: width 0.3s; }
.bar { height: 8px; border-radius: 8px; background: var(--surface-2); overflow: hidden; min-width: 80px; }
.bar > div { height: 100%; background: var(--blue); }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 4px solid var(--surface-2); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pied de page ───────────────────────────────────────────────────── */
.site-footer { text-align: center; padding: 24px 16px 32px; color: var(--muted); font-size: 0.85rem; }

/* ── Mobile ─────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 16px; }
  .container { padding: 16px 12px 110px; }
  .main-nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 60; background: var(--surface); border-top: 1px solid var(--border); justify-content: space-around; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .main-nav a { flex: 1; justify-content: center; flex-direction: column; font-size: 0.75rem; gap: 2px; padding: 6px 4px; min-height: 54px; }
  .main-nav a svg { width: 22px; height: 22px; }
  #toasts { bottom: calc(76px + env(safe-area-inset-bottom)); }
}
@media (min-width: 761px) { .main-nav a svg { display: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ── Impression (fiche QR) ──────────────────────────────────────────── */
#printSheet { display: none; }
@media print {
  body > *:not(#printSheet) { display: none !important; }
  body { background: #fff; color: #000; }
  #printSheet { display: block !important; text-align: center; padding-top: 10mm; }
  #printSheet h1 { font-size: 26pt; margin-bottom: 4mm; }
  #printSheet p { font-size: 13pt; }
  #printSheet img { width: 120mm; height: auto; margin: 8mm auto; display: block; }
  #printSheet .print-url { font-family: monospace; font-size: 12pt; word-break: break-all; }
}
