/* --- Stile Menu Laterale Moderno e Responsivo --- */

/* --- Contenitore Principale --- */
.dashboard-container {
    display: flex;
    background-color: var(--light-bg);
}

/* --- Sidebar --- */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    padding: 24px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    z-index: 1100;
    overflow-y: auto; /* Permette lo scroll verticale */
    overflow-x: hidden; /* Nasconde lo scroll orizzontale */

    /* Stili per renderlo fisso, a tutta altezza e animato */
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transition: transform 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

/* --- Logo --- */
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px 24px 8px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    text-decoration: none;
    color: var(--text-color);
}

.sidebar-logo .logo-icon-img {
    width: 36px;
    height: 36px;
    border-radius: 8px;
}

.sidebar-logo .logo-icon {
    width: 36px;
    height: 36px;
    background-color: var(--primary-color);
    border-radius: 8px;
}

.sidebar-logo .logo-text {
    font-size: 1.25rem;
    font-weight: 600;
}

/* --- Project Sub Info (shown under active menu item on project pages) --- */
.sidebar-project-sub-info {
    padding: 8px 16px 12px 52px; /* Allinea con il testo del menu item (icona 24px + margin-right 16px + padding 12px) */
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-project-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary-color); /* Colore blu active solo sul nome del progetto */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.sidebar-project-section {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted); /* Colore normale per la sezione */
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.85;
}


/* --- Navigazione --- */
.sidebar-nav {
    flex-grow: 1;
    overflow-y: visible; /* Permette lo scroll normale */
    overflow-x: hidden;
    min-height: 0; /* Permette al flex item di ridursi */
}

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

.sidebar-nav-list a {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    margin: 4px 0;
    border-radius: 8px;
    text-decoration: none;
    color: var(--sidebar-text);
    font-weight: 500;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar-nav-list a:hover {
    background-color: var(--light-bg);
    color: var(--text-color);
}

.sidebar-nav-list a.active {
    background-color: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
}

.sidebar-nav-list a svg {
    margin-right: 16px;
    width: 20px;
    height: 20px;
    stroke-width: 2px;
}


/* --- Sezione Utente --- */
.sidebar-footer {
    padding-top: 16px;
    margin-top: auto; /* Spinge il footer verso il basso */
    border-top: 1px solid var(--border-color);
    flex-shrink: 0; /* Previene la compressione del footer */
    position: relative; /* Footer normale - permette scroll */
    background-color: var(--sidebar-bg);
}

/* --- Sezione Premium Upgrade --- */
.premium-upgrade-section {
    display: block;
    text-decoration: none;
    margin-bottom: 16px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    box-shadow: 0 3px 12px rgba(102, 126, 234, 0.25);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.premium-upgrade-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.05) 100%);
    pointer-events: none;
}

.premium-upgrade-section:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.premium-upgrade-content {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    z-index: 1;
}

.premium-icon {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.premium-icon svg {
    color: white;
    width: 18px;
    height: 18px;
}

.premium-text {
    flex: 1;
    min-width: 0;
}

.premium-title {
    color: white;
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.premium-subtitle {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.875rem;
    font-weight: 400;
}

.premium-arrow {
    color: rgba(255, 255, 255, 0.6);
    transition: transform 0.2s ease;
}

.premium-upgrade-section:hover .premium-arrow {
    transform: translateX(4px);
}

    .footer-divider {
        height: 1px;
        background: var(--border-color);
        margin: 16px 0;
    }

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    width: 100%;
    box-sizing: border-box;
}

/* Layout mobile per user profile e logout */
@media (max-width: 992px) {
    .sidebar-footer {
        padding-top: 12px;
        margin-top: 12px;
    }
    
    .premium-upgrade-section {
        padding: 8px 12px; /* Ridotto padding verticale da 12px a 8px */
        margin-bottom: 8px;
        min-height: auto; /* Rimuove altezza minima */
        height: auto; /* Altezza automatica */
    }
    
    .footer-divider {
        margin: 8px 0;
    }
    
    .premium-upgrade-content {
        gap: 8px; /* Ridotto gap da 10px a 8px */
        align-items: center; /* Assicura allineamento verticale */
        min-height: auto; /* Rimuove altezza minima */
    }
    
    .premium-icon {
        width: 28px; /* Ridotto da 36px a 28px */
        height: 28px; /* Ridotto da 36px a 28px */
    }
    
    .premium-icon svg {
        width: 14px; /* Ridotto da 18px a 14px */
        height: 14px; /* Ridotto da 18px a 14px */
    }
    
    .premium-title {
        font-size: 0.8rem; /* Ridotto da 0.9rem a 0.8rem */
    }
    
    .premium-subtitle {
        font-size: 0.75rem; /* Ridotto da 0.8rem a 0.75rem */
    }
    
    /* Layout compatto per user profile e logout su mobile - UNA SOLA RIGA */
    .user-profile {
        width: 100% !important;
        margin-bottom: 4px !important;
        padding: 8px 12px !important;
        background-color: var(--light-bg) !important;
        border-radius: 8px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 8px !important;
        flex-direction: row !important;
    }
    
    .user-info {
        flex: 1 !important;
        min-width: 0 !important;
        display: flex !important;
        align-items: center !important;
    }
    
    .user-info .user-name {
        display: none !important; /* Nasconde il nome su mobile per risparmiare spazio */
    }
    
    .user-info .user-email {
        font-size: 0.8rem !important;
        color: var(--text-muted) !important;
        max-width: 140px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        line-height: 1.2 !important;
        vertical-align: middle !important;
        display: block !important; /* Assicura che l'email sia visibile anche su mobile */
    }
    
    /* Nasconde il logout button desktop su mobile */
    .logout-btn-desktop {
        display: none !important;
    }
    
    /* Logout button mobile sulla stessa riga dell'email */
    .logout-btn-mobile {
        width: auto !important;
        margin-top: 0 !important;
        margin-left: 0 !important;
        padding: 6px 8px !important;
        min-width: auto !important;
        height: auto !important;
        justify-content: center !important;
        border-radius: 6px !important;
        font-size: 0.8rem !important;
        align-items: center !important;
        flex-shrink: 0 !important;
        background-color: var(--danger-color) !important;
        color: white !important;
        border: none !important;
        gap: 0 !important;
        display: flex !important;
    }
    
    .logout-btn-mobile:hover {
        background-color: #d32f2f !important;
        transform: none !important;
    }
    
    .logout-btn-mobile svg {
        width: 16px !important;
        height: 16px !important;
        margin-right: 0 !important;
        vertical-align: middle !important;
    }
    
    .logout-btn-mobile span {
        display: none !important; /* Nasconde il testo "Logout" su mobile */
    }
}

.user-profile:hover {
    background-color: var(--light-bg);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.user-info {
    flex: 1;
    min-width: 0; /* Permette al contenuto di comprimersi */
}

.user-info .user-name {
    font-weight: 600;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.user-info .user-email {
    font-size: 0.875rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block; /* Assicura che l'email sia visibile su desktop */
}

/* Desktop: assicura che l'email sia sempre visibile */
@media (min-width: 993px) {
    .user-info .user-email {
        display: block !important;
        font-size: 0.875rem;
        color: var(--text-muted);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }
    
    .user-info .user-name {
        display: block !important;
        font-weight: 600;
        color: var(--text-color);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }
}


#logout-btn {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    margin-top: 12px;
    padding: 12px 16px;
    background: none;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    color: var(--danger-color);
    cursor: pointer;
    text-align: left;
    gap: 16px;
}

/* Desktop: logout button separato */
@media (min-width: 993px) {
    /* Nasconde il logout button mobile su desktop */
    .logout-btn-mobile {
        display: none !important;
    }
    
    /* Mostra il logout button desktop */
    .logout-btn-desktop {
        display: flex !important;
        align-items: center;
        justify-content: flex-start;
        width: 100%;
        margin-top: 12px;
        padding: 12px 16px;
        background: none;
        border: none;
        border-radius: 8px;
        font-size: 1rem;
        color: var(--danger-color);
        cursor: pointer;
        text-align: left;
        gap: 16px;
    }
    
    .logout-btn-desktop span {
        display: inline; /* Mostra il testo "Logout" su desktop */
    }
    
    /* Desktop: layout normale per user profile */
    .user-profile {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 8px;
        border-radius: 8px;
        transition: background-color 0.2s ease;
        width: 100%;
        box-sizing: border-box;
        flex-direction: row; /* Layout orizzontale su desktop */
    }
    
    .user-info {
        flex: 1;
        min-width: 0;
        display: block; /* Layout normale su desktop */
    }
}

#logout-btn:hover {
    background-color: #fce8e6;
}

/* Stili mobile per il pulsante logout */
@media (max-width: 992px) {
    #logout-btn {
        width: auto;
        margin-top: 0;
        padding: 6px 8px;
        min-width: auto;
        height: auto;
        justify-content: center;
        border-radius: 6px;
        font-size: 0.8rem;
        align-self: center;
        display: flex;
        align-items: center;
    }
    
    #logout-btn span {
        display: none; /* Nasconde il testo "Logout" su mobile per risparmiare spazio */
    }
    
    #logout-btn svg {
        margin-right: 0; /* Rimuove il margine dell'icona su mobile */
        width: 16px;
        height: 16px;
    }
}

/* --- Bottone Hamburger e Overlay (per mobile) --- */
.hamburger-btn {
    display: none; /* Nascosto di default su desktop */
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1200;
    width: 44px;
    height: 44px;
    background-color: var(--white);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: transform 0.4s cubic-bezier(0.23, 1, 0.32, 1); /* Transizione fluida */
}

.hamburger-btn svg {
    transition: opacity 0.3s ease;
}

.hamburger-btn .close-icon {
    display: none;
}

.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1099;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.mobile-menu-overlay.visible {
    display: block;
    opacity: 1;
}

/* --- Media Queries per la Responsività --- */

/* Tablet e Mobile */
@media (max-width: 992px) {
    .sidebar {
        /* Su mobile, il menu è nascosto di default fuori dallo schermo */
        transform: translateX(-100%);
        box-shadow: 0 0 25px rgba(0,0,0,0.2);
        /* Aggiunge scroll verticale per mobile */
        overflow-y: auto;
        overflow-x: hidden;
        /* Layout normale per mobile - permette scroll completo */
        display: flex;
        flex-direction: column;
        /* Permette lo scroll su mobile */
        -webkit-overflow-scrolling: touch; /* Scroll fluido su iOS */
        /* Assicura che tutto il contenuto sia scrollabile */
        height: 100vh;
        max-height: 100vh;
        /* Aggiunge padding bottom per evitare sovrapposizione con URL bar */
        padding-bottom: 20px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .hamburger-btn {
        display: flex;
    }

    /* Sposta l'hamburger quando il menu è aperto */
    .sidebar.open ~ .hamburger-btn {
        transform: translateX(200px);
    }
    
    /* Scambia le icone quando il menu è aperto */
    .sidebar.open ~ .hamburger-btn .hamburger-icon {
        display: none;
    }

    .sidebar.open ~ .hamburger-btn .close-icon {
        display: block;
    }

    /* Footer mobile normale - permette lo scroll */
    .sidebar-footer {
        margin-top: auto !important;
        position: relative !important;
        background-color: var(--sidebar-bg) !important;
        padding-bottom: 40px !important; /* Aumentato da 24px a 40px per evitare sovrapposizione con URL bar */
        border-top: 1px solid var(--border-color) !important;
    }
    
    /* Forza il layout mobile per user profile */
    .user-profile-link {
        display: block !important;
        width: 100% !important;
    }
    
    .user-profile-link .user-profile {
        width: 100% !important;
        margin-bottom: 4px !important;
        padding: 8px 12px !important;
        background-color: var(--light-bg) !important;
        border-radius: 8px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 8px !important;
        flex-direction: row !important;
    }
    
    /* Aggiunge spazio extra per evitare sovrapposizione con URL bar */
    .sidebar-nav {
        padding-bottom: 10px !important;
    }
    
    /* Mobile: Project sub info styling */
    .sidebar-project-sub-info {
        padding: 6px 12px 10px 48px; /* Ridotto padding su mobile */
    }
    
    .sidebar-project-name {
        font-size: 0.8rem;
    }
    
    .sidebar-project-section {
        font-size: 0.65rem;
    }
}

/* Phone-only tweaks: user/email+logout subito sotto al logo; lista nav scrolla */
@media (max-width: 768px) {
    .sidebar {
        display: flex;
        flex-direction: column;
    }
    /* Porta il footer subito sotto al logo su mobile stretto */
    .sidebar-footer {
        order: 1;
        margin-top: 0 !important;
        display: flex;
        flex-direction: column;
    }
    /* La navigazione viene dopo e diventa scrollabile */
    .sidebar-nav {
        order: 2;
        flex: 1 1 auto;
        overflow-y: auto;
        min-height: 0;
    }
    /* Ordina i contenuti del footer: prima profilo, poi premium */
    .user-profile-link {
        order: 1;
    }
    .premium-upgrade-section {
        order: 2;
    }
    .footer-divider {
        order: 3;
    }
    /* L'email può usare tutta la larghezza disponibile */
    .user-info .user-email {
        max-width: 100% !important;
    }
}