/* Shared screen overlay. Keep the switch legible even on pages without theme.css. */
@media screen {
  :root {
    --switch-face: #edf2f7;
    --switch-text: #003366;
    --switch-focus: #993300;
  }
  html[data-theme=light] {
    --switch-face: #fdfcf6;
    --switch-text: #304e39;
    --switch-edge: #808b79;
    --switch-focus: #265f50;
  }
  html[data-theme=dark] {
    --switch-face: #252e27;
    --switch-text: #dfebd7;
    --switch-edge: #899982;
    --switch-focus: #b8e3c9;
  }
  html .appearance-controls, html .topbar-appearance {
    display: inline-flex;
    flex: 0 1 auto;
    flex-wrap: wrap;
    align-items: center;
    gap: .25rem;
    min-width: 0;
    max-width: 100%;
  }
  /* Device utilities are part of the running head, not a second toolbar. */
  html:root .appearance-controls { gap: 0 .45rem; }
  html:root .topbar-appearance {
    gap: .2rem; padding: 0; border: 0; background: transparent; box-shadow: none;
  }
  html:root .appearance-choice {
    position: relative; display: inline-grid; flex: none; align-items: center;
    max-inline-size: 100%; min-inline-size: 0; margin: 0;
    font: 600 .875rem/1.2 system-ui, sans-serif; color: var(--switch-text);
  }
  html:root .appearance-choice > span {
    position: absolute; inset: .22em auto auto .65rem; z-index: 1;
    font: 550 .7rem/1.15 system-ui, sans-serif; pointer-events: none;
  }
  html:root label.appearance-choice select[data-appearance-select] {
    appearance: auto; box-sizing: border-box; margin: 0; min-height: 44px; height: auto;
    max-width: 100%; padding: 1rem .4rem .14rem .6rem; border-radius: 4px;
    border: 1px solid var(--switch-edge, var(--switch-text)); background: var(--switch-face);
    color: var(--switch-text); font: inherit; cursor: pointer;
  }
  html:root .appearance-choice > svg[aria-hidden=true], html:root .appearance-choice::after { display: none; }
  html:root [data-appearance-fallback] {
    grid-column: 1 / -1; justify-self: start; align-self: start;
    margin: .35rem 0; padding: .15rem min(3vw, 1rem);
  }
  /* Decoration has no hit box of its own. Leave native disclosure markers alone. */
  svg[data-interface-icon] {
    display: inline-block; width: 1.12em; height: 1.12em; flex: none;
    margin-inline-end: .38em; vertical-align: -.16em; pointer-events: none;
  }
  :is(a, button, summary):has(> svg[data-interface-icon]) { column-gap: 0; }
  svg[data-ui-icon]:has(> path[data-interface-replacement]) > g { display: none; }
  html:root .topbar-appearance button[data-appearance-mode] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    height: auto;
  }
  html:root .topbar-appearance button[data-appearance-mode=accessibility],
  html:root a.appearance-accessibility-info {
    box-sizing: border-box;
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: .35em;
    width: auto;
    max-width: 100%;
    min-height: 44px;
    padding: .36em .65em;
    border: 1px solid var(--switch-text);
    border-radius: .45rem;
    background: var(--switch-face);
    color: var(--switch-text);
    font: 650 .9375rem/1.35 system-ui, sans-serif;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  html:root .topbar-appearance button[data-appearance-mode=accessibility] {
    border: 1px solid var(--switch-edge, var(--switch-text)); border-radius: 4px;
    padding-inline: .62em; font-size: .875rem; box-shadow: none;
  }
  html:root a.appearance-accessibility-info {
    justify-content: flex-start; padding: .25em .2em; border: 0; border-radius: 2px;
    background: transparent; color: var(--switch-text); font-size: .875rem; font-weight: 500;
    text-decoration: underline; text-underline-offset: .2em;
  }
  html:root a.appearance-accessibility-info:hover { text-decoration-thickness: 2px; }
  html:root .topbar-appearance button[data-appearance-mode=accessibility][aria-pressed=true] {
    background: var(--switch-text);
    color: var(--switch-face);
    border: 3px double currentColor;
  }
  html .topbar-appearance button .appearance-accessibility-label,
  html .topbar-appearance button .appearance-accessibility-state { display: inline; font: inherit; color: inherit; }
  html .topbar-appearance button .appearance-accessibility-state:not(:empty) {
    padding: .12em .45em;
    border: 1px solid currentColor;
    border-radius: 1em;
    font-size: .85em; line-height: 1.2;
  }
  /* Older shared shells already supply this accessible name. */
  .topbar-appearance button[data-appearance-mode=accessibility]:not(:has(.appearance-accessibility-label))::after { content: attr(aria-label); }
  html:root :is(.topbar-appearance button, .appearance-choice select, a.appearance-accessibility-info):focus-visible {
    outline: 3px solid var(--switch-focus);
    outline-offset: 2px;
    box-shadow: 0 0 0 2px var(--switch-face);
    z-index: 1;
  }
  :is(.auth-header, .verification-header, .utilities):has(.topbar-appearance) { flex-wrap: wrap; }
  .head-inner:has(.topbar-appearance) { display: flex; flex-wrap: wrap; justify-content: space-between; }
  @media (max-width: 48em) {
    body:has(.auth-page, .error-page) :is(.guest-appearance, .appearance-start):has(.topbar-appearance) {
      position: static;
      width: fit-content;
      max-width: calc(100% - 2rem);
      margin: 1rem auto;
    }
  }

  /* The root + attribute deliberately outranks later component palettes,
     including the landing page's OS-dark fallback. Nesting keeps scope explicit. */
  html:root[data-theme=accessibility] {
    color-scheme: light;
    --stock: #f4f7fa; --bg: var(--stock); --paper: #fff;
    --soft: #edf2f7; --band: var(--soft); --sidebar: var(--soft); --topbar: var(--paper);
    --ink: #112233; --body: #222; --muted: #444; --meta: var(--muted);
    --placeholder: #555; --control-border: #555; --rule: var(--control-border); --line: #666;
    --link: #036; --accent: var(--link); --accent-dark: #002244; --on-accent: #fff;
    --selected: #dceaff; --selected-ink: #036; --mint: var(--selected); --selection: var(--selected);
    --focus: #993300; --focus-ring: var(--focus); --focus-halo: #fff;
    --success: #004433; --success-bg: #e6f4ee; --success-border: var(--success);
    --warning: #663300; --warning-bg: #fff4dd; --warning-border: var(--warning);
    --danger: #771122; --danger-bg: #ffeded; --danger-border: var(--danger);
    --info: #036; --info-bg: #e5efff; --info-border: var(--info);
    --billing-ink: #432374; --billing-bg: #eee4fa; --billing-edge: var(--billing-ink);
    --billing-action: var(--billing-ink); --billing-on-action: #fff;
    --site-ink: var(--success); --site-bg: var(--success-bg); --site-edge: var(--site-ink);
    --site-action: var(--site-ink); --site-on-action: #fff;
    --surface: var(--paper); --text: var(--body); --border: var(--control-border); --text-muted: var(--muted);
    --attention-bg: var(--warning-bg); --attention-ink: var(--warning);
    --signal: var(--selected); --plate: var(--ink); --button-ink: var(--on-accent);
    --shadow: none; --scrim: rgb(17 34 51 / 72%);
    font-size: 112.5%;
    line-height: 1.65;
    background: var(--bg);
    scroll-padding-block: 1rem;

    & body { background: var(--bg); color: var(--body); font-size: 1rem; line-height: 1.65; overflow-wrap: anywhere; }
    & ::selection { color: var(--ink); background: var(--selection); }
    & :is(h1, h2, h3, h4) { color: var(--ink); line-height: 1.22; letter-spacing: normal; }
    & :is(.subtitle, .hero p, .module-card p, .panel-body, .modal-heading p, .dialog-message, .field, .data-table) { font-size: 1rem; }
    & :is(.muted, .nav-label, .local-note, .brand-name small, .breadcrumbs, .stat-label, .stat-note, .pill, .form-note, .label-note, .record-cell-label, .data-table th, .footer-line, .caption, .eyebrow, .register-foot, .specimen-note) { font-size: .875rem; }
    & :is(.form-note, .muted, .subtitle, .stat-note, .hero p, .module-card p, .panel-header p, .modal-heading p) { color: var(--muted); }
    & a[href], & :is(.text-link, .module-open, .record-open, .asset-link strong, a.panel h2) {
      text-decoration: underline;
      text-underline-offset: .18em;
      text-decoration-thickness: .08em;
    }
    & a[href]:where(:not(.button, .ops-button)), & :is(.text-link, .module-open, .record-open) { color: var(--link); }
    & a[href]:hover { text-decoration-thickness: .15em; }
    & :is(.skip, .skip-link) { color: var(--link); background: var(--paper); }
    & :is(.topbar, .masthead, .mast, .library, .auth-card, .panel, .card, .module-card, .modal, .leaf, .register, .radio-desk) {
      color: var(--body); background: var(--paper); border-color: var(--line);
    }
    & :is(.hero, .sidebar, .module-banner, .soft-tip, .modal-heading, .modal-footer, .desk-loans [data-desk-register-state]) {
      color: var(--body); background: var(--soft); border-color: var(--line);
    }
    /* These labels sit on the light sidebar, not on a dark plate. */
    & .sidebar :is(.brand-name small, .local-note) { color: var(--muted); }
    & :is(.main-content, #admin-view) .panel-header { background: var(--section-bg, var(--soft)); }
    & .workspace-switch :is(strong, small), & .brand-name-ops {
      display: block; white-space: normal; overflow: visible; overflow-wrap: anywhere; max-width: 100%;
    }
    & .workspace-switch :is(strong, small) { font-size: .875rem; }
    & .stat-label { padding-inline-end: 1.6em; }

    /* Native widgets retain their activation, selection and editing behaviour. */
    & :is(button, select, summary, [role=button]) { min-inline-size: 24px; min-block-size: 44px; }
    & :is(.button, .ops-button, .segment, .step, .filter-pill, .status-chip, .profile-button, .icon-button, .nav-item, .radio-desk button) {
      min-height: 44px; min-width: 44px; height: auto; max-width: 100%;
      white-space: normal; font-size: .9375rem; line-height: 1.45;
      color: var(--action-ink, var(--ink)); background: var(--action-bg, var(--paper)); border: 1px solid var(--action-edge, var(--control-border));
    }
    & :is(.button.primary, .ops-button, .actions > .button, .pricing-action .button) {
      color: var(--on-accent); background: var(--action-fill, var(--accent)); border-color: var(--action-fill, var(--accent));
    }
    & :is(.button.primary, .ops-button, .actions > .button, .pricing-action .button):is(:hover, :active) {
      background: var(--accent-dark); color: white; text-decoration: underline;
    }
    & :is(.button, .record-summary, .radio-desk button):enabled:hover { text-decoration: underline; }
    & :is(.nav-item, .segment, .step, .filter-pill, .mobile-nav a).active,
    & :is(button, .step)[aria-pressed=true]:not([data-appearance-mode]), & a[aria-current=page] {
      color: var(--selected-ink); background: var(--selected); border: 3px double currentColor;
      font-weight: 700; text-decoration: underline double;
    }
    & :is(.nav-item, .mobile-nav a).active { border-inline-start: .3rem solid currentColor; }
    & :is(.checkbox-row, .check-label, .software-agreement-choice, nav a, .text-link, .module-open) { min-block-size: 44px; }
    & nav a { align-content: center; }
    & :is(input[type=checkbox], input[type=radio]) { inline-size: 24px; block-size: 24px; accent-color: var(--accent); flex: none; }
    & :is(.input, .select, textarea, select, input:not([type]), input:is([type=text], [type=email], [type=password], [type=search], [type=number], [type=date], [type=datetime-local], [type=file], [type=tel], [type=url])) {
      box-sizing: border-box; max-width: 100%; min-width: 0; height: auto; min-height: 44px;
      font-size: 1rem; line-height: 1.5; color: var(--body); background-color: var(--paper); border: 2px solid var(--control-border);
    }
    & .appearance select { appearance: auto; padding-inline: .6em; }
    & .appearance .icon { position: static; }
    & .appearance::after { content: none; }
    & input::file-selector-button { min-height: 44px; background: var(--soft); color: var(--ink); border: 1px solid var(--control-border); }
    & :is(input, textarea)::placeholder { color: var(--placeholder); opacity: 1; }
    & :is(input, select, textarea):is([aria-invalid=true], :user-invalid) { border: 3px double var(--danger); }
    /* Detached tools use the same action roles as the desk, including on hover. */
    & .register-page {
      --register-key: var(--accent); --register-key-hover: var(--accent-dark);
      --register-key-ink: var(--on-accent); --register-key-edge: var(--accent);
    }
    & :is(button.button, .register-page button, .radio-desk button, input, select, textarea, [role=button], a.button):is(:disabled, [aria-disabled=true]) {
      opacity: 1; color: #444; background: #eee; border: 2px dashed #555; box-shadow: none; cursor: not-allowed;
    }

    & :is(.pill, .chip, .callout, .hint, .toast) { background: var(--soft); color: var(--body); border: 1px solid currentColor; }
    & :is(.pill.green, .toast.success, .email-verification-panel[data-email-confirmed]) { color: var(--success); background: var(--success-bg); }
    & :is(.pill.blue, .toast.info) { color: var(--info); background: var(--info-bg); }
    & :is(.pill.amber, .callout.warning, .status-chip.offline, .email-verification-panel:not([data-email-confirmed])) { color: var(--warning); background: var(--warning-bg); }
    & :is(.pill.red, .button.danger, .form-error, .auth-error, .toast.error, .status-chip.error, p[role=alert]:not(:empty)) {
      color: var(--danger); background: var(--danger-bg); border-inline-start: .25rem solid currentColor; padding-inline-start: .7em;
    }
    & .status-chip.offline .dot { border-radius: 0; }
    & .status-chip.error .dot { border-radius: 0; transform: rotate(45deg); }
    & :is(.table-wrap, .record-table-region, .report-preview) { min-width: 0; max-width: 100%; overflow: auto; }
    & :is(.main-content, #admin-view, .modal, .desk-loans) .data-table thead th { background: var(--selected); color: var(--ink); }
    & :is(.main-content, #admin-view, .modal, .desk-loans) .data-table tbody tr:nth-child(even) { background: var(--soft); }
    & .data-table tbody tr:is(:hover, :focus-within, [aria-selected=true]) td { background: var(--selected); color: var(--ink); }
    & .data-table tr[aria-selected=true] td:first-child { border-inline-start: .3rem solid var(--link); }
    & .report-preview :is(figcaption, .report-meta), & .qr-label small { color: #444; }

    /* Public register, help and policy furniture. Leave illustrations intact. */
    & :is(.policy, .policy-page, .help-page, .leaf, .contents) { color: var(--body); background-color: var(--paper); }
    & :is(.plate, .pricing-panel) { --ink: white; --link: white; background: var(--plate); color: white; border-color: #555; }
    & :is(.plate-head, .plate figcaption, .plate-head b, .plate time) { border-color: #edf2f7; }
    & :is(.plate-head b, .plate small, .plate .caption, .pricing-panel .eyebrow, .pricing-action p, .pricing-action small) { color: white; }
    & .plate figcaption a { background: #036; color: white; border-color: white; }
    & .pricing-panel { --accent: #036; }
    & .pricing-panel .button { border-color: white; }
    & .pricing-panel .index b, & .foot nav a:last-child { background: var(--selected); color: #036; border-color: #036; }
    & :is(.plate-head, .plate-head div, .plate figcaption, .register-head, .register-foot) { height: auto; min-height: 2.75rem; flex-wrap: wrap; }
    & :is(.desk-header nav, .desk-scan-row, .topbar, .panel-header, .page-heading, .check-actions) { flex-wrap: wrap; }
    & :is(fieldset, .main-shell, .panel, .modal, .desk-field) { min-inline-size: 0; }
    & :is(a, button, input, select, textarea, summary, [tabindex], :target) { scroll-margin-block: 1rem; }
    & .topbar { position: static; }
    & :focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; box-shadow: 0 0 0 2px white; }
    & :is(.table-wrap, .modal-body, .contents a, .tabs a, .plate figcaption a):focus-visible { outline-offset: -4px; }
    & .plate figcaption a:focus-visible { outline-color: white; }

    @media (max-width: 50em) {
      & .mobile-nav { position: static; grid-template-columns: repeat(auto-fit, minmax(min(100%, 6rem), 1fr)); }
      & .mobile-nav a { font-size: .875rem; }
      & .auth-entry .auth-intro { display: block; }
    }
    @media (max-width: 36em) {
      & :is(.plan-row, .desk-field, .module-grid, .stats-row, .bundle-preview fieldset, .steps.hire-steps, .radio-check-results .field) { grid-template-columns: minmax(0, 1fr); }
      & .plan-row > .field:nth-child(4) { grid-column: auto; }
      & .head-inner { display: flex; flex-wrap: wrap; }
      & #company-site-add { white-space: normal; }
    }
    @media (max-height: 34em), (max-width: 36em) {
      & .modal { display: block; overflow: auto; max-height: calc(100dvh - 2rem); }
      & .modal-body { overflow: visible; }
    }
  }
}

/* Selecting Accessibility also removes nonessential motion without requiring
   the person to change their operating-system preference. */
@media screen {
  html:root[data-theme=accessibility], html:root[data-theme=accessibility] *,
  html:root[data-theme=accessibility] ::before, html:root[data-theme=accessibility] ::after {
    animation: none !important; transition: none !important; scroll-behavior: auto !important;
  }
}
@media print {
  svg[data-interface-icon], path[data-interface-replacement], [data-appearance-fallback] { display: none !important; }
}
@media screen and (forced-colors: active) {
  html:root { --switch-face: Canvas; --switch-text: CanvasText; --switch-edge: ButtonText; --switch-focus: Highlight; }
  html:root[data-theme=accessibility] {
    --focus: Highlight; --paper: Canvas; --body: CanvasText;
    & .plate { forced-color-adjust: auto; }
    & :is(button, select, .button, .pill, .status-chip) { border-color: ButtonText; }
    & :is(.plate figcaption a, a, button, input, select, textarea, summary, [tabindex]):focus-visible { outline-color: Highlight; }
  }
}
