/* =====================================================================
   Add-to-cart button
   ---------------------------------------------------------------------
   Styles and enhancements for Porto's AJAX add-to-cart button (both the
   in-page button and the sticky bar button). Currently covers:

     1. A spinner INSIDE the clicked button + blocked re-clicks, instead
        of Porto's default sibling spinner.
     2. A "✓ Added" success flash in the same button.
     3. Hiding the duplicate "View cart" link Porto injects after a
        successful add — the cart link lives in the toast instead.
     4. The confirmation toast.
     5. Removing Porto's "stuck" gold :hover/:focus/:active state.

   Add further add-to-cart button tweaks here.

   The matching JS (add-to-cart.js) hooks WooCommerce's standard
   `adding_to_cart` / `added_to_cart` jQuery events and injects/removes a
   `.scby-overlay` child element. We use a real child element (not an
   ::after pseudo) on purpose: Porto already uses ::before AND ::after on
   the single add-to-cart button for its icons, so a pseudo-element
   spinner would collide.
   ===================================================================== */

/* Positioning context so the overlay can sit centred over the button.
   Porto already sets overflow:hidden on this button, so the overlay is
   clipped to the button's rounded corners for free. */
.single_add_to_cart_button {
  position: relative;
}

/* ---- BUSY / SUCCESS: hide the button's own label + icons ----
   color:transparent hides the text label AND Porto's ::before/::after
   icon glyphs (they inherit the text colour). The overlay child supplies
   its own explicit colour, so it stays visible. opacity:1 guards against
   any theme rule that dims a .loading button. */
.single_add_to_cart_button.scby-busy {
  color: transparent !important;
  opacity: 1 !important;
  pointer-events: none;   /* block re-clicks even before `disabled` lands */
  cursor: default;
}

/* The injected overlay: centred over the whole button face. */
.scby-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  color: #fff;            /* button background is the dark heading colour */
  pointer-events: none;
  letter-spacing: 0;      /* the button uses negative tracking; reset it */
}

/* Loading indicator — a small gold tile flipping in 3D ("coin flip").
   Gold (#e9c87e) reads well on the dark button background. */
.scby-overlay .scby-spinner {
  width: 0.95em;
  height: 0.95em;
  border-radius: 3px;
  background: #e9c87e;
  animation: scby-coinflip 1.1s infinite ease-in-out;
}

@keyframes scby-coinflip {
  0%   { transform: perspective(80px) rotateY(0); }
  50%  { transform: perspective(80px) rotateY(180deg); }
  100% { transform: perspective(80px) rotateY(360deg); }
}

/* Shared stroked checkmark (used in the toast). Colour comes from the
   surrounding context via stroke:currentColor. */
.scby-tick {
  width: 1.1em;
  height: 1.1em;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Respect reduced-motion: no spin, just a static ring. */
@media (prefers-reduced-motion: reduce) {
  .scby-overlay .scby-spinner { animation: none; }
}

/* ---- "In cart" state on the button ----
   Porto shows an "is this product in your cart?" indicator on the
   add-to-cart button: a bag icon (::before) when it's NOT in the cart, and
   a checkmark (::after) when it IS. That state is rendered server-side, so
   it only updates on a full page load — an AJAX add doesn't reflect it.

   The JS adds `.scby-in-cart` to the add-to-cart button(s) after a
   successful AJAX add, and these rules mirror Porto's icon swap so the
   button matches what a page refresh would show: hide the bag, show the
   check. (We re-declare the glyph rather than rely on Porto's ancestor
   `.single-add-to-cart` class, so it works regardless of where Porto
   injects that.) */
.single_add_to_cart_button.scby-in-cart::before {
  content: none !important;
}
.single_add_to_cart_button.scby-in-cart::after {
  content: "\f00c" !important;                  /* Font Awesome check */
  font-family: "Font Awesome 6 Free" !important;
  font-weight: 900 !important;
  margin-left: 10px;
  font-size: 1.143em;
}

/* ---- No "stuck" gold state on the add-to-cart button ----
   Porto turns this button gold (var(--porto-primary-dark-5)) on
   :hover / :focus / :active via its generic `.button` / `[type=submit]`
   rules. On mobile that gold lingers after a tap (there's no pointer to
   "leave"), which looks broken; a stuck focus/active highlight is unwanted
   on desktop too.

   So we:
     - drop the gold for :focus / :active  -> no stuck highlight after a click;
     - drop the hover gold on touch devices -> it would otherwise stick;
     - keep the normal hover affordance on real-pointer (desktop) devices;
     - keep a keyboard-only focus ring (:focus-visible) for accessibility —
       it does NOT trigger on tap/click, so mobile stays clean.

   Background is forced dark even while the button is "busy", so the
   loading/success overlay always sits on the solid dark button. The label
   colour is only restored when NOT busy (busy keeps it transparent so the
   spinner / tick shows). */
.single_add_to_cart_button:focus,
.single_add_to_cart_button:active {
  background: var(--porto-heading-color) !important;
  outline: none;
  box-shadow: none;
}
.single_add_to_cart_button:focus:not(.scby-busy),
.single_add_to_cart_button:active:not(.scby-busy) {
  color: var(--porto-light-1) !important;
}

@media (hover: none) {
  .single_add_to_cart_button:hover {
    background: var(--porto-heading-color) !important;
  }
  .single_add_to_cart_button:hover:not(.scby-busy) {
    color: var(--porto-light-1) !important;
  }
}

/* Keyboard-only focus ring (won't appear on tap/click). */
.single_add_to_cart_button:focus-visible {
  outline: 2px solid var(--porto-primary-color, #c6a15b);
  outline-offset: 2px;
}

/* ---- Hide the duplicate "View cart" link Porto injects after success ----
   Porto forces this link with `display:block !important` at the selector
   `form.cart a.added_to_cart`, so we need higher specificity + !important
   to win. The cart link is surfaced in the toast instead. */
.product-summary-wrap form.cart a.added_to_cart,
.single-add-to-cart form.cart a.added_to_cart,
.sticky-product a.added_to_cart {
  display: none !important;
}

/* ---- Hide Porto's sibling loading icon (we render ours in the button) ----
   Porto SHOWS this icon during the AJAX add via
   `.sp-only-cart-form .porto-ajax-loading .porto-loading-icon { display:
   inline-block !important }` — specificity (0,3,0) + !important. A plain
   `.product-summary-wrap .porto-loading-icon` hide rule (0,2,0) loses that
   contest even with !important, so the icon kept showing (and squashed the
   button on mobile). The first selector below out-specifies Porto's (0,4,0);
   the others cover the idle / sticky cases. */
.sp-only-cart-form .product-summary-wrap .porto-ajax-loading .porto-loading-icon,
.product-summary-wrap .porto-loading-icon,
.sticky-product .porto-loading-icon {
  display: none !important;
}

/* ---- Suppress Porto's own add-to-cart success popup ----
   On shop/category (PLP) pages, Porto's loop "add to cart" buttons trigger
   its built-in popup (.after-loading-success-message). Our toast hooks the
   global `added_to_cart` event and fires there too, so the two showed at
   once. We standardise on our (localized, on-brand, checkout-directing)
   toast everywhere and hide Porto's popup. Porto reveals it with an inline
   jQuery .show() (display:block, NOT !important), so this wins. Porto's
   product-image loading spinner is a separate element and stays. */
.after-loading-success-message {
  display: none !important;
}

/* =====================================================================
   Toast / snackbar — bottom-right card
   Porto-flavoured content (thumbnail + product name + checkout button +
   close ✕) in our own brand styling. Sits in the bottom-right corner; the
   JS sets `bottom` so it clears the mobile sticky add-to-cart bar.
   ===================================================================== */

.scby-toast-wrap {
  position: fixed;
  z-index: 100000;
  right: 1rem;
  /* `bottom` is set inline by the JS (default below; lifted above the mobile
     sticky add-to-cart bar when that bar is on screen). */
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: max-content;
  max-width: min(92vw, 380px);
  pointer-events: none;   /* the wrap is click-through; toasts re-enable it */
}

.scby-toast {
  position: relative;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 1.1rem;            /* breathing room to the right of the thumbnail */
  background: #fff;
  color: #222;
  border-left: 4px solid #b58a48;   /* brand gold accent */
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  padding: 0.9rem 2.1rem 0.9rem 1rem;   /* extra right padding clears the ✕ */
  font-size: 0.9rem;
  line-height: 1.35;
  cursor: pointer;                       /* click anywhere to dismiss */
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.scby-toast.scby-show {
  opacity: 1;
  transform: translateY(0);
}

/* Thumbnail + success badge */
.scby-toast .scby-toast-thumb-wrap { position: relative; flex: 0 0 auto; }
.scby-toast .scby-toast-thumb {
  display: block;
  width: 54px;
  height: 54px;
  border-radius: 8px;
  object-fit: cover;
  background: #f3f0ea;
}
.scby-toast .scby-toast-badge {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #2e9e5b;
  color: #fff;
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scby-toast .scby-toast-badge .scby-tick { width: 0.7rem; height: 0.7rem; }

/* Body */
.scby-toast .scby-toast-body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.scby-toast .scby-toast-label { font-size: 0.78rem; color: #777; }
.scby-toast .scby-toast-name {
  font-weight: 700;
  font-size: 0.98rem;
  line-height: 1.25;
  color: #1a1a1a;
}

/* Checkout button — dark, matching the site's add-to-cart button */
.scby-toast .scby-toast-actions { margin-top: 0.55rem; }
.scby-toast a.scby-toast-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--porto-heading-color, #222529);
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  text-decoration: none;
  white-space: nowrap;
}
.scby-toast a.scby-toast-btn:hover { background: #000; color: #fff; }

/* Close ✕ */
.scby-toast .scby-toast-close {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  color: #aaa;
  font-size: 0.95rem;
  line-height: 1;
  border-radius: 50%;
}
.scby-toast .scby-toast-close:hover { color: #555; background: #f0f0f0; }

/* Error variant: no thumbnail, red inline badge */
.scby-toast .scby-toast-badge--error {
  position: static;
  flex: 0 0 auto;
  width: 1.5rem;
  height: 1.5rem;
  border: 0;
  background: #c0392b;
  font-size: 0.9rem;
}

/* Reduced-motion: drop the slide, keep the fade. */
@media (prefers-reduced-motion: reduce) {
  .scby-toast {
    transform: none;
    transition: opacity 0.2s ease;
  }
  .scby-toast.scby-show { transform: none; }
}
