/* ============================================================
   MANTA checkout — page-specific layout.
   Design tokens + shared components come from manta.css.
   Every id/class queried by checkout.js is preserved:
   #email #shipping-section #saved-address-view #saved-address-text
   #change-address-btn #address-form #order-items #checkout-subtotal
   #checkout-total .discount-section .apply-btn #payment-request-button
   #payment-request-overlay #express-unavailable #express-error-message
   #pay-with-card-btn .btn-text .btn-spinner #payment-message
   #custom-build-terms #controller-terms .terms-* .checkout-footer
   #policy-modal .close-modal .terms-modal .login-prompt
   ============================================================ */

/* ---------- Page shell ---------- */
.checkout-main {
  max-width: 560px;
  margin: 0 auto;
  padding: var(--s5) var(--gutter) var(--s7);
}

/* Taller fixed pay bar (two rows) needs more bottom clearance than the default */
body.no-tabbar.has-actionbar {
  padding-bottom: calc(132px + env(safe-area-inset-bottom, 0px));
}
@media (min-width: 900px) {
  body.no-tabbar.has-actionbar { padding-bottom: 0; }
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: var(--s3);
  transition: color .18s var(--ease);
}
.back-link:hover { color: var(--ink); }

.checkout-title {
  font-size: var(--text-h2);
  margin-bottom: var(--s5);
}

/* ---------- Order summary accordion ---------- */
.summary {
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  background: var(--paper);
  margin-bottom: var(--s6);
  overflow: hidden;
}
.summary-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  min-height: 56px;
  padding: var(--s3) var(--s4);
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.summary-head::-webkit-details-marker { display: none; }
.summary-label {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: .9375rem;
  font-weight: 500;
}
.summary-chevron {
  flex: none;
  color: var(--muted);
  transition: transform .28s var(--ease);
}
.summary[open] .summary-chevron { transform: rotate(180deg); }
.summary-count {
  font-size: .75rem;
  font-weight: 500;
  color: var(--muted);
}
.summary-count:not(:empty)::before { content: "· "; }
.summary-total { font-size: 1rem; }

.summary-body {
  padding: 0 var(--s4) var(--s4);
  border-top: 1px solid var(--hairline);
}

/* Items injected by checkout.js: .order-item / .item-image-wrap / .item-badge /
   .item-details / .item-name / .item-price */
.order-items { padding-top: var(--s2); }
.order-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) 0;
  font-size: .875rem;
  color: var(--muted);
}
.order-item + .order-item { border-top: 1px solid var(--hairline); }
.item-image-wrap {
  position: relative;
  flex: none;
  width: 56px;
  height: 56px;
  background: var(--surface);
  border-radius: 10px;
}
.item-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  mix-blend-mode: multiply;
  border-radius: 10px;
}
.item-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  background: var(--ink);
  color: #fff;
  font-size: .6875rem;
  font-weight: 700;
  line-height: 19px;
  text-align: center;
  border-radius: var(--r-chip);
}
.item-details { flex: 1; min-width: 0; }
.item-name {
  font-size: .875rem;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.item-price {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  white-space: nowrap;
}

/* Discount code: inline input + Apply */
.discount-section {
  display: flex;
  gap: var(--s2);
  padding: var(--s3) 0;
  border-top: 1px solid var(--hairline);
}
.discount-section input {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 0 var(--s4);
  font-size: 1rem; /* 16px — no iOS zoom */
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--r-btn);
  transition: border-color .18s var(--ease), background .18s var(--ease);
}
.discount-section input:focus {
  outline: none;
  border-color: var(--ink);
  background: var(--paper);
}
.discount-section input:disabled { color: var(--muted); }
.discount-section .apply-btn {
  flex: none;
  min-height: 48px;
  padding: 0 var(--s5);
  border: 1px solid var(--ink);
  border-radius: var(--r-btn);
  font-size: .875rem;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  transition: background .18s var(--ease), transform .18s var(--ease), opacity .18s var(--ease);
}
.discount-section .apply-btn:hover { background: var(--surface); }
.discount-section .apply-btn:active { transform: scale(.98); }
.discount-section .apply-btn:disabled {
  border-color: var(--hairline);
  color: var(--muted);
  pointer-events: none;
}

.summary-lines { padding-top: var(--s3); border-top: 1px solid var(--hairline); }
.summary-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s4);
  font-size: .875rem;
  color: var(--muted);
  padding: 3px 0;
}
.summary-line .price { color: var(--ink); }

/* ---------- Sections ---------- */
.ck-section { margin-bottom: var(--s6); }
.ck-section h2 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: var(--s4);
}
.ck-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
}
.ck-section-head h2 { margin-bottom: var(--s4); }
.login-prompt { font-size: .8125rem; color: var(--muted); }
.login-prompt a {
  color: var(--ink);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ck-hint {
  font-size: .75rem;
  color: var(--muted);
  margin-top: var(--s2);
}

/* ---------- Delivery address ---------- */
.saved-address-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  width: 100%;
  padding: var(--s4);
  background: var(--surface);
  border-radius: var(--r-card);
}
.address-details strong {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--s1);
}
.address-details p {
  font-size: .9375rem;
  line-height: 1.55;
  color: var(--ink);
}
.text-btn {
  flex: none;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 2px;
  min-height: 44px;
  padding: 0 var(--s2);
}

#address-form { display: flex; flex-direction: column; gap: var(--s3); }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s3);
}

/* ---------- Delivery method ---------- */
.delivery-option {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s4);
  border: 1px solid var(--ink);
  border-radius: var(--r-btn);
  cursor: default;
}
.delivery-option input[type="radio"] {
  flex: none;
  width: 20px;
  height: 20px;
  accent-color: var(--ink);
}
.delivery-option-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.delivery-option-name { font-size: .9375rem; font-weight: 500; }
.delivery-option-eta { font-size: .75rem; color: var(--muted); }
.delivery-option-price { flex: none; font-size: .9375rem; }

/* ---------- Payment ---------- */
.payment-subtitle { margin: calc(-1 * var(--s2)) 0 var(--s4); }

.express-checkout {
  padding: var(--s4);
  background: var(--surface);
  border-radius: var(--r-card);
}
.express-title {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--s3);
  text-align: center;
}
.payment-request-wrapper { position: relative; }
.express-btn-container { min-height: 48px; }
.payment-request-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  align-items: center;      /* JS toggles display none/flex */
  justify-content: center;
  background: rgba(255, 255, 255, .72);
  border-radius: var(--r-btn);
  cursor: not-allowed;
  text-align: center;
  padding: var(--s2);
}
.payment-request-overlay span { font-size: .75rem; color: var(--muted); }
.express-unavailable {
  font-size: .8125rem;
  color: var(--muted);
  text-align: center;
  padding: var(--s2) 0;
}

.payment-divider {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin: var(--s5) 0 var(--s4);
}
.divider-line { flex: 1; height: 1px; background: var(--hairline); }
.divider-text {
  font-size: .75rem;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.card-pay-note { text-align: center; }
.card-brands-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
}
.card-brands-inline img {
  width: 38px;
  height: 24px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: var(--paper);
}

/* ---------- Terms gating blocks (custom build / controller) ---------- */
.custom-build-terms {
  margin-bottom: var(--s5);
  padding: var(--s4);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  background: var(--surface);
}
.terms-checkbox-wrapper {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
}
.terms-checkbox-wrapper + .terms-checkbox-wrapper { margin-top: var(--s3); }
.terms-checkbox-wrapper input[type="checkbox"] {
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  accent-color: var(--ink);
}
.terms-checkbox-wrapper label {
  font-size: .875rem;
  line-height: 1.5;
  color: var(--ink);
}
.terms-link {
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.terms-confirmation-text {
  font-size: .75rem;
  color: var(--muted);
  margin-top: var(--s3);
}
.terms-error {
  font-size: .8125rem;
  font-weight: 500;
  color: var(--err);
  margin-top: var(--s3);
}

/* ---------- Sticky pay bar ---------- */
.checkout-paybar {
  flex-direction: column;
  align-items: stretch;
  gap: var(--s2);
}
.paybar-row {
  display: flex;
  align-items: center;
  gap: var(--s4);
}
.paybar-total {
  flex: none;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.paybar-total-label {
  font-size: .6875rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.paybar-total-value { font-size: 1.125rem; }
.pay-with-card-btn svg { flex: none; }
.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ck-spin .7s linear infinite;
}
@keyframes ck-spin { to { transform: rotate(360deg); } }
.paybar-trust {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: .6875rem;
  color: var(--muted);
}
.paybar-trust svg { flex: none; }
@media (min-width: 900px) {
  .checkout-paybar { margin-top: var(--s5); }
}

/* ---------- Payment messages (checkout.js sets className to
   "payment-message error|success" on #express-error-message / #payment-message) */
.payment-message {
  margin-top: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--r-btn);
  border: 1px solid var(--hairline);
  background: var(--paper);
  font-size: .875rem;
  line-height: 1.5;
}
.payment-message.error { color: var(--err); border-color: var(--err); }
.payment-message.success { color: var(--ok); border-color: var(--ok); }

/* ---------- Policy footer links ---------- */
.checkout-footer {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2) var(--s4);
  margin-top: var(--s6);
  padding-top: var(--s4);
  border-top: 1px solid var(--hairline);
}
.checkout-footer a {
  font-size: .75rem;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color .18s var(--ease);
}
.checkout-footer a:hover { color: var(--ink); }

/* ---------- Policy modal (checkout.js sets display:flex) ---------- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 140;
  background: rgba(10, 10, 11, .4);
  align-items: center;
  justify-content: center;
  padding: var(--gutter);
}
.modal-content {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--paper);
  border-radius: var(--r-card);
  padding: var(--s5);
}
.modal-content h2 {
  font-size: 1.25rem;
  margin-bottom: var(--s3);
  padding-right: var(--s6);
}
#policy-body { font-size: .9375rem; color: var(--muted); }
#policy-body p + p { margin-top: var(--s3); }
.close-modal {
  position: absolute;
  top: var(--s3);
  right: var(--s3);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  transition: background .15s var(--ease), color .15s var(--ease);
}
.close-modal:hover { background: var(--surface); color: var(--ink); }

/* ---------- Terms modals (checkout.js sets display:block) ---------- */
.terms-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(10, 10, 11, .4);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--s4) var(--gutter);
}
.terms-modal-content {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
  max-height: calc(100vh - 2 * var(--s4));
  max-height: calc(100dvh - 2 * var(--s4));
  margin: 0 auto;
  background: var(--paper);
  border-radius: var(--r-card);
  overflow: hidden;
}
.terms-modal-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--hairline);
}
.terms-modal-header h2 {
  font-size: 1.125rem;
  letter-spacing: -0.01em;
}
.terms-modal-close {
  flex: none;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  transition: background .15s var(--ease), color .15s var(--ease);
}
.terms-modal-close:hover { background: var(--surface); color: var(--ink); }
.terms-modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--s4) var(--s5);
  font-size: .9375rem;
  color: var(--muted);
}
.terms-modal-body h3 {
  font-family: var(--font-body);
  font-size: .9375rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0;
  margin: var(--s4) 0 var(--s2);
}
.terms-modal-body p + p { margin-top: var(--s2); }
.terms-modal-body ul {
  list-style: disc;
  padding-left: var(--s5);
  margin: var(--s2) 0;
}
.terms-modal-body li { margin: 2px 0; }
.terms-modal-body strong { color: var(--ink); }
.terms-updated {
  font-size: .75rem;
  color: var(--faint);
  margin-bottom: var(--s3);
}
.terms-modal-footer {
  flex: none;
  padding: var(--s3) var(--s5) calc(var(--s3) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--hairline);
}
.terms-modal-close-btn {
  width: 100%;
  min-height: 48px;
  border-radius: var(--r-btn);
  background: var(--ink);
  color: #fff;
  font-size: .9375rem;
  font-weight: 600;
  transition: background .18s var(--ease), transform .18s var(--ease);
}
.terms-modal-close-btn:hover { background: #232326; }
.terms-modal-close-btn:active { transform: scale(.98); }
