/* ============================================================
 * tokens.css —— 设计变量（UI 设计师所有）
 * 方向：暖黑底 + 玻璃拟态浮层 + 黄铜 / 暖米点缀 + 大留白 + 等宽数字
 * 约定：只放 :root 级设计变量与媒体查询覆盖，不写组件样式（组件归 app.css）。
 * 命名：--color-* / --font-* / --text-* / --space-* / --radius-* / --shadow-*
 *       --blur-* / --dur-* / --ease-* / --z-* / --panel-* / --bp-*
 * 说明：CSS 变量不能出现在 @media 条件里，断点变量仅作文档与 JS 参考，
 *       真正的媒体查询在文件末尾直接写像素值，且保持与断点表一致。
 * ============================================================ */
:root {
  color-scheme: dark;

  /* ---------- 品牌 / 黄铜 ---------- */
  --color-brand: #e0b67a;            /* 主黄铜：描边、图标、标记 */
  --color-brand-strong: #f2d3a0;     /* 高亮黄铜：悬停、强调数字 */
  --color-brand-deep: #a87e42;       /* 深黄铜：按下、暗部 */
  --color-brand-soft: rgba(224, 182, 122, 0.16);   /* 黄铜底光 */
  --color-brand-glow: rgba(224, 182, 122, 0.42);   /* 外发光 */
  --color-line-brand: rgba(224, 182, 122, 0.28);   /* 黄铜细描边 */

  /* ---------- 暖米 / 中性点缀 ---------- */
  --color-linen: #ece2d2;            /* 暖米：主按钮底、浅色强调 */
  --color-sand: #c8b9a3;             /* 沙色：次级文字、图例 */
  --color-clay: #8c7b67;             /* 陶土：分隔、弱化描边 */

  /* ---------- 暖黑底色层 ---------- */
  --color-bg: #0c0a08;               /* 画布外的暖黑（body 底） */
  --color-bg-elevated: #14110d;      /* 浮起底色（抽屉、弹层） */
  --color-bg-sunken: #080706;        /* 最深（加载层、遮罩） */
  --color-scrim: rgba(6, 5, 4, 0.58);        /* 遮罩层 */
  --color-scrim-strong: rgba(6, 5, 4, 0.78); /* 抽屉后方遮罩 */

  /* ---------- 玻璃拟态表面 ---------- */
  --color-surface: rgba(22, 19, 15, 0.62);         /* 主玻璃面板 */
  --color-surface-strong: rgba(28, 24, 19, 0.9);   /* 不透明浮层（toast、抽屉头） */
  --color-surface-soft: rgba(18, 16, 13, 0.4);     /* 轻玻璃（画面浮层、标签） */
  --color-surface-hover: rgba(255, 246, 232, 0.06);/* 悬停叠加 */
  --color-surface-active: rgba(224, 182, 122, 0.12);/* 选中叠加 */
  --color-line: rgba(255, 246, 232, 0.11);         /* 常规描边 */
  --color-line-strong: rgba(255, 246, 232, 0.2);   /* 强调描边 */
  --color-line-soft: rgba(255, 246, 232, 0.06);    /* 内部分隔 */
  --color-highlight: rgba(255, 250, 240, 0.08);    /* 顶部 1px 高光 */

  /* ---------- 文字 ---------- */
  --color-text: #f5efe4;
  --color-text-secondary: rgba(245, 239, 228, 0.74);
  --color-text-tertiary: rgba(245, 239, 228, 0.52);
  --color-text-muted: rgba(245, 239, 228, 0.36);   /* 仅装饰 / 禁用，不承载正文 */
  --color-text-inverse: #16130f;
  --color-text-on-brand: #1a150e;

  /* ---------- 语义色 ---------- */
  --color-success: #9cbf92;
  --color-success-soft: rgba(156, 191, 146, 0.16);
  --color-warning: #e0b070;
  --color-warning-soft: rgba(224, 176, 112, 0.16);
  --color-danger: #dd8f80;
  --color-danger-soft: rgba(221, 143, 128, 0.16);
  --color-info: #a7bdcd;
  --color-info-soft: rgba(167, 189, 205, 0.16);

  /* ---------- 色温语义色（滑块渐变 / 色温标签 / 场景联动） ---------- */
  --cct-warm: #ffb26b;               /* 暖光（≈2700–3000 K） */
  --cct-warm-soft: #ffd6a8;
  --cct-neutral: #ffe7c9;
  --cct-cool: #d5e3ff;               /* 冷白（≈6500 K） */
  /* 7 段色温刻度，与默认 2700–6500 K 范围对齐 */
  --cct-2700: #ffab5c;
  --cct-3000: #ffc07a;
  --cct-3500: #ffd2a0;
  --cct-4000: #ffe3c4;
  --cct-5000: #f6f1e6;
  --cct-5700: #e6eeff;
  --cct-6500: #c9ddff;
  --cct-current: var(--cct-3000);    /* UI 可用内联样式按当前色温覆盖 */
  --cct-current-soft: rgba(255, 192, 122, 0.24);

  /* ---------- 渐变 ---------- */
  --gradient-cct: linear-gradient(
    90deg,
    var(--cct-2700) 0%,
    var(--cct-3000) 15%,
    var(--cct-3500) 31%,
    var(--cct-4000) 47%,
    var(--cct-5000) 63%,
    var(--cct-5700) 81%,
    var(--cct-6500) 100%
  );
  --gradient-cct-soft: linear-gradient(
    90deg,
    rgba(255, 171, 92, 0.34) 0%,
    rgba(255, 227, 196, 0.26) 48%,
    rgba(201, 221, 255, 0.34) 100%
  );
  --gradient-panel: linear-gradient(
    158deg,
    rgba(255, 246, 232, 0.075) 0%,
    rgba(255, 246, 232, 0.022) 28%,
    rgba(255, 246, 232, 0) 62%
  );
  /* 玻璃面板的暗色衬底：叠在 --color-surface 之上，保证任何场景下正文对比度。
     与 --color-surface 复合后整体约 85% 不透明，仍是“透出光影的玻璃”而非实色块。 */
  --gradient-panel-scrim: linear-gradient(180deg, rgba(12, 10, 8, 0.6), rgba(12, 10, 8, 0.78));
  --gradient-sheen: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0));
  --gradient-brandline: linear-gradient(
    90deg,
    rgba(224, 182, 122, 0) 0%,
    rgba(224, 182, 122, 0.55) 50%,
    rgba(224, 182, 122, 0) 100%
  );
  --gradient-scrim-top: linear-gradient(180deg, rgba(8, 7, 5, 0.62), rgba(8, 7, 5, 0));
  --gradient-scrim-bottom: linear-gradient(0deg, rgba(8, 7, 5, 0.74), rgba(8, 7, 5, 0));

  /* ---------- 字体（全部系统字体，禁止网络字体） ---------- */
  --font-sans: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Hiragino Sans GB",
    "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", ui-sans-serif, system-ui,
    -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Songti SC", "STSong", "Source Han Serif SC", "Noto Serif SC",
    "Georgia", "SimSun", serif;
  --font-latin: "Optima", "Palatino Linotype", "Palatino", "Book Antiqua", "Georgia",
    "Times New Roman", serif;
  --font-mono: "SF Mono", "Cascadia Mono", "Consolas", "Menlo", "Roboto Mono",
    ui-monospace, "Courier New", monospace;

  /* 字重 */
  --weight-light: 300;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;

  /* 数字等宽：所有读数、单位、计时都用它，避免数值跳动 */
  --font-feature-tabular: "tnum" 1, "lnum" 1;
  --font-feature-display: "kern" 1, "liga" 1;
  --font-variant-numeric: tabular-nums lining-nums;

  /* ---------- 字号 ---------- */
  --text-2xs: 10px;                  /* 极小标签、刻度 */
  --text-xs: 11px;                   /* 说明脚注、单位 */
  --text-sm: 12px;                   /* 辅助说明、hint */
  --text-base: 13px;                 /* 正文（面板主体） */
  --text-md: 14px;                   /* 重点正文、滑块标签 */
  --text-lg: 16px;                   /* 区块标题 */
  --text-xl: 20px;                   /* 面板大标题 */
  --text-2xl: 26px;                  /* 参数卡大数字 */
  --text-3xl: 34px;                  /* 次级展示标题 */
  --text-display: clamp(38px, 4.4vw, 58px);  /* 首屏主标题 */
  --text-hero: clamp(44px, 5.6vw, 76px);     /* 场景内超大标题（备用） */
  --text-kpi: 30px;                  /* 参数卡主读数 */
  --text-num: 18px;                  /* 行内读数 */

  /* 行高 */
  --leading-none: 1;
  --leading-tight: 1.2;
  --leading-snug: 1.38;
  --leading-normal: 1.5;
  --leading-relaxed: 1.7;

  /* 字距 */
  --tracking-tight: -0.01em;
  --tracking-normal: 0;
  --tracking-wide: 0.04em;
  --tracking-wider: 0.12em;
  --tracking-widest: 0.32em;         /* LUMINA 字标、加载文案 */

  /* ---------- 间距（4px 基准；沿用原有 1–10 号位） ---------- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 56px;
  --space-10: 72px;
  --space-11: 88px;
  --space-12: 104px;

  /* 语义间距（组件内节奏） */
  --gap-inline-xs: var(--space-1);
  --gap-inline-sm: var(--space-2);
  --gap-inline-md: var(--space-3);
  --gap-stack-sm: var(--space-2);
  --gap-stack-md: var(--space-3);
  --gap-stack-lg: var(--space-5);
  --section-gap: var(--space-6);     /* 面板内区块间距 */
  --panel-pad-x: var(--space-5);
  --panel-pad-y: var(--space-5);
  --card-pad: var(--space-4);

  /* ---------- 控件尺寸 ---------- */
  --hit-target: 44px;                /* 最小可点击区域 */
  --control-height: 44px;
  --control-height-sm: 34px;
  --chip-height: 34px;
  --chip-pad-x: 14px;
  --tab-height: 48px;
  --icon-xs: 12px;
  --icon-sm: 14px;
  --icon-md: 18px;
  --icon-lg: 22px;
  --icon-xl: 28px;
  --switch-width: 44px;
  --switch-height: 24px;
  --track-height: 5px;               /* 滑块轨道 */
  --track-radius: var(--radius-pill);
  --thumb-size: 18px;                /* 滑块拖柄 */
  --thumb-size-hover: 20px;
  --tick-size: 3px;
  --divider-width: 1px;

  /* ---------- 圆角 ---------- */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-2xl: 34px;
  --radius-pill: 999px;
  --radius-control: var(--radius-md);   /* 按钮 / 滑块外壳 */
  --radius-card: var(--radius-lg);      /* 卡片 */
  --radius-sheet: var(--radius-xl);     /* 移动端底部面板（与 base.css 一致） */
  --radius-thumb: 50%;

  /* ---------- 阴影 ---------- */
  --shadow-panel: 0 28px 80px -24px rgba(0, 0, 0, 0.72),
    0 2px 0 0 rgba(255, 255, 255, 0.04) inset;
  --shadow-float: 0 18px 50px -18px rgba(0, 0, 0, 0.65);
  --shadow-card: 0 12px 30px -16px rgba(0, 0, 0, 0.58);
  --shadow-chip: 0 6px 18px -10px rgba(0, 0, 0, 0.6);
  --shadow-drawer: -32px 0 90px -34px rgba(0, 0, 0, 0.82);
  --shadow-sheet: 0 -24px 70px -28px rgba(0, 0, 0, 0.7);
  --shadow-inset-top: inset 0 1px 0 0 rgba(255, 250, 240, 0.08);
  --shadow-inset-hairline: inset 0 0 0 1px rgba(255, 250, 240, 0.05);
  --shadow-brand-glow: 0 0 0 1px var(--color-line-brand), 0 0 26px -6px var(--color-brand-glow);
  --shadow-thumb: 0 2px 6px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 250, 240, 0.22);
  --shadow-focus: 0 0 0 2px var(--color-bg), 0 0 0 4px rgba(224, 182, 122, 0.55);

  /* ---------- 模糊（玻璃） ---------- */
  --blur-glass: 22px;                /* 面板主模糊 */
  --blur-panel: 30px;                /* 抽屉 / 大浮层 */
  --blur-chip: 14px;                 /* 小标签、视角 chip */
  --saturate-glass: 1.15;
  --brightness-glass: 0.92;

  /* ---------- 动效 ---------- */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);      /* 主缓动：入场、切换 */
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);  /* 对称：展开、淡出 */
  --ease-soft: cubic-bezier(0.22, 0.61, 0.36, 1); /* 轻缓：悬停 */
  --ease-emphasis: cubic-bezier(0.2, 0, 0, 1);    /* 强调：抽屉滑入 */
  --dur-instant: 120ms;              /* 颜色 / 描边反馈 */
  --dur-fast: 160ms;                 /* 悬停、按下 */
  --dur-base: 260ms;                 /* 常规过渡 */
  --dur-slow: 480ms;                 /* 面板 / 预设切换（契约 300–500ms） */
  --dur-view: 640ms;                 /* 相机视角缓动 */
  --stagger: 55ms;                   /* 列表错峰 */
  --transition-fade: opacity var(--dur-base) var(--ease-out);
  --transition-standard: color var(--dur-fast) var(--ease-soft),
    background-color var(--dur-fast) var(--ease-soft),
    border-color var(--dur-fast) var(--ease-soft),
    box-shadow var(--dur-base) var(--ease-out),
    transform var(--dur-base) var(--ease-out);

  /* ---------- 层级 ---------- */
  --z-scene: 0;
  --z-overlay: 10;
  --z-panel: 20;
  --z-dock: 25;
  --z-topbar: 30;
  --z-plan: 40;
  --z-admin: 60;
  --z-toast: 80;
  --z-loader: 100;

  /* ---------- 布局 ---------- */
  --panel-width: 396px;
  --panel-top: calc(var(--topbar-height) + var(--space-2));
  --panel-min-height: 420px;
  --shell-gutter: 28px;
  --topbar-height: 84px;
  --topbar-gap: var(--space-6);
  --preset-dock-max: calc(100% - var(--panel-width) - var(--shell-gutter) * 3);
  --drawer-width: 640px;
  --drawer-inset: var(--space-6);
  --toast-offset: 36px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* 移动端（≤820px）骨架尺寸，必须与 base.css 中的数值保持一致 */
  --mobile-sheet-height: 46dvh;
  --mobile-stage-height: 54dvh;
  --mobile-sheet-handle: 36px;       /* 面板顶部拖拽条区域 */
  --toast-offset-mobile: calc(var(--mobile-sheet-height) + var(--space-4));

  /* ---------- 断点（文档 / JS 参考；媒体查询内直接写字面量） ---------- */
  --bp-xs: 480px;
  --bp-sm: 820px;
  --bp-md: 1024px;
  --bp-lg: 1180px;
  --bp-xl: 1440px;

  /* ---------- 焦点环 ---------- */
  --focus-ring-color: rgba(224, 182, 122, 0.62);
  --focus-ring-width: 2px;
}

/* ============================================================
 * 响应式覆盖
 * 断点：1440 / 1180 / 1024 / 820 / 480（与 --bp-* 保持一致）
 * ============================================================ */
@media (min-width: 1440px) {
  :root {
    --shell-gutter: 36px;
    --panel-width: 420px;
    --panel-pad-x: var(--space-6);
    --section-gap: var(--space-7);
  }
}

@media (max-width: 1180px) {
  :root {
    /* 注意：--panel-width（348）与 --shell-gutter（18）由 base.css 的 1180 断点定义，
       base.css 在本文件之后加载会覆盖同名变量，这里不再重复声明，避免双份真相。 */
    --topbar-height: 78px;
    --panel-pad-x: var(--space-4);
    --panel-pad-y: var(--space-4);
    --section-gap: var(--space-5);
  }
}

@media (max-width: 1024px) {
  :root {
    --shell-gutter: 18px;
    --topbar-gap: var(--space-4);
    --drawer-width: 560px;
    --text-display: clamp(30px, 4.2vw, 42px);
  }
}

/* 移动端：右侧面板改为底部面板；--panel-width 与 --shell-gutter 由 base.css 定义
   （100% / 14），此处不重复声明，尺寸以 base.css 为准 */
@media (max-width: 820px) {
  :root {
    --topbar-height: 60px;
    --topbar-gap: var(--space-2);
    --panel-pad-x: var(--space-4);
    --panel-pad-y: var(--space-4);
    --section-gap: var(--space-4);
    --chip-height: 32px;
    --chip-pad-x: 12px;
    --control-height: 48px;          /* 移动端加大触控高度 */
    --thumb-size: 22px;
    --thumb-size-hover: 22px;
    --track-height: 6px;
    --drawer-width: 100%;
    --drawer-inset: 0px;
    --text-display: clamp(30px, 8vw, 44px);
    --blur-glass: 18px;
    --blur-panel: 24px;
  }
}

@media (max-width: 480px) {
  :root {
    /* --shell-gutter 仍由 base.css 的 820 断点定为 14，此处不再覆盖 */
    --panel-pad-x: var(--space-3);
    --space-6: 20px;
    --space-7: 26px;
    --text-xl: 18px;
    --text-2xl: 24px;
  }
}

/* 矮屏（1366×768 一类笔记本）压缩垂直节奏，避免面板出现横向挤压 */
@media (max-height: 700px) and (min-width: 821px) {
  :root {
    --topbar-height: 68px;
    --panel-pad-y: var(--space-4);
    --section-gap: var(--space-4);
  }
}

/* 触控设备：拖柄与点击区再放大一档 */
@media (pointer: coarse) {
  :root {
    --hit-target: 48px;
    --thumb-size: 22px;
    --thumb-size-hover: 22px;
    --track-height: 6px;
  }
}

/* ============================================================
 * 能力降级
 * ============================================================ */

/* 不支持 backdrop-filter 时，玻璃必须变成可靠的不透明底，保证文字可读 */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root {
    --color-surface: rgba(18, 15, 12, 0.94);
    --color-surface-strong: rgba(24, 20, 16, 0.97);
    --color-surface-soft: rgba(16, 14, 11, 0.86);
    --blur-glass: 0px;
    --blur-panel: 0px;
    --blur-chip: 0px;
  }
}

/* 降低透明度（部分系统辅助功能）：去掉模糊，改用实底 */
@media (prefers-reduced-transparency: reduce) {
  :root {
    --color-surface: rgba(18, 15, 12, 0.94);
    --color-surface-strong: rgba(24, 20, 16, 0.97);
    --color-surface-soft: rgba(16, 14, 11, 0.9);
    --blur-glass: 0px;
    --blur-panel: 0px;
    --blur-chip: 0px;
  }
}

/* 高对比：加强描边与次级文字，弱化装饰 */
@media (prefers-contrast: more) {
  :root {
    --color-line: rgba(255, 246, 232, 0.24);
    --color-line-strong: rgba(255, 246, 232, 0.4);
    --color-text-secondary: rgba(245, 239, 228, 0.86);
    --color-text-tertiary: rgba(245, 239, 228, 0.68);
    --color-brand: #f0c98c;
    --focus-ring-width: 3px;
  }
}

/* 强制颜色模式（Windows 高对比主题）：交给系统色板 */
@media (forced-colors: active) {
  :root {
    --color-bg: Canvas;
    --color-bg-elevated: Canvas;
    --color-text: CanvasText;
    --color-text-secondary: CanvasText;
    --color-text-tertiary: CanvasText;
    --color-line: CanvasText;
    --color-line-strong: CanvasText;
    --color-brand: Highlight;
    --color-brand-strong: Highlight;
    --color-danger: LinkText;
    --focus-ring-color: Highlight;
  }
}

/* ============================================================
 * 减少动效（系统级）
 * 所有时长压到 1ms，缓动改为线性；JS 侧动画需自行读取
 * matchMedia('(prefers-reduced-motion: reduce)') 后跳过缓动。
 * ============================================================ */
@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-instant: 1ms;
    --dur-fast: 1ms;
    --dur-base: 1ms;
    --dur-slow: 1ms;
    --dur-view: 1ms;
    --stagger: 0ms;
    --ease-out: linear;
    --ease-in-out: linear;
    --ease-soft: linear;
    --ease-emphasis: linear;
  }
}
