/* ===================================================================
   Portal — Pulido final del tema oscuro
   Solo aplica con body[data-theme="dark"]. Se carga el ÚLTIMO.
   Corrige: textos "navy" fijos de los módulos, campos nativos (selects,
   fechas, archivos), paneles claros con letra clara y modales de
   Gestión documental, cuyos tokens caían en valores claros.
   =================================================================== */

/* 1) Controles nativos (desplegables, calendario, archivo, scroll) en oscuro */
body[data-theme="dark"] {
  color-scheme: dark;
  --dark-field-bg: #0f1c2e;
  --dark-field-text: #e8f4fc;
  --dark-field-border: rgba(148, 196, 255, 0.28);
  --dark-field-placeholder: #8fa8c4;
}

body[data-theme="dark"] select option,
body[data-theme="dark"] select optgroup,
body[data-theme="dark"] datalist option {
  color: var(--dark-field-text);
  background-color: #12233a;
}

body[data-theme="dark"] :is(input, textarea)::placeholder {
  color: var(--dark-field-placeholder);
  opacity: 1;
}

body[data-theme="dark"] input[type="file"]::file-selector-button {
  color: var(--dark-field-text);
  background: #1e3550;
  border: 1px solid var(--dark-field-border);
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  margin-right: 0.6rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

body[data-theme="dark"] input[type="file"] {
  color: var(--dark-field-text);
}

body[data-theme="dark"] :is(input, select, textarea):-webkit-autofill {
  -webkit-text-fill-color: var(--dark-field-text);
  box-shadow: 0 0 0 1000px #12233a inset;
  caret-color: var(--dark-field-text);
}

body[data-theme="dark"] :is(input, select, textarea):disabled {
  color: #7f97b2;
  -webkit-text-fill-color: #7f97b2;
  opacity: 1;
}

/* Campos de formularios dentro de modales y módulos: nunca letra blanca/transparente sobre fondo claro */
body[data-theme="dark"] :is(.modal, .modal-card, .portal-main) :is(input, select, textarea):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]) {
  color: var(--dark-field-text);
  -webkit-text-fill-color: var(--dark-field-text);
  caret-color: var(--dark-field-text);
}

/* 2) Tokens de texto de los módulos (en claro eran navy; en oscuro deben ser claros) */
body[data-theme="dark"] :is(.payroll-studio, .hiring-studio, .vehicles-studio, .transport-studio, .history-studio, .requests-studio, .notifications-studio, .sst-studio) {
  --pay-navy: #e8f4fc;
  --pay-navy-mid: #b8d9f5;
  --hi-navy: #e8f4fc;
  --hi-navy-mid: #b8d9f5;
  --veh-navy: #e8f4fc;
  --veh-navy-mid: #b8d9f5;
  --trn-navy: #e8f4fc;
  --trn-navy-mid: #b8d9f5;
  --hist-navy: #e8f4fc;
  --hist-navy-mid: #b8d9f5;
  --req-navy: #e8f4fc;
  --ntf-navy: #e8f4fc;
  --sst-navy: #e8f4fc;
}

/* Los degradados de cabecera/botones activos sí necesitan el azul profundo original */
body[data-theme="dark"] .payroll-studio .payroll-runs-view-toggle__btn.is-active {
  background: linear-gradient(135deg, #377cc0 0%, #123d6b 100%);
}
body[data-theme="dark"] .transport-studio [class*="hero"],
body[data-theme="dark"] .transport-studio .fleet-hero-strip {
  --trn-navy: #0b2138;
  --trn-navy-mid: #123d6b;
}
body[data-theme="dark"] .vehicles-studio [class*="hero"],
body[data-theme="dark"] .vehicles-studio .fleet-hero-strip {
  --veh-navy-mid: #123d6b;
}

/* 3) Tokens de Gestión documental para modales montados fuera de .doc-studio */
body[data-theme="dark"] {
  --doc-primary: #3b82f6;
  --doc-primary-soft: rgba(59, 130, 246, 0.14);
  --doc-surface: #1e293b;
  --doc-surface-2: #0f172a;
  --doc-text: #f1f5f9;
  --doc-text-soft: #a9b8cc;
  --doc-text-faint: #8b9bb0;
  --doc-border: #334155;
  --doc-border-strong: #475569;
  --doc-canvas: #0f172a;
}

/* 4) Paneles y textos puntuales que quedaban con colores de tema claro */
body[data-theme="dark"] .payroll-studio .hr-absence-team-panel {
  background: rgba(15, 28, 46, 0.7);
  border-color: rgba(148, 196, 255, 0.22);
}
body[data-theme="dark"] .payroll-studio .hr-absence-team-panel__empty {
  color: #9ec7e8;
}
body[data-theme="dark"] .payroll-studio .payroll-liquidation-mode__btn.is-active {
  color: #ffffff;
  background: rgba(55, 124, 192, 0.35);
  border-color: rgba(148, 196, 255, 0.45);
}
body[data-theme="dark"] .payroll-studio .payroll-overtime-field__badge--hed { background: rgba(59, 130, 246, 0.22); color: #93c5fd; }
body[data-theme="dark"] .payroll-studio .payroll-overtime-field__badge--hen { background: rgba(99, 102, 241, 0.24); color: #c7d2fe; }
body[data-theme="dark"] .payroll-studio .payroll-overtime-field__badge--hrdf { background: rgba(245, 158, 11, 0.22); color: #fcd34d; }
body[data-theme="dark"] .payroll-studio .payroll-overtime-field__badge--hrnf { background: rgba(236, 72, 153, 0.22); color: #f9a8d4; }
body[data-theme="dark"] .payroll-studio .payroll-overtime-field__badge--rn { background: rgba(14, 116, 144, 0.28); color: #67e8f9; }

/* Textos secundarios (gris de tema claro) legibles sobre fondo oscuro */
body[data-theme="dark"] :is(.portal-main, .modal) :is(
  .hr-action-card__desc,
  .payroll-overtime-field__meta,
  .field-help,
  .sst-operate-nav-hint,
  .sst-status-card__hint,
  .doc-storage-row__size,
  .doc-subfolder-card__meta,
  .doc-perm-section-title,
  .hiring-scope-tab,
  .report-preview-header,
  .vehicle-availability-bar__detail,
  .hist-trace-module-chip__count
) {
  color: #a9bdd4;
}
body[data-theme="dark"] .portal-main .field-help {
  color: #9ec7e8;
}

/* Indicadores/insignias con azul oscuro fijo */
body[data-theme="dark"] :is(.auth-tab-badge, .auth-ref-pill, .perm-group-count, .requests-data-sidebar__count, .hiring-browse__tab-count, .payroll-contract-count, #payroll-runs-selected-count, .driver-edit-photo-oval--placeholder, .ag-access-card__you) {
  color: #cfe6fb;
}
body[data-theme="dark"] .trip-ops-card-item-value,
body[data-theme="dark"] .vehicle-card-year,
body[data-theme="dark"] .ag-pass__license-num {
  color: #dbeafe;
}
body[data-theme="dark"] .required-marker {
  color: #ff8a8a;
}
body[data-theme="dark"] .portal-main :is(h3, h4):not([class*="hero"]) {
  color: inherit;
}

/* 5) Gestión documental: modales (subir, permisos, almacenamiento, carpetas) */
body[data-theme="dark"] .doc-upload-chip {
  background: #12233a;
  color: #dbe8f7;
  border-color: rgba(148, 196, 255, 0.28);
}
body[data-theme="dark"] .doc-upload-chip:hover {
  border-color: rgba(96, 165, 250, 0.7);
  background: #17304d;
}
body[data-theme="dark"] .doc-upload-chip.is-selected {
  background: rgba(59, 130, 246, 0.28);
  border-color: #60a5fa;
  color: #ffffff;
}
body[data-theme="dark"] .doc-upload-modal__select-wrap textarea,
body[data-theme="dark"] .doc-upload-destination__icon {
  background: #12233a;
  color: #e8f4fc;
}
body[data-theme="dark"] .doc-upload-modal__chip-empty,
body[data-theme="dark"] .doc-crumb-sep {
  color: #a9bdd4;
}
body[data-theme="dark"] .doc-dropzone__title,
body[data-theme="dark"] .doc-storage-details__total,
body[data-theme="dark"] .doc-storage-row__name,
body[data-theme="dark"] .doc-perm-user-name,
body[data-theme="dark"] .doc-perm-grid th {
  color: #e8f4fc;
}

/* 6) Insignias e iconos pastel de tema claro → versión translúcida legible en oscuro */
body[data-theme="dark"] :is(.report-cat-badge, .report-detail__icon, .detail-view-card__icon, .payroll-abs-chip, .simit-refresh) {
  background: rgba(148, 196, 255, 0.14) !important;
  color: #cfe6fb !important;
  border-color: rgba(148, 196, 255, 0.28) !important;
}
body[data-theme="dark"] .payroll-abs-chip[class*="vac"] {
  background: rgba(16, 185, 129, 0.2) !important;
  color: #a7f3d0 !important;
}
body[data-theme="dark"] .simit-refresh:hover {
  background: rgba(148, 196, 255, 0.24) !important;
}

/* 7) Contadores, etapas de contratación, paneles vacíos y textos secundarios */
body[data-theme="dark"] .dashboard-studio {
  --nx-green: #4ade80;
  --nx-accent: #8ec5ff;
}
body[data-theme="dark"] :is(
  .payroll-data-nav-count,
  .reports-card-count,
  .hiring-list-view__count,
  .hiring-browse__tab-count,
  .requests-data-sidebar__count,
  .hist-trace-module-chip__count
) {
  background: rgba(148, 196, 255, 0.16);
  color: #dbe9f8;
}
body[data-theme="dark"] :is(.is-active, [aria-selected="true"]) > :is(.payroll-data-nav-count, .hiring-browse__tab-count),
body[data-theme="dark"] :is(.payroll-data-nav-tab.is-active, .hiring-browse__tab.is-active) :is(.payroll-data-nav-count, .hiring-browse__tab-count) {
  background: rgba(8, 20, 38, 0.45);
  color: #fff;
}

body[data-theme="dark"] .hiring-studio .hiring-stage-pill--recibido { background: rgba(59, 130, 246, 0.22); color: #93c5fd; }
body[data-theme="dark"] .hiring-studio .hiring-stage-pill--preseleccionado { background: rgba(139, 92, 246, 0.24); color: #c4b5fd; }
body[data-theme="dark"] .hiring-studio .hiring-stage-pill--entrevistado { background: rgba(249, 115, 22, 0.22); color: #fdba74; }
body[data-theme="dark"] .hiring-studio .hiring-stage-pill--oferta-enviada { background: rgba(20, 184, 166, 0.22); color: #5eead4; }
body[data-theme="dark"] .hiring-studio .hiring-stage-pill--contratado { background: rgba(16, 185, 129, 0.22); color: #6ee7b7; }
body[data-theme="dark"] .hiring-studio .hiring-stage-pill--descartado { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; }

body[data-theme="dark"] .sst-studio .sst-employee-preview {
  background: linear-gradient(180deg, #14263d, #0f1f33);
  border-color: rgba(148, 196, 255, 0.2);
  color: #e8f4fc;
}
body[data-theme="dark"] .sst-studio .sst-employee-preview__empty { color: #a9bdd4; }
body[data-theme="dark"] .hiring-studio .hiring-list-detail__empty {
  background: #12233a;
  border-color: rgba(148, 196, 255, 0.2);
  color: #a9bdd4;
}
body[data-theme="dark"] .hiring-studio .hiring-list-detail__empty :is(p, .ico, svg) { color: #a9bdd4; }

body[data-theme="dark"] :is(
  .payroll-run-amount-label,
  .simit-head__meta,
  .sst-create-form__milestone-copy small
) { color: #a9bdd4; }
body[data-theme="dark"] .payroll-legal-field .field-label span { color: #cfe0f3; }
body[data-theme="dark"] :is(.hiring-list-row__next, .doc-link, .doc-cat-card__name) { color: #8ec5ff; }

body[data-theme="dark"] .ag-ring > span {
  background: #12233a;
  color: #e8f4fc;
}
body[data-theme="dark"] .documents-studio.doc-studio .doc-btn--primary {
  background: #2f6fe0;
  color: #fff;
}
body[data-theme="dark"] .documents-studio.doc-studio .doc-btn--primary:hover { background: #3b7df0; }

/* 7b) Refuerzo de especificidad para contadores y textos que seguían claros */
body[data-theme="dark"] :is(
  .auth-tab-badge,
  .payroll-data-nav-count,
  .hist-trace-module-chip__count,
  .reports-card-count,
  .hiring-list-view__count
) {
  background: rgba(148, 196, 255, 0.16) !important;
  color: #dbe9f8 !important;
  border-color: rgba(148, 196, 255, 0.22) !important;
}
body[data-theme="dark"] :is(.auth-tab-btn.is-active, .payroll-data-nav-tab.is-active, .hist-trace-module-chip.is-active) :is(.auth-tab-badge, .payroll-data-nav-count, .hist-trace-module-chip__count) {
  background: rgba(6, 16, 30, 0.38) !important;
  color: #fff !important;
}
body[data-theme="dark"] .documents-studio.doc-studio :is(.doc-upload-modal__step, .doc-perm-section-badge) { background: #2563eb; color: #fff; }
body[data-theme="dark"] .status.status-viaje_asignado { background: #17785a; color: #fff; }
body[data-theme="dark"] .documents-studio.doc-studio :is(.doc-link, .doc-link--row, .doc-cat-card__name) { color: #8ec5ff !important; }
body[data-theme="dark"] .documents-studio.doc-studio .doc-kpi__sub--ok { color: #34d399; }
body[data-theme="dark"] .documents-studio.doc-studio .doc-subfolder-card__avatar--amber { background: #b45309; }
body[data-theme="dark"] .documents-studio.doc-studio .doc-subfolder-card__avatar--cyan { background: #0e7490; }
body[data-theme="dark"] .documents-studio.doc-studio .doc-subfolder-card__avatar--green { background: #047857; }
body[data-theme="dark"] .documents-studio.doc-studio .doc-subfolder-card__avatar--blue { background: #1d4ed8; }
body[data-theme="dark"] .documents-studio.doc-studio button.is-danger,
body[data-theme="dark"] .documents-studio.doc-studio button.is-danger span { color: #fca5a5; }
body[data-theme="dark"] .ntf-pref-toggle__state { color: #c4d9ee; }

/* 8) SST: tarjetas que filtran y filtros plegables */
body[data-theme="dark"] .sst-studio button.sst-status-card { color: #e8f4fc; }
body[data-theme="dark"] .sst-studio .sst-status-card.is-active { background: #14263d; }
body[data-theme="dark"] .sst-studio .sst-filters-disclosure__summary {
  background: #12233a;
  border-color: rgba(148, 196, 255, 0.24);
  color: #cfe0f3;
}
body[data-theme="dark"] .sst-studio .sst-filters-disclosure__summary:hover { border-color: #8ec5ff; color: #fff; }
body[data-theme="dark"] .sst-studio .sst-filters-disclosure__on { background: rgba(148, 196, 255, 0.2); color: #dbe9f8; }
body[data-theme="dark"] .sst-studio .sst-due-cell__rel--expired { color: #fca5a5; }
body[data-theme="dark"] .sst-studio .sst-due-cell__rel--warning { color: #fcd34d; }
body[data-theme="dark"] .sst-studio .sst-due-cell__rel--missing { color: #a9bdd4; }
body[data-theme="dark"] .sst-studio .sst-due-cell__date { color: #e8f4fc; }
body[data-theme="dark"] .sst-studio .sst-person-avatar { background: rgba(148, 196, 255, 0.2); color: #dbe9f8; }
body[data-theme="dark"] .sst-studio .sst-person-name,
body[data-theme="dark"] .sst-studio .sst-control-name { color: #e8f4fc; }
body[data-theme="dark"] .sst-studio .sst-status-pill--expired { background: rgba(239, 68, 68, 0.24); color: #fecaca; }
body[data-theme="dark"] .sst-studio .sst-status-pill--warning { background: rgba(245, 158, 11, 0.24); color: #fde68a; }
body[data-theme="dark"] .sst-studio .sst-status-pill--ok { background: rgba(34, 197, 94, 0.22); color: #bbf7d0; }
body[data-theme="dark"] .sst-studio .sst-status-pill--missing { background: rgba(129, 140, 248, 0.24); color: #c7d2fe; }
body[data-theme="dark"] .sst-studio .sst-status-pill--total { background: rgba(59, 130, 246, 0.24); color: #bfdbfe; }
body[data-theme="dark"] .sst-studio .sst-consult-toolbar,
body[data-theme="dark"] .sst-studio .payroll-data-toolbar { background: transparent; box-shadow: none; }
body[data-theme="dark"] .sst-studio .sst-due-card {
  background: linear-gradient(180deg, #14263d, #0f1f33);
  border-color: rgba(148, 196, 255, 0.2);
  box-shadow: none;
}
body[data-theme="dark"] .sst-studio .sst-due-card--expired { border-color: rgba(239, 68, 68, 0.45); }
body[data-theme="dark"] .sst-studio .sst-due-card--warning { border-color: rgba(245, 158, 11, 0.4); }
body[data-theme="dark"] .sst-studio .hr-workspace-header--sst,
body[data-theme="dark"] .sst-studio .sst-consult-head { background: transparent; box-shadow: none; border-color: transparent; }

/* 9) Campos de formulario en modales (fuera de .portal-main): el foco/hover no debe volverse blanco */
body[data-theme="dark"] .modal-edit-form :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea):is(:focus, :focus-visible, :hover, :active),
body[data-theme="dark"] .modal :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select, textarea):is(:focus, :focus-visible) {
  background-color: #0c1a2b;
  color: #e8f4fc;
}
body[data-theme="dark"] .searchable-select-input:is(:focus, :hover, :active),
body[data-theme="dark"] .searchable-select--open .searchable-select-input {
  background-color: #0c1a2b;
  color: #e8f4fc;
}
body[data-theme="dark"] .modal-edit-form :is(input[readonly], input[disabled], select[disabled], textarea[disabled]) {
  background-color: rgba(148, 163, 184, 0.12);
  color: #a9bdd4;
  border-color: rgba(148, 196, 255, 0.16);
}
body[data-theme="dark"] .searchable-select-option:is(:hover, :focus) { background: rgba(148, 196, 255, 0.16); color: #fff; }
body[data-theme="dark"] .searchable-select-option.is-active { background: rgba(148, 196, 255, 0.24); color: #fff; }

/* 10) Estados hover/foco con fondo blanco fijo de tema claro → versión oscura (revisión global) */
body[data-theme="dark"] :is(
  .sst-studio .sst-row-more__btn:hover,
  .sst-studio .sst-row-more[open] .sst-row-more__btn,
  .sst-studio .sst-row-more__item:hover,
  .hiring-studio .hiring-action-menu__panel button:hover,
  .hiring-studio .hiring-consult-menu__panel button:hover,
  .simit-pill:hover,
  .detail-view-footer .detail-view-close-btn:hover:not(:disabled),
  a.portal-detail-tile:hover,
  .trip-ops-card-btn--outline:hover,
  .report-preview-export-btn:hover,
  .hr-workspace-tab--segment:hover,
  .hr-wizard-nav-btn:hover:not(:disabled)
) {
  background: rgba(148, 196, 255, 0.16);
  color: #fff;
}
body[data-theme="dark"] .trip-ops-card-btn--danger:hover { background: rgba(239, 68, 68, 0.22); color: #fecaca; }
body[data-theme="dark"] .sst-studio .sst-consult-table tbody tr:hover td,
body[data-theme="dark"] .sarlaft-evidence-list li:hover { background: rgba(148, 196, 255, 0.08); }
body[data-theme="dark"] :is(.simit-search:focus-within, .ag-fleet__controls .ag-search:focus-within) {
  background: #0c1a2b;
  color: #e8f4fc;
}
body[data-theme="dark"] .module-field-filter :is(select, input[type="date"]):is(:hover, :focus) {
  background-color: #0c1a2b;
  color: #e8f4fc;
}
