/* checkout.css - Shared PayPal modal and checkout styles */

/* 
 * PayPal Modal Management:
 * - Product page modals: Defined in HTML (product.html, index.html) for direct product checkout
 * - Cart drawer modals: Defined in HTML within cart drawer component scope for proper Alpine.js binding
 * - All modals share the same CSS classes (.modal, .pp-modal, .sheet, etc.)
 * 
 * Note: Cart modals must be in HTML (not JS-created) because Alpine.js needs to process
 * the x-show, x-transition, and @click directives at initialization time.
 */

/* =============================================================================
   MODAL OVERLAY SYSTEM
   ============================================================================= */

/* Main modal backdrop - creates dark overlay covering entire screen */
.modal {
  position: fixed;        /* Fixed positioning to cover entire viewport */
  inset: 0;              /* Shorthand for top: 0, right: 0, bottom: 0, left: 0 */
  background: rgba(0, 0, 0, 0.35);  /* Semi-transparent dark background */
  display: flex;          /* Flexbox for centering content */
  align-items: center;    /* Center vertically */
  justify-content: center; /* Center horizontally */
  padding: 18px;         /* Padding around modal content */
  z-index: 50;           /* High z-index to appear above other content */
}

/* Modal content container - the white box that appears in center */
.sheet {
  background: #fff;              /* White background for modal content */
  border-radius: 18px;           /* Rounded corners */
  max-width: 520px;             /* Maximum width constraint */
  width: 100%;                  /* Take full available width up to max-width */
  box-shadow: var(--shadow);     /* Drop shadow effect (defined in shared-styles.css) */
  border: 1px solid var(--border); /* Border color (defined in shared-styles.css) */
  /* Stabilize modal vertical layout */
  display: flex;                 /* Make modal a flex column */
  flex-direction: column;
  max-height: 90vh;             /* Prevent modal from exceeding viewport height */
  overflow: hidden;             /* Let body scroll internally */
}

/* Modal header section */
.sheet .hd {
  padding: 18px 18px 0;         /* Padding: top/sides 18px, bottom 0 */
  flex-shrink: 0;               /* Prevent header from shrinking */
}

/* Modal body section - main content area */
.sheet .bd {
  padding: 18px;                /* Equal padding on all sides */
  flex: 1 1 auto;               /* Allow body to grow/shrink */
  min-height: 0;                /* Critical for flex children to shrink */
  overflow-y: auto;             /* Scroll inside modal body instead of page */
  overscroll-behavior: contain; /* Avoid scroll chaining */
  scrollbar-gutter: stable;     /* Prevent width jumps when scrollbar toggles */
}

/* Modal footer section */
.sheet .ft {
  padding: 0 18px 18px;         /* Padding: top 0, sides/bottom 18px */
  flex-shrink: 0;               /* Prevent footer from shrinking */
}

/* PayPal specific modal sizing - slightly narrower than default */
.pp-modal .sheet {
  max-width: 480px;             /* Smaller max-width for PayPal checkout */
}

/* =============================================================================
   CART DRAWER (RIGHT SIDE)
   ============================================================================= */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  max-width: 90vw;
  height: 100vh;
  max-height: 100vh; /* CRITICAL: Prevent drawer from exceeding viewport */
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform .25s ease;
  z-index: 60;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* CRITICAL: Prevent container overflow, let body handle scrolling */
}

.drawer.open { transform: translateX(0); }

/* Background overlay for click-outside-to-close */
.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  z-index: 55; /* Below drawer but above page content */
}

/* Drawer header - fixed at top */
.drawer .hd { 
  padding: 16px; 
  border-bottom: 1px solid var(--border); 
  display:flex; 
  justify-content:space-between; 
  align-items:center;
  flex-shrink: 0; /* Prevent header from shrinking */
}

/* Drawer body - scrollable content area with proper constraints */
.drawer .bd { 
  padding: 16px; 
  overflow-y: auto; /* Only vertical scroll */
  overflow-x: hidden; /* Prevent horizontal scroll */
  flex: 1 1 auto; /* Allow growth and shrinkage */
  min-height: 0; /* Critical: allows flex child to shrink below content size */
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  /* Prevent layout shifts when scrollbars appear/disappear */
  overscroll-behavior: contain;
  scrollbar-gutter: stable; /* keep gutter space reserved */
}

/* Drawer footer - fixed at bottom */
.drawer .ft { 
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom)); /* iOS safe area */
  border-top: 1px solid var(--border);
  flex-shrink: 0; /* Prevent footer from shrinking */
}

/* Individual cart line item in drawer cart view */
.cart-line { 
  display:grid; 
  grid-template-columns: 1fr auto; 
  gap: 8px; 
  align-items:center; 
  padding: 10px 0; 
  border-bottom:1px solid #f3f4f6;
  /* Prevent cart lines from overflowing */
  min-width: 0; /* Allow grid children to shrink */
  box-sizing: border-box;
}

/* Product name in cart line - truncate if needed */
.cart-line h4 { 
  margin:0; 
  font-size:14px;
  /* Allow text to wrap on small screens */
  overflow-wrap: break-word;
  word-break: break-word;
  line-height: 1.3;
}

/* Quantity controls and remove button */
.cart-line .qty { 
  display:flex; 
  gap:8px; 
  align-items:center;
  /* Keep controls from wrapping */
  flex-shrink: 0;
}

/* Buttons inside cart line */
.cart-line button { 
  padding:6px 8px; 
  border-radius:8px;
  /* Ensure buttons don't get squished */
  flex-shrink: 0;
}

.cart-summary { display:grid; gap:8px; margin: 12px 0; }
.cart-summary .row { display:flex; justify-content:space-between; }

/* Mobile enhancement: full-screen drawer for better readability & scrolling */
@media (max-width: 560px){
  .drawer{
    left: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh; /* dynamic viewport to avoid URL bar issues */
    max-height: 100dvh; /* CRITICAL: Prevent mobile drawer from exceeding viewport */
    border-left: none;
    border-top: 1px solid var(--border);
    transform: translateY(100%);
    transition: transform .25s ease;
    overflow: hidden; /* Ensure container doesn't overflow on mobile */
  }
  .drawer.open{ transform: translateY(0); }
  
  /* Mobile drawer body - no sticky positioning needed, proper flex constraints handle it */
  .drawer .bd{ 
    -webkit-overflow-scrolling: touch;
    /* min-height: 0 already set in base styles above */
  }
  
  /* Mobile drawer header and footer - keep sticky for better UX during keyboard appearance */
  .drawer .hd{ 
    position: sticky; 
    top: 0; 
    background: #fff; 
    z-index: 2;
    flex-shrink: 0; /* Ensure it doesn't shrink */
  }
  .drawer .ft{ 
    position: sticky; 
    bottom: 0; 
    background: #fff; 
    z-index: 2;
    flex-shrink: 0; /* Ensure it doesn't shrink */
    /* Safe area padding already defined in base .drawer .ft rule above */
  }
}

/* ======================
   CHECKOUT REVIEW (DRAWER)
   ====================== */
/* 
 * Container for checkout review inside the drawer body
 * This wraps the order summary when in "review" mode
 */
.checkout-review { 
  background:#f9fafb; 
  border:1px solid #e9ecef; 
  border-radius:12px; 
  padding:12px;
  /* Ensure review container doesn't overflow drawer body */
  max-width: 100%;
  box-sizing: border-box;
}

/* Review items list - scrolls within checkout-review if needed */
.checkout-review .review-items { 
  display:grid; 
  gap:8px;
  /* Allow items list to scroll if it gets too long */
  max-height: 48vh; /* slightly below half to avoid bouncing with footer/header */
  overflow-y: auto;
  margin-bottom: 12px;
  overscroll-behavior: contain;
}

/* Individual review line item */
.checkout-review .review-line { 
  display:flex; 
  justify-content:space-between; 
  align-items:center; 
  border-bottom:1px dashed #eceff3; 
  padding-bottom:6px;
  /* Prevent line items from overflowing */
  min-width: 0; /* Allow flex children to shrink */
}

.checkout-review .review-line:last-child { 
  border-bottom:none; 
  padding-bottom:0; 
}

/* Product name in review - truncate if too long */
.checkout-review .review-name { 
  font-size:14px; 
  color:#2c3e50;
  /* Allow text to wrap if needed, but keep it readable */
  overflow-wrap: break-word;
  word-break: break-word;
  flex: 1;
  min-width: 0;
}

/* Quantity and price meta info */
.checkout-review .review-meta { 
  display:flex; 
  gap:10px; 
  align-items:center; 
  color:#6c757d;
  /* Keep meta info from wrapping */
  flex-shrink: 0;
  white-space: nowrap;
}

/* =============================================================================
   PRODUCT DETAILS DISPLAY
   ============================================================================= */

/* Container for product information in checkout modal */
.checkout-product-details {
  background: #f8f9fa;          /* Light gray background */
  border-radius: 12px;          /* Rounded corners */
  padding: 16px;               /* Internal spacing */
  margin-bottom: 20px;         /* Space below this section */
  border: 1px solid #e9ecef;   /* Light border */
}

/* Product details section heading */
.checkout-product-details h4 {
  margin: 0 0 12px 0;          /* Remove default margins, add bottom margin */
  font-size: 16px;             /* Slightly larger text */
  font-weight: 600;            /* Semi-bold weight */
  color: #2c3e50;              /* Dark blue-gray color */
}

/* Individual product detail rows (label: value pairs) */
.product-detail-row {
  display: flex;                /* Flexbox for label-value layout */
  justify-content: space-between; /* Push label left, value right */
  align-items: center;          /* Vertically center content */
  margin-bottom: 8px;          /* Space between rows */
  font-size: 14px;             /* Slightly smaller text */
}

/* Remove margin from last detail row */
.product-detail-row:last-child {
  margin-bottom: 0;            /* No margin on last row */
}

/* Labels for product details (left side) */
.product-detail-label {
  color: #6c757d;              /* Medium gray color */
  font-weight: 500;            /* Medium weight */
}

/* Values for product details (right side) */
.product-detail-value {
  color: #2c3e50;              /* Dark blue-gray color */
  font-weight: 600;            /* Semi-bold weight */
}

/* Special styling for product name - larger than other details */
.product-name-value {
  font-size: 16px;             /* Larger text for product name */
  font-weight: 700;            /* Bold weight for emphasis */
}

/* Special styling for custom text on hats - larger than hat color but smaller than product name */
.fun-text-value {
  font-family: 'Arial Black', Arial, sans-serif; /* Bold font family */
  font-weight: bold;           /* Extra bold weight */
  text-transform: uppercase;   /* Convert to uppercase */
  color: #000000;              /* Black color for standard text */
  font-size: 15px;             /* Larger than default but smaller than product name */
}

/* =============================================================================
   PRICING BREAKDOWN SECTION
   ============================================================================= */

/* Container for price calculation details */
.checkout-pricing {
  border-top: 1px solid #e9ecef;  /* Top border to separate from product details */
  padding-top: 16px;              /* Space above pricing content */
  margin-top: 16px;               /* Space above the border */
}

/* Individual pricing rows (subtotal, shipping, etc.) */
.pricing-row {
  display: flex;                   /* Flexbox for label-value layout */
  justify-content: space-between;  /* Push label left, value right */
  align-items: center;             /* Vertically center content */
  margin-bottom: 8px;             /* Space between pricing rows */
  font-size: 14px;                /* Standard text size */
}

/* Final total row - styled differently for emphasis */
.pricing-row:last-child {
  margin-bottom: 0;               /* No margin on final row */
  padding-top: 8px;               /* Extra space above total */
  padding-bottom: 16px;           /* Space below total line for checkout page separation */
  border-top: 1px solid #e9ecef;  /* Border above total line */
  font-weight: 700;               /* Bold text for total */
  font-size: 16px;                /* Larger text for total */
}

/* Labels for pricing rows (left side) */
.pricing-label {
  color: #6c757d;                 /* Medium gray color */
}

/* Values for pricing rows (right side) */
.pricing-value {
  color: #2c3e50;                 /* Dark blue-gray color */
  font-weight: 600;               /* Semi-bold weight */
}

/* Total row text styling - both label and value */
.pricing-row:last-child .pricing-label,
.pricing-row:last-child .pricing-value {
  color: #2c3e50;                 /* Dark color for total row */
}

/* Free shipping text - green color to highlight the deal */
.free-shipping {
  color: #28a745 !important;      /* Green color (important overrides other styles) */
  font-weight: 600;               /* Semi-bold weight */
}

/* =============================================================================
   LOADING ANIMATIONS & INTERACTIVE ELEMENTS
   ============================================================================= */

/* Spinning loading indicator */
.loading-spinner {
  display: inline-block;          /* Inline block for positioning */
  width: 20px;                   /* Fixed width */
  height: 20px;                  /* Fixed height */
  border: 3px solid #f3f3f3;     /* Light gray border */
  border-top: 3px solid var(--blue); /* Blue top border creates spinning effect */
  border-radius: 50%;            /* Perfect circle */
  animation: checkout-spin 1s linear infinite; /* Continuous rotation */
}

/* Keyframe animation for spinner rotation */
@keyframes checkout-spin {
  0% { transform: rotate(0deg); }    /* Start position */
  100% { transform: rotate(360deg); } /* Full rotation */
}

/* =============================================================================
   BUTTON STATES & INTERACTIONS
   ============================================================================= */

/* Hover effect for buttons - subtle lift animation */
.btn:hover {
  transform: translateY(-1px);    /* Move button up slightly on hover */
}

/* Disabled button state */
.btn:disabled {
  opacity: 0.5;                   /* Make button semi-transparent */
  cursor: not-allowed;            /* Show "not allowed" cursor */
}

/* =============================================================================
   PAYPAL INTEGRATION STYLING
   ============================================================================= */

/* Container for PayPal button - ensures minimum height */
#paypal-button-container {
  min-height: 45px;              /* Minimum height to prevent layout shifts */
}

/* Drawer checkout buttons container - stabilize height/width to avoid thrash */
#drawer-paypal-buttons{
  min-height: 56px; /* Reserve space so PayPal can mount without reflow */
  width: 100%;
  box-sizing: border-box;
}

/* Loading state for PayPal modal */
.paypal-loading {
  text-align: center;            /* Center align loading content */
  padding: 20px;                 /* Padding around loading content */
}

/* Loading message text styling */
.paypal-loading p {
  margin-top: 10px;              /* Space above loading message */
  color: var(--muted);           /* Muted text color (defined in shared-styles.css) */
}
