:root {
  --azul-primary: #004b87;
  --azul-gradient: linear-gradient(135deg, #092c4c 0%, #004b87 60%, #0284c7 100%);
  --azul-hover: #003866;
  --azul-escuro: #092c4c;
  --azul-claro: #f0f7ff;
  --azul-border: #bae6fd;
  
  --cinza-fundo: #f8fafc;
  --superficie: #ffffff;
  --borda: #e2e8f0;
  --borda-foco: #0284c7;
  
  --texto: #0f172a;
  --texto-secundario: #64748b;
  --texto-suave: #94a3b8;
  
  --verde: #059669;
  --verde-fundo: #ecfdf5;
  --verde-borda: #a7f3d0;
  
  --vermelho: #dc2626;
  --vermelho-fundo: #fef2f2;
  --vermelho-borda: #fecaca;
  
  --amarelo: #d97706;
  --amarelo-fundo: #fffbeb;
  --amarelo-borda: #fde68a;
  
  --roxo: #4f46e5;
  --roxo-fundo: #eef2ff;
  --roxo-borda: #c7d2fe;
  
  --sombra-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --sombra: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -1px rgba(15, 23, 42, 0.04);
  --sombra-lg: 0 12px 24px -4px rgba(15, 23, 42, 0.12), 0 4px 6px -2px rgba(15, 23, 42, 0.04);
  --raio: 12px;
  --raio-sm: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--texto);
  background: var(--cinza-fundo);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header Navbar */
.topo {
  background: var(--azul-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 0.85rem 2rem;
  box-shadow: var(--sombra);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}

.marca {
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.marca-icon {
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.2);
}

.topo nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.topo a.nav-link {
  color: #e2e8f0;
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.45rem 0.85rem;
  border-radius: var(--raio-sm);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.topo a.nav-link:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.topo a.nav-link.ativo {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
  font-weight: 600;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.usuario {
  color: #f1f5f9;
  font-size: 0.85rem;
  font-weight: 500;
  background: rgba(0, 0, 0, 0.25);
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.inline { display: inline; }

.linklike {
  background: none;
  border: none;
  color: #fca5a5;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: var(--raio-sm);
  transition: background 0.15s, color 0.15s;
}
.linklike:hover {
  background: rgba(239, 68, 68, 0.25);
  color: #fff;
}

main {
  max-width: 1280px;
  width: 100%;
  margin: 1.75rem auto;
  padding: 0 1.5rem;
  flex: 1;
}

footer {
  max-width: 1280px;
  width: 100%;
  margin: 3rem auto 1.5rem;
  padding: 1.5rem;
  color: var(--texto-secundario);
  font-size: 0.85rem;
  border-top: 1px solid var(--borda);
  text-align: center;
}
footer a { color: var(--azul-primary); text-decoration: none; font-weight: 500; }
footer a:hover { text-decoration: underline; }

h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--texto);
  margin: 0.2rem 0 0.5rem;
  letter-spacing: -0.025em;
}

h2 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--texto);
  margin: 1.75rem 0 0.85rem;
  letter-spacing: -0.015em;
}

/* Card Component */
.cartao {
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 1.75rem;
  box-shadow: var(--sombra);
}

.login {
  max-width: 400px;
  margin: 4.5rem auto;
  border-top: 4px solid var(--azul-primary);
}

/* Dashboard Metric Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--sombra-sm);
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--sombra);
}

.stat-icon {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}

.stat-icon.blue { background: #e0f2fe; color: #0284c7; }
.stat-icon.green { background: #dcfce7; color: #15803d; }
.stat-icon.amber { background: #fef3c7; color: #b45309; }
.stat-icon.purple { background: #f3e8ff; color: #7e22ce; }

.stat-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--texto-secundario);
}

.stat-val {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--texto);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-sub {
  font-size: 0.76rem;
  color: var(--texto-suave);
  margin-top: 0.1rem;
}

/* Insights Dashboard Panels */
.insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.insight-card {
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 1.25rem;
  box-shadow: var(--sombra-sm);
}

.insight-card h3 {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--texto);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.insight-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.insight-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

.insight-name {
  font-weight: 600;
  color: #334155;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.insight-val {
  font-weight: 700;
  color: var(--azul-primary);
  background: var(--azul-claro);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
}

.bar-bg {
  height: 6px;
  background: #f1f5f9;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.25rem;
}
.bar-fill {
  height: 100%;
  background: var(--azul-primary);
  border-radius: 999px;
}

/* Forms & Inputs */
label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #334155;
}

input, select, button {
  font: inherit;
  border-radius: var(--raio-sm);
  border: 1px solid var(--borda);
  padding: 0.55rem 0.8rem;
  background: var(--superficie);
  color: var(--texto);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--borda-foco);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.18);
}

button {
  background: var(--azul-primary);
  color: #fff;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: background 0.15s, transform 0.05s, box-shadow 0.15s;
}
button:hover { background: var(--azul-hover); box-shadow: var(--sombra-sm); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.65; cursor: not-allowed; }

.botao-alerta {
  background: #b45309;
  color: #fff;
}
.botao-alerta:hover { background: #92400e; }

/* Filter Panel */
.filtros-painel {
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  box-shadow: var(--sombra-sm);
  padding: 1.35rem;
  margin-bottom: 1.5rem;
}

.filtros-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1rem;
}

.filtros-grid .full-col {
  grid-column: 1 / -1;
}

.filtros-acoes {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--borda);
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.filtros-botoes {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  align-items: center;
}

.botao-secundario {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.52rem 0.9rem;
  border: 1px solid var(--borda);
  border-radius: var(--raio-sm);
  text-decoration: none;
  color: #334155;
  background: var(--superficie);
  font-size: 0.88rem;
  font-weight: 500;
  transition: all 0.15s;
}
.botao-secundario:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: var(--texto);
}

/* Feedback Messages */
.erro {
  color: var(--vermelho);
  background: var(--vermelho-fundo);
  border: 1px solid var(--vermelho-borda);
  padding: 0.85rem 1.1rem;
  border-radius: var(--raio-sm);
  margin-bottom: 1.25rem;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.flash {
  color: var(--verde);
  background: var(--verde-fundo);
  border: 1px solid var(--verde-borda);
  padding: 0.85rem 1.1rem;
  border-radius: var(--raio-sm);
  margin-bottom: 1.25rem;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.vazio {
  color: var(--texto-secundario);
  background: var(--azul-claro);
  border: 1px dashed var(--azul-border);
  padding: 2.25rem 1.5rem;
  border-radius: var(--raio);
  text-align: center;
  font-size: 0.95rem;
}

.contador {
  color: var(--texto-secundario);
  font-size: 0.88rem;
  font-weight: 500;
}

/* Table Design */
.tabela-scroll {
  overflow-x: auto;
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  box-shadow: var(--sombra-sm);
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.88rem;
}

th, td {
  padding: 0.75rem 0.95rem;
  border-bottom: 1px solid var(--borda);
  text-align: left;
  white-space: nowrap;
}

th {
  background: #f8fafc;
  color: #475569;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 2px solid var(--borda);
  text-transform: uppercase;
  font-size: 0.76rem;
  letter-spacing: 0.04em;
}

tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: #f1f5f9; }

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.link-tabela {
  color: var(--azul-primary);
  text-decoration: none;
  font-weight: 600;
}
.link-tabela:hover { text-decoration: underline; }

/* Status Badges */
.sit {
  font-weight: 600;
  font-size: 0.76rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  letter-spacing: 0.02em;
}
.sit-co { background: var(--verde-fundo); color: var(--verde); border: 1px solid var(--verde-borda); }
.sit-er, .sit-re { background: var(--vermelho-fundo); color: var(--vermelho); border: 1px solid var(--vermelho-borda); }
.sit-ca, .sit-rt { background: var(--amarelo-fundo); color: var(--amarelo); border: 1px solid var(--amarelo-borda); }
.sit-in, .sit-su, .sit-cr { background: var(--roxo-fundo); color: var(--roxo); border: 1px solid var(--roxo-borda); }

.badge-origem {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: inline-block;
}
.badge-origem.sisgru { background: #e0f2fe; color: #0369a1; border: 1px solid #bae6fd; }
.badge-origem.api { background: #f3e8ff; color: #7e22ce; border: 1px solid #e9d5ff; }
.badge-origem.xml { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.badge-origem.import { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }

/* Pagination */
.paginacao {
  display: flex;
  gap: 0.4rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}
.paginacao a, .paginacao span {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--borda);
  border-radius: var(--raio-sm);
  background: var(--superficie);
  text-decoration: none;
  color: var(--texto);
  font-size: 0.88rem;
  min-width: 36px;
  text-align: center;
  transition: all 0.15s;
}
.paginacao a:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}
.paginacao .atual {
  background: var(--azul-primary);
  color: #fff;
  border-color: var(--azul-primary);
  font-weight: 600;
}

/* Detail Card */
.detalhe-card {
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  box-shadow: var(--sombra);
  padding: 1.75rem;
  margin-top: 1rem;
}

.detalhe-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--borda);
  flex-wrap: wrap;
  gap: 0.75rem;
}

.detalhe {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  gap: 0.65rem 1.25rem;
}
.detalhe dt {
  font-weight: 600;
  color: #475569;
  font-size: 0.88rem;
}
.detalhe dd {
  margin: 0;
  font-size: 0.92rem;
  word-break: break-word;
}

.raw-container {
  position: relative;
  margin-top: 1rem;
}
.btn-copiar {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  font-size: 0.78rem;
  padding: 0.3rem 0.6rem;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  border-radius: 4px;
}
.btn-copiar:hover {
  background: rgba(255, 255, 255, 0.3);
}

.raw {
  background: #0f172a;
  color: #e2e8f0;
  padding: 1.25rem;
  border-radius: var(--raio);
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.45;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.loading-aviso {
  display: none;
  align-items: center;
  gap: 0.6rem;
  color: var(--azul-primary);
  font-weight: 600;
  font-size: 0.95rem;
  margin-top: 1rem;
  padding: 0.85rem 1.1rem;
  background: var(--azul-claro);
  border-radius: var(--raio-sm);
  border: 1px solid var(--azul-border);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(0, 75, 135, 0.2);
  border-top-color: var(--azul-primary);
  border-radius: 50%;
  animation: girar 0.8s linear infinite;
}

@keyframes girar {
  to { transform: rotate(360deg); }
}

.erro-tabela {
  color: var(--vermelho);
  max-width: 420px;
  white-space: normal;
  font-size: 0.82rem;
}

code {
  background: var(--azul-claro);
  color: var(--azul-primary);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: ui-monospace, SFMono-Regular, monospace;
}

/* Media Queries & Responsive layout */
@media (max-width: 860px) {
  .topo {
    flex-direction: column;
    align-items: flex-start;
    padding: 0.85rem 1.25rem;
    gap: 0.75rem;
  }
  .topo nav {
    width: 100%;
    justify-content: flex-start;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  main {
    padding: 0 0.85rem;
    margin: 1rem auto;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .detalhe {
    grid-template-columns: 1fr;
    gap: 0.25rem 0;
  }
  .detalhe dt {
    margin-top: 0.6rem;
  }
  .filtros-grid {
    grid-template-columns: 1fr;
  }
  .filtros-acoes {
    flex-direction: column;
    align-items: stretch;
  }
  .filtros-botoes {
    flex-direction: column;
    width: 100%;
  }
  .filtros-botoes button, .filtros-botoes a {
    width: 100%;
    justify-content: center;
  }
}
