/* ============================================
   WiFiHapa - Purchase components (shared)
   Package picker modal, mobile money number with network detection,
   payment status window. Used by index.php, wifi.php and checkout.php
   with includes/components/*.php and assets/js/purchase.js.
   ============================================ */

body.dark .modal-content-custom {
  background: #2d2d3d;
}

body.dark .modal-header-custom {
  border-bottom-color: #3d3d4d;
}

body.dark .modal-header-custom h3 {
  color: #e8e8e8 !important;
}

body.dark .close-modal {
  color: #d0d0d0 !important;
}

body.dark .close-modal:hover {
  color: #d4a11e !important;
}

body.dark .package-option {
  background: #3d3d4d;
  border-color: #4d4d5d;
  color: #d0d0d0 !important;
}

body.dark .package-option.selected {
  background: #fff9e6;
  color: #0a2c3d !important;
}

body.dark .package-option.selected .price-large {
  color: #0a2c3d !important;
}

body.dark .package-option .price-large {
  color: #d0d0d0 !important;
}

body.dark .comparison-note {
  background: #1a3a2a;
}

body.dark .comparison-note .fw-semibold {
  color: #d0d0d0 !important;
}

body.dark .comparison-note .text-secondary {
  color: #b0b0b0 !important;
}

body.dark .btn-proceed {
  background: #0d6efd;
  color: white !important;
}

body.dark .btn-pay {
  background: #d4a11e;
  color: white !important;
}

body.dark .btn-pay:hover {
  background: #b3881a;
  color: white !important;
}

body.dark .btn-link {
  color: #4d9aff !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ----- MODAL STYLES ----- */

.modal-custom {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(3px);
  z-index: 10000;
  padding: 1.5rem;
  align-items: center;
  justify-content: center;
}

.modal-custom.show {
  display: flex;
}

/* Header + scrollable body + optional sticky footer */

.modal-content-custom {
  background: #f8fafd;
  width: 100%;
  max-width: 720px;
  max-height: calc(100vh - 3rem);
  max-height: calc(100dvh - 3rem);
  border-radius: 28px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
  animation: slideDown 0.3s ease;
}

@keyframes sheetUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.modal-header-custom {
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

.modal-header-custom h3 {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0;
}

.modal-body-custom {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  flex: 1 1 auto;
  overscroll-behavior: contain;
}

.modal-footer-custom {
  padding: 1rem 1.5rem 1.1rem;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  background: white;
  flex-shrink: 0;
}

.close-modal {
  background: none;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  color: #0a2c3d;
  transition: 0.2s;
  flex-shrink: 0;
}

.close-modal:hover {
  color: #d4a11e;
  background: rgba(0, 0, 0, 0.04);
  transform: rotate(90deg);
}

.modal-subtitle {
  font-size: 1rem;
  font-weight: 700;
  margin: 1.25rem 0 0.75rem;
}

/* Selected router summary strip */

.selected-router {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: white;
  border: 1px solid rgba(13, 110, 253, 0.08);
  border-radius: 18px;
  padding: 0.85rem 1rem;
}

.selected-router-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: #e4edff;
  color: #0d6efd;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.selected-router-info {
  min-width: 0;
}

.selected-router-name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selected-router-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.3rem;
}

.modal-custom .badge-isp,
.modal-custom .badge-network,
.modal-custom .distance-meter {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.7rem;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.modal-custom .badge-isp {
  background: #e4edff;
  color: #0d6efd;
}

.modal-custom .badge-network {
  background: #1e2f4e;
  color: white !important;
}

.modal-custom .distance-meter {
  background: #f0f3fa;
  color: #0a2c3d;
}

.comparison-note {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  background: #fff9e6;
  padding: 0.8rem 1rem;
  border-radius: 16px;
  margin-top: 0.75rem;
  font-size: 0.85rem;
}

.comparison-note i {
  color: #d4a11e;
  margin-top: 0.2rem;
}

.comparison-note p {
  margin: 0.15rem 0 0;
  color: #6c757d;
  font-size: 0.8rem;
}

/* Package grid: 3 columns on every screen, compact tiles */

.package-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
}

.package-option {
  background: white;
  border: 2px solid #e9ecef;
  border-radius: 16px;
  padding: 0.7rem 0.4rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  color: #0a2c3d;
  font-family: inherit;
}

.package-option:hover {
  border-color: #0d6efd;
  transform: translateY(-2px);
}

.package-option.selected {
  border-color: #d4a11e;
  background: #fff9e6;
  box-shadow: 0 6px 16px rgba(212, 161, 30, 0.15);
}

.pkg-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #6c757d;
}

.package-option.selected .pkg-label {
  color: #b3881a;
}

.pkg-time {
  font-weight: 700;
  font-size: 0.95rem;
}

.price-large,
.pkg-price {
  font-weight: 800;
  font-size: 1.15rem;
  line-height: 1.2;
}

.pkg-price small {
  font-size: 0.65rem;
  font-weight: 600;
}

/* Footer total row */

.total-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.total-row .total-label {
  color: #6c757d;
  font-size: 0.9rem;
}

.total-row .total-amount {
  font-weight: 800;
  font-size: 1.4rem;
  color: #0a2c3d;
}

.duration-chip {
  margin-left: auto;
  background: #e4edff;
  color: #0d6efd;
  padding: 0.3rem 0.8rem;
  border-radius: 50px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.modal-note {
  text-align: center;
  color: #6c757d;
  font-size: 0.8rem;
  margin: 0.6rem 0 0;
}

.btn-proceed,
.btn-pay {
  width: 100%;
  color: white !important;
  border: none;
  border-radius: 50px;
  padding: 0.85rem;
  font-weight: 700;
  font-size: 1rem;
  transition: 0.2s;
}

.btn-proceed {
  background: #0d6efd;
}

.btn-proceed:hover {
  background: #0b5ed7;
  transform: scale(0.98);
}

.btn-pay {
  background: #d4a11e;
}

.btn-pay:hover {
  background: #b3881a;
}

.btn-back {
  background: none;
  border: none;
  color: #0d6efd;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.5rem 0;
  margin-bottom: 0.25rem;
}

/* Payment step - network is detected from the number's prefix */

.phone-input-group {
  margin: 0.5rem 0 1rem;
}

.phone-input-wrap {
  position: relative;
}

.phone-input-wrap input {
  padding-right: 7rem !important;
}

.network-detected {
  display: none;
  position: absolute;
  right: 0.55rem;
  top: 50%;
  transform: translateY(-50%);
  padding: 0.3rem 0.8rem;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 700;
  color: white !important;
}

.network-detected.show {
  display: inline-block;
}

.network-detected.net-vodacom {
  background: #e60000;
}

.network-detected.net-airtel {
  background: #c8102e;
}

.network-detected.net-yas {
  background: #1d3d8f;
}

.network-detected.net-halotel {
  background: #f26522;
}

.network-detected.net-ttcl {
  background: #0057a8;
}

.phone-hint {
  display: block;
  margin: 0.4rem 0 0 1rem;
  font-size: 0.8rem;
  color: #6c757d;
}

.phone-hint.ok {
  color: #198754;
  font-weight: 600;
}

.phone-hint.error {
  color: #dc3545;
  font-weight: 600;
}

.modal-custom .phone-input-group label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
}

.modal-custom .phone-input-group input {
  width: 100%;
  padding: 0.8rem 1.1rem;
  border: 2px solid #e9ecef;
  border-radius: 50px;
  font-size: 1rem;
}

.payment-summary {
  background: white;
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 16px;
  padding: 0.8rem 1rem;
  font-size: 0.9rem;
}

.payment-summary div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.2rem 0;
}

.payment-summary strong {
  text-align: right;
  overflow-wrap: anywhere;
}

/* Payment status window */

.modal-content-custom.modal-pay-status {
  max-width: 460px;
}

.modal-pay-status [hidden] {
  display: none !important;
}

.pay-status-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  background: #e4edff;
  border-radius: 14px;
  padding: 0.7rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.pay-status-summary span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pay-status-summary strong {
  font-size: 1.15rem;
  color: #0d6efd;
  white-space: nowrap;
}

.pay-spinner {
  position: relative;
  width: 96px;
  height: 96px;
  margin: 0.25rem auto 0;
}

.pay-spinner span {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 6px solid #e4edff;
  border-top-color: #0d6efd;
  border-right-color: #d4a11e;
  animation: spin 1s linear infinite;
}

.pay-spinner i {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: #0d6efd;
}

.pay-status-heading {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 1rem 0 0.35rem;
}

.pay-status-text {
  color: #6c757d;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.pay-steps {
  text-align: left;
  max-width: 290px;
  margin: 0.9rem auto 0;
}

.pay-steps div {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.3rem 0;
  color: #9aa5ae;
  font-weight: 500;
  font-size: 0.9rem;
}

.pay-steps i {
  width: 18px;
  text-align: center;
}

.pay-steps .done {
  color: #198754;
}

.pay-steps .now {
  color: #0d6efd;
}

.pay-status-keep {
  display: block;
  margin-top: 0.75rem;
  color: #6c757d;
}

.pay-result {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  margin: 0.25rem auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pay-result.bad {
  background: #fde8ea;
  color: #dc3545;
}

body.dark .pay-result.bad {
  background: #3a1a1f;
}

.pay-result.ok {
  background: #e1f5e8;
  color: #198754;
}

@keyframes popIn {
  from {
    transform: scale(0.4);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

body.dark .pay-status-summary {
  background: #1a3a5a;
}

body.dark .pay-status-summary strong {
  color: #6dafff !important;
}

body.dark .pay-spinner span {
  border-color: #2d3d55;
  border-top-color: #4d9aff;
  border-right-color: #d4a11e;
}

body.dark .pay-steps div,
body.dark .pay-steps div span {
  color: #8888a0 !important;
}

body.dark .pay-steps .done,
body.dark .pay-steps .done span {
  color: #80d0a0 !important;
}

body.dark .pay-steps .now,
body.dark .pay-steps .now span {
  color: #6dafff !important;
}

body.dark .pay-result.ok {
  background: #1a3a2a;
}

/* Dark mode for the modal blocks above */

body.dark .modal-content-custom {
  background: #23232f;
}

body.dark .modal-header-custom,
body.dark .modal-footer-custom {
  border-color: rgba(255, 255, 255, 0.06);
}

body.dark .modal-footer-custom,
body.dark .selected-router,
body.dark .payment-summary {
  background: #2d2d3d;
  border-color: #3d3d4d;
}

body.dark .selected-router-icon {
  background: #1a3a5a;
}

body.dark .modal-custom .badge-isp {
  background: #1a3a5a;
  color: #6dafff !important;
}

body.dark .modal-custom .distance-meter {
  background: #3d3d4d;
  color: #d0d0d0 !important;
}

body.dark .package-option span {
  color: #d0d0d0 !important;
}

body.dark .package-option.selected span {
  color: #0a2c3d !important;
}

body.dark .phone-hint {
  color: #a8a8b8 !important;
}

body.dark .phone-hint.ok {
  color: #80d0a0 !important;
}

body.dark .phone-hint.error {
  color: #ff8a8a !important;
}

body.dark .total-row .total-amount {
  color: #f0f0f0 !important;
}

body.dark .duration-chip {
  background: #1a3a5a;
  color: #6dafff !important;
}

body.dark .comparison-note p {
  color: #a8a8b8 !important;
}

body.dark .modal-custom .phone-input-group input {
  background: #3d3d4d;
  border-color: #4d4d5d;
  color: #e0e0e0;
}

body.dark .btn-back {
  color: #4d9aff !important;
}

@media (max-width: 768px) {
  .close-modal {
      min-height: 40px;
    }
}

@media (max-width: 575.98px) {
  .modal-custom {
      padding: 0;
      align-items: flex-end;
    }

  .modal-content-custom {
      max-height: 92vh;
      max-height: 92dvh;
      border-radius: 24px 24px 0 0;
      animation: sheetUp 0.3s ease;
    }

  .modal-header-custom {
      padding: 0.9rem 1.1rem;
    }

  .modal-header-custom h3 {
      font-size: 1.1rem;
    }

  .modal-body-custom {
      padding: 1rem 1.1rem;
    }

  .modal-footer-custom {
      padding: 0.85rem 1.1rem calc(0.85rem + env(safe-area-inset-bottom));
    }

  .package-grid {
      gap: 0.45rem;
    }

  .package-option {
      padding: 0.6rem 0.25rem;
      border-radius: 14px;
    }

  .pkg-time {
      font-size: 0.85rem;
    }

  .pkg-price {
      font-size: 1rem;
    }
}

@media (max-width: 360px) {
  .pkg-label {
      font-size: 0.6rem;
    }
}

/* ----- ACCOUNT AFTER PAYMENT ----- */
.account-existing {
  margin: 0.9rem 0 0;
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
  background: #e4edff;
  color: #0d6efd;
  font-size: 0.85rem;
  font-weight: 600;
}

.account-offer {
  margin-top: 1rem;
  padding: 1rem;
  border: 2px solid #d4a11e;
  border-radius: 18px;
  background: #fffaf0;
}

.account-offer-head {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.85rem;
}

.account-offer-head > i {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #d4a11e;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.account-offer-head strong {
  display: block;
  font-size: 0.95rem;
}

.account-offer-head p {
  margin: 0.15rem 0 0;
  font-size: 0.82rem;
  color: #6c757d;
}

#accountForm {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

#accountForm[hidden] {
  display: none;
}

#accountForm .form-control {
  border-radius: 12px;
  padding: 0.65rem 0.9rem;
}

.account-error {
  color: #dc3545;
  font-weight: 600;
  font-size: 0.8rem;
}

body.dark .account-existing {
  background: #1a3a5a;
  color: #6dafff !important;
}

body.dark .account-offer {
  background: #2d2a1f;
}

body.dark .account-offer-head p {
  color: #a8a8b8 !important;
}

body.dark #accountForm .form-control {
  background: #3d3d4d;
  border-color: #4d4d5d;
  color: #e0e0e0;
}

body.dark .account-error {
  color: #ff8a8a !important;
}

.account-wifi-pass {
  margin: 0 0 0.25rem;
  padding: 0.55rem 0.8rem;
  border-radius: 12px;
  background: #e1f5e8;
  color: #0f5132;
  font-size: 0.85rem;
}

#payReceipt[hidden],
#payStatusSummary[hidden] {
  display: none !important;
}

body.dark .account-wifi-pass {
  background: #1a3a2a;
  color: #80d0a0 !important;
}

/* ===== Ways to pay, wallet, passes, router login page (purchase.js) ===== */
.package-pass .pkg-label { color: #0d6efd; }
.pay-methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin: 0.8rem 0; }
.pay-method {
  border: 2px solid #e9ecef; background: white; border-radius: 14px; padding: 0.55rem 0.3rem; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 0.2rem; font-size: 0.78rem; font-weight: 600; color: #0a2c3d; cursor: pointer;
}
.pay-method i { font-size: 1.1rem; color: #0d6efd; }
.pay-method.active { border-color: #d4a11e; background: #fff9e6; }
.wallet-pay-box { margin-bottom: 1rem; }
.wallet-pay-box label { font-size: 0.85rem; font-weight: 600; display: block; margin-bottom: 0.3rem; }
.pin-input { letter-spacing: 0.6rem; text-align: center; font-size: 1.3rem; font-weight: 700; max-width: 200px; }
.wallet-links { display: flex; flex-wrap: wrap; gap: 0.2rem 1rem; margin-top: 0.4rem; }
.link-btn { background: none; border: 0; padding: 0; color: #0d6efd; font-weight: 600; font-size: 0.85rem; cursor: pointer; font-family: inherit; }
.link-btn:hover { text-decoration: underline; }
.portal-connect { margin-top: 1rem; }
.wallet-pin-form, .invite-box { margin-top: 1rem; border: 1px solid #e9ecef; border-radius: 16px; padding: 0.9rem; }
.invite-box { display: flex; gap: 0.8rem; align-items: center; background: #f3f8ff; border-color: #d6e6ff; }
.invite-box > i { font-size: 1.5rem; color: #d4a11e; }
.invite-box strong { display: block; font-size: 0.9rem; }
.wallet-tabs { display: flex; gap: 0.4rem; margin-bottom: 1rem; overflow-x: auto; }
.wallet-tab { flex: 1; border: 1px solid #e9ecef; background: white; border-radius: 50px; padding: 0.45rem 0.6rem; font-size: 0.8rem; font-weight: 600; white-space: nowrap; color: #0a2c3d; font-family: inherit; cursor: pointer; }
.wallet-tab.active { background: #0d6efd; border-color: #0d6efd; color: white; }
.topup-amounts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
.topup-amount { border: 2px solid #e9ecef; background: white; border-radius: 14px; padding: 0.7rem; font-weight: 800; font-size: 1.05rem; color: #0a2c3d; font-family: inherit; cursor: pointer; }
.topup-amount.selected { border-color: #d4a11e; background: #fff9e6; }
.wallet-balance { font-size: 2rem; font-weight: 800; color: #0a2c3d; text-align: center; margin-bottom: 0.6rem; }
.wallet-line { display: flex; justify-content: space-between; align-items: center; padding: 0.45rem 0; border-bottom: 1px solid #f1f3f5; font-size: 0.88rem; }
.wallet-line small { display: block; color: #6c757d; font-size: 0.72rem; }
body.dark .pay-method, body.dark .wallet-tab, body.dark .topup-amount { background: #232c3f; border-color: #2a3448; color: #e6edf3; }
body.dark .pay-method.active, body.dark .topup-amount.selected { background: #3a3220; border-color: #d4a11e; }
body.dark .wallet-tab.active { background: #0d6efd; border-color: #0d6efd; color: white; }
body.dark .wallet-pin-form { border-color: #2a3448; }
body.dark .invite-box { background: #1e2a40; border-color: #2a3448; }
body.dark .wallet-balance { color: #e6edf3; }
body.dark .wallet-line { border-color: #2a3448; }
@media (max-width: 380px) { .pay-method { font-size: 0.7rem; } }

/* A package the router does not sell (its owner's own prices, assets/js/purchase.js applyRouterPrices) */
.package-option[hidden] { display: none !important; }
