/* ==============================================
   DISPARADOR WHATSAPP — Monitora Chat CRM
   Módulo de Disparo de Mensagens via API Oficial Meta
   ============================================== */

/* ── Overlay Principal ── */
#wpp-dispatcher-overlay {
  position: fixed;
  inset: 0;
  background: #f0f4f8;
  z-index: 9980;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Inter', 'Segoe UI', sans-serif;
}
#wpp-dispatcher-overlay.open {
  display: flex;
}

/* ── Board Container ── */
#wpp-dispatcher-board {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* ── Header ── */
.wpp-header {
  background: linear-gradient(135deg, #128C7E 0%, #075E54 100%);
  padding: 20px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
.wpp-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.wpp-header-icon {
  width: 40px; height: 40px;
  background: rgba(255,255,255,0.2);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.wpp-header-icon svg { width: 22px; height: 22px; }
.wpp-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  flex-direction: column;
}
.wpp-header h1 small {
  font-size: 0.75rem;
  font-weight: 400;
  color: rgba(255,255,255,0.75);
  margin-top: 2px;
}
.wpp-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Botões ── */
.wpp-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 8px;
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  white-space: nowrap;
}
.wpp-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.wpp-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.wpp-btn-primary {
  background: #25D366;
  color: #fff;
}
.wpp-btn-primary:hover:not(:disabled) { background: #1dbc5a; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(37,211,102,0.3); }

.wpp-btn-secondary {
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
}
.wpp-btn-secondary:hover:not(:disabled) { background: rgba(255,255,255,0.3); }

.wpp-btn-ghost {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}
.wpp-btn-ghost:hover:not(:disabled) { background: #e2e8f0; }

.wpp-btn-danger {
  background: #fee2e2;
  color: #dc2626;
}
.wpp-btn-danger:hover:not(:disabled) { background: #fecaca; }

.wpp-btn-sm {
  padding: 6px 12px;
  font-size: 0.78rem;
}

/* ── Layout do conteúdo ── */
.wpp-content {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 0;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar esquerda ── */
.wpp-sidebar {
  background: #fff;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.wpp-sidebar-section {
  border-bottom: 1px solid #f1f5f9;
  padding: 16px 20px;
}
.wpp-sidebar-section:last-child { border-bottom: none; }
.wpp-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
  margin: 0 0 12px 0;
}

/* ── Template Selector ── */
.wpp-template-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}
.wpp-template-item {
  padding: 10px 14px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 0.84rem;
}
.wpp-template-item:hover { border-color: #128C7E; background: #f0faf9; }
.wpp-template-item.selected { border-color: #128C7E; background: #e6f7f5; }
.wpp-template-item.disabled {
  cursor: not-allowed;
  background: #f8fafc;
  opacity: 0.72;
}
.wpp-template-item.disabled:hover {
  border-color: #e2e8f0;
  background: #f8fafc;
}
.wpp-template-item-name {
  font-weight: 600;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 6px;
}
.wpp-template-item-meta {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 3px;
  display: flex;
  gap: 8px;
}
.wpp-template-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}
.wpp-template-badge.marketing { background: #fef3c7; color: #d97706; }
.wpp-template-badge.utility { background: #dbeafe; color: #1d4ed8; }
.wpp-template-badge.authentication { background: #f3e8ff; color: #7e22ce; }
.wpp-template-badge.approved { background: #dcfce7; color: #16a34a; }
.wpp-template-status {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 0.68rem;
  font-weight: 700;
}
.wpp-template-status.approved { background: #dcfce7; color: #16a34a; }
.wpp-template-status.pending,
.wpp-template-status.in_review { background: #fef3c7; color: #b45309; }
.wpp-template-status.rejected,
.wpp-template-status.disabled { background: #fee2e2; color: #dc2626; }
.wpp-template-status.paused { background: #e0e7ff; color: #4338ca; }

.wpp-template-diagnostics {
  padding: 8px 10px;
  background: #eef6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: #1e40af;
  font-size: 0.72rem;
  line-height: 1.45;
}
.wpp-template-diagnostics span { color: #64748b; }

.wpp-empty-templates {
  padding: 16px;
  text-align: center;
  color: #64748b;
  font-size: 0.82rem;
  background: #f8fafc;
  border-radius: 8px;
  border: 1.5px dashed #cbd5e1;
  line-height: 1.6;
}
.wpp-empty-templates a {
  color: #128C7E;
  font-weight: 600;
  text-decoration: none;
}
.wpp-empty-templates a:hover { text-decoration: underline; }
.wpp-empty-templates b { color: #334155; }
.wpp-empty-template-detail {
  margin-top: 10px;
}
.wpp-empty-templates code {
  background: #e2e8f0;
  border-radius: 4px;
  padding: 1px 5px;
  color: #334155;
  font-family: 'Courier New', monospace;
  font-size: 0.78rem;
}

/* ── Variáveis Dinâmicas ── */
.wpp-variables-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wpp-var-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.wpp-var-label {
  font-size: 0.78rem;
  color: #64748b;
  min-width: 40px;
  font-weight: 500;
}
.wpp-var-input {
  flex: 1;
  padding: 7px 10px;
  border: 1.5px solid #e2e8f0;
  border-radius: 7px;
  font-size: 0.83rem;
  color: #1e293b;
  transition: border-color 0.15s;
  background: #fff;
}
.wpp-var-input:focus {
  outline: none;
  border-color: #128C7E;
}

/* ── Envio de Texto Livre ── */
.wpp-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.84rem;
  color: #1e293b;
  resize: vertical;
  min-height: 80px;
  font-family: inherit;
  transition: border-color 0.15s;
  box-sizing: border-box;
}
.wpp-textarea:focus { outline: none; border-color: #128C7E; }
.wpp-char-count {
  font-size: 0.72rem;
  color: #94a3b8;
  text-align: right;
  margin-top: 4px;
}
.wpp-char-count.over { color: #dc2626; }

/* ── Área principal direita ── */
.wpp-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px 24px;
  gap: 16px;
}

/* ── Seção de Destinatários ── */
.wpp-recipients-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.wpp-recipients-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 8px;
}
.wpp-recipients-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: #128C7E;
  color: #fff;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 700;
}
.wpp-recipients-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.wpp-funnel-column-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #64748b;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.wpp-select {
  min-width: 190px;
  height: 31px;
  padding: 6px 10px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  color: #334155;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}
.wpp-select:focus {
  outline: none;
  border-color: #128C7E;
}
.wpp-select:disabled {
  background: #f8fafc;
  color: #94a3b8;
  cursor: not-allowed;
}
.wpp-file-input {
  display: none;
}
.wpp-add-recipient-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.wpp-cost-estimate {
  display: grid;
  grid-template-columns: minmax(160px, auto) 1fr;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid #c7d2fe;
  border-left: 4px solid #128C7E;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.wpp-cost-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.wpp-cost-main span {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #64748b;
}
.wpp-cost-main strong {
  color: #0f766e;
  font-size: 1.2rem;
  line-height: 1.15;
}
.wpp-cost-main small {
  color: #64748b;
  font-size: 0.76rem;
  font-weight: 600;
}
.wpp-cost-copy {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.wpp-cost-detail {
  color: #1e293b;
  font-size: 0.82rem;
  font-weight: 600;
}
.wpp-cost-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  color: #64748b;
  font-size: 0.74rem;
}
.wpp-cost-muted,
.wpp-cost-warning {
  font-size: 0.74rem;
  line-height: 1.35;
}
.wpp-cost-muted { color: #94a3b8; }
.wpp-cost-warning { color: #b45309; }

.wpp-input {
  flex: 1;
  padding: 9px 12px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.85rem;
  color: #1e293b;
  transition: border-color 0.15s;
  font-family: inherit;
}
.wpp-input:focus { outline: none; border-color: #128C7E; }
.wpp-input.error { border-color: #ef4444; }

/* ── Tabela de Destinatários ── */
.wpp-recipients-table-wrap {
  flex: 1;
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #fff;
}
.wpp-recipients-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}
.wpp-recipients-table th {
  background: #f8fafc;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: #64748b;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 0;
}
.wpp-recipients-table td {
  padding: 10px 14px;
  border-bottom: 1px solid #f1f5f9;
  color: #1e293b;
  vertical-align: middle;
}
.wpp-recipients-table tr:last-child td { border-bottom: none; }
.wpp-recipients-table tr:hover td { background: #f8fafc; }
.wpp-recipients-table tr.wpp-recipient-blocked td { background: #fff7ed; }
.wpp-recipients-table tr.wpp-recipient-blocked:hover td { background: #ffedd5; }
.wpp-recipients-table input[type="checkbox"] { cursor: pointer; accent-color: #128C7E; width: 16px; height: 16px; }

/* Status de resultado */
.wpp-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 0.73rem;
  font-weight: 600;
}
.wpp-status-badge.pending { background: #f1f5f9; color: #64748b; }
.wpp-status-badge.sending { background: #fef3c7; color: #d97706; }
.wpp-status-badge.success { background: #dcfce7; color: #16a34a; }
.wpp-status-badge.error   { background: #fee2e2; color: #dc2626; }

.wpp-origin-badge,
.wpp-eligibility-badge {
  display: inline-flex;
  align-items: center;
  max-width: 150px;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wpp-origin-badge.funnel { background: #e0f2fe; color: #0369a1; }
.wpp-origin-badge.csv { background: #f1f5f9; color: #475569; }
.wpp-origin-badge.manual { background: #fef3c7; color: #92400e; }
.wpp-eligibility-badge.ok { background: #dcfce7; color: #166534; }
.wpp-eligibility-badge.warn { background: #fef9c3; color: #854d0e; }
.wpp-eligibility-badge.error { background: #fee2e2; color: #991b1b; }

/* Número formatado */
.wpp-phone-display {
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
  color: #334155;
}
.wpp-phone-invalid { color: #ef4444; font-style: italic; }

/* ── Barra de Progresso ── */
.wpp-progress-wrap {
  background: #f1f5f9;
  border-radius: 8px;
  padding: 14px 18px;
  display: none;
}
.wpp-progress-wrap.visible { display: block; }
.wpp-progress-label {
  font-size: 0.82rem;
  color: #475569;
  font-weight: 500;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
}
.wpp-progress-bar-bg {
  background: #e2e8f0;
  border-radius: 99px;
  height: 8px;
  overflow: hidden;
}
.wpp-progress-bar-fill {
  background: linear-gradient(90deg, #128C7E, #25D366);
  height: 100%;
  border-radius: 99px;
  transition: width 0.4s ease;
  width: 0%;
}
.wpp-progress-stats {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 0.78rem;
}
.wpp-progress-stat-ok  { color: #16a34a; font-weight: 600; }
.wpp-progress-stat-err { color: #dc2626; font-weight: 600; }
.wpp-progress-stat-tot { color: #64748b; }

/* ── Preview do Template ── */
.wpp-preview-card {
  background: #fff;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px;
  font-size: 0.84rem;
}
.wpp-preview-header {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
  margin-bottom: 8px;
}
.wpp-preview-bubble {
  background: #dcf8c6;
  border-radius: 10px 10px 2px 10px;
  padding: 12px 14px;
  color: #1e293b;
  line-height: 1.55;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.wpp-preview-placeholder {
  color: #128C7E;
  font-weight: 600;
}

/* ── Formulário de Envio Individual ── */
.wpp-single-send-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

/* ── Tabs ── */
.wpp-tabs {
  display: flex;
  gap: 4px;
  background: #f1f5f9;
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 12px;
}
.wpp-tab {
  flex: 1;
  padding: 7px 14px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.wpp-tab.active {
  background: #fff;
  color: #128C7E;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* ── Toast / Notificação ── */
.wpp-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  animation: wppToastIn 0.3s ease;
  max-width: 360px;
}
.wpp-toast.success { background: #166534; }
.wpp-toast.error   { background: #991b1b; }
@keyframes wppToastIn {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Info Box ── */
.wpp-info-box {
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.81rem;
  color: #92400e;
  line-height: 1.5;
  display: flex;
  gap: 10px;
}
.wpp-info-box svg { flex-shrink: 0; width: 18px; height: 18px; color: #d97706; }
.wpp-info-box a { color: #92400e; font-weight: 700; }

/* ── Scrollbar customizada ── */
.wpp-recipients-table-wrap::-webkit-scrollbar,
.wpp-template-list::-webkit-scrollbar,
.wpp-sidebar::-webkit-scrollbar { width: 5px; }
.wpp-recipients-table-wrap::-webkit-scrollbar-track,
.wpp-template-list::-webkit-scrollbar-track,
.wpp-sidebar::-webkit-scrollbar-track { background: #f1f5f9; }
.wpp-recipients-table-wrap::-webkit-scrollbar-thumb,
.wpp-template-list::-webkit-scrollbar-thumb,
.wpp-sidebar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }

/* ── Empty state ── */
.wpp-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: #94a3b8;
  font-size: 0.85rem;
  gap: 10px;
  text-align: center;
}
.wpp-empty-state svg { width: 40px; height: 40px; opacity: 0.4; }

/* ── Divider ── */
.wpp-divider {
  border: none;
  border-top: 1px solid #f1f5f9;
  margin: 12px 0;
}

/* ── Delete row btn ── */
.wpp-del-btn {
  background: none;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
}
.wpp-del-btn:hover { color: #ef4444; background: #fee2e2; }
.wpp-del-btn svg { width: 15px; height: 15px; }

/* ── Loading spinner ── */
.wpp-spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: wppSpin 0.7s linear infinite;
  display: inline-block;
}
@keyframes wppSpin { to { transform: rotate(360deg); } }

/* ── Sidebar scrollável ── */
.wpp-sidebar { overflow-y: auto; }

@media (max-width: 920px) {
  .wpp-cost-estimate {
    grid-template-columns: 1fr;
  }
}
