/* Console de conversas — tema WhatsApp Desktop (dark). */
:root {
  --bg-app:      #111b21;  /* painel da lista */
  --header-bg:   #202c33;  /* barras de cabeçalho */
  --chat-bg:     #0b141a;  /* fundo do chat */
  --search-bg:   #202c33;  /* caixa de busca */
  --hover:       #202c33;  /* hover de item */
  --active:      #2a3942;  /* item selecionado */
  --incoming:    #202c33;  /* balão recebido */
  --outgoing:    #005c4b;  /* balão enviado */
  --text:        #e9edef;  /* texto primário */
  --text-2:      #8696a0;  /* texto secundário */
  --text-3:      #667781;  /* texto terciário */
  --accent:      #00a884;  /* verde WhatsApp */
  --accent-2:    #25d366;  /* verde claro (badges) */
  --divider:     rgba(134,150,160,.15);
  --link:        #53bdeb;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--chat-bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--text); -webkit-font-smoothing: antialiased; }
body { display: flex; flex-direction: column; height: 100vh; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(134,150,160,.3); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---- Cabeçalho global ---- */
.app-header { background: var(--header-bg); color: var(--text); padding: 10px 18px; flex: 0 0 auto;
  border-bottom: 1px solid var(--divider); }
.app-header-inner { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; }
/* Cabeçalho no padrão Semantic UI (ui inverted header), ajustado ao dark theme. */
.app-title.ui.header { margin: 0 !important; font-size: 18px; color: var(--text) !important; }
.app-title .sub.header { font-size: 12px; color: var(--text-2) !important; font-weight: 400; margin-top: 3px; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.header-actions .ui.button { font-size: 13px; }
.stat { font-size: 12px; color: var(--text-2); }
/* ---- Top bar compartilhada (header.js): marca · navegação · cluster direito ---- */
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; flex: 0 0 auto; }
.brand-logo { height: 28px; width: auto; opacity: .92; flex: 0 0 auto; }
.login-logo { height: 26px; width: auto; opacity: .85; margin: 0 auto 16px; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { font-size: 15px; font-weight: 700; color: var(--text) !important; white-space: nowrap; letter-spacing: .2px; }
.brand-sub { font-size: 9.5px; font-weight: 500; color: var(--text-3); white-space: nowrap; text-transform: uppercase; letter-spacing: .6px; }
.topnav { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.topnav a { color: var(--text-2); text-decoration: none; font-size: 13px; padding: 5px 9px; border-radius: 7px; white-space: nowrap; }
.topnav a:hover { color: var(--text); background: rgba(255,255,255,.06); }
.topnav a.active { color: var(--text); background: rgba(37,211,102,.16); font-weight: 600; }
.tb-right { display: flex; align-items: center; gap: 8px 12px; margin-left: auto; flex-wrap: wrap; }
.tb-zone { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tb-user { display: flex; align-items: center; gap: 10px; padding-left: 12px; border-left: 1px solid var(--divider); }
.user-chip { font-size: 12px; color: var(--text-2); }
.app-header .ui.button { font-size: 12.5px; }
/* itens admin escondidos para o colaborador (header.js marca body.is-admin) */
body:not(.is-admin) .admin-only { display: none !important; }
/* itens só-colaborador escondidos para o admin (ex.: "Minha conexão" — admin não conecta
   número próprio, gerencia tudo em "Contas e usuários") */
body.is-admin .collab-only { display: none !important; }
/* RFC 0009: itens revelados conforme as capacidades do usuário (header.js marca o body
   a partir do /api/me): "Conversas" só p/ quem tem conta visível; "Grupos" p/ admin/dono. */
body:not(.can-see-conversations) .convs-only { display: none !important; }
body:not(.can-manage-groups) .groups-only { display: none !important; }

/* toggle on/off (interruptor) — on=verde, off=cinza. Usado nas colunas de
   configuração por conta (Zoho auto / push diário). */
.toggle { position: relative; display: inline-block; width: 42px; height: 22px; padding: 0;
  border: none; border-radius: 999px; cursor: pointer; vertical-align: middle;
  background: #3a4750; transition: background .15s ease; }
.toggle.on { background: var(--accent); }
.toggle[disabled] { opacity: .5; cursor: default; }
.toggle .knob { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: left .15s ease; box-shadow: 0 1px 2px rgba(0,0,0,.4); }
.toggle.on .knob { left: 22px; }
.toggle:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* tooltip "balão" estilizado: elemento com .hint-tip[data-tip] mostra o texto ao passar o
   mouse (substitui o title nativo, lento e sem estilo). Em <span> ganha sublinhado pontilhado
   de "ajuda"; em <button> mantém o visual do botão. .tip-right ancora o balão à direita
   (colunas no fim da tabela, p/ não estourar a borda). */
.hint-tip { position: relative; }
span.hint-tip { cursor: help; border-bottom: 1px dotted var(--text-3); }
.hint-tip::after, .hint-tip::before { position: absolute; opacity: 0; pointer-events: none;
  transition: opacity .12s ease; z-index: 50; }
.hint-tip::after { content: attr(data-tip); left: 0; bottom: calc(100% + 8px); width: max-content; max-width: 280px;
  white-space: normal; text-align: left; background: #0b141a; color: var(--text); border: 1px solid var(--divider);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; font-weight: 400; line-height: 1.45;
  box-shadow: 0 6px 20px rgba(0,0,0,.45); }
.hint-tip::before { content: ""; left: 14px; bottom: calc(100% + 2px); border: 6px solid transparent;
  border-top-color: #0b141a; }
.hint-tip.tip-right::after { left: auto; right: 0; }
.hint-tip.tip-right::before { left: auto; right: 14px; }
.hint-tip:hover::after, .hint-tip:hover::before, .hint-tip:focus::after, .hint-tip:focus::before { opacity: 1; }
.svc-status { font-size: 12px; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; cursor: default; white-space: nowrap; }
.svc-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 8px; }
.svc-dot.on { background: var(--accent-2); box-shadow: 0 0 6px rgba(37,211,102,.7); }
.svc-dot.off { background: #f15c6d; }
/* no ar, mas nem toda conta vinculada está conectada (religando) */
.svc-dot.warn { background: #e8b53a; box-shadow: 0 0 6px rgba(232,181,58,.7); }
/* chip de associação Zoho na lista/thread (Contato = verde; Lead = âmbar) */
.zoho-link { display: inline-block; padding: 0 6px; border-radius: 9px; font-size: 11px;
  line-height: 16px; font-weight: 600; text-decoration: none; }
.zoho-link.contact { background: rgba(0,168,132,.18); color: var(--accent-2); }
.zoho-link.lead { background: rgba(232,181,58,.18); color: #e8b53a; }
.zoho-link:hover { filter: brightness(1.2); }
.btn { background: var(--accent); color: #0b141a; border: none; border-radius: 18px;
  padding: 7px 16px; font-size: 13px; font-weight: 600; cursor: pointer; transition: background .15s; }
.btn:hover { background: #06cf9c; }
.btn:disabled { opacity: .55; cursor: default; }
.navlink { color: var(--text-2); text-decoration: none; font-size: 13px; }
.navlink:hover { color: var(--accent); }

.app-main { flex: 1 1 auto; display: flex; min-height: 0; }

/* ---- Lista de conversas ---- */
.conv-list { flex: 0 0 380px; border-right: 1px solid var(--divider); background: var(--bg-app);
  display: flex; flex-direction: column; min-height: 0; }
.search-wrap { padding: 8px 12px; flex: 0 0 auto; background: var(--bg-app); }
.search { width: 100%; padding: 8px 12px 8px 38px; border: none; border-radius: 8px;
  font-size: 14px; background: var(--search-bg) no-repeat 12px center; color: var(--text);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238696a0' stroke-width='2' stroke-linecap='round'><circle cx='11' cy='11' r='7'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>"); }
.search::placeholder { color: var(--text-3); }
.search:focus { outline: none; }
#conv-items { overflow-y: auto; flex: 1 1 auto; }
.conv-row { display: flex; gap: 13px; padding: 10px 14px; cursor: pointer; align-items: center;
  border-bottom: 1px solid var(--divider); transition: background .12s; }
.conv-row:hover { background: var(--hover); }
.conv-row.active { background: var(--active); }
.avatar { flex: 0 0 49px; width: 49px; height: 49px; border-radius: 50%; background: #6a7175;
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 500; font-size: 17px; }
.avatar.lead { background: #5e84c2; }
.conv-meta { flex: 1 1 auto; min-width: 0; }
.conv-name { font-size: 15px; font-weight: 400; color: var(--text); display: flex;
  justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-name > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-name .time { font-size: 12px; color: var(--text-2); font-weight: 400; white-space: nowrap; }
.conv-sub { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.conv-preview { font-size: 13.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.tag { display: inline-block; font-size: 10px; padding: 1px 7px; border-radius: 999px;
  margin-left: 6px; vertical-align: middle; font-weight: 500; }
.tag.lead { background: rgba(94,132,194,.22); color: #9bb8e8; }
.tag.contact { background: rgba(0,168,132,.22); color: #5fd6b6; }

/* ---- Thread ---- */
.conv-view { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); }
.placeholder, .empty { color: var(--text-2); text-align: center; padding: 40px; margin: auto; font-size: 14px; }
.thread { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.thread-head { flex: 0 0 auto; background: var(--header-bg); border-bottom: 1px solid var(--divider);
  padding: 9px 18px; display: flex; align-items: center; gap: 13px; }
.thread-head .avatar { flex: 0 0 40px; width: 40px; height: 40px; font-size: 15px; }
.thread-head .name { font-weight: 500; font-size: 16px; color: var(--text); }
.thread-head .meta { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.thread-head a { color: var(--link); text-decoration: none; font-size: 12px; }
.thread-head a:hover { text-decoration: underline; }

.messages { flex: 1 1 auto; overflow-y: auto; padding: 16px 7%; background: var(--chat-bg);
  display: flex; flex-direction: column; }
/* RFC 0009 F-b: caixa de resposta assinada (só aparece p/ quem pode interagir) */
.composer { flex: 0 0 auto; display: flex; gap: 8px; align-items: flex-end; padding: 10px 7%;
  background: var(--header-bg); border-top: 1px solid var(--divider); }
.composer textarea { flex: 1 1 auto; resize: none; max-height: 140px; padding: 9px 12px; border: none;
  border-radius: 8px; background: var(--search-bg); color: var(--text); font-size: 14px; line-height: 1.35;
  font-family: inherit; }
.composer textarea:focus { outline: 1px solid var(--link); }
.composer-attach { flex: 0 0 auto; background: transparent; border: none; cursor: pointer; font-size: 20px;
  line-height: 1; padding: 6px 8px; border-radius: 8px; color: var(--text-2); }
.composer-attach:hover { background: rgba(255,255,255,.06); color: var(--text); }
.composer-attach.busy { opacity: .5; pointer-events: none; }
/* reações (emoji) ancoradas no rodapé do balão */
.msg-reactions { position: absolute; bottom: -10px; left: 8px; display: flex; gap: 2px;
  background: var(--header-bg); border: 1px solid var(--divider); border-radius: 10px; padding: 1px 5px;
  font-size: 12.5px; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.msg.out .msg-reactions { left: auto; right: 8px; }
.msg { margin-bottom: 8px; }
.msg { max-width: 65%; margin: 4px 0; padding: 6px 9px 8px; border-radius: 7.5px; font-size: 14.2px;
  line-height: 1.35; box-shadow: 0 1px .5px rgba(11,20,26,.13); word-wrap: break-word; white-space: pre-wrap;
  color: var(--text); position: relative; }
.msg.in  { background: var(--incoming); align-self: flex-start; border-top-left-radius: 0; }
.msg.out { background: var(--outgoing); align-self: flex-end; border-top-right-radius: 0; }
.msg .when { display: block; font-size: 11px; color: var(--text-2); margin-top: 2px; text-align: right; }
.msg.out .when { color: rgba(233,237,239,.6); }
.msg .author { display: block; font-size: 12.5px; color: var(--accent-2); font-weight: 600; margin-bottom: 2px; }
.msg .att { font-size: 12.5px; color: var(--link); }

/* ---- Página Execuções (dark) ---- */
.runs-main { flex: 1 1 auto; overflow: auto; padding: 16px 24px; background: var(--chat-bg); }
.runs-table, .trace-table { width: 100%; border-collapse: collapse; background: var(--bg-app);
  font-size: 13px; color: var(--text); border-radius: 8px; overflow: hidden; }
.runs-table th, .runs-table td, .trace-table th, .trace-table td { padding: 8px 11px;
  border-bottom: 1px solid var(--divider); text-align: left; }
.runs-table th, .trace-table th { background: var(--header-bg); color: var(--text-2); font-weight: 600;
  font-size: 12px; position: sticky; top: 0; }
.run-row { cursor: pointer; }
.run-row:hover { background: var(--hover); }
.dim { color: var(--text-3); font-size: 12px; }
.ok  { color: var(--accent-2); font-weight: 600; }
.err { color: #f15c6d; font-weight: 600; }
.tag.internal { background: rgba(255,196,0,.16); color: #e0b34d; }
.tag.official { background: rgba(94,132,194,.22); color: #9bb8e8; }
.path { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--text-2); word-break: break-all; }

.trace-modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 16px; z-index: 1000; }
.trace-modal[hidden] { display: none; }
.trace-card { background: var(--bg-app); border-radius: 10px; width: min(1000px, 96vw); max-height: 86vh;
  display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,.5); border: 1px solid var(--divider); }
.trace-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px;
  border-bottom: 1px solid var(--divider); }
.trace-content { overflow: auto; padding: 8px 16px 16px; }

/* ---- Página Análise LLM ---- */
.llm-main { flex: 1 1 auto; overflow: auto; padding: 16px 24px 40px; background: var(--chat-bg);
  display: flex; flex-direction: column; gap: 16px; max-width: 1100px; width: 100%; margin: 0 auto; }
.panel { background: var(--bg-app); border: 1px solid var(--divider); border-radius: 10px; padding: 14px 18px 18px; }
.panel h2 { font-size: 15px; font-weight: 600; color: var(--text); margin: 0 0 12px; }
.panel-hint { font-size: 11.5px; color: var(--text-3); font-weight: 400; margin-left: 6px; }
.form-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.form-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-field.wide { grid-column: 1 / -1; }
.form-field label, .form-row > label { font-size: 12px; color: var(--text-2); font-weight: 600; }
.llm-main input, .llm-main select, .llm-main textarea {
  background: var(--search-bg); border: 1px solid var(--divider); border-radius: 6px;
  color: var(--text); font-size: 13px; padding: 7px 10px; font-family: inherit; }
.llm-main input:focus, .llm-main select:focus, .llm-main textarea:focus { outline: none; border-color: var(--accent); }
.llm-main textarea { resize: vertical; }
.key-status { font-size: 12px; }
.mini-btn { background: transparent; border: 1px solid var(--divider); color: var(--text-2);
  border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.mini-btn:hover { color: var(--text); border-color: var(--accent); }
.mini-btn.danger:hover { color: #f15c6d; border-color: #f15c6d; }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; color: var(--text);
  line-height: 1.45; cursor: pointer; }
.check input { margin-top: 3px; }
.indent { margin: 8px 0 0 26px; display: flex; flex-direction: column; gap: 6px; }
.action-block { padding: 10px 0; border-top: 1px solid var(--divider); }
.action-block:first-of-type { border-top: none; }
.inst-card { border: 1px solid var(--divider); border-radius: 8px; padding: 10px; margin-bottom: 10px;
  display: flex; flex-direction: column; gap: 8px; }
.inst-card.off { opacity: .5; }
.inst-head { display: flex; align-items: center; gap: 8px; }
.inst-title { flex: 1 1 auto; font-weight: 600; }
.fm-row { display: flex; align-items: center; gap: 8px; }
.fm-row input { flex: 1 1 auto; }
.fm-arrow { color: var(--text-3); }
.ana-resumo { max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.runs-table a { color: var(--link); text-decoration: none; }

/* ---- Painel de análise na conversa ---- */
.analysis-panel { flex: 0 0 auto; background: var(--bg-app); border-bottom: 1px solid var(--divider);
  padding: 10px 18px; font-size: 13px; max-height: 38vh; overflow-y: auto; }
.analysis-panel .ana-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.analysis-panel .ana-meta { font-size: 11.5px; color: var(--text-3); margin-left: auto; }
.analysis-panel .badge { display: inline-block; font-size: 11px; padding: 2px 9px; border-radius: 999px; font-weight: 600; }
.badge.cls { background: rgba(0,168,132,.2); color: #5fd6b6; }
.badge.sent-positivo { background: rgba(37,211,102,.18); color: var(--accent-2); }
.badge.sent-neutro { background: rgba(134,150,160,.2); color: var(--text-2); }
.badge.sent-negativo { background: rgba(241,92,109,.18); color: #f15c6d; }
.badge.score { background: rgba(94,132,194,.22); color: #9bb8e8; }
.analysis-panel .ana-alert { color: #e0b34d; font-size: 12.5px; }
.analysis-panel .ana-action { color: var(--text-2); font-size: 12.5px; margin-top: 4px; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--header-bg); color: var(--text); padding: 10px 16px; border-radius: 8px; font-size: 13px;
  opacity: 0; transition: opacity .2s; pointer-events: none; box-shadow: 0 4px 16px rgba(0,0,0,.4); }
.toast.show { opacity: .97; }

/* ---- adições do wpp-business-pusher ---- */
.account-select { background: var(--search-bg); color: var(--text); border: none;
  border-radius: 8px; padding: 6px 10px; font-size: 13px; max-width: 200px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--header-bg); color: var(--text); padding: 10px 20px; border-radius: 10px;
  border: 1px solid var(--divider); font-size: 13px; opacity: 0; transition: all .25s; z-index: 99; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ---- mídias nas mensagens (F11) ---- */
.msg-media { max-width: 320px; max-height: 320px; border-radius: 8px; display: block; margin: 2px 0 4px; }
.msg-media-audio { width: 280px; margin: 2px 0 4px; display: block; }

/* ---- anexos / mídia no chat ---- */
.att-bar { margin: 2px 0 4px; }
.att-dl { font-size: 11.5px; color: var(--link); text-decoration: none; }
.att-dl:hover { color: var(--accent); }
.att-missing { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2);
  background: var(--search-bg); border-radius: 8px; padding: 4px 10px; font-size: 13px; }
.att-doc { display: inline-flex; align-items: center; gap: 6px; color: var(--text);
  background: var(--search-bg); border-radius: 8px; padding: 5px 10px; text-decoration: none; }
.att-doc:hover { background: var(--hover); }
.att-tag { font-size: 10px; padding: 1px 6px; border-radius: 999px; background: rgba(134,150,160,.2); color: var(--text-2); }
.att-doc .att-tag { background: rgba(0,168,132,.22); color: var(--accent-2); }
