/* ==========================================================================
   WooGrub — cart.css
   Floating cart: collapsed icon, expanded panel, mobile bottom sheet.
   ========================================================================== */

/* ── Floating cart wrapper ───────────────────────────────────────────────── */
.wg-floating-cart {
  position: fixed;
  bottom: var(--wg-space-6);
  right: var(--wg-space-6);
  /* No z-index on wrapper — would create a stacking context that traps children.
     Toggle and panel each declare their own z-index independently. */

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

@media (max-width: 767px) {
  .wg-floating-cart {
    bottom: calc( var(--wg-space-4) + env(safe-area-inset-bottom, 0px) );
    right: var(--wg-space-4);
  }
}

/* ── Toggle button — collapsed state ─────────────────────────────────────── */
.wg-floating-cart__toggle {
  position: relative;
  z-index: var(--wg-z-cart-toggle);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: var(--wg-radius-full);
  background-color: var(--wg-cart-btn-bg);
  color: var(--wg-cart-icon-color);
  box-shadow: var(--wg-shadow-lg);
  border: none;
  cursor: pointer;
  transition:
    background-color var(--wg-transition),
    transform var(--wg-transition),
    box-shadow var(--wg-transition);
  z-index: 1;
}

@media (hover: hover) {
  .wg-floating-cart__toggle:hover {
    background-color: var(--wg-cart-btn-hover-bg);
    transform: scale(1.05);
    box-shadow: var(--wg-shadow-overlay);
  }
}

.wg-floating-cart__toggle:active {
  transform: scale(0.97);
}

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

/* Hide toggle when panel is open */
.wg-floating-cart.is-open .wg-floating-cart__toggle {
  pointer-events: none;
  opacity: 0;
  transform: scale(0.8);
}

/* ── Badge ───────────────────────────────────────────────────────────────── */
.wg-cart-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding-inline: 4px;
  border-radius: var(--wg-radius-full);
  background-color: var(--wg-cart-badge-bg);
  color: var(--wg-text-on-primary);
  font-size: 0.6875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--wg-surface);
  line-height: 1;
}

/* Pill shape at 10+ items */
.wg-cart-badge--pill {
  border-radius: var(--wg-radius-full);
  padding-inline: var(--wg-space-2);
  font-size: 0.625rem;
}

/* ── Expanded panel — desktop: slides up from bottom-right ──────────────── */
.wg-floating-cart__panel {
  position: fixed;
  bottom: 0;
  right: var(--wg-space-6);
  width: 460px;
  max-height: 65vh;
  min-height: 120px;
  background-color: var(--wg-surface);
  border-radius: var(--wg-radius-lg) var(--wg-radius-lg) 0 0;
  box-shadow: var(--wg-shadow-overlay);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--wg-border);
  border-bottom: none;
  z-index: var(--wg-z-cart);

  /* Slides up from below the viewport */
  transform: translateY(100%);
  transition: transform var(--wg-transition-slow);
  pointer-events: none;
}

.wg-floating-cart__panel.is-open {
  transform: translateY(0);
  pointer-events: auto;
}

.wg-floating-cart__panel[hidden] {
  display: flex; /* keep in flow so transition works; visibility hides it */
  visibility: hidden;
}

.wg-floating-cart__panel.is-open[hidden] {
  visibility: visible;
}

/* ── Expanded panel — mobile: full-screen bottom sheet ───────────────────── */
@media (max-width: 767px) {
  .wg-floating-cart__panel {
    right: 0;
    left: 0;
    width: 100%;
    max-height: 90dvh;

    border-radius: var(--wg-radius-lg) var(--wg-radius-lg) 0 0;
    border: none;
    border-top: 1px solid var(--wg-border);
  }

  .wg-floating-cart__panel.is-open {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ── Drag handle (mobile) ────────────────────────────────────────────────── */
.wg-floating-cart__drag-handle {
  display: none;
  justify-content: center;
  padding-top: var(--wg-space-3);
  padding-bottom: var(--wg-space-2);
  flex-shrink: 0;
  cursor: grab;
  /* Larger touch target */
  padding-left: var(--wg-space-8);
  padding-right: var(--wg-space-8);
}

.wg-floating-cart__drag-handle:active {
  cursor: grabbing;
}

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

@media (max-width: 767px) {
  .wg-floating-cart__drag-handle {
    display: flex;
  }
}

/* ── Panel header ────────────────────────────────────────────────────────── */
.wg-floating-cart__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--wg-space-4) var(--wg-space-5);
  border-bottom: 1px solid var(--wg-border);
  flex-shrink: 0;
}

.wg-floating-cart__title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--wg-text);
  margin: 0;
}

.wg-floating-cart__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--wg-radius-full);
  background: transparent;
  color: var(--wg-text-muted);
  border: none;
  cursor: pointer;
  transition: background-color var(--wg-transition), color var(--wg-transition);
}

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

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

/* ── Items list ──────────────────────────────────────────────────────────── */
.wg-floating-cart__items {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: var(--wg-space-3) var(--wg-space-5);
  display: flex;
  flex-direction: column;
  gap: var(--wg-space-1);
  /* Minimum height matches the empty state so the cart never shrinks
     below the empty state height regardless of how many items are in it */
  min-height: 80px;
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.wg-floating-cart__empty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--wg-space-3) 0;
  color: var(--wg-text-muted);
  font-size: 0.9375rem;
}

/* ── Line item ───────────────────────────────────────────────────────────── */
.wg-floating-cart__item {
  display: flex;
  align-items: center;
  gap: var(--wg-space-3);
  padding-block: var(--wg-space-3);
  border-bottom: 1px solid var(--wg-border);
}

.wg-floating-cart__item:last-child {
  border-bottom: none;
}

.wg-floating-cart__item-info {
  flex: 1;
  min-width: 0;
}

.wg-floating-cart__item-name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--wg-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}

.wg-floating-cart__item-variation {
  display: inline-flex;
  align-items: center;
  margin: var(--wg-space-1) 0 0;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--wg-text-muted);
  background-color: var(--wg-bg);
  border: 1px solid var(--wg-border);
  border-radius: var(--wg-radius-full);
  padding: 1px var(--wg-space-2);
  line-height: 1.5;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wg-floating-cart__item-options {
  font-size: 0.8125rem;
  color: var(--wg-text-muted);
  margin: var(--wg-space-1) 0 0;
  white-space: normal;
  line-height: 1.4;
}

/* ── Item controls: stepper + total + remove ─────────────────────────────── */
.wg-floating-cart__item-controls {
  display: flex;
  align-items: center;
  gap: var(--wg-space-2);
  flex-shrink: 0;
  margin-left: auto;
}

.wg-floating-cart__item-qty {
  display: flex;
  align-items: center;
  gap: var(--wg-space-1);
  background-color: var(--wg-bg);
  border: 1px solid var(--wg-border);
  border-radius: var(--wg-radius-full);
  padding: 2px var(--wg-space-1);
  flex-shrink: 0;
}

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

@media (hover: hover) {
  .wg-floating-cart__qty-btn:hover {
    background-color: var(--wg-primary);
    color: var(--wg-text-on-primary);
  }
}

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

.wg-floating-cart__qty-value {
  font-size: 0.8125rem;
  font-weight: 600;
  min-width: 16px;
  text-align: center;
}

.wg-floating-cart__item-total {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--wg-text);
  width: 64px;
  text-align: right;
  flex-shrink: 0;
}

.wg-floating-cart__remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--wg-radius-full);
  background: transparent;
  color: var(--wg-text-muted);
  border: none;
  cursor: pointer;
  transition: color var(--wg-transition), background-color var(--wg-transition);
}

.wg-floating-cart__remove:hover {
  color: #dc2626;
  background-color: #fef2f2;
}

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

/* ── Panel footer ────────────────────────────────────────────────────────── */
.wg-floating-cart__footer {
  padding: var(--wg-space-4) var(--wg-space-5);
  border-top: 1px solid var(--wg-border);
  background-color: var(--wg-surface);
  flex-shrink: 0;
  padding-bottom: calc( var(--wg-space-4) + env(safe-area-inset-bottom, 0px) );
}

/* ── Checkout button ─────────────────────────────────────────────────────── */
.wg-floating-cart__checkout-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--wg-space-3) var(--wg-space-5);
  background-color: var(--wg-checkout-bg);
  color: var(--wg-text-on-primary);
  border-radius: var(--wg-radius-full);
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color var(--wg-transition), transform var(--wg-transition);
}

.wg-floating-cart__checkout-btn:hover {
  background-color: var(--wg-checkout-hover-bg);
  color: var(--wg-text-on-primary);
}

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

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

/* Disabled state when cart is empty */
.wg-floating-cart__checkout-btn.is-disabled {
  background-color: var(--wg-border);
  color: var(--wg-text-muted);
  pointer-events: none;
  cursor: not-allowed;
}

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

[data-theme="dark"] .wg-floating-cart__header {
  border-bottom-color: var(--wg-border);
}

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

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

[data-theme="dark"] .wg-floating-cart__remove:hover {
  background-color: rgba(220, 38, 38, 0.15);
  color: #f87171;
}

[data-theme="dark"] .wg-floating-cart__checkout-btn.is-disabled {
  background-color: var(--wg-surface-raised);
  color: var(--wg-text-muted);
}
