/**
 * FECHA CHEF PRO - ESTILOS DA IA
 * Botão 🤖 IA no topo, modal de configuração (chaves e provedores), modal "Organizar texto com IA",
 * aba "Perguntar" (chat) e selos "lido pela IA / lido pelo OCR" nos comprovantes.
 * Usa as variáveis do style.css e respeita o tema claro (body.theme-light).
 */

/* ==========================================
   BOTÃO DO TOPO + BOLINHA DE STATUS
   ========================================== */
.btn-ia-header { white-space: nowrap; }
.ia-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: var(--radius-full);
  background: #64748b;
  box-shadow: 0 0 0 2px rgba(100, 116, 139, 0.25);
  flex-shrink: 0;
}
.ia-dot-off { background: #64748b; box-shadow: 0 0 0 2px rgba(100, 116, 139, 0.25); }
.ia-dot-ligada { background: #fbbf24; box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3), 0 0 10px rgba(245, 158, 11, 0.45); }
.ia-dot-ok { background: var(--emerald-400); box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3), 0 0 10px rgba(16, 185, 129, 0.5); }
.ia-dot-erro { background: #f87171; box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.3), 0 0 10px rgba(239, 68, 68, 0.45); }

/* ==========================================
   MODAL DE CONFIGURAÇÃO DA IA
   ========================================== */
.modal-ia { max-width: 780px !important; max-height: min(92vh, 92dvh) !important; }
/* O corpo ocupa o que sobra do cartão (cabeçalho e rodapé ficam fixos) em vez de uma altura presa */
.modal-ia-body {
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.ia-aviso-fixo {
  background: rgba(245, 158, 11, 0.08);
  border: 1px dashed rgba(245, 158, 11, 0.4);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text-primary);
}

.ia-switch-geral {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.95rem;
}
.ia-switch-geral input,
.ia-switch input,
.ia-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--emerald-500);
  cursor: pointer;
  flex-shrink: 0;
}
.ia-resumo-status { font-size: 0.8rem; color: var(--text-secondary); }

.ia-secao-titulo {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-top: 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border-color);
}

/* Lista de provedores */
.ia-lista-provedores { display: flex; flex-direction: column; gap: 0.75rem; }

.ia-prov-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.ia-prov-card.ia-prov-principal {
  border-color: rgba(245, 158, 11, 0.55);
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.2), 0 8px 24px -8px rgba(245, 158, 11, 0.25);
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.07), var(--bg-card));
}

.ia-prov-topo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.ia-prov-nome {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
  flex: 1 1 auto;
  min-width: 0;
}
.ia-prov-selos { display: inline-flex; gap: 0.35rem; flex-wrap: wrap; }
.ia-selo {
  font-size: 0.62rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.ia-selo-principal { background: rgba(245, 158, 11, 0.2); border: 1px solid rgba(245, 158, 11, 0.55); color: #fbbf24; }
.ia-selo-gratis { background: rgba(16, 185, 129, 0.18); border: 1px solid rgba(16, 185, 129, 0.45); color: #34d399; }
.ia-selo-bloqueado { background: rgba(239, 68, 68, 0.18); border: 1px solid rgba(239, 68, 68, 0.45); color: #f87171; text-transform: none; }

.ia-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  margin-left: auto;
  white-space: nowrap;
}

/* Campos do provedor: 2 colunas no computador, 1 no celular */
.ia-prov-campos {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem 1rem;
  align-items: end;
}
.ia-prov-campos .mlb-field-group label { font-size: 0.72rem; }
.ia-prov-url-wrap { grid-column: 1 / -1; }
.ia-prov-campos .ia-check { grid-column: 1 / -1; }

.ia-chave-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.ia-chave-wrap .ia-prov-chave { flex: 1 1 auto; min-width: 0; font-family: var(--font-mono); font-size: 0.85rem; letter-spacing: 0.04em; }
.ia-chave-info { display: block; margin-top: 0.3rem; font-size: 0.72rem; color: var(--text-muted); }
.ia-prov-campos .ia-prov-aviso {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.5;
  color: #fbbf24;
}
.ia-olho {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.7rem;
  font-size: 1rem;
  line-height: 1;
  color: var(--text-secondary);
}
.ia-olho:hover { text-decoration: none; background: rgba(255, 255, 255, 0.12); color: var(--text-primary); }

/* Ações do provedor */
.ia-prov-acoes {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-color);
}
.ia-prov-acoes .ia-btn-testar { padding: 0.5rem 1rem; font-size: 0.85rem; }
.ia-prov-acoes .ia-btn-remover { color: #f87171; }
.ia-prov-acoes .ia-btn-principal { color: #fbbf24; }
.ia-prov-teste {
  font-size: 0.78rem;
  margin-left: auto;
  overflow-wrap: anywhere;
}
.ia-teste-ok { color: var(--emerald-400); font-weight: 600; }
.ia-teste-erro { color: #f87171; font-weight: 600; }
.ia-teste-nunca { color: var(--text-muted); }

/* Linha "Adicionar provedor" */
.ia-adicionar-linha {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.ia-adicionar-linha .mlb-input { flex: 1 1 220px; width: auto; padding: 0.6rem 0.85rem; }
.ia-adicionar-linha .btn-salvar-cartorio { padding: 0.6rem 1rem; font-size: 0.85rem; white-space: nowrap; }
.ia-link-obter {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--emerald-400);
  text-decoration: none;
  white-space: nowrap;
}
.ia-link-obter:hover { text-decoration: underline; }
.ia-link-obter[hidden] { display: none; }
.ia-aviso-preset {
  font-size: 0.78rem;
  color: #fbbf24;
  line-height: 1.5;
  margin: -0.35rem 0 0;
  min-height: 0;
}
.ia-aviso-preset:empty { display: none; }

/* Usos ("O que a IA faz") */
/* Cada função: liga/desliga, "grátis primeiro" e a fila de chaves (1º → 2º → 3º) */
.ia-lista-usos { display: flex; flex-direction: column; gap: 0.5rem; }
.ia-uso-bloco {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.ia-uso-topo { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.ia-uso-topo .ia-check { padding-left: 0; }
.ia-gratis-primeiro { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.75rem; font-weight: 600; color: #34d399; cursor: pointer; white-space: nowrap; }
.ia-gratis-primeiro input { accent-color: var(--emerald-500); }
.ia-fila { display: flex; align-items: center; flex-wrap: wrap; gap: 0.3rem; font-size: 0.74rem; }
.ia-fila-item { padding: 2px 8px; border-radius: var(--radius-full); border: 1px solid var(--border-color); white-space: nowrap; }
.ia-fila-paga { background: rgba(245, 158, 11, 0.12); border-color: rgba(245, 158, 11, 0.4); color: #fbbf24; }
.ia-fila-gratis { background: rgba(16, 185, 129, 0.12); border-color: rgba(16, 185, 129, 0.4); color: #34d399; }
.ia-fila-seta { color: var(--text-muted); }
.ia-fila-vazia, .ia-fila-nota { color: var(--text-muted); font-style: italic; }
.ia-fila-nota { margin-left: auto; }

/* ==========================================
   CHAVES DE API (mesma lógica do Claude Console)
   ========================================== */
.ia-conta-chaves { display: inline-block; min-width: 1.4em; padding: 0 6px; margin-left: 0.35rem; border-radius: var(--radius-full); background: rgba(255, 255, 255, 0.08); font-size: 0.7rem; text-align: center; color: var(--text-secondary); }
.ia-chaves-intro { margin: -0.5rem 0 0; font-size: 0.78rem; color: var(--text-muted); line-height: 1.5; }
.ia-avisos-chaves { display: flex; flex-direction: column; gap: 0.4rem; }
.ia-avisos-chaves:empty { display: none; }
.ia-chaves-barra { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.ia-chaves-barra .mlb-input { width: auto; flex: 1 1 140px; padding: 0.5rem 0.75rem; font-size: 0.85rem; }
.ia-chaves-barra #iaBuscaChaves { flex: 2 1 200px; }
.ia-btn-nova-chave { padding: 0.5rem 0.9rem; font-size: 0.85rem; white-space: nowrap; }

.ia-tabela-chaves { border: 1px solid var(--border-color); border-radius: var(--radius-md); background: var(--bg-card); }
.ia-chaves-linha {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1.6fr) minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 0.8fr) minmax(0, 0.9fr) 2.2rem;
  gap: 0.6rem;
  align-items: center;
  padding: 0.65rem 0.75rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.ia-chaves-cab { border-top: none; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); padding-top: 0.5rem; padding-bottom: 0.5rem; }
.ia-chaves-linha > span { min-width: 0; overflow-wrap: anywhere; }
.ia-chaves-editando { background: rgba(245, 158, 11, 0.06); box-shadow: inset 3px 0 0 #f59e0b; }
.ia-status-expirada, .ia-status-desligada, .ia-status-sem_chave { opacity: 0.75; }
.ia-col-chave { cursor: pointer; display: flex; flex-direction: column; gap: 0.15rem; }
.ia-col-chave strong { color: var(--text-primary); font-size: 0.85rem; }
.ia-col-chave code { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-muted); }
.ia-col-chave:hover strong { text-decoration: underline; }
.ia-col-prov { display: flex; flex-direction: column; gap: 0.25rem; color: var(--text-primary); }
.ia-col-selos { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.ia-selo-st-ativa { background: rgba(16, 185, 129, 0.15); border: 1px solid rgba(16, 185, 129, 0.4); color: #34d399; }
.ia-selo-st-desligada { background: rgba(148, 163, 184, 0.15); border: 1px solid rgba(148, 163, 184, 0.4); color: #94a3b8; }
.ia-selo-st-expirada { background: rgba(239, 68, 68, 0.15); border: 1px solid rgba(239, 68, 68, 0.45); color: #f87171; }
.ia-selo-st-sem_chave { background: rgba(148, 163, 184, 0.1); border: 1px dashed rgba(148, 163, 184, 0.4); color: #94a3b8; }
.ia-usadas { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.ia-usada { font-size: 0.66rem; padding: 1px 6px; border-radius: var(--radius-full); background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border-color); color: var(--text-secondary); white-space: nowrap; }
.ia-usada-1 { border-color: rgba(16, 185, 129, 0.45); color: #34d399; }
.ia-usada-nao { font-style: italic; color: var(--text-muted); }
.ia-col-modelo { font-family: var(--font-mono); font-size: 0.72rem; display: flex; flex-direction: column; gap: 0.15rem; }
.ia-col-modelo small { color: var(--text-muted); }
.ia-exp-perto { color: #fbbf24; font-weight: 600; }
.ia-exp-vencida { color: #f87171; font-weight: 600; }
.ia-exp-nenhuma { color: var(--text-muted); }
.ia-col-custo { display: flex; flex-direction: column; gap: 0.1rem; font-variant-numeric: tabular-nums; }
.ia-custo-usd { color: #60a5fa; font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
.ia-custo-gratis { color: #34d399; font-weight: 700; }
.ia-col-custo small { font-size: 0.68rem; color: var(--text-muted); }
.ia-col-menu { position: relative; justify-self: end; }
.ia-menu summary { list-style: none; cursor: pointer; width: 2rem; height: 2rem; display: grid; place-items: center; border-radius: var(--radius-md); font-size: 1.1rem; font-weight: 700; color: var(--text-secondary); }
.ia-menu summary::-webkit-details-marker { display: none; }
.ia-menu summary:hover, .ia-menu[open] summary { background: rgba(255, 255, 255, 0.08); color: var(--text-primary); }
.ia-menu-itens {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  min-width: 230px;
  display: flex;
  flex-direction: column;
  padding: 0.3rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.ia-menu-itens button { text-align: left; background: none; border: none; color: var(--text-primary); padding: 0.55rem 0.7rem; border-radius: 6px; font-size: 0.82rem; cursor: pointer; }
.ia-menu-itens button:hover { background: rgba(255, 255, 255, 0.07); }
.ia-menu-itens .ia-menu-perigo { color: #f87171; }
.ia-chaves-vazio { padding: 0.75rem; }
.ia-lista-provedores:empty { display: none; }
.ia-so-texto { color: #fbbf24; font-weight: 400; }
.ia-creditos-restante { font-size: 0.7rem; font-weight: 400; color: var(--text-muted); line-height: 1.4; }
body.theme-light .ia-menu-itens { background: #ffffff; }
body.theme-light .ia-menu-itens button:hover, body.theme-light .ia-menu summary:hover { background: rgba(15, 23, 42, 0.06); }

/* Tabela no meio-termo (tablet / janela estreita): some a coluna "Criada" */
@media (max-width: 900px) and (min-width: 701px) {
  .ia-chaves-linha { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 0.9fr) 2.2rem; }
  .ia-col-criada, .ia-chaves-cab span:nth-child(5) { display: none; }
}
.ia-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-md);
  transition: background 0.15s;
}
.ia-check:hover { background: rgba(255, 255, 255, 0.04); }
.ia-check input:disabled { cursor: not-allowed; opacity: 0.6; }

/* ==========================================
   CONTROLE DE GASTOS
   ========================================== */
.ia-painel-gasto { display: flex; flex-direction: column; gap: 0.75rem; }
.ia-gasto-alerta {
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  line-height: 1.5;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.45);
  color: #fbbf24;
}
.ia-gasto-alerta[hidden] { display: none; }
.ia-gasto-alerta-bloqueado { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.5); color: #f87171; }
.ia-gasto-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.6rem; }
.ia-gasto-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.7rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}
.ia-gasto-rotulo { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.ia-gasto-card strong { font-size: 1.15rem; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.ia-gasto-card small { font-size: 0.72rem; color: var(--text-muted); overflow-wrap: anywhere; }
.ia-gasto-barra { height: 6px; border-radius: var(--radius-full); background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.ia-gasto-barra span { display: block; height: 100%; width: 0; background: var(--emerald-500); transition: width 0.3s; }
.ia-gasto-barra span.ia-barra-alerta { background: #f59e0b; }
.ia-gasto-barra span.ia-barra-estourou { background: #ef4444; }
.ia-gasto-limites { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.6rem; }
.ia-gasto-limites label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.72rem; font-weight: 600; color: var(--text-secondary); }
.ia-gasto-limites .mlb-input { width: 100%; padding: 0.55rem 0.75rem; font-variant-numeric: tabular-nums; }
.ia-gasto-nota { margin: 0; font-size: 0.74rem; line-height: 1.5; color: var(--text-muted); }
.ia-gasto-nota a { color: var(--emerald-400); }
.ia-gasto-por-uso, .ia-gasto-ultimas > div { display: flex; flex-direction: column; gap: 0.15rem; }
.ia-gasto-linha {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 0.75rem;
  align-items: baseline;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm, 6px);
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.ia-gasto-linha:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.ia-gasto-linha strong { color: var(--text-primary); text-align: right; }
.ia-gasto-ultima { grid-template-columns: auto minmax(0, 1fr) auto auto; }
.ia-gasto-ultima span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ia-gasto-vazio { margin: 0; font-size: 0.8rem; color: var(--text-muted); }
.ia-gasto-ultimas summary { cursor: pointer; font-size: 0.82rem; font-weight: 600; color: var(--text-secondary); padding: 0.25rem 0; }
.ia-gasto-ultimas[open] summary { margin-bottom: 0.4rem; }
.ia-rodape-botoes { display: inline-flex; gap: 0.5rem; flex-wrap: wrap; }
body.theme-light .ia-gasto-barra { background: rgba(15, 23, 42, 0.1); }
body.theme-light .ia-gasto-linha:nth-child(odd) { background: rgba(15, 23, 42, 0.04); }

/* Rodapé: gasto estimado + testar todos */
.ia-rodape-gasto {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.65rem 0.85rem;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.ia-rodape-gasto .btn-micro-action { font-size: 0.82rem; }

/* ==========================================
   MODAL "ORGANIZAR TEXTO COM IA"
   ========================================== */
.modal-ia-organizar { max-width: 760px !important; }
.ia-textarea {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.ia-textarea:focus { outline: none; border-color: var(--emerald-500); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15); }
.ia-status-linha {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.5;
  min-height: 1.2em;
  margin: 0;
  overflow-wrap: anywhere;
}
.ia-status-linha:empty { display: none; }
.ia-status-info { color: var(--text-secondary); }
.ia-status-alerta { color: #fbbf24; }
.ia-status-erro { color: #f87171; }

/* ==========================================
   ABA "PERGUNTAR" (ASSISTENTE)
   ========================================== */
.ia-assistente-wrap {
  max-width: 860px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  backdrop-filter: blur(12px);
}
.ia-assistente-cabecalho h2 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}
.ia-assistente-cabecalho p { font-size: 0.85rem; color: var(--text-secondary); }

.ia-chips { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.ia-chip {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-full);
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}
.ia-chip:hover { background: rgba(99, 102, 241, 0.22); transform: translateY(-1px); }
body.theme-light .ia-chip { background: rgba(99, 102, 241, 0.08); color: #312e81; }

.ia-chat-historico {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 240px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}
.ia-chat-historico:empty::before {
  content: 'Faça uma pergunta sobre as planilhas abertas. Ex.: "quem ainda não pagou em julho?"';
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: auto;
  text-align: center;
  padding: 1rem;
}

.ia-msg {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.ia-msg-texto {
  padding: 0.7rem 1rem;
  font-size: 0.88rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  border-radius: 14px;
}
.ia-msg-user { align-self: flex-end; align-items: flex-end; }
.ia-msg-user .ia-msg-texto {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #022c22;
  border-bottom-right-radius: 4px;
  font-weight: 500;
}
.ia-msg-ia { align-self: flex-start; align-items: flex-start; }
.ia-msg-ia .ia-msg-texto {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}
.ia-msg-meta { font-size: 0.68rem; color: var(--text-muted); padding: 0 0.35rem; }

/* Propostas da IA no chat (nada muda sem Aplicar) */
.ia-chip-acao { border-color: rgba(16, 185, 129, 0.5) !important; color: #34d399 !important; }
.ia-acoes-grupo { align-self: stretch; display: flex; flex-direction: column; gap: 0.5rem; padding: 0.75rem; border: 1px dashed rgba(16, 185, 129, 0.45); border-radius: var(--radius-md); background: rgba(16, 185, 129, 0.04); }
.ia-acoes-cab { font-size: 0.78rem; font-weight: 700; color: #34d399; }
.ia-acao { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 0.7rem 0.85rem; display: flex; flex-direction: column; gap: 0.4rem; transition: opacity 0.2s, border-color 0.2s; }
.ia-acao-titulo { display: flex; flex-direction: column; gap: 0.2rem; }
.ia-acao-tipo { font-size: 0.68rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.ia-acao-titulo strong { font-size: 0.88rem; color: var(--text-primary); overflow-wrap: anywhere; }
.ia-acao-linhas { margin: 0; padding-left: 1.1rem; font-size: 0.8rem; color: var(--text-secondary); line-height: 1.5; overflow-wrap: anywhere; }
.ia-acao-motivo { margin: 0; font-size: 0.78rem; color: var(--text-muted); font-style: italic; }
.ia-acao-botoes { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.ia-acao-aplicar { padding: 0.45rem 0.9rem; font-size: 0.82rem; }
.ia-acao-status { font-size: 0.76rem; color: var(--text-muted); overflow-wrap: anywhere; }
.ia-acao-feita { border-color: rgba(16, 185, 129, 0.6); }
.ia-acao-feita .ia-acao-status { color: #34d399; font-weight: 600; }
.ia-acao-invalida { opacity: 0.7; border-style: dashed; }
.ia-acao-invalida .ia-acao-status { color: #f87171; }
.ia-acao-ignorada { opacity: 0.5; }
.ia-acao-todas { align-self: flex-start; }
@media (max-width: 700px) {
  .ia-acoes-grupo { padding: 0.5rem; }
  .ia-acao-aplicar, .ia-acao-desfazer { flex: 1 1 auto; min-height: 42px; }
}

.ia-chat-form {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
}
.ia-chat-form .mlb-input { flex: 1 1 auto; min-width: 0; }
.ia-chat-form .btn-vincular-confirmar { padding: 0.75rem 1.4rem; white-space: nowrap; }
.ia-chat-form .btn-vincular-confirmar:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* ==========================================
   SELOS NOS COMPROVANTES (fila e card de conferência)
   ========================================== */
.item-fila-leitura {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.ia-leitura-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  margin-bottom: 0.75rem;
  overflow-wrap: anywhere;
}
.ia-leitura-ia { background: rgba(99, 102, 241, 0.16); border: 1px solid rgba(99, 102, 241, 0.45); color: #a5b4fc; }
.ia-leitura-ocr { background: rgba(148, 163, 184, 0.14); border: 1px solid rgba(148, 163, 184, 0.3); color: #cbd5e1; }

.ia-sugestao-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  background: rgba(99, 102, 241, 0.1);
  border: 1px dashed rgba(99, 102, 241, 0.45);
  border-radius: var(--radius-md);
  padding: 0.7rem 0.9rem;
  margin: 0.5rem 0 0.75rem;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text-primary);
}
.ia-sugestao-box[hidden] { display: none; }
.ia-sugestao-box.ia-sugestao-vazia { border-style: dotted; background: transparent; color: var(--text-muted); }
.ia-leitura-obs { font-size: 0.8rem; color: var(--text-secondary); margin: -0.4rem 0 0.75rem; overflow-wrap: anywhere; }
.ia-sugestao-box strong { color: #a5b4fc; }
.ia-sugestao-box .btn-micro-action { font-size: 0.8rem; }

/* ==========================================
   TEMA CLARO
   ========================================== */
body.theme-light .ia-prov-card,
body.theme-light .ia-switch-geral,
body.theme-light .ia-assistente-wrap { background: #ffffff; }
body.theme-light .ia-prov-card.ia-prov-principal { background: linear-gradient(135deg, rgba(245, 158, 11, 0.08), #ffffff); }
body.theme-light .ia-aviso-fixo { background: rgba(245, 158, 11, 0.1); color: #78350f; }
body.theme-light .ia-selo-principal, body.theme-light .ia-aviso-preset, body.theme-light .ia-prov-acoes .ia-btn-principal { color: #b45309; }
body.theme-light .ia-selo-gratis, body.theme-light .ia-teste-ok, body.theme-light .ia-link-obter { color: #047857; }
body.theme-light .ia-selo-bloqueado, body.theme-light .ia-teste-erro, body.theme-light .ia-prov-acoes .ia-btn-remover { color: #b91c1c; }
body.theme-light .ia-dot-ligada { background: #d97706; }
body.theme-light .ia-dot-ok { background: #059669; }
body.theme-light .ia-dot-erro { background: #dc2626; }
body.theme-light .ia-olho { background: rgba(15, 23, 42, 0.05); }
body.theme-light .ia-olho:hover { background: rgba(15, 23, 42, 0.1); }
body.theme-light .ia-check:hover { background: rgba(15, 23, 42, 0.04); }
body.theme-light .ia-rodape-gasto,
body.theme-light .ia-chat-historico { background: rgba(15, 23, 42, 0.04); }
body.theme-light .ia-msg-ia .ia-msg-texto { background: #ffffff; }
body.theme-light .ia-leitura-ia, body.theme-light .ia-sugestao-box strong { color: #4338ca; }
body.theme-light .ia-leitura-ocr { color: #334155; }
body.theme-light .ia-sugestao-box { background: rgba(99, 102, 241, 0.07); }
body.theme-light .ia-sugestao-box.ia-sugestao-vazia { background: transparent; }
body.theme-light .ia-prov-campos .ia-prov-aviso, body.theme-light .ia-status-alerta { color: #b45309; }
body.theme-light .ia-status-erro { color: #b91c1c; }
/* Campos de texto dentro das telas da IA: fundo claro no tema claro */
body.theme-light .modal-ia .mlb-input,
body.theme-light .modal-ia-organizar .mlb-input,
body.theme-light .ia-assistente-wrap .mlb-input,
body.theme-light .ia-textarea { background: #ffffff; color: #0f172a; }

/* ==========================================
   CELULAR: tudo em uma coluna
   ========================================== */
@media (max-width: 700px) {
  /* Configuração da IA vira tela cheia: sem a margem de 2rem do overlay e sem cantos */
  #modalConfigIA { padding: 0; align-items: stretch; }
  #modalConfigIA .modal-ia { max-width: 100vw !important; width: 100%; height: 100vh; height: 100dvh; max-height: none !important; border-radius: 0; border: none; }
  #modalConfigIA .modal-header-bar { padding: 0.75rem 1rem; padding-top: max(0.75rem, env(safe-area-inset-top)); }
  #modalConfigIA .modal-header-bar .sub-text { display: none; }
  #modalConfigIA .modal-lancamento-footer { padding: 0.75rem 1rem; padding-bottom: max(0.75rem, env(safe-area-inset-bottom)); }
  #modalConfigIA .modal-lancamento-footer .btn-cancelar { width: 100%; }
  /* 16px nos campos: abaixo disso o iPhone dá zoom ao tocar */
  #modalConfigIA .mlb-input, #modalConfigIA select, #modalConfigIA input[type="text"], #modalConfigIA input[type="password"] { font-size: 16px; }
  .modal-ia-organizar { max-width: 95vw !important; }
  .modal-ia-body { padding: 1rem; }
  .ia-prov-card { padding: 0.85rem; }
  .ia-prov-acoes { gap: 0.4rem 0.75rem; }
  .ia-prov-acoes .ia-btn-testar { flex: 1 1 100%; min-height: 44px; }
  .ia-gasto-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ia-gasto-cards .ia-gasto-card:last-child { grid-column: 1 / -1; }
  .ia-gasto-limites { grid-template-columns: 1fr 1fr; }
  .ia-gasto-limites label:last-child { grid-column: 1 / -1; }
  .ia-gasto-ultima { grid-template-columns: auto minmax(0, 1fr) auto; }
  .ia-gasto-ultima span:nth-child(3) { display: none; }
  .ia-rodape-botoes { width: 100%; }
  .ia-rodape-botoes .btn-micro-action { flex: 1 1 0; min-height: 40px; }
  .ia-prov-campos { grid-template-columns: 1fr; }
  /* Chaves: cada linha vira um cartão com rótulo em cada campo */
  .ia-chaves-cab { display: none; }
  .ia-chaves-linha { grid-template-columns: 1fr 1fr; gap: 0.5rem 0.75rem; padding: 0.75rem; position: relative; }
  .ia-chaves-linha:first-of-type { border-top: none; }
  .ia-col-chave, .ia-col-prov { grid-column: 1 / -1; padding-right: 2.4rem; }
  .ia-col-menu { position: absolute; top: 0.55rem; right: 0.5rem; }
  .ia-col-modelo, .ia-col-exp, .ia-col-criada, .ia-col-custo { display: flex; flex-direction: column; }
  .ia-col-modelo::before, .ia-col-exp::before, .ia-col-criada::before, .ia-col-custo::before {
    content: attr(data-rotulo); font-family: var(--font-body, inherit); font-size: 0.64rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 0.1rem;
  }
  .ia-chaves-barra .mlb-input, .ia-chaves-barra #iaBuscaChaves { flex: 1 1 calc(50% - 0.5rem); }
  .ia-chaves-barra #iaBuscaChaves, .ia-btn-nova-chave { flex: 1 1 100%; }
  .ia-btn-nova-chave { min-height: 44px; }
  .ia-menu-itens button { padding: 0.75rem; font-size: 0.9rem; }
  .ia-fila-nota { margin-left: 0; width: 100%; }
  .ia-prov-topo { align-items: flex-start; }
  .ia-switch { margin-left: 0; width: 100%; }
  .ia-prov-acoes .ia-prov-teste { margin-left: 0; width: 100%; }
  .ia-adicionar-linha { flex-direction: column; align-items: stretch; }
  .ia-adicionar-linha .mlb-input, .ia-adicionar-linha .btn-salvar-cartorio { width: 100%; flex: none; }
  .ia-link-obter { text-align: center; }
  .ia-rodape-gasto { flex-direction: column; align-items: flex-start; }
  .ia-assistente-wrap { padding: 1rem; border-radius: var(--radius-md); }
  .ia-chat-historico { max-height: 50vh; min-height: 180px; }
  .ia-msg { max-width: 95%; }
  .ia-chat-form { flex-direction: column; }
  .ia-chat-form .btn-vincular-confirmar { width: 100%; }
  .ia-textarea { min-height: 200px; }
  .btn-ia-header { padding: 0.55rem 0.7rem; }
}

/* Celular bem estreito (até 380px): menos respiro */
@media (max-width: 380px) {
  .modal-ia-body { padding: 0.75rem; gap: 0.8rem; }
  .ia-aviso-fixo { font-size: 0.76rem; padding: 0.6rem 0.75rem; }
  .ia-gasto-cards, .ia-gasto-limites { grid-template-columns: 1fr; }
}

/* Tabelas nas respostas do assistente (rolam de lado no celular, sem quebrar a página) */
.ia-tabela-wrap { overflow-x: auto; margin: 0.4rem 0; border: 1px solid var(--border-color); border-radius: var(--radius-md); white-space: normal; }
.ia-tabela { width: 100%; border-collapse: collapse; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.ia-tabela th { text-align: left; padding: 0.45rem 0.6rem; background: rgba(255, 255, 255, 0.05); color: var(--text-muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
.ia-tabela td { padding: 0.4rem 0.6rem; border-top: 1px solid var(--border-color); color: var(--text-primary); }
.ia-tabela td.ia-num { text-align: right; white-space: nowrap; }
.ia-tabela tbody tr:nth-child(even) td { background: rgba(255, 255, 255, 0.02); }
body.theme-light .ia-tabela th { background: rgba(15, 23, 42, 0.05); }

/* A bolha nunca passa da conversa: o que é largo (tabela) rola por dentro */
.ia-chat-historico { overflow-x: hidden; }
.ia-msg { min-width: 0; }
.ia-msg-texto { max-width: 100%; min-width: 0; box-sizing: border-box; }
.ia-msg-ia:has(.ia-tabela-wrap) { width: 100%; max-width: 100%; }
.ia-msg-ia:has(.ia-tabela-wrap) .ia-msg-texto { width: 100%; }
.ia-tabela-wrap { max-width: 100%; }
.ia-acoes-grupo { min-width: 0; max-width: 100%; box-sizing: border-box; }

/* Memória da IA */
.ia-lista-regras { display: flex; flex-direction: column; gap: 0.35rem; max-height: 260px; overflow-y: auto; }
.ia-regra { display: flex; gap: 0.5rem; align-items: flex-start; padding: 0.5rem 0.65rem; background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius-md); font-size: 0.8rem; line-height: 1.45; color: var(--text-secondary); }
.ia-regra span { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.ia-regra-apagar { flex-shrink: 0; }

/* Modo online: menu do dono (sair, senha, backup) e bolinha de gravação no servidor */
.srv-menu-wrap { position: relative; }
.srv-btn { display: inline-flex; align-items: center; gap: 0.35rem; }
.srv-dot { width: 9px; height: 9px; border-radius: 50%; background: #64748b; display: inline-block; }
.srv-dot.srv-salvo { background: #10b981; box-shadow: 0 0 6px rgba(16, 185, 129, 0.6); }
.srv-dot.srv-salvando { background: #f59e0b; animation: srvPisca 1s infinite; }
.srv-dot.srv-offline, .srv-dot.srv-erro { background: #ef4444; }
@keyframes srvPisca { 50% { opacity: 0.35; } }
.srv-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 1200; min-width: 240px; display: flex; flex-direction: column; gap: 0.2rem; padding: 0.5rem; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius-md); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45); }
.srv-pop[hidden] { display: none; }
.srv-pop button { text-align: left; background: none; border: none; color: var(--text-primary); padding: 0.6rem 0.7rem; border-radius: 6px; font-size: 0.85rem; cursor: pointer; }
.srv-pop button:hover { background: rgba(255, 255, 255, 0.07); }
.srv-pop .srv-sair { color: #f87171; }
.srv-status { font-size: 0.75rem; color: var(--text-muted); padding: 0.3rem 0.7rem 0.5rem; border-bottom: 1px solid var(--border-color); margin-bottom: 0.2rem; line-height: 1.4; }

/* Erro da IA no chat: bolha própria, com quem foi tentado e "Tentar de novo" */
.ia-msg-erro .ia-msg-texto { border: 1px solid rgba(244, 63, 94, 0.45); background: rgba(244, 63, 94, 0.08); color: var(--text-primary); }
.ia-msg-repetir { margin: 0.2rem 0.35rem 0; padding: 0.35rem 0.8rem; border-radius: 999px; border: 1px solid rgba(52, 211, 153, 0.5); background: rgba(16, 185, 129, 0.1); color: var(--emerald-400); font: inherit; font-size: 0.78rem; font-weight: 700; cursor: pointer; }
.ia-msg-repetir:hover { background: rgba(16, 185, 129, 0.2); }
body.theme-light .ia-msg-erro .ia-msg-texto { background: #fff1f2; }
body.theme-light .ia-msg-repetir { color: #047857; }

/* ==========================================
   SALDO ONLINE, GASTO POR DIA E POR PROVEDOR (controle de gastos)
   ========================================== */
.ia-gasto-card-saldo strong { color: #60a5fa; }
.ia-saldos { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.75rem 0.85rem; border: 1px solid var(--border-color); border-radius: var(--radius-md); background: var(--bg-card); }
.ia-saldos-cab { display: flex; align-items: center; flex-wrap: wrap; gap: 0.35rem 0.75rem; }
.ia-saldos-cab strong { font-size: 0.86rem; color: var(--text-primary); }
.ia-saldos-cab small { flex: 1 1 auto; font-size: 0.72rem; color: var(--text-muted); }
.ia-saldos-lista { display: flex; flex-direction: column; gap: 0.4rem; }
.ia-saldo-linha { display: grid; grid-template-columns: minmax(130px, 0.8fr) minmax(0, 2fr) auto; align-items: center; gap: 0.4rem 0.85rem; padding: 0.55rem 0.7rem; border-radius: var(--radius-sm, 6px); border: 1px solid var(--border-color); border-left: 3px solid var(--border-color); background: rgba(255, 255, 255, 0.02); }
.ia-saldo-linha.ia-saldo-ok { border-left-color: #10b981; }
.ia-saldo-linha.ia-saldo-baixo { border-left-color: #f59e0b; background: rgba(245, 158, 11, 0.06); }
.ia-saldo-linha.ia-saldo-sem { border-left-color: #ef4444; background: rgba(239, 68, 68, 0.07); }
.ia-saldo-nome { display: flex; flex-direction: column; min-width: 0; }
.ia-saldo-nome strong { font-size: 0.82rem; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ia-saldo-nome small { font-size: 0.68rem; color: var(--text-muted); }
.ia-saldo-corpo { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.ia-saldo-valor { font-size: 1rem; font-weight: 800; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.ia-saldo-detalhe { font-size: 0.74rem; color: var(--text-secondary); line-height: 1.4; }
.ia-saldo-erro { font-size: 0.72rem; color: #fbbf24; }
.ia-saldo-botoes { display: inline-flex; gap: 0.35rem; flex-wrap: wrap; justify-content: flex-end; }
.ia-saldo-link { text-decoration: none; }
.ia-saldo-mini { color: #60a5fa !important; }
.ia-saldo-mini-baixo { color: #fbbf24 !important; }
.ia-sem-nome { color: var(--text-muted) !important; font-style: italic; font-weight: 600; }
.ia-dar-nome { display: block; font-size: 0.66rem; color: var(--emerald-400); }
.ia-gasto-grafico { padding: 0.7rem 0.85rem 0.5rem; border: 1px solid var(--border-color); border-radius: var(--radius-md); background: var(--bg-card); }
.ia-gasto-grafico-cab { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.75rem; margin-bottom: 0.5rem; }
.ia-gasto-grafico-cab strong { font-size: 0.84rem; color: var(--text-primary); }
.ia-gasto-grafico-cab small { font-size: 0.72rem; color: var(--text-muted); }
.ia-gasto-dias { display: flex; align-items: flex-end; gap: 3px; height: 74px; padding-bottom: 14px; }
.ia-dia { position: relative; flex: 1 1 0; min-width: 2px; height: 100%; display: flex; align-items: flex-end; }
.ia-dia i { display: block; width: 100%; border-radius: 3px 3px 1px 1px; background: #3b82f6; opacity: 0.75; transition: opacity 0.15s; }
.ia-dia:hover i { opacity: 1; }
.ia-dia.ia-dia-gratis i { background: #10b981; }
.ia-dia.ia-dia-hoje i { opacity: 1; box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.35); }
.ia-dia.ia-dia-futuro i { opacity: 0; }
.ia-dia b { position: absolute; bottom: -15px; left: 50%; transform: translateX(-50%); font-size: 0.6rem; font-weight: 600; color: var(--text-muted); }
.ia-gasto-duas { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.ia-gasto-subtitulo { margin: 0 0 0.35rem; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.ia-gasto-sub { display: block; font-size: 0.66rem; color: var(--text-muted); }
.ia-ultimas-mais { align-self: flex-start; margin-top: 0.35rem; }
body.theme-light .ia-saldo-linha { background: rgba(15, 23, 42, 0.02); }
body.theme-light .ia-gasto-card-saldo strong, body.theme-light .ia-saldo-mini { color: #1d4ed8 !important; }
body.theme-light .ia-saldo-erro, body.theme-light .ia-saldo-mini-baixo { color: #b45309 !important; }
body.theme-light .ia-dar-nome { color: #047857; }
@media (max-width: 700px) {
  .ia-gasto-cards .ia-gasto-card:last-child { grid-column: auto; }
  .ia-saldo-linha { grid-template-columns: minmax(0, 1fr) auto; }
  .ia-saldo-corpo { grid-column: 1 / -1; grid-row: 2; }
  .ia-saldo-botoes { grid-column: 2; grid-row: 1; }
  .ia-gasto-duas { grid-template-columns: 1fr; }
  .ia-gasto-dias { gap: 2px; }
}
