/* ============================================
   CHATBOT.CSS — Ticket Flow
   Interface de chat de tickets (estilo WhatsApp).
   Usa exclusivamente os tokens --rb-* definidos em
   tokens.css (ver DESIGN_SYSTEM.md). Painéis sólidos,
   sem glassmorphism / backdrop-filter / gradientes de
   marca — só --rb-primary sólido.
   ============================================ */

/* ============================================
   CONTAINER PRINCIPAL
   ============================================ */

.whatsapp-container {
  display: flex;
  height: calc(100vh - 180px);
  min-height: 500px;
  max-height: calc(100vh - 180px);

  background: var(--rb-bg);
  border-radius: 16px;
  overflow: hidden;

  border: 1px solid var(--rb-border);
  box-shadow: var(--rb-shadow-lg);
}

/* ============================================
   SIDEBAR — LISTA DE CONVERSAS
   ============================================ */

.whatsapp-sidebar {
  position: relative; /* âncora do botão .lista-topo; no celular a regra abaixo troca por fixed */
  width: 400px;
  background: var(--rb-surface-2);
  display: flex;
  flex-direction: column;

  border-right: 1px solid var(--rb-border);
}

/* Botão "voltar ao topo da lista", flutuando no canto de baixo da barra lateral */
.lista-topo {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 5;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 999px;
  border: 1px solid var(--rb-border-strong);
  background: var(--rb-surface);
  color: var(--rb-text);
  box-shadow: var(--rb-shadow-lg);
  cursor: pointer;
  transition: background var(--rb-dur) var(--rb-ease), color var(--rb-dur) var(--rb-ease);
}
.lista-topo:hover,
.lista-topo:focus-visible {
  background: var(--rb-primary);
  border-color: var(--rb-primary);
  color: var(--rb-on-primary);
}

/* Header da Sidebar */
.sidebar-header {
  background: var(--rb-primary);
  color: var(--rb-on-primary);
  padding: 12px 16px;

  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 60px;

  box-shadow: var(--rb-shadow-sm);
}

.header-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  object-fit: cover;
  box-shadow: var(--rb-shadow-sm);
}

.sidebar-header h1 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: .2px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: currentColor;
  width: 40px;
  height: 40px;
  border-radius: 999px;

  display: flex;
  align-items: center;
  justify-content: center;

  cursor: pointer;
  transition: all 0.25s ease;
  font-size: 1.25rem;
  position: relative;
  overflow: hidden;
}

.icon-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  /* usa a cor do texto ambiente (branco no header, texto apagado no footer)
     em vez de uma cor fixa, para funcionar em qualquer contexto/tema */
  background: currentColor;
  border-radius: 999px;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity .3s ease, transform .3s ease;
}

.icon-btn:hover::before {
  opacity: .15;
  transform: scale(1);
}

.icon-btn:hover {
  transform: translateY(-1px);
}

/* Busca */
.sidebar-search {
  background: transparent;
  padding: 10px 12px;
  border-bottom: 1px solid var(--rb-border);
}

.search-box {
  background: var(--rb-surface);
  border-radius: 999px;
  border: 1px solid var(--rb-border-strong);

  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;

  transition: border-color var(--rb-dur) var(--rb-ease),
              box-shadow var(--rb-dur) var(--rb-ease);
}

.search-box:focus-within {
  border-color: var(--rb-primary);
  box-shadow: 0 0 0 3px var(--rb-focus-ring);
}

.search-box i {
  color: var(--rb-primary);
  font-size: 1rem;
  opacity: .9;
}

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;

  font-size: 0.925rem;
  color: var(--rb-text);
}

.search-box input::placeholder {
  color: var(--rb-text-muted);
}

/* Lista de conversas */
.conversations-list {
  flex: 1;
  overflow-y: auto;
  background: transparent;
}

.conversations-list::-webkit-scrollbar {
  width: 6px;
}
.conversations-list::-webkit-scrollbar-thumb {
  background: var(--rb-scrollbar);
  border-radius: 999px;
}

.conversation-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;

  cursor: pointer;
  text-decoration: none;
  color: inherit;

  border-bottom: 1px solid var(--rb-border);
  transition: all .25s ease;
  position: relative;
}

.conversation-item:hover {
  background: var(--rb-surface-3);
  transform: translateY(-1px);
  box-shadow: var(--rb-shadow-sm);
}

.conversation-item.active {
  background: var(--rb-primary-subtle);
}

.conversation-item.active::before {
  content: "";
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  background: var(--rb-primary);
  border-radius: 999px;
}

.conversation-avatar img {
  width: 50px;
  height: 50px;
  border-radius: 999px;
  object-fit: cover;
  box-shadow: var(--rb-shadow-sm);
}

.conversation-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conversation-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.conversation-name {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  color: var(--rb-text);
}

.conversation-time {
  font-size: 0.75rem;
  color: var(--rb-text-muted);
  flex-shrink: 0;
}

.conversation-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
}

.conversation-message {
  font-size: 0.875rem;
  color: var(--rb-text-muted);
  margin: 0;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  display: flex;
  align-items: center;
  gap: 6px;
}

/* Badges (mantém as classes status-*) */
.conversation-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: .3px;

  background: var(--rb-neutral-subtle);
  color: var(--rb-neutral-text);
  border: 1px solid var(--rb-neutral-border);
}

.conversation-badge.status-aberto {
  background: var(--rb-danger-subtle);
  color: var(--rb-danger-text);
}

.conversation-badge.status-em_andamento {
  background: var(--rb-warning-subtle);
  color: var(--rb-warning-text);
}

.conversation-badge.status-concluido {
  background: var(--rb-success-subtle);
  color: var(--rb-success-text);
}

/* .status-pendente e .status-aguardando são o mesmo estado visual
   (depende de qual classe o template/JS aplica) — ambas em "info". */
.conversation-badge.status-pendente,
.conversation-badge.status-aguardando {
  background: var(--rb-info-subtle);
  color: var(--rb-info-text);
}

.empty-conversations {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  height: 100%;
  color: var(--rb-text-muted);
  gap: 12px;
  padding: 40px 20px;
}

.empty-conversations i {
  font-size: 4rem;
  opacity: 0.25;
}

.empty-conversations p {
  margin: 0;
  font-size: 0.9rem;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--rb-border);
  background: transparent;
}

/* ============================================
   ÁREA DE CHAT
   ============================================ */

.whatsapp-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;

  background: transparent;
  height: 100%;
  overflow: hidden;
  min-height: 0;
}

/* Header do Chat */
.chat-header {
  background: var(--rb-primary);
  color: var(--rb-on-primary);
  padding: 10px 16px;

  display: flex;
  justify-content: space-between;
  align-items: center;

  min-height: 60px;
  box-shadow: var(--rb-shadow-sm);
  z-index: 10;
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar img {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  object-fit: cover;
  box-shadow: var(--rb-shadow-sm);
}

.chat-info h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
}

.chat-info p {
  font-size: 0.8rem;
  margin: 2px 0 0;
  opacity: 0.95;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--rb-success);
  display: inline-block;
}
.status-dot.status-fechado { background: var(--rb-neutral); }
.status-dot.status-pendente { background: var(--rb-warning); }

.chat-header-actions {
  display: flex;
  gap: 4px;
}

.chat-header .icon-btn {
  color: var(--rb-on-primary);
}

/* Fundo sutil atrás das mensagens (sólido, sem gradiente decorativo) */
.chat-background {
  position: absolute;
  top: 60px;
  left: 0;
  right: 0;
  bottom: 0;

  background: var(--rb-bg);
  pointer-events: none;
  z-index: 0;
}

/* Mensagens */
.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  min-height: 0;
  z-index: 1;

  padding: 16px;
  height: 0;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--rb-scrollbar);
  border-radius: 999px;
}

.messages-container {
  display: flex;
  flex-direction: column;
  gap: 8px;

  /* ocupa toda a largura do chat */
  width: 100%;
  max-width: none;
  margin: 0;          /* remove centralização */
  padding: 0;
}

.message-wrapper {
  display: flex;
  width: 100%;        /* importante para sent/received encostarem */
  margin-bottom: 4px;
  animation: fadeIn 0.3s ease;
}

.message-wrapper.sent { justify-content: flex-end; }
.message-wrapper.received { justify-content: flex-start; }

.message {
  max-width: 65%;
  padding: 8px 12px 6px;
  border-radius: 12px;
  position: relative;

  word-wrap: break-word;
  box-shadow: var(--rb-shadow-sm);
  border: 1px solid var(--rb-border);
}

.message-wrapper.sent .message {
  background: var(--rb-primary-subtle);
  border-top-right-radius: 4px;
}

.message-wrapper.received .message {
  background: var(--rb-surface-2);
  border-top-left-radius: 4px;
}

.message.message-internal {
  background: var(--rb-warning-subtle);
  border-color: var(--rb-warning-border);
}

.message-sender {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--rb-text);
  margin-bottom: 4px;
  opacity: .95;
}

.message-internal-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;

  font-size: 0.7rem;
  color: var(--rb-warning-text);
  background: var(--rb-warning-subtle);

  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 6px;
  font-weight: 700;
  letter-spacing: .3px;
}

.message-text {
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--rb-text);
  margin-bottom: 4px;
}

.message-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
}

.message-time {
  font-size: 0.72rem;
  color: var(--rb-text-muted);
}

.message-status {
  display: flex;
  align-items: center;
  color: var(--rb-info);
  font-size: 0.9rem;
}

/* Empty states */
.chat-empty-state,
.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  height: 100%;
  gap: 16px;
  color: var(--rb-text-muted);
  text-align: center;
  padding: 40px;

  background: transparent;
}

.empty-icon {
  width: 100px;
  height: 100px;
  border-radius: 999px;
  background: var(--rb-bg);

  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-icon i {
  font-size: 3rem;
  opacity: 0.25;
  color: var(--rb-primary);
}

.chat-empty-state h3,
.chat-empty h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0;
  color: var(--rb-text);
}

.chat-empty-state p,
.chat-empty p {
  font-size: 0.95rem;
  margin: 0;
  max-width: 520px;
  line-height: 1.6;
}

/* Footer - Input de mensagem */
.chat-footer {
  margin-top: auto;
  background: var(--rb-surface);

  padding: 10px 16px;
  border-top: 1px solid var(--rb-border);

  z-index: 10;
  flex-shrink: 0;

  /* altura de UMA linha de mensagem: campo e botões usam a mesma, então ficam
     no mesmo eixo; com o campo crescendo, os botões acompanham a última linha */
  --chat-row-h: 44px;
}

.message-input-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.footer-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  height: var(--chat-row-h);
}

.footer-actions .icon-btn {
  color: var(--rb-text-muted);
  font-size: 1.5rem;
}

.footer-actions .icon-btn:hover {
  background: var(--rb-surface-2);
}

.message-input-wrapper {
  flex: 1;
}

.message-input-wrapper textarea {
  width: 100%;
  border: 1px solid var(--rb-border-strong);

  background: var(--rb-surface);
  border-radius: 20px;   /* pílula com 1 linha; cantos arredondados (não "cápsula") quando cresce */
  padding: 10px 16px;

  min-height: var(--chat-row-h);
  max-height: 160px;     /* ~6 linhas; passou disso, rola. O script ajusta a altura ao digitar */

  font-size: 0.95rem;
  resize: none;
  outline: none;

  overflow-y: hidden;    /* o script liga a rolagem só ao atingir o máximo */
  font-family: inherit;
  line-height: 1.4;

  color: var(--rb-text);
  transition: border-color var(--rb-dur) var(--rb-ease),
              box-shadow var(--rb-dur) var(--rb-ease);
}

.message-input-wrapper textarea:focus {
  border-color: var(--rb-primary);
  box-shadow: 0 0 0 3px var(--rb-focus-ring);
}

.message-input-wrapper textarea::-webkit-scrollbar {
  width: 6px;
}
.message-input-wrapper textarea::-webkit-scrollbar-thumb {
  background: var(--rb-scrollbar);
  border-radius: 999px;
}

.footer-send {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--chat-row-h);
}

/* Cadeado de mensagem interna.
   Desligado: só o ícone, discreto. Ligado: etiqueta amarela com o texto "Interna", impossível de não ver. */
.internal-toggle {
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;

  padding: 8px;
  border: 1px solid transparent;
  border-radius: 999px;

  transition: background 0.2s, border-color 0.2s, color 0.2s;
  color: var(--rb-text-muted);
}

.internal-toggle:hover {
  background: var(--rb-surface-2);
}

/* Fora da tela mas focável: o cadeado também funciona pelo teclado (Tab e Espaço) */
.internal-toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.internal-toggle:has(input:focus-visible) {
  box-shadow: 0 0 0 3px var(--rb-focus-ring);
}

.internal-toggle .internal-icon-on { display: none; }

/* O texto existe sempre (leitores de tela), mas só aparece com o cadeado ligado */
.internal-toggle .internal-toggle-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.internal-toggle:has(input:checked) {
  padding: 8px 14px 8px 12px;
  background: var(--rb-warning-subtle);
  border-color: var(--rb-warning);
  color: var(--rb-warning-text);
}
.internal-toggle:has(input:checked) .internal-icon-off { display: none; }
.internal-toggle:has(input:checked) .internal-icon-on { display: inline; }
.internal-toggle:has(input:checked) .internal-toggle-text {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  font-size: 0.85rem;
  font-weight: var(--rb-fw-semibold);
}

/* Campo de digitar em modo interno: fundo e borda amarelos */
.message-input-form.modo-interno .message-input-wrapper textarea {
  background: var(--rb-warning-subtle);
  border-color: var(--rb-warning);
}
.message-input-form.modo-interno .message-input-wrapper textarea:focus {
  border-color: var(--rb-warning);
  box-shadow: 0 0 0 3px rgba(var(--rb-warning-rgb), 0.3);
}

/* Faixa acima do campo: avisa que o cliente não vai receber */
.internal-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -10px -16px 10px; /* cola nas bordas do .chat-footer */
  padding: 8px 16px;
  background: var(--rb-warning-subtle);
  border-bottom: 1px solid var(--rb-warning-border);
  color: var(--rb-warning-text);
  font-size: 0.85rem;
}
.internal-banner[hidden] { display: none; }

.send-btn {
  width: var(--chat-row-h);
  height: var(--chat-row-h);
  border-radius: 999px;

  background: var(--rb-primary);
  border: none;
  color: var(--rb-on-primary);

  display: flex;
  align-items: center;
  justify-content: center;

  cursor: pointer;
  transition: all 0.25s ease;
  font-size: 1.25rem;

  box-shadow: var(--rb-shadow);
}

.send-btn:hover {
  background: var(--rb-primary-hover);
  transform: translateY(-2px) scale(1.04);
  box-shadow: var(--rb-shadow-lg);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Quick Actions */
.quick-actions {
  display: none;
  gap: 12px;
  padding: 8px 0 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.quick-actions::-webkit-scrollbar { display: none; }

.quick-action {
  display: flex;
  align-items: center;
  gap: 6px;

  padding: 6px 12px;
  border-radius: 999px;

  background: var(--rb-surface);
  border: 1px solid var(--rb-border);

  font-size: 0.85rem;
  color: var(--rb-text-muted);

  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  text-decoration: none;
}

.quick-action:hover {
  background: var(--rb-surface-2);
  color: var(--rb-text);
  transform: translateY(-1px);
}

.quick-action-success {
  background: var(--rb-success-subtle);
  color: var(--rb-success-text);
  border-color: var(--rb-success-border);
}

.quick-action-success:hover {
  background: rgba(var(--rb-success-rgb), .22);
  color: var(--rb-success-text);
}

/* ============================================
   OFFCANVAS — INFORMAÇÕES
   ============================================ */

.whatsapp-info {
  width: 400px;
}

.whatsapp-info .offcanvas-header {
  background: var(--rb-primary);
  color: var(--rb-on-primary);
  padding: 16px;
}

.whatsapp-info .btn-close {
  filter: invert(1);
  opacity: 0.8;
}

.info-profile {
  text-align: center;
  padding: 32px 20px;
  background: var(--rb-surface);
}

.profile-avatar img {
  width: 120px;
  height: 120px;
  border-radius: 999px;
  object-fit: cover;
  margin-bottom: 16px;
  box-shadow: var(--rb-shadow);
}

.info-profile h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--rb-text);
}

.info-profile p {
  font-size: 0.9rem;
  color: var(--rb-text-muted);
  margin: 0;
}

.info-section {
  background: transparent;
  margin-bottom: 8px;
}

.info-header {
  padding: 12px 16px;
  font-size: 0.875rem;
  color: var(--rb-text);
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
  opacity: .9;
}

.info-list { padding: 0 16px; }

.info-item {
  display: flex;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--rb-border);
}

.info-item:last-child { border-bottom: none; }

.info-icon {
  flex-shrink: 0;
  width: 24px;
  display: flex;
  align-items: center;
  justify-content: center;

  color: var(--rb-text-muted);
  font-size: 1.1rem;
}

.info-content { flex: 1; }

.info-label {
  font-size: 0.8rem;
  color: var(--rb-text-muted);
  margin-bottom: 2px;
}

.info-value {
  font-size: 0.95rem;
  color: var(--rb-text);
}

.info-description {
  padding: 16px;
  font-size: 0.92rem;
  color: var(--rb-text);
  line-height: 1.6;
}

.info-actions { padding: 16px; }

.info-action-btn {
  display: flex;
  align-items: center;
  gap: 16px;

  padding: 16px;
  background: var(--rb-surface);
  border: 1px solid var(--rb-border);

  width: 100%;
  text-align: left;

  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 12px;

  color: inherit;
  text-decoration: none;
}

.info-action-btn:hover {
  background: var(--rb-surface-2);
  transform: translateY(-1px);
  box-shadow: var(--rb-shadow-sm);
}

.info-action-btn i {
  font-size: 1.25rem;
  color: var(--rb-text-muted);
}

.info-action-btn span {
  font-size: 0.95rem;
  color: var(--rb-text);
  font-weight: 600;
}

/* ============================================
   MODAIS
   ============================================ */

.whatsapp-modal .modal-header {
  background: var(--rb-primary);
  color: var(--rb-on-primary);
  border: none;
}

.whatsapp-modal .modal-title {
  font-size: 1rem;
  font-weight: 700;
}

.whatsapp-modal .btn-close {
  filter: invert(1);
  opacity: 0.8;
}

.quick-actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  padding: 8px 0;
}

.quick-action-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;

  padding: 20px;
  background: var(--rb-surface);

  border: 1px solid var(--rb-border);
  border-radius: 14px;

  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  color: inherit;
}

.quick-action-card:hover {
  border-color: var(--rb-primary);
  box-shadow: var(--rb-shadow);
  transform: translateY(-2px);
}

.action-icon {
  width: 56px;
  height: 56px;
  border-radius: 999px;

  display: flex;
  align-items: center;
  justify-content: center;

  color: var(--rb-on-primary);
  background: var(--rb-primary);
  font-size: 1.5rem;

  box-shadow: var(--rb-shadow-sm);
}

/* Paleta decorativa de categoria para os ícones de exemplo de ação (seletor de tipo de interação). */
.action-icon-1  { background: var(--rb-cat-1); }
.action-icon-2  { background: var(--rb-cat-2); }
.action-icon-3  { background: var(--rb-cat-3); }
.action-icon-4  { background: var(--rb-cat-4); }
.action-icon-5  { background: var(--rb-cat-5); }
.action-icon-6  { background: var(--rb-cat-6); }
.action-icon-7  { background: var(--rb-cat-7); }
.action-icon-8  { background: var(--rb-cat-8); }
.action-icon-9  { background: var(--rb-cat-9); }
.action-icon-10 { background: var(--rb-cat-10); }
.action-icon-11 { background: var(--rb-cat-11); }

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--rb-radius-pill);
  background: var(--rb-surface-2);
  border: 1px solid var(--rb-border);
  color: var(--rb-text);
}
.attach-chip-name {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attach-chip-size { color: var(--rb-text-muted); }
.attach-chip-remove {
  color: var(--rb-text-muted);
  text-decoration: none;
}
.attach-chip-remove:hover { color: var(--rb-danger-text); }

.quick-action-card span {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--rb-text);
  text-align: center;
}

/* ============================================
   DROPDOWNS E ALERTAS
   Escopados em .whatsapp-container: main.css/modais.css já
   estilizam .dropdown-menu/.dropdown-item/.alert globalmente;
   essas regras só existem para o dropdown/alert específicos
   do chat, sem vazar para o resto do site.
   ============================================ */

.whatsapp-container .dropdown-menu {
  border: 1px solid var(--rb-border);
  background: var(--rb-surface);
  box-shadow: var(--rb-shadow);
  border-radius: 12px;
  padding: 8px;
}

.whatsapp-container .dropdown-item {
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;

  display: flex;
  align-items: center;
  gap: 8px;

  color: var(--rb-text);
}

.whatsapp-container .dropdown-item:hover {
  background: var(--rb-surface-2);
}

.whatsapp-container .alert-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  max-width: 400px;
}

.whatsapp-container .alert {
  border-radius: 12px;
  box-shadow: var(--rb-shadow);
  border: none;
}

/* =========================================================
   BUSCA NO CHAT (desktop + mobile)
   ========================================================= */

/* Base da barra de busca do chat */
.chat-search {
  display: none; /* escondida por padrão; o JS adiciona .active */
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--rb-border-strong);
  background-color: var(--rb-surface-2);
}

.chat-search.active {
  display: flex;
}

.chat-search > i {
  font-size: 0.95rem;
  color: var(--rb-text-muted);
}

.chat-search input {
  border: none;
  outline: none;
  background: transparent;
  width: 100%;
  font-size: 0.9rem;
  color: var(--rb-text);
}

.chat-search input::placeholder {
  color: var(--rb-text-subtle);
}

.chat-search-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: 0.25rem;
}

.chat-search-count {
  font-size: 0.7rem;
  color: var(--rb-text-muted);
}

.chat-search-btn {
  border: none;
  background: transparent;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--rb-text-muted);
}

.chat-search-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.chat-search-btn i {
  font-size: 0.85rem;
}

#chatSearchClose.icon-btn {
  width: 28px;
  height: 28px;
  margin-left: 0.25rem;
}

/* Destaque do termo encontrado */
.chat-search-mark {
  background: var(--rb-mark-bg);
  color: var(--rb-text);
  padding: 0 2px;
  border-radius: 2px;
}

/* Destaque do resultado atual */
.message-wrapper.search-current .message {
  outline: 2px solid var(--rb-warning);
  outline-offset: 2px;
  transition: outline 120ms ease;
}

/* ============================================
   RESPONSIVIDADE
   ============================================ */

@media (max-width: 992px) {
  .whatsapp-container { margin: 0; }
  .whatsapp-sidebar { width: 100%; max-width: 400px; }
}

@media (max-width: 768px) {
  .whatsapp-container {
    height: calc(100vh - 60px);
    position: relative;
    overflow: hidden;
  }

  /* Sidebar vira um painel deslizante */
  .whatsapp-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    max-width: 420px;
    height: 100vh;
    z-index: 1050;

    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  /* dois mecanismos de abertura convivem: .show na própria sidebar
     e .sidebar-open no container (o usado pelo JS atual) */
  .whatsapp-sidebar.show,
  .whatsapp-container.sidebar-open .whatsapp-sidebar {
    transform: translateX(0);
  }

  .message { max-width: 80%; }

  .quick-actions-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Ajustes gerais para telas pequenas (chat + header + busca) */
@media (max-width: 767.98px) {

  /* Container geral – mais compacto */
  .whatsapp-container {
    font-size: 0.9rem;
  }

  /* SIDEBAR (lista de conversas) */
  .whatsapp-sidebar {
    width: 100%;
  }

  .sidebar-header {
    padding: 0.4rem 0.75rem;
  }

  .sidebar-header .header-content {
    gap: 0.4rem;
  }

  .sidebar-header .header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 999px;
  }

  .sidebar-header h1 {
    font-size: 1rem;
    margin: 0;
    line-height: 1.2;
  }

  .sidebar-header .header-actions .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
  }

  .sidebar-search {
    padding: 0.3rem 0.75rem 0.4rem;
  }

  .sidebar-search .search-box {
    padding: 0.25rem 0.6rem;
  }

  .sidebar-search .search-box input {
    font-size: 0.85rem;
    padding: 0.2rem 0.4rem 0.2rem 1.9rem;
  }

  .conversations-list {
    padding: 0.2rem 0;
  }

  .conversation-item {
    padding: 0.4rem 0.6rem;
  }

  .conversation-avatar img {
    width: 36px;
    height: 36px;
  }

  .conversation-name {
    font-size: 0.9rem;
  }

  .conversation-time {
    font-size: 0.75rem;
  }

  .conversation-message {
    font-size: 0.75rem;
  }

  .conversation-badge {
    font-size: 0.7rem;
    padding: 0.1rem 0.35rem;
  }

  /* HEADER DO CHAT (lado direito) */
  .chat-header {
    padding: 0.4rem 0.6rem;
  }

  .chat-header-left {
    gap: 0.4rem;
  }

  .chat-avatar img {
    width: 36px;
    height: 36px;
    border-radius: 999px;
  }

  .chat-info h2 {
    font-size: 0.95rem;
    margin: 0 0 0.1rem 0;
    line-height: 1.2;
  }

  .chat-subtitle {
    font-size: 0.75rem;
    line-height: 1.2;
    flex-wrap: wrap; /* permite quebrar para 2 linhas se apertar */
  }

  .ticket-number {
    font-size: 0.75rem;
    margin-left: 0; /* evita ficar muito colado no badge */
  }

  #ticketStatusLabel {
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
  }

  .chat-header-actions {
    gap: 0.25rem;
  }

  .chat-header-actions .icon-btn,
  #btnToggleSidebar.icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
    padding: 0;
  }

  /* Barra de busca do chat na posição "mobile"
     (abaixo do header, largura quase total) */
  .chat-search.chat-search-mobile {
    border-radius: 0.75rem;
    margin: 0.25rem 0.6rem 0.35rem;
    width: auto;
    padding: 0.3rem 0.6rem;
  }

  .chat-search.chat-search-mobile input {
    font-size: 0.85rem;
  }

  .chat-search.chat-search-mobile .chat-search-btn {
    width: 26px;
    height: 26px;
  }

  .chat-search.chat-search-mobile .chat-search-count {
    font-size: 0.7rem;
  }

  /* Mensagens e rodapé */
  .chat-messages {
    padding: 0.4rem 0.4rem 0.2rem;
  }

  .message {
    font-size: 0.8rem;
    padding: 0.35rem 0.45rem;
    border-radius: 0.75rem;
  }

  .message-sender {
    font-size: 0.7rem;
    margin-bottom: 0.15rem;
  }

  .message-time {
    font-size: 0.7rem;
  }

  .message-internal-badge {
    font-size: 0.7rem;
    padding: 0.1rem 0.3rem;
  }

  .chat-footer {
    padding: 0.35rem 0.5rem;
    --chat-row-h: 38px;
  }

  .message-input-form {
    gap: 0.3rem;
  }

  .message-input-wrapper textarea {
    font-size: 0.85rem;
    padding: 0.35rem 0.5rem;
  }

  .footer-actions .icon-btn,
  .footer-send .send-btn {
    width: 34px;
    height: 34px;
    font-size: 0.9rem;
  }

  .internal-toggle {
    font-size: 0.75rem;
  }
}

/* ============================================
   ANIMAÇÕES
   ============================================ */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Acessibilidade: reduzir movimento */
@media (prefers-reduced-motion: reduce) {
  .expand-icon,
  .pool-details-content,
  .message-wrapper,
  .chat-search {
    transition: none !important;
    animation: none !important;
  }
}

/* ====== Banner "mensagem recebida" (canto inferior direito) ====== */
.wa-incoming {
  position: absolute;
  right: 16px;
  bottom: 86px; /* acima do footer de enviar mensagem */
  z-index: 30000;

  display: flex;
  align-items: center;
  gap: 10px;

  max-width: min(420px, calc(100% - 32px));
  padding: 10px 12px;

  border-radius: 14px;
  background: var(--rb-surface);
  border: 1px solid var(--rb-border);
  box-shadow: var(--rb-shadow-lg);

  transform: translateY(8px);
  opacity: 0;
  pointer-events: none;

  transition: opacity .18s ease, transform .18s ease;
}

.wa-incoming.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  cursor: pointer;
}

.wa-incoming .wa-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--rb-success);
  box-shadow: 0 0 0 3px rgba(var(--rb-success-rgb), .18);
  flex: 0 0 auto;
}

.wa-incoming .wa-texts {
  overflow: hidden;
  min-width: 0;
}

.wa-incoming .wa-title {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.1;
  margin: 0;
  color: var(--rb-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wa-incoming .wa-preview {
  font-size: 12px;
  line-height: 1.25;
  margin: 0;
  color: var(--rb-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wa-incoming .wa-action {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--rb-text-muted);
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.wa-incoming .wa-action:hover {
  background: var(--rb-surface-2);
  color: var(--rb-text);
}

/* ====== Unread dot na sidebar ====== */
.conversation-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.unread-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--rb-success);
  box-shadow: 0 0 0 3px rgba(var(--rb-success-rgb), .18);
  display: inline-block;
}

/* deixa o item um pouco mais "vivo" quando tiver unread */
.conversation-item.has-unread .conversation-name {
  font-weight: 800;
}

/* ====== Upload de anexo ====== */
.attachment-upload {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px dashed var(--rb-border-strong);
  border-radius: 10px;
  margin-top: 8px;
  background: var(--rb-surface-2);
}

.attachment-upload .spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--rb-border-strong);
  border-top-color: var(--rb-text-muted);
  /* spinner de carregamento: única animação infinita permitida (DESIGN_SYSTEM.md §1) */
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.attachment-upload .meta {
  flex: 1;
  min-width: 0;
}

.attachment-upload .name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--rb-text);
}

.attachment-upload .sub {
  font-size: 12px;
  color: var(--rb-text-muted);
  margin-top: 2px;
}

.attachment-upload .bar {
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--rb-surface-3);
  margin-top: 6px;
}

.attachment-upload .bar > div {
  height: 100%;
  width: 0%;
  background: var(--rb-primary);
  transition: width .12s linear;
}

.attachment-upload.failed {
  border-style: solid;
  border-color: var(--rb-danger-border);
  background: var(--rb-danger-subtle);
}

/* ====== Anexos dentro da mensagem (partials/_ticket_attachment.html) ======
   Antes era um <style> no ticket_chatbot.html com rgba() cru. O fundo é um
   véu do próprio texto do tema, então funciona em qualquer balão
   (recebido, enviado, interno) nos dois temas. */
.message-attachments { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.ticket-attachment {
  padding: 8px 10px;
  border-radius: var(--rb-radius);
  background: rgba(var(--rb-text-rgb), .05);
  border: 1px solid var(--rb-border);
}
.ticket-attachment-link { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.ticket-attachment-name { font-weight: var(--rb-fw-semibold); }
.ticket-attachment-size { margin-left: auto; font-size: var(--rb-fs-xs); color: var(--rb-text-muted); }

/* Prévia de arquivos selecionados (static/js/chat_attachments.js) */
.attach-preview-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--rb-radius);
}
.attach-preview-chip .attach-preview-name {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attach-preview-chip .attach-preview-size { color: var(--rb-text-muted); }
.attach-preview-chip .btn-link { --bs-btn-color: inherit; min-height: 0; text-decoration: none; }

/* Títulos dentro das faixas na cor da marca: main.css/modais.css dão
   color: var(--rb-text) a h1–h6/.modal-title/.offcanvas-title; aqui o
   texto precisa herdar o --rb-on-primary da faixa. */
.sidebar-header h1,
.sidebar-header h2,
.chat-header h1, .chat-header h2, .chat-header h3, .chat-header h4, .chat-header h5, .chat-header h6,
.whatsapp-info .offcanvas-header .offcanvas-title,
.whatsapp-info .offcanvas-header h5,
.whatsapp-modal .modal-header .modal-title,
.whatsapp-modal .modal-header .modal-title i { color: inherit; }

/* ====== Anexos: miniaturas, baixar e visualizador (partials/_ticket_attachment.html,
   partials/_attachment_viewer.html, static/js/attachment_viewer.js) ====== */
.ticket-attachment-link { min-width: 0; }
.ticket-attachment-open {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  text-decoration: none;
}
.ticket-attachment-open .ticket-attachment-name,
.ticket-attachment-meta .ticket-attachment-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ticket-attachment-link .ticket-attachment-size { margin-left: 0; flex: 0 0 auto; }

.ticket-attachment-dl {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--rb-radius-pill);
  color: var(--rb-text-muted);
  text-decoration: none;
  transition: background var(--rb-dur) var(--rb-ease), color var(--rb-dur) var(--rb-ease);
}
.ticket-attachment-dl:hover { background: rgba(var(--rb-text-rgb), .08); color: var(--rb-primary); }

.ticket-attachment-media { width: min(260px, 100%); padding: 6px; }
.ticket-attachment-thumb {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  padding: 0;
  border: 0;
  border-radius: calc(var(--rb-radius) - 2px);
  overflow: hidden;
  background: rgba(var(--rb-text-rgb), .12);
  cursor: zoom-in;
}
.ticket-attachment-thumb img,
.ticket-attachment-thumb video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none; /* o clique é do botão, não do vídeo/imagem */
  transition: filter var(--rb-dur) var(--rb-ease);
}
.ticket-attachment-thumb:hover img,
.ticket-attachment-thumb:hover video { filter: brightness(.9); }
.ticket-attachment-thumb:focus-visible { outline: 2px solid var(--rb-primary); outline-offset: 2px; }

.ticket-attachment-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
  color: var(--rb-on-solid);
  background: rgba(0, 0, 0, .22);
  text-shadow: 0 1px 6px rgba(0, 0, 0, .5);
  pointer-events: none;
}

.ticket-attachment-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  min-width: 0;
  font-size: var(--rb-fs-sm);
}
.ticket-attachment-meta .ticket-attachment-name { flex: 1 1 auto; }
.ticket-attachment-meta .ticket-attachment-size { margin-left: 0; flex: 0 0 auto; }

/* Visualizador (modal). O palco é preto nos dois temas: foto/vídeo se veem melhor assim. */
.att-viewer .modal-content {
  background: var(--rb-surface);
  border: 1px solid var(--rb-border);
  overflow: hidden;
}
.att-viewer .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--rb-border);
}
.att-viewer-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.att-viewer-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: var(--rb-fw-semibold);
}
.att-viewer-counter { flex: 0 0 auto; color: var(--rb-text-muted); font-size: var(--rb-fs-xs); }
.att-viewer-actions { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }

.att-viewer-body {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
  padding: 12px;
  background: rgba(0, 0, 0, .9);
}
.att-viewer-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
}
.att-viewer-media {
  display: block;
  max-width: 100%;
  max-height: 75vh;
  object-fit: contain;
  border-radius: var(--rb-radius);
}
.att-viewer-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 40px 20px;
  color: #fff;
  text-align: center;
}
.att-viewer-error i { font-size: 2rem; }

.att-viewer-nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 1.2rem;
  transform: translateY(-50%);
  cursor: pointer;
}
.att-viewer-nav:hover { background: rgba(0, 0, 0, .8); }
.att-viewer-nav[disabled] { opacity: .3; cursor: default; }
.att-viewer-nav[hidden] { display: none; }
.att-viewer-prev { left: 12px; }
.att-viewer-next { right: 12px; }

@media (max-width: 575.98px) {
  .att-viewer .modal-dialog { margin: 0; max-width: none; }
  .att-viewer .modal-content { border-radius: 0; min-height: 100vh; }
  .att-viewer-media { max-height: 70vh; }
}

/* ====== Editar / excluir mensagem (partials/_ticket_message.html, static/js/chat_message_actions.js) ====== */
.message-actions {
  position: absolute;
  top: -13px; /* flutua na borda do balão para não cobrir o nome do autor */
  right: 8px;
  z-index: 2;
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: var(--rb-radius-pill);
  background: var(--rb-surface);
  border: 1px solid var(--rb-border);
  box-shadow: var(--rb-shadow-sm);
  opacity: 0;
  transition: opacity var(--rb-dur) var(--rb-ease);
}
.message:hover .message-actions,
.message:focus-within .message-actions { opacity: 1; }
.message-actions[hidden] { display: none; }
@media (hover: none) { .message-actions { opacity: .85; } } /* celular: sem hover, sempre visível */

.message-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--rb-text-muted);
  font-size: .8rem;
  cursor: pointer;
}
.message-action:hover { background: var(--rb-surface-2); color: var(--rb-text); }
.message-action[data-action="delete"]:hover { color: var(--rb-danger); }
.message-action:focus-visible { outline: 2px solid var(--rb-primary); outline-offset: 1px; }

/* selo "editada HH:MM" */
.message-edited {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-right: 6px;
  color: var(--rb-text-muted);
  font-size: var(--rb-fs-xs);
  font-style: italic;
}
.message-edited i { font-size: .6rem; }

/* mensagem apagada: aviso em itálico, sem texto nem anexos */
.message-deleted {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  color: var(--rb-text-muted);
  font-style: italic;
}
.message-deleted-time { font-size: var(--rb-fs-xs); }
.message-wrapper.is-deleted .message { opacity: .8; }

/* edição no próprio balão */
.message-edit { margin-top: 4px; min-width: min(420px, 60vw); }
.message-edit-input {
  width: 100%;
  min-height: 56px;
  padding: 8px 10px;
  resize: vertical;
  border: 1px solid var(--rb-border-strong);
  border-radius: var(--rb-radius);
  background: var(--rb-surface);
  color: var(--rb-text);
  font: inherit;
}
.message-edit-input:focus { outline: 2px solid var(--rb-primary); outline-offset: 0; }
.message-edit-error { margin-top: 4px; color: var(--rb-danger); font-size: var(--rb-fs-sm); }
.message-edit-bar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.message-edit-hint { margin-right: auto; color: var(--rb-text-muted); font-size: var(--rb-fs-xs); }

/* confirmação de exclusão */
.message-confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
  padding: 6px 8px;
  border-radius: var(--rb-radius);
  background: var(--rb-danger-subtle);
  border: 1px solid var(--rb-danger-border);
  color: var(--rb-danger-text);
  font-size: var(--rb-fs-sm);
}
.message-confirm-text { margin-right: auto; }

/* excluir com opção de apagar os arquivos do R2 */
.message-confirm { align-items: flex-start; }
.message-confirm-body { flex: 1 1 220px; min-width: 0; }
.message-confirm-btns { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.message-confirm-purge {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 6px;
  cursor: pointer;
  font-weight: var(--rb-fw-semibold);
}
.message-confirm-purge input { margin-top: 3px; accent-color: var(--rb-danger); }
.message-confirm-hint { margin-top: 2px; color: var(--rb-text-muted); font-size: var(--rb-fs-xs); }
.message-confirm.is-purge { border-color: var(--rb-danger); }
.message-deleted-files {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 6px;
  border-radius: var(--rb-radius-pill);
  background: var(--rb-danger-subtle);
  color: var(--rb-danger-text);
  font-size: var(--rb-fs-xs);
  font-style: normal;
}


/* ============================================
   TELA CHEIA (computador e celular): o chat ocupa a tela inteira, sem as margens do .container
   ============================================ */
/* O seletor com 3 classes vence o limite de largura do .container-wider (main.css), que vale em telas grandes */
main.container.container-wider.chat-page,
main.chat-page {
  max-width: none;
  width: 100%;
  padding: 0 !important; /* vence o py-2 do base.html e o padding do .container */
}

main.chat-page .whatsapp-container {
  /* altura da navbar (56px) + 1px da borda inferior */
  height: calc(100vh - var(--rb-navbar-h) - 1px);   /* navegadores sem dvh */
  height: calc(100dvh - var(--rb-navbar-h) - 1px);  /* descontando a barra de endereço do celular */
  min-height: 0;
  max-height: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

@media (max-width: 767.98px) {
  /* painel de conversas por cima de tudo, também ajustado à tela real */
  main.chat-page .whatsapp-sidebar {
    height: 100vh;
    height: 100dvh;
    max-width: none;
  }
}

/* ============================================
   CELULAR: painel de tickets pela metade (lado oposto ao das informações)
   e busca do chat visível
   ============================================ */

/* O painel de informações (offcanvas) e o de tickets têm a mesma largura:
   400px, mas nunca mais que 88% da tela, para sempre sobrar uma faixa de fundo para tocar e fechar */
.whatsapp-info { --bs-offcanvas-width: min(400px, 88vw); }

@media (max-width: 768px) {
  main.chat-page .whatsapp-sidebar {
    width: min(400px, 88vw);
    max-width: none;
    height: 100vh;
    height: 100dvh;
    box-shadow: none;
  }

  /* aberto: sombra + fundo escurecido (o toque fora já fecha, ver o script do ticket_chatbot) */
  main.chat-page .whatsapp-container.sidebar-open .whatsapp-sidebar { box-shadow: var(--rb-shadow-lg); }

  main.chat-page .whatsapp-container.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 1040; /* abaixo do painel (1050), acima do resto da página */
    background: rgba(0, 0, 0, .5);
    animation: chat-backdrop-in .2s ease;
  }

  /* sem ticket selecionado a lista é a tela inteira (não há conversa por trás para mostrar) */
  main.chat-page .whatsapp-container[data-has-ticket="0"] .whatsapp-sidebar { width: 100%; }
  main.chat-page .whatsapp-container[data-has-ticket="0"].sidebar-open::after { display: none; }
}

@keyframes chat-backdrop-in { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  main.chat-page .whatsapp-container.sidebar-open::after { animation: none; }
}

/* A busca é movida pelo script para logo abaixo do cabeçalho. Como não tinha posição,
   ficava PINTADA ATRÁS da camada de fundo do chat (.chat-background, absolute) e sumia. */
.chat-search.chat-search-mobile {
  position: relative;
  z-index: 5;
  flex-shrink: 0;
}

/* Link com aparência de .icon-btn (ex.: abrir WhatsApp do cliente no cabeçalho do chat) */
a.icon-btn {
  color: inherit;
  text-decoration: none;
}

/* Filtro de status abaixo da busca da barra lateral */
/* Os filtros (status e técnico) ficam lado a lado, cada um com metade da largura */
.sidebar-filters {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.sidebar-search .status-filter {
  flex: 1 1 0;
  min-width: 0;
  text-overflow: ellipsis;
  border-radius: 999px;
  padding-left: 14px;
  background-color: var(--rb-surface);
  border-color: var(--rb-border-strong);
  color: var(--rb-text);
}
.sidebar-search .status-filter:focus {
  border-color: var(--rb-primary);
  box-shadow: 0 0 0 3px var(--rb-focus-ring);
}

/* ============================================
   LARGURA DA LISTA AJUSTÁVEL (só em tela grande)
   ============================================ */
.sidebar-resizer { display: none; }

@media (min-width: 993px) {
  /* --chat-sidebar-w é definida pelo script (arrastar a alça ou setas do teclado) */
  .whatsapp-sidebar {
    width: var(--chat-sidebar-w, 400px);
    min-width: 280px;
    max-width: 60%;
  }

  /* Área de agarrar na borda direita da lista; só a linha fina aparece ao passar o mouse */
  .sidebar-resizer {
    display: block;
    position: absolute;
    top: 0;
    right: -4px;
    width: 9px;
    height: 100%;
    z-index: 30;
    cursor: col-resize;
    touch-action: none;
  }
  .sidebar-resizer::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 4px;
    width: 2px;
    background: transparent;
    transition: background var(--rb-dur) var(--rb-ease);
  }
  .sidebar-resizer:hover::after,
  .sidebar-resizer:focus-visible::after,
  .sidebar-resizer.arrastando::after {
    background: var(--rb-primary);
  }
  .sidebar-resizer:focus-visible { outline: none; }
}

/* Durante o arraste: cursor fixo e sem selecionar texto das duas áreas */
body.redimensionando-lista {
  cursor: col-resize;
  user-select: none;
}

/* Rodapé do chat para quem só pode ler (interno sem SAV): no lugar do campo de mensagem */
.chat-readonly {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 16px;
  color: var(--rb-text-muted);
  font-size: 0.9rem;
  text-align: center;
}

/* Avatar ao lado do nome do autor da mensagem */
.message-sender { display: flex; align-items: center; gap: 6px; }

/* @menção no texto da mensagem e lista de sugestões ao digitar "@" */
.message-text .mention {
  padding: 0 4px;
  font-weight: var(--rb-fw-semibold);
  color: var(--rb-primary-subtle-text);
  background: var(--rb-primary-subtle);
  border-radius: var(--rb-radius-sm);
}

.mention-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 30;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
  background: var(--rb-surface);
  border: 1px solid var(--rb-border-strong);
  border-radius: var(--rb-radius);
  box-shadow: var(--rb-shadow-md, 0 6px 20px rgba(0, 0, 0, .18));
}
.mention-menu[hidden] { display: none; }
.mention-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  text-align: left;
  color: var(--rb-text);
  background: transparent;
  border: 0;
  border-radius: var(--rb-radius-sm);
}
.mention-item:hover,
.mention-item.is-active { background: var(--rb-surface-2); }
.mention-item small { margin-left: auto; color: var(--rb-text-muted); }
.mention-vazio { padding: 8px; color: var(--rb-text-muted); font-size: var(--rb-fs-sm); }
.message-input-wrapper { position: relative; }

/* Selo "convidado" ao lado do nome de quem entrou por link (sem conta) */
.convidado-tag {
  margin-left: 4px;
  font-size: 0.65rem;
  font-weight: var(--rb-fw-semibold);
  color: var(--rb-info-text);
  background: var(--rb-info-subtle);
}

/* Lista de convites na janela "Convidar para a conversa" */
.convite-lista { display: flex; flex-direction: column; gap: var(--rb-space-2); }
.convite-linha {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--rb-space-3);
  padding: var(--rb-space-2) var(--rb-space-3);
  border: 1px solid var(--rb-border);
  border-radius: var(--rb-radius);
  background: var(--rb-surface-2);
}
.convite-info { min-width: 0; }

/* Faixa "Nova mensagem" (static/js/chat_novas.js): fica grudada no fim da área rolável, sobre as mensagens,
   quando chega mensagem e a pessoa está lendo mais acima. */
.chat-novas-wrap {
  position: sticky;
  bottom: 8px;
  display: flex;
  justify-content: center;
  height: 0;            /* não ocupa espaço na conversa; o botão flutua acima do fim */
  overflow: visible;
  pointer-events: none;
}
.chat-novas-wrap.d-none { display: none !important; }
.chat-novas {
  align-self: flex-end;
  padding: 6px 14px;
  font-size: var(--rb-fs-sm);
  font-weight: var(--rb-fw-semibold);
  color: var(--rb-on-primary);
  background: var(--rb-primary);
  border: 0;
  border-radius: 999px;
  box-shadow: var(--rb-shadow-md, 0 6px 20px rgba(0, 0, 0, .25));
  pointer-events: auto;
}


/* ===================== Cartão do resultado da pesquisa de satisfação (linha do sistema) ===================== */
.message-wrapper .message.message-internal:has(.pesquisa-card) {
  width: min(680px, 100%);
  max-width: 100%;
  background: var(--rb-warning-subtle);
  border-color: var(--rb-warning-border);
}
.pesquisa-card { display: flex; flex-direction: column; gap: var(--rb-space-3); }
.pesquisa-selo {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border: 1px solid var(--rb-warning-border);
  border-radius: var(--rb-radius-pill);
  background: var(--rb-warning-subtle);
  color: var(--rb-warning-text);
  font-size: var(--rb-fs-xs);
  font-weight: var(--rb-fw-bold);
}
.pesquisa-topo { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--rb-space-3) var(--rb-space-5); }
.pesquisa-rotulo { color: var(--rb-text-muted); font-size: var(--rb-fs-base); }
.pesquisa-nota {
  font-family: var(--rb-font-mono);
  font-size: 2.8rem;
  font-weight: var(--rb-fw-bold);
  line-height: 1.1;
  letter-spacing: .04em;
  color: var(--rb-text);
}
.pesquisa-nota small { margin-left: 4px; font-size: var(--rb-fs-md); font-weight: var(--rb-fw-medium); letter-spacing: 0; color: var(--rb-text-muted); }
.pesquisa-estrelas { display: flex; gap: 3px; padding-top: 1.1rem; font-size: 1.3rem; color: var(--rb-warning); }
/* cada estrela: o contorno de fundo (apagado) e, por cima, a estrela cheia recortada até --p (0 a 100 %) */
.pesquisa-estrela { position: relative; display: inline-block; width: 1em; height: 1em; line-height: 1; }
.pesquisa-estrela .bi { position: absolute; inset: 0; }
.pesquisa-estrela .bi-star { opacity: .35; }
.pesquisa-estrela .bi-star-fill { clip-path: inset(0 calc(100% - var(--p, 0%)) 0 0); }
.pesquisa-quesitos,
.pesquisa-sugestao {
  padding: var(--rb-space-3) var(--rb-space-4);
  background: var(--rb-surface);
  border: 1px solid var(--rb-border);
  border-radius: var(--rb-radius-lg);
}
.pesquisa-linha { display: grid; grid-template-columns: minmax(120px, 38%) minmax(0, 1fr) 2.2ch; align-items: center; gap: var(--rb-space-3); padding: 5px 0; }
.pesquisa-nome { color: var(--rb-text); }
.pesquisa-barra { height: 8px; overflow: hidden; border-radius: var(--rb-radius-pill); background: var(--rb-surface-3); }
.pesquisa-barra i { display: block; height: 100%; border-radius: inherit; background: var(--rb-cat-10); }
.pesquisa-valor { text-align: right; color: var(--rb-text); }
.pesquisa-mais summary { padding-top: 4px; font-size: var(--rb-fs-sm); color: var(--rb-text-muted); cursor: pointer; }
.pesquisa-sugestao span { display: block; font-size: var(--rb-fs-sm); color: var(--rb-text-muted); }
.pesquisa-sugestao p { margin: 2px 0 0; overflow-wrap: anywhere; color: var(--rb-text); }
.pesquisa-quem { font-size: var(--rb-fs-xs); color: var(--rb-text-muted); }
@media (max-width: 575.98px) {
  .pesquisa-nota { font-size: 2.2rem; }
  .pesquisa-estrelas { padding-top: 0; font-size: 1.1rem; }
  .pesquisa-linha { grid-template-columns: minmax(0, 1fr) 2.2ch; row-gap: 2px; }
  .pesquisa-barra { grid-column: 1 / -1; grid-row: 2; }
}
