/* Projeto IA — Estilos globais
   Paleta DCA (sidebar azul #064A6A + accent vermelho #D2141E),
   accent é configurável por instância via --accent (ia_empresa_config.cor_accent). */

:root {
    --sb-bg: #064A6A;
    --sb-bg-2: #043B54;
    --sb-text: #b9c3d4;
    --sb-text-muted: #8592a6;
    --bg-app: #f3f5f9;
    --card-bg: #ffffff;
    --border: #dde4ee;
    --text-main: #1e293b;
    --accent: #D2141E;
    --accent-green: #22c55e;
    --accent-red: #ef4444;
    --accent-yellow: #f59e0b;
    --radius: 10px;
    --sb-width: 250px;
    --topnav-h: 58px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
/* O Chrome Android "font-boosting" aumenta sozinho a fonte de blocos de texto
   muito longos (respostas de consulta ao ERP passam de 3 mil caracteres)
   e estoura o layout no celular. 100% desliga o auto-ajuste SEM desligar o
   zoom por pinça. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg-app);
    color: var(--text-main);
    font-size: 14px;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; }

/* ── Layout ─────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sb-width);
    background: var(--sb-bg);
    color: var(--sb-text);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand img { height: 32px; width: auto; border-radius: 6px; }
.sidebar-brand .name { font-weight: 700; color: #fff; font-size: 14px; line-height: 1.3; }

.nav-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--sb-text-muted); padding: 16px 16px 6px;
}
.sidebar ul { list-style: none; margin: 0; padding: 0 8px; }
.sidebar li { margin: 2px 0; }
.sidebar a.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: 8px; color: var(--sb-text);
    font-size: 13.5px; font-weight: 500;
}
.sidebar a.nav-link i { width: 18px; text-align: center; opacity: .85; }
.sidebar a.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar a.nav-link.active { background: var(--accent); color: #fff; }
.nav-divider { border: none; border-top: 1px solid rgba(255,255,255,.08); margin: 10px 12px; }
.sidebar-version { margin-top: auto; padding: 14px 16px; font-size: 11px; color: #4b5768; text-align: center; border-top: 1px solid rgba(255,255,255,.08); font-family: monospace; line-height: 1.7; }
.sidebar-version a { color: #6b7a8f; text-decoration: none; }
.sidebar-version a:hover { color: var(--accent); text-decoration: underline; }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: var(--topnav-h); background: #fff; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; padding: 0 22px;
    position: sticky; top: 0; z-index: 5;
}
.topbar .user-box { display: flex; align-items: center; gap: 12px; font-size: 13px; color: #475569; }
.topbar .user-box .avatar {
    width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px;
}
.topbar a.btn-logout { color: #94a3b8; font-size: 13px; }
.topbar a.btn-logout:hover { color: var(--accent-red); }

main.content { padding: 22px 26px 40px; flex: 1; }

/* ── Componentes ────────────────────────────────────── */
.card {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px 20px; box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.card + .card { margin-top: 16px; }
/* Cards dentro de grades: o gap da grid já espaça nas duas orientações
   (lado a lado ou empilhada) — o margin-top de empilhamento aqui só
   deslocava o 2º card dentro da linha e deixava a dupla desnivelada. */
.grid-2 > .card + .card,
.grid-2-wide > .card + .card,
.grid-3 > .card + .card { margin-top: 0; }
.card h3 { font-size: 15px; font-weight: 700; margin-bottom: 12px; color: var(--text-main); }

.btn {
    display: inline-flex; align-items: center; gap: 8px; border: none; border-radius: 7px;
    padding: 9px 16px; font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: #f1f5f9; color: #475569; border: 1px solid var(--border); }
.btn-danger { background: var(--accent-red); color: #fff; }
.btn-outline-primary { background: #fff; color: var(--accent); border: 1px solid var(--accent); }
.btn-outline-primary:hover { background: rgba(59,158,255,.08); }
.btn-outline-danger { background: #fff; color: var(--accent-red); border: 1px solid var(--accent-red); }
.btn-outline-danger:hover { background: rgba(239,68,68,.08); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Interruptor liga/desliga (ERP, Web search, etc.) ─────────────
   É um interruptor de verdade (trilho + bolinha + rótulo ON/OFF), não um botão
   que muda de cor: o estado precisa ser óbvio de longe, porque ligado significa
   que a IA tem acesso de leitura ao ERP ou à internet. */
.switch-tool,
.switch-erp,
.switch-web-search {
    display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
    background: #f1f5f9; color: #64748b; border: 1px solid var(--border);
    border-radius: 7px; padding: 8px 12px; font-size: 13px; font-weight: 600;
    transition: background .15s, color .15s, border-color .15s;
}
.switch-tool:disabled,
.switch-erp:disabled,
.switch-web-search:disabled { opacity: .5; cursor: not-allowed; }
.switch-trilho {
    width: 34px; height: 18px; border-radius: 999px; background: #cbd5e1;
    position: relative; flex-shrink: 0; transition: background .18s;
}
.switch-bolinha {
    position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
    border-radius: 50%; background: #fff; transition: transform .18s;
    box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch-tool .switch-estado,
.switch-erp-estado,
.switch-web-search-estado { font-size: 11px; font-weight: 800; letter-spacing: .06em; min-width: 26px; }

/* Verde: ERP (dados internos/ERP) */
.switch-tool.switch-erp.ativo,
.switch-erp.ativo {
    background: rgba(34,197,94,.12); color: #15803d; border-color: var(--accent-green);
}
.switch-tool.switch-erp.ativo .switch-trilho,
.switch-erp.ativo .switch-trilho { background: var(--accent-green); }
.switch-tool.switch-erp.ativo .switch-bolinha,
.switch-erp.ativo .switch-bolinha { transform: translateX(16px); }

/* Azul: Web search (internet) */
.switch-tool.switch-web-search.ativo,
.switch-web-search.ativo {
    background: rgba(59,158,255,.12); color: #1d4ed8; border-color: var(--accent);
}
.switch-tool.switch-web-search.ativo .switch-trilho,
.switch-web-search.ativo .switch-trilho { background: var(--accent); }
.switch-tool.switch-web-search.ativo .switch-bolinha,
.switch-web-search.ativo .switch-bolinha { transform: translateX(16px); }

/* ── Interruptor de permissão (Admin > Usuários) ───────────────────────
   Versão compacta do switch-tool pra listar várias permissões lado a lado.
   Estrutura: label > span.switch-label + span.switch-trilho + input.
   O input fica fora do fluxo (absolute) e nunca interfere no layout. */
.switch-permissao {
    position: relative;
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    background: #f8fafc; color: #64748b; border: 1px solid var(--border);
    border-radius: 8px; padding: 10px 12px; font-size: 13px;
    cursor: pointer; transition: background .15s, color .15s, border-color .15s;
    min-width: 0;
}
.switch-permissao input[type="checkbox"] {
    position: absolute; opacity: 0; pointer-events: none;
    top: 0; left: 0; width: 0; height: 0; margin: 0;
}
.switch-permissao .switch-label {
    flex: 1 1 auto; min-width: 0;
    font-weight: 600; line-height: 1.3; padding-right: 4px;
}
.switch-permissao .switch-trilho {
    flex: 0 0 30px;
    width: 30px; height: 16px; border-radius: 999px; background: #cbd5e1;
    position: relative; transition: background .18s;
}
.switch-permissao .switch-bolinha {
    position: absolute; top: 2px; left: 2px; width: 12px; height: 12px;
    border-radius: 50%; background: #fff; transition: transform .18s;
    box-shadow: 0 1px 2px rgba(0,0,0,.25);
}

/* Grid de permissões — 2 colunas no desktop, 1 no mobile */
.permissoes-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 6px;
}
/* display:flex é reafirmado aqui de propósito: a grade de módulos fica dentro
   de um .form-group, e a regra global `.form-group label { display:block }`
   (mais específica que .switch-permissao) sobrescrevia o flex e fazia o trilho
   do interruptor colapsar/ficar invisível. Esta regra vence e restaura o layout. */
.permissoes-grid .switch-permissao { display: flex; width: 100%; }

@media (max-width: 560px) {
    .permissoes-grid { grid-template-columns: 1fr; }
}

.switch-permissao.ativo {
    background: rgba(34,197,94,.10); color: #15803d; border-color: var(--accent-green);
}
.switch-permissao.ativo .switch-trilho { background: var(--accent-green); }
.switch-permissao.ativo .switch-bolinha { transform: translateX(14px); }

/* Chips de seleção múltipla — empresas do ERP liberadas por usuário.
   Sem :has() (navegador do cliente não suporta): o estado ativo é pintado
   pela classe .ativo controlada por JS, mesmo padrão dos switches. */
.chips-empresas { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-empresa {
    display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px;
    font-size: 12.5px; font-weight: 600; color: #64748b; cursor: pointer;
    background: #fff; user-select: none;
    transition: background .15s, color .15s, border-color .15s;
}
.chip-empresa input { margin: 0; accent-color: var(--accent-green); }
.chip-empresa.ativo { background: rgba(34,197,94,.10); color: #15803d; border-color: var(--accent-green); }
.chip-empresa input:disabled { opacity: .5; }

/* ── Título de seção dentro de formulários/modais ─────
   Divide o formulário em blocos (ex: "Liberações de módulos" e
   "Permissões de administrador" no modal de usuário). */
.secao-titulo {
    display: flex; align-items: center; gap: 8px;
    font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
    color: #475569; margin: 20px 0 10px; padding-top: 14px; border-top: 1px dashed #dde4ee;
}
.secao-titulo i { color: var(--accent); width: 16px; text-align: center; font-size: 13px; }
.secao-titulo:first-child { margin-top: 0; border-top: none; padding-top: 0; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 600; color: #475569; margin-bottom: 5px; }
.form-control {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 7px;
    font-size: 13.5px; background: #fff; color: var(--text-main);
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,158,255,.15); }
textarea.form-control { resize: vertical; min-height: 90px; }

.alert { padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; border: 1px solid transparent; }
.alert-success { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.alert-error   { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert-info    { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }

.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th { text-align: left; padding: 10px 12px; background: #f8fafc; color: #64748b; font-weight: 600; border-bottom: 1px solid var(--border); }
table.data-table td { padding: 10px 12px; border-bottom: 1px solid #f1f5f9; }
table.data-table tr:hover td { background: #f8fafc; }

/* ── Tipografia padrão das páginas ───────────────────────────────
   Título e subtítulo únicos, para todas as telas ficarem iguais
   (antes cada página repetia esses valores em style="" inline). */
.page-title { font-size: 20px; font-weight: 800; color: #1e293b; margin: 0; line-height: 1.25; }
.page-sub { font-size: 13px; color: #64748b; margin: 4px 0 0; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-green  { background: rgba(34,197,94,.12);  color: #15803d; }
.badge-red    { background: rgba(239,68,68,.12);  color: #b91c1c; }
.badge-gray   { background: rgba(100,116,139,.12); color: #475569; }
.badge-blue   { background: rgba(59,158,255,.12); color: #1d4ed8; }

/* Grids reaproveitados pelos formulários (admin/apis, admin/usuarios, admin/auditoria) —
   em vez de grid-template-columns inline, para poder colapsar em telas pequenas. */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2-wide { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-filtros { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr 1fr auto auto; gap: 12px; align-items: end; }

/* Mini gráfico de barras (CSS puro, sem lib) — usado no dashboard do usuário
   para "últimos 7 dias", propositalmente pequeno e sem exigir Chart.js. */
.mini-bars { display: flex; align-items: flex-end; gap: 8px; height: 100px; }
.mini-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.mini-bar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.mini-bar { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; transition: height .2s; }
.mini-bar-label { font-size: 10.5px; color: #94a3b8; margin-top: 6px; }

/* Dashboard: cards de consumo parelhos — o min-height igual trava os dois
   cards na MESMA altura em qualquer viewport (a grade estica por cima disso).
   Altura FIXA nas barras: flex com height:auto quebrava a cadeia de % dos
   filhos (.mini-bar-col height:100%) e as barrinhas colapsavam pra 2px. */
.dash-consumo { display: flex; flex-direction: column; min-height: 168px; }
.dash-consumo .consumo-centro { flex: 1; display: flex; align-items: center; }
.dash-consumo .mini-bars { height: 96px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.kpi-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.kpi-card .kpi-label { font-size: 12px; color: #64748b; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-card .kpi-value { font-size: 26px; font-weight: 800; color: var(--text-main); margin-top: 6px; }
.kpi-card .kpi-sub { font-size: 12px; color: #94a3b8; margin-top: 4px; }

.tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; margin-top: 6px; }
.tool-card {
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px 18px; display: flex; flex-direction: column; gap: 8px;
    text-decoration: none; color: inherit; position: relative; overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,.04); transition: transform .12s, box-shadow .15s;
}
.tool-card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(59,158,255,.15); }
.tool-card::before { content:''; position:absolute; top:0; left:0; right:0; height:3px; background: var(--stripe, var(--accent)); }
.tool-icon { width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.15em; background: var(--icon-bg, rgba(59,158,255,.1)); color: var(--icon-color, var(--accent)); }
.tool-name { font-size: 14px; font-weight: 700; }
.tool-desc { font-size: 12px; color: #64748b; line-height: 1.5; }

/* ── Chat ───────────────────────────────────────────── */
.chat-layout { display: flex; gap: 18px; align-items: flex-start; }
.chat-sidebar { width: 230px; flex-shrink: 0; padding: 14px; }
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* Altura da lista de conversas em classe (não inline) pra poder encurtar no
   celular — empilhada acima do chat, 60vh de lista empurrava a conversa
   inteira pra fora da tela. */
.chat-conv-lista { max-height: 60vh; overflow-y: auto; }
.chat-conv-item { display: flex; align-items: center; justify-content: space-between; border-radius: 7px; margin-bottom: 2px; }
.chat-conv-item a.chat-conv-link {
    flex: 1; display: block; padding: 8px 10px; font-size: 12.5px; color: #475569; min-width: 0;
    border-radius: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-conv-item.ativo a.chat-conv-link { background: #eff6ff; color: var(--accent); font-weight: 600; }
.chat-conv-meta { font-size: 10.5px; color: #94a3b8; }
.chat-conv-del { color: #cbd5e1; padding: 6px 8px; opacity: 0; transition: opacity .15s, color .15s; flex-shrink: 0; }
.chat-conv-item:hover .chat-conv-del { opacity: 1; }
.chat-conv-del:hover { color: var(--accent-red); }

.chat-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.chat-header-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 6px; min-width: 0; }
.chat-header-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.chat-header-controls { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.chat-header-controls select { max-width: 220px; }
.chat-campo { display: flex; flex-direction: column; gap: 4px; }
.chat-campo-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: #64748b; }
.chat-modelo-tag { background: #f1f5f9; border: 1px solid var(--border); border-radius: 7px; padding: 8px 12px; font-size: 12.5px; color: #334155; min-width: 130px; box-sizing: border-box; }

.btn-icon { background: none; border: none; color: #94a3b8; cursor: pointer; font-size: 12px; padding: 3px 5px; border-radius: 5px; }
.btn-icon:hover { color: var(--accent); background: rgba(59,158,255,.08); }
.btn-icon-sm { background: none; border: none; color: #94a3b8; cursor: pointer; font-size: 10.5px; padding: 0; }
.btn-icon-sm:hover { color: var(--accent); }

.chat-header-switches { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.chat-header-switches .switch-tool,
.chat-header-switches .switch-erp,
.chat-header-switches .switch-web-search {
    padding: 6px 10px; font-size: 12px; gap: 6px;
}
.chat-header-switches .switch-trilho { width: 28px; height: 15px; }
.chat-header-switches .switch-bolinha { width: 11px; height: 11px; top: 2px; left: 2px; }
.chat-header-switches .switch-tool.switch-erp.ativo .switch-bolinha,
.chat-header-switches .switch-erp.ativo .switch-bolinha,
.chat-header-switches .switch-tool.switch-web-search.ativo .switch-bolinha,
.chat-header-switches .switch-web-search.ativo .switch-bolinha { transform: translateX(13px); }

.chat-consumo { margin-bottom: 14px; }
.chat-consumo-bar-wrap { background: #f1f5f9; border-radius: 6px; height: 6px; overflow: hidden; }
.chat-consumo-bar { height: 100%; transition: width .3s; background: var(--accent); }
.chat-consumo-label { font-size: 11px; color: #64748b; margin-top: 5px; }

.chat-window { display: flex; flex-direction: column; gap: 16px; padding: 8px 2px 20px; max-height: 56vh; overflow-y: auto; }
.msg-row { display: flex; flex-direction: column; max-width: 80%; }
.msg-row-user { align-self: flex-end; align-items: flex-end; }
.msg-row-assistant { align-self: flex-start; align-items: flex-start; }
.msg { padding: 12px 16px; border-radius: 12px; font-size: 13.5px; line-height: 1.55; word-break: break-word; }
.msg-user { background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.msg-assistant { background: #f1f5f9; color: var(--text-main); border-bottom-left-radius: 3px; }
.msg-content { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
.msg-content p { margin: 0 0 8px; }
.msg-content p:last-child { margin-bottom: 0; }
/* Headings do markdown: sem regra própria, o navegador aplica o tamanho
   default (h1 = 2x o texto) — quando a IA usa a busca ela responde
   estruturada com #/## e isso explodiu a fonte no celular. Aqui a hierarquia
   continua visível, mas sempre proporcional ao texto da bolha. */
.msg-content h1, .msg-content h2, .msg-content h3, .msg-content h4, .msg-content h5, .msg-content h6 {
    margin: 12px 0 6px; line-height: 1.3; font-weight: 700;
}
.msg-content h1 { font-size: 16px; }
.msg-content h2 { font-size: 15px; }
.msg-content h3 { font-size: 14px; }
.msg-content h4, .msg-content h5, .msg-content h6 { font-size: 13.5px; }
.msg-content h1:first-child, .msg-content h2:first-child, .msg-content h3:first-child { margin-top: 0; }
/* Citação (a IA usa > quando busca/cita): normaliza as margens default e dá
   um indicador visual lateral em vez do recuo gigante do navegador. */
.msg-content blockquote {
    margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--accent);
    background: rgba(59,158,255,.06); border-radius: 0 6px 6px 0; color: #475569;
}
.msg-user .msg-content blockquote { background: rgba(255,255,255,.12); border-left-color: rgba(255,255,255,.7); color: #fff; }
.msg-content ul, .msg-content ol { margin: 6px 0; padding-left: 20px; }
.msg-content pre { background: #0f172a; color: #e2e8f0; padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: 12px; margin: 8px 0; }
.msg-content pre code { background: none; padding: 0; }
/* Tabelas dentro da resposta da IA (markdown) — resultado de consulta ao
   ERP quase sempre volta como tabela, e sem isso ela estoura o balão e
   dá rolagem horizontal na PÁGINA inteira no celular. O truque do
   `display:block; width:max-content` (mesmo usado pelo GitHub) faz a rolagem
   ficar contida na própria tabela. */
.msg-content table { display: block; width: max-content; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 12px; margin: 8px 0; }
.msg-content th, .msg-content td { border: 1px solid rgba(0,0,0,.12); padding: 5px 9px; text-align: left; white-space: nowrap; }
.msg-content th { background: rgba(0,0,0,.05); font-weight: 700; }
.msg-user .msg-content th, .msg-user .msg-content td { border-color: rgba(255,255,255,.25); }
.msg-user .msg-content th { background: rgba(255,255,255,.15); }
.msg-content img { max-width: 100%; height: auto; }
.msg-user .msg-content code { background: rgba(255,255,255,.18); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.msg-assistant .msg-content code { background: rgba(0,0,0,.07); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.msg-attachment { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-top: 6px; opacity: .9; }
.msg-meta { font-size: 10.5px; color: #94a3b8; margin-top: 4px; display: flex; align-items: center; gap: 6px; }

/* ── Painel "Processos" (o que a IA fez por baixo) ─────
   Recolhido por padrão: quem só quer a resposta não vê nada, quem precisa
   auditar abre e vê cada SQL, o tempo e as linhas retornadas. */
.processos { margin-top: 10px; border-top: 1px dashed #cbd5e1; padding-top: 8px; }
.processos > summary {
    cursor: pointer; font-size: 11.5px; font-weight: 700; color: #64748b;
    list-style: none; display: flex; align-items: center; gap: 6px;
}
.processos > summary::-webkit-details-marker { display: none; }
.processos > summary::before { content: '\25B8'; font-size: 10px; transition: transform .15s; }
.processos[open] > summary::before { transform: rotate(90deg); }
.processos > summary:hover { color: var(--accent); }
.processos-lista { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.processo-item { font-size: 11.5px; color: #475569; }
.processo-cab { font-weight: 700; color: #334155; margin-bottom: 3px; }
.processo-sql {
    background: #0f172a; color: #e2e8f0; padding: 8px 10px; border-radius: 6px;
    font-size: 11px; line-height: 1.5; margin: 0; overflow-x: auto; white-space: pre-wrap; word-break: break-word;
}
.processo-ok   { color: #15803d; font-weight: 600; }
.processo-erro { color: #b91c1c; font-weight: 600; }

.typing-dots { display: inline-flex; gap: 3px; align-items: center; padding: 2px 0; }
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: #94a3b8; animation: typingPulse 1.2s infinite ease-in-out; }
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes typingPulse { 0%, 60%, 100% { opacity: .3; transform: scale(.8); } 30% { opacity: 1; transform: scale(1); } }

.chat-input-row { display: flex; gap: 10px; align-items: flex-end; border-top: 1px solid var(--border); padding-top: 14px; }
/* O min-height: 90px de textarea.form-control (pensado pros formulários) fazia
   o campo do chat nascer com 3 linhas de altura, apesar do rows="1" e do
   auto-grow no JS — no celular isso comia meia tela. */
.chat-input-row textarea { flex: 1; max-height: 240px; min-height: 42px; }
/* Microfone (voz → texto): em gravação o botão fica vermelho pulsando —
   o estado precisa ser óbvio de longe, sem depender de texto. */
.btn-mic.ativo {
    background: var(--accent-red); color: #fff; border-color: var(--accent-red);
    animation: micPulse 1.2s ease-in-out infinite;
}
@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.45); }
    50% { box-shadow: 0 0 0 7px rgba(239,68,68,0); }
}

.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }

/* ── Login ──────────────────────────────────────────── */
body.login-body {
    background: #f3f5f9; display: flex; align-items: center; justify-content: center; min-height: 100vh;
    background-image: radial-gradient(circle at 50% 0%, rgba(6,74,106,.16), transparent 62%);
    padding: 20px;
}
.login-card {
    width: 100%; max-width: 400px; background: #ffffff; border-radius: 16px; padding: 34px 30px;
    border: 1px solid #dde4ee; box-shadow: 0 20px 60px rgba(6,74,106,.16);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand img { height: 46px; margin-bottom: 10px; }
.login-brand .name { color: #064A6A; font-weight: 700; letter-spacing: .05em; font-size: 14px; }
.login-card label { color: #475569; }
.login-card .form-control { background: #ffffff; border-color: #dde4ee; color: #1e293b; }
.login-card .form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(210,20,30,.12); }
.login-card .btn-primary { width: 100%; justify-content: center; padding: 11px; font-size: 13.5px; letter-spacing: .03em; }
.login-card .btn-primary:hover { filter: brightness(1.08); }
.login-footer { text-align: center; margin-top: 18px; font-size: 11px; color: #94a3b8; line-height: 1.7; }
.login-footer a { color: #64748b; text-decoration: none; }
.login-footer a:hover { color: var(--accent); text-decoration: underline; }
.attempts-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 14px; }
.attempts-dots .dot { width: 8px; height: 8px; border-radius: 50%; background: #e2e8f0; }
.attempts-dots .dot.usada { background: var(--accent-red); }

/* ── Utilities ──────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-0 { margin-top: 0; }
.text-muted { color: #64748b; }

.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 19; }

@media (max-width: 880px) {
    .sidebar { position: fixed; left: -100%; z-index: 20; transition: left .2s; box-shadow: 4px 0 20px rgba(0,0,0,.3); }
    .sidebar.open { left: 0; }
    .sidebar.open ~ .sidebar-backdrop { display: block; }
    .app-shell { display: block; }

    main.content { padding: 16px 14px 30px; }
    .topbar { padding: 0 14px; }

    /* Nome de usuário longo empurrava o botão de sair fora da tela. */
    .topbar .user-box { gap: 8px; min-width: 0; }
    .topbar .user-box > span:first-of-type { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 34vw; }

    /* iOS Safari dá zoom automático ao focar campo com fonte < 16px, e o zoom
       desloca o layout todo — é o que mais dá sensação de "quebrou". 16px
       exatos desligam esse comportamento. */
    input.form-control, select.form-control, textarea.form-control { font-size: 16px; }

    .grid-2, .grid-2-wide, .grid-3 { grid-template-columns: 1fr; }

    /* Cards de consumo empilhados: mesmo min-height nos dois + barras mais
       compactas com altura fixa — empilhado, os dois cards ficam com a mesma
       altura (140px) e as barrinhas continuam desenhando (sem colapso de %). */
    .dash-consumo { min-height: 140px; }
    .dash-consumo .mini-bars { height: 64px; }

    .grid-filtros { grid-template-columns: 1fr; }
    .grid-filtros button, .grid-filtros a.btn { width: 100%; text-align: center; justify-content: center; }

    /* As tabelas têm de 6 a 9 colunas e `width:100%`: dentro do
       .table-responsive elas se esmagavam até ficar ilegível em vez de rolar.
       Com uma largura mínima, o wrapper finalmente rola na horizontal. */
    table.data-table { min-width: 700px; }

    /* Textarea sozinha na primeira linha e os botões numa linha só embaixo,
       com o "Enviar" empurrado pra direita — senão cada botão cai numa linha. */
    .chat-input-row { flex-wrap: wrap; align-items: center; }
    .chat-input-row textarea { order: -1; flex: 1 0 100%; width: 100%; }
    .chat-input-row > .btn:last-child { margin-left: auto; }
    .msg-row { max-width: 92%; }

    .chat-layout { flex-direction: column; }
    .chat-sidebar { width: 100% !important; }
    .chat-conv-lista { max-height: 30vh; }
    .chat-window { max-height: 60vh; }
    /* Sem :hover em tela de toque, a lixeira de excluir conversa ficava
       invisível pra sempre — no celular ela é sempre visível. */
    .chat-conv-del { opacity: 1; }

    .chat-header { flex-direction: column; align-items: stretch; }
    /* No celular os campos do header empilham em largura cheia (alvo de toque
       grande) em vez de quebrarem em linhas irregulares com largura natural
       de 220px — o flex-wrap + justify-content:flex-end do desktop deixava
       os selects flutuando à direita e desalinhados. */
    .chat-header-controls { flex-direction: column; align-items: stretch; justify-content: flex-start; }
    .chat-header-controls select { max-width: none; }
    .chat-campo { width: 100%; }
    .chat-modelo-tag { align-self: flex-start; min-width: 0; }
    .chat-header-switches { justify-content: flex-start; }
    .chat-header-title span { max-width: none; }

    /* Modal em tela pequena: cola no topo e rola, em vez de ficar centralizado
       e ter o miolo cortado quando o teclado virtual sobe. */
    .modal-overlay { align-items: flex-start; padding: 12px; overflow-y: auto; }
}

/* ── Celular estreito ───────────────────────────────── */
@media (max-width: 560px) {
    main.content { padding: 14px 10px 26px; }
    .topbar { padding: 0 10px; }
    .card { padding: 14px 13px; }
    .card + .card { margin-top: 12px; }

    /* Abaixo disso não cabe nome + badge + sair na mesma barra: sobra o avatar
       com a inicial (o nome inteiro fica no atributo title). */
    .topbar .user-box > span:first-of-type { display: none; }

    .kpi-card { padding: 15px 16px; }
    .kpi-card .kpi-value { font-size: 22px; }
    .kpi-card .kpi-label { font-size: 11px; }

    .btn { padding: 9px 13px; }
    /* Topbar apertada: o botão "Ajuda" fica só com o ícone (o nome do
       usuário já some nesta largura). */
    .btn-ajuda-header-texto { display: none; }
    .btn-ajuda-header { padding: 4px 6px; }
    .modal-overlay .card { padding: 16px 14px; }
    .login-card { padding: 26px 20px; }
    .mini-bar-label { font-size: 9px; }
    .chat-window { max-height: 56vh; }
    .msg-row { max-width: 96%; }
}

/* Botão "?" flutuante de ajuda contextual (footer.php) */
.btn-ajuda { position: fixed; bottom: 18px; right: 18px; width: 42px; height: 42px; border-radius: 50%; border: none; background: var(--accent); color: #fff; font-size: 19px; font-weight: 800; line-height: 1; cursor: pointer; z-index: 25; box-shadow: 0 4px 14px rgba(0,0,0,.25); display: flex; align-items: center; justify-content: center; }
.btn-ajuda:hover { filter: brightness(1.1); transform: scale(1.05); }
/* X no canto do "?": dispensa (esconde) os botões de ajuda e memoriza no
   localStorage — o botão "Ajuda" do header (header.php) reativa. */
.btn-ajuda-x {
    position: absolute; top: -4px; right: -4px; width: 16px; height: 16px;
    border-radius: 50%; background: #1e293b; color: #fff;
    font-size: 11px; font-weight: 700; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; border: 1px solid rgba(255,255,255,.35);
}
.btn-ajuda-x:hover { background: var(--accent-red); }
/* Botão "Ajuda" na topbar (header.php) */
.btn-ajuda-header {
    display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
    background: none; border: none; cursor: pointer;
    color: #64748b; font-size: 13px; font-weight: 600;
    padding: 4px 8px; border-radius: 6px;
}
.btn-ajuda-header:hover { color: var(--accent); background: rgba(59,158,255,.08); }

/* Linha de tabela clicável (histórico de conversas): cursor de link */
table.data-table tr[onclick] { cursor: pointer; }

/* ── Sino de notificações (módulo Projetos) ─────────────────────── */
.sino-wrap { position: relative; display: inline-flex; flex-shrink: 0; }
.btn-sino {
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    background: none; border: none; cursor: pointer; color: #64748b;
    font-size: 15px; padding: 4px 6px; border-radius: 6px;
}
.btn-sino:hover { color: var(--accent); background: rgba(59,158,255,.08); }
.sino-badge {
    position: absolute; top: -4px; right: -6px; min-width: 16px; height: 16px;
    padding: 0 3px; border-radius: 9px; background: var(--accent-red); color: #fff;
    font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
}
.sino-dropdown {
    position: absolute; top: calc(100% + 8px); right: 0; z-index: 90;
    width: 320px; max-width: 86vw; background: #fff; border: 1px solid #e2e8f0;
    border-radius: 10px; box-shadow: 0 10px 30px rgba(15,23,42,.14);
}
.sino-item {
    display: block; padding: 10px 14px; text-decoration: none; color: #1e293b;
    border-bottom: 1px solid #f1f5f9; cursor: pointer;
}
.sino-item:hover { background: #f8fafc; }
.sino-item:last-child { border-bottom: none; }
@media (max-width: 880px) {
    .sino-dropdown { width: 300px; }
}

/* Mobile: títulos menores para não quebrar linha demais */
@media (max-width: 560px) {
    .page-title { font-size: 17px; }
    .page-sub { font-size: 12px; }
}
