/* ============================================================
 * Nexus AI · Components
 * 创建于 2026-05-25，对应 spec §7 公共组件清单
 * ============================================================ */

/* ===== Layout: Topbar 顶栏 ===== */
.topbar {
  height: 64px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  color: var(--color-primary-600);
}
.topbar-logo-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-primary-700));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

/* ===== Layout: Sidebar 左侧菜单 ===== */
.sidebar {
  width: 260px;
  min-height: calc(100vh - 64px);
  background: var(--bg-card);
  border-right: 1px solid var(--border-default);
  padding: 12px 8px;
  flex-shrink: 0;
}

.sidebar-group-title {
  font-size: 12px;
  color: var(--color-gray-500);
  font-weight: 500;
  padding: 8px 12px 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--color-gray-700);
  cursor: pointer;
  font-size: 14px;
  margin-bottom: 2px;
  transition: background .15s, color .15s;
}
.sidebar-nav-item:hover {
  background: var(--color-gray-100);
  color: var(--color-gray-900);
}
.sidebar-nav-item.active {
  background: var(--color-primary-50);
  color: var(--color-primary-600);
  font-weight: 500;
}
.sidebar-nav-item .nav-icon {
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}
.sidebar-nav-item .nav-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--color-gray-400);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: all .15s;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.btn-primary {
  background: var(--color-primary-500);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-600); }
.btn-primary:disabled { background: var(--color-gray-300); cursor: not-allowed; }

.btn-secondary {
  background: var(--bg-card);
  color: var(--color-gray-700);
  border-color: var(--border-default);
}
.btn-secondary:hover {
  border-color: var(--color-primary-500);
  color: var(--color-primary-500);
}

.btn-ghost {
  background: transparent;
  color: var(--color-gray-600);
  padding: 6px 10px;
}
.btn-ghost:hover {
  background: var(--color-gray-100);
  color: var(--color-gray-900);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover { background: #DC2626; }

.btn-text {
  background: transparent;
  color: var(--color-primary-500);
  padding: 6px 10px;
}
.btn-text:hover { color: var(--color-primary-700); }

/* 按钮尺寸 */
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-lg { padding: 11px 20px; font-size: 15px; }

/* ===== Card 卡片 ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  transition: box-shadow .2s, border-color .2s, transform .2s;
}
.card-hover:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary-200);
  transform: translateY(-1px);
}
.card-flat {
  box-shadow: none;
}

/* ===== Form Controls ===== */
.input, .select, .textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-size: 14px;
  color: var(--color-gray-900);
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder, .textarea::placeholder { color: var(--color-gray-400); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 3px rgba(51, 102, 255, 0.1);
}
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--color-gray-50);
  color: var(--color-gray-400);
  cursor: not-allowed;
}
.input-sm { padding: 5px 10px; font-size: 13px; }
.input-lg { padding: 11px 14px; font-size: 15px; }

.textarea { resize: vertical; min-height: 80px; }

/* 复选框 / 单选 */
.checkbox, .radio {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary-500);
  cursor: pointer;
}

/* 开关 */
.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--color-gray-300);
  border-radius: 10px;
  transition: .2s;
}
.switch-slider::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}
.switch input:checked + .switch-slider { background: var(--color-primary-500); }
.switch input:checked + .switch-slider::before { transform: translateX(16px); }

/* Field Group：标签 + 字段 */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-gray-700);
}
.field-label .required { color: var(--color-danger); margin-right: 2px; }
.field-hint {
  font-size: 12px;
  color: var(--color-gray-500);
}
.field-error {
  font-size: 12px;
  color: var(--color-danger);
}

/* ===== Tags ===== */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
}
.tag-success { background: var(--color-success-bg); color: #065F46; }
.tag-warning { background: var(--color-warning-bg); color: #92400E; }
.tag-danger  { background: var(--color-danger-bg); color: #991B1B; }
.tag-info    { background: var(--color-info-bg); color: #1E40AF; }
.tag-default { background: var(--color-gray-100); color: var(--color-gray-700); }
.tag-primary { background: var(--color-primary-50); color: var(--color-primary-600); }
.tag-outline {
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--color-gray-600);
}

/* ===== Table ===== */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
}
.table th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 500;
  font-size: 13px;
  color: var(--color-gray-600);
  background: var(--color-gray-50);
  border-bottom: 1px solid var(--border-default);
}
.table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-gray-100);
  font-size: 14px;
  color: var(--color-gray-700);
}
.table tbody tr {
  transition: background .15s;
}
.table tbody tr:hover {
  background: var(--color-gray-50);
}
.table tbody tr:last-child td { border-bottom: none; }

.table-wrapper {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  overflow: hidden;
}

/* ===== Drawer 抽屉 ===== */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: var(--z-drawer-backdrop);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: -600px;
  height: 100vh;
  width: 600px;
  background: var(--bg-card);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-drawer);
  transition: right .25s ease;
  display: flex;
  flex-direction: column;
}
.drawer.open { right: 0; }
.drawer-sm { width: 400px; right: -400px; }
.drawer-sm.open { right: 0; }
.drawer-lg { width: 800px; right: -800px; }
.drawer-lg.open { right: 0; }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-default);
}
.drawer-title { font-size: 16px; font-weight: 600; color: var(--color-gray-900); }
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.drawer-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-default);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ===== Modal 对话框 ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: var(--z-modal-backdrop);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  width: 480px;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-lg { width: 720px; }
.modal-xl { width: 960px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-default);
}
.modal-title { font-size: 16px; font-weight: 600; color: var(--color-gray-900); }
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-default);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.close-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-gray-500);
  cursor: pointer;
}
.close-btn:hover { background: var(--color-gray-100); color: var(--color-gray-900); }

/* ===== Toast 通知 ===== */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-card);
  border-left: 4px solid var(--color-success);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 12px 16px;
  min-width: 280px;
  max-width: 400px;
  font-size: 14px;
  animation: toast-in .3s;
}
.toast-success { border-left-color: var(--color-success); }
.toast-warning { border-left-color: var(--color-warning); }
.toast-danger  { border-left-color: var(--color-danger); }
.toast-info    { border-left-color: var(--color-info); }
@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-default);
  gap: 4px;
}
.tab {
  padding: 12px 16px;
  cursor: pointer;
  color: var(--color-gray-600);
  border-bottom: 2px solid transparent;
  transition: all .15s;
  font-size: 14px;
  user-select: none;
  margin-bottom: -1px;
}
.tab:hover { color: var(--color-primary-500); }
.tab.active {
  color: var(--color-primary-500);
  border-bottom-color: var(--color-primary-500);
  font-weight: 500;
}

/* 单选按钮组 Tab */
.radio-tabs {
  display: inline-flex;
  background: var(--color-gray-100);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.radio-tab {
  padding: 6px 14px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  color: var(--color-gray-600);
  cursor: pointer;
  transition: all .15s;
}
.radio-tab.active {
  background: var(--bg-card);
  color: var(--color-gray-900);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

/* ===== Status Dot ===== */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}
.status-dot.pending { background: var(--color-gray-300); }
.status-dot.processing {
  background: var(--color-info);
  animation: pulse 1.5s ease-in-out infinite;
}
.status-dot.success { background: var(--color-success); }
.status-dot.partial-fail { background: var(--color-warning); }
.status-dot.failed { background: var(--color-danger); }
.status-dot.disabled { background: var(--color-gray-500); }
@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
  50% { opacity: 0.6; box-shadow: 0 0 0 6px rgba(59, 130, 246, 0); }
}

/* ===== Code Block ===== */
.code-block {
  background: #1F2937;
  color: #E5E7EB;
  padding: 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
}
.code-inline {
  background: var(--color-gray-100);
  color: var(--color-primary-700);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 64px 16px;
  color: var(--color-gray-500);
}
.empty-state-icon {
  font-size: 48px;
  opacity: 0.4;
  margin-bottom: 12px;
}
.empty-state-title {
  font-size: 15px;
  color: var(--color-gray-700);
  margin-bottom: 4px;
  font-weight: 500;
}
.empty-state-desc {
  font-size: 13px;
  color: var(--color-gray-500);
  margin-bottom: 16px;
}

/* ===== Avatar ===== */
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary-100);
  color: var(--color-primary-600);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  font-size: 12px;
  flex-shrink: 0;
}
.avatar-sm { width: 24px; height: 24px; font-size: 11px; }
.avatar-lg { width: 48px; height: 48px; font-size: 16px; }

/* ===== Badge ===== */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--color-danger);
  color: #fff;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
}

/* ===== Divider ===== */
.divider {
  height: 1px;
  background: var(--border-default);
  margin: 16px 0;
}
.divider-vertical {
  width: 1px;
  background: var(--border-default);
  margin: 0 12px;
  align-self: stretch;
}

/* ===== Tooltip (CSS only) ===== */
.tooltip {
  position: relative;
}
.tooltip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-gray-900);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}
.tooltip:hover::after { opacity: 1; }

/* ===== Page Container ===== */
.page-container {
  display: flex;
  min-height: calc(100vh - 64px);
}
.page-content {
  flex: 1;
  padding: 24px;
  overflow-x: hidden;
}
.page-content-no-padding { flex: 1; }

/* 页面顶部条 */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--color-gray-900);
}
.page-subtitle {
  font-size: 13px;
  color: var(--color-gray-500);
  margin-top: 4px;
}

/* 操作工具栏 */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar-spacer { flex: 1; }

/* ===== Stat Card 统计卡片 ===== */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-card-label {
  font-size: 13px;
  color: var(--color-gray-500);
  margin-bottom: 8px;
}
.stat-card-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--color-gray-900);
  line-height: 1.2;
}
.stat-card-trend {
  font-size: 12px;
  margin-top: 6px;
}
.stat-card-trend.up { color: var(--color-success); }
.stat-card-trend.down { color: var(--color-danger); }
