/* ATENA · Chat interno. Duas colunas na altura da tela (conversas | conversa aberta);
 * até 720px, uma coluna só: a lista e a conversa se alternam (botão de voltar).
 * Componentes do kit (at-btn, at-input, at-textarea, at-menu, at-chip, at-badge,
 * at-avatar, at-empty, at-skeleton); aqui só a arrumação e as peças do chat. Só tokens.
 * .conversa, .msg, .msg-texto e .mencao são ganchos dos testes: o estilo usa chat-*. */

/* ---------- altura: a tela inteira, menos a margem do conteúdo ---------- */
.tela-chat { height: calc(100vh - 2 * var(--space-8)); height: calc(100dvh - 2 * var(--space-8)); min-height: 520px; }
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat > .at-page-header { flex: none; margin-bottom: var(--space-5); }
.chat-painel { flex: 1; min-height: 0; padding: 0; display: grid; grid-template-columns: 300px minmax(0, 1fr); }

/* ---------- coluna das conversas ---------- */
.chat-lateral {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--surface-sunken); border-right: 1px solid var(--line);
  border-radius: calc(var(--radius-lg) - 1px) 0 0 calc(var(--radius-lg) - 1px);
}
.chat-busca { position: relative; flex: none; padding: var(--space-3); border-bottom: 1px solid var(--line); }
.chat-resultados { position: absolute; left: var(--space-3); top: calc(100% - var(--space-2)); width: min(440px, calc(100vw - 2 * var(--space-8))); max-height: 60vh; overflow-y: auto; }
.chat-resultado {
  display: flex; flex-direction: column; gap: 2px; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm);
  color: var(--ink); font-weight: 500; transition: background-color var(--duration-fast) var(--ease-standard);
}
.chat-resultado:hover, .chat-resultado:focus-visible { background: var(--brand-soft-hover); color: var(--ink); text-decoration: none; }
.chat-resultado__meta { font-size: 12px; line-height: 16px; font-weight: 600; color: var(--ink-muted); }
.chat-resultado__texto { font-size: 14px; line-height: 20px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.chat-resultados__vazio { padding: var(--space-3); font-size: 13px; line-height: 18px; color: var(--ink-muted); }

.chat-lista { flex: 1; min-height: 0; overflow-y: auto; padding: var(--space-1) var(--space-2) var(--space-4); }
.chat-lista__secao { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-3) 0 var(--space-1) var(--space-3); color: var(--ink-muted); text-transform: uppercase; }
.chat-lista__vazio { padding: var(--space-1) var(--space-3) var(--space-2); font-size: 13px; line-height: 18px; color: var(--ink-muted); }

.chat-item {
  display: flex; align-items: center; gap: var(--space-3); min-height: 52px; padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md); color: var(--ink-secondary); font-weight: 600; text-decoration: none;
  transition: background-color var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}
.chat-item:hover { background: var(--brand-soft-hover); color: var(--ink); text-decoration: none; }
.chat-item.is-unread { color: var(--ink); }
.chat-item.is-unread .chat-item__nome { font-weight: 800; }
.chat-item.is-active { background: var(--brand-soft); color: var(--brand-text); }
.chat-item__texto { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-item__nome { font-size: 14px; line-height: 20px; }
.chat-item__previa { font-size: 12px; line-height: 16px; font-weight: 500; color: var(--ink-muted); }
.chat-item.is-active .chat-item__previa { color: var(--ink-secondary); }

/* marca do canal (#) no lugar do avatar */
.chat-canal-marca {
  width: 32px; height: 32px; flex: none; display: inline-grid; place-items: center;
  border-radius: var(--radius-md); background: var(--surface-raised); border: 1px solid var(--line); color: var(--ink-muted);
}
.chat-item.is-active .chat-canal-marca { color: var(--brand-text); border-color: var(--brand-300); }

.chat-esqueleto__item { display: flex; align-items: center; gap: var(--space-3); min-height: 52px; padding: var(--space-2) var(--space-3); }
.chat-esqueleto__msg { display: flex; align-items: flex-start; gap: var(--space-3); margin-top: var(--space-2); padding: var(--space-1) var(--space-3); }
.chat-esqueleto__item > .at-skeleton, .chat-esqueleto__msg > .at-skeleton, .chat-topo > .at-skeleton { flex: none; }

/* ---------- conversa aberta ---------- */
.chat-principal { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-principal > .at-empty { margin: auto; }
.chat-topo { flex: none; display: flex; align-items: center; gap: var(--space-3); min-height: 64px; padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--line); }
.chat-topo__titulo { font-size: 16px; line-height: 24px; font-weight: 700; letter-spacing: -0.005em; color: var(--ink); }
.chat-topo__sub { font-size: 13px; line-height: 18px; color: var(--ink-muted); }
.chat-topo__sub:empty { display: none; }
.chat-voltar { display: none; }
.chat-topo--so-voltar { display: none; } /* erro ao abrir: no computador a lista já está ao lado */

.chat-mensagens { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--space-5) var(--space-3) var(--space-3); }
.chat-mensagens > .at-empty { min-height: 100%; }
.chat-mais { display: flex; justify-content: center; padding-bottom: var(--space-3); }

.chat-dia { display: flex; align-items: center; gap: var(--space-3); margin: var(--space-5) 0 var(--space-2); color: var(--ink-muted); }
.chat-dia:first-child, .chat-mais + .chat-dia { margin-top: 0; }
.chat-dia::before, .chat-dia::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.chat-dia span { padding: 2px var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--surface-raised); font-size: 12px; line-height: 16px; font-weight: 700; }

/* daqui para baixo, o que chegou depois da última leitura */
.chat-novas { display: flex; align-items: center; gap: var(--space-2); margin: var(--space-3) 0 var(--space-1); color: var(--brand-text); }
.chat-novas::before { content: ""; flex: 1; height: 1px; background: var(--brand); }
.chat-novas span { font-size: 11px; line-height: 16px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }

/* ---------- mensagem ---------- */
.chat-msg {
  position: relative; display: grid; grid-template-columns: 32px minmax(0, 1fr); column-gap: var(--space-3);
  margin-top: var(--space-2); padding: var(--space-1) var(--space-3); border-radius: var(--radius-md);
  transition: background-color var(--duration-fast) var(--ease-standard);
}
.chat-msg--junta { margin-top: 0; padding-top: 2px; padding-bottom: 2px; }
.chat-msg:hover, .chat-msg:focus-within { background: var(--brand-soft-hover); }
.chat-msg.is-highlighted { animation: at-highlight 1.6s var(--ease-out) both; }
.chat-msg__lado { display: flex; justify-content: center; padding-top: 2px; }
.chat-msg__marca { display: block; width: 32px; height: 32px; }
.chat-msg__hora-lado { visibility: hidden; font-size: 11px; line-height: 22px; font-weight: 600; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.chat-msg:hover .chat-msg__hora-lado, .chat-msg:focus-within .chat-msg__hora-lado, .chat-msg.is-open .chat-msg__hora-lado { visibility: visible; }
.chat-msg__corpo { min-width: 0; }
.chat-msg__topo { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); min-height: 20px; }
.chat-msg__autor { font-size: 14px; line-height: 20px; font-weight: 700; color: var(--ink); }
.chat-msg--minha .chat-msg__autor { color: var(--brand-text); }
.chat-msg__hora { font-size: 12px; line-height: 16px; font-weight: 600; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.chat-msg__texto { font-size: 14px; line-height: 22px; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-msg__editada { font-size: 12px; font-weight: 500; color: var(--ink-muted); }
.chat-msg--apagada .chat-msg__texto { color: var(--ink-muted); }

/* menção: o nome acende na cor da marca (texto brand-text sobre brand-soft) */
.chat-mencao { padding: 0 3px; border-radius: var(--radius-xs); background: var(--brand-soft); color: var(--brand-text); font-weight: 700; }

/* mensagem automática do sistema (lead novo, matrícula): tile da ATENA e o aviso em gold-soft */
.chat-msg__aviso {
  display: inline-block; max-width: 100%; margin-top: 2px; padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md); background: var(--gold-soft); color: var(--ink);
  font-size: 14px; line-height: 22px; white-space: pre-wrap; overflow-wrap: anywhere;
}

/* trecho da mensagem respondida (clique leva até ela) */
.chat-msg__citacao {
  display: block; width: 100%; max-width: 560px; margin: 2px 0 var(--space-1); padding: var(--space-1) var(--space-3);
  border: 0; border-left: 3px solid var(--brand); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-sunken); color: var(--ink-secondary); font-size: 13px; line-height: 18px; text-align: left;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  transition: background-color var(--duration-fast) var(--ease-standard);
}
.chat-msg__citacao:hover { background: var(--brand-soft); }
.chat-msg__citacao strong { margin-right: var(--space-1); color: var(--ink); font-weight: 700; }

.chat-reacoes { display: flex; flex-wrap: wrap; gap: var(--space-1); margin-top: var(--space-1); }
.chat-reacao { height: 26px; padding: 0 var(--space-2); gap: var(--space-1); font-size: 13px; }

/* barra de ações no hover */
.chat-msg__acoes {
  position: absolute; top: calc(-1 * var(--space-4)); right: var(--space-3); z-index: 2;
  display: none; gap: 2px; padding: 2px;
  background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
}
.chat-msg:hover .chat-msg__acoes, .chat-msg:focus-within .chat-msg__acoes, .chat-msg:has(.chat-flutuante) .chat-msg__acoes {
  display: flex; animation: at-fade var(--duration-fast) var(--ease-standard) both;
}

/* menus da mensagem (reagir, mais ações): .at-menu preso à mensagem */
.chat-flutuante { position: absolute; right: var(--space-3); top: var(--space-5); transform-origin: top right; }
.chat-flutuante--cima { top: auto; bottom: calc(100% + var(--space-5)); transform-origin: bottom right; }
.chat-emojis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-1); }
.chat-emojis__item {
  height: var(--control-height); border: 0; border-radius: var(--radius-sm); background: transparent; font-size: 20px; line-height: 1;
  transition: background-color var(--duration-fast) var(--ease-standard), transform var(--duration-fast) var(--ease-spring);
}
.chat-emojis__item:hover, .chat-emojis__item:focus-visible { background: var(--brand-soft-hover); transform: scale(1.12); }

/* ---------- escrever ---------- */
.chat-escrever { position: relative; flex: none; padding: var(--space-3) var(--space-5) var(--space-3); border-top: 1px solid var(--line); }
.chat-escrever__linha { display: flex; align-items: flex-end; gap: var(--space-2); }
.chat-campo { flex: 1; min-height: var(--control-height); height: var(--control-height); max-height: 180px; padding: var(--space-2) var(--space-3); line-height: 22px; resize: none; }
.chat-escrever__dica { margin-top: var(--space-1); font-size: 12px; line-height: 16px; color: var(--ink-muted); }
.chat-escrever--leitura { display: flex; align-items: center; justify-content: center; gap: var(--space-2); padding-block: var(--space-4); font-size: 13px; line-height: 18px; color: var(--ink-muted); }
.chat-respondendo {
  display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); padding: 2px 2px 2px var(--space-3);
  border-left: 3px solid var(--brand); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-sunken); color: var(--ink-secondary); font-size: 13px; line-height: 18px;
}
.chat-respondendo > .at-icon { color: var(--brand-text); }
.chat-respondendo strong { color: var(--ink); }
/* sugestões de @menção: .at-menu acima do campo */
.chat-sugestoes { position: absolute; left: var(--space-5); bottom: calc(100% - var(--space-2)); width: min(320px, calc(100% - 2 * var(--space-5))); transform-origin: bottom left; }

/* ---------- pessoas (modais: nova conversa, membros, criar e gerenciar canal) ---------- */
.chat-pessoas { display: flex; flex-direction: column; gap: 2px; max-height: 50vh; overflow-y: auto; margin: 0 calc(-1 * var(--space-2)); padding: 2px var(--space-2); }
.chat-pessoa {
  display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: 52px; padding: var(--space-2);
  border: 0; border-radius: var(--radius-md); background: transparent; color: var(--ink); text-align: left;
  transition: background-color var(--duration-fast) var(--ease-standard);
}
button.chat-pessoa:hover, label.chat-pessoa:hover { background: var(--brand-soft-hover); }
.chat-pessoa .at-person__name, .chat-pessoa .at-person__meta { display: block; }

/* ---------- telas médias: coluna das conversas mais estreita ---------- */
@media (max-width: 1100px) {
  .chat-painel { grid-template-columns: 260px minmax(0, 1fr); }
}

/* ---------- celular: uma coluna, lista ⇄ conversa ---------- */
@media (max-width: 720px) {
  main[data-tela="chat"] { padding: 0; }
  .tela-chat { height: 100vh; height: 100dvh; min-height: 0; }
  .chat > .at-page-header { padding: var(--space-4) var(--space-4) 0; margin-bottom: var(--space-4); }
  .chat-painel { grid-template-columns: minmax(0, 1fr); border: 0; border-radius: 0; box-shadow: none; }
  .chat-lateral { border-right: 0; border-radius: 0; }
  .chat-principal { display: none; }
  .chat--com-conversa > .at-page-header, .chat--com-conversa .chat-lateral { display: none; }
  .chat--com-conversa .chat-principal { display: flex; }
  .chat-voltar { display: inline-flex; }
  .chat-topo--so-voltar { display: flex; }
  .chat-topo { gap: var(--space-2); min-height: 56px; padding: var(--space-2) var(--space-3); }
  .chat-mensagens { padding: var(--space-4) var(--space-1) var(--space-2); }
  .chat-msg { padding-inline: var(--space-2); column-gap: var(--space-2); }
  .chat-escrever { padding: var(--space-2) var(--space-3) var(--space-3); }
  .chat-escrever__dica { display: none; }
  .chat-sugestoes { left: var(--space-3); width: calc(100% - 2 * var(--space-3)); }
  .chat-resultados { right: var(--space-3); width: auto; }
  /* sem hover no toque: tocar na mensagem abre a barra de ações embaixo dela */
  .chat-msg:not(.is-open) .chat-msg__acoes { display: none; }
  .chat-msg.is-open { background: var(--brand-soft-hover); }
  .chat-msg.is-open .chat-msg__acoes {
    position: static; grid-column: 2; justify-content: flex-end; margin-top: var(--space-1);
    padding: 0; border: 0; background: transparent; box-shadow: none;
  }
  .chat-flutuante { top: calc(100% + var(--space-1)); right: var(--space-2); }
  .chat-flutuante--cima { top: auto; bottom: calc(100% + var(--space-1)); }
}
