/* TotalZap & WAHA - Central de Mensagens Interativas & Ligações de Voz */

/* 0. Supressão definitiva de barras e widgets flutuantes secundários */
#tz-call-floating-pill,
#tz-pwa-active-bar,
.tz-pwa-active-bar,
.tz-native-call-elevated {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  opacity: 0 !important;
  height: 0 !important;
  width: 0 !important;
}

/* 0.1 No Mobile/PWA: ocultar o widget flutuante estilo desktop (fixed left-8 bottom-6) */
@media (max-width: 1024px) {
  .fixed.left-8.bottom-6,
  [class*="left-8"][class*="bottom-6"],
  div.fixed:has(button[title*="End call"]),
  div.fixed:has(button[title*="Encerrar chamada"]) {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
    opacity: 0 !important;
  }
}

/* 0.2 Ocultação do botão verde legado (mantendo apenas botão nativo no cabeçalho) */
#tz-pwa-central-call-bar,
.tz-pwa-central-call-bar,
#tz-btn-pwa-call,
.tz-pwa-central-call-btn {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  opacity: 0 !important;
  height: 0 !important;
  width: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
}

/* 0.3 Barra Flutuante de Chamada Ativa no PWA (Sempre na Frente) */
.tz-pwa-active-bar {
  position: fixed !important;
  top: max(12px, env(safe-area-inset-top)) !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  z-index: 99999999 !important;
  background: rgba(17, 24, 39, 0.96) !important;
  backdrop-filter: blur(16px) !important;
  -webkit-backdrop-filter: blur(16px) !important;
  color: #ffffff !important;
  padding: 8px 16px !important;
  border-radius: 9999px !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3) !important;
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  max-width: calc(100vw - 20px) !important;
  animation: tzSlideDown 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
  pointer-events: auto !important;
}

@keyframes tzSlideDown {
  0% { transform: translateX(-50%) translateY(-20px) scale(0.95); opacity: 0; }
  100% { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }
}

.tz-pulse-green {
  width: 10px;
  height: 10px;
  background: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: tzPulseRing 2s infinite ease-in-out;
  flex-shrink: 0;
}

@keyframes tzPulseRing {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.tz-pwa-active-bar .tz-call-title {
  color: #9ca3af;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.tz-pwa-active-bar .tz-call-timer {
  font-weight: 700;
  color: #10b981;
  font-variant-numeric: tabular-nums;
}

.tz-pwa-active-bar .tz-btn-action {
  border: none;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  user-select: none;
  white-space: nowrap;
}

.tz-pwa-active-bar .tz-btn-mute {
  background: #374151;
  color: #ffffff;
}

.tz-pwa-active-bar .tz-btn-mute.muted {
  background: #f59e0b;
  color: #ffffff;
}

.tz-pwa-active-bar .tz-btn-hangup {
  background: #ef4444;
  color: #ffffff;
}

.tz-pwa-active-bar .tz-btn-hangup:hover {
  background: #dc2626;
}

/* 1. Botão de Chamada no Header da Conversa */
.tz-btn-call-whatsapp {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff !important;
  font-weight: 600;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 9999px;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.3);
  transition: all 0.2s ease;
  margin-right: 8px;
  user-select: none;
}
.tz-btn-call-whatsapp:hover {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.4);
}
.tz-btn-call-whatsapp:active {
  transform: translateY(0);
}
.tz-btn-call-whatsapp svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

/* 2. Botão de Mensagem Interativa no Composer */
.tz-btn-composer-interactive {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: #64748b;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-right: 4px;
}
.tz-btn-composer-interactive:hover {
  background: #f1f5f9;
  color: #0f172a;
  border-color: #cbd5e1;
}
.dark .tz-btn-composer-interactive:hover {
  background: #334155;
  color: #f8fafc;
  border-color: #475569;
}

/* 3. Modal / Drawer da Central Interativa WAHA */
#tz-interactive-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
#tz-interactive-modal-overlay.tz-open {
  opacity: 1;
  pointer-events: auto;
}

.tz-modal-card {
  background: #ffffff;
  border-radius: 20px;
  width: 100%;
  max-width: 980px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  transform: scale(0.96) translateY(10px);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
#tz-interactive-modal-overlay.tz-open .tz-modal-card {
  transform: scale(1) translateY(0);
}
.dark .tz-modal-card {
  background: #1e293b;
  color: #f8fafc;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.tz-modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
}
.dark .tz-modal-header {
  background: #0f172a;
  border-bottom-color: #334155;
}
.tz-modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  color: #0f172a;
}
.dark .tz-modal-title {
  color: #f8fafc;
}
.tz-modal-title .tz-badge {
  background: #10b981;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tz-btn-close {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.tz-btn-close:hover {
  background: #e2e8f0;
  color: #0f172a;
}
.dark .tz-btn-close:hover {
  background: #334155;
  color: #f8fafc;
}

/* Tabs do Modal */
.tz-tabs {
  display: flex;
  padding: 0 24px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  gap: 8px;
}
.dark .tz-tabs {
  background: #0f172a;
  border-bottom-color: #334155;
}
.tz-tab-btn {
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 600;
  color: #64748b;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tz-tab-btn:hover {
  color: #0f172a;
}
.dark .tz-tab-btn:hover {
  color: #cbd5e1;
}
.tz-tab-btn.active {
  color: #10b981;
  border-bottom-color: #10b981;
}

/* Corpo Principal do Modal com 2 Colunas (Form + Preview) */
.tz-modal-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.tz-tab-content {
  display: none;
  width: 100%;
  height: 100%;
  overflow-y: auto;
}
.tz-tab-content.active {
  display: flex;
}

/* Coluna Esquerda: Formulário / Configuração */
.tz-form-col {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  border-right: 1px solid #e2e8f0;
}
.dark .tz-form-col {
  border-right-color: #334155;
}

/* Coluna Direita: Simulador Celular WhatsApp */
.tz-preview-col {
  width: 380px;
  background: #f1f5f9;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
}
.dark .tz-preview-col {
  background: #0f172a;
}

/* Phone Mockup */
.tz-phone-mockup {
  width: 320px;
  background: #0b141a;
  border-radius: 36px;
  padding: 12px;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.4), 0 0 0 4px #222d34;
  border: 1px solid #334155;
  display: flex;
  flex-direction: column;
}
.tz-phone-screen {
  background: #efeae2;
  background-image: radial-gradient(#d1d7db 1px, transparent 1px);
  background-size: 16px 16px;
  border-radius: 26px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 480px;
}
.dark .tz-phone-screen {
  background: #0b141a;
  background-image: radial-gradient(#1f2c34 1px, transparent 1px);
  background-size: 16px 16px;
}
.tz-phone-header {
  background: #008069;
  color: #ffffff;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
}
.tz-phone-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #ffffff;
  color: #008069;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}
.tz-phone-chat-body {
  flex: 1;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

/* WhatsApp Message Bubble */
.tz-wa-bubble {
  background: #d9fdd3;
  color: #111b21;
  border-radius: 10px 10px 0 10px;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
  margin-bottom: 4px;
  align-self: flex-end;
  max-width: 90%;
  word-break: break-word;
}
.dark .tz-wa-bubble {
  background: #005c4b;
  color: #e9edef;
}
.tz-wa-header-img {
  width: 100%;
  border-radius: 8px;
  margin-bottom: 6px;
  max-height: 140px;
  object-fit: cover;
  display: block;
}
.tz-wa-header-title {
  font-weight: 700;
  font-size: 13.5px;
  margin-bottom: 4px;
  color: #0f172a;
}
.dark .tz-wa-header-title {
  color: #ffffff;
}
.tz-wa-body-text {
  white-space: pre-wrap;
}
.tz-wa-footer-text {
  font-size: 11px;
  color: #667781;
  margin-top: 6px;
}
.dark .tz-wa-footer-text {
  color: #8696a0;
}
.tz-wa-meta {
  font-size: 10px;
  color: #667781;
  text-align: right;
  margin-top: 2px;
}
.dark .tz-wa-meta {
  color: #8696a0;
}

/* Botões do WhatsApp anexados ao balão */
.tz-wa-buttons-container {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-self: flex-end;
  width: 90%;
}
.tz-wa-btn-pill {
  background: #ffffff;
  color: #00a884;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  user-select: none;
  cursor: pointer;
  border: none;
  transition: background 0.15s ease;
}
.dark .tz-wa-btn-pill {
  background: #1f2c34;
  color: #00a884;
}
.tz-wa-btn-pill:hover {
  background: #f0f2f5;
}
.dark .tz-wa-btn-pill:hover {
  background: #2a3942;
}

/* Modelos Grid */
.tz-templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  padding: 24px;
  width: 100%;
}
.tz-template-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
}
.dark .tz-template-card {
  background: #1e293b;
  border-color: #334155;
}
.tz-template-card:hover {
  border-color: #10b981;
  transform: translateY(-2px);
  box-shadow: 0 8px 16px -4px rgba(16, 185, 129, 0.15);
}
.tz-template-icon {
  font-size: 24px;
  margin-bottom: 8px;
}
.tz-template-title {
  font-size: 14px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}
.dark .tz-template-title {
  color: #f8fafc;
}
.tz-template-desc {
  font-size: 12px;
  color: #64748b;
  line-height: 1.4;
  margin-bottom: 12px;
  flex: 1;
}
.tz-template-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tz-template-pill {
  font-size: 10px;
  font-weight: 600;
  background: #f1f5f9;
  color: #475569;
  padding: 2px 8px;
  border-radius: 9999px;
}
.dark .tz-template-pill {
  background: #334155;
  color: #94a3b8;
}

/* Formulário de Campos */
.tz-form-group {
  margin-bottom: 16px;
}
.tz-form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 6px;
}
.dark .tz-form-label {
  color: #cbd5e1;
}
.tz-input, .tz-textarea, .tz-select {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
  color: #0f172a;
  outline: none;
  transition: border-color 0.15s ease;
}
.dark .tz-input, .dark .tz-textarea, .dark .tz-select {
  background: #0f172a;
  border-color: #334155;
  color: #f8fafc;
}
.tz-input:focus, .tz-textarea:focus, .tz-select:focus {
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}
.tz-textarea {
  min-height: 80px;
  resize: vertical;
}

/* Construtor Dinâmico de Botões */
.tz-buttons-builder {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px;
}
.dark .tz-buttons-builder {
  background: #0f172a;
  border-color: #334155;
}
.tz-button-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  background: #ffffff;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}
.dark .tz-button-row {
  background: #1e293b;
  border-color: #334155;
}
.tz-btn-remove {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  font-size: 16px;
}
.tz-btn-remove:hover {
  background: #fee2e2;
}

/* Alerta de Validação Técnica */
.tz-alert-validation {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 16px;
  display: none;
}
.tz-alert-validation.active {
  display: block;
}

/* Rodapé do Modal com Ações */
.tz-modal-footer {
  padding: 14px 24px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background: #f8fafc;
}
.dark .tz-modal-footer {
  background: #0f172a;
  border-top-color: #334155;
}
.tz-btn-secondary {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  background: #ffffff;
  color: #475569;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  cursor: pointer;
}
.dark .tz-btn-secondary {
  background: #1e293b;
  color: #cbd5e1;
  border-color: #475569;
}
.tz-btn-primary {
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  background: #10b981;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s ease;
}
.tz-btn-primary:hover {
  background: #059669;
}
.tz-btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Renderização de Botões no Feed de Mensagens do Chatwoot */
.tz-chat-interactive-pills {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tz-chat-interactive-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid rgba(16, 185, 129, 0.2);
  text-decoration: none;
}
.dark .tz-chat-interactive-pill {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.3);
}

/* Chip/Badge de Atalho no Campo de Digitação (Composer) */
.tz-composer-inline-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #f0fdf4;
  color: #166534;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 9999px;
  border: 1px solid #bbf7d0;
  cursor: pointer;
  transition: all 0.15s ease;
  margin: 4px 6px;
  user-select: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.tz-composer-inline-chip:hover {
  background: #dcfce7;
  border-color: #86efac;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(22, 101, 52, 0.15);
}
.dark .tz-composer-inline-chip {
  background: #064e3b;
  color: #a7f3d0;
  border-color: #047857;
}
.dark .tz-composer-inline-chip:hover {
  background: #065f46;
  border-color: #059669;
}

/* Botão de Inserir no Editor (Modal Footer) */
.tz-btn-insert-editor {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  background: #f8fafc;
  color: #0f172a;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}
.tz-btn-insert-editor:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
  color: #059669;
}
.dark .tz-btn-insert-editor {
  background: #1e293b;
  color: #f8fafc;
  border-color: #475569;
}
.dark .tz-btn-insert-editor:hover {
  background: #334155;
  color: #34d399;
}

/* Ações dos Cards de Modelos */
.tz-template-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.tz-template-btn-insert {
  flex: 1;
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #cbd5e1;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
}
.tz-template-btn-insert:hover {
  background: #e2e8f0;
  color: #059669;
  border-color: #10b981;
}
.dark .tz-template-btn-insert {
  background: #334155;
  color: #cbd5e1;
  border-color: #475569;
}
.dark .tz-template-btn-insert:hover {
  background: #475569;
  color: #34d399;
}
.tz-template-btn-open {
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  background: #10b981;
  color: #ffffff;
  border: none;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
}
.tz-template-btn-open:hover {
  background: #059669;
}
