:root {
  --bg-main: #0B0F19;
  --bg-card: #111827;
  --bg-card-hover: #1F2937;
  --border-color: #1F2937;
  --border-active: #374151;
  --primary: #7C3AED;
  --primary-light: #8B5CF6;
  --primary-glow: rgba(124, 58, 237, 0.25);
  --success: #10B981;
  --success-glow: rgba(16, 185, 129, 0.25);
  --warning: #F59E0B;
  --danger: #EF4444;
  --text-main: #F9FAFB;
  --text-muted: #9CA3AF;
  --text-sub: #6B7280;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body {
  background: var(--bg-main);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", PingFang SC, sans-serif;
  min-height: 100vh;
  line-height: 1.5;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.top-bar {
  background: rgba(17, 24, 39, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

.brand-section { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  font-size: 22px;
  background: linear-gradient(135deg, #7C3AED, #3B82F6);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px var(--primary-glow);
  flex-shrink: 0;
}
.brand-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.version-badge {
  background: rgba(124, 58, 237, 0.2);
  color: #C4B5FD;
  border: 1px solid #7C3AED;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}
.system-pulse {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
}
.pulse-item { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.action-buttons { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.btn {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  min-height: 38px;
  user-select: none;
}
.btn-primary { background: linear-gradient(135deg, #7C3AED, #6D28D9); color: #fff; box-shadow: 0 4px 12px var(--primary-glow); }
.btn-primary:active { transform: scale(0.97); }
.btn-outline { background: rgba(31, 41, 55, 0.6); border-color: var(--border-color); color: var(--text-muted); }
.btn-outline:active { transform: scale(0.97); }

.nav-tabs-wrapper {
  background: var(--bg-main);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 62px;
  z-index: 90;
}
.nav-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 20px 0 20px;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  flex-shrink: 0;
  border-radius: 8px 8px 0 0;
}
.tab-btn.active { color: #A78BFA; border-bottom-color: #8B5CF6; background: rgba(124, 58, 237, 0.12); }

.main-container { padding: 20px; max-width: 1440px; margin: 0 auto; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 16px 18px;
  border-radius: 12px;
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
}
.stat-title { font-size: 12px; color: var(--text-sub); margin-bottom: 4px; display: flex; justify-content: space-between; }
.stat-value { font-size: 24px; font-weight: 800; color: var(--text-main); font-family: var(--font-mono); }
.stat-desc { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.matrix-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.matrix-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(31, 41, 55, 0.4);
  flex-wrap: wrap;
  gap: 8px;
}
.matrix-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.matrix-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 13px; }
.matrix-table th {
  background: rgba(17, 24, 39, 0.95);
  color: var(--text-sub);
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
}
.matrix-table td { padding: 14px 16px; border-bottom: 1px solid rgba(31, 41, 55, 0.6); vertical-align: middle; }
.matrix-table tr:hover { background: var(--bg-card-hover); }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(16, 185, 129, 0.15);
  color: #34D399;
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
}
.status-badge.loading { background: rgba(245, 158, 11, 0.15); color: #FBBF24; border-color: rgba(245, 158, 11, 0.3); }
.status-badge.error { background: rgba(239, 68, 68, 0.15); color: #F87171; border-color: rgba(239, 68, 68, 0.3); }

.endpoint-tag {
  background: rgba(31, 41, 55, 0.8);
  border: 1px solid #374151;
  padding: 3px 8px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #E5E7EB;
  display: inline-block;
  word-break: break-all;
}

.grid-2col { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; }
.panel-card { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 12px; padding: 18px; }
.panel-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #E5E7EB;
  flex-wrap: wrap;
  gap: 6px;
}
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.form-control {
  width: 100%;
  background: #0B0F19;
  border: 1px solid #374151;
  color: #F9FAFB;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  min-height: 40px;
}
.form-control:focus { border-color: var(--primary); }

.slider-container { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.slider-container input[type=range] { flex: 1; accent-color: var(--primary); height: 24px; }
.slider-val { width: 45px; text-align: right; font-family: var(--font-mono); font-weight: bold; color: #A78BFA; font-size: 13px; }

.json-box {
  background: #060911;
  border: 1px solid #1F2937;
  padding: 12px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #38BDF8;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal-content {
  background: var(--bg-card);
  border: 1px solid #374151;
  border-radius: 16px;
  width: 100%;
  max-width: 680px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  right: 20px;
  left: 20px;
  max-width: 400px;
  margin: 0 auto;
  background: #1F2937;
  border: 1px solid var(--primary);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 2000;
  text-align: center;
}

@media (max-width: 768px) {
  .top-bar { flex-direction: column; align-items: stretch; gap: 8px; }
  .system-pulse { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-size: 11px; }
  .action-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .btn { min-height: 44px; font-size: 13px; }
  .main-container { padding: 12px; }
  .grid-2col { grid-template-columns: 1fr; }
  .matrix-table thead { display: none; }
  .matrix-table, .matrix-table tbody, .matrix-table tr, .matrix-table td { display: block; width: 100%; }
  .matrix-table tbody { padding: 10px; display: flex; flex-direction: column; gap: 12px; }
  .matrix-table tr { background: #0D1322; border: 1px solid #1F2937; border-radius: 12px; padding: 14px; }
  .matrix-table td { padding: 6px 0; border-bottom: none; }
  .mobile-card-row1 { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
  .mobile-card-name { font-size: 15px; font-weight: bold; color: #F3F4F6; }
  .mobile-card-algo { font-size: 11px; color: #9CA3AF; margin-top: 4px; line-height: 1.4; }
  .mobile-btn-probe { width: 100%; margin-top: 10px; min-height: 42px; font-size: 13px; }
}
