/* ============================================
   SIDEBAR - SISTEMA DE NAVEGACIÓN LATERAL
   ============================================ */

:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 72px;
    --sidebar-bg: linear-gradient(180deg, #1e3a5f 0%, #0f1c2e 100%);
    --sidebar-text: rgba(255, 255, 255, 0.85);
    --sidebar-text-muted: rgba(255, 255, 255, 0.5);
    --sidebar-hover: rgba(255, 255, 255, 0.08);
    --sidebar-active: rgba(16, 185, 129, 0.2);
    --sidebar-active-border: #10b981;
    --sidebar-transition: 0.25s ease;
    --header-height: 64px;
}

/* ============================================
   LAYOUT BASE
   ============================================ */

body.has-sidebar {
    background: #f1f5f9;
    min-height: 100vh;
}

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

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: width var(--sidebar-transition);
    overflow: hidden;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* ============================================
   SIDEBAR HEADER
   ============================================ */

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    min-height: 70px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    overflow: hidden;
}

.sidebar-logo-img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    flex-shrink: 0;
}

.sidebar-logo-text {
    font-size: 1.4rem;
    font-weight: 700;
    color: white;
    white-space: nowrap;
    transition: opacity var(--sidebar-transition);
}

.logo-highlight {
    color: #10b981;
}

.sidebar.collapsed .sidebar-logo-text {
    opacity: 0;
    width: 0;
}

.sidebar-toggle-inner {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--sidebar-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--sidebar-transition);
    flex-shrink: 0;
}

.sidebar-toggle-inner:hover {
    background: rgba(255, 255, 255, 0.15);
}

.sidebar-toggle-inner i {
    transition: transform var(--sidebar-transition);
}

.sidebar.collapsed .sidebar-toggle-inner i {
    transform: rotate(180deg);
}

.sidebar.collapsed .sidebar-toggle-inner {
    margin: 0 auto;
}

/* ============================================
   SIDEBAR NAVIGATION
   ============================================ */

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 12px;
}

/* Scrollbar personalizada */
.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

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

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Secciones */
.sidebar-section {
    margin-bottom: 24px;
}

.sidebar-section-title {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--sidebar-text-muted);
    padding: 0 12px;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--sidebar-transition);
}

.sidebar.collapsed .sidebar-section-title {
    opacity: 0;
    height: 0;
    margin: 0;
    padding: 0;
}

/* Links de navegación */
.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 10px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all var(--sidebar-transition);
    position: relative;
    margin-bottom: 4px;
    white-space: nowrap;
}

.sidebar-nav-link:hover {
    background: var(--sidebar-hover);
    color: white;
}

.sidebar-nav-link.active {
    background: var(--sidebar-active);
    color: white;
}

.sidebar-nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 24px;
    background: var(--sidebar-active-border);
    border-radius: 0 3px 3px 0;
}

.sidebar-nav-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.sidebar-nav-text {
    font-size: 0.9rem;
    font-weight: 500;
    transition: opacity var(--sidebar-transition);
}

.sidebar.collapsed .sidebar-nav-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

/* Tooltip para modo colapsado */
.sidebar.collapsed .sidebar-nav-link {
    justify-content: center;
    padding: 12px 0;
}

.sidebar.collapsed .sidebar-nav-link::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(var(--sidebar-collapsed-width) + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: #1e293b;
    color: white;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 1001;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.sidebar.collapsed .sidebar-nav-link::before {
    left: -3px;
}

.sidebar.collapsed .sidebar-nav-link:hover::after {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   SIDEBAR FOOTER
   ============================================ */

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logout-form {
    margin-bottom: 12px;
}

.sidebar-logout {
    width: 100%;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #ef4444 !important;
}

.sidebar-logout:hover {
    background: rgba(239, 68, 68, 0.15) !important;
}

.sidebar-user-mini {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    overflow: hidden;
}

.sidebar-user-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.sidebar-user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity var(--sidebar-transition);
}

.sidebar-user-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.75rem;
    color: var(--sidebar-text-muted);
}

.sidebar.collapsed .sidebar-user-info {
    opacity: 0;
    width: 0;
}

.sidebar.collapsed .sidebar-user-mini {
    justify-content: center;
    padding: 12px 8px;
}

/* ============================================
   MAIN WRAPPER
   ============================================ */

.main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left var(--sidebar-transition);
    display: flex;
    flex-direction: column;
}

.main-wrapper.sidebar-collapsed {
    margin-left: var(--sidebar-collapsed-width);
}

/* ============================================
   TOP HEADER
   ============================================ */

.top-header {
    height: var(--header-height);
    background: white;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
}

.top-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.sidebar-toggle {
    width: 40px;
    height: 40px;
    border: none;
    background: #f1f5f9;
    border-radius: 10px;
    color: #475569;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s ease;
}

.sidebar-toggle:hover {
    background: #e2e8f0;
    color: #1e3a5f;
}

.page-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #64748b;
}

.top-header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    color: #475569;
}

.user-name i {
    font-size: 1.2rem;
    color: #94a3b8;
}

.user-badge {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

/* ============================================
   MAIN CONTENT
   ============================================ */

.main-content {
    flex: 1;
    padding: 24px;
}

.messages-container {
    margin-bottom: 20px;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 991px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
    }
    
    .sidebar:not(.collapsed) {
        transform: translateX(0);
    }
    
    .main-wrapper {
        margin-left: 0 !important;
    }
    
    /* Overlay cuando sidebar está abierto en móvil */
    .sidebar:not(.collapsed)::after {
        content: '';
        position: fixed;
        top: 0;
        left: var(--sidebar-width);
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }
}

@media (max-width: 576px) {
    .top-header {
        padding: 0 16px;
    }
    
    .page-title {
        font-size: 1rem;
    }
    
    .main-content {
        padding: 16px;
    }
    
    .user-name span {
        display: none;
    }
}

/* ============================================
   DARK MODE SUPPORT (opcional)
   ============================================ */

@media (prefers-color-scheme: dark) {
    body.has-sidebar {
        background: #0f172a;
    }
    
    .top-header {
        background: #1e293b;
        border-color: #334155;
    }
    
    .sidebar-toggle {
        background: #334155;
        color: #94a3b8;
    }
    
    .sidebar-toggle:hover {
        background: #475569;
        color: white;
    }
    
    .page-title {
        color: white;
    }
    
    .user-name {
        color: #94a3b8;
    }
}
