/* ============================================================
   Base — Reset / Typography / Primitives / 通用组件
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-surface-3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-elevated); }

/* 数字字体 */
.num { font-family: var(--font-dig); font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.mono { font-family: var(--font-mono); }

/* ====== 按钮 ====== */
.btn {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  height: 32px; padding: 0 var(--sp-3);
  border-radius: var(--r-sm);
  font-size: 12.5px; font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  transition: all var(--dur) var(--ease);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-surface-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-danger { background: rgba(255, 59, 48, 0.15); border-color: rgba(255, 59, 48, 0.4); color: var(--danger); }
.btn-danger:hover { background: rgba(255, 59, 48, 0.25); }
.btn-sm { height: 26px; padding: 0 var(--sp-2); font-size: 11.5px; }
.btn-lg { height: 40px; padding: 0 var(--sp-5); font-size: 14px; }
.btn:disabled, .btn.is-disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

/* ====== 开关 Switch ====== */
.switch {
  position: relative; display: inline-block;
  width: 38px; height: 20px; flex-shrink: 0;
  background: var(--bg-surface-3); border-radius: var(--r-pill);
  cursor: pointer; transition: background var(--dur) var(--ease);
  border: 1px solid var(--border);
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--text-secondary);
  transition: all var(--dur) var(--ease-out);
}
.switch.on { background: var(--accent); border-color: var(--accent); }
.switch.on::after { left: 20px; background: #fff; }
.switch.is-disabled { opacity: 0.4; cursor: not-allowed; }
.switch.lg { width: 46px; height: 24px; }
.switch.lg::after { width: 18px; height: 18px; }
.switch.lg.on::after { left: 24px; }

/* ====== 徽标 / 标签 ====== */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  height: 18px; padding: 0 7px;
  border-radius: var(--r-xs);
  font-size: 10.5px; font-weight: 600;
  background: var(--bg-surface-3); color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.tag-accent { background: var(--accent-soft); color: var(--accent); }
.tag-ai { background: var(--ai-soft); color: var(--ai); }
.tag-success { background: rgba(46, 204, 113, 0.15); color: var(--success); }
.tag-warning { background: rgba(255, 167, 38, 0.15); color: var(--warning); }
.tag-danger { background: rgba(255, 59, 48, 0.15); color: var(--danger); }

.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot-live { background: var(--success); box-shadow: 0 0 0 0 rgba(46,204,113,.5); animation: pulse 1.8s infinite; }
.dot-warn { background: var(--warning); }
.dot-off  { background: var(--text-tertiary); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(46,204,113,.5); }
  70% { box-shadow: 0 0 0 6px rgba(46,204,113,0); }
  100% { box-shadow: 0 0 0 0 rgba(46,204,113,0); }
}

/* ====== 卡片 ====== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.card-hover { transition: all var(--dur) var(--ease); cursor: pointer; }
.card-hover:hover { border-color: var(--border-strong); background: var(--bg-surface-2); transform: translateY(-1px); }

/* ====== 分段选择 / Tab 条 ====== */
.seg {
  display: inline-flex; gap: 2px;
  background: var(--bg-surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 2px;
}
.seg-item {
  padding: 5px 12px; border-radius: 5px;
  font-size: 12px; color: var(--text-secondary);
  transition: all var(--dur-fast) var(--ease);
}
.seg-item:hover { color: var(--text-primary); }
.seg-item.active { background: var(--bg-elevated); color: var(--text-primary); }

/* ====== 输入 ====== */
.field {
  display: flex; align-items: center; gap: var(--sp-2);
  height: 30px; padding: 0 var(--sp-3);
  background: var(--bg-surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.field input, .field select {
  background: transparent; border: none; outline: none;
  color: var(--text-primary); font-size: 12.5px; width: 100%;
}
select.field { padding-right: var(--sp-2); }

/* ====== 进度条 ====== */
.bar { height: 6px; background: var(--bg-surface-3); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width var(--dur-slow) var(--ease); }

/* ====== 头像 ====== */
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #ff8a3d);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: #fff; flex-shrink: 0;
}
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.avatar.lg { width: 40px; height: 40px; font-size: 16px; }

/* ====== 工具类 ====== */
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.between { justify-content: space-between; }
.center { align-items: center; justify-content: center; }
.gap-1 { gap: var(--sp-1); } .gap-2 { gap: var(--sp-2); } .gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); } .gap-5 { gap: var(--sp-5); } .gap-6 { gap: var(--sp-6); }
.flex-1 { flex: 1; } .flex-grow { flex-grow: 1; }
.muted { color: var(--text-secondary); }
.dim { color: var(--text-tertiary); }
.tiny { font-size: 11px; }
.smaller { font-size: 11.5px; }
.bold { font-weight: 600; }
.upper { text-transform: uppercase; letter-spacing: 0.05em; }
.hide { display: none !important; }
.scroll { overflow-y: auto; overflow-x: hidden; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ====== 图标（用内联 SVG 统一） ====== */
.icon { width: 16px; height: 16px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 14px; height: 14px; }
.icon.lg { width: 20px; height: 20px; }
.icon.xl { width: 28px; height: 28px; }

/* ====== Tooltip ====== */
[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--bg-elevated); color: var(--text-primary);
  padding: 4px 8px; border-radius: var(--r-xs);
  font-size: 11px; white-space: nowrap; z-index: 9999;
  border: 1px solid var(--border-strong); pointer-events: none;
}

/* ====== Modal 遮罩 ====== */
.mask {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(5, 7, 10, 0.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  animation: fade var(--dur) var(--ease);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ====== Toast ====== */
.toast-wrap { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  padding: 10px 16px; border-radius: var(--r-sm);
  font-size: 12.5px; display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-lg); animation: slide-up var(--dur) var(--ease-out);
}

/* ====== 空状态 ====== */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--sp-12) var(--sp-6); text-align: center;
}
.empty-state .empty-icon { color: var(--text-tertiary); opacity: 0.6; }
.empty-state .empty-icon .icon { width: 44px; height: 44px; }
