/* 组件库：按钮、表单、卡片、弹窗、提示、表格、标签等通用样式。 */

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 550;
  white-space: nowrap;
  transition: background var(--speed) var(--ease), border-color var(--speed) var(--ease), transform 80ms var(--ease), box-shadow var(--speed) var(--ease);
  user-select: none;
}
.btn:active { transform: translateY(1px) scale(0.995); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(5, 155, 76, 0.24); }
.btn-primary:hover:not(:disabled) { background: var(--brand-600); }
.btn-soft { background: var(--brand-soft); color: var(--brand-700); }
.btn-soft:hover:not(:disabled) { background: color-mix(in srgb, var(--brand-soft) 70%, var(--brand) 12%); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-quiet { background: transparent; color: var(--text-2); padding: 0 10px; height: 34px; }
.btn-quiet:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger-soft) 70%, var(--danger) 14%); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-lg { height: 46px; padding: 0 22px; font-size: 15px; border-radius: var(--radius); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; gap: 4px; border-radius: var(--radius-xs); }
.btn-sm svg { width: 14px; height: 14px; }
.btn-block { width: 100%; }
.btn-link { height: auto; padding: 0; color: var(--brand); font-weight: 500; }
.btn-link:hover { text-decoration: underline; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
  flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.active { background: var(--brand-soft); color: var(--brand-700); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm svg { width: 16px; height: 16px; }

/* ============ 头像 ============ */
.avatar {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: #fff;
  font-weight: 650;
  font-size: 15px;
  letter-spacing: 0;
  user-select: none;
  background: var(--brand);
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.xs { width: 24px; height: 24px; font-size: 11px; }
.avatar.sm { width: 32px; height: 32px; font-size: 12.5px; }
.avatar.lg { width: 52px; height: 52px; font-size: 19px; }
.avatar.xl { width: 72px; height: 72px; font-size: 26px; }
.avatar.rounded { border-radius: 30%; }
.avatar-wrap { position: relative; flex: none; }
.avatar-wrap .presence {
  position: absolute; right: -1px; bottom: -1px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--success); border: 2px solid var(--surface);
}

/* ============ 表单 ============ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field-label { font-size: 13px; font-weight: 550; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--text-3); }
.field-error { font-size: 12px; color: var(--danger); }
.input, .textarea, .select {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
  font-size: 14px;
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .textarea:hover, .select:hover { border-color: color-mix(in srgb, var(--border-2) 60%, var(--text-3)); }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.input:disabled, .textarea:disabled { background: var(--surface-2); color: var(--text-3); }
.textarea { min-height: 88px; resize: vertical; line-height: 1.55; }
.input-icon { position: relative; }
.input-icon > svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--text-3); pointer-events: none; }
.input-icon .input { padding-left: 38px; }
.input-affix { position: relative; }
.input-affix .input { padding-right: 44px; }
.input-affix .affix { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.search-input { position: relative; }
.search-input svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-3); }
.search-input input {
  width: 100%; height: 36px; padding: 0 30px 0 32px;
  border-radius: var(--radius-sm); border: 1px solid transparent; background: var(--surface-3);
  transition: background var(--speed), border-color var(--speed);
}
.search-input input:focus { outline: none; background: var(--surface); border-color: var(--brand); box-shadow: var(--ring); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 42px; height: 24px; border-radius: 999px; background: var(--border-2);
  transition: background var(--speed) var(--ease); position: relative; flex: none;
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
  background: #fff; border-radius: 50%; transition: transform var(--speed) var(--ease);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: var(--ring); }

.checkbox { display: inline-flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 13.5px; color: var(--text-2); }
.checkbox input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--brand); flex: none; }

/* ============ 卡片 / 面板 ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}
.card-pad { padding: var(--space-5); }
.card-head { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: var(--space-3); }
.card-body { padding: var(--space-5); }
.card-foot { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--space-2); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.panel-body { padding: var(--space-5); }

/* ============ 标签 / 徽标 / 圆点 ============ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 1; justify-content: center;
}
.badge.soft { background: var(--brand-soft); color: var(--brand-700); }
.badge.neutral { background: var(--surface-3); color: var(--text-2); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.online { background: var(--success); }
.dot.offline { background: var(--text-3); }
.dot.warn { background: var(--warning); }
.dot.error { background: var(--danger); }
.dot.pulse { animation: pulse-dot 2s ease-in-out infinite; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 24px; padding: 0 9px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-2); font-size: 12px; white-space: nowrap;
}
.chip.brand { background: var(--brand-soft); color: var(--brand-700); }
.chip.clickable { cursor: pointer; transition: background var(--speed); }
.chip.clickable:hover { background: var(--border); }
.chip .x { display: inline-flex; opacity: 0.6; }
.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 5px;
  border: 1px solid var(--border-2); border-bottom-width: 2px;
  background: var(--surface-2); color: var(--text-3); font-size: 11px; font-family: var(--font-mono);
}

/* ============ 标签页 ============ */
.tabs { display: flex; gap: 2px; padding: 3px; background: var(--surface-3); border-radius: var(--radius-sm); }
.tabs .tab {
  flex: 1; height: 30px; padding: 0 12px; border-radius: 7px;
  font-size: 13px; color: var(--text-2); font-weight: 500;
  transition: background var(--speed), color var(--speed); white-space: nowrap;
}
.tabs .tab:hover { color: var(--text); }
.tabs .tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); font-weight: 600; }
.tabbar { display: flex; gap: var(--space-5); border-bottom: 1px solid var(--border); padding: 0 var(--space-1); }
.tabbar .tab { position: relative; height: 44px; font-size: 14px; color: var(--text-2); font-weight: 550; }
.tabbar .tab.active { color: var(--brand-700); }
.tabbar .tab.active::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--brand); border-radius: 2px; }

/* ============ 表格 ============ */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-weight: 600; font-size: 12px; letter-spacing: 0.02em;
  color: var(--text-3); padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap;
}
.table td { padding: 13px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table .actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ============ 提示条 ============ */
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius); font-size: 13px; line-height: 1.5; }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.alert-info { background: var(--info-soft); color: color-mix(in srgb, var(--info) 75%, var(--text)); }
.alert-warn { background: var(--warning-soft); color: color-mix(in srgb, var(--warning) 78%, var(--text)); }
.alert-danger { background: var(--danger-soft); color: color-mix(in srgb, var(--danger) 82%, var(--text)); }
.alert-success { background: var(--success-soft); color: color-mix(in srgb, var(--success) 80%, var(--text)); }

/* ============ 空状态 / 加载 ============ */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-3); padding: var(--space-8) var(--space-5); text-align: center; color: var(--text-3); }
.empty .empty-icon { width: 64px; height: 64px; border-radius: 22px; background: var(--surface-3); display: grid; place-items: center; color: var(--text-3); }
.empty .empty-icon svg { width: 30px; height: 30px; }
.empty h3 { color: var(--text-2); font-size: 15px; }
.empty p { font-size: 13px; max-width: 320px; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid color-mix(in srgb, currentColor 22%, transparent); border-top-color: currentColor; animation: spin 0.7s linear infinite; flex: none; }
.spinner.lg { width: 26px; height: 26px; border-width: 3px; }
.loading-row { display: flex; align-items: center; justify-content: center; gap: 10px; padding: var(--space-5); color: var(--text-3); font-size: 13px; }
.skeleton { border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%); background-size: 800px 100%; animation: shimmer 1.4s linear infinite; }

/* ============ 弹窗 ============ */
dialog.modal, .modal-backdrop { position: fixed; inset: 0; z-index: 120; }
dialog.modal {
  margin: auto; padding: 0; border: none; background: transparent; max-width: min(520px, calc(100vw - 32px));
  width: 100%; color: var(--text);
}
dialog.modal::backdrop { background: var(--overlay); backdrop-filter: blur(3px); animation: fade-in 140ms var(--ease); }
dialog.modal[open] .modal-box { animation: pop-in 200ms var(--ease); }
.modal-box {
  background: var(--surface); border-radius: var(--radius-xl); box-shadow: var(--shadow-3);
  border: 1px solid var(--border); max-height: min(86vh, 860px); display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-5) var(--space-5) var(--space-3); }
.modal-head h2 { font-size: 17px; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 0 var(--space-5) var(--space-4); overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-5) var(--space-5); }
.modal-wide { max-width: min(760px, calc(100vw - 32px)); }
.modal-full { max-width: min(980px, calc(100vw - 32px)); }

/* ============ 轻提示 ============ */
.toast-stack { position: fixed; z-index: 200; left: 50%; bottom: 28px; transform: translateX(-50%); display: flex; flex-direction: column-reverse; gap: 8px; pointer-events: none; align-items: center; }
.toast {
  display: flex; align-items: center; gap: 9px; max-width: min(88vw, 480px);
  padding: 10px 16px; border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--text) 92%, transparent);
  color: var(--bg); font-size: 13.5px; box-shadow: var(--shadow-2);
  animation: slide-up 220ms var(--ease); pointer-events: auto;
}
.toast svg { width: 17px; height: 17px; flex: none; }
.toast.success { background: var(--success); color: #fff; }
.toast.danger { background: var(--danger); color: #fff; }
.toast.warning { background: #b47616; color: #fff; }
.toast.leaving { animation: fade-in 160ms var(--ease) reverse forwards; }

/* ============ 下拉菜单 ============ */
.menu {
  position: fixed; z-index: 150; min-width: 180px; padding: 5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-2); animation: pop-in 140ms var(--ease);
}
.menu .menu-item {
  display: flex; align-items: center; gap: 9px; width: 100%; height: 34px; padding: 0 10px;
  border-radius: 7px; font-size: 13.5px; color: var(--text-2); text-align: left;
}
.menu .menu-item svg { width: 16px; height: 16px; color: var(--text-3); }
.menu .menu-item:hover { background: var(--surface-3); color: var(--text); }
.menu .menu-item.danger { color: var(--danger); }
.menu .menu-item.danger svg { color: var(--danger); }
.menu .menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }
.menu .menu-title { padding: 6px 10px 4px; font-size: 11px; color: var(--text-3); font-weight: 600; }

/* ============ 提示气泡（纯 CSS tooltip） ============ */
[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip); position: absolute; z-index: 160; left: 50%; bottom: calc(100% + 8px);
  transform: translateX(-50%); padding: 5px 9px; border-radius: 7px;
  background: color-mix(in srgb, var(--text) 94%, transparent); color: var(--bg);
  font-size: 12px; white-space: nowrap; pointer-events: none; animation: fade-in 120ms;
}

/* ============ 弹层 / 抽屉 ============ */
.backdrop { position: fixed; inset: 0; z-index: 110; background: var(--overlay); animation: fade-in 160ms var(--ease); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 130; width: min(400px, 92vw);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-3);
  display: flex; flex-direction: column; animation: slide-in-right 220ms var(--ease);
}
@keyframes slide-in-right { from { transform: translateX(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }

/* ============ 进度条 ============ */
.progress { height: 5px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width 160ms linear; }

/* ============ 头像组 ============ */
.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-left: -8px; border: 2px solid var(--surface); }
.avatar-stack .avatar:first-child { margin-left: 0; }
