.checkout-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s, visibility 0.2s;
}

.checkout-modal-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.checkout-modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 920px;
  max-height: 92vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.18);
  animation: checkoutModalIn 0.25s ease;
}

@keyframes checkoutModalIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.checkout-modal-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.checkout-modal-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 4px 6px 0;
  border-radius: var(--radius-sm);
  min-height: 36px;
  flex-shrink: 0;
}

.checkout-modal-back i {
  font-size: 20px;
  line-height: 1;
}

.checkout-modal-back:hover {
  color: var(--primary);
}

.checkout-modal-head h2 {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0;
  min-width: 0;
  text-align: center;
}

.checkout-modal-head h2 i {
  color: var(--primary);
}

.checkout-modal-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.checkout-modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 20px 22px 24px;
}

.checkout-modal-grid {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.checkout-modal-form {
  order: 1;
}

.checkout-modal-summary {
  order: 2;
}

@media (max-width: 768px) {
  .checkout-modal-overlay {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 0;
    overflow: hidden;
  }

  .checkout-modal-box {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    margin: 0;
    border-radius: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
    box-shadow: none;
  }

  .checkout-modal-head {
    flex-shrink: 0;
    padding-top: max(18px, calc(12px + var(--safe-top, env(safe-area-inset-top))));
  }

  .checkout-modal-grid {
    gap: 16px;
  }

  /* Form first, order summary below */
  .checkout-modal-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
    padding: 14px 16px calc(24px + var(--safe-bottom, env(safe-area-inset-bottom)));
  }

  .checkout-modal-summary {
    position: relative;
    max-height: none;
    overflow: visible;
  }

  #checkout-modal-items {
    overflow: visible;
    max-height: none;
  }
}

.checkout-modal-form .cm-section {
  margin-bottom: 18px;
}

.checkout-modal-form .cm-section-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
}

.checkout-modal-form .cm-section-title i {
  color: var(--primary);
}

.checkout-modal-form .cm-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.checkout-modal-form .cm-row-1 {
  grid-template-columns: 1fr;
}

@media (max-width: 500px) {
  .checkout-modal-form .cm-row {
    grid-template-columns: 1fr;
  }
}

.checkout-modal-form .cm-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.checkout-modal-form .cm-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.checkout-modal-form .cm-input {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  background: var(--surface);
}

.checkout-modal-form .cm-input:focus {
  border-color: var(--primary);
}

.checkout-modal-form .cm-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236B6B6B' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.cm-payment-block {
  margin-top: 4px;
}

.cm-pay-heading {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--text);
}

.cm-pay-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 14px;
}

.cm-pay-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.cm-pay-tile {
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.cm-pay-tile:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
}

.cm-pay-tile.selected {
  border-color: #e2136e;
  background: #fdf2f8;
  color: #e2136e;
}

.cm-pay-tile[data-method="nagad"].selected {
  border-color: #e65100;
  background: #fff8f0;
  color: #e65100;
}

.cm-pay-tile[data-method="rocket"].selected {
  border-color: #7b1fa2;
  background: #f3e8ff;
  color: #7b1fa2;
}

.cm-pay-tile[data-method="cod"].selected {
  border-color: var(--primary);
  background: var(--primary-pale);
  color: var(--primary);
}

.cm-zone-grid,
.checkout-zone-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.cm-zone-tile,
.checkout-zone-tile {
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  text-align: center;
}

.cm-zone-tile:hover,
.checkout-zone-tile:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
}

.cm-zone-tile.selected,
.checkout-zone-tile.selected {
  border-color: var(--primary);
  background: var(--primary-pale);
  color: var(--primary);
}

.cm-zone-hint,
.checkout-zone-hint {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-muted);
}

.cm-pay-instruct-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.cm-pay-instruct-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.cm-pay-instruct-text {
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 10px;
  color: var(--text);
}

.cm-pay-number {
  display: block;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  padding: 12px 16px;
  margin: 0 0 10px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-sm);
  background: #fff;
  letter-spacing: 0.5px;
}

.cm-pay-instruct-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.45;
}

.cm-trx-field.hidden {
  display: none;
}

.checkout-modal-summary {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

@media (min-width: 769px) {
  .checkout-modal-summary {
    position: static;
  }
}

.checkout-modal-summary h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
}

.cm-summary-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  min-height: 0;
}

.cm-summary-item:last-of-type {
  border-bottom: none;
}

.cm-summary-thumb {
  width: 44px;
  height: 44px;
  min-width: 44px;
  max-width: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.cm-summary-thumb img {
  width: 100%;
  height: 100%;
  min-width: 0;
  object-fit: cover;
  display: block;
}

.cm-summary-thumb i {
  font-size: 20px;
}

.cm-summary-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  line-height: 1.3;
}

.cm-summary-price {
  font-weight: 700;
  color: var(--accent);
}

.cm-coupon-row {
  margin: 10px 0 12px;
  flex-wrap: wrap;
}

.cm-coupon-row .c-coupon-input {
  min-width: 0;
}

.cm-summary-rows {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1.5px solid var(--border);
}

.cm-summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.cm-summary-row.cm-total {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-top: 8px;
  margin-bottom: 14px;
}

.cm-summary-row.cm-total span:last-child {
  color: var(--accent);
}

.cm-summary-row.cm-reward-points-row {
  color: #92400e;
  font-weight: 600;
  margin-top: 4px;
}

.cm-summary-row.cm-reward-points-row span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cm-summary-row.cm-reward-points-row span:first-child i {
  color: #d97706;
  font-size: 16px;
}

.cm-summary-row.cm-reward-points-row .summary-reward-points {
  color: #b45309;
  font-weight: 700;
}

.cm-summary-row.cm-reward-points-row[hidden] {
  display: none !important;
}

.btn-place-order-modal {
  width: 100%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff;
  border: none;
  padding: 14px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(212, 134, 150, 0.35);
}

.btn-place-order-modal:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn-place-order-modal:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.cm-secure {
  text-align: center;
  font-size: 11px;
  color: var(--text-light);
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

body.checkout-modal-open {
  overflow: hidden;
}

/* ===== Full checkout page (replaces popup) ===== */
.checkout-page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.checkout-page-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.checkout-page-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.checkout-page-back:hover {
  border-color: var(--primary-light);
  background: var(--primary-pale);
}

.checkout-page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkout-page-title i {
  color: var(--primary);
}

.checkout-page-steps {
  margin-bottom: 20px;
}

.checkout-page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 24px;
  align-items: start;
}

.checkout-page-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.checkout-page-summary {
  position: sticky;
  top: 88px;
}

.checkout-page-legal {
  margin: 12px 0 0;
  font-size: 11px;
  color: var(--text-light);
  text-align: center;
  line-height: 1.5;
}

.checkout-page-legal a {
  color: var(--primary);
}

.checkout-steps {
  display: flex;
  align-items: center;
  gap: 0;
  max-width: 1120px;
  margin: 0 auto 20px;
  padding: 0 4px;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.step-active .step-circle {
  background: var(--primary);
  color: #fff;
}

.step-done .step-circle {
  background: var(--green);
  color: #fff;
}

.step-inactive .step-circle {
  background: var(--border);
  color: var(--text-muted);
}

.step-label {
  font-size: 12px;
  font-weight: 600;
}

.step-active .step-label {
  color: var(--primary);
}

.step-done .step-label {
  color: var(--green);
}

.step-inactive .step-label {
  color: var(--text-muted);
}

.step-line {
  flex: 1;
  height: 2px;
  background: var(--border);
  margin: 0 8px;
  min-width: 20px;
}

.step-line-done {
  background: var(--green);
}

@media (max-width: 900px) {
  .checkout-page-grid {
    grid-template-columns: 1fr;
  }

  .checkout-page-summary {
    position: static;
  }
}

@media (max-width: 520px) {
  .checkout-page {
    padding: 12px 12px 32px;
  }

  .checkout-page-title {
    font-size: 18px;
  }

  .checkout-steps {
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .step-label {
    font-size: 10px;
  }
}
