/* ===== 手机端布局（PWA / APP 视图） =====
   触发条件：窄屏 或 ?ui=mobile（Electron 桌面端用 data-force-desktop 固定桌面布局） */

@media (max-width: 860px) {
  :root { --list-w: 100%; }
  .shell { flex-direction: column; height: 100dvh; position: relative; }

  /* 底部 Tab 栏固定在最下方，不再占用文档流 */
  .rail {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: 100%; height: auto; flex-direction: row; align-items: center;
    justify-content: space-around; padding: 4px 6px calc(4px + var(--safe-b));
    border-right: 0; border-top: 1px solid var(--line); background: var(--bg-head);
    z-index: 30; transition: transform .24s var(--ease);
  }
  .app-chat-open .rail { transform: translateY(110%); pointer-events: none; }
  .app-chat-open .chat-panel { bottom: 0; }
  .rail-top, .rail-bottom { display: none; }
  .rail-mid { flex-direction: row; flex: 1; justify-content: space-around; gap: 0; }
  .rail-btn { width: 58px; height: 46px; border-radius: 12px; }
  .rail-btn.active { background: transparent; color: var(--accent); }
  .rail-btn.active::after {
    content: ""; position: absolute; bottom: 2px; width: 18px; height: 2.5px; border-radius: 2px; background: var(--accent);
  }
  .rail-badge { top: 2px; right: 8px; }

  /* 列表全屏（底部给 Tab 栏让位） */
  .list-panel {
    order: 1; width: 100%; flex: 1; border-right: 0; min-height: 0;
    position: absolute; top: 0; left: 0; right: 0; bottom: calc(54px + var(--safe-b)); z-index: 4;
    transition: transform .26s var(--ease), opacity .2s;
    will-change: transform;
  }
  .list-head { padding-top: calc(10px + var(--safe-t)); }
  .list-title-row { padding: 2px 4px 10px; }
  .list-title-row h2 { font-size: 24px; letter-spacing: -.4px; }
  .list-item { padding: 10px 12px; gap: 12px; border-radius: 12px; margin-bottom: 2px; }
  .list-item .avatar { width: 52px; height: 52px; font-size: 18px; }
  .li-name { font-size: 16px; }
  .li-preview { font-size: 13.5px; }

  /* 聊天区：从右侧滑入，同样给 Tab 栏让位 */
  .chat-panel {
    order: 2; position: absolute; top: 0; left: 0; right: 0; bottom: calc(54px + var(--safe-b)); z-index: 8;
    transform: translateX(100%); transition: transform .26s var(--ease);
    will-change: transform; background-color: var(--bg-chat);
  }
  .app-chat-open .chat-panel { transform: translateX(0); }
  .app-chat-open .list-panel { transform: translateX(-22%); opacity: 0; pointer-events: none; }
  .chat-empty { display: none !important; }
  .back-btn { display: grid; }
  .chat-head { height: auto; flex: 0 0 auto; padding: calc(8px + var(--safe-t)) 10px 8px; gap: 9px; }
  .chat-head-avatar .avatar { width: 36px; height: 36px; }
  .chat-head-name { font-size: 15.5px; }
  .chat-head-actions .icon-btn { width: 34px; height: 34px; }

  .msg-row { padding: 1px 10px; }
  .msg-col { max-width: 82%; }
  .bubble { font-size: 15.5px; padding: 8px 12px 7px; border-radius: 14px; }
  .msg-row.out .bubble { border-bottom-right-radius: 5px; }
  .msg-row.in .bubble { border-bottom-left-radius: 5px; }
  .img-single { max-width: 62vw; }
  .album { width: 66vw; }
  .composer { padding: 6px 8px calc(8px + var(--safe-b)); }
  .composer textarea { font-size: 16px; /* 防 iOS 聚焦缩放 */ padding: 11px 14px; }
  .composer-row { gap: 4px; }
  .composer .icon-btn { width: 36px; height: 36px; }
  .send-btn { width: 42px; height: 42px; }
  .emoji-panel { left: 8px; right: 8px; width: auto; bottom: calc(100% + 6px); height: 300px; }
  .emoji-grid { grid-template-columns: repeat(7, 1fr); }
  .emoji-grid button { height: 44px; font-size: 24px; }
  .list-item.active { background: var(--bg-hover); }

  /* 弹层全宽 */
  .modal { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; }
  .modal-host { place-items: stretch; }
  .modal-head { padding-top: calc(14px + var(--safe-t)); }
  .modal-body { padding-bottom: calc(24px + var(--safe-b)); }
  .modal-foot { padding-bottom: calc(14px + var(--safe-b)); }
  .modal-backdrop { display: none; }
  .lb-nav { display: none; }
  .toast-host { bottom: calc(76px + var(--safe-b)); }
  .scroll-down { right: 12px; bottom: 12px; width: 40px; height: 40px; }
  .ctx-menu { min-width: 170px; }
}

@media (min-width: 861px) {
  .app-chat-open .list-panel { transform: none; }
}

/* 强制桌面布局（Electron 客户端） */
html[data-force-desktop] .rail { width: var(--rail-w); flex: 0 0 var(--rail-w); flex-direction: column; justify-content: flex-start; height: 100dvh; border-top: 0; border-right: 1px solid var(--line); padding: 10px 0 12px; }
html[data-force-desktop] .rail-top, html[data-force-desktop] .rail-bottom { display: grid; }
html[data-force-desktop] .rail-mid { flex-direction: column; justify-content: flex-start; flex: 1; }
html[data-force-desktop] .list-panel { position: static; transform: none; width: var(--list-w); flex: 0 0 var(--list-w); border-right: 1px solid var(--line); opacity: 1; pointer-events: auto; }
html[data-force-desktop] .chat-panel { position: static; transform: none; }
html[data-force-desktop] .back-btn { display: none; }
html[data-force-desktop] .modal { width: min(520px, calc(100vw - 32px)); height: auto; max-height: 84vh; border-radius: 16px; border: 1px solid var(--line); }
