/* ==================================================================
   FormBridge · 设计令牌
   浅色 / 深色 / 跟随系统 三态主题，切换通过 data-theme 属性驱动，
   所有颜色走 CSS 变量，切换成本 = 一次样式重算，零闪烁。
   ================================================================== */

:root {
  /* 品牌色 —— 靛蓝主色 + 青绿辅色，克制而不廉价 */
  --brand-50:  #eef2ff;
  --brand-100: #e0e7ff;
  --brand-200: #c7d2fe;
  --brand-400: #818cf8;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;

  --accent-400: #2dd4bf;
  --accent-500: #14b8a6;
  --accent-600: #0d9488;

  --ok-500: #10b981;
  --ok-600: #059669;
  --warn-500: #f59e0b;
  --warn-600: #d97706;
  --err-500: #ef4444;
  --err-600: #dc2626;
  --info-500: #3b82f6;

  /* 字体阶梯 */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 15px;
  --fs-md: 17px;
  --fs-lg: 20px;
  --fs-xl: 26px;
  --fs-2xl: 34px;

  /* 间距节奏（8pt 网格） */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --r-full: 999px;

  /* 高级感的核心：缓动曲线。默认 ease 太"塑料"了 */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --t-fast: 140ms var(--ease-out);
  --t-base: 260ms var(--ease-out);
  --t-slow: 420ms var(--ease-out);

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
               'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
}

/* ---------- 浅色 ---------- */
:root, [data-theme='light'] {
  --bg-base: #f6f7fb;
  --bg-surface: #ffffff;
  --bg-raised: #ffffff;
  --bg-sunken: #f1f3f9;
  --bg-hover: rgba(15, 23, 42, 0.04);
  --bg-active: rgba(99, 102, 241, 0.08);

  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(15, 23, 42, 0.08);

  --text-1: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --text-inv: #ffffff;

  --line-1: rgba(15, 23, 42, 0.09);
  --line-2: rgba(15, 23, 42, 0.16);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.07), 0 2px 4px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.10), 0 4px 8px rgba(15, 23, 42, 0.04);
  --shadow-brand: 0 8px 24px rgba(79, 70, 229, 0.22);

  --tint-ok: rgba(16, 185, 129, 0.10);
  --tint-warn: rgba(245, 158, 11, 0.12);
  --tint-err: rgba(239, 68, 68, 0.10);
  --tint-info: rgba(59, 130, 246, 0.10);
  --tint-brand: rgba(99, 102, 241, 0.10);
}

/* ---------- 深色 ---------- */
[data-theme='dark'] {
  --bg-base: #0a0e1a;
  --bg-surface: #111827;
  --bg-raised: #171f2f;
  --bg-sunken: #070b14;
  --bg-hover: rgba(255, 255, 255, 0.05);
  --bg-active: rgba(129, 140, 248, 0.14);

  --glass-bg: rgba(23, 31, 47, 0.72);
  --glass-border: rgba(255, 255, 255, 0.08);

  --text-1: #f1f5f9;
  --text-2: #a3b0c2;
  --text-3: #64748b;
  --text-inv: #0f172a;

  --line-1: rgba(255, 255, 255, 0.09);
  --line-2: rgba(255, 255, 255, 0.16);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
  --shadow-brand: 0 8px 28px rgba(79, 70, 229, 0.35);

  --brand-500: #818cf8;
  --brand-600: #6366f1;

  --tint-ok: rgba(16, 185, 129, 0.16);
  --tint-warn: rgba(245, 158, 11, 0.16);
  --tint-err: rgba(239, 68, 68, 0.16);
  --tint-info: rgba(59, 130, 246, 0.16);
  --tint-brand: rgba(129, 140, 248, 0.16);
}

/* ---------- 基础重置 ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.6;
  color: var(--text-1);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* 主题切换时颜色平滑过渡，不刺眼 */
  transition: background-color var(--t-base), color var(--t-base);
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--brand-600); text-decoration: none; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: var(--r-full);
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.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;
}

/* ---------- 通用组件 ---------- */

.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--line-1);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

/* 磁吸反馈：hover 微微抬起，active 快速回弹，手感扎实 */
.magnetic {
  transition: transform var(--t-base), box-shadow var(--t-base), background-color var(--t-fast);
  will-change: transform;
}
.magnetic:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.magnetic:active { transform: translateY(0) scale(0.985); transition-duration: 90ms; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 10px 18px;
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  font-weight: 500;
  border: 1px solid var(--line-1);
  background: var(--bg-surface);
  color: var(--text-1);
  transition: all var(--t-fast);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--line-2); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0) scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--brand-600), var(--brand-500));
  color: #fff; border-color: transparent;
  box-shadow: var(--shadow-brand);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--brand-700), var(--brand-600));
  transform: translateY(-2px);
}
.btn-danger { color: var(--err-600); border-color: var(--line-1); }
.btn-danger:hover:not(:disabled) { background: var(--tint-err); border-color: var(--err-500); }
.btn-sm { padding: 6px 12px; font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 500; line-height: 1.5;
}
.badge-ok   { background: var(--tint-ok);   color: var(--ok-600); }
.badge-warn { background: var(--tint-warn); color: var(--warn-600); }
.badge-err  { background: var(--tint-err);  color: var(--err-600); }
.badge-info { background: var(--tint-info); color: var(--info-500); }
.badge-idle { background: var(--bg-sunken); color: var(--text-3); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.dot-pulse { animation: pulse 1.6s var(--ease-in-out) infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.82); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

.spinner {
  width: 14px; height: 14px; flex: none;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: spin 0.7s linear infinite;
}

/* 主题切换器：三态分段控件，滑块跟随 */
.theme-switch {
  display: inline-flex; align-items: center;
  padding: 3px; gap: 2px;
  background: var(--bg-sunken);
  border: 1px solid var(--line-1);
  border-radius: var(--r-full);
}
.theme-switch button {
  display: grid; place-items: center;
  width: 30px; height: 26px;
  border-radius: var(--r-full);
  color: var(--text-3);
  transition: all var(--t-base);
}
.theme-switch button:hover { color: var(--text-1); }
.theme-switch button[aria-pressed='true'] {
  background: var(--bg-surface);
  color: var(--brand-600);
  box-shadow: var(--shadow-sm);
}
.theme-switch svg { width: 15px; height: 15px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
