/* ============================================
   BOTTOM SHEET - Mobile Native Commerce UX
   Shopify/iOS-grade bottom sheet with snap behavior
   ============================================ */

/* ========== Overlay ========== */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
  z-index: 9998;
  -webkit-tap-highlight-color: transparent;
}

.sheet-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ========== Sheet Container ========== */
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100dvh;
  height: calc(var(--vh, 1vh) * 100); /* iOS fallback */
  transform: translateY(100%);
  border-radius: 22px 22px 0 0;
  background: var(--bg-primary, #fff);
  z-index: 9999;
  
  display: flex;
  flex-direction: column;
  touch-action: none;
  will-change: transform;
  transition: transform 200ms cubic-bezier(0.25, 0.8, 0.25, 1);
  
  /* iOS safe area */
  padding-bottom: env(safe-area-inset-bottom, 0);
  
  /* Shadow for depth */
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.15);
}

/* Snap to 75% height */
.sheet.snap-75 {
  transform: translateY(25dvh);
  transform: translateY(calc(var(--vh, 1vh) * 25));
}

/* Fully open */
.sheet.open {
  transform: translateY(0);
}

/* ========== Handle Indicator ========== */
.sheet__handle {
  width: 42px;
  height: 5px;
  background: var(--gray-300, #ccc);
  border-radius: 100px;
  margin: 10px auto 6px;
  flex-shrink: 0;
  cursor: grab;
}

.sheet__handle:active {
  cursor: grabbing;
  background: var(--gray-400, #999);
}

/* ========== Header ========== */
.sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem 0.75rem;
  border-bottom: 1px solid var(--gray-200, #e5e5e5);
  flex-shrink: 0;
}

.sheet__title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary, #1a1a1a);
  margin: 0;
}

.sheet__close {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--gray-100, #f5f5f5);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms ease, transform 150ms ease;
}

.sheet__close:hover {
  background: var(--gray-200, #e5e5e5);
}

.sheet__close:active {
  transform: scale(0.95);
}

.sheet__close svg {
  width: 18px;
  height: 18px;
  color: var(--gray-600, #666);
}

/* ========== Scrollable Content ========== */
.sheet__content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 1rem 1rem calc(1.5rem + env(safe-area-inset-bottom, 0));
}

/* ========== Footer (sticky actions) ========== */
.sheet__footer {
  flex-shrink: 0;
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--gray-200, #e5e5e5);
  background: var(--bg-primary, #fff);
}

/* ========== Desktop: Keep centered modal style ========== */
@media (min-width: 768px) {
  .sheet {
    left: 50%;
    right: auto;
    bottom: 0;
    height: 92vh;
    max-width: 480px;
    width: 100%;
    transform: translate(-50%, 100%);
    border-radius: 14px 14px 0 0;
  }
  
  .sheet.snap-75 {
    transform: translate(-50%, 25vh);
  }
  
  .sheet.open {
    transform: translate(-50%, 0);
  }
  
  .sheet__handle {
    display: none; /* No drag handle on desktop */
  }
}

/* ========== Dark Mode Support ========== */
[data-theme="dark"] .sheet,
.dark-mode .sheet {
  background: var(--bg-secondary, #1a1a1a);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .sheet__header,
.dark-mode .sheet__header,
[data-theme="dark"] .sheet__footer,
.dark-mode .sheet__footer {
  border-color: var(--gray-700, #333);
}

[data-theme="dark"] .sheet__close,
.dark-mode .sheet__close {
  background: var(--gray-800, #2a2a2a);
}

[data-theme="dark"] .sheet__close:hover,
.dark-mode .sheet__close:hover {
  background: var(--gray-700, #333);
}

/* ========== Animation States ========== */
@keyframes sheetSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes sheetSlideDown {
  from { transform: translateY(0); }
  to { transform: translateY(100%); }
}

/* Prevent body scroll when sheet is open */
body.sheet-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ============================================
   CART-SPECIFIC SHEET STYLING
   Merges bottom sheet with existing cart styles
   ============================================ */
.sheet.cart-modal .cart-header {
  padding: 0.5rem 1rem 0.75rem;
  border-bottom: 1px solid var(--gray-200, #e5e5e5);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet.cart-modal .cart-header-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sheet.cart-modal .cart-header-content h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
}

.sheet.cart-modal .cart-body {
  padding: 0;
}

.sheet.cart-modal .free-shipping-progress {
  padding: 0.75rem 1rem;
  background: var(--gray-50, #f9f9f9);
  border-bottom: 1px solid var(--gray-100, #eee);
}

.sheet.cart-modal .cart-items {
  padding: 0.5rem 1rem;
}

.sheet.cart-modal .cart-footer {
  border-top: 1px solid var(--gray-200, #e5e5e5);
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
}

.sheet.cart-modal .cart-summary {
  margin-bottom: 1rem;
}

.sheet.cart-modal .cart-actions {
  display: flex;
  gap: 0.75rem;
}

.sheet.cart-modal .cart-actions .btn {
  flex: 1;
}

.sheet.cart-modal .cart-trust-signals {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: var(--gray-500, #666);
}
