/* =========================================================
   CrochetBy Rumi — Custom Product Card
   Colors / fonts copied 1:1 from the brand reference file.
   ========================================================= */

:root {
  --crb-cream: #FAF5EC;
  --crb-paper: #F2EADC;
  --crb-paperline: #E2D5BD;
  --crb-ink: #2B2420;
  --crb-inksoft: #5B5044;
  --crb-wine: #6E1F2B;
  --crb-wine-light: #9C3A46;
  --crb-wine-dark: #4C1620;
  --crb-wine-50: #FBEEEF;
  --crb-olive: #6C7A3D;
  --crb-olive-dark: #525E2D;
  --crb-mustard: #D29A2C;
  --crb-mustard-dark: #A87A1F;
  --crb-blush: #E3B6AC;
  --crb-font-display: 'Fraunces', serif;
  --crb-font-body: 'Outfit', sans-serif;
}

.crb-hidden { display: none !important; }

/* ---------- Grid wrapper ----------
   Targets the standard WooCommerce loop wrapper. If your live theme already
   provides its own grid CSS for ul.products, delete this block and only
   keep the .crb-card rules below. */
ul.products {
  display: grid !important;
  /* auto-fit + minmax: the browser works out how many cards fit per row
     from the available width on its own — no per-device column count is
     hardcoded anywhere, and a card can never be wider than the screen or
     get cut off, because minmax()'s max side is always 1fr (share of the
     row, capped at the row's own width). */
  grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr));
  gap: 1.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
ul.products li.crb-product-li {
  list-style: none;
  margin: 0;
  padding: 0;
  width: auto;
  float: none;
  min-width: 0; /* grid items default to min-width:auto, which lets a wide
                   image force the column wider than the screen — this is
                   what was causing the horizontal scroll on mobile */
  box-sizing: border-box;
}

/* ---------- Card ---------- */
.crb-card {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  background: #ffffff;
  border: 1px solid var(--crb-paperline);
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(43, 36, 32, 0.06), 0 1px 2px rgba(43, 36, 32, 0.06);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.35s ease;
  font-family: var(--crb-font-body);
}
.crb-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 18px 30px -12px rgba(110, 31, 43, 0.22);
}
@media (prefers-reduced-motion: reduce) {
  .crb-card, .crb-img, .crb-wishlist-btn, .crb-btn-primary, .crb-toast { transition: none !important; animation: none !important; }
}

/* ---------- Image + hover swap/zoom ---------- */
.crb-card-media {
  position: relative !important;
  display: block !important;
  aspect-ratio: 4 / 5 !important;
  overflow: hidden !important;
  background: var(--crb-paper);
  padding: 0 !important;
  margin: 0 !important;
  min-height: 0 !important;
}
.crb-img {
  /* !important here is deliberate: many WordPress themes ship a global
     img { max-width:100%; height:auto } reset. Combined with position:
     absolute, "height:auto" can win and shrink the image to its own
     intrinsic ratio — leaving a blank strip of the card's background
     color showing underneath. Forcing these wins that fight reliably. */
  position: absolute !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: none !important;
  margin: 0 !important;
  object-fit: cover !important;
  transition: opacity 0.5s ease, transform 0.7s ease;
}
.crb-img-primary { opacity: 1; transform: scale(1); z-index: 1; }
.crb-img-secondary { opacity: 0; transform: scale(1.08); z-index: 2; }
.crb-card:hover .crb-img-primary { opacity: 0; transform: scale(1.05); }
.crb-card:hover .crb-img-secondary { opacity: 1; transform: scale(1.08); }

/* If there is no secondary image, keep a gentle zoom on the primary only */
.crb-card-media:not(:has(.crb-img-secondary)):hover .crb-img-primary {
  opacity: 1;
  transform: scale(1.05);
}

/* ---------- Badges ---------- */
.crb-badges {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}
.crb-badge {
  font-family: var(--crb-font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.625rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}
.crb-badge-sale        { background: var(--crb-wine);    color: var(--crb-cream); }
.crb-badge-new         { background: var(--crb-olive);   color: var(--crb-cream); }
.crb-badge-bestseller  { background: var(--crb-mustard); color: var(--crb-ink); }
.crb-badge-madetoorder { background: var(--crb-olive);   color: var(--crb-cream); }
.crb-badge-limited     { background: var(--crb-wine);    color: var(--crb-cream); }

/* ---------- Wishlist heart ---------- */
.crb-wishlist-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 3;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  border: none;
  background: rgba(250, 245, 236, 0.9);
  backdrop-filter: blur(4px);
  color: var(--crb-wine);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
  padding: 0;
}
.crb-wishlist-btn:hover  { transform: scale(1.1); background: var(--crb-cream); }
.crb-wishlist-btn:active { transform: scale(0.95); }
.crb-wishlist-btn.is-active { color: var(--crb-wine); }
.crb-wishlist-btn svg { pointer-events: none; }

/* ---------- Body ---------- */
.crb-card-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 1.1rem 1.25rem 1.25rem;
}
.crb-card-cat {
  font-family: var(--crb-font-body);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.68rem;
  color: rgba(91, 80, 68, 0.7);
  margin: 0 0 0.25rem;
}
.crb-card-title {
  font-family: var(--crb-font-display);
  font-size: 1.125rem;
  line-height: 1.35;
  color: var(--crb-ink);
  text-decoration: none;
  transition: color 0.25s ease;
  display: inline-block;
}
.crb-card-title:hover { color: var(--crb-wine); }
.crb-card-title:focus-visible {
  outline: 2.5px solid var(--crb-wine);
  outline-offset: 2px;
  border-radius: 2px;
}

.crb-card-rating {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-top: 0.375rem;
  font-size: 0.75rem;
  color: var(--crb-inksoft);
}
.crb-stars { color: var(--crb-mustard); letter-spacing: 2px; }

.crb-card-footer {
  margin-top: auto;
  padding-top: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.crb-card-price {
  font-family: var(--crb-font-display);
  font-size: 1.25rem;
  color: var(--crb-wine);
}
.crb-card-price del { color: var(--crb-inksoft); opacity: 0.6; font-size: 0.85em; }
.crb-card-price ins { text-decoration: none; color: var(--crb-wine); }

.crb-out-of-stock {
  font-size: 0.75rem;
  color: var(--crb-inksoft);
  font-style: italic;
}

/* WooCommerce core automatically inserts a "View cart" link right after any
   add-to-cart button once the item is added — our own popup already tells
   the shopper it worked, so we hide that default link inside the card. */
.crb-card-footer .added_to_cart,
.crb-card-footer a.wc-forward {
  display: none !important;
}

/* ---------- Buttons ---------- */
.crb-btn-primary {
  background: var(--crb-wine);
  color: var(--crb-cream);
  border: none;
  font-family: var(--crb-font-body);
  font-weight: 500;
  font-size: 0.75rem;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.25s ease, transform 0.15s ease;
  white-space: nowrap;
}
.crb-card-footer .crb-btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.crb-btn-icon {
  display: none; /* desktop shows text only; mobile swaps this in, see below */
  flex-shrink: 0;
}
.crb-btn-primary:hover  { background: var(--crb-wine-dark); color: var(--crb-cream); }
.crb-btn-primary:active { transform: scale(0.97); background: var(--crb-wine-dark); color: var(--crb-cream); }
.crb-btn-primary:focus-visible {
  outline: 2.5px solid var(--crb-wine-dark);
  outline-offset: 2px;
}
.crb-btn-primary[disabled] {
  background: var(--crb-paperline);
  color: var(--crb-inksoft);
  cursor: not-allowed;
}

/* ---------- Modal: variation picker ---------- */
.crb-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
}
.crb-modal.is-open { display: flex; }
.crb-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(43, 36, 32, 0.55);
}
.crb-modal-box {
  position: relative;
  background: var(--crb-cream);
  border-radius: 1rem;
  padding: 1.75rem;
  width: 90%;
  max-width: 26rem;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 18px 30px -12px rgba(110, 31, 43, 0.3);
}
.crb-modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.9rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--crb-inksoft);
  cursor: pointer;
  line-height: 1;
}
.crb-modal-close:hover { color: var(--crb-wine); }
.crb-modal-title {
  font-family: var(--crb-font-display);
  font-size: 1.25rem;
  color: var(--crb-ink);
  margin: 0 0 1rem;
  padding-right: 1.5rem;
}
.crb-variation-row { margin-bottom: 1rem; }
.crb-variation-label {
  display: block;
  font-family: var(--crb-font-body);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--crb-inksoft);
  margin-bottom: 0.35rem;
}
.crb-variation-row select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--crb-paperline);
  border-radius: 0.5rem;
  background: #fff;
  color: var(--crb-ink);
  font-family: var(--crb-font-body);
}
.crb-variation-row select:focus-visible {
  outline: 2.5px solid var(--crb-wine);
  outline-offset: 2px;
}

/* ---------- Swatches (color / size) ---------- */
.crb-swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}
.crb-swatch {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}
.crb-swatch-color {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  border: 2px solid var(--crb-paperline);
  box-shadow: inset 0 0 0 2px #ffffff; /* thin white ring so the color reads clearly against the border */
  transition: border-color 0.2s ease, transform 0.15s ease;
}
.crb-swatch-color:hover { transform: scale(1.08); }
.crb-swatch-color.is-selected {
  border-color: var(--crb-wine);
  box-shadow: inset 0 0 0 2px #ffffff, 0 0 0 2px var(--crb-wine-50);
}
.crb-swatch-size {
  min-width: 2.4rem;
  height: 2.4rem;
  padding: 0 0.6rem;
  border-radius: 0.5rem;
  border: 1.5px solid var(--crb-paperline);
  background: #ffffff;
  color: var(--crb-ink);
  font-family: var(--crb-font-body);
  font-size: 0.8rem;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.crb-swatch-size:hover:not(.is-selected) { border-color: var(--crb-wine-light); }
.crb-swatch-size.is-selected {
  background: var(--crb-wine);
  color: var(--crb-cream);
  border-color: var(--crb-wine);
}
.crb-swatch:focus-visible {
  outline: 2.5px solid var(--crb-wine);
  outline-offset: 2px;
}
.crb-modal-submit { width: 100%; margin-top: 0.5rem; padding: 0.75rem 1rem; font-size: 0.875rem; }

/* ---------- Toast: success popup ---------- */
.crb-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 10000;
  display: none;
  align-items: center;
  gap: 0.65rem;
  background: var(--crb-ink);
  color: var(--crb-cream);
  padding: 0.85rem 1.1rem;
  border-radius: 0.75rem;
  box-shadow: 0 18px 30px -12px rgba(43, 36, 32, 0.4);
  font-family: var(--crb-font-body);
  font-size: 0.875rem;
}
.crb-toast.is-visible { display: flex; animation: crbToastIn 0.35s ease both; }
@keyframes crbToastIn {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}
.crb-toast-icon {
  width: 1.4rem;
  height: 1.4rem;
  background: var(--crb-olive);
  color: var(--crb-cream);
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  flex-shrink: 0;
}
.crb-toast-link { color: var(--crb-mustard); text-decoration: underline; font-weight: 500; white-space: nowrap; }

/* =========================================================
   MOBILE (<=767px)
   Per spec: vw is used for width/size-type properties; em is used
   for spacing (margin/padding/gap). clamp() wraps the vw values so
   text never becomes unreadably small on narrow phones — pure vw
   font-sizing without a floor is a common source of "tiny text"
   bugs on small devices, so this keeps a safe minimum while still
   scaling with vw as requested.
   ========================================================= */
@media (max-width: 767px) {
  html, body { overflow-x: hidden; max-width: 100%; }
  ul.products { padding: 0 2vw; gap: 0.85em; }

  .crb-card { border-radius: 4vw; }

  .crb-badges { top: 2vw; left: 2vw; gap: 0.35em; }
  .crb-badge {
    font-size: clamp(9px, 2.4vw, 11px);
    padding: 0.3em 0.7em;
  }

  .crb-wishlist-btn {
    top: 2vw; right: 2vw;
    width: clamp(30px, 8vw, 38px);
    height: clamp(30px, 8vw, 38px);
  }
  .crb-wishlist-btn svg {
    width: clamp(14px, 4vw, 17px);
    height: clamp(14px, 4vw, 17px);
  }

  .crb-card-body { padding: 0.9em 1em 1em; }
  .crb-card-cat { font-size: clamp(9px, 2.4vw, 11px); margin-bottom: 0.25em; }
  .crb-card-title { font-size: clamp(15px, 4vw, 18px); }

  .crb-card-rating { font-size: clamp(10px, 2.6vw, 12px); gap: 0.3em; margin-top: 0.3em; }

  .crb-card-footer { padding-top: 0.6em; gap: 0.4em; }
  .crb-card-price { font-size: clamp(16px, 4.2vw, 20px); }
  .crb-card-footer .crb-btn-primary {
    padding: 0;
    width: clamp(32px, 9vw, 40px);
    height: clamp(32px, 9vw, 40px);
    border-radius: 50%;
    justify-content: center;
  }
  .crb-card-footer .crb-btn-label { display: none; } /* text hidden on mobile — icon only */
  .crb-card-footer .crb-btn-icon {
    display: inline-block;
    width: clamp(15px, 4.2vw, 18px);
    height: clamp(15px, 4.2vw, 18px);
  }

  .crb-modal-box { padding: 1.25em; width: 92vw; }
  .crb-modal-title { font-size: clamp(17px, 4.5vw, 20px); }
  .crb-variation-label { font-size: clamp(11px, 2.8vw, 13px); }

  .crb-toast {
    right: 2vw; left: 2vw; bottom: 2vw;
    font-size: clamp(12px, 3.2vw, 14px);
    padding: 0.7em 0.9em;
  }
}