/**
 * FICHIER : assets/css/app-layout.css
 * -------------------------------------------------------------------------
 * Ossature commune du portail familial.
 * Inspirée du nouveau tableau de bord administrateur :
 * - menu latéral rétractable sur ordinateur ;
 * - tiroir latéral sur téléphone et tablette ;
 * - icônes SVG ;
 * - styles isolés avec le préfixe app-.
 * -------------------------------------------------------------------------
 */

:root {
    --app-sidebar-width: 264px;
    --app-sidebar-collapsed-width: 78px;
    --app-bg: #f4f7fb;
    --app-panel: #ffffff;
    --app-sidebar: #17212f;
    --app-sidebar-soft: #223044;
    --app-text: #1d2939;
    --app-muted: #667085;
    --app-border: #e6ebf2;
    --app-primary: #3867e8;
    --app-primary-soft: #eef3ff;
    --app-shadow: 0 12px 28px rgba(30, 41, 59, 0.08);
}

body.layout-app,
body.layout-public,
body.layout-standalone {
    min-height: 100vh;
    background: var(--app-bg);
}

.app-svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ----------------------------------------------------------------------
 * MODE APPLICATION CONNECTÉE
 * ---------------------------------------------------------------------- */

.app-shell {
    position: relative;
    display: grid;
    min-height: 100vh;
    grid-template-columns: var(--app-sidebar-width) minmax(0, 1fr);
    transition: grid-template-columns 0.22s ease;
}

.app-shell.is-collapsed {
    grid-template-columns: var(--app-sidebar-collapsed-width) minmax(0, 1fr);
}

.app-sidebar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    height: 100vh;
    min-height: 100vh;
    flex-direction: column;
    overflow: hidden;
    background: var(--app-sidebar);
    color: #d8e0eb;
}

.app-sidebar-header {
    display: flex;
    min-height: 76px;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.app-brand {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 12px;
    color: inherit;
    text-decoration: none;
}

.app-brand:hover {
    color: inherit;
}

.app-brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    place-items: center;
    border-radius: 14px;
    background: linear-gradient(135deg, #4b7bec, #45d6b5);
    color: #ffffff;
}

.app-brand-copy {
    display: grid;
    gap: 2px;
    white-space: nowrap;
}

.app-brand-copy strong {
    color: #ffffff;
    font-size: 1rem;
}

.app-brand-copy small {
    color: #a7b3c6;
    font-size: 0.74rem;
}

.app-sidebar-collapse,
.app-mobile-menu,
.app-sidebar-overlay {
    border: 0;
    cursor: pointer;
}

.app-sidebar-collapse {
    display: grid;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    place-items: center;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    color: #d8e0eb;
}

.app-collapse-closed {
    display: none;
}

.app-sidebar-nav {
    display: grid;
    gap: 4px;
    overflow-y: auto;
    padding: 14px 10px;
}

.app-sidebar-link {
    display: flex;
    min-height: 44px;
    align-items: center;
    gap: 13px;
    padding: 0 12px;
    border-radius: 12px;
    color: #b8c3d2;
    text-decoration: none;
    transition: background 0.18s ease, color 0.18s ease;
}

.app-sidebar-link:hover,
.app-sidebar-link.is-active {
    background: var(--app-sidebar-soft);
    color: #ffffff;
}

.app-sidebar-icon {
    display: grid;
    width: 24px;
    flex: 0 0 24px;
    place-items: center;
}

.app-sidebar-label {
    overflow: hidden;
    white-space: nowrap;
}

.app-sidebar-badge {
    display: inline-grid;
    min-width: 21px;
    height: 21px;
    margin-left: auto;
    place-items: center;
    border-radius: 999px;
    background: #e75364;
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 800;
}

.app-sidebar-footer {
    display: grid;
    gap: 4px;
    margin-top: auto;
    padding: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.app-sidebar-logout {
    color: #f2a8af;
}

.app-shell.is-collapsed .app-brand-copy,
.app-shell.is-collapsed .app-sidebar-label,
.app-shell.is-collapsed .app-sidebar-badge {
    display: none;
}

.app-shell.is-collapsed .app-sidebar-header {
    justify-content: center;
    flex-wrap: wrap;
}

.app-shell.is-collapsed .app-sidebar-link {
    justify-content: center;
    padding-inline: 0;
}

.app-shell.is-collapsed .app-collapse-open {
    display: none;
}

.app-shell.is-collapsed .app-collapse-closed {
    display: inline-grid;
}

.app-workspace {
    display: flex;
    min-width: 0;
    min-height: 100vh;
    flex-direction: column;
}

.app-topbar {
    display: flex;
    min-height: 76px;
    align-items: center;
    gap: 14px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--app-border);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(12px);
}

.app-mobile-menu {
    display: none;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 12px;
    background: var(--app-primary-soft);
    color: var(--app-primary);
}

.app-topbar-title p {
    margin: 0 0 2px;
    color: var(--app-primary);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.app-topbar-title h1 {
    margin: 0;
    color: var(--app-text);
    font-size: 1.25rem;
    font-weight: 750;
}

.app-topbar-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    color: var(--app-text);
    text-decoration: none;
}

.app-topbar-profile:hover {
    color: var(--app-text);
}

.app-topbar-profile-copy {
    display: grid;
    gap: 1px;
    text-align: right;
}

.app-topbar-profile-copy small {
    color: var(--app-muted);
    font-size: 0.72rem;
}

.app-topbar-profile img,
.app-avatar-placeholder {
    display: grid;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    place-items: center;
    border: 2px solid #dce5f7;
    border-radius: 50%;
    object-fit: cover;
}

.app-avatar-placeholder {
    background: var(--app-primary-soft);
    color: var(--app-primary);
    font-weight: 800;
}

.app-page-content {
    width: 100%;
    max-width: none;
    flex: 1;
    margin: 0;
    padding: 24px;
}

.app-page-content > main,
.app-page-content > section {
    max-width: 1440px;
    margin-inline: auto;
}

.app-footer,
.public-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--app-border);
    background: #ffffff;
    color: var(--app-muted);
    text-align: center;
    font-size: 0.82rem;
}

.app-sidebar-overlay {
    display: none;
}

/* ----------------------------------------------------------------------
 * PAGES PUBLIQUES
 * ---------------------------------------------------------------------- */

.public-shell {
    display: flex;
    min-height: 100vh;
    flex-direction: column;
}

.public-topbar {
    display: flex;
    min-height: 72px;
    align-items: center;
    padding: 14px 22px;
    background: var(--app-sidebar);
}

.public-main {
    width: 100%;
    max-width: 620px;
    flex: 1;
    margin: 0 auto;
    padding: 28px 18px;
}

/* ----------------------------------------------------------------------
 * PAGE AUTONOME : DASHBOARD ADMIN DÉJÀ REFONDU
 * ---------------------------------------------------------------------- */

.standalone-main {
    width: 100%;
    max-width: none;
    flex: 1;
    margin: 0;
    padding: 0;
}

/* ----------------------------------------------------------------------
 * RESPONSIVE
 * ---------------------------------------------------------------------- */

@media (max-width: 1050px) {
    .app-shell {
        display: block;
    }

    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: min(300px, 88vw);
        transform: translateX(-105%);
        transition: transform 0.22s ease;
    }

    .app-shell.is-mobile-open .app-sidebar {
        transform: translateX(0);
    }

    .app-shell.is-mobile-open .app-sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 30;
        display: block;
        background: rgba(15, 23, 42, 0.52);
    }

    .app-sidebar-collapse {
        display: none;
    }

    .app-mobile-menu {
        display: grid;
    }
}

@media (max-width: 720px) {
    .app-topbar {
        min-height: 68px;
        padding: 12px 15px;
    }

    .app-topbar-title h1 {
        max-width: 155px;
        overflow: hidden;
        font-size: 1.08rem;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-topbar-profile-copy small {
        display: none;
    }

    .app-topbar-profile-copy strong {
        display: block;
        max-width: 105px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-page-content {
        padding: 15px;
    }
}

/* =========================================================
   MOBILE : barre supérieure toujours visible
   ========================================================= */

@media (max-width: 768px) {
    .app-topbar,
    .app-topbar.is-hidden {
        transform: translateY(0) !important;
    }
}

/* ----------------------------------------------------------------------
 * PHASE 7 : ROBUSTESSE MOBILE ET HIÉRARCHIE D'AFFICHAGE
 * ---------------------------------------------------------------------- */

body.app-sidebar-open {
    overflow: hidden;
}

.app-sidebar {
    z-index: 80;
}

.app-sidebar-overlay {
    z-index: 70;
}

.app-topbar {
    position: relative;
    z-index: 20;
}

.app-page-content {
    overflow-x: hidden;
}

.app-sidebar-link:focus-visible,
.app-mobile-menu:focus-visible,
.app-sidebar-collapse:focus-visible {
    outline: 3px solid rgba(69, 214, 181, 0.75);
    outline-offset: 2px;
}

@media (max-width: 1050px) {
    .app-sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .app-sidebar-overlay {
        -webkit-tap-highlight-color: transparent;
    }
}

@media (max-width: 520px) {
    .app-page-content {
        padding:
            13px
            max(12px, env(safe-area-inset-right))
            15px
            max(12px, env(safe-area-inset-left));
    }

    .app-topbar {
        padding:
            10px
            max(12px, env(safe-area-inset-right))
            10px
            max(12px, env(safe-area-inset-left));
    }

    .app-topbar-profile img,
    .app-avatar-placeholder {
        width: 38px;
        height: 38px;
        flex-basis: 38px;
    }
}

/* =========================================================
   CORRECTIF FINAL : BARRE SUPÉRIEURE FIXE SUR MOBILE
   ---------------------------------------------------------
   Conserve en permanence à l'écran :
   - bouton burger ;
   - titre de la page ;
   - cloche ;
   - profil.

   L'espace ajouté à .app-workspace empêche le contenu
   de passer sous la barre fixe.
   ========================================================= */

@media (max-width: 1050px) {
    .app-topbar,
    .app-topbar.is-hidden {
        position: fixed !important;
        top: 0;
        right: 0;
        left: 0;
        z-index: 60;
        width: 100%;
        box-sizing: border-box;
        transform: translateY(0) !important;
    }

    .app-workspace {
        padding-top: 76px;
    }
}

@media (max-width: 720px) {
    .app-workspace {
        padding-top: 68px;
    }
}

