/* ==========================================================================
   WooGrub — modal.css
   Product modal: desktop centred overlay + mobile bottom sheet.
   ========================================================================== */

/* ── Modal wrap — the mount point ───────────────────────────────────────── */
.wg-modal-wrap {
  position: fixed;
  z-index: var(--wg-z-modal);
  inset: 0;
  display: flex;
  align-items: flex-end;     /* Mobile: bottom sheet */
  justify-content: center;
  pointer-events: none;
}

.wg-modal-wrap.is-open {
  pointer-events: auto;
}

/* ── Modal panel ─────────────────────────────────────────────────────────── */
.wg-modal {
  position: relative;
  background-color: var(--wg-surface);
  width: 100%;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  border-radius: var(--wg-radius-lg) var(--wg-radius-lg) 0 0;
  box-shadow: var(--wg-shadow-overlay);
  overflow: hidden;

  /* Entry animation — slide up */
  transform: translateY(100%);
  transition: transform var(--wg-transition-slow);
  will-change: transform;
}

.wg-modal-wrap.is-open .wg-modal {
  transform: translateY(0);
}

/* ── Desktop: centred overlay ────────────────────────────────────────────── */
@media (min-width: 768px) {
  .wg-modal-wrap {
    align-items: center;
    padding: var(--wg-space-8);
  }

  .wg-modal {
    width: 100%;
    max-width: 540px;
    max-height: 85dvh;
    border-radius: var(--wg-radius-lg);

    /* Desktop: scale in instead of slide up */
    transform: scale(0.95);
    opacity: 0;
    transition:
      transform var(--wg-transition-slow),
      opacity var(--wg-transition-slow);
  }

  .wg-modal-wrap.is-open .wg-modal {
    transform: scale(1);
    opacity: 1;
  }
}

/* ── Drag handle (mobile only) ───────────────────────────────────────────── */
.wg-modal__drag-handle {
  display: flex;
  justify-content: center;
  padding-top: var(--wg-space-3);
  padding-bottom: var(--wg-space-2);
  flex-shrink: 0;
  cursor: grab;
  touch-action: none;
}

.wg-modal__drag-handle:active {
  cursor: grabbing;
}

.wg-modal__drag-handle-bar {
  width: 40px;
  height: 4px;
  background-color: var(--wg-border-strong);
  border-radius: var(--wg-radius-full);
}

@media (min-width: 768px) {
  .wg-modal__drag-handle {
    display: none;
  }
}

/* ── Close button ────────────────────────────────────────────────────────── */
.wg-modal__close {
  position: absolute;
  top: var(--wg-space-3);
  right: var(--wg-space-3);
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--wg-radius-full);
  background-color: var(--wg-surface-raised);
  color: var(--wg-text-muted);
  border: 1px solid var(--wg-border);
  transition:
    background-color var(--wg-transition),
    color var(--wg-transition);
}

.wg-modal__close:hover {
  background-color: var(--wg-bg);
  color: var(--wg-text);
}

.wg-modal__close:focus-visible {
  outline: 2px solid var(--wg-primary);
  outline-offset: 2px;
}

/* ── Scrollable content region ───────────────────────────────────────────── */
.wg-modal__scroll-region {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ── Product image ───────────────────────────────────────────────────────── */
.wg-modal__image-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  flex-shrink: 0;
}

.wg-modal__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

/* ── Text content ────────────────────────────────────────────────────────── */
.wg-modal__content {
  padding: var(--wg-space-5) var(--wg-space-5) var(--wg-space-1);
  display: flex;
  flex-direction: column;
  gap: var(--wg-space-4);
}

.wg-modal__title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--wg-text);
  line-height: 1.25;
  margin: 0;
  padding-right: var(--wg-space-8); /* avoid overlap with close btn */
}

.wg-modal__price {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--wg-text);
}

.wg-modal__price .woocommerce-Price-amount {
  color: var(--wg-text);
}

.wg-modal__price del {
  color: var(--wg-text-muted);
  font-weight: 400;
  font-size: 0.9375rem;
}

.wg-modal__price ins {
  text-decoration: none;
  color: var(--wg-primary);
}

.wg-modal__description {
  font-size: 0.9375rem;
  color: var(--wg-text-muted);
  line-height: 1.6;
}

.wg-modal__description p {
  max-width: none;
  margin-block-end: var(--wg-space-3);
}

.wg-modal__description p:last-child {
  margin-block-end: 0;
}

/* ── Dietary tags ─────────────────────────────────────────────────────────── */
.wg-modal__tags:empty {
  display: none;
}

/* ── Variations ──────────────────────────────────────────────────────────── */
.wg-modal__variations {
  display: flex;
  flex-direction: column;
  gap: var(--wg-space-4);
}

.wg-modal__variation-group {
  display: flex;
  flex-direction: column;
  gap: var(--wg-space-2);
}

.wg-modal__variation-label-row {
  display: flex;
  align-items: center;
  gap: var(--wg-space-3);
  margin-block-end: var(--wg-space-2);
}

.wg-modal__variation-label {
  display: flex;
  align-items: center;
  gap: var(--wg-space-3);
  flex: 1;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--wg-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
  white-space: nowrap;
}

/* Inline divider line — grows between label text and required pill */
.wg-modal__variation-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background-color: var(--wg-border);
}

.wg-modal__variation-required {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--wg-primary);
  background-color: color-mix(in srgb, var(--wg-primary) 10%, transparent);
  padding: 2px var(--wg-space-2);
  border-radius: var(--wg-radius-full);
  flex-shrink: 0;
}

.wg-modal__variation-options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--wg-space-2);
}

/* ── Row layout (variations with different prices) ──────────────────────── */
.wg-modal__variation-options--rows {
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 0;
}

.wg-modal__variation-option--row {
  display: flex;
  align-items: center;
  width: 100%;
  gap: var(--wg-space-3);
}

.wg-modal__variation-option--row .wg-modal__variation-radio {
  position: static;
  opacity: 1;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--wg-primary);
  cursor: pointer;
  flex-shrink: 0;
}

.wg-modal__variation-option--row .wg-modal__variation-option-label {
  display: flex;
  align-items: center;
  flex: 1;
  gap: var(--wg-space-3);
  padding: var(--wg-space-3) var(--wg-space-2);
  margin: 0 calc(-1 * var(--wg-space-2));
  border: none;
  border-radius: var(--wg-radius-sm);
  background-color: transparent;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--wg-text);
}

.wg-modal__variation-option--row .wg-modal__variation-option-name {
  flex: 1;
}

.wg-modal__variation-option-price {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--wg-text-muted);
  white-space: nowrap;
}

.wg-modal__variation-options--rows .wg-modal__variation-radio:checked + .wg-modal__variation-option-label .wg-modal__variation-option-name,
.wg-modal__variation-options--rows .wg-modal__variation-radio:checked + .wg-modal__variation-option-label .wg-modal__variation-option-price {
  color: var(--wg-primary);
}

.wg-modal__variation-option--row .wg-modal__variation-radio:focus-visible {
  outline: 2px solid var(--wg-primary);
  outline-offset: 2px;
}

.wg-modal__variation-option {
  display: flex;
  align-items: center;
  cursor: pointer;
}

/* Hide native radio, style the label */
.wg-modal__variation-radio {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.wg-modal__variation-option-label {
  display: inline-flex;
  align-items: center;
  padding: var(--wg-space-2) var(--wg-space-4);
  border-radius: var(--wg-radius-full);
  border: 1.5px solid var(--wg-border);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--wg-text);
  transition:
    border-color var(--wg-transition),
    background-color var(--wg-transition),
    color var(--wg-transition);
  cursor: pointer;
}

.wg-modal__variation-radio:checked + .wg-modal__variation-option-label {
  border-color: var(--wg-primary);
  background-color: var(--wg-primary);
  color: var(--wg-text-on-primary);
}

.wg-modal__variation-options--rows .wg-modal__variation-radio:checked + .wg-modal__variation-option-label {
  border-color: transparent;
  background-color: color-mix(in srgb, var(--wg-primary) 10%, transparent);
  color: var(--wg-text);
}

.wg-modal__variation-radio:focus-visible + .wg-modal__variation-option-label {
  outline: 2px solid var(--wg-primary);
  outline-offset: 2px;
}

/* ── Out-of-stock variation pill ─────────────────────────────────────────── */
.wg-modal__variation-option--oos {
  position: relative;  /* anchor for the tooltip */
  cursor: not-allowed;
}

.wg-modal__variation-option--oos .wg-modal__variation-option-label {
  opacity: 0.45;
  cursor: not-allowed;
  /* Red strikethrough via pseudo-element so we can colour it independently */
  position: relative;
  overflow: visible;
}

.wg-modal__variation-option--oos .wg-modal__variation-option-label::after {
  content: '';
  position: absolute;
  inset-inline: 6px;           /* slight inset so it doesn't poke past the pill */
  top: 50%;
  height: 1.5px;
  background-color: #ba1a1a;
  border-radius: 1px;
  pointer-events: none;
}

/* ── Out-of-stock tooltip ────────────────────────────────────────────────── */
.wg-variation-oos-tooltip {
  position: absolute;
  bottom: calc(100% + 10px);   /* float above the pill */
  left: 50%;
  transform: translateX(-50%);
  z-index: calc(var(--wg-z-modal) + 10);

  background-color: #ba1a1a;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  padding: 5px 10px;
  border-radius: var(--wg-radius-sm);
  pointer-events: none;

  /* Entrance */
  opacity: 0;
  transition: opacity 150ms ease;
}

/* Downward-pointing caret */
.wg-variation-oos-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #ba1a1a;
}

.wg-variation-oos-tooltip.is-visible {
  opacity: 1;
}

/* ── Option groups ───────────────────────────────────────────────────────── */
.wg-modal__option-groups {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.wg-modal__option-group {
  padding-block: var(--wg-space-3);
}

.wg-modal__option-group-title {
  display: flex;
  align-items: center;
  gap: var(--wg-space-3);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--wg-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-block-end: var(--wg-space-3);
  white-space: nowrap;
}

/* Inline divider line — grows to the right of the title */
.wg-modal__option-group-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background-color: var(--wg-border);
}

.wg-modal__options {
  display: flex;
  flex-direction: column;
  gap: var(--wg-space-1);
}

.wg-modal__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--wg-space-3);
  min-height: 40px;
}

.wg-modal__option-label {
  display: flex;
  align-items: center;
  gap: var(--wg-space-3);
  flex: 1;
  cursor: pointer;
  padding-block: var(--wg-space-2);
}

.wg-modal__option-checkbox {
  width: 18px;
  height: 18px;
  border-radius: var(--wg-radius-sm);
  accent-color: var(--wg-primary);
  cursor: pointer;
  flex-shrink: 0;
}

.wg-modal__option-checkbox:focus-visible {
  outline: 2px solid var(--wg-primary);
  outline-offset: 2px;
}

.wg-modal__option-name {
  font-size: 0.9375rem;
  color: var(--wg-text);
  flex: 1;
}

.wg-modal__option-price {
  font-size: 0.875rem;
  color: var(--wg-text-muted);
  white-space: nowrap;
  margin-left: auto;
  padding-right: var(--wg-space-2);
}

/* ── allow_multiples qty stepper ─────────────────────────────────────────── */
.wg-modal__option-stepper {
  display: flex;
  align-items: center;
  gap: var(--wg-space-2);
  flex-shrink: 0;

  /* Animate in when revealed */
  animation: wg-stepper-in 150ms ease forwards;
}

@keyframes wg-stepper-in {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

.wg-modal__option-stepper-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--wg-radius-full);
  border: 1.5px solid var(--wg-border);
  background: var(--wg-surface);
  color: var(--wg-text);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition:
    border-color var(--wg-transition),
    background-color var(--wg-transition);
}

.wg-modal__option-stepper-btn:hover {
  border-color: var(--wg-primary);
  background-color: var(--wg-primary);
  color: var(--wg-text-on-primary);
}

.wg-modal__option-stepper-value {
  font-size: 0.875rem;
  font-weight: 600;
  min-width: 16px;
  text-align: center;
}

/* ── Sticky footer ───────────────────────────────────────────────────────── */
.wg-modal__footer {
  display: flex;
  align-items: center;
  gap: var(--wg-space-3);
  padding: var(--wg-space-4) var(--wg-space-5);
  background-color: var(--wg-surface);
  flex-shrink: 0;

  /* Safe area for devices with home bar */
  padding-bottom: calc( var(--wg-space-4) + env(safe-area-inset-bottom, 0px) );
}

/* ── Qty stepper (footer) ────────────────────────────────────────────────── */
.wg-modal__qty-wrap {
  display: flex;
  align-items: center;
  gap: var(--wg-space-2);
  flex-shrink: 0;
  background-color: var(--wg-bg);
  border-radius: var(--wg-radius-full);
  padding: var(--wg-space-1) var(--wg-space-2);
  border: 1px solid var(--wg-border);
}

.wg-modal__qty-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--wg-radius-full);
  background: transparent;
  color: var(--wg-text);
  border: none;
  transition: background-color var(--wg-transition), color var(--wg-transition);
}

.wg-modal__qty-btn:hover {
  background-color: var(--wg-primary);
  color: var(--wg-text-on-primary);
}

.wg-modal__qty-btn:focus-visible {
  outline: 2px solid var(--wg-primary);
  outline-offset: 2px;
}

.wg-modal__qty-value {
  font-size: 0.9375rem;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
}

/* ── Add to Cart button ──────────────────────────────────────────────────── */
.wg-modal__add-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--wg-space-3);
  padding: var(--wg-space-3) var(--wg-space-5);
  background-color: var(--wg-primary);
  color: var(--wg-text-on-primary);
  border: none;
  border-radius: var(--wg-radius-full);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--wg-transition), transform var(--wg-transition);
}

.wg-modal__add-btn:hover {
  background-color: var(--wg-accent);
}

.wg-modal__add-btn:active {
  transform: scale(0.98);
}

.wg-modal__add-btn:focus-visible {
  outline: 2px solid var(--wg-primary);
  outline-offset: 2px;
}

.wg-modal__add-btn:disabled,
.wg-modal__add-btn[aria-disabled="true"] {
  background-color: var(--wg-border);
  color: var(--wg-text-muted);
  cursor: not-allowed;
  transform: none;
}

.wg-modal__add-btn-label {
  font-weight: 600;
}

.wg-modal__add-btn-total {
  font-weight: 700;
  opacity: 0.9;
}

/* ── Skeleton loader ─────────────────────────────────────────────────────── */
.wg-modal--skeleton .wg-modal__scroll-region {
  padding: var(--wg-space-5);
  display: flex;
  flex-direction: column;
  gap: var(--wg-space-4);
}

.wg-skeleton {
  background: linear-gradient(
    90deg,
    var(--wg-border) 25%,
    var(--wg-surface-raised) 50%,
    var(--wg-border) 75%
  );
  background-size: 200% 100%;
  animation: wg-shimmer 1.4s ease infinite;
  border-radius: var(--wg-radius-sm);
}

@keyframes wg-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.wg-skeleton--image  { width: 100%; aspect-ratio: 16/9; border-radius: 0; }
.wg-skeleton--title  { height: 28px; width: 70%; }
.wg-skeleton--price  { height: 22px; width: 30%; }
.wg-skeleton--text   { height: 16px; width: 100%; }
.wg-skeleton--text-short { height: 16px; width: 60%; }

/* ── Dark mode ───────────────────────────────────────────────────────────── */
[data-theme="dark"] .wg-modal {
  background-color: var(--wg-surface);
}

[data-theme="dark"] .wg-modal__close {
  background-color: var(--wg-surface-raised);
  border-color: var(--wg-border);
}

[data-theme="dark"] .wg-modal__footer {
  background-color: var(--wg-surface);
  border-top-color: var(--wg-border);
}

[data-theme="dark"] .wg-modal__qty-wrap {
  background-color: var(--wg-surface-raised);
  border-color: var(--wg-border);
}

[data-theme="dark"] .wg-modal__variation-option-label {
  border-color: var(--wg-border);
  color: var(--wg-text);
}

[data-theme="dark"] .wg-modal__option-stepper-btn {
  border-color: var(--wg-border);
  background-color: var(--wg-surface-raised);
}
