/* ========== رسپانسیو موبایل (عرض ≤ ۹۰۰px) ========== */
@media (max-width: 900px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
    overflow: hidden;
  }

  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    background: var(--panel);
    transform: translateX(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    border-left: none;
    overflow: hidden;
  }

  .chat {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    z-index: 200;
    background: var(--bg);
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .chat.active { transform: translateX(0); }
  .chat.active ~ .sidebar { transform: translateX(-100%); }

  .sidebar-header {
    flex-shrink: 0;
    height: 60px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    background: rgba(23, 33, 43, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
  }

  .hamburger-menu { display: flex !important; margin-left: 8px; }
  .sidebar-brand {
    font-size: 18px;
    font-weight: 700;
    flex: 1;
    text-align: right;
  }

  .search-container {
    flex-shrink: 0;
    padding: 12px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
  }
  #userSearchInput {
    height: 44px;
    border-radius: 10px;
    font-size: 15px;
  }

  .room-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--panel);
  }

  .back-to-rooms {
    display: flex !important;
    order: -1;
    margin-right: 10px;
    margin-left: 0;
  }

  .chat.active .chat-header {
    display: flex !important;
    height: 60px;
    padding: 0;
    align-items: center;
    background: rgba(23, 33, 43, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    width: 100%;
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 300;
  }
  .chat.active .chat-header-left {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 16px;
  }
  .chat-header-info {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    margin-left: 0;
  }
  .chat-header-avatar {
    width: 40px;
    height: 40px;
    margin-left: 12px;
  }
  .chat-header-text { flex: 1; min-width: 0; }
  .chat-title {
    font-weight: 900;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: right;
  }
  .chat-sub {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: right;
  }

  .back-to-rooms {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 90, 90, 0.1);
    border: 1px solid rgba(255, 90, 90, 0.3);
    color: #ff6b6b;
    margin-right: auto;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
  }
  .back-to-rooms:hover { background: rgba(255, 90, 90, 0.2); transform: scale(1.05); }
  .back-to-rooms:active { transform: scale(0.95); }

  .chat.active .composer {
    display: flex !important;
    padding: 10px 16px;
    background: rgba(23, 33, 43, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    width: 100%;
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    z-index: 300;
  }

  .chat.active .messages {
    flex: 1;
    padding: 76px 12px 70px 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #uploadPreview {
    position: fixed;
    bottom: 70px;
    right: 0;
    left: 0;
    z-index: 250;
    padding: 10px 16px;
    background: var(--panel);
    border-top: 1px solid var(--border);
  }

  #voiceRecordingPreview {
    position: fixed;
    bottom: 70px;
    right: 0;
    left: 0;
    z-index: 250;
    margin: 0;
    border-radius: 0;
    border-top: 1px solid var(--border);
  }

  .room-item {
    padding: 16px;
    min-height: 72px;
    -webkit-tap-highlight-color: transparent;
  }
  .room-item:active { background-color: rgba(255, 255, 255, 0.05); }
  .room-avatar {
    width: 48px;
    height: 48px;
    font-size: 18px;
  }
  .room-name {
    font-size: 16px;
    font-weight: 700;
  }
  .room-meta { font-size: 12px; }

  .user-dropdown {
    position: fixed;
    top: 60px;
    right: 16px;
    left: 16px;
    width: auto;
    max-height: 70vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  }

  .search-results {
    position: fixed;
    top: 140px;
    left: 16px;
    right: 16px;
    max-height: 60vh;
  }

  .modal-card {
    width: 95vw;
    max-height: 85vh;
    margin: 0;
  }

  input, textarea, select { font-size: 16px; }

  button, .room-item, .search-result-item {
    cursor: pointer;
    user-select: none;
  }

  .sidebar, .chat {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .room-item.active { animation: roomSelect 0.2s ease; }
  @keyframes roomSelect {
    0% { background-color: transparent; }
    50% { background-color: rgba(46, 166, 255, 0.2); }
    100% { background-color: rgba(46, 166, 255, 0.12); }
  }

  .unread-badge {
    min-width: 22px;
    height: 22px;
    font-size: 11px;
    animation: pulse 2s infinite;
  }

  .chat:not(.active) { display: none; }
}

/* ========== حالت دسکتاپ (عرض ≥ ۹۰۱px) ========== */
@media (min-width: 901px) {
  .back-to-rooms { display: none !important; }
  .app-shell {
    display: grid;
    grid-template-columns: 360px 1fr;
  }
  .sidebar {
    position: relative;
    transform: none !important;
    height: 100vh;
  }
  .chat {
    position: relative;
    transform: none !important;
    height: 100vh;
  }
  .chat-header { display: none; }
  .chat.active .chat-header { display: flex; }
  .chat.active .composer { display: flex !important; padding: 10px 12px; position: sticky; bottom: 0; }
  .chat.active .messages { padding: 18px 16px; }
}

/* ========== انیمیشن‌های انتقال ========== */
.sidebar, .chat {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}