/* ═══════════════════════════════════════════════════════════════════
   NYX CRM — DARK THEME LAYER
   Se carga DESPUÉS de todas las hojas (incl. MudBlazor) para unificar
   el modo oscuro. Consume SOLO tokens (definidos en dashboard.css):
   --bg / --surface / --surface-2 / --surface-3 / --line / --line-strong
   --text / --text-2 / --muted / --faint / --brand / semánticos.
   Cambiar la tonalidad (Grafito / Medianoche / Carbón) re-pinta todo.
   ═══════════════════════════════════════════════════════════════════ */

/* ───────────────── 0. BASE ───────────────── */
[data-theme="dark"] {
    scrollbar-color: var(--line-strong) transparent;
}

[data-theme="dark"] ::selection {
    background: var(--brand-ring);
    color: #fff;
}

[data-theme="dark"] ::-webkit-scrollbar-track { background: transparent !important; }
[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: var(--line-strong) !important;
    border-radius: 10px;
}
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: var(--faint) !important; }

/* Bootstrap 5.3 → se mapea a los tokens NYX (data-bs-theme="dark" lo pone UserPreferencesService) */
[data-theme="dark"],
[data-bs-theme="dark"] {
    --bs-body-bg: var(--surface);
    --bs-body-bg-rgb: 22, 26, 33;
    --bs-body-color: var(--text);
    --bs-emphasis-color: var(--text);
    --bs-heading-color: var(--text);
    --bs-secondary-color: var(--muted);
    --bs-tertiary-color: var(--faint);
    --bs-secondary-bg: var(--surface-2);
    --bs-tertiary-bg: var(--surface-2);
    --bs-border-color: var(--line);
    --bs-border-color-translucent: var(--line);
    --bs-link-color: var(--brand);
    --bs-link-hover-color: var(--brand-strong);
    --bs-primary-bg-subtle: var(--brand-soft);
    --bs-success-bg-subtle: var(--ok-soft);
    --bs-warning-bg-subtle: var(--warn-soft);
    --bs-danger-bg-subtle: var(--err-soft);
    --bs-info-bg-subtle: var(--info-soft);
    --bs-primary-text-emphasis: var(--brand);
    --bs-success-text-emphasis: var(--ok);
    --bs-warning-text-emphasis: var(--warn);
    --bs-danger-text-emphasis: var(--err);
    --bs-info-text-emphasis: var(--info);
    --bs-primary-border-subtle: var(--brand-ring);
    --bs-success-border-subtle: var(--ok-line);
    --bs-warning-border-subtle: var(--warn-line);
    --bs-danger-border-subtle: var(--err-line);
    --bs-info-border-subtle: var(--info-line);
}

/* MudBlazor → tokens (IsDarkMode activa la variante; aquí se aplica la tonalidad) */
[data-theme="dark"] {
    --mud-palette-background: var(--bg);
    --mud-palette-background-gray: var(--surface-2);
    --mud-palette-surface: var(--surface);
    --mud-palette-appbar-background: var(--surface);
    --mud-palette-drawer-background: var(--surface);
    --mud-palette-text-primary: var(--text);
    --mud-palette-text-secondary: var(--muted);
    --mud-palette-lines-default: var(--line);
    --mud-palette-lines-inputs: var(--line-strong);
    --mud-palette-table-lines: var(--line);
    --mud-palette-divider: var(--line);
    --mud-palette-divider-light: var(--line);
    --mud-palette-action-default: var(--text-2);
    --mud-palette-overlay-dark: var(--overlay);
}

/* ───────────────── 1. SHELL ───────────────── */
[data-theme="dark"] .rail {
    background: var(--surface) !important;
    box-shadow: 0 0 0 1px var(--line), var(--shadow) !important;
}

[data-theme="dark"] .item:hover,
[data-theme="dark"] .me:hover { background: var(--surface-2) !important; }

[data-theme="dark"] .logo-box {
    background: var(--surface-3) !important;
    box-shadow: 0 0 0 1px var(--line-strong) !important;
}

[data-theme="dark"] .rail:not(.open) .item[data-tip]:hover::after {
    background: var(--surface-3) !important;
    color: var(--text) !important;
    border: 1px solid var(--line-strong);
    box-shadow: var(--shadow-pop) !important;
}

[data-theme="dark"] .search,
[data-theme="dark"] .pill {
    background: var(--surface) !important;
    border-color: var(--line) !important;
    color: var(--muted) !important;
    box-shadow: 0 0 0 1px var(--line) !important;
}

[data-theme="dark"] .search:hover { color: var(--text) !important; }
[data-theme="dark"] .pill span { color: var(--text) !important; }

[data-theme="dark"] kbd {
    background: var(--surface-3) !important;
    color: var(--text-2) !important;
    border: 1px solid var(--line-strong) !important;
    box-shadow: none !important;
}

/* ───────────────── 2. TARJETAS / PANELES ───────────────── */
[data-theme="dark"] .card,
[data-theme="dark"] .premium-card,
[data-theme="dark"] .recording-card,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .card-panel,
[data-theme="dark"] .audit-card,
[data-theme="dark"] .role-card,
[data-theme="dark"] .kb-card,
[data-theme="dark"] .admin-header,
[data-theme="dark"] .sidebar,
[data-theme="dark"] .sb-head,
[data-theme="dark"] .client-card,
[data-theme="dark"] .details-panel,
[data-theme="dark"] .asesor-hero-card,
[data-theme="dark"] .asesor-kpi-card,
[data-theme="dark"] .table-card,
[data-theme="dark"] .tracking-checkpoint-card,
[data-theme="dark"] .venta-section-card,
[data-theme="dark"] .preview-invoice-card,
[data-theme="dark"] .timeline-preview-card,
[data-theme="dark"] .hub-quick-kpi,
[data-theme="dark"] .settings-card,
[data-theme="dark"] .belt-card,
[data-theme="dark"] .advisor-node-card,
[data-theme="dark"] .leads-flow-card,
[data-theme="dark"] .checkpoint-deck-card,
[data-theme="dark"] .lead-hero-box,
[data-theme="dark"] .lead-strip-item {
    background: var(--surface) !important;
    background-color: var(--surface) !important;
    border: 1px solid var(--line) !important;
    color: var(--text) !important;
    box-shadow: var(--shadow) !important;
}

[data-theme="dark"] .magnitud-panel,
.theme-dark .magnitud-panel {
    background: var(--surface-2) !important;
    border: 1px solid var(--line) !important;
    box-shadow: none !important;
}

/* ─── Tonalidad Grafito: Sombra de alta definición y separación de cards ─── */
:is([data-theme="dark"]:not([data-tone]), [data-theme="dark"][data-tone="pure"], .theme-dark:not([data-tone]), .theme-dark.tone-pure) :is(
    .details-panel,
    .asesor-hero-card,
    .asesor-kpi-card,
    .table-card,
    .tracking-checkpoint-card,
    .venta-section-card,
    .preview-invoice-card,
    .timeline-preview-card,
    .hub-quick-kpi,
    .settings-card,
    .belt-card,
    .advisor-node-card,
    .leads-flow-card,
    .checkpoint-deck-card,
    .lead-hero-box,
    .lead-strip-item
) {
    border: 1px solid var(--line) !important;
    box-shadow: 0 12px 34px -4px rgba(0, 0, 0, 0.82), 0 4px 14px -2px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.08) !important;
}

:is([data-theme="dark"]:not([data-tone]), [data-theme="dark"][data-tone="pure"], .theme-dark:not([data-tone]), .theme-dark.tone-pure) :is(
    .belt-card:hover,
    .advisor-node-card:hover,
    .leads-flow-card:hover,
    .checkpoint-deck-card:hover,
    .lead-strip-item:hover,
    .asesor-lead-card:hover,
    .table-card:hover
) {
    box-shadow: 0 18px 46px -6px rgba(0, 0, 0, 0.92), 0 6px 18px -2px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.15) !important;
    border-color: var(--line-strong) !important;
}

[data-theme="dark"] .hub-header,
.theme-dark .hub-header,
[data-theme="dark"] .hub-profile-row,
.theme-dark .hub-profile-row {
    background: transparent !important;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
}

[data-theme="dark"] .recording-card {
    background: radial-gradient(circle at top left, var(--brand-soft) 0%, transparent 60%), var(--surface) !important;
}

[data-theme="dark"] .asesor-hero-card {
    background:
        radial-gradient(120% 140% at 0% 0%, var(--brand-soft) 0%, transparent 55%),
        var(--surface) !important;
}

/* Tarjeta de lead (Asesor) */
[data-theme="dark"] .asesor-lead-card {
    background: var(--surface) !important;
    border: 1px solid var(--line) !important;
    box-shadow: var(--shadow) !important;
}

[data-theme="dark"] .asesor-lead-card:hover {
    background: var(--surface-2) !important;
    border-color: var(--brand-ring) !important;
    box-shadow: 0 14px 34px -10px rgba(0, 0, 0, .7), 0 0 0 1px var(--brand-ring) !important;
}

[data-theme="dark"] .card-client-name,
[data-theme="dark"] .card-detail-value { color: var(--text) !important; }

[data-theme="dark"] .card-detail-label,
[data-theme="dark"] .card-lead-date { color: var(--muted) !important; }

[data-theme="dark"] .card-phone-pill {
    background-color: var(--surface-2) !important;
    border-color: var(--line) !important;
    color: var(--text) !important;
}

[data-theme="dark"] .card-phone-pill i { color: var(--muted) !important; }

[data-theme="dark"] .card-pill-badge,
[data-theme="dark"] .card-pill-badge.neutral,
[data-theme="dark"] .timeline-compact-pill,
[data-theme="dark"] .stepper-current-pill,
[data-theme="dark"] .cp-item-pill.next-pill,
[data-theme="dark"] .cp-item-pill.current-pill.blocked-pill,
[data-theme="dark"] .nyx-table-badge.secondary,
[data-theme="dark"] .tag-mod {
    background: var(--surface-2) !important;
    border-color: var(--line-strong) !important;
    color: var(--text-2) !important;
}

[data-theme="dark"] .card-progress-track { background-color: var(--surface-3) !important; }

[data-theme="dark"] .btn-card-dots { color: var(--muted) !important; }
[data-theme="dark"] .btn-card-dots:hover {
    background: var(--surface-3) !important;
    color: var(--text) !important;
}

/* Menú contextual de las cards (Información / Ficha / Asignar / Historial) */
[data-theme="dark"] .card-dropdown-menu-custom {
    background: var(--surface-3) !important;
    border: 1px solid var(--line-strong) !important;
    box-shadow: var(--shadow-pop) !important;
    opacity: 1 !important;
    backdrop-filter: none !important;
}

[data-theme="dark"] .card-dropdown-item-custom { color: var(--text) !important; }
[data-theme="dark"] .card-dropdown-item-custom:hover { background: rgba(255, 255, 255, 0.06) !important; }
[data-theme="dark"] .card-dropdown-text { color: var(--text) !important; }
[data-theme="dark"] .card-dropdown-icon { color: var(--muted) !important; }
[data-theme="dark"] .card-dropdown-item-custom:hover .card-dropdown-text { color: #fff !important; }
[data-theme="dark"] .card-dropdown-item-custom:hover .card-dropdown-icon { color: var(--brand) !important; }

/* ───────────────── 3. HERO / TOOLBAR ASESOR ───────────────── */
[data-theme="dark"] .hero-toggle-group,
[data-theme="dark"] .btn-hero-search {
    background: var(--surface-2) !important;
    border-color: var(--line) !important;
    color: var(--text) !important;
}

[data-theme="dark"] .btn-hero-search:hover,
[data-theme="dark"] .hero-toggle-btn:hover:not(.active) {
    background: var(--surface-3) !important;
    color: var(--text) !important;
}

[data-theme="dark"] .hero-toggle-btn:not(.active) { color: var(--muted) !important; background: transparent !important; }

[data-theme="dark"] .hero-toggle-btn.active,
[data-theme="dark"] .btn-hero-cta {
    background: var(--brand-strong) !important;
    border-color: var(--brand-strong) !important;
    color: #fff !important;
    box-shadow: 0 6px 18px -6px var(--brand-ring) !important;
}

[data-theme="dark"] .btn-hero-cta:hover {
    background: var(--brand) !important;
    border-color: var(--brand) !important;
}

/* KPI pills (Pre-Ventas / Convertidas / Aprobadas) */
[data-theme="dark"] .kpi-pill-badge { box-shadow: none !important; }

[data-theme="dark"] .kpi-pill-blue {
    background: var(--info-soft) !important;
    border-color: var(--info-line) !important;
    color: var(--text-2) !important;
}
[data-theme="dark"] .kpi-pill-blue .kpi-pill-val { color: var(--info) !important; }

[data-theme="dark"] .kpi-pill-green {
    background: var(--ok-soft) !important;
    border-color: var(--ok-line) !important;
    color: var(--text-2) !important;
}
[data-theme="dark"] .kpi-pill-green .kpi-pill-val { color: var(--ok) !important; }

[data-theme="dark"] .kpi-pill-purple {
    background: var(--violet-soft) !important;
    border-color: var(--violet-line) !important;
    color: var(--text-2) !important;
}
[data-theme="dark"] .kpi-pill-purple .kpi-pill-val { color: var(--violet) !important; }

/* ───────────────── 4. UTILIDADES BOOTSTRAP ───────────────── */
[data-theme="dark"] .text-dark,
[data-theme="dark"] .text-black,
[data-theme="dark"] .text-body,
[data-theme="dark"] .text-body-emphasis { color: var(--text) !important; }

[data-theme="dark"] .text-secondary { color: var(--text-2) !important; }
[data-theme="dark"] .text-muted,
[data-theme="dark"] .text-body-secondary { color: var(--muted) !important; }

[data-theme="dark"] .text-primary { color: var(--brand) !important; }
[data-theme="dark"] .text-success { color: var(--ok) !important; }
[data-theme="dark"] .text-danger  { color: var(--err) !important; }
[data-theme="dark"] .text-warning { color: var(--warn) !important; }
[data-theme="dark"] .text-info    { color: var(--info) !important; }

[data-theme="dark"] .bg-white,
[data-theme="dark"] .bg-body {
    background-color: var(--surface) !important;
    color: var(--text) !important;
}

[data-theme="dark"] .bg-light,
[data-theme="dark"] .bg-body-tertiary,
[data-theme="dark"] .bg-body-secondary {
    background-color: var(--surface-2) !important;
    color: var(--text) !important;
}

[data-theme="dark"] .bg-primary.bg-opacity-10,
[data-theme="dark"] .bg-primary-subtle { background-color: var(--brand-soft) !important; }
[data-theme="dark"] .bg-success.bg-opacity-10,
[data-theme="dark"] .bg-success-subtle { background-color: var(--ok-soft) !important; }
[data-theme="dark"] .bg-danger.bg-opacity-10,
[data-theme="dark"] .bg-danger-subtle  { background-color: var(--err-soft) !important; }
[data-theme="dark"] .bg-warning.bg-opacity-10,
[data-theme="dark"] .bg-warning-subtle { background-color: var(--warn-soft) !important; }
[data-theme="dark"] .bg-info.bg-opacity-10,
[data-theme="dark"] .bg-info-subtle    { background-color: var(--info-soft) !important; }
[data-theme="dark"] .bg-secondary.bg-opacity-10,
[data-theme="dark"] .bg-secondary-subtle { background-color: var(--surface-3) !important; }

[data-theme="dark"] .border,
[data-theme="dark"] .border-top,
[data-theme="dark"] .border-bottom,
[data-theme="dark"] .border-start,
[data-theme="dark"] .border-end,
[data-theme="dark"] .border-light,
[data-theme="dark"] .border-secondary-subtle,
[data-theme="dark"] .border-light-subtle { border-color: var(--line) !important; }

[data-theme="dark"] .shadow-sm { box-shadow: 0 1px 2px rgba(0, 0, 0, .4) !important; }
[data-theme="dark"] .shadow,
[data-theme="dark"] .shadow-lg { box-shadow: var(--shadow-pop) !important; }

/* Botones */
[data-theme="dark"] .btn-light,
[data-theme="dark"] .btn-white,
[data-theme="dark"] .btn.bg-white {
    background: var(--surface-2) !important;
    border-color: var(--line-strong) !important;
    color: var(--text) !important;
}

[data-theme="dark"] .btn-outline-secondary,
[data-theme="dark"] .btn-outline-dark,
[data-theme="dark"] .btn-outline-light {
    background: transparent !important;
    border-color: var(--line-strong) !important;
    color: var(--text-2) !important;
}

[data-theme="dark"] .btn-light:hover,
[data-theme="dark"] .btn-white:hover,
[data-theme="dark"] .btn-outline-secondary:hover:not(:disabled),
[data-theme="dark"] .btn-outline-dark:hover:not(:disabled) {
    background: var(--surface-3) !important;
    border-color: var(--faint) !important;
    color: var(--text) !important;
}

[data-theme="dark"] .btn-outline-secondary:disabled,
[data-theme="dark"] .btn-outline-secondary.disabled {
    opacity: .4 !important;
}

[data-theme="dark"] .btn-primary,
[data-theme="dark"] .btn-outline-primary.active,
[data-theme="dark"] .page-item.active .page-link {
    background: var(--brand-strong) !important;
    border-color: var(--brand-strong) !important;
    color: #fff !important;
}

[data-theme="dark"] .btn-outline-primary {
    border-color: var(--brand-ring) !important;
    color: var(--brand) !important;
}

[data-theme="dark"] .btn-outline-primary:hover {
    background: var(--brand-soft) !important;
}

[data-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(1.6);
    opacity: .7;
}

/* Formularios */
[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not(.form-input):not(#login-form input),
[data-theme="dark"] select,
[data-theme="dark"] textarea,
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="dark"] .input-group-text {
    background-color: var(--surface-2) !important;
    border-color: var(--line-strong) !important;
    color: var(--text) !important;
}

[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder { color: var(--faint) !important; }

[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus,
[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus {
    background-color: var(--surface-3) !important;
    border-color: var(--brand) !important;
    box-shadow: 0 0 0 3px var(--brand-soft) !important;
}

[data-theme="dark"] input:disabled,
[data-theme="dark"] .form-control:disabled,
[data-theme="dark"] .form-control[readonly] {
    background-color: var(--surface) !important;
    color: var(--muted) !important;
}

[data-theme="dark"] .form-check-input {
    background-color: var(--surface-3);
    border-color: var(--line-strong);
}

[data-theme="dark"] .form-check-input:checked {
    background-color: var(--brand-strong);
    border-color: var(--brand-strong);
}

/* Dropdowns */
[data-theme="dark"] .dropdown-menu {
    background-color: var(--surface-3) !important;
    border: 1px solid var(--line-strong) !important;
    color: var(--text) !important;
    box-shadow: var(--shadow-pop) !important;
}

[data-theme="dark"] .dropdown-item,
[data-theme="dark"] .dropdown-item.text-dark { color: var(--text) !important; }

[data-theme="dark"] .dropdown-item:hover,
[data-theme="dark"] .dropdown-item:focus {
    background-color: rgba(255, 255, 255, 0.06) !important;
    color: #fff !important;
}

[data-theme="dark"] .dropdown-item.active,
[data-theme="dark"] .dropdown-item:active {
    background-color: var(--brand-strong) !important;
    color: #fff !important;
}

[data-theme="dark"] .dropdown-divider { border-color: var(--line) !important; }

/* Tablas */
[data-theme="dark"] .table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.02);
    --bs-table-hover-bg: var(--surface-2);
    --bs-table-border-color: var(--line);
    color: var(--text) !important;
}

[data-theme="dark"] .table-modern-asesor,
.theme-dark .table-modern-asesor {
    --bs-table-bg: transparent !important;
    --bs-table-striped-bg: transparent !important;
    --bs-table-hover-bg: var(--surface-2) !important;
    background-color: transparent !important;
}

[data-theme="dark"] table th,
[data-theme="dark"] .table-modern-asesor thead th,
[data-theme="dark"] .table-light th,
[data-theme="dark"] thead.table-light th {
    background-color: var(--surface-2) !important;
    color: var(--muted) !important;
    border-color: var(--line) !important;
}

[data-theme="dark"] table td,
[data-theme="dark"] .table-modern-asesor td {
    border-color: var(--line) !important;
    color: var(--text) !important;
}

[data-theme="dark"] .table-modern-asesor tbody tr,
.theme-dark .table-modern-asesor tbody tr {
    background-color: transparent !important;
}

[data-theme="dark"] .table-modern-asesor tbody tr > *,
.theme-dark .table-modern-asesor tbody tr > * {
    background-color: transparent !important;
    color: var(--text) !important;
}

[data-theme="dark"] .table-modern-asesor tbody tr:nth-child(even),
.theme-dark .table-modern-asesor tbody tr:nth-child(even),
[data-theme="dark"] .table-modern-asesor tbody tr:nth-child(even) > *,
.theme-dark .table-modern-asesor tbody tr:nth-child(even) > * {
    background-color: rgba(255, 255, 255, 0.025) !important;
}

[data-theme="dark"] .table-hover tbody tr:hover > *,
[data-theme="dark"] .table-modern-asesor tbody tr:hover,
[data-theme="dark"] .table-modern-asesor tbody tr:hover > * { background-color: var(--surface-2) !important; }

[data-theme="dark"] .table-modern-asesor .text-dark,
.theme-dark .table-modern-asesor .text-dark {
    color: #F8FAFC !important;
}

/* Lista / nav / paginación / alertas */
[data-theme="dark"] .list-group-item {
    background-color: var(--surface) !important;
    border-color: var(--line) !important;
    color: var(--text) !important;
}

[data-theme="dark"] .list-group-item-action:hover { background-color: var(--surface-2) !important; }

[data-theme="dark"] .nav-tabs { border-color: var(--line) !important; }
[data-theme="dark"] .nav-tabs .nav-link { color: var(--muted) !important; }
[data-theme="dark"] .nav-tabs .nav-link.active {
    background: var(--surface) !important;
    border-color: var(--line) var(--line) var(--surface) !important;
    color: var(--text) !important;
}

[data-theme="dark"] .page-link {
    background: transparent !important;
    border-color: var(--line-strong) !important;
    color: var(--text-2) !important;
}

[data-theme="dark"] .page-link:hover { background: var(--surface-3) !important; color: var(--text) !important; }

[data-theme="dark"] .alert-info    { background: var(--info-soft) !important; border-color: var(--info-line) !important; color: var(--text) !important; }
[data-theme="dark"] .alert-success { background: var(--ok-soft) !important;   border-color: var(--ok-line) !important;   color: var(--text) !important; }
[data-theme="dark"] .alert-warning { background: var(--warn-soft) !important; border-color: var(--warn-line) !important; color: var(--text) !important; }
[data-theme="dark"] .alert-danger  { background: var(--err-soft) !important;  border-color: var(--err-line) !important;  color: var(--text) !important; }
[data-theme="dark"] .alert-light,
[data-theme="dark"] .alert-secondary { background: var(--surface-2) !important; border-color: var(--line) !important; color: var(--text) !important; }

[data-theme="dark"] .badge.bg-light,
[data-theme="dark"] .badge.bg-white {
    background: var(--surface-3) !important;
    color: var(--text-2) !important;
}

[data-theme="dark"] .badge.bg-warning.text-dark { color: #1a1300 !important; }

[data-theme="dark"] hr { border-color: var(--line) !important; opacity: 1; }

/* ───────────────── 5. MODALES (contenedor) ───────────────── */
/* Overlays: oscurecen + desenfoque, sin “lavado” blanco */
[data-theme="dark"] .modal-backdrop-custom,
[data-theme="dark"] .modal-backdrop-blur,
[data-theme="dark"] .venta-modal-overlay,
[data-theme="dark"] .u-modal-overlay,
[data-theme="dark"] .audit-modal-overlay,
[data-theme="dark"] .aggressive-handshake-overlay,
[data-theme="dark"] .modal.show,
[data-theme="dark"] .modal[style*="display: block"],
[data-theme="dark"] .modal[style*="display:block"] {
    background-color: var(--overlay) !important;
}

[data-theme="dark"] .modal-backdrop { background-color: #000 !important; }
[data-theme="dark"] .modal-backdrop.show { opacity: .7 !important; }

/* Cajas de modal */
[data-theme="dark"] .modal-content,
[data-theme="dark"] .modal-card,
[data-theme="dark"] .modal-box-custom,
[data-theme="dark"] .modal-container,
[data-theme="dark"] .venta-modal-box,
[data-theme="dark"] .presale-modal-card,
[data-theme="dark"] .u-modal-card,
[data-theme="dark"] .audit-modal,
[data-theme="dark"] .derivacion-modal,
[data-theme="dark"] .devolucion-modal,
[data-theme="dark"] .handshake-v2-modal,
[data-theme="dark"] .double-calendar-popup,
[data-theme="dark"] .mud-dialog {
    background: var(--surface) !important;
    background-color: var(--surface) !important;
    border: 1px solid var(--line-strong) !important;
    color: var(--text) !important;
    box-shadow: var(--shadow-pop) !important;
}

/* Doble Calendario & Filtros Asesor Dark */
[data-theme="dark"] .nyx-filter-bar,
.dark-theme .nyx-filter-bar {
    background: var(--surface) !important;
    background-color: var(--surface) !important;
    border-color: var(--line) !important;
}
[data-theme="dark"] .nyx-search-box-v2,
.dark-theme .nyx-search-box-v2,
[data-theme="dark"] .custom-filter-trigger,
.dark-theme .custom-filter-trigger,
[data-theme="dark"] .range-box-trigger,
.dark-theme .range-box-trigger {
    background: var(--surface-2, #1E293B) !important;
    border-color: var(--line, #334155) !important;
    color: var(--text, #F8FAFC) !important;
}
[data-theme="dark"] .nyx-search-box-v2 .search-input,
.dark-theme .nyx-search-box-v2 .search-input {
    color: var(--text, #F8FAFC) !important;
}
[data-theme="dark"] .nyx-search-box-v2 .search-input::placeholder,
.dark-theme .nyx-search-box-v2 .search-input::placeholder {
    color: var(--muted, #64748B) !important;
}
[data-theme="dark"] .range-pill,
.dark-theme .range-pill,
[data-theme="dark"] .range-pill b,
.dark-theme .range-pill b {
    color: var(--text, #F8FAFC) !important;
}
[data-theme="dark"] .custom-filter-dropdown-menu,
.dark-theme .custom-filter-dropdown-menu {
    background: var(--surface-2, #1E293B) !important;
    border-color: var(--line, #334155) !important;
}
[data-theme="dark"] .custom-filter-dropdown-option,
.dark-theme .custom-filter-dropdown-option {
    color: var(--text, #CBD5E1) !important;
}
[data-theme="dark"] .custom-filter-dropdown-option:hover,
.dark-theme .custom-filter-dropdown-option:hover {
    background: var(--surface-3, #334155) !important;
    color: var(--brand-electric, #818CF8) !important;
}
[data-theme="dark"] .cal-month-title,
.dark-theme .cal-month-title {
    color: var(--text, #F8FAFC) !important;
}
[data-theme="dark"] .cal-day,
.dark-theme .cal-day {
    color: var(--text, #E2E8F0) !important;
}
[data-theme="dark"] .cal-day:hover,
.dark-theme .cal-day:hover {
    background: var(--surface-3, #334155) !important;
    color: var(--brand-electric, #818CF8) !important;
}
[data-theme="dark"] .cal-nav-btn,
.dark-theme .cal-nav-btn {
    background: var(--surface-2, #1E293B) !important;
    border-color: var(--line, #334155) !important;
    color: var(--muted, #94A3B8) !important;
}
[data-theme="dark"] .cal-pane-label,
.dark-theme .cal-pane-label {
    border-bottom-color: var(--line, #334155) !important;
}
[data-theme="dark"] .double-cal-footer,
.dark-theme .double-cal-footer {
    border-top-color: var(--line, #334155) !important;
}
[data-theme="dark"] .cal-status-text,
.dark-theme .cal-status-text {
    color: var(--muted, #94A3B8) !important;
}
[data-theme="dark"] .nyx-preset-btn,
.dark-theme .nyx-preset-btn,
[data-theme="dark"] .btn-collapse-filters,
.dark-theme .btn-collapse-filters,
[data-theme="dark"] .nyx-filter-count-badge,
.dark-theme .nyx-filter-count-badge {
    background: var(--surface-2, #1E293B) !important;
    border-color: var(--line, #334155) !important;
    color: var(--muted, #94A3B8) !important;
}
[data-theme="dark"] .nyx-preset-btn.active,
.dark-theme .nyx-preset-btn.active {
    background: #6366F1 !important;
    border-color: #6366F1 !important;
    color: #FFFFFF !important;
}
[data-theme="dark"] .presale-modal-card {
    --ps-surface: var(--surface);
    --ps-surface-2: var(--surface-2);
    --ps-line: var(--line);
    --ps-ink: var(--text);
    --ps-ink-dim: var(--muted);
    --ps-ink-faint: var(--faint);
    --ps-indigo-dim: rgba(91, 95, 233, 0.18);
    --ps-green-dim: var(--ok-soft);
    --ps-amber-dim: var(--warn-soft);
    --ps-red-dim: var(--err-soft);
    --ps-blue-dim: var(--info-soft);
}

[data-theme="dark"] .presale-modal-card .ps-section-num {
    background: var(--surface-3) !important;
    color: var(--text) !important;
    border: 1px solid var(--line-strong);
}

/* Cabeceras / cuerpos / pies */
[data-theme="dark"] :is(.modal-content, .modal-card, .modal-box-custom, .modal-container, .venta-modal-box, .presale-modal-card, .u-modal-card, .audit-modal, .derivacion-modal, .devolucion-modal, .handshake-v2-modal, .mud-dialog)
    :is(.modal-header, .modal-body, .modal-head-custom, .modal-body-custom, .venta-modal-header, .ps-head, .ps-body, .u-head, .derivacion-header, .derivacion-header-top, .derivacion-body, .devolucion-header, .devolucion-header-top, .devolucion-body, .mud-dialog-title, .mud-dialog-content) {
    background: transparent !important;
    background-color: transparent !important;
    border-color: var(--line) !important;
    color: var(--text) !important;
}

[data-theme="dark"] :is(.modal-content, .modal-card, .modal-box-custom, .modal-container, .venta-modal-box, .presale-modal-card, .u-modal-card, .audit-modal, .derivacion-modal, .devolucion-modal, .handshake-v2-modal, .mud-dialog)
    :is(.modal-footer, .modal-foot-custom, .ps-foot, .u-foot, .mud-dialog-actions) {
    background: var(--surface-2) !important;
    background-color: var(--surface-2) !important;
    border-color: var(--line) !important;
}

/* El cuerpo del modal de venta usa el fondo base para dar profundidad a sus tarjetas */
[data-theme="dark"] .venta-modal-box .venta-modal-body { background: var(--bg) !important; background-color: var(--bg) !important; }

/* Texto dentro de modales (títulos, labels, párrafos) */
[data-theme="dark"] :is(.modal-content, .modal-card, .modal-box-custom, .modal-container, .venta-modal-box, .presale-modal-card, .u-modal-card, .audit-modal, .derivacion-modal, .devolucion-modal, .handshake-v2-modal)
    :is(h1, h2, h3, h4, h5, h6, label, strong, b, dt, legend, .modal-title, [class*="title"], [class*="heading"], [class*="-name"])
    :not([class*="badge"]):not([class*="btn"]):not([class*="text-"]):not([class*="chip"]):not([class*="pill"]):not(.req) {
    color: var(--text) !important;
}

[data-theme="dark"] :is(.modal-content, .modal-card, .modal-box-custom, .modal-container, .venta-modal-box, .presale-modal-card, .u-modal-card, .audit-modal, .derivacion-modal, .devolucion-modal, .handshake-v2-modal)
    :is(p, dd, small, [class*="desc"], [class*="subtitle"], [class*="-sub"], [class*="hint"], [class*="caption"], [class*="helper"])
    :not([class*="badge"]):not([class*="btn"]):not([class*="text-"]):not([class*="err"]):not([class*="error"]) {
    color: var(--muted) !important;
}

/* Campos, triggers y menús internos de modales */
[data-theme="dark"] :is(.modal-content, .modal-card, .modal-box-custom, .modal-container, .venta-modal-box, .presale-modal-card, .u-modal-card, .audit-modal, .derivacion-modal, .devolucion-modal, .handshake-v2-modal)
    :is([class*="trigger"], [class*="textarea"], [class*="comment"], [class*="-flow"], [class*="badge-neutral"], .memo-card-field) {
    background: var(--surface-2) !important;
    border-color: var(--line-strong) !important;
    color: var(--text) !important;
}

[data-theme="dark"] :is(.modal-content, .modal-card, .modal-box-custom, .modal-container, .venta-modal-box, .presale-modal-card, .u-modal-card, .audit-modal, .derivacion-modal, .devolucion-modal, .handshake-v2-modal)
    :is([class*="trigger"].open, [class*="textarea"]:focus) {
    background: var(--surface-3) !important;
    border-color: var(--brand) !important;
}

[data-theme="dark"] :is(.modal-content, .modal-card, .modal-box-custom, .modal-container, .venta-modal-box, .presale-modal-card, .u-modal-card, .audit-modal, .derivacion-modal, .devolucion-modal, .handshake-v2-modal)
    :is([class*="dd-menu"], [class*="select-menu"], [class*="dropdown-menu"]) {
    background: var(--surface-3) !important;
    border: 1px solid var(--line-strong) !important;
    box-shadow: var(--shadow-pop) !important;
}

[data-theme="dark"] :is(.modal-content, .modal-card, .modal-box-custom, .modal-container, .venta-modal-box, .presale-modal-card, .u-modal-card, .audit-modal, .derivacion-modal, .devolucion-modal, .handshake-v2-modal)
    :is([class*="dd-option"], [class*="-option"], [class*="user-option"]) {
    color: var(--text-2) !important;
}

[data-theme="dark"] :is(.modal-content, .modal-card, .modal-box-custom, .modal-container, .venta-modal-box, .presale-modal-card, .u-modal-card, .audit-modal, .derivacion-modal, .devolucion-modal, .handshake-v2-modal)
    :is([class*="dd-option"], [class*="-option"], [class*="user-option"]):hover {
    background: rgba(255, 255, 255, 0.06) !important;
    color: #fff !important;
}

/* Botones secundarios / cerrar en modales */
[data-theme="dark"] .btn-close-modal,
[data-theme="dark"] .audit-close-btn,
[data-theme="dark"] .ps-icon-btn,
[data-theme="dark"] .ps-scroll-hint,
[data-theme="dark"] [class*="btn-cancel"],
[data-theme="dark"] .presale-modal-card .ps-btn:not(.primary) {
    background: var(--surface-2) !important;
    border: 1px solid var(--line-strong) !important;
    color: var(--text-2) !important;
}

[data-theme="dark"] .btn-close-modal:hover,
[data-theme="dark"] .audit-close-btn:hover,
[data-theme="dark"] .ps-icon-btn:hover,
[data-theme="dark"] [class*="btn-cancel"]:hover,
[data-theme="dark"] .presale-modal-card .ps-btn:not(.primary):hover {
    background: var(--surface-3) !important;
    color: var(--text) !important;
}

/* ───────────────── 6. CATCH-ALL ESTILOS INLINE (fondos claros / texto oscuro) ───────────────── */
[data-theme="dark"] [style*="background: #fff"],
[data-theme="dark"] [style*="background:#fff"],
[data-theme="dark"] [style*="background: #FFF"],
[data-theme="dark"] [style*="background:#FFF"],
[data-theme="dark"] [style*="background-color: #fff"],
[data-theme="dark"] [style*="background-color:#fff"],
[data-theme="dark"] [style*="background-color: #FFF"],
[data-theme="dark"] [style*="background: white"],
[data-theme="dark"] [style*="background-color: white"],
[data-theme="dark"] [style*="background: #f8fafc"],
[data-theme="dark"] [style*="background: #F8FAFC"],
[data-theme="dark"] [style*="background-color: #f8fafc"],
[data-theme="dark"] [style*="background: #f1f5f9"],
[data-theme="dark"] [style*="background: #F1F5F9"],
[data-theme="dark"] [style*="background-color: #f1f5f9"],
[data-theme="dark"] [style*="background: #f9fafb"],
[data-theme="dark"] [style*="background: #fafafa"],
[data-theme="dark"] [style*="background: #F6F7FB"] {
    background: var(--surface-2) !important;
    background-color: var(--surface-2) !important;
    border-color: var(--line) !important;
}

[data-theme="dark"] [style*="color: #0f172a"],
[data-theme="dark"] [style*="color:#0f172a"],
[data-theme="dark"] [style*="color: #0F172A"],
[data-theme="dark"] [style*="color: #111827"],
[data-theme="dark"] [style*="color: #1e293b"],
[data-theme="dark"] [style*="color: #1E293B"],
[data-theme="dark"] [style*="color: #151A2E"],
[data-theme="dark"] [style*="color: #000"],
[data-theme="dark"] [style*="color: black"] {
    color: var(--text) !important;
}

[data-theme="dark"] [style*="color: #334155"],
[data-theme="dark"] [style*="color: #475569"],
[data-theme="dark"] [style*="color: #374151"] {
    color: var(--text-2) !important;
}

[data-theme="dark"] [style*="border: 1px solid #e2e8f0"],
[data-theme="dark"] [style*="border: 1px solid #E2E8F0"],
[data-theme="dark"] [style*="border-color: #e2e8f0"],
[data-theme="dark"] [style*="border: 1px solid #e5e7eb"] {
    border-color: var(--line) !important;
}

/* ───────────────── 7. MUDBLAZOR ───────────────── */
[data-theme="dark"] .mud-paper,
[data-theme="dark"] .mud-popover,
[data-theme="dark"] .mud-list,
[data-theme="dark"] .mud-picker-paper {
    background-color: var(--surface-3) !important;
    color: var(--text) !important;
}

[data-theme="dark"] .mud-popover { border: 1px solid var(--line-strong); box-shadow: var(--shadow-pop) !important; }

[data-theme="dark"] .mud-list-item:hover,
[data-theme="dark"] .mud-menu-item:hover { background-color: rgba(255, 255, 255, 0.06) !important; }

[data-theme="dark"] .mud-snackbar {
    background: var(--surface-3) !important;
    color: var(--text) !important;
    border: 1px solid var(--line-strong);
    box-shadow: var(--shadow-pop) !important;
}

[data-theme="dark"] .mud-overlay-dark,
[data-theme="dark"] .mud-overlay .mud-overlay-scrim.mud-overlay-dark { background-color: var(--overlay) !important; }

/* ───────────────── 8. CONFIGURACIÓN ───────────────── */
[data-theme="dark"] .theme-card,
[data-theme="dark"] .btn-preset,
[data-theme="dark"] .font-preview-box { background: var(--surface-2) !important; border-color: var(--line) !important; }

[data-theme="dark"] .tone-card,
[data-theme="dark"] .lang-card { background: var(--surface) !important; border-color: var(--line) !important; }

[data-theme="dark"] .theme-card:hover,
[data-theme="dark"] .tone-card:hover,
[data-theme="dark"] .lang-card:hover,
[data-theme="dark"] .btn-preset:hover,
[data-theme="dark"] .btn-reset-settings:hover { border-color: var(--line-strong) !important; background: var(--surface-2) !important; }

[data-theme="dark"] .theme-card.active,
[data-theme="dark"] .btn-preset.active,
[data-theme="dark"] .tone-card.active,
[data-theme="dark"] .lang-card.active {
    border-color: var(--brand) !important;
    background: var(--brand-soft) !important;
}

[data-theme="dark"] .theme-badge { background: var(--surface-3) !important; }
[data-theme="dark"] .preview-chip.success { background: var(--ok-soft) !important; color: var(--ok) !important; }
[data-theme="dark"] .tone-swatch { border-color: var(--line-strong) !important; }

/* ═══════════════════════════════════════════════════════════════════
   SNACKBAR & TOAST POPUPS - ALWAYS ON TOP OF ANY MODAL OVERLAY
   ═══════════════════════════════════════════════════════════════════ */
.mud-snackbar-provider,
.mud-snackbar-location-top-right,
.mud-snackbar-location-top-center,
.mud-snackbar-location-top-left,
.mud-snackbar-location-bottom-right,
.mud-snackbar-location-bottom-center,
.mud-snackbar-location-bottom-left,
.mud-snackbar-container,
.mud-snackbar,
.toast-container {
    z-index: 99999999 !important;
}

[data-theme="dark"] .mud-snackbar-provider,
.theme-dark .mud-snackbar-provider,
[data-theme="dark"] .mud-snackbar-location-top-right,
.theme-dark .mud-snackbar-location-top-right,
[data-theme="dark"] .mud-snackbar-location-top-center,
.theme-dark .mud-snackbar-location-top-center,
[data-theme="dark"] .mud-snackbar-location-top-left,
.theme-dark .mud-snackbar-location-top-left,
[data-theme="dark"] .mud-snackbar-location-bottom-right,
.theme-dark .mud-snackbar-location-bottom-right,
[data-theme="dark"] .mud-snackbar-location-bottom-center,
.theme-dark .mud-snackbar-location-bottom-center,
[data-theme="dark"] .mud-snackbar-location-bottom-left,
.theme-dark .mud-snackbar-location-bottom-left,
[data-theme="dark"] .mud-snackbar-container,
.theme-dark .mud-snackbar-container,
[data-theme="dark"] .mud-snackbar,
.theme-dark .mud-snackbar,
[data-theme="dark"] .toast-container,
.theme-dark .toast-container {
    z-index: 99999999 !important;
}

/* ═══════════════════════════════════════════════════════════════════
   HIGH-CONTRAST DARK MODE WARNING BADGES & LABELS (AMBER-400 / 300)
   ═══════════════════════════════════════════════════════════════════ */
[data-theme="dark"] .nyx-badge.warning,
.theme-dark .nyx-badge.warning,
[data-theme="dark"] .checkpoint-step-pill.pending-accept,
.theme-dark .checkpoint-step-pill.pending-accept,
[data-theme="dark"] .cp-item-pill.current-pill.pending-accept-pill,
.theme-dark .cp-item-pill.current-pill.pending-accept-pill,
[data-theme="dark"] .nyx-table-badge.warning,
.theme-dark .nyx-table-badge.warning,
[data-theme="dark"] .action-badge-pending,
.theme-dark .action-badge-pending,
[data-theme="dark"] .btn-memo-note,
.theme-dark .btn-memo-note {
    background: rgba(245, 158, 11, 0.16) !important;
    color: #FBBF24 !important;
    border-color: rgba(245, 158, 11, 0.45) !important;
}

[data-theme="dark"] .btn-memo-note:hover,
.theme-dark .btn-memo-note:hover {
    background: rgba(245, 158, 11, 0.28) !important;
    color: #FDE047 !important;
    border-color: #F59E0B !important;
}

/* ═══════════════════════════════════════════════════════════════════
   CHECKPOINT ACTION & SUPERVISOR AUDIT GLOBAL CONTRAST FIXES
   ═══════════════════════════════════════════════════════════════════ */
.cp-btn-submit.remediation,
.cp-btn-submit.remediation *,
.cp-btn-submit.remediation span,
.cp-btn-submit.remediation i,
.cp-btn-submit.enabled,
.cp-btn-submit.enabled *,
.cp-btn-submit.enabled span,
.cp-btn-submit.enabled i,
[data-theme="dark"] .cp-btn-submit.remediation,
.theme-dark .cp-btn-submit.remediation,
[data-theme="dark"] .cp-btn-submit.enabled,
.theme-dark .cp-btn-submit.enabled {
    color: #FFFFFF !important;
    fill: #FFFFFF !important;
}

[data-theme="dark"] .chk-row-item.selected,
.theme-dark .chk-row-item.selected {
    background: rgba(30, 64, 175, 0.35) !important;
    border-color: #3b82f6 !important;
}

[data-theme="dark"] .chk-row-item.selected .chk-label-title span,
.theme-dark .chk-row-item.selected .chk-label-title span {
    color: #F8FAFC !important;
}

[data-theme="dark"] .btn-ejecutar-checkpoint:disabled,
.theme-dark .btn-ejecutar-checkpoint:disabled,
[data-theme="dark"] .btn-ejecutar-checkpoint.disabled-dept,
.theme-dark .btn-ejecutar-checkpoint.disabled-dept {
    background: #162032 !important;
    color: #94A3B8 !important;
    border-color: #1f293d !important;
}

/* ═══════════════════════════════════════════════════════════════════
   RENDIMIENTO DE EQUIPO / SUPERVISOR EQUIPO GLOBAL FIXES
   ═══════════════════════════════════════════════════════════════════ */
[data-theme="dark"] .team-perf-page .table-card,
.theme-dark .team-perf-page .table-card,
[data-theme="dark"] .team-perf-page .kpi-card,
.theme-dark .team-perf-page .kpi-card,
[data-theme="dark"] .team-perf-page .filter-bar,
.theme-dark .team-perf-page .filter-bar,
[data-theme="dark"] .team-perf-page .sup-chip-card,
.theme-dark .team-perf-page .sup-chip-card {
    background: #111827 !important;
    border-color: #1f293d !important;
    color: #f8fafc !important;
}

[data-theme="dark"] table.perf-table tr.supervisor-row td,
.theme-dark table.perf-table tr.supervisor-row td {
    background: #111827 !important;
    color: #f8fafc !important;
    border-bottom-color: #1f293d !important;
}

[data-theme="dark"] table.perf-table tr.supervisor-row:hover td,
.theme-dark table.perf-table tr.supervisor-row:hover td {
    background: #1e293b !important;
}

[data-theme="dark"] table.perf-table tr.supervisor-row.expanded td,
.theme-dark table.perf-table tr.supervisor-row.expanded td {
    background: rgba(59, 130, 246, 0.16) !important;
    border-bottom-color: rgba(59, 130, 246, 0.3) !important;
}

[data-theme="dark"] table.perf-table tr.advisor-row,
.theme-dark table.perf-table tr.advisor-row,
[data-theme="dark"] table.perf-table tr.advisor-row td,
.theme-dark table.perf-table tr.advisor-row td {
    background: #162032 !important;
    color: #f8fafc !important;
    border-bottom-color: #1f293d !important;
}

[data-theme="dark"] table.perf-table tr.advisor-row:hover td,
.theme-dark table.perf-table tr.advisor-row:hover td {
    background: #1e293b !important;
}

[data-theme="dark"] .team-card,
.theme-dark .team-card {
    background: #111827 !important;
    border-color: #1f293d !important;
    color: #f8fafc !important;
}

[data-theme="dark"] .count-advisors-pill,
.theme-dark .count-advisors-pill {
    background: #162032 !important;
    border-color: rgba(59, 130, 246, 0.3) !important;
    color: #60a5fa !important;
}


