/**
 * wh_wcag widget + WCAG 2.2 page modes.
 *
 * Brand values come from var(--wh-*) tokens with fallbacks. High contrast
 * palettes are fixed a11y values (not brand), overridable via --wh-wcag-*.
 * Widget internals use px: the widget itself scales the root font size.
 */

.wh-wcag {
  /* Local tokens; admin overrides arrive inline on this element (style="...")
     and inline wins over this class definition */
  --wh-wcag-primary: var(--wh-color-primary, #0049ff);
  --wh-wcag-primary-soft: var(--wh-wcag-primary-soft-base, #eef3ff);
  --wh-wcag-zoom: 1;
  --wh-wcag-text: var(--wh-color-text-primary, #1a1a1a);
  --wh-wcag-bg: var(--wh-color-bg, #ffffff);
  --wh-wcag-body-bg: var(--wh-wcag-body-bg-base, #f3f5f8);
  --wh-wcag-border: var(--wh-wcag-border-color, #e2e6ec);
  --wh-wcag-muted: var(--wh-wcag-muted-color, #5f6875);
  --wh-wcag-font: var(--wh-font-body, sans-serif);
  --wh-wcag-radius: var(--wh-wcag-radius-base, 16px);
  --wh-wcag-radius-tile: var(--wh-wcag-radius-tile-base, 12px);
  --wh-wcag-shadow: var(--wh-wcag-shadow-base, 0 12px 40px rgba(9, 17, 51, 0.22));
  --wh-wcag-z-filter: var(--wh-wcag-z-filter-base, 2147483000);
  --wh-wcag-z-widget: var(--wh-wcag-z-widget-base, 2147483600);
  font-family: var(--wh-wcag-font);
}
/* Derive the soft shade from the primary so admin custom colors propagate */
@supports (background: color-mix(in srgb, red 10%, white)) {
  .wh-wcag {
    --wh-wcag-primary-soft: color-mix(in srgb, var(--wh-wcag-primary) 10%, #ffffff);
  }
}

.wh-wcag__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Floating toggle button ===== */

.wh-wcag__toggle {
  position: fixed;
  bottom: 24px;
  z-index: var(--wh-wcag-z-widget);
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--wh-wcag-toggle-size, 56px);
  height: var(--wh-wcag-toggle-size, 56px);
  padding: 0;
  border: 2px solid var(--wh-wcag-bg);
  border-radius: 50%;
  background: var(--wh-wcag-primary);
  color: var(--wh-wcag-toggle-icon, var(--wh-color-text-inverse, #ffffff));
  box-shadow: var(--wh-wcag-shadow);
  cursor: pointer;
  transition: transform var(--wh-duration-fast, 150ms) ease;
  /* Widget zoom uses CSS zoom (reflow, box stays inside the viewport).
     transform: scale pushed the full width mobile sheet off screen. */
  zoom: var(--wh-wcag-zoom, 1);
}
.wh-wcag__toggle svg {
  width: calc(var(--wh-wcag-toggle-size, 56px) * 0.54);
  height: calc(var(--wh-wcag-toggle-size, 56px) * 0.54);
}
.wh-wcag--right .wh-wcag__toggle { right: 24px; }
.wh-wcag--left .wh-wcag__toggle { left: 24px; }
@media (hover: hover) {
.wh-wcag__toggle:hover { transform: scale(1.07); }
}

.wh-wcag__toggle:focus-visible,
.wh-wcag__close:focus-visible,
.wh-wcag__tile:focus-visible,
.wh-wcag__profile:focus-visible,
.wh-wcag__reset:focus-visible,
.wh-wcag__statement:focus-visible {
  outline: 3px solid var(--wh-wcag-focus-ring, #d90368);
  outline-offset: 2px;
}

/* ===== Panel ===== */

.wh-wcag__panel {
  position: fixed;
  bottom: 92px;
  z-index: var(--wh-wcag-z-widget);
  width: 392px;
  max-width: calc(100vw - 32px);
  /* Divide by zoom so the rendered height stays constant when zoomed */
  max-height: calc(min(78vh, 640px) / var(--wh-wcag-zoom, 1));
  zoom: var(--wh-wcag-zoom, 1);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--wh-wcag-border);
  border-radius: var(--wh-wcag-radius);
  background: var(--wh-wcag-body-bg);
  color: var(--wh-wcag-text);
  box-shadow: var(--wh-wcag-shadow);
  font-size: 14px;
  line-height: 1.4;
  overflow: hidden;
}
.wh-wcag--right .wh-wcag__panel { right: 24px; transform-origin: bottom right; }
.wh-wcag--left .wh-wcag__panel { left: 24px; transform-origin: bottom left; }
.wh-wcag__panel:not([hidden]) { animation: wh-wcag-pop var(--wh-duration-fast, 150ms) ease-out; }
@keyframes wh-wcag-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .wh-wcag__panel:not([hidden]) { animation: none; }
  .wh-wcag__toggle { transition: none; }
}

.wh-wcag__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 18px;
  background: var(--wh-wcag-primary);
  color: var(--wh-wcag-head-text, var(--wh-color-text-inverse, #ffffff));
}
.wh-wcag__title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  font-family: var(--wh-font-heading, var(--wh-wcag-font));
}
.wh-wcag__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--wh-wcag-head-btn, rgba(255, 255, 255, 0.16));
  color: inherit;
  cursor: pointer;
}
@media (hover: hover) {
.wh-wcag__close:hover { background: var(--wh-wcag-head-btn-hover, rgba(255, 255, 255, 0.3)); }
}

.wh-wcag__body {
  overflow-y: auto;
  padding: 6px 14px 14px;
}

.wh-wcag__section-title {
  margin: 12px 4px 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--wh-wcag-muted);
  font-family: inherit;
}

/* ===== Zoom switch row ===== */

.wh-wcag__switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  margin-top: 12px;
  padding: 8px 14px;
  border: 2px solid var(--wh-wcag-border);
  border-radius: var(--wh-wcag-radius-tile);
  background: var(--wh-wcag-bg);
}
.wh-wcag__switch-label { font-size: 13px; font-weight: 600; }
.wh-wcag__switch {
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--wh-wcag-border);
  cursor: pointer;
  transition: background-color var(--wh-duration-fast, 150ms) ease;
}
.wh-wcag__switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--wh-wcag-bg);
  box-shadow: var(--wh-wcag-knob-shadow, 0 1px 3px rgba(0, 0, 0, 0.25));
  transition: transform var(--wh-duration-fast, 150ms) ease;
}
.wh-wcag__switch[aria-checked="true"] { background: var(--wh-wcag-primary); }
.wh-wcag__switch[aria-checked="true"] .wh-wcag__switch-knob { transform: translateX(20px); }
.wh-wcag__switch:focus-visible {
  outline: 3px solid var(--wh-wcag-focus-ring, #d90368);
  outline-offset: 2px;
}

/* ===== Profile presets (2 column grid) ===== */

.wh-wcag__profiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.wh-wcag__profile {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 12px;
  border: 2px solid var(--wh-wcag-border);
  border-radius: var(--wh-wcag-radius-tile);
  background: var(--wh-wcag-bg);
  color: var(--wh-wcag-text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--wh-duration-fast, 150ms) ease, background-color var(--wh-duration-fast, 150ms) ease;
}
@media (hover: hover) {
.wh-wcag__profile:hover { border-color: var(--wh-wcag-primary); }
}
.wh-wcag__profile-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--wh-wcag-primary-soft);
  color: var(--wh-wcag-primary);
}
.wh-wcag__profile-label { flex: 1 1 auto; line-height: 1.2; }
.wh-wcag__profile[aria-pressed="true"] {
  border-color: var(--wh-wcag-primary);
  background: var(--wh-wcag-primary);
  color: var(--wh-wcag-head-text, var(--wh-color-text-inverse, #ffffff));
}
.wh-wcag__profile[aria-pressed="true"] .wh-wcag__profile-icon {
  background: var(--wh-wcag-head-btn, rgba(255, 255, 255, 0.18));
  color: inherit;
}

/* Check badge shared by profiles and tiles */
.wh-wcag__check {
  position: absolute;
  top: 6px;
  right: 6px;
  display: none;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--wh-wcag-primary);
  color: var(--wh-wcag-head-text, var(--wh-color-text-inverse, #ffffff));
}
[aria-pressed="true"] > .wh-wcag__check { display: flex; }
.wh-wcag__profile[aria-pressed="true"] .wh-wcag__check {
  background: var(--wh-wcag-head-text, var(--wh-color-text-inverse, #ffffff));
  color: var(--wh-wcag-primary);
}

/* ===== Feature tiles (3 column grid) ===== */

.wh-wcag__tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.wh-wcag__tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 96px;
  padding: 14px 8px 12px;
  border: 2px solid var(--wh-wcag-border);
  border-radius: var(--wh-wcag-radius-tile);
  background: var(--wh-wcag-bg);
  color: var(--wh-wcag-text);
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--wh-duration-fast, 150ms) ease, transform var(--wh-duration-fast, 150ms) ease;
}
@media (hover: hover) {
.wh-wcag__tile:hover { border-color: var(--wh-wcag-primary); transform: translateY(-1px); }
}
.wh-wcag__tile[aria-pressed="true"] {
  border-color: var(--wh-wcag-primary);
  background: var(--wh-wcag-primary-soft);
}
.wh-wcag__tile-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  color: var(--wh-wcag-text);
}
.wh-wcag__tile[aria-pressed="true"] .wh-wcag__tile-icon,
.wh-wcag__tile[aria-pressed="true"] .wh-wcag__tile-label { color: var(--wh-wcag-primary); }
.wh-wcag__tile-glyph {
  font-size: 21px;
  font-weight: 800;
  font-family: var(--wh-font-heading, var(--wh-wcag-font));
  letter-spacing: 0.02em;
}
.wh-wcag__tile-label {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
}

/* Progress dots on multi level tiles */
.wh-wcag__dots { display: flex; gap: 4px; }
.wh-wcag__dots i {
  width: 16px;
  height: 3px;
  border-radius: 2px;
  background: var(--wh-wcag-border);
  transition: background-color var(--wh-duration-fast, 150ms) ease;
}
.wh-wcag__dots i.is-on { background: var(--wh-wcag-primary); }

/* ===== Footer ===== */

.wh-wcag__foot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--wh-wcag-border);
  background: var(--wh-wcag-bg);
}
.wh-wcag__reset {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--wh-wcag-border);
  border-radius: 10px;
  background: var(--wh-wcag-bg);
  color: var(--wh-wcag-text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}
/* Inline SVG has baseline descent, block display keeps it aligned with text */
.wh-wcag__reset svg { display: block; flex: 0 0 auto; }
@media (hover: hover) {
.wh-wcag__reset:hover { border-color: var(--wh-wcag-primary); color: var(--wh-wcag-primary); }
}

/* Statement link always in the primary color, theme pseudo class selectors
   have higher specificity, hence the reinforced selectors */
.wh-wcag .wh-wcag__statement,
.wh-wcag .wh-wcag__statement:visited {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--wh-wcag-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.wh-wcag .wh-wcag__statement:focus,
.wh-wcag .wh-wcag__statement:active {
  color: var(--wh-wcag-primary);
  text-decoration-thickness: 2px;
}
@media (hover: hover) {
.wh-wcag .wh-wcag__statement:hover {
  color: var(--wh-wcag-primary);
  text-decoration-thickness: 2px;
}
}

@media (max-width: 767px) {
  .wh-wcag--hide-mobile { display: none; }
}
@media (max-width: 576px) {
  /* Bottom sheet; zoom still works (CSS zoom reflows inside the full width) */
  .wh-wcag--right .wh-wcag__panel,
  .wh-wcag--left .wh-wcag__panel {
    left: 8px;
    right: 8px;
    bottom: 88px;
    width: auto;
    max-width: none;
    max-height: calc(72vh / var(--wh-wcag-zoom, 1));
  }
}
@media print {
  .wh-wcag, .wh-wcag-skiplink { display: none !important; }
}

/* ===== Skip link (WCAG 2.4.1), visible on focus only ===== */

.wh-wcag-skiplink {
  position: absolute;
  top: -1000px;
  left: 8px;
  z-index: var(--wh-wcag-z-widget-base, 2147483600);
  padding: 12px 20px;
  border-radius: 0 0 8px 8px;
  background: var(--wh-color-primary, #0049ff);
  color: var(--wh-wcag-toggle-icon, var(--wh-color-text-inverse, #ffffff));
  font-size: 16px;
  text-decoration: none;
}
.wh-wcag-skiplink:focus {
  top: 0;
  outline: 3px solid var(--wh-wcag-focus-ring, #d90368);
  outline-offset: 2px;
}

/* ===== Visible focus (WCAG 2.4.7 / 2.4.11 / 2.4.13) =====
   wcag-focus-site: admin option (whole shop), wcag-focus: user toggle */

html.wcag-focus-site :is(a, button, input, select, textarea, summary, [tabindex]):focus-visible,
html.wcag-focus :is(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--wh-wcag-focus-ring, #d90368) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 6px var(--wh-wcag-focus-halo, rgba(255, 255, 255, 0.85)) !important;
}

/* Text size has no CSS: JS measures the real root font size after load
   and sets an inline style (no 62.5% vs 100% assumptions) */

/* ===== Grayscale / invert =====
   backdrop-filter overlay above content, below the widget. A filter on
   <html> would become a containing block and break position: fixed. */

.wh-wcag__filter {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--wh-wcag-z-filter);
  pointer-events: none;
}
html.wcag-grayscale .wh-wcag__filter,
html.wcag-invert .wh-wcag__filter { display: block; }
html.wcag-grayscale .wh-wcag__filter {
  -webkit-backdrop-filter: grayscale(1);
  backdrop-filter: grayscale(1);
}
html.wcag-invert .wh-wcag__filter {
  -webkit-backdrop-filter: invert(1) hue-rotate(180deg);
  backdrop-filter: invert(1) hue-rotate(180deg);
}
html.wcag-invert.wcag-grayscale .wh-wcag__filter {
  -webkit-backdrop-filter: grayscale(1) invert(1);
  backdrop-filter: grayscale(1) invert(1);
}
/* No backdrop-filter: fall back to a filter on <html> (known fixed quirk) */
@supports not ((backdrop-filter: invert(1)) or (-webkit-backdrop-filter: invert(1))) {
  .wh-wcag__filter { display: none !important; }
  html.wcag-grayscale { filter: grayscale(1); }
  html.wcag-invert { filter: invert(1) hue-rotate(180deg); }
  html.wcag-invert.wcag-grayscale { filter: grayscale(1) invert(1); }
}

/* ===== High contrast modes (WCAG 1.4.3 / 1.4.6) =====
   Fixed a11y palette, media elements and the widget stay untouched */

/* ⚠️ MUST come before the palette rules below.
   Themes animate `color` (Hummingbird/Fashion: `transition: color .15s`).
   When the contrast class is added, such elements keep rendering their OLD
   colour, so forced-black backgrounds end up with the theme's original text
   colour on top: measured 1.79:1 (brand brown #40362e on #000) — far below
   the 4.5:1 required by 1.4.3, i.e. the accessibility feature made contrast
   WORSE than before.
   Killing transitions/animations makes the override land immediately and is
   correct for a high-contrast mode anyway (nothing here should animate).
   Verified on the Fashion demo: elements below threshold 16 -> 0. */
html.wcag-contrast-dark body *,
html.wcag-contrast-light body * {
  transition: none !important;
  animation: none !important;
}

html.wcag-contrast-dark body,
html.wcag-contrast-dark body :not(img):not(svg):not(svg *):not(video):not(iframe):not(picture):not(canvas):not(embed):not(object):not(.wh-wcag):not(.wh-wcag *) {
  background-color: var(--wh-wcag-hc-dark-bg, #000000) !important;
  background-image: none !important;
  color: var(--wh-wcag-hc-dark-text, #ffff00) !important;
  border-color: var(--wh-wcag-hc-dark-text, #ffff00) !important;
  text-shadow: none !important;
  box-shadow: none !important;
}
html.wcag-contrast-dark body a:not(.wh-wcag *),
html.wcag-contrast-dark body a:not(.wh-wcag *) * {
  color: var(--wh-wcag-hc-dark-link, #00ffff) !important;
  text-decoration: underline !important;
}

html.wcag-contrast-light body,
html.wcag-contrast-light body :not(img):not(svg):not(svg *):not(video):not(iframe):not(picture):not(canvas):not(embed):not(object):not(.wh-wcag):not(.wh-wcag *) {
  background-color: var(--wh-wcag-hc-light-bg, #ffffff) !important;
  background-image: none !important;
  color: var(--wh-wcag-hc-light-text, #000000) !important;
  border-color: var(--wh-wcag-hc-light-text, #000000) !important;
  text-shadow: none !important;
  box-shadow: none !important;
}
html.wcag-contrast-light body a:not(.wh-wcag *),
html.wcag-contrast-light body a:not(.wh-wcag *) * {
  color: var(--wh-wcag-hc-light-link, #0000ee) !important;
  text-decoration: underline !important;
}

/* ===== Link underlining (WCAG 1.4.1) ===== */

html.wcag-links body a:not(.wh-wcag *) {
  text-decoration: underline !important;
  text-decoration-thickness: 2px !important;
  text-underline-offset: 2px !important;
}

/* ===== Readable font =====
   Icon fonts excluded, otherwise ligatures would render as plain text */

html.wcag-readable body,
html.wcag-readable body *:not(.material-icons):not(.material-symbols-outlined):not([class^="icon-"]):not([class*=" icon-"]):not(.fa):not([class^="fa-"]):not([class*=" fa-"]):not(.wh-wcag *) {
  font-family: var(--wh-wcag-readable-font, Arial, Helvetica, Verdana, sans-serif) !important;
  font-style: normal !important;
}

/* ===== Text spacing (WCAG 1.4.12) ===== */

html.wcag-spacing body *:not(.wh-wcag *) {
  line-height: 1.6 !important;
  letter-spacing: 0.12em !important;
  word-spacing: 0.16em !important;
}
html.wcag-spacing body p { margin-bottom: 2em !important; }

/* ===== Stop animations (WCAG 2.2.2 / 2.3.3) =====
   0.001s instead of none, some scripts wait for animationend */

html.wcag-motion *,
html.wcag-motion *::before,
html.wcag-motion *::after {
  animation-duration: 0.001s !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001s !important;
  transition-delay: 0s !important;
  scroll-behavior: auto !important;
}

/* ===== Big cursor ===== */

html.wcag-cursor,
html.wcag-cursor body *,
html.wcag-cursor body a,
html.wcag-cursor body button {
  cursor: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44' viewBox='0 0 24 24'%3E%3Cpath d='M5.5 3.2v17.6c0 .45.54.67.85.35l4.86-4.86a.5.5 0 0 1 .35-.15h6.87c.45 0 .67-.54.35-.85L6.35 2.85a.5.5 0 0 0-.85.35z' fill='%23000' stroke='%23fff' stroke-width='1.2'/%3E%3C/svg%3E") 4 3, auto !important;
}

/* ===== Screen reader highlight ===== */

.wh-wcag-reading {
  outline: 3px solid var(--wh-wcag-reader-ring, var(--wh-color-primary, #0049ff)) !important;
  outline-offset: 2px !important;
  background: var(--wh-wcag-reader-bg, rgba(255, 214, 0, 0.3)) !important;
}

/* ===== Reading guide ===== */

.wh-wcag__guide {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  top: 40vh;
  height: 12px;
  z-index: var(--wh-wcag-z-filter);
  pointer-events: none;
  background: var(--wh-wcag-guide-color, rgba(255, 214, 0, 0.55));
  border-top: 1px solid var(--wh-wcag-guide-border, rgba(0, 0, 0, 0.6));
  border-bottom: 1px solid var(--wh-wcag-guide-border, rgba(0, 0, 0, 0.6));
}
html.wcag-guide .wh-wcag__guide { display: block; }
