/* ==========================================================================
   Template principal — structure générale
   ========================================================================== */

/* ==========================================================================
   Variables structurelles
   ========================================================================== */

:root {
    /* Dimensions */

    --app-navbar-height: 58px;
    --app-sidebar-width: 240px;
    --app-content-width: 1440px;

    /* Espacements */

    --app-space-xs: 6px;
    --app-space-sm: 10px;
    --app-space-md: 16px;
    --app-space-lg: 22px;

    /* Arrondis */

    --app-radius-sm: 8px;
    --app-radius-md: 12px;
    --app-radius-lg: 16px;

    /* Typographie compacte */

    --app-font-xs: 0.75rem;
    /* 12px */
    --app-font-sm: 0.8125rem;
    /* 13px */
    --app-font-base: 0.875rem;
    /* 14px */
    --app-font-md: 1rem;
    /* 16px */
    --app-font-lg: 1.125rem;
    /* 18px */
}

/* ==========================================================================
   Calcul global des dimensions
   ========================================================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

/* ==========================================================================
   Document
   ========================================================================== */

html {
    min-height: 100%;
    background: var(--theme-page-background);
}

body {
    min-height: 100vh;
    margin: 0;

    background: var(--theme-page-background);
    color: var(--theme-text);

    font-family: 'Croissant One', sans-serif;

    font-size: var(--app-font-base);
    line-height: 1.5;
}

/* ==========================================================================
   Structure principale
   ========================================================================== */

.app-template {
    display: flex;
    flex-direction: column;

    min-height: 100vh;
}

/* ==========================================================================
   En-tête et navbar
   ========================================================================== */

.app-header {
    position: sticky;
    z-index: 100;
    top: 0;
}

.app-navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--app-space-md);

    min-height: var(--app-navbar-height);
    padding-inline: var(--app-space-md);

    border-bottom: 1px solid var(--theme-navbar-border);

    background: var(--theme-navbar-background);
    color: var(--theme-text);

    box-shadow: var(--theme-shadow-soft);
}

.app-navbar__group {
    display: flex;
    align-items: center;
    gap: var(--app-space-xs);

    min-width: 0;
}

.app-navbar__group--start {
    flex: 1 1 auto;
}

.app-navbar__group--end {
    justify-content: flex-end;
}

.app-navbar__brand {
    display: inline-flex;
    align-items: center;
    gap: var(--app-space-sm);

    min-width: 0;

    color: var(--theme-text);

    font-size: var(--app-font-md);
    font-weight: 700;
    text-decoration: none;
}

.app-navbar__brand-logo {
    display: block;
    flex: 0 0 auto;

    width: 32px;
    height: 32px;

    object-fit: contain;
}

.app-navbar__brand-text {
    white-space: nowrap;
}

.app-navbar__action,
.app-navbar__user,
.app-search-panel__close {
    position: relative;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--app-space-xs);

    min-width: 36px;
    min-height: 36px;
    padding: 7px 10px;

    border: 1px solid transparent;
    border-radius: var(--app-radius-sm);

    background: transparent;
    color: var(--theme-text-muted);

    font: inherit;
    font-size: var(--app-font-sm);
    text-decoration: none;

    cursor: pointer;
}

.app-navbar__action:hover,
.app-navbar__action:focus-visible,
.app-navbar__user:hover,
.app-navbar__user:focus-visible,
.app-search-panel__close:hover,
.app-search-panel__close:focus-visible {
    border-color: var(--theme-border);

    background: var(--theme-surface-hover);
    color: var(--theme-text);
}

.app-navbar__action--create {
    background: var(--theme-primary-soft);
    color: var(--theme-primary);
}

.app-navbar__action-text {
    font-size: var(--app-font-xs);
    font-weight: 600;
}

.app-navbar__badge {
    position: absolute;
    top: 1px;
    right: 1px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-width: 16px;
    height: 16px;
    padding-inline: 4px;

    border: 2px solid var(--theme-navbar-background);
    border-radius: 999px;

    background: var(--theme-danger);
    color: var(--theme-page-background);

    font-size: 9px;
    font-weight: 700;
    line-height: 1;
}

.app-navbar__dropdown {
    position: relative;
}

.app-navbar__user {
    padding: 4px 7px;
}

.app-navbar__avatar {
    width: 28px;
    height: 28px;

    border: 1px solid var(--theme-border);
    border-radius: 50%;

    object-fit: cover;
}

.app-navbar__avatar--large {
    width: 38px;
    height: 38px;
}

.app-navbar__username {
    max-width: 130px;
    overflow: hidden;

    color: var(--theme-text);

    font-size: var(--app-font-xs);
    font-weight: 600;

    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-navbar__user-arrow {
    color: var(--theme-text-soft);

    font-size: 9px;
}

.app-navbar__link {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-height: 34px;
    padding-inline: var(--app-space-sm);

    border-radius: var(--app-radius-sm);

    color: var(--theme-text-muted);

    font-size: var(--app-font-xs);
    font-weight: 600;
    text-decoration: none;
}

.app-navbar__link:hover,
.app-navbar__link:focus-visible {
    background: var(--theme-surface-hover);
    color: var(--theme-text);
}

.app-navbar__link--primary {
    background: var(--theme-primary-soft);
    color: var(--theme-primary);
}

/* ==========================================================================
   Menus déroulants de la navbar
   ========================================================================== */

.app-navbar__menu {
    position: absolute;
    z-index: 120;
    top: calc(100% + 8px);
    right: 0;

    width: min(340px, calc(100vw - 20px));
    max-height: min(520px, calc(100vh - 80px));
    overflow-y: auto;

    border: 1px solid var(--theme-border);
    border-radius: var(--app-radius-md);

    background: var(--theme-surface);
    color: var(--theme-text);

    box-shadow: var(--theme-shadow);
}

.app-navbar__menu--user {
    width: min(250px, calc(100vw - 20px));
}

.app-navbar__menu-header {
    padding: var(--app-space-md);

    border-bottom: 1px solid var(--theme-border);
}

.app-navbar__menu-title {
    display: block;

    color: var(--theme-text);

    font-size: var(--app-font-sm);
    line-height: 1.3;
}

.app-navbar__menu-meta {
    display: block;

    margin-top: 2px;

    color: var(--theme-text-soft);

    font-size: var(--app-font-xs);
}

.app-navbar__user-identity {
    display: flex;
    align-items: center;
    gap: var(--app-space-sm);
}

.app-navbar__menu-link,
.app-navbar__menu-footer {
    display: flex;
    align-items: center;
    gap: var(--app-space-sm);

    padding: 10px var(--app-space-md);

    color: var(--theme-text-muted);

    font-size: var(--app-font-xs);
    text-decoration: none;
}

.app-navbar__menu-link i {
    width: 16px;

    text-align: center;
}

.app-navbar__menu-link:hover,
.app-navbar__menu-link:focus-visible,
.app-navbar__menu-footer:hover,
.app-navbar__menu-footer:focus-visible {
    background: var(--theme-surface-hover);
    color: var(--theme-text);
}

.app-navbar__menu-link--danger {
    color: var(--theme-danger);
}

.app-navbar__menu-separator {
    height: 1px;
    margin-block: var(--app-space-xs);

    background: var(--theme-border);
}

.app-navbar__menu-footer {
    justify-content: center;

    border-top: 1px solid var(--theme-border);

    color: var(--theme-primary);

    font-weight: 600;
}

.app-navbar__menu-empty {
    padding: var(--app-space-md);

    color: var(--theme-text-soft);

    font-size: var(--app-font-xs);
    text-align: center;
}

/* ==========================================================================
   Notifications
   ========================================================================== */

.app-navbar__notification-item {
    display: flex;
    align-items: flex-start;
    gap: var(--app-space-sm);

    padding: var(--app-space-sm) var(--app-space-md);

    border-bottom: 1px solid var(--theme-border);

    color: var(--theme-text-muted);
    text-decoration: none;
}

.app-navbar__notification-item:hover,
.app-navbar__notification-item:focus-visible {
    background: var(--theme-surface-hover);
}

.app-navbar__notification-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;

    width: 26px;
    height: 26px;

    border-radius: 50%;

    background: var(--theme-primary-soft);
    color: var(--theme-primary);

    font-size: var(--app-font-xs);
}

.app-navbar__notification-avatar {
    flex: 0 0 auto;

    width: 28px;
    height: 28px;

    border-radius: 50%;

    object-fit: cover;
}

.app-navbar__notification-content {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 3px;

    min-width: 0;
}

.app-navbar__notification-message {
    color: var(--theme-text-muted);

    font-size: var(--app-font-xs);
    line-height: 1.4;
}

.app-navbar__notification-date {
    color: var(--theme-text-soft);

    font-size: 11px;
}

/* ==========================================================================
   Panneau de recherche globale
   ========================================================================== */

.app-search-panel {
    position: absolute;
    z-index: 110;
    top: 100%;
    right: 0;
    left: 0;

    padding: var(--app-space-sm) var(--app-space-md);

    border-bottom: 1px solid var(--theme-border);

    background: var(--theme-surface);
    color: var(--theme-text);

    box-shadow: var(--theme-shadow-soft);
}

.app-search-panel__inner {
    display: flex;
    align-items: center;
    gap: var(--app-space-sm);

    width: min(100%, var(--app-content-width));
    margin-inline: auto;
}

.app-search-panel__field {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    gap: var(--app-space-sm);

    min-width: 0;
    padding-inline: var(--app-space-sm);

    border: 1px solid var(--theme-border);
    border-radius: var(--app-radius-sm);

    background: var(--theme-layout-background);
    color: var(--theme-text-soft);
}

.app-search-panel__input {
    flex: 1 1 auto;

    min-width: 0;
    min-height: 36px;

    border: 0;
    outline: 0;

    background: transparent;
    color: var(--theme-text);

    font: inherit;
    font-size: var(--app-font-sm);
}

.app-search-panel__input::placeholder {
    color: var(--theme-text-soft);
}

.app-search-panel__message {
    width: min(100%, var(--app-content-width));
    margin: var(--app-space-xs) auto 0;

    color: var(--theme-text-soft);

    font-size: var(--app-font-xs);
}

/* ==========================================================================
   Welcom
   ========================================================================== */

.page-welcome {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 0;
    margin-bottom: var(--app-space-sm);
}

.welcome-text {
    font-size: clamp(0.72rem,
            2.5vw,
            0.9rem);
}

/* ==========================================================================
   Zone centrale
   ========================================================================== */

.app-layout {
    display: grid;
    grid-template-columns:
        var(--app-sidebar-width) minmax(0, 1fr);

    flex: 1 1 auto;

    width: 100%;
    min-width: 0;
    min-height: 0;
}

/* ==========================================================================
   Sidebar
   ========================================================================== */

.app-sidebar {
    position: sticky;
    top: var(--app-navbar-height);

    align-self: start;

    width: 100%;
    height: calc(100vh - var(--app-navbar-height));
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto;

    border-right: 1px solid var(--theme-sidebar-border);

    background: var(--theme-sidebar-background);
    color: var(--theme-text);
}

.app-sidebar__inner {
    display: flex;
    flex-direction: column;
    gap: var(--app-space-md);

    min-height: 100%;
    padding: var(--app-space-md);
}

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

.app-layout.is-sidebar-collapsed .app-sidebar {
    display: none;
}

/* Identité utilisateur */

.app-sidebar__profile {
    display: flex;
    align-items: center;
    gap: var(--app-space-sm);

    min-width: 0;
    padding: var(--app-space-sm);

    border: 1px solid var(--theme-border);
    border-radius: var(--app-radius-md);

    background: var(--theme-surface);
    color: var(--theme-text);

    text-decoration: none;
}

.app-sidebar__profile:hover,
.app-sidebar__profile:focus-visible {
    border-color: var(--theme-border-strong);
    background: var(--theme-surface-hover);
}

.app-sidebar__avatar {
    display: block;
    flex: 0 0 auto;

    width: 38px;
    height: 38px;

    border: 1px solid var(--theme-border);
    border-radius: 50%;

    object-fit: cover;
}

.app-sidebar__identity {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;

    min-width: 0;
}

.app-sidebar__username {
    overflow: hidden;

    color: var(--theme-text);

    font-size: var(--app-font-sm);
    line-height: 1.3;

    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-sidebar__role {
    color: var(--theme-text-soft);

    font-size: var(--app-font-xs);
    line-height: 1.3;
}

/* Navigation */

.app-sidebar__navigation {
    display: flex;
    flex-direction: column;
    gap: var(--app-space-md);
}

.app-sidebar__section {
    min-width: 0;
}

.app-sidebar__section-title {
    margin: 0 0 var(--app-space-xs);
    padding-inline: var(--app-space-sm);

    color: var(--theme-text-soft);

    font-size: 11px;
    font-weight: 700;
    line-height: 1.3;

    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.app-sidebar__links {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.app-sidebar__link {
    display: flex;
    align-items: center;
    gap: var(--app-space-sm);

    min-width: 0;
    min-height: 36px;
    padding: 8px var(--app-space-sm);

    border: 1px solid transparent;
    border-radius: var(--app-radius-sm);

    color: var(--theme-text-muted);

    font-size: var(--app-font-xs);
    font-weight: 600;
    line-height: 1.3;
    text-decoration: none;
}

.app-sidebar__link i {
    flex: 0 0 auto;

    width: 18px;

    color: var(--theme-text-soft);

    font-size: var(--app-font-sm);
    text-align: center;
}

.app-sidebar__link-label {
    overflow: hidden;

    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-sidebar__link:hover,
.app-sidebar__link:focus-visible {
    border-color: var(--theme-border);

    background: var(--theme-surface-hover);
    color: var(--theme-text);
}

.app-sidebar__link:hover i,
.app-sidebar__link:focus-visible i {
    color: var(--theme-primary);
}

.app-sidebar__link.is-active {
    border-color: var(--theme-border-strong);

    background: var(--theme-primary-soft);
    color: var(--theme-primary);
}

.app-sidebar__link.is-active i {
    color: var(--theme-primary);
}


/* ==========================================================================
   Sidebar — sous-menus
   ========================================================================== */

.app-sidebar__submenu {
    min-width: 0;
    margin: 2px 0;
}

.app-sidebar__submenu>summary {
    list-style: none;
}

.app-sidebar__submenu>summary::-webkit-details-marker {
    display: none;
}

.app-sidebar__submenu-toggle {
    cursor: pointer;
}

.app-sidebar__submenu-arrow {
    margin-left: auto;

    color: var(--theme-text-soft);

    font-size: 10px;

    transition: transform 0.18s ease;
}

.app-sidebar__submenu[open]>.app-sidebar__submenu-toggle {
    border-color: var(--theme-border);

    background: var(--theme-primary-soft);
    color: var(--theme-text);
}

.app-sidebar__submenu[open]>.app-sidebar__submenu-toggle i {
    color: var(--theme-primary);
}

.app-sidebar__submenu[open]>.app-sidebar__submenu-toggle .app-sidebar__submenu-arrow {
    transform: rotate(180deg);
}

/*
 * Le bloc des sous-liens est volontairement plus clair que le fond
 * général du sidebar afin de distinguer immédiatement les deux niveaux.
 */

.app-sidebar__submenu-links {
    display: flex;
    flex-direction: column;
    gap: 3px;

    margin: 4px 0 5px 18px;
    padding: 6px;

    border: 1px solid var(--theme-border);
    border-left: 3px solid var(--theme-border-strong);
    border-radius: var(--app-radius-sm);

    background: var(--theme-surface);
}

.app-sidebar__link--child {
    min-height: 32px;
    padding: 7px 8px;

    background: var(--theme-surface-hover);
    color: var(--theme-text);

    font-size: 11px;
    font-weight: 500;
}

.app-sidebar__link--child i {
    width: 16px;

    color: var(--theme-text-muted);

    font-size: var(--app-font-xs);
}

.app-sidebar__link--child:hover,
.app-sidebar__link--child:focus-visible {
    border-color: var(--theme-border-strong);

    background: var(--theme-primary-soft);
    color: var(--theme-primary);
}

.app-sidebar__link--child.is-active {
    border-color: var(--theme-primary);

    background: var(--theme-primary-soft);
    color: var(--theme-primary);

    font-weight: 700;
}

.app-sidebar__link--child.is-active i {
    color: var(--theme-primary);
}

/* ==========================================================================
   Contenu principal
   ========================================================================== */

.app-main {
    min-width: 0;
    padding: var(--app-space-lg);

    background: var(--theme-layout-background);
}

.app-main__content {
    width: 100%;
    max-width: var(--app-content-width);
    min-width: 0;
    margin-inline: auto;
}

/* ==========================================================================
   Medias
   ========================================================================== */

img,
video,
audio,
iframe {
    max-width: 100%;
}

img,
video {
    height: auto;
}

/* ==========================================================================
   Footer
   ========================================================================== */

/* ==========================================================================
   Footer
   ========================================================================== */

.app-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;

    width: 100%;
    margin-top: auto;

    padding: 5px 10px;

    background: var(--theme-footer-background);
    color: var(--theme-text-muted);

    border-top: 1px solid var(--theme-footer-border);
    box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.5);

    font-size: small;
    gap: 5px 10px;
}

.app-footer > div {
    min-width: 0;
}

.app-footer__text {
    margin: 0;
}

.app-footer__link {
    color: var(--theme-primary);
    font-weight: 600;
    text-decoration: none;
}

.app-footer__link:hover,
.app-footer__link:focus-visible {
    color: var(--theme-primary-hover);
    text-decoration: underline;
}


/* ==========================================================================
   Titres compacts du template
   ========================================================================== */

.app-title {
    margin: 0;

    color: var(--theme-text);

    font-size: var(--app-font-lg);
    font-weight: 700;
    line-height: 1.3;
}

.app-subtitle {
    margin: 0;

    color: var(--theme-text-muted);

    font-size: var(--app-font-sm);
    font-weight: 500;
    line-height: 1.4;
}

.app-label {
    color: var(--theme-text-muted);

    font-size: var(--app-font-xs);
    font-weight: 600;
    line-height: 1.3;
}

/* ==========================================================================
   Panneau générique du template
   ========================================================================== */

.app-panel {
    padding: var(--app-space-md);

    border: 1px solid var(--theme-border);
    border-radius: var(--app-radius-md);

    background: var(--theme-surface);
    color: var(--theme-text);

    box-shadow: var(--theme-shadow-soft);
}

.app-panel__heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--app-space-md);

    margin-bottom: var(--app-space-sm);
}

.app-panel__title {
    margin: 0;

    color: var(--theme-text);

    font-size: var(--app-font-md);
    font-weight: 700;
    line-height: 1.3;
}

.app-panel__text {
    margin: 0;

    color: var(--theme-text-muted);

    font-size: var(--app-font-sm);
    line-height: 1.5;
}

.app-panel__meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--app-space-sm);

    margin-top: var(--app-space-md);

    color: var(--theme-text-soft);

    font-size: var(--app-font-xs);
}

/* ==========================================================================
   Sidebar réduite sur ordinateur
   ========================================================================== */

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

.app-layout.is-sidebar-collapsed .app-sidebar {
    display: none;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

/* ==========================================================================
   Sidebar réduite sur ordinateur
   --------------------------------------------------------------------------
   Cette règle ne doit jamais s'appliquer sur tablette ou mobile.
   ========================================================================== */

@media (min-width: 901px) {

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

    .app-layout.is-sidebar-collapsed .app-sidebar {
        display: none;
    }

}

/* ==========================================================================
   Responsive — tablette et mobile
   ========================================================================== */

@media (max-width: 900px) {

    /*
     * Le contenu principal occupe toute la largeur.
     */

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

    /*
     * Éléments compacts de la navbar.
     */

    .app-navbar__username,
    .app-navbar__action-text {
        display: none;
    }

    .app-navbar__user {
        padding-inline: 4px;
    }

    /*
     * Sidebar fermée par défaut.
     *
     * La classe ordinateur is-sidebar-collapsed ne doit plus
     * pouvoir imposer display: none dans cette largeur.
     */

    .app-sidebar,
    .app-layout.is-sidebar-collapsed .app-sidebar {
        position: static;

        display: none;

        width: 100%;
        height: auto;

        border-right: 0;
        border-bottom: 1px solid var(--theme-sidebar-border);
    }

    /*
     * Sidebar ouverte par le JavaScript.
     */

    .app-sidebar.is-open,
    .app-layout.is-sidebar-collapsed .app-sidebar.is-open {
        display: block;
    }

    .app-main {
        padding: var(--app-space-md);
    }

}

/* ==========================================================================
   Très petits écrans
   ========================================================================== */

@media (max-width: 480px) {

    :root {
        --app-navbar-height: 54px;
    }

    .app-navbar {
        gap: var(--app-space-xs);
        padding-inline: var(--app-space-sm);
    }

    .app-navbar__brand-text {
        display: none;
    }

    .app-navbar__group {
        gap: 3px;
    }

    .app-navbar__action,
    .app-navbar__user {
        min-width: 34px;
        min-height: 34px;
        padding: 5px;
    }

    .app-navbar__menu {
        position: fixed;
        top: calc(var(--app-navbar-height) + 6px);
        right: var(--app-space-sm);
        left: var(--app-space-sm);

        width: auto;
    }

    .app-search-panel {
        padding-inline: var(--app-space-sm);
    }

    .app-main {
        padding: var(--app-space-sm);
    }

    .app-title {
        font-size: var(--app-font-md);
    }

    .app-footer {
        font-size: small;
        padding: 8px 15px;
    }

}