.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Sidebar (Top Navbar) */
.sidebar {
    background-color: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 1.5rem;
    display: flex;
    flex-direction: row;
    align-items: center;
    position: sticky;
    top: 0;
    width: 100%;
    z-index: 1000;
    overflow-x: auto;
    overflow-y: hidden;
    box-sizing: border-box;
}

/* Scrollbar minimalista para el Sidebar */
.sidebar::-webkit-scrollbar {
    width: 5px;
}
.sidebar::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 10px;
}
.sidebar::-webkit-scrollbar-thumb:hover {
    background: #cbd5e1;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-right: 2rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    box-shadow: var(--shadow-md);
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-menu {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.25rem;
}

.nav-section-title {
    display: none;
}

.sidebar-footer {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.25rem;
    margin-left: 1rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.9rem;
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
    white-space: nowrap;
}

.nav-item svg, .nav-item i {
    width: 18px;
    height: 18px;
    stroke-width: 1.75px;
    transition: transform 0.15s ease;
}

.nav-item:hover {
    background-color: var(--bg-hover);
    color: var(--primary);
}

.nav-item:active {
    transform: scale(0.97);
}

.nav-item.active {
    background-color: rgba(14, 165, 233, 0.1);
    color: var(--primary);
    font-weight: 600;
}

/* Main Content */
.main-content {
    padding: 2rem 3rem;
    max-width: 100%;
    margin: 0 auto;
    width: 100%;
    min-width: 0; /* Previene que hijos muy grandes (como tablas) rompan el layout */
    box-sizing: border-box;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    position: relative; /* Fix z-index stacking context for dropdown */
    z-index: 50; /* Ensure header dropdowns appear above main content */
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.btn-icon {
    color: var(--primary);
    padding: 0.5rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
}

.btn-logout-style {
    color: var(--accent);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem;
    border-radius: var(--radius-xl);
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

@media (max-width: 1024px) {
    .sidebar .logo-text, .sidebar span {
        display: none;
    }
    .sidebar {
        padding: 0.5rem;
    }
}

@media (max-width: 768px) {
    /* Asegurar que el layout se vea correcto en móvil */
    .app-container:not([style*="display: none"]):not([style*="display:none"]) {
        display: flex !important;
        flex-direction: column !important;
        width: 100%;
        max-width: 100vw;
        padding-bottom: 0;
    }
    
    /* Transform Sidebar into Top Navbar for mobile */
    .sidebar {
        position: sticky;
        top: 0;
        bottom: auto;
        left: 0;
        right: 0;
        height: 70px;
        width: 100%;
        padding: 0;
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        box-shadow: 0 4px 12px rgba(0,0,0,0.05);
        z-index: 1000;
        background: var(--bg-card);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }

    body.dark-theme .sidebar {
        background: rgba(31, 41, 55, 0.85);
    }

    .logo-container, .nav-section-title {
        display: none !important; 
    }

    .nav-menu {
        display: flex;
        flex-direction: row;
        flex: 1;
        overflow-x: auto;
        -ms-overflow-style: none;
        scrollbar-width: none;
        padding: 0 0.5rem;
        align-items: center;
        justify-content: flex-start;
    }
    
    .nav-menu::-webkit-scrollbar {
        display: none;
    }

    .sidebar-footer {
        display: flex;
        align-items: center;
        padding-right: 0.5rem;
    }

    .nav-item {
        flex-direction: column;
        gap: 0.25rem;
        padding: 0.5rem 0.25rem; /* Ajustado el padding para maximizar espacio */
        margin-bottom: 0;
        flex: 1;
        min-width: 66px; /* Reducido levemente para evitar cortes drásticos */
        justify-content: center;
        border-radius: var(--radius-sm);
    }

    .nav-item i {
        font-size: 1.25rem;
        margin: 0;
        display: block !important;
    }

    .sidebar .nav-item span {
        display: block;
        font-size: 0.58rem; /* Reducido tamaño de letra para encajar palabras largas */
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        width: 100%;
        font-weight: 600;
    }

    /* Main Content adjustments */
    .main-content {
        padding: 1rem;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start !important;
        margin-bottom: 1.5rem;
    }
    
    .header h2 {
        font-size: 1.25rem; /* Prevent huge text from wrapping awkwardly */
    }

    .header > div:last-child {
        width: 100%;
        justify-content: space-between;
    }
    
    .header-actions {
        width: 100%;
        justify-content: space-between;
    }
}

/* Split-screen Login Mobile Hide */
@media (min-width: 992px) {
    .login-branding {
        display: flex !important;
    }
}
