/**
 * Fit Quiz - Storefront Styles
 * Optimized for Native Theme Inheritance
 * Uses :where() for visuals, but STRONG selectors for layout to prevent glitches.
 */

/* ============================================
   LAYOUT & STRUCTURE (Keep these)
   ============================================ */

/* Container - padding keeps form field edges from being clipped by theme/section */
:where(.fq) {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
  box-sizing: border-box;
  overflow: visible;
}

/* Header */
:where(.fq__header) {
  margin-bottom: 1.5rem;
}

:where(.fq__title) {
  margin: 0 0 0.5rem;
  /* Font size/weight inherited from .h1 class */
}

:where(.fq__description) {
  margin: 0;
  /* Color/font inherited from .rte class */
}

/* ============================================
   PROGRESS BAR (Custom Component - Keep Styles)
   ============================================ */
:where(.fq__progress) {
  margin-bottom: 2rem;
}

:where(.fq__progress-bar) {
  height: 6px;
  /* Use semi-transparent foreground for track */
  background: color-mix(in srgb, var(--color-foreground) 25%, transparent);
  border-radius: 3px;
  overflow: hidden;
}

:where(.fq__progress-fill) {
  height: 100%;
  /* Use foreground (text) color for fill */
  background: var(--color-foreground);
  border-radius: 3px;
  transition: width 250ms ease;
  will-change: width;
}

:where(.fq__progress-text) {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: rgba(var(--color-foreground), 0.6);
}

/* ============================================
   STEPS & ANIMATION
   ============================================ */
:where(.fq__step) {
  animation: fq-slide-in 350ms ease-out forwards;
  overflow: visible;
}

:where(.fq__step--reverse) {
  animation: fq-slide-in-reverse 350ms ease-out forwards;
}

@keyframes fq-slide-in {
  from {
    opacity: 0;
    transform: translateX(16px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fq-slide-in-reverse {
  from {
    opacity: 0;
    transform: translateX(-16px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

:where(.fq__step-header) {
  margin-bottom: 1.5rem;
}

:where(.fq__step-title) {
  margin: 0 0 0.25rem;
  /* Font size/weight inherited from .h2 class */
}

:where(.fq__step-title:focus) {
  outline: none;
}

:where(.fq__step-description) {
  margin: 0;
}

/* ============================================
   QUESTIONS LAYOUT
   ============================================ */
:where(.fq__questions) {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

:where(.fq__question) {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Error Shake Animation */
:where(.fq__question--error) {
  animation: fq-shake 0.4s ease;
}

@keyframes fq-shake {

  0%,
  100% {
    transform: translateX(0);
  }

  20%,
  60% {
    transform: translateX(-4px);
  }

  40%,
  80% {
    transform: translateX(4px);
  }
}

/* Labels (when not using .field__label) */
:where(.fq__label) {
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.9375rem;
}

:where(.fq__required) {
  color: #dc2626;
  font-weight: 600;
}

:where(.fq__help-text) {
  font-size: 0.8125rem;
  color: rgba(var(--color-foreground), 0.6);
  margin: -0.25rem 0 0;
}

:where(.fq__error) {
  color: #dc2626;
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.25rem;
}

/* ============================================
   ROBUST LAYOUT FIXES (Strong Selectors)
   ============================================ */
/* 
   We use STRONG selectors (no :where) here to ENFORCE correct layout
   and prevent overlapping text, even if the theme's JS/CSS is missing.
*/

.fq .field {
  position: relative;
  width: 100%;
  display: flex;
}

/* Allow fields containing selects to size to content */
.fq .field:has(.select) {
  width: auto;
  max-width: 100%;
}

.fq .field__input {
  width: 100%;
  flex-grow: 1;
  text-align: left;
  /* Inherit padding/height from theme's .field__input */
  appearance: none;
  -webkit-appearance: none;
}

.fq .select__select {
  width: auto;
  min-width: 200px;
  flex-grow: 0;
  text-align: left;
  padding-right: 3rem !important;
  cursor: pointer;
  /* Inherit padding/height from theme's .field__input */
  appearance: none;
  -webkit-appearance: none;
  /* Re-add arrow if theme removed it */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8.825L1.175 4 2.233 2.942 6 6.708l3.767-3.766L10.825 4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1.5rem center;
  background-size: 12px;
  background-color: var(--color-input-background);
  /* User requested override */
}

/* Ensure textareas have height */
.fq .fq__textarea {
  min-height: 120px;
  resize: vertical;
}

/* Select Arrow (Native Fallback) */
.fq .select {
  position: relative;
  width: auto;
  max-width: 100%;
}


/* ============================================
   RADIO & CHECKBOX OPTIONS (Custom UI)
   ============================================ */
:where(.fq__options) {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

:where(.fq__option) {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;

  /* Keep basic structure but use theme vars for colors if possible */
  background: rgb(var(--color-base-background-1));
  border: 1px solid rgba(var(--color-foreground), 0.15);
  border-radius: 4px;
  /* Default fallback */

  cursor: pointer;
  transition: all 150ms ease;
  user-select: none;
}

:where(.fq__option:hover) {
  border-color: rgba(var(--color-foreground), 0.3);
}

:where(.fq__option--selected) {
  border-color: rgb(var(--color-button));
  background: rgba(var(--color-button), 0.05);
}

:where(.fq__option input) {
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  accent-color: rgb(var(--color-button));
}

/* ============================================
   BOOT SELECTOR
   ============================================ */
:where(.fq__boot-selector) {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ============================================
   NAVIGATION
   ============================================ */
:where(.fq__nav) {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2rem;
  gap: 1rem;
}

/* Loading state for button */
:where(.fq__btn--loading) {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

:where(.fq__btn--loading::after) {
  content: '';
  position: absolute;
  width: 1rem;
  height: 1rem;
  top: 50%;
  left: 50%;
  margin: -0.5rem 0 0 -0.5rem;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: fq-spin 0.6s linear infinite;
}

@keyframes fq-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   RESULTS
   ============================================ */
:where(.fq__results) {
  animation: fq-fade-in 350ms ease-out forwards;
}

@keyframes fq-fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

:where(.fq__results-header) {
  text-align: center;
  margin-bottom: 2rem;
}

:where(.fq__recommendations) {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

:where(.fq__recommendation) {
  display: flex;
  gap: 1.25rem;
  padding: 1.25rem;
  background: rgb(var(--color-base-background-1));
  border: 1px solid rgba(var(--color-foreground), 0.1);
  border-radius: 8px;
  position: relative;
}

:where(.fq__recommendation--top) {
  border-color: rgb(var(--color-button));
  box-shadow: 0 4px 16px rgba(var(--color-button), 0.15);
}

:where(.fq__recommendation-badge) {
  position: absolute;
  top: -0.625rem;
  left: 1rem;
  padding: 0.25rem 0.75rem;
  background: rgb(var(--color-button));
  color: rgb(var(--color-button-text));
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 4px;
}

:where(.fq__recommendation-image) {
  width: 100px;
  height: 100px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: rgba(var(--color-foreground), 0.05);
}

:where(.fq__recommendation-content) {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

:where(.fq__recommendation-title) {
  margin: 0;
  /* Font inherited from .h3 */
}

:where(.fq__recommendation-price) {
  font-weight: 600;
  color: rgb(var(--color-button));
}

:where(.fq__recommendation-stock) {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  margin-top: 0.25rem;
}

:where(.fq__recommendation-stock--out) {
  background-color: rgba(var(--color-foreground), 0.1);
  color: rgba(var(--color-foreground), 0.7);
}

:where(.fq__recommendation-ai) {
  font-size: 0.8125rem;
  color: rgba(var(--color-foreground), 0.8);
  background: rgba(var(--color-foreground), 0.03);
  padding: 0.75rem;
  border-radius: 6px;
  line-height: 1.5;
}

:where(.fq__recommendation-actions) {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: auto;
  padding-top: 0.5rem;
}

:where(.fq__results-actions) {
  display: flex;
  justify-content: center;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(var(--color-foreground), 0.1);
}

/* ============================================
   MODAL
   ============================================ */
:where(.fq-modal) {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 250ms ease, visibility 250ms ease;
  backdrop-filter: blur(4px);
}

:where(.fq-modal--open) {
  opacity: 1;
  visibility: visible;
}

:where(.fq-modal__content) {
  position: relative;
  width: 100%;
  max-width: 720px;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  background: rgb(var(--color-base-background-1));
  border-radius: 12px;
  transform: translateY(16px) scale(0.98);
  transition: transform 250ms ease;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2);
}

:where(.fq-modal--open .fq-modal__content) {
  transform: translateY(0) scale(1);
}

:where(.fq-modal__header) {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.75rem 1rem;
  background: inherit;
  border-bottom: 1px solid rgba(var(--color-foreground), 0.1);
  z-index: 1;
}

:where(.fq-modal__close) {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  background: rgba(var(--color-foreground), 0.05);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: rgb(var(--color-foreground));
  transition: background 150ms ease;
}

:where(.fq-modal__close:hover) {
  background: rgba(var(--color-foreground), 0.1);
}

:where(.fq-modal__body) {
  padding: 1.5rem;
}

/* Step CTA (button below questions) */
:where(.fq__step-cta) {
  margin-top: 1rem;
}

/* Step info modal (CTA opens this) */
:where(.fq-step-modal) {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 250ms ease, visibility 250ms ease;
}

:where(.fq-step-modal__backdrop) {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

:where(.fq-step-modal--open) {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

:where(.fq-step-modal__content) {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  background: rgb(var(--color-base-background-1));
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2);
}

:where(.fq-step-modal__header) {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(var(--color-foreground), 0.1);
}

:where(.fq-step-modal__close) {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  background: rgba(var(--color-foreground), 0.05);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: rgb(var(--color-foreground));
}

:where(.fq-step-modal__close:hover) {
  background: rgba(var(--color-foreground), 0.1);
}

:where(.fq-step-modal__body) {
  padding: 1.5rem;
}

:where(.fq-step-modal__video) {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%;
  margin-bottom: 1rem;
}

:where(.fq-step-modal__video iframe) {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

:where(.fq-step-modal__rte) {
  line-height: 1.6;
}

:where(.fq-step-modal__rte p) {
  margin: 0 0 0.75rem;
}

:where(.fq-step-modal__rte p:last-child) {
  margin-bottom: 0;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media screen and (max-width: 749px) {
  :where(.fq__recommendation) {
    flex-direction: column;
  }

  :where(.fq__recommendation-image) {
    width: 100%;
    height: 180px;
  }

  :where(.fq__nav) {
    flex-direction: column-reverse;
  }
}