/*
 * happydrewienko - base layer (plugin).
 *
 * Loaded on every front-end request (see Happydrewienko\Assets), before the theme stylesheets,
 * so the theme keeps the last word. This file owns the shared component system that the theme
 * deliberately does not style: .hd-btn, .hd-card, .hd-field, .hd-note, .hd-trust, .hd-safety,
 * .hd-drawer - plus the cookie banner (contract §19).
 *
 * Colours come exclusively from the design tokens. The :root block below repeats them so the
 * plugin still renders correctly when the theme CSS is missing (another theme, a stripped
 * install, a WooCommerce page rendered outside our child theme). The theme's tokens.css loads
 * later and simply wins when it is present.
 *
 * Contrast rules honoured here: white sits on --hd-accent-dark; matte gold (--hd-buy)
 * carries the dark --hd-on-buy label on purchase buttons and selected quantity. Mobile first,
 * verified target: no horizontal overflow at 360px. Touch targets are at least 44px.
 */

/* ------------------------------------------------------------------ *
 * 1. Design tokens - fallback copy (contract §11)
 * ------------------------------------------------------------------ */

:root {
  --hd-bg: #F3F7F3;
  --hd-background: var(--hd-bg);
  --hd-photo: #E4EEE6;
  --hd-story-surface: #E4F4EB;
  --hd-story-detail-surface: #F2E8D8;
  --hd-story-line: #D8C9B2;
  --hd-surface: #FFFFFF;
  --hd-wood: #C89B6D;        /* wood: the product and its logo, not the interface */
  --hd-wood-dark: #A97C4F;
  --hd-accent: #3C5142;
  --hd-accent-dark: #3C5142;
  --hd-on-accent: #FFFFFF;
  --hd-on-accent-muted: #DDE8DA;
  --hd-accent-line: #82977D;
  --hd-buy: #C9AA54;
  --hd-on-buy: #25352A;
  --hd-buy-sheen: none;
  --hd-buy-soft: #FAF5E7;
  --hd-buy-line: #D9C58D;
  --hd-control-border: #8A9A8D;
  --hd-inactive: #F1F4F0;
  --hd-text: #25352A;
  --hd-text-muted: #52645A;
  --hd-border: #D4DED5;
  --hd-overlay: rgba(37, 53, 42, .45);
  --hd-success: #1E6B3E;
  --hd-error: #9B2C2C;
  --hd-warning: #8A5A12;
  --hd-info: #33566B;
  --hd-radius: 14px;
  --hd-radius-sm: 10px;
  --hd-radius-lg: 20px;
  --hd-shadow: 0 2px 10px rgba(37, 53, 42, .07);
  --hd-shadow-lg: 0 12px 34px rgba(37, 53, 42, .16);
  --hd-font-head: "Nunito", ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display", "Trebuchet MS", system-ui, sans-serif;
  --hd-font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --hd-maxw: 1180px;
}

/* ------------------------------------------------------------------ *
 * 2. Accessibility helpers
 * ------------------------------------------------------------------ */

/*
 * Several components below set a display value on elements that PHP toggles with the `hidden`
 * attribute (.hd-field__error, .hd-drawer, the invoice block). A class rule beats the UA
 * [hidden] rule, so the attribute is re-asserted here once for the whole plugin.
 */
[hidden] {
  display: none !important;
}

.hd-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  clip-path: inset(50%);
  border: 0;
  white-space: nowrap;
  word-wrap: normal !important;
}

/* Contract §11: 3px outline in --hd-accent-dark, 2px offset. */
:focus-visible {
  outline: 3px solid var(--hd-accent-dark);
  outline-offset: 2px;
}

.hd-btn:focus-visible,
.hd-field .hd-field__input:focus-visible,
.hd-fontpick__input:focus-visible,
.hd-drawer__panel:focus-visible,
.hd-consent:focus-visible {
  outline: 3px solid var(--hd-accent-dark);
  outline-offset: 2px;
}

/* Only hide the ring where the browser understands the modern selector. */
:focus:not(:focus-visible) {
  outline: none;
}

@media (prefers-reduced-motion: reduce) {
  .hd-btn,
  .hd-drawer,
  .hd-drawer__panel,
  .hd-consent {
    transition: none !important;
  }
}

/* ------------------------------------------------------------------ *
 * 3. Buttons
 * The theme excludes .hd-btn from its own button rules with :not(), so these
 * declarations are the only ones that apply.
 * ------------------------------------------------------------------ */

.hd-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  min-width: 44px;
  max-width: 100%;
  padding: 0.7rem 1.25rem;
  background-color: var(--hd-surface);
  color: var(--hd-accent-dark);
  border: 2px solid var(--hd-accent-dark);
  border-radius: var(--hd-radius);
  box-shadow: none;
  text-shadow: none;
  font-family: var(--hd-font-head);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  overflow-wrap: break-word;
  transition: filter 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.hd-btn:hover,
.hd-btn:focus {
  background-color: var(--hd-bg);
  color: var(--hd-accent-dark);
  text-decoration: none;
}

/* Primary: white on --hd-accent-dark passes AA (7.9:1). */
.hd-btn--primary {
  background-color: var(--hd-accent-dark);
  color: #fff;
  border-color: var(--hd-accent-dark);
}

.hd-btn--primary:hover,
.hd-btn--primary:focus {
  background-color: var(--hd-accent-dark);
  color: #fff;
  /* Darkening with a filter keeps us inside the token palette. */
  filter: brightness(0.92);
}

/*
 * Purchase: gold with the dark label (7.2:1). Printed next to .hd-btn--primary on the buttons that
 * buy - add to cart, go to the checkout, pay - and nowhere else, so gold keeps meaning "buy".
 * The sheen on top is what makes the flat gold read as gold rather than mustard.
 */
.hd-btn--buy {
  background-color: var(--hd-buy);
  background-image: var(--hd-buy-sheen);
  color: var(--hd-on-buy);
  border-color: var(--hd-buy);
}

.hd-btn--buy:hover,
.hd-btn--buy:focus {
  background-color: var(--hd-buy);
  color: var(--hd-on-buy);
  filter: brightness(0.94);
}

.hd-btn--secondary {
  background-color: var(--hd-surface);
  color: var(--hd-accent-dark);
  border-color: var(--hd-accent-dark);
}

.hd-btn--secondary:hover,
.hd-btn--secondary:focus {
  background-color: var(--hd-bg);
}

.hd-btn--ghost {
  background-color: transparent;
  color: var(--hd-accent-dark);
  border-color: transparent;
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.hd-btn--ghost:hover,
.hd-btn--ghost:focus {
  background-color: transparent;
  color: var(--hd-text);
  text-decoration: underline;
}

.hd-btn[disabled],
.hd-btn[aria-disabled="true"],
.hd-btn.disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}

.hd-btn--block {
  display: flex;
  width: 100%;
}

/* ------------------------------------------------------------------ *
 * 4. Card
 * ------------------------------------------------------------------ */

.hd-card {
  margin: 0 0 1.25rem;
  padding: 1.15rem;
  background-color: var(--hd-surface);
  border: 1px solid var(--hd-border);
  border-radius: var(--hd-radius);
  box-shadow: var(--hd-shadow);
  color: var(--hd-text);
}

.hd-card > :last-child {
  margin-bottom: 0;
}

@media (min-width: 768px) {
  .hd-card {
    padding: 1.5rem;
  }
}

/* ------------------------------------------------------------------ *
 * 5. Fields
 * Two classes (0,2,0) deliberately out-specify input[type="text"] (0,1,1), so the
 * plugin's own fields look the same with or without the theme stylesheet.
 * ------------------------------------------------------------------ */

.hd-field {
  display: block;
  margin: 0 0 1rem;
}

.hd-field__label {
  display: block;
  margin: 0 0 0.25rem;
  color: var(--hd-text);
  font-family: var(--hd-font-head);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}

.hd-field__optional {
  color: var(--hd-text-muted);
  font-family: var(--hd-font-body);
  font-size: 0.875rem;
  font-weight: 400;
}

.hd-field .hd-field__input {
  display: block;
  width: 100%;
  max-width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.75rem;
  background-color: var(--hd-surface);
  color: var(--hd-text);
  border: 1px solid var(--hd-border);
  border-radius: var(--hd-radius-sm);
  box-shadow: none;
  font-family: var(--hd-font-body);
  font-size: 1rem;
  line-height: 1.4;
}

.hd-field .hd-field__input:focus {
  border-color: var(--hd-accent-dark);
}

.hd-field .hd-field__input[aria-invalid="true"] {
  border-color: var(--hd-error);
}

.hd-field__hint,
.hd-field__counter {
  display: block;
  margin: 0.3rem 0 0;
  color: var(--hd-text-muted);
  font-size: 0.875rem;
  line-height: 1.4;
}

.hd-field__counter {
  font-variant-numeric: tabular-nums;
}

.hd-field__error {
  display: block;
  margin: 0.35rem 0 0;
  color: var(--hd-error);
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.4;
}

/* The `hidden` attribute must still win over the display value above. */
.hd-field__error[hidden],
.hd-field__hint[hidden],
.hd-field__counter[hidden] {
  display: none;
}

.hd-field input[type="checkbox"],
.hd-field input[type="radio"] {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--hd-accent-dark);
}

/* A checkbox/radio row: the label is the touch target, so it carries the 44px. */
.hd-field__choice {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  min-height: 44px;
  padding: 0.4rem 0;
  font-family: var(--hd-font-body);
  font-weight: 400;
}

/* ------------------------------------------------------------------ *
 * 6. Notes
 * ------------------------------------------------------------------ */

.hd-note {
  margin: 0 0 1rem;
  padding: 0.75rem 0.9rem;
  background-color: var(--hd-surface);
  border: 1px solid var(--hd-border);
  border-left: 4px solid var(--hd-accent-dark);
  border-radius: var(--hd-radius-sm);
  color: var(--hd-text);
  font-size: 0.95rem;
  line-height: 1.55;
}

.hd-note > :last-child {
  margin-bottom: 0;
}

.hd-note--info {
  border-left-color: var(--hd-info);
}

.hd-note--warn {
  border-left-color: var(--hd-warning);
  background-color: var(--hd-bg);
}

.hd-note--warn strong {
  color: var(--hd-warning);
}

/* ------------------------------------------------------------------ *
 * 7. Trust bar (templates/trust-bar.php)
 * ------------------------------------------------------------------ */

.hd-trust {
  margin: 1.25rem 0;
}

.hd-trust__list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.hd-trust__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  color: var(--hd-text);
  font-size: 0.9rem;
  line-height: 1.35;
}

.hd-trust__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 2.25rem;
  height: 2.25rem;
  background-color: var(--hd-bg);
  border: 1px solid var(--hd-border);
  border-radius: 50%;
  color: var(--hd-accent-dark);
}

.hd-trust__svg {
  width: 1.25rem;
  height: 1.25rem;
}

.hd-trust__label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.hd-trust__ref {
  display: inline-block;
  min-width: 24px;
  padding: 0 0.2rem;
  color: var(--hd-accent-dark);
  text-decoration: none;
}

.hd-trust__note {
  margin: 0.6rem 0 0;
  color: var(--hd-text-muted);
  font-size: 0.8125rem;
  line-height: 1.5;
}

@media (min-width: 720px) {
  .hd-trust__list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* ------------------------------------------------------------------ *
 * 8. Safety notice (templates/safety-notice.php)
 * The e-mail variant carries its own inline styles and must stay untouched here.
 * ------------------------------------------------------------------ */

.hd-safety {
  margin: 1rem 0;
  padding: 0.9rem 1rem;
  background-color: var(--hd-bg);
  border: 1px solid var(--hd-border);
  border-left: 4px solid var(--hd-accent-dark);
  border-radius: var(--hd-radius-sm);
  color: var(--hd-text);
}

.hd-safety__heading {
  margin: 0 0 0.35rem;
  color: var(--hd-text);
  font-family: var(--hd-font-head);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
}

.hd-safety__text {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.6;
}

.hd-safety--cart .hd-safety__text,
.hd-safety--footer .hd-safety__text {
  font-size: 0.8125rem;
  color: var(--hd-text-muted);
}

.hd-safety--footer {
  background-color: transparent;
  border: 0;
  border-top: 1px solid var(--hd-border);
  border-radius: 0;
  padding: 0.9rem 0 0;
}

/* ------------------------------------------------------------------ *
 * 9. Drawer shell
 * The mini-cart fills .hd-drawer__panel (see assets/css/cart.css); this file only
 * provides the overlay, the panel geometry and the open/closed states. Several
 * state conventions are accepted so the drawer works however its script marks it.
 * ------------------------------------------------------------------ */

.hd-drawer {
  position: fixed;
  inset: 0;
  z-index: 9990;
  display: flex;
  justify-content: flex-end;
  background-color: var(--hd-overlay);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.hd-drawer.is-open,
.hd-drawer[data-hd-open="1"],
.hd-drawer[aria-hidden="false"] {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.hd-drawer__panel {
  display: flex;
  flex-direction: column;
  width: min(100%, 26rem);
  max-width: 100%;
  height: 100%;
  margin-left: auto;
  padding: 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  background-color: var(--hd-surface);
  border-left: 1px solid var(--hd-border);
  box-shadow: var(--hd-shadow-lg);
  color: var(--hd-text);
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

.hd-drawer.is-open .hd-drawer__panel,
.hd-drawer[data-hd-open="1"] .hd-drawer__panel,
.hd-drawer[aria-hidden="false"] .hd-drawer__panel {
  transform: translateX(0);
}

/* ------------------------------------------------------------------ *
 * 10. Cookie banner (templates/consent-banner.php)
 * ------------------------------------------------------------------ */

.hd-consent {
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 9995;
  width: calc(100% - 24px);
  max-width: 38rem;
  max-height: 70vh;
  max-height: 70dvh;
  overflow-y: auto;
  padding: 14px 16px 10px;
  background-color: var(--hd-surface);
  border: 1px solid var(--hd-border);
  border-radius: 12px;
  box-shadow: var(--hd-shadow-lg);
  color: var(--hd-text);
}

.hd-consent__inner {
  display: grid;
  gap: 6px;
}

.hd-consent .hd-consent__title {
  margin: 0;
  color: var(--hd-text);
  font-family: var(--hd-font-head);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}

.hd-consent .hd-consent__text {
  margin: 0 0 4px;
  color: var(--hd-text-muted);
  font-size: 0.875rem;
  line-height: 1.45;
}

.hd-consent__actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 4px 8px;
}

.hd-consent .hd-consent__btn {
  min-width: 0;
  min-height: 44px;
  height: 100%;
  padding: 8px 10px;
  font-size: 0.8125rem;
  line-height: 1.3;
  white-space: normal;
}

.hd-consent__link {
  display: inline-flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-self: center;
  min-height: 32px;
  color: var(--hd-accent-dark);
  font-size: 0.75rem;
}

@media (min-width: 720px) {
  .hd-consent {
    right: 20px;
    bottom: 20px;
  }
}

/* ------------------------------------------------------------------ *
 * 11. Small shared primitives printed by the plugin on every page
 * ------------------------------------------------------------------ */

.hd-price-suffix {
  color: var(--hd-text-muted);
  font-size: 0.8125rem;
  font-weight: 400;
  white-space: nowrap;
}

/* Printed by Shipping_Estimate on the cart page, on top of .hd-note--info. */
.hd-dispatch__date {
  display: block;
  color: var(--hd-text);
  font-family: var(--hd-font-head);
}

.hd-dispatch__lead {
  display: block;
  margin-top: 0.2rem;
  color: var(--hd-text-muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

/* Omnibus line: small print wherever it is printed (product, loop, cart). */
.hd-omnibus {
  margin: 0.35rem 0 0;
  color: var(--hd-text-muted);
  font-size: 0.8125rem;
  line-height: 1.5;
}

/* ------------------------------------------------------------------ *
 * 12. Availability ticker (templates/checkout-ticker.php)
 *
 * Printed above the checkout header (Checkout::render_ticker) and above the site header on the
 * product page (Product_Page::render_ticker), so the rules live here rather than in either
 * page's stylesheet. Moved unchanged from checkout.css, section 10.
 *
 * Every line it shows is read from the shop (stock, cutoff, free-shipping threshold), so it is
 * worth showing properly: one clipped, scrolling row, never four wrapped lines.
 * ------------------------------------------------------------------ */

.hd-ticker {
  overflow: hidden;
  background-color: var(--hd-accent-dark);
  color: var(--hd-on-accent);
  font-size: 0.78rem;
  line-height: 1.5;
}

.hd-ticker__track {
  display: flex;
  width: max-content;
  flex-wrap: nowrap;
  animation: hd-ticker-scroll 26s linear infinite;
}

/* Reading stops while the pointer is on it. */
.hd-ticker:hover .hd-ticker__track,
.hd-ticker:focus-within .hd-ticker__track {
  animation-play-state: paused;
}

.hd-ticker__group {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: nowrap;
}

.hd-ticker__item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-right: 2rem;
  padding: 0.4rem 0;
  white-space: nowrap;
}

.hd-ticker__item::before {
  content: "";
  flex: 0 0 auto;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background-color: var(--hd-on-accent-muted);
}

/* The second group is the seamless-loop copy, so half a track is one full set. */
@keyframes hd-ticker-scroll {
  to { transform: translateX(-50%); }
}

/*
 * Wide screens. Half a track is one set only while one set is wider than the screen; on a laptop or
 * a 4K monitor it is not, and the loop ran out of text before it restarted. assets/js/ticker.js
 * clones the set until the track covers the bar plus one set, then scrolls by exactly one set's
 * width at the same pace - seamless at any width.
 */
@keyframes hd-ticker-shift {
  to { transform: translateX(var(--hd-ticker-shift, -50%)); }
}

.hd-ticker.is-measured .hd-ticker__track {
  animation-name: hd-ticker-shift;
  animation-duration: var(--hd-ticker-duration, 26s);
}

@media (prefers-reduced-motion: reduce) {
  .hd-ticker__track,
  .hd-ticker.is-measured .hd-ticker__track {
    width: auto;
    flex-wrap: wrap;
    justify-content: center;
    animation: none;
  }

  /* With no movement every copy after the first would just read again. */
  .hd-ticker__group + .hd-ticker__group {
    display: none;
  }
}
