/* Struttura del portale: spazio costante per le etichette, contenuto libero di restringersi. */
.portal-shell {
    display: grid;
    grid-template-columns: 304px minmax(0, 1fr);
    min-height: 100vh;
}

.portal-sidebar {
    background: var(--portal-sidebar) !important;
    border-right: 1px solid var(--portal-sidebar-line);
    color: var(--portal-ink);
    min-width: 0;
}

.portal-sidebar-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.portal-sidebar-header { flex-shrink: 0; padding: 24px 20px 18px; }
.portal-sidebar-brand { align-items: center; display: flex; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.portal-sidebar .portal-brand-copy > span { color: var(--portal-sidebar-muted); }
.portal-sidebar .portal-sidebar-label { color: var(--portal-sidebar-muted); font-size: 9px; font-weight: 700; letter-spacing: 1px; }
.portal-menu-close { display: none; }
.portal-mobile-header { display: none; }

.portal-skip-link {
    background: #fff;
    border: 2px solid var(--portal-brand);
    border-radius: 8px;
    color: var(--portal-brand-dark);
    left: 12px;
    padding: 10px 16px;
    position: fixed;
    top: 12px;
    transform: translateY(-160%);
    z-index: 1080;
}

.portal-skip-link:focus { transform: none; }
.portal-sidebar :is(a, button, select):focus-visible,
.portal-menu-button:focus-visible { outline: 3px solid #8c83de; outline-offset: 2px; }

/* Il contesto precede le azioni: un solo selettore, sempre riferito agli spazi assegnati. */
.portal-space-context { background: #f8f8fc; border: 1px solid var(--portal-sidebar-line); border-radius: 12px; padding: 12px; }
.portal-space-context > .portal-sidebar-label { display: block; margin-bottom: 5px; }
.portal-space-context > strong { display: block; font-size: 13px; font-weight: 650; line-height: 1.5; overflow-wrap: anywhere; }
.portal-workspace-switcher { min-width: 0; }
.portal-workspace-switcher label { display: block; margin-bottom: 8px; }
.portal-workspace-switcher .form-select { border-color: #d9d4e9; font-size: 13px; font-weight: 600; min-height: 42px; padding-left: 10px; width: 100%; }
.portal-workspace-switcher small { color: var(--portal-sidebar-muted); display: block; font-size: 10px; line-height: 1.5; margin-top: 7px; }

/* I contenuti di uso quotidiano hanno più risalto; le altre funzioni restano raggruppate. */
.portal-navigation { display: grid; gap: 20px; min-height: 0; overflow-y: auto; padding: 0 12px 20px; scrollbar-width: thin; }
.portal-nav-group { display: grid; gap: 3px; }
.portal-nav-group > .portal-sidebar-label { display: block; margin: 0 10px 4px; }
.portal-nav-primary { background: #f7f6fd; border: 1px solid #edeafa; border-radius: 14px; padding: 12px 0 4px; }
.portal-nav-primary > .portal-sidebar-label { color: #665399; }
.portal-nav-link {
    align-items: flex-start;
    border: 1px solid transparent;
    border-radius: 10px;
    color: #39364a;
    display: flex;
    gap: 10px;
    min-height: 58px;
    padding: 10px;
    text-decoration: none;
    transition: background-color .15s, border-color .15s;
}

.portal-nav-symbol { align-items: center; color: #7c728f; display: flex; flex: 0 0 30px; height: 30px; justify-content: center; border-radius: 9px; }
.portal-nav-symbol .portal-content-icon { height: 20px; width: 20px; }
.portal-nav-primary .portal-nav-symbol { background: #ece8fa; color: #6e58ae; }
.portal-nav-copy { min-width: 0; }
.portal-nav-copy strong { display: block; font-size: 13px; font-weight: 650; line-height: 1.4; }
.portal-nav-copy small { color: var(--portal-sidebar-muted); display: block; font-size: 11px; line-height: 1.5; margin-top: 3px; }
.portal-nav-link:hover { background: #eae5f4; color: #312847; }
.portal-nav-link.active { background: #e4def5; border-color: #d0c5ed; box-shadow: inset 3px 0 0 #6552bc; color: #3f2f7b; }
.portal-nav-link.active .portal-nav-symbol { background: #6552bc; color: #fff; }
.portal-nav-link.active .portal-nav-copy small { color: #675782; }

/* L'account resta raggiungibile anche quando il menu richiede uno scorrimento. */
.portal-sidebar-account { align-items: center; border-top: 1px solid var(--portal-sidebar-line); display: flex; flex-shrink: 0; gap: 10px; margin-top: auto; padding: 16px; }
.portal-account-avatar { align-items: center; background: #e6dff4; border-radius: 50%; color: #67549d; display: flex; flex: 0 0 34px; font-size: 13px; font-weight: 700; height: 34px; justify-content: center; }
.portal-account-copy { flex: 1; min-width: 0; }
.portal-account-copy strong { display: block; font-size: 12px; font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
.portal-account-copy small { color: var(--portal-sidebar-muted); display: block; font-size: 10px; margin-top: 2px; }
.portal-logout { align-items: center; background: transparent; border: 0; border-radius: 8px; color: #766985; display: flex; flex-direction: column; font-size: 10px; gap: 2px; justify-content: center; min-height: 44px; min-width: 44px; padding: 5px; }
.portal-logout .portal-content-icon { height: 18px; width: 18px; }
.portal-logout:hover { background: #f2eef8; color: #49376a; }

@media (min-width: 992px) {
    .portal-sidebar { align-self: start; height: 100vh; height: 100dvh; position: sticky; top: 0; }
}

/* Bootstrap gestisce il pannello mobile e la tastiera; i contenuti non finiscono sotto un lungo menu. */
@media (max-width: 991.98px) {
    .portal-shell { display: block; min-height: 0; }
    .portal-sidebar { --bs-offcanvas-width: 320px; height: 100vh; height: 100dvh; max-width: calc(100vw - 28px); }
    .portal-sidebar-header { padding-top: 20px; }
    .portal-menu-close { display: block; flex-shrink: 0; min-height: 24px; min-width: 24px; padding: 10px; }
    .portal-mobile-header { background: var(--portal-sidebar); border-bottom: 1px solid var(--portal-sidebar-line); display: block; padding: 16px 20px 12px; position: sticky; top: 0; z-index: 1020; }
    .portal-mobile-heading { align-items: center; display: flex; gap: 12px; justify-content: space-between; }
    .portal-mobile-heading .portal-brand-mark { flex-basis: 36px; height: 36px; width: 36px; }
    .portal-mobile-heading .portal-brand { gap: 9px; }
    .portal-mobile-heading .portal-brand-copy strong { font-size: 18px; }
    .portal-mobile-heading .portal-brand-copy > span { color: var(--portal-sidebar-muted); font-size: 10px; margin-top: 1px; }
    .portal-menu-button { align-items: center; background: #f7f5fd; border: 1px solid #e3ddf1; border-radius: 10px; color: #594387; display: flex; flex-shrink: 0; font-size: 13px; font-weight: 600; gap: 7px; min-height: 44px; padding: 9px 12px; }
    .portal-menu-button .portal-content-icon { height: 18px; width: 18px; }
    .portal-mobile-space { align-items: flex-start; color: var(--portal-sidebar-muted); display: flex; font-size: 11px; gap: 7px; line-height: 1.5; margin-top: 12px; }
    .portal-mobile-space .portal-content-icon { height: 16px; width: 16px; }
    .portal-mobile-space span { min-width: 0; overflow-wrap: anywhere; }
    .portal-mobile-space strong { color: #4b405d; font-weight: 600; }
    #portal-main { scroll-margin-top: 120px; }
}

@media (prefers-reduced-motion: reduce) {
    .portal-nav-link { transition: none; }
}
