/* =============================================================
   Components · 通用组件层
   按钮 / 表单 / 卡片 / 表格 / 标签 / 头像 / 弹窗 / Toast / Tabs ...
   ============================================================= */

/* ---------- 按钮 ---------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-bd: var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 38px;
  padding: 0 var(--sp-4);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-bd);
  border-radius: var(--r-sm);
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease-out),
              border-color var(--t-fast) var(--ease-out),
              box-shadow var(--t-fast) var(--ease-out),
              transform var(--t-fast) var(--ease-out);
}
.btn:hover { background: var(--surface-hover); border-color: var(--gray-300); }
.btn:active { transform: translateY(0.5px) scale(0.99); }
.btn .msym { font-size: 18px; }

.btn-primary {
  --btn-bg: var(--brand-gradient);
  --btn-fg: var(--text-on-brand);
  --btn-bd: transparent;
  box-shadow: 0 2px 6px rgba(var(--brand-rgb), 0.30), inset 0 1px 0 rgba(255,255,255,0.18);
}
.btn-primary:hover { --btn-bg: linear-gradient(135deg, #3f7bff, #2a63ec 100%); border-color: transparent; box-shadow: 0 8px 20px rgba(var(--brand-rgb), 0.34), inset 0 1px 0 rgba(255,255,255,0.18); transform: translateY(-1px); }
.btn-primary:active { --btn-bg: var(--brand-700); transform: translateY(0); }

.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--text-muted); }
.btn-ghost:hover { --btn-bg: var(--gray-75); --btn-fg: var(--text); }

.btn-subtle { --btn-bg: var(--gray-75); --btn-bd: transparent; --btn-fg: var(--text); }
.btn-subtle:hover { --btn-bg: var(--gray-100); }

.btn-danger { --btn-bg: var(--surface); --btn-bd: var(--border-strong); --btn-fg: var(--danger-600); }
.btn-danger:hover { --btn-bg: var(--danger-50); border-color: var(--danger-500); }

.btn-sm { height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-xs); }
.btn-lg { height: 44px; padding: 0 var(--sp-5); font-size: var(--fs-base); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* 图标按钮 */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  transition: background var(--t-fast), color var(--t-fast);
}
.icon-btn:hover { background: var(--gray-75); color: var(--text); }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn .msym { font-size: 20px; }

/* 链接按钮 */
.btn-link {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  color: var(--text-link); font-weight: var(--fw-semibold); font-size: var(--fs-sm);
  padding: var(--sp-1) var(--sp-2); border-radius: var(--r-sm);
  transition: background var(--t-fast);
}
.btn-link:hover { background: var(--brand-50); text-decoration: none; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field-label {
  font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text);
  display: flex; align-items: center; gap: var(--sp-1);
}
.field-label .req { color: var(--danger-500); }
.field-hint { font-size: var(--fs-xs); color: var(--text-muted); }

.input, .textarea, .select {
  width: 100%;
  min-height: 40px;
  padding: 9px var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--text-strong);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--gray-300); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: var(--ring-brand);
}
.textarea { min-height: 88px; resize: vertical; line-height: var(--lh-base); padding: var(--sp-3); }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236b7689' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 36px;
  cursor: pointer;
}
.select-sm {
  width: auto; min-height: 30px; padding: 4px 30px 4px 10px;
  font-size: var(--fs-xs); background-position: right 8px center; border-radius: var(--r-xs);
}

/* 带图标输入 */
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap .lead-icon {
  position: absolute; left: 11px; color: var(--text-faint); pointer-events: none; font-size: 19px;
}
.input-wrap .input { padding-left: 38px; }

/* 复选 / 单选 / 开关 */
.check {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-sm); color: var(--text); cursor: pointer; user-select: none;
}
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check .box {
  width: 18px; height: 18px; border-radius: 5px;
  border: 1.5px solid var(--gray-300); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center;
  transition: all var(--t-fast) var(--ease-out); flex-shrink: 0;
}
.check .box .msym { font-size: 14px; color: #fff; opacity: 0; transform: scale(0.6); transition: all var(--t-fast); }
.check input:checked + .box { background: var(--brand-600); border-color: var(--brand-600); }
.check input:checked + .box .msym { opacity: 1; transform: scale(1); }
.check input:focus-visible + .box { box-shadow: var(--ring-brand); }
.check input:disabled + .box { background: var(--gray-100); border-color: var(--gray-200); }
.check.radio .box { border-radius: var(--r-full); }

.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch .track {
  width: 38px; height: 22px; border-radius: var(--r-full);
  background: var(--gray-200); transition: background var(--t-base) var(--ease-out); position: relative;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: var(--r-full); background: #fff;
  box-shadow: var(--shadow-sm); transition: transform var(--t-base) var(--ease-spring);
}
.switch input:checked + .track { background: var(--brand-600); }
.switch input:checked + .track::after { transform: translateX(16px); }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
}
.card-pad { padding: var(--sp-5); }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-faint);
}
.card-title { font-size: var(--fs-h3); font-weight: var(--fw-semibold); color: var(--text-strong); display: flex; align-items: center; gap: var(--sp-2); }
.card-title .msym { color: var(--brand-600); font-size: 20px; }
.card-body { padding: var(--sp-5); }
.card-hover { transition: box-shadow var(--t-base) var(--ease-out), border-color var(--t-base), transform var(--t-base); }
.card-hover:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }

/* ---------- 标签 / 徽章 ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px;
  font-size: var(--fs-2xs); font-weight: var(--fw-semibold); line-height: 1;
  border-radius: var(--r-xs);
  background: var(--gray-100); color: var(--text-muted);
  white-space: nowrap;
}
.tag .msym { font-size: 13px; }
.tag-blue { background: var(--brand-50); color: var(--brand-700); }
.tag-green { background: var(--success-50); color: var(--success-600); }
.tag-orange { background: var(--warning-50); color: var(--warning-600); }
.tag-red { background: var(--danger-50); color: var(--danger-600); }
.tag-violet { background: #f3edff; color: #6d28d9; }
.tag-teal { background: #e3f6f2; color: #0c8074; }
.tag-solid { background: var(--brand-600); color: #fff; }
.tag-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.badge-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  font-size: var(--fs-2xs); font-weight: var(--fw-bold);
  border-radius: var(--r-full); background: var(--gray-100); color: var(--text-muted);
}

/* 状态点 */
.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  padding: 4px 10px; border-radius: var(--r-full);
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pending { background: var(--gray-100); color: var(--gray-600); }
.status-running { background: var(--brand-50); color: var(--brand-700); }
.status-running::before { animation: pulse 1.6s var(--ease-in-out) infinite; }
.status-done { background: var(--success-50); color: var(--success-600); }
.status-paused { background: var(--warning-50); color: var(--warning-600); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ---------- 头像 ---------- */
.avatar {
  --size: 32px;
  width: var(--size); height: var(--size);
  border-radius: var(--r-full);
  background: var(--brand-100); color: var(--brand-700);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: calc(var(--size) * 0.4); font-weight: var(--fw-semibold);
  overflow: hidden; flex-shrink: 0;
  border: 1.5px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.xs { --size: 24px; }
.avatar.sm { --size: 28px; }
.avatar.lg { --size: 40px; }
.avatar.xl { --size: 56px; }
.avatar-tone-orange { background: var(--warning-50); color: var(--warning-600); }
.avatar-tone-green { background: var(--success-50); color: var(--success-600); }
.avatar-tone-violet { background: #f3edff; color: #6d28d9; }
.avatar-tone-teal { background: #e3f6f2; color: #0c8074; }

.avatar-stack { display: inline-flex; align-items: center; }
.avatar-stack .avatar { margin-left: -8px; }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* ---------- 进度条 ---------- */
.progress {
  height: 6px; border-radius: var(--r-full);
  background: var(--gray-100); overflow: hidden; position: relative;
}
.progress > span {
  display: block; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, var(--brand-500), var(--brand-600));
  transition: width var(--t-slow) var(--ease-out);
}
.progress.green > span { background: linear-gradient(90deg, #34d399, var(--success-500)); }
.progress.thin { height: 4px; }

/* ---------- 表格 ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table thead th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  color: var(--text-muted); text-transform: none;
  padding: var(--sp-3) var(--sp-4);
  background: var(--gray-50);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm);
  border-bottom: 1px solid var(--border-faint);
  vertical-align: middle;
}
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--gray-25); }
.table tbody tr:last-child td { border-bottom: none; }

/* ---------- 分段控制 ---------- */
.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--gray-100); border-radius: var(--r-md);
}
.segmented button {
  padding: 6px 14px; font-size: var(--fs-sm); font-weight: var(--fw-semibold);
  color: var(--text-muted); border-radius: var(--r-sm);
  transition: all var(--t-fast) var(--ease-out);
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--surface); color: var(--brand-700); box-shadow: var(--shadow-xs); }

/* ---------- Tabs (下划线) ---------- */
.tabs { display: flex; gap: var(--sp-5); border-bottom: 1px solid var(--border); }
.tab {
  position: relative; padding: var(--sp-3) 2px var(--sp-3);
  font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-muted);
  display: inline-flex; align-items: center; gap: 6px;
  transition: color var(--t-fast);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand-700); }
.tab::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: var(--brand-600); border-radius: 2px 2px 0 0;
  transform: scaleX(0); transform-origin: center; transition: transform var(--t-base) var(--ease-out);
}
.tab.active::after { transform: scaleX(1); }
.tab .badge-count { background: var(--gray-100); }
.tab.active .badge-count { background: var(--brand-100); color: var(--brand-700); }

/* ---------- 弹窗 / 抽屉 ---------- */
.overlay-mask {
  position: fixed; inset: 0; z-index: var(--z-overlay);
  background: rgba(22, 27, 39, 0.42);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-6);
  animation: fade-in var(--t-base) var(--ease-out);
}
.modal {
  width: min(100%, 720px);
  max-height: calc(100vh - 80px);
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  display: flex; flex-direction: column; overflow: hidden;
  animation: pop-in var(--t-base) var(--ease-out);
}
/* 弹窗就地重渲（勾选/输入等）不重播入场动画，避免抖动 */
.overlay-mask.no-anim, .modal.no-anim { animation: none !important; }
.modal.lg { width: min(100%, 880px); }
.modal.sm { width: min(100%, 460px); }
.modal-head {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border-faint);
}
.modal-head .modal-titles { flex: 1; min-width: 0; }
.modal-head h2 { font-size: var(--fs-h2); font-weight: var(--fw-bold); }
.modal-head p { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 2px; }
.modal-body { padding: var(--sp-6); overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border-faint);
  background: var(--gray-25);
}

/* ---------- Toast ---------- */
.toast-host {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--sp-2);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 10px var(--sp-4);
  background: var(--gray-900); color: #fff;
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
  animation: pop-in var(--t-base) var(--ease-out);
}
.toast .msym { font-size: 18px; }
.toast.success .msym { color: #34d399; }
.toast.error .msym { color: #f87171; }
.toast.info .msym { color: var(--brand-300); }

/* ---------- 空状态 ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: var(--sp-9) var(--sp-6); gap: var(--sp-3);
}
.empty-state .empty-icon {
  width: 64px; height: 64px; border-radius: var(--r-xl);
  background: var(--gray-75); color: var(--text-faint);
  display: flex; align-items: center; justify-content: center;
}
.empty-state .empty-icon .msym { font-size: 30px; }
.empty-state h3 { font-size: var(--fs-h3); color: var(--text-strong); }
.empty-state p { font-size: var(--fs-sm); color: var(--text-muted); max-width: 360px; }

/* 富插画空状态 */
.empty-state.rich { padding: var(--sp-8) var(--sp-6); gap: 8px; }
.empty-illust { position: relative; display: inline-flex; margin-bottom: 4px; }
.empty-art { display: block; }
.empty-glyph {
  position: absolute; left: 50%; top: 47%; transform: translate(-50%, -50%);
  width: 46px; height: 46px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  background: var(--ec, var(--brand-600)); color: #fff;
  box-shadow: 0 10px 22px color-mix(in srgb, var(--ec, var(--brand-600)) 36%, transparent), inset 0 1px 0 rgba(255,255,255,0.25);
}
.empty-glyph .msym { font-size: 24px; }
.empty-state.rich h3 { font-size: var(--fs-h2); }

/* ---------- 骨架屏 ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-75) 37%, var(--gray-100) 63%);
  background-size: 800px 100%; animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-sm);
}
.sk-head { display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 24px; }
.sk-tabs { display: flex; gap: 36px; padding-bottom: 14px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.sk-row { display: grid; grid-template-columns: 1.4fr 0.7fr 2fr 1.4fr; gap: 28px; align-items: start; padding: 24px; border-bottom: 1px solid var(--border-faint); }
.sk-row:last-child { border-bottom: none; }
.sk-cellgroup { display: flex; flex-direction: column; min-width: 0; }
.sk-goalgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.sk-goalgrid.four { grid-template-columns: repeat(4, 1fr); }
.sk-tile { padding: 16px; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); display: flex; flex-direction: column; }
.sk-tile.row { flex-direction: row; align-items: center; gap: 12px; }
.sk-tile.row > span { display: flex; flex-direction: column; }
.sk-line { display: grid; grid-template-columns: 22px 1fr auto auto; gap: 16px; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border-faint); }
.sk-line.sm { grid-template-columns: 34px 1fr; padding: 10px 4px; border-bottom: none; }
.sk-twocol { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; margin-top: 16px; }
.sk-deck { display: flex; gap: 10px; margin-top: 12px; overflow: hidden; }
@media (max-width: 1080px) { .sk-twocol { grid-template-columns: 1fr; } }

/* ---------- Popover ---------- */
.popover {
  position: absolute; z-index: var(--z-popover);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  padding: var(--sp-3); min-width: 240px;
  animation: pop-in var(--t-fast) var(--ease-out);
}

/* ---------- 分隔 / 杂项 ---------- */
.divider { height: 1px; background: var(--border-faint); border: none; margin: var(--sp-4) 0; }
.divider-v { width: 1px; align-self: stretch; background: var(--border); }
.kbd {
  font-family: var(--font-mono); font-size: var(--fs-2xs);
  padding: 2px 6px; border-radius: var(--r-xs);
  background: var(--gray-75); border: 1px solid var(--border); color: var(--text-muted);
}
.dot-sep { color: var(--text-faint); }

/* ================= 飞书式微交互（克制） ================= */
@media (prefers-reduced-motion: no-preference) {
  .deck-card, .goal-card, .stat-card, .tl-node, .bc, .candidate, .ledger-member { will-change: transform; }
  .icon-btn:active { transform: scale(0.9); }
  .top-nav-item:active { transform: scale(0.97); }
  .role-chip:active, .chip-check:active, .status-tab:active, .seg-btn:active, .pill-btn:active { transform: scale(0.97); }
  .deck-card:active, .goal-card:active, .stat-card:active, .candidate:active { transform: translateY(0) scale(0.99); }
  .bc:active { transform: scale(0.985); }
  /* 主按钮按下涟漪式高光 */
  .btn-primary { position: relative; overflow: hidden; }
  .btn-primary::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at center, rgba(255,255,255,0.5), transparent 60%); opacity: 0; transform: scale(0.2); transition: opacity 0.5s, transform 0.5s; pointer-events: none; }
  .btn-primary:active::after { opacity: 0.35; transform: scale(1); transition: 0s; }
}
/* 图标按钮 hover 采用飞书风格中性叠加 */
.icon-btn { transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast) var(--ease-spring); }
.icon-btn:hover { background: rgba(31,37,51,0.06); }
.top-nav-item, .status-tab, .role-chip, .pill-btn, .seg-btn { transition: all var(--t-fast) var(--ease-out); }
