/* ============================================================
 * aiprd Design System — Design Tokens
 * ------------------------------------------------------------
 * 项目: aiprd (AI PRD Generator) · aiprd.cc
 * 版本: v1.0
 * 日期: 2026-04-20
 *
 * 设计原则 (Design Principles)
 *  1. 克制 (Restraint)        — 不用过饱和色，不用大渐变
 *  2. 工具感 (Craft)           — 像 Linear/Vercel/Anthropic 那样的工程美学
 *  3. 温暖信任 (Warmth)        — 中性灰偏暖一档，辅色用 amber
 *  4. 文档友好 (Document-first) — 长文排版优先，对比度不刺眼
 *
 * 色彩体系 (Color Philosophy)
 *  - 全部使用 oklch() 定义，色彩在 HDR/sRGB 下均一致
 *  - 主色 "Signal Blue": oklch 70-ish 0.14 220 (偏青蓝，不走烂大街 #3B82F6)
 *  - 辅色 "Paper Amber": oklch 76 0.13 75 (羊皮纸/标注黄)
 *  - 中性灰偏暖 1 档 (chroma 0.005，hue 250)，避免纯冷灰
 * ============================================================ */


/* ==========================================================
 * 1. COLORS — oklch 色阶
 * ========================================================== */

:root {
  /* ── Brand · Signal Blue ─────────────────────────────────
   * aiprd 主色：偏青的工程蓝。不是默认 Tailwind Blue-500，
   * 避开所有蓝紫 SaaS 品牌。在暗色背景下不刺眼，在亮色背景
   * 下仍保持清晰识别度。
   * ────────────────────────────────────────────────────── */
  --brand-50:  oklch(97.5% 0.015 220);
  --brand-100: oklch(94%   0.030 220);
  --brand-200: oklch(88%   0.055 220);
  --brand-300: oklch(80%   0.085 220);
  --brand-400: oklch(72%   0.110 220);
  --brand-500: oklch(64%   0.135 220);  /* ★ primary */
  --brand-600: oklch(56%   0.140 220);
  --brand-700: oklch(48%   0.125 220);
  --brand-800: oklch(40%   0.100 220);
  --brand-900: oklch(32%   0.075 220);
  --brand-950: oklch(22%   0.055 220);

  /* ── Accent · Paper Amber ────────────────────────────────
   * 辅色：文档标注黄。用于 badge、highlight、status dot。
   * 温暖、怀旧、像手账笔记里的荧光笔。与主色冷暖平衡。
   * ────────────────────────────────────────────────────── */
  --accent-50:  oklch(97% 0.025 75);
  --accent-100: oklch(94% 0.050 75);
  --accent-200: oklch(88% 0.090 75);
  --accent-300: oklch(82% 0.120 75);
  --accent-400: oklch(78% 0.140 75);
  --accent-500: oklch(74% 0.145 75);  /* ★ accent */
  --accent-600: oklch(66% 0.140 75);
  --accent-700: oklch(56% 0.120 75);
  --accent-800: oklch(46% 0.095 75);
  --accent-900: oklch(36% 0.070 75);

  /* ── Semantic · 状态色 ────────────────────────────────────
   * 四种状态色饱和度对齐，避免"success 很亮 / warning 很闷"
   * 的失衡。所有 status 在 dark/light 下都有足够对比度。
   * ────────────────────────────────────────────────────── */
  --success-500: oklch(68% 0.155 155);  /* 草绿 — PRD 生成成功 */
  --success-100: oklch(94% 0.050 155);
  --success-900: oklch(34% 0.085 155);

  --warning-500: oklch(76% 0.155 68);   /* 琥珀 — 警告 */
  --warning-100: oklch(94% 0.055 68);
  --warning-900: oklch(38% 0.095 68);

  --error-500:   oklch(62% 0.200 25);   /* 偏珊瑚红 — 不是血红 */
  --error-100:   oklch(94% 0.045 25);
  --error-900:   oklch(34% 0.110 25);

  --info-500:    oklch(68% 0.130 240);  /* 信息蓝 — 与 brand 分离 */
  --info-100:    oklch(94% 0.045 240);
  --info-900:    oklch(34% 0.095 240);

  /* ── Neutral · 10 级灰 (暖偏 +1) ──────────────────────────
   * 为什么偏暖：纯 hue=0 的灰在文档场景显得冷硬、医疗。
   * 我们用 hue=250、chroma=0.005 让灰色带一点点蓝紫调，
   * 整体看起来像"优质打印纸"的灰。
   * ────────────────────────────────────────────────────── */
  --gray-0:   oklch(100% 0     0);        /* 纯白 */
  --gray-50:  oklch(98.5% 0.003 250);
  --gray-100: oklch(96%   0.005 250);
  --gray-200: oklch(92%   0.007 250);
  --gray-300: oklch(86%   0.009 250);
  --gray-400: oklch(74%   0.011 250);
  --gray-500: oklch(60%   0.013 250);
  --gray-600: oklch(48%   0.013 250);
  --gray-700: oklch(38%   0.012 250);
  --gray-800: oklch(28%   0.010 250);
  --gray-900: oklch(20%   0.008 250);
  --gray-950: oklch(14%   0.008 250);
  --gray-1000: oklch(8%   0.008 250);     /* 近黑但不纯黑 */
}


/* ==========================================================
 * 2. THEME — Light (default) & Dark
 * ----------------------------------------------------------
 * 语义 token 映射：组件应该引用 --surface/--text/--border
 * 这类语义变量，而不是直接引用 --gray-800。
 * ========================================================== */

:root,
[data-theme="light"] {
  color-scheme: light;

  /* Surface — 背景层级 */
  --bg:           var(--gray-50);       /* 页面背景 */
  --surface:      var(--gray-0);        /* 卡片背景 */
  --surface-2:    var(--gray-100);      /* 次级区块 (code block / nested) */
  --surface-3:    var(--gray-200);      /* 更深区块 (disabled / hover fill) */
  --overlay:      oklch(20% 0.008 250 / 0.55);  /* modal 遮罩 */

  /* Border — 分隔线 */
  --border:       var(--gray-200);      /* 默认边框 */
  --border-strong: var(--gray-300);     /* 强调边框 */
  --border-subtle: var(--gray-100);     /* 微弱分隔 */

  /* Text */
  --text:         var(--gray-950);      /* 标题、主要内容 */
  --text-2:       var(--gray-700);      /* 正文 */
  --text-3:       var(--gray-600);      /* 辅助说明 */
  --muted:        var(--gray-500);      /* 占位、元信息 */
  --text-inverse: var(--gray-0);        /* 深色按钮上的文字 */

  /* Brand 映射 — 在亮色下用 600-700 档以保证对比度 */
  --primary:         var(--brand-600);
  --primary-hover:   var(--brand-700);
  --primary-active:  var(--brand-800);
  --primary-subtle:  var(--brand-50);   /* 浅底色（ghost hover、selected bg） */
  --primary-fg:      var(--gray-0);     /* 主色按钮上的文字 */

  --accent:          var(--accent-700);
  --accent-subtle:   var(--accent-50);

  /* Status — 亮色主题 */
  --success:         var(--success-500);
  --success-bg:      var(--success-100);
  --warning:         var(--warning-500);
  --warning-bg:      var(--warning-100);
  --danger:          var(--error-500);
  --danger-bg:       var(--error-100);
  --info:            var(--info-500);
  --info-bg:         var(--info-100);

  /* Focus Ring — 可访问性高亮 */
  --ring: oklch(64% 0.135 220 / 0.35);

  /* Shadow base color */
  --shadow-color: 220 15% 20%;
  --shadow-strength: 0.06;
}

[data-theme="dark"] {
  color-scheme: dark;

  /* Surface — 暗色场景下层级靠 "抬高色阶" 实现 (Material elevation) */
  --bg:           var(--gray-1000);     /* 最底层 (#0a0b10 附近) */
  --surface:      var(--gray-950);      /* 卡片 */
  --surface-2:    var(--gray-900);      /* 次级 */
  --surface-3:    var(--gray-800);      /* 更亮 */
  --overlay:      oklch(6% 0.008 250 / 0.7);

  --border:       var(--gray-800);
  --border-strong: var(--gray-700);
  --border-subtle: var(--gray-900);

  --text:         var(--gray-50);
  --text-2:       var(--gray-200);
  --text-3:       var(--gray-400);
  --muted:        var(--gray-500);
  --text-inverse: var(--gray-950);

  /* Brand 在暗色下用 400-500 档，饱和度看起来刚好不刺眼 */
  --primary:         var(--brand-400);
  --primary-hover:   var(--brand-300);
  --primary-active:  var(--brand-500);
  --primary-subtle:  oklch(40% 0.100 220 / 0.18);
  --primary-fg:      var(--gray-1000);

  --accent:          var(--accent-400);
  --accent-subtle:   oklch(46% 0.095 75 / 0.15);

  --success:         oklch(72% 0.155 155);
  --success-bg:      oklch(34% 0.085 155 / 0.2);
  --warning:         oklch(80% 0.155 68);
  --warning-bg:      oklch(38% 0.095 68 / 0.2);
  --danger:          oklch(70% 0.180 25);
  --danger-bg:       oklch(34% 0.110 25 / 0.22);
  --info:            oklch(72% 0.130 240);
  --info-bg:         oklch(34% 0.095 240 / 0.2);

  --ring: oklch(72% 0.110 220 / 0.45);

  --shadow-color: 220 40% 3%;
  --shadow-strength: 0.5;
}

/* 系统自动跟随 (当用户未显式选择时) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg:           var(--gray-1000);
    --surface:      var(--gray-950);
    --surface-2:    var(--gray-900);
    --surface-3:    var(--gray-800);
    --overlay:      oklch(6% 0.008 250 / 0.7);
    --border:       var(--gray-800);
    --border-strong: var(--gray-700);
    --border-subtle: var(--gray-900);
    --text:         var(--gray-50);
    --text-2:       var(--gray-200);
    --text-3:       var(--gray-400);
    --muted:        var(--gray-500);
    --text-inverse: var(--gray-950);
    --primary:         var(--brand-400);
    --primary-hover:   var(--brand-300);
    --primary-active:  var(--brand-500);
    --primary-subtle:  oklch(40% 0.100 220 / 0.18);
    --primary-fg:      var(--gray-1000);
    --accent:          var(--accent-400);
    --accent-subtle:   oklch(46% 0.095 75 / 0.15);
    --ring: oklch(72% 0.110 220 / 0.45);
    --shadow-color: 220 40% 3%;
    --shadow-strength: 0.5;
  }
}


/* ==========================================================
 * 3. TYPOGRAPHY
 * ----------------------------------------------------------
 * 字体策略：
 *  - Sans: Geist (Vercel 出品) — 非 Inter，辨识度高，几何现代
 *    fallback: system-ui — 次选 Sans 系统字体
 *  - Mono: Geist Mono / JetBrains Mono — code 和元信息
 *  - Serif: Newsreader — 用于长文/引用/"文档感"点缀 (可选)
 *  - Display: Instrument Serif / 保留 Syne 用于少量大标题
 *  - CJK:  Noto Sans SC / PingFang SC — 中文正文
 * ========================================================== */

:root {
  /* Font families */
  --font-sans:
    "Geist", "Inter var", ui-sans-serif, system-ui,
    "PingFang SC", "Noto Sans SC", "Microsoft YaHei",
    -apple-system, BlinkMacSystemFont, sans-serif;

  --font-mono:
    "Geist Mono", "JetBrains Mono", ui-monospace,
    SFMono-Regular, Menlo, Consolas, monospace;

  --font-serif:
    "Newsreader", "Source Serif 4", ui-serif, Georgia,
    "Songti SC", "Noto Serif SC", serif;

  --font-display:
    "Instrument Serif", "Newsreader", ui-serif, Georgia,
    "Noto Serif SC", serif;

  /* Font sizes — modular scale (1.125 ratio at small end, 1.25 at large) */
  --text-2xs:  0.6875rem;   /* 11px — 元信息、label */
  --text-xs:   0.75rem;     /* 12px — caption */
  --text-sm:   0.875rem;    /* 14px — 次要 UI */
  --text-base: 1rem;        /* 16px — 正文基准 */
  --text-md:   1.0625rem;   /* 17px — 舒适阅读 */
  --text-lg:   1.25rem;     /* 20px — 小标题 */
  --text-xl:   1.5rem;      /* 24px */
  --text-2xl:  1.875rem;    /* 30px */
  --text-3xl:  2.25rem;     /* 36px */
  --text-4xl:  3rem;        /* 48px — hero 小屏 */
  --text-5xl:  clamp(2.5rem, 5.5vw, 4.5rem);  /* hero 响应式 */

  /* Line heights */
  --leading-none:    1;
  --leading-tight:   1.2;   /* display 标题 */
  --leading-snug:    1.35;  /* 卡片小标题 */
  --leading-normal:  1.55;  /* UI 正文 */
  --leading-relaxed: 1.75;  /* 长文阅读 */
  --leading-loose:   2;

  /* Font weights */
  --weight-regular: 400;
  --weight-medium:  500;
  --weight-semibold: 600;
  --weight-bold:    700;
  --weight-black:   800;

  /* Letter spacing — 字间距 */
  --tracking-tight:  -0.02em;   /* 大标题 */
  --tracking-snug:   -0.01em;
  --tracking-normal: 0;
  --tracking-wide:   0.02em;    /* 正文中文 */
  --tracking-wider:  0.06em;    /* 等宽 label / 小标签 */
  --tracking-widest: 0.12em;    /* CAPS label */
}


/* ==========================================================
 * 4. SPACING — 4px base grid
 * ----------------------------------------------------------
 * 规则：4px 基线，小尺寸 4 递增，大尺寸 8 递增。
 * 命名按 rem 尺寸 (0.25 / 0.5 / 1 ...) 以便记忆。
 * ========================================================== */

:root {
  --space-0:    0;
  --space-px:   1px;
  --space-0-5:  0.125rem;  /* 2px */
  --space-1:    0.25rem;   /* 4px */
  --space-1-5:  0.375rem;  /* 6px */
  --space-2:    0.5rem;    /* 8px */
  --space-2-5:  0.625rem;  /* 10px */
  --space-3:    0.75rem;   /* 12px */
  --space-4:    1rem;      /* 16px */
  --space-5:    1.25rem;   /* 20px */
  --space-6:    1.5rem;    /* 24px */
  --space-8:    2rem;      /* 32px */
  --space-10:   2.5rem;    /* 40px */
  --space-12:   3rem;      /* 48px */
  --space-16:   4rem;      /* 64px */
  --space-20:   5rem;      /* 80px */
  --space-24:   6rem;      /* 96px */
  --space-32:   8rem;      /* 128px */

  /* Container — 内容区最大宽度 */
  --container-sm: 640px;
  --container-md: 768px;
  --container-lg: 1024px;
  --container-xl: 1200px;    /* aiprd 默认 */
  --container-2xl: 1440px;
  --container-prose: 72ch;   /* 正文阅读区 (PRD 展示) */
}


/* ==========================================================
 * 5. RADIUS — 圆角
 * ----------------------------------------------------------
 * 克制的圆角：不搞 16-24px 大圆角。主要组件 6-10px。
 * ========================================================== */

:root {
  --radius-none: 0;
  --radius-xs:   2px;        /* badge, tag */
  --radius-sm:   4px;        /* input, small button */
  --radius-md:   6px;        /* default button, card inner */
  --radius-lg:   10px;       /* card */
  --radius-xl:   14px;       /* modal, hero panel */
  --radius-2xl:  20px;       /* 大面板 */
  --radius-full: 9999px;     /* pill, avatar */
}


/* ==========================================================
 * 6. SHADOW — 双层式阴影
 * ----------------------------------------------------------
 * 每级阴影 = 细边描边(模拟环境光遮蔽) + 柔和投影
 * 暗色下阴影不可见，靠 border 体现层级
 * ========================================================== */

:root {
  /* 使用 hsl() + CSS 变量避免 rgba 硬编码 */
  --shadow-xs:
    0 1px 2px 0 hsl(var(--shadow-color) / calc(var(--shadow-strength) * 1));

  --shadow-sm:
    0 1px 2px 0  hsl(var(--shadow-color) / calc(var(--shadow-strength) * 0.8)),
    0 1px 1px -1px hsl(var(--shadow-color) / calc(var(--shadow-strength) * 1.2));

  --shadow-md:
    0 2px 4px 0  hsl(var(--shadow-color) / calc(var(--shadow-strength) * 0.7)),
    0 4px 8px -2px hsl(var(--shadow-color) / calc(var(--shadow-strength) * 1.1));

  --shadow-lg:
    0 4px 8px 0  hsl(var(--shadow-color) / calc(var(--shadow-strength) * 0.6)),
    0 12px 24px -4px hsl(var(--shadow-color) / calc(var(--shadow-strength) * 1.2));

  --shadow-xl:
    0 8px 16px 0  hsl(var(--shadow-color) / calc(var(--shadow-strength) * 0.5)),
    0 24px 48px -8px hsl(var(--shadow-color) / calc(var(--shadow-strength) * 1.3));

  /* Focus ring — 单独一层 */
  --shadow-ring: 0 0 0 3px var(--ring);

  /* Inset — 输入框按下的凹陷感 */
  --shadow-inset: inset 0 1px 2px 0 hsl(var(--shadow-color) / calc(var(--shadow-strength) * 0.6));
}


/* ==========================================================
 * 7. MOTION — 动效
 * ----------------------------------------------------------
 * 默认走"sharp and fast"：UI 反馈 120-200ms。
 * 大位移才用 300ms+。所有曲线避免默认 ease (太"塑料")。
 * ========================================================== */

:root {
  --duration-instant: 80ms;
  --duration-fast:    140ms;   /* 按钮 hover、颜色过渡 */
  --duration-normal:  220ms;   /* 卡片 transform */
  --duration-slow:    360ms;   /* modal 出入、抽屉 */
  --duration-slower:  520ms;   /* 页面切换 */

  /* Easing curves — 偷师 Material 和 Linear */
  --ease-linear:     linear;
  --ease-in:         cubic-bezier(0.4, 0.0, 1, 1);
  --ease-out:        cubic-bezier(0.0, 0.0, 0.2, 1);  /* 默认 UI 出现 */
  --ease-in-out:     cubic-bezier(0.4, 0.0, 0.2, 1);  /* 默认 UI 切换 */
  --ease-spring:     cubic-bezier(0.34, 1.56, 0.64, 1); /* 轻微回弹 */
  --ease-emphasize:  cubic-bezier(0.2, 0.0, 0.0, 1);  /* 强调 — 先慢后快 */

  /* 常用组合 */
  --transition-base:    all var(--duration-fast) var(--ease-out);
  --transition-colors:  color var(--duration-fast) var(--ease-out),
                        background-color var(--duration-fast) var(--ease-out),
                        border-color var(--duration-fast) var(--ease-out);
  --transition-transform: transform var(--duration-normal) var(--ease-out);
}

/* 尊重用户的 reduce-motion 偏好 */
@media (prefers-reduced-motion: reduce) {
  :root {
    --duration-instant: 0ms;
    --duration-fast:    0ms;
    --duration-normal:  0ms;
    --duration-slow:    0ms;
    --duration-slower:  0ms;
  }
}


/* ==========================================================
 * 8. Z-INDEX — 层级规则
 * ----------------------------------------------------------
 * 留出 10 的梯度以便中间插入，避免 999999 魔法数字。
 * ========================================================== */

:root {
  --z-hide:       -1;
  --z-base:        0;
  --z-raised:      10;     /* sticky content */
  --z-dropdown:    100;
  --z-sticky:      200;    /* sticky nav, tabs */
  --z-fixed:       300;    /* fixed panel */
  --z-overlay:     400;    /* backdrop */
  --z-modal:       500;
  --z-popover:     600;    /* 比 modal 高的浮层 */
  --z-toast:       700;
  --z-tooltip:     800;
  --z-max:         9999;   /* only for dev tools / debug overlays */
}


/* ==========================================================
 * 9. FOUNDATIONS — 基础样式 (可选 reset)
 * ---------------------------------------------------------- */

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-family: var(--font-sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  letter-spacing: var(--tracking-wide);
  font-feature-settings: "cv11", "ss03", "calt", "ss01";  /* Geist 字形开关 */
}

/* 选区颜色 */
::selection {
  background: var(--primary-subtle);
  color: var(--text);
}

/* Focus ring — 全局键盘可达性 */
:focus-visible {
  outline: none;
  box-shadow: var(--shadow-ring);
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) {
  outline: none;
}

/* 滚动条（仅 webkit） */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); }


/* ==========================================================
 * 10. COMPONENTS — 核心组件
 * ---------------------------------------------------------- */

/* ── Button ──────────────────────────────────────────────
 * 变体: primary / secondary / ghost / danger
 * 尺寸: sm (28px) / md (36px) / lg (44px)
 * 状态: default / hover / active / disabled / loading
 * ────────────────────────────────────────────────────── */

.btn {
  --btn-bg: transparent;
  --btn-fg: var(--text);
  --btn-border: transparent;
  --btn-bg-hover: var(--surface-2);
  --btn-bg-active: var(--surface-3);
  --btn-ring: var(--ring);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);

  height: 36px;
  padding: 0 var(--space-4);

  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1;
  white-space: nowrap;
  letter-spacing: var(--tracking-snug);

  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-md);

  cursor: pointer;
  user-select: none;
  text-decoration: none;

  transition: var(--transition-base);
  transition-property: background-color, border-color, color, box-shadow, transform;
}

.btn:hover:not(:disabled):not([aria-busy="true"]) {
  background: var(--btn-bg-hover);
}
.btn:active:not(:disabled):not([aria-busy="true"]) {
  background: var(--btn-bg-active);
  transform: translateY(0.5px);
}
.btn:focus-visible {
  box-shadow: var(--shadow-ring);
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Sizes */
.btn--sm { height: 28px; padding: 0 var(--space-3); font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn--md { height: 36px; padding: 0 var(--space-4); font-size: var(--text-sm); }
.btn--lg { height: 44px; padding: 0 var(--space-5); font-size: var(--text-md); border-radius: var(--radius-md); }

/* Variants */
.btn--primary {
  --btn-bg:        var(--primary);
  --btn-fg:        var(--primary-fg);
  --btn-border:    var(--primary);
  --btn-bg-hover:  var(--primary-hover);
  --btn-bg-active: var(--primary-active);
  box-shadow: var(--shadow-xs);
}
.btn--primary:hover:not(:disabled):not([aria-busy="true"]) {
  border-color: var(--primary-hover);
}

.btn--secondary {
  --btn-bg:        var(--surface);
  --btn-fg:        var(--text);
  --btn-border:    var(--border-strong);
  --btn-bg-hover:  var(--surface-2);
  --btn-bg-active: var(--surface-3);
  box-shadow: var(--shadow-xs);
}

.btn--ghost {
  --btn-bg:        transparent;
  --btn-fg:        var(--text-2);
  --btn-border:    transparent;
  --btn-bg-hover:  var(--surface-2);
  --btn-bg-active: var(--surface-3);
}
.btn--ghost:hover { color: var(--text); }

.btn--danger {
  --btn-bg:        var(--danger);
  --btn-fg:        var(--gray-0);
  --btn-border:    var(--danger);
  --btn-bg-hover:  oklch(56% 0.210 25);
  --btn-bg-active: oklch(50% 0.210 25);
}

/* Loading — [aria-busy="true"] */
.btn[aria-busy="true"] {
  cursor: wait;
  color: transparent !important;
  position: relative;
}
.btn[aria-busy="true"]::after {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--btn-fg);
  animation: btn-spin 0.7s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }


/* ── Input / Textarea ────────────────────────────────────
 * 状态: default / focus / error / disabled / readonly
 * ────────────────────────────────────────────────────── */

.input,
.textarea {
  display: block;
  width: 100%;
  padding: 0 var(--space-3);
  height: 36px;

  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--text);

  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-inset);

  transition: var(--transition-colors), box-shadow var(--duration-fast) var(--ease-out);
}
.input::placeholder,
.textarea::placeholder {
  color: var(--muted);
}
.input:hover:not(:disabled):not([readonly]),
.textarea:hover:not(:disabled):not([readonly]) {
  border-color: var(--muted);
}
.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-inset), var(--shadow-ring);
}
.input:disabled,
.textarea:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
}
.input[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger);
}
.input[aria-invalid="true"]:focus,
.textarea[aria-invalid="true"]:focus {
  box-shadow: var(--shadow-inset), 0 0 0 3px oklch(62% 0.200 25 / 0.28);
}

.textarea {
  height: auto;
  min-height: 96px;
  padding: var(--space-2-5) var(--space-3);
  line-height: var(--leading-relaxed);
  resize: vertical;
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1-5);
}
.field__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-2);
  letter-spacing: var(--tracking-wide);
}
.field__hint {
  font-size: var(--text-xs);
  color: var(--muted);
}
.field__error {
  font-size: var(--text-xs);
  color: var(--danger);
  font-family: var(--font-mono);
  letter-spacing: var(--tracking-wider);
}


/* ── Tabs ────────────────────────────────────────────────
 * 三种变体: .tabs--line (默认) / .tabs--pill / .tabs--vertical
 * ────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: var(--space-1);
}

.tabs__item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wider);
  color: var(--muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: var(--transition-colors);
  position: relative;
}
.tabs__item:hover { color: var(--text-2); }

/* Line (底部下划线) */
.tabs--line {
  border-bottom: 1px solid var(--border);
}
.tabs--line .tabs__item {
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding-bottom: calc(var(--space-2) + 2px);
}
.tabs--line .tabs__item[aria-selected="true"] {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Pill (胶囊) */
.tabs--pill {
  padding: var(--space-1);
  background: var(--surface-2);
  border-radius: var(--radius-md);
  gap: 0;
}
.tabs--pill .tabs__item {
  border-radius: var(--radius-sm);
  padding: var(--space-1-5) var(--space-3);
}
.tabs--pill .tabs__item[aria-selected="true"] {
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

/* Vertical */
.tabs--vertical {
  flex-direction: column;
  gap: var(--space-0-5);
  border-right: 1px solid var(--border);
  padding-right: var(--space-2);
}
.tabs--vertical .tabs__item {
  justify-content: flex-start;
  width: 100%;
  border-right: 2px solid transparent;
  margin-right: -2px;
}
.tabs--vertical .tabs__item[aria-selected="true"] {
  color: var(--primary);
  background: var(--primary-subtle);
  border-right-color: var(--primary);
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}


/* ── Card ────────────────────────────────────────────────
 * default / interactive / elevated
 * ────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: var(--transition-base);
  transition-property: border-color, box-shadow, transform, background-color;
}
.card--interactive {
  cursor: pointer;
}
.card--interactive:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.card--interactive:active {
  transform: translateY(-1px);
}
.card--elevated {
  box-shadow: var(--shadow-lg);
  border-color: transparent;
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.card__title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-snug);
  color: var(--text);
}
.card__meta {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--muted);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
}
.card__body {
  color: var(--text-2);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
}


/* ── Badge ───────────────────────────────────────────────
 * 变体: neutral / primary / success / warning / danger / info
 * 带 dot 样式 — .badge--dot
 * ────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1-5);

  height: 22px;
  padding: 0 var(--space-2);

  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  white-space: nowrap;

  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
}

.badge--primary { background: var(--primary-subtle); color: var(--primary); border-color: transparent; }
.badge--success { background: var(--success-bg); color: var(--success); border-color: transparent; }
.badge--warning { background: var(--warning-bg); color: var(--warning); border-color: transparent; }
.badge--danger  { background: var(--danger-bg);  color: var(--danger);  border-color: transparent; }
.badge--info    { background: var(--info-bg);    color: var(--info);    border-color: transparent; }

.badge--dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px currentColor;
  opacity: 1;
  animation: badge-pulse 2s var(--ease-in-out) infinite;
}
@keyframes badge-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}


/* ── Modal ───────────────────────────────────────────────
 * 标准 <dialog> 元素 + 自定义皮肤
 * ────────────────────────────────────────────────────── */

.modal {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xl);
  max-width: 520px;
  width: calc(100% - var(--space-8));
}
.modal::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(4px);
}
.modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6) var(--space-3);
}
.modal__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-snug);
}
.modal__body {
  padding: 0 var(--space-6) var(--space-5);
  font-size: var(--text-sm);
  color: var(--text-2);
  line-height: var(--leading-relaxed);
}
.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}


/* ── Toast ───────────────────────────────────────────────
 * 容器: .toast-region (aria-live polite)
 * ────────────────────────────────────────────────────── */

.toast-region {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: var(--z-toast);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-width: 280px;
  max-width: 420px;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  animation: toast-in var(--duration-slow) var(--ease-spring);
}
.toast--success { border-left-color: var(--success); }
.toast--warning { border-left-color: var(--warning); }
.toast--danger  { border-left-color: var(--danger); }
.toast--info    { border-left-color: var(--info); }

.toast__icon {
  flex-shrink: 0;
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary);
}
.toast__body { flex: 1; }
.toast__title { font-weight: var(--weight-semibold); margin-bottom: 2px; }
.toast__desc  { color: var(--text-3); font-size: var(--text-xs); line-height: var(--leading-normal); }

@keyframes toast-in {
  from { transform: translateX(24px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}


/* ── Utility helpers (optional) ──────────────────────── */

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 var(--space-1-5);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
}
