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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f6f8;
  color: #1a1a1a;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background: linear-gradient(135deg, #1f3a5f 0%, #2c5282 100%);
  color: #fff;
  padding: 24px 32px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-logo-link { display: flex; align-items: center; flex-shrink: 0; }

.header-logo {
  height: 40px;
  width: auto;
  filter: brightness(0) invert(1);
}

.tagline {
  font-size: 14px;
  opacity: 0.85;
  margin-top: 4px;
}

main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 32px;
}

.controls {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  margin-bottom: 24px;
}

.upload-zone {
  border: 2px dashed #cbd5e1;
  border-radius: 10px;
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: #fafbfc;
}

.upload-zone:hover, .upload-zone.dragging {
  border-color: #2c5282;
  background: #f0f6ff;
}

.upload-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.upload-texto strong {
  display: block;
  font-size: 16px;
  color: #1a1a1a;
  margin-bottom: 4px;
}

.upload-texto span {
  display: block;
  font-size: 13px;
  color: #475569;
  margin-bottom: 6px;
}

.upload-texto small {
  display: block;
  font-size: 11px;
  color: #94a3b8;
}

.upload-texto a {
  color: #2c5282;
  text-decoration: underline;
  font-weight: 600;
}

.controls-divisor {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: #94a3b8;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.controls-divisor::before,
.controls-divisor::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e2e8f0;
}

.btn-secundario {
  background: #fff;
  color: #475569;
  border: 1.5px solid #cbd5e1;
  width: 100%;
}

.btn-secundario:hover {
  background: #f8fafc;
  color: #2c5282;
  border-color: #2c5282;
}

.status-extracao {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-extracao.info {
  background: #f0f6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

.status-extracao.erro {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.status-extracao.sucesso {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.btn-destaque {
  background: #16a34a !important;
  color: #fff !important;
  border-color: #16a34a !important;
}

.btn-destaque:hover {
  background: #15803d !important;
  border-color: #15803d !important;
}

/* ===== Modal de mapa ===== */
.modal-mapa {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #000;
}

#mapa-container {
  width: 100%;
  height: 100vh;
}

.mapa-barra-topo {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 1001;
  display: flex;
  gap: 8px;
  align-items: center;
}

.busca-wrapper {
  position: relative;
  flex: 1;
  max-width: 560px;
}

.busca-endereco {
  display: flex;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.busca-contexto {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 4px;
  pointer-events: none;
}

.dropdown-resultados {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  max-height: 320px;
  overflow-y: auto;
  z-index: 1002;
}

.resultado-item {
  width: 100%;
  display: block;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid #f1f5f9;
  padding: 10px 14px;
  cursor: pointer;
  color: #1a1a1a;
}

.resultado-item:last-child { border-bottom: none; }
.resultado-item:hover { background: #f0f6ff; }

.resultado-item strong {
  display: block;
  font-size: 14px;
  margin-bottom: 2px;
  color: #1a1a1a;
  font-weight: 600;
}

.resultado-item small {
  display: block;
  font-size: 12px;
  color: #64748b;
  line-height: 1.4;
}

.resultado-vazio, .resultado-carregando {
  padding: 12px 14px;
  font-size: 13px;
  color: #64748b;
  text-align: center;
}

.busca-endereco input {
  flex: 1;
  border: none;
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
}

.busca-endereco button {
  background: #2c5282;
  color: #fff;
  border: none;
  padding: 0 16px;
  cursor: pointer;
  font-size: 16px;
}

.busca-endereco button:hover { background: #1f3a5f; }

.btn-fechar {
  margin-left: auto;
  background: #fff;
  color: #1a1a1a;
  border: none;
  height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-fechar:hover { background: #f1f5f9; }

.mapa-painel-lateral {
  position: absolute;
  right: 12px;
  top: 70px;
  z-index: 1001;
  width: 280px;
  background: #fff;
  border-radius: 10px;
  padding: 18px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  max-height: calc(100vh - 90px);
  overflow-y: auto;
}

.mapa-painel-lateral h3 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #475569;
  margin-bottom: 14px;
}

.campo-controle {
  margin-bottom: 16px;
}

.campo-controle label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 6px;
}

.campo-controle input[type="range"] {
  width: 100%;
  margin-bottom: 6px;
}

.botoes-rotacao {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.botoes-rotacao button {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
}

.botoes-rotacao button:hover { background: #e2e8f0; color: #2c5282; }

.cores {
  display: flex;
  gap: 6px;
}

.cor-opcao {
  width: 28px;
  height: 28px;
  border: 2px solid #cbd5e1;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
}

.cor-opcao.ativo {
  border-color: #1a1a1a;
  transform: scale(1.15);
}

.mapa-painel-lateral hr {
  border: none;
  border-top: 1px solid #e2e8f0;
  margin: 12px 0;
}

.mapa-dica {
  font-size: 12px;
  line-height: 1.6;
  color: #475569;
  background: #f8fafc;
  padding: 10px;
  border-radius: 6px;
}

.mapa-info {
  margin-top: 12px;
  font-size: 13px;
}

.mapa-info > div { margin-bottom: 4px; }
.mapa-info .lbl { color: #64748b; font-weight: 600; }

.mapa-exportacoes {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mapa-exportacoes .btn-export {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
}

button {
  background: #2c5282;
  color: #fff;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover { background: #1f3a5f; }
button:disabled { background: #94a3b8; cursor: not-allowed; }

.hint {
  margin-top: 12px;
  font-size: 13px;
  color: #64748b;
}

.resultado {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

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

.info-card {
  background: #f8fafc;
  padding: 12px 16px;
  border-radius: 8px;
  border-left: 3px solid #2c5282;
}

.info-card .label {
  display: block;
  font-size: 12px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.info-card .value {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
}

.info-card .value.ok { color: #16a34a; }
.info-card .value.warn { color: #d97706; }
.info-card .value.error { color: #dc2626; }

.canvas-wrapper {
  background: #fafbfc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px;
  overflow: auto;
}

canvas {
  display: block;
  max-width: 100%;
  background: #fff;
  border-radius: 4px;
}

.export-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 14px 16px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.export-label {
  font-weight: 600;
  font-size: 14px;
  color: #475569;
  margin-right: 4px;
}

.btn-export {
  background: #fff;
  color: #2c5282;
  border: 1.5px solid #2c5282;
  padding: 8px 16px;
  font-size: 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.15s;
}

.btn-export:hover:not(.btn-disabled) {
  background: #2c5282;
  color: #fff;
}

.btn-export.btn-disabled {
  color: #94a3b8;
  border-color: #cbd5e1;
  background: #f1f5f9;
  cursor: not-allowed;
  position: relative;
}

.export-hint {
  font-size: 12px;
  color: #64748b;
  margin-left: auto;
}

.tabela-segmentos {
  margin-top: 20px;
  background: #f8fafc;
  border-radius: 8px;
  padding: 12px 16px;
}

.tabela-segmentos summary {
  cursor: pointer;
  font-weight: 600;
  color: #2c5282;
  padding: 4px 0;
}

table {
  width: 100%;
  margin-top: 12px;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

th {
  background: #fff;
  font-weight: 600;
  color: #475569;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

tbody tr:hover { background: #fff; }

footer {
  text-align: center;
  padding: 20px;
  color: #94a3b8;
  font-size: 13px;
}

/* ===== Impressao do mapa ===== */
/* Legenda some na tela; aparece so quando o mapa e impresso. */
.legenda-impressao { display: none; }

@media print {
  /* Mapa e largo: imprime em paisagem, sem margens do navegador. */
  @page { size: landscape; margin: 0; }

  /* Ao imprimir o mapa, esconde tudo que nao for o mapa em si. */
  body.imprimindo-mapa > header,
  body.imprimindo-mapa > main,
  body.imprimindo-mapa > footer {
    display: none !important;
  }
  body.imprimindo-mapa .mapa-barra-topo,
  body.imprimindo-mapa .mapa-painel-lateral {
    display: none !important;
  }
  body.imprimindo-mapa .modal-mapa {
    position: absolute;
    inset: 0;
    background: #fff;
  }

  /* Legenda com numero da matricula e area, no canto inferior. */
  body.imprimindo-mapa .legenda-impressao {
    display: block;
    position: absolute;
    bottom: 12px;
    left: 12px;
    z-index: 2000;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 12px;
    color: #1a1a1a;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  }
  body.imprimindo-mapa .legenda-impressao strong {
    display: block;
    font-size: 14px;
    margin-bottom: 2px;
  }

  /* Garante que as cores/imagens do mapa sejam impressas. */
  body.imprimindo-mapa * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
