* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif; background: #eef0f2; }

.page { display: flex; flex-direction: column; height: 100vh; }
.app { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 320px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #ddd;
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid #eee;
}
.sidebar-header h1 { font-size: 18px; margin: 0; }
.sidebar-header-right { display: flex; align-items: center; gap: 8px; }
.current-user { font-size: 12px; color: #666; }
.btn-logout {
  border: none; background: none; cursor: pointer; color: #999; font-size: 15px;
  padding: 0 2px; line-height: 1;
}
.btn-logout:hover { color: #c0392b; }

.status-dot {
  width: 10px; height: 10px; border-radius: 50%; background: #ccc; display: inline-block;
}
.status-dot.connected { background: #2ecc71; }
.status-dot.qr { background: #f39c12; }
.status-dot.disconnected { background: #e74c3c; }

.tabs { display: flex; border-bottom: 1px solid #eee; }
.tab {
  flex: 1; padding: 10px; border: none; background: none; cursor: pointer;
  font-size: 13px; color: #666; border-bottom: 2px solid transparent;
}
.tab.active { color: #128c7e; border-bottom-color: #128c7e; font-weight: 600; }

.ticket-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.ticket-item {
  padding: 12px 16px; border-bottom: 1px solid #f2f2f2; cursor: pointer;
}
.ticket-item:hover { background: #f7f7f7; }
.ticket-item.selected { background: #e8f5f3; }
.ticket-item .name { font-weight: 600; font-size: 14px; }
.ticket-item .preview { font-size: 12px; color: #777; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-item .attendant-badge {
  display: inline-block; margin-top: 4px; font-size: 11px; padding: 1px 7px; border-radius: 10px;
  background: #eef0f2; color: #666;
}
.ticket-item .attendant-badge.unassigned { background: #fff3cd; color: #7a5c00; }
.ticket-item .department-badge {
  display: inline-block; margin-top: 4px; margin-right: 4px; font-size: 11px; padding: 1px 7px;
  border-radius: 10px; background: #e5eefc; color: #1a5fb4;
}

/* aba "Contatos" (réplica do Digisac) — reaproveita .ticket-list/.ticket-item pro visual da
   lista, só troca o conteúdo de cada item (telefone em vez de preview de mensagem) */
.contacts-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.contacts-toolbar { display: flex; gap: 6px; padding: 8px 16px; }
.contacts-toolbar input {
  flex: 1; padding: 6px 8px; border: 1px solid #ccc; border-radius: 6px; font-size: 12px;
}
.contacts-toolbar button {
  padding: 6px 10px; border: none; border-radius: 6px; background: #128c7e; color: #fff;
  font-size: 12px; cursor: pointer; white-space: nowrap;
}
.contacts-toolbar button:hover { background: #0f7469; }

/* busca nas abas Abertas/Fila/Fechadas — mesmo visual do campo de busca da aba Contatos */
.tickets-toolbar { padding: 8px 16px; }
.tickets-toolbar input {
  width: 100%; padding: 6px 8px; border: 1px solid #ccc; border-radius: 6px; font-size: 12px;
}
.contact-item .name { font-weight: 600; font-size: 14px; }
.contact-item .phone { font-size: 12px; color: #777; }
.contacts-empty { padding: 24px 16px; text-align: center; color: #999; font-size: 13px; }

.chat { flex: 1; display: flex; flex-direction: column; background: #f5f6f7; }
.chat-empty { margin: auto; color: #999; }
.chat-active { display: flex; flex-direction: column; height: 100%; }
.hidden { display: none !important; }

/* Dados do contato (aba "Contatos", clicar num contato antes de abrir conversa) */
.contact-details { flex: 1; display: flex; align-items: center; justify-content: center; }
.contact-details-card {
  background: #fff; border-radius: 10px; padding: 28px 32px; width: 320px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06); display: flex; flex-direction: column; gap: 14px;
}
.contact-details-header { display: flex; align-items: baseline; }
.contact-details-header .chat-name-display strong { font-size: 18px; }
.contact-details-fields { margin: 0; }
.contact-details-fields dt { font-size: 11px; color: #999; text-transform: uppercase; margin-top: 10px; }
.contact-details-fields dt:first-child { margin-top: 0; }
.contact-details-fields dd { margin: 2px 0 0; font-size: 14px; color: #333; }
.btn-open-conversation {
  margin-top: 6px; padding: 10px; border: none; border-radius: 6px; background: #128c7e;
  color: #fff; font-size: 14px; cursor: pointer;
}
.btn-open-conversation:hover { background: #0f7469; }
.btn-delete-contact {
  padding: 8px; border: 1px solid #f5c6cb; border-radius: 6px; background: #fff;
  color: #c0392b; font-size: 13px; cursor: pointer;
}
.btn-delete-contact:hover { background: #fdecea; }

/* nome do contato no cabeçalho da conversa — clicável, abre o popup de informações */
.chat-contact-name-clickable { cursor: pointer; }
.chat-contact-name-clickable:hover { text-decoration: underline; text-decoration-color: #128c7e; }

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; background: #fff; border-bottom: 1px solid #ddd;
}
.chat-header .muted { font-size: 12px; color: #888; }
.chat-header-contact { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 8px; }
.chat-header-contact .muted { flex-basis: 100%; }
.chat-name-display { display: inline-flex; align-items: baseline; gap: 4px; }
.btn-rename {
  border: none; background: none; cursor: pointer; color: #888; font-size: 14px;
  padding: 0 2px; line-height: 1;
}
.btn-rename:hover { color: #128c7e; }

.chat-name-input {
  font: inherit; font-weight: 600; font-size: 15px; /* casa com o <strong> do cabeçalho */
  border: none; border-bottom: 2px solid #128c7e; background: #f5f6f7;
  padding: 1px 4px; border-radius: 3px; outline: none; min-width: 180px;
}
.chat-actions button {
  margin-left: 8px; padding: 6px 12px; border: 1px solid #ccc; background: #fff;
  border-radius: 6px; cursor: pointer; font-size: 13px;
}
.chat-actions button:hover { background: #f0f0f0; }
.assign-select {
  padding: 5px 8px; border: 1px solid #ccc; border-radius: 6px; font-size: 13px;
  background: #fff; max-width: 160px;
}

.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 60%; padding: 8px 12px; border-radius: 10px; font-size: 14px; line-height: 1.4; }
.msg.in { align-self: flex-start; background: #fff; border: 1px solid #eee; }
.msg.out { align-self: flex-end; background: #d9fdd3; }
.msg .time { display: block; font-size: 10px; color: #999; margin-top: 4px; text-align: right; }

/* mensagem enviada pelo bot de triagem (fase 6) — precisa se destacar de uma resposta humana,
   senão parece que alguém do time já atendeu esse ticket */
.msg.origin-bot { background: #fff3cd; border: 1px solid #ffe69c; }
.bot-tag { display: block; font-size: 11px; font-weight: 600; color: #8a6d1a; margin-bottom: 2px; }

/* mídia dentro da bolha de mensagem — imagem/vídeo/áudio/documento */
.msg.type-image, .msg.type-sticker, .msg.type-video, .msg.type-audio, .msg.type-document {
  padding: 6px; max-width: 70%;
}
.msg-media { display: block; max-width: 100%; border-radius: 6px; }
.msg-image { max-height: 260px; object-fit: cover; cursor: pointer; }
audio.msg-media { width: 260px; height: 40px; }
video.msg-media { max-height: 260px; }
.msg-caption { padding: 6px 4px 2px; font-size: 14px; }
.msg-document {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  background: rgba(0,0,0,0.04); border-radius: 6px; color: #128c7e; text-decoration: none;
  font-size: 13px; word-break: break-all;
}
.msg-document:hover { background: rgba(0,0,0,0.08); }
.msg-media-missing {
  padding: 8px 10px; font-size: 13px; color: #999; font-style: italic;
}

.send-error {
  margin: 0 20px; padding: 8px 12px; background: #fdecea; color: #c0392b;
  border: 1px solid #f5c6cb; border-radius: 6px; font-size: 13px;
}

.send-form { display: flex; gap: 8px; padding: 14px 20px; background: #fff; border-top: 1px solid #ddd; align-items: center; }
.send-form input[type="text"] { flex: 1; padding: 10px 12px; border: 1px solid #ccc; border-radius: 20px; font-size: 14px; }
.send-form button[type="submit"] {
  padding: 10px 18px; border: none; border-radius: 20px; background: #128c7e; color: #fff; cursor: pointer;
}
.send-form button[type="submit"]:hover { background: #0f7469; }

.btn-attach {
  flex-shrink: 0; width: 38px; height: 38px; border-radius: 50%; border: 1px solid #ccc;
  background: #fff; cursor: pointer; font-size: 16px; line-height: 1;
}
.btn-attach:hover { background: #f0f0f0; }

.attachment-preview {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 0 20px 8px; padding: 8px 12px; background: #eef7f5; border: 1px solid #cdeae4;
  border-radius: 6px; font-size: 13px; color: #0f5c52;
}
.attachment-preview span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#btn-remove-attachment {
  flex-shrink: 0; border: none; background: none; cursor: pointer; color: #c0392b; font-size: 13px;
}

/* Banner não-bloqueante (não é mais um overlay fixed cobrindo a tela — isso trancava a
   atendente fora do painel inteiro enquanto o WhatsApp não estivesse "open", inclusive
   impedindo ver conversas já abertas). Só o formulário de envio depende de estar conectado. */
.wa-banner {
  flex-shrink: 0; display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; background: #fff3cd; color: #7a5c00;
  border-bottom: 1px solid #ffe69c; font-size: 13px;
}
.wa-banner img { width: 90px; height: 90px; border-radius: 4px; }
.wa-banner button {
  padding: 6px 16px; border: none; border-radius: 16px;
  background: #128c7e; color: #fff; font-size: 13px; cursor: pointer;
}
.wa-banner button:hover { background: #0f7469; }
.wa-banner button:disabled { opacity: 0.6; cursor: default; }

.login-screen {
  position: fixed; inset: 0; background: #eef0f2;
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.login-box {
  background: #fff; padding: 36px 32px; border-radius: 10px; width: 320px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08); display: flex; flex-direction: column; gap: 12px;
}
.login-box h2 { margin: 0 0 8px; font-size: 18px; text-align: center; color: #128c7e; }
.login-box input {
  padding: 10px 12px; border: 1px solid #ccc; border-radius: 6px; font-size: 14px;
}
.login-box button {
  padding: 10px; border: none; border-radius: 6px; background: #128c7e; color: #fff;
  font-size: 14px; cursor: pointer; margin-top: 4px;
}
.login-box button:hover { background: #0f7469; }
.login-error {
  background: #fdecea; color: #c0392b; border: 1px solid #f5c6cb;
  border-radius: 6px; padding: 8px 10px; font-size: 13px;
}

.btn-icon {
  border: none; background: none; cursor: pointer; color: #999; font-size: 15px;
  padding: 0 2px; line-height: 1;
}
.btn-icon:hover { color: #128c7e; }

/* modal genérico (troca de senha por enquanto) — mesmo visual da tela de login, mas por cima
   do painel em vez de substituir a tela inteira */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 300;
}
.modal-box {
  background: #fff; padding: 28px 32px; border-radius: 10px; width: 320px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15); display: flex; flex-direction: column; gap: 8px;
}
.modal-box h2 { margin: 0 0 4px; font-size: 18px; color: #128c7e; }
.modal-box label { font-size: 13px; color: #555; margin-top: 4px; }
.modal-box input {
  padding: 10px 12px; border: 1px solid #ccc; border-radius: 6px; font-size: 14px;
}
.modal-hint { font-size: 12px; color: #888; margin: 0 0 4px; }
.modal-success {
  background: #e8f8f0; color: #128c7e; border: 1px solid #b7e8d3;
  border-radius: 6px; padding: 8px 10px; font-size: 13px;
}
.modal-actions { display: flex; gap: 8px; margin-top: 8px; }
.modal-actions button {
  flex: 1; padding: 10px; border: none; border-radius: 6px; font-size: 14px; cursor: pointer;
}
.modal-actions button[type="submit"] { background: #128c7e; color: #fff; }
.modal-actions button[type="submit"]:hover { background: #0f7469; }
.btn-secondary { background: #eee; color: #333; }
.btn-secondary:hover { background: #e2e2e2; }
