:root {
  --bg: #0f172a;
  --panel: #111827;
  --border: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --up: #22c55e;
  --degraded: #eab308;
  --down: #ef4444;
  --unknown: #6b7280;
  /* Rampa sequencial (magnitude de "quantos alertas"), de propósito separada
     das cores de status acima -- um gráfico de frequência não deve usar a
     mesma cor de "ponto fora do ar" agora, senão confunde as duas coisas. */
  --seq-1: #4338ca;
  --seq-2: #4f46e5;
  --seq-3: #6366f1;
  --seq-4: #818cf8;
  --seq-5: #a5b4fc;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.topnav {
  height: 48px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topnav-brand {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-right: 16px;
}

.topnav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
}

.topnav a:hover {
  color: var(--text);
}

.topnav a.active {
  color: var(--text);
  background: var(--border);
}

.topnav-logout {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.topnav-logout:hover {
  color: var(--text);
  border-color: var(--muted);
}

#app {
  display: grid;
  grid-template-columns: 1fr 340px;
  height: calc(100vh - 48px);
}

#map {
  height: 100%;
}

#sidebar {
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#sidebar header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

#sidebar header h1 {
  font-size: 15px;
  margin: 0 0 4px;
}

#sidebar header p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

#status-summary {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.pill {
  display: flex;
  align-items: center;
  gap: 4px;
}

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

.dot.up {
  background: var(--up);
}

.dot.degraded {
  background: var(--degraded);
}

.dot.down {
  background: var(--down);
}

.dot.unknown {
  background: var(--unknown);
}

#type-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.legend-item svg {
  display: block;
}

/* Marcadores do mapa (ver iconFor/shapeSvg em app.js): a cor do preenchimento
   é sempre o status; a forma é sempre o tipo de equipamento. */
.network-marker svg {
  display: block;
  overflow: visible;
}

.network-marker.marker-alert-critical svg {
  filter: drop-shadow(0 0 3px var(--down)) drop-shadow(0 0 6px var(--down));
}

.network-marker.marker-alert-warning svg {
  filter: drop-shadow(0 0 3px var(--degraded)) drop-shadow(0 0 6px var(--degraded));
}

.network-marker.marker-alert-info svg {
  filter: drop-shadow(0 0 3px #60a5fa) drop-shadow(0 0 6px #60a5fa);
}

#alerts {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

#alerts .empty {
  color: var(--muted);
  font-size: 13px;
  padding: 16px;
  text-align: center;
}

.alert-card {
  background: #1a1030;
  /* cor da borda vem inline (JS), de acordo com a severidade -- crítico,
     aviso ou informativo não são todos igualmente urgentes. */
  border: 1px solid var(--down);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  animation: pulse-in 0.3s ease-out;
}

.alert-card .kind {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.severity-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.severity-tag {
  margin-left: auto;
  font-size: 9px;
  font-weight: 500;
  text-transform: none;
  color: var(--muted);
  letter-spacing: normal;
}

.alert-card .desc {
  font-size: 13px;
  margin: 4px 0;
}

.alert-card .time {
  color: var(--muted);
  font-size: 11px;
}

#conn-state {
  padding: 8px 16px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

#conn-state.connected::before {
  content: "● ";
  color: var(--up);
}

#conn-state.disconnected::before {
  content: "● ";
  color: var(--down);
}

/* ---- Página de Análises ---- */

#analytics {
  height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 20px 24px 40px;
  max-width: 1000px;
  margin: 0 auto;
}

.analytics-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.analytics-toolbar h1 {
  font-size: 16px;
  margin: 0;
}

.analytics-toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

#period-select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.kpi-tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.kpi-tile .value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
}

.kpi-tile .label {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.chart-card h2 {
  font-size: 13px;
  margin: 0 0 4px;
}

.chart-card .subtitle {
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 14px;
}

.chart-card .empty {
  color: var(--muted);
  font-size: 13px;
  padding: 24px 0;
  text-align: center;
}

.insights-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 4px;
}

.insights-header h2 {
  margin: 0;
}

.insights-header .subtitle {
  margin: 4px 0 0;
}

#insights-btn {
  flex-shrink: 0;
  background: var(--seq-2);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

#insights-btn:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

#insights-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#insights-list li {
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 12px;
  background: rgba(99, 102, 241, 0.08);
  border-left: 2px solid var(--seq-3);
  border-radius: 0 6px 6px 0;
}

#insights-list li.insight-error {
  background: rgba(239, 68, 68, 0.08);
  border-left-color: var(--down);
  color: var(--muted);
}

.bars-vertical {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 140px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  min-width: 0;
}

.bar-col-fill {
  width: 100%;
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  background: var(--border);
}

.bar-col-label {
  font-size: 9px;
  color: var(--muted);
  margin-top: 4px;
  white-space: nowrap;
}

.bars-horizontal {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 150px 1fr 36px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.bar-row-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-row-track {
  background: var(--border);
  border-radius: 4px;
  height: 10px;
  overflow: hidden;
}

.bar-row-fill {
  height: 100%;
  border-radius: 4px;
  min-width: 2px;
}

.bar-row-value {
  text-align: right;
  color: var(--muted);
}

/* ---- Landing ---- */

.topnav-cta {
  margin-left: auto;
  background: var(--seq-2);
  color: #fff !important;
  padding: 6px 14px !important;
}

.landing {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 20px;
}

.hero {
  padding: 72px 0 48px;
  text-align: center;
}

.hero h1 {
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1.25;
  margin: 0 0 16px;
}

.hero-subtitle {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.6;
  max-width: 640px;
  margin: 0 auto 28px;
}

.hero-ctas {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-primary,
.btn-secondary {
  display: inline-block;
  padding: 11px 22px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

.btn-primary {
  background: var(--seq-2);
  color: #fff;
}

.btn-primary:hover {
  background: var(--seq-1);
}

.btn-secondary {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  border-color: var(--muted);
}

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  padding: 20px 0 56px;
}

.feature-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}

.feature-card h2 {
  font-size: 15px;
  margin: 0 0 8px;
}

.feature-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  margin: 0;
}

.lead-section {
  max-width: 420px;
  margin: 0 auto;
  padding: 24px 0 72px;
  text-align: center;
}

.lead-section h2 {
  font-size: 20px;
  margin: 0 0 6px;
}

.lead-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 20px;
}

.lead-section form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}

.lead-section label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

.lead-section input,
.lead-section textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}

.lead-section input:focus,
.lead-section textarea:focus {
  outline: 1px solid var(--seq-3);
}

.lead-section button[type="submit"] {
  margin-top: 16px;
  background: var(--seq-2);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.lead-section button[type="submit"]:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

.lead-success {
  color: var(--up);
  font-size: 14px;
  text-align: center;
  margin: 0;
}

.landing-footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 24px 0 40px;
}

/* ---- Login ---- */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 16px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
}

.auth-card h1 {
  font-size: 18px;
  margin: 0 0 4px;
}

.auth-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 20px;
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-card label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

.auth-card input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 9px 10px;
  font-size: 14px;
}

.auth-card input:focus {
  outline: 1px solid var(--seq-3);
}

.auth-card button[type="submit"] {
  margin-top: 16px;
  background: var(--seq-2);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.auth-card button[type="submit"]:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

.auth-error {
  color: var(--down);
  font-size: 12px;
  margin: 8px 0 0;
}

.auth-back {
  display: block;
  text-align: center;
  margin-top: 16px;
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}

.auth-back:hover {
  color: var(--text);
}

@keyframes pulse-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
