/* 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; }
/* O atributo hidden perde pra qualquer display explícito (ex.: .login-card form
   { display:flex }, .ui.button do Semantic) — esta regra garante que hidden SEMPRE esconde. */
[hidden] { display: none !important; }
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; justify-content: space-between; gap: 16px; }
/* 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; flex-wrap: wrap; justify-content: flex-end; }
.header-actions .ui.button { font-size: 13px; }
.stat { font-size: 12px; color: var(--text-2); }
.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; }
.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; }

/* ---- Filtro por direção da última mensagem ---- */
.filter-bar { display: flex; gap: 6px; padding: 0 12px 8px; background: var(--bg-app); flex: 0 0 auto; }
.chip { background: var(--search-bg); border: 1px solid var(--divider); color: var(--text-2);
  border-radius: 999px; padding: 4px 12px; font-size: 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: all .12s; }
.chip:hover { color: var(--text); border-color: var(--text-3); }
.chip.active { background: var(--active); color: var(--text); border-color: var(--accent); }
.chip .count { color: var(--text-3); font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 8px; }
.dot.in { background: #e0b34d; }
.dot.out { background: var(--accent-2); }

.conv-row { display: flex; gap: 13px; padding: 10px 14px 10px 11px; cursor: pointer; align-items: center;
  border-bottom: 1px solid var(--divider); transition: background .12s;
  border-left: 3px solid transparent; }
/* cor pela direção da ÚLTIMA mensagem: âmbar = cliente falou por último (aguardando o time);
   verde = nosso time respondeu por último */
.conv-row.dir-in { border-left-color: #e0b34d; }
.conv-row.dir-out { border-left-color: var(--accent-2); }
.conv-row.dir-in .time { color: #e0b34d; }
.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; }
.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; }

/* ---- Acesso à console (allowlist de roles do CRM) ---- */
.access-role { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13px;
  color: var(--text); cursor: pointer; border-bottom: 1px solid var(--divider); }
.access-role:last-child { border-bottom: none; }
.access-role input { accent-color: var(--accent); width: 15px; height: 15px; }
.access-role input:disabled { opacity: .55; }

/* ---- Teste de conexão (passos em tempo real) ---- */
.test-step { font-size: 13px; color: var(--text-2); padding: 3px 0; }
.test-step strong { color: var(--text); font-weight: 600; }
.test-hint { font-size: 13px; color: #e0b34d; margin-top: 6px; line-height: 1.5; }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--divider);
  border-top-color: var(--accent); border-radius: 50%; vertical-align: -2px;
  animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.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,
.login-card input, .login-card select {
  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,
.login-card input: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; }
.inline-num { width: 58px; padding: 3px 7px !important; margin: 0 2px; }
.panel-text { font-size: 13px; color: var(--text-2); line-height: 1.6; margin: 0; }
.panel-text strong { color: var(--text); }

/* ---- Manual ---- */
.manual .panel-text { margin-bottom: 8px; }
.manual code { background: var(--search-bg); border-radius: 4px; padding: 1px 6px; font-size: 12px; }
.manual a { color: var(--link); text-decoration: none; }
.manual a:hover { text-decoration: underline; }
.toc { margin: 0; padding-left: 18px; line-height: 1.9; font-size: 13.5px; }
.manual-list { margin: 0; padding-left: 18px; font-size: 13px; color: var(--text-2); line-height: 1.7; }
.manual-list li { margin-bottom: 4px; }
.manual-list strong { color: var(--text); }
.manual-list .dot { margin-right: 4px; }
.manual-table { margin-top: 4px; }
.manual-table td { color: var(--text-2); font-size: 12.5px; }
.manual-table td:first-child { color: var(--text); }
.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; }

/* ---- Autenticação / permissões da console ---- */
/* Controles administrativos ficam ocultos até /api/me confirmar role=admin (app.js). */
body:not(.is-admin) .admin-only { display: none !important; }
.user-chip { font-size: 12px; color: var(--text-2); background: var(--bg-app);
  border: 1px solid var(--divider); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { width: 360px; padding: 26px 28px 28px; display: flex; flex-direction: column; gap: 12px; }
.login-title { font-size: 18px; color: var(--text); margin: 0 0 6px; text-align: center; }
.login-title span { display: block; font-size: 12px; color: var(--text-3); font-weight: 400; margin-top: 4px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-error { color: #f15c6d; font-size: 12.5px; }
.login-sep { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 12px; }
.login-sep::before, .login-sep::after { content: ""; flex: 1; border-top: 1px solid var(--divider); }

/* ---- Compositor de resposta (janela de 24h da Meta) ---- */
.reply-bar { flex: 0 0 auto; border-top: 1px solid var(--divider); background: var(--bg-app); padding: 10px 14px; }
.reply-box { display: flex; align-items: flex-end; gap: 8px; }
.reply-box textarea { flex: 1; resize: none; border: 1px solid var(--divider); border-radius: 18px;
  background: var(--bg-app); color: var(--text); padding: 9px 14px; font: inherit; font-size: 14px;
  line-height: 1.4; max-height: 140px; overflow-y: auto; }
.reply-box textarea:focus { outline: none; border-color: var(--accent); }
.reply-box .button { flex: 0 0 auto; }
.reply-hint { font-size: 11.5px; color: var(--text-3); margin: 6px 2px 0; }
.reply-closed { flex: 0 0 auto; border-top: 1px solid var(--divider); background: var(--bg-app);
  color: var(--text-3); font-size: 13px; padding: 14px; text-align: center; }
.msg.out.pending { opacity: .72; }
.msg.out.pending .when { font-style: italic; }

/* ---- Painel do serviço de poll (admin) ---- */
.svc-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.svc-card { background: var(--bg-app); border: 1px solid var(--divider); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.svc-card-label { font-size: 11.5px; color: var(--text-3); margin-bottom: 4px; }
.svc-card-value { font-size: 14px; color: var(--text); font-weight: 600; word-break: break-word; }
.svc-alert { margin-top: 12px; background: rgba(241,92,109,.12); border: 1px solid rgba(241,92,109,.4);
  color: #f3a3ac; border-radius: 8px; padding: 9px 12px; font-size: 13px; }
.svc-note { margin-top: 10px; background: rgba(94,132,194,.14); border: 1px solid rgba(94,132,194,.4);
  color: #9bb8e8; border-radius: 8px; padding: 9px 12px; font-size: 13px; }
.svc-log { background: #0b141a; color: #c8d2d8; border: 1px solid var(--divider); border-radius: 8px;
  padding: 12px 14px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  line-height: 1.55; white-space: pre-wrap; word-break: break-word; max-height: 46vh; overflow-y: auto; margin: 0; }
.muted { color: var(--text-3); }
a.svc-status { text-decoration: none; }
a.svc-status:hover { color: var(--accent); }
