/* ===== CSS Variables ===== */
:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-card: #1e2131;
  --bg-card-hover: #252840;
  --border-color: #2a2d3e;
  --text-primary: #e8eaed;
  --text-secondary: #9aa0b0;
  --text-muted: #5f6578;
  --accent-blue: #4a9eff;
  --accent-green: #34d399;
  --accent-yellow: #fbbf24;
  --accent-red: #ef4444;
  --accent-purple: #a78bfa;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --radius: 12px;
  --radius-sm: 8px;
}

/* ===== Reset & Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
}

/* ===== Navbar ===== */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.nav-logo { font-size: 24px; }
.nav-title {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.nav-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}
.nav-divider { color: var(--text-muted); margin: 0 4px; }
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.connected { background: var(--accent-green); box-shadow: 0 0 8px var(--accent-green); }
.status-dot.disconnected { background: var(--accent-red); box-shadow: 0 0 8px var(--accent-red); }

/* ===== Container ===== */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 32px;
}

/* ===== Summary Bar ===== */
.summary-bar {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 16px;
  margin-bottom: 24px;
}
.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform 0.2s, box-shadow 0.2s;
}
.summary-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.summary-icon {
  font-size: 32px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}
.cpu-icon { background: rgba(74,158,255,0.15); }
.mem-icon { background: rgba(52,211,153,0.15); }
.net-icon { background: rgba(167,139,250,0.15); }
.uptime-icon { background: rgba(251,191,36,0.15); }
.summary-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.summary-value { font-size: 26px; font-weight: 700; }

/* ===== Filter Bar ===== */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.filter-group {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}
.filter-btn {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.filter-btn:hover { color: var(--text-primary); }
.filter-btn.active {
  background: var(--accent-blue);
  color: white;
}
.filter-btn.offline-filter.active {
  background: var(--accent-red);
  color: white;
}
.guangming-filter.active {
  background:green;
  color: white;
}
.anti-scam-filter.active {
  background: #ef4444;
  color: white;
}
.filter-search input {
  padding: 8px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  width: 240px;
  outline: none;
  transition: border-color 0.2s;
}
.filter-search input:focus { border-color: var(--accent-blue); }
.filter-search input::placeholder { color: var(--text-muted); }

/* ===== Server Cards (Layered Layout) ===== */
.servers-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* --- Flow Connector Between Layers --- */
.layer-section + .layer-section::before {
  content: '⬇';
  display: block;
  text-align: center;
  font-size: 18px;
  color: var(--text-muted);
  padding: 4px 0;
  opacity: 0.4;
}

/* --- Layer Section --- */
.layer-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
}
.layer-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}
.layer-icon {
  font-size: 28px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--bg-primary);
  flex-shrink: 0;
}
.layer-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}
.layer-count {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 8px;
}
.layer-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.layer-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
  padding: 16px;
}
.server-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  padding-top: 0;
  cursor: pointer;
  transition: all 0.25s;
  animation: fadeIn 0.4s ease;
  position: relative;
  overflow: hidden;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Status bar (top colored strip) --- */
.card-status-bar {
  height: 4px;
  margin: 0 -20px 16px -20px;
  transition: background 0.3s;
}
.card-status-bar.online  { background: var(--accent-green); }
.card-status-bar.offline { background: var(--accent-red); }

/* --- Online card --- */
.server-card.online {
  border-color: rgba(52,211,153,0.15);
}
.server-card.online:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 24px rgba(52,211,153,0.08);
  border-color: var(--accent-green);
  background: var(--bg-card-hover);
}

/* --- Offline card --- */
.server-card.offline {
  border-color: rgba(239,68,68,0.2);
  background: rgba(239,68,68,0.03);
  opacity: 0.75;
}
.server-card.offline:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 24px rgba(239,68,68,0.12);
  border-color: var(--accent-red);
  background: rgba(239,68,68,0.06);
  opacity: 0.9;
}

/* --- Pending (password needed) card --- */
.card-status-bar.pending { background: var(--accent-yellow); }
.server-card.pending {
  border-color: rgba(251,191,36,0.25);
  background: rgba(251,191,36,0.03);
}
.server-card.pending:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 24px rgba(251,191,36,0.1);
  border-color: var(--accent-yellow);
  background: rgba(251,191,36,0.06);
}
.status-indicator.pending {
  color: var(--accent-yellow);
  background: rgba(251,191,36,0.12);
  animation: pulse-pending 2s ease-in-out infinite;
}

/* --- Password input in card --- */
.password-prompt {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 6px;
  align-items: center;
}
.password-prompt input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}
.password-prompt input:focus { border-color: var(--accent-yellow); }
.password-prompt input:first-child { flex: 0 0 70px; }
.password-prompt button {
  padding: 6px 14px;
  background: var(--accent-yellow);
  border: none;
  border-radius: 6px;
  color: #000;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}
.password-prompt button:hover { background: #f59e0b; }
.password-prompt button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Header */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}
.card-name {
  font-size: 16px;
  font-weight: 600;
}
.card-ip {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.card-domains {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 3px;
  line-height: 1.5;
}
.domain-link {
  color: var(--accent-blue);
  text-decoration: none;
  transition: color 0.2s;
}
.domain-link:hover {
  color: #6ab0ff;
  text-decoration: underline;
}
.card-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
}
/* tabbed tags: 有 filter 按钮的用彩色衬底 */
.tag-eurybia   { background: linear-gradient(135deg, rgba(74,158,255,0.2), rgba(167,139,250,0.2)); color: #a78bfa; font-weight: 600; border: 1px solid rgba(167,139,250,0.25); }
.tag-anti-scam { background: rgba(239,68,68,0.12); color: #ef4444; font-weight: 600; border: 1px solid rgba(239,68,68,0.2); }
.tag-CityU     { background: rgba(52,211,153,0.12); color: #34d399; font-weight: 600; border: 1px solid rgba(52,211,153,0.2); }
.tag-AIFT      { background: rgba(251,191,36,0.12); color: #fbbf24; font-weight: 600; border: 1px solid rgba(251,191,36,0.2); }
.tag-光明城 { background: rgba(244,114,182,0.12); color: #f472b6; font-weight: 600; border: 1px solid rgba(244,114,182,0.2); }
/* status tags: removed (offline/pending now shown via card status bar) */
@keyframes pulse-pending {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ===== API Usage Card ===== */
.api-icon { font-size: 22px; }

/* --- Status indicator (badge next to name) --- */
.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 3px 10px;
  border-radius: 99px;
  margin-left: 8px;
  vertical-align: middle;
}
.status-indicator.online {
  color: var(--accent-green);
  background: rgba(52,211,153,0.12);
}
.status-indicator.offline {
  color: var(--accent-red);
  background: rgba(239,68,68,0.15);
  animation: pulse-offline 2s ease-in-out infinite;
}
@keyframes pulse-offline {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Metrics */
.card-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.metric {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.metric-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.metric-value {
  font-size: 14px;
  font-weight: 600;
}
.metric-bar {
  height: 4px;
  background: var(--bg-primary);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 2px;
}
.metric-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.6s ease, background 0.6s ease;
}
.metric-fill.green { background: var(--accent-green); }
.metric-fill.yellow { background: var(--accent-yellow); }
.metric-fill.red { background: var(--accent-red); }

/* Services row */
.card-services {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}
.service-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 99px;
  background: var(--bg-primary);
}
.service-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
}
.service-dot.running { background: var(--accent-green); }
.service-dot.stopped { background: var(--accent-red); }
.service-uptime {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
}


/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 28px;
  border-bottom: 1px solid var(--border-color);
}
.modal-header h2 { font-size: 20px; }
.modal-close {
  width: 32px; height: 32px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.modal-close:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}
.modal-body { padding: 28px; }

/* Modal Detail Grid */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.detail-item {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 16px;
}
.detail-item .metric-label { font-size: 12px; margin-bottom: 6px; }
.detail-item .metric-value { font-size: 18px; }

.chart-container {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 20px;
  margin-bottom: 16px;
  max-height: 280px;
}
.chart-container canvas {
  max-height: 220px;
}
.chart-container h3 {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* ===== Disk Progress ===== */
.disk-info { margin-top: 12px; }
.disk-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.disk-label {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 36px;
}
.disk-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-primary);
  border-radius: 3px;
  overflow: hidden;
}
.disk-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}
.disk-value {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 72px;
  text-align: right;
}

/* ===== GPU ===== */
.metric-gpu { 
  background: rgba(167,139,250,0.06);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.gpu-bar-track {
  height: 4px;
  background: var(--bg-primary);
  border-radius: 2px;
  overflow: hidden;
}
.gpu-card {
  transition: box-shadow 0.2s;
}
.gpu-card:hover {
  box-shadow: 0 2px 12px rgba(167,139,250,0.1);
}

/* ===== Modal Process Lists ===== */
.top-process-section { margin-top: 16px; }
.top-process-title { font-size: 14px; color: var(--text-secondary); margin-bottom: 10px; }
.top-process-list { display: flex; flex-direction: column; gap: 6px; }
.top-process-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.top-process-name { flex: 1; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-process-val { width: 80px; text-align: right; flex-shrink: 0; }
.top-process-val.cpu { color: var(--accent-yellow); }
.top-process-val.mem { color: var(--accent-blue); }

/* ===== Detail Section Header ===== */
.detail-section { margin-top: 16px; }
.detail-section-title { font-size: 14px; color: var(--text-secondary); margin-bottom: 10px; }
.detail-services-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.detail-service-badge { padding: 6px 12px; font-size: 13px; }
.detail-service-status { color: var(--text-muted); margin-left: 4px; }

/* ===== Modal Domain Links ===== */
.detail-domains { font-size: 14px; }
.detail-domain-link { display: inline-block; margin-right: 12px; }

/* ===== SSL Expiry Colors ===== */
.ssl-critical { color: var(--accent-red); }
.ssl-warning { color: var(--accent-yellow); }
.ssl-ok { color: var(--accent-green); }

/* ===== Detail Time ===== */
.detail-time { font-size: 14px; }

/* ===== Password Prompt ===== */
@media (max-width: 768px) {
  .container { padding: 16px; }
  .summary-bar { grid-template-columns: repeat(2, 1fr); }
  .servers-grid { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-search input { width: 100%; }
  .detail-grid { grid-template-columns: 1fr; }
  .navbar { padding: 12px 16px; }
}
