/* ============================================================
   全局样式 + 组件类
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;600;700&family=Noto+Sans+SC:wght@300;400;500;600&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

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

html { font-size: 14px; }

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* 滚动条 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-line); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ============================================================
   布局
   ============================================================ */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-line);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border-line);
}
.sidebar-brand h1 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}
.sidebar-brand p {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 4px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-group {
  margin-bottom: 4px;
}
.nav-group-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 8px 20px 4px;
  font-weight: 500;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  border-left: 2px solid transparent;
}
.nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}
.nav-item .nav-icon {
  width: 16px;
  text-align: center;
  font-size: var(--text-sm);
  opacity: 0.7;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-line);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-footer .avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-sm); font-weight: 600;
}
.sidebar-footer .user-info {
  flex: 1; min-width: 0;
}
.sidebar-footer .user-name {
  font-size: var(--text-sm);
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-footer .user-role {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}
.sidebar-footer .logout-btn {
  background: none; border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  transition: color var(--transition);
}
.sidebar-footer .logout-btn:hover { color: var(--signal-red); }

.main-area {
  flex: 1;
  margin-left: 240px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 52px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-line);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .breadcrumb {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.topbar .breadcrumb .current {
  color: var(--text-primary);
  font-weight: 500;
}
.topbar .spacer { flex: 1; }
.topbar .search-box {
  background: var(--bg-inset);
  border: 1px solid var(--border-line);
  border-radius: var(--radius);
  padding: 5px 12px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  width: 240px;
  outline: none;
  transition: border-color var(--transition);
}
.topbar .search-box:focus { border-color: var(--border-focus); }

.page-content {
  padding: 24px 32px;
  flex: 1;
}

/* ============================================================
   KPI 卡片
   ============================================================ */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-line);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--accent);
}
.kpi-card.red::before    { background: var(--signal-red); }
.kpi-card.amber::before  { background: var(--signal-amber); }
.kpi-card.blue::before   { background: var(--signal-blue); }
.kpi-card.violet::before { background: var(--signal-violet); }

.kpi-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.kpi-value {
  font-family: var(--font-mono);
  font-size: var(--text-3xl);
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 4px;
  line-height: 1.1;
}
.kpi-sub {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 4px;
}
.kpi-sub .up { color: var(--accent); }
.kpi-sub .down { color: var(--signal-red); }

/* ============================================================
   卡片容器
   ============================================================ */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-line);
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h3 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
}
.card-body { padding: 20px; }
.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-line);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* ============================================================
   表格
   ============================================================ */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.data-table th {
  text-align: left;
  padding: 10px 16px;
  font-weight: 500;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-line);
  background: var(--bg-inset);
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-line);
  color: var(--text-primary);
}
.data-table tr:hover td {
  background: var(--bg-elevated);
}
.data-table .mono {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

/* ============================================================
   标签/徽章
   ============================================================ */

.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
  font-weight: 500;
  border: 1px solid transparent;
}
.badge-green  { background: rgba(90,147,103,0.15); color: var(--accent); border-color: rgba(90,147,103,0.3); }
.badge-red    { background: rgba(199,84,80,0.15); color: var(--signal-red); border-color: rgba(199,84,80,0.3); }
.badge-amber  { background: rgba(212,160,76,0.15); color: var(--signal-amber); border-color: rgba(212,160,76,0.3); }
.badge-blue   { background: rgba(91,141,190,0.15); color: var(--signal-blue); border-color: rgba(91,141,190,0.3); }
.badge-violet { background: rgba(139,122,184,0.15); color: var(--signal-violet); border-color: rgba(139,122,184,0.3); }
.badge-gray   { background: rgba(168,162,154,0.1); color: var(--text-secondary); border-color: var(--border-line); }

/* ============================================================
   按钮
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: var(--text-sm);
  font-family: var(--font-body);
  border-radius: var(--radius);
  border: 1px solid var(--border-line);
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--text-tertiary); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-inverse);
  font-weight: 500;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger {
  background: var(--signal-red);
  border-color: var(--signal-red);
  color: var(--text-inverse);
}
.btn-danger:hover { opacity: 0.9; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-elevated); }

.btn-sm { padding: 3px 8px; font-size: var(--text-xs); }

/* ============================================================
   表单
   ============================================================ */

.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg-inset);
  border: 1px solid var(--border-line);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: var(--text-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  outline: none;
  transition: border-color var(--transition);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--border-focus);
}
.form-textarea { min-height: 80px; resize: vertical; }

/* ============================================================
   筛选栏
   ============================================================ */

.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-bar .form-input, .filter-bar .form-select {
  width: auto;
  min-width: 140px;
}

/* ============================================================
   状态徽章
   ============================================================ */

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.status-pending   { background: rgba(212,160,76,0.15); color: var(--signal-amber); }
.status-approved  { background: rgba(90,147,103,0.15); color: var(--accent); }
.status-rejected  { background: rgba(199,84,80,0.15); color: var(--signal-red); }
.status-assigned  { background: rgba(91,141,190,0.15); color: var(--signal-blue); }
.status-completed { background: rgba(90,147,103,0.15); color: var(--accent); }
.status-failed    { background: rgba(199,84,80,0.15); color: var(--signal-red); }
.status-cancelled { background: rgba(168,162,154,0.1); color: var(--text-secondary); }
.status-running   { background: rgba(90,147,103,0.15); color: var(--accent); }
.status-draft     { background: rgba(168,162,154,0.1); color: var(--text-secondary); }
.status-paused    { background: rgba(212,160,76,0.15); color: var(--signal-amber); }

/* ============================================================
   优先级标记
   ============================================================ */

.priority-tag {
  display: inline-block;
  width: 20px; height: 20px;
  line-height: 20px;
  text-align: center;
  border-radius: 50%;
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: var(--font-mono);
}
.priority-1 { background: rgba(168,162,154,0.15); color: var(--text-secondary); }
.priority-2 { background: rgba(91,141,190,0.15); color: var(--signal-blue); }
.priority-3 { background: rgba(212,160,76,0.15); color: var(--signal-amber); }
.priority-4 { background: rgba(199,84,80,0.15); color: var(--signal-red); }
.priority-5 { background: rgba(199,84,80,0.2); color: var(--signal-red); font-weight: 700; }

/* ============================================================
   加载/空状态
   ============================================================ */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}
.loading::before {
  content: '';
  width: 16px; height: 16px;
  border: 2px solid var(--border-line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-tertiary);
}
.empty-state h4 {
  font-size: var(--text-base);
  margin-bottom: 8px;
  color: var(--text-secondary);
}

/* ============================================================
   模态框
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 560px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
}
.modal-body { padding: 20px; }
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ============================================================
   数据大屏
   ============================================================ */

.dashboard-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  padding: 12px;
  gap: 10px;
}

.dash-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 8px;
  flex-shrink: 0;
}
.dash-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.dash-pulse {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: dashPulse 2s ease-in-out infinite;
}
@keyframes dashPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.dash-kpis {
  display: flex;
  gap: 24px;
  margin-left: auto;
}
.dash-kpi {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.dash-kpi-num {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}
.dash-kpi-label {
  font-size: 10px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}

.dash-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 10px;
  min-height: 0;
}
.dash-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.dash-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-line);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}
.dash-card-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-line);
  margin-bottom: 8px;
}

.dash-chart-lg { flex: 1; min-height: 220px; }
.dash-chart-md { flex: 1; min-height: 180px; }
.dash-chart-sm { flex: 1; min-height: 140px; }

.dash-task-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  overflow-y: auto;
}
.dash-task-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
}
.dash-task-bar {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  margin-right: 8px;
}
.dash-task-bar .dash-task-name { font-size: 13px; color: #fff; font-weight: 500; }
.dash-task-bar .dash-task-count { font-family: var(--font-mono); font-size: 18px; font-weight: 700; color: #fff; }
.dash-task-priority { display: flex; gap: 3px; flex-shrink: 0; }

.dash-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-line);
  border-radius: var(--radius);
  flex-shrink: 0;
}
.dash-footer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.dash-footer-sep {
  width: 1px;
  height: 16px;
  background: var(--border-line);
}

.dash-clock { margin-left: auto; }

/* ============================================================
   角色切换
   ============================================================ */

.role-switch-panel {
  position: absolute;
  bottom: 72px;
  left: 12px;
  right: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-line);
  border-radius: var(--radius);
  padding: 12px;
  z-index: 110;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.3);
}
.role-switch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.role-switch-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.role-switch-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  transition: all var(--transition);
}
.role-switch-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.role-switch-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.role-switch-hint {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-line);
  line-height: 1.5;
}

.role-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.role-badge-topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg-inset);
  border: 1px solid var(--border-line);
  border-radius: var(--radius);
  margin-right: 4px;
}

/* ============================================================
   分页
   ============================================================ */

.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  padding: 16px 0;
}
.pagination button {
  min-width: 28px;
  height: 28px;
  border: 1px solid var(--border-line);
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  transition: all var(--transition);
}
.pagination button:hover { background: var(--bg-elevated); color: var(--text-primary); }
.pagination button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-inverse);
}
.pagination button:disabled { opacity: 0.4; cursor: default; }

/* ============================================================
   杂项
   ============================================================ */

.text-mono { font-family: var(--font-mono); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-tertiary { color: var(--text-tertiary); }
.text-secondary { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.text-red { color: var(--signal-red); }
.text-amber { color: var(--signal-amber); }
.text-blue { color: var(--signal-blue); }

.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.w-full { width: 100%; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }

.fade-in {
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.stagger > * {
  animation: fadeIn 0.3s ease both;
}
.stagger > *:nth-child(1) { animation-delay: 0.02s; }
.stagger > *:nth-child(2) { animation-delay: 0.04s; }
.stagger > *:nth-child(3) { animation-delay: 0.06s; }
.stagger > *:nth-child(4) { animation-delay: 0.08s; }
.stagger > *:nth-child(5) { animation-delay: 0.10s; }
.stagger > *:nth-child(6) { animation-delay: 0.12s; }
.stagger > *:nth-child(7) { animation-delay: 0.14s; }
.stagger > *:nth-child(8) { animation-delay: 0.16s; }
