:root {
    /* --- Vibrant Color Palette (Unified) --- */
    /* Primary Gradient: Deep Blue to Cyan (Vibrant & Professional) */
    --primary-gradient: linear-gradient(135deg, #2E86AB 0%, #00D2FF 100%);
    --primary-color: #2E86AB;
    --primary-light: #00D2FF;

    /* Secondary Gradient: Royal Purple to Magenta (Distinct Accent) */
    --secondary-gradient: linear-gradient(135deg, #A23B72 0%, #E91E63 100%);
    --secondary-color: #A23B72;

    /* Accent & Status Colors */
    --accent-color: #FFC107;
    /* Amber - High Visibility */
    --success-color: #00C853;
    /* Vibrant Green */
    --danger-color: #DC3545;
    /* Vibrant Red */
    --info-color: #17A2B8;
    /* Cyan */

    /* --- Surface & Backgrounds (Light Mode) --- */
    --bg-body: #F4F7F6;
    /* Soft Gray/Blue Tint */
    --bg-surface: #FFFFFF;
    --text-primary: #1E293B;
    /* Slate 800 */
    --text-secondary: #64748B;
    /* Slate 500 */
    --border-color: #E2E8F0;

    /* --- Glassmorphism Tokens --- */
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(255, 255, 255, 0.5);
    --glass-blur: blur(12px);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);

    /* --- Spacing & Layout --- */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    /* Standard Card Radius */
    --radius-xl: 30px;
    --navbar-height: 65px;
}

/* --- Dark Mode Configuration --- */
html[data-theme="dark"] {
    /* Backgrounds */
    --bg-body: #0F172A;
    /* Slate 900 */
    --bg-surface: #1E293B;
    /* Slate 800 */

    /* Text */
    --text-primary: #F8FAFC;
    /* Slate 50 */
    --text-secondary: #94A3B8;
    /* Slate 400 */
    --border-color: #334155;

    /* Glassmorphism Dark */
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);

    /* Adjust Status Colors for Dark BG */
    --accent-color: #FFD54F;
}

/* --- Dark Mode Text Color Overrides --- */
html[data-theme="dark"] .text-gray-800,
html[data-theme="dark"] .text-gray-700,
html[data-theme="dark"] .text-gray-900 {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .text-gray-600,
html[data-theme="dark"] .text-gray-500 {
    color: var(--text-secondary) !important;
}

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

html[data-theme="dark"] .card-label,
html[data-theme="dark"] .card-title {
    color: var(--text-primary) !important;
}

/* Badge overrides for dark mode */
html[data-theme="dark"] .badge-light-primary {
    background-color: rgba(46, 134, 171, 0.4) !important;
    color: #7BC4E8 !important;
    border: 1px solid rgba(123, 196, 232, 0.6) !important;
    font-weight: 600 !important;
}

html[data-theme="dark"] .badge-light-success {
    background-color: rgba(0, 200, 83, 0.4) !important;
    color: #81C784 !important;
    border: 1px solid rgba(129, 199, 132, 0.6) !important;
    font-weight: 600 !important;
}

html[data-theme="dark"] .badge-light-warning {
    background-color: rgba(255, 193, 7, 0.4) !important;
    color: #FFF176 !important;
    border: 1px solid rgba(255, 241, 118, 0.6) !important;
    font-weight: 600 !important;
}

html[data-theme="dark"] .badge-light-danger {
    background-color: rgba(220, 53, 69, 0.4) !important;
    color: #E57373 !important;
    border: 1px solid rgba(229, 115, 115, 0.6) !important;
    font-weight: 600 !important;
}

html[data-theme="dark"] .badge-light-info {
    background-color: rgba(23, 162, 184, 0.4) !important;
    color: #64B5F6 !important;
    border: 1px solid rgba(100, 181, 246, 0.6) !important;
    font-weight: 600 !important;
}

/* Button overrides for better visibility in dark mode */
html[data-theme="dark"] .btn-bg-light {
    background-color: rgba(255, 255, 255, 0.1) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .btn-bg-light:hover {
    background-color: rgba(255, 255, 255, 0.2) !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .btn-icon {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .btn-active-color-success:hover {
    color: #66BB6A !important;
    background-color: rgba(102, 187, 106, 0.2) !important;
}

html[data-theme="dark"] .btn-active-color-info:hover {
    color: #4FC3F7 !important;
    background-color: rgba(79, 195, 247, 0.2) !important;
}

/* Symbol and badge icons for dark mode */
html[data-theme="dark"] .symbol-label {
    background-color: var(--bg-surface) !important;
    border: 1px solid var(--border-color) !important;
}

html[data-theme="dark"] .symbol-label.bg-info {
    background-color: rgba(23, 162, 184, 0.8) !important;
    color: white !important;
}

/* Card overrides for dark mode */
html[data-theme="dark"] .card {
    background-color: var(--bg-surface) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .card-header {
    background-color: rgba(30, 41, 59, 0.8) !important;
    border-bottom: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .card-body {
    color: var(--text-primary) !important;
}

/* Table overrides for dark mode */
html[data-theme="dark"] .table {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .table th {
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

html[data-theme="dark"] .table td {
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

html[data-theme="dark"] .table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(255, 255, 255, 0.02) !important;
}

html[data-theme="dark"] .table-hover tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.05) !important;
}

/* Button overrides for dark mode */
html[data-theme="dark"] .btn-light {
    background-color: var(--bg-surface) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .btn-light:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .btn-outline-primary {
    border-color: var(--primary-color) !important;
    color: var(--primary-light) !important;
}

html[data-theme="dark"] .btn-outline-primary:hover {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
    color: white !important;
}

/* Form control overrides for dark mode */
html[data-theme="dark"] .form-control {
    background-color: var(--bg-surface) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .form-control:focus {
    background-color: var(--bg-surface) !important;
    border-color: var(--primary-light) !important;
    color: var(--text-primary) !important;
    box-shadow: 0 0 0 0.2rem rgba(0, 210, 255, 0.25) !important;
}

html[data-theme="dark"] .form-select {
    background-color: var(--bg-surface) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

/* Alert overrides for dark mode */
html[data-theme="dark"] .alert-info {
    background-color: rgba(23, 162, 184, 0.1) !important;
    border-color: rgba(23, 162, 184, 0.3) !important;
    color: #4FC3F7 !important;
}

/* Global text overrides for better visibility in dark mode */
html[data-theme="dark"] .text-muted {
    color: var(--text-secondary) !important;
}

html[data-theme="dark"] .text-gray-500,
html[data-theme="dark"] .text-gray-600,
html[data-theme="dark"] .text-gray-700,
html[data-theme="dark"] .text-gray-800,
html[data-theme="dark"] .text-gray-900 {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .fw-bold,
html[data-theme="dark"] .fw-semibold {
    color: var(--text-primary) !important;
}

/* Table and DataTable specific overrides */
html[data-theme="dark"] .table {
    --bs-table-bg: var(--bg-surface) !important;
    --bs-table-color: var(--text-primary) !important;
    color: var(--text-primary) !important;
    background-color: var(--bg-surface) !important;
}

html[data-theme="dark"] .table td,
html[data-theme="dark"] .table th {
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
    background-color: transparent !important;
}

html[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > td {
    --bs-table-accent-bg: rgba(255, 255, 255, 0.02) !important;
    background-color: rgba(255, 255, 255, 0.02) !important;
}

html[data-theme="dark"] .table-hover > tbody > tr:hover > td {
    --bs-table-hover-bg: rgba(255, 255, 255, 0.05) !important;
    background-color: rgba(255, 255, 255, 0.05) !important;
}

/* Card glass specific overrides for better dark mode support */
html[data-theme="dark"] .card-glass {
    background: var(--glass-bg) !important;
    backdrop-filter: var(--glass-blur) !important;
    border: 1px solid var(--glass-border) !important;
    color: var(--text-primary) !important;
}

/* Dropdown overrides for dark mode */
html[data-theme="dark"] .dropdown-menu {
    background-color: var(--bg-surface) !important;
    border: 1px solid var(--border-color) !important;
}

html[data-theme="dark"] .dropdown-item {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .dropdown-item:hover,
html[data-theme="dark"] .dropdown-item:focus {
    background-color: rgba(46, 134, 171, 0.2) !important;
    color: var(--text-primary) !important;
}

/* Pagination overrides */
html[data-theme="dark"] .page-link {
    background-color: var(--bg-surface) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .page-link:hover {
    background-color: rgba(46, 134, 171, 0.1) !important;
    border-color: var(--primary-color) !important;
    color: var(--primary-light) !important;
}

/* DataTables specific dark mode overrides */
html[data-theme="dark"] .dataTables_wrapper {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .dataTables_wrapper .dataTables_length,
html[data-theme="dark"] .dataTables_wrapper .dataTables_filter,
html[data-theme="dark"] .dataTables_wrapper .dataTables_info,
html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .dataTables_wrapper .dataTables_length select,
html[data-theme="dark"] .dataTables_wrapper .dataTables_filter input {
    background-color: var(--bg-surface) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
    padding: 0.375rem 0.75rem !important;
    border-radius: 0.375rem !important;
}

html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button {
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
    color: white !important;
}

/* Critical overrides with high specificity */
html[data-theme="dark"] body {
    background-color: var(--bg-body) !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .card,
html[data-theme="dark"] .card-body,
html[data-theme="dark"] .card-header {
    background-color: var(--bg-surface) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

/* Button overrides for better visibility in dark mode */
html[data-theme="dark"] .btn-bg-light {
    background-color: rgba(255, 255, 255, 0.1) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .btn-bg-light:hover {
    background-color: rgba(255, 255, 255, 0.2) !important;
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .btn-icon {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .btn-active-color-success:hover {
    color: #66BB6A !important;
    background-color: rgba(102, 187, 106, 0.2) !important;
}

html[data-theme="dark"] .btn-active-color-info:hover {
    color: #4FC3F7 !important;
    background-color: rgba(79, 195, 247, 0.2) !important;
}

html[data-theme="dark"] .text-gray-800,
html[data-theme="dark"] .text-gray-700,
html[data-theme="dark"] .text-gray-900,
html[data-theme="dark"] .text-dark,
html[data-theme="dark"] .fw-bold,
html[data-theme="dark"] .card-label,
html[data-theme="dark"] .card-title {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .text-gray-600,
html[data-theme="dark"] .text-gray-500,
html[data-theme="dark"] .text-muted {
    color: var(--text-secondary) !important;
}

/* Ensure all badge classes work properly in dark mode */
html[data-theme="dark"] .badge {
    border: 1px solid transparent;
}

html[data-theme="dark"] .badge-primary {
    background-color: var(--primary-color) !important;
    color: white !important;
}

html[data-theme="dark"] .badge-success {
    background-color: var(--success-color) !important;
    color: white !important;
}

html[data-theme="dark"] .badge-warning {
    background-color: var(--accent-color) !important;
    color: #1a1a1a !important;
}

html[data-theme="dark"] .badge-danger {
    background-color: var(--danger-color) !important;
    color: white !important;
}

html[data-theme="dark"] .badge-info {
    background-color: var(--info-color) !important;
    color: white !important;
}

/* Ensure navbar works correctly in dark mode */
html[data-theme="dark"] .navbar-custom {
    background-color: var(--bg-surface) !important;
}

html[data-theme="dark"] .navbar-custom .navbar-brand,
html[data-theme="dark"] .navbar-custom .nav-link {
    color: var(--text-primary) !important;
}

html[data-theme="dark"] .navbar-custom .nav-link:hover {
    color: var(--primary-light) !important;
}

/* Symbol and badge icons for dark mode */
html[data-theme="dark"] .symbol-label {
    background-color: var(--bg-surface) !important;
    border: 1px solid var(--border-color) !important;
}

html[data-theme="dark"] .symbol-label.bg-info {
    background-color: rgba(23, 162, 184, 0.8) !important;
    color: white !important;
}

html[data-theme="dark"] .symbol-label.bg-primary {
    background-color: var(--primary-color) !important;
    color: white !important;
}

html[data-theme="dark"] .symbol-label.bg-success {
    background-color: var(--success-color) !important;
    color: white !important;
}

html[data-theme="dark"] .symbol-label.bg-warning {
    background-color: var(--accent-color) !important;
    color: #1a1a1a !important;
}

html[data-theme="dark"] .symbol-label.bg-danger {
    background-color: var(--danger-color) !important;
    color: white !important;
}

/* Enhanced Badge Light Variants - High Specificity for Both Themes */

/* Light Theme Badge Improvements */
body .badge.badge-light-primary {
    background-color: rgba(46, 134, 171, 0.15) !important;
    color: #2E86AB !important;
    border: 1px solid #2E86AB !important;
    font-weight: 600 !important;
    padding: 0.35em 0.65em !important;
}

body .badge.badge-light-success {
    background-color: rgba(40, 167, 69, 0.15) !important;
    color: #28a745 !important;
    border: 1px solid #28a745 !important;
    font-weight: 600 !important;
    padding: 0.35em 0.65em !important;
}

body .badge.badge-light-warning {
    background-color: rgba(255, 193, 7, 0.15) !important;
    color: #856404 !important;
    border: 1px solid #ffc107 !important;
    font-weight: 600 !important;
    padding: 0.35em 0.65em !important;
}

body .badge.badge-light-danger {
    background-color: rgba(220, 53, 69, 0.15) !important;
    color: #dc3545 !important;
    border: 1px solid #dc3545 !important;
    font-weight: 600 !important;
    padding: 0.35em 0.65em !important;
}

body .badge.badge-light-secondary {
    background-color: rgba(108, 117, 125, 0.15) !important;
    color: #6c757d !important;
    border: 1px solid #6c757d !important;
    font-weight: 600 !important;
    padding: 0.35em 0.65em !important;
}

body .badge.badge-light-info {
    background-color: rgba(13, 202, 240, 0.15) !important;
    color: #0dcaf0 !important;
    border: 1px solid #0dcaf0 !important;
    font-weight: 600 !important;
    padding: 0.35em 0.65em !important;
}

/* Dark Theme Badge Improvements */
html[data-theme="dark"] body .badge.badge-light-primary {
    background-color: rgba(46, 134, 171, 0.8) !important;
    color: #ffffff !important;
    border: 2px solid #2E86AB !important;
    font-weight: 700 !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7) !important;
    min-width: 60px !important;
    padding: 0.35em 0.65em !important;
}

html[data-theme="dark"] body .badge.badge-light-success {
    background-color: rgba(40, 167, 69, 0.8) !important;
    color: #ffffff !important;
    border: 2px solid #28a745 !important;
    font-weight: 700 !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7) !important;
    min-width: 60px !important;
    padding: 0.35em 0.65em !important;
}

html[data-theme="dark"] body .badge.badge-light-warning {
    background-color: rgba(255, 193, 7, 0.9) !important;
    color: #000000 !important;
    border: 2px solid #ffc107 !important;
    font-weight: 700 !important;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5) !important;
    min-width: 60px !important;
    padding: 0.35em 0.65em !important;
}

html[data-theme="dark"] body .badge.badge-light-danger {
    background-color: rgba(220, 53, 69, 0.8) !important;
    color: #ffffff !important;
    border: 2px solid #dc3545 !important;
    font-weight: 700 !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7) !important;
    min-width: 60px !important;
    padding: 0.35em 0.65em !important;
}

html[data-theme="dark"] body .badge.badge-light-secondary {
    background-color: rgba(108, 117, 125, 0.8) !important;
    color: #ffffff !important;
    border: 2px solid #6c757d !important;
    font-weight: 700 !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7) !important;
    min-width: 60px !important;
    padding: 0.35em 0.65em !important;
}

html[data-theme="dark"] body .badge.badge-light-info {
    background-color: rgba(13, 202, 240, 0.9) !important;
    color: #000000 !important;
    border: 2px solid #0dcaf0 !important;
    font-weight: 700 !important;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5) !important;
    min-width: 60px !important;
    padding: 0.35em 0.65em !important;
}

/* Modal and overlay fixes for proper z-index stacking */
.modal {
    z-index: 1055 !important;
}

.modal-backdrop {
    z-index: 1050 !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
}

.modal.show {
    display: block !important;
}

.modal-content {
    position: relative;
    z-index: 1060 !important;
    background: #ffffff !important;
    border: none !important;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
}

/* Dark theme modal fixes */
html[data-theme="dark"] .modal-content {
    background-color: #1f2937 !important;
    color: #ffffff !important;
    border: 1px solid #374151 !important;
}

html[data-theme="dark"] .modal-header {
    border-bottom-color: #374151 !important;
}

html[data-theme="dark"] .modal-footer {
    border-top-color: #374151 !important;
}

html[data-theme="dark"] .btn-close {
    filter: invert(1) !important;
}

/* Form control improvements for better visibility */
.form-control, .form-select {
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out !important;
    border: 1px solid #ced4da !important;
    background-color: #fff !important;
}

.form-control:focus, .form-select:focus {
    outline: 0 !important;
    border-color: var(--primary-color, #2E86AB) !important;
    box-shadow: 0 0 0 0.2rem rgba(46, 134, 171, 0.25) !important;
}

/* Input group addon styling */
.input-group-text {
    border: 1px solid #ced4da !important;
    background-color: #e9ecef !important;
    color: #495057 !important;
}

/* Dark mode form controls */
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
    border: 1px solid #495057 !important;
    background-color: var(--bg-surface, #1e1e1e) !important;
    color: var(--text-primary, #fff) !important;
}

html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus {
    border-color: var(--primary-light, #00D2FF) !important;
    box-shadow: 0 0 0 0.2rem rgba(0, 210, 255, 0.25) !important;
}

html[data-theme="dark"] .input-group-text {
    border: 1px solid #495057 !important;
    background-color: #343a40 !important;
    color: #adb5bd !important;
}

/* Position relative icons properly */
.position-relative .fas {
    pointer-events: none !important;
}

/* Select2 dark mode fixes */
html[data-theme="dark"] .select2-container--default .select2-dropdown {
    background-color: #2b3035 !important;
    border: 1px solid #495057 !important;
}

html[data-theme="dark"] .select2-container--default .select2-results__option {
    color: #ffffff !important;
}

html[data-theme="dark"] .select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: var(--primary-color) !important;
}

/* Enhanced Table Visibility for Dark Mode */
html[data-theme="dark"] .table td,
html[data-theme="dark"] .table th {
    color: #ffffff !important;
    border-color: #495057 !important;
    background-color: transparent !important;
}

html[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > td,
html[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > th {
    background-color: rgba(255, 255, 255, 0.05) !important;
}

html[data-theme="dark"] .table-hover > tbody > tr:hover > td,
html[data-theme="dark"] .table-hover > tbody > tr:hover > th {
    background-color: rgba(46, 134, 171, 0.2) !important;
}

/* Force DataTables to use proper dark styling */
html[data-theme="dark"] .dataTables_wrapper .dataTables_filter input:focus,
html[data-theme="dark"] .dataTables_wrapper .dataTables_length select:focus {
    background-color: #3a4048 !important;
    border-color: var(--primary-color) !important;
    box-shadow: 0 0 0 0.25rem rgba(46, 134, 171, 0.25) !important;
}

/* Navbar dropdown z-index fix - asegurar que esté por encima del contenido */
.navbar.sticky-top {
    z-index: 1030 !important;
}

.navbar .dropdown-menu {
    z-index: 1040 !important;
}

.navbar .dropdown-menu.show {
    z-index: 1040 !important;
}

/* Asegurar que el contenido principal no interfiera con el navbar */
.container-fluid > main,
main[role="main"] {
    position: relative;
    z-index: 1 !important;
}
