/* MDTED — coque : barre haute, menu latéral, canevas, pied de page.
   Le menu est un seul composant à trois volumes : 256 px libellé, 72 px
   d'icônes sous 1120 px ou sur préférence « réduit », tiroir hors-canvas
   sous 860 px. Sans JavaScript, le tiroir reste une pile atteignable. */

/* ===================== cadre =====================
   Sur grand écran, l'application occupe la fenêtre : seul le canevas
   défile. Le menu latéral reste fixe, sans barre de défilement. */
.app { min-height: 100vh; display: flex; flex-direction: column; }
@supports (height: 100dvh) { .app { min-height: 100dvh; } }
@media (min-width: 861px) {
  body[data-shell="app"] { overflow: hidden; height: 100vh; }
  body[data-shell="app"] .app { height: 100%; min-height: 0; overflow: hidden; }
  body[data-shell="app"] .app-body { flex: 1; min-height: 0; overflow: hidden; }
  body[data-shell="app"] .sidebar { height: 100%; overflow: hidden; }
  body[data-shell="app"] .canvas {
    flex: 1; min-width: 0; min-height: 0;
    overflow-y: auto; overscroll-behavior: contain;
  }
  body[data-shell="app"] .footer-meta { flex-shrink: 0; }
  @supports (height: 100dvh) {
    body[data-shell="app"] { height: 100dvh; }
  }
}

.appbar {
  height: 58px; flex-shrink: 0;
  display: flex; align-items: center; gap: var(--s-4);
  padding: 0 var(--s-5);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: var(--z-appbar);
}
.appbar-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text-1); flex-shrink: 0;
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(140deg, var(--accent), var(--accent-bright));
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-on-accent); font-weight: 800; font-size: var(--text-2xs); letter-spacing: .02em;
}
.brand-word { font-weight: 800; letter-spacing: .04em; font-size: var(--text-lg); }
.appbar-spacer { flex: 1; }

/* ===================== fil d'Ariane ===================== */
.breadcrumb { min-width: 0; }
.breadcrumb ol {
  list-style: none; margin: 0; padding: 0;
  display: flex; align-items: center; gap: 6px;
  font-size: var(--text-xs); color: var(--text-2);
  overflow: hidden; white-space: nowrap;
}
.breadcrumb li { display: flex; align-items: center; gap: 6px; min-width: 0; }
.breadcrumb li + li::before { content: "›"; color: var(--text-3); }
.breadcrumb a { color: var(--text-2); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent-strong); text-decoration: underline; }
.breadcrumb li:last-child span {
  color: var(--text-1); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis;
}

/* ===================== préférences d'affichage ===================== */
.appbar-prefs { display: flex; align-items: center; gap: 2px; }
.pref-form { display: flex; }
.shell-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--control-h); height: var(--control-h);
  border: 1px solid transparent; border-radius: var(--control-radius);
  background: none; color: var(--text-2); cursor: pointer; padding: 0;
  transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease),
    border-color var(--motion-fast) var(--ease);
}
.shell-btn:hover { background: var(--accent-soft); color: var(--accent-strong); border-color: var(--accent-line); }
.btn-nav, .btn-nav-close { display: none; }

/* ===================== aide ===================== */
.appbar-help {
  display: inline-flex; align-items: center; gap: 7px;
  height: var(--control-h); padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius-pill);
  color: var(--text-2); text-decoration: none;
  font-size: var(--text-sm); font-weight: 600;
  transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease),
    border-color var(--motion-fast) var(--ease);
}
.appbar-help:hover { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-strong); }

/* ===================== menu de compte ===================== */
.appbar-user { position: relative; }
.user-button {
  display: flex; align-items: center; gap: 9px;
  height: var(--control-h);
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius-pill); padding: 3px 12px 3px 3px;
  cursor: pointer; font: inherit; color: var(--text-1);
  transition: background var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}
.user-button:hover { background: var(--surface-2); border-color: var(--line-strong); }
.user-badge {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--text-2xs); font-weight: 800;
}
.user-name { font-size: var(--text-sm); font-weight: 600; }
.user-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 232px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-menu); padding: 6px; z-index: var(--z-menu);
}
.user-menu.open { display: block; }
.user-menu a {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text-1); text-decoration: none; font-size: var(--text-sm);
}
.user-menu a:hover { background: var(--accent-soft); color: var(--accent-strong); }
.user-menu .menu-label {
  font-size: var(--text-2xs); font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-3); padding: 10px 10px 4px;
}
.user-menu .menu-rule { height: 1px; background: var(--line); margin: 6px 4px; }

/* ===================== corps et menu latéral =====================
   Sur grand écran, seul le canevas défile : le menu reste figé dans
   la hauteur utile, sans barre de défilement visible. */
.app-body { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 256px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: var(--s-3) var(--s-2) var(--s-4);
  gap: 0;
  align-self: stretch;
  height: auto;
  overflow: hidden;
  z-index: var(--z-sidebar);
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--s-2) 6px; flex-shrink: 0;
}
.sidebar-caption {
  font-size: var(--text-2xs); font-weight: 700; letter-spacing: .14em;
  text-transform: uppercase; color: var(--text-3);
}
.nav-groups {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 0;
  flex: 1; min-height: 0;
  /* Le menu défile quand il dépasse la hauteur utile : sans cela, les
     dernières entrées sont purement et simplement coupées. */
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.nav-groups::-webkit-scrollbar { width: 8px; }
.nav-groups::-webkit-scrollbar-track { background: transparent; }
.nav-groups::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 8px;
  border: 2px solid transparent; background-clip: content-box;
}
.nav-groups::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }
.nav-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.nav-group + .nav-group { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
/* Sans intertitre, la première entrée collerait au repère « Navigation » :
   elle reprend le souffle que le titre lui donnait. */
.nav-group-bare { margin-top: 4px; }
.nav-group-label {
  margin: 0 0 4px; padding: 0 var(--s-2);
  font-size: var(--text-2xs); font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-3);
}
.nav-item {
  display: flex; align-items: center; gap: 8px;
  min-height: 36px; padding: 4px 6px;
  border-radius: 8px;
  color: var(--text-2); text-decoration: none;
  font-size: var(--text-sm); font-weight: 600; line-height: 1.2;
  transition: background var(--motion-base) var(--ease), color var(--motion-base) var(--ease);
}
.nav-item:hover { background: var(--surface-2); color: var(--text-1); }
.nav-item.is-active {
  background: var(--accent-soft); color: var(--accent-strong);
  font-weight: 700;
}
.nav-icon {
  width: 28px; height: 28px; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; color: var(--text-2);
  background: var(--surface-2);
}
.nav-item:hover .nav-icon { color: var(--accent-strong); background: var(--accent-soft); }
.nav-item.is-active .nav-icon { background: var(--accent); color: var(--text-on-accent); }
.nav-icon .ico { width: 15px; height: 15px; }
.nav-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-scrim { display: none; }
.sidebar-foot { display: none; }
html:not(.js) .sidebar-foot {
  display: grid; gap: var(--nav-gap);
  margin-top: var(--s-3); padding-top: var(--s-3);
  border-top: 1px solid var(--line);
}

/* ---- volume réduit : 72 px d'icônes, au-dessus du seuil du tiroir ---- */
@media (min-width: 861px) {
  [data-nav="mini"] .sidebar { width: 72px; padding: var(--s-3) var(--s-2); }
  [data-nav="mini"] .sidebar-head,
  [data-nav="mini"] .nav-group-label { display: none; }
  [data-nav="mini"] .nav-group + .nav-group { margin-top: var(--s-2); padding-top: 0; border-top: 0; }
  [data-nav="mini"] .nav-item { justify-content: center; padding: 6px; }
  [data-nav="mini"] .nav-item.is-active { background: transparent; }
  [data-nav="mini"] .nav-item.is-active .nav-icon { background: var(--accent); color: var(--text-on-accent); }
  /* Le libellé reste dans l'arbre accessible (il nomme le lien) mais sort du
     flux : à 72 px, un texte visible déborderait sur le canevas. */
  [data-nav="mini"] .nav-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}

/* ---- largeur de l'espace de travail, sans jamais perdre les libellés ----
   Une bascule automatique en icônes seules faisait disparaître les noms de
   page entre 861 et 1120 px sans que personne ne l'ait demandé : on ne
   comprend pas ce qu'on ne nomme plus. Le rail se resserre, le texte reste.
   Le volume réduit demeure un choix, matérialisé par le bouton de bascule. */
@media (min-width: 861px) and (max-width: 1120px) {
  .sidebar { width: 224px; }
}
@media (max-width: 860px) {
  /* Le menu est un tiroir : la bascule de volume n'a plus rien à régler. */
  .btn-navmode { display: none; }
}

/* ---- tiroir et repli sans script ---- */
@media (max-width: 860px) {
  :root { --control-h: 44px; }
  .appbar { gap: var(--s-2); padding: 0 var(--s-3); }
  .breadcrumb { display: none; }

  html.js .btn-nav { display: inline-flex; }
  html.js .sidebar {
    position: fixed; inset: 58px auto 0 0; width: min(300px, 84vw);
    height: calc(100vh - 58px); padding: var(--s-4) var(--s-3);
    transform: translateX(-100%); visibility: hidden;
    overflow: hidden;
    transition: transform var(--motion-base) var(--ease), visibility 0s var(--motion-base);
    box-shadow: var(--shadow-menu);
  }
  @supports (height: 100dvh) {
    html.js .sidebar { height: calc(100dvh - 58px); }
  }
  /* À l'ouverture, `visibility` bascule sans délai : le tiroir est
     immédiatement focalisable. À la fermeture il attend la fin du glissement. */
  html.js .sidebar.is-open {
    transform: none; visibility: visible;
    transition: transform var(--motion-base) var(--ease), visibility 0s;
  }
  html.js .sidebar-head { display: flex; }
  html.js .btn-nav-close { display: inline-flex; }
  html.js .nav-scrim {
    display: block; position: fixed; inset: 58px 0 0; z-index: var(--z-scrim);
    background: rgba(20, 22, 26, .42); opacity: 0; pointer-events: none;
    transition: opacity var(--motion-base) var(--ease);
  }
  html.js .nav-scrim.is-open { opacity: 1; pointer-events: auto; }

  /* Sans script la bascule d'icônes n'a pas de sens : on garde le menu
     libellé, empilé au-dessus du contenu et donc atteignable au clavier. */
  html:not(.js) .app-body { flex-direction: column; }
  html:not(.js) .sidebar {
    position: static; width: auto; height: auto;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  html:not(.js) .nav-groups { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  html:not(.js) .nav-group { grid-column: 1 / -1; }
}

/* Les cibles tactiles passent à 44 px ; la règle des très petits écrans vient
   après pour que la barre tienne quand la largeur manque vraiment. */
@media (hover: none), (pointer: coarse) {
  :root { --control-h: 44px; }
  .nav-item { min-height: 44px; }
}

@media (max-width: 480px) {
  /* 24x24 reste la cible minimale AA (SC 2.5.8) : on peut réduire sans
     tomber sous la norme quand la barre manque de place. L'aide disparaît
     parce que son destinataire est déjà dans le menu de compte. */
  :root { --control-h: 38px; }
  .appbar { gap: 4px; padding: 0 var(--s-2); }
  .brand-word, .appbar-help-text, .user-name, .appbar-help { display: none; }
}

/* ===================== canevas ===================== */
.canvas {
  flex: 1; min-width: 0; padding: var(--pad-page);
  /* Un jeton technique sans espace (nom de livrable, empreinte, requête) ne
     doit jamais élargir la page : il se casse quand il dépasse la ligne. */
  overflow-wrap: break-word;
}
/* Les retraits responsives viennent après la règle de base : déclarés avant,
   ils étaient battus par elle à spécificité égale. */
@media (max-width: 860px) { .canvas { padding: var(--s-4) var(--s-4) var(--s-8); } }
@media (max-width: 480px) { .canvas { padding: var(--s-3) var(--s-3) var(--s-6); } }
.canvas-inner { max-width: 1320px; margin: 0 auto; }
.footer-meta {
  display: flex; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap;
  padding: 14px var(--s-8) 18px; color: var(--text-3); font-size: var(--text-xs);
}

/* ===================== en-têtes de page ===================== */
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--s-4); margin-bottom: var(--s-5); flex-wrap: wrap;
}
.page-lead { color: var(--text-2); margin: 6px 0 0; font-size: var(--text-md); max-width: 70ch; }
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); margin-bottom: var(--s-5); flex-wrap: wrap;
}

/* ===================== impression ===================== */
@media print {
  .appbar, .sidebar, .nav-scrim, .skip-link, .footer-meta, .live-region { display: none; }
  .canvas { padding: 0; }
}
