/*
 * Customer-selectable visual themes and responsive text containment.
 * Theme choices change brand/navigation accents only. Semantic state colors
 * remain stable so risk, warning, success, and information keep one meaning.
 */

:root {
  /* Semantic foreground and surface roles shared by every visual theme. */
  --qms-on-brand: #ffffff;
  --qms-on-brand-muted: #dbeaf2;
  --qms-on-action: #ffffff;
  --qms-action-surface: var(--qms-brand-quality, #0f766e);
  --qms-action-surface-hover: var(--qms-brand-quality-strong, #115e59);
  --qms-shell-context-surface: var(--qms-shell-topbar-strong, #0b2942);
  --qms-shell-context-border: var(--qms-shell-rail-border, #4f7189);
  --qms-shell-context-ink: var(--qms-on-brand);
  --qms-shell-context-icon: var(--qms-on-brand-muted);
}

html[data-qms-theme="navy"] {
  --qms-brand-ink: #123b5d;
  --qms-brand-ink: oklch(35% 0.08 245);
  --qms-brand-ink-strong: #0b2942;
  --qms-brand-ink-strong: oklch(27% 0.065 245);
  --qms-brand-quality: #0f766e;
  --qms-brand-quality: oklch(50% 0.085 183);
  --qms-brand-quality-strong: #115e59;
  --qms-brand-quality-strong: oklch(42% 0.07 183);
  --qms-brand-quality-soft: #e7f5f2;
  --qms-brand-soft: #edf3f7;
  --qms-canvas: #f5f7fa;
  --qms-surface-muted: #f1f4f7;
  --qms-border: #d7e0e7;
  --qms-border-strong: #b8c5cf;
  --qms-shell-topbar: #123b5d;
  --qms-shell-topbar-strong: #0b2942;
  --qms-shell-rail: #123b5d;
  --qms-shell-rail-hover: #0b2942;
  --qms-shell-rail-active: #0f766e;
  --qms-shell-rail-ink: #ffffff;
  --qms-shell-rail-muted: #dbeaf2;
  --qms-shell-rail-border: #4f7189;
  --qms-shell-rail-active-ink: #115e59;
  --qms-shell-nav-active: #e7f5f2;
  --qms-shell-nav-active-border: #a9ddd4;
}

html[data-qms-theme="teal"] {
  --qms-brand-ink: #0f625c;
  --qms-brand-ink: oklch(43% 0.075 183);
  --qms-brand-ink-strong: #0a4743;
  --qms-brand-ink-strong: oklch(34% 0.06 183);
  --qms-brand-quality: #245f7a;
  --qms-brand-quality: oklch(45% 0.07 230);
  --qms-brand-quality-strong: #19465c;
  --qms-brand-quality-strong: oklch(35% 0.055 230);
  --qms-brand-quality-soft: #e6f3f2;
  --qms-brand-soft: #eaf4f3;
  --qms-canvas: #f3f8f7;
  --qms-surface-muted: #edf5f4;
  --qms-text: #172725;
  --qms-text-muted: #506763;
  --qms-border: #d2e1df;
  --qms-border-strong: #afc6c2;
  --qms-shell-topbar: #0f625c;
  --qms-shell-topbar-strong: #0a4743;
  --qms-shell-rail: #0f625c;
  --qms-shell-rail-hover: #0a4743;
  --qms-shell-rail-active: #245f7a;
  --qms-shell-rail-ink: #ffffff;
  --qms-shell-rail-muted: #d7efec;
  --qms-shell-rail-border: #4f8882;
  --qms-shell-rail-active-ink: #19465c;
  --qms-shell-nav-active: #e6f3f2;
  --qms-shell-nav-active-border: #afd9d3;
}

html[data-qms-theme="rose"] {
  --qms-brand-ink: #7a284e;
  --qms-brand-ink: oklch(43% 0.12 350);
  --qms-brand-ink-strong: #581a37;
  --qms-brand-ink-strong: oklch(33% 0.1 350);
  --qms-brand-quality: #176d66;
  --qms-brand-quality: oklch(47% 0.075 183);
  --qms-brand-quality-strong: #11534e;
  --qms-brand-quality-strong: oklch(38% 0.06 183);
  --qms-brand-quality-soft: #f2e8ee;
  --qms-brand-soft: #f5edf2;
  --qms-canvas: #faf6f8;
  --qms-surface-muted: #f6eff3;
  --qms-text: #2d2027;
  --qms-text-muted: #695661;
  --qms-border: #e4d6de;
  --qms-border-strong: #c9b3bf;
  --qms-shell-topbar: #7a284e;
  --qms-shell-topbar-strong: #581a37;
  --qms-shell-rail: #7a284e;
  --qms-shell-rail-hover: #581a37;
  --qms-shell-rail-active: #176d66;
  --qms-shell-rail-ink: #ffffff;
  --qms-shell-rail-muted: #f5dbe7;
  --qms-shell-rail-border: #9f5c7d;
  --qms-shell-rail-active-ink: #11534e;
  --qms-shell-nav-active: #f2e8ee;
  --qms-shell-nav-active-border: #d8b8c8;
}

html[data-qms-theme="graphite"] {
  --qms-brand-ink: #2c3645;
  --qms-brand-ink: oklch(34% 0.03 255);
  --qms-brand-ink-strong: #171f2b;
  --qms-brand-ink-strong: oklch(24% 0.025 255);
  --qms-brand-quality: #315f73;
  --qms-brand-quality: oklch(45% 0.055 225);
  --qms-brand-quality-strong: #234758;
  --qms-brand-quality-strong: oklch(36% 0.045 225);
  --qms-brand-quality-soft: #e9eef1;
  --qms-brand-soft: #eef1f4;
  --qms-canvas: #f4f5f7;
  --qms-surface-muted: #eef0f3;
  --qms-text: #20252d;
  --qms-text-muted: #59616d;
  --qms-border: #d7dce2;
  --qms-border-strong: #b7c0ca;
  --qms-shell-topbar: #2c3645;
  --qms-shell-topbar-strong: #171f2b;
  --qms-shell-rail: #2c3645;
  --qms-shell-rail-hover: #171f2b;
  --qms-shell-rail-active: #315f73;
  --qms-shell-rail-ink: #ffffff;
  --qms-shell-rail-muted: #dbe3e9;
  --qms-shell-rail-border: #657483;
  --qms-shell-rail-active-ink: #234758;
  --qms-shell-nav-active: #e9eef1;
  --qms-shell-nav-active-border: #bac9d3;
}

body:not(.login-body) .domain-navigation .topbar-nav-item:hover,
body:not(.login-body) .domain-navigation .topbar-nav-item.active,
body:not(.login-body) .domain-navigation .domain-nav-item.is-active .topbar-nav-item,
body:not(.login-body) .domain-navigation .nav-item-icon,
body:not(.login-body) .domain-mega-heading-icon {
  background: var(--qms-brand-soft) !important;
}

.qms-theme-options {
  display: grid;
  gap: 7px;
}

.qms-theme-option {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 8px 10px;
  border: 1px solid var(--qms-border);
  border-radius: var(--qms-radius-sm);
  background: var(--qms-surface);
  color: var(--qms-text);
  cursor: pointer;
  text-align: left;
}

.qms-theme-option:hover,
.qms-theme-option[aria-checked="true"] {
  border-color: var(--qms-brand-quality);
  background: var(--qms-brand-soft);
}

.qms-theme-option-swatch {
  width: 24px;
  height: 24px;
  border: 1px solid var(--qms-border-strong);
  border-radius: 50%;
  background: var(--theme-swatch);
}

.qms-theme-option-copy {
  min-width: 0;
}

.qms-theme-option-copy strong,
.qms-theme-option-copy small {
  display: block;
  overflow-wrap: anywhere;
}

.qms-theme-option-copy strong {
  font-size: 12px;
}

.qms-theme-option-copy small {
  margin-top: 2px;
  color: var(--qms-text-muted);
  font-size: 10px;
  line-height: 1.35;
}

.qms-theme-option-check {
  color: var(--qms-brand-quality-strong);
  font-weight: 800;
  opacity: 0;
}

.qms-theme-option[aria-checked="true"] .qms-theme-option-check {
  opacity: 1;
}

/*
 * System-wide contrast guarantees for legacy accreditation screens. These
 * selectors only correct text contrast; semantic colors and module behavior
 * stay unchanged.
 */
body:not(.login-body) :is(
  .hacc-kpi-card small,
  .hacc-muted,
  .hacc-gauge-ticks,
  .hacc-chart-data-item span,
  .hacc-mini-metric span
) {
  color: var(--qms-text-muted, #52606d) !important;
}

body:not(.login-body) :is(
  .hacc-btn.hacc-primary,
  a.hacc-btn.hacc-primary,
  button.hacc-btn.hacc-primary
) {
  color: #ffffff !important;
}

body:not(.login-body) .domain-navigation .dropdown-chevron {
  color: var(--qms-text-muted, #475569) !important;
}

/*
 * Shared text and layout containment. These rules preserve content instead of
 * clipping it when translations, email addresses, standard codes, or action
 * labels are longer than their original desktop mock.
 */
body:not(.login-body) :is(
  .main-wrapper,
  .page-content,
  main,
  section,
  article,
  aside,
  header,
  footer,
  form,
  fieldset,
  .card-box,
  .card-head,
  .inner-page-banner,
  .qms-page-heading,
  .qms-data-panel,
  .role-admin-layout,
  .role-editor,
  .role-directory
) {
  min-width: 0;
}

body:not(.login-body) :is(
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  p,
  label,
  small,
  strong,
  .nav-label,
  .topbar-action-label,
  .page-subtitle,
  .card-head span,
  .qms-notice,
  .qms-status
) {
  max-width: 100%;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

body:not(.login-body) :is(h1, h2, h3) {
  text-wrap: balance;
}

body:not(.login-body) :is(
  .welcome-actions,
  .qms-heading-actions,
  .topbar-action-row,
  .card-head,
  .qms-form-actions,
  .filter-actions,
  .table-actions
) {
  flex-wrap: wrap;
  min-width: 0;
}

body:not(.login-body) :is(code, pre, .mono, [data-long-value]) {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

body:not(.login-body) :is(.table-wrap, .qms-table-scroll) {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

body:not(.login-body) table :is(th, td) {
  overflow-wrap: anywhere;
  vertical-align: top;
}

@media (max-width: 1023px) {
  body:not(.login-body) :is(.inner-page-banner, .qms-page-heading) {
    align-items: flex-start;
    gap: 14px;
  }
}

@media (max-width: 767px) {
  body:not(.login-body) .page-content {
    width: 100%;
    padding-inline: 12px !important;
  }

  body:not(.login-body) :is(.inner-page-banner, .qms-page-heading) {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
  }

  body:not(.login-body) :is(.welcome-actions, .qms-heading-actions, .qms-form-actions) {
    width: 100%;
  }

  body:not(.login-body) :is(.welcome-actions, .qms-heading-actions, .qms-form-actions) > :is(a, button) {
    min-width: 0;
    max-width: 100%;
    flex: 1 1 160px;
    white-space: normal;
  }

  body:not(.login-body) :is(input, select, textarea) {
    max-width: 100%;
    font-size: 16px !important;
  }
}

@media (pointer: coarse) {
  .qms-theme-option,
  body:not(.login-body) :is(a, button, input, select) {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .qms-theme-option {
    transition: none !important;
  }
}
