/* ROSTERIA — Feuille globale, sans framework ni dépendance.
   Charger avant les styles propres aux pages.
   Thème : <html data-theme="light"> ou <html data-theme="dark">.
   Sans attribut (ou avec data-theme="system"), suit le système.
   Classes principales : .container .card .btn .badge .field .table-wrap.
   Les variables --r-* permettent de personnaliser les composants.
*/

/* 1. Identité et palette claire */
:root {
  color-scheme: light;
  --r-bg: #f8f9fb;
  --r-surface: #ffffff;
  --r-surface-alt: #f2f3f7;
  --r-text: #191c25;
  --r-text-muted: #626877;
  --r-border: #e6e8ee;
  --r-input-border: #7d8391;
  --r-primary: #6d4aff;
  --r-primary-hover: #5935e8;
  --r-primary-active: #4c2bc7;
  --r-on-primary: #ffffff;
  --r-primary-soft: #f0ecff;
  --r-success: #16724d;
  --r-success-soft: #eaf6ef;
  --r-warning: #986010;
  --r-warning-soft: #fff4df;
  --r-danger: #b4233a;
  --r-danger-soft: #fff0f2;
  --r-info: #245ea8;
  --r-info-soft: #edf4ff;
  --r-shadow-sm: 0 2px 8px rgb(25 28 37 / 4%);
  --r-shadow-md: 0 8px 28px rgb(25 28 37 / 7%);
  --r-shadow-lg: 0 24px 70px rgb(25 28 37 / 12%);
  --r-font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --r-font-mono: ui-monospace, SFMono-Regular, Consolas, monospace;
  --r-radius-sm: 6px;
  --r-radius: 10px;
  --r-radius-lg: 15px;
  --r-radius-xl: 22px;
  --r-space-1: .25rem;
  --r-space-2: .5rem;
  --r-space-3: .75rem;
  --r-space-4: 1rem;
  --r-space-5: 1.5rem;
  --r-space-6: 2rem;
  --r-space-7: 3rem;
  --r-space-8: 4rem;
  --r-duration: 160ms;
  --r-container: 1160px;
}

/* 2. Palette sombre explicite */
:root[data-theme="dark"] {
  color-scheme: dark;
  --r-bg: #111318;
  --r-surface: #1b1e26;
  --r-surface-alt: #242832;
  --r-text: #f3f4f7;
  --r-text-muted: #a6adbb;
  --r-border: #30343f;
  --r-input-border: #777e8d;
  --r-primary: #a594ff;
  --r-primary-hover: #b9abff;
  --r-primary-active: #9580f0;
  --r-on-primary: #171124;
  --r-primary-soft: #30284c;
  --r-success: #83dcb2;
  --r-success-soft: #1d362d;
  --r-warning: #efc378;
  --r-warning-soft: #3a3020;
  --r-danger: #ff9aaa;
  --r-danger-soft: #3d232d;
  --r-info: #9cc5ff;
  --r-info-soft: #20324b;
  --r-shadow-sm: 0 2px 8px rgb(0 0 0 / 12%);
  --r-shadow-md: 0 8px 28px rgb(0 0 0 / 18%);
  --r-shadow-lg: 0 24px 70px rgb(0 0 0 / 28%);
}

/* Même palette quand le choix est laissé au système. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]), :root[data-theme="system"] {
    color-scheme: dark;
    --r-bg: #111318;
    --r-surface: #1b1e26;
    --r-surface-alt: #242832;
    --r-text: #f3f4f7;
    --r-text-muted: #a6adbb;
    --r-border: #30343f;
    --r-input-border: #777e8d;
    --r-primary: #a594ff;
    --r-primary-hover: #b9abff;
    --r-primary-active: #9580f0;
    --r-on-primary: #171124;
    --r-primary-soft: #30284c;
    --r-success: #83dcb2;
    --r-success-soft: #1d362d;
    --r-warning: #efc378;
    --r-warning-soft: #3a3020;
    --r-danger: #ff9aaa;
    --r-danger-soft: #3d232d;
    --r-info: #9cc5ff;
    --r-info-soft: #20324b;
    --r-shadow-sm: 0 2px 8px rgb(0 0 0 / 12%);
    --r-shadow-md: 0 8px 28px rgb(0 0 0 / 18%);
    --r-shadow-lg: 0 24px 70px rgb(0 0 0 / 28%);
  }
}

/* 3. Base et typographie */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 6rem; }
body {
  margin: 0;
  background: var(--r-bg);
  color: var(--r-text);
  font-family: var(--r-font);
  font-size: 1rem;
  line-height: 1.6;
  letter-spacing: -.015em;
  overflow-wrap: break-word;
}
[hidden] { display: none !important; }
img, video { display: block; max-width: 100%; height: auto; }
svg { vertical-align: middle; }
button, input, textarea, select { font: inherit; }
button, a, input, select, textarea, summary { touch-action: manipulation; }
h1, h2, h3, h4, h5, h6 {
  margin: 0 0 .75rem;
  color: var(--r-text);
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -.035em;
  text-wrap: balance;
}
h1 { font-size: clamp(2rem, 1.5rem + 2vw, 3.25rem); }
h2 { font-size: clamp(1.5rem, 1.25rem + 1vw, 2.25rem); }
h3 { font-size: 1.25rem; }
h4, h5, h6 { font-size: 1rem; }
p { margin: 0 0 1rem; }
small, .text-small { font-size: .875rem; }
strong { font-weight: 650; }
ul, ol { padding-inline-start: 1.5rem; }
hr { margin-block: 1.5rem; border: 0; border-top: 1px solid var(--r-border); }
code, pre { font-family: var(--r-font-mono); font-size: .875em; }
code { background: var(--r-surface-alt); padding: .15em .35em; border-radius: 4px; }
pre { padding: 1rem; background: var(--r-surface-alt); border-radius: var(--r-radius); overflow-x: auto; }
pre code { padding: 0; }
::selection { background: var(--r-primary); color: var(--r-on-primary); }
:focus-visible { outline: 3px solid var(--r-primary); outline-offset: 3px; }

/* 4. Liens : soulignement conservé dans le contenu */
a { color: var(--r-primary); text-decoration: underline; text-underline-offset: .2em; text-decoration-thickness: 1px; }
a:hover { color: var(--r-primary-hover); }
a:active { color: var(--r-primary-active); }
.link-muted { color: var(--r-text-muted); }
.nav-link { display: flex; align-items: center; gap: .75rem; min-height: 44px; padding: .65rem .9rem; border-radius: var(--r-radius); color: var(--r-text-muted); text-decoration: none; font-size: .875rem; }
.nav-link:hover { background: var(--r-surface-alt); color: var(--r-text); }
.nav-link[aria-current="page"], .nav-link.is-active { background: var(--r-primary-soft); color: var(--r-primary); font-weight: 600; }

/* 5. Boutons : les <button> sont primaires par défaut.
   .btn permet le même rendu sur un lien <a>.
   Préférer <button disabled> pour une action indisponible.
   aria-disabled seul n'empêche pas l'activation : la gérer côté application. */
button, .btn, input[type="submit"], input[type="reset"], input[type="button"] {
  --r-btn-bg: var(--r-primary);
  --r-btn-text: var(--r-on-primary);
  --r-btn-border: transparent;
  --r-btn-hover-bg: var(--r-primary-hover);
  --r-btn-hover-text: var(--r-on-primary);
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: .6rem;
  min-height: 44px;
  max-width: 100%;
  padding: .65rem 1.1rem;
  border: 1px solid var(--r-btn-border);
  border-radius: var(--r-radius);
  background: var(--r-btn-bg);
  color: var(--r-btn-text);
  font-size: .875rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  text-decoration: none;
  white-space: normal;
  cursor: pointer;
  transition: background-color var(--r-duration), color var(--r-duration), border-color var(--r-duration), box-shadow var(--r-duration);
}
button:hover, .btn:hover, input[type="submit"]:hover, input[type="reset"]:hover, input[type="button"]:hover { background: var(--r-btn-hover-bg); color: var(--r-btn-hover-text); }
.btn-primary { --r-btn-bg: var(--r-primary); --r-btn-text: var(--r-on-primary); }
.btn-secondary { --r-btn-bg: var(--r-surface); --r-btn-text: var(--r-text); --r-btn-border: var(--r-border); --r-btn-hover-bg: var(--r-surface-alt); --r-btn-hover-text: var(--r-text); }
.btn-ghost { --r-btn-bg: transparent; --r-btn-text: var(--r-text-muted); --r-btn-hover-bg: var(--r-surface-alt); --r-btn-hover-text: var(--r-text); }
.btn-danger { --r-btn-bg: var(--r-danger-soft); --r-btn-text: var(--r-danger); --r-btn-hover-bg: var(--r-danger); --r-btn-hover-text: var(--r-surface); }
.btn-sm { padding: .5rem .8rem; font-size: .875rem; }
.btn-lg { min-height: 52px; padding: .85rem 1.5rem; font-size: 1rem; }
.btn-icon { width: 44px; height: 44px; padding: .65rem; flex-shrink: 0; }
.btn-block { display: flex; width: 100%; }
.btn svg, button svg { width: 1.125rem; height: 1.125rem; flex-shrink: 0; }
button:disabled, input:disabled, select:disabled, textarea:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
button:disabled:hover, input[type="submit"]:disabled:hover, input[type="reset"]:disabled:hover, input[type="button"]:disabled:hover, .btn[aria-disabled="true"]:hover { background: var(--r-btn-bg); color: var(--r-btn-text); }

/* 6. Cards */
.card { min-width: 0; padding: 1.25rem; background: var(--r-surface); border: 1px solid var(--r-border); border-radius: var(--r-radius-lg); box-shadow: var(--r-shadow-sm); }
.card-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.card-title { margin: 0; font-size: 1.125rem; letter-spacing: -.025em; }
.card-description { margin: .35rem 0 0; color: var(--r-text-muted); font-size: .875rem; }
.card-body > :last-child { margin-bottom: 0; }
.card-footer { display: flex; align-items: center; flex-wrap: wrap; gap: .75rem; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--r-border); }
.card-accent { background: var(--r-primary-soft); border-color: transparent; }
.card-flat { box-shadow: none; }
a.card { display: block; color: var(--r-text); text-decoration: none; }
a.card:hover { border-color: var(--r-primary); box-shadow: var(--r-shadow-md); }
.stat-label { color: var(--r-text-muted); font-size: .875rem; }
.stat-value { display: block; margin: .5rem 0 .25rem; font-size: clamp(1.8rem, 1.5rem + 1vw, 2.25rem); line-height: 1.2; font-weight: 650; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.stat-caption { color: var(--r-text-muted); font-size: .875rem; }

/* 7. Formulaires : un vrai <label> reste nécessaire. */
.field { display: grid; gap: .5rem; margin-bottom: 1.25rem; }
label, legend { color: var(--r-text); font-size: .875rem; font-weight: 600; }
fieldset { min-width: 0; margin: 0 0 1.5rem; padding: 1rem; border: 1px solid var(--r-border); border-radius: var(--r-radius); }
legend { padding-inline: .35rem; }
input:where(:not([type="checkbox"],[type="radio"],[type="range"],[type="submit"],[type="reset"],[type="button"],[type="hidden"],[type="color"])), select, textarea {
  display: block; width: 100%; min-width: 0; min-height: 44px; padding: .65rem .8rem;
  color: var(--r-text); background: var(--r-surface);
  border: 1px solid var(--r-input-border); border-radius: var(--r-radius);
  font-size: 1rem; line-height: 1.5;
}
textarea { min-height: 120px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--r-text-muted); opacity: 1; }
input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--r-primary); }
input[type="checkbox"], input[type="radio"] { width: 1.125rem; height: 1.125rem; margin: 0; flex-shrink: 0; }
.check-label { display: flex; align-items: center; gap: .65rem; min-height: 44px; font-weight: 400; cursor: pointer; }
input[type="range"] { width: 100%; min-height: 44px; }
input[type="color"] { min-width: 44px; min-height: 44px; background: var(--r-surface); border: 1px solid var(--r-input-border); border-radius: var(--r-radius-sm); }
input::file-selector-button { padding: .45rem .7rem; margin-inline-end: .75rem; background: var(--r-primary-soft); color: var(--r-primary); border: 0; border-radius: var(--r-radius-sm); cursor: pointer; font: inherit; }
[aria-invalid="true"] { border-color: var(--r-danger); }
.field-help { margin: 0; color: var(--r-text-muted); font-size: .875rem; }
.field-error { margin: 0; color: var(--r-danger); font-size: .875rem; }

/* 8. Badges et alertes : toujours inclure un libellé explicite. */
.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .6rem; background: var(--r-surface-alt); color: var(--r-text-muted); border-radius: var(--r-radius-sm); font-size: .875rem; font-weight: 550; line-height: 1.4; }
.badge-primary { background: var(--r-primary-soft); color: var(--r-primary); }
.badge-success { background: var(--r-success-soft); color: var(--r-success); }
.badge-warning { background: var(--r-warning-soft); color: var(--r-warning); }
.badge-danger { background: var(--r-danger-soft); color: var(--r-danger); }
.badge-info { background: var(--r-info-soft); color: var(--r-info); }
.alert { padding: 1rem 1.25rem; border: 1px solid currentColor; border-radius: var(--r-radius); font-size: .875rem; }
.alert > :last-child { margin-bottom: 0; }
.alert-info { color: var(--r-info); background: var(--r-info-soft); }
.alert-success { color: var(--r-success); background: var(--r-success-soft); }
.alert-warning { color: var(--r-warning); background: var(--r-warning-soft); }
.alert-danger { color: var(--r-danger); background: var(--r-danger-soft); }
.alert a { color: inherit; }

/* 9. Tableaux et progression */
.table-wrap { max-width: 100%; overflow-x: auto; background: var(--r-surface); border: 1px solid var(--r-border); border-radius: var(--r-radius-lg); }
table { width: 100%; border-collapse: collapse; text-align: start; font-size: .875rem; }
caption { padding: 1rem; text-align: start; color: var(--r-text-muted); }
th, td { padding: .9rem 1rem; border-bottom: 1px solid var(--r-border); vertical-align: middle; }
th { background: var(--r-surface-alt); color: var(--r-text-muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--r-surface-alt); }
.numeric { text-align: end; font-variant-numeric: tabular-nums; }
progress { display: block; width: 100%; height: 6px; appearance: none; border: 0; border-radius: 99px; background: var(--r-surface-alt); color: var(--r-primary); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--r-surface-alt); border-radius: 99px; }
progress::-webkit-progress-value { background: var(--r-primary); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--r-primary); border-radius: 99px; }
details { padding-block: 1rem; border-bottom: 1px solid var(--r-border); }
summary { min-height: 44px; padding-block: .5rem; font-weight: 600; cursor: pointer; }
details > p { margin-top: .75rem; color: var(--r-text-muted); }

/* 10. Mise en page mobile first et utilitaires */
.container { width: min(var(--r-container), calc(100% - 2.5rem)); margin-inline: auto; }
.section { padding-block: clamp(2.5rem, 6vw, 5rem); }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }
.text-muted { color: var(--r-text-muted); }
.text-primary { color: var(--r-primary); }
.text-success { color: var(--r-success); }
.text-warning { color: var(--r-warning); }
.text-danger { color: var(--r-danger); }
.text-center { text-align: center; }
.eyebrow { margin-bottom: .75rem; font-size: .75rem; font-weight: 650; letter-spacing: .12em; text-transform: uppercase; color: var(--r-primary); }
.avatar { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--r-primary-soft); color: var(--r-primary); font-size: .875rem; font-weight: 650; flex-shrink: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
@media (min-width: 640px) {
  .card { padding: 1.5rem; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  button, .btn, .card, .badge, .alert { border: 1px solid ButtonText; }
  progress { forced-color-adjust: auto; }
}
