/* ============================================================
   Textmolt Design Token Seed (--tm-*)
   Phase 2 Workstream A — 51-token base layer (49 base + 2 brand-rgb helpers)
   + v2 Extension (Design-System Overhaul 2026-07-02, D 路 §3.1)
   Source: docs/plans/PHASE_2_IMPLEMENTATION_PLAN.md (v1.1 Codex PASS)
   Census:  docs/plans/PHASE_1B_TOKEN_CENSUS.md — 51 seed + v2 extension

   Categories (count): brand 4 + brand-rgb 2 + semantic 6 + border 2 + status 3 +
                      overlay 2 + z-index 11 + radius 6 + shadow 6 +
                      spacing 6 + motion 3 = 51

   Loaded BEFORE styles.css so legacy --accent-/--bg-/--text-/--shadow-/
   --radius-/--border- aliases can reference --tm-*. Theme variants
   model-family data attributes override --tm-brand-purple-rgb
   indirectly via existing --primary-glow-rgb plumbing.
   ============================================================ */

:root {
  /* ── Brand color (4) ── */
  --tm-brand-purple: #5545b6;        /* 品牌紫墨（0728 观墨窗拍板：亮紫全族换 #5545b6 家族） */
  --tm-brand-purple-rgb: 85, 69, 182;
  --tm-brand-blue: #1E40AF;
  --tm-brand-blue-rgb: 30, 64, 175;
  --tm-brand-green: #10b981;
  --tm-brand-orange: #f97316;

  /* ── Semantic color (6) — text + bg ── */
  --tm-text-primary: #1e293b;
  --tm-text-secondary: #475569;
  --tm-text-muted: #94a3b8;
  --tm-bg-1: #f9fafb;                 /* page background */
  --tm-bg-2: #ffffff;                 /* surface / card */
  --tm-bg-3: #f3f4f6;                 /* tertiary / chip */

  /* ── Border (2) ── */
  --tm-border-default: #e5e7eb;
  --tm-border-soft: #d1d5db;

  /* ── Status (3) ── */
  --tm-status-success: #10b981;
  --tm-status-danger: #ef4444;
  /* danger 的 rgb 三元组（供 rgba() 合成半透明底/边；D§4.3 登记 · s02 B5 错误卡） */
  --tm-status-danger-rgb: 239, 68, 68;
  --tm-status-warning: #f59e0b;

  /* ── Overlay (2) ── */
  --tm-overlay-modal: rgba(0, 0, 0, 0.45);
  --tm-overlay-toast: rgba(0, 0, 0, 0.25);

  /* ── z-index scale (11) — names per plan A.7 ── */
  --tm-z-fab: 20;
  --tm-z-raised: 50;
  --tm-z-sticky: 100;
  --tm-z-update-banner: 101; /* 介于 sticky(100) 与 banner(200) 之间，UpdateBanner 专用 */
  --tm-z-banner: 200;
  --tm-z-toast: 10150; /* toast 须浮于一切可交互层(抽屉 9001/modal-top/onboarding)之上、仅低于 critical——撤销条曾被往卷纸抽屉整张盖住(0810 真机盲区) */
  --tm-z-modal: 2000;
  --tm-z-overlay: 9000;
  --tm-z-modal-top: 10000;
  --tm-z-onboarding: 10100;
  --tm-z-critical: 10200;

  /* ── Radius (6) ── */
  --tm-radius-xs: 4px;
  --tm-radius-sm: 6px;
  --tm-radius-md: 10px;
  --tm-radius-lg: 12px;
  --tm-radius-xl: 16px;
  --tm-radius-full: 9999px;

  /* ── Shadow (6) ── */
  --tm-shadow-1: 0 1px 2px rgba(0, 0, 0, 0.05);
  --tm-shadow-2: 0 4px 12px rgba(0, 0, 0, 0.08);
  --tm-shadow-3: 0 8px 24px rgba(0, 0, 0, 0.12);
  --tm-shadow-inset: inset 0 2px 4px rgba(0, 0, 0, 0.05);
  --tm-shadow-float: 0 20px 50px -10px rgba(0, 0, 0, 0.12);
  --tm-shadow-xl: 0 16px 48px -8px rgba(0, 0, 0, 0.18);

  /* ── Spacing scale (6) — 4 / 8 / 12 / 16 / 24 / 32 ── */
  --tm-space-1: 4px;
  --tm-space-2: 8px;
  --tm-space-3: 12px;
  --tm-space-4: 16px;
  --tm-space-5: 24px;
  --tm-space-6: 32px;

  /* ── Layout: safe-area insets（R2 W2，非视觉 token）── */
  --tm-safe-top: env(safe-area-inset-top, 0px);
  --tm-safe-bottom: env(safe-area-inset-bottom, 0px);

  /* ── Motion (3) — 复合 token 保留（T6 兼容律），值刷新为引用 v2 scale ── */
  --tm-motion-fast: var(--tm-dur-fast) var(--tm-ease-out);
  --tm-motion-normal: var(--tm-dur-normal) var(--tm-ease-out);
  --tm-motion-slow: var(--tm-dur-slow) var(--tm-ease-expo);
}

/* ============================================================
   v2 Extension — Design-System Overhaul 2026-07-02 (D 路)
   Spec: docs/plans/FRONTEND_UIUX_OVERHAUL_2026-07-02/04_PLAN_DESIGN_SYSTEM.md
   新增维度: typography / duration / easing / surface / glass /
             focus / model-accent + INDEX R3 跨路合并（B 紫系 / C status 面）。
   不改动上方 51 seed 任何值。
   ============================================================ */
:root {
  /* ── Typography: size 8 档（§2.5）── */
  --tm-text-2xs: 10px;   /* 徽章/角标专用，正文禁用 */
  --tm-text-xs: 11px;
  --tm-text-sm: 12px;
  --tm-text-md: 13px;    /* UI 默认 */
  --tm-text-base: 15px;  /* 聊天正文 */
  --tm-text-lg: 17px;
  --tm-text-xl: 20px;
  --tm-text-2xl: 24px;

  /* ── Typography: leading 5 档 ── */
  --tm-leading-none: 1.2;
  --tm-leading-tight: 1.35;
  --tm-leading-snug: 1.45;
  --tm-leading-normal: 1.5;
  --tm-leading-relaxed: 1.6;

  /* ── Typography: weight 3 档（禁 700+，§2.5）── */
  --tm-weight-regular: 400;
  --tm-weight-medium: 500;
  --tm-weight-semibold: 600;

  /* ── Typography: font stacks ── */
  --tm-font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI",
                  Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  --tm-font-mono: "Cascadia Code", Consolas, "JetBrains Mono",
                  "SF Mono", Menlo, monospace;

  /* ── Motion: duration 7 档（§2.4.1）── */
  --tm-dur-instant: 80ms;
  --tm-dur-fast: 150ms;
  --tm-dur-normal: 250ms;
  --tm-dur-slow: 400ms;
  --tm-dur-deliberate: 700ms;
  --tm-dur-ambient: 4s;
  --tm-dur-scene: 20s;

  /* ── Motion: easing 5 条（§2.4.2）── */
  --tm-ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --tm-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --tm-ease-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --tm-ease-in: cubic-bezier(0.4, 0, 1, 1);
  --tm-ease-linear: linear;

  /* ── Surface 4 级（§2.3；0/1/2 引用 seed 保持同源）── */
  --tm-surface-0: var(--tm-bg-1);
  --tm-surface-1: var(--tm-bg-2);
  --tm-surface-2: var(--tm-bg-3);
  --tm-surface-3: #eceef2;
  /* R2-s01 W3 R-05/R-06: inverse toast surface + text */
  --tm-surface-inverse: #111827;
  --tm-text-on-inverse: #f9fafb;

  /* ── Glass 三档四件套（§2.3；降级底色见 system.css @supports 层）── */
  --tm-glass-bg: rgba(255, 255, 255, 0.72);
  --tm-glass-bg-strong: rgba(255, 255, 255, 0.85);
  --tm-glass-bg-faint: rgba(255, 255, 255, 0.45);
  --tm-glass-border: rgba(255, 255, 255, 0.5);
  --tm-glass-highlight: inset 0 0 0 1px rgba(255, 255, 255, 0.3);
  --tm-glass-blur-soft: 8px;
  --tm-glass-blur: 12px;
  --tm-glass-blur-heavy: 20px;
  --tm-glass-saturate: 160%;
  /* 无 backdrop-filter 时的实底替代（M1 规则） */
  --tm-glass-fallback-bg: rgba(255, 255, 255, 0.92);

  /* ── Focus（§2.7 A1）── */
  --tm-focus-ring-color: var(--tm-brand-purple);
  --tm-focus-ring: 0 0 0 2px var(--tm-bg-2), 0 0 0 4px var(--tm-focus-ring-color);
  --tm-focus-ring-outline: 2px solid var(--tm-focus-ring-color);

  /* ── Model accent 单一事实源（§2.2；默认 = registry default）── */
  --tm-model-accent-rgb: 99, 102, 241;
  --tm-model-accent: rgb(var(--tm-model-accent-rgb));
  --tm-model-glow-rgb: var(--tm-model-accent-rgb);

  /* ── R2-s02 U8 Settings Impress primitives（layout/motion, theme-neutral）── */
  --tm-settings-row-touch: 52px;
  --tm-settings-chevron-nudge: 2px;
  --tm-settings-avatar-ring: 2px;

  /* ── INDEX R3 合并 · B 路紫系（02_PLAN §6 增量登记）── */
  --tm-brand-purple-strong: #46389f;                              /* hover 深紫 */
  /* 沉纸墨紫（P3-12 / 切片② 插入按钮工作流态共用）：实底后果性动作的
     低饱和深紫——比 brand-purple 沉一档，接近纸上墨色的克制感。 */
  --tm-ink-purple: #4c3fa5;
  --tm-ink-purple-strong: #3e3190;
  --tm-brand-purple-dark: #8d81da;                                /* 显式亮紫常量，不随主题翻转 */
  --tm-brand-purple-alpha-08: rgba(var(--tm-brand-purple-rgb), 0.08);
  --tm-brand-purple-alpha-10: rgba(var(--tm-brand-purple-rgb), 0.10);
  --tm-brand-purple-alpha-28: rgba(var(--tm-brand-purple-rgb), 0.28);

  /* ── INDEX R3 合并 · C 路 status surface 面（03_PLAN §5：C-02 banner 等）── */
  --tm-status-warning-bg: rgba(245, 158, 11, 0.10);
  --tm-status-warning-fg: #92400e;
  --tm-status-danger-bg: rgba(239, 68, 68, 0.10);
  --tm-status-danger-fg: #991b1b;

  /* ── 0728 观墨窗纸面族（B4 v1《书房动线》拍板；chat 空态 + zotero 面板 + 封面共用，
        色值 = mockup 权威 anchor；dark = 夜书房推导，纹理关闭）── */
  --tm-serif: Georgia, "Times New Roman", "Songti SC", "SimSun", serif;
  --tm-paper: #f7f2e8;
  --tm-paper-2: #f1eadb;
  --tm-paper-raised: #fbf8f1;
  --tm-paper-band: #f4eee1;
  --tm-paper-hairline: #d8cdb6;
  --tm-paper-hairline-2: #c9bda2;
  --tm-paper-ink: #2b2534;
  --tm-paper-ink-2: #5c5468;
  --tm-paper-ink-mut: #8b8296;
  --tm-paper-exlibris: #3a2f52;
  --tm-paper-exlibris-2: #6b5f85;
  /* B5 刀③ 对话卷：楷体族（你的手书=朱批便笺；西文回落 Georgia italic 同源）
     + 朱墨（沉褐朱砂——与错误红 #ef4444 刻意拉开，rubrication 史实色） */
  --tm-kai: "KaiTi", "STKaiti", "DFKai-SB", Georgia, "Times New Roman", serif;
  --tm-cinnabar: #8a4032;
  --tm-paper-texture: url("../assets/ink/paper.jpg");
  /* 纹理罩层：纸纹 jpg 不透明且自带灰阶起伏，直铺整窗会显灰带——
     暖纸色罩在纹理上，只留细颗粒透出（三面共用：chat 空态/zotero 面板/colophon）。
     B5 v2 四档对比用户选定 0.76（纹理比 0.88 更显、仍不出灰带）。 */
  --tm-paper-veil: rgba(247, 242, 232, 0.76);
}

/* ── Model accent per data-model（唯一允许出现模型判定的位置）── */
:root:is([data-model="gpt_5_6_luna"],[data-model="gpt_5_6_terra"],[data-model="gpt_5_6_sol"]) { --tm-model-accent-rgb: 16,185,129; }
:root:is([data-model="claude_sonnet_5"],[data-model="claude_opus_5"],[data-model="claude_fable_5"]) { --tm-model-accent-rgb: 249,115,22; }
:root:is([data-model="gemini_3_7_flash"],[data-model="gemini_3_1_pro_preview"]) { --tm-model-accent-rgb: 26,115,232; --tm-model-glow-rgb: 66,133,244; --tm-model-aurora-1: rgba(59,130,246,.14); --tm-model-aurora-2: rgba(37,99,235,.12); --tm-model-aurora-3: rgba(14,165,233,.10); --tm-model-orb-start: #dbeafe; --tm-model-orb-end: #1e40af; }
:root:is([data-model="deepseek_v4_flash_0731"],[data-model="deepseek_v4_pro_0813"]) { --tm-model-accent-rgb: 139,92,246; }
/* registry default 用默认值，无需覆盖 */

/* ── s03 E§3.4: element 级模型徽点（会话行 model dot）──
   模型判定仍唯一存在于本文件；其余样式层只挂 .tm-model-dot 类 + data-model 属性。
   未知/缺省 modelId（含 wps-ai）落品牌 indigo 默认。 */
.tm-model-dot                        { background: rgb(var(--tm-model-accent-rgb)); }

/* ============================================================
   Dark theme overrides — 25 of 51 tokens override under dark
   (brand 6 + semantic 6 + border 2 + status 3 + overlay 2 + shadow 6 = 25;
    z-index / radius / spacing / motion 不分主题)
   Trigger: html[data-theme="dark"]
   ============================================================ */
:root[data-theme="dark"] {
  /* Brand (lifted brightness for dark surface) */
  --tm-brand-purple: #988be4;
  --tm-brand-purple-rgb: 152, 139, 228;
  --tm-brand-blue: #3b82f6;
  --tm-brand-blue-rgb: 59, 130, 246;
  --tm-brand-green: #34d399;
  --tm-brand-orange: #fb923c;

  /* Semantic */
  --tm-text-primary: #f1f5f9;
  --tm-text-secondary: #cbd5e1;
  --tm-text-muted: #94a3b8;
  --tm-bg-1: #121212;
  --tm-bg-2: #1e1e1e;
  --tm-bg-3: #121212;

  /* Border */
  --tm-border-default: #2a2a2a;
  --tm-border-soft: #3a3a3a;

  /* Status */
  --tm-status-success: #34d399;
  --tm-status-danger: #f87171;
  --tm-status-warning: #fbbf24;

  /* Overlay (deeper) */
  --tm-overlay-modal: rgba(0, 0, 0, 0.6);
  --tm-overlay-toast: rgba(0, 0, 0, 0.4);

  /* Shadow (deeper for dark) */
  --tm-shadow-1: 0 1px 3px rgba(0, 0, 0, 0.3);
  --tm-shadow-2: 0 4px 12px rgba(0, 0, 0, 0.4);
  --tm-shadow-3: 0 8px 24px rgba(0, 0, 0, 0.5);
  --tm-shadow-inset: inset 0 2px 4px rgba(0, 0, 0, 0.3);
  --tm-shadow-float: 0 20px 50px -10px rgba(0, 0, 0, 0.6);
  --tm-shadow-xl: 0 16px 48px -8px rgba(0, 0, 0, 0.65);

  /* ── v2 Extension dark overrides（§3.1）── */
  --tm-surface-2: #252528;           /* D3: 暗色越浮越亮，修层次塌陷 */
  --tm-surface-3: #2e2e32;
  --tm-surface-inverse: #f8fafc;
  --tm-text-on-inverse: #0f172a;

  --tm-glass-bg: rgba(30, 30, 30, 0.8);          /* 收编 styles.css:10236 已调优值 */
  --tm-glass-bg-strong: rgba(30, 30, 30, 0.92);
  --tm-glass-bg-faint: rgba(30, 30, 30, 0.55);
  --tm-glass-border: rgba(255, 255, 255, 0.1);
  --tm-glass-highlight: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  --tm-glass-fallback-bg: rgba(24, 24, 26, 0.94);

  --tm-focus-ring: 0 0 0 2px var(--tm-bg-2), 0 0 0 4px var(--tm-focus-ring-color);

  /* R3 · B 路紫系 dark（alpha 族经 brand-purple-rgb 自动切换，无需重复） */
  --tm-brand-purple-strong: #aca2ec;             /* 暗底 hover 提亮一档 */
  /* 沉纸墨紫 dark：暗底提亮保持可辨（仍低于 brand-purple 的鲜度） */
  --tm-ink-purple: #7a6cd0;
  --tm-ink-purple-strong: #8b7ee0;

  /* R3 · C 路 status surface 面 dark（03_PLAN C-02 已调优值） */
  --tm-status-warning-bg: rgba(245, 158, 11, 0.14);
  --tm-status-warning-fg: #fcd34d;
  --tm-status-danger-bg: rgba(239, 68, 68, 0.16);
  --tm-status-danger-fg: #fca5a5;

  /* 0728 观墨窗纸面族 dark（夜书房：墨紫底、纹理关） */
  --tm-paper: #191521;
  --tm-paper-2: #1e1927;
  --tm-paper-raised: #231d2e;
  --tm-paper-band: #201a2a;
  --tm-paper-hairline: #322b40;
  --tm-paper-hairline-2: #3f374f;
  --tm-paper-ink: #e9e4f2;
  --tm-paper-ink-2: #b6adc6;
  --tm-paper-ink-mut: #857c97;
  --tm-paper-exlibris: #c6bbe0;
  --tm-paper-exlibris-2: #9a90b4;
  /* 朱墨 dark：夜书房提亮为陶朱，仍与 danger #f87171 分明 */
  --tm-cinnabar: #c08a7a;
  --tm-paper-texture: none;
  --tm-paper-veil: rgba(25, 21, 33, 0.94);
}

/* ============================================================
   v2 dark model-glow — 暗色辉光 -30% 饱和（§2.6 D2 / dark-optical）
   glow 与 accent 分离，仅辉光弱化；通配在前、具体在后（双保险：
   [data-theme][data-model] 双属性本就更特异）。
   ============================================================ */
:root[data-theme="dark"]                        { --tm-model-glow-rgb: var(--tm-model-accent-rgb); }

/* ============================================================
   z-index utility classes (consumed by JS-injected components
   that cannot read CSS custom properties from inline cssText).
   See A.5: AnnouncementBanner / AnnouncementModal /
   UpdateBanner / versionCheckFlow.
   Only sets z-index — does NOT touch position / inset / display.
   ============================================================ */
.tm-z-banner-sticky { z-index: var(--tm-z-sticky); }       /* AnnouncementBanner (was 100) */
.tm-z-update-banner { z-index: var(--tm-z-update-banner); } /* UpdateBanner 101 (one tier above sticky) */
.tm-z-overlay-modal { z-index: var(--tm-z-overlay); }      /* AnnouncementModal + versionCheckFlow force-update overlay (was 9999) */
