/* shell.css — coque de l'application (lot 3a) : barre latérale, tiroir, barre basse, carte utilisateur.
   Cible : plan/ihm/maquettes/01-liste-ao.html (sections 3.1, « coque commune », complément responsive v1.1).
   Consomme les variables de tokens.css (mêmes noms que maquettes/_tokens.css).
   Chargé après styles.css et responsive.css : remplace #navbar / .nav-link (GR-1, GR-R1, GR-14 supprimés).
   Dimensions en rem / jetons (1rem = 16 px, html à 100 %) : suivent le zoom texte. Restent en px : bordures 1 px, ombres, media queries. */

/* ─── Variables de la coque (sur :root : body, html et #toast-container, hors #app-shell, les consomment) ─── */
:root {
    --touch: 2.75rem;
    --topbar-h: 3.5rem;
    --bottom-nav-h: 3.5rem;
    --sh-control: var(--control-h);
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.hidden { display: none !important; }
/* Tiroir ouvert : la page en arrière-plan ne défile plus */
body:has(#app-shell[data-nav="open"]) { overflow: hidden; }

/* ─── Accessibilité : lien d'évitement ─────────────────────── */
.skip-link {
    position: absolute; left: 0.5rem; top: 0.5rem; z-index: var(--z-toast, 60);
    padding: 0.5rem 0.75rem; background: var(--bg-elevated); color: var(--accent-text);
    border-radius: var(--radius-md); box-shadow: var(--shadow-2);
    transform: translateY(-200%); text-decoration: none; min-height: 2.75rem; display: flex; align-items: center;
}
.skip-link:focus { transform: none; }
#main:focus, #main-content:focus { outline: none; }
#view-container h1:focus, #view-container h2:focus { outline: none; }
#app-shell :focus-visible { outline: var(--focus-width, 2px) solid var(--focus-ring); outline-offset: var(--focus-offset, 2px); }
#app-shell .sidebar :focus-visible, #app-shell .bottom-nav :focus-visible { outline-offset: -2px; }

#app-shell .icon {
    width: 1rem; height: 1rem; flex: none; fill: none; stroke: currentColor;
    stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
#app-shell .sr-only {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ─── 3.1 Grille de la coque ───────────────────────────────── */
#app-shell.app {
    display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh;
    --sb: calc(var(--sidebar-w) - 1px);
    background: linear-gradient(to right, var(--bg-subtle) var(--sb), var(--border) var(--sb), var(--border) calc(var(--sb) + 1px), var(--bg) calc(var(--sb) + 1px));
    font-size: var(--text-md); line-height: var(--leading-normal); color: var(--text);
}
#app-shell.app[data-sidebar="collapsed"] { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); --sb: calc(var(--sidebar-w-collapsed) - 1px); }
#app-shell .app-content { background: var(--bg); min-width: 0; display: flex; flex-direction: column; min-height: 100dvh; }
#app-shell .app-content > .main { flex: 1; width: 100%; }

/* Contenu : remplace le centrage 1400 px de styles.css (#main-content) */
#app-shell #main-content {
    max-width: var(--content-max, 90rem); margin: 0 auto; width: 100%; min-width: 0;
    padding: 1.5rem 2rem 3rem; position: relative;
}
.topbar, .bottom-nav, .nav-backdrop { display: none; }

/* ─── Barre latérale ───────────────────────────────────────── */
#app-shell .sidebar {
    position: sticky; top: 0; height: 100dvh; overflow-y: auto; z-index: var(--z-sidebar, 20);
    display: flex; flex-direction: column; gap: var(--space-3);
    padding: var(--space-3) var(--space-2);
    background: var(--bg-subtle); border-right: 1px solid var(--border);
}
.sidebar-head { display: flex; align-items: center; gap: var(--space-1); }
.sidebar-brand {
    display: flex; align-items: center; gap: var(--space-2); height: 2.5rem; padding: 0 var(--space-2);
    color: var(--brand-ink, var(--text)); text-decoration: none; border-radius: var(--radius-sm);
}
.sidebar-head .sidebar-brand { flex: 1; min-width: 0; }
.sidebar-brand:hover { text-decoration: none; }
.sidebar-brand .logo { height: 1rem; width: auto; aspect-ratio: 141 / 46; flex: none; fill: none; }
.app-name { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-collapse, .sidebar-close {
    display: inline-grid; place-items: center; width: var(--sh-control); height: var(--sh-control); padding: 0;
    border: 0; border-radius: var(--radius-md); background: none; color: var(--text-2); cursor: pointer;
}
.sidebar-collapse:hover, .sidebar-close:hover { background: var(--bg-muted); color: var(--text); }
.sidebar-collapse .icon { transition: transform var(--duration, 150ms) var(--ease, ease); }
.sidebar-close { display: none; }

#nav-groups { display: flex; flex-direction: column; gap: var(--space-3); }
.nav-group { display: flex; flex-direction: column; gap: 0.0625rem; }
.nav-label { padding: var(--space-2) var(--space-2) var(--space-1); font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--text-3); }
.nav-item {
    position: relative; display: flex; align-items: center; gap: var(--space-3);
    width: 100%; height: var(--sh-control); padding: 0 var(--space-2); border: 0; border-radius: var(--radius-sm);
    background: none; font: inherit; font-size: var(--text-md); text-align: left; cursor: pointer;
    color: var(--text-2); font-weight: var(--weight-medium); text-decoration: none; white-space: nowrap;
}
.nav-item > .icon { box-sizing: content-box; width: 1.125rem; height: 1.125rem; padding: 0 0.0625rem; color: var(--text-2); }
.nav-item:hover { background: var(--bg-muted); color: var(--text); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--accent-bg); color: var(--accent-text); }
.nav-item[aria-current="page"] > .icon { color: inherit; }
.nav-kbd {
    margin-left: auto; display: inline-flex; align-items: center; height: 1.25rem; padding: 0 var(--space-1);
    font-size: var(--text-xs); color: var(--text-2); background: var(--bg-muted); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 0.125rem; padding-top: var(--space-2); border-top: 1px solid var(--border); }
#nav-admin { display: flex; flex-direction: column; }
#nav-admin:empty { display: none; }

.user-card {
    display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: 3rem;
    padding: var(--space-2) var(--space-2) var(--space-2) 0.25rem;
    border: 0; border-radius: var(--radius-sm); background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.user-card:hover, .user-card[aria-expanded="true"] { background: var(--bg-muted); }
.user-card > .icon { color: var(--text-2); margin-left: auto; }
#app-shell .avatar {
    display: inline-grid; place-items: center; flex: none; border-radius: 50%;
    width: 1.75rem; height: 1.75rem; font-size: 0.6875rem; font-weight: var(--weight-semibold);
    background: var(--accent-bg); color: var(--accent-text);
}
.user-meta { display: grid; flex: 1; min-width: 0; line-height: var(--leading-tight, 1.25); gap: 0.125rem; }
.user-name { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: var(--text-xs); color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-head, .mobile-only { display: none; }

/* Menu du compte */
.user-menu {
    position: fixed; z-index: var(--z-popover, 40); width: 14rem; padding: var(--space-1);
    background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border);
    border-radius: var(--radius-md); box-shadow: var(--shadow-2);
}
.user-menu[hidden] { display: none; }
.um-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-2) var(--space-3); margin-bottom: var(--space-1); border-bottom: 1px solid var(--border); }
.um-mail { font-size: var(--text-xs); color: var(--text-2); overflow-wrap: anywhere; }
.um-item {
    display: flex; align-items: center; gap: var(--space-2); width: 100%; min-height: 2.25rem; padding: 0 var(--space-2);
    border: 0; border-radius: var(--radius-sm); background: none; color: var(--text); font: inherit; font-size: var(--text-md);
    text-align: left; cursor: pointer;
}
.um-item:hover, .um-item:focus-visible { background: var(--bg-muted); }
.um-item .icon { color: var(--text-2); }
.user-menu :focus-visible { outline-offset: -2px; }

/* Infobulle (barre repliée) */
.tip {
    position: fixed; z-index: var(--z-toast, 60); padding: var(--space-1) var(--space-2); border-radius: var(--radius-sm);
    background: var(--text); color: var(--bg); font-size: var(--text-xs); font-weight: var(--weight-medium);
    white-space: nowrap; pointer-events: none; box-shadow: var(--shadow-1);
}
.tip[hidden] { display: none; }

/* ─── Barre repliée (56 px) : icônes seules, libellés lus ──── */
#app-shell.app[data-sidebar="collapsed"] :is(.nav-text, .nav-label, .app-name, .nav-kbd, .user-meta) {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
#app-shell.app[data-sidebar="collapsed"] .sidebar { padding-inline: 0.3125rem; }
#app-shell.app[data-sidebar="collapsed"] .sidebar .sidebar-brand { height: 2.75rem; flex: none; }
#app-shell.app[data-sidebar="collapsed"] .sidebar-head { flex-direction: column; gap: var(--space-2); }
#app-shell.app[data-sidebar="collapsed"] .sidebar .sidebar-brand { padding: 0; justify-content: center; width: 100%; }
#app-shell.app[data-sidebar="collapsed"] .sidebar .sidebar-brand .logo { width: 2.25rem; height: auto; }
#app-shell.app[data-sidebar="collapsed"] :is(.nav-item, .user-card) { justify-content: center; padding-inline: 0; }
#app-shell.app[data-sidebar="collapsed"] .user-card > .icon { display: none; }
#app-shell.app[data-sidebar="collapsed"] .nav-group + .nav-group { border-top: 1px solid var(--border); padding-top: var(--space-2); }
#app-shell.app[data-sidebar="collapsed"] .sidebar-collapse .icon { transform: scaleX(-1); }

/* ─── Tablette (641–1023 px) : repliée par défaut, dépliable ─ */
@media (min-width: 641px) and (max-width: 1023px) {
    #app-shell.app:not([data-sidebar="expanded"]) { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); --sb: calc(var(--sidebar-w-collapsed) - 1px); }
    #app-shell.app:not([data-sidebar="expanded"]) :is(.nav-text, .nav-label, .app-name, .nav-kbd, .user-meta) {
        position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
    }
    #app-shell.app:not([data-sidebar="expanded"]) .sidebar { padding-inline: 0.3125rem; }
    #app-shell.app:not([data-sidebar="expanded"]) .sidebar .sidebar-brand { height: 2.75rem; flex: none; }
    #app-shell.app:not([data-sidebar="expanded"]) .sidebar-head { flex-direction: column; gap: var(--space-2); }
    #app-shell.app:not([data-sidebar="expanded"]) .sidebar .sidebar-brand { padding: 0; justify-content: center; width: 100%; }
    #app-shell.app:not([data-sidebar="expanded"]) .sidebar .sidebar-brand .logo { width: 2.25rem; height: auto; }
    #app-shell.app:not([data-sidebar="expanded"]) :is(.nav-item, .user-card) { justify-content: center; padding-inline: 0; }
    #app-shell.app:not([data-sidebar="expanded"]) .user-card > .icon { display: none; }
    #app-shell.app:not([data-sidebar="expanded"]) .nav-group + .nav-group { border-top: 1px solid var(--border); padding-top: var(--space-2); }
    #app-shell.app:not([data-sidebar="expanded"]) .sidebar-collapse .icon { transform: scaleX(-1); }
    #app-shell #main-content { padding: 1.25rem 1.5rem 2.5rem; }
}

/* Cibles de 44 px sur tablette et écran tactile */
@media (max-width: 1023px), (pointer: coarse) {
    #app-shell { --sh-control: var(--touch); }
    .user-card { min-height: 3.25rem; }
    .um-item { min-height: 2.75rem; }
}

/* ─── Mobile (≤ 640 px) : barre supérieure, barre basse, tiroir ─ */
@media (max-width: 640px) {
    #app-shell { --sh-control: var(--touch); }
    #app-shell.app, #app-shell.app[data-sidebar] { display: block; background: var(--bg); }
    #app-shell #main-content { padding: var(--space-4) var(--space-4) var(--space-8); }

    /* En-tête de 56 px qui défile avec la page */
    .topbar {
        display: flex; align-items: center; gap: var(--space-2);
        height: var(--topbar-h); padding: 0 var(--space-2); background: var(--bg); border-bottom: 1px solid var(--border);
    }
    .topbar .sidebar-brand { flex: 1; height: var(--touch); min-width: 0; justify-content: flex-start; padding: 0 var(--space-2); }
    .topbar .avatar { width: 2rem; height: 2rem; font-size: 0.75rem; margin-right: var(--space-2); }

    /* Barre du bas, seule partie fixe */
    .bottom-nav {
        position: fixed; inset: auto 0 0 0; z-index: var(--z-sidebar, 20);
        display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
        height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--bg); border-top: 1px solid var(--border);
    }
    .bn-item {
        position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.125rem;
        min-width: var(--touch); min-height: var(--touch); padding: 0 0.125rem; border: 0; background: none; cursor: pointer;
        font: inherit; font-size: 0.6875rem; font-weight: var(--weight-medium); line-height: 1.2; color: var(--text-2); text-decoration: none;
    }
    .bn-item .icon { width: 1.25rem; height: 1.25rem; }
    .bn-item[aria-current="page"] { color: var(--accent-text); }
    .bn-item[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 2px; border-radius: 0 0 2px 2px; background: var(--accent-solid); }
    .bn-item:hover { text-decoration: none; }
    body { padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px)); }
    #app-shell .app-content { min-height: calc(100dvh - var(--bottom-nav-h) - env(safe-area-inset-bottom, 0px)); }
    html { scroll-padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 0.5rem); }
    #toast-container { bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 0.5rem); }

    /* Tiroir latéral « Plus » */
    #app-shell .sidebar {
        position: fixed; inset: 0 auto 0 0; width: min(18rem, 85vw); height: 100dvh; z-index: var(--z-modal, 50);
        transform: translateX(-100%); visibility: hidden; box-shadow: var(--shadow-2);
        transition: transform var(--duration, 150ms) var(--ease, ease), visibility 0s linear var(--duration, 150ms);
    }
    #app-shell.app[data-nav="open"] .sidebar { transform: none; visibility: visible; transition: transform var(--duration, 150ms) var(--ease, ease); }
    #app-shell.app .sidebar :is(.nav-text, .nav-label, .app-name, .nav-kbd, .user-meta) { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
    #app-shell.app .sidebar .nav-item { justify-content: flex-start; padding-inline: var(--space-2); height: var(--touch); }
    /* Contenu plus haut que l'écran : le tiroir défile, ses entrées ne rétrécissent jamais sous 44 px */
    #app-shell.app .sidebar { overflow-y: auto; overscroll-behavior: contain; }
    #app-shell.app .sidebar > * { flex-shrink: 0; }
    #app-shell.app .sidebar .sidebar-head, #app-shell.app .sidebar .user-card, #app-shell.app .sidebar .nav-kbd { display: none; }
    #app-shell.app .sidebar .mobile-only { display: flex; }
    .drawer-head { display: grid; gap: var(--space-2); padding-bottom: var(--space-3); border-bottom: 1px solid var(--border); }
    .drawer-user { display: flex; align-items: center; gap: var(--space-3); padding-left: 0.25rem; }
    .drawer-user .sidebar-close { display: inline-grid; margin-left: auto; width: var(--touch); height: var(--touch); }
    #app-shell.app .sidebar .nav-group + .nav-group { border-top: 0; padding-top: 0; }
    .sidebar-collapse { display: none; }
    .nav-backdrop { position: fixed; inset: 0; z-index: calc(var(--z-modal, 50) - 1); background: var(--bg-overlay); display: block; }
    .nav-backdrop[hidden] { display: none; }
}

/* ─── Bascule de thème (menu du compte et tiroir) ─────────────────────── */
.um-theme { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-height: 2.5rem; padding: var(--space-1) var(--space-2); font-size: var(--text-md); color: var(--text); }
.seg-theme { display: inline-flex; gap: 2px; padding: 2px; background: var(--bg-muted); border-radius: var(--radius-md); }
.seg-theme > button { display: grid; place-items: center; width: 2rem; height: 2rem; padding: 0; border: 0; border-radius: var(--radius-sm); background: none; color: var(--text-2); cursor: pointer; }
.seg-theme > button:hover { color: var(--text); }
.seg-theme > button[aria-pressed="true"] { background: var(--surface-selected, var(--accent-bg)); color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--accent-border); }
.seg-theme > button:focus-visible { outline-offset: 0; }
@media (pointer: coarse), (max-width: 640px) { .seg-theme > button { width: var(--touch); height: var(--touch); } }
.drawer-head .um-theme { padding-inline: var(--space-2); }

/* ─── Barre de contenu (≥ 641 px) : fil d'Ariane, recherche globale, action principale ─ */
.contentbar {
    position: sticky; top: 0; z-index: var(--z-sticky, 10); flex: none;
    display: flex; align-items: center; gap: var(--space-4); height: 3.5rem; padding: 0 var(--space-8);
    background: var(--bg); border-bottom: var(--border-width, 1px) solid var(--border);
}
.contentbar .breadcrumb { flex: 1; min-width: 0; margin: 0; display: block; font-size: var(--text-md); color: var(--text-2); }
.breadcrumb ol { display: flex; flex-wrap: nowrap; gap: var(--space-2); margin: 0; padding: 0; list-style: none; min-width: 0; }
.breadcrumb li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
/* Seul le dernier élément (page courante) rétrécit : les liens intermédiaires restent entiers et cliquables */
.breadcrumb li:not(:last-child) { flex: none; }
.breadcrumb li + li::before { content: "\203A"; margin-right: var(--space-2); color: var(--text-3); }
.breadcrumb li a { color: inherit; text-decoration: none; }
.breadcrumb li a:hover { color: var(--text); text-decoration: underline; }
.breadcrumb [aria-current="page"] { color: var(--text); font-weight: var(--weight-medium); }
.search-trigger {
    display: inline-flex; align-items: center; gap: var(--space-2); width: 17.5rem; max-width: 40%; height: var(--sh-control, var(--control-h)); flex: none;
    padding: 0 var(--space-2) 0 var(--space-3); border: var(--border-width, 1px) solid var(--border-control); border-radius: var(--radius-md);
    background: var(--bg); color: var(--text-3); font: inherit; font-size: var(--text-md); cursor: pointer; text-align: left;
}
.search-trigger:hover { border-color: var(--text-3); color: var(--text-2); }
.search-trigger .kbd {
    margin-left: auto; display: inline-flex; align-items: center; height: 1.25rem; padding: 0 var(--space-1);
    font-size: var(--text-xs); color: var(--text-2); background: var(--bg-muted); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.search-trigger-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contentbar-new { flex: none; display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--sh-control, var(--control-h)); }
.contentbar-new .icon { width: 1rem; height: 1rem; }
@media (min-width: 641px) and (max-width: 1023px) {
    .contentbar { padding: 0 var(--space-6); }
}
@media (max-width: 760px) {
    .search-trigger { width: var(--sh-control); max-width: none; padding: 0; justify-content: center; }
    .search-trigger-text, .search-trigger .kbd { display: none; }
}
@media (max-width: 640px) { .contentbar { display: none; } }

/* Compteur de la navigation (Bac de veille) */
.nav-count {
    margin-left: auto; min-width: 1.25rem; height: 1.25rem; padding: 0 var(--space-1); display: inline-grid; place-items: center;
    border-radius: 999px; background: var(--accent-bg); color: var(--accent-text); font-size: var(--text-xs); font-weight: var(--weight-semibold);
}
#app-shell.app[data-sidebar="collapsed"] .nav-count { position: absolute; top: 0.25rem; right: 0.125rem; margin: 0; min-width: 1rem; height: 1rem; font-size: 0.625rem; }
@media (min-width: 641px) and (max-width: 1023px) {
    #app-shell.app:not([data-sidebar="expanded"]) .nav-count { position: absolute; top: 0.25rem; right: 0.125rem; margin: 0; min-width: 1rem; height: 1rem; font-size: 0.625rem; }
}
.bn-item .nav-count { position: absolute; top: 0.25rem; left: 55%; margin: 0; min-width: 1rem; height: 1rem; font-size: 0.625rem; }

/* ─── Tablette : barre dépliée en tiroir superposé (ne pousse pas le contenu) ─ */
@media (min-width: 641px) and (max-width: 1023px) {
    #app-shell.app[data-sidebar="expanded"] { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); --sb: calc(var(--sidebar-w-collapsed) - 1px); }
    #app-shell.app[data-sidebar="expanded"] .sidebar {
        width: var(--sidebar-w); z-index: var(--z-panel, 30); box-shadow: var(--shadow-2);
    }
    #app-shell.app[data-sidebar="expanded"] .sidebar-head { flex-direction: row; }
}

/* Tiroir mobile : la barre haute (avatar) disparaît sous le voile */
@media (max-width: 640px) {
    #app-shell.app[data-nav="open"] .topbar .avatar { visibility: hidden; }
}

/* Cibles tactiles : lien du fil d'Ariane (tablette et écrans tactiles) */
@media (max-width: 1023px), (pointer: coarse) {
    .contentbar .breadcrumb li a { display: inline-flex; align-items: center; min-height: var(--touch, 2.75rem); min-width: var(--touch, 2.75rem); }
}
