/* Shared native wheel/keyboard scrolling for both application surfaces. */
html { min-height: 100%; scroll-padding-block: 16px; }
body { min-height: 100dvh; overflow-y: auto; }

/* All full-screen overlays stay within the visual viewport. Their cards own overflow. */
:is(.auth-modal,.workbench-modal,.history-detail-modal,.history-details-modal,.action-confirm-overlay,.system-announcement-modal) {
  max-height: 100dvh;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
}
:is(.auth-card,.workbench-modal-card,.history-detail-panel,.history-details-panel,.history-detail-card,.action-confirm-panel,.system-announcement-card) {
  min-height: 0;
  max-height: calc(100dvh - 36px);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
}
/* One bounded flex column: header never clips the password action below it. */
.workbench-modal > .account-settings-modal {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: min(720px,calc(100dvh - 36px));
  overflow: hidden;
}
.account-settings-modal > header { flex: 0 0 auto; }
.account-settings-modal > .account-settings-layout {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
  padding-bottom: 24px;
}
.settings-drawer { height: 100dvh; max-height: 100dvh; overflow-y: auto; overscroll-behavior-y: contain; }
:is(.chat-toolbar-popover,.chat-wallpaper-menu,.chat-qr-popover,.support-client-emoji-picker) {
  max-height: calc(100dvh - 90px);
  overflow-y: auto;
  overscroll-behavior-y: contain;
}
.chat-sidebar { min-height: 0; max-height: 100dvh; overflow-y: auto; }
.chat-sidebar > :not(.chat-sidebar-spacer) { flex-shrink: 0; }
:is(.chat-messages,.chat-config-card,.pending-order,.wallet-ledger,.history-detail-body,.support-message-list,.support-admin-chat-body,.support-admin-list,.audit-scroll,.table-scroll,.model-table) {
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}
:is(.chat-messages,.support-message-list,.support-admin-chat-body) { overscroll-behavior-y: contain; }
:is(.support-window,.support-chat-body,.support-admin-chat) { min-height: 0; }
.support-window { max-height: calc(100dvh - 20px); }
.support-chat-body { overflow: hidden; }
.support-message-list { flex: 1 1 auto; }

/* Administrative navigation and long data tables also keep their own wheel area. */
.sidebar { min-height: 0; max-height: 100dvh; }
.sidebar > .nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; }
.table-scroll { max-width: 100%; overflow-x: auto; max-height: min(720px,70dvh); }
.audit-scroll { max-height: min(520px,70dvh); }
@media(min-width:901px) {
  .support-admin-layout { height: calc(100dvh - 150px); min-height: min(480px,calc(100dvh - 150px)); max-height: calc(100dvh - 110px); }
}
@media(max-width:900px) {
  .support-admin-chat { height: min(760px,calc(100dvh - 100px)); min-height: 280px; }
}
@media(max-width:640px) {
  .workbench-modal { padding: 10px; }
  .workbench-modal > .account-settings-modal { max-height: calc(100dvh - 20px); }
}

/* Native administrative dialogs (2FA, SMTP and confirmation) are bounded too. */
dialog[open] {
  min-height: 0;
  max-height: calc(100dvh - 36px);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
}
