:root {
  --bg: #f0f2f5;
  --surface: #fff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --fail: #dc2626;
  --radius: 8px;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Microsoft YaHei UI", "PingFang SC", sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* —— 顶栏 —— */
.topbar {
  flex-shrink: 0;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.topbar-brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted);
}

.topbar-stats {
  flex: 1;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.topbar-stats .sep { margin: 0 10px; color: #d1d5db; }
.stat-ok { color: var(--ok); }
.stat-fail { color: var(--fail); }

.ver {
  font-size: 10px;
  color: #9ca3af;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: #f0fdf4;
  color: var(--ok);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid #bbf7d0;
}

.status-pill.running {
  background: #eff6ff;
  color: var(--primary);
  border-color: #bfdbfe;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.status-pill.running .status-dot {
  animation: blink 1.2s infinite;
}

@keyframes blink { 50% { opacity: 0.35; } }

/* —— 主区域 —— */
.main {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.pane-left {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  overflow: hidden;
}

.pane-right {
  width: 400px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.03);
}

/* —— 邀请码栏 —— */
.invite-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.invite-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.invite-label {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.invite-input {
  width: 160px;
  max-width: 28vw;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
}

.invite-input::placeholder {
  color: #9ca3af;
  font-weight: 400;
}

.invite-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

/* —— 左侧面板 —— */
.panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
}

.panel-grow {
  flex: 1;
}

.panel-log {
  flex-shrink: 0;
  height: 140px;
}

.panel-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  background: #f9fafb;
  border-bottom: 1px solid var(--line);
}

.panel-title { flex: 1; }

.table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  position: relative;
  padding: 0 12px 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

table.account-table {
  table-layout: fixed;
  width: 100%;
}

table.account-table col.col-account { width: 18%; }
table.account-table col.col-proxy { width: 14%; }
table.account-table col.col-status { width: 16%; }
table.account-table col.col-detail { width: 52%; }

table.account-table thead th {
  text-align: center;
  padding: 10px 12px;
  letter-spacing: 0.02em;
}

table.account-table tbody tr {
  height: 42px;
}

table.account-table tbody td {
  padding: 8px 14px;
  vertical-align: middle;
  border-bottom: 1px solid #f0f0f0;
}

table.account-table tbody tr:nth-child(even):not(.row-running):not(.row-ok):not(.row-fail) {
  background: #fafafa;
}

table.account-table tbody tr:hover {
  background: #f3f4f6;
}

table.account-table tbody tr.row-running:hover { background: #e0edff; }
table.account-table tbody tr.row-ok:hover { background: #e6f9ed; }
table.account-table tbody tr.row-fail:hover { background: #fde8e8; }

.cell-account {
  text-align: center;
  font-weight: 600;
  color: #374151;
  font-variant-numeric: tabular-nums;
}

.cell-proxy {
  text-align: center;
  font-size: 10px;
  color: #6b7280;
  word-break: break-all;
  line-height: 1.35;
}

.cell-status {
  text-align: center;
}

.cell-detail {
  text-align: left;
  font-size: 11px;
  color: #6b7280;
  word-break: break-word;
  line-height: 1.45;
}

th, td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f9fafb;
  font-size: 11px;
  font-weight: 600;
  color: #4b5563;
}

.row-running { background: #eff6ff; }
.row-ok { background: #f0fdf4; }
.row-fail { background: #fef2f2; }

.table-pager {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 10px;
  border-top: 1px solid var(--line);
  background: #f9fafb;
  font-size: 12px;
}

.table-pager.hidden {
  display: none;
}

.pager-info {
  color: #4b5563;
  min-width: 160px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.empty-hint {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

.empty-hint.visible {
  display: flex;
}

.log-box {
  flex: 1;
  margin: 0;
  padding: 8px 12px;
  overflow: auto;
  font-family: Consolas, "Microsoft YaHei UI", monospace;
  font-size: 11px;
  line-height: 1.45;
  background: #fafafa;
  border: none;
  white-space: pre-wrap;
  word-break: break-all;
}

.muted { color: var(--muted); font-size: 12px; }

/* —— 右侧配置 —— */
.config-tabs {
  display: flex;
  flex-shrink: 0;
  padding: 8px 8px 0;
  gap: 4px;
  background: #f3f4f6;
  border-bottom: 1px solid var(--line);
}

.config-tab {
  flex: 1;
  padding: 10px 0;
  border: none;
  border-radius: 6px 6px 0 0;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.config-tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.6); }

.config-tab.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 -1px 0 var(--surface);
}

.config-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  min-height: 0;
}

.page-tab { display: none; }
.page-tab.active { display: block; }

.block {
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}

.block:last-child { margin-bottom: 0; }

.block-title {
  font-size: 12px;
  font-weight: 700;
  color: #374151;
  margin-bottom: 8px;
}

.hint {
  font-size: 11px;
  color: var(--muted);
  margin: 6px 0 0;
  line-height: 1.4;
}

.hint.center { text-align: center; }

.mt-sm { margin-top: 8px; }

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #4b5563;
}

.field-stack > span { font-weight: 500; }

.inline-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.inline-row select { flex: 1; min-width: 0; }

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

.check-row label { cursor: pointer; }

.check-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin-top: 10px;
}

.proxy-test-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.proxy-test-result {
  flex: 1;
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
}

textarea, input[type="text"], input[type="number"], select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
}

textarea {
  resize: vertical;
  min-height: 64px;
  font-family: Consolas, inherit;
  font-size: 12px;
}

textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

/* —— 按钮 —— */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { background: #f3f4f6; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: #4b5563;
}

.btn-ghost:hover { background: #f3f4f6; border-color: var(--line); }

.btn-xs { padding: 3px 10px; font-size: 11px; }

.btn-sm { padding: 6px 12px; font-size: 12px; }

.btn-block { width: 100%; margin-top: 4px; }

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

.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

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

.btn-stop {
  flex: 0 0 auto;
  padding: 10px 16px;
  background: #f3f4f6;
  font-weight: 500;
}

.action-bar {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: #fafafa;
}

.btn-action {
  flex: 1;
  padding: 11px 8px;
  font-weight: 600;
  font-size: 13px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.badge-running { background: #dbeafe; color: #1d4ed8; }
.badge-ok { background: #d1fae5; color: #047857; }
.badge-fail { background: #fee2e2; color: #b91c1c; }
.badge-idle { background: #e5e7eb; color: #6b7280; }

.toast-host {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.toast-error { background: #b91c1c; }
.toast-success { background: #047857; }
.toast-info { background: #1d4ed8; }

@media (max-width: 900px) {
  html, body { overflow: auto; }
  .app { height: auto; min-height: 100vh; }
  .main { flex-direction: column; }
  .pane-right { width: 100%; min-height: 420px; }
  .panel-log { height: 160px; }
}
