/**
 * Gift Product Display Styles
 * Cart row and selection modal for Buy X Get Y free product gifts.
 *
 * Shadcn-style neutral palette. Every colour, size and reset is pinned on the
 * plugin's own classes so the look survives whatever the active theme does to
 * bare `button`, `input`, `h3`, `ul` and `a` elements. Tokens are scoped to the
 * plugin roots and can be overridden by a theme from a higher-level selector.
 */

.yaydp-gift-item,
.yaydp-gift-badge-small,
.yaydp-modal-overlay {
  --yaydp-bg: #ffffff;
  --yaydp-fg: #09090b;
  --yaydp-muted: #f4f4f5;
  --yaydp-muted-fg: #71717a;
  --yaydp-border: #e4e4e7;
  --yaydp-primary: #18181b;
  --yaydp-primary-fg: #fafafa;
  --yaydp-ring: #a1a1aa;
  --yaydp-destructive: #ef4444;
  --yaydp-radius: 8px;
  --yaydp-gift-accent: #16a34a;
}

/* ------------------------------------------------------------------ */
/* Shared controls                                                    */
/* ------------------------------------------------------------------ */

/* Button. The trailing class repeat lifts specificity above the theme's
   `.entry-content button`-style rules without needing !important. */
.yaydp-btn.yaydp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 16px;
  margin: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--yaydp-fg);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0;
  text-transform: none;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    opacity 0.15s ease;
}

.yaydp-btn.yaydp-btn:focus {
  outline: none;
}

.yaydp-btn.yaydp-btn:focus-visible {
  outline: 2px solid var(--yaydp-ring);
  outline-offset: 2px;
}

.yaydp-btn.yaydp-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.yaydp-btn.yaydp-btn-primary {
  background: var(--yaydp-primary);
  border-color: var(--yaydp-primary);
  color: var(--yaydp-primary-fg);
}

.yaydp-btn.yaydp-btn-primary:hover {
  background: color-mix(in srgb, var(--yaydp-primary) 90%, transparent);
  border-color: transparent;
  color: var(--yaydp-primary-fg);
}

.yaydp-btn.yaydp-btn-outline {
  background: var(--yaydp-bg);
  border-color: var(--yaydp-border);
  color: var(--yaydp-fg);
}

.yaydp-btn.yaydp-btn-outline:hover,
.yaydp-btn.yaydp-btn-ghost:hover {
  background: var(--yaydp-muted);
  color: var(--yaydp-fg);
}

.yaydp-btn.yaydp-btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
}

.yaydp-btn.yaydp-btn-icon {
  width: 36px;
  padding: 0;
}

.yaydp-btn.yaydp-btn svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

/* ------------------------------------------------------------------ */
/* Cart row                                                           */
/* ------------------------------------------------------------------ */

.yaydp-gift-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  color: var(--yaydp-fg);
}

/* Badge */
.yaydp-gift-badge,
.yaydp-gift-badge-small {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--yaydp-gift-accent);
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  line-height: 16px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  vertical-align: middle;
}

.yaydp-gift-badge-small {
  padding: 0 8px;
  font-size: 10px;
  margin-right: 6px;
}

.yaydp-gift-title {
  font-weight: 500;
  line-height: 1.4;
}

/* Selected items summary */
.yaydp-gift-selections {
  /* Themes reset lists from an id selector (Divi's #main-content ul), which
     no class chain can beat. */
  list-style: none !important;
  margin: 0 !important;
  padding: 0 !important;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  max-width: 320px;
}

.yaydp-gift-selection-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--yaydp-border);
  border-radius: 6px;
  background: var(--yaydp-muted);
  font-size: 13px;
  line-height: 1.4;
}

.yaydp-gift-selection-qty {
  min-width: 28px;
  color: var(--yaydp-muted-fg);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.yaydp-gift-selection-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.yaydp-gift-none-text {
  color: var(--yaydp-muted-fg);
  font-size: 13px;
}

/* Saving state: the row's items are replaced until the reload renders them. */
.yaydp-gift-selections-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--yaydp-muted-fg);
  font-size: 13px;
}

.yaydp-gift-selections-loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid var(--yaydp-border);
  border-top-color: var(--yaydp-fg);
  border-radius: 50%;
  animation: yaydp-gift-spin 0.7s linear infinite;
}

@keyframes yaydp-gift-spin {
  to {
    transform: rotate(360deg);
  }
}

.yaydp-gift-manage-btn {
  margin-top: 2px;
}

a:has(.yaydp-gift-icon) {
  text-decoration: none !important;
}

/* Gift icon in place of the product thumbnail */
.yaydp-gift-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border: 1px solid var(--yaydp-border, #e4e4e7);
  border-radius: 8px;
  background: var(--yaydp-muted, #f4f4f5);
  font-size: 32px;
  line-height: 1;
}

.yaydp-gift-price,
.yaydp-gift-subtotal {
  color: var(--yaydp-gift-accent, #16a34a);
  font-weight: 500;
}

.yaydp-gift-qty,
.yaydp-gift-qty-readonly {
  display: block;
  font-weight: 500;
  text-align: center;
}

/* ------------------------------------------------------------------ */
/* Modal                                                              */
/* ------------------------------------------------------------------ */

.yaydp-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  padding: 16px;
  background: rgba(0, 0, 0, 0.8);
  z-index: 999999;
  justify-content: center;
  align-items: center;
  color: var(--yaydp-fg);
  font-size: 14px;
  line-height: 1.5;
}

.yaydp-modal-overlay.active {
  display: flex;
  animation: yaydp-fade-in 0.15s ease-out;
}

.yaydp-modal-overlay *,
.yaydp-modal-overlay *::before,
.yaydp-modal-overlay *::after {
  box-sizing: border-box;
}

.yaydp-modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1040px;
  max-height: min(88vh, 88dvh);
  border: 1px solid var(--yaydp-border);
  border-radius: var(--yaydp-radius);
  background: var(--yaydp-bg);
  box-shadow:
    0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -4px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.yaydp-modal-overlay.active .yaydp-modal {
  animation: yaydp-zoom-in 0.2s ease-out;
}

@keyframes yaydp-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes yaydp-zoom-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .yaydp-modal-overlay.active,
  .yaydp-modal-overlay.active .yaydp-modal {
    animation: none;
  }
}

/* Header */
.yaydp-modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--yaydp-border);
}

.yaydp-modal-header h3 {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0;
  color: var(--yaydp-fg);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.yaydp-modal-counter {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--yaydp-muted);
  color: var(--yaydp-fg);
  font-size: 12px;
  font-weight: 600;
  line-height: 16px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.yaydp-modal .yaydp-modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin: 0 -6px 0 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--yaydp-fg);
  box-shadow: none;
  opacity: 0.7;
  cursor: pointer;
  transition:
    opacity 0.15s ease,
    background-color 0.15s ease;
}

.yaydp-modal .yaydp-modal-close:hover {
  background: var(--yaydp-muted);
  opacity: 1;
}

.yaydp-modal .yaydp-modal-close:focus {
  outline: none;
}

.yaydp-modal .yaydp-modal-close:focus-visible {
  outline: 2px solid var(--yaydp-ring);
  outline-offset: 2px;
  opacity: 1;
}

/* Body */
.yaydp-modal-body {
  flex: 1;
  min-height: 0;
  padding: 0 24px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.yaydp-modal-body form {
  margin: 0;
}

/* Footer */
.yaydp-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--yaydp-border);
  background: var(--yaydp-bg);
}

.yaydp-modal-footer-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

/* Search: sticky bar with the magnifier drawn into the field. */
.yaydp-gift-search {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0 0 20px;
  padding: 20px 0 12px;
  background: var(--yaydp-bg);
}

.yaydp-modal .yaydp-gift-search-input {
  display: block;
  width: 100%;
  height: 40px;
  margin: 0;
  padding: 0 12px 0 40px;
  border: 1px solid var(--yaydp-border);
  border-radius: 6px;
  background-color: var(--yaydp-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  background-size: 16px 16px;
  color: var(--yaydp-fg);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: none;
  -webkit-appearance: none;
  appearance: none;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.yaydp-modal .yaydp-gift-search-input::placeholder {
  color: var(--yaydp-muted-fg);
  opacity: 1;
}

.yaydp-modal .yaydp-gift-search-input:focus {
  outline: none;
  border-color: var(--yaydp-ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--yaydp-ring) 40%, transparent);
}

/* Native clear button: hidden until there is something to clear. */
.yaydp-modal .yaydp-gift-search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  cursor: pointer;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 6l12 12M18 6L6 18'/%3E%3C/svg%3E")
    center / 16px 16px no-repeat;
}

.yaydp-gift-search-empty {
  margin: 12px 0 0;
  padding: 0;
  text-align: center;
  color: var(--yaydp-muted-fg);
  font-size: 14px;
}

/* Selected / Available sections */
.yaydp-gift-section + .yaydp-gift-section {
  margin-top: 28px;
}

/* Centred label with a rule running out to each side. */
.yaydp-modal .yaydp-gift-section-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
  padding: 0;
  color: var(--yaydp-muted-fg);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.yaydp-gift-section-title::before,
.yaydp-gift-section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--yaydp-border);
}

/* Product grid */
.yaydp-gift-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
}

/* Fades while the next page is fetched. */
.yaydp-gift-available-grid.is-loading {
  opacity: 0.5;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.yaydp-gift-card {
  /* Column so the stepper can be pinned to the bottom of every card. */
  display: flex;
  flex-direction: column;
  padding: 12px;
  border: 1px solid var(--yaydp-border);
  border-radius: var(--yaydp-radius);
  background: var(--yaydp-bg);
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  text-align: center;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.yaydp-gift-card:hover {
  border-color: var(--yaydp-ring);
}

/* Cards holding a quantity get the primary ring so the Selected row reads at a glance. */
.yaydp-gift-selected-grid .yaydp-gift-card {
  border-color: var(--yaydp-primary);
  box-shadow: 0 0 0 1px var(--yaydp-primary);
}

.yaydp-gift-card.out-of-stock {
  opacity: 0.5;
  pointer-events: none;
}

.yaydp-gift-card-image {
  overflow: hidden;
  border-radius: 6px;
  background: var(--yaydp-muted);
}

.yaydp-gift-card-image img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  margin: 0;
  object-fit: cover;
  border-radius: 0;
  box-shadow: none;
}

.yaydp-gift-card-info {
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* Long names clamp at two lines, and short ones still reserve both, so the
   price and stepper sit at the same height across the row. */
.yaydp-modal .yaydp-gift-card h4 {
  margin: 10px 0 4px;
  padding: 0;
  color: var(--yaydp-fg);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0;
  min-height: 2.7em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.yaydp-modal .yaydp-gift-card h4 a {
  color: inherit;
  text-decoration: none;
  box-shadow: none;
  border: 0;
}

.yaydp-modal .yaydp-gift-card h4 a:hover {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.yaydp-free-label {
  color: var(--yaydp-gift-accent);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* Stepper: minus, field, plus as one control. */
.yaydp-gift-card-qty {
  display: flex;
  justify-content: center;
  align-items: stretch;
  margin-top: auto;
  padding-top: 10px;
}

.yaydp-modal .yaydp-qty-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 32px;
  min-width: 0;
  height: 32px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--yaydp-border);
  background: var(--yaydp-bg);
  color: var(--yaydp-fg);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  line-height: 1;
  box-shadow: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: background-color 0.15s ease;
}

.yaydp-modal .yaydp-qty-minus {
  border-radius: 6px 0 0 6px;
}

.yaydp-modal .yaydp-qty-plus {
  border-radius: 0 6px 6px 0;
}

.yaydp-modal .yaydp-qty-step:hover:not(:disabled) {
  background: var(--yaydp-muted);
}

.yaydp-modal .yaydp-qty-step:focus {
  outline: none;
}

.yaydp-modal .yaydp-qty-step:focus-visible {
  outline: 2px solid var(--yaydp-ring);
  outline-offset: 2px;
  z-index: 1;
}

.yaydp-modal .yaydp-qty-step:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.yaydp-modal .yaydp-gift-qty-input {
  width: 44px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--yaydp-border);
  border-left: 0;
  border-right: 0;
  border-radius: 0;
  background: var(--yaydp-bg);
  color: var(--yaydp-fg);
  /* Themes commonly put an inset shadow on inputs; the stepper wants a flat field. */
  box-shadow: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
  -webkit-appearance: none;
  appearance: none;
  -moz-appearance: textfield;
}

.yaydp-modal .yaydp-gift-qty-input:focus {
  outline: none;
  border-color: var(--yaydp-ring);
  box-shadow: inset 0 0 0 1px var(--yaydp-ring);
}

.yaydp-modal .yaydp-gift-qty-input:disabled {
  background: var(--yaydp-muted);
  opacity: 0.6;
  cursor: not-allowed;
}

/* The buttons replace the native spinners. */
.yaydp-modal .yaydp-gift-qty-input::-webkit-outer-spin-button,
.yaydp-modal .yaydp-gift-qty-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.yaydp-variation-select {
  width: 100%;
  margin-top: 8px;
}

.yaydp-out-of-stock-label {
  display: block;
  margin-top: 10px;
  color: var(--yaydp-destructive);
  font-size: 12px;
  font-weight: 500;
}

/* Variation attributes inside a gift card */
.yaydp-gift-card-attributes {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  color: var(--yaydp-muted-fg);
  font-size: 12px;
}

/* Pagination */
.yaydp-gift-pagination {
  display: flex;
  align-items: center;
  gap: 8px;
}

.yaydp-gift-pagination .yaydp-page-info {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--yaydp-muted-fg);
  font-size: 14px;
  font-weight: 400;
}

.yaydp-gift-pagination .yaydp-page-total {
  color: var(--yaydp-fg);
  font-weight: 500;
}

.yaydp-modal .yaydp-page-input {
  width: 52px;
  height: 36px;
  margin: 0;
  padding: 0 6px;
  border: 1px solid var(--yaydp-border);
  border-radius: 6px;
  background: var(--yaydp-bg);
  color: var(--yaydp-fg);
  /* Themes commonly put an inset shadow on inputs; the field wants to be flat. */
  box-shadow: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
  -webkit-appearance: none;
  appearance: none;
  -moz-appearance: textfield;
}

.yaydp-modal .yaydp-page-input:focus {
  outline: none;
  border-color: var(--yaydp-ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--yaydp-ring) 40%, transparent);
}

.yaydp-modal .yaydp-page-input::-webkit-outer-spin-button,
.yaydp-modal .yaydp-page-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ------------------------------------------------------------------ */
/* Responsive                                                         */
/* ------------------------------------------------------------------ */

@media (max-width: 1024px) {
  .yaydp-gift-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .yaydp-modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  /* Bottom sheet on phones. */
  .yaydp-modal {
    max-height: min(92vh, 92dvh);
    border-radius: var(--yaydp-radius) var(--yaydp-radius) 0 0;
    border-bottom: 0;
  }

  .yaydp-modal-header,
  .yaydp-modal-footer {
    padding: 16px;
  }

  .yaydp-modal-body {
    padding: 0 16px 16px;
  }

  .yaydp-gift-search {
    padding-top: 16px;
  }

  /* iOS zooms the page in on any field under 16px. */
  .yaydp-modal .yaydp-gift-search-input,
  .yaydp-modal .yaydp-page-input,
  .yaydp-modal .yaydp-gift-qty-input {
    font-size: 16px;
  }

  .yaydp-gift-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .yaydp-modal-footer-actions {
    width: 100%;
  }

  .yaydp-modal-footer-actions .yaydp-btn {
    flex: 1;
  }

  .yaydp-gift-selections {
    max-width: none;
  }
}
