:root {
  --cor: #0b6bcb; --cor-texto: #fff;
  --fundo: #f1f4f8; --card: #fff; --texto: #1c2430; --suave: #6b7686; --borda: #e1e6ec;
  --verde: #1f9d55; --vermelho: #d33a2c; --amarelo: #fff4d6;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--fundo); color: var(--texto); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--borda); border-radius: 8px; background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--cor); }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
label small { font-weight: 400; color: var(--suave); }
h2 { margin: 0 0 16px; font-size: 20px; } h3 { margin: 0 0 14px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--borda); background: #fff; cursor: pointer; white-space: nowrap; text-decoration: none; font-size: 13px; }
.btn:hover { background: #f6f8fa; }
.btn.primario { background: var(--cor); color: var(--cor-texto); border-color: transparent; }
.btn.primario:hover { filter: brightness(.95); }
.btn.perigo { color: var(--vermelho); border-color: #f0c9c5; }
.btn.grande { padding: 12px; font-size: 15px; width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-icone { background: none; border: 0; cursor: pointer; font-size: 18px; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 8px; flex: none; }
.btn-icone:hover { background: #eef1f5; }
.btn-link { background: none; border: 0; color: var(--cor); cursor: pointer; text-decoration: underline; padding: 0; }
.erro { color: var(--vermelho); margin: 0; }

/* Login */
.pg-login { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.login-box { background: #fff; padding: 28px 24px; border-radius: 14px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.08); text-align: center; }
.login-box h1 { font-size: 20px; margin: 0 0 4px; }
.login-box label { text-align: left; }
.login-logo { height: 64px; object-fit: contain; }

/* Layout */
.app { display: flex; height: 100vh; height: 100dvh; }
.menu { width: 72px; background: var(--cor); color: var(--cor-texto); display: flex; flex-direction: column; align-items: center; padding: 10px 0; gap: 4px; flex: none; }
.menu-logo { width: 46px; height: 46px; object-fit: contain; background: #fff; border-radius: 10px; padding: 4px; margin-bottom: 10px; }
.menu-item { position: relative; background: none; border: 0; color: inherit; width: 60px; padding: 8px 0; border-radius: 10px; cursor: pointer; font-size: 20px; display: flex; flex-direction: column; align-items: center; gap: 2px; opacity: .8; }
.menu-item span { font-size: 10px; }
.menu-item:hover, .menu-item.ativo { background: rgba(255,255,255,.18); opacity: 1; }
.menu-fim { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.badge { position: absolute; top: 2px; right: 6px; background: var(--vermelho); color: #fff; font-size: 10px; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }
body:not(.admin) .so-admin { display: none; }

.aba { display: none; flex: 1; min-width: 0; }
.aba.ativa { display: flex; }
.pagina { padding: 22px; overflow: auto; width: 100%; }
.card { background: #fff; border: 1px solid var(--borda); border-radius: 12px; padding: 16px; margin-bottom: 16px; }

/* Lista */
.lista-col { width: 320px; background: #fff; border-right: 1px solid var(--borda); display: flex; flex-direction: column; flex: none; }
.lista-topo { display: flex; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid var(--borda); }
.eu { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.eu small { color: var(--suave); }
.filtros { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--borda); }
.filtro { flex: 1; border: 1px solid var(--borda); background: #fff; padding: 6px; border-radius: 20px; cursor: pointer; font-size: 12px; }
.filtro.ativo { background: var(--cor); color: var(--cor-texto); border-color: transparent; }
.lista { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.lista li { padding: 11px 12px; border-bottom: 1px solid #f0f2f5; cursor: pointer; display: flex; flex-direction: column; gap: 3px; position: relative; }
.lista li:hover { background: #f7f9fb; }
.lista li.sel { background: #eaf2fc; box-shadow: inset 3px 0 0 var(--cor); }
.lista li .l1 { display: flex; justify-content: space-between; gap: 8px; }
.lista li .l1 b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lista li .l1 time { color: var(--suave); font-size: 12px; flex: none; }
.lista li .l2 { color: var(--suave); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lista li .tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: #eef1f5; color: var(--suave); }
.tag.verde { background: #e2f5ea; color: var(--verde); } .tag.vermelho { background: #fde8e6; color: var(--vermelho); } .tag.azul { background: #e6f0fb; color: var(--cor); }
.lista li.nova b::after { content: ''; display: inline-block; width: 8px; height: 8px; background: var(--verde); border-radius: 50%; margin-left: 6px; vertical-align: middle; }
.lista-vazia { padding: 30px 16px; text-align: center; color: var(--suave); }

/* Chat */
.chat-col { flex: 1; min-width: 0; display: flex; }
.vazio { margin: auto; color: var(--suave); text-align: center; padding: 20px; }
.chat { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.chat-topo { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #fff; border-bottom: 1px solid var(--borda); flex-wrap: wrap; }
.btn-voltar { display: none; background: none; border: 0; font-size: 30px; line-height: 1; cursor: pointer; padding: 0 6px; }
.chat-titulo { flex: 1; min-width: 160px; display: flex; flex-direction: column; }
.chat-titulo small { color: var(--suave); display: flex; align-items: center; gap: 5px; }
.ponto { width: 8px; height: 8px; border-radius: 50%; background: #c3c9d1; display: inline-block; }
.ponto.on { background: var(--verde); }
.acoes { display: flex; gap: 6px; flex-wrap: wrap; }
.aviso-expirado { background: var(--amarelo); padding: 8px 14px; font-size: 13px; }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; background: #eef1f5; }
.msg { max-width: 70%; padding: 7px 10px 4px; border-radius: 12px; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.05); font-size: 14px; }
.msg.cliente { align-self: flex-start; background: #fff; border-bottom-left-radius: 3px; }
.msg.atendente { align-self: flex-end; background: #dcebfb; border-bottom-right-radius: 3px; }
.msg.sistema { align-self: center; background: var(--amarelo); font-size: 12.5px; max-width: 85%; text-align: center; box-shadow: none; }
.msg .quem { display: block; font-size: 11.5px; font-weight: 600; color: var(--cor); }
.msg .hora { display: block; text-align: right; font-size: 11px; color: var(--suave); }
.msg img { max-width: 260px; max-height: 260px; display: block; border-radius: 8px; cursor: zoom-in; }
.dia { align-self: center; font-size: 11.5px; color: var(--suave); background: #fff; padding: 2px 10px; border-radius: 10px; }
.digitando { font-size: 12px; color: var(--suave); padding: 4px 16px; background: #eef1f5; }
.compositor { display: flex; align-items: flex-end; gap: 6px; padding: 10px; background: #fff; border-top: 1px solid var(--borda); }
.compositor textarea { resize: none; max-height: 140px; }
.respostas { width: 48px; flex: none; padding: 8px 4px; cursor: pointer; }

/* Info */
.info-col { width: 300px; background: #fff; border-left: 1px solid var(--borda); overflow-y: auto; flex: none; }
.info-topo { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--borda); }
#info { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.campo small { display: block; color: var(--suave); font-size: 11.5px; }
.servico { border: 1px solid var(--borda); border-radius: 8px; padding: 8px; }

/* Tabelas */
.busca { display: flex; gap: 8px; margin-bottom: 14px; max-width: 560px; }
.tabela-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--borda); border-radius: 12px; }
.tabela { width: 100%; border-collapse: collapse; }
.tabela th, .tabela td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #f0f2f5; white-space: nowrap; }
.tabela th { font-size: 12px; color: var(--suave); font-weight: 600; background: #fafbfc; }
.grade { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.form-config { display: flex; flex-direction: column; gap: 14px; max-width: 620px; }
.form-config input[type=color] { width: 80px; height: 40px; padding: 2px; }
.logo-edit { display: flex; align-items: center; gap: 14px; }
.logo-edit img { width: 80px; height: 80px; object-fit: contain; border: 1px solid var(--borda); border-radius: 12px; padding: 4px; }

/* Modais */
.dlg { border: 0; border-radius: 14px; padding: 20px; width: min(460px, calc(100vw - 24px)); box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.dlg-largo { width: min(760px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(20,28,38,.45); }
.dlg form, .dlg #novoPronto { display: flex; flex-direction: column; gap: 12px; }
.dlg-acoes { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.dlg-cab { display: flex; justify-content: space-between; align-items: center; }
.linha { display: flex; gap: 8px; align-items: flex-end; }
.flex1 { flex: 1; }
.hub-resultado { border: 1px solid var(--borda); border-radius: 8px; max-height: 180px; overflow: auto; }
.hub-resultado button { display: block; width: 100%; text-align: left; background: #fff; border: 0; border-bottom: 1px solid #f0f2f5; padding: 8px 10px; cursor: pointer; }
.hub-resultado button:hover { background: #eaf2fc; }
.hub-resultado p { margin: 0; padding: 10px; color: var(--suave); }
.conv-info { color: var(--suave); font-size: 13px; margin: 6px 0 10px; }
.msgs-leitura { max-height: 55vh; border-radius: 10px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1c2430; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 100; max-width: calc(100vw - 32px); }
.visor { position: fixed; inset: 0; background: rgba(0,0,0,.9); display: grid; place-items: center; z-index: 90; cursor: zoom-out; }
.visor img { max-width: 95vw; max-height: 95vh; }

/* Painel no celular: lista e conversa em telas separadas */
@media (max-width: 900px) {
  .info-col { position: fixed; inset: 0 0 0 auto; width: min(340px, 100vw); z-index: 30; box-shadow: -10px 0 30px rgba(0,0,0,.15); }
}
@media (max-width: 760px) {
  .app { flex-direction: column-reverse; }
  .menu { width: 100%; flex-direction: row; justify-content: space-around; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .menu-logo { display: none; }
  .menu-fim { margin: 0; flex-direction: row; display: contents; }
  .menu-item { flex: 1; min-width: 0; width: auto; padding: 5px 2px; font-size: 18px; }
  .menu-item span { font-size: 9.5px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .badge { right: 18%; }
  .aba.ativa { min-height: 0; }
  .lista-col { width: 100%; border: 0; }
  .chat-col { display: none; }
  #aba-atendimentos.em-chat .lista-col { display: none; }
  #aba-atendimentos.em-chat .chat-col { display: flex; }
  .btn-voltar { display: block; }
  .acoes .btn { padding: 6px 8px; font-size: 12px; }
  .msg { max-width: 85%; }
  .compositor textarea { font-size: 16px; }
  .pagina { padding: 14px; }
}
