/* Kraftrs Promotions — Custom Cart Drawer
 * Plugin-owned floating trigger + slide-in drawer. Reuses the .kp-drawer-overlay
 * / .kp-drawer-container / .kp-drawer-close shell already defined in
 * gift-popup.css; this file adds the trigger button and cart-specific content.
 */

/* ── Cart Trigger — base (shared by the floating button and any number of
   widget-placed instances; click handling in cart-drawer.js binds by this
   class, not an id, so multiple triggers can coexist on one page) ── */
.kp-cart-trigger {
  position: relative;
  border: none;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  font-family: var(--kp-font, inherit);
}

.kp-drawer-trigger-icon {
  font-size: 22px;
  line-height: 1;
}

.kp-drawer-trigger-count {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border-radius: 10px;
  background: var(--kp-drawer-badge-bg, #111);
  color: var(--kp-drawer-badge-text, #fff);
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}

/* ── Floating variant (the default trigger, fixed to a screen corner) ── */
.kp-drawer-trigger {
  position: fixed;
  bottom: 20px;
  z-index: 999997;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  /* --kp-drawer-accent lets the cart button be styled independently of the
     global brand color; falls through to --kp-primary when unset. */
  background: var(--kp-drawer-accent, var(--kp-primary, #f5a623));
  color: var(--kp-drawer-accent-text, #fff);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.kp-drawer-trigger .kp-drawer-trigger-icon {
  font-size: 24px;
}

.kp-drawer-trigger:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.kp-drawer-trigger--bottom-right {
  right: 20px;
}

.kp-drawer-trigger--bottom-left {
  left: 20px;
}

/* ── Widget variant — sits inline wherever it's placed (e.g. a header
   widget area), so it inherits the surrounding theme's text color/size
   rather than imposing the floating button's fixed brand-color circle. ── */
.kp-cart-trigger--widget {
  color: inherit;
}

.kp-drawer-trigger-count:empty,
.kp-drawer-trigger-count[data-kp-drawer-count="0"] {
  display: none;
}

/* ── Drawer container (extends the shared .kp-drawer-container shell) ── */
.kp-cart-drawer-container {
  max-width: 420px;
  font-family: var(--kp-font, inherit);
  display: flex;
  flex-direction: column;
  /* If the theme sets a dark color-scheme on :root when the visitor's
     system is in dark mode, browsers auto-darken native form control
     chrome (input backgrounds, scrollbars, date pickers) inside this
     drawer even though every color here is our own fixed light palette —
     that mismatch (dark-styled native inputs on our light drawer) was
     part of what "broke" the checkout look. Pinning this explicitly
     stops that inheritance regardless of what the theme declares. */
  color-scheme: light;
}

/* Flex column: .kp-drawer-scroll-area (flex:1, its own scrollbar) +
   .kp-drawer-footer (fixed height, always last) as two independent
   children — this is what actually pins Checkout to the drawer's true
   bottom edge regardless of how much/little content is above it. See the
   comment in cart-drawer-content.php for why position:sticky alone
   couldn't do this. */
.kp-cart-drawer-content {
  flex: 1;
  min-height: 0; /* required for the flex child below to be allowed to scroll instead of overflowing */
  display: flex;
  flex-direction: column;
  padding: 0;
}

.kp-drawer-scroll-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px 0;
}

.kp-cart-drawer-loading {
  text-align: center;
  padding: 40px 0;
  color: var(--kp-text-light, #6b7280);
}

/* ── Header logo (optional, merchant-supplied) ── */
.kp-drawer-header {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.kp-drawer-logo {
  max-height: 28px;
  width: auto;
  flex-shrink: 0;
}

/* ── Skeleton loader — shown until the first AJAX fetch resolves. Reads as
   the cart materializing in place instead of a bare "Loading..." string. ── */
.kp-drawer-skeleton {
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* .kp-cart-drawer-content itself has padding:0 now (the real padding lives
     on .kp-drawer-scroll-area once real content replaces this on first
     fetch) — this placeholder needs its own matching inset. */
  padding: 20px 24px 4px;
}

.kp-skeleton-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.kp-skeleton-thumb {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  flex-shrink: 0;
}

.kp-skeleton-lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kp-skeleton-lines i {
  display: block;
  height: 10px;
  border-radius: 4px;
}

.kp-skeleton-lines i:first-child { width: 70%; }
.kp-skeleton-lines i:last-child  { width: 40%; }

.kp-skeleton-thumb,
.kp-skeleton-lines i {
  background: linear-gradient(90deg, rgba(0,0,0,.06) 25%, rgba(0,0,0,.12) 37%, rgba(0,0,0,.06) 63%);
  background-size: 400% 100%;
  animation: kp-skeleton-shimmer 1.4s ease infinite;
}

@keyframes kp-skeleton-shimmer {
  0%   { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

@media (prefers-reduced-motion: reduce) {
  .kp-skeleton-thumb,
  .kp-skeleton-lines i {
    animation: none;
  }
}

/* ── Visible keyboard focus. The drawer is a dialog with a focus trap, so
   focus must be visible or keyboard users can't tell where they are.
   :focus-visible keeps it from firing on mouse clicks. ── */
.kp-cart-trigger:focus-visible,
.kp-drawer-close:focus-visible,
.kp-drawer-qty-btn:focus-visible,
.kp-drawer-item-remove:focus-visible,
.kp-drawer-coupon-input:focus-visible,
.kp-drawer-coupon-apply:focus-visible,
.kp-drawer-checkout-btn:focus-visible,
.kp-drawer-view-cart-link:focus-visible,
.kp-drawer-continue-shopping:focus-visible {
  outline: 2px solid var(--kp-drawer-accent, var(--kp-primary, #f5a623));
  outline-offset: 2px;
}

/* WP core utility class isn't guaranteed present on every theme. */
.kp-cart-drawer-content .screen-reader-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  white-space: nowrap;
}

.kp-drawer-empty-state {
  text-align: center;
  padding: 60px 20px;
}

.kp-drawer-empty-icon {
  display: block;
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.kp-drawer-empty {
  color: var(--kp-text-light, #6b7280);
  margin: 0 0 16px;
}

.kp-drawer-continue-shopping {
  display: inline-block;
  padding: 10px 24px;
  border-radius: 8px;
  background: var(--kp-drawer-accent, var(--kp-primary, #f5a623));
  color: var(--kp-drawer-accent-text, #fff);
  font-weight: 700;
  text-decoration: none;
  font-size: 0.85rem;
  transition: opacity 0.15s ease;
}

.kp-drawer-continue-shopping:hover {
  opacity: 0.9;
  color: #fff;
}

/* ── Item rows ── */
.kp-drawer-items {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}

.kp-drawer-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  animation: kp-drawer-item-in 0.25s ease both;
  transition: opacity 0.2s ease, transform 0.2s ease, max-height 0.2s ease, margin 0.2s ease;
}

.kp-drawer-item--removing {
  opacity: 0;
  transform: translateX(12px);
}

@keyframes kp-drawer-item-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.kp-drawer-item-image {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  display: block;
}

.kp-drawer-item-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.kp-drawer-item-info {
  flex: 1;
  min-width: 0;
}

.kp-drawer-item-name {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--kp-text, #1f2937);
  text-decoration: none;
  margin-bottom: 6px;
}

.kp-drawer-item-name:hover {
  color: var(--kp-primary, #f5a623);
}

.kp-drawer-item-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--kp-success, #10b981);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-right: 8px;
}

.kp-drawer-item-qty-static {
  font-size: 0.8rem;
  color: var(--kp-text-light, #6b7280);
}

.kp-drawer-item-qty {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--kp-border, #e5e7eb);
  border-radius: 6px;
  padding: 2px 4px;
}

.kp-drawer-qty-btn {
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--kp-text, #1f2937);
  font-size: 14px;
  cursor: pointer;
  border-radius: 4px;
}

.kp-drawer-qty-btn {
  transition: background 0.15s ease, transform 0.1s ease;
}

.kp-drawer-qty-btn:hover {
  background: var(--kp-bg, #f9fafb);
}

.kp-drawer-qty-btn:active {
  transform: scale(0.88);
}

.kp-drawer-qty-value {
  min-width: 16px;
  text-align: center;
  font-size: 0.85rem;
}

.kp-drawer-item-price {
  flex-shrink: 0;
  text-align: right;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--kp-text, #1f2937);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.kp-drawer-item-was-price {
  color: var(--kp-text-light, #6b7280);
  font-weight: 500;
  font-size: 0.8rem;
  text-decoration: line-through;
}

.kp-drawer-item-free-label {
  color: var(--kp-success, #10b981);
  font-weight: 800;
  font-size: 0.85rem;
}

.kp-drawer-item-remove {
  border: none;
  background: transparent;
  color: var(--kp-text-light, #6b7280);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  padding: 2px;
}

.kp-drawer-item-remove:hover {
  color: var(--kp-danger, #ef4444);
}

/* ── Sticky footer: coupon + totals + checkout, always visible, item list
   scrolls independently above it (position:sticky within the scrolling
   .kp-cart-drawer-content — no separate AJAX region needed). ── */
.kp-drawer-footer {
  /* Plain flex child now (see .kp-cart-drawer-content above) — no longer
     sticky/nested inside the scrolling area, no negative-margin trick
     needed since it's not clawing back the scroll-area's own padding. */
  flex-shrink: 0;
  background: #fff;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--kp-border, #e5e7eb);
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.04);
}

/* ── Coupon ── */
.kp-drawer-coupon {
  margin-bottom: 16px;
}

.kp-drawer-coupon-form {
  display: flex;
  gap: 8px;
}

.kp-drawer-coupon-input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--kp-border, #e5e7eb);
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
}

.kp-drawer-coupon-input:focus {
  outline: none;
  border-color: var(--kp-primary, #f5a623);
}

.kp-drawer-coupon-apply {
  padding: 0 16px;
  height: 38px;
  border: none;
  border-radius: 6px;
  background: #111111;
  color: #fff;
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
  transition: opacity 0.15s ease;
  white-space: nowrap;
}

.kp-drawer-coupon-apply:hover {
  opacity: 0.85;
}

.kp-drawer-coupon-apply:disabled {
  opacity: 0.5;
  cursor: default;
}

.kp-drawer-coupon-message {
  margin: 6px 0 0;
  font-size: 0.78rem;
  min-height: 1em;
}

.kp-drawer-coupon-message.kp-error {
  color: var(--kp-danger, #ef4444);
}

.kp-drawer-coupon-message.kp-success {
  color: var(--kp-success, #10b981);
}

.kp-drawer-coupon-applied {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  font-size: 0.8rem;
}

.kp-drawer-coupon-icon {
  font-size: 0.9rem;
}

.kp-drawer-coupon-code {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.kp-drawer-coupon-discount {
  color: #16a34a;
  margin-left: auto;
}

.kp-drawer-coupon-remove {
  border: none;
  background: transparent;
  color: var(--kp-text-light, #6b7280);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
}

.kp-drawer-coupon-remove:hover {
  color: var(--kp-danger, #ef4444);
}

/* ── Totals & checkout ── */
.kp-drawer-totals {
  border-top: 1px solid var(--kp-border, #e5e7eb);
  padding-top: 16px;
}

.kp-drawer-totals-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.kp-drawer-totals-row--total {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--kp-text, #1f2937);
}

/* Explicit line for each applied discount fee — previously Subtotal jumped
   straight to a lower Total with no line explaining the gap. */
.kp-drawer-totals-row--discount {
  color: var(--kp-success, #10b981);
  font-weight: 600;
}

.kp-drawer-tax-note {
  font-size: 0.72rem;
  color: var(--kp-text-light, #6b7280);
  text-align: center;
  margin: 0 0 4px;
}

.kp-drawer-checkout-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-top: 12px;
  padding: 14px 18px;
  border-radius: 8px;
  background: var(--kp-drawer-accent, var(--kp-primary, #f5a623));
  color: var(--kp-drawer-accent-text, #fff);
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.kp-drawer-checkout-total {
  font-weight: 800;
}

.kp-drawer-checkout-btn:hover {
  opacity: 0.92;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.kp-drawer-checkout-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.kp-drawer-view-cart-link {
  display: block;
  text-align: center;
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--kp-text-light, #6b7280);
  text-decoration: underline;
  transition: color 0.15s ease;
}

.kp-drawer-view-cart-link:hover {
  color: var(--kp-primary, #f5a623);
}

/* Notices/progress bar reused inside the drawer read a bit tighter than full-page. */
.kp-cart-drawer-content .kp-cart-notice,
.kp-cart-drawer-content .kp-progress-wrap {
  margin-bottom: 8px;
}

/* Extra-compact inside the drawer specifically — offers/nudges sit directly
   above the cart items here (unlike the toast, a standalone floating card),
   so they need to read as a quiet header strip, not compete with the items
   for attention. */
.kp-cart-drawer-content .kp-tier-progress {
  padding: 8px 12px;
  margin-bottom: 6px;
}

.kp-cart-drawer-content .kp-tier-message,
.kp-cart-drawer-content .kp-tier-achieved {
  font-size: 0.76rem;
}

.kp-cart-drawer-content .kp-progress-bar-track {
  height: 5px;
}

/* The "spend more to unlock" nudge dismiss button (progress-bar.php is shared
   between the toast and the drawer, but toast.css only scopes styling to
   .kp-toast-content — without this, the button renders unstyled/default here). */
.kp-cart-drawer-content .kp-nudge-dismiss {
  display: inline-block;
  width: auto;
  margin-top: 4px;
  padding: 2px 0;
  border: none;
  background: transparent;
  color: var(--kp-text-light, #6b7280);
  font-family: inherit;
  font-size: 0.7rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  transition: color 0.15s ease;
}

.kp-cart-drawer-content .kp-nudge-dismiss:hover {
  color: var(--kp-text, #1f2937);
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .kp-drawer-trigger {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    width: 52px;
    height: 52px;
  }

  .kp-drawer-trigger--bottom-right {
    right: calc(16px + env(safe-area-inset-right, 0px));
  }

  .kp-drawer-trigger--bottom-left {
    left: calc(16px + env(safe-area-inset-left, 0px));
  }

  .kp-cart-drawer-container {
    max-width: 100%;
    width: 100%;
  }

  /* Touch targets below ~44px are hard to hit reliably on a phone (WCAG
     2.5.5) — 22px qty buttons and an unpadded 16px remove × were both well
     under that on the one surface where precision matters least (a moving
     bus, one thumb, etc.). Desktop keeps the original compact sizing. */
  .kp-drawer-qty-btn {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  .kp-drawer-item-remove {
    padding: 10px;
    margin: -10px;
    font-size: 18px;
  }

  .kp-drawer-coupon-apply,
  .kp-drawer-checkout-btn,
  .kp-offers-rail-close,
  .kp-drawer-close {
    min-height: 44px;
  }

  .kp-drawer-scroll-area,
  .kp-drawer-skeleton {
    padding-left: 16px;
    padding-right: 16px;
  }

  /* iPhone home-indicator / gesture-nav area — without the bottom inset the
     footer's Checkout button sits flush against it. */
  .kp-drawer-footer {
    padding-left: 16px;
    padding-right: 16px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }

  /* Item rows: on very narrow phones (iPhone SE, budget Android ~360px and
     below) the image + name + price three-column layout got tight enough
     that the price/remove-× column could crowd the qty stepper. Shrinking
     the thumbnail buys back room without changing the layout structure. */
  .kp-drawer-item-image {
    width: 52px;
    height: 52px;
  }
}

@media (max-width: 360px) {
  .kp-drawer-scroll-area,
  .kp-drawer-skeleton,
  .kp-drawer-footer {
    padding-left: 12px;
    padding-right: 12px;
  }

  .kp-drawer-item-name {
    font-size: 0.85rem;
  }
}

/* Intentionally no @media (prefers-color-scheme: dark) block. It used to
   flip .kp-cart-drawer-container to a dark background but only remapped a
   handful of text colors (item name, totals-row--total, coupon input) —
   everything else (item price, qty value, coupon message, subtotal row,
   tax note, etc.) kept its light-mode dark-on-white color, which against
   the new dark background became dark-text-on-dark-background: unreadable.
   Rather than track down and dark-mode every single text/border color in
   this file (and keep it in sync as new elements are added), the drawer
   now always renders its light palette regardless of the visitor's system
   theme — guaranteed readable, at the cost of not matching a dark OS/
   browser theme. */
