/* Hyperviseur — styles. Aucune ressource tierce, aucune police distante (CSP : style-src 'self'). */
:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #121821;
  --muted: #4a5568;
  --border: #c9d1dd;
  --accent: #1d4ed8;
  --accent-text: #ffffff;
  --accent-soft: #e3ebff;
  --focus: #1d4ed8;
  --ok: #05603a;
  --ok-bg: #e4f5ec;
  --warn: #8a4b00;
  --warn-bg: #fff1d6;
  --err: #b42318;
  --err-bg: #fde8e6;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131a;
    --surface: #161d27;
    --surface-2: #1d2733;
    --text: #e8edf4;
    --muted: #a9b4c3;
    --border: #324053;
    --accent: #7aa7ff;
    --accent-text: #08111f;
    --accent-soft: #1b2b4d;
    --focus: #9cc0ff;
    --ok: #62d49a;
    --ok-bg: #12301f;
    --warn: #f2b45c;
    --warn-bg: #3a2a0e;
    --err: #ff9b92;
    --err-bg: #3d1713;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

main { flex: 1; width: 100%; padding: 1.25rem 1rem 2rem; outline: none; }

h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 .75rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; line-height: 1.3; margin: 0 0 .5rem; }
p { margin: 0 0 .9rem; }
a { color: var(--accent); text-underline-offset: 3px; }
code { font-family: var(--mono); font-size: .92em; background: var(--surface-2); padding: .1em .35em; border-radius: 6px; }
.break { overflow-wrap: anywhere; word-break: break-all; }
.lead { color: var(--muted); }
.hint { color: var(--muted); font-size: .9rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Focus : toujours visible, jamais masqué (WCAG 2.4.7 / 2.4.11). */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
main:focus { outline: none; }

.skip {
  position: absolute; left: .5rem; top: -4rem; z-index: 10;
  background: var(--accent); color: var(--accent-text);
  padding: .6rem 1rem; border-radius: 8px; text-decoration: none;
}
.skip:focus { top: .5rem; }

/* En-tête */
.top { background: var(--surface); border-bottom: 1px solid var(--border); padding-left: env(safe-area-inset-left); }
.top-in {
  max-width: 64rem; margin: 0 auto; padding: .5rem 1rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem;
}
.brand {
  display: inline-flex; align-items: center; gap: .55rem; min-height: 44px;
  font-weight: 650; color: var(--text); text-decoration: none; letter-spacing: -.01em;
}
.brand-mark { width: 1.4rem; height: 1.4rem; border-radius: 6px; background: var(--accent); display: inline-block; }
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 .75rem;
  color: var(--muted); text-decoration: none; border-radius: 8px;
  transition: background-color 140ms ease-out, color 140ms ease-out;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { color: var(--text); background: var(--accent-soft); font-weight: 600; }
.logout { margin-left: auto; }

/* Cartes */
.card {
  max-width: 44rem; margin: 0 auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem;
  animation: rise 180ms ease-out both;
}
.card.narrow { max-width: 28rem; }
.card.wide { max-width: 64rem; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 1.1rem; gap: .5rem;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  color: var(--text); background: var(--surface); border: 1px solid var(--muted); border-radius: 10px;
  touch-action: manipulation;
  transition: background-color 140ms ease-out, border-color 140ms ease-out, transform 140ms ease-out;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); border-color: var(--accent); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--text); }
.btn-block { display: flex; width: 100%; }
.btn[hidden] { display: none; }

/* Formulaires */
.field { margin: 0 0 1rem; }
label { display: block; font-weight: 600; margin-bottom: .35rem; }
input[type="text"], input[type="password"] {
  width: 100%; min-height: 48px; padding: .6rem .8rem;
  font: inherit; font-size: 1rem; /* >= 16 px : pas de zoom automatique sur mobile */
  color: var(--text); background: var(--bg); border: 1px solid var(--muted); border-radius: 10px;
}
input[type="text"]#code { font-family: var(--mono); letter-spacing: .08em; }
.check { display: flex; align-items: flex-start; gap: .6rem; font-weight: 500; margin: 1rem 0; min-height: 44px; }
.check input { width: 1.4rem; height: 1.4rem; margin-top: .15rem; accent-color: var(--accent); flex: none; }

/* Messages (jamais la couleur seule : icône + texte) */
.notice { padding: .7rem .9rem; border-radius: 10px; border: 1px solid transparent; margin: 0 0 1rem; }
.notice[hidden] { display: none; }
.notice-ok { background: var(--ok-bg); color: var(--ok); border-color: currentColor; }
.notice-err { background: var(--err-bg); color: var(--err); border-color: currentColor; }
.notice-warn { background: var(--warn-bg); color: var(--warn); border-color: currentColor; }
.notice-err::before, .notice-warn::before { content: "⚠ "; }

/* Étapes d'enrôlement */
.steps { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: 1rem; }
.step { border: 1px solid var(--border); border-radius: 10px; padding: 1rem; background: var(--bg); }
.step.done { border-color: var(--ok); }
.step h2 { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; }
.num {
  display: inline-grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); font-size: .95rem;
}
.state { margin-left: auto; font-size: .9rem; font-weight: 500; color: var(--muted); }
.step.done .state { color: var(--ok); font-weight: 650; }
.plain { list-style: none; padding: 0; margin: 0 0 .9rem; }
.qr { display: block; width: 220px; max-width: 100%; height: auto; margin: .5rem 0 1rem; border: 6px solid #fff; border-radius: 8px; background: #fff; }
.secret-box { margin: 0 0 1rem; }
.secret-box summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; }
.secret { font-size: 1.05rem; letter-spacing: .06em; overflow-wrap: anywhere; user-select: all; }
.codes {
  list-style: none; padding: 0; margin: 0 0 1rem;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .5rem;
}
.codes li { background: var(--surface-2); border-radius: 8px; padding: .5rem .75rem; }
.codes code { background: transparent; font-size: 1.05rem; letter-spacing: .05em; }

/* Informations */
.facts { display: grid; gap: .75rem; margin: 1rem 0; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
.facts div { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: .75rem 1rem; }
.facts dt { color: var(--muted); font-size: .9rem; }
.facts dd { margin: 0; font-weight: 600; }

/* Journal : tableau large, cartes sur petit écran */
.table-wrap { margin: 1rem 0; }
.journal { width: 100%; border-collapse: collapse; font-size: .92rem; }
.journal th { text-align: left; color: var(--muted); font-weight: 600; padding: .5rem .6rem; border-bottom: 2px solid var(--border); white-space: nowrap; }
.journal td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.journal code { overflow-wrap: anywhere; }
.pill { display: inline-block; padding: .05rem .55rem; border-radius: 999px; font-weight: 600; font-size: .85rem; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.err { background: var(--err-bg); color: var(--err); }
.pill.neutral { background: var(--surface-2); color: var(--muted); }

@media (max-width: 47.99rem) {
  .journal thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .journal, .journal tbody, .journal tr, .journal td { display: block; width: 100%; }
  .journal tr { border: 1px solid var(--border); border-radius: 10px; margin: 0 0 .75rem; padding: .35rem .25rem; background: var(--bg); }
  .journal td { display: grid; grid-template-columns: 7.5rem 1fr; gap: .5rem; border: 0; padding: .3rem .6rem; }
  .journal td::before { content: attr(data-label); color: var(--muted); font-weight: 600; }
}

.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom)); }
.foot p { margin: 0; }

/* htmx : indicateur discret pendant une requête */
.htmx-request { opacity: .6; transition: opacity 140ms ease-out; }

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

@media (min-width: 48rem) {
  main { padding-top: 2rem; }
  .card { padding: 1.75rem; }
}

@media print { .top, .foot { display: none; } }
