:root {
  --bg: #0f1420;
  --bg-card: #171e2e;
  --bg-card-hover: #1d2536;
  --border: #262f45;
  --text: #e6e9f0;
  --text-dim: #9aa4bb;
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.12);
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.12);
  --blue: #3b82f6;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f9;
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    --border: #e2e6ee;
    --text: #1a2033;
    --text-dim: #5c6580;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1420;
  --bg-card: #171e2e;
  --bg-card-hover: #1d2536;
  --border: #262f45;
  --text: #e6e9f0;
  --text-dim: #9aa4bb;
}

:root[data-theme="light"] {
  --bg: #f3f5f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --border: #e2e6ee;
  --text: #1a2033;
  --text-dim: #5c6580;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
  line-height: 1.2;
}

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

.logo-tuxnet {
  height: 38px;
  width: auto;
}

.subtitulo-sistema {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-dim);
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

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

.resumo-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 18px;
}

.resumo-pill span#resumo-count-ativos,
.resumo-pill span#resumo-count-resolvidos {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1;
}

.btn-refresh {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 1rem;
}
.btn-refresh:hover { background: var(--bg-card-hover); }
.btn-refresh.spinning { animation: spin 0.6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
  }

  .topbar-marca {
    flex: 1 1 auto;
    min-width: 0;
  }

  .logo-tuxnet {
    height: 30px;
  }

  .topbar h1 {
    font-size: 1rem;
  }

  .subtitulo-sistema {
    font-size: 0.68rem;
  }

  .topbar-status {
    order: 1;
    margin-left: auto;
  }

  #ultima-atualizacao {
    display: none;
  }

  .topbar-resumo {
    order: 2;
    width: 100%;
    justify-content: stretch;
  }

  .resumo-pill {
    flex: 1 1 0;
    justify-content: center;
    padding: 7px 10px;
    font-size: 0.8rem;
  }

  .resumo-pill span#resumo-count-ativos,
  .resumo-pill span#resumo-count-resolvidos {
    font-size: 1.2rem;
  }
}

@media (max-width: 380px) {
  .resumo-pill {
    font-size: 0.72rem;
    padding: 7px 6px;
    gap: 5px;
  }

  .resumo-48h {
    display: none;
  }
}

.container {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
  max-width: 1600px;
  margin: 0 auto;
}

.coluna-titulo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  margin: 0 0 12px;
}

.subtitulo {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-weight: normal;
}

.badge {
  margin-left: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot-ativo { background: var(--red); box-shadow: 0 0 0 4px var(--red-bg); }
.dot-resolvido { background: var(--green); box-shadow: 0 0 0 4px var(--green-bg); }

.lista-alertas {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.lista-alertas.timeline-alertas {
  display: block;
}

.timeline-alerta .timeline-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.timeline-alerta .timeline-content:hover { background: var(--bg-card-hover); }

.timeline-marker.resolvido { background: var(--green); }

.btn-carregar-mais {
  display: block;
  margin: 14px auto 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 20px;
  font-size: 0.85rem;
  cursor: pointer;
}
.btn-carregar-mais:hover { background: var(--bg-card-hover); }
.btn-carregar-mais.hidden { display: none; }

.vazio {
  grid-column: 1 / -1;
  color: var(--text-dim);
  font-size: 0.9rem;
  padding: 16px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.card:hover { background: var(--bg-card-hover); }

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

.card-local {
  font-weight: 600;
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-local-vazio {
  font-weight: 500;
  color: var(--text-dim);
}

.card-tempo {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.card-texto {
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-rodape {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.btn-historico-card {
  background: none;
  border: 1px solid var(--border);
  color: var(--blue);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn-historico-card:hover { background: var(--bg-card-hover); }

.status-pill {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}
.status-pill.ativo { background: var(--red-bg); color: var(--red); }
.status-pill.resolvido { background: var(--green-bg); color: var(--green); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 640px;
  width: 100%;
  padding: 24px;
  position: relative;
}

.modal-fechar {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-dim);
  cursor: pointer;
}

.modal h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
  padding-right: 24px;
}

.modal-meta {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.modal-texto {
  white-space: pre-wrap;
  font-size: 0.92rem;
  line-height: 1.5;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
}

.modal-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 16px 0 8px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.afetados-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.afetados-grupo {
  font-size: 0.85rem;
}
.afetados-grupo strong { display: block; margin-bottom: 4px; color: var(--text-dim); font-weight: 600; }

.btn-historico {
  margin-top: 16px;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.9rem;
  cursor: pointer;
  width: 100%;
}
.btn-historico:hover { opacity: 0.9; }

.timeline {
  margin-top: 16px;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 4px;
}

.timeline-item {
  position: relative;
  padding-left: 20px;
  padding-bottom: 16px;
  font-size: 0.85rem;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 14px;
  bottom: -2px;
  width: 2px;
  background: var(--border);
}

.timeline-item:last-child::before { display: none; }

.timeline-marker {
  position: absolute;
  left: 0;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 0 3px var(--bg-card);
}

.timeline-content .h-data {
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-bottom: 3px;
}

.timeline-content .h-usuario {
  font-weight: 600;
  margin-bottom: 3px;
}

.timeline-content .h-texto {
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
}

.btn-ver-mais {
  margin-top: 6px;
  background: none;
  border: none;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
.btn-ver-mais:hover { text-decoration: underline; }

.loading-inline {
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 8px 0;
}

.erro-inline {
  color: var(--red);
  font-size: 0.85rem;
  padding: 8px 0;
}
