.sidebar {
    background: var(--bg-sidebar, var(--bg-surface));
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    gap: 16px;
    height: 100vh;
    height: 100dvh;
    width: var(--sidebar-w);
    transition: width 0.32s cubic-bezier(0.16, 1, 0.3, 1), padding 0.32s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s ease, background-color 0.25s ease;
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
}
.brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-subtle);
    transition: all 0.3s ease;
}
.brand-left {
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s ease;
}
.brand-left:hover .brand-badge {
    transform: scale(1.06);
    box-shadow: 0 0 20px rgba(16, 184, 199, 0.6);
}
.brand-badge {
    background: linear-gradient(135deg, var(--emerald-500), #059669);
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #fff;
    box-shadow: 0 0 16px var(--emerald-glow);
    flex-shrink: 0;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease;
}
.brand-text-block {
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.brand-title { font-size: 15px; font-weight: 700; letter-spacing: -0.3px; white-space: nowrap; }
.brand-version { font-size: 10px; font-family: var(--font-mono); color: var(--emerald-400); background: rgba(16,185,129,0.12); padding: 2px 6px; border-radius: 4px; white-space: nowrap; }

/* Mini Rail de Iconos Vertical para Modo Contraído */
.sidebar-rail-nav {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 100%;
    align-items: center;
    flex: 1;
    min-height: 0;
    padding: 6px 0 10px 0;
    box-sizing: border-box;
}

.sidebar-rail-top,
.sidebar-rail-bottom {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    align-items: center;
}

.sidebar-rail-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
    position: relative;
    border: 1px solid transparent;
}

/* 1. Nueva Conversación: Verde Esmeralda */
.rail-btn-new {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.35);
    color: #34d399;
}
.rail-btn-new:hover {
    background: rgba(16, 185, 129, 0.28);
    border-color: #10b981;
    color: #ffffff;
    transform: scale(1.12);
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.6), 0 0 4px rgba(16, 185, 129, 0.8);
}

/* 2. Chats: Cyan / Sky Blue */
.rail-btn-chats {
    background: rgba(6, 182, 212, 0.12);
    border-color: rgba(6, 182, 212, 0.35);
    color: #38bdf8;
}
.rail-btn-chats:hover {
    background: rgba(6, 182, 212, 0.28);
    border-color: #06b6d4;
    color: #ffffff;
    transform: scale(1.12);
    box-shadow: 0 0 20px rgba(6, 182, 212, 0.6), 0 0 4px rgba(6, 182, 212, 0.8);
}

/* 3. Archivos: Ámbar / Dorado */
.rail-btn-files {
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.35);
    color: #fbbf24;
}
.rail-btn-files:hover {
    background: rgba(245, 158, 11, 0.28);
    border-color: #f59e0b;
    color: #ffffff;
    transform: scale(1.12);
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.6), 0 0 4px rgba(245, 158, 11, 0.8);
}

/* 4. Modo Claro / Oscuro: Ámbar Solar */
.rail-btn-theme {
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.35);
    color: #fbbf24;
}
.rail-btn-theme:hover {
    background: rgba(245, 158, 11, 0.28);
    border-color: #f59e0b;
    color: #ffffff;
    transform: scale(1.12);
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.6), 0 0 4px rgba(245, 158, 11, 0.8);
}
.rail-btn-theme .theme-sun-icon {
    transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.rail-btn-theme:hover .theme-sun-icon {
    transform: rotate(45deg) scale(1.1);
}

/* 5. Configuración Admin: Violeta / Púrpura */
.rail-btn-settings {
    background: rgba(139, 92, 246, 0.12);
    border-color: rgba(139, 92, 246, 0.35);
    color: #a78bfa;
}
.rail-btn-settings:hover {
    background: rgba(139, 92, 246, 0.28);
    border-color: #8b5cf6;
    color: #ffffff;
    transform: scale(1.12);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.6), 0 0 4px rgba(139, 92, 246, 0.8);
}

/* 6. Cerrar Sesión: Rojo Coral */
.rail-btn-logout {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.35);
    color: #f87171;
}
.rail-btn-logout:hover {
    background: rgba(239, 68, 68, 0.28);
    border-color: #ef4444;
    color: #ffffff;
    transform: scale(1.12);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.6), 0 0 4px rgba(239, 68, 68, 0.8);
}

/* Reglas cuando el Sidebar está contraído en Desktop */
.app-layout.sidebar-collapsed .sidebar {
    width: 68px;
    padding: 16px 8px;
    align-items: center;
}
.app-layout.sidebar-collapsed .brand {
    justify-content: center;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 14px;
    width: 100%;
}
.app-layout.sidebar-collapsed .brand-left {
    justify-content: center;
    gap: 0;
}
.app-layout.sidebar-collapsed .brand-text-block,
.app-layout.sidebar-collapsed .btn-sidebar-close-mobile,
.app-layout.sidebar-collapsed .sidebar-main-content {
    display: none !important;
}
.app-layout.sidebar-collapsed .sidebar-rail-nav {
    display: flex !important;
}

.btn-new-chat {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(16, 185, 129, 0.05));
    border: 1px solid var(--border-active);
    color: var(--emerald-400);
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}
.btn-new-chat:hover { background: var(--emerald-500); color: #000; box-shadow: 0 0 16px var(--emerald-glow); }

.sidebar-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-card);
    padding: 3px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}
.sidebar-tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 11.5px;
    font-weight: 600;
    padding: 6px 4px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: center;
}
.sidebar-tab-btn.active {
    background: var(--bg-surface);
    color: var(--emerald-400);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.threads-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.thread-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: transparent;
    transition: all 0.15s ease;
    border: 1px solid transparent;
}
.thread-item:hover, .thread-item.active {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}
.thread-item.active {
    border-color: var(--border-active);
    color: var(--emerald-400);
}
.thread-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin-right: 8px;
}
.thread-actions {
    display: none;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.thread-item:hover .thread-actions, 
.thread-item.active .thread-actions {
    display: flex;
}
@media (hover: none) {
    .thread-actions {
        display: flex;
    }
}
.btn-thread-action {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    width: 24px;
    height: 24px;
    padding: 0;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}
.btn-thread-action:hover {
    color: #38bdf8;
    background: rgba(56, 189, 248, 0.16);
    border-color: rgba(56, 189, 248, 0.45);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(56, 189, 248, 0.25);
}
.btn-thread-action.delete:hover {
    color: #f87171;
    background: rgba(239, 68, 68, 0.18);
    border-color: rgba(239, 68, 68, 0.45);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.25);
}

/* Explorador de Archivos */
.files-tree-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.tree-header-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px 8px 8px;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 6px;
}
.tree-header-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}
.tree-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}
.tree-action-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    width: 26px;
    height: 26px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}
.tree-action-btn:hover {
    background: var(--bg-card-hover);
    color: var(--emerald-400);
    border-color: var(--border-active);
}
.tree-folder {
    display: flex;
    flex-direction: column;
}
.tree-folder-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    color: var(--text-primary);
    font-weight: 600;
    transition: background 0.15s ease;
    user-select: none;
}
.tree-folder-header:hover {
    background: var(--bg-card);
}
.tree-folder-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tree-badge {
    font-size: 10px;
    background: rgba(255,255,255,0.06);
    color: var(--text-muted);
    padding: 1px 6px;
    border-radius: 10px;
}
.tree-folder-children {
    display: flex;
    flex-direction: column;
    padding-left: 14px;
    gap: 2px;
}
.tree-file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    transition: all 0.15s ease;
    border: 1px solid transparent;
}
.tree-file-item:hover, .tree-file-item.active {
    background: var(--bg-card);
    color: var(--text-primary);
}
.tree-file-item.active {
    border-color: var(--border-active);
    color: var(--emerald-400);
    background: rgba(16,185,129,0.08);
}
.tree-file-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tree-file-actions {
    display: none;
    gap: 3px;
}
.tree-file-item:hover .tree-file-actions, .tree-file-item.active .tree-file-actions {
    display: flex;
}
.btn-tree-opt {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    width: 22px;
    height: 22px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.12s ease;
}
.btn-tree-opt:hover {
    color: var(--emerald-400);
    border-color: var(--border-active);
    background: var(--bg-card-hover);
}
.btn-tree-opt.delete:hover {
    color: var(--red-500);
    border-color: rgba(239, 68, 68, 0.4);
}

/* User profile */
.user-profile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    margin-top: auto;
    width: 100%;
    box-sizing: border-box;
}
.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--emerald-500);
    color: #000;
    font-weight: 700;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; min-width: 0; flex: 1; margin-left: 8px; }
.user-name { font-size: 12px; font-weight: 600; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 10px; color: var(--emerald-400); font-family: var(--font-mono); }
.user-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.btn-user-opt {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}
.btn-user-opt:hover {
    color: var(--text-primary);
    border-color: var(--border-active);
    background: var(--bg-card-hover);
}
.btn-user-opt.logout:hover {
    color: var(--red-500);
    border-color: rgba(239, 68, 68, 0.4);
}

/* Botón Moderno de Modo Claro / Oscuro en Sidebar */
.btn-sidebar-theme {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.28);
    color: #fbbf24;
    width: 29px;
    height: 29px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
}
.btn-sidebar-theme:hover {
    background: rgba(245, 158, 11, 0.22);
    border-color: #f59e0b;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 0 14px rgba(245, 158, 11, 0.4);
}
.btn-sidebar-theme:active {
    transform: translateY(0);
}
.btn-sidebar-theme .theme-sun-icon {
    transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.btn-sidebar-theme:hover .theme-sun-icon {
    transform: rotate(45deg) scale(1.1);
}

/* Botón Moderno de Configuración Admin en Sidebar */
.btn-sidebar-admin-gear {
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.28);
    color: #34d399;
    width: 29px;
    height: 29px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
}
.btn-sidebar-admin-gear:hover {
    background: rgba(16, 185, 129, 0.22);
    border-color: var(--emerald-400);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 0 14px rgba(16, 185, 129, 0.35);
}
.btn-sidebar-admin-gear:active {
    transform: translateY(0);
}
.admin-gear-icon {
    transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.btn-sidebar-admin-gear:hover .admin-gear-icon {
    transform: rotate(60deg);
}

/* Botón Moderno de Cerrar Sesión */
.btn-sidebar-logout {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #f87171;
    width: 29px;
    height: 29px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
}
.btn-sidebar-logout:hover {
    background: rgba(239, 68, 68, 0.22);
    border-color: #ef4444;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 0 14px rgba(239, 68, 68, 0.35);
}
.btn-sidebar-logout:active {
    transform: translateY(0);
}

/* ==========================================================================
   RESPONSIVE MÓVILES PANTALLA SIMPLE (< 600px)
   ========================================================================== */
@media (max-width: 599px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(320px, 86vw);
        z-index: 2200;
        transform: translateX(-100%);
        box-shadow: none;
    }
    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 10px 0 50px rgba(0, 0, 0, 0.85);
    }
    .btn-sidebar-close-mobile {
        display: none;
    }
    .thread-actions, .tree-file-actions {
        display: flex;
    }
}

/* ==========================================================================
   PANTALLAS DOBLES / DISPOSITIVOS PLEGABLES / ESCRITORIO (>= 600px)
   ========================================================================== */
@media (min-width: 600px) {
    .sidebar {
        position: relative;
        left: auto;
        top: auto;
        bottom: auto;
        transform: none !important;
        z-index: 100;
        box-shadow: none;
    }
}

/* ==========================================================================
   ESTILOS ESPECÍFICOS MODO CLARO RETRO-TECH (SIDEBAR)
   ========================================================================== */
[data-theme="light"] .brand-badge {
    background: linear-gradient(135deg, #FF6B4A, #EA580C);
    box-shadow: 0 0 16px rgba(255, 107, 74, 0.4);
}
[data-theme="light"] .btn-new-chat {
    background: #FFEAE3;
    border-color: #FFB39F;
    color: #EA580C;
}
[data-theme="light"] .btn-new-chat:hover {
    background: #FF6B4A;
    color: #FFFFFF;
    box-shadow: 0 0 16px rgba(255, 107, 74, 0.35);
}
[data-theme="light"] .sidebar-tab-btn.active {
    background: #FFFFFF;
    color: #EA580C;
    box-shadow: 0 1px 4px rgba(22, 34, 56, 0.08);
}
[data-theme="light"] .thread-item.active {
    background: #FFFFFF;
    border-color: #FFB39F;
    color: #162238;
    box-shadow: 0 2px 8px rgba(22, 34, 56, 0.05);
}
[data-theme="light"] .thread-item:hover:not(.active) {
    background: #EFE9E0;
    color: #162238;
}
