/* Keep the checkout layout independent of the dashboard's generic form rules. */
.modal-backdrop:has(> .topup-modal) {
  grid-template-columns: minmax(0, 1fr);
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.topup-modal {
  box-sizing: border-box;
  width: min(940px, 100%);
  min-width: 0;
  min-inline-size: 0;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - max(12px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(16px, 3vw, 28px);
  text-align: start;
}

.topup-modal :is(.modal-title, .topup-layout, .topup-form, .topup-summary) { min-width: 0; }
.topup-modal .modal-title { padding-inline-end: 48px; }
.topup-modal .modal-title h2 { font-size: clamp(22px, 3.4vw, 28px); line-height: 1.17; }
.topup-modal .modal-title p { color: #aaa3bd; font-size: 13px; line-height: 1.5; }
.topup-modal .modal-title .aim-currency-switch { margin: 4px 0 8px; }
.topup-modal .modal-title .aim-currency-switch button { min-width: 43px; min-height: 34px; }
.topup-modal .modal-close { inset: 12px 12px auto auto; width: 44px; height: 44px; }

.topup-modal .topup-layout {
  grid-template-columns: minmax(0, 1.15fr) minmax(0, .95fr);
  align-items: start;
  gap: clamp(14px, 2.5vw, 24px);
  margin-top: 18px;
}
.topup-modal :is(.topup-form, .topup-summary) { grid-template-columns: minmax(0, 1fr); gap: 12px; }
.topup-modal :is(.topup-form, .topup-summary) > * { box-sizing: border-box; min-width: 0; }
.topup-modal .field-label { font-size: 12px; color: #c4bcd5; line-height: 1.25; }

.topup-modal .payment-gateway {
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  min-height: 0;
  padding: 12px;
  border-radius: 12px;
}
.topup-modal .payment-gateway-icon { width: 36px; height: 36px; }
.topup-modal .payment-gateway-icon svg { width: 18px; height: 18px; }
.topup-modal .payment-gateway strong { font-size: 14px; line-height: 1.25; }
.topup-modal .payment-gateway small { color: #aaa8ba; font-size: 11px; line-height: 1.4; }

.topup-modal .amount-field {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
  width: 100%;
  min-width: 0;
}
.topup-modal .amount-field > span {
  margin: 0 !important;
  padding-inline: 2px;
  color: #c4bcd5;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35 !important;
}
.topup-modal .amount-field > div {
  box-sizing: border-box;
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  min-height: 62px !important;
  height: auto;
  gap: 10px !important;
  padding: 6px 14px !important;
  border-radius: 14px !important;
}
.topup-modal .amount-field > div:focus-within {
  border-color: #ad95ff !important;
  box-shadow: 0 0 0 3px #9f83ff36 !important;
}
.topup-modal input[name="topup-amount"] {
  box-sizing: border-box;
  display: block;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  height: 46px !important;
  font-size: clamp(26px, 4vw, 38px) !important;
}
.topup-modal .amount-field b { padding-inline-end: 0; font-size: 14px !important; white-space: nowrap; }
.topup-modal #aim-topup-amount-message { margin: 0; font-size: 12px; }
.topup-modal .amount-slider { display: block; width: 100%; height: 24px; min-width: 0; margin: 0; }
.topup-modal .range-caption { gap: 8px; margin-top: -9px; font-size: 11px; }
.topup-modal .range-caption > span:last-child { text-align: end; }
.topup-modal .amount-presets { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; margin: 0; }
.topup-modal .amount-presets button {
  min-width: 0;
  min-height: 44px;
  padding: 4px 5px;
  border-radius: 10px;
  font-size: 11px;
  line-height: 1.2;
  white-space: normal;
  overflow-wrap: anywhere;
}
.topup-modal .promo-entry { border-radius: 12px; padding: 10px; }
.topup-modal .promo-entry label > span { color: #c4bcd5; font-size: 12px; }
.topup-modal .promo-entry label > div { min-width: 0; grid-template-columns: minmax(0, 1fr) auto; }
.topup-modal .promo-entry input { box-sizing: border-box; width: 100%; min-width: 0; height: 44px; font-size: 16px; }
.topup-modal .promo-entry button { min-width: 0; min-height: 44px; padding: 0 8px; font-size: 12px; }

.topup-modal .topup-summary { padding: clamp(13px, 2vw, 20px); border-radius: 14px; }
.topup-modal .summary-total { min-width: 0; gap: 5px; }
.topup-modal .summary-total span, .topup-modal .summary-total small { color: #bdb5ca; }
.topup-modal .summary-total small { font-size: 11px; line-height: 1.45; }
.topup-modal .summary-total strong { font-size: clamp(24px, 3.4vw, 34px); line-height: 1.15; overflow-wrap: anywhere; }
.topup-modal .topup-summary dl { gap: 8px; }
.topup-modal .topup-summary dl div { gap: 10px; font-size: 12px; line-height: 1.35; }
.topup-modal .topup-summary dt { color: #bdb5ca; }
.topup-modal .topup-summary dd { min-width: 0; text-align: end; overflow-wrap: anywhere; }
.topup-modal .aim-legal-ack { margin: 0; }
.topup-modal .aim-legal-ack label > span { min-width: 0; overflow-wrap: anywhere; }
.topup-modal .topup-summary .primary-button { width: 100%; min-height: 46px; padding-inline: 10px; white-space: normal; line-height: 1.3; }
.topup-modal .topup-summary .primary-button svg { flex-shrink: 0; }
.topup-modal .topup-summary .legal { margin: 0; color: #aaa3bd; font-size: 11px; line-height: 1.4; }

@media (max-width: 820px) {
  .topup-modal { width: min(550px, 100%); border-radius: 20px; }
  .topup-modal .topup-layout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 520px) {
  .modal-backdrop:has(> .topup-modal) {
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
             max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  .topup-modal {
    width: 100%;
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom)));
    padding: 14px;
  }
  .topup-modal .modal-title { padding-inline-end: 0; }
  .topup-modal .modal-title h2 { padding-inline-end: 45px; }
  .topup-modal .modal-title p { font-size: 12px; }
  .topup-modal .modal-close { inset: 8px 8px auto auto; }
  .topup-modal .topup-layout { margin-top: 14px; }
  .topup-modal .payment-gateway { grid-template-columns: auto minmax(0, 1fr); row-gap: 5px; }
  .topup-modal .payment-gateway-icon { grid-row: span 2; }
  .topup-modal .payment-gateway-ready { grid-column: 2; justify-self: start; }
  .topup-modal .amount-field > div { min-height: 58px !important; }
  .topup-modal .amount-presets { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
