/* Refonte B « Raffinée & Structurée » : structure commune des trois espaces.
   Le menu latéral occupe toute la hauteur à gauche (logo en tête) ; le bandeau et le contenu sont à sa droite.
   Le bandeau est hors de #app : #app garde ses largeurs habituelles (.app.wide, .wide-plan…). */

.app-header {
  background: var(--header-bg);
  border-bottom: 1px solid var(--line-strong);
  /* iPhone (application installée, barre d'état translucide) : le lin du bandeau monte jusque sous l'encoche */
  margin: calc(-1 * env(safe-area-inset-top)) calc(-1 * env(safe-area-inset-right)) 0 calc(-1 * env(safe-area-inset-left));
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
.app-header[hidden] { display: none; }
.hd-inner {
  display: grid; grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr); grid-template-areas: "brand switch end";
  align-items: center; gap: 8px 16px; min-height: 76px; padding: 8px 20px;
}
.hd-brand { grid-area: brand; display: flex; align-items: center; gap: 8px; min-width: 0; }
.hd-brand picture, .hd-brand img { display: block; }
.hd-brand img { height: 30px; width: auto; max-width: 100%; }
/* Avec le menu latéral, le logo est en tête du volet : le bandeau ne le répète pas (sauf sur téléphone, où le volet est un tiroir) */
body.has-side .hd-brand picture { display: none; }
.hd-switch { grid-area: switch; justify-self: center; min-width: 0; }
.hd-end { grid-area: end; display: flex; align-items: center; gap: 8px; justify-self: end; }
.hd-tools { display: flex; align-items: center; gap: 6px; }

/* Boutons-icônes du bandeau : discrets sur le lin, la pastille rouge reste la même (.bell-count) */
.app-header .bell, .app-header .hd-settings, .app-header .hd-tools > .btn { background: transparent; border-color: transparent; min-height: 40px; }
.app-header .bell:hover, .app-header .hd-settings:hover, .app-header .hd-tools > .btn:hover:not(:disabled) { background: rgb(255 255 255 / .45); border-color: var(--line-strong); }
.app-header .bell.on, .app-header .hd-settings.on { background: rgb(255 255 255 / .45); border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }

/* Sélecteur d'espace : même lin que le bandeau, survol discret, espace ouvert en vert profond (sysadmin.css garde ses règles ailleurs) */
.app-header .space-switch, .sn-top .space-switch { background: transparent; border: 1px solid var(--line-strong); border-radius: var(--radius-pill); padding: 3px; gap: 2px; }
.app-header .space-btn, .sn-top .space-btn { background: transparent; color: var(--ink); border: 0 !important; border-radius: var(--radius-pill); min-height: 36px; padding: 6px 16px; }
.app-header .space-btn:hover:not([aria-pressed=true]), .sn-top .space-btn:hover:not([aria-pressed=true]) { background: rgb(255 255 255 / .45); }
.app-header .space-btn[aria-pressed=true], .sn-top .space-btn[aria-pressed=true] { background: var(--brand); color: var(--on-brand); }
.app-header .space-btn:focus-visible, .sn-top .space-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- menu utilisateur ---------- */
.um { position: relative; }
.um-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 4px 8px 4px 4px; font: inherit; color: var(--ink);
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-pill); cursor: pointer; position: relative;
}
.um-btn:hover, .um-btn[aria-expanded=true] { background: rgb(255 255 255 / .6); border-color: var(--line-strong); }
.um-avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: .8rem; letter-spacing: .02em;
}
.um-name { font-weight: 600; font-size: .92rem; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.um-chev { display: inline-flex; color: var(--muted); }
.um-chev .nav-ico { width: 16px; height: 16px; stroke-width: 2; }
.um-dot { display: none; position: absolute; top: 2px; left: 26px; width: 10px; height: 10px; border-radius: 50%; background: var(--badge); border: 2px solid var(--header-bg); }
.um-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 250px; max-width: min(320px, calc(100vw - 24px));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-2); padding: 6px;
}
.um-panel[hidden] { display: none; }
.um-head { padding: 10px 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.um-head strong { display: block; overflow-wrap: anywhere; }
.um-head span { display: block; color: var(--muted); font-size: .85rem; margin-top: 2px; }
.um-group { border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 6px; }
.um-item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 8px 10px; position: relative;
  font: inherit; font-weight: 500; color: var(--ink); text-align: left; background: none; border: 0; border-radius: var(--radius-sm); cursor: pointer;
}
.um-item:hover { background: var(--surface-2); }
.um-item .nav-ico { width: 20px; height: 20px; color: var(--muted); }
.um-item .bell-count { position: static; margin-left: auto; }
.um-item.um-logout { color: var(--bad); }
.um-item.um-logout .nav-ico { color: var(--bad); }
.um-only-phone, .um-only-tablet { display: none; }
.um-phone-group { display: none; }

/* ---------- barre d'établissement : fine barre en haut de la zone centrale ---------- */
/* Même sélecteur, même fonctionnement (en-tête X-Site) : seulement plus discret. La teinte de la crèche choisie reste (site-theme.js). */
.site-bar { background: var(--bg); border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 6px 2px; margin: -4px 0 14px; box-shadow: none; }
.site-bar label { font-weight: 600; font-size: .92rem; color: var(--muted); }
.site-bar select { min-height: 36px; max-width: 360px; }
.site-bar.on { border-radius: var(--radius); border: 1px solid var(--line-strong); padding-inline: 12px; }
@media (pointer: coarse) { .site-bar select { min-height: 44px; } }

/* ---------- structure : menu latéral sur toute la hauteur, bandeau et contenu à sa droite ---------- */
.app-shell { display: flex; align-items: flex-start; min-height: 100vh; min-height: 100dvh; }
.app-column { flex: 1 1 auto; min-width: 0; width: 100%; }
.app-frame > .app { min-width: 0; }

/* ---------- menu latéral (side-nav.js) : deux niveaux au plus ---------- */
.side-nav {
  position: sticky; top: 0; flex: none; width: 264px; height: 100vh; height: 100dvh; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 6px; padding: 0 10px 14px;
  padding-top: env(safe-area-inset-top);
  background: var(--sidebar-bg); border-right: 1px solid var(--line-strong);
}
.side-nav[hidden] { display: none; }
/* Logo Little Bee original, centré en tête du volet, aligné sur la hauteur du bandeau */
.sn-brand { display: flex; align-items: center; justify-content: center; min-height: 76px; padding: 10px 8px; margin: 0 -10px 6px; border-bottom: 1px solid var(--line-strong); }
.sn-logo { display: block; width: auto; height: 44px; max-width: 100%; }
.sn-logo-mini { display: none; width: 40px; height: 40px; border-radius: 10px; }
.sn-top { display: none; }
.sn-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.sn-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 42px; padding: 8px 12px; position: relative;
  font: inherit; font-weight: 500; font-size: .95rem; color: var(--ink); text-align: left; background: transparent;
  border: 0; border-radius: var(--radius-pill); cursor: pointer;
}
.sn-item:hover { background: var(--brand-soft); }
/* Écran ouvert sans sous-rubrique : pilule verte ; rubrique qui contient l'écran ouvert : texte appuyé, la sous-rubrique porte le vert */
.sn-item[aria-current=page] { background: var(--brand); color: var(--on-brand); font-weight: 600; }
.sn-item.sn-has-current { font-weight: 700; }
.sn-ico { position: relative; display: inline-flex; flex: none; }
.sn-ico .nav-ico { width: 22px; height: 22px; color: var(--brand); }
.sn-item[aria-current=page] .nav-ico { color: var(--on-brand); }
.sn-item[aria-current=page] .nav-ico .acc { fill: var(--honey); }
.sn-lbl { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sn-chev { display: inline-flex; color: var(--muted); flex: none; }
.sn-chev .nav-ico { width: 16px; height: 16px; stroke-width: 2; transition: transform .15s; }
.sn-parent[aria-expanded=true] .sn-chev .nav-ico { transform: rotate(180deg); }
.sn-count { min-width: 20px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--badge); color: #fff; font-size: .75rem; font-weight: 700; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums; }
.sn-count[hidden] { display: none; }
.sn-parent[aria-expanded=true] > .sn-count, .sn-parent[aria-expanded=true] > .help-count, .sn-parent[aria-expanded=true] > .lib-count { display: none; }   /* dépliée : les pastilles sont sur ses sous-rubriques */
.sn-dot { display: none; position: absolute; top: -3px; right: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--badge); border: 2px solid var(--sidebar-bg); }
/* Sous-rubriques : légèrement décalées, l'écran ouvert en vert profond */
.sn-sub { list-style: none; margin: 2px 0 6px; padding: 0 0 0 22px; display: flex; flex-direction: column; gap: 1px; }
.sn-sub[hidden] { display: none; }
.sn-subitem {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 38px; padding: 6px 12px 6px 22px; position: relative;
  font: inherit; font-size: .9rem; font-weight: 500; color: var(--ink-2, var(--ink)); text-align: left; background: transparent;
  border: 0; border-left: 1px solid var(--line-strong); border-radius: 0 var(--radius-pill) var(--radius-pill) 0; cursor: pointer;
}
.sn-subitem:hover { background: var(--brand-soft); }
.sn-subitem[aria-current=page] { background: var(--brand); color: var(--on-brand); font-weight: 600; border-left-color: var(--brand); }
.sn-subitem .sn-count { flex: none; }
/* groupe dans une rubrique (Demandes › Messagerie) : intitulé en gras discret, entrées en retrait ; replié, seule la pastille reste */
.sn-grouphead { font-weight: 600; }
.sn-grouphead.sn-has-current { color: var(--brand-ink, inherit); }
.sn-grouphead[aria-expanded=true] .sn-chev .nav-ico { transform: rotate(180deg); }
.sn-grouphead[aria-expanded=true] > .sn-count, .sn-grouphead[aria-expanded=true] > .help-count { display: none; }   /* ouvert : la pastille est sur son entrée */
.sn-item.sn-parent, .sn-grouphead { cursor: pointer; }
.sn-item.sn-parent.sn-has-current[aria-expanded=false], .sn-grouphead.sn-has-current[aria-expanded=false] { background: var(--brand-soft, rgba(62,77,62,.10)); }   /* refermée mais contient l'écran ouvert : repérable */
.sn-sub2 { list-style: none; margin: 1px 0 4px; padding: 0 0 0 16px; display: flex; flex-direction: column; gap: 1px; }
.sn-subitem2 { min-height: 34px; font-size: .88rem; }
.sn-sub2[hidden] { display: none; }
.sn-toggle {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none; color: var(--ink);
  background: transparent; border: 1px solid transparent; border-radius: var(--radius); cursor: pointer;
}
.sn-toggle:hover { background: rgb(255 255 255 / .6); border-color: var(--line-strong); }
.sn-toggle .nav-ico { width: 22px; height: 22px; }
.sn-scrim { position: fixed; inset: 0; z-index: 70; background: rgb(32 42 37 / .38); }
.sn-scrim[hidden] { display: none; }

/* Replié (ordinateur au choix, tablette par défaut) : icônes seules, l'abeille en tête, pastille réduite à un point rouge */
body.side-collapsed .side-nav { width: 64px; padding-inline: 8px; }
body.side-collapsed .sn-brand { margin-inline: -8px; padding-inline: 4px; }
body.side-collapsed .sn-logo { display: none; }
body.side-collapsed .sn-logo-mini { display: block; }
body.side-collapsed .sn-item { justify-content: center; padding-inline: 0; }
body.side-collapsed .side-nav .sn-lbl, body.side-collapsed .side-nav .sn-count, body.side-collapsed .side-nav .sn-chev,
body.side-collapsed .side-nav .help-count, body.side-collapsed .side-nav .lib-count { display: none; }
body.side-collapsed .sn-sub { display: none; }
body.side-collapsed .sn-item:has(.sn-count:not([hidden]), .help-count:not([hidden]), .lib-count:not([hidden])) .sn-dot { display: block; }
body.side-collapsed .sn-item[aria-current=page] .sn-dot { border-color: var(--brand); }

/* ---------- largeurs ---------- */
/* Tablette et petit ordinateur : l'export et les outils marqués « tablet » passent dans le menu utilisateur */
@media (max-width: 1023px) {
  .hd-inner { padding: 6px 14px; gap: 6px 10px; }
  .hd-collapse-tablet { display: none !important; }
  .um-only-tablet { display: flex; }
  .um-phone-group:has(.um-only-tablet) { display: block; }
  .app-header .space-btn { padding-inline: 10px; }
  /* le sélecteur d'espace passe sur une seconde ligne, centré, pour ne jamais chevaucher les boutons du bandeau */
  .hd-inner { grid-template-columns: auto 1fr; grid-template-areas: "brand end" "switch switch"; }
  .hd-switch { justify-self: stretch; display: flex; justify-content: center; }
}
@media (max-width: 760px) { .um-name, .um-chev { display: none; } .um-btn { padding: 4px; } }
@media (min-width: 1024px) { .hd-brand img { height: 40px; } }
/* Téléphone : logo compact dans le bandeau, cloche et menu utilisateur ; Messagerie, « ? » et Paramètres dans le menu utilisateur ;
   le menu latéral devient un tiroir par-dessus le contenu, avec le sélecteur d'espace en tête */
@media (max-width: 640px) {
  .hd-inner { grid-template-columns: auto 1fr; grid-template-areas: "brand end" "switch switch"; padding: 6px 12px 8px; gap: 6px 8px; min-height: 56px; }
  body.has-side .hd-brand picture { display: block; }
  .hd-brand img { height: 26px; }
  .hd-collapse-phone { display: none !important; }
  .um-only-phone { display: flex; }
  .um-phone-group { display: block; }
  .um:has(.um-only-phone .bell-count:not([hidden])) .um-dot,
  .um:has(.um-only-tablet .bell-count:not([hidden])) .um-dot { display: block; }
  .hd-switch { justify-self: stretch; }
  .hd-switch .space-switch { display: flex; width: 100%; }
  .hd-switch .space-btn { flex: 1 1 0; min-width: 0; padding-inline: 6px; }
  body.has-side .hd-switch { display: none; }
  body.has-side .hd-inner { grid-template-areas: "brand end"; }

  .side-nav {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 80; width: min(300px, 86vw); height: auto;
    padding: env(safe-area-inset-top) 12px calc(12px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow-2); visibility: hidden;
  }
  body.side-open .side-nav { transform: none; visibility: visible; }
  .sn-brand { min-height: 60px; margin-inline: -12px; }
  .sn-logo { height: 36px; }
  body.side-collapsed .side-nav { width: min(300px, 86vw); padding-inline: 12px; }
  body.side-collapsed .sn-logo { display: block; }
  body.side-collapsed .sn-logo-mini { display: none; }
  body.side-collapsed .side-nav .sn-lbl, body.side-collapsed .side-nav .sn-count, body.side-collapsed .side-nav .sn-chev { display: revert; }
  body.side-collapsed .sn-sub { display: flex; }
  body.side-collapsed .sn-sub[hidden] { display: none; }
  body.side-collapsed .sn-item { justify-content: flex-start; padding-inline: 12px; }
  body.side-collapsed .sn-item .sn-dot { display: none !important; }
  .sn-top { display: block; padding: 2px 2px 10px; border-bottom: 1px solid var(--line-strong); margin-bottom: 4px; }
  .sn-top .space-switch { display: flex; width: 100%; }
  .sn-top .space-btn { flex: 1 1 auto; min-width: 0; padding-inline: 6px; font-size: .82rem; }
  .sn-item { min-height: 48px; font-size: 1rem; }
  .sn-subitem { min-height: 44px; font-size: .95rem; }
  /* une pastille dans le menu fermé : point rouge sur le bouton du menu */
  .sn-toggle { position: relative; }
  body:has(.side-nav .sn-count:not([hidden])) .sn-toggle::after { content: ""; position: absolute; top: 4px; right: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--badge); border: 2px solid var(--header-bg); }
}
@media (prefers-reduced-motion: reduce) { .side-nav, .sn-chev .nav-ico { transition: none; } }
@media (max-width: 1180px) and (min-width: 1024px) { .hd-settings .hd-txt { display: none; } }

@media print { .app-header, .side-nav, .sn-scrim { display: none !important; } }

/* Centre d'aide : message d'orientation sous le titre de la FAQ (décision du 3/11, à retirer après validation de Pierre) */
.help-moved { margin-top: 6px; color: var(--muted); font-size: .92rem; }
.help-moved .btn-link { min-height: 0; padding: 0 2px; color: var(--brand); font-weight: 600; }
/* Largeur d'affichage (21/11/2026) : tablette avec le menu latéral déplié, le bandeau n'a plus que ~550 px.
   Les libellés « Paramètres » et le nom passent en icône seule pour que les boutons ne chevauchent pas le bouton du menu. */
@media (max-width: 1023px) and (min-width: 761px) {
  body.has-side:not(.side-collapsed) .hd-settings .hd-txt, body.has-side:not(.side-collapsed) .um-name, body.has-side:not(.side-collapsed) .um-chev { display: none; }
  .hd-end { min-width: 0; }
}
