/* Responsive component fixes. Keep payment and account behavior in the original templates. */
body.sx .sx-table-wrap,
body.sx .sx-code,
body.sx .sx-split > *,
body.sx .sx-hero > *,
body.sx .sx-ledger-hero > *,
body.sx .sx-form-wrap > *,
body.sx .sx-form-main > *,
body.sx .sx-field-grid > *,
body.sx .sx-field-grid-2 > *,
body.sx .sx-auth-page > * {
  min-width: 0;
  max-width: 100%;
}
body.sx .sx-table-wrap,
body.sx .sx-code {
  overscroll-behavior-x: contain;
}
body.sx .sx-title,
body.sx .sx-auth-headline,
body.sx .sx-notice > span,
body.sx .sx-alert > span,
body.sx .sx-step > div,
body.sx .sx-context {
  overflow-wrap: anywhere;
  min-width: 0;
}
/* A tall dialog must scroll inside the viewport, including landscape and keyboards. */
body.sx .sx-modal-panel,
body.sx .integ-modal-dialog {
  min-width: 0;
  flex-shrink: 0;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  margin-top: auto;
  margin-bottom: auto;
}
body.sx #ticketMessages,
body.sx #ticketMessages .message,
body.sx .sx-modal-title {
  overflow-wrap: anywhere;
  min-width: 0;
}
@media (max-width: 900px) {
  /* Match the existing important desktop selector so mobile padding takes effect. */
  body.sx > .flex.min-h-screen > main > .app-content {
    padding: 24px 18px 56px !important;
    max-width: 100% !important;
  }
  body.sx > .flex.min-h-screen > main > .app-content::before {
    display: none;
  }
  body.sx .sx-search,
  body.sx .sx-field-inline,
  body.sx .sx-select {
    min-width: 0;
    max-width: 100%;
  }
}
@media (max-width: 767px) {
  /* Inline columns in permissions/acquirer forms otherwise beat the shared media rules. */
  body.sx .sx-options[style*="grid-template-columns"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}
@media (max-width: 640px) {
  body.sx .sx-nav-account #accountSwitcherDropdown {
    position: fixed;
    top: calc(var(--sx-nav-h) + 8px) !important;
    bottom: auto !important;
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
    max-height: calc(100vh - var(--sx-nav-h) - 24px);
    max-height: calc(100dvh - var(--sx-nav-h) - 24px);
    overflow-y: auto;
    overscroll-behavior-y: contain;
  }
  body.sx .sx-nav-right {
    gap: 8px;
    min-width: 0;
  }
  body.sx .sx-nav-icon,
  body.sx .sx-nav-avatar {
    flex-shrink: 0;
  }
  body.sx .sx-notice {
    flex-wrap: wrap;
  }
  body.sx .sx-notice > span {
    flex: 1 1 160px;
  }
  body.sx .sx-notice a {
    max-width: 100%;
    white-space: normal;
  }
  body.sx .sx-field-inline input:not([type="checkbox"]):not([type="radio"]) {
    min-width: 0;
    max-width: 100%;
  }
  body.sx .sx-variant-spacer {
    display: none;
  }
  body.sx .sx-variant .sx-field {
    flex: 1 1 0;
    min-width: 0;
  }
  body.sx .integ-modal-dialog {
    padding: 20px 18px;
  }
  body.sx .sx-modal-header,
  body.sx .sx-modal-footer {
    gap: 12px;
    flex-wrap: wrap;
  }
  body.sx .sx-modal-header > div {
    min-width: 0;
  }
}
@media (max-width: 480px) {
  body.sx > .flex.min-h-screen > main > .app-content {
    padding: 20px 12px 48px !important;
  }
  body.sx .sx-nav {
    padding: 0 12px;
    gap: 8px;
  }
  body.sx .sx-nav .sx-brand-name {
    display: none;
  }
  body.sx .sx-nav .sx-brand {
    gap: 0;
  }
  body.sx .sx-strip:not(.sx-strip-3) {
    grid-template-columns: minmax(0, 1fr);
  }
  body.sx .sx-strip > div {
    border-right: 0;
    border-bottom: 1px solid var(--sx-rule);
  }
  body.sx .sx-strip > div:last-child {
    border-bottom: 0;
  }
  body.sx .sx-ledger-split {
    flex-wrap: wrap;
  }
  body.sx .sx-ledger-split > div:first-child {
    flex: 1 1 140px;
  }
  body.sx .sx-modal-list > div {
    flex-wrap: wrap;
  }
  body.sx .sx-modal-list .sx-value {
    max-width: 100%;
  }
  body.sx .sx-switch-row {
    gap: 12px;
  }
}

/* Page-specific mobile fixes. Classes only change layout; form behavior is unchanged. */
@media (max-width: 640px) {
  body.sx .sx-security-filters,
  body.sx .sx-sound-grid,
  body.sx #quickEditModal .sx-quick-edit-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    min-width: 0;
    max-width: 100%;
  }
  body.sx .sx-security-filters > *,
  body.sx .sx-sound-card,
  body.sx #quickEditModal .sx-quick-edit-grid > * {
    min-width: 0;
    max-width: 100%;
  }
  body.sx .sx-sound-content,
  body.sx .sx-device-content {
    padding: 16px !important;
  }
  body.sx .sx-sound-card input[type="radio"] {
    flex-shrink: 0;
  }
  body.sx .sx-device-card {
    min-width: 0;
    max-width: 100%;
    padding: 14px !important;
  }
  body.sx .sx-device-info {
    min-width: 0 !important;
    flex-basis: 100% !important;
    max-width: 100%;
  }
  body.sx .sx-device-info > div {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  body.sx .sx-device-actions {
    min-width: 0;
    max-width: 100%;
    flex-wrap: wrap;
  }
  body.sx .sx-device-actions > form {
    min-width: 0;
    max-width: 100%;
  }
  body.sx .sx-device-actions .btn {
    max-width: 100%;
    white-space: normal;
  }
  body.sx .sx-variant .sx-variant-spacer {
    display: none;
  }
  body.sx .sx-variant .sx-field {
    min-width: 0;
    flex: 1 1 0;
  }
}

/* The desktop navigation needs room before the tablet breakpoint. */
@media (max-width: 1200px) {
  body.sx .sx-nav-role { display: none !important; }
  body.sx .sx-nav-sections,
  body.sx .sx-nav-balance { display: none; }
  body.sx .sx-nav-icon.sx-drawer-toggle { display: grid; }
}

@media (max-width: 480px) {
  body.sx .amt-hero { font-size: clamp(26px, 8vw, 38px); }
  body.sx .amt-xxl { font-size: clamp(22px, 7vw, 32px); }
  body.sx .sx-hero-main .amount,
  body.sx .sx-ledger-primary .amount { max-width: 100%; }
}

body.sx .sx-auth-box { min-width: 0; }
body.sx .sx-field .sx-upload input[type="file"] {
  width: 0;
  height: 0;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0 !important;
}
@media (max-width: 640px) {
  body.sx .sx-acquirer-title { flex-wrap: wrap; }
  body.sx .sx-acquirer-title > .status-badge {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

/* Fixed backdrops are independent of the surrounding space-y content spacing. */
body.sx [role="dialog"].fixed,
body.sx .sx-ann-popup {
  margin: 0 !important;
}
body.sx .sx-ann-popup {
  overflow-y: auto;
}
body.sx .sx-ann-popup > div {
  min-width: 0;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  margin-top: auto;
  margin-bottom: auto;
  overflow-wrap: anywhere;
}

/* The avatar crop keeps its original canvas and actions inside a scrollable panel. */
body.sx #avatarCropModal {
  margin: 0 !important;
  overflow-y: auto;
}
body.sx #avatarCropModal > div {
  min-width: 0;
  flex-shrink: 0;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  margin-top: auto;
  margin-bottom: auto;
}

/* Keep the financial hero in one column while the desktop gutter leaves too little room. */
@media (min-width: 901px) and (max-width: 1100px) {
  body.sx .sx-hero { grid-template-columns: minmax(0, 1fr); }
  body.sx .sx-hero-main {
    padding: 26px 20px;
    border-right: 0;
    border-bottom: 1px solid var(--sx-rule);
  }
  body.sx .amt-hero { font-size: 48px; }
}
