:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #6c7293;
  --border: #e4e6ef;
  --primary: #3366ff;
  --primary-light: #eef2ff;
  --success: #0bb783;
  --success-light: #e8fff3;
  --warning: #ffa800;
  --warning-light: #fff8dd;
  --danger: #f64e60;
  --danger-light: #ffe2e5;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ---- 顶栏 ---- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.refresh-hint {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ---- 按钮 ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:hover { background: var(--bg); }
.btn:active { transform: scale(0.98); }
.btn-sm { padding: 5px 12px; font-size: 12px; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: #2952cc; }

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}
.btn-success:hover { background: #099a6e; }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger-light); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- 容器 ---- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* ---- 概览统计 ---- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.stat-online .stat-value { color: var(--success); }
.stat-auto .stat-value { color: var(--primary); }
.stat-warn .stat-value { color: var(--warning); }

/* ---- 区块 ---- */
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.section-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-header h2 {
  font-size: 15px;
  font-weight: 600;
}

/* ---- 用户列表 ---- */
.user-list {
  min-height: 200px;
}

.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

/* 用户行 */
.user-row {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.user-row:last-child { border-bottom: none; }
.user-row:hover { background: #fafbfe; }

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  overflow: hidden;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-company {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* 标签 */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.tag-success { background: var(--success-light); color: var(--success); }
.tag-danger { background: var(--danger-light); color: var(--danger); }
.tag-primary { background: var(--primary-light); color: var(--primary); }
.tag-warning { background: var(--warning-light); color: var(--warning); }
.tag-muted { background: var(--bg); color: var(--text-secondary); }

/* 状态列 */
.user-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  min-width: 140px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 自动化列 */
.user-automation {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 180px;
}

.auto-stats {
  font-size: 12px;
  color: var(--text-secondary);
}

.auto-time {
  font-size: 11px;
  color: var(--text-secondary);
}

/* 操作列 */
.user-actions {
  display: flex;
  gap: 8px;
  min-width: 160px;
  justify-content: flex-end;
}

/* ---- 指示灯 ---- */
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-green { background: var(--success); box-shadow: 0 0 6px rgba(11,183,131,0.4); }
.dot-red { background: var(--danger); }
.dot-gray { background: #ccc; }
.dot-blue { background: var(--primary); box-shadow: 0 0 6px rgba(51,102,255,0.3); }

/* ---- 弹窗 ---- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  width: 600px;
  max-width: 92vw;
  max-height: 94vh;
  overflow: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 20px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: var(--bg); }

.modal-body {
  padding: 18px 20px;
}

/* 表单样式 */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-input {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 10px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  width: 100%;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(51,102,255,0.1);
}

.form-input-sm {
  width: 100px;
}

.form-hint {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.form-sep {
  color: var(--text-secondary);
  font-size: 13px;
}

/* 开关 */
.switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input { display: none; }

.switch-slider {
  position: absolute;
  inset: 0;
  background: #ddd;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.switch-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}

.switch input:checked + .switch-slider {
  background: var(--primary);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(20px);
}

/* 策略按钮组 */
.strategy-group {
  display: flex;
  gap: 6px;
}

.strategy-btn {
  flex: 1;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.strategy-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* 运行状态详情 */
.runtime-info {
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 12px;
}

.runtime-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 4px 0;
}

.runtime-row + .runtime-row {
  border-top: 1px solid var(--border);
}

.runtime-label {
  color: var(--text-secondary);
}

.runtime-value {
  font-weight: 500;
}

/* ---- 响应式 ---- */
@media (max-width: 768px) {
  .stats { grid-template-columns: repeat(2, 1fr); }

  .user-row {
    flex-wrap: wrap;
    gap: 10px;
  }

  .user-status,
  .user-automation,
  .user-actions {
    min-width: auto;
    align-items: flex-start;
  }

  .user-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .container { padding: 16px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 22px; }
}

/* ---- 日志面板 ---- */

.log-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.log-toolbar label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.log-container {
  height: 420px;
  overflow-y: auto;
  background: #1e1e2e;
  border-radius: 8px;
  padding: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #cdd6f4;
}

.log-line {
  white-space: pre-wrap;
  word-break: break-all;
  padding: 1px 0;
}

.log-error { color: #f38ba8; }
.log-warn { color: #fab387; }
.log-success { color: #a6e3a1; }
.log-info { color: #89b4fa; }

.log-ts {
  color: #6c7086;
  margin-right: 6px;
}

.log-mod {
  color: #94e2d5;
  margin-right: 6px;
}

.log-src-worker,
.log-src-server {
  display: inline-block;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  margin-right: 6px;
  vertical-align: middle;
}

.log-src-worker {
  background: #89b4fa;
  color: #1e1e2e;
}

.log-src-server {
  background: #a6e3a1;
  color: #1e1e2e;
}
