/* AF-Health v18 — final dark-mode guardrails.
   Loaded after theme customizations and late portal styles. */

html[data-theme="light"]{color-scheme:light}
html[data-theme="dark"]{color-scheme:dark}

html[data-theme="dark"] body[class*="frontend-theme-"]:not(.role-admin){
  background-color:var(--bg)!important;
  color:var(--text)!important;
}
html[data-theme="dark"] body[class*="frontend-theme-"]:not(.role-admin) :where(.app-main,.page-content,.public-main){
  color:var(--text);
}

/* The two newest themes contained late light-only portal rules after their
   original dark-mode block. Re-apply those components using dark variables. */
html[data-theme="dark"] body.portal-experience.frontend-theme-sunrise_gold:not(.role-admin){
  --portal-shell-bg:var(--theme-sidebar);
  --portal-shell-ink:var(--text);
  --portal-shell-muted:var(--muted);
  --portal-shell-soft:var(--surface-2);
  --portal-shell-soft-2:var(--surface-3);
  --portal-shell-line:var(--border);
  --portal-shell-accent:var(--primary);
}
html[data-theme="dark"] body.portal-experience.frontend-theme-crimson_pulse:not(.role-admin){
  --portal-shell-bg:var(--theme-sidebar);
  --portal-shell-ink:var(--text);
  --portal-shell-muted:var(--muted);
  --portal-shell-soft:var(--surface-2);
  --portal-shell-soft-2:var(--surface-3);
  --portal-shell-line:var(--border);
  --portal-shell-accent:var(--primary);
}
html[data-theme="dark"] body.portal-experience:is(.frontend-theme-sunrise_gold,.frontend-theme-crimson_pulse):not(.role-admin) .sidebar{
  background:linear-gradient(165deg,var(--theme-sidebar),var(--theme-sidebar-2))!important;
  color:var(--text)!important;
  border-color:var(--border)!important;
  scrollbar-color:color-mix(in srgb,var(--primary) 40%,transparent) transparent!important;
}
html[data-theme="dark"] body.portal-experience:is(.frontend-theme-sunrise_gold,.frontend-theme-crimson_pulse):not(.role-admin) .sidebar :where(.app-brand,.brand-copy,.brand-copy strong,.brand-copy small,.sidebar-close){
  color:var(--text)!important;
}
html[data-theme="dark"] body.portal-experience:is(.frontend-theme-sunrise_gold,.frontend-theme-crimson_pulse):not(.role-admin) :where(.workspace-chip,.sidebar-user-card,.provider-nav-search){
  border-color:var(--border)!important;
  background:color-mix(in srgb,var(--surface-2) 94%,transparent)!important;
  color:var(--text)!important;
  box-shadow:inset 0 1px 0 color-mix(in srgb,#fff 7%,transparent)!important;
}
html[data-theme="dark"] body.portal-experience:is(.frontend-theme-sunrise_gold,.frontend-theme-crimson_pulse):not(.role-admin) :where(.workspace-chip,.sidebar-user-card) :where(strong,small),
html[data-theme="dark"] body.portal-experience:is(.frontend-theme-sunrise_gold,.frontend-theme-crimson_pulse):not(.role-admin) .provider-nav-search input{
  color:var(--text)!important;
}
html[data-theme="dark"] body.portal-experience:is(.frontend-theme-sunrise_gold,.frontend-theme-crimson_pulse):not(.role-admin) :where(.workspace-chip,.sidebar-user-card) small,
html[data-theme="dark"] body.portal-experience:is(.frontend-theme-sunrise_gold,.frontend-theme-crimson_pulse):not(.role-admin) .provider-nav-search input::placeholder{
  color:var(--muted)!important;
  opacity:1!important;
}
html[data-theme="dark"] body.provider-portal.portal-experience:is(.frontend-theme-sunrise_gold,.frontend-theme-crimson_pulse):not(.role-admin) .provider-nav-search:focus-within,
html[data-theme="dark"] body.provider-portal.portal-experience:is(.frontend-theme-sunrise_gold,.frontend-theme-crimson_pulse):not(.role-admin) .provider-nav-search kbd{
  border-color:var(--border)!important;
  background:var(--surface-3)!important;
  color:var(--text)!important;
}

/* Common theme-aware surfaces: this catches hard-coded light surfaces without
   erasing the individual theme palette or administrator dark-color choices. */
html[data-theme="dark"] body.guest-shell[class*="frontend-theme-"]:not(.role-admin) :where(
  .public-header,.auth-card,.auth-card-modern,.signup-form-surface,.registration-form-card,.marketplace-registration-panel
),
html[data-theme="dark"] body.portal-experience[class*="frontend-theme-"]:not(.role-admin) :where(
  .topbar,.card,.metric-card-pro,.doctor-dashboard-metric,.quick-action-pro,.doctor-command-card,.subscription-panel,.doctor-plan-panel
){
  border-color:var(--border)!important;
  color:var(--text)!important;
}

/* Signup pages in dark mode always follow each theme's dark variables. */
html[data-theme="dark"] body[class*="frontend-theme-"]:not(.role-admin) .dedicated-signup :where(
  .signup-form-surface,.signup-section,.provider-intro,.patient-signup-story,.checkbox-row,.file-drop-field,.degree-upload-card,.marketplace-entity-option span
){
  border-color:color-mix(in srgb,var(--primary) 22%,var(--border))!important;
  color:var(--text)!important;
}
html[data-theme="dark"] body[class*="frontend-theme-"]:not(.role-admin) .dedicated-signup :where(.input,.select,.textarea,input[type="file"]){
  border-color:var(--border)!important;
  background:var(--surface-2)!important;
  color:var(--text)!important;
}
