/* Gate Evolution — 精简版样式 (暗色模式默认) */

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --bg-card-hover: #1a4a7a;
  --bg-header: #0a0a1a;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0b0;
  --text-muted: #6a6a80;
  --accent: #00d4aa;
  --accent-dim: rgba(0, 212, 170, 0.15);
  --border: #2a2a4a;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 0.2s ease;
  --font-sans: "Inter", "SF PRO Display", -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  --max-width: 1400px;
  --header-height: 56px;
}

[data-theme="light"] {
  --bg-primary: #f5f6fa;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f4ff;
  --bg-header: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #555570;
  --text-muted: #8888a0;
  --border: #e0e0ee;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --accent-dim: rgba(0, 212, 170, 0.1);
}

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

html { font-size: 15px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit; font-size: inherit;
  cursor: pointer; border: none; background: none; color: inherit;
}

input, select {
  font-family: inherit; font-size: inherit;
  color: inherit; background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px; outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ---------- 布局 ---------- */
#app {
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 100vh;
}

/* ---------- 顶部导航 ---------- */
.app-header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  height: var(--header-height);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.header-left, .header-right { display: flex; align-items: center; gap: 12px; }

.logo { display: flex; align-items: center; gap: 8px; font-size: 1.1rem; font-weight: 700; }

.logo-icon { font-size: 1.4rem; color: var(--accent); }

.logo-text {
  background: linear-gradient(135deg, var(--accent), #4fc3f7);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

.header-status { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--text-muted); }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); animation: pulse 2s ease-in-out infinite;
}
.status-dot.error { background: #ff5252; animation: none; }
.status-dot.loading { background: #ffc107; animation: pulse 1s ease-in-out infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ---------- 按钮 ---------- */
.btn-icon { padding: 8px; border-radius: 50%; }
.btn-icon:hover { background: var(--accent-dim); }
.btn-icon svg { transition: transform var(--transition); }
.btn-icon:active svg { transform: rotate(180deg); }

/* ---------- 主体 ---------- */
.app-main {
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}

/* ---------- 工具栏 ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.toolbar-group {
  display: flex; flex-direction: column; gap: 4px;
  flex: 1; min-width: 150px;
}

.search-group { flex: 2; min-width: 200px; }

.toolbar-label {
  font-size: 0.75rem; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}

.form-select {
  background: var(--bg-card);
  color: var(--text-primary);
  width: 100%; max-width: 220px;
}

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.search-box svg { color: var(--text-muted); flex-shrink: 0; }
.search-box input { border: none; padding: 0; flex: 1; font-size: 0.9rem; }
.search-box input::placeholder { color: var(--text-muted); }

/* ---------- 统计栏 ---------- */
.stats-bar {
  display: flex; flex-wrap: wrap; gap: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.stat-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  flex: 1; min-width: 80px; padding: 4px 8px;
}

.stat-value {
  font-size: 1.3rem; font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.03em;
}

/* ---------- 节点列表 ---------- */
.nodes-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.nodes-loading, .nodes-empty, .nodes-error {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px 16px; gap: 12px;
  color: var(--text-muted);
}

.nodes-loading p, .nodes-empty p, .nodes-error p { font-size: 0.9rem; }

.loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 表格 (8 列) ---------- */
.nodes-table { display: flex; flex-direction: column; gap: 2px; }

.nodes-table-header, .node-row {
  display: grid;
  grid-template-columns: 36px 1.5fr 90px 55px 50px 75px 1fr 70px;
  gap: 4px;
  align-items: center;
}

.nodes-table-header {
  padding: 8px 10px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: calc(var(--header-height) + 8px);
  z-index: 10;
}

.nodes-table-body { display: flex; flex-direction: column; gap: 2px; }

.node-row {
  padding: 8px 10px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  transition: background var(--transition), box-shadow var(--transition);
}

.node-row:hover {
  background: var(--bg-card-hover);
  box-shadow: var(--shadow);
}

.cell {
  display: flex; align-items: center; gap: 6px;
  min-width: 0; overflow: hidden;
}

/* 排名 */
.cell-rank {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-align: center;
}
.cell-rank.top { color: var(--accent); }

/* 国家 */
.cell-country { display: flex; align-items: center; gap: 8px; font-weight: 500; }

.flag {
  width: 18px; height: 14px;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* IP */
.cell-ip {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* 会话人数 */
.cell-sessions {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: center;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.82rem;
}

.cell-sessions.high { background: rgba(255, 82, 82, 0.15); color: #ff5252; }
.cell-sessions.medium { background: rgba(255, 193, 7, 0.15); color: #ffc107; }
.cell-sessions.low { background: rgba(0, 212, 170, 0.15); color: var(--accent); }

/* 延迟 */
.cell-ping {
  font-variant-numeric: tabular-nums;
  text-align: center;
  font-weight: 600;
  font-size: 0.82rem;
}

.cell-ping.excellent { color: var(--accent); }
.cell-ping.good { color: #4fc3f7; }
.cell-ping.fair { color: #ffc107; }
.cell-ping.poor { color: #ff5252; }

/* 速度 */
.cell-speed {
  font-variant-numeric: tabular-nums;
  text-align: center;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-primary);
}

/* 服务商 */
.cell-operator {
  font-size: 0.78rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 操作按钮 */
.cell-actions {
  display: flex; gap: 4px; justify-content: flex-end;
}

.btn-copy {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-copy:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.btn-copy.copied { color: var(--accent); border-color: var(--accent); }

.btn-copy svg { flex-shrink: 0; }

/* ---------- 页脚 ---------- */
.app-footer {
  padding: 12px 16px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.app-footer a { color: var(--accent); font-weight: 500; }
.footer-disclaimer { margin-top: 4px; font-size: 0.7rem; }

/* ---------- 诊断栏 ---------- */
.diag-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.diag-icon { color: var(--accent); font-weight: 700; }

/* ---------- Toast ---------- */
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}

.toast {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 0.82rem;
  color: var(--text-primary);
  animation: toast-in 0.3s ease;
}

.toast.error { border-color: #ff5252; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  html { font-size: 13px; }
  .app-header { padding: 0 12px; }
  .app-main { padding: 10px; }
  .toolbar { padding: 10px; gap: 8px; }
  .toolbar-group { min-width: 120px; }
  .form-select { max-width: none; }
  .nodes-section { padding: 10px; }

  .nodes-table-header, .node-row {
    grid-template-columns: 30px 1.4fr 75px 45px 45px 55px 0.8fr 60px;
    gap: 2px;
    padding: 6px 6px;
  }

  .cell { font-size: 0.75rem; gap: 4px; }
  .cell-rank { font-size: 0.7rem; }
}

@media (max-width: 600px) {
  .app-header { padding: 0 10px; height: 48px; }
  .header-status { display: none; }
  .logo-text { font-size: 0.95rem; }
  .toolbar { flex-direction: column; padding: 8px; }
  .toolbar-group, .search-group { min-width: 100%; }
  .stats-bar { gap: 4px; padding: 8px; }
  .stat-item { min-width: 60px; padding: 4px; }
  .stat-value { font-size: 1rem; }
  .stat-label { font-size: 0.6rem; }

  .nodes-table-header, .node-row {
    grid-template-columns: 28px 1.3fr 70px 40px 40px 50px 0.7fr 55px;
    gap: 2px;
    padding: 5px 5px;
  }

  .cell { font-size: 0.72rem; gap: 3px; }

  .btn-copy {
    padding: 3px 6px;
    font-size: 0.68rem;
  }
}

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- 主题图标 ---------- */
#icon-sun, #icon-moon { transition: opacity var(--transition); }
[data-theme="light"] #icon-sun { display: block; }
[data-theme="light"] #icon-moon { display: none; }
[data-theme="dark"] #icon-sun { display: none; }
[data-theme="dark"] #icon-moon { display: block; }
