@charset "utf-8";
/* ==========================================================================
   mobile.css —— 手机端专属样式
   --------------------------------------------------------------------------
   为什么单独一个文件：composer.css / bottom.css 在 style.css 之后加载，
   同优先级的规则会被它们覆盖（实测 textarea 的 min-height 就被 composer.css
   的 72px 顶掉了）。所以手机端覆盖统一放这里，在 index.html 里最后引入。

   2026-11-25 修的问题：
     1) 24 个角色标签在 360px 宽里折成 7 行，把消息区挤到只剩 32px
        → 角色条改成「当前角色 + 底部弹层选择」
     2) .chat-shell 用 calc(100dvh - ...) 硬算高度，键盘一弹就算错
        → 改成撑满父容器，由各区块自己滚
     3) 输入框在手机上 181px 高，吃掉近三分之一屏幕
        → 降到 1~2 行（聚焦后随内容长高）
     4) 页面本身可滚动 66px，底栏被推出屏幕
        → 一屏锁定，只有内容区滚
   ========================================================================== */

.role-picker { display: none; }

@media (max-width: 899px) {
  /* ---- 1. 一屏布局：页面不滚，各区块自己滚 ---- */
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  /* 注意：安卓 WebView 版本差异很大。华为 Mate9 自带的是 Chrome 92，
     dvh 单位要 Chrome 108 才有 —— 老内核上 `height: 100dvh` 整条声明被忽略，
     #app 退化成按内容撑高，底部输入框就被挤出屏幕（真机实测 main=697 > 视口 616）。
     所以先用 100% 保证老内核正确，再对支持的内核升级成 dvh。 */
  #app {
    height: 100%;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas: "topbar" "main";
    overflow: hidden;
  }
  @supports (height: 100dvh) {
    #app { height: 100dvh; }
  }
  .main {
    height: 100%; min-height: 0;
    overflow: hidden;
    display: flex; flex-direction: column;
    padding: 8px 8px 0;
    padding-bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
  }
  .main > .tab { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .main > .tab.active { display: flex; flex-direction: column; }
  /* 用 grid + 单行 minmax(0,1fr) 逼住高度。
     之前用 flex 时，.chat-shell 仍按内容(548)撑开，超出容器(498)，
     结果底部输入框被固定底栏盖住 —— flex 的 stretch 没压住它的内容高度。 */
  .workbench {
    flex: 1 1 auto; min-height: 0; height: 100%;
    display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
  }
  .workbench > .chat-shell { height: 100%; min-height: 0; }
  .chat-shell {
    flex: 1 1 auto; min-height: 0; height: auto;
    grid-template-rows: auto minmax(0, 1fr) auto;
    border-radius: var(--r-md);
  }
  .chat-log { min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .chat-welcome { margin: 0 auto; padding: var(--sp-4) var(--sp-3); }

  /* ---- 2. 角色条：桌面长条藏起来，换成一行选择器 ---- */
  .chat-toolbar { flex-wrap: nowrap; padding: 8px 10px; }
  .role-tabs { display: none; }
  .role-picker {
    display: flex; align-items: center; gap: 10px;
    width: 100%; min-height: 48px; padding: 6px 10px;
    background: var(--raised); border: 1px solid var(--border);
    border-radius: var(--r-md); font-family: inherit; text-align: left;
    -webkit-tap-highlight-color: transparent;
  }
  .role-picker:active { background: var(--sunken); }
  .rp-avatar {
    flex: 0 0 auto; width: 32px; height: 32px; border-radius: 8px;
    display: grid; place-items: center;
    background: var(--accent-dim); color: var(--accent);
    font-size: 0.875rem; font-weight: 600;
  }
  .rp-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
  .rp-name { font-size: 0.875rem; font-weight: 600; color: var(--fg); }
  .rp-duty {
    font-size: 0.6875rem; color: var(--fg-3); line-height: 1.35;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .rp-chev { flex: 0 0 auto; color: var(--fg-3); display: flex; }

  /* ---- 3. 输入区：手机上 1~2 行就够 ---- */
  /* 注意：这几条要压过 composer.css，所以写得更具体 + 用 !important 兜底 */
  .chat-shell .composer { flex: 0 0 auto; padding: 6px 10px 8px; }
  .chat-shell .composer-box { padding: 6px 10px 6px; border-radius: var(--r-md); }
  .chat-shell .composer textarea {
    min-height: 40px !important; max-height: 108px !important;
    font-size: 1rem !important;   /* 小于 16px 时手机聚焦会把页面整体放大 */
    line-height: 1.5; padding: 4px 0;
  }
  .chat-shell .composer-hint { display: none; }
  .chat-shell .composer-bar { margin-top: 2px; padding-top: 6px; }
  .chat-shell .composer-send { min-height: 38px; padding: 0 16px; }

  /* ---- 4. 顶栏：手机上只留必要按钮，图标加大到好点 ---- */
  .topbar { padding: 0 10px; gap: 4px; }
  .topbar .status #status-text { display: none; }
  .topbar .icon-btn { width: 38px; height: 38px; }
  #tab-title { font-size: 1rem; }

  /* ---- 5. 弹层：从底部升起 ---- */
  .role-sheet { display: block; position: fixed; inset: 0; z-index: 200; }
  .role-sheet[hidden] { display: none; }
  .role-sheet-mask {
    position: absolute; inset: 0; background: rgba(0,0,0,.32);
    opacity: 0; transition: opacity var(--dur) var(--ease-out);
  }
  .role-sheet.open .role-sheet-mask { opacity: 1; }
  .role-sheet-body {
    position: absolute; left: 0; right: 0; bottom: 0;
    max-height: 78vh; display: flex; flex-direction: column;
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateY(100%);
    transition: transform var(--dur-slow) var(--ease-out);
    box-shadow: var(--shadow-up);
  }
  .role-sheet.open .role-sheet-body { transform: translateY(0); }
  .role-sheet-grab {
    width: 36px; height: 4px; border-radius: 999px;
    background: var(--border-hi); margin: 8px auto 2px;
  }
  .role-sheet-head {
    padding: 8px 16px 10px; font-size: 0.875rem; font-weight: 600; color: var(--fg);
    border-bottom: 1px solid var(--border);
  }

  /* 弹层头部：标题 + 关闭按钮。
     光靠点遮罩不够 —— 手机上用户不敢乱点，得有一个看得见的关闭方式。 */
  .role-sheet-head {
    display: flex; align-items: center; justify-content: space-between;
  }
  .role-sheet-x {
    width: 40px; height: 40px; margin: 0px 0px 0px 0;
    display: grid; place-items: center;
    background: none; border: 0; color: var(--fg-3);
    border-radius: 50%; -webkit-tap-highlight-color: transparent;
  }
  .role-sheet-x:active { background: var(--sunken); color: var(--fg); }
  .role-sheet-x .icon { width: 20px; height: 20px; }

  .role-sheet-list {
    flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: 6px 10px 12px;
  }
  .role-sheet .role-group {
    display: flex; flex-wrap: wrap; align-items: center;
    gap: 6px; padding: 8px 0 4px;
  }
  .role-sheet .role-group-name {
    flex: 0 0 100%; font-size: 0.6875rem; color: var(--fg-3);
    font-weight: 500; letter-spacing: .02em;
  }
  .role-sheet .role-chip {
    font-size: 0.8125rem; padding: 8px 12px; min-height: 40px;
    background: var(--raised); border-color: var(--border); color: var(--fg-2);
  }
  .role-sheet .role-chip.active {
    background: var(--accent-dim); border-color: var(--accent-line); color: var(--accent);
  }
}

/* 支持 dvh 的内核上用 dvh（带地址栏的浏览器里，vh 会把地址栏高度也算进去） */
@supports (height: 100dvh) {
  @media (max-width: 899px) {
    .role-sheet-body { max-height: 78dvh; }
  }
}

/* 桌面：弹层不参与布局（选择器按钮也隐藏，用横排标签） */
@media (min-width: 900px) {
  .role-sheet { display: none; }
}


/* ══════════════════════════════════════════════════════════════
   以下是后来追加的手机规则。
   教训：mobile.css 里 @media 之外写东西 = 对桌面也生效。
   上一次把「隐藏顶部切换」写在媒体查询外面，桌面直接看不到切换按钮了。
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 899px) {
  /* 语音输入：手机上按 40px 起，低于这个用拇指点不准 */
  .chat-shell .composer-mic { min-width: 40px; min-height: 40px; margin-left: 4px; }

  /* ── 对话对象 ──
     360px 宽放不下「切换 + 找谁 + 当前对象」一行：
     切换收进弹层，顶部只留「找谁」整行 + 当前对象按钮。 */
  .chat-toolbar { flex-wrap: wrap; gap: 6px; }
  .chat-toolbar .toolbar-switch { display: none; }
  .chat-toolbar .contact-find { order: 2; flex: 1 1 100%; min-width: 0; }
  .chat-toolbar .contact-find-mic { width: 32px; height: 32px; }
  .chat-toolbar .role-tabs { display: none; }
  .chat-toolbar .role-picker { order: 3; flex: 1 1 100%; }

  /* 弹层里的切换和搜索 */
  .sheet-switch { margin: 0 16px 10px; display: flex; }
  .sheet-switch button { flex: 1 1 auto; text-align: center; }
}
