:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text2: #8b949e;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --blue: #58a6ff;
  --accent: #1f6feb;
  --radius: 8px;
  /* Overrides injetados pelo backend por tenant */
  --cor-primaria: #2563eb;
  --cor-fundo: #0f1117;
}

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

html { font-size: 16px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

/* Header */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
  margin-bottom: 32px;
}
header .container { padding-top: 0; padding-bottom: 0; display: flex; align-items: center; gap: 12px; }
.logo-icon {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.logo-icon svg { width: 20px; height: 20px; fill: #fff; }
header h1 { font-size: 1.1rem; font-weight: 600; }
header p { font-size: 0.8rem; color: var(--text2); }

/* Disclaimer */
.disclaimer {
  background: #161b22;
  border: 1px solid #30363d;
  border-left: 3px solid var(--yellow);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.8rem;
  color: var(--text2);
  margin-bottom: 24px;
}

/* Form de entrada */
.setup-form {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 540px) { .setup-form { grid-template-columns: 1fr; } }

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text2);
  margin-bottom: 6px;
  font-weight: 500;
}
.form-group input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
.form-group input:focus { border-color: var(--accent); }
.form-group input::placeholder { color: var(--text2); }

/* Botão principal */
.btn-primary {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 12px 28px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s, opacity 0.15s;
}
.btn-primary:hover:not(:disabled) { background: #388bfd; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: #30363d; }

/* Progress global */
#progress-bar-wrap {
  display: none;
  margin-bottom: 24px;
}
.progress-label {
  font-size: 0.8rem;
  color: var(--text2);
  margin-bottom: 6px;
}
.progress-track {
  height: 4px;
  background: var(--bg3);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.3s ease;
  width: 0%;
}

/* Seções de resultado */
.section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.section-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.section-icon {
  width: 28px; height: 28px;
  background: var(--bg3);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.section-icon svg { width: 14px; height: 14px; fill: var(--text2); }
.section-title { font-size: 0.9rem; font-weight: 600; flex: 1; }
.section-status {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 500;
}
.status-waiting { background: var(--bg3); color: var(--text2); }
.status-running { background: #1a3a6a; color: var(--blue); }
.status-done { background: #12261e; color: var(--green); }
.status-error { background: #2d1315; color: var(--red); }

.section-body {
  padding: 16px;
}

/* Métricas */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.metric-card {
  background: var(--bg3);
  border-radius: 6px;
  padding: 12px;
}
.metric-label { font-size: 0.72rem; color: var(--text2); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.metric-value { font-size: 1.4rem; font-weight: 700; line-height: 1; }
.metric-unit { font-size: 0.75rem; color: var(--text2); margin-top: 2px; }

.good { color: var(--green); }
.warn { color: var(--yellow); }
.bad  { color: var(--red); }
.neutral { color: var(--text); }

/* Gráfico de latência */
#latency-chart {
  width: 100%;
  height: 80px;
  display: block;
  margin-top: 12px;
}

/* Barra de velocidade */
.speed-bar-wrap { margin-top: 12px; }
.speed-bar-label { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--text2); margin-bottom: 4px; }
.speed-bar-track { height: 6px; background: var(--bg3); border-radius: 99px; overflow: hidden; }
.speed-bar-fill { height: 100%; border-radius: 99px; transition: width 0.2s ease; background: var(--accent); }

/* Tabela de info */
.info-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.info-table tr { border-bottom: 1px solid var(--bg3); }
.info-table tr:last-child { border-bottom: none; }
.info-table td { padding: 7px 4px; }
.info-table td:first-child { color: var(--text2); width: 48%; }
.info-table td:last-child { color: var(--text); font-weight: 500; word-break: break-all; }

/* Badge de status */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.78rem; padding: 3px 8px;
  border-radius: 99px; font-weight: 500;
}
.badge-good { background: #12261e; color: var(--green); }
.badge-warn { background: #2d2107; color: var(--yellow); }
.badge-bad  { background: #2d1315; color: var(--red); }
.badge-neutral { background: var(--bg3); color: var(--text2); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Ações finais */
#actions {
  display: none;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 24px;
}
#actions .btn-secondary { flex: 1; min-width: 160px; }

/* Spinner */
.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Loading placeholder */
.loading-text { color: var(--text2); font-size: 0.85rem; font-style: italic; }

@media (max-width: 480px) {
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .metric-value { font-size: 1.2rem; }
}

/* Multi-tenant: usa variáveis injetadas pelo backend */
.btn-primary { background: var(--cor-primaria, #2563eb); }
.btn-primary:hover { filter: brightness(1.15); }
body { background: var(--cor-fundo, #0d1117); }

.header-brand { display: flex; align-items: center; gap: 12px; }
#tenant-logo { max-height: 48px; max-width: 140px; object-fit: contain; }

.codigo-relatorio {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1.05em;
  color: var(--text);
  margin-bottom: 8px;
}
.codigo-relatorio strong { color: var(--cor-primaria, var(--blue)); font-size: 1.2em; }
