/* =========================================================
   CoParentManager - Sidebar applicazione reale
   Desktop: persistente. Mobile/tablet: offcanvas.
   Professionisti: blu navy. Famiglia: verde.
   ========================================================= */

:root {
    --cpm-sidebar-width: 292px;
    --cpm-sidebar-topbar-height: 58px;
    --cpm-sidebar-professional: #173b5a;
    --cpm-sidebar-professional-deep: #102f49;
    --cpm-sidebar-professional-accent: #4ea8de;
    --cpm-sidebar-family: #176047;
    --cpm-sidebar-family-deep: #104b38;
    --cpm-sidebar-family-accent: #63d5a4;
}

.app-layout-content {
    min-width: 0;
    transition: margin-left .22s ease;
}

.app-sidebar-topbar {
    min-height: var(--cpm-sidebar-topbar-height);
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .05);
    position: sticky;
    top: 0;
    z-index: 1042;
}

.app-sidebar-topbar-inner {
    min-height: var(--cpm-sidebar-topbar-height);
    width: 100%;
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) 52px;
    align-items: center;
    padding: 0 1rem;
}

.app-sidebar-topbar-left,
.app-sidebar-topbar-center,
.app-sidebar-topbar-right {
    display: flex;
    align-items: center;
}

.app-sidebar-topbar-left { justify-content: flex-start; }
.app-sidebar-topbar-center { justify-content: center; min-width: 0; }
.app-sidebar-topbar-right { justify-content: flex-end; }

.app-sidebar-brand {
    font-weight: 800;
    color: #0f6f91;
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: .01em;
}

.app-sidebar-brand:hover { color: #0b5874; }

.app-sidebar-toggle {
    width: 42px;
    height: 38px;
    padding: 6px 8px;
    border: 1px solid rgba(15, 23, 42, .16);
    border-radius: .6rem;
    background: transparent;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
}

.app-sidebar-toggle:hover { background: #f8fafc; }
.app-sidebar-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 .15rem rgba(21, 124, 163, .22);
}

.app-sidebar-toggler-line {
    display: block;
    width: 22px;
    height: 2px;
    background: rgba(15, 23, 42, .76);
    border-radius: 2px;
}

.app-sidebar-notif-btn {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: .6rem;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.app-sidebar-notif-btn:hover { background: #eef2f7; }
.app-sidebar-notif-btn::after { display: none; }

.app-sidebar-wrapper {
    position: fixed;
    inset: 0;
    z-index: 3000;
    pointer-events: none;
}

.app-sidebar-wrapper.open { pointer-events: auto; }

.app-sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, .48);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .22s ease, visibility .22s ease;
    z-index: 3001;
}

.app-sidebar-wrapper.open .app-sidebar-overlay {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--cpm-sidebar-width);
    max-width: 88vw;
    height: 100vh;
    background: #fff;
    color: #334155;
    z-index: 3002;
    transform: translateX(-100%);
    transition: transform .22s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: 3px 0 22px rgba(2, 6, 23, .22);
}

.app-sidebar-wrapper.open .app-sidebar { transform: translateX(0); }
body.app-sidebar-open { overflow: hidden; }

aside.app-sidebar.app-sidebar--professional {
    background: linear-gradient(180deg, var(--cpm-sidebar-professional) 0%, var(--cpm-sidebar-professional-deep) 100%) !important;
    color: #fff !important;
}

aside.app-sidebar.app-sidebar--family {
    background: linear-gradient(180deg, var(--cpm-sidebar-family) 0%, var(--cpm-sidebar-family-deep) 100%) !important;
    color: #fff !important;
}

.app-sidebar-header {
    padding: 1.15rem 1.25rem 1rem;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, .14);
}

.app-sidebar:not(.app-sidebar--professional):not(.app-sidebar--family) .app-sidebar-header {
    background: #f8fafc;
    border-bottom-color: #e5e7eb;
}

.app-sidebar-kicker {
    font-size: .67rem;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
    opacity: .72;
    margin-bottom: .35rem;
}

.app-sidebar-title {
    font-size: 1.03rem;
    font-weight: 800;
    line-height: 1.25;
}

.app-sidebar-role {
    margin-top: .3rem;
    font-size: .82rem;
    opacity: .78;
}

.app-sidebar-close {
    border: 1px solid rgba(255,255,255,.2);
    background: rgba(255,255,255,.1);
    color: inherit;
    width: 34px;
    height: 34px;
    border-radius: .55rem;
    flex: 0 0 auto;
}

.app-sidebar:not(.app-sidebar--professional):not(.app-sidebar--family) .app-sidebar-close {
    color: #334155;
    border-color: #dbe2ea;
    background: #fff;
}

.app-sidebar-user-info {
    padding: .9rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,.12);
}

.app-sidebar:not(.app-sidebar--professional):not(.app-sidebar--family) .app-sidebar-user-info {
    border-bottom-color: #e5e7eb;
}

.app-sidebar-user-name {
    font-weight: 700;
    font-size: .87rem;
    line-height: 1.25;
}

.app-sidebar-user-email {
    margin-top: .2rem;
    font-size: .72rem;
    opacity: .66;
    overflow-wrap: anywhere;
}

.app-sidebar-nav { padding: .4rem 0 1rem; }

.app-sidebar-section-title {
    padding: 1.05rem 1.25rem .38rem;
    font-size: .66rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .1em;
    opacity: .62;
}

.app-sidebar-link,
.app-sidebar-sublink,
.app-sidebar-nested-link {
    width: calc(100% - 1rem);
    margin: .08rem .5rem;
    border: 0;
    background: transparent;
    display: flex;
    align-items: center;
    gap: .66rem;
    text-decoration: none;
    text-align: left;
    border-radius: .62rem;
    color: inherit;
    transition: background .16s ease, color .16s ease, transform .16s ease;
}

.app-sidebar-link {
    padding: .66rem .78rem;
    font-weight: 600;
    font-size: .91rem;
}

.app-sidebar-sublink {
    padding: .52rem .78rem .52rem 2.1rem;
    font-weight: 500;
    font-size: .84rem;
    opacity: .9;
}

.app-sidebar-nested-link {
    padding: .5rem .78rem .5rem 3.2rem;
    font-size: .82rem;
}

.app-sidebar--professional .app-sidebar-link:hover,
.app-sidebar--professional .app-sidebar-sublink:hover,
.app-sidebar--professional .app-sidebar-nested-link:hover,
.app-sidebar--family .app-sidebar-link:hover,
.app-sidebar--family .app-sidebar-sublink:hover,
.app-sidebar--family .app-sidebar-nested-link:hover {
    background: rgba(255,255,255,.1);
    color: #fff;
}

.app-sidebar:not(.app-sidebar--professional):not(.app-sidebar--family) .app-sidebar-link:hover,
.app-sidebar:not(.app-sidebar--professional):not(.app-sidebar--family) .app-sidebar-sublink:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.app-sidebar--professional .app-sidebar-link.active,
.app-sidebar--professional .app-sidebar-sublink.active {
    background: #fff;
    color: #173b5a;
    font-weight: 750;
    box-shadow: 0 4px 14px rgba(0,0,0,.1);
}

.app-sidebar--family .app-sidebar-link.active,
.app-sidebar--family .app-sidebar-sublink.active {
    background: #fff;
    color: #14523e;
    font-weight: 750;
    box-shadow: 0 4px 14px rgba(0,0,0,.1);
}

.app-sidebar:not(.app-sidebar--professional):not(.app-sidebar--family) .active {
    background: #eef2ff;
    color: #3730a3;
    font-weight: 700;
}

.app-sidebar-action {
    cursor: pointer;
    font: inherit;
}

.app-sidebar-status {
    display: block;
    padding: 0 1.25rem .3rem 2.6rem;
    font-size: .68rem;
    opacity: .68;
}

.app-sidebar-divider {
    height: 1px;
    background: rgba(255,255,255,.13);
    margin: .8rem 1rem;
}

.app-sidebar:not(.app-sidebar--professional):not(.app-sidebar--family) .app-sidebar-divider {
    background: #e5e7eb;
}

.app-sidebar-logout {
    color: #ffd2d7 !important;
    margin-top: .2rem;
}

.app-sidebar-logout:hover {
    background: rgba(220,53,69,.18) !important;
    color: #fff !important;
}

.app-sidebar .disabled-sub {
    opacity: .42 !important;
}

/* Mantiene compatibilità con eventuali sottomenu ancora presenti altrove. */
.app-sidebar-menu-button { cursor: pointer; }
.app-sidebar-chevron { margin-left: auto; transition: transform .2s ease; }
.app-sidebar-menu-button[aria-expanded="true"] .app-sidebar-chevron { transform: rotate(180deg); }
.app-sidebar-submenu,
.app-sidebar-submenu-nested {
    max-height: 0;
    overflow: hidden;
    transition: max-height .22s ease;
}
.app-sidebar-submenu.open { max-height: 1000px; }
.app-sidebar-submenu-nested.open { max-height: 400px; }

@media (min-width: 992px) {
    body.app-sidebar-desktop .app-sidebar-topbar {
        margin-left: var(--cpm-sidebar-width);
        width: calc(100% - var(--cpm-sidebar-width));
    }

    body.app-sidebar-desktop .app-layout-content {
        margin-left: var(--cpm-sidebar-width);
    }

    .app-sidebar-wrapper[data-authenticated="true"] {
        top: 0;
        right: auto;
        bottom: 0;
        left: 0;
        width: var(--cpm-sidebar-width);
        height: 100vh;
        pointer-events: auto;
        z-index: 1051;
    }

    .app-sidebar-wrapper[data-authenticated="true"] .app-sidebar-overlay {
        display: none !important;
    }

    .app-sidebar-wrapper[data-authenticated="true"] .app-sidebar {
        top: 0;
        width: var(--cpm-sidebar-width);
        max-width: none;
        height: 100vh;
        transform: translateX(0) !important;
        z-index: 1052;
        box-shadow: 2px 0 15px rgba(2, 6, 23, .12);
    }

    .app-sidebar-wrapper[data-authenticated="true"] .app-sidebar-close,
    body.app-sidebar-desktop .app-sidebar-toggle {
        display: none;
    }

    body.app-sidebar-desktop.app-sidebar-open {
        overflow: auto;
    }
}

@media (max-width: 991.98px) {
    .app-layout-content { margin-left: 0 !important; }

    /*
     * Mobile / PWA: usa l'altezza realmente visibile della viewport.
     * 100vh può includere l'area occupata dalle barre del browser/PWA e
     * lasciare le ultime voci (es. Logout) fuori dalla zona raggiungibile.
     */
    .app-sidebar {
        width: min(330px, 88vw);
        height: 100vh;
        height: 100dvh;
        max-height: 100dvh;
        overflow: hidden;
    }

    /* Header fisso nella sidebar; scorre soltanto l'elenco delle voci. */
    .app-sidebar-header {
        flex: 0 0 auto;
    }

    .app-sidebar-nav {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        touch-action: pan-y;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }
}

@media (max-width: 420px) {
    .app-sidebar-topbar-inner { padding: 0 .7rem; }
    .app-sidebar-brand { font-size: .95rem; }
}
