/* Web-only responsive layer; desktop renderer and media behavior are shared. */
#mobile-rooms-button, #mobile-rooms-backdrop { display: none; }
@media (max-width: 767px), (max-width: 900px) and (max-height: 500px) {
  body.browser-client { --mobile-top: calc(48px + env(safe-area-inset-top, 0px)); --mobile-controls: 76px; height: var(--mobile-height, 100dvh); }
  body.browser-client #titlebar { height: var(--mobile-top); padding: env(safe-area-inset-top, 0px) max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px)); }
  body.browser-client .titlebar-drag-region { padding: 0; min-width: 0; }
  body.browser-client .browser-download { display: none; }
  #mobile-rooms-button:not([hidden]) { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 14px; color: var(--text-normal); background: transparent; border: 0; border-radius: 10px; }
  body.browser-client #app-workspace, body.browser-client #login-screen { top: var(--mobile-top); height: calc(var(--mobile-height, 100dvh) - var(--mobile-top)); width: 100%; bottom: auto; min-width: 0; }
  body.browser-client #login-screen { padding: 12px 12px max(16px, env(safe-area-inset-bottom, 0px)); align-items: flex-start; }
  body.browser-client #login-screen .login-card { padding: 24px 18px; margin: auto; min-width: 0; }
  body.browser-client input:not([type=range]), body.browser-client select, body.browser-client textarea { font-size: 16px !important; max-width: 100%; }
  body.browser-client input, body.browser-client textarea { user-select: text; -webkit-user-select: text; }
  body.browser-client button, body.browser-client [role=button] { touch-action: manipulation; }
  body.browser-client #app-workspace > .sidebar-left { display: none !important; }
  @keyframes mobileDrawerSlideIn {
    from {
      transform: translateX(-100%) translateZ(0);
    }
    to {
      transform: translateX(0) translateZ(0);
    }
  }
  @keyframes mobileBackdropFadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }
  body.browser-client #app-workspace.mobile-rooms-open > .sidebar-left { display: flex !important; position: absolute; inset: 0 auto 0 0; z-index: 110; width: min(320px, calc(100% - 40px)); min-width: 0; max-width: none; opacity: 1; visibility: visible; pointer-events: auto; animation: mobileDrawerSlideIn 0.28s cubic-bezier(0.16, 1, 0.3, 1) both; will-change: transform; }
  #app-workspace.mobile-rooms-open #mobile-rooms-backdrop { display: block; position: absolute; inset: 0; z-index: 105; border: 0; background: #0008; animation: mobileBackdropFadeIn 0.24s cubic-bezier(0.16, 1, 0.3, 1) both; }
  body.browser-client #app-workspace.mobile-rooms-open.sidebar-left-collapsed > .sidebar-left { width: min(320px, calc(100% - 40px)) !important; opacity: 1 !important; pointer-events: auto !important; }
  body.browser-client .channels-container { overflow-y: auto; }
  body.browser-client .user-widget { width: calc(100% - 24px); margin: 12px; flex-shrink: 0; }
  body.browser-client .user-widget-actions { flex-wrap: wrap; }
  body.browser-client .user-widget-actions button, body.browser-client .btn-icon, body.browser-client .btn-send, body.browser-client .btn-emoji { min-width: 44px; min-height: 44px; }
  body.browser-client .center-workspace { width: 100%; min-width: 0; flex: 1 1 100%; }
  body.browser-client .splash-screen { padding: 16px; overflow: auto; }
  body.browser-client .splash-content { width: 100%; padding: 24px 16px; }
  body.browser-client .splash-actions { flex-direction: column; }
  /* One compact header row: title on the left, view modes + link on the right. */
  body.browser-client .room-header { position: relative; height: 52px; min-height: 52px; padding: 4px 8px 4px 12px; display: flex; flex-direction: row; align-items: center; gap: 8px; }
  body.browser-client .room-title { position: static; transform: none; min-width: 0; flex: 1 1 auto; height: 44px; gap: 6px; }
  body.browser-client .room-actions { position: static; transform: none; min-width: 0; flex: 0 0 auto; width: auto; height: 44px; gap: 4px; justify-content: flex-end; }
  body.browser-client .room-title-copy { min-width: 0; flex: 1; }
  body.browser-client #active-room-title { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
  body.browser-client .connection-quality-chip { display: none; }
  body.browser-client .view-mode-switcher { width: auto; flex: 0 0 auto; }
  body.browser-client .room-title { align-items: center; }
  body.browser-client .view-mode-btn { width: 38px; min-width: 38px; height: 38px; }
  body.browser-client #copy-room-link-btn { min-width: 40px; width: 40px; height: 38px; padding: 0; }
  body.browser-client #copy-room-link-btn span { display: none; }
  body.browser-client .media-workspace { height: auto; min-height: 0; flex: 1; }
  body.browser-client .media-workspace .peers-grid { left: 8px; right: 8px; top: 8px; bottom: var(--mobile-controls) !important; width: auto; height: auto !important; transform: none; min-height: 0 !important; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: auto; }
  body.browser-client .media-workspace .peers-grid.peers-count-1 { grid-template-columns: minmax(0, 1fr); }
  body.browser-client .media-workspace .peer-card { min-width: 0; min-height: 150px; height: auto !important; max-height: none; }
  body.browser-client .media-workspace[data-view-mode=list] .peers-grid { grid-template-columns: minmax(0, 1fr); }
  body.browser-client .media-workspace[data-view-mode=list] .peer-card { min-height: 76px; }
  body.browser-client .media-workspace[data-view-mode=speaker] .peers-grid { bottom: calc(var(--mobile-controls) + 92px) !important; grid-template-columns: minmax(0, 1fr); }
  body.browser-client .speaker-participants-strip { left: 8px; right: 8px; width: auto; bottom: var(--mobile-controls) !important; overflow-x: auto; grid-template-columns: none !important; grid-auto-flow: column; grid-auto-columns: 76px; }
  /* One row of icon buttons (labels live in aria-label/title). */
  body.browser-client .call-controls { width: calc(100% - 16px); max-width: 440px; height: 60px; bottom: 8px; padding: 6px; gap: 4px; display: flex; justify-content: space-between; border-radius: 20px; }
  body.browser-client .call-controls .control-btn { flex: 1 1 0; width: auto; min-width: 0; max-width: 56px; height: 48px; border-radius: 14px; }
  body.browser-client .call-controls .control-btn::before { width: 24px; height: 24px; flex-shrink: 0; }
  body.browser-client .call-controls .control-btn.mobile-unsupported { display: none; }
  /* The popup lives inside the reactions button; anchor it to the whole bar instead. */
  body.browser-client #control-reactions-btn { position: static; transform: none !important; will-change: auto; }
  body.browser-client .reactions-popup { position: absolute; left: 0; right: 0; bottom: calc(100% + 8px); width: auto; transform: none; animation: none !important; flex-wrap: wrap; justify-content: center; max-height: 40vh; overflow-y: auto; z-index: 120; }
  /* Chat/people open as a bottom sheet so the call stays visible above it. */
  body.browser-client #workspace-sidebar-right:not(.hidden), body.browser-client #workspace-sidebar-right.is-closing { position: absolute; inset: auto 0 calc(var(--mobile-controls) + var(--mobile-rail, 0px)) 0; width: 100% !important; min-width: 0; max-width: none; height: 58% !important; max-height: calc(100% - var(--mobile-controls) - 48px); z-index: 65; background: var(--bg-secondary); border-radius: 18px 18px 0 0; box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.45); animation: mobileSheetUp 240ms cubic-bezier(0.16, 1, 0.3, 1) both; will-change: transform; }
  body.browser-client #workspace-sidebar-right.is-closing { animation: mobileSheetDown 200ms cubic-bezier(0.25, 1, 0.5, 1) both !important; pointer-events: none; }
  @keyframes mobileSheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
  @keyframes mobileSheetDown { from { transform: translateY(0); } to { transform: translateY(100%); } }
  body.browser-client .compact-sidebar-close { display: inline-flex; width: 44px; height: 44px; }
  body.browser-client .sidebar-right-tabs { left: 64px; right: 12px; height: 44px; width: auto; top: 10px; }
  body.browser-client .tab-btn { flex: 1 1 0; min-width: 0; height: 36px; font-size: 13px; }
  body.browser-client #sidebar-participants-pane, body.browser-client #sidebar-quality-pane { padding-top: 64px; box-sizing: border-box; }
  /* Participant cards: avatar above the name instead of both centered on top of each other. */
  body.browser-client .media-workspace[data-view-mode=grid] #peers-grid .peer-card, body.browser-client .media-workspace[data-view-mode=speaker] #peers-grid .peer-card.focus-primary-speaker { display: flex; }
  body.browser-client .media-workspace:not([data-view-mode=list]) .peer-card { flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 190px; padding: 44px 12px 16px; box-sizing: border-box; }
  body.browser-client .media-workspace:not([data-view-mode=list]) .peer-card > .peer-avatar-container,
  body.browser-client .media-workspace:not([data-view-mode=list]) .peer-card > .peer-info { position: relative !important; inset: auto !important; transform: none !important; margin: 0 !important; max-width: 100%; }
  body.browser-client .media-workspace:not([data-view-mode=list]) .peer-card > .peer-avatar-container { width: 96px !important; height: 96px !important; flex: 0 0 auto; }
  body.browser-client .media-workspace:not([data-view-mode=list]) .peers-grid:not(.peers-count-1) .peer-card > .peer-avatar-container { width: 64px !important; height: 64px !important; }
  body.browser-client .media-workspace:not([data-view-mode=list]) .peer-card .peer-avatar-container .avatar { width: 100% !important; height: 100% !important; }
  body.browser-client .chat-input-area { padding: 8px; }
  body.browser-client .chat-input-wrapper { width: 100%; min-width: 0; box-sizing: border-box; align-items: center; }
  body.browser-client #chat-input { min-width: 0; flex: 1 1 auto; font-size: 16px; line-height: 20px; padding-top: 0; padding-bottom: 0; }
  /* Modals open below the fixed title bar instead of under it. */
  body.browser-client .modal-overlay { padding: calc(var(--mobile-top) + 8px) max(10px, env(safe-area-inset-right, 0px)) max(10px, env(safe-area-inset-bottom, 0px)); align-items: flex-start; }
  body.browser-client .modal-content, body.browser-client .modal-card { width: 100% !important; min-width: 0 !important; max-width: 540px !important; max-height: calc(var(--mobile-height, 100dvh) - var(--mobile-top) - 20px); overflow-y: auto; }
  /* Toasts sit above the call controls, not over the room title. */
  body.browser-client .toast-container { top: auto; left: 12px; right: 12px; width: auto; transform: none; bottom: calc(var(--mobile-controls) + 72px + env(safe-area-inset-bottom, 0px)); align-items: center; pointer-events: none; }
  body.browser-client .toast-container > * { max-width: 100%; }
  /* Rooms drawer must be opaque; the home screen bled through before. */
  body.browser-client #app-workspace.mobile-rooms-open > .sidebar-left { background: #171a20 !important; backdrop-filter: none; }
  body.browser-client.light-theme #app-workspace.mobile-rooms-open > .sidebar-left { background: #f4f5f7 !important; }
  /* The messenger covers the call view; its controls must not float on top. */
  body.browser-client.messenger-open .call-controls { display: none; }
  body.browser-client .audio-unlock-banner { top: calc(var(--mobile-top) + 60px); width: calc(100% - 32px); }
  body.browser-client .modal-body { padding: 16px; min-height: 0; overflow-y: auto; }
  body.browser-client .modal-close-btn { min-width: 44px; min-height: 44px; }
  body.browser-client .modal-footer { gap: 8px; flex-wrap: wrap; }
  body.browser-client.mobile-typing .call-controls { visibility: hidden; }
  body.browser-client.mobile-typing #workspace-sidebar-right:not(.hidden) { bottom: 0; }
  body.browser-client .profile-settings-card { display: flex; flex-direction: column; min-width: 0; }
  body.browser-client .settings-group, body.browser-client .settings-select { min-width: 0; width: 100%; }
  body.browser-client .settings-toggle-row { gap: 12px; }
  body.browser-client .media-workspace.screen-share-active .screen-share-presentation { left: 8px; right: 8px; top: 8px; bottom: var(--mobile-controls); width: auto; min-width: 0; }
  body.browser-client .screen-share-header { flex-wrap: wrap; height: auto; gap: 6px; padding: 8px; }
  body.browser-client .screen-share-zoom-control { display: none; }
}

/* The app section rail becomes a bottom bar at this width (messenger.css). */
@media (max-width: 760px) {
  body.browser-client { --mobile-rail: 62px; }
}
