/* ====== Layout geral ====== */
html {
  height: 100%;
}

body {
  background-color: #f5f6fa;
  font-family: "Segoe UI", Arial, sans-serif;
  color: #333;
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

.container {
  max-width: 100% !important;
  width: 100% !important;
  padding-left: 15px;
  padding-right: 15px;
}

/* ====== Dropdown customizado para CNAE ====== */
.cnae-search-wrapper {
  position: relative;
}

.cnae-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 300px;
  overflow-y: auto;
  background: white;
  border: 1px solid #ced4da;
  border-top: none;
  border-radius: 0 0 0.375rem 0.375rem;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  z-index: 1000;
}

.cnae-dropdown.show {
  display: block;
}

.cnae-dropdown-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.9rem;
}

.cnae-dropdown-item:hover {
  background-color: #e9ecef;
}

.cnae-dropdown-item.selected {
  background-color: #0d6efd;
  color: white;
}

.cnae-dropdown-empty {
  padding: 12px;
  text-align: center;
  color: #6c757d;
  font-style: italic;
}

#cnaeDescricao:focus {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

#cnaeDescricao:focus + .cnae-dropdown.show {
  border-color: #86b7fe;
}

/* ====== Card ====== */
.app-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.05);
  padding: 16px;
  margin: 10px;
}

/* ====== Formulário ====== */
label.form-label {
  font-weight: 500;
  color: #444;
}

/* ====== Estados da Tabela ====== */
.empty-state, .loading-state, .error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.loading-state .spinner-border {
  width: 3rem;
  height: 3rem;
  border-width: 0.3rem;
}

.empty-state i, .error-state i {
  margin-bottom: 1rem;
}

/* ====== Container da Tabela ====== */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  margin-top: 12px;
  border-radius: 8px;
  border: 1px solid #eee;
}

/* ====== Tabela ====== */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  table-layout: auto; /* largura automática */
  white-space: nowrap;
  min-width: 1800px; /* evita esmagar colunas */
}

.table th,
.table td {
  padding: 10px 14px;
  vertical-align: middle;
  text-align: left;
  border-bottom: 1px solid #e6e6e6;
}

.table th {
  background-color: #f8f9fb;
  font-weight: 600;
  color: #333;
  text-transform: none;
  position: sticky;
  top: 0;
  z-index: 2;
}

/* ====== Fixar as 3 primeiras colunas ====== */
.table th:nth-child(1),
.table td:nth-child(1) {
  position: sticky;
  left: 0;
  background-color: #fff;
  z-index: 3;
  min-width: 140px;
}

.table th:nth-child(2),
.table td:nth-child(2) {
  position: sticky;
  left: 150px;
  background-color: #fff;
  z-index: 3;
  min-width: 220px;
}

.table th:nth-child(3),
.table td:nth-child(3) {
  position: sticky;
  left: 370px;
  background-color: #fff;
  z-index: 3;
  min-width: 200px;
}

.table td.pre-line {
  white-space: pre-line;
}

/* ====== Bordas da tabela ====== */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  table-layout: auto;
  white-space: normal;
  border: 1px solid #ddd; /* borda externa */
}

.table th,
.table td {
  padding: 6px 8px;
  vertical-align: middle;
  text-align: left;
  border: 1px solid #f0f0f0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-height: 38px;
  height: 38px !important;
  line-height: 26px;
  word-break: keep-all;
}

/* Remove qualquer possibilidade de quebra */
.table tbody tr {
  height: 38px;
  max-height: 38px;
}

/* Cabeçalho mais destacado */
.table th {
  background-color: #f8f9fa;
  font-weight: 600;
  color: #333;
  text-transform: none;
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 2px solid #ccc;
  height: 42px !important;
}


/* ====== Larguras suaves ====== */
.table th:nth-child(1), .table td:nth-child(1) { min-width: 150px; max-width: 150px; }
.table th:nth-child(2), .table td:nth-child(2) { min-width: 250px; max-width: 250px; }
.table th:nth-child(3), .table td:nth-child(3) { min-width: 200px; max-width: 200px; }
.table th:nth-child(4), .table td:nth-child(4) { min-width: 200px; max-width: 200px; }
.table th:nth-child(5), .table td:nth-child(5) { min-width: 100px; max-width: 100px; text-align: center; }
.table th:nth-child(6), .table td:nth-child(6) { min-width: 80px; max-width: 80px; text-align: center; }
.table th:nth-child(7), .table td:nth-child(7) { min-width: 120px; max-width: 120px; text-align: right; }
.table th:nth-child(8), .table td:nth-child(8) { min-width: 80px; max-width: 80px; text-align: center; }
.table th:nth-child(9), .table td:nth-child(9) { min-width: 60px; max-width: 60px; text-align: center; }
.table th:nth-child(10), .table td:nth-child(10) { min-width: 100px; max-width: 100px; text-align: center; }
.table th:nth-child(11), .table td:nth-child(11) { min-width: 100px; max-width: 100px; text-align: center; }
.table th:nth-child(12), .table td:nth-child(12) { min-width: 200px; max-width: 200px; }
.table th:nth-child(13), .table td:nth-child(13) { min-width: 200px; max-width: 200px; }
.table th:nth-child(14), .table td:nth-child(14) { min-width: 250px; max-width: 250px; }
.table th:nth-child(15), .table td:nth-child(15) { min-width: 60px; max-width: 60px; text-align: center; }
.table th:nth-child(16), .table td:nth-child(16) { min-width: 100px; max-width: 100px; }
.table th:nth-child(17), .table td:nth-child(17) { min-width: 150px; max-width: 150px; }
.table th:nth-child(18), .table td:nth-child(18) { min-width: 90px; max-width: 90px; text-align: center; }
.table th:nth-child(19), .table td:nth-child(19) { min-width: 50px; max-width: 50px; text-align: center; }
.table th:nth-child(20), .table td:nth-child(20) { min-width: 150px; max-width: 150px; }
.table th:nth-child(21), .table td:nth-child(21) { min-width: 120px; max-width: 120px; }
.table th:nth-child(22), .table td:nth-child(22) { min-width: 120px; max-width: 120px; }
.table th:nth-child(23), .table td:nth-child(23) { min-width: 200px; max-width: 200px; }
.table th:nth-child(24), .table td:nth-child(24) { min-width: 250px; max-width: 250px; }
.table th:nth-child(25), .table td:nth-child(25) { min-width: 120px; max-width: 120px; text-align: center; font-weight: 600; }
.table th:nth-child(26), .table td:nth-child(26) {
  min-width: 150px;
  text-align: center;
  font-weight: 600;
  color: #444;
}
.table th:nth-child(27), .table td:nth-child(27) { min-width: 180px; }



/* ====== Paginação Otimizada ====== */
.paginacao {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #dee2e6;
}

.pagination-info {
  text-align: center;
  font-size: 14px;
  color: #495057;
}

.pagination-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.pagination-controls button {
  min-width: 40px;
  height: 35px;
  font-size: 13px;
}

.pagination-jump {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.pagination-jump label {
  margin: 0;
  font-weight: 500;
  color: #495057;
}

/* Destaque do campo UF obrigatório */
.form-label .text-danger {
  font-weight: bold;
}

.form-select.is-invalid {
  border-color: #dc3545;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right calc(0.375em + 0.1875rem) center;
  background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.invalid-feedback {
  display: none;
  font-size: 0.875rem;
  color: #dc3545;
}

.form-select.is-invalid ~ .invalid-feedback {
  display: block;
}

/* ====== Painel de Estatísticas ====== */
.stats-panel {
  margin: 20px 0;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-bottom: 15px;
}

.stat-card {
  background: white;
  border-radius: 10px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 15px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border-left: 4px solid;
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.stat-card.stat-primary {
  border-left-color: #0d6efd;
  background: linear-gradient(135deg, #ffffff 0%, #e7f1ff 100%);
}

.stat-card.stat-success {
  border-left-color: #198754;
  background: linear-gradient(135deg, #ffffff 0%, #e7f5ed 100%);
}

.stat-card.stat-info {
  border-left-color: #0dcaf0;
  background: linear-gradient(135deg, #ffffff 0%, #e7f9fc 100%);
}

.stat-card.stat-warning {
  border-left-color: #ffc107;
  background: linear-gradient(135deg, #ffffff 0%, #fff9e6 100%);
}

.stat-icon {
  font-size: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.stat-primary .stat-icon {
  color: #0d6efd;
}

.stat-success .stat-icon {
  color: #198754;
}

.stat-info .stat-icon {
  color: #0dcaf0;
}

.stat-warning .stat-icon {
  color: #ffc107;
}

.stat-content {
  flex: 1;
}

.stat-label {
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 600;
  color: #6c757d;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: #212529;
  line-height: 1;
  font-family: 'Segoe UI', system-ui, sans-serif;
}

.stats-details {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #dee2e6;
}

.filter-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: white;
  border-radius: 20px;
  font-size: 13px;
  color: #495057;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.filter-badge i {
  color: #0d6efd;
}

.filter-badge strong {
  color: #212529;
}

.filter-badge span {
  color: #0d6efd;
  font-weight: 600;
}

/* Responsividade do painel de stats */
@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .stat-value {
    font-size: 24px;
  }
  
  .stat-icon {
    font-size: 28px;
    width: 50px;
    height: 50px;
  }
}


/* ====== Hover ====== */
.table-hover tbody tr:hover {
  background-color: #eef4ff;
  transition: 0.2s;
}

/* Tooltip no hover para ver conteúdo completo */
.table td {
  position: relative;
  cursor: pointer;
}

.table td:hover::after {
  content: attr(title);
  position: absolute;
  left: 0;
  top: 100%;
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 12px;
  white-space: normal;
  max-width: 300px;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  word-wrap: break-word;
  line-height: 1.4;
}

.table td:hover::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 100%;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid rgba(0, 0, 0, 0.9);
  z-index: 1001;
}

/* Tooltip no hover para ver conteúdo completo */
.table td {
  position: relative;
  cursor: pointer;
}

.table td:hover::after {
  content: attr(title);
  position: absolute;
  left: 0;
  top: 100%;
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 12px;
  white-space: normal;
  max-width: 300px;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  word-wrap: break-word;
  line-height: 1.4;
}

.table td:hover::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 100%;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid rgba(0, 0, 0, 0.9);
  z-index: 1001;
}

/* ====== Situação visual ====== */
.table td.situacao-ATIVA { color: #0a7d28; font-weight: 600; }
.table td.situacao-INATIVA { color: #a00; font-weight: 600; }
.table td.situacao-BAIXADA { color: #888; font-style: italic; }

/* ====== Scrollbar ====== */
.table-wrap::-webkit-scrollbar {
  height: 8px;
}
.table-wrap::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}
.table-wrap::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* ====== Spinner ====== */
#spinnerOverlay {
  position: fixed;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.spinner {
  width: 50px;
  height: 50px;
  border: 5px solid #ddd;
  border-top-color: #0d6efd;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ====== Modal de Exportação ====== */
.export-modal {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(3px);
}

.export-modal-content {
  background: white;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  min-width: 400px;
  max-width: 500px;
  text-align: center;
  animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.export-modal-content h4 {
  margin: 0 0 15px 0;
  color: #0d6efd;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.export-modal-content h4 i {
  font-size: 28px;
}

.export-modal-content p {
  margin: 10px 0;
  color: #495057;
  font-size: 16px;
}

.progress-bar {
  width: 100%;
  height: 30px;
  background: #e9ecef;
  border-radius: 15px;
  overflow: hidden;
  margin: 20px 0;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #0d6efd 0%, #0dcaf0 100%);
  transition: width 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  font-size: 13px;
  border-radius: 15px;
}

.export-details {
  font-size: 14px;
  color: #6c757d;
  font-weight: 600;
}

/* Responsividade do modal */
@media (max-width: 576px) {
  .export-modal-content {
    min-width: 90%;
    padding: 20px;
  }
}
