:root {
  --bg: #f7f7f8; --lateral: #eef0f3; --card: #fff; --texto: #1d2330; --suave: #5e6778; --borda: #dde1e8;
  --primaria: #1f5fbf; --primaria-texto: #fff; --usuario: #e6eefb; --erro: #b42318; --ok: #12805c;
  --hover: rgba(16, 24, 40, .06); --ativo: rgba(31, 95, 191, .12); --codigo: #f0f2f5;
  --sombra: 0 4px 24px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .06);
  --largura: 780px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191d; --lateral: #111316; --card: #212429; --texto: #e7e9ee; --suave: #9aa3b2; --borda: #2f343c;
    --primaria: #5b93e6; --primaria-texto: #0d1117; --usuario: #273449; --erro: #f97066; --ok: #4ccf9a;
    --hover: rgba(255, 255, 255, .06); --ativo: rgba(91, 147, 230, .18); --codigo: #1b1e22;
    --sombra: 0 4px 24px rgba(0, 0, 0, .35), 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--texto); font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; padding: 8px 14px; background: transparent; color: inherit; }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--primaria); outline-offset: 2px; }
input, textarea, select { font: inherit; color: var(--texto); background: var(--card); border: 1px solid var(--borda); border-radius: 10px; padding: 9px 11px; }
[hidden] { display: none !important; }
.sprite { display: none; }
.icone { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.botao-icone { width: 36px; height: 36px; padding: 0; display: inline-grid; place-items: center; color: var(--suave); border-radius: 10px; flex: none; }
.botao-icone:hover:not(:disabled) { background: var(--hover); color: var(--texto); }
.primario { background: var(--primaria); color: var(--primaria-texto); font-weight: 600; }
.espaco { flex: 1; }
.erro { color: var(--erro); margin: 0; font-size: 14px; }

.marca { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.logo { width: 28px; height: 28px; border-radius: 8px; display: inline-grid; place-items: center; background: var(--primaria); color: var(--primaria-texto); font-size: 12px; font-weight: 800; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--borda); border-radius: 16px; padding: 28px; width: min(400px, 100%); display: grid; gap: 14px; box-shadow: var(--sombra); }
.card label { display: grid; gap: 4px; color: var(--suave); font-size: 14px; }
.card .erro { min-height: 1.2em; }
.sub { margin: 0; color: var(--suave); font-size: 14px; }

/* ---------- estrutura ---------- */
.app { height: 100vh; height: 100dvh; display: flex; overflow: hidden; }
.principal { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

/* ---------- painel lateral ---------- */
.lateral { width: 280px; flex: none; display: flex; flex-direction: column; gap: 6px; padding: 12px 10px; background: var(--lateral); border-right: 1px solid var(--borda); min-height: 0; }
.lateral-topo { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 6px 6px; }
.empresa-campo { display: grid; gap: 4px; padding: 0 6px 6px; font-size: 12px; color: var(--suave); }
.empresa-campo select { width: 100%; padding: 7px 9px; font-size: 14px; }
.nova-conversa { display: flex; align-items: center; gap: 10px; padding: 9px 10px; font-weight: 600; border-radius: 10px; color: var(--primaria); }
.nova-conversa:hover { background: var(--hover); }
.lateral-titulo { padding: 10px 10px 4px; font-size: 12px; font-weight: 600; color: var(--suave); text-transform: uppercase; letter-spacing: .04em; }
.lista-conversas { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.lista-vazia { padding: 6px 10px; color: var(--suave); font-size: 13px; }
.item-conversa { position: relative; display: flex; align-items: center; border-radius: 10px; }
.item-conversa:hover { background: var(--hover); }
.item-conversa.ativa { background: var(--ativo); }
.item-conversa .abrir { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; text-align: left; padding: 8px 10px; font-size: 14px; border-radius: 10px; }
.item-conversa .abrir span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-conversa .apagar { width: 30px; height: 30px; margin-right: 4px; opacity: 0; }
.item-conversa:hover .apagar, .item-conversa.ativa .apagar, .item-conversa .apagar:focus-visible { opacity: 1; }
.item-conversa .apagar .icone { width: 16px; height: 16px; }
.item-conversa .girando { width: 12px; height: 12px; flex: none; }
.lateral-nota { margin: 0; padding: 6px 10px; font-size: 12px; color: var(--suave); }
.conta { display: flex; align-items: center; gap: 10px; padding: 10px 4px 0 6px; border-top: 1px solid var(--borda); }
.avatar { width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center; background: var(--ativo); color: var(--primaria); font-weight: 700; font-size: 13px; text-transform: uppercase; }
.usuario { flex: 1; min-width: 0; font-size: 13px; color: var(--suave); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fundo-lateral { display: none; }

/* ---------- topo ---------- */
.topo { height: 52px; flex: none; display: flex; align-items: center; gap: 6px; padding: 0 10px; }
.titulo-conversa { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#abrir-lateral, .so-recolhida { display: none; }
.app.lateral-recolhida .lateral, .app.lateral-recolhida .fundo-lateral { display: none; }
.app.lateral-recolhida #abrir-lateral, .app.lateral-recolhida .so-recolhida { display: inline-grid; }

/* ---------- área das mensagens (uma rolagem só, a da coluna inteira) ---------- */
.rolagem { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-gutter: stable; }
.boas-vindas { max-width: var(--largura); margin: 0 auto; padding: 12vh 20px 24px; text-align: center; }
.boas-vindas h1 { margin: 0 0 6px; font-size: 30px; font-weight: 600; letter-spacing: -.02em; }
.boas-vindas-sub { margin: 0 auto; max-width: 520px; color: var(--suave); }
.sugestoes { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-top: 28px; }
.sugestoes button { background: var(--card); border: 1px solid var(--borda); text-align: left; padding: 12px 14px; border-radius: 14px; color: var(--texto); font-size: 14px; }
.sugestoes button:hover { border-color: var(--primaria); }

.conversa { max-width: var(--largura); margin: 0 auto; padding: 8px 20px 40px; display: flex; flex-direction: column; gap: 26px; }
.conversa > * { flex: none; }
.msg-usuario { align-self: flex-end; max-width: min(85%, 640px); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.msg-usuario .bolha { background: var(--usuario); border-radius: 18px 18px 6px 18px; padding: 10px 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-imagens { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.msg-imagens img { width: 120px; height: 120px; object-fit: cover; border-radius: 12px; border: 1px solid var(--borda); cursor: zoom-in; background: var(--card); }
.msg-imagens.uma img { width: auto; height: auto; max-width: min(100%, 360px); max-height: 280px; }

.msg-assistente { min-width: 0; }
.msg-assistente .aviso-msg { margin: 10px 0 0; font-size: 14px; color: var(--suave); }
.msg-assistente .aviso-msg.erro { color: var(--erro); }

.markdown { overflow-wrap: anywhere; line-height: 1.65; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p, .markdown ul, .markdown ol { margin: 0 0 12px; }
.markdown ul, .markdown ol { padding-left: 24px; }
.markdown li { margin: 3px 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: 20px 0 8px; line-height: 1.3; }
.markdown h1 { font-size: 21px; } .markdown h2 { font-size: 18px; } .markdown h3, .markdown h4 { font-size: 16px; }
.markdown a { color: var(--primaria); }
.markdown code { font: 13px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace; background: var(--codigo); border-radius: 5px; padding: 1px 5px; }
.markdown pre { background: var(--codigo); border: 1px solid var(--borda); border-radius: 12px; padding: 12px 14px; overflow-x: auto; margin: 0 0 12px; }
.markdown pre code { background: none; padding: 0; }
.markdown blockquote { margin: 0 0 12px; padding: 2px 14px; border-left: 3px solid var(--borda); color: var(--suave); }
.markdown hr { border: 0; border-top: 1px solid var(--borda); margin: 18px 0; }
.markdown .tabela { overflow-x: auto; margin: 4px 0 14px; border: 1px solid var(--borda); border-radius: 12px; }
.markdown table { border-collapse: collapse; min-width: 100%; font-size: 14px; }
.markdown th, .markdown td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--borda); vertical-align: top; }
.markdown th { background: var(--hover); font-weight: 600; white-space: nowrap; }
.markdown tr:last-child td { border-bottom: 0; }
.markdown td + td, .markdown th + th { border-left: 1px solid var(--borda); }

/* passos (consultas ao ERP) */
.passos { margin-bottom: 10px; font-size: 14px; color: var(--suave); }
.passos summary { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; padding: 4px 10px 4px 8px; border-radius: 8px; user-select: none; }
.passos summary::-webkit-details-marker { display: none; }
.passos summary:hover { background: var(--hover); color: var(--texto); }
.passos summary .seta { width: 14px; height: 14px; transition: transform .15s; }
.passos[open] summary .seta { transform: rotate(90deg); }
.passos ul { list-style: none; margin: 4px 0 0; padding: 2px 0 2px 14px; border-left: 2px solid var(--borda); margin-left: 15px; display: grid; gap: 3px; }
.passos li { display: flex; align-items: center; gap: 8px; }
.passos li .icone { width: 14px; height: 14px; }
.passos li.ok .icone { color: var(--ok); }
.passos li.falhou { color: var(--erro); }
.girando { width: 14px; height: 14px; border: 2px solid var(--borda); border-top-color: var(--primaria); border-radius: 50%; animation: girar .8s linear infinite; flex: none; }
@keyframes girar { to { transform: rotate(360deg); } }

.pensando { display: flex; gap: 5px; padding: 8px 0; }
.pensando span { width: 7px; height: 7px; border-radius: 50%; background: var(--suave); animation: pulsar 1.2s infinite ease-in-out; }
.pensando span:nth-child(2) { animation-delay: .15s; }
.pensando span:nth-child(3) { animation-delay: .3s; }
@keyframes pulsar { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

.msg-acoes { display: flex; align-items: center; gap: 6px; margin-top: 8px; min-height: 30px; }
.msg-acoes .botao-icone { width: 30px; height: 30px; }
.msg-acoes .icone { width: 16px; height: 16px; }
.msg-meta { font-size: 12px; color: var(--suave); font-variant-numeric: tabular-nums; }
.msg-usuario .msg-meta { padding-right: 4px; }
.msg-usuario .msg-meta:empty { display: none; }

/* gráficos (ECharts, mesma paleta do ERP-Frontend) */
.grafico { margin: 6px 0 16px; padding: 12px 12px 8px 14px; border: 1px solid var(--borda); border-radius: 14px; background: var(--card); }
.grafico-topo { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 4px; }
.grafico figcaption { flex: 1; min-width: 0; display: grid; gap: 1px; padding-top: 4px; }
.grafico figcaption strong { font-size: 15px; line-height: 1.35; }
.grafico figcaption span { font-size: 13px; color: var(--suave); }
.grafico-topo .botao-icone { width: 32px; height: 32px; }
.grafico-topo .icone { width: 17px; height: 17px; }
.grafico-area { width: 100%; height: 300px; display: grid; place-items: center; color: var(--suave); font-size: 13px; }
.grafico-aviso { display: flex; align-items: center; gap: 10px; padding: 14px 16px; color: var(--suave); font-size: 14px; }
.grafico-erro { color: var(--erro); }
.grafico-tooltip { font-family: inherit; }
.tt-titulo { font-weight: 600; margin-bottom: 4px; }
.tt-linha { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.tt-linha b { margin-left: auto; padding-left: 14px; font-variant-numeric: tabular-nums; }
.tt-total { display: flex; gap: 8px; margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--borda); }
.tt-total b { margin-left: auto; padding-left: 14px; }
.tt-suave { color: var(--suave); font-size: 12px; margin-top: 2px; }
.tt-ponto { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--suave); }
.tt-ponto.c0 { background: #3b82f6; } .tt-ponto.c1 { background: #22c55e; } .tt-ponto.c2 { background: #f59e0b; }
.tt-ponto.c3 { background: #ef4444; } .tt-ponto.c4 { background: #a855f7; } .tt-ponto.c5 { background: #06b6d4; }
.tt-ponto.c6 { background: #64748b; } .tt-ponto.c7 { background: #ec4899; } .tt-ponto.c8 { background: #14b8a6; }
.tt-ponto.c9 { background: #f97316; }

/* ---------- compositor ---------- */
.compositor-area { flex: none; position: relative; padding: 0 16px 10px; }
.compositor { max-width: var(--largura); margin: 0 auto; background: var(--card); border: 1px solid var(--borda); border-radius: 22px; box-shadow: var(--sombra); padding: 10px 10px 8px 12px; display: flex; flex-direction: column; gap: 4px; transition: border-color .15s; }
.compositor:focus-within { border-color: color-mix(in srgb, var(--primaria) 55%, var(--borda)); }
.compositor textarea { border: 0; background: transparent; resize: none; outline: none; padding: 6px 4px; max-height: 40vh; min-height: 30px; line-height: 1.5; }
.compositor-acoes { display: flex; align-items: center; gap: 4px; }
.botao-enviar { width: 36px; height: 36px; padding: 0; display: grid; place-items: center; border-radius: 12px; background: var(--primaria); color: var(--primaria-texto); }
.botao-enviar:disabled { background: var(--borda); color: var(--suave); opacity: 1; }
.botao-enviar.parar { background: var(--texto); color: var(--bg); }
#microfone.gravando { background: color-mix(in srgb, var(--erro) 16%, transparent); color: var(--erro); }
.ouvindo { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--erro); margin-right: 4px; }
.onda { width: 8px; height: 8px; border-radius: 50%; background: var(--erro); animation: pulsar 1.2s infinite ease-in-out; }
.anexos { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 2px 4px; }
.anexo { position: relative; width: 64px; height: 64px; }
.anexo img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; border: 1px solid var(--borda); cursor: zoom-in; display: block; }
.anexo button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0; border-radius: 50%; display: grid; place-items: center; background: var(--texto); color: var(--bg); border: 2px solid var(--card); }
.anexo button .icone { width: 12px; height: 12px; stroke-width: 3; }
.anexo.carregando { display: grid; place-items: center; border: 1px dashed var(--borda); border-radius: 12px; }
.rodape { max-width: var(--largura); margin: 8px auto 0; text-align: center; font-size: 12px; color: var(--suave); }
.aviso { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(100% + 10px); margin: 0; padding: 8px 14px; border-radius: 10px; background: var(--texto); color: var(--bg); font-size: 14px; box-shadow: var(--sombra); max-width: calc(100% - 32px); z-index: 5; }
.ir-fim { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(100% + 10px); width: 36px; height: 36px; padding: 0; border-radius: 50%; display: grid; place-items: center; background: var(--card); color: var(--texto); border: 1px solid var(--borda); box-shadow: var(--sombra); z-index: 4; }
.ir-fim .icone { width: 18px; height: 18px; }

/* arrastar imagens */
.principal.arrastando::after { content: "Solte as imagens para anexar"; position: absolute; inset: 10px; border: 2px dashed var(--primaria); border-radius: 18px; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 88%, transparent); color: var(--primaria); font-weight: 600; font-size: 16px; z-index: 20; pointer-events: none; }

/* visualizador de imagem */
.visualizador { padding: 0; border: 0; background: transparent; max-width: 94vw; max-height: 94vh; }
.visualizador::backdrop { background: rgba(0, 0, 0, .78); }
.visualizador img { display: block; max-width: 94vw; max-height: 94vh; border-radius: 10px; cursor: zoom-out; }

/* ---------- celular e telas estreitas ---------- */
@media (max-width: 860px) {
  .lateral { position: fixed; inset: 0 auto 0 0; z-index: 30; width: min(300px, 86vw); transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--sombra); }
  .app.lateral-aberta .lateral { transform: none; }
  .app.lateral-aberta .fundo-lateral { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, .4); }
  .app.lateral-recolhida .lateral { display: flex; }
  #abrir-lateral, .so-recolhida { display: inline-grid; }
  .boas-vindas { padding-top: 6vh; }
  .boas-vindas h1 { font-size: 24px; }
  .sugestoes { grid-template-columns: 1fr; }
  .conversa { padding: 8px 14px 32px; }
  .compositor-area { padding: 0 10px 8px; }
  .rodape { display: none; }
  .item-conversa .apagar { opacity: 1; }
}
