/* ==========================================
   VARIABLES GLOBALES (TEMA CLARO POR DEFECTO)
   ========================================== */
:root {
    --bg-body: #f4f6f9;
    --bg-surface: #ffffff;
    --primary: #0d6efd;
    --text-main: #2b3445;
    --text-muted: #6c757d;
    --border-color: #e9ecef;
    --hover-bg: #e3f2fd;
    --sidebar-width: 260px;
    --sidebar-collapsed: 70px;
    --header-height: 70px;
}

/* ==========================================
   VARIABLES GLOBALES (MODO OSCURO)
   ========================================== */
[data-bs-theme="dark"] {
    --bg-body: #121212;         /* Fondo general oscuro */
    --bg-surface: #1e1e24;      /* Superficies (cartas, barra, menús) */
    --primary: #6ea8fe;         /* Azul ligeramente más brillante para legibilidad */
    --text-main: #f8f9fa;       /* Texto principal blanco hueso */
    --text-muted: #adb5bd;      /* Texto secundario gris claro */
    --border-color: #343a40;    /* Bordes oscurecidos para evitar brillo */
    --hover-bg: rgba(13, 110, 253, 0.15); /* Fondo sutil al hacer hover */
}

/* ==========================================
   ESTRUCTURA PRINCIPAL
   ========================================== */
body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

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

/* --- SIDEBAR --- */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    transition: width 0.3s ease, background-color 0.3s ease;
    display: flex;
    flex-direction: column;
    z-index: 1000;
}

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

.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .brand-text {
    display: none;
}

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

.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    color: var(--text-muted);
    border-radius: 8px;
    margin-bottom: 5px;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.nav-link i {
    font-size: 1.2rem;
    min-width: 30px;
}

.sidebar.collapsed .nav-link span {
    display: none;
}

.nav-link:hover, .nav-link.active {
    background-color: var(--hover-bg);
    color: var(--primary);
    font-weight: 600;
}

/* --- MAIN CONTENT & TOPBAR --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: calc(100% - var(--sidebar-width));
    transition: width 0.3s ease;
}

.topbar {
    height: var(--header-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 25px;
    transition: background-color 0.3s ease;
}

.btn-toggle-sidebar {
    background: none;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    padding: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
}

.avatar {
    width: 40px;
    height: 40px;
    cursor: pointer;
}

.content-area {
    flex: 1;
    overflow-y: auto;
}

/* ==========================================
   RESPONSIVE DESIGN (TABLETS Y MÓVILES)
   ========================================== */
@media (max-width: 991px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        box-shadow: 2px 0 10px rgba(0,0,0,0.2);
    }

    .sidebar.mobile-show {
        transform: translateX(0);
    }

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

/* ==========================================
   AJUSTES PROFUNDOS MODO OSCURO (OVERRIDE BOOTSTRAP)
   ========================================== */
[data-bs-theme="dark"] .bg-white,
[data-bs-theme="dark"] .bg-light {
    background-color: var(--bg-surface) !important;
}

[data-bs-theme="dark"] .text-dark {
    color: var(--text-main) !important;
}

[data-bs-theme="dark"] .card,
[data-bs-theme="dark"] .modal-content {
    background-color: var(--bg-surface) !important;
    border: 1px solid var(--border-color) !important;
}

/* Corrección de Tablas para legibilidad perfecta */
[data-bs-theme="dark"] .table {
    color: var(--text-main) !important;
    border-color: var(--border-color) !important;
}

[data-bs-theme="dark"] .table-light,
[data-bs-theme="dark"] .table-light th {
    background-color: #272b30 !important;
    color: #ffffff !important;
    border-bottom: 2px solid #121212 !important;
}

[data-bs-theme="dark"] .table-hover>tbody>tr:hover>* {
    background-color: #2c3238 !important;
    color: #ffffff !important;
}

/* Inputs, Selects y Textareas oscuros */
[data-bs-theme="dark"] input.form-control,
[data-bs-theme="dark"] select.form-select,
[data-bs-theme="dark"] textarea.form-control {
    background-color: #121212 !important;
    color: #ffffff !important;
    border-color: #444 !important;
}

[data-bs-theme="dark"] .input-group-text {
    background-color: #272b30 !important;
    color: #ffffff !important;
    border-color: #444 !important;
}

/* Corrección de bordes generales */
[data-bs-theme="dark"] .border,
[data-bs-theme="dark"] .border-bottom,
[data-bs-theme="dark"] .border-top {
    border-color: var(--border-color) !important;
}

/* Corrección visual específica para el Dashboard (quitar fondos blancos forzados) */
[data-bs-theme="dark"] [style*="background: linear-gradient(to right, #ffffff, #f8f9fa)"] {
    background: var(--bg-surface) !important;
}
/* =========================================================
   INTEGRACIÓN SWEETALERT2 CON BOOTSTRAP 5 MODO OSCURO
   ========================================================= */
html[data-bs-theme="dark"] .swal2-popup {
    background-color: var(--bs-body-bg) !important;
    color: var(--bs-body-color) !important;
    border: 1px solid var(--bs-border-color) !important;
}

html[data-bs-theme="dark"] .swal2-title, 
html[data-bs-theme="dark"] .swal2-html-container {
    color: var(--bs-body-color) !important;
}

html[data-bs-theme="dark"] .swal2-input,
html[data-bs-theme="dark"] .swal2-textarea,
html[data-bs-theme="dark"] .swal2-select {
    background-color: var(--bs-body-bg) !important;
    color: var(--bs-body-color) !important;
    border-color: var(--bs-border-color) !important;
}

html[data-bs-theme="dark"] .swal2-input:focus,
html[data-bs-theme="dark"] .swal2-textarea:focus {
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25) !important;
}