/* ==========================================================================
   Noir · Chat / Memory — RESPONSIVE LAYER（新增层，按断点组织）
   ---------------------------------------------------------------------------
   0. 文件定位 / 断点总览
   1. BASE  · 所有尺寸通用：把 390 设计框改成全屏 App、去掉外链字体依赖
   2. MOBILE · < 768px：单列 + 底部 Tab（原交互 100% 保留）
   3. ≥ 768px · 大屏共用：半屏抽屉改为居中对话框、绝对坐标改为流式
   4. TABLET · 768–1099px：76px 图标导航栏 + 主内容
   5. DESKTOP · ≥ 1100px：264px 左侧导航 + 主区 + 320px 右侧上下文（三栏）
   6. WIDE · ≥ 1600px：加宽侧栏与阅读宽度
   7. 动效偏好 / 开发状态面板

   设计原则：桌面是「空间重排」，不是把 390 画面等比放大。
   原 styles.css / memory.css 未改动，作为手机端基线原样保留。
   所有新增节点用 dr-* / dc-* / dt-* 前缀，不与原有 ID / data-* 冲突。
   ========================================================================== */

/* ==========================================================================
   1. BASE — 所有尺寸通用
   ========================================================================== */
html, body { height: 100%; }
body { background: var(--c-surface); }
/* 本地字体：拉丁字形优先用随包的 Inter，中文再落到 Noto Sans SC 子集 */
:root { --font-cn: 'Inter', 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif; }

/* 设计稿外壳（状态切换器 / 画布总览）默认隐藏，产品界面保持干净。
   ?dev=1 或左栏「设计状态」按钮可唤出，功能本身没有删除。 */
.stage { min-height: 100dvh; height: 100dvh; display: flex; flex-direction: column; }
.stage-head { display: none; }
.state-rail { display: none; }
.stage-body { flex: 1; min-height: 0; display: block; padding: 0; }
.live-wrap { display: block; width: 100%; height: 100%; }
body.dev-stage .state-rail {
  display: flex; position: fixed; right: 16px; top: 72px; z-index: 200;
  box-shadow: 0 18px 48px rgba(42, 31, 77, .24);
}

/* 390×844 固定框 → 全屏流式 App */
.phone,
body.bare .phone {
  width: 100%; height: 100dvh; max-width: none; margin: 0;
  box-shadow: none; border-radius: 0; overflow: hidden;
}
/* 手机状态栏 / Home Indicator 是设计框装饰，真实 App 不需要（DOM 仍保留） */
.status-bar, .home-indicator { display: none; }
/* V1：大屏时搜索页宽度小于视口，仅靠 translateX(100%) 会露出一条边，
   用 visibility 保证未打开时彻底不可见。
   V2-FIX-07：translateX(100%) 还会把隐藏层推到容器外，令 .phone 的
   scrollWidth 虚增（390→+390 / 1440→+536），干扰长内容横向溢出核验，
   也可能在基线里触发不必要的横向滚动容器。改成小位移 + 透明度过渡：
   滑入观感保留，隐藏态不再越界。 */
.search-screen {
  top: 0; visibility: hidden; opacity: 0;
  transform: translateY(8px);          /* 纵向微移，绝不产生横向溢出 */
  transition: transform .3s cubic-bezier(.22,.8,.3,1), opacity .3s, visibility .3s;
}
.search-screen.is-on { visibility: visible; opacity: 1; transform: translateY(0); }

/* 新增的桌面栏在手机端一律隐藏 */
.desk-rail, .desk-context, .desk-only, .dc-reopen, .dr-toast { display: none; }

/* 原样式里写死 390px 的元素改为跟随容器 */
.tab-divider { width: 100%; }
.tab-bar { justify-content: space-around; }
.tab { width: auto; flex: 1 1 0; }
.home-highlight { left: 50%; transform: translateX(-50%); }
.tab-bar { height: auto; min-height: 80px; padding: 4px 0 calc(18px + env(safe-area-inset-bottom, 0px)); }

/* 弹层内的绝对定位 .el 写死了 width:358px → 改为左右撑满 */
.sheet .el { width: auto !important; left: 16px !important; right: 16px !important; }
.model-menu { left: 16px !important; right: 16px !important; width: auto !important; }
.handle { left: 50% !important; transform: translateX(-50%); }
.sheet .func-card { flex: 1; min-width: 0; width: auto; }
.sheet .thumb-img { flex: 1; min-width: 0; width: auto; }
.slider-track { width: calc(100% - 20px) !important; }
.ticks { width: calc(100% - 20px) !important; display: flex; justify-content: space-between; }
.ticks span { position: static !important; left: auto !important; transform: none !important; }
.toast { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); max-width: min(320px, 88vw); }

/* ---------------------------------------------------------------------------
   V2-FIX-01 · textarea 原生边框 / 白底黑框
   原 styles.css 只 reset 了 `.input-field input`，换成 textarea 后浏览器默认
   border + background + box-shadow 全部生效，出现白底黑框。这里做完整 reset，
   并覆盖 :focus / :focus-visible / :-webkit-autofill / disabled，避免焦点态复发。
   注意：只改外观，不绑定任何发送事件（Enter / Shift+Enter 属于业务层职责）。
   --------------------------------------------------------------------------- */
.input-field textarea,
textarea#msgInput {
  -webkit-appearance: none; appearance: none;
  box-sizing: border-box;
  width: 100%; min-height: 20px; max-height: 96px;
  padding: 0; margin: 0; resize: none;
  border: 0 !important; border-radius: 0;
  outline: 0 !important; box-shadow: none !important;
  background: transparent !important; background-color: transparent !important;
  background-image: none !important;
  font: 400 12px/20px var(--font-cn); color: var(--c-ink);
  overflow-y: auto; overflow-wrap: anywhere;
}
.input-field textarea:focus,
.input-field textarea:focus-visible,
.input-field textarea:-webkit-autofill,
.input-field textarea:disabled,
textarea#msgInput:focus,
textarea#msgInput:focus-visible {
  border: 0 !important; outline: 0 !important; box-shadow: none !important;
  background: transparent !important; -webkit-box-shadow: 0 0 0 0 transparent;
}
.input-field textarea::placeholder { color: var(--c-muted-2); opacity: 1; }
/* 焦点反馈交给外层容器，而不是给 textarea 画框 */
.input-field:focus-within { box-shadow: inset 0 0 0 1px var(--c-lav-400); }
/* 键盘可达性：其它交互元素保留可见焦点环（prefers-reduced-motion 不关焦点） */
.dt-chip:focus-visible, .dr-nav-item:focus-visible, .dr-conv:focus-visible,
.dc-icon-btn:focus-visible, .dc-link-btn:focus-visible, .dc-ghost:focus-visible,
.dc-model:focus-visible, .dc-apply:focus-visible, .dc-reopen:focus-visible {
  outline: 2px solid var(--c-purple-2); outline-offset: 2px;
}

/* ---------------------------------------------------------------------------
   V2-FIX-04 · 长内容：不撑破栅格、不出现横向滚动、英文/URL 强折行
   --------------------------------------------------------------------------- */
.bubble-ai, .bubble-user, .transcript, .dc-card p,
.dr-conv-col b, .dr-conv-col small, .search-results .result-item {
  overflow-wrap: anywhere; word-break: break-word; min-width: 0;
}
.dc-scroll, .messages, .ov-scroll { overflow-x: hidden; }
#dcRefs, .dc-sec { min-width: 0; }
.dc-card { min-width: 0; }
/* 长引用先折 5 行，点击卡片可展开；纯粹的视觉行为，不读写业务状态 */
.dc-card p {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 5;
  max-height: none; overflow: hidden; cursor: pointer;
}
.dc-card.is-expanded p {
  display: block; -webkit-line-clamp: unset; max-height: none; overflow: visible;
}

/* ==========================================================================
   2. MOBILE — < 768px：单列 + 底部 Tab
   ========================================================================== */
@media (max-width: 767px) {
  .phone { display: flex; flex-direction: column; }
  .app { flex: 1; min-height: 0; }
  .messages { padding: 16px; }
  .chat-header { padding: 0 16px; }
  .composer { height: 63px; }
  .input-bar { height: 62px; }
  /* 平板以下依旧使用原半屏抽屉（底部滑出），只是宽度随屏幕变化 */
  .sheet { left: 0; right: 0; bottom: 0; max-height: 94dvh; overflow-y: auto; }
  .sheet .handle { top: 10px; }
  .reader { inset: 0; }

  /* V2-FIX-05 · 从桌面缩回手机时的导航兜底：
     无论桌面态是否收起过右栏（body.ctx-collapsed 会残留），手机端都必须
     恢复底部 Tab，并且不残留任何桌面专用节点。用 !important 压过 ≥768px
     规则在极端视口 / 缩放场景下的层叠残留。 */
  .tab-bar { display: flex !important; }
  .desk-rail, .desk-context, .desk-only, .dc-reopen, .dr-toast { display: none !important; }
  .search-screen { left: 0 !important; right: 0 !important; }
  .reader { left: 0 !important; right: 0 !important; }
  .messages { padding-left: 16px !important; padding-right: 16px !important; }
  .desk-toolbar, .desk-hint { display: none !important; }
  .input-field textarea { font-size: 12px; line-height: 20px; }
}

/* ==========================================================================
   3. ≥ 768px 大屏共用 — 半屏抽屉 → 居中对话框，绝对坐标 → 流式布局
   ========================================================================== */
@media (min-width: 768px) {
  /* ---- 弹层容器：不再贴底铺满，改为居中卡片 ---- */
  .sheet,
  .sheet.is-open {
    position: absolute; inset: 0; margin: auto;
    width: min(560px, 92vw); height: max-content !important; max-height: 86dvh;
    border-radius: 24px; padding: 24px;
    box-shadow: 0 26px 70px rgba(42, 31, 77, .22);
    overflow-x: hidden; overflow-y: auto;
    display: none;
  }
  .sheet.is-open { display: flex; flex-direction: column; gap: 12px; }
  .sheet.is-closing { display: flex; flex-direction: column; }
  .sheet .handle { top: 10px; }

  /* 原来按 390 稿写死的 left/top/width/height 全部释放为流式 */
  .sheet .el {
    position: relative !important;
    left: auto !important; right: auto !important;
    top: auto !important; bottom: auto !important;
    width: auto !important; height: auto !important;
    flex: none;
  }
  .sheet .primary-btn { height: 46px !important; }
  .sheet .panel-header { min-height: 26px; }
  .sheet .func-grid { min-height: 80px; }
  .sheet .dropzone { min-height: 150px; }
  .sheet .uploaded-row { min-height: 52px; }
  .sheet .name-section { min-height: 71px; }
  .sheet .thumbs { min-height: 108px; }
  .sheet .sources { min-height: 44px; }
  .sheet .selected-photo { min-height: 72px; }
  .sheet .send-bar { min-height: 42px; }
  .sheet .section-row, .sheet .effort-head { min-height: 22px; }
  .sheet .thinking-slider { height: 48px !important; }
  .sheet .file-row { min-height: 46px; }
  .sheet .browse-local { min-height: 42px; }
  .sheet .model-select { min-height: 48px; }
  .sheet .usage-rail { min-height: 146px; }
  .sheet .name-input { height: 44px; }

  /* 模型下拉菜单改为跟随在选择框下方 */
  .sheet .model-menu {
    position: relative !important; left: auto !important; top: auto !important;
    width: 100% !important; flex: none; z-index: 8;
  }
  /* 思考强度滑轨按实际宽度撑开（app.js 已改为测量 .slider-track） */
  .sheet .slider-track { left: 10px !important; right: 10px !important; width: auto !important; }
  .sheet .ticks { left: 10px !important; right: 10px !important; width: auto !important; display: flex; justify-content: space-between; }
  .sheet .ticks span { position: static !important; transform: none !important; }

  /* 记忆详情 / 表情包：需要确定高度才能内部滚动 */
  .sheet.sheet-stickers, .sheet.sheet-memory { height: min(560px, 86dvh) !important; }
  .sheet-memory #memoryCards {
    position: relative !important;
    left: auto !important; right: auto !important; top: auto !important; bottom: auto !important;
    flex: 1 1 auto; min-height: 0; overflow-y: auto;
  }
  .sheet-memory #memoryCards .memory-card { flex: none; }

  /* Memory 页面板 */
  .mem-date, .mem-ctx, .mem-manage, .mem-more, .mem-edit { min-height: 0; }
  .mem-date .date-body, .mem-ctx .ctx-body, .mem-manage .mg-body,
  .mem-edit .edit-body { max-height: 56dvh; }
  .edit-textarea { min-height: 190px; }
  .cal-grid { grid-auto-rows: 44px; }

  /* 通用：桌面光标反馈 */
  .mem-row:hover, .rm-card:hover, .rf-card:hover, .layer-card:hover { border-color: var(--c-purple); }
  .toast { bottom: 32px; }

  /* ---- 桌面输入区：工具栏 + 输入框 + 提示行 ---- */
  .composer { height: auto; min-height: 0; }
  .input-bar { height: auto; min-height: 60px; padding: 10px 28px; gap: 12px; }
  .input-field { height: auto; min-height: 44px; border-radius: 16px; padding: 10px 16px; }
  .input-field textarea { font-size: 13px; line-height: 22px; }
  .bare-icon { width: 24px; height: 24px; }
  .send-btn { width: 38px; height: 38px; }
  .desk-only { display: flex; }
  .desk-toolbar { justify-content: space-between; align-items: center; padding: 14px 28px 2px; gap: 12px; }
  .dt-group { display: flex; gap: 8px; flex-wrap: wrap; }
  .dt-chip {
    display: inline-flex; align-items: center; gap: 6px;
    height: 30px; padding: 0 12px; border-radius: 10px;
    background: var(--c-lav-50); color: var(--c-ink-2);
    font: 500 11px/16px var(--font-cn);
  }
  .dt-chip:hover { background: var(--c-lav-200); }
  .dt-chip .ic { width: 14px; height: 14px; }
  .dt-chip .ic svg { width: 14px; height: 14px; }
  .dt-status { font: 400 10px/14px var(--font-cn); color: var(--c-muted-2); white-space: nowrap; }
  .desk-hint {
    justify-content: space-between; padding: 8px 28px 14px;
    font: 400 10px/14px var(--font-cn); color: var(--c-muted-3);
  }

  /* ---- 聊天主区：内容限宽，气泡不被拉成一条细线 ---- */
  .chat-header { height: 72px; padding: 0 28px; }
  .partner-name { font-size: 16px; }
  .search-entry { height: 34px; border-radius: 12px; padding: 0 12px; min-width: 190px; }
  .messages { padding-top: 28px; padding-bottom: 28px; }
  .messages {
    padding-left: max(28px, calc((100% - 720px) / 2));
    padding-right: max(28px, calc((100% - 720px) / 2));
  }
  .ai-col { width: min(480px, 72%); }
  .bubble-ai { width: 100%; font-size: 14px; line-height: 23px; }
  .voice-col { width: min(470px, 72%); }
  .bubble-voice { width: 100%; }
  .user-col { max-width: 420px; }
  .bubble-user { max-width: 420px; font-size: 14px; line-height: 23px; }
  .memory-bar, .memory-bar-wide { width: min(300px, 100%); }
  .bubble-image { max-width: 300px; }
  .sent-image { width: 240px; height: 150px; }
  .bubble-file { max-width: 300px; }

  /* ---- 桌面新增栏：基础外观 ---- */
  .desk-rail, .desk-context {
    flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  }
  .desk-rail { background: var(--c-surface); border-right: 1px solid var(--c-line); }
  .desk-context { background: #fff; border-left: 1px solid var(--c-line); }
  .desk-rail::-webkit-scrollbar, .desk-context::-webkit-scrollbar { width: 6px; }
  .desk-rail::-webkit-scrollbar-thumb, .desk-context::-webkit-scrollbar-thumb { background: var(--c-lav-400); border-radius: 3px; }

  .dr-brand { display: flex; align-items: center; gap: 10px; padding: 20px 16px 16px; flex: none; }
  .dr-mark { width: 32px; height: 32px; border-radius: 10px; background: linear-gradient(135deg, #A78BFA, #7C5CE0); display: grid; place-items: center; flex: none; }
  .dr-mark svg { width: 20px; height: 20px; }
  .dr-brand-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
  .dr-brand-text strong { font: 600 17px/21px var(--font-display); color: var(--c-ink); }
  .dr-brand-text span { font: 400 10px/14px var(--font-cn); color: var(--c-muted-2); }
  .dr-tag {
    margin-left: auto; font: 600 9px/13px var(--font-en); letter-spacing: .04em;
    color: var(--c-purple-2); background: var(--c-lav-100); border-radius: 6px; padding: 3px 6px;
  }

  .dr-top { padding: 0 16px; display: flex; flex-direction: column; gap: 10px; flex: none; }
  .dr-new {
    height: 40px; border-radius: 12px; background: var(--c-purple); color: #fff;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    font: 500 13px/18px var(--font-cn);
  }
  .dr-new:hover { background: #9778F5; }
  .dr-new svg { width: 15px; height: 15px; }
  .dr-search {
    height: 38px; border-radius: 11px; background: var(--c-lav-100);
    display: flex; align-items: center; gap: 8px; padding: 0 12px; text-align: left;
    font: 400 12px/17px var(--font-cn); color: var(--c-muted);
  }
  .dr-search:hover { background: var(--c-lav-200); }
  .dr-search svg { width: 15px; height: 15px; flex: none; }

  .dr-group-label {
    display: flex; justify-content: space-between; align-items: center;
    padding: 22px 18px 8px; font: 500 11px/15px var(--font-cn); color: var(--c-muted-2); flex: none;
  }
  .dr-group-label em { font-style: normal; font: 600 9px/13px var(--font-en); color: var(--c-purple-3); background: var(--c-lav-100); border-radius: 6px; padding: 2px 6px; }
  .dr-convs { display: flex; flex-direction: column; gap: 4px; padding: 0 10px; flex: none; }
  .dr-conv {
    display: flex; align-items: center; gap: 10px; padding: 10px;
    border-radius: 12px; text-align: left; width: 100%;
  }
  .dr-conv:hover { background: var(--c-lav-50); }
  .dr-conv.is-active { background: var(--c-lav-200); }
  .dr-av { width: 32px; height: 32px; border-radius: 16px; flex: none; background: var(--c-lav-400); }
  .dr-av.tone-noir { background: #D5C8F5; }
  .dr-av.tone-pink { background: #FFE6F6; }
  .dr-av.tone-blue { background: #EFF5FF; }
  .dr-conv-col { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
  .dr-conv-col b { font: 600 12px/17px var(--font-cn); color: var(--c-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .dr-conv-col small { font: 400 10px/14px var(--font-cn); color: var(--c-muted-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .dr-spacer { flex: 1 1 auto; min-height: 12px; }
  .dr-nav { display: flex; flex-direction: column; gap: 3px; padding: 0 10px 8px; flex: none; }
  .dr-nav-item {
    height: 38px; border-radius: 10px; display: flex; align-items: center; gap: 10px;
    padding: 0 10px; font: 400 12px/17px var(--font-cn); color: var(--c-ink-3); text-align: left;
  }
  .dr-nav-item:hover { background: var(--c-lav-50); }
  .dr-nav-item.is-active { background: var(--c-lav-100); color: var(--c-ink-2); font-weight: 600; }
  .dr-nav-item .ic { width: 18px; height: 18px; flex: none; }
  .dr-nav-item .ic svg { width: 18px; height: 18px; }
  .dr-dev { margin: 0 16px 10px; font: 400 10px/14px var(--font-cn); color: var(--c-muted-3); text-align: left; flex: none; }
  .dr-dev:hover { color: var(--c-ink-2); }
  .dr-account {
    margin: 0 12px 14px; padding: 10px; border-radius: 12px; background: #fff;
    border: 1px solid var(--c-line); display: flex; align-items: center; gap: 10px; flex: none;
  }
  .dr-account .dr-av { width: 30px; height: 30px; background: var(--c-lav-400); }
  .dr-account b { font: 600 11px/16px var(--font-cn); color: var(--c-ink); }
  .dr-account small { font: 400 9px/13px var(--font-cn); color: var(--c-muted-2); }

  .dc-head {
    height: 72px; flex: none; padding: 0 20px; display: flex; align-items: center;
    justify-content: space-between; border-bottom: 1px solid var(--c-line);
  }
  .dc-head b { display: block; font: 600 15px/21px var(--font-cn); color: var(--c-ink); }
  .dc-head span { display: block; font: 400 11px/15px var(--font-cn); color: var(--c-muted-2); margin-top: 2px; }
  .dc-icon-btn { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; }
  .dc-icon-btn:hover { background: var(--c-lav-50); }
  .dc-icon-btn svg { width: 16px; height: 16px; }
  .dc-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 20px; }
  .dc-sec { display: flex; flex-direction: column; gap: 10px; }
  .dc-sec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .dc-sec-head b { font: 600 13px/19px var(--font-cn); color: var(--c-ink); }
  .dc-sec-head span, .dc-link-btn { font: 400 10px/14px var(--font-cn); color: var(--c-purple-3); }
  .dc-link-btn:hover { text-decoration: underline; }
  .dc-card { border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
  .dc-card.t1 { background: var(--c-lav-50); }
  .dc-card.t2 { background: var(--c-blue-50); }
  .dc-card.t3 { background: var(--c-rose-50); }
  .dc-card small { font: 400 10px/14px var(--font-cn); color: var(--c-muted); }
  .dc-card p { margin: 0; font: 400 12px/19px var(--font-cn); color: var(--c-ink); }
  .dc-model {
    width: 100%; min-height: 42px; border-radius: 12px; background: var(--c-surface-2);
    border: 1px solid var(--c-line-3); padding: 0 12px; display: flex; align-items: center;
    justify-content: space-between; text-align: left; font: 500 12px/17px var(--font-cn); color: var(--c-ink);
  }
  .dc-model:hover { border-color: var(--c-purple); }
  .dc-model svg { width: 12px; height: 12px; }
  .dc-effort-label { font: 400 11px/16px var(--font-cn); color: var(--c-muted-2); }
  .dc-effort-track { height: 8px; border-radius: 4px; background: var(--c-lav-200); overflow: hidden; }
  .dc-effort-fill { height: 8px; border-radius: 4px; background: var(--c-purple); transition: width .2s ease; }
  .dc-effort-ticks { display: flex; justify-content: space-between; font: 400 9px/13px var(--font-cn); color: var(--c-muted-3); }
  .dc-quota { border-radius: 16px; background: var(--c-surface-2); border: 1px solid var(--c-lav-200); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
  .dc-quota-row { display: flex; flex-direction: column; gap: 5px; }
  .dc-quota-line { display: flex; justify-content: space-between; font: 500 11px/16px var(--font-cn); color: var(--c-ink); }
  .dc-quota-line b { font: 600 11px/16px var(--font-en); color: var(--c-purple-2); }
  .dc-quota-bar { height: 5px; border-radius: 3px; background: var(--c-lav-200); overflow: hidden; }
  .dc-quota-bar i { display: block; height: 5px; border-radius: 3px; background: var(--c-purple-2); }
  .dc-quota-row.week .dc-quota-bar i { background: var(--c-purple); }
  .dc-quota-row small { font: 400 9px/13px var(--font-cn); color: var(--c-ink-3); }
  .dc-apply { width: 100%; height: 40px; border-radius: 20px; background: var(--c-purple); color: #fff; font: 500 13px/18px var(--font-cn); }
  .dc-apply:hover { background: #9778F5; }
  .dc-note { border-radius: 12px; background: var(--c-lav-50); padding: 10px 12px; font: 400 10px/16px var(--font-cn); color: var(--c-ink-3); }
  /* V2 · 真实状态契约：未接线时显示「待接线」，绝不渲染假数值 / DEMO 角标 */
  .dc-pending {
    border-radius: 12px; background: var(--c-lav-50); border: 1px dashed var(--c-lav-400);
    padding: 10px 12px; font: 400 10px/16px var(--font-cn); color: var(--c-ink-3);
  }
  .dc-pending b { display: block; font-weight: 600; color: var(--c-ink-2); margin-bottom: 2px; }
  .dc-unavailable { opacity: .5; pointer-events: none; }
  .dc-src { font: 400 9px/13px var(--font-en); color: var(--c-muted-3); letter-spacing: .02em; }
  /* V2-FIX-02 · 右栏引用与「查看全部」共用同一份绑定元数据 */
  .dc-ref-bundle { display: flex; flex-direction: column; gap: 10px; }
  .dc-ref-meta {
    font: 400 9px/13px var(--font-en); color: var(--c-muted-3);
    display: flex; justify-content: space-between; gap: 8px; word-break: break-all;
  }
  .dc-card[data-ref-id] { cursor: default; }
  .dc-ghost { width: 100%; min-height: 38px; border-radius: 11px; background: var(--c-lav-50); padding: 0 12px; text-align: left; font: 500 11px/16px var(--font-cn); color: var(--c-ink-2); display: flex; align-items: center; justify-content: space-between; }
  .dc-ghost:hover { background: var(--c-lav-200); }
  .dc-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .dc-stat { border-radius: 14px; background: var(--c-lav-50); padding: 14px; display: flex; flex-direction: column; gap: 3px; }
  .dc-stat b { font: 700 24px/29px var(--font-display); color: var(--c-purple-2); }
  .dc-stat small { font: 400 10px/14px var(--font-cn); color: var(--c-muted-2); }
  .dc-layer { display: flex; flex-direction: column; gap: 5px; }
  .dc-layer-top { display: flex; justify-content: space-between; font: 400 11px/16px var(--font-cn); color: var(--c-ink-3); }
  .dc-layer-bar { height: 6px; border-radius: 3px; background: var(--c-lav-100); overflow: hidden; }
  .dc-layer-bar i { display: block; height: 6px; border-radius: 3px; background: var(--ly, var(--c-purple)); }
  .dc-sync { border-radius: 12px; background: var(--c-lav-50); padding: 12px; display: flex; flex-direction: column; gap: 4px; }
  .dc-sync b { font: 500 11px/16px var(--font-cn); color: var(--c-green); }
  .dc-sync small { font: 400 10px/14px var(--font-cn); color: var(--c-muted-2); }
  .dc-reopen { display: none; }
  body.ctx-collapsed .dc-reopen {
    display: flex; position: absolute; right: 20px; top: 20px; z-index: 90;
    height: 32px; padding: 0 14px; border-radius: 16px; align-items: center;
    background: #fff; border: 1px solid var(--c-line-3); box-shadow: 0 4px 14px rgba(42,31,77,.12);
    font: 500 11px/16px var(--font-cn); color: var(--c-ink-2);
  }
  .dr-toast {
    display: block;
    position: absolute; left: 50%; bottom: 28px; transform: translate(-50%, 8px);
    background: rgba(42,31,77,.92); color: #fff; font: 400 11px/1.4 var(--font-cn);
    padding: 8px 14px; border-radius: 18px; opacity: 0; pointer-events: none;
    transition: opacity .2s, transform .2s; z-index: 210; white-space: nowrap;
  }
  .dr-toast.is-on { opacity: 1; transform: translate(-50%, 0); }
}

/* ==========================================================================
   4. TABLET — 768–1099px：76px 图标栏 + 主内容（两栏）
   ========================================================================== */
@media (min-width: 768px) and (max-width: 1099px) {
  .phone {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    grid-template-rows: 100dvh;
  }
  .desk-rail { display: flex; grid-column: 1; grid-row: 1; align-items: center; padding: 12px 0; }
  .app { grid-column: 2; grid-row: 1; min-width: 0; }
  .desk-context, .dc-reopen { display: none !important; }
  .tab-bar { display: none; }
  .status-bar, .home-indicator { display: none; }

  /* 图标栏只留品牌标 + 四个导航图标 */
  .dr-brand { padding: 4px 0 18px; justify-content: center; }
  .dr-brand-text, .dr-tag, .dr-top, .dr-group-label, .dr-convs,
  .dr-dev, .dr-account, .dr-spacer, .dr-nav-item .dr-label { display: none; }
  .dr-nav { padding: 0; gap: 8px; }
  .dr-nav-item { width: 48px; height: 48px; justify-content: center; padding: 0; border-radius: 14px; }
  .dr-nav-item .ic, .dr-nav-item .ic svg { width: 22px; height: 22px; }

  .chat-header { padding: 0 24px; }
  .messages { padding-left: max(24px, calc((100% - 680px) / 2)); padding-right: max(24px, calc((100% - 680px) / 2)); }
  .desk-toolbar, .desk-hint, .input-bar { padding-left: 24px; padding-right: 24px; }
  .search-screen { left: 76px; right: 0; top: 0; bottom: 0; }
  .reader { left: 76px; right: 0; top: 0; bottom: 0; }

  /* Memory 页：五层卡 3 列，最近区 2 列 */
  .ov-head { padding: 16px 24px; }
  .layer-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); overflow: visible; padding: 0 24px; }
  .layer-card { width: auto; }
  .recent-memories, .recent-feels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; padding: 0 24px; }
  .rm-card, .rf-card { width: auto; }
  .sec-head { padding: 0 24px 8px; }
  .mem-list { padding: 0 24px; }
  .ov-scroll { padding: 18px 0 0; }
}

/* ==========================================================================
   5. DESKTOP — ≥ 1100px：264 左栏 + 主区 + 320 右栏（三栏）
   ========================================================================== */
@media (min-width: 1100px) {
  .phone {
    --rail-w: 264px; --ctx-w: 320px;
    display: grid;
    grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--ctx-w);
    grid-template-rows: 100dvh;
  }
  body.ctx-collapsed .phone { --ctx-w: 0px; }
  body.ctx-collapsed .desk-context { display: none; }
  .desk-rail { display: flex; grid-column: 1; grid-row: 1; }
  .app { grid-column: 2; grid-row: 1; min-width: 0; }
  .desk-context { display: flex; grid-column: 3; grid-row: 1; }
  .tab-bar { display: none; }
  .status-bar, .home-indicator { display: none; }

  /* V2-FIX-06 · 右栏收起后主区必须真正扩展，而不是留下一条空栅格。
     显式重写三列模板；同时让覆盖层跟随 --ctx-w 归零，避免右栏位置留下空白。 */
  body.ctx-collapsed .phone {
    grid-template-columns: var(--rail-w) minmax(0, 1fr) 0px;
  }
  body.ctx-collapsed .desk-context,
  body.ctx-collapsed .desk-context * { visibility: hidden; }
  body.ctx-collapsed .search-screen { right: 0; }
  body.ctx-collapsed .reader { right: 0; }
  .phone { position: relative; }

  /* 对话页：顶部身份栏 + 居中限宽消息列 */
  .chat-header { background: #fff; }
  .chat-screen { background: #fff; }
  .messages { background: var(--c-surface); }

  /* 关键字搜索改为覆盖主内容区（右栏常驻可见） */
  .search-screen { left: var(--rail-w); right: var(--ctx-w); top: 0; bottom: 0; box-shadow: none; border-right: 1px solid var(--c-line); }
  .search-results, .search-summary { padding-left: 28px; padding-right: 28px; }
  .search-nav { padding: 0 28px; }
  .search-results .result-item { max-width: 640px; }

  /* Memory 页：桌面重排（标题行 / 五层网格 / 双列最近区） */
  .ov-head {
    flex-direction: row; align-items: center; flex-wrap: wrap; gap: 12px 18px;
    padding: 20px 28px; background: #fff;
  }
  .ov-head.is-scrolled { padding-top: 20px; padding-bottom: 20px; gap: 12px 18px; box-shadow: none; border-bottom-color: var(--c-line); }
  .ov-head.is-scrolled .ov-title-block { margin-bottom: 0; }
  .ov-head.is-scrolled .mem-title { font-size: 30px; line-height: 36px; }
  .ov-head.is-scrolled .mem-subtitle { max-height: 20px; opacity: 1; }
  .ov-head.is-scrolled .sync-row { max-height: 44px; opacity: 1; padding-top: 8px; padding-bottom: 8px; margin-bottom: 0; pointer-events: auto; }
  .ov-title-block { flex: none; }
  .mem-title { font-size: 30px; line-height: 36px; }
  .sync-row { flex: none; max-width: 260px; margin-left: auto; }
  .ov-tools { flex: 1 1 100%; justify-content: flex-start; order: 3; }
  .mem-search { flex: 0 1 360px; }
  .date-btn { max-width: 160px; }

  .ov-scroll { padding: 24px 28px 0; }
  .layer-cards {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px; overflow: visible; padding: 0; scroll-snap-type: none;
  }
  .layer-card { width: auto; min-height: 126px; }
  .layer-card:hover { border-color: var(--ly); box-shadow: 0 8px 22px -16px rgba(42,31,77,.7); }
  .ov-section { margin-top: 26px; }
  .sec-head { padding: 0 0 10px; }
  .recent-memories, .recent-feels {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px; overflow: visible; padding: 0; scroll-snap-type: none;
  }
  .rm-card, .rf-card { width: auto; min-height: 108px; }
  .mem-list { padding: 0; max-width: 820px; }
  .ov-pad { height: 40px; }

  /* 沉浸阅读器：覆盖主区 + 右栏，卡片限宽居中 */
  .reader { left: var(--rail-w); right: 0; top: 0; bottom: 0; }
  .reader-stage { padding: 24px 32px 0; align-items: center; }
  .flip-card { width: min(680px, 100%); margin: auto 0 0; }
  .reader-hint { width: min(680px, 100%); margin: 0 0 auto; }
  .reader-head, .reader-foot { padding-left: 32px; padding-right: 32px; }
  .reader-foot { justify-content: center; }
  .reader-foot .foot-btn { flex: 0 1 220px; }
}

/* ==========================================================================
   6. WIDE — ≥ 1600px
   ========================================================================== */
@media (min-width: 1600px) {
  .phone { --rail-w: 288px; --ctx-w: 360px; }
  .messages { padding-left: max(40px, calc((100% - 760px) / 2)); padding-right: max(40px, calc((100% - 760px) / 2)); }
  .chat-header, .desk-toolbar, .desk-hint, .input-bar { padding-left: 40px; padding-right: 40px; }
  .ov-head { padding-left: 40px; padding-right: 40px; }
  .ov-scroll { padding-left: 40px; padding-right: 40px; }
  .search-screen { left: var(--rail-w); right: var(--ctx-w); }
  .reader { left: var(--rail-w); }
  .dc-scroll { padding: 24px; }
}

/* ==========================================================================
   7. 动效偏好
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .dc-effort-fill { transition: none; }
}

.integration-controls,.worldbook-entry{padding:10px 16px;font-size:12px;color:var(--text-secondary,#666);background:var(--surface,#faf9f7)}.integration-controls button,.worldbook-entry button{padding:6px 10px;margin:3px;border:1px solid #ddd;border-radius:12px;background:transparent;color:inherit}.worldbook-entry input,.worldbook-entry textarea,.worldbook-entry select{display:block;box-sizing:border-box;width:100%;margin:6px 0;padding:8px;border:1px solid #ddd;border-radius:10px;background:transparent;color:inherit}.worldbook-entry p{overflow-wrap:anywhere}.worldbook-entry[open]{max-height:50vh;overflow:auto}

/* ==========================================================================
   T80.d · Noir PWA Chat UX Enhancements
   Adapted portions from deepseek-ai/chat-demo (MIT, Copyright (c) 2026 DeepSeek)
   ========================================================================== */
@media not all and (min-width: 768px) {
  .phone,
  body.bare .phone {
    position: fixed;
    top: var(--app-viewport-top, 0px);
    left: 0;
    right: 0;
    bottom: auto;
    height: var(--app-viewport-height, 100dvh);
  }
  .phone[data-keyboard-open="1"] .tab-bar {
    display: none !important;
  }
  .phone[data-keyboard-open="1"] .integration-controls {
    padding: 4px 12px;
  }
}

.input-field {
  position: relative;
}
.input-field input.is-voice-recording,
.input-field textarea.is-voice-recording {
  visibility: hidden;
}
.noir-voice-spectrum {
  position: absolute;
  inset: 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 100%;
  pointer-events: none;
  opacity: 0.85;
}
.noir-voice-spectrum-bar {
  flex-shrink: 0;
  width: 2px;
  height: 5px;
  border-radius: 1px;
  background-color: var(--c-purple-2, #7C5CE0);
  transform-origin: center;
  will-change: transform;
}
.noir-voice-timer {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  font-size: 11px;
  line-height: 16px;
  color: var(--c-ink-2, #6F55B8);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
@media not all and (min-width: 768px) {
  .noir-voice-timer {
    display: none;
  }
}
#micBtn.is-recording {
  position: relative;
  border-radius: 50%;
  background: rgba(124, 92, 224, 0.18);
  box-shadow: 0 0 0 4px rgba(167, 139, 250, 0.22);
}
#micBtn.is-transcribing {
  position: relative;
  border-radius: 50%;
  opacity: 0.75;
}
#micBtn.is-transcribing::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border: 1.5px solid var(--c-lav-400, #E3D8FF);
  border-top-color: var(--c-purple-2, #7C5CE0);
  animation: noirVoiceSpin 0.8s linear infinite;
}
@keyframes noirVoiceSpin {
  to { transform: rotate(360deg); }
}

/* Rich text / Markdown inside message bubbles */
.ds-markdown {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.ds-markdown .md-p,
.ds-markdown .md-heading,
.ds-markdown .md-quote,
.ds-markdown .md-list {
  margin: 0;
}
.ds-markdown .md-heading {
  font-weight: 600;
  line-height: 1.35;
}
.ds-markdown .md-h1 { font-size: 16px; }
.ds-markdown .md-h2 { font-size: 15px; }
.ds-markdown .md-h3,
.ds-markdown .md-h4 { font-size: 14px; }
.ds-markdown .md-list {
  padding-left: 18px;
}
.ds-markdown .md-quote {
  padding-left: 10px;
  border-left: 2px solid var(--c-purple, #A78BFA);
  opacity: 0.9;
}
.ds-markdown .md-inline-code {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(42, 31, 77, 0.08);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}
.bubble-user .ds-markdown .md-inline-code {
  background: rgba(255, 255, 255, 0.22);
}
.ds-markdown .md-link {
  color: var(--c-purple-2, #7C5CE0);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.bubble-user .ds-markdown .md-link {
  color: #fff;
}
.ds-markdown .md-code-block {
  border-radius: 10px;
  border: 1px solid var(--c-line-2, #E9E0FF);
  background: #1E1936;
  color: #F6F1FF;
  overflow: hidden;
  margin: 2px 0;
}
.ds-markdown .md-code-block-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 11px;
  line-height: 16px;
}
.ds-markdown .md-code-lang {
  color: #D5C8F5;
  font-family: var(--font-en, monospace);
}
.ds-markdown .md-code-copy {
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 11px;
  color: #EFE8FF;
  background: rgba(255, 255, 255, 0.1);
}
.ds-markdown .md-code-copy:hover {
  background: rgba(255, 255, 255, 0.18);
}
.ds-markdown .md-code-block pre {
  margin: 0;
  padding: 8px 10px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 18px;
  white-space: pre;
}
