:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.14);
  --orange: #f97316;
  --orange-bg: rgba(249, 115, 22, 0.16);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.18);
  --amber: #f59e0b;
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 12px var(--green);
}
.brand h1 { margin: 0; font-size: 18px; font-weight: 700; }
.subtitle { margin: 0; font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.sync-pill {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
}

.container { max-width: 1440px; margin: 0 auto; padding: 20px 24px 48px; }
.section { margin-bottom: 28px; }
.section-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.section-head h2 { margin: 0; font-size: 16px; font-weight: 600; }

.mode-legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--green); }
.dot-orange { background: var(--orange); }
.dot-red { background: var(--red); }

/* 告警横幅 */
.alert-banner {
  background: rgba(127, 29, 29, 0.32);
  border: 1px solid rgba(239, 68, 68, 0.55);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 24px;
}
.alert-banner-header {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.alert-banner-title { display: flex; align-items: center; gap: 8px; font-weight: 600; color: #fecaca; }
.alert-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.alert-item {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  background: rgba(15, 23, 42, 0.72); border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 8px; padding: 10px 12px;
}
.alert-item-title { font-weight: 600; font-size: 13px; color: #fee2e2; }
.alert-item-detail { font-size: 12px; color: #cbd5e1; white-space: pre-wrap; margin-top: 2px; }

/* 节点网格 */
.nodes-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.node-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; position: relative;
}
.node-card.offline { border-color: rgba(239, 68, 68, 0.65); }
.node-card.takeover {
  border-color: var(--red);
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.45), 0 0 24px rgba(239, 68, 68, 0.18);
}
.node-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.node-code { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.status-pill {
  font-size: 12px; padding: 3px 10px; border-radius: 999px; font-weight: 600;
}
.status-online { background: var(--green-bg); color: #86efac; border: 1px solid rgba(34, 197, 94, 0.4); }
.status-offline { background: var(--red-bg); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.5); }

.takeover-warning {
  margin: 8px 0; padding: 8px 10px; border-radius: 8px;
  background: var(--red-bg); border: 1px solid rgba(239, 68, 68, 0.6);
  color: #fecaca; font-size: 13px; font-weight: 600;
}

.kv-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 12px; font-size: 13px; margin-top: 10px; }
.kv-label { color: var(--muted); font-size: 12px; display: block; }

/* 项目卡片网格 */
.projects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.project-card {
  background: var(--surface); border: 1px solid var(--border);
  border-top: 4px solid var(--green);
  border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.project-card:hover { transform: translateY(-2px); border-color: #475569; }
.project-card.mode-api_background { border-top-color: var(--green); }
.project-card.mode-virtual_desktop { border-top-color: var(--orange); }
.project-card.mode-local_takeover { border-top-color: var(--red); }

.project-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.project-title { font-size: 16px; font-weight: 700; margin: 0; }
.project-code { font-size: 12px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }

.mode-badge {
  font-size: 11px; padding: 3px 8px; border-radius: 6px; font-weight: 600; white-space: nowrap;
}
.mode-badge.api_background { background: var(--green-bg); color: #86efac; }
.mode-badge.virtual_desktop { background: var(--orange-bg); color: #fdba74; }
.mode-badge.local_takeover { background: var(--red-bg); color: #fca5a5; }
.mode-badge.idle { background: rgba(148, 163, 184, 0.15); color: #cbd5e1; }

.progress-wrap { background: #0f172a; border-radius: 999px; height: 8px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); transition: width 0.25s ease; }
.progress-bar.success { background: var(--green); }
.progress-bar.failed { background: var(--red); }
.progress-bar.waiting_human { background: var(--amber); }

.project-footer {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  margin-top: auto; padding-top: 8px; border-top: 1px solid rgba(51, 65, 85, 0.65);
}

/* 表格 */
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow-x: auto;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  padding: 11px 12px; text-align: left; border-bottom: 1px solid rgba(51, 65, 85, 0.6);
}
.data-table th { color: var(--muted); font-weight: 600; background: rgba(15, 23, 42, 0.45); white-space: nowrap; }
.data-table tr:hover td { background: rgba(51, 65, 85, 0.28); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.badge-pending { background: rgba(148, 163, 184, 0.18); color: #e2e8f0; }
.badge-claimed { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.badge-running { background: rgba(14, 165, 233, 0.22); color: #7dd3fc; }
.badge-waiting_human { background: rgba(245, 158, 11, 0.24); color: #fde047; }
.badge-success { background: var(--green-bg); color: #86efac; }
.badge-failed, .badge-danger { background: var(--red-bg); color: #fca5a5; }
.badge-cancelled { background: rgba(100, 116, 139, 0.25); color: #cbd5e1; }

/* 表单与按钮 */
.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 7px 13px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.btn:hover { filter: brightness(1.1); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-danger { background: rgba(239, 68, 68, 0.2); border-color: rgba(239, 68, 68, 0.5); color: #fecaca; }
.btn-warn { background: rgba(245, 158, 11, 0.2); border-color: rgba(245, 158, 11, 0.5); color: #fde68a; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 9px; font-size: 12px; }

.select, .input, .textarea {
  background: #0f172a; color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 13px;
}
.input-group { display: flex; gap: 8px; align-items: center; }
.input-group .input { flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 12px; }
.code-textarea { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.error-text { color: #fca5a5; font-size: 13px; margin: 6px 0 0; }
.empty-card {
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: var(--radius); padding: 24px; text-align: center; color: var(--muted);
}

/* 弹窗 */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(2, 6, 23, 0.72);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  width: 100%; max-width: 560px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.modal-sm { max-width: 420px; }
.modal-lg { max-width: 760px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 18px; max-height: 75vh; overflow-y: auto; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 12px 18px; border-top: 1px solid var(--border);
}

/* 抽屉 */
.drawer { position: fixed; inset: 0; z-index: 40; display: flex; justify-content: flex-end; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(2, 6, 23, 0.65); }
.drawer-panel {
  position: relative; z-index: 1; width: min(680px, 100vw); height: 100%;
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.drawer-header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.drawer-header h3 { margin: 0 0 4px; font-size: 16px; }
.drawer-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.drawer-body h4 { margin: 18px 0 8px; font-size: 14px; color: #cbd5e1; }
.drawer-actions { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.detail-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 14px;
  background: #0f172a; padding: 12px; border-radius: 8px; font-size: 13px;
}
.human-box {
  background: rgba(245, 158, 11, 0.16); border: 1px solid rgba(245, 158, 11, 0.55);
  color: #fde68a; border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; font-size: 13px;
}
.code-box {
  background: #0b1120; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; font-size: 12px; overflow-x: auto; max-height: 220px;
  font-family: ui-monospace, Consolas, monospace; margin: 0;
}
.log-box {
  background: #0b1120; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-family: ui-monospace, Consolas, monospace; font-size: 12px;
  max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px;
}
.log-line { word-break: break-word; }
.log-level-info { color: #93c5fd; }
.log-level-warn { color: #fcd34d; }
.log-level-error { color: #fca5a5; }
.artifacts-list { display: flex; flex-direction: column; gap: 8px; }
.artifact-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: #0f172a; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-size: 13px;
}
.preview-img { max-width: 100%; max-height: 65vh; border-radius: 8px; border: 1px solid var(--border); }
