/* ===== CHECKOUT MODAL =====
 * Stripe embedded checkout modal styles
 * Self-contained component with its own CSS variables
 */

/* ===== Default Variables (Light Mode) ===== */
.checkout-modal {
  --white: #FFFFFF;
  --ice: #F8FAFC;
  --navy: #0F172A;
  --text-dark: #334155;
  --text-muted: #64748B;
  --border: #E2E8F0;
  --green: #2ea043;
  --green-hover: #238636;
}

/* ===== Dark Mode Variables ===== */
.dark .checkout-modal,
html.dark .checkout-modal {
  --white: #1E293B;
  --ice: #0F172A;
  --navy: #F8FAFC;
  --text-dark: #E2E8F0;
  --text-muted: #94A3B8;
  --border: #334155;
}

.checkout-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.checkout-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.checkout-modal-content {
  position: relative;
  background: var(--white);
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  max-height: 90dvh; /* Dynamic viewport height for mobile browsers */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  animation: modalSlideUp 0.3s ease-out;
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.checkout-modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--ice);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background 0.2s;
}

.checkout-modal-close:hover {
  background: var(--border);
}

.checkout-modal-close svg {
  width: 18px;
  height: 18px;
  color: var(--text-dark);
}

.checkout-modal-header {
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.checkout-modal-header h2 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.5rem;
  color: var(--navy);
  margin-bottom: 0;
}

.checkout-modal-header p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

#checkout-container {
  flex: 1;
  min-height: 400px;
  padding: 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
  /* Stripe embedded checkout requires light background - doesn't support dark mode */
  background: #FFFFFF;
  border-radius: 8px;
}

.checkout-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 300px;
  color: var(--text-muted);
}

.checkout-loading svg {
  animation: spin 1s linear infinite;
}

.checkout-error {
  text-align: center;
  padding: 32px;
}

.checkout-error p {
  color: var(--text-dark);
  margin-bottom: 16px;
}

.checkout-error button {
  background: var(--green);
  color: var(--white);
  border: none;
  padding: 12px 24px;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.checkout-error button:hover {
  background: var(--green-hover);
}

/* Dark mode: Ensure button text is always readable on colored backgrounds */
.dark .checkout-error button,
html.dark .checkout-error button {
  color: #FFFFFF;
}

/* Mobile: Full screen modal */
@media (max-width: 640px) {
  .checkout-modal-content {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height accounts for mobile browser chrome */
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }

  #checkout-container {
    flex: 1;
    min-height: 0; /* Allow flex shrink */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ===== TWO-STEP EMAIL CAPTURE ===== */

.checkout-step {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0; /* Allow flex shrink for scrolling */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.checkout-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 8px;
  margin-bottom: 0;
}

/* Email capture form */
.email-capture-form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.email-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.email-input-group label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-dark);
}

.email-input-group input {
  padding: 14px 16px;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--white);
  color: var(--navy);
}

.email-input-group input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(46, 160, 67, 0.15);
}

.email-input-group input.input-error {
  border-color: #dc3545;
}

.email-input-group input.input-error:focus {
  box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.15);
}

.email-error {
  font-size: 0.85rem;
  color: #dc3545;
  min-height: 1.2em;
}

/* Order summary */
.checkout-summary {
  background: var(--ice);
  border-radius: 8px;
  padding: 16px;
}

.checkout-summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  color: var(--text-muted);
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.checkout-summary-total {
  display: flex;
  justify-content: space-between;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--navy);
}

/* Email submit button */
.email-submit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 16px 24px;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--white);
  background: var(--green);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.email-submit-btn:hover {
  background: var(--green-hover);
}

.email-submit-btn:active {
  transform: scale(0.98);
}

/* Dark mode: Ensure button text is always readable */
.dark .email-submit-btn,
html.dark .email-submit-btn {
  color: #FFFFFF;
}

.email-submit-btn svg {
  width: 20px;
  height: 20px;
}

/* Reassurance text below submit button */
.checkout-reassurance {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  margin: 16px 0 0 0;
  line-height: 1.4;
}

/* Mobile adjustments for email form */
@media (max-width: 640px) {
  .email-capture-form {
    padding: 20px 16px;
  }

  .email-submit-btn {
    font-size: 1rem;
    padding: 14px 20px;
  }
}

/* ===== CONFIRMATION STEP ===== */

.checkout-confirmation {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  gap: 16px;
}

.checkout-confirmation svg {
  margin-bottom: 8px;
}

.checkout-confirmation h2 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.75rem;
  color: var(--navy);
  margin: 0;
}

.checkout-confirmation-message {
  font-size: 1.1rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}

.checkout-close-btn {
  margin-top: 16px;
  padding: 14px 32px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--white);
  background: var(--green);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.checkout-close-btn:hover {
  background: var(--green-hover);
}

.checkout-close-btn:active {
  transform: scale(0.98);
}

/* Dark mode: Ensure button text is always readable */
.dark .checkout-close-btn,
html.dark .checkout-close-btn {
  color: #FFFFFF;
}
