/*
 * Reusable primitives: Button, Text link, Icon button, Form field, Select, Checkbox,
 * Radio, Badge, Price, Rating, Quantity selector, Accordion, Skeleton loader.
 * States implemented per states-spec.md / DESIGN_RULES.md §6,§10. Touch targets 44x44px
 * minimum per accessibility-spec.md. All values from tokens.css — see DESIGN_RULES.md §1.
 */

/* ================= Button ================= */
/**
 * Component: Button (.btn)
 * Purpose: primary CTA — Add to Cart, Place Order, etc. Rebuilt 2026-07-22 to match the
 * repeated source exactly: 13px text, 0.03em tracking, regular weight (source shows no
 * explicit font-weight on any primary button — inherits normal body weight), uniform 14px
 * padding. A second variant, .btn--outline, exists per the Homepage hero CTA — the
 * DESIGN_RULES §6 "no secondary/outline variant" statement was incorrect and is corrected.
 * States: default, hover, active, focus, disabled, loading (.is-loading), success (label swap via JS).
 * A11y: real <button>/<a>, visible focus ring, disabled uses [disabled] or aria-disabled,
 * min-height:44px preserved regardless of the lighter visual padding.
 */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-btn-padding);
  background: var(--color-action-primary);
  color: var(--color-text-on-accent);
  border: none;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-weight: var(--font-weight-body);
  font-size: var(--font-size-button);
  letter-spacing: var(--letter-spacing-button);
  cursor: pointer;
  transition: background var(--animation-duration) var(--animation-easing);
}
.btn:hover { background: var(--color-background-accent-hover); }
.btn:active { background: var(--color-background-accent-active); transform: scale(0.98); }
.btn:disabled, .btn[aria-disabled="true"] {
  background: var(--color-action-primary-disabled);
  color: var(--color-text-muted);
  cursor: not-allowed;
}
.btn.is-loading { pointer-events: none; }
.btn.is-loading .btn__label { visibility: hidden; }
.btn__spinner { display: none; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; }
.btn.is-loading .btn__spinner { display: block; animation: gb-spin 800ms linear infinite; }
.btn--full { width: 100%; }

/**
 * Component: Button — outline variant (.btn--outline)
 * Purpose: secondary CTA (e.g. "Відкрити колекцію"). Explicit request (button-system
 * unification pass): one shared text treatment across primary/secondary — same font-size/
 * letter-spacing/casing as .btn, sentence case (never uppercase) — outline vs. filled is the
 * only visual distinction between the two types now. Radius inherits .btn's --radius-pill.
 */
.btn--outline {
  background: transparent;
  border: 1px solid var(--color-text-primary);
  color: var(--color-text-primary);
  padding: var(--space-btn-outline-padding-y) var(--space-7);
}
.btn--outline:hover { background: color-mix(in srgb, var(--color-text-primary) 6%, transparent); }
.btn--outline:active { background: color-mix(in srgb, var(--color-text-primary) 10%, transparent); transform: scale(0.98); }
.btn--outline:disabled, .btn--outline[aria-disabled="true"] {
  border-color: var(--color-action-primary-disabled);
  color: var(--color-text-muted);
  background: transparent;
}

/* ================= Icon button ================= */
/**
 * Component: Icon button (.icon-btn)
 * Purpose: search / cart / close / hamburger / qty +− triggers.
 * States: default, hover (tint), active, focus, disabled (40% opacity).
 */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: transparent;
  border: none;
  border-radius: var(--radius-small);
  color: var(--color-text-primary);
  cursor: pointer;
  transition: background var(--animation-duration) var(--animation-easing);
}
.icon-btn:hover { background: color-mix(in srgb, var(--color-text-primary) 7%, transparent); }
.icon-btn:active { background: color-mix(in srgb, var(--color-text-primary) 12%, transparent); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
/* Glyph reduced 18px→16px (~11%) for a lighter feel; the 44x44 hit box above is untouched
   so the tappable area still meets the 44px accessibility floor — visual polish pass 2026-07-22. */
.icon-btn svg { flex: none; width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.6; }

/* ================= Text link ================= */
/**
 * Component: Text link (.link)
 * Purpose: nav items, "Дізнатись більше", footer links.
 * States: default (no underline), hover/focus (underline appears).
 */
.link {
  color: var(--color-text-primary);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--animation-duration) var(--animation-easing), color var(--animation-duration) var(--animation-easing);
}
.link:hover, .link:focus-visible { border-bottom-color: currentColor; }
.link--muted { color: var(--color-text-muted); }
.link--muted:hover { color: var(--color-text-primary); }

/* ================= Badge ================= */
/**
 * Component: Badge (.badge)
 * Purpose: status sticker — NEW, BESTSELLER (pill), SOLD OUT (illustrated).
 * Variants: .badge--new, .badge--bestseller, .badge--sold-out.
 * Never both NEW and BESTSELLER at once (DESIGN_RULES §7).
 */
.badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-body);
  font-size: var(--font-size-badge);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-label);
  font-weight: var(--font-weight-emphasis);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  line-height: 1.2;
}
.badge--new { background: var(--color-background-accent); color: var(--color-text-on-accent); }
/* BESTSELLER: source uses a golden/amber fill with DARK text, not terracotta+cream — neither
   is a tokenized color pairing (design-tokens.css has no "text-on-terracotta-dark" pair), so
   this stays on --color-accent-terracotta (the closest existing token) with dark text to match
   the source's light-background-needs-dark-text pattern. Flagged, not silently invented — see
   TODO.md; a real token should be added if this exact pairing is confirmed intentional. */
.badge--bestseller { background: var(--color-accent-terracotta); color: var(--color-text-primary); }

/* Sold-out sticker: illustrated CSS shape, intentionally NOT tokenized per DESIGN_RULES §2
   exception (asset-inventory.md: "naive tomato-shaped sticker, built from CSS shapes"). */
/* Sticker diameter reduced 64px→56px (~12%) — decorative, not a touch target, so freely
   resizable — visual polish pass 2026-07-22. */
.badge--sold-out {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #C24B2C;
  border: 2px dashed #F0C93C;
  color: #FBF8F1;
  font-size: 8px;
  text-align: center;
  padding: var(--space-2);
}
.badge--sold-out::before {
  content: '';
  position: absolute;
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 9px;
  background: #4B7A4A;
  border-radius: 0 50% 0 50%;
}

/* ================= Price ================= */
/**
 * Component: Price (.price)
 * Purpose: consistent price formatting. States: regular, on-sale, free.
 */
.price { font-family: var(--font-body); }
.price__regular { color: var(--color-text-primary); font-weight: var(--font-weight-emphasis); }
.price__regular.is-struck {
  text-decoration: line-through;
  color: var(--color-text-muted);
  font-weight: var(--font-weight-body);
  margin-right: var(--space-2);
}
.price__sale { color: var(--color-text-primary); font-weight: var(--font-weight-emphasis); }
.price__free { color: var(--color-success); font-weight: var(--font-weight-emphasis); }

/* ================= Rating ================= */
/**
 * Component: Rating (.rating)
 * Purpose: star rating + review count. Hidden entirely at 0 reviews — see inc/components.php gb_rating().
 */
.rating { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--font-size-label); color: var(--color-text-muted); }
.rating__stars { display: inline-flex; gap: 1px; color: var(--color-accent-terracotta); }
.rating__stars svg { width: 12px; height: 12px; }
.rating__stars svg.is-empty { color: var(--color-border-default); }
.rating__stars svg { fill: currentColor; stroke: none; }

/* ================= Quantity selector ================= */
/**
 * Component: Quantity selector (.qty)
 * Purpose: stepper for cart/product qty. States: default, disabled at min/max, editing.
 * Rebuilt 2026-07-22: source renders this control at 36×36px (cart drawer / PDP sticky bar),
 * below the 44px accessibility floor. Per source-priority rule #3 (accessibility remains
 * mandatory even where the visual control is smaller), the VISIBLE control stays 36×36px to
 * match the source exactly, but each button's real tappable box is invisibly expanded to
 * 44×44px via an absolutely-positioned ::before — no visual change, full 44px hit area.
 */
.qty { display: inline-flex; align-items: stretch; height: var(--qty-control-size); border: var(--border-width) solid var(--color-border-default); border-radius: var(--radius-small); }
.qty__btn {
  position: relative;
  width: var(--qty-control-size);
  height: var(--qty-control-size);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-primary);
  font-size: 14px;
  transition: background var(--animation-duration) var(--animation-easing);
}
/* Invisible 44px hit-area expansion — (44-36)/2 = 4px out on every side. */
.qty__btn::before {
  content: '';
  position: absolute;
  inset: -4px;
}
.qty__btn:hover:not(:disabled) { background: color-mix(in srgb, var(--color-text-primary) 7%, transparent); }
.qty__btn:disabled { opacity: 0.4; cursor: not-allowed; }
.qty__input {
  width: var(--qty-control-size);
  height: var(--qty-control-size);
  text-align: center;
  border: none;
  border-left: var(--border-width) solid var(--color-border-default);
  border-right: var(--border-width) solid var(--color-border-default);
  background: transparent;
  font-family: var(--font-body);
  font-size: var(--font-size-body);
  -moz-appearance: textfield;
}
.qty__input::-webkit-inner-spin-button, .qty__input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.qty__input:focus-visible { outline: none; box-shadow: inset 0 0 0 1.5px var(--color-action-primary); }

/* ================= Form field / Select / Checkbox / Radio ================= */
/**
 * Component: FormField (.field)
 * Purpose: labeled text/tel/email/textarea input with validation state.
 * States: default, focus, filled, error, disabled. See accessibility-spec.md for aria wiring.
 */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field__label { font-size: var(--font-size-label); text-transform: uppercase; letter-spacing: var(--letter-spacing-label); color: var(--color-text-muted); }
.field__required { color: var(--color-error); margin-left: 2px; }
.field__input {
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  border: var(--border-width) solid var(--color-border-default);
  border-radius: var(--radius-small);
  background: var(--color-background-surface);
  font-family: var(--font-body);
  font-size: var(--font-size-body);
  color: var(--color-text-primary);
  transition: border-color var(--animation-duration) var(--animation-easing);
}
textarea.field__input { min-height: 96px; resize: vertical; }
.field__input:focus-visible { outline: none; border-width: 1.5px; border-color: var(--color-action-primary); }
.field__input:disabled { background: color-mix(in srgb, var(--color-border-default) 40%, var(--color-background-primary)); color: var(--color-text-muted); cursor: not-allowed; }
.field.is-error .field__input { border-width: 1.5px; border-color: var(--color-error); }
.field__error { font-size: var(--font-size-label); color: var(--color-error); display: none; }
.field.is-error .field__error { display: block; }

/**
 * Component: Select (.select)
 * Purpose: native <select> styled to match FormField.
 */
.select { position: relative; display: block; }
.select::after {
  content: '';
  position: absolute;
  right: var(--space-4);
  top: 50%;
  width: 8px; height: 8px;
  border-right: 1.5px solid var(--color-text-muted);
  border-bottom: 1.5px solid var(--color-text-muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.select select.field__input { appearance: none; padding-right: var(--space-8); width: 100%; }

/**
 * Component: Checkbox / Radio (.checkbox / .radio)
 * Purpose: privacy agreement, delivery/payment method selection.
 * A11y: focus ring wraps the whole label row, not just the input (DESIGN_RULES §10).
 */
.checkbox, .radio {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  cursor: pointer;
  font-size: var(--font-size-body);
  padding: var(--space-1);
  border-radius: var(--radius-small);
}
.checkbox:focus-within, .radio:focus-within { outline: 2px solid var(--color-action-primary); outline-offset: 2px; }
.checkbox input, .radio input {
  appearance: none;
  position: relative;
  width: 18px; height: 18px;
  flex-shrink: 0;
  margin-top: 2px;
  border: var(--border-width) solid var(--color-border-default);
  background: var(--color-background-surface);
  cursor: pointer;
}
.checkbox input { border-radius: 4px; }
.radio input { border-radius: 50%; }
.checkbox input:checked, .radio input:checked { border-color: var(--color-action-primary); }
.checkbox input:checked { background: var(--color-action-primary); }
.checkbox input:checked::after {
  content: '';
  position: absolute; left: 5px; top: 2px;
  width: 5px; height: 9px;
  border: solid var(--color-text-on-accent);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.radio input:checked::after {
  content: '';
  position: absolute; inset: 4px;
  border-radius: 50%;
  background: var(--color-action-primary);
}
.checkbox.is-disabled, .radio.is-disabled { opacity: 0.4; pointer-events: none; }
.checkbox.is-error input, .radio.is-error input { border-color: var(--color-error); }

/* ================= Accordion ================= */
/**
 * Component: Accordion (.accordion)
 * Purpose: collapsible sections (scent notes, ingredients, how-to-use, FAQ).
 * Implementation: native <details>/<summary> per accessibility-spec.md preference —
 * no custom JS/animation needed for open/close state, keeps it robust with zero script.
 */
.accordion { border-bottom: var(--border-width) solid var(--color-border-default); }
.accordion > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) 0;
  min-height: 44px;
  cursor: pointer;
  list-style: none;
  font-family: var(--font-body);
  font-size: var(--font-size-body);
  color: var(--color-text-primary);
  transition: color var(--animation-duration) var(--animation-easing);
}
.accordion > summary::-webkit-details-marker { display: none; }
.accordion > summary:hover { color: var(--color-background-accent); }
.accordion > summary:focus-visible { outline: 2px solid var(--color-action-primary); outline-offset: 2px; }
.accordion__icon { font-size: 16px; line-height: 1; flex-shrink: 0; font-weight: var(--font-weight-heading); }
.accordion__icon::before { content: '+'; }
.accordion[open] > summary .accordion__icon::before { content: '\2212'; }
.accordion__panel { padding-bottom: var(--space-4); font-size: var(--font-size-body); color: var(--color-text-muted); line-height: var(--line-height-body); }

/* ================= Skeleton loader ================= */
/**
 * Component: SkeletonLoader (.skeleton)
 * Purpose: shared loading placeholder. Variants: --card, --detail, --row.
 */
.skeleton {
  background: linear-gradient(90deg, var(--color-border-default) 25%, color-mix(in srgb, var(--color-border-default) 50%, var(--color-background-surface)) 37%, var(--color-border-default) 63%);
  background-size: 400% 100%;
  animation: gb-shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-small);
}
.skeleton--card { aspect-ratio: 3 / 4; width: 100%; }
.skeleton--detail { aspect-ratio: 1 / 1; width: 100%; }
.skeleton--row { height: 16px; width: 100%; }
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

/* ================= Responsive image ================= */
/**
 * Component: ResponsiveImage (.responsive-image)
 * Purpose: aspect-ratio-locked image wrapper (product card 3/4, gallery 1/1, editorial 16/9, story 4/5).
 */
.responsive-image { position: relative; overflow: hidden; border-radius: var(--radius-medium); background: var(--color-border-default); }
.responsive-image img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.responsive-image--product { aspect-ratio: 3 / 4; }
.responsive-image--gallery { aspect-ratio: 1 / 1; }
.responsive-image--editorial { aspect-ratio: 16 / 9; }
.responsive-image--story { aspect-ratio: 4 / 5; }

/* ================= Shared keyframes ================= */
@keyframes gb-spin { to { transform: rotate(360deg); } }
@keyframes gb-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
