/* ==================== CSS 变量 & 主题 ==================== */
:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #a5b4fc;
  --primary-bg: #eef2ff;
  --primary-glow: rgba(99,102,241,.18);
  --success: #10b981;
  --success-bg: #d1fae5;
  --success-dark: #059669;
  --danger: #ef4444;
  --danger-bg: #fee2e2;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --bg: #f0f4f9;
  --bg-alt: #e8edf4;
  --card: #ffffff;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --radius-round: 24px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 14px rgba(0,0,0,.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  --nav-height: 60px;
  --transition: .2s cubic-bezier(.4,0,.2,1);
  --chart-grid: rgba(0,0,0,.06);
}

[data-theme="dark"] {
  --primary: #818cf8;
  --primary-dark: #6366f1;
  --primary-light: #a5b4fc;
  --primary-bg: #1e1b4b;
  --primary-glow: rgba(129,140,248,.15);
  --success: #34d399;
  --success-bg: #064e3b;
  --success-dark: #6ee7b7;
  --danger: #f87171;
  --danger-bg: #450a0a;
  --warning: #fbbf24;
  --warning-bg: #451a03;
  --bg: #0b1120;
  --bg-alt: #0f172a;
  --card: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow-md: 0 4px 14px rgba(0,0,0,.4);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
  --chart-grid: rgba(255,255,255,.08);
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  padding-top: var(--nav-height);
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

.container { max-width: 1280px; margin: 0 auto; padding: 0 20px; }

/* ==================== 导航栏 ==================== */
.navbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border-bottom: 1px solid var(--border);
  height: var(--nav-height);
  transition: background var(--transition), border-color var(--transition);
}
[data-theme="dark"] .navbar {
  background: rgba(15,23,42,.88);
}
.nav-inner {
  max-width: 1280px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 20px;
  height: 100%;
}
.nav-brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-svg { flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; }
.brand-title { font-weight: 700; font-size: 16px; color: var(--text); line-height: 1.3; }
.brand-subtitle { font-size: 10px; color: var(--text-muted); letter-spacing: .5px; text-transform: uppercase; }

.nav-toggle { display: none; background: none; border: none; cursor: pointer; padding: 6px 10px; border-radius: var(--radius-xs); color: var(--text); transition: background var(--transition); }
.nav-toggle:hover { background: var(--bg); }

.nav-stats {
  display: flex; align-items: center; gap: 18px;
  margin-left: auto;
}
.nav-stat-item { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.nav-stat-dot {
  width: 7px; height: 7px; border-radius: 50%; display: inline-block;
}
.nav-stat-dot.green { background: var(--success); box-shadow: 0 0 8px rgba(16,185,129,.5); }
.nav-stat-dot.red { background: var(--danger); box-shadow: 0 0 8px rgba(239,68,68,.4); }
.nav-stat-value { font-weight: 700; font-size: 14px; color: var(--text); }
.nav-stat-label { font-weight: 700; font-size: 14px; color: var(--text); }
.nav-stat-unit { font-size: 11px; color: var(--text-muted); }
.nav-stat-divider { width: 1px; height: 16px; background: var(--border); }

/* 脉冲动画 */
.pulse { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.45} }

/* ==================== 主内容 ==================== */
.main { padding: 24px 0 40px; }

/* ==================== 概览卡片 ==================== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--primary-light);
}
.stat-card-icon {
  width: 46px; height: 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  position: relative;
}
.stat-card-icon.blue { background: linear-gradient(135deg, #eef2ff, #e0e7ff); }
.stat-card-icon.green { background: linear-gradient(135deg, #d1fae5, #a7f3d0); }
.stat-card-icon.purple { background: linear-gradient(135deg, #f3e8ff, #ede9fe); }
.stat-card-icon.orange { background: linear-gradient(135deg, #fef3c7, #fde68a); }
[data-theme="dark"] .stat-card-icon.blue { background: linear-gradient(135deg, #1e1b4b, #312e81); }
[data-theme="dark"] .stat-card-icon.green { background: linear-gradient(135deg, #064e3b, #065f46); }
[data-theme="dark"] .stat-card-icon.purple { background: linear-gradient(135deg, #3b0764, #4c1d95); }
[data-theme="dark"] .stat-card-icon.orange { background: linear-gradient(135deg, #451a03, #78350f); }
[data-theme="dark"] .stat-card-icon svg { stroke: var(--text); }

/* QQ 统计卡片暗色模式 */
[data-theme="dark"] #qqStatsRow .stat-card:nth-child(1) { background: linear-gradient(135deg, #2d1b29, #1a0f1a) !important; }
[data-theme="dark"] #qqStatsRow .stat-card:nth-child(2) { background: linear-gradient(135deg, #2d1b3d, #1a0f2a) !important; }
[data-theme="dark"] #qqStatsRow .stat-card:nth-child(3) { background: linear-gradient(135deg, #0d2b1d, #0a1f15) !important; }
[data-theme="dark"] #qqStatsRow .stat-card:nth-child(4) { background: linear-gradient(135deg, #0d1b3d, #0a152a) !important; }
[data-theme="dark"] #qqStatsRow .stat-card-icon { background: var(--card) !important; }
[data-theme="dark"] #qqChartSection .card-title svg { stroke: #f472b6 !important; }

/* QQ 图表暗色适配 */
[data-theme="dark"] #qqChartSection { border-color: rgba(244,114,182,.2); }

.stat-card-body { min-width: 0; }
.stat-card-value {
  font-size: 24px; font-weight: 800;
  color: var(--text); line-height: 1.2;
  letter-spacing: -.5px;
}
.stat-card-value small { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.stat-card-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; font-weight: 500; }

/* ==================== 通用卡片 ==================== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: box-shadow var(--transition), border-color var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  margin-bottom: 6px;
}
.card-title { font-size: 17px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; }
.card-desc { font-size: 12px; color: var(--text-muted); margin-bottom: 20px; }
.card-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 12px;
  border-radius: var(--radius-round); font-size: 12px; font-weight: 600;
  background: var(--primary-bg); color: var(--primary);
}
.card-badge.secondary { background: var(--bg); color: var(--text-secondary); }
.card-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.card-action-hint { font-size: 11px; color: var(--text-muted); }

/* 算法选择器下拉 */
.algo-selector { width: auto; padding: 5px 12px; font-size: 13px; min-width: 100px; }

/* ==================== 算法卡片 ==================== */
.algo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.algo-card {
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.algo-card:hover {
  border-color: var(--primary);
  background: var(--primary-bg);
  transform: translateY(-1px);
}
.algo-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
[data-theme="dark"] .algo-card.active { background: rgba(129,140,248,.08); }
[data-theme="light"] .algo-card.active { background: var(--primary-bg); }
.algo-card-icon { font-size: 22px; margin-bottom: 6px; }
.algo-card-name { font-weight: 700; font-size: 14px; color: var(--text); margin-bottom: 2px; }
.algo-card-desc { font-size: 11px; color: var(--text-muted); line-height: 1.4; }
.algo-card-check {
  position: absolute; top: 6px; right: 6px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: none; align-items: center; justify-content: center;
  font-size: 10px; line-height: 1;
}
.algo-card.active .algo-card-check { display: flex; }

/* ==================== 图表 ==================== */
.chart-wrapper {
  position: relative;
  width: 100%;
  height: 260px;
  margin-top: 8px;
}
.chart-wrapper canvas { width: 100% !important; height: 100% !important; }
.chart-legend { display: flex; gap: 16px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-muted); }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

/* ==================== 按钮 ==================== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border: none; border-radius: var(--radius-xs);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all var(--transition); font-family: var(--font);
  line-height: 1.4; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 14px var(--primary-glow); }
.btn-secondary { background: var(--bg-alt); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(239,68,68,.25); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-xs { padding: 3px 10px; font-size: 11px; border-radius: 4px; }
.btn-icon { background: none; border: none; cursor: pointer; padding: 6px; font-size: 15px; border-radius: var(--radius-xs); transition: all var(--transition); color: var(--text-secondary); display: inline-flex; align-items: center; justify-content: center; }
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* 主题切换按钮 */
.btn-theme { position: relative; width: 34px; height: 34px; }
.theme-sun, .theme-moon { position: absolute; transition: opacity .3s, transform .3s; }
[data-theme="dark"] .theme-sun { opacity: 1; transform: rotate(0); }
[data-theme="dark"] .theme-moon { opacity: 0; transform: rotate(90deg); }
[data-theme="light"] .theme-sun { opacity: 0; transform: rotate(-90deg); }
[data-theme="light"] .theme-moon { opacity: 1; transform: rotate(0); }

/* ==================== 表单 ==================== */
.add-backend-form, .add-group-form, .add-rule-form {
  background: var(--bg-alt);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}
.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.form-group { flex: 1; min-width: 140px; }
.form-group-sm { flex: 0 0 110px; min-width: 90px; }
.form-group-btn { flex: 0 0 auto; min-width: auto; }
.form-group label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--text-secondary); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .3px;
}
.form-input {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-xs);
  font-size: 13px; color: var(--text);
  background: var(--card); outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: var(--font);
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.form-input.disabled { background: var(--bg); color: var(--text-muted); }
.form-hint { display: block; font-size: 10px; color: var(--text-muted); margin-top: 3px; }
select.form-input { cursor: pointer; appearance: auto; }

/* ==================== frpc 配置面板 ==================== */
.frpc-layout {
  display: flex; gap: 20px; margin-bottom: 20px;
  align-items: stretch;
}
.frpc-info {
  flex: 0 0 340px;
  background: var(--bg); border-radius: var(--radius-sm); padding: 18px;
  display: flex; flex-direction: column; gap: 14px;
  border: 1px solid var(--border);
}
.frpc-info-header {
  font-size: 12px; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .4px;
  display: flex; align-items: center; gap: 6px;
}
.frpc-fields { display: flex; flex-direction: column; gap: 12px; }

.frpc-commands {
  flex: 1;
  background: var(--bg); border-radius: var(--radius-sm); padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
  border: 1px solid var(--border);
}
.frpc-commands-header {
  display: flex; align-items: flex-start; gap: 8px;
}
.frpc-commands-header svg { margin-top: 1px; flex-shrink: 0; stroke: var(--text-secondary); }
.frpc-commands-title {
  font-size: 12px; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .4px;
}
.frpc-commands-sub { font-size: 10px; color: var(--text-muted); margin-top: 1px; }

.cmd-block { display: flex; flex-direction: column; gap: 6px; }
.cmd-block-title {
  display: flex; align-items: center; justify-content: space-between;
}
.cmd-label { font-size: 11px; color: var(--text-secondary); }
.cmd-pre {
  background: #0f172a; color: #e2e8f0;
  border-radius: var(--radius-xs); padding: 12px 14px;
  font-size: 12px; font-family: monospace;
  white-space: pre-wrap; word-break: break-all;
  margin: 0; line-height: 1.6;
}
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); padding: 2px 10px; font-size: 11px; border-radius: 4px; cursor: pointer; transition: all var(--transition); font-family: var(--font); font-weight: 500; }
.btn-ghost:hover { background: var(--border); color: var(--text); }
[data-theme="dark"] .cmd-pre { background: #020617; }

.section-title {
  font-size: 14px; font-weight: 700; margin-bottom: 10px;
  display: flex; align-items: center; gap: 6px; color: var(--text);
}

/* ==================== 表格 ==================== */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}
.table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 13px;
}
.table th {
  text-align: left; padding: 10px 12px;
  font-weight: 600; color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  position: sticky; top: 0; background: var(--card); z-index: 1;
}
.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--bg); }

/* 状态标签 */
.status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 10px; border-radius: var(--radius-round);
  font-size: 11px; font-weight: 600;
}
.status-badge.online { background: var(--success-bg); color: var(--success-dark); }
.status-badge.offline { background: var(--danger-bg); color: #991b1b; }
.status-dot {
  width: 6px; height: 6px; border-radius: 50%; display: inline-block;
}
.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--danger); }

/* 类型徽标 */
.type-badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 8px; border-radius: 4px;
  font-size: 10px; font-weight: 600; white-space: nowrap;
}
.type-badge.tunnel { background: #f3e8ff; color: #6b21a8; }
.type-badge.http { background: #dbeafe; color: #1d4ed8; }

/* 方法标签 */
.method-badge {
  display: inline-block; padding: 1px 8px; border-radius: 4px;
  font-size: 10px; font-weight: 700; font-family: monospace;
}
.method-badge.get { background: #dbeafe; color: #1d4ed8; }
.method-badge.post { background: var(--success-bg); color: #065f46; }
.method-badge.put { background: var(--warning-bg); color: #92400e; }
.method-badge.delete { background: var(--danger-bg); color: #991b1b; }
.method-badge.agent { background: #f3e8ff; color: #6b21a8; }

/* 状态码 */
.status-code { font-weight: 700; font-family: monospace; font-size: 11px; }
.status-code.success { color: var(--success); }
.status-code.error { color: var(--danger); }
.status-code.redirect { color: var(--warning); }

/* 标签编辑 */
.tag-display {
  display: inline-flex; align-items: center; gap: 4px;
  cursor: pointer; padding: 2px 6px; border-radius: 4px;
  transition: background var(--transition);
}
.tag-display:hover { background: var(--bg); }
.tag-text { max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-edit-icon { font-size: 11px; opacity: 0.3; transition: opacity var(--transition); }
.tag-display:hover .tag-edit-icon { opacity: 1; }

.table-empty { text-align: center; padding: 36px 20px; }
.empty-icon { margin-bottom: 10px; display: inline-flex; }
.empty-icon svg { stroke: var(--text-muted); opacity: .4; }
.empty-text { color: var(--text-muted); font-size: 13px; }

/* 日志表格 */
.table-logs { font-size: 12px; }
.table-logs th { font-size: 10px; }
.table-logs td { padding: 6px 10px; }
.logs-wrapper {
  max-height: 420px; overflow-y: auto;
  margin: 0 -24px; padding: 0 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.logs-wrapper::-webkit-scrollbar { width: 5px; }
.logs-wrapper::-webkit-scrollbar-track { background: transparent; }
.logs-wrapper::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ==================== Toast 通知 ==================== */
.toast-container {
  position: fixed; top: 16px; right: 16px; z-index: 99999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  color: var(--text);
  min-width: 240px;
  max-width: 380px;
  animation: toastIn .25s ease;
  transition: opacity .2s, transform .2s;
}
.toast.removing { opacity: 0; transform: translateX(30px); }
.toast-icon { flex-shrink: 0; font-size: 16px; line-height: 1; }
.toast-message { flex: 1; word-break: break-word; }
.toast-close { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 16px; padding: 0 2px; line-height: 1; }
.toast-close:hover { color: var(--text); }

.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info .toast-icon { color: var(--primary); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ==================== 弹窗 ==================== */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--card); border-radius: var(--radius);
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 24px 0;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-muted); padding: 0 4px; line-height: 1; transition: color var(--transition); }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 16px 24px; }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 0 24px 20px;
}

/* ==================== 底部 ==================== */
.footer {
  border-top: 1px solid var(--border);
  padding: 20px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  transition: border-color var(--transition);
}

/* ==================== 动画 ==================== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.stats-row .stat-card { animation: fadeIn .4s ease forwards; }
.stats-row .stat-card:nth-child(1) { animation-delay: 0s; }
.stats-row .stat-card:nth-child(2) { animation-delay: .05s; }
.stats-row .stat-card:nth-child(3) { animation-delay: .1s; }
.stats-row .stat-card:nth-child(4) { animation-delay: .15s; }

/* 优雅的进入动画 */
.card {
  animation: cardFadeIn .45s cubic-bezier(.16,1,.3,1) both;
}
.card:nth-child(2) { animation-delay: .06s; }
.card:nth-child(3) { animation-delay: .12s; }
.card:nth-child(4) { animation-delay: .18s; }
.card:nth-child(5) { animation-delay: .24s; }
.card:nth-child(6) { animation-delay: .3s; }
.card:nth-child(7) { animation-delay: .36s; }
.card:nth-child(8) { animation-delay: .42s; }
.card:nth-child(9) { animation-delay: .48s; }

@keyframes cardFadeIn {
  from { opacity: 0; transform: translateY(20px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes highlightRow {
  from { background: var(--primary-bg); }
  to { background: transparent; }
}
.log-row-new { animation: highlightRow 1.5s ease; }

/* 悬停微动效 */
.stat-card, .algo-card, .group-card, .rule-item, .config-panel, .frpc-info, .frpc-commands {
  transition: all .25s cubic-bezier(.16,1,.3,1);
}

/* 弹窗 */
@keyframes modalIn {
  from { opacity: 0; transform: scale(.94) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes modalOverlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal-overlay.show { animation: modalOverlayIn .2s ease; }
.modal { animation: modalIn .25s cubic-bezier(.16,1,.3,1); }

/* 脉冲状态指示灯 */
.pulse { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.45} }

/* 悬浮提示淡入 */
@keyframes tooltipIn {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 表单切换平滑 */
.add-backend-form, .add-group-form, .add-rule-form {
  transition: all .3s cubic-bezier(.16,1,.3,1);
  overflow: hidden;
}

/* 数字变化动画 */
.stat-card-value {
  transition: color .3s;
}
.stat-card-value.changed {
  color: var(--primary);
}

/* ==================== 登录页 ==================== */
.login-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  display: flex; align-items: center; justify-content: center; z-index: 9999;
  padding: 20px;
}
.login-card {
  background: rgba(255,255,255,.98);
  border-radius: 20px; padding: 44px 36px; width: 380px; max-width: 100%;
  box-shadow: 0 25px 80px rgba(0,0,0,.5);
  text-align: center;
  animation: modalIn .3s ease;
}
.login-icon { margin-bottom: 14px; display: flex; justify-content: center; }
.login-title { font-size: 22px; font-weight: 700; color: #0f172a; margin: 0 0 4px; }
.login-subtitle { font-size: 13px; color: var(--text-muted); margin: 0 0 24px; }
.login-input { margin-bottom: 16px; font-size: 15px; padding: 12px 16px; width: 100%; box-sizing: border-box; border-radius: 10px; border: 2px solid var(--border); transition: border-color var(--transition), box-shadow var(--transition); }
.login-input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-glow); }
.login-error { background: var(--danger-bg); color: #dc2626; padding: 10px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 16px; }
.login-btn { width: 100%; padding: 12px; font-size: 16px; font-weight: 700; border-radius: 10px; letter-spacing: 1px; }
.login-hint { font-size: 11px; color: var(--text-muted); margin: 20px 0 0; }

/* ==================== 分组管理 ==================== */
.group-card {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 16px; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.group-card:hover { border-color: var(--primary-light); box-shadow: 0 2px 8px var(--primary-glow); }
.group-card:last-child { margin-bottom: 0; }
.group-card-info { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.group-card-name { font-weight: 700; font-size: 14px; }
.group-card-algo {
  display: inline-block; padding: 2px 10px; border-radius: var(--radius-round);
  font-size: 11px; font-weight: 600;
  background: var(--primary-bg); color: var(--primary);
}
.group-card-desc { font-size: 11px; color: var(--text-muted); }
.group-card-count { font-size: 11px; color: var(--text-muted); }

/* ==================== 路由规则 ==================== */
.rule-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 6px;
  transition: border-color var(--transition);
}
.rule-item:hover { border-color: var(--primary-light); }
.rule-item:last-child { margin-bottom: 0; }
.rule-item-left {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.rule-item-right {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.rule-path {
  font-family: monospace; font-size: 13px; font-weight: 700; color: var(--primary);
  background: var(--primary-bg); padding: 2px 8px; border-radius: 4px;
  white-space: nowrap;
}
.rule-arrow { color: var(--text-muted); font-size: 13px; }
.rule-group { font-weight: 600; font-size: 12px; white-space: nowrap; }
.rule-priority { font-size: 10px; color: var(--text-muted); }
.rule-tag {
  display: inline-flex; align-items: center; padding: 2px 10px;
  border-radius: 10px; font-size: 10px; font-weight: 600; white-space: nowrap;
}
.rule-tag-prefix { background: var(--primary-bg); color: var(--primary); }
.rule-tag-query { background: #f3e8ff; color: #6b21a8; }
.rule-tag-json { background: #fef3c7; color: #92400e; }

/* ==================== 设置表单 ==================== */
.settings-form { margin-top: 8px; }
.settings-form .form-row { align-items: flex-end; }
#settingsStatus { transition: opacity .3s; }

/* ==================== 分组徽标 ==================== */
.group-badge {
  display: inline-block; padding: 1px 8px; border-radius: 4px;
  font-size: 10px; font-weight: 600;
  background: #f0fdf4; color: #166534;
}
.group-badge.api { background: #dbeafe; color: #1e40af; }
.group-badge.static { background: #fef3c7; color: #92400e; }
.group-badge.default { background: var(--bg); color: var(--text-muted); }

/* ==================== 空状态 ==================== */
.empty-state { text-align: center; padding: 20px; color: var(--text-muted); font-size: 13px; }

/* ==================== 滚动条美化 ==================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ==================== 自适应 ==================== */
@media (max-width: 1100px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .frpc-layout { flex-direction: column; }
  .frpc-info { flex: none; width: 100%; }
}

@media (max-width: 900px) {
  .algo-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .container { padding: 0 12px; }
  .main { padding: 12px 0 24px; }

  .nav-toggle { display: block; }
  .nav-stats {
    display: none;
    position: absolute; top: var(--nav-height); left: 0; right: 0;
    flex-direction: column; gap: 0;
    background: var(--card); border-bottom: 1px solid var(--border);
    padding: 12px 20px;
    box-shadow: var(--shadow-md);
  }
  .nav-stats.open { display: flex; }
  .nav-stat-item { width: 100%; padding: 8px 0; }
  .nav-stat-divider { display: none; }
  .nav-stat-value { font-size: 15px; }

  .stats-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px 16px; gap: 12px; }
  .stat-card-icon { width: 38px; height: 38px; border-radius: 10px; }
  .stat-card-value { font-size: 20px; }
  .stat-card-label { font-size: 11px; }

  .card { padding: 16px; }
  .card-title { font-size: 15px; }
  .card-desc { font-size: 11px; margin-bottom: 12px; }

  .algo-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .algo-card { padding: 12px; }
  .algo-card-icon { font-size: 18px; }
  .algo-card-name { font-size: 13px; }
  .algo-card-desc { display: none; }

  .chart-wrapper { height: 200px; }

  .form-row { flex-direction: column; gap: 8px; }
  .form-group { min-width: 0; width: 100%; }
  .form-group-sm { flex: 1; min-width: 0; width: 100%; }
  .form-group-btn { width: 100%; }
  .form-group-btn .btn { flex: 1; justify-content: center; }

  .table th, .table td { padding: 8px 8px; }
  .table-logs th:nth-child(4), .table-logs td:nth-child(4) { display: none; }
  .table-logs th:nth-child(5), .table-logs td:nth-child(5) { display: none; }

  .logs-wrapper { max-height: 280px; margin: 0 -16px; padding: 0 16px; }

  .card-actions { flex-direction: column; align-items: flex-start; gap: 8px; }
  .chart-legend { gap: 8px; }

  .login-card { padding: 32px 24px; }
  .login-title { font-size: 18px; }
  .login-icon svg { width: 36px; height: 36px; }

  .frpc-layout { flex-direction: column; }
  .frpc-info { flex: none; width: 100%; }

  .rule-item { flex-wrap: wrap; }
  .rule-item-left, .rule-item-right { width: 100%; }
  .rule-item-right { justify-content: flex-start; }
}

@media (max-width: 480px) {
  .container { padding: 0 8px; }

  .stats-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-card-icon { width: 34px; height: 34px; border-radius: 8px; }
  .stat-card-value { font-size: 17px; }
  .stat-card-label { font-size: 10px; }

  .card { padding: 12px; }
  .card-title { font-size: 14px; }

  .algo-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .algo-card { padding: 10px; }
  .algo-card-name { font-size: 12px; }

  .chart-wrapper { height: 160px; }

  .table { font-size: 12px; }
  .table th, .table td { padding: 6px 6px; }
  .table-logs th:nth-child(8), .table-logs td:nth-child(8) { display: none; }

  .brand-subtitle { display: none; }

  .logs-wrapper { max-height: 240px; }

  .login-card { padding: 28px 20px; border-radius: 16px; }
  .login-title { font-size: 17px; }
}

/* ==================== QQ 统计行自适应 ==================== */
#qqStatsRow .stat-card:nth-child(4) .stat-card-value {
  font-size: 18px;
}
#qqStatsRow .stat-card-icon svg {
  width: 20px; height: 20px;
}

/* ==================== Toggle 开关 ==================== */
.toggle-input { display: none; }
.toggle-slider {
  position: relative;
  width: 40px; height: 22px;
  background: var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: background var(--transition);
  flex-shrink: 0;
}
.toggle-slider::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.toggle-input:checked + .toggle-slider {
  background: var(--primary);
}
.toggle-input:checked + .toggle-slider::after {
  transform: translateX(18px);
}
.toggle-text {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ==================== QQ 统计卡片在移动端适配 ==================== */
@media (max-width: 768px) {
  #qqStatsRow { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  #qqStatsRow .stat-card-value { font-size: 15px; }
}
