/* ═══════════════════════════════════════════════════════════════════
   WhatsApp Test Panel — Design System
   Dark theme premium com accent indigo
═══════════════════════════════════════════════════════════════════ */

/* ── Tokens de design ──────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg:           #080b14;
  --bg-surface:   #0d1021;
  --bg-card:      #111624;
  --bg-card-alt:  #141827;
  --bg-input:     #0c0f1d;

  /* Borders */
  --border:       rgba(255,255,255,0.06);
  --border-hover: rgba(255,255,255,0.10);
  --border-focus: rgba(99,102,241,0.50);

  /* Brand / Accent */
  --accent:       #6366f1;
  --accent-light: #818cf8;
  --accent-dim:   rgba(99,102,241,0.12);
  --accent-glow:  rgba(99,102,241,0.20);

  /* Semântica */
  --success:      #22c55e;
  --success-dim:  rgba(34,197,94,0.12);
  --warning:      #eab308;
  --warning-dim:  rgba(234,179,8,0.12);
  --danger:       #ef4444;
  --danger-dim:   rgba(239,68,68,0.12);
  --info:         #3b82f6;
  --info-dim:     rgba(59,130,246,0.12);

  /* Texto */
  --text:         #e2e8f0;
  --text-2:       #94a3b8;
  --text-muted:   #475569;
  --text-mono:    'Courier New', monospace;

  /* Raios */
  --r-sm:  6px;
  --r-md:  12px;
  --r-lg:  16px;
  --r-xl:  20px;

  /* Sombras */
  --shadow-sm:  0 1px 4px rgba(0,0,0,0.4);
  --shadow-md:  0 4px 20px rgba(0,0,0,0.5);
  --shadow-lg:  0 8px 40px rgba(0,0,0,0.6);

  /* Layout */
  --topbar-h:  58px;
  --sidebar-w: 340px;
  --gap:       16px;

  /* Transições */
  --t:         0.18s ease;
}

/* ── Reset & Base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar customizado */
::-webkit-scrollbar            { width: 5px; }
::-webkit-scrollbar-track     { background: transparent; }
::-webkit-scrollbar-thumb     { background: rgba(255,255,255,0.1); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover{ background: rgba(255,255,255,0.18); }

/* ── Layout geral ──────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: var(--accent-dim);
  border: 1px solid var(--border-focus);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-light);
}
.brand-icon svg { width: 18px; height: 18px; }

.brand-title  { font-size: 16px; font-weight: 700; color: var(--text); line-height: 1.2; }
.brand-subtitle{ font-size: 11px; color: var(--text-muted); }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.topbar-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
}
.topbar-badge .badge-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}
.topbar-badge--ok .badge-dot   { background: var(--success); box-shadow: 0 0 6px var(--success); }
.topbar-badge--warn .badge-dot { background: var(--warning); }
.topbar-badge--error .badge-dot{ background: var(--danger); }

/* Layout dois painéis */
.layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-surface);
  overflow-y: auto;
  padding: var(--gap);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* Painel principal */
.main-panel {
  flex: 1;
  overflow-y: auto;
  padding: var(--gap);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.panel-row {
  display: flex;
  gap: var(--gap);
  align-items: flex-start;
}

.flex-1 { flex: 1; min-width: 0; }
.flex-2 { flex: 2; min-width: 0; }

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: border-color var(--t);
}
.card:hover { border-color: var(--border-hover); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.card-body { padding: 16px 18px; }

/* Card com múltiplas seções (sem padding externo) */
.card-section { border-bottom: 1px solid var(--border); }
.card-section:last-child { border-bottom: none; }
.card-section .card-header { border-bottom: 1px solid var(--border); }
.card-section .preview-area, .card-section .send-area, .card-section .send-log { padding: 14px 18px; }

.icon { width: 15px; height: 15px; flex-shrink: 0; color: var(--text-2); }

/* ── Status Badge ──────────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 600;
  width: 100%;
  margin-bottom: 14px;
  border: 1px solid;
}

.status-badge--init         { background: rgba(148,163,184,0.08); border-color: rgba(148,163,184,0.2); color: var(--text-2); }
.status-badge--qr_ready     { background: var(--warning-dim);     border-color: rgba(234,179,8,0.3);   color: var(--warning); }
.status-badge--authenticating{ background: var(--info-dim);       border-color: rgba(59,130,246,0.3);  color: var(--info); }
.status-badge--connected     { background: var(--success-dim);    border-color: rgba(34,197,94,0.3);   color: var(--success); }
.status-badge--disconnected  { background: var(--danger-dim);     border-color: rgba(239,68,68,0.3);   color: var(--danger); }
.status-badge--auth_failure  { background: var(--danger-dim);     border-color: rgba(239,68,68,0.3);   color: var(--danger); }

.status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: currentColor;
  position: relative;
}

/* Pulsação animada para estados ativos */
.status-badge--qr_ready .status-dot::after,
.status-badge--authenticating .status-dot::after,
.status-badge--connected .status-dot::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid currentColor;
  animation: pulse-ring 1.8s ease-out infinite;
}
@keyframes pulse-ring {
  0%   { transform: scale(1); opacity: 0.7; }
  70%  { transform: scale(2.2); opacity: 0; }
  100% { transform: scale(2.2); opacity: 0; }
}

.status-dot--on   { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot--warn { background: var(--warning); }

.status-details { display: flex; flex-direction: column; gap: 8px; }

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}
.detail-label { color: var(--text-muted); }
.detail-value { color: var(--text); font-weight: 500; }
.text-muted   { color: var(--text-muted) !important; font-weight: 400 !important; }

/* ── QR Code ───────────────────────────────────────────────────── */
.qr-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px 0;
  color: var(--text-2);
  font-size: 13px;
  text-align: center;
}

.qr-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.qr-frame {
  background: #fff;
  border-radius: var(--r-md);
  padding: 12px;
  display: inline-block;
  box-shadow: 0 0 0 1px #e5e7eb, var(--shadow-md);
  position: relative;
}

.qr-frame::before,
.qr-frame::after {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  border-color: var(--accent);
  border-style: solid;
}
.qr-frame::before { top: -2px; left: -2px; border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.qr-frame::after  { bottom: -2px; right: -2px; border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }

.qr-frame img {
  display: block;
  width: 220px; height: 220px;
  border-radius: 6px;
}
.qr-hint {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 10px;
  line-height: 1.6;
}
.qr-hint strong { color: var(--text-2); }

/* Conectado */
.connected-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 0;
  text-align: center;
}
.connected-icon {
  width: 56px; height: 56px;
  background: var(--success-dim);
  border: 2px solid rgba(34,197,94,0.3);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--success);
}
.connected-icon svg { width: 24px; height: 24px; }
.connected-title { font-weight: 600; font-size: 14px; color: var(--success); }
.connected-sub   { font-size: 12px; color: var(--text-2); }

/* ── Botões de sessão ──────────────────────────────────────────── */
.session-buttons { display: flex; flex-direction: column; gap: 8px; }

/* ── Badges ────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  color: var(--text-2);
  white-space: nowrap;
}
.badge-success { background: var(--success-dim); border-color: rgba(34,197,94,0.3); color: var(--success); }
.badge-warning { background: var(--warning-dim); border-color: rgba(234,179,8,0.3); color: var(--warning); }
.badge-danger  { background: var(--danger-dim);  border-color: rgba(239,68,68,0.3); color: var(--danger); }
.badge-info    { background: var(--info-dim);    border-color: rgba(59,130,246,0.3); color: var(--info); }

/* ── Botões ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
.btn-full { width: 100%; }
.btn-sm   { padding: 5px 10px; font-size: 12px; }

.btn-primary   { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover   { background: var(--accent-light); border-color: var(--accent-light); box-shadow: 0 0 14px var(--accent-glow); }

.btn-secondary { background: var(--bg-input); color: var(--text-2); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-card-alt); border-color: var(--border-hover); color: var(--text); }

.btn-danger    { background: rgba(239,68,68,0.12); color: var(--danger); border-color: rgba(239,68,68,0.25); }
.btn-danger:hover  { background: rgba(239,68,68,0.20); border-color: rgba(239,68,68,0.4); }

.btn-success   { background: rgba(34,197,94,0.12); color: var(--success); border-color: rgba(34,197,94,0.3); }
.btn-success:hover { background: rgba(34,197,94,0.22); border-color: rgba(34,197,94,0.5); }

.btn-ghost     { background: transparent; color: var(--text-2); border-color: transparent; }
.btn-ghost:hover   { background: var(--accent-dim); color: var(--accent-light); }

.btn-icon { width: 15px; height: 15px; flex-shrink: 0; }

/* Loading spinner no botão */
.btn-loading::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Enviar — maior */
.btn-send {
  min-width: 110px;
  padding: 10px 20px;
  font-weight: 600;
  flex-shrink: 0;
}

/* ── Inputs & Textarea ─────────────────────────────────────────── */
.input, .textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 13px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color var(--t), box-shadow var(--t);
  -webkit-appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:focus, .textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.textarea {
  resize: vertical;
  min-height: 140px;
  line-height: 1.6;
  font-size: 13px;
}

.input-label { display: block; font-size: 11px; color: var(--text-muted); margin-bottom: 5px; font-weight: 500; }
.input-hint  { display: block; font-size: 11px; color: var(--text-muted); margin-top: 5px; }
.input-with-label { flex: 1; min-width: 0; }

/* ── Editor ────────────────────────────────────────────────────── */
.editor-body { display: flex; flex-direction: column; gap: 12px; }

.char-counter {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.char-counter.warn    { color: var(--warning); }
.char-counter.danger  { color: var(--danger); }

.tags-section { display: flex; flex-direction: column; gap: 6px; }
.tags-label   { font-size: 11px; color: var(--text-muted); font-weight: 500; }
.tags-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  background: var(--accent-dim);
  border: 1px solid rgba(99,102,241,0.2);
  color: var(--accent-light);
  transition: all var(--t);
  user-select: none;
}
.tag-pill:hover {
  background: rgba(99,102,241,0.22);
  border-color: rgba(99,102,241,0.45);
  transform: translateY(-1px);
  box-shadow: 0 3px 10px var(--accent-glow);
}
.tag-pill:active { transform: translateY(0); }

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 4px;
}

/* ── Templates list ────────────────────────────────────────────── */
.templates-list { display: flex; flex-direction: column; gap: 6px; max-height: 420px; overflow-y: auto; }

.template-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  cursor: pointer;
  transition: all var(--t);
}
.template-item:hover { border-color: var(--border-focus); background: var(--accent-dim); }
.template-item.active { border-color: var(--accent); background: var(--accent-dim); }

.template-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.template-meta {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Formulário dinâmico ───────────────────────────────────────── */
.dynamic-form-fields { display: flex; flex-direction: column; gap: 12px; }

.form-field { display: flex; flex-direction: column; gap: 5px; }

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 6px;
}
.form-label .label-tag {
  font-size: 10px;
  background: var(--accent-dim);
  color: var(--accent-light);
  padding: 1px 6px;
  border-radius: 99px;
  font-weight: 600;
  font-family: monospace;
}
.form-label.missing .label-tag { background: var(--warning-dim); color: var(--warning); }

/* ── Preview ───────────────────────────────────────────────────── */
.preview-area { padding: 14px 18px; }

.message-preview {
  background: #0f1f0d;
  border: 1px solid rgba(34,197,94,0.1);
  border-radius: var(--r-md);
  padding: 14px 16px;
  min-height: 80px;
  max-height: 220px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.7;
  color: #dcfce7;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
}

.preview-placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
}

/* Tags ainda não preenchidas no preview */
.tag-missing {
  background: rgba(239,68,68,0.2);
  color: #fca5a5;
  border-radius: 3px;
  padding: 0 3px;
  font-family: monospace;
  font-size: 13px;
}

/* ── Área de envio ─────────────────────────────────────────────── */
.send-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.send-feedback {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
}
.send-feedback.success { background: var(--success-dim); border: 1px solid rgba(34,197,94,0.3); color: var(--success); }
.send-feedback.error   { background: var(--danger-dim);  border: 1px solid rgba(239,68,68,0.3); color: var(--danger); }

/* ── Logs de envio ─────────────────────────────────────────────── */
.send-log {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}

.log-entry {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  font-size: 12px;
  animation: fadeSlideIn 0.25s ease;
}
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.log-entry.success { border-left: 3px solid var(--success); }
.log-entry.error   { border-left: 3px solid var(--danger);  }

.log-status { font-size: 15px; flex-shrink: 0; }
.log-content { min-width: 0; }
.log-phone   { font-weight: 600; color: var(--text); }
.log-msg     { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-err     { color: var(--danger); font-size: 11px; margin-top: 2px; }
.log-time    { color: var(--text-muted); white-space: nowrap; flex-shrink: 0; text-align: right; }

/* ── Alertas inline ────────────────────────────────────────────── */
.alert {
  padding: 10px 13px;
  border-radius: var(--r-sm);
  font-size: 12px;
  line-height: 1.5;
}
.alert-warning { background: var(--warning-dim); border: 1px solid rgba(234,179,8,0.3); color: var(--warning); }
.alert-danger  { background: var(--danger-dim);  border: 1px solid rgba(239,68,68,0.3);  color: var(--danger);  }

/* ── SMTP status card ──────────────────────────────────────────── */
.smtp-ok, .smtp-warn {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}
.smtp-ok   { color: var(--success); }
.smtp-warn { color: var(--warning); }
.smtp-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.5;
}
.smtp-detail code {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  color: var(--accent-light);
}

/* ── Empty state ───────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 28px 12px;
  color: var(--text-muted);
  text-align: center;
}
.empty-state svg { width: 36px; height: 36px; opacity: 0.4; }
.empty-state p   { font-size: 12px; max-width: 200px; line-height: 1.5; }
.empty-state.compact { padding: 16px; }
.empty-state.compact p { font-size: 12px; }

/* ── Missing badge vars ────────────────────────────────────────── */
#missing-vars-badge { transition: opacity var(--t); }

/* ── Toast notifications ───────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--r-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  max-width: 340px;
  pointer-events: all;
  animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.toast.out { animation: toastOut 0.25s ease forwards; }

.toast-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.toast-body { flex: 1; }
.toast-title { font-weight: 600; margin-bottom: 2px; }
.toast-msg   { color: var(--text-2); font-size: 12px; }

.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger);  }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-info    { border-left: 3px solid var(--accent);  }

@keyframes toastIn  { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { from { transform: none; opacity: 1; }  to { transform: translateX(110%); opacity: 0; } }

/* ── Responsive (tablet) ───────────────────────────────────────── */
@media (max-width: 900px) {
  .layout        { flex-direction: column; overflow-y: auto; }
  .sidebar       { width: 100%; border-right: none; border-bottom: 1px solid var(--border); overflow: visible; }
  .main-panel    { overflow: visible; }
  .panel-row     { flex-direction: column; }
  .flex-1, .flex-2 { flex: unset; width: 100%; }
  --sidebar-w: 100%;
}
