/* ================================================================
  SISTEMA GAFA - ESTILO GLOBAL E MODULAR (Versão 2.1 - Otimizada)
  Pesquisa, Tecnologia e Inovação em Dados
   ================================================================ */

/* --- 1. VARIÁVEIS DO SISTEMA E RESET --- */
:root {
  --gafa-blue: #003366;
  --gafa-blue-dark: #002244;
  --gafa-orange: #FF8C00;
  --gafa-orange-hover: #e67e00;
  --gafa-light: #f4f7f6;
  --gafa-text: #333333;
  --gafa-white: #ffffff;
  --gafa-border: #dee2e6;
  --excel-yellow: #fff9db;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--gafa-light);
  color: var(--gafa-text);
  margin: 0;
  padding: 0;
  line-height: 1.6;
}

/* Scrollbars Globais */
.custom-scrollbar::-webkit-scrollbar {
  height: 8px;
  width: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: #bbb;
}


/* --- 2. LAYOUT BASE E NAVEGAÇÃO --- */
.navbar {
  background-color: var(--gafa-blue) !important;
  border-bottom: 3px solid var(--gafa-orange);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  padding: 0.8rem 1rem;
  position: relative;
  z-index: 1050 !important;
}

.navbar-brand {
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gafa-white) !important;
  display: flex;
  align-items: center;
}

.navbar-brand span {
  color: var(--gafa-orange);
}

.action-footer-fixed {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.98);
  border-top: 2px solid var(--gafa-blue);
  padding: 15px;
  z-index: 2000;
  box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.1);
  transform: none !important;
}

/* Desabilita o deslocamento de 2px apenas nos botões do rodapé fixo */
.action-footer-fixed .btn:hover {
  transform: none !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
  /* Mantém apenas a sombra no hover */
}

/* Garante que o rodapé fique sempre acima de qualquer outro elemento da tabela */
.action-footer-fixed {
  z-index: 3000 !important;
}


/* --- 3. BOTÕES E BADGES --- */
.btn-gafa {
  background-color: var(--gafa-blue) !important;
  color: var(--gafa-white) !important;
  font-weight: 600;
  border: 2px solid transparent;
  padding: 10px 24px;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.btn-gafa:hover {
  background-color: var(--gafa-blue-dark) !important;
  border-color: var(--gafa-orange);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn-gafa:active {
  transform: translateY(0);
  box-shadow: none;
}

.btn-gafa-alt {
  background-color: var(--gafa-orange) !important;
  color: var(--gafa-white) !important;
}

.btn-gafa-alt:hover {
  background-color: var(--gafa-orange-hover) !important;
}

.btn-audit {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.btn-audit:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.btn-validar:hover {
  background-color: #198754;
  color: white;
  border-color: #198754;
}

.btn-manter:hover {
  background-color: #6c757d;
  color: white;
  border-color: #6c757d;
}

.key-badge {
  font-family: 'Courier New', Courier, monospace;
  background: #e9ecef;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--gafa-blue);
  font-weight: bold;
}


/* --- 4. TABELA PRINCIPAL (HIGIENIZAÇÃO E FIX DO CABEÇALHO) --- */
.mass-clean-wrapper {
  min-height: 100vh;
  padding-bottom: 120px;
  display: flex;
  flex-direction: column;
}

/* 1. Remove o efeito de "pulo" do card nesta página específica para não deslocar o rodapé fixo */
.mass-clean-wrapper .card:hover {
  transform: none !important;
}

/* 2. Mantém a sombra no card ao passar o mouse (para manter o feedback visual sem mover) */
.mass-clean-wrapper .card:hover {
  box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .08) !important;
}

.table-responsive-excel {
  height: calc(100vh - 280px);
  /* Altura dinâmica unificada */
  min-height: 450px;
  overflow: auto;
  border: 1px solid var(--gafa-border);
  background: var(--gafa-white);
  position: relative;
  border-radius: 4px;
  margin-bottom: 80px;
}

/* FIX DEFINITIVO DO CABEÇALHO (Sticky e Z-Index Consolidado) */
#excelTable thead th,
.table-responsive-excel thead th,
.sticky-header-dark th {
  position: sticky !important;
  top: 0 !important;
  z-index: 2100 !important;
  /* Prioridade máxima sobre o corpo da tabela */
  background-color: #212529 !important;
  color: var(--gafa-white) !important;
  min-width: 160px;
  padding: 12px 8px 45px 8px !important;
  text-align: left;
  font-size: 0.75rem;
  border-bottom: 2px solid #444;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  background-clip: padding-box;
  /* Evita que o texto vaze nas bordas invisíveis */
}

/* Corpo da tabela principal */
#excelTable tbody td {
  color: #212529 !important;
  background-color: #ffffff !important;
  vertical-align: middle !important;
  font-size: 0.85rem;
  border: 1px solid #eee;
  height: 48px;
  padding: 4px 10px;
  max-width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#excelTable tbody td:hover {
  cursor: help;
  background-color: #fff9db !important;
}

.target-column-highlight {
  background-color: var(--excel-yellow) !important;
  border-left: 2px solid var(--gafa-orange) !important;
  border-right: 2px solid var(--gafa-orange) !important;
}

/* Melhorias Visuais de Foco (UX) */
table tbody tr.data-row:hover {
  --bs-table-bg-state: #f8f9fa !important;
  cursor: pointer;
}

table tbody tr.data-row:focus-within {
  --bs-table-bg-state: #e6f2ff !important;
}

table tbody tr.data-row:focus-within td {
  border-top: 1px solid #0d6efd !important;
  border-bottom: 1px solid #0d6efd !important;
}

.correction-input:focus {
  border: 2px solid #0d6efd !important;
  box-shadow: 0 0 10px rgba(13, 110, 253, 0.2) !important;
  outline: none;
}

/* Destaque das Sugestões da IA (Quebra de Linha Automática) */
.suggestion-info {
  display: block !important;
  width: 100% !important;
  white-space: pre-wrap !important;
  word-wrap: break-word !important;
  overflow-wrap: break-word !important;
  overflow: visible !important;
  line-height: 1.2 !important;
  margin-top: 5px;
}


/* --- 5. FILTROS (DROPDOWNS TIPO EXCEL) --- */
.excel-filter-container {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
}

.filter-trigger {
  background: #495057;
  color: #fff;
  padding: 4px 8px;
  font-size: 0.7rem;
  border: 1px solid #666;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
}

.filter-dropdown-content {
  display: none !important;
  position: absolute;
  min-width: 280px !important;
  max-height: 400px !important;
  display: flex !important;
  flex-direction: column !important;
  background: white !important;
  border: 1px solid var(--gafa-border) !important;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2) !important;
  z-index: 9999 !important;
  border-radius: 4px;
  overflow: hidden;
}

.excel-filter-container .filter-dropdown-content {
  display: none !important;
}

.excel-filter-container .filter-dropdown-content.active {
  display: flex !important;
}

.filter-list-container {
  flex: 1 !important;
  overflow-y: auto !important;
  min-height: 100px;
  background: #fff;
}

.cb-item {
  display: flex !important;
  align-items: center !important;
  padding: 8px 12px !important;
  width: 100%;
  transition: background 0.2s;
  border-bottom: 1px solid #f1f1f1;
}

.cb-item:hover {
  background-color: #f8f9fa;
}

.cb-item label {
  font-size: 1.1rem !important;
  margin-bottom: 0 !important;
  margin-left: 10px !important;
  cursor: pointer;
  color: var(--gafa-text);
  font-weight: 500;
  white-space: nowrap;
}

.cb-item input[type="checkbox"] {
  width: 18px !important;
  height: 18px !important;
  cursor: pointer;
  margin: 0 !important;
}

.filter-dropdown-buttons {
  padding: 10px !important;
  background: #f8f9fa !important;
  border-top: 1px solid #dee2e6 !important;
  flex-shrink: 0 !important;
}

.filter-dropdown-buttons button {
  width: 100% !important;
}


/* --- 6. TABELAS SECUNDÁRIAS (AUDITORIA, SEMÂNTICA E MODAL) --- */
.auditoria-table {
  width: 100%;
  border-collapse: collapse;
  background-color: #fff;
}

.auditoria-table thead tr {
  background-color: #212529 !important;
  color: #ffffff !important;
  text-align: left;
}

.auditoria-table th {
  padding: 15px 10px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

.auditoria-table td {
  padding: 15px 10px;
  border-bottom: 1px solid #eee;
}

.auditoria-table tbody tr:hover td {
  background-color: rgba(13, 110, 253, 0.08) !important;
  transition: all 0.2s ease-in-out;
}

.pai-column {
  background-color: #fcfcfc;
  border-right: 2px solid #f0f0f0;
  vertical-align: top;
}

/* Tabela Semântica */
#semantica-tbody tr:hover td {
  background-color: rgba(0, 51, 102, 0.07) !important;
  transition: background-color 0.2s ease;
}

#semantica-tbody .small-text-pair {
  font-size: 0.95rem !important;
  color: var(--gafa-text);
}

#semantica-tbody .context-text {
  font-size: 0.85rem !important;
  color: #6c757d;
  font-style: italic;
}

#semantica-tbody .btn-acao-semantica {
  width: 100px !important;
  font-size: 0.85rem !important;
  padding: 5px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

#semantica-tbody .textarea-audit {
  font-size: 1.1rem !important;
  font-weight: 500;
  border: 1px solid var(--gafa-border);
  background-color: var(--gafa-white);
}

/* Tabela Modal Spell Checker */
#spell-checker-tbody tr td,
#spell-checker-tbody tr td span {
  font-size: 1.1rem !important;
  font-weight: bolder;
}

#spell-checker-tbody tr td input {
  font-size: 1.1rem !important;
  height: auto;
  font-weight: bold;
  color: #0d6efd;
}

#spell-checker-tbody tr:hover td {
  background-color: rgba(13, 110, 253, 0.08) !important;
  transition: all 0.2s ease-in-out;
  cursor: pointer;
}

#spell-checker-tbody input.form-control-sm:focus {
  border-color: var(--gafa-orange);
  box-shadow: 0 0 0 0.2rem rgba(255, 140, 0, 0.25);
}


/* --- 7. CARDS E UTILITÁRIOS GERAIS --- */
.dashboard-widget-scroll {
  max-height: 320px;
  overflow-y: auto;
}

.text-unanswered {
  color: #adb5bd;
  font-style: italic;
}

.dictionary-item:hover {
  background-color: #f1f3f5;
  transition: background 0.2s;
}

.dropdown-menu {
  z-index: 1050 !important;
}

.card {
  overflow: visible !important;
}

.selectable-card {
  transition: all 0.3s ease;
  border-width: 1px !important;
}

.card-selected {
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25) !important;
}

.border-dashed {
  border-style: dashed !important;
}

.sticky-bottom {
  z-index: 1020;
  border-radius: 15px 15px 0 0;
}

.sticky-top {
  top: -1px;
  z-index: 10;
}

.term-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.term-item {
  padding: 4px 0;
  display: flex;
  align-items: center;
}

code {
  font-size: 0.85em;
  padding: 2px 6px;
  background: #f8f9fa;
  color: #d63384;
  border-radius: 4px;
  border: 1px solid #e9ecef;
}

.bg-info-light {
  background-color: #e1f5fe;
  color: #0288d1;
}

.badge-score {
  font-size: 0.7rem;
  padding: 3px 6px;
  font-weight: bold;
}

.term-pai-atual {
  color: #212529;
  font-weight: 700;
  line-height: 1.2;
}

.sugestao-robo {
  color: #0d6efd;
  font-weight: 700;
  line-height: 1.2;
}

.term-compare-box {
  word-wrap: break-word;
  white-space: normal;
  line-height: 1.3;
}

.term-atual-text {
  color: #212529;
  font-weight: 700;
  font-size: 0.95rem;
}

.term-sugestao-text {
  color: #0d6efd;
  font-weight: 700;
  font-size: 0.95rem;
}

.transition-row {
  transition: all 0.4s ease;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* --- 8. PLAYGROUND E RENDERIZAÇÃO DINÂMICA (TEMPLATES) --- */

/* Variáveis de fallback caso o banco esteja vazio */
:root {
  --primary-accent: #990000;
  --header-bg: #e6e6e6;
  --font-size-table: 0.85rem;
}

.playground-table {
  font-size: var(--font-size-table) !important;
}

.playground-table .target-header {
  background-color: var(--header-bg) !important;
  color: var(--primary-accent) !important;
  font-weight: 900 !important;
  transition: all 0.3s ease;
  /* Efeito suave ao trocar no Admin */
}

.playground-table th,
.playground-table td.row-label {
  background-color: var(--header-bg) !important;
  color: var(--primary-accent) !important;
}

.playground-table td.data-cell-zebra:nth-child(even) {
  background-color: #f2f2f2 !important;
}




/*===========================
  GERADOR DE TEMPLATES
  ============================*/


/* 1. LAYOUT DE 2 CONTAINERS (80/15) */
.editor-main-grid {
  display: flex;
  width: 100%;
  min-height: 80vh;
  gap: 20px;
  justify-content: center;
}

.area-tabela {
  flex: 0 0 80%;
  /* Espaço maior para os dados */
  background-color: #ffffff;
  /* Branco profissional, azul era para validação */
  padding: 30px;
  border-radius: 12px;
  border: 1px solid #dee2e6;
  overflow: auto;
  /* Scroll interno para tabelas largas */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.area-config {
  flex: 0 0 15%;
  /* Espaço menor para controles */
  background-color: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 12px;
  padding: 20px;
  position: sticky;
  top: 20px;
  height: fit-content;
}

/* 2. TABELA MASTER */
.table-master {
  width: 100%;
  min-width: 1000px;
  border-collapse: collapse;
  margin-bottom: 3rem;
  font-family: var(--f-family);
  font-size: var(--f-size);
  border: var(--b-width) solid var(--b-color);
}

/* style.css - REMOVA O !IMPORTANT DAQUI */
.table-master th,
.table-master td {
  border: var(--b-width) solid var(--b-color);
  padding: 10px 15px;
  vertical-align: middle;
  /* Removido o !important para permitir personalização */
  background-color: #ffffff;
}

/* 3. ESTILIZAÇÃO DO TÍTULO GLOBAL */
.cell-header-main {
  /* Imprescindível para o vertical-align funcionar */
  display: table-cell !important;

  height: var(--h-min-h);
  vertical-align: var(--t-align-v);
  line-height: var(--t-line-h);
  text-align: var(--t-align-h);

  /* Cores e Tipografia */
  background-color: var(--t-bg);
  color: var(--t-color);
  font-size: var(--t-f-size);
  text-decoration: var(--t-underline);

  /* Bordas Individuais Estilo Excel */
  border-top: var(--t-border-width) var(--t-border-top-style) var(--b-color) !important;
  border-bottom: var(--t-border-width) var(--t-border-bottom-style) var(--b-color) !important;
  border-left: var(--t-border-width) var(--t-border-left-style) var(--b-color) !important;
  border-right: var(--t-border-width) var(--t-border-right-style) var(--b-color) !important;

  transition: all 0.1s ease;
}

.cell-column-title {
  font-weight: bold;
  text-align: center;
  background-color: #fafafa !important;
}

.cell-label {
  font-weight: bold;
  color: var(--p-color) !important;
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
}

.cell-data {
  text-align: center;
}

.cell-missing-spacer {
  width: 45px;
  border-right: calc(var(--b-width) + 1px) solid var(--b-color) !important;
}

/* 4. INTERATIVIDADE */
.selectable {
  cursor: pointer;
  transition: all 0.2s;
}

.selectable:hover {
  outline: 2px dashed #0d6efd !important;
  outline-offset: -2px;
}

.selected-element {
  outline: 3px solid #ff8c00 !important;
  outline-offset: -2px;
}

/* Padronização dos botões de borda */
.btn-border-preset {
  width: 62px !important;
  height: 62px !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 4px !important;
  line-height: 1.1 !important;
  transition: all 0.2s ease;
}

.btn-border-preset i {
  font-size: 1.2rem !important;
  margin-bottom: 4px !important;
}

.btn-border-preset small {
  font-size: 0.6rem !important;
  text-transform: uppercase;
  font-weight: bold;
  display: block;
}

/* Ajuste do container para não espremer os botões */
.grid-border-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  /* 3 colunas iguais */
  gap: 8px;
  justify-items: center;
}


/* --- 9. AUTOCOMPLETE UI (FASE 3.3) --- */
.autocomplete-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 2500;
  /* Acima da tabela, abaixo do rodapé fixo */
  background: var(--gafa-white);
  border: 1px solid var(--gafa-border);
  border-radius: 0 0 4px 4px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
  max-height: 220px;
  overflow-y: auto;
  display: none;
}

.suggestion-item {
  padding: 10px 12px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--gafa-text);
  border-bottom: 1px solid #f1f1f1;
  transition: background 0.2s;
}

.suggestion-item:hover,
.suggestion-item.active {
  background-color: var(--gafa-light);
  color: var(--gafa-blue);
  font-weight: bold;
}

/* --- CORREÇÃO DEFINITIVA DO AUTOCOMPLETE (ETAPA 3.3) --- */

/* 1. Liberação do Overflow (Sem forçar z-index permanente) 
   Impede que a célula corte o dropdown, mas mantém a célula no seu nível original. */
#excelTable tbody td.position-relative {
  overflow: visible !important;
  white-space: normal !important;
}

/* 2. O Pulo do Gato (Contexto Dinâmico de Empilhamento)
  Garante que APENAS a célula ativa (onde o cursor está) salte para a frente.
  O valor 1000 sobrepõe as linhas de baixo, mas fica ABAIXO do cabeçalho (1020). 
*/
#excelTable tbody td.position-relative:focus-within {
  z-index: 1000 !important;
}

/* 3. Estética e Posição do Dropdown */
.autocomplete-suggestions {
  display: none;
  position: absolute;
  top: calc(100% - 6px);
  /* Fixa o menu "colado" na base do textarea */
  left: 4px;
  /* Respeita o padding interno da célula */
  right: 4px;
  background: var(--gafa-white);
  border: 1px solid var(--gafa-blue);
  border-top: none;
  /* Une visualmente com o input */
  border-radius: 0 0 6px 6px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15) !important;
  max-height: 200px;
  overflow-y: auto;
  z-index: 1005 !important;
}

/* 4. Opções do Menu */
.suggestion-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--gafa-text);
  border-bottom: 1px solid #f1f1f1;
}

.suggestion-item:hover {
  background-color: var(--gafa-blue);
  color: #ffffff;
  font-weight: bold;
}



/*
  ÁREA DE ACOMPANHAMENTO DE PESQUISAS
  🏛️ REFORMULAÇÃO MODERNA DOS BOTÕES E ABAS DO PAINEL DE MONITORAMENTO 
*/

/* Casca da Barra Superior */
.monitoring-wrapper .control-bar {
  background-color: #ffffff;
  border: 1px solid #eef2f6 !important;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03) !important;
  padding: 12px 16px !important;
}

/* Botão de Refresh Sutil */
.monitoring-wrapper .btn-refresh-modern {
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  color: #64748b;
  border-radius: 8px;
  transition: all 0.2s ease-in-out;
}

.monitoring-wrapper .btn-refresh-modern:hover {
  background-color: #f1f5f9;
  border-color: #cbd5e1;
  color: #0f172a;
  transform: translateY(-1px);
}

/* Grupo de Abas (Estilo Pílula Minimalista) */
.monitoring-wrapper .tab-nav-container {
  background-color: #f1f5f9;
  padding: 4px;
  border-radius: 8px;
  display: inline-flex;
  gap: 2px;
}

/* Botão de Aba Individual */
.monitoring-wrapper .btn-tab-modern {
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 16px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 95px;
  transition: all 0.2s ease-in-out;
}

/* Estado de Hover (Passar o Mouse) */
.monitoring-wrapper .btn-tab-modern:hover {
  color: #334155;
  background-color: rgba(255, 255, 255, 0.5);
}

/* Estado Ativo Elegante (Destaque limpo sem carregar a tela) */
.monitoring-wrapper .btn-tab-modern.active-tab-highlight {
  background-color: #ffffff !important;
  color: #0f172a !important;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08) !important;
}

/* Botão Especial de Sair */
.monitoring-wrapper .btn-tab-exit {
  background-color: rgba(239, 68, 68, 0.05);
  color: #ef4444;
  border-radius: 6px;
  border: 1px solid rgba(239, 68, 68, 0.1);
}

.monitoring-wrapper .btn-tab-exit:hover {
  background-color: #ef4444;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}