:root {
    /* Backgrounds */
    --bg-main: #020617;
    --bg-card: #0f172a;
    --bg-elevated: #1e293b;

    /* Text - Solid colors, no opacity */
    --text-primary: #f8fafc;
    --text-secondary: #e2e8f0;
    --text-muted: #cbd5e1;

    /* Borders */
    --border-subtle: #1e293b;
    --border-strong: #334155;

    /* Accents & Status */
    --accent-primary: #818cf8;
    --accent-primary-rgb: 129, 140, 248;
    --accent-soft: rgba(var(--accent-primary-rgb), 0.1);
    --status-success: #4ade80;
    --status-danger: #f87171;
    --status-warning: #fbbf24;

    /* Utils */
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --header-bg: rgba(15, 23, 42, 0.8);
    --close-filter: invert(1) brightness(1.5);
    --sidebar-bg: #0f172a;
    --sidebar-text: #f8fafc;
}

[data-theme='light'] {
    /* Backgrounds */
    --bg-main: #f1f5f9;
    --bg-card: #ffffff;
    --bg-elevated: #ffffff;

    /* Text - Solid colors, no opacity */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;

    /* Borders */
    --border-subtle: #e2e8f0;
    --border-strong: #cbd5e1;

    /* Accents & Status */
    --accent-primary: #4f46e5;
    --accent-primary-rgb: 79, 70, 229;
    --accent-soft: #f5f3ff;
    --status-success: #15803d;
    --status-danger: #b91c1c;
    --status-warning: #b45309;

    /* Utils */
    --sidebar-bg: #1e293b;
    --header-bg: rgba(255, 255, 255, 0.9);
    --close-filter: none;
}

/* Accessibilty Fixes (Readonly High Contrast) */
[data-theme='dark'] .form-control:disabled,
[data-theme='dark'] .form-control[readonly] {
    background-color: #1e293b !important;
    /* var(--bg-elevated) */
    color: #e2e8f0 !important;
    /* var(--text-secondary) */
    border-color: #334155 !important;
    opacity: 1;
}

/* Bootstrap Utility Overrides for Theme Consistency */
.text-primary {
    color: var(--accent-primary) !important;
}

.text-secondary {
    color: var(--text-secondary) !important;
}

.text-success {
    color: var(--status-success) !important;
}

.icon-profile {
    color: var(--text-primary) !important;
}

.text-danger {
    color: var(--status-danger) !important;
}

.text-warning {
    color: var(--status-warning) !important;
}

.text-muted {
    color: var(--text-muted) !important;
}

.bg-muted {
    background-color: var(--bg-main) !important;
}

/* Bootstrap Card Override for Dark Mode */
.card {
    background-color: var(--bg-card);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

.bg-light {
    background-color: var(--bg-main) !important;
}

.bg-white {
    background-color: var(--bg-card) !important;
}

/* Dark Mode Form Overrides */
.form-control,
.form-select,
.input-group-text {
    background-color: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-strong) !important;
}

.form-control:focus,
.form-select:focus {
    background-color: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border-color: var(--accent-primary) !important;
    box-shadow: 0 0 0 0.25rem var(--accent-soft) !important;
}

/* Placeholder color fix */
.form-control::placeholder {
    color: var(--text-muted) !important;
    opacity: 1;
}

/* Disabled state */
.form-control:disabled,
.form-control[readonly],
.form-select:disabled {
    background-color: var(--bg-main) !important;
    color: var(--text-secondary) !important;
    opacity: 1;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    overflow-x: hidden;
    margin: 0;
    transition: var(--transition);
}

/* Layout Structure */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    position: fixed;
    height: 100vh;
    z-index: 1000;
}

.sidebar-brand {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 2.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--sidebar-text);
    text-decoration: none;
}

.sidebar-brand .material-symbols-outlined {
    color: var(--accent-primary);
    font-size: 28px;
}

.sidebar-brand img {
    height: 38px;
    width: 38px;
    object-fit: contain;
    border-radius: 6px;
    background-color: white;
    padding: 3px;
    flex-shrink: 0;
    margin-right: 4px;
}

.sidebar-brand span {
    line-height: 1;
}

[data-theme='dark'] .sidebar-brand img {
    filter: brightness(0.9);
}

.sidebar-link {
    color: #94a3b8;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: var(--transition);
    text-decoration: none;
}

.sidebar-link .material-symbols-outlined {
    font-size: 24px;
    color: inherit;
}

.sidebar-link:hover,
.sidebar-link.active {
    background-color: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.sidebar-link.active {
    color: var(--accent-primary) !important;
    font-weight: 600;
}

.sidebar-link.active .material-symbols-outlined {
    color: var(--accent-primary);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 10px 30px 30px;
    transition: var(--transition);
    min-height: 100vh;
}

/* Header */
.header {
    position: sticky;
    top: 0;
    background-color: var(--header-bg);
    backdrop-filter: blur(12px);
    padding: 1.25rem 0;
    margin-bottom: 2rem;
    z-index: 900;
    border-bottom: 2px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Cards & Stats */
.card-custom {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    transition: var(--transition);
    margin-bottom: 1.5rem;
}

.card-custom:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    border-color: var(--border-strong);
}

/* Table Design */
.table-responsive {
    border-radius: 0.75rem;
    overflow: hidden !important;
    border: 1px solid var(--border-subtle);
    background: var(--bg-card);
}

.table {
    margin-bottom: 0;
    border-collapse: separate;
    border-spacing: 0;
}

.table th {
    background-color: var(--bg-main);
    color: var(--text-secondary);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    padding: 1rem;
    border-bottom: 2px solid var(--border-strong);
    cursor: pointer;
    transition: var(--transition);
}

.table th:hover {
    color: var(--accent-primary);
    background-color: var(--accent-soft);
}

.table td {
    padding: 1.25rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    font-size: 0.9375rem;
}

.table-hover tbody tr:hover {
    background-color: var(--accent-soft);
}

/* Dark Mode Table Overrides */
[data-theme='dark'] .table {
    background-color: transparent !important;
}

[data-theme='dark'] .table td {
    background-color: transparent !important;
    color: var(--text-primary) !important;
}

[data-theme='dark'] .table-hover tbody tr {
    background-color: var(--bg-card) !important;
}

[data-theme='dark'] .table-hover tbody tr:hover {
    background-color: var(--accent-soft) !important;
}

/* Modal Tables in Dark Mode Fix */
[data-theme='dark'] .modal-body table,
[data-theme='dark'] .modal-body thead,
[data-theme='dark'] .modal-body tbody,
[data-theme='dark'] .modal-body tr,
[data-theme='dark'] .modal-body td {
    background-color: var(--bg-elevated) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-subtle) !important;
}

/* Badges */
.badge-status {
    padding: 0.375rem 0.875rem;
    border-radius: 0.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-block;
    text-transform: capitalize;
}

.status-activo {
    background-color: rgba(34, 197, 94, 0.1);
    color: #22c55e;
    border: 1px solid #22c55e;
}

[data-theme='dark'] .status-activo {
    background-color: rgba(34, 197, 94, 0.15);
    color: #4ade80;
    border: 1px solid #4ade80;
}

.status-inactivo {
    background-color: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid #ef4444;
}

[data-theme='dark'] .status-inactivo {
    background-color: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid #f87171;
}

/* Search & Filters */
.search-wrapper {
    position: relative;
    width: 100%;
}

.search-wrapper i {
    position: absolute;
    left: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-wrapper input {
    padding: 0.75rem 1rem 0.75rem 3rem;
    border-radius: 0.75rem;
    border: 2px solid var(--border-strong);
    background: var(--bg-card);
    color: var(--text-primary);
    font-weight: 500;
    transition: var(--transition);
}

.search-wrapper input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

.search-wrapper input:focus {
    outline: none;
    box-shadow: 0 0 0 4px var(--accent-soft);
    border-color: var(--accent-primary);
}

/* Theme Toggle */
.theme-toggle {
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-card);
    border: 2px solid var(--border-strong);
    color: var(--text-primary);
    transition: var(--transition);
}

.theme-toggle:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background-color: var(--accent-soft);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-main);
}

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 10px;
    border: 2px solid var(--bg-main);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Modal Enhancements */
.modal-content {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 1.25rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-header {
    border-bottom: 2px solid var(--border-subtle);
    padding: 1.5rem 2rem;
}

.modal-title {
    font-weight: 800;
    color: var(--text-primary);
}

.modal-body {
    padding: 2rem;
    max-height: 80vh;
    overflow-y: auto;
    color: var(--text-primary);
}

.modal-body label {
    color: var(--text-secondary);
    font-weight: 700;
    margin-bottom: 0.5rem;
    display: block;
}

.btn-close {
    filter: var(--close-filter);
    opacity: 1;
    /* Override bootstrap default opacity */
}

/* Helper Classes */
.text-gradient {
    background: linear-gradient(135deg, var(--accent-primary) 0%, #a855f7 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

/* Responsive */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
        width: 260px;
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }
}

@media (max-width: 900px) {
    .sidebar,
    .sidebar.sidebar-collapsed {
        position: fixed;
        z-index: 1300;
    }

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

    .main-content {
        width: 100%;
        margin-left: 0;
        padding: 66px 12px 24px;
    }
}

/* Tabs for Detail Modal */
.modal-tabs {
    display: flex;
    gap: 1rem;
    border-bottom: 2px solid var(--border-subtle);
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    overflow-x: auto;
}

.modal-tab {
    padding: 0.5rem 1rem;
    cursor: pointer;
    border-radius: 0.5rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: var(--transition);
    white-space: nowrap;
}

.modal-tab:hover {
    background-color: var(--accent-soft);
    color: var(--accent-primary);
}

.modal-tab.active {
    background-color: var(--accent-primary);
    color: white;
}

.modal-tab span {
    font-size: 1.2rem;
    vertical-align: middle;
}

/* Payment Card Style */
.payment-card {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: 1rem;
    padding: 1.25rem;
    margin-bottom: 1rem;
    position: relative;
    transition: var(--transition);
}

.payment-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.payment-card-badge {
    position: absolute;
    top: -10px;
    right: 20px;
    background: var(--accent-primary);
    color: white;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: bold;
}

/* Checkbox Buttons (Pills) */
.btn-check-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-check-pill {
    display: block;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border-subtle);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    text-align: center;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-check-pill:hover {
    border-color: var(--accent-primary);
    background: var(--accent-soft);
    color: var(--accent-primary);
}

.btn-check:checked+.btn-check-pill {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.payment-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(0, 0, 0, 0.02);
    padding: 0.75rem;
    border-radius: 0.75rem;
    margin-bottom: 0.5rem;
    border: 1px dashed var(--border-subtle);
}

.payment-row-num {
    width: 70px;
    font-weight: bold;
    color: var(--accent-primary);
    font-size: 0.8rem;
    text-transform: uppercase;
}

/* Custom Autocomplete UI (Wizard v3.0) */
.autocomplete-container {
    position: relative;
    width: 100%;
}

.autocomplete-results {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background-color: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-top: none;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    max-height: 250px;
    overflow-y: auto;
    z-index: 9999;
    display: none;
    /* Hidden by default */
}

.autocomplete-item {
    padding: 10px 15px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: var(--transition);
    border-bottom: 1px solid var(--border-subtle);
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background-color: var(--accent-soft);
    color: var(--accent-primary);
}

/* Fixed Wizard Layout spacing */
#wizardModal .modal-body {
    min-height: 400px;
    /* Reduced since lists are absolute now */
    padding-bottom: 50px;
}

/* Dashboard Glassmorphism */
.glass-card {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1.25rem;
    padding: 2rem 1rem;
    text-align: center;
    transition: var(--transition);
    cursor: pointer;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

[data-theme='light'] .glass-card {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.05);
}

.glass-card:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-primary);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.glass-card .icon {
    font-size: 2.5rem;
    color: var(--accent-primary);
}

.glass-card h6 {
    margin: 0;
    font-weight: 700;
    color: var(--text-primary);
}

.icon-circle {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
