:root {
  --fundo: #f4f6f5; --cartao: #fff; --texto: #1d2420; --suave: #66706a; --borda: #dde3df;
  --verde: #128c4a; --verde-escuro: #0d6b38; --vermelho: #c0392b; --amarelo: #b7791f; --azul: #2b6cb0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--texto);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--fundo); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 12px; }
h2 { font-size: 1.25rem; }
button, .botao {
  background: var(--verde); color: #fff; border: 0; border-radius: 6px; padding: 8px 14px;
  font: inherit; cursor: pointer;
}
button:hover { background: var(--verde-escuro); }
button.secundario { background: #e7ece9; color: var(--texto); }
button.perigo { background: var(--vermelho); }
button.link { background: none; color: var(--azul); padding: 0; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--borda); border-radius: 6px; font: inherit; background: #fff;
}
textarea { min-height: 120px; resize: vertical; }
label { display: block; margin-bottom: 12px; font-size: .9rem; color: var(--suave); }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--texto); }
label.check { display: flex; gap: 8px; align-items: center; color: var(--texto); }
label.check input { width: auto; margin: 0; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .cartao { width: 100%; max-width: 360px; }
.cartao { background: var(--cartao); border: 1px solid var(--borda); border-radius: 10px; padding: 20px; margin-bottom: 16px; }
.msg-erro { color: var(--vermelho); min-height: 1.2em; margin: 0 0 8px; }
.msg-ok { color: var(--verde); }
.dica { color: var(--suave); font-size: .85rem; margin: -6px 0 12px; }

.topo {
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 10px 16px;
  background: var(--cartao); border-bottom: 1px solid var(--borda);
}
.topo nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.topo nav button { background: none; color: var(--texto); }
.topo nav button.ativa { background: #e3f3ea; color: var(--verde-escuro); }
.quem { color: var(--suave); font-size: .9rem; }
main { max-width: 1000px; margin: 0 auto; padding: 16px; }

.grade { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.linha { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tabela-rolagem { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--borda); vertical-align: top; }
th { color: var(--suave); font-weight: 600; }
tr.clicavel { cursor: pointer; }
tr.clicavel:hover { background: #f0f5f2; }

.selo { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .8rem; background: #e7ece9; }
.selo.conectado, .selo.concluida, .selo.enviado { background: #d8f0e2; color: var(--verde-escuro); }
.selo.aguardando_qr, .selo.iniciando, .selo.autenticando, .selo.na_fila, .selo.enviando, .selo.pendente { background: #fdf0d5; color: var(--amarelo); }
.selo.erro, .selo.cancelada, .selo.cancelado { background: #f9dcd8; color: var(--vermelho); }
.qr { display: block; margin: 12px auto; max-width: 100%; }
.mensagem-previa { white-space: pre-wrap; background: #e3f3ea; border-radius: 8px; padding: 10px; }
dialog { border: 0; border-radius: 10px; width: min(560px, calc(100vw - 32px)); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.35); }

/* ---------- Conversas (web chat) ---------- */
.badge { display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 999px; background: var(--verde); color: #fff; font-size: .75rem; text-align: center; }
body.modo-chat #tela-app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
body.modo-chat main { max-width: none; padding: 0; flex: 1; min-height: 0; width: 100%; }
.webchat { display: grid; grid-template-columns: 340px 1fr; height: 100%; background: var(--cartao); }
.conv { border-right: 1px solid var(--borda); display: flex; flex-direction: column; min-height: 0; }
.conv-topo { padding: 10px; display: grid; gap: 8px; border-bottom: 1px solid var(--borda); }
.conv-lista { overflow-y: auto; flex: 1; }
.conv-item { display: flex; gap: 10px; width: 100%; text-align: left; background: none; color: var(--texto); border-radius: 0;
  padding: 10px 12px; border-bottom: 1px solid #eef1ef; align-items: center; }
.conv-item:hover { background: #f3f7f5; }
.conv-item.ativa { background: #e3f3ea; }
.conv-info { flex: 1; min-width: 0; display: grid; gap: 2px; }
.conv-linha { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.conv-linha strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-linha small, .conv-numero { color: var(--suave); font-size: .75rem; }
.conv-ultima { color: var(--suave); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; background: #cfe8da; color: var(--verde-escuro);
  display: grid; place-items: center; font-weight: 600; font-size: .85rem; }
.chat { display: flex; flex-direction: column; min-height: 0; background: #efeae2; }
.chat-vazio { margin: auto; text-align: center; color: var(--suave); }
.chat-vazio div { font-size: 3rem; }
.chat-topo { display: flex; gap: 10px; align-items: center; padding: 8px 12px; background: var(--cartao); border-bottom: 1px solid var(--borda); }
.chat-msgs { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 4px; }
.dia { align-self: center; background: #fff; color: var(--suave); font-size: .75rem; padding: 3px 10px; border-radius: 8px; margin: 8px 0; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.bolha { max-width: min(75%, 520px); padding: 6px 9px 4px; border-radius: 8px; box-shadow: 0 1px 1px rgba(0,0,0,.08); word-wrap: break-word; }
.bolha.dele { align-self: flex-start; background: #fff; border-top-left-radius: 2px; }
.bolha.minha { align-self: flex-end; background: #d9fdd3; border-top-right-radius: 2px; }
.bolha .texto { white-space: pre-wrap; }
.bolha .autor { font-size: .72rem; color: var(--verde-escuro); font-weight: 600; margin-bottom: 2px; }
.bolha .meta { text-align: right; font-size: .7rem; color: var(--suave); margin-top: 2px; }
.bolha .ack.lida { color: #34b7f1; }
.bolha img.midia, .bolha video.midia { display: block; max-width: 100%; max-height: 320px; border-radius: 6px; }
.bolha img.figurinha { width: 140px; height: 140px; object-fit: contain; }
.bolha audio { width: 260px; max-width: 100%; }
.bolha .doc { display: inline-block; padding: 8px; background: rgba(0,0,0,.05); border-radius: 6px; color: var(--texto); text-decoration: none; }
.chat-aviso { background: #fdf0d5; color: var(--amarelo); padding: 6px 12px; font-size: .85rem; }
.chat-entrada { display: flex; gap: 6px; align-items: flex-end; padding: 8px 10px; background: #f0f2f0; }
.chat-entrada textarea { min-height: 40px; max-height: 140px; resize: none; border-radius: 20px; padding: 9px 14px; }
button.icone { background: none; color: var(--suave); font-size: 1.3rem; padding: 6px 8px; flex: none; }
button.icone:hover { background: rgba(0,0,0,.06); }
button.icone.enviar { color: var(--verde); }
button.icone.gravando { color: var(--vermelho); animation: pisca 1s infinite; }
@keyframes pisca { 50% { opacity: .4; } }
.chat-topo .voltar { display: none; }
@media (max-width: 760px) {
  .webchat { grid-template-columns: 1fr; }
  .webchat.abriu .conv { display: none; }
  .webchat:not(.abriu) .chat { display: none; }
  .chat-topo .voltar { display: inline-block; }
  .chat-msgs { padding: 12px; }
  .bolha { max-width: 88%; }
}
@media (max-width: 760px) {
  .topo { flex-wrap: nowrap; gap: 8px; padding: 6px 8px; }
  .topo > strong { display: none; }
  .topo nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .topo nav button { white-space: nowrap; padding: 6px 10px; }
  .quem #quem { display: none; }
}

/* ---------- Atendimento (setores, status, etiquetas) ---------- */
.topo { background: #0f3d2a; border-bottom: 0; color: #fff; }
.topo > strong { color: #fff; letter-spacing: .2px; }
.topo nav button { color: #d6e9de; }
.topo nav button:hover { background: rgba(255,255,255,.08); }
.topo nav button.ativa { background: #1f6b47; color: #fff; }
.topo .quem { color: #b9d3c4; }
.topo button.link { color: #fff; text-decoration: underline; }
.topo .badge { background: #25d366; }
button.pequeno { padding: 5px 10px; font-size: .85rem; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600;
  --cor: #66706a; color: var(--cor); background: color-mix(in srgb, var(--cor) 14%, #fff); border: 1px solid color-mix(in srgb, var(--cor) 35%, #fff); white-space: nowrap; }
.conv-chips { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 2px; }
.conv-chips:empty { display: none; }
.filtros { display: flex; gap: 6px; }
.filtros select { font-size: .8rem; padding: 5px 6px; }
.abas-conv { display: flex; gap: 2px; background: #eef2ef; border-radius: 8px; padding: 3px; }
.abas-conv button { flex: 1; background: none; color: var(--suave); font-size: .78rem; padding: 6px 4px; border-radius: 6px; white-space: nowrap; }
.abas-conv button:hover { background: rgba(0,0,0,.04); }
.abas-conv button.ativa { background: #fff; color: var(--verde-escuro); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.abas-conv .cont { font-weight: 700; }
.abas-conv button[data-k="aguardando"] .cont { color: var(--amarelo); }
.chat-topo { flex-wrap: wrap; }
.chat-quem { flex: 1; min-width: 160px; }
.chat-acoes { display: flex; gap: 6px; flex-wrap: wrap; }
.chat-faixa { background: #fff8e6; color: #7a5310; padding: 7px 12px; font-size: .85rem; border-top: 1px solid #f3e2b8; }
.chat-faixa button.link { font-size: .85rem; font-weight: 600; }
.evento { align-self: center; background: #e1f0ff; color: #2c5282; font-size: .75rem; padding: 3px 10px; border-radius: 8px; margin: 4px 0; }
.compor { position: relative; }
.sugestoes { position: absolute; bottom: 100%; left: 10px; right: 10px; max-height: 260px; overflow-y: auto; background: #fff;
  border: 1px solid var(--borda); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.12); padding: 4px; z-index: 5; }
.sugestoes button { display: grid; gap: 2px; width: 100%; text-align: left; background: none; color: var(--texto); padding: 8px 10px; border-radius: 6px; }
.sugestoes button:hover { background: #f0f5f2; }
.sugestoes button strong { color: var(--verde-escuro); font-size: .85rem; }
.sugestoes button span { color: var(--suave); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lista-config { display: grid; gap: 8px; }
input.cor { width: 42px; height: 36px; padding: 2px; flex: none; }
.resposta-config { border: 1px solid var(--borda); border-radius: 8px; padding: 12px; }
.resposta-config textarea { min-height: 70px; }
main:has(> .cartao + .cartao) { max-width: 820px; }
@media (max-width: 760px) {
  .chat-acoes { width: 100%; }
  .filtros select { flex: 1; min-width: 0; }
}

/* ---------- Visual comercial: menu lateral escuro ---------- */
:root { --marinho: #0b1f33; --marinho-2: #12304d; --marinho-3: #1b4268; }
#tela-app:not([hidden]) { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; }
.topo { flex-direction: column; align-items: stretch; flex-wrap: nowrap; gap: 6px; padding: 18px 12px; background: var(--marinho);
  position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; }
.marca { display: flex; gap: 8px; align-items: center; color: #fff; padding: 0 8px 12px; border-bottom: 1px solid rgba(255,255,255,.08); }
.marca .logo { font-size: 1.4rem; }
.perfil { display: grid; justify-items: center; gap: 6px; padding: 16px 0 10px; color: #fff; text-align: center; }
.perfil .avatar { width: 64px; height: 64px; font-size: 1.3rem; background: var(--marinho-3); color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.12); }
.perfil #quem { display: grid; gap: 2px; }
.perfil #quem small { color: #8fa9c4; font-size: .78rem; }
.menu-titulo { color: #6f8aa6; font-size: .7rem; letter-spacing: 1.2px; margin: 10px 10px 4px; }
.topo nav { flex-direction: column; flex-wrap: nowrap; gap: 2px; flex: 1; }
.topo nav button, .topo .sair { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; color: #c9d6e3;
  background: none; padding: 10px 12px; border-radius: 8px; font-size: .95rem; }
.topo nav button:hover, .topo .sair:hover { background: rgba(255,255,255,.06); color: #fff; }
.topo nav button.ativa { background: var(--marinho-3); color: #fff; }
.topo nav .badge { margin-left: auto; background: #1f9d55; }
.topo .ic { width: 22px; text-align: center; }
.topo .sair { margin-top: 8px; border-top: 1px solid rgba(255,255,255,.08); border-radius: 0; padding-top: 14px; }
main { width: 100%; }
body.modo-chat #tela-app:not([hidden]) { display: grid; flex-direction: unset; height: 100vh; height: 100dvh; min-height: 0; }
body.modo-chat main { height: 100%; min-height: 0; overflow: hidden; }

/* lista e chat */
.conv { background: #f7f9fb; }
.conv-item { background: #fff; }
.conv-item:hover { background: #f1f5f9; }
.conv-item.ativa { background: #e3ecf6; box-shadow: inset 3px 0 0 var(--marinho-3); }
.avatar { background: #dbe6f1; color: var(--marinho-2); }
.chat-topo { background: var(--marinho); color: #fff; border-bottom: 0; padding: 10px 14px; }
.chat-topo .dica { color: #9fb5cb; }
.chat-topo .avatar { background: var(--marinho-3); color: #fff; }
.chat-topo button.icone { color: #fff; }
.chat-topo button.secundario { background: rgba(255,255,255,.12); color: #fff; }
.chat-topo button.secundario:hover { background: rgba(255,255,255,.22); }
.chat-topo .chip { background: rgba(255,255,255,.92); }
.chat { background: #fff; }
.chat-msgs { background: #fff; padding: 18px 5%; gap: 6px; }
.bolha { border-radius: 18px; padding: 8px 14px 5px; box-shadow: none; }
.bolha.dele { background: #e9edf1; border-top-left-radius: 18px; border-bottom-left-radius: 4px; }
.bolha.minha { background: var(--marinho-2); color: #fff; border-top-right-radius: 18px; border-bottom-right-radius: 4px; }
.bolha.minha .meta { color: #9fb5cb; }
.bolha.minha .autor { color: #8cc4ff; }
.bolha.minha .ack.lida { color: #5fd1ff; }
.bolha.minha .doc { color: #fff; background: rgba(255,255,255,.1); }
.dia { background: #f1f4f7; box-shadow: none; }
.chat-entrada { background: #f7f9fb; border-top: 1px solid var(--borda); }
.chat-entrada textarea { border-color: #d5dde5; }
button.icone.enviar { color: var(--marinho-2); }

@media (max-width: 760px) {
  #tela-app:not([hidden]) { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .topo, .topo nav { min-width: 0; }
  body.modo-chat #tela-app:not([hidden]) { grid-template-rows: auto minmax(0, 1fr); }
  .topo { flex-direction: row; align-items: center; height: auto; position: static; padding: 6px 8px; overflow: visible; }
  .marca, .perfil, .menu-titulo { display: none; }
  .topo nav { flex-direction: row; overflow-x: auto; }
  .topo nav button, .topo .sair { width: auto; padding: 7px 10px; gap: 6px; white-space: nowrap; font-size: .85rem; }
  .topo .sair { margin: 0; border: 0; padding-top: 7px; }
  .topo .sair .tx { display: none; }
}
label.check.destaque { background: #f0ebff; border: 1px solid #d8ccff; padding: 10px 12px; border-radius: 8px; color: #44337a; }
.dia-check { margin: 0; padding: 4px 8px; border: 1px solid var(--borda); border-radius: 6px; }
.opcao-robo .num-opcao { color: var(--marinho-2); }
.abas-conv button[data-k="bot"] .cont { color: #6b46c1; }
.conv { min-width: 0; overflow: hidden; }
.conv-linha .conv-ultima { flex: 1; min-width: 0; }
.conv-linha strong { min-width: 0; }
.conv-linha small { flex: none; }
.abas-conv { overflow-x: auto; scrollbar-width: none; }
.abas-conv button { flex: 1 0 auto; font-size: .74rem; padding: 6px 6px; }
.conv-topo .linha > div { min-width: 0; }
.conv-info { grid-template-columns: minmax(0, 1fr); }
