@media (max-width: 768px) {
  html,
  body {
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    overflow: hidden;
  }

  body {
    max-width: 100vw;
    overscroll-behavior: none;
  }

  .app {
    grid-template-columns: 1fr;
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    max-width: 100vw;
    overflow: hidden;
  }

  .sidebar {
    display: flex;
    width: 100%;
    height: 100dvh;
    min-width: 0;
    min-height: 0;
    border-right: 0;
    overflow: hidden;
  }

  .profile {
    min-height: 64px;
    padding: 10px 12px;
    gap: 8px;
    flex-shrink: 0;
  }

  .profile-main {
    gap: 10px;
  }

  .avatar {
    width: 38px;
    height: 38px;
    border-radius: 10px;
  }

  .profile-name {
    font-size: 15px;
  }

  .profile-status {
    font-size: 12px;
  }

  .logout-button {
    min-width: 44px;
    width: auto;
    height: 36px;
    padding: 0 10px;
    font-size: 12px;
  }

  .sidebar-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-section {
    padding: 0;
  }

  .sidebar-section-header {
    min-height: 46px;
    padding: 12px;
    gap: 10px;
    font-size: 11px;
  }

  .sidebar-section-body {
    padding: 0 8px 10px;
    gap: 6px;
    max-height: none;
    overflow: visible;
  }

  .sidebar-item {
    min-height: 52px;
    padding: 8px;
    gap: 8px;
    border-radius: 8px;
  }

  .sidebar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 9px;
  }

  .sidebar-item-main {
    min-width: 0;
  }

  .sidebar-item-title,
  .sidebar-item-subtitle {
    max-width: 100%;
  }

  .sidebar-item-meta {
    max-width: 72px;
    font-size: 11px;
  }

  .sidebar-item-menu-button {
    width: 40px;
    height: 40px;
    margin-left: 0;
    border-radius: 10px;
    background: #232323;
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 40px;
    font-size: 24px;
    line-height: 1;
    font-weight: 800;
  }

  .sidebar-item-menu-button:active {
    background: #2d2618;
    color: var(--accent-strong);
  }

  .profile-sound-row {
    grid-template-columns: 1fr;
  }

  .profile-notification-action {
    grid-template-columns: 1fr;
  }

  .toast-container {
    left: 10px;
    right: 10px;
    bottom: calc(86px + env(safe-area-inset-bottom, 0px));
    width: auto;
  }

  body:not(.mobile-chat-open) .toast-container,
  .app:not(.mobile-chat-open) ~ .toast-container {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .toast {
    border-radius: 9px;
  }

  .unread-badge {
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
  }

  .friend-request-item,
  .group-member-option,
  .member-row,
  .manageable-group-row {
    min-height: 52px;
    padding: 10px;
  }

  .friend-request-item {
    align-items: center;
    flex-wrap: wrap;
  }

  .friend-request-actions,
  .member-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .friend-action-button,
  .member-action-button,
  .secondary-modal-button {
    min-height: 38px;
  }

  .friend-request-name {
    flex: 1 1 110px;
    font-size: 13px;
  }

  .friend-request-actions {
    flex: 0 1 auto;
    max-width: 100%;
  }

  .friend-action-button {
    min-height: 30px;
    padding: 0 8px;
    font-size: 11px;
  }

  .app-version {
    margin-top: 0;
    padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
    flex-shrink: 0;
  }

  .chat {
    position: fixed;
    inset: 0;
    z-index: 20;
    width: 100%;
    max-width: 100vw;
    height: 100dvh;
    min-height: 0;
    transform: translateX(100%);
    transition: transform 0.2s ease;
    grid-template-rows: 64px minmax(0, 1fr) auto;
    overflow: hidden;
  }

  body.mobile-chat-open .chat,
  .app.mobile-chat-open .chat {
    transform: translateX(0);
  }

  body.mobile-chat-open .sidebar,
  .app.mobile-chat-open .sidebar {
    pointer-events: none;
  }

  .chat-header {
    height: 64px;
    min-height: 64px;
    padding: 8px 10px;
    gap: 8px;
  }

  .mobile-back-button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: #232323;
    color: var(--accent-strong);
    display: none;
    align-items: center;
    justify-content: center;
    flex: 0 0 44px;
    font-size: 24px;
    font-weight: 800;
  }

  body.mobile-chat-open .mobile-back-button,
  .app.mobile-chat-open .mobile-back-button {
    display: inline-flex;
  }

  .chat-header-info {
    min-width: 0;
  }

  .chat-header h1 {
    font-size: 17px;
    line-height: 1.2;
  }

  .chat-header p {
    margin-top: 3px;
    font-size: 12px;
    line-height: 1.25;
  }

  .messages {
    min-height: 0;
    padding: 12px;
    gap: 10px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .message {
    max-width: 92%;
    padding: 9px 11px;
    border-radius: 12px;
    overflow-wrap: anywhere;
  }

  .system-message {
    max-width: 92%;
    border-radius: 10px;
  }

  .file-message {
    width: min(92%, calc(100vw - 24px));
    max-width: 92%;
  }

  .file-card {
    width: 100%;
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
  }

  .file-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 19px;
  }

  .file-card-title {
    min-width: 0;
  }

  .file-card-meta {
    overflow-wrap: anywhere;
  }

  .file-card-download {
    grid-column: 1 / -1;
    width: 100%;
    min-height: 42px;
  }

  .file-unavailable-badge {
    grid-column: 1 / -1;
    width: 100%;
    min-height: 38px;
  }

  .file-download-progress {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
  }

  .message-form {
    width: 100%;
    min-height: 0;
    max-height: 40dvh;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    gap: 8px;
    overflow: visible;
  }

  .message-form .file-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 10px;
    flex: 0 0 44px;
  }

  .message-form textarea {
    min-height: 44px;
    max-height: 128px;
    padding: 12px;
    border-radius: 10px;
    overflow-y: auto;
  }

  .message-form button:not(.file-button) {
    width: 88px;
    min-width: 0;
    height: 44px;
    padding: 0 8px;
    border-radius: 10px;
    flex: 0 0 88px;
    overflow: hidden;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .modal,
  .auth-modal,
  .confirm-modal,
  .modal-overlay {
    padding: 12px;
    overflow: hidden;
  }

  .modal-window,
  .auth-window,
  .confirm-window {
    width: calc(100vw - 24px);
    max-width: none;
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    padding: 18px;
    border-radius: 14px;
  }

  .modal-window form {
    flex-direction: column;
  }

  .modal-window input,
  .modal-window select,
  .auth-window input,
  .file-caption-input {
    min-height: 44px;
  }

  input[type="checkbox"] {
    min-height: 20px;
  }

  .modal-actions,
  .confirm-actions,
  .member-admin-actions {
    flex-wrap: wrap;
    justify-content: stretch;
  }

  .modal-actions > button,
  .confirm-actions > button,
  .member-admin-actions > button {
    flex: 1 1 132px;
    min-height: 42px;
  }

  .group-members-list,
  .members-list,
  .manageable-groups-list {
    max-height: min(300px, 42dvh);
  }

  .member-row,
  .manageable-group-row,
  .ownership-transfer-row {
    align-items: flex-start;
  }

  .file-upload-modal .modal-window {
    max-width: none;
  }

  .file-upload-summary {
    margin: 12px 0;
    padding: 10px;
  }

  .file-preview-image {
    max-height: min(220px, 32dvh);
  }

  .file-caption-input {
    min-height: 84px;
    max-height: 26dvh;
    resize: none;
  }

  .attachment-composer {
    margin: 0 12px 10px;
    padding: 12px;
    max-height: min(56dvh, 460px);
  }

  .attachment-preview {
    grid-template-columns: 1fr;
  }

  .attachment-preview-image {
    max-height: min(220px, 28dvh);
  }

  .attachment-caption {
    min-height: 78px;
    max-height: 22dvh;
    resize: none;
  }

  .attachment-no-compress,
  .file-no-compress {
    align-items: flex-start;
  }

  .attachment-actions {
    flex-wrap: wrap;
  }

  .attachment-actions > button {
    flex: 1 1 132px;
  }

  .file-upload-progress,
  .attachment-progress,
  .file-download-progress {
    padding: 10px;
  }

  .context-menu,
  .group-actions-menu {
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
  }


  .message.image-message {
    width: min(92%, calc(100vw - 24px));
    max-width: 92%;
    padding: 8px;
  }

  .message.image-message.image-unavailable {
    width: fit-content;
    max-width: min(92%, calc(100vw - 24px));
  }

  .chat-photo {
    max-height: min(420px, 52dvh);
    border-radius: 10px;
  }

  .message-image-unavailable,
  .image-unavailable-message {
    min-height: 36px;
    max-height: 44px;
    padding: 7px 10px;
    font-size: 13px;
  }

}
