/* ============================================================
 * 96-mobile.css —— 手机端布局（重要：手机上要能用）
 *
 * 手机上的核心问题（从截图看到的）：
 *   ① 输入框被工具栏和发送按钮挤成一条缝，文字竖着排
 *   ② 顶栏"在线 6 人 + 日期 + 搜索"挤成两行
 *   ③ 侧栏占地方，聊天区窄
 *   ④ 弹窗贴边、按钮点不到
 *
 * 处理原则：
 *   · 输入框永远优先占满宽度；工具栏按钮缩小但保持可点
 *   · 次要功能收进"更多"，不跟输入框抢位置
 *   · 触控目标最小 36px（手指点得中）
 *   · 适配 iPhone 底部安全区（env(safe-area-inset-bottom)）
 * ============================================================ */

/* ==================== 手机（≤640px） ==================== */
@media (max-width: 640px) {

  /* ---------- ① 输入区：输入框优先占满 ---------- */
  .composer {
    display: flex !important;
    align-items: flex-end !important;
    gap: 6px !important;
    padding: 6px 8px !important;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)) !important;
    flex-wrap: nowrap !important;
  }

  /* 输入框：能缩能长，最少留出 120px，不再被挤成竖条 */
  .composer #input-msg,
  .composer textarea {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    width: auto !important;
    max-width: none !important;
    min-height: 36px !important;
    max-height: 96px !important;
    padding: 8px 10px !important;
    font-size: 15px !important;   /* iOS 上 <16px 会触发自动放大，这里用 15 + 下面禁用缩放 */
    line-height: 1.4 !important;
    white-space: pre-wrap !important;
    word-break: break-word !important;
  }

  /* 发送按钮：固定宽度，不抢输入框 */
  .composer #btn-send,
  .composer .btn.primary {
    flex: 0 0 auto !important;
    min-width: 56px !important;
    height: 36px !important;
    padding: 0 12px !important;
    font-size: 14px !important;
  }

  /* 工具栏按钮（表情/语音/图片…）：缩小成 32px 方块，横着排一行 */
  .composer > .btn.ghost,
  .composer > button.icon,
  .composer .tool-btn {
    flex: 0 0 auto !important;
    width: 32px !important;
    min-width: 32px !important;
    height: 36px !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .composer > .btn.ghost .ico,
  .composer > button.icon .ico {
    width: 19px !important;
    height: 19px !important;
  }

  /* 手机上工具栏最多显示 3 个按钮，其余收起来（避免挤成一坨） */
  .composer > .btn.ghost:nth-of-type(n + 4),
  .composer > button.icon:nth-of-type(n + 4) {
    display: none !important;
  }

  /* ---------- ② 房间顶栏：一行放下 ---------- */
  .room-head,
  .chat-head,
  .messages-head {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    padding: 6px 8px !important;
    flex-wrap: nowrap !important;
    overflow: hidden !important;
  }

  /* 日期选择器、搜索框在手机上收起来（省地方） */
  .room-head .jump-date,
  .room-head #jump-date,
  .room-head .search-input,
  .room-head #search-input,
  .jump-date,
  #jump-date,
  .search-input,
  #search-input {
    display: none !important;
  }

  .room-head h2,
  .chat-head h2 {
    font-size: 15px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }

  /* 在线人数/状态：不换行 */
  .room-head .room-online,
  .chat-head .room-online {
    font-size: 12px !important;
    white-space: nowrap !important;
    flex: 0 0 auto !important;
  }

  /* ---------- ③ 侧栏：手机上是抽屉，默认收起 ---------- */
  #sidebar {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    width: 78vw !important;
    max-width: 300px !important;
    z-index: 60 !important;
    background: var(--panel, #fff) !important;
    box-shadow: 2px 0 16px rgba(0, 0, 0, .18) !important;
    transform: translateX(-104%) !important;
    transition: transform .22s ease !important;
    overflow-y: auto !important;
  }
  #sidebar.open,
  body.sidebar-open #sidebar {
    transform: translateX(0) !important;
  }

  /* 主区域占满整屏 */
  .main,
  .chat,
  .chat-main {
    width: 100% !important;
    min-width: 0 !important;
  }

  /* ---------- ④ 弹窗：手机全屏更顺手 ---------- */
  .mask .modal,
  .modal {
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    max-height: calc(100vh - 32px) !important;
    border-radius: 14px !important;
    padding: 16px 14px !important;
  }

  .modal.profile-modal,
  .modal.gift-modal,
  .modal.sched-modal {
    width: calc(100vw - 16px) !important;
  }

  /* 按钮：手指点得中 */
  .modal .btn,
  .modal-actions .btn {
    min-height: 40px !important;
    font-size: 15px !important;
  }

  /* ---------- ⑤ 消息区 ---------- */
  .messages {
    padding: 8px 8px 4px !important;
  }

  .msg {
    max-width: 88% !important;
  }
  .msg .bubble {
    font-size: 15px !important;
    line-height: 1.5 !important;
    padding: 8px 10px !important;
    word-break: break-word !important;
  }
  .msg .avatar {
    width: 32px !important;
    height: 32px !important;
  }

  /* 长网址/长代码不要撑破屏幕 */
  .msg .bubble pre,
  .msg .bubble code,
  .msg .bubble a {
    overflow-wrap: anywhere !important;
    word-break: break-all !important;
  }
  .msg .bubble pre {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* ---------- ⑥ 更多面板 ---------- */
  .more-panel {
    width: calc(100vw - 24px) !important;
    max-width: 360px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    right: auto !important;
  }

  /* ---------- ⑦ 底部安全区（iPhone 小白条） ---------- */
  .composer {
    margin-bottom: 0 !important;
  }
  .app,
  .shell {
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
  }
}

/* ==================== 小手机（≤380px） ==================== */
@media (max-width: 380px) {
  .composer > .btn.ghost:nth-of-type(n + 3),
  .composer > button.icon:nth-of-type(n + 3) {
    display: none !important;
  }
  .composer #input-msg { font-size: 14px !important; }
  .composer #btn-send { min-width: 48px !important; padding: 0 8px !important; }
}

/* ==================== 触屏通用：去掉 hover 效果、加大点击区 ==================== */
@media (hover: none), (pointer: coarse) {
  .more-cell:hover,
  .btn:hover,
  .member-btn:hover {
    filter: none !important;
  }
  .more-cell:active,
  .btn:active {
    transform: scale(.96);
  }
  /* 成员列表里的小按钮点得中 */
  .member-btn {
    min-width: 34px !important;
    min-height: 34px !important;
  }
}

/* ==================== 横屏（手机横过来） ==================== */
@media (orientation: landscape) and (max-height: 480px) {
  .composer textarea,
  .composer #input-msg {
    max-height: 56px !important;
  }
  .messages {
    padding-bottom: 2px !important;
  }
}
