/* =========================================================
   LAYOUT GENERALE
   Gestione Permessi
========================================================= */


/* =========================================================
   VARIABILI LAYOUT
========================================================= */

:root {
    --topbar-height: 72px;
    --footer-height: 48px;
    --sidebar-width: 240px;
}


/* =========================================================
   RESET BASE
========================================================= */

* {
    box-sizing: border-box;
}


html,
body {
    width: 100%;
    min-height: 100%;

    margin: 0;
    padding: 0;
}


html {
    scroll-behavior: smooth;
}


body {
    min-height: 100vh;

    margin: 0;

    background-color: #eaf6ff;

    color: #212529;
}


/* =========================================================
   TOPBAR
   FISSA IN ALTO
========================================================= */

.topbar {
    position: fixed;

    top: 0;
    left: 0;
    right: 0;

    width: 100%;
    height: var(--topbar-height);

    display: flex;
    align-items: center;

    gap: 25px;

    padding: 0 28px;

    background-color: #ffffff;

    border-bottom: 1px solid #dee2e6;

    z-index: 1100;
}


/* =========================================================
   LOGO + NOME APPLICAZIONE
========================================================= */

.topbar-brand {
    flex-shrink: 0;

    display: flex;
    align-items: center;

    gap: 10px;

    white-space: nowrap;

    color: #212529;
}


.topbar-logo {
    display: block;

    width: 55px;
    height: 55px;

    object-fit: contain;

    flex-shrink: 0;
}


.topbar-brand-text {
    display: block;

    font-size: 20px;
    font-weight: 700;

    line-height: 1;
}


/* =========================================================
   RICERCA TOPBAR
========================================================= */

.topbar-search {
    flex: 1;

    min-width: 0;

    display: flex;
    justify-content: center;
    align-items: center;
}


#global-search-form {
    width: 100%;
    max-width: 500px;

    display: flex;
    align-items: center;

    margin: 0;
}


#global-search-input {
    flex: 1;

    min-width: 0;

    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}


#global-search-form .btn {
    flex-shrink: 0;

    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}


/* =========================================================
   SUGGERIMENTI RICERCA
========================================================= */

#global-search-suggestions {
    max-height: 350px;

    overflow-y: auto;

    z-index: 1200;
}


/* =========================================================
   AZIONI TOPBAR
========================================================= */

.topbar-actions {
    display: flex;
    align-items: center;

    gap: 10px;

    flex-shrink: 0;
}


.topbar-user {
    margin-right: 5px;

    white-space: nowrap;
}


.topbar-actions form {
    margin: 0;
    padding: 0;
}


/* =========================================================
   STRUTTURA PRINCIPALE
========================================================= */

.app-wrapper {
    width: 100%;

    min-height: 100vh;

    background-color: #eaf6ff;
}


/* =========================================================
   SIDEBAR
   FISSA TRA TOPBAR E FOOTER
========================================================= */

.sidebar {
    position: fixed;

    top: var(--topbar-height);
    left: 0;
    bottom: var(--footer-height);

    width: var(--sidebar-width);

    padding: 22px 15px 18px;

    background-color: #ffffff;

    border-right: 1px solid #dee2e6;

    overflow: hidden;

    z-index: 1000;
}


/* =========================================================
   CONTENITORE NAVIGAZIONE SIDEBAR
========================================================= */

.sidebar-nav {
    width: 100%;
    height: 100%;

    display: flex;
    flex-direction: column;

    min-height: 0;
}


/* =========================================================
   PARTE PRINCIPALE SIDEBAR
========================================================= */

.sidebar-main {
    display: flex;
    flex-direction: column;

    gap: 8px;

    min-height: 0;

    overflow-y: auto;
    overflow-x: hidden;

    /* Mantiene lo scroll ma nasconde la barra */
    scrollbar-width: none;
    -ms-overflow-style: none;
}


/* =========================================================
   LINK SIDEBAR
========================================================= */

.sidebar-link {
    display: block;

    flex-shrink: 0;

    padding: 11px 14px;

    border-radius: 7px;

    color: #343a40;

    text-decoration: none;

    font-weight: 500;

    line-height: 1.45;

    transition:
        background-color 0.2s ease,
        color 0.2s ease;
}


/* Hover */

.sidebar-link:hover {
    background-color: #e9ecef;

    color: #0d6efd;
}


/* Pagina selezionata */

.sidebar-link.active {
    background-color: #0d6efd;

    color: #ffffff;
}


/* =========================================================
   PARTE INFERIORE SIDEBAR
   UTENTI + PROFILO
========================================================= */

.sidebar-admin {
    margin-top: auto;

    padding-top: 20px;
    padding-bottom: 2px;

    border-top: 1px solid #dee2e6;

    display: flex;
    flex-direction: column;

    gap: 10px;

    flex-shrink: 0;
}


/* =========================================================
   SCROLL INTERNO SIDEBAR
   Scroll attivo senza barra visibile
========================================================= */

.sidebar-main::-webkit-scrollbar {
    display: none;
}


/* =========================================================
   CONTENUTO PRINCIPALE
========================================================= */

.page-content {
    width: auto;

    min-width: 0;

    min-height: 100vh;

    /*
     * Lascia libero lo spazio occupato
     * dalla sidebar.
     */
    margin-left: var(--sidebar-width);

    /*
     * Lascia libero lo spazio occupato
     * dalla topbar.
     */
    padding-top: var(--topbar-height);

    /*
     * Lascia libero lo spazio occupato
     * dal footer.
     */
    padding-bottom: var(--footer-height);

    background-color: #eaf6ff;
}


/* =========================================================
   CONTENUTO AJAX
========================================================= */

#page-content {
    width: 100%;

    min-width: 0;
}


/* =========================================================
   FOOTER
   FISSO IN BASSO
========================================================= */

.footer {
    position: fixed;

    left: 0;
    right: 0;
    bottom: 0;

    width: 100%;
    height: var(--footer-height);

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 20px;

    padding: 0 28px;

    background-color: #ffffff;

    border-top: 1px solid #dee2e6;

    color: #343a40;

    font-size: 14px;

    z-index: 1100;
}


.footer > div:first-child {
    text-align: left;
}


.footer > div:last-child {
    text-align: right;
}


/* =========================================================
   PAGINE SENZA SIDEBAR / UTENTE NON AUTENTICATO
========================================================= */

/*
 * Se la sidebar esiste ma è vuota perché l'utente non è
 * autenticato, viene nascosta.
 */

.sidebar:empty {
    display: none;
}


/*
 * Se il browser supporta :has(), quando la sidebar è vuota
 * il contenuto torna a tutta larghezza.
 */

.app-wrapper:not(:has(.sidebar nav)) .page-content {
    margin-left: 0;
}


/* =========================================================
   RESPONSIVE - FINO A 1200PX
========================================================= */

@media (max-width: 1200px) {

    .topbar {
        gap: 15px;

        padding-left: 20px;
        padding-right: 20px;
    }


    #global-search-form {
        max-width: 420px;
    }


    .topbar-actions {
        gap: 7px;
    }
}


/* =========================================================
   RESPONSIVE - TABLET
========================================================= */

@media (max-width: 992px) {

    :root {
        --topbar-height: 72px;
        --sidebar-width: 220px;
    }


    .topbar {
        gap: 12px;

        padding-left: 15px;
        padding-right: 15px;
    }


    .topbar-logo {
        width: 48px;
        height: 48px;
    }


    .topbar-brand-text {
        font-size: 18px;
    }


    .topbar-actions {
        gap: 6px;
    }


    .topbar-user {
        margin-right: 2px;
    }


    #global-search-form {
        max-width: 350px;
    }


    .sidebar {
        padding-left: 12px;
        padding-right: 12px;
    }


    .sidebar-link {
        padding: 10px 12px;

        font-size: 15px;
    }
}


/* =========================================================
   RESPONSIVE - MOBILE
========================================================= */

@media (max-width: 768px) {

    /*
     * Su smartphone togliamo il fixed.
     *
     * In questo modo non si rischia che topbar,
     * sidebar e footer occupino quasi tutto
     * lo schermo.
     */

    body {
        min-height: 100vh;

        display: flex;
        flex-direction: column;
    }


    /* =====================================================
       TOPBAR MOBILE
    ===================================================== */

    .topbar {
        position: relative;

        top: auto;
        left: auto;
        right: auto;

        width: 100%;

        height: auto;
        min-height: 72px;

        flex-wrap: wrap;

        gap: 12px;

        padding:
            10px
            15px;
    }


    .topbar-brand {
        flex-shrink: 0;
    }


    .topbar-logo {
        width: 42px;
        height: 42px;
    }


    .topbar-brand-text {
        font-size: 18px;
    }


    .topbar-search {
        order: 3;

        width: 100%;

        flex-basis: 100%;
    }


    #global-search-form {
        width: 100%;
        max-width: 100%;
    }


    .topbar-actions {
        margin-left: auto;

        flex-wrap: wrap;

        gap: 6px;
    }


    /* =====================================================
       WRAPPER MOBILE
    ===================================================== */

    .app-wrapper {
        width: 100%;

        min-height: 0;

        display: flex;
        flex-direction: column;

        flex: 1;
    }


    /* =====================================================
       SIDEBAR MOBILE
    ===================================================== */

    .sidebar {
        position: relative;

        top: auto;
        left: auto;
        bottom: auto;

        width: 100%;
        height: auto;

        padding: 12px 15px;

        border-right: none;
        border-bottom: 1px solid #dee2e6;

        overflow: visible;
    }


    .sidebar-nav {
        width: 100%;
        height: auto;

        display: flex;
        flex-direction: row;
        flex-wrap: wrap;

        align-items: center;

        gap: 8px;
    }


    .sidebar-main {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;

        gap: 8px;

        overflow: visible;

        padding-right: 0;
    }


    .sidebar-admin {
        margin-top: 0;
        margin-left: 0;

        padding-top: 0;
        padding-bottom: 0;

        border-top: none;

        display: flex;
        flex-direction: row;
        flex-wrap: wrap;

        gap: 8px;
    }


    .sidebar-link {
        padding: 8px 12px;

        font-size: 14px;
    }


    /* =====================================================
       CONTENUTO MOBILE
    ===================================================== */

    .page-content,
    .app-wrapper .page-content {
        width: 100%;

        min-width: 0;
        min-height: 0;

        margin-left: 0;

        padding-top: 0;
        padding-bottom: 0;

        flex: 1;
    }


    /* =====================================================
       FOOTER MOBILE
    ===================================================== */

    .footer {
        position: relative;

        left: auto;
        right: auto;
        bottom: auto;

        width: 100%;

        height: auto;
        min-height: 48px;

        flex-direction: column;

        justify-content: center;

        gap: 3px;

        padding:
            10px
            15px;

        text-align: center;
    }


    .footer > div:first-child,
    .footer > div:last-child {
        text-align: center;
    }
}


/* =========================================================
   RESPONSIVE - TELEFONI PICCOLI
========================================================= */

@media (max-width: 576px) {

    .topbar {
        align-items: stretch;
    }


    .topbar-brand {
        width: 100%;

        justify-content: center;
    }


    .topbar-search {
        order: initial;

        width: 100%;

        flex-basis: 100%;
    }


    .topbar-actions {
        width: 100%;

        margin-left: 0;

        justify-content: center;
    }


    #global-search-form {
        width: 100%;
    }


    .sidebar-nav {
        flex-direction: column;

        align-items: stretch;
    }


    .sidebar-main {
        width: 100%;

        flex-direction: column;
    }


    .sidebar-admin {
        width: 100%;

        flex-direction: column;

        margin-top: 8px;

        padding-top: 8px;

        border-top: 1px solid #dee2e6;
    }


    .sidebar-link {
        width: 100%;
    }


    .footer {
        font-size: 13px;
    }

    /* =========================================================
    ANCORAGGIO DOCENTE
    ========================================================= */

    .docente-anchor {
        scroll-margin-top: 95px;
    }

    /* =========================================================
   SUPPORTO HEADER STICKY TABELLE
   ========================================================= */

    /*
    * Desktop:
    * la topbar è fixed e alta 72px.
    *
    * Le tabelle sticky devono quindi fermarsi
    * immediatamente SOTTO la topbar.
    */
    :root {
        --sticky-page-top: var(--topbar-height);
    }


    /*
    * IMPORTANTISSIMO:
    * questi contenitori NON devono diventare
    * contenitori di scroll verticale.
    */
    .app-wrapper,
    .page-content,
    #page-content {
        overflow: visible;
    }


    /*
    * Su mobile la topbar non è più fixed.
    * Quindi lo sticky può tornare a top: 0.
    */
    @media (max-width: 768px) {

        :root {
            --sticky-page-top: 0px;
        }

    }
}