/*
 * CSS Otimizado e Responsivo
 * Tema: Dark (Glassmorphism)
 * Unidades: Relativas (rem, %, vw)
 * Layout: Flexbox e CSS Grid
 */

:root {
  --primary-dark: #0B1426;
  --primary-medium: #1E3A5F;
  --accent-blue: #3B82F6;
  --accent-green: #10B981;
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --text-primary: #FFFFFF;
  --text-secondary: #B0BEC5;
  --shadow-deep: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  --shadow-card: 0 10px 25px rgba(0, 0, 0, 0.3);
  --border-radius: 16px;
  --transition: all .3s cubic-bezier(.4, 0, .2, 1);
  --font-base: 16px; /* Base para rem */
}

/* Reset e Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: var(--font-base); /* Define a base para rem */
}

body {
  font-family: 'Segoe UI', 'Roboto', sans-serif;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-medium) 100%);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* Animações */
@keyframes glow {
  from { box-shadow: 0 0 20px rgba(59, 130, 246, .5); }
  to { box-shadow: 0 0 30px rgba(59, 130, 246, .8), 0 0 40px rgba(16, 185, 129, .4); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .7; transform: scale(1.1); }
}

@keyframes blink {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.05); }
}

/* Header */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  background: linear-gradient(135deg, rgba(11, 20, 38, .95) 0%, rgba(30, 58, 95, .95) 100%);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  padding: 1rem 0; /* Ajuste de padding */
  box-shadow: var(--shadow-deep);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 100%;
  margin: 0 auto;
  padding: 0 2rem;
  flex-wrap: wrap; /* Essencial para responsividade */
  gap: 1rem;
}

/* Seção de Logos e Título */
.logo-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex: 1 1 auto; /* Flexível para ocupar espaço */
  min-width: 250px; /* Garante que não encolha demais */
}

.logo-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  flex-wrap: wrap; /* Permite que os logos quebrem a linha */
}

.logo-img {
  height: 4rem; /* Usar rem */
  width: auto;
  max-width: 100%; /* Garante que a imagem não ultrapasse o contêiner */
  object-fit: contain;
  filter: drop-shadow(0 0 0.5rem rgba(59, 130, 246, 0.6));
  transition: var(--transition);
}

.title {
  font-size: clamp(1.5rem, 4vw, 3rem); /* Tamanho de fonte fluido */
  font-weight: 700;
  background: linear-gradient(45deg, var(--accent-blue), var(--accent-green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-align: center;
  margin-top: 0.5rem;
  line-height: 1.2;
}

/* Seção de Status e Botão */
.status-section {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--glass-bg);
  padding: .5rem 1rem;
  border-radius: 25px;
  border: 1px solid var(--glass-border);
}

.live-dot {
  width: 0.5rem; height: 0.5rem;
  background: #EF4444;
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
}

.update-time {
  font-size: 0.9rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.filter-toggle .button {
  background-color: var(--accent-blue);
  color: var(--text-primary);
  padding: 0.5rem 1rem;
  border-radius: 25px;
  text-decoration: none;
  font-size: 0.9rem;
  transition: var(--transition);
  white-space: nowrap;
  display: inline-block;
}

.filter-toggle .button:hover {
  background-color: #5B9EFF;
}

/* Conteúdo Principal */
.main-content {
  padding-top: 10rem; /* Valor inicial que será ajustado pelo JS */
  padding: 1.5rem 2rem; /* Adicionar padding lateral */
  max-width: 100%; /* Ocupar 100% da largura */
  margin: 0 auto;
  transition: padding-top .3s ease;
}

/* MÉTRICAS */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); /* Min-width menor para mobile */
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.metric-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 1rem;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius);
  padding: 1rem;
  box-shadow: var(--shadow-card);
  transition: var(--transition);
}

.metric-icon img {
  width: 2.5rem; /* Usar rem */
  height: 2.5rem;
  filter: drop-shadow(0 0 0.375rem rgba(59,130,246,0.6));
  transition: transform 0.3s ease;
}

.metric-card:hover .metric-icon img {
  transform: scale(1.1);
}

/* Efeitos para Status */
.status-normal img { filter: drop-shadow(0 0 0.5rem #10B981); }
.status-warning img { filter: drop-shadow(0 0 0.5rem #FACC15); }
.status-critical img {
  filter: drop-shadow(0 0 0.625rem #EF4444);
  animation: blink 1.2s infinite alternate;
}

.metric-value {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.2;
}

.metric-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* GRÁFICOS E TABELAS */
.charts-section {
  display: grid;
  grid-template-columns: 1fr 1.2fr; /* Ajuste para dar mais espaço à tabela */
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.chart-container {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
}

.chart-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 1rem;
  text-align: center;
}

#pie-chart {
  width: 100%;
  /* Definindo tamanho fixo em pixels para evitar encolhimento com o zoom */
  height: 800px; /* Aumentado para que o gráfico fique maior */
  min-height: 600px;
  min-width: 450px; /* Mantendo largura mínima */
}

/* TABELA */
.table-wrapper {
  overflow-x: auto; /* Garante que a tabela seja scrollável horizontalmente se necessário */
}

.routes-table {
  width: 100%;
  min-width: 40rem; /* Garante largura mínima para não quebrar colunas */
  border-collapse: collapse;
}

.routes-table th, .routes-table td {
  padding: 0.75rem 0.5rem; /* Ajuste de padding */
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, .05);
  font-size: 0.9rem; /* Fonte um pouco menor para mais densidade */
}

.routes-table th:first-child, .routes-table td:first-child {
  text-align: left;
  padding-left: 1rem;
}

.routes-table th {
  background: rgba(255, 255, 255, .02);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
}

.routes-table tbody tr:nth-child(even) { background: rgba(255,255,255,.01); }
.routes-table tbody tr:hover { background: rgba(255,255,255,.02); }

.traffic-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary-dark);
  white-space: nowrap;
}

.traffic-badge.traffic-Livre { background-color: #28a745; color: #fff; } /* Verde claro */
.traffic-badge.traffic-Leve { background-color: #155724; color: #fff; } /* Verde escuro */
.traffic-badge.traffic-Moderado { background-color: #ffc107; color: #000; } /* Amarelo */
.traffic-badge.traffic-Pesado { background-color: #fd7e14; color: #fff; } /* Laranja */
.traffic-badge.traffic-Congestionado { background-color: #dc3545; color: #fff; } /* Vermelho */

/* FOOTER */
footer.footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: linear-gradient(135deg, rgba(11, 20, 38, .95) 0%, rgba(30, 58, 95, .95) 100%);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--glass-border);
}

/* MEDIA QUERIES - RESPONSIVIDADE */

/* Tablet (max-width: 1024px) */
@media (max-width: 64rem) { /* 1024px */
  .charts-section {
    grid-template-columns: 1fr; /* Coloca gráficos e tabelas em coluna */
  }

  #pie-chart {
    height: 450px; /* Aumentado para tablet */
  min-height: 450px;
  min-width: 350px;
  }

  .main-content {
    padding: 1rem;
  }
}

/* Mobile (max-width: 768px) */
@media (max-width: 48rem) { /* 768px */
  .header-content {
    flex-direction: column; /* Empilha o conteúdo do header */
    align-items: center;
    padding: 0.5rem 1rem;
  }

  .logo-section {
    order: 1;
    margin-bottom: 0.5rem;
  }

  .status-section {
    order: 2;
    width: 100%;
    justify-content: space-around;
  }

  .filter-toggle {
    order: 3;
    margin-top: 0.5rem;
  }

  .logo-img {
    height: 3rem; /* Logos menores no mobile */
  }

  .title {
    font-size: clamp(1.5rem, 6vw, 2rem);
  }

  .metrics-grid {
    grid-template-columns: 1fr; /* Uma coluna para métricas */
  }

  .metric-card {
    flex-direction: column;
    text-align: center;
    align-items: center;
  }

  .metric-value {
    font-size: 1.5rem;
  }

  .routes-table {
    min-width: 35rem; /* Garante largura mínima para a tabela */
  }

  #pie-chart {
    height: 350px; /* Aumentado para mobile */
  min-height: 350px;
  min-width: 300px;
  }
}

/* Mobile Pequeno (max-width: 480px) */
@media (max-width: 30rem) { /* 480px */
  .logo-group {
    gap: 0.5rem;
  }

  .logo-img {
    height: 2.5rem;
  }

  .status-section {
    flex-direction: column;
    gap: 0.5rem;
  }

  .update-time, .filter-toggle .button {
    font-size: 0.8rem;
  }

  .main-content {
    padding: 0.5rem;
  }

  .chart-container {
    padding: 1rem;
  }
}

/* NAVEGAÇÃO PRINCIPAL */
.main-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--glass-border);
  margin-bottom: 1rem;
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.5rem 1rem;
  margin: 0 0.5rem;
  border-radius: 8px;
  transition: var(--transition);
  font-weight: 500;
  font-size: 1rem;
  white-space: nowrap;
}

.nav-link:hover {
  background-color: rgba(59, 130, 246, 0.1);
  color: var(--text-primary);
}

.nav-link.active {
  background-color: var(--accent-blue);
  color: var(--text-primary);
  font-weight: 700;
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.4);
}

/* Ajuste de responsividade para o header */
@media (max-width: 48rem) {
  .main-nav {
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
  }
  .nav-link {
    width: 90%;
    text-align: center;
  }
}
