/* ==================== 队列面板（极简版） ==================== */

.queue-badge {
    position: absolute; top: -4px; right: -4px;
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 14px; height: 14px; padding: 0 3px;
    font-size:  var(--fs-3xs); font-weight: 700; line-height: 1;
    color: #fff; background: var(--accent);
    border-radius: 7px;
    box-shadow: 0 1px 3px color-mix(in srgb, var(--accent) 30%, transparent);
    pointer-events: none;
}
.queue-badge.has-items { animation: queueBadgePop .25s ease; }
@keyframes queueBadgePop {
    0% { transform: scale(0.5); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.queue-panel {
    position: absolute;
    bottom: 6px;
    left: 8px;
    right: 20px;
    z-index: var(--z-float-btn);
    max-height: 0;
    overflow: hidden;
    transition: max-height .28s ease, opacity .2s ease, border-color .25s ease;
    opacity: 0;
    border-bottom: 1px solid transparent;
}
.queue-panel.open {
    max-height: min(40vh, var(--panel-max-h, 40vh));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 1;
    border-bottom-color: var(--border-strong);
    background: var(--bg-hover);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    box-shadow: var(--shadow-panel);
}
/* 面板内层容器：flex 纵向布局，由列表区单独滚动，滚动条不再横跨标题栏 */
.queue-panel-inner {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
    overflow: hidden;
}
.queue-panel-header {
    display: flex; align-items: center;
    padding: 6px 10px;
    font-size:  var(--fs-xs);
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-strong);
    border-left: 3px solid var(--accent);
    border-radius: 7px 0 0 0;
    background: var(--bg-active);
    cursor: pointer; user-select: none;
    flex-shrink: 0;
}
.queue-panel-header:hover { background: var(--bg-hover); }
.queue-panel-title { flex: 1; }
.queue-panel-header .queue-panel-toggle {
    font-size:  var(--fs-3xs); margin-right: 6px;
    transition: transform .2s; flex-shrink: 0;
}
.queue-panel.open .queue-panel-header .queue-panel-toggle {
    transform: rotate(90deg);
}
.queue-panel-count {
    margin-left: auto;
    font-size:  var(--fs-xs);
    font-weight: 400;
    color: var(--text-muted);
}
/* 内容直接渲染在 .queue-panel-inner 中，无 body 包装层 */
.queue-panel-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 2px 0;
}

/* 面板列表自定义滚动条：内容超长时始终可见（移动端 overlay 滚动条默认不显示，仅滚动时闪现）。
   标准属性仅在【不支持 ::-webkit-scrollbar 的引擎】（Firefox 等）生效：
   Chromium 121+ 一旦读到非 auto 的 scrollbar-width / scrollbar-color，会整体忽略下方
   ::-webkit-scrollbar 精调（几何、圆角、hover 全失效，回退系统 thin 厚度），故做引擎分流。 */
@supports (not selector(::-webkit-scrollbar)) or (-moz-appearance: none) {
    .queue-panel-list {
        scrollbar-width: thin;
        scrollbar-color: var(--scrollbar-thumb) transparent;
    }
}
.queue-panel-list::-webkit-scrollbar {
    width: 6px;
    height: 6px; /* 横向条同粗：缺 height 时横向会回退 UA 默认厚度（详见 window.css .messages-container 注释） */
}
.queue-panel-list::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 3px;
}
.queue-panel-list::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}
.queue-panel-list::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* 移动端：隐藏原生 overlay 滚动条（拖动时闪现、停止后消失），改由 JS 滚动条指示器常驻显示 */
@media (max-width: 768px) {
    .queue-panel-list {
        scrollbar-width: none;
    }
    .queue-panel-list::-webkit-scrollbar {
        display: none;
    }
}
/* 输入框：有列表时位于列表滚动区末尾（随列表滚动，滚动到底部即可完整访问，
   不做 sticky 偏移，避免空间不足时被推挤/裁剪）；空队列时作为面板底部
   flex 子项（flex-shrink:0 保持贴底） */
.queue-panel-add {
    display: flex; gap: 6px;
    padding: 5px 10px;
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
    background: var(--bg-hover);
}
.queue-add-input {
    flex: 1; min-width: 0;
    border: 1px solid var(--border);
    border-radius: 3px; padding: 4px 8px;
    font-size:  var(--fs-sm); background: var(--input-bg);
    outline: none;
}.queue-add-input:focus { border-color: var(--accent); }
.queue-add-btn {
    padding: 4px 12px;
    border: none; border-radius: 3px;
    font-size:  var(--fs-xs);
    background: var(--accent); color: #fff;
    cursor: pointer; transition: background .12s;
    flex-shrink: 0;
}
.queue-add-btn:hover { background: var(--accent-hover); }
.queue-add-btn:active { transform: scale(0.95); }
.queue-add-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.queue-add-pri {
    flex-shrink: 0;
    max-width: 78px;
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 3px 4px;
    font-size:  var(--fs-xs);
    background: var(--input-bg);
    color: var(--text-body);
    cursor: pointer;
    outline: none;
}
.queue-add-pri:focus { border-color: var(--accent); }

.queue-panel-empty-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* 队列面板空态滚动区：同样是面板内的滚动区，规格对齐 .queue-panel-list（6px） */
@supports (not selector(::-webkit-scrollbar)) or (-moz-appearance: none) {
    .queue-panel-empty-scroll {
        scrollbar-width: thin;
        scrollbar-color: var(--scrollbar-thumb) transparent;
    }
}
.queue-panel-empty-scroll::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.queue-panel-empty-scroll::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 3px;
}
.queue-panel-empty-scroll::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}
.queue-panel-empty-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

.queue-panel-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    color: var(--text-muted);
    font-size:  var(--fs-sm);
}
.queue-panel-empty-icon {
    font-size:  var(--fs-xl);
    margin-bottom: 4px;
    opacity: 0.4;
}
.queue-panel-empty-sub {
    font-size:  var(--fs-xs);
    margin-top: 4px;
    color: var(--text-muted-light);
}


.queue-item {
    display: flex; align-items: flex-start; gap: 6px;
    padding: 5px 10px; user-select: none;
    transition: background .12s;
    border-bottom: 1px solid var(--border-light);
    /* 优先级文字色：亮色模式局部加深以满足 WCAG AA（与气泡聚合信息一致）
       暗色模式由下方 [data-theme] 覆盖恢复语义色 */
    --task-pri-immediate: #c0392b;
    --task-pri-high:      #a8640e;
    --task-pri-normal:    var(--accent);
    --task-pri-low:       var(--text-muted);
}
/* 暗色模式：语义色本身对比度已达标，恢复语义色更协调 */
[data-theme="dark"] .queue-item {
    --task-pri-immediate: var(--danger);
    --task-pri-high:      var(--warning);
    --task-pri-normal:    var(--accent);
    --task-pri-low:       var(--text-muted);
}
.queue-item:last-child { border-bottom: none; }
.queue-item:hover { background: var(--bg-active); }
.queue-item.dragging { opacity: 0.4; }
.queue-item.drag-over {
    border-top: 2px solid var(--accent);
    background: var(--accent-soft, color-mix(in srgb, var(--accent) 6%, transparent));
}
.queue-item:first-child.drag-over {
    border-top: none;
    border-bottom: 2px solid var(--accent);
}

.queue-item-drag-handle {
    font-size:  var(--fs-xs); color: var(--text-muted);
    cursor: grab; flex-shrink: 0; line-height: 1;
    padding: 4px 2px 0 2px; opacity: 0.4;
    transition: opacity .12s;
}
.queue-item:hover .queue-item-drag-handle { opacity: 0.8; }
.queue-item-drag-handle:active { cursor: grabbing; }

.queue-item-content { flex: 1; min-width: 0; }

.queue-item-main {
    display: flex; align-items: center; gap: 6px; min-height: 22px;
}
.queue-item-icon { font-size:  var(--fs-sm); flex-shrink: 0; line-height: 1.4; }
.queue-item-goal {
    flex: 1; font-size:  var(--fs-sm); color: var(--text-primary);
    line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.queue-meta { display: flex; flex-wrap: wrap; gap: 2px 5px; padding-left: 20px; }
.queue-meta-empty { display: none; }
/* 优先级标签：无背景文字色区分，hover 轻微背景提示可点击切换 */
.queue-pri {
    font-size:  var(--fs-2xs); font-weight: 600; line-height: 1.3;
    cursor: pointer; border-radius: 4px; padding: 0 4px;
    transition: background .12s, color .12s;
}
.queue-pri:hover { background: var(--bg-active); }
.queue-meta-source, .queue-meta-attach {
    font-size:  var(--fs-2xs); color: var(--text-muted); line-height: 1.3;
}

.queue-item-actions {
    display: flex; gap: 2px; flex-shrink: 0;
    opacity: 0; transition: opacity .1s;
}
.queue-item:hover .queue-item-actions { opacity: 1; }

.queue-item-btn {
    width: 22px; height: 22px; border: 0; background: none;
    cursor: pointer; border-radius: 5px;
    display: flex; align-items: center; justify-content: center;
    font-size:  var(--fs-xs); color: var(--text-muted); line-height: 1;
    transition: background .12s, color .12s, transform .12s;
}
.queue-item-btn:active { transform: scale(0.9); }
.queue-item-btn:hover { background: var(--bg-active); color: var(--text-secondary); }
.queue-item-move-up:hover, .queue-item-move-down:hover { color: var(--accent); }
.queue-item-remove:hover { color: var(--danger); }

.queue-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}
.queue-action-btn {
    padding: 2px 8px; font-size:  var(--fs-2xs); border: 0;
    border-radius: 4px; background: none; color: var(--text-muted);
    cursor: pointer; transition: background .12s, color .12s;
}
.queue-action-btn:hover { background: var(--bg-active); }
.queue-action-execute:hover {
    color: var(--accent);
    background: var(--accent-soft, color-mix(in srgb, var(--accent) 6%, transparent));
}
.queue-action-clear:hover {
    color: var(--danger);
    background: var(--danger-soft, color-mix(in srgb, var(--danger) 5%, transparent));
}



/* 移动端 */
@media (max-width: 768px) {
      .queue-item { padding: 2px 8px; gap: 4px; }
      .queue-item-actions { opacity: 1; }
      .queue-item-goal { font-size:  var(--fs-sm); }
      .queue-item-btn { width: 18px; height: 18px; font-size:  var(--fs-2xs); }
      .queue-panel-header { padding: 4px 8px; font-size:  var(--fs-xs); }
    .queue-panel.open { max-height: min(50vh, var(--panel-max-h, 50vh)); }
      .queue-panel-add { padding: 4px 8px; }
    .queue-add-input { font-size:  var(--fs-xs); padding: 3px 6px; }
    .queue-add-pri { font-size:  var(--fs-xs); padding: 2px 4px; max-width: 68px; }
    .queue-add-btn { padding: 3px 8px; font-size:  var(--fs-xs); }
    .queue-badge { min-width: 12px; height: 12px; font-size:  var(--fs-4xs); }
}
@media (max-width: 480px) {
      .queue-item { padding: 1px 6px; }
      .queue-item-goal { font-size:  var(--fs-xs); }
      .queue-item-btn { width: 16px; height: 16px; font-size:  var(--fs-3xs); }
    .queue-panel.open { max-height: min(45vh, var(--panel-max-h, 45vh)); }
      .queue-panel-header { padding: 3px 6px; font-size:  var(--fs-2xs); }
    .queue-panel-add { padding: 3px 6px; }
    .queue-add-input { font-size:  var(--fs-xs); padding: 2px 5px; }
    .queue-add-pri { font-size:  var(--fs-2xs); padding: 1px 3px; max-width: 60px; }
    .queue-add-btn { padding: 2px 7px; font-size:  var(--fs-2xs); }
    .queue-badge { min-width: 10px; height: 10px; font-size:  var(--fs-4xs); top: -3px; right: -3px; }
}

#desktop,
#toolbar .dropdown-menu,
.agent-window,
.window-titlebar {
    user-select: none;
    -webkit-user-select: none;
}
.agent-window,
.window-titlebar {
    display: flex;
}
.agent-window {
    position: absolute;
    border-radius: var(--window-radius);
    box-shadow: var(--window-shadow);
    background: var(--card-bg);
    flex-direction: column;
    overflow: hidden;
    min-width: 280px;
    min-height: 200px;
    transition: box-shadow .25s var(--transition-ease);
    will-change: left,top,width,height,transform,opacity;
}
.agent-window.active {
    box-shadow: var(--window-shadow-active);
}
.agent-window.maximized {
    border-radius: 0;
}
.window-titlebar {
    height: var(--titlebar-height);
    position: relative;
    z-index: var(--z-window-titlebar);
    background: var(--bg-subtle);
    align-items: center;
    padding: 0 8px 0 14px;
    cursor: grab;
    touch-action: none;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-light);
}
/* 活动窗口标题栏装饰条 — 左侧主题色竖条，直观标明当前活动窗口（顶部延伸到左上角，底部贯穿至标题栏底缘） */
.agent-window.active .window-titlebar::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    border-radius: 0 2px 2px 0;
    background: var(--accent);
    box-shadow: 0 0 5px var(--accent-glow);
    z-index: calc(var(--z-window-titlebar) + 1);
    pointer-events: none;
}

/* 活动窗口标题栏 — 主题色渐变晕染底色 + 主题色下边框，与普通窗口一眼区分 */
.agent-window.active .window-titlebar {
    background: linear-gradient(90deg, var(--accent-soft), transparent 52%), var(--bg-subtle);
    border-bottom: 1px solid color-mix(in srgb, var(--accent) 38%, var(--border-strong));
}

/* 非活跃窗口标题栏 — 柔化降调，让背景窗口退后 */
.agent-window:not(.active) .window-titlebar {
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--border-light);
}
.agent-window:not(.active) .window-titlebar .title .title-text {
    color: var(--text-muted);
}

/* 活跃窗口标题文字颜色加重 */
.agent-window.active .window-titlebar .title {
    color: var(--text-primary);
}
/* 活跃窗口会话标题颜色与代理名一致（非活跃时两者同为 text-muted，保持对称） */
.agent-window.active .window-titlebar .title .session-title-chip {
    color: var(--text-primary);
}
/* 活跃窗口代理圆点放大（保留大小变化，去掉导致遮挡的阴影） */
.agent-window.active .window-titlebar .title .agent-dot-wrap .agent-dot {
    width: 11px;
    height: 11px;
}
.agent-window.maximized .window-titlebar {
    cursor: default;
}
.window-titlebar .title {
    margin-right: auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size:  var(--fs-md-lg);
    font-weight: 600;
    color: var(--text-secondary);
    flex: 1;
    min-width: 0;
    /* overflow:hidden 已移除 — 会导致 agent-dot hover 放大时左侧被裁切 */
}
.window-titlebar .title .agent-dot-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: help;
}
.window-titlebar .title .agent-dot-wrap .agent-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: transform .15s var(--transition-ease);
}
/* agent-dot hover 微放大，暗示可交互 */
.window-titlebar .title .agent-dot-wrap:hover .agent-dot {
    transform: scale(1.3);
}

/* ========== agent-dot Tooltip（悬浮卡片）挂载于 document.body ========== */
.agent-tooltip {
     position: fixed;
     /* left/top 由 JS _positionTooltip 动态计算 */
     transform: translateX(-50%);
     padding: 6px 12px;
     border-radius: 8px;                /* 与下拉菜单/Toast 统一 */
     background: var(--tooltip-bg);      /* base.css 定义，继承工具栏配色 */
     color: var(--tooltip-text);
     font-size:  var(--fs-sm);
     font-weight: 500;
     line-height: 1.5;
     font-family: var(--font-sans);      /* 与 UI 其他文字统一 */
     white-space: nowrap;
     pointer-events: none;
     opacity: 0;
     visibility: hidden;
     transition: opacity .18s var(--transition-ease),
                 visibility .18s var(--transition-ease);
     z-index: var(--z-tooltip); /* 高于工具栏（400），低于遮罩层（1000）*/
     box-shadow: var(--shadow-pop);  /* 与下拉菜单阴影统一 */
     border: 1px solid rgba(255,255,255,.1);  /* 深色浮层边框（与下拉菜单一致）*/
     max-width: none;
 }
 /* tooltip 小三角箭头 — left 由 JS 动态设置（--arrow-left），始终指向圆点 */
 .agent-tooltip::after {
     content: '';
     position: absolute;
     top: 100%;                /* 箭头在 tooltip 底部，向下指向 dot */
     left: var(--arrow-left, 50%);
     transform: translateX(-50%);
     border: 5px solid transparent;
     border-top-color: var(--tooltip-bg);  /* 与 tooltip 背景色一致 */
 }
 /* tooltip 改显在锚点下方时（上方空间不足，见 JS _positionTooltipEl），
    箭头翻到顶部向上指 */
 .agent-tooltip[data-arrow-dir="up"]::after {
     top: auto;
     bottom: 100%;
     border-top-color: transparent;
     border-bottom-color: var(--tooltip-bg);
 }

/* hover 时显示 tooltip（由 JS _showTooltip/_hideTooltip 控制） */
.agent-tooltip.visible {
    opacity: 1;
    visibility: visible;
}

/* agent-dot tooltip 的双行形态（代理信息 / 已加载技能）：
   技能名数量不定且可能带长目录名，不允许像旧版那样 nowrap 把浮层拉出视口——
   改为限宽 + 自动换行，各行独占一行；定位仍由 JS 按实测尺寸居中/贴边。 */
.agent-tooltip.agent-tooltip-rich {
    white-space: normal;
    max-width: min(360px, 80vw);
    text-align: left;
    overflow-wrap: anywhere;
}
.agent-tooltip.agent-tooltip-rich .agent-tooltip-row {
    display: block;
}
.agent-tooltip.agent-tooltip-rich .agent-tooltip-row + .agent-tooltip-row {
    margin-top: 2px;
    opacity: .85;
}
/* 会话标题 chip 的完整标题提示（仅当标题被省略号截断、悬浮 chip 时出现）
   复用 agent-tooltip 配色/箭头，但标题可能很长：改为可换行 + 限宽，
   避免单行 nowrap 把浮层拉出视口（定位逻辑只会做视口内平移，不会缩宽） */
.agent-tooltip.session-title-tooltip {
    white-space: normal;
    max-width: min(420px, 80vw);
    text-align: left;
    overflow-wrap: anywhere;
}
.window-titlebar .title .title-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
/* 标题内联编辑输入框（双击改名）— textarea 单行样式（与底部输入框同为
   textarea，规避部分 WebView 对 input 长按编辑菜单的抑制） */
.window-titlebar .title .title-edit-input {
    display: none;
    flex: 1;
    min-width: 60px;
    max-width: 180px;
    height: 24px;
    padding: 0 6px;
    font-size:  var(--fs-md);
    font-family: var(--font-sans);
    color: var(--text-primary);
    background: var(--input-bg);
    border: 1px solid var(--accent);
    border-radius: 4px;
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-soft);
    vertical-align: middle;
    line-height: 24px;
    position: relative;
    z-index: var(--z-titlebar-edit);
    resize: none;
    overflow: hidden;
    white-space: nowrap;
}
.window-titlebar .title .title-edit-input:focus {
    border-color: var(--accent-hover);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
/* 会话标题 chip（标题栏第二栏，双击可编辑）
   字号继承 .title（与代理名一致），不再单独声明。
   桌面端（用户口径 2026-09-24）：会话标题普遍较长，原固定 max-width:180px 过早
   截断；改为跟随标题栏可用宽度自适应（上限 60%，避免挤占代理名与状态徽标）。
   超长仍以 … 截断（见下方 .session-title-text），此时悬浮 chip 由 JS 弹
   完整标题提示（.session-title-tooltip）。
   移动端另有收窄规则（mobile.css ≤768px → 96px、≤375px → 64px）。 */
.window-titlebar .title .session-title-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 1;
    min-width: 0;
    max-width: 60%;
    padding: 1px 4px;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: .02em;
    line-height: 1.5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none;
    -webkit-user-select: none;
    transition: color .25s var(--transition-ease);
}
.window-titlebar .title .session-title-chip::before {
    content: '\1F4C4 ';
    flex-shrink: 0;
    font-size:  var(--fs-sm); /* 与文字同比例放大 */
}
/* 会话标题文本：chip 的 text-overflow 对 flex 子项内的文本不生效，
   需在文本自身声明省略号；min-width:0 允许压缩到可用宽度以内 */
.window-titlebar .title .session-title-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
/* 会话标题编辑输入框 — textarea 单行样式（同 .title-edit-input） */
.window-titlebar .title .session-title-input {
    display: none;
    flex: 1;
    min-width: 60px;
    max-width: 180px;
    height: 24px;
    padding: 0 6px;
    font-size:  var(--fs-md);
    font-family: var(--font-sans);
    color: var(--text-primary);
    background: var(--input-bg);
    border: 1px solid var(--accent);
    border-radius: 4px;
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-soft);
    vertical-align: middle;
    line-height: 24px;
    position: relative;
    z-index: var(--z-titlebar-edit);
    resize: none;
    overflow: hidden;
    white-space: nowrap;
}
.window-titlebar .title .session-title-input:focus {
    border-color: var(--accent-hover);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ═══════════════════════════════════════════
   移动端：代理名 / 会话标题的文本选择与系统编辑菜单

   背景 Bug：标题栏父级 .window-titlebar 为防拖拽误选设置了
   user-select:none + touch-action:none，该组合在移动端会抑制
   长按文本选择与系统编辑菜单（拷贝/剪切/粘贴/全选）的弹出——
   即使已在输入框内选定文字，再次长按也不出现编辑菜单。

   修复（三层）：
   1. 仅在触摸设备（pointer:coarse / hover:none）上，对
      可编辑文本（title-text / session-title-chip）与编辑输入框
      （title-edit-input / session-title-input）显式放行文本选择，
      恢复移动端长按菜单；桌面端保持不可选中（避免拖拽误选）。
   2. touch-action 是 effective intersection（目标元素到最近滚动
      祖先的 touch-action 交集）：子元素声明 manipulation 仍会被
      祖先 .window-titlebar 的 none 交集为 none，Android Chrome 上
      依旧抑制长按编辑菜单。因此编辑态（JS 在
      _startRename/_startSessionTitleEdit 时加 .editing class）
      需额外将 .window-titlebar 的 touch-action/user-select 放宽，
      退出编辑态恢复 none（保证非编辑态拖拽不被浏览器手势接管）。
   3. 核心修复：.agent-window 默认 overflow:hidden 会裁剪位于窗口
      顶部的输入框移动端选择手柄（上/下方小圆点）→ 无法取消选择、
      长按编辑菜单不弹。编辑态（JS 加 .editing-window class）放行
      overflow，让手柄可见可操作；非编辑态保持 hidden。
   ═══════════════════════════════════════════ */
@media (hover: none), (pointer: coarse) {
    .window-titlebar .title .title-text,
    .window-titlebar .title .session-title-chip,
    .window-titlebar .title .title-edit-input,
    .window-titlebar .title .session-title-input {
        user-select: text;
        -webkit-user-select: text;
        -webkit-touch-callout: default;
        touch-action: manipulation;
    }
    /* 编辑态：标题栏 touch-action/user-select 放宽（textarea 自身已放行，
       此处覆盖 titlebar 级避免 effective intersection/祖先 none 影响）；
       仅编辑态生效，不影响非编辑态拖拽 */
    .window-titlebar.editing,
    .window-titlebar:focus-within {
        user-select: text;
        -webkit-user-select: text;
        touch-action: manipulation;
    }
    /* 编辑态：窗口放行 overflow——选择手柄不被裁剪（核心修复，见上注释） */
    .agent-window.editing-window {
        overflow: visible;
    }
    /* 编辑输入框字号提到 16px：iOS Safari 对 <16px 的 input 聚焦会自动
       zoom（页面放大），布局变化会干扰长按系统编辑菜单的弹出 */
    .window-titlebar .title .title-edit-input,
    .window-titlebar .title .session-title-input {
        font-size: var(--fs-input-ios-min);
    }
}
/* 远程代理窗口信令状态图标（更形象的 SVG 图标） */


.window-titlebar .title .signaling-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: 6px;
    vertical-align: middle;
    line-height: 1;
    width: 16px;
    height: 16px;
    transition: color .3s, opacity .3s;
}
.window-titlebar .title .signaling-indicator[data-status="connected"] {
    color: var(--accent);
}
.window-titlebar .title .signaling-indicator[data-status="connecting"] {
    color: var(--warning);
}
.window-titlebar .title .signaling-indicator[data-status="connecting"] .signal-spin {
    animation: signalSpin .8s linear infinite;
    transform-origin: center;
}
.window-titlebar .title .signaling-indicator[data-status="disconnected"] {
    color: var(--text-muted);
}
/* 响应式：小屏幕适配 */
.window-titlebar .title .signaling-indicator[data-status="error"] {
    color: var(--danger);
}
.window-titlebar .title .signaling-indicator[data-status="partial"] {
    color: var(--warning);
}
.window-controls,
.window-controls button,
.window-titlebar .title {
    display: flex;
    user-select: none;
    -webkit-user-select: none;
}
.window-controls {
    flex-shrink: 0;
    height: var(--titlebar-height);
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    /* 改为 flex 右端项（非绝对定位）：标题内容溢出时由 flex 布局让位，不再与控制按钮重叠 */
}
/* 标题栏内容自适应折叠：空间不足时由 JS 按优先级折叠次要元素，避免与控制按钮重叠 */
.window-titlebar .title [data-titlebar-collapsed="1"] {
    display: none !important;
}

.window-controls button {
    width: 26px;
    height: 28px;
    border: 0;
    border-radius: 5px;
    cursor: pointer;
    font-size:  var(--fs-md-lg);
    background: none;
    color: var(--text-muted);
    transition: background .12s, color .12s;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: var(--z-hover-ctrl);
}
.window-controls button:hover {
    background: var(--bg-active);
    color: var(--text-secondary);
}
.window-controls .btn-minimize:hover {
    background: var(--btn-minimize-hover-bg);
    color: var(--btn-minimize-hover-color);
}
/* 按下态：:active 为主（桌面鼠标），.is-pressed 由 JS 在触屏按下时维护
   （触屏上 :active 时机不可靠，且标题栏 user-select/touch-action:none 会进一步抑制） */
.window-controls .btn-minimize:active,
.window-controls .btn-minimize.is-pressed {
    background: var(--btn-minimize-hover-bg);
    color: var(--btn-minimize-hover-color);
}
.window-controls .btn-maximize:hover {
    background: var(--btn-maximize-hover-bg);
    color: var(--btn-maximize-hover-color);
}
.window-controls .btn-maximize:active,
.window-controls .btn-maximize.is-pressed {
    background: var(--btn-maximize-hover-bg);
    color: var(--btn-maximize-hover-color);
}
.window-controls button:active,
.window-controls button.is-pressed {
    transform: scale(0.92);
}
.window-controls button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.window-controls .btn-close:hover {
    background: var(--btn-close-hover-bg);
    color: var(--btn-close-hover-color);
}
.window-controls .btn-close:active,
.window-controls .btn-close.is-pressed {
    background: var(--btn-close-hover-bg);
    color: var(--btn-close-hover-color);
}
.window-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    padding: 12px 8px 0;
}
.msg-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding-bottom: 12px;
}

/* ========== 待作答的输入请求（request_user_input） ==========
   浮层，而不是消息流里的一块：贴在 .msg-area 底部、盖在消息之上，消息滚到哪里都看得见
   （接在消息后面时会停在视野之外，阻塞项等于没人答）。
   容器自身不吃鼠标（pointer-events:none），只有卡片可交互，卡片之外的区域照常滚消息/选文本；
   底部留出 54px 给「滚动到底部」浮动按钮（bottom:16px + 34px 高）——用 bottom 偏移 + max-height，
   而不是 padding-bottom：padding 会算进溢判定，让本来放得下的卡片也冒出滚动条；
   右侧比左侧多留 8px：让开消息区 8px 宽的纵向滚动条，否则滚动条会被浮层盖住一半。 */
.request-dock {
    position: absolute;
    left: 4px;
    /* 8px 滚动条 + 4px 间隙 */
    right: 12px;
    bottom: 54px;
    max-height: calc(100% - 54px);
    z-index: calc(var(--z-float-btn) + 1);
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    /* 纵向可滚，横向 never：卡片宽度由浮层控制（卡内不得再带 margin），
       一旦溢出就会被横向裁切，看起来就是「右侧少了一块」 */
    overflow-x: hidden;
    overscroll-behavior: contain;
    pointer-events: none;
}
.request-dock > * {
    flex: 0 0 auto;
    pointer-events: auto;
}
/* 浮层滚动条（只在**内容超出**时出现；放得下就没有——overflow-y:auto 的原生语义）：
   此前用 padding-bottom:52px 给浮动按钮让位，那 52px 计入了内容高度，
   单张卡片也会被判成溢出，滚动条就「总是显示」。现将让位改成 bottom 偏移 + max-height，
   内容高度就是卡片实际高度，溢出判定才对。 */
.request-dock::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.request-dock::-webkit-scrollbar-track {
    background: var(--bg-hover);
    border-radius: 3px;
}
.request-dock::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}
.request-dock::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* ========== 底部工具条（替代标题栏"更多操作"菜单） ========== */
.window-toolbar {
    display: flex;
    align-items: center;
    padding: 2px 8px;
    height: 30px;
    background: var(--bg-subtle);
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
    gap: 2px;
    z-index: var(--z-window-toolbar);
}
.agent-window.active .window-toolbar {
    background: var(--bg-active);
    border-top-color: color-mix(in srgb, var(--accent) 15%, var(--border-light));
}
.agent-window:not(.active) .window-toolbar {
    background: var(--bg-subtle);
    border-top: 1px solid var(--border-light);
}
.window-toolbar .toolbar-btn {
     width: 26px;
     height: 24px;
     border: 0;
     border-radius: 4px;
     cursor: pointer;
     font-size:  var(--fs-md);
     background: none;
     color: var(--text-muted);
     display: inline-flex;
     align-items: center;
     justify-content: center;
     transition: background .12s, color .12s;
     flex-shrink: 0;
     position: relative;
     /* 触摸手势不被浏览器接管（与 .window-titlebar 同口径）：否则在按钮上拖几 px
        就会触发 pointercancel，按住/微动后的松手不再由 touchActivate 判定（动作丢失） */
     touch-action: none;
 }
.window-toolbar .toolbar-btn:hover {
    background: var(--bg-hover);
    color: var(--text-secondary);
}
.window-toolbar .toolbar-btn:active,
.window-toolbar .toolbar-btn.is-pressed {
    background: var(--bg-hover);
    color: var(--text-secondary);
    transform: scale(0.92);
}
.window-toolbar .toolbar-spacer {
    flex: 1;
}
.window-toolbar .toolbar-model-label {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    max-width: 160px;
}
.window-toolbar .toolbar-model-select {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size:  var(--fs-xs);
    padding: 1px 18px 1px 6px;
    cursor: pointer;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3E%3Cpath fill='%23888' d='M1 2l3 4 3-4z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 4px center;
    outline: none;
    transition: border-color .15s;
}
.window-toolbar .toolbar-model-select:hover {
    border-color: var(--accent-soft);
}
.window-toolbar .toolbar-model-select:focus {
    border-color: var(--accent);
}

/* 优化1：传输容器折叠 — max-height + overflow-y 防止多文件撑破界面 */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 2px 4px 0 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    touch-action: pan-y;
    user-select: text;
    -webkit-user-select: text;
}

/* 自定义滚动条必须把【两个轴】的尺寸都写全：
   只写 width 时，横向滚动条的粗细会回退到 UA 默认值（Windows Chrome 约 16px），
   与纵向的 8px 差一倍——表现为「水平滚动条明显比垂直滚动条粗、样式不一致」。
   .messages-container 的 overflow-x 会因 overflow-y:auto 被计算为 auto，
   消息里有宽内容（宽表格、长公式、超长行）时横向条必然出现，故必须显式声明 height。 */
.messages-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.messages-container::-webkit-scrollbar-track {
    background: var(--bg-hover);
    border-radius: 4px;
}
.messages-container::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}
.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}
/* 两轴同时出现时的交界角：跟随轨道底色，避免露出浏览器默认方块 */
.messages-container::-webkit-scrollbar-corner {
    background: var(--bg-hover);
}
/* ========== 统一缩放手柄方案（所有屏幕） ========== */
/* 主体 pointer-events:none 穿透到下层元素，
   伪元素跨越窗口边缘 8-12px 捕获拖拽 + 显示缩放光标 */

.agent-window .resize-handle {
    position: absolute;
    z-index: var(--z-window-resize);
    background: none;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: none;
}

/* ── 底部（工具条区域）提高 z-index 确保伪元素可捕获 ── */
.agent-window .resize-s,
.agent-window .resize-sw,
.agent-window .resize-se {
    z-index: calc(var(--z-window-toolbar) + 1);
}

/* ── 四边：突出窗口边缘 4px，总 12px 敏感区 ── */
.agent-window .resize-n,
.agent-window .resize-s {
    left: 28px;
    right: 28px;
    height: 12px;
}
.agent-window .resize-n {
    top: -4px;
    cursor: n-resize;
}
.agent-window .resize-s {
    bottom: -4px;
    cursor: s-resize;
}
.agent-window .resize-e,
.agent-window .resize-w {
    top: 28px;
    bottom: 28px;
    width: 12px;
}
.agent-window .resize-e {
    right: -4px;
    cursor: e-resize;
}
.agent-window .resize-w {
    left: -4px;
    cursor: w-resize;
}

/* ── 四角：突出窗口边缘 4px ── */
.agent-window .resize-ne,
.agent-window .resize-nw,
.agent-window .resize-se,
.agent-window .resize-sw {
    width: 28px;
    height: 28px;
}
.agent-window .resize-ne {
    top: -4px;
    right: -4px;
    cursor: ne-resize;
}
.agent-window .resize-nw {
    top: -4px;
    left: -4px;
    cursor: nw-resize;
}
.agent-window .resize-se {
    bottom: -4px;
    right: -4px;
    cursor: se-resize;
}
.agent-window .resize-sw {
    bottom: -4px;
    left: -4px;
    cursor: sw-resize;
}

/* ── 四边伪元素：跨越窗口边缘 8px（内外各 4px），显示缩放光标 ── */
.agent-window .resize-s::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 8px;
    pointer-events: auto;
    cursor: s-resize;
}
.agent-window .resize-n::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 8px;
    pointer-events: auto;
    cursor: n-resize;
}
.agent-window .resize-e::after {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: 8px;
    pointer-events: auto;
    cursor: e-resize;
}
.agent-window .resize-w::after {
    content: '';
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 8px;
    pointer-events: auto;
    cursor: w-resize;
}

/* ── 四角伪元素：跨越窗口边缘 12px，显示缩放光标 ── */
.agent-window .resize-se::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 12px;
    pointer-events: auto;
    cursor: se-resize;
}
.agent-window .resize-sw::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 12px;
    pointer-events: auto;
    cursor: sw-resize;
}
.agent-window .resize-ne::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 12px;
    pointer-events: auto;
    cursor: ne-resize;
}
.agent-window .resize-nw::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 12px;
    pointer-events: auto;
    cursor: nw-resize;
}

.agent-window.maximized .resize-handle {
    display: none;
}
/* ---------- 响应式布局（合并优化） ---------- */





/* ========== 状态徽章（标题栏右侧） ========== */
.window-titlebar .status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    margin-left: 6px;
    padding: 1px 8px;
    border-radius: 10px;
    font-size:  var(--fs-xs);
    font-weight: 600;
    letter-spacing: .02em;
    white-space: nowrap;
    line-height: 1.6;
    user-select: none;
    -webkit-user-select: none;
    transition: background .25s var(--transition-ease),
                color .25s var(--transition-ease),
                border-color .25s var(--transition-ease);
    border: 1px solid transparent;
}
/* 状态: 空闲 - 浅灰 */
.window-titlebar .status-badge[data-status="idle"] {
    background: rgba(0,0,0,.04);
    color: var(--text-muted);
    border-color: var(--border-light);
}
/* 状态: 已暂停 - 柔和中性灰（挂起态）。使用明确色值（不依赖 color-mix，兼容旧浏览器），
   亮色与暗色各自取系统暖灰阶的中间值：比 idle 略深、比正文浅，形成清晰但不突兀的层级 */
.window-titlebar .status-badge[data-status="paused"] {
    background: #f0ece5;
    color: #6e665c;
    border-color: #d6cec4;
}
[data-theme="dark"] .window-titlebar .status-badge[data-status="paused"] {
    background: #2c2824;
    color: #a29a90;
    border-color: #4a4440;
}
/* 状态: 思考中 - 紫色渐变 */
.window-titlebar .status-badge[data-status="thinking"] {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent-glow);
}
/* 状态: 工作中 - 蓝色渐变 */
.window-titlebar .status-badge[data-status="working"] {
    background: var(--info-soft);
    color: var(--info);
    border-color: color-mix(in srgb, var(--info) 20%, transparent);
}
/* 状态: 等待响应 - 橙色渐变 */
.window-titlebar .status-badge[data-status="awaiting"] {
    background: var(--warning-soft);
    color: var(--warning);
    border-color: color-mix(in srgb, var(--warning) 20%, transparent);
}
/* 状态: 出错 - 红色渐变 */
.window-titlebar .status-badge[data-status="error"] {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: color-mix(in srgb, var(--danger) 20%, transparent);
}
/* 状态: 已完成 - 绿色渐变 */
.window-titlebar .status-badge[data-status="finished"] {
    background: var(--success-soft);
    color: var(--success);
    border-color: color-mix(in srgb, var(--success) 20%, transparent);
}
.messages-container .empty-placeholder .placeholder-icon {
    font-size: var(--fs-icon-lg);
    margin-bottom: 12px;
    opacity: .4;
    color: var(--text-muted);
    line-height: 1;
}
.messages-container .empty-placeholder .placeholder-title {
    font-size:  var(--fs-base);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    line-height: 1.4;
}
.messages-container .empty-placeholder .placeholder-subtitle {
    font-size:  var(--fs-md);
    color: var(--text-muted);
    max-width: 240px;
    line-height: 1.5;
}

/* ========== 移动端：标题栏控制按钮微调 ========== */
@media (max-width: 768px) {
    .window-controls {
        gap: 6px;
    }
    .window-controls button {
        width: 30px;
        height: 32px;
        border-radius: 6px;
    }
    .window-controls button svg {
        width: 14px;
        height: 14px;
    }
}

/* ========== 移动端：工具条紧凑 ========== */
@media (max-width: 768px) {
    /* ── 工具条四周 3px 留白，紧凑美观 ── */
    .window-toolbar {
        padding: 3px 8px;
        height: 30px;
    }
 }