/* ==========================================================================
   Console UI v1 : style commun des applications
   Sobre, aéré, lisible. Tokens (variables) d'abord, composants ensuite.
   Clair par défaut, sombre automatique (prefers-color-scheme) ou forcé :
   <html data-theme="light"> ou <html data-theme="dark">.
   Chaque application peut changer son accent en redéfinissant --accent*.
   Polices : Inter (licence OFL), hébergée ici. Icônes : Lucide (licence ISC).
   ========================================================================== */

@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("./fonts/inter-latin-wght-normal.woff2") format("woff2-variations");
}

/* ---------- 1. Tokens ---------- */
:root {
  --font: "Inter Variable", ui-sans-serif, system-ui, "Segoe UI Variable", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;

  /* Espacement : base 4 px, mêmes valeurs partout */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px;

  /* Rayons */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-xl: 20px; --r-pill: 999px;

  /* Typographie : 12 · 13 · 14 · 16 · 20 · 24 · 30 */
  --t-xs: 12px; --t-sm: 13px; --t-md: 14px; --t-base: 16px; --t-lg: 20px; --t-xl: 24px; --t-2xl: 30px;

  /* Couleurs : clair */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f4f8;
  --surface-3: #e9eef5;
  --border: #e3e8ef;
  --border-strong: #cdd5e0;
  --text: #0b1220;
  --text-2: #435066;
  --text-3: #5f6f86;          /* 4,9:1 sur blanc : lisible (WCAG AA) */
  --ac: #0f766e;              /* accent en mode clair : 5,5:1 avec du texte blanc */
  --as: #2dd4bf;              /* accent en mode sombre */
  --accent: var(--ac);
  --accent-hover: color-mix(in srgb, var(--accent) 82%, #000);
  --accent-soft: color-mix(in srgb, var(--accent) 11%, var(--surface));
  --accent-text: #ffffff;
  --ink: #0b1220;
  --success: #15803d; --success-soft: #e7f6ec;
  --warning: #a16207; --warning-soft: #fdf3dc;
  --danger: #b91c1c;  --danger-soft: #fdeaea;
  --info: #1d4ed8;    --info-soft: #e8efff;
  --focus: color-mix(in srgb, var(--accent) 38%, transparent);

  /* Élévation : deux couches, lumière en haut */
  --sh-1: 0 1px 2px rgba(11, 18, 32, .05), 0 1px 1px rgba(11, 18, 32, .03);
  --sh-2: 0 1px 3px rgba(11, 18, 32, .06), 0 8px 24px -10px rgba(11, 18, 32, .12);
  --sh-3: 0 4px 12px rgba(11, 18, 32, .08), 0 24px 48px -16px rgba(11, 18, 32, .22);

  --sidebar-w: 264px;
  --sidebar-w-reduit: 76px;
  --topbar-h: 64px;
  --contenu-max: 1200px;
  --duree: 160ms;
  --courbe: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}

/* Sombre : mêmes noms, autres valeurs */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #090e18; --surface: #0f1624; --surface-2: #141d2e; --surface-3: #1b2639;
    --border: #1f2a3d; --border-strong: #2e3c55;
    --text: #e8edf5; --text-2: #aab6c9; --text-3: #8d9bb1;
    --accent: var(--as); --accent-hover: color-mix(in srgb, var(--accent) 80%, #fff); --accent-text: #0b1220;
    --success: #4ade80; --success-soft: rgba(74, 222, 128, .12);
    --warning: #fbbf24; --warning-soft: rgba(251, 191, 36, .12);
    --danger: #f87171;  --danger-soft: rgba(248, 113, 113, .13);
    --info: #8db4ff;    --info-soft: rgba(141, 180, 255, .13);
    --focus: color-mix(in srgb, var(--accent) 45%, transparent);
    --sh-1: 0 1px 2px rgba(0, 0, 0, .35);
    --sh-2: 0 1px 3px rgba(0, 0, 0, .4), 0 10px 28px -12px rgba(0, 0, 0, .6);
    --sh-3: 0 4px 12px rgba(0, 0, 0, .45), 0 28px 56px -16px rgba(0, 0, 0, .75);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #090e18; --surface: #0f1624; --surface-2: #141d2e; --surface-3: #1b2639;
  --border: #1f2a3d; --border-strong: #2e3c55;
  --text: #e8edf5; --text-2: #aab6c9; --text-3: #8d9bb1;
  --accent: var(--as); --accent-hover: color-mix(in srgb, var(--accent) 80%, #fff); --accent-text: #0b1220;
  --success: #4ade80; --success-soft: rgba(74, 222, 128, .12);
  --warning: #fbbf24; --warning-soft: rgba(251, 191, 36, .12);
  --danger: #f87171;  --danger-soft: rgba(248, 113, 113, .13);
  --info: #8db4ff;    --info-soft: rgba(141, 180, 255, .13);
  --focus: color-mix(in srgb, var(--accent) 45%, transparent);
  --sh-1: 0 1px 2px rgba(0, 0, 0, .35);
  --sh-2: 0 1px 3px rgba(0, 0, 0, .4), 0 10px 28px -12px rgba(0, 0, 0, .6);
  --sh-3: 0 4px 12px rgba(0, 0, 0, .45), 0 28px 56px -16px rgba(0, 0, 0, .75);
  color-scheme: dark;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 var(--t-md)/1.55 var(--font); font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.011em; font-weight: var(--titre-poids, 650); color: var(--text); font-family: var(--font-titre, var(--font)); }
h1 { font-size: var(--t-2xl); letter-spacing: -.02em; }
h2 { font-size: var(--t-xl); letter-spacing: -.015em; }
h3 { font-size: var(--t-lg); }
h4 { font-size: var(--t-base); }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
::selection { background: var(--accent-soft); }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s-5) 0; }
code, kbd { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--text-3); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Icônes : <svg class="icon"><use href="icons.svg#i-search"/></svg> */
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon--sm { width: 16px; height: 16px; }
.icon--lg { width: 24px; height: 24px; }

/* ---------- 3. Structure : menu latéral + barre du haut + contenu ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; transition: grid-template-columns var(--duree) var(--courbe); }
.shell[data-menu="reduit"] { grid-template-columns: var(--sidebar-w-reduit) minmax(0, 1fr); }

.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--s-4);
  padding: var(--s-4) var(--s-3); background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto;
}
.sidebar__brand { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-2) var(--s-3); min-height: 56px; }
.sidebar__brand img { width: 40px; height: 40px; flex: none; }
.sidebar__brand strong { font-size: var(--t-base); letter-spacing: -.01em; }
.sidebar__brand small { display: block; color: var(--text-3); font-size: var(--t-xs); font-weight: 500; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group__titre { padding: var(--s-3) var(--s-3) var(--s-1); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.nav-item {
  display: flex; align-items: center; gap: var(--s-3); min-height: var(--ctl-h, 40px); padding: 0 var(--s-3); border-radius: var(--r-md);
  color: var(--text-2); font-weight: 500; text-decoration: none; transition: background var(--duree), color var(--duree);
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .badge { margin-left: auto; }
.sidebar__pied { margin-top: auto; display: flex; flex-direction: column; gap: 2px; padding-top: var(--s-3); border-top: 1px solid var(--border); }
.shell[data-menu="reduit"] .nav-item span, .shell[data-menu="reduit"] .nav-group__titre, .shell[data-menu="reduit"] .sidebar__brand div, .shell[data-menu="reduit"] .nav-item .badge { display: none; }
.shell[data-menu="reduit"] .nav-item { justify-content: center; padding: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h); display: flex; align-items: center; gap: var(--s-4); padding: 0 var(--s-6);
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--border);
}
.topbar__espace { flex: 1; }
.recherche { position: relative; flex: 0 1 380px; }
.recherche .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.recherche .input { padding-left: 40px; background: var(--surface); }

.contenu { width: 100%; max-width: var(--contenu-max); margin: 0 auto; padding: var(--s-6); display: flex; flex-direction: column; gap: var(--gap-page, var(--s-6)); }
.page-entete { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }
.page-entete p { color: var(--text-3); margin-top: var(--s-1); max-width: 62ch; }
.fil { display: flex; align-items: center; gap: var(--s-2); color: var(--text-3); font-size: var(--t-sm); margin-bottom: var(--s-2); }
.fil a { color: inherit; text-decoration: none; }
.fil a:hover { color: var(--text); }

.grille { display: grid; gap: var(--s-5); }
.grille--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grille--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grille--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.pile { display: flex; flex-direction: column; gap: var(--s-4); }
.rangee { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }

/* ---------- 4. Boîtes (cartes) ---------- */
.carte { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--pad-carte, var(--s-5)); box-shadow: var(--sh-1); }
.carte__entete { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); }
.carte__titre { font-size: var(--t-base); font-weight: 650; }
.carte__sous { color: var(--text-3); font-size: var(--t-sm); }
.carte--plate { box-shadow: none; background: var(--surface-2); border-color: transparent; }
.carte--relief { border-color: transparent; box-shadow: var(--sh-2); }
.carte--cliquable { text-decoration: none; color: inherit; display: block; transition: transform var(--duree) var(--courbe), box-shadow var(--duree), border-color var(--duree); }
.carte--cliquable:hover { transform: translateY(-2px); box-shadow: var(--sh-2); border-color: var(--border-strong); }
.carte--accent { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); background: linear-gradient(180deg, var(--accent-soft), var(--surface) 70%); }
.carte--sans-marge { padding: 0; overflow: hidden; }

/* Indicateur chiffré */
.stat { display: flex; flex-direction: column; gap: var(--s-2); }
.stat__etiquette { display: flex; align-items: center; gap: var(--s-2); color: var(--text-3); font-size: var(--t-sm); font-weight: 500; }
.stat__valeur { font-size: var(--t-2xl); font-weight: 650; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat__delta { font-size: var(--t-sm); font-weight: 550; color: var(--text-3); }
.stat__delta--haut { color: var(--success); }
.stat__delta--bas { color: var(--danger); }

/* Tuile d'application : logo, nom, état */
.app-tuile { display: flex; flex-direction: column; gap: var(--s-4); }
.app-tuile__tete { display: flex; align-items: center; gap: var(--s-4); }
.app-tuile__logo { width: 52px; height: 52px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; overflow: hidden; flex: none; }
.app-tuile__logo img { width: 80%; height: 80%; object-fit: contain; }
.app-tuile h3 { font-size: var(--t-base); }
.app-tuile p { color: var(--text-3); font-size: var(--t-sm); }
.app-tuile__pied { display: flex; align-items: center; justify-content: space-between; color: var(--text-3); font-size: var(--t-sm); }

/* Encadré d'information */
.encadre { display: flex; gap: var(--s-3); padding: var(--s-4); border-radius: var(--r-md); border: 1px solid transparent; font-size: var(--t-md); }
.encadre .icon { margin-top: 1px; }
.encadre strong { display: block; margin-bottom: 2px; }
.encadre--info { background: var(--info-soft); color: var(--info); }
.encadre--succes { background: var(--success-soft); color: var(--success); }
.encadre--attention { background: var(--warning-soft); color: var(--warning); }
.encadre--erreur { background: var(--danger-soft); color: var(--danger); }
.encadre > div { color: var(--text); }
.encadre > div strong { color: inherit; }

/* État vide */
.vide { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-3); padding: var(--s-7) var(--s-5); }
.vide__icone { width: 56px; height: 56px; border-radius: var(--r-xl); background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.vide p { color: var(--text-3); max-width: 44ch; }

/* ---------- 5. Boutons ---------- */
.btn {
  --h: var(--ctl-h, 40px); display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); height: var(--h); padding: 0 var(--s-4);
  border: 1px solid transparent; border-radius: var(--r-md); font: 600 var(--t-md)/1 var(--font); text-decoration: none; cursor: pointer; white-space: nowrap;
  background: var(--accent); color: var(--accent-text); transition: background var(--duree), border-color var(--duree), box-shadow var(--duree), transform 80ms;
}
.btn:hover { background: var(--accent-hover); color: var(--accent-text); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.btn--secondaire { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--sh-1); }
.btn--secondaire:hover { background: var(--surface-2); color: var(--text); }
.btn--discret { background: transparent; color: var(--text-2); }
.btn--discret:hover { background: var(--surface-2); color: var(--text); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); color: #fff; }
.btn--petit { --h: calc(var(--ctl-h, 40px) - 8px); padding: 0 var(--s-3); font-size: var(--t-sm); }
.btn--grand { --h: calc(var(--ctl-h, 40px) + 8px); padding: 0 var(--s-5); font-size: var(--t-base); }
.btn--icone { width: var(--h); padding: 0; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* ---------- 6. Formulaires ---------- */
.champ { display: flex; flex-direction: column; gap: var(--s-2); }
.champ > label, .etiquette { font-size: var(--t-sm); font-weight: 600; color: var(--text); }
.champ__aide { font-size: var(--t-sm); color: var(--text-3); }
.champ__erreur { font-size: var(--t-sm); color: var(--danger); font-weight: 500; }
.input, .select, .textarea {
  width: 100%; height: var(--ctl-h, 40px); padding: 0 var(--s-3); background: var(--surface); color: var(--text); font: 400 var(--t-md)/1.4 var(--font);
  border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--sh-1); transition: border-color var(--duree), box-shadow var(--duree);
}
.textarea { height: auto; min-height: 96px; padding: var(--s-3); resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); opacity: .8; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.formulaire { display: grid; gap: var(--s-5); }
.formulaire--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.formulaire .pleine { grid-column: 1 / -1; }

.interrupteur { display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; font-weight: 500; }
.interrupteur input { appearance: none; width: 40px; height: 24px; border-radius: var(--r-pill); background: var(--border-strong); position: relative; cursor: pointer; transition: background var(--duree); margin: 0; flex: none; }
.interrupteur input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--sh-1); transition: transform var(--duree) var(--courbe); }
.interrupteur input:checked { background: var(--accent); }
.interrupteur input:checked::after { transform: translateX(16px); }
.interrupteur input:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.case { display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; }
.case input { appearance: none; width: 20px; height: 20px; margin: 0; border: 1.5px solid var(--border-strong); border-radius: 6px; background: var(--surface); display: grid; place-items: center; cursor: pointer; transition: all var(--duree); }
.case input:checked { background: var(--accent); border-color: var(--accent); }
.case input:checked::after { content: ""; width: 10px; height: 6px; border-left: 2px solid var(--accent-text); border-bottom: 2px solid var(--accent-text); transform: translateY(-1px) rotate(-45deg); }
.case input:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }

/* ---------- 7. Pastilles, avatars, onglets ---------- */
.pastille { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: var(--r-pill); font-size: var(--t-xs); font-weight: 600; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.pastille::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pastille--sans-point::before { display: none; }
.pastille--accent { background: var(--accent-soft); color: var(--accent); }
.pastille--succes { background: var(--success-soft); color: var(--success); }
.pastille--attention { background: var(--warning-soft); color: var(--warning); }
.pastille--erreur { background: var(--danger-soft); color: var(--danger); }
.pastille--info { background: var(--info-soft); color: var(--info); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 650; font-size: var(--t-sm); flex: none; }
.onglets { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--border); }
.onglet { padding: var(--s-3) var(--s-4); margin-bottom: -1px; border: 0; background: none; color: var(--text-3); font: 600 var(--t-md)/1 var(--font); cursor: pointer; border-bottom: 2px solid transparent; transition: color var(--duree), border-color var(--duree); }
.onglet:hover { color: var(--text); }
.onglet[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.touche { display: inline-block; min-width: 22px; padding: 1px 6px; text-align: center; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px; background: var(--surface); color: var(--text-2); font-size: var(--t-xs); }

/* ---------- 8. Tableaux ---------- */
.tableau-conteneur { overflow-x: auto; }
.tableau { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--t-md); }
.tableau th { position: sticky; top: 0; text-align: left; padding: var(--s-3) var(--pad-cell, var(--s-4)); font-size: var(--t-xs); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.tableau td { padding: var(--pad-cell, var(--s-4)); border-bottom: 1px solid var(--border); vertical-align: middle; }
.tableau tbody tr { transition: background var(--duree); }
.tableau tbody tr:hover { background: var(--surface-2); }
.tableau tbody tr:last-child td { border-bottom: 0; }
.tableau .num { text-align: right; font-variant-numeric: tabular-nums; }
.cellule-id { display: flex; align-items: center; gap: var(--s-3); }
.cellule-id strong { display: block; font-weight: 600; }
.cellule-id span { color: var(--text-3); font-size: var(--t-sm); }

/* ---------- 9. Fenêtre, avis, menu déroulant ---------- */
dialog.fenetre { width: min(520px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: var(--r-xl); background: var(--surface); color: var(--text); box-shadow: var(--sh-3); }
dialog.fenetre::backdrop { background: rgba(9, 14, 24, .55); backdrop-filter: blur(3px); }
.fenetre__corps { padding: var(--s-5); display: flex; flex-direction: column; gap: var(--s-4); }
.fenetre__pied { display: flex; justify-content: flex-end; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-xl) var(--r-xl); }
.avis { position: fixed; right: var(--s-5); bottom: var(--s-5); z-index: 50; display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); background: var(--ink); color: #fff; border-radius: var(--r-md); box-shadow: var(--sh-3); font-weight: 500; }
.squelette { border-radius: var(--r-sm); background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: squelette 1.4s infinite linear; min-height: 14px; }
@keyframes squelette { to { background-position: -200% 0; } }

/* ---------- 10. Adaptation : téléphone, tablette, poste ----------
   Les points de rupture suivent les classes de fenêtre d'Android (compact < 600, moyen 600-839, étendu ≥ 840) :
   on s'adapte à la LARGEUR DISPONIBLE (qui change en écran partagé, en rotation ou en dépliant un pliable), jamais au modèle.
   - Téléphone (< 600 px) : barre d'onglets en bas (zone du pouce), une colonne, tableaux en cartes, fenêtres en feuille du bas.
   - Tablette (600 à 1023 px) : rail d'icônes à gauche, contenu en deux colonnes.
   - Poste (≥ 1024 px) : menu complet.
   Le script adaptation.js ajoute data-appareil / data-largeur / data-pointeur sur <html> pour les règles fines. */

/* Pièces communes */
.onglets-bas { display: none; }
.shell { min-height: 100vh; min-height: 100dvh; }
.sidebar { height: 100vh; height: 100dvh; }
.zone-stylet { touch-action: none; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }

/* Écran tactile : cibles de 44 px (Apple : 44 pt ; Material : 48 dp ; WCAG 2.2 : 24 px minimum) et texte de champ à 16 px,
   sinon iOS agrandit la page au clic dans un champ. */
@media (pointer: coarse) {
  html:root:root { --ctl-h: 44px; }
  .input, .select, .textarea { font-size: 16px; }
  .nav-item, .onglet { min-height: 44px; }
  .btn--petit { --h: 36px; }
  .case input { width: 24px; height: 24px; }
  .interrupteur input { width: 48px; height: 28px; }
  .interrupteur input::after { width: 22px; height: 22px; }
  .interrupteur input:checked::after { transform: translateX(20px); }
}
@media (hover: none) { .carte--cliquable:hover { transform: none; box-shadow: var(--sh-1); } }

/* Grands écrans : le contenu respire sans s'étirer */
@media (min-width: 1600px) { :root { --contenu-max: 1360px; } }
@media (max-width: 1280px) { .grille--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Tablette (600 à 1023 px) : rail d'icônes */
@media (min-width: 600px) and (max-width: 1023px) {
  .shell { grid-template-columns: var(--sidebar-w-reduit) minmax(0, 1fr); }
  .sidebar { padding: var(--s-4) var(--s-2); align-items: stretch; }
  .sidebar .nav-item span, .sidebar .nav-group__titre, .sidebar__brand div, .sidebar .nav-item .badge, .sidebar .nav-item .pastille { display: none; }
  .sidebar .nav-item { justify-content: center; padding: 0; position: relative; }
  .sidebar__brand { justify-content: center; padding: var(--s-2) 0 var(--s-3); }
  .nav-group + .nav-group { border-top: 1px solid var(--border); padding-top: var(--s-2); }
  .topbar { padding: 0 var(--s-5); }
  .contenu { padding: var(--s-5); }
  .grille--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Téléphone (< 600 px) : navigation en bas, une colonne */
@media (max-width: 599px) {
  .shell, .shell[data-menu="reduit"] { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar { height: calc(56px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(var(--s-4), env(safe-area-inset-right)) 0 max(var(--s-4), env(safe-area-inset-left)); }
  .recherche { display: none; }
  .contenu { padding: var(--s-4) max(var(--s-4), env(safe-area-inset-right)) calc(88px + env(safe-area-inset-bottom)) max(var(--s-4), env(safe-area-inset-left)); gap: var(--s-5); }
  h1 { font-size: 26px; }
  .page-entete { align-items: stretch; }
  .page-entete > .rangee { width: 100%; }
  .page-entete > .rangee .btn { flex: 1; }
  .grille--2, .grille--3, .formulaire--2 { grid-template-columns: minmax(0, 1fr); }
  .grille--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
  .grille--4 .carte { padding: var(--s-4); }
  .stat__valeur { font-size: 24px; }
  .carte { padding: var(--s-4); }
  .onglets { overflow-x: auto; scrollbar-width: none; }
  .onglet { white-space: nowrap; }

  /* Tableaux : chaque rangée devient une carte ; <td data-etiquette="Nom"> donne le titre de la valeur */
  .tableau--cartes thead { display: none; }
  .tableau--cartes, .tableau--cartes tbody, .tableau--cartes tr, .tableau--cartes td { display: block; width: 100%; }
  .tableau--cartes tr { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border); }
  .tableau--cartes td { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); padding: var(--s-2) 0; border: 0; text-align: right; }
  .tableau--cartes td::before { content: attr(data-etiquette); color: var(--text-3); font-size: var(--t-sm); font-weight: 500; text-align: left; }
  .tableau--cartes td:first-child { display: block; text-align: left; }
  .tableau--cartes td:first-child::before { display: none; }
  .tableau--cartes .num { text-align: right; }

  /* Fenêtres : feuille ancrée en bas, à portée du pouce */
  dialog.fenetre { width: 100%; max-width: none; margin: auto 0 0; border-radius: var(--r-xl) var(--r-xl) 0 0; max-height: 92vh; max-height: 92dvh; padding-bottom: env(safe-area-inset-bottom); }
  .fenetre__pied { flex-direction: column-reverse; border-radius: 0; }
  .fenetre__pied .btn { width: 100%; }
  .avis { left: var(--s-4); right: var(--s-4); bottom: calc(80px + env(safe-area-inset-bottom)); }

  /* Barre d'onglets du bas (4 destinations + « Plus ») */
  .onglets-bas { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: var(--s-1) max(var(--s-2), env(safe-area-inset-right)) calc(var(--s-1) + env(safe-area-inset-bottom)) max(var(--s-2), env(safe-area-inset-left)); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(1.4) blur(14px); border-top: 1px solid var(--border); }
  .onglet-bas { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; padding: var(--s-1); border-radius: var(--r-md); color: var(--text-3); font-size: 11px; font-weight: 600; text-decoration: none; background: none; border: 0; cursor: pointer; font-family: inherit; }
  .onglet-bas .icon { width: 24px; height: 24px; }
  .onglet-bas[aria-current="page"] { color: var(--accent); }
  .onglet-bas[aria-current="page"] .icon { stroke-width: 2.1; }
}

/* Téléphone tenu en paysage : peu de hauteur, on compacte */
@media (max-width: 899px) and (max-height: 480px) and (orientation: landscape) {
  .topbar { height: calc(44px + env(safe-area-inset-top)); }
  .onglet-bas { min-height: 44px; flex-direction: row; gap: var(--s-2); }
  .contenu { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media print { .sidebar, .topbar, .avis, .onglets-bas { display: none !important; } .shell { display: block; } body { background: #fff; } .carte { box-shadow: none; } }
