/* Paint-only adapters for the existing shells. Layout and state stay in legacy CSS. */
:root,
[data-theme="light"] {
    color-scheme: light;
    --appearance-bg: var(--brand-light);
    --appearance-surface: #fff;
    --appearance-raised: var(--brand-light);
    --appearance-text: var(--brand-navy);
    --appearance-muted: var(--brand-text);
    --appearance-line: #c5cdd6;
    --appearance-soft: #20c5bc1a;
    --appearance-focus: var(--brand-blue);
    --appearance-danger: #a52336;
    --appearance-warning: #80500b;
    --appearance-success: #176542;
    --appearance-info: #145c82;
}

[data-theme="dark"] {
    color-scheme: dark;
    --appearance-bg: var(--brand-navy);
    --appearance-surface: #14243f;
    --appearance-raised: #1a2c4a;
    --appearance-text: var(--brand-light);
    --appearance-muted: #a9bcd6;
    --appearance-line: #2a4066;
    --appearance-soft: #20c5bc29;
    --appearance-focus: #56d9d1;
    --appearance-danger: #ffacb7;
    --appearance-warning: #f5cd83;
    --appearance-success: #86efac;
    --appearance-info: #93c5fd;
}

html[data-theme] {
    --bg-main: var(--appearance-bg);
    --bg-panel: var(--appearance-surface);
    --bg-elevated: var(--appearance-raised);
    --bg-soft: var(--appearance-raised);
    --border: var(--appearance-line);
    --border-color: var(--appearance-line);
    --border-soft: var(--appearance-line);
    --text-primary: var(--appearance-text);
    --text-secondary: var(--appearance-muted);
    --text-muted: var(--appearance-muted);
    --color-primary: var(--brand-turquoise);
    --color-primary-hover: #56d9d1;
    --brand-green: var(--brand-turquoise);
    --brand-green-dark: #56d9d1;
}

html[data-theme] body {
    font-family: var(--brand-font);
    background: var(--appearance-bg);
    color: var(--appearance-text);
}

html[data-theme] :is(.sidebar, .topbar, .login-card, .password-card,
    .card, .page-card, .stat-card, .resumen-card, .auditoria-card,
    .modal-content, .dashboard-v4-panel, .dashboard-v4-mini-panel,
    .informes-pro-block, .informe-preview, .logs-pro-panel, .logs-pro-table-card,
    .info-item, .factura-resumen, .verifactu-card, .verifactu-notice,
    .verifactu-subcard, .factura-envio-item, .calendario-rrhh-dia.con-eventos,
    .auditoria-detail-panel, .auditoria-detail-card, .auditoria-detail-empty,
    .auditoria-revision-resumen, .auditoria-verificaciones-card,
    .informe-preview-placeholder, .empleados-resumen-kpis, .fichajes-resumen-kpis) {
    background: var(--appearance-surface);
    color: var(--appearance-text);
    border-color: var(--appearance-line);
}

/* These legacy ID selectors otherwise outrank the common card adapter. */
html[data-theme] :is(#moduloInformes .card, #dashboardSection .dashboard-v4-panel,
    #dashboardSection .dashboard-v4-mini-panel, #dashboardSection .dashboard-v4-operational-item) {
    background: var(--appearance-surface);
    color: var(--appearance-text);
}

/* Keep the existing primary metric's information role readable on a light card. */
html[data-theme="light"] #dashboardSection .dashboard-v4-operational-item.primary strong {
    color: var(--appearance-info);
}

html[data-theme] :is(.login-wrapper, .password-container, .login-body) {
    background: var(--appearance-bg);
}

html[data-theme] :is(h1, h2, h3, h4, h5, h6),
html[data-theme] :is(#moduloInformes h3, .resumen-card strong, .resumen-card p,
    .modal-content label, .auditoria-detail-empty strong, .auditoria-detail-header h3,
    .auditoria-detail-card h4, .auditoria-detail-kv strong, .auditoria-revision-cell strong,
    .auditoria-verificacion-row strong, .auditoria-revision-readonly > strong) {
    color: var(--appearance-text);
}

html[data-theme] :is(.login-subtitle, .password-info, .timeline-hora, .timeline-total) {
    color: var(--appearance-muted);
}

html[data-theme] :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea),
html[data-theme] :is(#moduloInformes input, #moduloInformes select) {
    background: var(--appearance-raised);
    color: var(--appearance-text);
    border-color: var(--appearance-line);
}

html[data-theme] :is(input, textarea)::placeholder {
    color: var(--appearance-muted);
}

html[data-theme] :is(th, .tabla th, #tabla-logs th) {
    background: var(--appearance-raised);
    color: var(--appearance-text);
    border-color: var(--appearance-line);
}

html[data-theme] :is(td, .tabla td, #tabla-logs td) {
    color: var(--appearance-text);
    border-color: var(--appearance-line);
}

html[data-theme] :is(tbody tr, #tabla-logs tbody tr, #tabla-logs tbody tr:nth-child(even)) {
    background: var(--appearance-surface);
    color: var(--appearance-text);
}

html[data-theme] :is(tbody tr:hover, #tabla-logs tbody tr:hover) {
    background: var(--appearance-raised);
}

html[data-theme] :is(.btn-primary, .login-btn, #loginBtn, #btnCambiarPassword),
html[data-appearance-token="access_token"] button:not([class]),
html[data-appearance-token="access_token"] button.form-grid-full {
    /* Superadmin's unclassified buttons are its existing primary action primitive. */
    background: var(--brand-turquoise);
    color: var(--brand-navy);
}

html[data-theme] :is(.btn-primary, .login-btn, #loginBtn, #btnCambiarPassword):hover:not(:disabled) {
    background: #56d9d1;
    color: var(--brand-navy);
}

html[data-theme] .btn-secondary,
html[data-theme] #moduloInformes .informes-pro-action.secondary {
    background: var(--appearance-raised);
    color: var(--appearance-text);
    border-color: var(--appearance-line);
}

html[data-theme] .btn-secondary:hover:not(:disabled),
html[data-theme] #moduloInformes .informes-pro-action.secondary:hover:not(:disabled) {
    background: var(--appearance-soft);
}

html[data-theme] .sidebar a:not(.logout-btn) {
    color: var(--appearance-muted);
}

html[data-theme] .sidebar a:not(.logout-btn):is(.active, :hover) {
    background: var(--appearance-soft);
    color: var(--appearance-text);
}

/* Logout remains a danger action, including over its existing translucent hover paint. */
html[data-theme] .sidebar a.logout-btn,
html[data-theme] .sidebar a.logout-btn:hover {
    color: var(--appearance-danger);
}

html[data-theme] .sidebar a.logout-btn:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* Operational success is distinct from the turquoise corporate action color. */
html[data-theme] .topbar-status {
    color: var(--appearance-success);
    background: rgba(63, 163, 107, 0.15);
}

/* Preserve the operational hue of existing states; replace only low-contrast text. */
html[data-theme] :is(.error, .form-error, .verifactu-unavailable, .badge-envio-error,
    .estado-envio-error, .ausencia-estado-badge.estado-rechazada) {
    color: var(--appearance-danger);
}

html[data-theme] :is(.badge-success, .badge-activa, .badge-envio-ok,
    .estado-envio-enviado, .ausencia-estado-badge.estado-aprobada) {
    color: var(--appearance-success);
}

html[data-theme] :is(.verifactu-flag, .badge-envio-warn,
    .ausencia-estado-badge.estado-pendiente) {
    color: var(--appearance-warning);
}

html[data-theme] :is(.badge-inactiva, .ausencia-estado-badge.estado-cancelada) {
    color: var(--appearance-muted);
}

html[data-theme] #dashboardSection .dashboard-v4-action.success {
    color: var(--appearance-success);
}
html[data-theme] #dashboardSection .dashboard-v4-action.info {
    color: var(--appearance-info);
}
html[data-theme] #dashboardSection .dashboard-v4-action.warning {
    color: var(--appearance-warning);
}
html[data-theme] #dashboardSection .dashboard-v4-action.purple {
    color: var(--appearance-text);
}
html[data-theme] #dashboardSection .dashboard-v4-action.primary {
    background: var(--brand-turquoise);
    color: var(--brand-navy);
}

html[data-theme] :is(button, a, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 3px solid var(--appearance-focus);
    outline-offset: 3px;
}

/* Neutral document text that predates the legacy semantic variables. */
html[data-theme] :is(.auditoria-detail-header p, .auditoria-detail-kv span,
    .auditoria-detail-text, .auditoria-detail-note, .auditoria-inline-label,
    .auditoria-verificacion-row p, .auditoria-muted, .auditoria-revision-cell small,
    .auditoria-inconsistencia-row small, .logs-mono-cell, .module-empty-state,
    .resumen-card h4, .auditoria-detail-empty) {
    color: var(--appearance-muted);
}

html[data-theme] :is(.btn-mini-secondary, .btn-mini-primary, .audit-hash-box code) {
    background: var(--appearance-raised);
    color: var(--appearance-text);
}

/* Legacy pastel status text needs its darker equivalent on light surfaces.
   Background/border hues and all disabled/danger/visibility behavior are retained. */
html[data-theme="light"] :is(.btn-toggle, .dashboard-alert.success, .empleados-estado-badge.success,
    .informes-pro-badge.success, .fichajes-chip.success, .vacaciones-saldo-badge.success,
    .logs-integridad-pill.success, .log-action-badge.success, .log-origin-badge.kiosco,
    .auditoria-summary-pill.success, .auditoria-status-badge.success, .audit-review-ok,
    .audit-chip-success, .audit-hash-box.success span, .estado.pagada,
    .ausencia-tipo-baja_medica, .calendario-rrhh-contador) {
    color: var(--appearance-success);
}

html[data-theme="light"] :is(.dashboard-alert.danger, .fichajes-chip.danger,
    .vacaciones-saldo-badge.danger, .logs-integridad-pill.danger, .log-action-badge.danger,
    .auditoria-summary-pill.danger, .auditoria-status-badge.danger, .btn-danger-soft,
    .audit-hash-box.danger span, .factura-envio-error, .estado.anulada,
    .ausencia-tipo-ausencia_no_justificada, .calendario-rrhh-evento.origen-kiosco.estado-abierta,
    #facturasVencidasTotal, #facturasVencidasImporte, #empresasImpago) {
    color: var(--appearance-danger);
}

html[data-theme="light"] :is(.btn-incidencia, .btn-reset, .pausa-version-warning, .fichajes-chip.warning,
    .vacaciones-saldo-badge.warning, .log-action-badge.warning, .informes-pro-badge.warning,
    .auditoria-summary-pill.warning, .auditoria-status-badge.warning, .audit-review-pending,
    .auditoria-revision-badge.pendiente, .estado.borrador, .estado.pendiente,
    .tipo-factura.tipo-mixta, .factura-alerta, .ausencia-tipo-permiso_no_retribuido,
    .calendario-rrhh-evento.origen-kiosco, #facturasVencen7DiasTotal,
    #facturasVencen7DiasImporte, #facturasPendientes, #pendienteCobroTotal) {
    color: var(--appearance-warning);
}

html[data-theme="light"] :is(.fichajes-chip.info, .informes-pro-badge.info,
    .log-action-badge.info, .log-origin-badge.admin, .empleados-jornada-badge,
    .auditoria-summary-pill.info, .auditoria-status-badge.info, .ausencia-tipo-vacaciones,
    .estado.emitida, .estado.enviada, .tipo-factura.tipo-automatica,
    #dashboardAlertasResumen, #facturacionMesActual, #mrr, #facturacionTotal) {
    color: var(--appearance-info);
}

html[data-theme="light"] :is(.badge-primary, .ausencia-tipo-chip, .ausencia-tipo-permiso_retribuido,
    .fichajes-chip.neutral, .empleados-estado-badge.muted, .audit-chip-neutral,
    .auditoria-id-badge, .auditoria-inconsistencia-row code, .log-action-badge.admin,
    .tipo-factura.tipo-manual, .tipo-factura.tipo-rectificativa, .estado.rectificada) {
    color: var(--appearance-text);
}

html[data-theme] [data-appearance-select] {
    width: auto;
    max-width: 100%;
    margin: 4px 8px;
}
