/* ==================== */
/* SIDEBAR DASHBOARD */
/* ==================== */

:root {
    --sidebar-width: 64px;
    --sidebar-width-expanded: 232px;
}

body.is-sidebar-expanded {
    --sidebar-width: var(--sidebar-width-expanded);
}

.sidebar-dashboard {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background: var(--background-alt);
    display: flex;
    flex-direction: column;
    z-index: 90;
    transition: width 0.18s ease;
    overflow: hidden;
}

.sidebar-nav {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 999px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-item {
    position: relative;
}

.sidebar-separator {
    height: 1px;
    margin: 6px 12px;
    background: var(--border-color);
}

/* ==================== */
/* LINK */
/* ==================== */

.sidebar-link {
    width: 100%;
    height: 64px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0;
    color: var(--primary-color);
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.2s ease, color 0.2s ease;
}

.sidebar-link__icon {
    flex: 0 0 64px;
    width: 64px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sidebar-link__label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.9375rem;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.14s ease;
    pointer-events: none;
}

.sidebar-link:hover {
    color: var(--primary-hover);
}

/* ==================== */
/* STATO ESPANSO */
/* ==================== */

body.is-sidebar-expanded .sidebar-link__label {
    opacity: 1;
    padding-right: 14px;
}

body.is-sidebar-expanded .sidebar-tooltip {
    display: none;
}

/* ==================== */
/* STATO ATTIVO */
/* ==================== */

.sidebar-link.is-active {
    background: var(--background-active);
    color: var(--primary-color);
}

.sidebar-link.is-active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 12px;
    bottom: 12px;
    width: 3px;
    background: var(--primary-color);
    border-radius: 0 4px 4px 0;
}

/* ==================== */
/* PIN */
/* ==================== */

.sidebar-pin-badge {
    position: absolute;
    top: 10px;
    right: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--background-active);
    color: var(--primary-color);
    pointer-events: none;
}

body:not(.is-sidebar-expanded) .sidebar-pin-badge {
    top: 6px;
    right: 4px;
}

/* Con la sidebar espansa il pin e' ridondante: la voce sta gia' nel gruppo in alto. */
body.is-sidebar-expanded .sidebar-pin-badge {
    display: none;
}

.sidebar-context-menu {
    position: fixed;
    z-index: 200;
    min-width: 190px;
    padding: 6px;
    background: var(--background-alt);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.sidebar-context-menu[hidden] {
    display: none;
}

.sidebar-context-menu__item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: var(--radius-sm, 8px);
    background: transparent;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

.sidebar-context-menu__item:hover {
    background: var(--background-active);
    color: var(--primary-color);
}

/* ==================== */
/* TOGGLE */
/* ==================== */

.sidebar-toggle {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    height: 56px;
    padding: 0;
    border: 0;
    border-top: 1px solid var(--border-color);
    background: transparent;
    color: var(--primary-color);
    cursor: pointer;
    white-space: nowrap;
}

.sidebar-toggle:hover {
    background: var(--background-active);
    color: var(--primary-hover);
}

.sidebar-toggle .sidebar-link__icon iconify-icon {
    transition: transform 0.18s ease;
}

body.is-sidebar-expanded .sidebar-toggle .sidebar-link__icon iconify-icon {
    transform: rotate(180deg);
}

/* ==================== */
/* TOOLTIP */
/* ==================== */

/* Fixed sul body: la nav scrollabile ritaglierebbe un tooltip in position absolute. */
.sidebar-tooltip {
    position: fixed;
    transform: translateY(-50%);
    background: var(--primary-color);
    color: var(--background-alt);
    padding: 6px 12px;
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: var(--shadow-md);
    z-index: 120;
}

.sidebar-tooltip[hidden] {
    display: none;
}

/* ==================== */
/* LAYOUT DASHBOARD */
/* ==================== */

.dashboard-layout {
    padding-left: var(--sidebar-width);
    transition: padding-left 0.18s ease;
}

/* ==================== */
/* MOBILE: NASCONDI SIDEBAR */
/* ==================== */

@media (max-width: 968px) {
    .sidebar-dashboard {
        display: none;
    }

    .dashboard-layout {
        padding-left: 0;
    }
}

/* Pallino col numero di cose da lavorare, sulla voce di menu.
   Col menu ridotto la voce e' solo un'icona: il numero si sposta in alto a
   destra, altrimenti sparirebbe proprio quando serve vederlo. */
.sidebar-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    margin-left: auto;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--primary-color);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
}

body:not(.is-sidebar-expanded) .sidebar-badge {
    position: absolute;
    /* In basso a destra: in alto c'è il pin delle voci fissate, e i due si
       coprivano a vicenda. */
    bottom: 6px;
    right: 6px;
    margin-left: 0;
    min-width: 18px;
    height: 18px;
    font-size: 0.68rem;
    box-shadow: 0 0 0 2px var(--background-alt, #fff);
}

/* Col menu aperto il numero sta subito dopo l'etichetta, lontano dal pin
   che vive nell'angolo in alto a destra. */
body.is-sidebar-expanded .sidebar-badge {
    margin-left: 8px;
    margin-right: 32px;
}

body:not(.is-sidebar-expanded) .sidebar-link {
    position: relative;
}
