:root {
  --bg: #0b0f17;
  --bg-elevated: #111827;
  --bg-subtle: #0f172a;
  --border: #1f2937;
  --border-light: #2b3748;
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  --emerald: #10b981;
  --emerald-soft: rgba(16, 185, 129, 0.14);
  --cyan: #06b6d4;
  --cyan-soft: rgba(6, 182, 212, 0.14);
  --violet: #a855f7;
  --violet-soft: rgba(168, 85, 247, 0.14);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.14);
  --blue: #3b82f6;
  --blue-soft: rgba(59, 130, 246, 0.14);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.35);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at top right, rgba(6, 182, 212, 0.08), transparent 36%),
              radial-gradient(circle at top left, rgba(168, 85, 247, 0.06), transparent 32%),
              var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: var(--mono);
}

.hidden {
  display: none !important;
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(12px);
  background: rgba(11, 15, 23, 0.85);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  font-size: 15px;
  box-shadow: 0 6px 18px rgba(6, 182, 212, 0.25);
}

.brand-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

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

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Badges & Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border-light);
  background: var(--bg-subtle);
  color: var(--text-muted);
  white-space: nowrap;
}

.badge-ok {
  background: var(--emerald-soft);
  border-color: rgba(16, 185, 129, 0.35);
  color: #34d399;
}

.badge-warn {
  background: var(--amber-soft);
  border-color: rgba(245, 158, 11, 0.35);
  color: #fbbf24;
}

.badge-err {
  background: var(--red-soft);
  border-color: rgba(239, 68, 68, 0.35);
  color: #f87171;
}

.badge-vless {
  background: var(--cyan-soft);
  border-color: rgba(6, 182, 212, 0.35);
  color: #22d3ee;
}

.badge-naive {
  background: var(--violet-soft);
  border-color: rgba(168, 85, 247, 0.35);
  color: #c084fc;
}

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

.dot-pulse {
  box-shadow: 0 0 0 0 currentColor;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Demo banner */
.demo-banner {
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 1px solid rgba(245, 158, 11, 0.3);
  color: #fcd34d;
  text-align: center;
  padding: 7px 16px;
  font-size: 12px;
}

/* Main container */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Grids */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 580px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .container {
    padding: 14px;
  }
}

/* Cards */
.card {
  background: rgba(17, 24, 39, 0.88);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}

.kpi-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.proto-split {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Progress bars */
.metric-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.metric-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}

.progress {
  height: 7px;
  background: #0b1220;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s ease, background-color 0.25s ease;
  background: var(--cyan);
}

.progress-fill.ram {
  background: var(--violet);
}

.progress-fill.disk {
  background: var(--emerald);
}

.progress-fill.warn {
  background: var(--amber);
}

.progress-fill.danger {
  background: var(--red);
}

/* Sparkline & Charts */
.sparkline-wrap {
  height: 44px;
  width: 100%;
}

.chart-wrap {
  height: 240px;
  width: 100%;
  position: relative;
}

.tabs {
  display: inline-flex;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  background: #1e293b;
  color: var(--text);
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: #182234;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.btn:hover:not(:disabled) {
  background: #223049;
  border-color: #3b4b63;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, #0891b2, #0284c7);
  border-color: rgba(34, 211, 238, 0.35);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #06b6d4, #0ea5e9);
}

.btn-emerald {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}

.btn-emerald:hover:not(:disabled) {
  background: rgba(16, 185, 129, 0.25);
}

.btn-amber {
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fbbf24;
}

.btn-amber:hover:not(:disabled) {
  background: rgba(245, 158, 11, 0.25);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.4);
  color: #f87171;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
}

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

.input, .select {
  background: #0b1220;
  border: 1px solid var(--border-light);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease;
}

.input:focus, .select:focus {
  border-color: var(--cyan);
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

/* Table */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(31, 41, 55, 0.65);
  vertical-align: middle;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.025);
}

.empty-state {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-sm);
  background: rgba(11, 18, 32, 0.5);
}

/* Service strip & Logs */
.service-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  padding: 10px 14px;
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-muted);
}

.service-meta strong {
  color: var(--text);
  font-weight: 600;
}

.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.logs-pre {
  margin: 0;
  padding: 14px;
  background: #070a10;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  color: #cbd5e1;
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Login Page */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid var(--border-light);
  border-radius: 18px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.alert-error {
  background: var(--red-soft);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* Modal & Toasts */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(5, 8, 15, 0.72);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}

.toast {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: #162032;
  border: 1px solid var(--border-light);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: slideIn 0.18s ease;
}

.toast-ok {
  border-color: rgba(16, 185, 129, 0.45);
}

.toast-err {
  border-color: rgba(239, 68, 68, 0.5);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
