/* Pull-to-refresh is a browser navigation, not an app refresh. Preserve pinch zoom. */
html,
body {
  overscroll-behavior-y: none;
}
.support-history-toggle {
  display: none;
}

@media (max-width: 760px), (max-width: 1100px) and (max-height: 500px) {
  :root {
    font-size: 14px;
  }
  body.app-loaded {
    height: 100dvh;
    overflow: hidden;
  }
  #workspace {
    height: 100dvh;
    grid-template-columns: 48px minmax(0, 1fr);
    grid-template-rows: 28px minmax(0, 1fr);
    font-size: 13px;
  }
  #workspace .app-titlebar {
    padding: 0 8px;
    font-size: 11px;
  }
  #workspace .rail {
    padding: 8px 4px;
  }
  #workspace .rail-home,
  #workspace .rail-home img,
  #workspace .server-icon,
  #workspace .rail-action {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 12px;
    font-size: 16px;
  }
  #workspace .rail-line {
    margin: 7px auto 9px;
  }
  #workspace .rail-help {
    height: 44px;
    gap: 2px;
  }
  #workspace .rail-help > .icon {
    width: 22px;
    height: 22px;
  }
  #workspace .rail-help > span:not(.unread-badge) {
    font-size: 8px;
  }
  #workspace .room-header {
    height: 42px;
    min-height: 42px;
    padding: 4px 6px;
  }
  #workspace .room-header strong {
    font-size: 13px;
  }
  #workspace.menu-open .sidebar {
    left: 48px;
    top: 28px;
    width: min(264px, calc(100vw - 56px));
  }
  #workspace.has-members-panel.members-open .members {
    top: 28px;
    width: min(270px, calc(100vw - 24px));
  }
  #workspace .panel-backdrop {
    top: 28px;
  }
  #room-view {
    padding: 10px 8px 4px;
  }
  #room-view .stage-top h1 {
    font-size: 15px;
    margin: 5px 0;
  }
  #stage-kind {
    font-size: 9px;
  }
  #workspace .main-footer {
    display: none;
  }
  #workspace .prejoin {
    padding: 20px 8px;
  }
  #workspace .prejoin-symbol {
    width: 58px;
    height: 58px;
    margin-bottom: 14px;
  }
  #workspace .prejoin h2 {
    font-size: 19px;
  }
  #workspace .prejoin p {
    font-size: 13px;
  }
  #tiles {
    gap: 8px;
    overscroll-behavior: contain;
  }
  #tiles:not(.has-screen) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #tiles > .tile:not(.screen) {
    min-height: 104px;
    height: 112px;
    padding: 8px 6px 24px;
  }
  #tiles > .tile:not(.screen) .initial {
    width: 48px;
    height: 48px;
    min-width: 48px;
    font-size: 25px;
    margin: 0;
  }
  #tiles.has-screen > .tile:not(.screen) {
    flex-basis: calc(50% - 4px);
    width: calc(50% - 4px);
    height: 88px;
    min-height: 88px;
  }
  #tiles.has-screen > .tile:not(.screen) .initial {
    width: 38px;
    height: 38px;
    min-width: 38px;
    font-size: 23px;
  }
  #tiles .tile-label {
    bottom: 4px;
    left: 4px;
    max-width: calc(100% - 8px);
    padding: 4px 6px;
    font-size: 10px;
    line-height: 1.2;
  }
  #call-controls {
    padding: 10px 4px 4px;
    gap: 3px;
    border-radius: 14px;
  }
  #call-controls .control-item > button:not(.device-chevron) {
    min-width: 32px;
    width: 32px;
    height: 44px;
    padding: 7px;
  }
  #call-controls .control-item .icon {
    width: 18px;
    height: 18px;
  }
  #chat-pane {
    font-size: 13px;
  }
  #chat-messages .message {
    padding: 8px 4px;
    gap: 8px;
  }
  #chat-messages .avatar {
    width: 30px;
    height: 30px;
    min-width: 30px;
    font-size: 17px;
  }
  #chat-messages .message-heading {
    font-size: 12px;
  }
  #chat-messages .message p {
    font-size: 13px;
    line-height: 1.45;
  }
  .platform-banner {
    margin: 5px;
    padding: 7px 9px;
    gap: 6px;
    font-size: 11px;
    border-radius: 9px;
  }
  .platform-banner button {
    min-height: 32px;
    padding: 5px 8px;
    font-size: 11px;
  }
  #notification-offer {
    max-height: none;
    overflow: visible;
  }
  #tour-welcome {
    max-height: 92px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  /* Keep native inputs at 16px: Safari should not zoom the page on focus. */
  input,
  textarea,
  select {
    font-size: 16px;
  }
  #support-widget {
    left: 12px;
    right: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
    width: min(340px, calc(100vw - 24px));
    max-height: min(500px, 64dvh);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
  }
  #support-widget[hidden] {
    display: none;
  }
  #support-widget > header {
    padding: 6px 12px;
    min-height: 40px;
    font-size: 13px;
    flex-shrink: 0;
  }
  #support-close {
    min-width: 36px;
    height: 32px;
  }
  #support-widget .support-layout {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: none;
    overflow: hidden;
  }
  #support-widget .support-layout > aside {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 7px;
    max-height: 145px;
    overflow: auto;
  }
  #support-new,
  #support-widget .support-history-toggle {
    display: block;
    flex: 1;
    min-height: 32px;
    padding: 6px 8px;
    font-size: 12px;
  }
  #support-widget #support-tickets,
  #support-widget .support-pages {
    display: none;
  }
  #support-widget.support-history-open #support-tickets {
    display: flex;
    flex: 0 0 100%;
    overflow-x: auto;
  }
  #support-widget.support-history-open .support-pages {
    display: flex;
  }
  #support-widget .support-layout > section {
    padding: 10px;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  #support-widget h3 {
    font-size: 15px;
    margin: 0 0 8px;
  }
  #support-widget p,
  #support-widget label {
    font-size: 12px;
    line-height: 1.4;
  }
  #support-widget input,
  #support-widget textarea {
    font-size: 16px;
    padding: 7px;
    margin: 4px 0 8px;
  }
  #support-widget textarea {
    min-height: 62px;
    max-height: 100px;
  }
  #support-messages {
    height: min(180px, 24dvh);
  }
  #support-widget button.primary {
    min-height: 34px;
    padding: 7px 12px;
    font-size: 12px;
  }
  dialog::backdrop {
    backdrop-filter: none;
  }
  #call-controls {
    backdrop-filter: none;
    box-shadow: none;
  }
}

/* Низкий экран телефона: прокручивается содержимое, а не панель звонка. */
@media (max-width: 1100px) and (max-height: 500px) and (orientation: landscape) {
  #workspace main {
    min-height: 0;
    overflow: hidden;
  }
  #workspace .room-header {
    flex-shrink: 0;
  }
  #workspace:not(.call-active) #room-view {
    overflow-y: auto;
  }
  #workspace .prejoin {
    padding: 8px 12px;
    margin: auto;
  }
  #workspace .prejoin-symbol {
    display: none;
  }
  #workspace .prejoin .primary {
    margin-top: 12px;
    min-height: 44px;
  }
  #workspace #tiles:not(.has-screen) {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    align-content: start;
  }
  #workspace #tiles > .tile:not(.screen) {
    height: 100px;
    min-height: 100px;
    aspect-ratio: auto;
  }
  #workspace #call-controls {
    position: relative;
    inset: auto;
    transform: none;
    flex-shrink: 0;
    margin: 8px auto 4px;
    order: 3;
  }
  #workspace.chat-open #room-view #call-chat {
    order: 2;
    flex: 1 1 0;
    min-height: 0;
    height: auto;
    overflow: hidden;
    padding: 6px 8px;
  }
  #workspace.chat-open #call-chat > header {
    flex-shrink: 0;
    min-height: 32px;
    padding-bottom: 4px;
    margin-bottom: 4px;
  }
  #workspace.chat-open #call-chat #chat-form {
    flex-shrink: 0;
  }
  #workspace.chat-open #chat-messages {
    padding-block: 4px;
  }
  body.viewing-screen #workspace #call-controls {
    position: fixed;
    inset: auto auto max(4px, env(safe-area-inset-bottom)) 50%;
    transform: translateX(-50%);
    margin: 0;
  }
  body.viewing-screen #room-view #call-chat {
    position: fixed;
    top: 8px;
    bottom: 76px;
    left: auto;
    right: 8px;
    width: min(400px, calc(100vw - 24px));
    height: auto;
    min-height: 0;
  }
  dialog[open] {
    max-height: calc(100dvh - 20px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  #support-widget {
    max-height: calc(100dvh - 20px);
  }
}
