@media (max-width: 920px) {
  html.chat-open .app-shell {
    padding: 0;
    gap: 0;
  }

  html.chat-open #chat-modal.chat-pane {
    position: fixed;
    inset: 0;
    z-index: 90;
    width: 100%;
    height: auto;
  }

  html.chat-open .topbar {
    display: none;
  }

  html.chat-open .workspace-view {
    height: 100%;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .stats {
    grid-column: 1 / -1;
  }

  .workspace-view {
    display: block;
    min-height: 0;
  }

  #board-view.board-pane {
    height: 100%;
  }

  .chat-pane {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    padding: 0;
    background: transparent;
  }

  .chat-window {
    width: 100%;
    height: 100%;
    border-radius: 0;
    max-height: none;
    min-height: 0;
  }

  .user-detail-view {
    border-radius: 0;
  }

  .dashboard-grid,
  .dashboard-grid.compact {
    grid-template-columns: 1fr 1fr;
  }

  .admin-create-form {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 620px) {
  input,
  textarea,
  select {
    font-size: 16px;
  }

  .app-shell {
    padding: 6px 8px 0;
  }

  .drawer {
    left: 8px;
    right: 8px;
    top: 8px;
    bottom: 8px;
    width: auto;
    height: auto;
    max-height: calc(100dvh - 16px);
    border-radius: 20px;
    overflow: auto;
  }

  .drawer-head {
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: 60px;
    padding: 12px 16px;
    background: linear-gradient(180deg, #1f2d3a, #1a2834);
  }

  .topbar {
    padding: 10px 12px;
    grid-template-columns: 38px minmax(0, 1fr) 38px;
    gap: 10px;
  }

  .pill {
    min-width: 78px;
  }

  .conversation-item {
    grid-template-columns: 46px minmax(0, 1fr);
    gap: 10px;
    padding: 9px 8px;
  }

  .conv-avatar {
    width: 46px;
    height: 46px;
  }

  .msg {
    max-width: 88%;
  }

  .user-detail-header {
    position: sticky;
    top: 0;
    z-index: 4;
    min-height: 54px;
    padding: 6px 12px 10px;
  }

  .tg-profile-hero {
    min-height: 170px;
    padding: 14px 14px 12px;
  }

  .tg-profile-top {
    min-height: 140px;
    justify-content: center;
    gap: 10px;
  }

  .tg-profile-avatar-wrap,
  .user-card-avatar,
  .user-card-avatar-fallback {
    width: 88px;
    height: 88px;
  }

  .tg-profile-name {
    font-size: 24px;
  }

  .chat-header {
    position: relative;
    z-index: 4;
    min-height: 54px;
    padding: 6px 12px 10px;
    gap: 10px;
  }

  #chat-back {
    display: inline-grid;
  }

  #chat-profile-trigger.chat-user-btn {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 10px;
  }

  .chat-header-avatar {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }

  #chat-header-title {
    font-size: 15px;
  }

  .chat-header-subtitle {
    font-size: 11px;
  }

  #mark-resolved,
  #mark-waiting {
    min-width: 92px;
    min-height: 40px;
    padding: 0 14px;
    font-size: 14px;
    pointer-events: auto;
    z-index: 5;
  }

  .messages {
    flex: 1 1 auto;
    padding: 8px 12px 12px;
    min-height: 0;
  }

  .reply-form {
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    position: relative;
    z-index: 5;
    background: #101923;
    min-height: 56px;
  }

  html.ios-standalone .reply-form {
    margin-bottom: 6px;
  }

  html.ios-device.chat-open .chat-window {
    grid-template-rows: minmax(0, 1fr) auto;
  }

  html.ios-device.chat-open .chat-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 12;
    min-height: calc(54px + env(safe-area-inset-top));
    padding-top: calc(6px + env(safe-area-inset-top));
  }

  html.ios-device.chat-open .chat-body {
    padding-top: calc(54px + env(safe-area-inset-top));
  }

  .reply-form :is(textarea, #message-input) {
    min-height: 40px;
    max-height: 132px;
    padding: 9px 14px;
    border-radius: 20px;
    font-size: 16px;
  }

  #reply-submit {
    grid-column: auto;
    width: 40px;
    min-width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    font-size: 0;
    position: relative;
    justify-self: end;
    background: linear-gradient(180deg, #56a8f4, #3f95e4);
  }

  #reply-submit::before {
    content: "➤";
    font-size: 16px;
    line-height: 1;
    color: #fff;
    transform: translateX(1px) translateY(-1px);
    display: inline-block;
  }

  .clip-btn {
    width: 40px;
    height: 40px;
  }

  .quick-reply-suggestions {
    left: 0;
    right: 0;
    bottom: calc(100% + 6px);
    padding: 6px;
    max-height: 176px;
  }

  .quick-reply-suggestion {
    min-height: 46px;
    grid-template-columns: 92px minmax(0, 1fr);
    padding: 8px 12px;
  }

  .quick-reply-suggestion-key {
    font-size: 13px;
  }

  .quick-reply-suggestion-text {
    font-size: 11px;
  }

  .dashboard-grid,
  .dashboard-grid.compact,
  .profile-grid,
  .admin-create-form {
    grid-template-columns: 1fr;
  }

  .users-toolbar {
    justify-content: stretch;
  }

  .users-create-btn {
    width: 100%;
    justify-content: center;
  }

  .staff-summary-main {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 10px;
  }

  .quick-reply-item {
    grid-template-columns: 1fr;
  }

  .quick-reply-actions {
    width: 100%;
  }

  .quick-reply-action-btn {
    flex: 1 1 0;
  }

  .staff-avatar {
    width: 40px;
    height: 40px;
    font-size: 14px;
  }

  .staff-copy-top {
    flex-wrap: wrap;
  }

  .staff-copy-meta {
    white-space: normal;
  }

  .user-detail-content {
    padding: 0 0 8px;
  }

  .msg.has-media {
    width: min(92%, 360px);
    max-width: min(92%, 360px);
  }

  .msg-media-button {
    min-height: 120px;
  }

  .msg-media-button-image {
    max-height: none;
  }

  .msg-media-button-image img {
    max-height: min(40vh, 280px);
  }

  .msg-media-button-video {
    max-height: min(34vh, 240px);
  }

  .media-viewer-card {
    padding: 8px;
  }

  .media-viewer-title {
    font-size: 0;
  }

  .media-viewer-title.has-text {
    font-size: 13px;
  }

  .media-viewer-image {
    max-height: calc(100dvh - 40px);
  }
}
