/* Fonts loaded async via _Layout.cshtml */

@import url('./variables.css');
@import url('./base.css');
@import url('./layout.css');
@import url('./sidebar.css');
@import url('./buttons.css');
@import url('./cards.css');
@import url('./forms.css');
@import url('./datatables.css');
@import url('./animations.css');
@import url('./utilities.css');
@import url('./darkmode.css');
@import url('./dashboard.css');

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #a5b4fc;
    --primary-subtle: #eef2ff;
    --secondary: #6b7280;
    --success: #10b981;
    --success-subtle: #ecfdf5;
    --warning: #f59e0b;
    --warning-subtle: #fffbeb;
    --danger: #ef4444;
    --danger-subtle: #fef2f2;
    --info: #06b6d4;
    --info-subtle: #ecfeff;
    --dark: #0f172a;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.03);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --font-base: 13px;
}

html {
    font-size: var(--font-base);
    scroll-behavior: smooth;
}

@media (min-width: 768px) {
    html { font-size: 13.5px; }
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    margin-bottom: 60px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Tema oscuro global: el fondo base de la pagina y los textos cambian en
   todas las pestanas. Las vistas pueden agregar sus propios overrides con
   body.dark-mode para componentes concretos. */
body.dark-mode {
    background: var(--gray-900);
    color: var(--gray-200);
}
body.dark-mode .main-area { background: var(--gray-900); }
body.dark-mode .card { background: var(--gray-800); border-color: #334155; }
body.dark-mode .card-header, body.dark-mode .card-body, body.dark-mode .card-footer { background: transparent; color: var(--gray-200); }
body.dark-mode h1, body.dark-mode h2, body.dark-mode h3, body.dark-mode h4, body.dark-mode h5, body.dark-mode h6 { color: #f1f5f9; }
body.dark-mode p, body.dark-mode li, body.dark-mode label, body.dark-mode td, body.dark-mode th { color: var(--gray-200); }
body.dark-mode .table { --bs-table-bg: transparent; color: var(--gray-200); }
body.dark-mode .table td, body.dark-mode .table th { border-color: #334155; }
body.dark-mode .table-striped>tbody>tr:nth-of-type(odd) { --bs-table-bg: #162032; }
body.dark-mode .form-control, body.dark-mode .form-select { background: var(--gray-900); border-color: #334155; color: var(--gray-200); }
body.dark-mode .form-control:focus, body.dark-mode .form-select:focus { background: var(--gray-900); border-color: var(--primary); color: var(--gray-200); }
body.dark-mode .form-control::placeholder { color: #64748b; }
body.dark-mode .input-group-text { background: var(--gray-800); border-color: #334155; color: var(--gray-200); }
body.dark-mode .border, body.dark-mode .border-top, body.dark-mode .border-bottom,
body.dark-mode .border-start, body.dark-mode .border-end { border-color: #334155 !important; }
body.dark-mode .text-muted { color: #94a3b8 !important; }
body.dark-mode .list-group-item { background: var(--gray-800); border-color: #334155; color: var(--gray-200); }
body.dark-mode .dropdown-menu { background: var(--gray-800); border-color: #334155; }
body.dark-mode .dropdown-item { color: var(--gray-200); }
body.dark-mode .dropdown-item:hover { background: #334155; }
body.dark-mode .nav-tabs .nav-link { color: var(--gray-300); }
body.dark-mode .nav-tabs .nav-link.active { background: var(--gray-800); color: #fff; border-color: #334155; }
body.dark-mode .progress { background: #334155; }
body.dark-mode .alert { background: var(--gray-800); color: var(--gray-200); border-color: #334155; }
body.dark-mode .alert-success { background: #064e3b; color: #a7f3d0; border-color: #065f46; }
body.dark-mode .alert-danger { background: #7f1d1d; color: #fecaca; border-color: #991b1b; }
body.dark-mode .alert-warning { background: #78350f; color: #fde68a; border-color: #92400e; }
body.dark-mode .alert-info { background: #1e3a5f; color: #bfdbfe; border-color: #1e40af; }
body.dark-mode .bg-white { background: var(--gray-800) !important; }
body.dark-mode .bg-light { background: #162032 !important; }
body.dark-mode .btn-outline-secondary { color: var(--gray-300); border-color: #475569; }
body.dark-mode .btn-outline-secondary:hover { background: #334155; color: #fff; }
body.dark-mode .page-link { background: var(--gray-800); border-color: #334155; color: var(--gray-300); }
body.dark-mode .page-item.active .page-link { background: var(--primary); border-color: var(--primary); }
body.dark-mode .page-item.disabled .page-link { background: var(--gray-900); color: #475569; }
body.dark-mode .breadcrumb-item, body.dark-mode .breadcrumb-item a { color: var(--gray-300); }
body.dark-mode .breadcrumb-item.active { color: #94a3b8; }
body.dark-mode .form-check-input { background-color: var(--gray-900); border-color: #475569; }
body.dark-mode .form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }
body.dark-mode hr { border-color: #334155; opacity: 1; }

.card {
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}
.card:hover {
    border-color: var(--gray-300);
}
.card-header {
    background: white;
    border-bottom: 1px solid var(--gray-100);
    padding: 1rem 1.25rem;
}
.card-body {
    padding: 1.25rem;
}

.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.45rem 1rem;
    transition: var(--transition);
}
.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.btn-sm {
    font-size: 0.78rem;
    padding: 0.3rem 0.75rem;
}
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}
.btn-success {
    background: var(--success);
    border-color: var(--success);
}
.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}
.btn-outline-primary:hover {
    background: var(--primary);
    border-color: var(--primary);
}

.form-control, .form-select {
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-200);
    font-size: 0.85rem;
    padding: 0.45rem 0.75rem;
    transition: var(--transition);
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.form-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 0.3rem;
}

.badge {
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.7rem;
}

.alert {
    border-radius: var(--radius-md);
    border: none;
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
}

.text-muted {
    color: var(--gray-500) !important;
}

/* --- Cards modernas --- */
.card-modern {
    background: white;
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}
.card-modern:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

/* --- Botones rediseñados --- */
.btn-modern {
    border-radius: var(--radius-sm);
    font-weight: 600;
    padding: 0.35rem 1rem;
    transition: var(--transition);
    border: none;
}
.btn-modern:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.btn-primary-modern {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
}
.btn-primary-modern:hover {
    background: linear-gradient(135deg, var(--primary-dark), #4338ca);
    color: white;
}

/* --- Tablas con estilo --- */
.table-modern {
    border-collapse: separate;
    border-spacing: 0;
}
.table-modern thead th {
    background: var(--gray-50);
    color: var(--gray-500);
    font-weight: 600;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.5rem 0.7rem;
    border-bottom: 2px solid var(--gray-200);
}
.table-modern tbody td {
    padding: 0.45rem 0.7rem;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

/* --- Badges modernos --- */
.badge-modern {
    font-weight: 600;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.7rem;
    letter-spacing: 0.02em;
}

/* --- Animaciones --- */
.fade-in {
    animation: fadeIn 0.3s ease-out;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.slide-up {
    animation: slideUp 0.4s ease-out;
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Skeleton loader --- */
.skeleton-line {
    background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* --- Scrollbar personalizada --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--gray-100);
}
::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

/* --- Glass effect --- */
.glass {
    background: rgba(255,255,255,0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.2);
}

/* --- Utilidades --- */
.text-gradient {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.fw-800 { font-weight: 800; }
.tiny-text { font-size: 0.75rem; }
.letter-spacing { letter-spacing: 0.05em; }

.highlight-text {
    background: #fef3c7;
    padding: 0 2px;
    border-radius: 2px;
}
.highlight-fade {
    transition: background 0.5s ease;
    background: transparent;
}

/* --- Context menu --- */
.context-menu {
    position: absolute;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    padding: 0.5rem;
    min-width: 200px;
    z-index: 9999;
    list-style: none;
    border: 1px solid var(--gray-200);
}
.context-menu li {
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--gray-700);
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.context-menu li:hover {
    background: var(--gray-100);
    color: var(--primary);
}
.context-menu .divider {
    height: 1px;
    background: var(--gray-200);
    margin: 0.25rem 0;
    padding: 0;
}

/* --- Active user avatars --- */
.user-avatar-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.user-avatar-sm:hover {
    transform: scale(1.15);
    z-index: 2;
}

/* --- DataTable font sizing --- */
table.dataTable td {
    font-size: 0.78rem;
}
table.dataTable th {
    font-size: 0.7rem;
}

/* --- Flatpickr business panel --- */
.fp-bi-panel {
    display: flex;
    gap: 4px;
    padding: 8px;
    border-bottom: 1px solid var(--gray-200);
    flex-wrap: wrap;
}
.btn-periodo-bi {
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--gray-600);
    transition: var(--transition);
}
.btn-periodo-bi:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* --- Filter dropdown container --- */
.filter-dropdown-container {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    padding: 0.5rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 1050;
}
.filter-dropdown-container select,
.filter-dropdown-container input {
    border-radius: 6px;
    border: 1px solid var(--gray-200);
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
    width: 100%;
}
.filter-dropdown-container select:focus,
.filter-dropdown-container input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}

/* --- Excel export dropdown --- */
.export-dropdown .dropdown-item {
    padding: 0.5rem 0.8rem;
    font-size: 0.8rem;
    border-radius: 6px;
    transition: var(--transition);
}
.export-dropdown .dropdown-item:hover {
    background: var(--gray-50);
    color: var(--primary);
}
.export-dropdown .dropdown-item i {
    width: 1.4rem;
}

/* --- Mode width classes --- */
.mode-small #reportMainContent {
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
}
.mode-normal #reportMainContent {
    max-width: 1140px;
    margin-left: auto;
    margin-right: auto;
}
.mode-large #reportMainContent {
    max-width: 100%;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

/* --- Select2 in dark mode --- */
body.dark-mode .select2-dropdown {
    background-color: var(--color-card-bg, #131c31) !important;
    border-color: var(--color-border, #1e293b) !important;
}
body.dark-mode .select2-results__option {
    color: var(--color-text, #e2e8f0) !important;
}
body.dark-mode .select2-results__option--highlighted {
    background: var(--color-primary, #6366f1) !important;
    color: white !important;
}
body.dark-mode .select2-container--bootstrap-5 .select2-selection {
    background-color: var(--color-input-bg, #1a2744) !important;
    border-color: var(--color-border, #1e293b) !important;
}
body.dark-mode .select2-container--bootstrap-5 .select2-selection__rendered {
    color: var(--color-text, #e2e8f0) !important;
}
body.dark-mode .select2-container--bootstrap-5 .select2-selection__choice {
    background: var(--color-light, #1a2744) !important;
    color: var(--color-text, #e2e8f0) !important;
    border-color: var(--color-border, #1e293b) !important;
}

/* --- History clickable name --- */
.history-name {
    cursor: pointer;
    flex: 1;
    padding: 0.25rem 0;
}
.history-name:hover {
    color: var(--primary);
}

/* --- Print export --- */
@media print {
    .navbar-glass, .footer-modern, .position-fixed { display: none !important; }
    #reportMainContent { max-width: 100% !important; }
    .dashboard-table th { background: #1a335d !important; color: white !important; }
}

/* --- Swal dark mode --- */
body.dark-mode .swal2-popup {
    background: var(--color-card-bg, #131c31) !important;
}
body.dark-mode .swal2-title {
    color: var(--color-text, #e2e8f0) !important;
}
body.dark-mode .swal2-html-container {
    color: var(--color-text-secondary, #94a3b8) !important;
}

/* ===== EXPORT PANEL ===== */
.export-panel {
    padding: 0.5rem;
}
.export-options {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.export-option {
    padding: 0.65rem 0.75rem;
    border-radius: 10px;
    border: 1px solid var(--gray-200);
    transition: all 0.2s ease;
    background: white;
}
.export-option:hover {
    border-color: var(--primary);
    background: rgba(99,102,241,0.03);
}
.export-option.selected {
    border-color: var(--primary);
    background: rgba(99,102,241,0.06);
    box-shadow: 0 0 0 2px rgba(99,102,241,0.12);
}
.export-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.export-option .check-icon {
    font-size: 1.1rem;
}

/* --- Email panel --- */
.email-panel {
    padding: 0.25rem;
}
.email-panel .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99,102,241,0.12);
}

/* ===== DARK MODE OVERRIDES FOR NEW ELEMENTS ===== */
body.dark-mode .export-panel {
    color: var(--color-text, #e2e8f0);
}
body.dark-mode .export-option {
    background: var(--color-card-bg, #131c31);
    border-color: var(--color-border, #1e293b);
}
body.dark-mode .export-option:hover {
    border-color: var(--color-primary, #6366f1);
    background: rgba(99,102,241,0.08);
}
body.dark-mode .export-option.selected {
    border-color: var(--color-primary, #6366f1);
    background: rgba(99,102,241,0.12);
}
body.dark-mode .modal-content {
    background: var(--color-card-bg, #131c31);
    color: var(--color-text, #e2e8f0);
    border-color: var(--color-border, #1e293b);
}
body.dark-mode .modal-header {
    border-bottom-color: var(--color-border, #1e293b);
}
body.dark-mode .modal-footer {
    border-top-color: var(--color-border, #1e293b);
}
body.dark-mode .btn-light {
    background: var(--color-light, #1a2744);
    border-color: var(--color-border, #1e293b);
    color: var(--color-text, #e2e8f0);
}
body.dark-mode .btn-light:hover {
    background: var(--color-card-bg, #131c31);
}
body.dark-mode .form-control {
    background: var(--color-input-bg, #1a2744);
    border-color: var(--color-border, #1e293b);
    color: var(--color-text, #e2e8f0);
}
body.dark-mode .form-control:focus {
    background: var(--color-input-bg, #1a2744);
    border-color: var(--color-primary, #6366f1);
    color: var(--color-text, #e2e8f0);
}
body.dark-mode .text-muted {
    color: var(--color-text-secondary, #94a3b8) !important;
}
body.dark-mode .modal-backdrop.show {
    opacity: 0.6;
}

/* ===== KEYBOARD SHORTCUT HINT ===== */
.keyboard-hint {
    display: inline-block;
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    padding: 0 5px;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--gray-500);
    font-family: monospace;
}

/* ===== BUTTON XS ===== */
.btn-xs {
    padding: 0.15rem 0.4rem;
    font-size: 0.7rem;
    border-radius: 4px;
}

/* ===== FILTER ICON DEFAULT ===== */
.filter-icon {
    opacity: 0.6;
    transition: opacity 0.15s;
}
.filter-icon:hover {
    opacity: 1;
}

/* =============================================
   SIDEBAR LAYOUT
   ============================================= */
:root {
    --sidebar-width: 230px;
    --sidebar-collapsed-width: 62px;
    --sidebar-bg: #0f172a;
    --sidebar-hover: rgba(255,255,255,0.06);
    --sidebar-active: rgba(99,102,241,0.15);
    --sidebar-text: rgba(255,255,255,0.65);
    --sidebar-text-active: #fff;
    --sidebar-border: rgba(255,255,255,0.06);
    --topbar-height: 48px;
}

/* --- Sidebar base --- */
.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    z-index: 1030;
    display: flex;
    flex-direction: column;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    border-right: 1px solid var(--sidebar-border);
}

/* --- Brand --- */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--sidebar-border);
    min-height: 58px;
    flex-shrink: 0;
}
.sidebar-brand .brand-icon {
    font-size: 1.4rem;
    color: var(--primary-light);
    flex-shrink: 0;
}
.sidebar-brand .brand-text {
    font-size: 1.1rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-light), #c4b5fd);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
    transition: opacity 0.25s;
}

/* --- Nav --- */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 10px;
}
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

.sidebar-section-label {
    padding: 16px 12px 4px;
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.25);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-section-label.sidebar-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    cursor: pointer;
    padding-bottom: 6px;
    transition: color .15s ease;
}
.sidebar-section-label.sidebar-group-toggle:hover {
    color: rgba(255,255,255,0.55);
}
.sidebar-group-icon {
    font-size: 0.55rem;
    opacity: .7;
    transition: transform .2s ease;
}
.sidebar-group-toggle.open .sidebar-group-icon {
    transform: rotate(180deg);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 500;
    transition: all 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
}
.sidebar-link i {
    font-size: 1.15rem;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}
.sidebar-link span {
    transition: opacity 0.25s;
}
.sidebar-link .sidebar-badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 0.1rem 0.4rem;
    border-radius: 99px;
    line-height: 1.2;
    min-width: 18px;
    text-align: center;
}
.app-sidebar.collapsed .sidebar-link .sidebar-badge {
    display: none !important;
}
.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}
.sidebar-link.active {
    background: var(--sidebar-active);
    color: var(--sidebar-text-active);
}
.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--primary);
    border-radius: 0 3px 3px 0;
}

/* --- Footer --- */
.sidebar-footer {
    padding: 10px;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.sidebar-user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
}
.sidebar-user-info {
    overflow: hidden;
    transition: opacity 0.25s;
}
.sidebar-user-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role {
    font-size: 0.6rem;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.sidebar-logout {
    background: transparent;
    border: 1px solid var(--sidebar-border);
    border-radius: 8px;
    color: rgba(255,255,255,0.5);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}
.sidebar-logout:hover {
    background: rgba(239,68,68,0.15);
    color: var(--danger);
    border-color: rgba(239,68,68,0.3);
}

/* --- Toggle group --- */
.sidebar-toggle-group {
    position: absolute;
    bottom: 70px;
    right: -14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 5;
}
.sidebar-toggle,
.sidebar-pin-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    border: 2px solid rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.sidebar-toggle:hover,
.sidebar-pin-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: scale(1.15);
    box-shadow: 0 4px 16px rgba(99,102,241,0.5);
}
.sidebar-pin-btn.pinned {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.sidebar-pin-btn.pinned i {
    transform: rotate(45deg);
}
.app-sidebar.collapsed .sidebar-toggle-group {
    right: 50%;
    transform: translateX(50%);
    bottom: 65px;
}
.app-sidebar.collapsed .sidebar-toggle i {
    transform: rotate(180deg);
}

/* --- Collapsed state --- */
.app-sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}
.app-sidebar.collapsed .brand-text,
.app-sidebar.collapsed .sidebar-link span,
.app-sidebar.collapsed .sidebar-user-info,
.app-sidebar.collapsed .sidebar-section-label {
    opacity: 0;
    pointer-events: none;
}
.app-sidebar.collapsed .sidebar-link {
    justify-content: center;
    padding: 9px 0;
}
.app-sidebar.collapsed .sidebar-link i {
    margin: 0;
}
.app-sidebar.collapsed .sidebar-user {
    justify-content: center;
}
.app-sidebar.collapsed .sidebar-footer {
    justify-content: center;
}
.app-sidebar.collapsed .sidebar-toggle i {
    transform: rotate(180deg);
}

/* --- Main area --- */
.main-area {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.main-area.sidebar-collapsed {
    margin-left: var(--sidebar-collapsed-width);
}
.main-app-content-wrapper {
    flex: 1;
    min-width: 0;
    padding: 1.5rem 1.5rem 0;
}

/* --- Top bar --- */
.top-bar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: white;
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
}
.top-bar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}
.top-bar-toggle {
    background: transparent;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-600);
    font-size: 1.1rem;
}
.active-users-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: 20px;
    padding: 3px 12px 3px 8px;
    font-size: 0.75rem;
    color: var(--gray-700);
    white-space: nowrap;
}
.dot-pulse {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.85); }
}

/* --- Footer --- */
.app-footer {
    background: white;
    border-top: 1px solid var(--gray-200);
    font-size: 0.75rem;
    color: var(--gray-400);
    flex-shrink: 0;
}

/* --- Mobile overlay --- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1029;
}
.sidebar-overlay.show {
    display: block;
}

/* --- Responsive --- */
@media (max-width: 767.98px) {
    .app-sidebar {
        left: calc(var(--sidebar-width) * -1);
        width: var(--sidebar-width) !important;
    }
    .app-sidebar.mobile-open {
        left: 0;
    }
    .main-area, .main-area.sidebar-collapsed {
        margin-left: 0 !important;
    }
    .main-app-content-wrapper {
        padding: 1rem 1rem 0;
    }
    .sidebar-toggle {
        display: none;
    }
}

/* --- Print --- */
@media print {
    .app-sidebar, .top-bar, .app-footer, .position-fixed { display: none !important; }
    .main-area, .main-area.sidebar-collapsed { margin-left: 0 !important; }
    .main-app-content-wrapper { padding: 0 !important; }
}

/* --- Floating show-filters button --- */
.btn-show-filters {
    position: fixed;
    bottom: 24px;
    left: calc(var(--sidebar-width) + 16px);
    z-index: 1020;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 100px;
    padding: 0.5rem 1.2rem;
    font-size: 0.78rem;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(99,102,241,0.35);
    transition: all 0.3s ease;
    cursor: pointer;
    display: none;
}
.btn-show-filters:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(99,102,241,0.4);
    color: white;
}
.main-area.sidebar-collapsed .btn-show-filters {
    left: calc(var(--sidebar-collapsed-width) + 16px);
}
@media (max-width: 767.98px) {
    .btn-show-filters {
        left: 16px !important;
    }
}

/* --- Dark mode sidebar overrides --- */
body.dark-mode .app-sidebar {
    border-right-color: rgba(255,255,255,0.04);
}
body.dark-mode .top-bar {
    background: var(--color-card-bg, #131c31);
    border-bottom-color: var(--color-border, #1e293b);
}
body.dark-mode .top-bar-toggle {
    border-color: var(--color-border, #1e293b);
    color: var(--color-text, #e2e8f0);
}
body.dark-mode .app-footer {
    background: var(--color-card-bg, #131c31);
    border-top-color: var(--color-border, #1e293b);
    color: var(--color-text-secondary, #94a3b8);
}
body.dark-mode .active-users-indicator {
    background: var(--color-card-bg, #131c31);
    border-color: var(--color-border, #1e293b);
    color: var(--color-text-secondary, #94a3b8);
}

/* --- Sidebar dark mode compat --- */
body.dark-mode .sidebar-brand .brand-text {
    background: linear-gradient(135deg, #a5b4fc, #c4b5fd);
    -webkit-background-clip: text;
    background-clip: text;
}

/* === #17 content-visibility for offscreen sections === */
.accordion-body, #tablaResultados_wrapper, .offcanvas-body {
    content-visibility: auto;
    contain-intrinsic-size: auto 500px;
}

/* === #18 will-change for animated elements === */
.app-sidebar { will-change: width; }
.main-area { will-change: margin-left; }

/* === #23 touch targets on mobile === */
@media (max-width: 767.98px) {
    .btn-xs, .btn-sm, .sidebar-link, .nav-link, .dropdown-item {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
    }
}

/* === #28 focus-visible on sidebar/nav links === */
.sidebar-link:focus-visible,
.nav-link:focus-visible,
.dropdown-item:focus-visible {
    outline: 2px solid var(--primary, #6366f1);
    outline-offset: -2px;
    border-radius: 4px;
}
.sidebar-link:focus-visible {
    background: rgba(99, 102, 241, 0.1);
}

/* === #68 skip nav === */
.skip-nav { position: absolute; top: -100%; left: 0; z-index: 10000; background: #6366f1; color: white; padding: 8px 16px; font-size: 0.85rem; text-decoration: none; border-radius: 0 0 8px 0; }
.skip-nav:focus { top: 0; outline: 3px solid #f59e0b; }

/* === #68 focus contrast WCAG AA === */
*:focus-visible { outline: 3px solid #f59e0b !important; outline-offset: 2px !important; border-radius: 4px; }

/* === TOAST NOTIFICATIONS === */
#toastContainer { position: fixed; top: 1rem; right: 1rem; z-index: 99999; display: flex; flex-direction: column; gap: 0.5rem; max-width: 500px; }
.toast-msg { display: flex; align-items: flex-start; gap: 0.6rem; padding: 0.75rem 1rem; border-radius: 12px; font-size: 0.82rem; font-weight: 500; box-shadow: 0 8px 30px rgba(0,0,0,0.15); animation: toastIn 0.3s ease, toastOut 0.3s 3.2s ease forwards; pointer-events: all; line-height: 1.4; }
.toast-msg i { font-size: 1.1rem; flex-shrink: 0; }
.toast-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.toast-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.toast-warn    { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.toast-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
body.dark-mode .toast-success { background: #064e3b; color: #a7f3d0; border-color: #065f46; }
body.dark-mode .toast-error   { background: #7f1d1d; color: #fecaca; border-color: #991b1b; }
body.dark-mode .toast-warn    { background: #78350f; color: #fde68a; border-color: #92400e; }
body.dark-mode .toast-info    { background: #1e3a5f; color: #bfdbfe; border-color: #1e40af; }
@@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }
@@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-10px); } }

/* === SKELETON LOADER === */
@@keyframes shimmer { 0% { background-position: -400px 0; } 100% { background-position: 400px 0; } }
.skeleton-row { height: 38px; margin-bottom: 4px; border-radius: 8px; background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%); background-size: 800px 100%; animation: shimmer 1.5s infinite linear; }
.skeleton-header { height: 44px; margin-bottom: 8px; border-radius: 8px; background: linear-gradient(90deg, #cbd5e1 25%, #e2e8f0 50%, #cbd5e1 75%); background-size: 800px 100%; animation: shimmer 1.5s infinite linear; }
body.dark-mode .skeleton-row { background: linear-gradient(90deg, #334155 25%, #475569 50%, #334155 75%); background-size: 800px 100%; }
body.dark-mode .skeleton-header { background: linear-gradient(90deg, #1e293b 25%, #334155 50%, #1e293b 75%); background-size: 800px 100%; }

/* === FULLSCREEN === */
.fullscreen-active { position: fixed !important; inset: 0 !important; z-index: 9998 !important; background: var(--gray-50); overflow: auto; padding: 1.5rem; }
body.dark-mode .fullscreen-active { background: var(--gray-900); }
.btn-fs { position: absolute; top: 0.5rem; right: 0.5rem; z-index: 10; opacity: 0.5; transition: opacity 0.2s; }
.btn-fs:hover { opacity: 1; }

/* === CANCEL BUTTON === */
.btn-cancel-query { animation: pulse-cancel 1.5s infinite; }
@@keyframes pulse-cancel { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

/* === TOGGLE PASSWORD === */
.input-group .toggle-pwd { cursor: pointer; background: transparent; border: none; color: var(--gray-400); padding: 0 10px; }
.input-group .toggle-pwd:hover { color: var(--primary); }

/* === STICKY HEADER + ROW EXPAND === */
.table-sticky-header thead { position: sticky; top: 0; z-index: 5; }
.table-sticky-header thead th { background: #444E6A !important; color: white !important; }
body.dark-mode .table-sticky-header thead th { background: #1e293b !important; color: #e2e8f0 !important; border-color: #334155 !important; }
.row-expand-btn { cursor: pointer; color: var(--primary); font-size: 0.75rem; padding: 2px 6px; border-radius: 4px; border: 1px solid var(--gray-200); background: white; }
.row-expand-btn:hover { background: var(--primary-subtle); }
body.dark-mode .row-expand-btn { background: #1e293b; border-color: #334155; }
body.dark-mode .row-expand-btn:hover { background: #1e3a5f; }
.row-detail { display: none; background: var(--gray-50); font-size: 0.75rem; padding: 0.5rem 1rem; }
.row-detail.show { display: table-row; }
body.dark-mode .row-detail { background: #0f172a; }

/* === STATS FOOTER ROW === */
.tfoot-stats td { border-top: 2px solid var(--gray-400) !important; font-weight: 600 !important; font-size: 0.78rem; background: var(--gray-100) !important; }
body.dark-mode .tfoot-stats td { background: #1e293b !important; border-color: #475569 !important; }

/* === FAVORITE BUTTON === */
.btn-fav { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--gray-200); background: white; cursor: pointer; transition: all 0.2s; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.btn-fav:hover { border-color: #f59e0b; }
.btn-fav.active { background: #fef3c7; border-color: #f59e0b; color: #d97706; }
body.dark-mode .btn-fav { background: #1e293b; border-color: #334155; }
body.dark-mode .btn-fav.active { background: #78350f; border-color: #92400e; color: #fbbf24; }

/* === DARK MODE DATATABLES FIX === */
body.dark-mode .dataTables_wrapper { color: var(--gray-300); }
body.dark-mode .dataTables_wrapper .dataTables_length,
body.dark-mode .dataTables_wrapper .dataTables_filter,
body.dark-mode .dataTables_wrapper .dataTables_info,
body.dark-mode .dataTables_wrapper .dataTables_paginate { color: var(--gray-300); }
body.dark-mode .dataTables_wrapper .page-link { background: #1e293b; color: var(--gray-300); border-color: #334155; }
body.dark-mode .dataTables_wrapper .page-item.active .page-link { background: var(--primary); border-color: var(--primary); color: #fff; }
body.dark-mode .dataTables_wrapper .page-item.disabled .page-link { background: #0f172a; color: #475569; }
body.dark-mode table.dataTable tbody td { color: var(--gray-200); }
body.dark-mode table.dataTable tbody tr { background: #1e293b; }
body.dark-mode table.dataTable.table-striped>tbody>tr:nth-of-type(odd)>* { background: #162032; color: var(--gray-200); }
body.dark-mode table.dataTable thead th { background: #1e293b; color: var(--gray-200); border-color: #334155; }
body.dark-mode .dt-filter { background: #1e293b !important; color: var(--gray-200) !important; border-color: #334155 !important; }
body.dark-mode .dt-filter::placeholder { color: #64748b; }
body.dark-mode table.dataTable tfoot td { color: var(--gray-200); background: #0f172a; }

/* === DARK MODE BUTTON TEXT === */
body.dark-mode .btn-dark-mode { color: var(--gray-200); }

/* Fix DataTable length select */
.dataTables_length select { padding: 2px 20px 2px 4px !important; min-width: 55px; }
.dataTables_length label { font-size: 0.75rem; }
.chk-dropdown { position:relative; display:inline-block; }
.chk-dropdown-btn { width:150px; font-size:11px; padding:4px 8px; border:1px solid var(--gray-200); border-radius:6px; background:#fff; text-align:left; cursor:pointer; white-space:nowrap; overflow:hidden; display:flex; align-items:center; gap:4px; }
.chk-dd-label { flex:1 1 auto; overflow:hidden; text-overflow:ellipsis; color:#64748b; font-weight:600; }
.chk-dd-caret { flex:0 0 auto; font-size:9px; color:#94a3b8; }
.chk-dropdown.active .chk-dd-label { color:#4f46e5; }
.chk-dropdown.active .chk-dd-caret { color:#4f46e5; }
.chk-dropdown.active .chk-dropdown-btn { border-color:#6366f1; background:#eef2ff; }
body.dark-mode .chk-dropdown-btn { background:#0f172a; border-color:#334155; color:#e2e8f0; }
body.dark-mode .chk-dd-label { color:#94a3b8; }
body.dark-mode .chk-dropdown.active .chk-dropdown-btn { background:#1e1b4b; border-color:#6366f1; }
body.dark-mode .chk-dropdown.active .chk-dd-label { color:#a5b4fc; }
.chk-dropdown-panel { display:none; position:absolute; z-index:100; background:#fff; border:1px solid var(--gray-200); border-radius:8px; box-shadow:0 8px 24px rgba(0,0,0,.15); min-width:180px; max-height:200px; overflow-y:auto; padding:4px 0; }
body.dark-mode .chk-dropdown-panel { background:#1e293b; border-color:#334155; }
.chk-dropdown-panel.show { display:block; }
.chk-dropdown-panel label { display:flex; align-items:center; gap:6px; padding:4px 10px; font-size:11px; cursor:pointer; white-space:nowrap; }
.chk-dropdown-panel label:hover { background:#f1f5f9; }
body.dark-mode .chk-dropdown-panel label:hover { background:#334155; }
.chk-dropdown-panel input[type=checkbox] { margin:0; flex-shrink:0; }
.chk-actions { display:flex; gap:4px; padding:4px 8px; border-top:1px solid var(--gray-100); }
body.dark-mode .chk-actions { border-color:#334155; }
.chk-actions button { font-size:10px; padding:2px 6px; border-radius:4px; border:1px solid var(--gray-200); background:#fff; cursor:pointer; flex:1; }
body.dark-mode .chk-actions button { background:#0f172a; border-color:#334155; color:#e2e8f0; }
.chk-actions button.chk-apply { background:#4f46e5; color:#fff; border-color:#4f46e5; font-weight:600; }
.chk-actions button.chk-apply:hover { background:#4338ca; }
body.dark-mode .chk-actions button.chk-apply { background:#6366f1; color:#fff; border-color:#6366f1; }
body.dark-mode .chk-actions button.chk-apply:hover { background:#4f46e5; }

/* Chips de filtros activos */
.dt-filter-chips { display:flex; flex-wrap:wrap; gap:4px; align-items:center; }
.chip-filter { display:inline-flex; align-items:center; gap:4px; background:#eef2ff; color:#3730a3; border:1px solid #c7d2fe; border-radius:999px; padding:1px 4px 1px 8px; font-size:0.7rem; max-width:260px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.chip-filter b { font-weight:600; overflow:hidden; text-overflow:ellipsis; }
.chip-x { width:15px; height:15px; line-height:13px; text-align:center; border:none; border-radius:50%; background:#c7d2fe; color:#3730a3; font-size:12px; cursor:pointer; padding:0; flex-shrink:0; }
.chip-x:hover { background:#a5b4fc; color:#1e1b4b; }
body.dark-mode .chip-filter { background:#1e1b4b; color:#a5b4fc; border-color:#4338ca; }
body.dark-mode .chip-x { background:#4338ca; color:#c7d2fe; }
body.dark-mode .chip-x:hover { background:#4f46e5; }
#ctxMenu { transition: opacity 0.1s; }
body.dark-mode #ctxMenu { background: #1e293b; border-color: #334155; color: #e2e8f0; }
body.dark-mode #ctxMenu div:hover { background: #334155 !important; }

/* === #70 reduced motion === */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
    #particles-js { display: none; }
    .fade-up, .zoom-in, .btn-login { animation: none !important; transition: none !important; }
    .hero-home, .stat-modern, .action-card { transition: none !important; }
    .app-sidebar { transition: none !important; }
}

/* === #69 aria-live announcements for form validation === */
[aria-live="polite"] { clip: auto; height: auto; overflow: visible; position: relative; width: auto; }
