/* ============================================================================
 * wechat-mobile / patches.css — v6（微信交互修正：按钮去重 + 通配宽度收回）
 * ----------------------------------------------------------------------------
 * v5 的两个毛病（本轮修）：
 *   1) 底栏/右上角按钮的选择器没去重：页面里有多颗同名按钮（比如两颗
 *      aria="New session"、侧栏 footer 还有一颗 Settings），全被钉到同一个
 *      fixed 坐标叠成一摞 → 用户看到"小按钮是乱的"。
 *      修法：每颗钉死的按钮都加类名锚点限定（[class*="toggle"] /
 *      [class*="panelRow"] / [class*="rail"] / [class*="newSession"]），保证唯一。
 *   2) 列表宽度补丁里用了 [class*="_root_"]、[class*="list"]、
 *      [class*="sidebar"] > div 这类大通配，把侧栏内部一堆不相干的容器全拉成
 *      100vw，工作区头部那排小按钮（搜索/筛选/加工作区）被挤散。
 *      修法：只留 treeBody / regionArea / listArea / groupSection 四个准确锚点。
 * 铁律不变：
 *   1) 皮肤中心强加前缀 html[data-dsh-skin="<id>"] （带空格）→ :root / 最前面的
 *      :has() 永不匹配；全局状态只能 body:has(...) / body:not(:has(...))。
 *   2) [data-slot] 出口全是 display:contents，布局用 [class*=] 锚点。
 * ========================================================================= */

/* ---------- 窄屏：微信两级页面 ---------- */
@media (max-width: 820px) {

  /* ===== 底部三栏 Tab（常驻；每颗按钮用类名锚点限定，保证唯一）===== */
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Open sidebar"][class*="toggle"],
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Collapse sidebar"][class*="toggle"],
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Plugins"][class*="panelRow"],
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Settings"][class*="rail"],
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Settings"]:not([class*="rail"]):not([class*="brand"]) {
    visibility: visible !important;
    opacity: 1 !important;
    position: fixed !important;
    bottom: env(safe-area-inset-bottom, 0px);
    top: auto !important;
    right: auto !important;
    left: auto !important;
    z-index: 60 !important;
    width: 33.33vw !important;
    min-width: 33.33vw !important;
    height: 56px !important;
    min-height: 56px !important;
    border-radius: 0 !important;
    background: var(--dsw-alias-bg-layer-1, #fff) !important;
    border-top: 1px solid var(--dsw-alias-border-l2, #e5e5e5) !important;
    color: var(--dsw-alias-label-secondary, #888) !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 3px;
    padding: 0 !important;
  }
  /* 从左到右：任务(聊天) | 插件库 | 市场 */
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Open sidebar"][class*="toggle"],
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Collapse sidebar"][class*="toggle"] { left: 0 !important; }
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Plugins"][class*="panelRow"]        { left: 33.33vw !important; }
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Settings"][class*="rail"]           { left: 66.66vw !important; }
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Settings"]:not([class*="rail"]):not([class*="brand"]) { left: 66.66vw !important; }

  /* 藏掉底栏按钮里的官方英文文字（font-size:0 不伤图标），只留图标 + 中文 */
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Open sidebar"][class*="toggle"],
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Collapse sidebar"][class*="toggle"],
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Plugins"][class*="panelRow"],
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Settings"][class*="rail"],
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Settings"]:not([class*="rail"]):not([class*="brand"]) {
    font-size: 0 !important;
  }

  /* 底栏文字（聊天页那颗叫「任务」，列表页那颗叫「聊天」，跟着状态走） */
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Open sidebar"][class*="toggle"]::after     { content: "任务"; }
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Collapse sidebar"][class*="toggle"]::after { content: "聊天"; }
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Plugins"][class*="panelRow"]::after        { content: "插件库"; }
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Settings"][class*="rail"]::after           { content: "市场"; }
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Settings"]:not([class*="rail"]):not([class*="brand"])::after { content: "市场"; }
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Open sidebar"][class*="toggle"]::after,
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Collapse sidebar"][class*="toggle"]::after,
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Plugins"][class*="panelRow"]::after,
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Settings"][class*="rail"]::after,
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Settings"]:not([class*="rail"]):not([class*="brand"])::after {
    font-size: 10px !important;
    line-height: 1;
    color: var(--dsw-alias-label-secondary, #888);
  }

  /* ===== 列表页右上角「+」（只钉列表页里侧栏头部那一颗，其余同名按钮不动）===== */
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-sidebar-collapsed="true"])) button[aria-label="New session"][class*="newSession"] {
    visibility: visible !important;
    opacity: 1 !important;
    position: fixed !important;
    top: calc(env(safe-area-inset-top, 0px) + 10px) !important;
    right: 12px !important;
    left: auto !important;
    bottom: auto !important;
    z-index: 70 !important;
    width: 36px !important;
    height: 36px !important;
    border-radius: 50% !important;
    background: var(--dsw-alias-bg-layer-1, #fff) !important;
    border: none !important;
    box-shadow: 0 1px 4px rgba(0,0,0,.12) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
  }
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-sidebar-collapsed="true"])) button[aria-label="New session"][class*="newSession"] > * {
    display: none !important;
  }
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-sidebar-collapsed="true"])) button[aria-label="New session"][class*="newSession"]::before {
    content: "+";
    font-size: 24px;
    font-weight: 300;
    line-height: 1;
    color: var(--dsw-alias-label-primary, #191919);
  }

  /* ===== 聊天页：有消息行时整屏盖住列表 ===== */
  html[data-dsh-skin="wechat-mobile"] body:has([data-chat-anchor-key]) [data-dsh-surface="conversation"],
  html[data-dsh-skin="wechat-mobile"] body:has([data-chat-anchor-key]) [class*="centerCol"] {
    display: block !important;
    position: fixed;
    inset: 0;
    z-index: 35;
    width: 100vw;
    max-width: none;
    min-width: 0;
    height: 100vh;
    height: 100dvh;
    border-left: none;
    background: var(--dsw-alias-bg-base, #ededed);
  }
  /* 聊天页左上角挖洞露出官方 toggle */
  html[data-dsh-skin="wechat-mobile"] body:has([data-chat-anchor-key]) [data-dsh-surface="conversation"],
  html[data-dsh-skin="wechat-mobile"] body:has([data-chat-anchor-key]) [class*="centerCol"] {
    clip-path: polygon(56px 0, 100% 0, 100% 100%, 0 100%, 0 56px, 56px 56px);
  }
  /* 无消息行兜底（初始空会话），避免白屏 */
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-chat-anchor-key])):has([data-sidebar-collapsed="true"]) [data-dsh-surface="conversation"],
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-chat-anchor-key])):has([data-sidebar-collapsed="true"]) [class*="centerCol"] {
    display: block !important;
    position: fixed;
    inset: 0;
    z-index: 20;
    width: 100vw;
    max-width: none;
    min-width: 0;
    height: 100vh;
    height: 100dvh;
    background: var(--dsw-alias-bg-base, #ededed);
  }

  /* ===== 列表页（侧栏展开）===== */
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-chat-anchor-key])):not(:has([data-sidebar-collapsed="true"])) [class*="sidebarCol"] {
    position: fixed;
    inset: 0;
    z-index: 30;
    width: 100vw;
    max-width: none;
    min-width: 0;
    border-right: none;
    background: var(--dsw-specific-sidebar-fill, #ededed);
    padding-bottom: 56px;
    padding-top: calc(env(safe-area-inset-top, 0px) + 6px);
  }
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-chat-anchor-key])):not(:has([data-sidebar-collapsed="true"])) [class*="centerCol"] {
    display: none !important;
  }
  /* 列表页顶部：deepseek 那行 logo 藏掉（微信列表顶上没有这块），列表区给右上角 + 号留一行高度 */
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-sidebar-collapsed="true"])) [class*="logoRow"] {
    height: 0 !important;
    overflow: visible !important;
  }
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-sidebar-collapsed="true"])) [class*="logoRow"] > *:not([class*="toggle"]) {
    display: none !important;
  }
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-sidebar-collapsed="true"])) [class*="regionArea"],
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-sidebar-collapsed="true"])) [class*="listArea"] {
    padding-top: 36px !important;
  }

  /* 列表页顶部的长条「New Session」胶囊藏掉：右上角已有 + 号（微信没有这颗） */
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-sidebar-collapsed="true"])) button[aria-label="New session"][class*="brand"] {
    display: none !important;
  }

  /* ===== 会话列表行：微信样式（头像 + 标题 + 时间 + 分割线）===== */
  html[data-dsh-skin="wechat-mobile"] [class*="sessionRow"] {
    position: relative;
    min-height: 68px;
    border-radius: 0 !important;
    border-bottom: 1px solid rgba(0,0,0,.05);
    padding-left: 72px !important;
    padding-top: 12px !important;
    padding-bottom: 12px !important;
    background: var(--dsw-alias-bg-layer-1, #fff);
  }
  html[data-dsh-skin="wechat-mobile"] [class*="sessionRow"]:active { background: rgba(0,0,0,.04); }
  /* 头像：圆角方块，四个一循环换色（微信里每个对话头像颜色不同） */
  html[data-dsh-skin="wechat-mobile"] [class*="sessionRow"]::before {
    content: "";
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border-radius: 10px;
    background: linear-gradient(145deg, #07c160 0%, #06ad56 100%);
    box-shadow: 0 2px 6px rgba(7,193,96,.25);
  }
  html[data-dsh-skin="wechat-mobile"] [class*="sessionRow"]:nth-child(4n+2)::before { background: linear-gradient(145deg, #10a3ff 0%, #0a7fd4 100%); box-shadow: 0 2px 6px rgba(16,163,255,.25); }
  html[data-dsh-skin="wechat-mobile"] [class*="sessionRow"]:nth-child(4n+3)::before { background: linear-gradient(145deg, #fa9d3b 0%, #f2801d 100%); box-shadow: 0 2px 6px rgba(250,157,59,.25); }
  html[data-dsh-skin="wechat-mobile"] [class*="sessionRow"]:nth-child(4n+0)::before { background: linear-gradient(145deg, #7d6ff2 0%, #5b4bd4 100%); box-shadow: 0 2px 6px rgba(125,111,242,.25); }
  /* 头像上的白色对话气泡图形 */
  html[data-dsh-skin="wechat-mobile"] [class*="sessionRow"]::after {
    content: "";
    position: absolute;
    left: 27px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 16px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.95);
    clip-path: polygon(0 0, 100% 0, 100% 70%, 55% 70%, 35% 100%, 35% 70%, 0 70%);
  }

  /* ===== 微信式输入框 ===== */
  html[data-dsh-skin="wechat-mobile"] [class*="composerSeat"] {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 56px;
    z-index: 31;
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    background: var(--dsw-alias-bg-base, #ededed);
    border-top: none;
  }
  /* 卡片变透明排版壳：白色输入胶囊全宽，加号/发送绝对定位在两侧（微信输入条同构） */
  html[data-dsh-skin="wechat-mobile"] [data-composer-card] {
    position: relative !important;
    display: block !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    padding: 0 96px 0 46px !important;
    min-height: 44px;
  }
  /* 官方的按钮行压扁成 0 高，按钮各自绝对定位 */
  html[data-dsh-skin="wechat-mobile"] [class*="uV2eYG_row"] { height: 0 !important; overflow: visible !important; }
  /* 输入区 = 白色胶囊（微信输入框本体） */
  html[data-dsh-skin="wechat-mobile"] [class*="uV2eYG_scroll"] {
    background: #ffffff !important;
    border-radius: 8px !important;
    padding: 9px 12px !important;
    min-height: 40px;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
  }
  html[data-dsh-skin="wechat-mobile"] [data-composer-input],
  html[data-dsh-skin="wechat-mobile"] [contenteditable="true"] {
    font-size: 16px !important;
    line-height: 1.4 !important;
    color: var(--dsw-alias-label-primary, #191919) !important;
  }
  /* 左侧加号（附件/功能入口，微信同款圆形） */
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Add files or run commands"] {
    position: absolute !important;
    left: 4px !important;
    bottom: 4px !important;
    width: 36px !important;
    height: 36px !important;
    border-radius: 50% !important;
    background: transparent !important;
    color: var(--dsw-alias-label-primary, #191919) !important;
  }
  /* 发送 = 微信绿色圆角「发送」钮 */
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Send message"] {
    position: absolute !important;
    right: 8px !important;
    bottom: 5px !important;
    width: auto !important;
    min-width: 58px;
    height: 34px !important;
    border-radius: 6px !important;
    background: #07c160 !important;
    border: none !important;
    color: #fff !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 14px !important;
  }
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Send message"] svg { display: none !important; }
  html[data-dsh-skin="wechat-mobile"] button[aria-label="Send message"]::after { content: "发送"; font-size: 14px; line-height: 1; color: #fff; }
  /* 藏掉输入条里的功能键：访问模式盾牌、模型选择、底部三条用量胶囊（用户要求藏进按钮里） */
  html[data-dsh-skin="wechat-mobile"] button[aria-label^="Access mode"] { display: none !important; }
  html[data-dsh-skin="wechat-mobile"] button[aria-label^="Select model"] { display: none !important; }
  html[data-dsh-skin="wechat-mobile"] [class*="bOPqQW_pill"],
  html[data-dsh-skin="wechat-mobile"] [class*="JObwrW_trigger"] { display: none !important; }

  /* ===== 元凶：ofm 插件的「Plugin hot-reloaded」提示卡（z-index 1200）=====
     它盖在右下角，正好压住底栏右边那一格——这就是"底栏只有三分之二宽"的原因。
     直接藏掉，并补一条整宽白条垫在底栏按钮后面兜底。 */
  html[data-dsh-skin="wechat-mobile"] .ofm_toasts { display: none !important; }
  html[data-dsh-skin="wechat-mobile"] body::after {
    content: "";
    position: fixed;
    left: 0;
    right: 0;
    bottom: env(safe-area-inset-bottom, 0px);
    height: 56px;
    background: var(--dsw-alias-bg-layer-1, #fff);
    border-top: 1px solid var(--dsw-alias-border-l2, #e5e5e5);
    z-index: 25;
    pointer-events: none;
  }

  /* ===== 藏掉手机上没有的桌面件 ===== */
  html[data-dsh-skin="wechat-mobile"] [data-rightbar-col],
  html[data-dsh-skin="wechat-mobile"] [data-dsh-part="resize-handle"],
  html[data-dsh-skin="wechat-mobile"] [data-dockkit-strip],
  html[data-dsh-skin="wechat-mobile"] [data-dockkit-pane],
  html[data-dsh-skin="wechat-mobile"] [data-dockkit-drop-zones] {
    display: none !important;
  }

  /* 聊天页顶栏避让左上角的洞 */
  html[data-dsh-skin="wechat-mobile"] [data-dsh-surface="session-header"] > * {
    padding-left: 56px;
    padding-top: env(safe-area-inset-top, 0px);
  }

  html[data-dsh-skin="wechat-mobile"] [data-dsh-part="scrollport"] { padding-bottom: 160px; }
  html[data-dsh-skin="wechat-mobile"] [data-dsh-part="message-row"] { padding-left: 12px; padding-right: 12px; position: relative; }

  /* ===== 聊天气泡两侧头像（微信样式：自己右侧蓝、对方左侧绿）===== */
  html[data-dsh-skin="wechat-mobile"] [data-dsh-part="message-row"][data-chat-flow-kind="user"] {
    padding-right: 56px !important;
  }
  html[data-dsh-skin="wechat-mobile"] [data-dsh-part="message-row"][data-chat-flow-kind="user"]::after {
    content: "";
    position: absolute;
    right: 0;
    top: 2px;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: linear-gradient(145deg, #10a3ff, #0a7fd4);
  }
  html[data-dsh-skin="wechat-mobile"] [data-dsh-part="message-row"][data-chat-flow-kind="assistant-step"] {
    padding-left: 56px !important;
  }
  html[data-dsh-skin="wechat-mobile"] [data-dsh-part="message-row"][data-chat-flow-kind="assistant-step"]::before {
    content: "";
    position: absolute;
    left: 0;
    top: 2px;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: linear-gradient(145deg, #07c160, #06ad56);
  }
}

/* ---------- 超窄屏（<=420px）---------- */
@media (max-width: 420px) {
  html[data-dsh-skin="wechat-mobile"] [data-dsh-part="scrollport"] { padding-bottom: 150px; }
}

/* ---------- 通用：浮层不吃点击 ---------- */
html[data-dsh-skin="wechat-mobile"] [data-dsh-surface="overlay"] { pointer-events: none; }

/* ---------- 列表容器拉满（只用四个准确锚点，不再大通配） ---------- */
@media (max-width: 820px) {
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-sidebar-collapsed="true"])) [class*="treeBody"],
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-sidebar-collapsed="true"])) [class*="regionArea"],
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-sidebar-collapsed="true"])) [class*="listArea"] {
    width: 100vw !important;
    max-width: 100vw !important;
    box-sizing: border-box;
  }
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-sidebar-collapsed="true"])) [class*="groupSection"],
  html[data-dsh-skin="wechat-mobile"] body:not(:has([data-sidebar-collapsed="true"])) [class*="sessionRow"] {
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box;
  }
}

html[data-dsh-skin="wechat-mobile"] [id="root"] { background: transparent; }

html[data-dsh-skin="wechat-mobile"] body { --shiki-background: var(--dsw-alias-markdown-code-block); }
