/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Garante que o atributo hidden sempre esconde o elemento,
   mesmo quando o CSS define display: flex ou display: grid */
[hidden] { display: none !important; }

:root {
  --azul:      #3b82f6;
  --azul-esc:  #1d4ed8;
  --azul-clr:  #eff6ff;
  --verde:     #22c55e;
  --verde-clr: #f0fdf4;
  --amarelo:   #f59e0b;
  --amarelo-clr: #fffbeb;
  --vermelho:  #ef4444;
  --verm-clr:  #fef2f2;
  --cinza:     #94a3b8;
  --cinza-clr: #f1f5f9;

  --sidebar-bg:   #0f172a;
  --sidebar-txt:  #94a3b8;
  --sidebar-sel:  #1e293b;

  --fundo:    #f8fafc;
  --card:     #ffffff;
  --borda:    #e2e8f0;
  --texto:    #1e293b;
  --texto-2:  #64748b;

  --sidebar-w: 220px;
  --raio: 10px;
  --sombra: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--texto);
  background: var(--fundo);
  line-height: 1.5;
}

/* ===== LOGIN ===== */
#tela-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}

.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  font-size: 18px;
  font-weight: 700;
  color: var(--texto);
}

.login-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--texto);
}

/* ===== LAYOUT PRINCIPAL ===== */
#painel {
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  font-size: 16px;
  font-weight: 700;
  color: white;
  border-bottom: 1px solid #1e293b;
}

.sidebar-empresa {
  padding: 16px;
  border-bottom: 1px solid #1e293b;
}

.sidebar-empresa label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--cinza);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
}

.sidebar-empresa select {
  width: 100%;
  background: var(--sidebar-sel);
  border: 1px solid #334155;
  color: white;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.sidebar-empresa select:focus { outline: none; border-color: var(--azul); }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--sidebar-txt);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
  user-select: none;
}

.nav-item:hover { background: var(--sidebar-sel); color: white; }
.nav-item.ativo  { background: var(--azul); color: white; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid #1e293b;
}

.btn-sair {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--cinza);
  font-size: 13px;
  transition: color .15s;
}

.btn-sair:hover { color: var(--vermelho); }

/* ===== CONTEÚDO ===== */
.conteudo {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px;
  max-width: calc(100vw - var(--sidebar-w));
}

.tab-content { display: block; }

/* ===== PAGE HEADER ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
}

.subtitulo {
  font-size: 13px;
  color: var(--texto-2);
  margin-top: 2px;
}

/* ===== CARDS ===== */
.card {
  background: var(--card);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--sombra);
}

.card.sem-padding { padding: 0; overflow: hidden; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
}

/* ===== FORMULÁRIOS ===== */
.campo {
  margin-bottom: 16px;
}

.campo label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--texto);
  margin-bottom: 6px;
}

.campo label .hint {
  font-weight: 400;
  color: var(--texto-2);
  font-size: 12px;
}

.campo input,
.campo select,
.campo textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--borda);
  border-radius: 7px;
  font-size: 14px;
  color: var(--texto);
  background: white;
  transition: border-color .15s, box-shadow .15s;
}

.campo input:focus,
.campo select:focus,
.campo textarea:focus {
  outline: none;
  border-color: var(--azul);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.grade-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grade-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 16px; }

.acoes {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

/* ===== BOTÕES ===== */
.btn-primario,
.btn-secundario {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
}

.btn-primario {
  background: var(--azul);
  color: white;
}
.btn-primario:hover { background: var(--azul-esc); }
.btn-primario:disabled { opacity: .6; cursor: not-allowed; }

.btn-secundario {
  background: white;
  color: var(--texto);
  border: 1px solid var(--borda);
}
.btn-secundario:hover { background: var(--cinza-clr); }

.btn-full { width: 100%; justify-content: center; padding: 12px; font-size: 14px; }

.btn-link {
  background: none;
  border: none;
  color: var(--azul);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
  margin-top: 6px;
  display: block;
}
.btn-link:hover { text-decoration: underline; }

.btn-fechar {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--texto-2);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.btn-fechar:hover { background: var(--cinza-clr); }

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
}

.badge-verde   { background: var(--verde-clr); color: #15803d; }
.badge-vermelho{ background: var(--verm-clr);  color: #b91c1c; }
.badge-amarelo { background: var(--amarelo-clr); color: #b45309; }
.badge-azul    { background: var(--azul-clr);  color: var(--azul-esc); }
.badge-cinza   { background: var(--cinza-clr); color: var(--texto-2); }

/* ===== TABELAS ===== */
.tabela {
  width: 100%;
  border-collapse: collapse;
}

.tabela thead th {
  background: var(--cinza-clr);
  padding: 11px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--texto-2);
  text-transform: uppercase;
  letter-spacing: .03em;
  border-bottom: 1px solid var(--borda);
}

.tabela tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--borda);
  font-size: 13px;
  color: var(--texto);
}

.tabela tbody tr:last-child td { border-bottom: none; }
.tabela tbody tr:hover td { background: var(--cinza-clr); }

.tabela .btn-ver {
  background: none;
  border: 1px solid var(--borda);
  color: var(--azul);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.tabela .btn-ver:hover { background: var(--azul-clr); border-color: var(--azul); }

/* ===== FILTROS ===== */
.filtros {
  margin-bottom: 16px;
  display: flex;
  gap: 12px;
}

.filtros select {
  padding: 8px 12px;
  border: 1px solid var(--borda);
  border-radius: 7px;
  font-size: 13px;
  background: white;
  color: var(--texto);
}

/* ===== RESULTADO TESTE FIREBIRD ===== */
.resultado-teste {
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
}
.resultado-ok    { background: var(--verde-clr); color: #15803d; }
.resultado-erro  { background: var(--verm-clr);  color: #b91c1c; }

/* ===== MENSAGENS DE ERRO / INFO ===== */
.msg-erro {
  color: var(--vermelho);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
}

.texto-centro { text-align: center; }
.carregando   { color: var(--texto-2); padding: 32px !important; }

/* ===== MODAIS ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-card {
  background: var(--card);
  border-radius: var(--raio);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.modal-grande .modal-card { max-width: 680px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--borda);
  position: sticky;
  top: 0;
  background: white;
}

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-card form,
#corpo-modal-conversa,
#corpo-modal-orcamento {
  padding: 24px;
}

/* ===== CONVERSAS — mensagens ===== */
.mensagens-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 60vh;
  overflow-y: auto;
}

.msg-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
}

.msg-bubble.cliente {
  background: var(--cinza-clr);
  color: var(--texto);
  align-self: flex-start;
  border-bottom-left-radius: 3px;
}

.msg-bubble.bot {
  background: var(--azul);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 3px;
}

.msg-bubble.bloqueada {
  background: var(--verm-clr);
  color: #b91c1c;
  align-self: flex-start;
}

.msg-meta {
  font-size: 11px;
  opacity: .6;
  margin-top: 4px;
}

/* ===== ORÇAMENTO DETALHE ===== */
.orc-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.orc-info-item label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--texto-2);
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: 2px;
}

.orc-info-item span {
  font-size: 14px;
  color: var(--texto);
}

.orc-itens-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  border-top: 1px solid var(--borda);
  padding-top: 16px;
}

.orc-total {
  border-top: 2px solid var(--borda);
  padding-top: 12px;
  margin-top: 8px;
  text-align: right;
  font-size: 16px;
  font-weight: 700;
}

/* ===== SPINNER ===== */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: white;
  z-index: 300;
  animation: slideUp .2s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}

.toast.sucesso  { background: #16a34a; }
.toast.erro     { background: var(--vermelho); }
.toast.info     { background: var(--azul); }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== TOOLTIP ===== */
.tooltip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  background: var(--texto-2);
  color: white;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  position: relative;
  margin-left: 5px;
  user-select: none;
  vertical-align: middle;
  flex-shrink: 0;
  transition: background .15s;
}

.tooltip-icon:hover { background: var(--azul); }

.tooltip-icon .tooltip-text {
  display: none;
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: white;
  font-size: 12px;
  font-weight: 400;
  padding: 10px 14px;
  border-radius: 8px;
  width: 260px;
  line-height: 1.6;
  z-index: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  white-space: normal;
  pointer-events: none;
}

.tooltip-icon .tooltip-text::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #1e293b;
}

.tooltip-icon:hover .tooltip-text,
.tooltip-icon.aberto .tooltip-text {
  display: block;
}

/* Quando o tooltip abrir para um campo no final da página, abre para baixo */
.tooltip-icon.tooltip-baixo .tooltip-text {
  bottom: auto;
  top: calc(100% + 10px);
}
.tooltip-icon.tooltip-baixo .tooltip-text::after {
  top: auto;
  bottom: 100%;
  border-top-color: transparent;
  border-bottom-color: #1e293b;
}

/* ===== ASSISTENTE DE MAPEAMENTO ===== */
.secao-subtitulo {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--texto-2);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--borda);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  white-space: nowrap;
}

.assistente-card {
  background: var(--cinza-clr);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 20px;
  margin-bottom: 24px;
}

.assistente-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 14px;
}

/* ===== BANNER DE DETECÇÃO ===== */
.banner-deteccao {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 20px;
  line-height: 1.5;
}

.banner-deteccao.sucesso {
  background: var(--verde-clr);
  border: 1px solid #bbf7d0;
  color: #15803d;
}

.banner-deteccao.aviso {
  background: var(--amarelo-clr);
  border: 1px solid #fde68a;
  color: #92400e;
}

.banner-deteccao .banner-icon {
  font-size: 16px;
  flex-shrink: 0;
  margin-top: 1px;
}

.banner-deteccao strong { font-weight: 600; }

/* ===== CHECKBOX LABEL ===== */
.label-check {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--texto);
}

.label-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  accent-color: var(--azul);
  cursor: pointer;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }
  .conteudo { margin-left: 0; padding: 20px; }
  .grade-2, .grade-3 { grid-template-columns: 1fr; }
}
