/**
 * PactaHealth Dark-Mode Selector Overrides
 *
 * SINGLE SOURCE OF TRUTH for all `[data-theme="dark"]` selector rules.
 * Token overrides live in design-system.css (`[data-theme="dark"] { --token: … }`).
 * his-bridge.css holds the bridge-token mapping. Everything else (component-level
 * tweaks that need a different gradient/shadow/structure than tokens alone provide)
 * goes here.
 *
 * Loaded LAST so cascade behavior is identical to the previous scattered layout.
 *
 * RULES:
 *   1. Do not put pure token swaps here — put them in design-system.css.
 *   2. Do not put structural/light-mode rules here.
 *   3. Keep groups together with section comments to ease audits.
 *   4. Adding a `[data-theme="dark"] …` rule anywhere else is a CI fail (see Phase 5).
 */

/* ============================================================
   FORMS — surfaces, native control color-scheme, file inputs
   ============================================================ */

[data-theme='dark'] input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='file']):not([type='color']):not([type='submit']):not([type='button']):not([type='reset']),
[data-theme='dark'] textarea,
[data-theme='dark'] select,
[data-theme='dark'] .form-control,
[data-theme='dark'] .form-select {
  border-color: var(--border-medium);
  background: var(--surface-subtle);
}

[data-theme='dark'] select,
[data-theme='dark'] .form-select,
[data-theme='dark'] select.form-control {
  color-scheme: dark;
}

[data-theme='dark'] input[type='date'],
[data-theme='dark'] input[type='time'],
[data-theme='dark'] input[type='datetime-local'],
[data-theme='dark'] input[type='month'],
[data-theme='dark'] input[type='week'] {
  color-scheme: dark;
}

[data-theme='dark'] select option,
[data-theme='dark'] .form-select option,
[data-theme='dark'] .form-control option {
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

[data-theme='dark'] input[type='file'],
[data-theme='dark'] .form-control[type='file'] {
  background: var(--surface-subtle);
  border-color: var(--border-medium);
}

[data-theme='dark'] input[type='file']::file-selector-button,
[data-theme='dark'] .form-control[type='file']::file-selector-button {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.28);
  color: var(--color-primary-light);
}

[data-theme='dark'] .settings-panel {
  border-color: var(--chrome-border);
  background: linear-gradient(180deg, var(--surface-strong), var(--surface-raised));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 20px 40px -28px rgba(0, 0, 0, 0.7);
}

/* ============================================================
   CARDS — gradient depth + inset highlight that tokens can't express
   ============================================================ */

[data-theme='dark'] .card {
  border-color: var(--chrome-border);
  background: linear-gradient(180deg, var(--surface-strong), var(--surface-raised));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 20px 40px -28px rgba(0, 0, 0, 0.7);
}

[data-theme='dark'] .card:hover {
  border-color: var(--border-medium);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 26px 48px -30px rgba(0, 0, 0, 0.85);
}

[data-theme="dark"] .metric-card {
  background: var(--surface-subtle);
  border-color: var(--border-light);
}

[data-theme="dark"] .qa-card--primary {
  border-color: var(--his-400);
  background: var(--status-info-bg);
}

/* ============================================================
   ALERTS / VALIDATION SUMMARIES
   ============================================================ */

[data-theme="dark"] .alert-success {
  background-color: rgba(16, 185, 129, 0.14);
  border-left-color: #10b981;
  color: #34d399;
}
[data-theme="dark"] .alert-warning {
  background-color: rgba(251, 191, 36, 0.14);
  border-left-color: #fbbf24;
  color: #fcd34d;
}
[data-theme="dark"] .alert-error {
  background-color: rgba(239, 68, 68, 0.14);
  border-left-color: #ef4444;
  color: #f87171;
}
[data-theme="dark"] .alert-info {
  background-color: rgba(14, 165, 233, 0.14);
  border-left-color: #0ea5e9;
  color: #38bdf8;
}

[data-theme="dark"] .validation-summary-errors {
  background-color: rgba(239, 68, 68, 0.14);
  border-left-color: #ef4444;
  color: #f87171;
}

/* ============================================================
   BADGES / CHIPS / TOAST
   ============================================================ */

[data-theme="dark"] .badge-primary {
  background-color: rgba(16, 185, 129, 0.20);
  color: #34d399;
}
[data-theme="dark"] .badge-success {
  background-color: rgba(16, 185, 129, 0.20);
  color: #34d399;
}
[data-theme="dark"] .badge-warning {
  background-color: rgba(251, 191, 36, 0.20);
  color: #fcd34d;
}
[data-theme="dark"] .badge-error {
  background-color: rgba(239, 68, 68, 0.20);
  color: #f87171;
}
[data-theme="dark"] .badge-info {
  background-color: rgba(14, 165, 233, 0.20);
  color: #38bdf8;
}

[data-theme="dark"] .chip-primary {
  background: var(--surface-strong);
  color: var(--color-primary-light);
}

[data-theme="dark"] .toast {
  background: var(--surface-strong);
  border-color: var(--border-light);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.04);
}

/* ============================================================
   TABLES — generic and HIS-specific
   ============================================================ */

[data-theme="dark"] .table thead th {
  background-color: var(--surface-strong);
  border-bottom-color: var(--border-medium);
  color: var(--text-secondary);
}
[data-theme="dark"] .table tbody tr:hover {
  background-color: var(--surface-subtle);
}
[data-theme="dark"] .table tbody td {
  border-bottom-color: var(--border-light);
}

[data-theme="dark"] .his-table tbody tr.row-selected td {
  background: var(--surface-strong);
}

[data-theme="dark"] .his-tab.active {
  color: var(--color-primary-light);
  border-bottom-color: var(--primary-400);
}

/* ============================================================
   ADMIN / EMPTY STATES
   ============================================================ */

[data-theme="dark"] .admin-empty-state {
  background: var(--surface-subtle);
  border-color: var(--border-light);
}

/* ============================================================
   HIS DASHBOARD QUICK ACTIONS
   ============================================================ */

[data-theme="dark"] .his-dashboard-action--primary {
  border-color: color-mix(in srgb, var(--his-400) 68%, var(--border));
  background:
    linear-gradient(
      to bottom right,
      color-mix(in srgb, var(--his-800) 42%, var(--surface-strong)),
      color-mix(in srgb, var(--his-900) 28%, var(--surface-raised))
    );
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--his-400) 24%, transparent), var(--sh-xs);
}

[data-theme="dark"] .his-dashboard-action--primary:hover {
  border-color: var(--his-400);
  background:
    linear-gradient(
      to bottom right,
      color-mix(in srgb, var(--his-700) 46%, var(--surface-strong)),
      color-mix(in srgb, var(--his-900) 32%, var(--surface-raised))
    );
}

[data-theme="dark"] .his-dashboard-action--primary .his-dashboard-action__badge {
  background: var(--his-500);
  color: var(--neutral-50);
}

/* ============================================================
   ENTERPRISE SHELL / HEADER / TOOLBAR
   ============================================================ */

[data-theme="dark"] .enterprise-shell {
  background:
    radial-gradient(ellipse at top left, rgba(16, 185, 129, 0.08), transparent 40%),
    radial-gradient(ellipse at top right, rgba(14, 165, 233, 0.08), transparent 40%),
    var(--bg-shell);
}

[data-theme="dark"] .enterprise-header {
  background: linear-gradient(180deg, var(--surface-strong), var(--surface-raised));
  border-bottom-color: var(--chrome-border);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03), 0 20px 40px -30px rgba(0, 0, 0, 0.8);
}

[data-theme="dark"] .active-module-chip,
[data-theme="dark"] .toolbar-btn,
[data-theme="dark"] .toolbar-chip,
[data-theme="dark"] .user-panel {
  border-color: var(--chrome-border);
  background: linear-gradient(180deg, var(--surface-strong), var(--surface-raised));
  box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .toolbar-chip:hover,
[data-theme="dark"] .toolbar-btn:hover,
[data-theme="dark"] .user-panel-link:hover {
  border-color: var(--border-medium);
  box-shadow: var(--shadow-md);
}

[data-theme="dark"] .toolbar-chip-indicator {
  background: var(--color-success);
  box-shadow: 0 0 0 5px var(--color-success-light);
}

[data-theme="dark"] .toolbar-chip-danger:hover {
  border-color: rgba(239, 68, 68, 0.36);
  background: rgba(239, 68, 68, 0.1);
}

[data-theme="dark"] .page-surface {
  background: var(--surface-raised);
  border-color: var(--chrome-border);
}

/* Module strip tabs dark mode depth */
[data-theme="dark"] .module-strip__tabs .module-nav {
  background: linear-gradient(180deg, var(--surface-subtle), var(--surface-raised));
  border-color: rgba(123, 156, 193, 0.14);
  box-shadow: none;
}

[data-theme="dark"] .module-strip__tabs .module-nav .module-nav__item {
  color: rgba(200, 218, 238, 0.82);
}

[data-theme="dark"] .module-strip__tabs .module-nav .module-nav__item:hover {
  color: var(--text-primary);
  background: var(--surface-strong);
  border-color: rgba(103, 190, 255, 0.2);
  box-shadow: none;
}

[data-theme="dark"] .module-strip__tabs .module-nav .module-nav__item.is-active,
[data-theme="dark"] .module-strip__tabs .module-nav .module-nav__item.active {
  color: var(--neutral-0);
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.30), rgba(5, 150, 105, 0.25));
  border-color: rgba(16, 185, 129, 0.36);
  box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.18), var(--shadow-sm);
}

[data-theme="dark"] .module-strip__tabs .module-nav .module-nav__item.is-active::after,
[data-theme="dark"] .module-strip__tabs .module-nav .module-nav__item.active::after {
  background: linear-gradient(90deg, var(--color-primary), var(--color-secondary));
}

/* ============================================================
   SPLASH — brand-logo light/dark variants
   ============================================================ */

[data-theme="dark"] .splash-brand-logo--light {
  display: none;
}

[data-theme="dark"] .splash-brand-logo--dark {
  display: block;
}
