/* ==========================================================================
   WHATSAPP INTELIGENTE — ESTILOS GLASSMORPHISM & RESPONSIVOS
   ========================================================================== */

:root {
  --wi-bg-main: #0B0F19;
  --wi-bg-card: rgba(15, 23, 42, 0.75);
  --wi-bg-card-hover: rgba(30, 41, 59, 0.85);
  --wi-border: rgba(255, 255, 255, 0.1);
  --wi-border-gold: rgba(212, 175, 55, 0.4);
  --wi-gold: #D4AF37;
  --wi-gold-light: #F3E5AB;
  --wi-green: #10B981;
  --wi-red: #EF4444;
  --wi-yellow: #F59E0B;
  --wi-blue: #3B82F6;
  --wi-purple: #8B5CF6;
  --wi-text-primary: #F8FAFC;
  --wi-text-secondary: #94A3B8;
}

/* Container do Módulo */
#whatsapp_inteligente {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  color: var(--wi-text-primary);
  background: var(--wi-bg-main);
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  border: 1px solid var(--wi-border);
}

/* Header & Menu de Sub-Abas */
.wi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 10px;
}

.wi-title-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wi-title-area h2 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
  background: linear-gradient(135deg, #FFF 0%, var(--wi-gold-light) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.wi-tabs-nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--wi-border);
  margin-bottom: 1.25rem;
  scroll-behavior: smooth;
}

.wi-tab-btn {
  background: rgba(30, 41, 59, 0.5);
  color: var(--wi-text-secondary);
  border: 1px solid var(--wi-border);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.wi-tab-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #FFF;
}

.wi-tab-btn.active {
  background: linear-gradient(135deg, rgba(212,175,55,0.2) 0%, rgba(15,23,42,0.9) 100%);
  color: var(--wi-gold-light);
  border-color: var(--wi-gold);
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.15);
}

/* Sub-Aba Container */
.wi-tab-content {
  display: none;
  animation: wiFadeIn 0.3s ease;
}

.wi-tab-content.active {
  display: block;
}

@keyframes wiFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Grids de KPI Cards */
.wi-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 1.5rem;
}

.wi-kpi-card {
  background: var(--wi-bg-card);
  border: 1px solid var(--wi-border);
  border-radius: 14px;
  padding: 1rem;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.wi-kpi-card:hover {
  transform: translateY(-2px);
  border-color: var(--wi-gold);
}

.wi-kpi-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: #FFF;
  margin-top: 4px;
}

.wi-kpi-label {
  font-size: 0.78rem;
  color: var(--wi-text-secondary);
  font-weight: 600;
}

/* Layout 3 Colunas — Central de Conversas */
.wi-chat-container {
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  gap: 14px;
  height: 720px;
  background: var(--wi-bg-card);
  border: 1px solid var(--wi-border);
  border-radius: 16px;
  overflow: hidden;
}

/* Coluna 1: Lista & Filtros */
.wi-chat-col1 {
  border-right: 1px solid var(--wi-border);
  display: flex;
  flex-direction: column;
  background: rgba(15, 23, 42, 0.9);
}

.wi-filter-select {
  background: #1E293B;
  color: #FFF;
  border: 1px solid var(--wi-border);
  padding: 8px 12px;
  border-radius: 8px;
  width: 100%;
  font-size: 0.85rem;
}

.wi-conversation-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.wi-conv-item {
  padding: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  cursor: pointer;
  transition: background 0.2s ease;
}

.wi-conv-item:hover, .wi-conv-item.active {
  background: rgba(212, 175, 55, 0.12);
  border-left: 3px solid var(--wi-gold);
}

/* Coluna 2: Chat */
.wi-chat-col2 {
  display: flex;
  flex-direction: column;
  background: rgba(11, 15, 25, 0.7);
}

.wi-chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--wi-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 23, 42, 0.9);
}

.wi-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wi-msg-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.4;
  word-break: break-word;
}

.wi-msg-bubble.sent {
  align-self: flex-end;
  background: #047857;
  color: #FFF;
  border-bottom-right-radius: 2px;
}

.wi-msg-bubble.received {
  align-self: flex-start;
  background: #1E293B;
  color: #F8FAFC;
  border-bottom-left-radius: 2px;
  border: 1px solid var(--wi-border);
}

.wi-chat-input-area {
  padding: 12px;
  border-top: 1px solid var(--wi-border);
  display: flex;
  gap: 8px;
  background: rgba(15, 23, 42, 0.9);
}

/* Coluna 3: Inteligência Comercial IA */
.wi-chat-col3 {
  border-left: 1px solid var(--wi-border);
  padding: 14px;
  overflow-y: auto;
  background: rgba(15, 23, 42, 0.95);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Badges de Temperatura */
.wi-badge-quente { background: rgba(239, 68, 68, 0.2); color: #EF4444; border: 1px solid #EF4444; padding: 2px 8px; border-radius: 10px; font-weight: 800; font-size: 0.72rem; }
.wi-badge-morno { background: rgba(245, 158, 11, 0.2); color: #F59E0B; border: 1px solid #F59E0B; padding: 2px 8px; border-radius: 10px; font-weight: 800; font-size: 0.72rem; }
.wi-badge-frio { background: rgba(59, 130, 246, 0.2); color: #3B82F6; border: 1px solid #3B82F6; padding: 2px 8px; border-radius: 10px; font-weight: 800; font-size: 0.72rem; }

/* Construtor de Chatbot Canvas & Flowchart */
.wi-chatbot-builder-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 14px;
  height: 680px;
  background: var(--wi-bg-card);
  border: 1px solid var(--wi-border);
  border-radius: 16px;
  overflow: hidden;
}

.wi-chatbot-builder {
  height: 100%;
  background: radial-gradient(circle, rgba(255,255,255,0.08) 1px, transparent 1px);
  background-size: 24px 24px;
  position: relative;
  overflow: auto;
  user-select: none;
  cursor: grab;
}

.wi-chatbot-builder:active {
  cursor: grabbing;
}

.wi-bot-node {
  width: 240px;
  background: rgba(15, 23, 42, 0.95);
  border: 1.5px solid var(--wi-border);
  border-radius: 14px;
  padding: 12px;
  position: absolute;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  transition: border-color 0.2s, box-shadow 0.2s;
  cursor: move;
  z-index: 2;
}

.wi-bot-node:hover {
  border-color: var(--wi-gold-light);
}

.wi-bot-node.selected {
  border-color: var(--wi-gold);
  box-shadow: 0 0 16px rgba(212, 175, 55, 0.4);
}

.wi-node-socket {
  width: 14px;
  height: 14px;
  background: var(--wi-gold);
  border: 2px solid #0F172A;
  border-radius: 50%;
  position: absolute;
  cursor: pointer;
  transition: transform 0.2s;
}

.wi-node-socket:hover {
  transform: scale(1.3);
  background: #34D399;
}

.wi-node-socket.input { top: -7px; left: 50%; transform: translateX(-50%); }
.wi-node-socket.output { bottom: -7px; left: 50%; transform: translateX(-50%); }

.wi-builder-editor-panel {
  background: rgba(15, 23, 42, 0.95);
  border-left: 1px solid var(--wi-border);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Modal do Simulador de WhatsApp */
.wi-simulator-overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wi-simulator-box {
  width: 900px;
  max-width: 95vw;
  height: 650px;
  background: #0F172A;
  border: 1px solid var(--wi-border);
  border-radius: 20px;
  display: grid;
  grid-template-columns: 360px 1fr;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,0.8);
}

.wi-sim-phone {
  background: #0B0F19;
  border-right: 1px solid var(--wi-border);
  display: flex;
  flex-direction: column;
}

.wi-sim-header {
  background: #1E293B;
  padding: 12px 16px;
  border-bottom: 1px solid var(--wi-border);
  display: flex;
  align-items: center;
  gap: 10px;
  color: #FFF;
  font-weight: 700;
  font-size: 0.9rem;
}

.wi-sim-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wi-sim-logs {
  padding: 16px;
  overflow-y: auto;
  background: rgba(15, 23, 42, 0.9);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wi-log-item {
  font-size: 0.78rem;
  padding: 8px 10px;
  background: rgba(255,255,255,0.03);
  border-left: 3px solid var(--wi-gold);
  border-radius: 4px;
  color: var(--wi-text-secondary);
  line-height: 1.4;
}

/* Responsividade Mobile & Tablet (Refinada 3.0) */
@media (max-width: 1024px) {
  .wi-chat-container {
    grid-template-columns: 1fr;
    height: auto;
  }
  .wi-chat-col1, .wi-chat-col3 {
    max-height: 400px;
  }
  .wi-chatbot-builder-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
}

@media (max-width: 768px) {
  #whatsapp_inteligente {
    padding: 0.75rem;
    border-radius: 12px;
  }

  .wi-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .wi-title-area h2 {
    font-size: 1.15rem;
  }

  .wi-tabs-nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
  }

  .wi-tab-btn {
    padding: 6px 10px;
    font-size: 0.78rem;
    flex-shrink: 0;
  }

  /* Grid de Ação do Chatbot Builder no Mobile */
  .wi-chatbot-builder-layout {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 520px;
    border-radius: 14px;
    overflow: hidden;
  }

  .wi-chatbot-builder {
    height: 380px;
    width: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .wi-builder-editor-panel {
    border-left: none;
    border-top: 1px solid var(--wi-border);
    max-height: 320px;
    padding: 12px;
  }

  .wi-kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .wi-kpi-card {
    padding: 0.75rem;
  }

  .wi-kpi-value {
    font-size: 1.2rem;
  }

  /* Chatbot Builder Toolbar Mobile */
  .wi-builder-toolbar-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 6px !important;
  }

  .wi-builder-toolbar-controls > * {
    flex: 1 1 calc(50% - 6px);
    font-size: 0.78rem !important;
  }

  /* Central de Conversas no Mobile */
  .wi-chat-container {
    display: flex;
    flex-direction: column;
    height: auto;
  }

  .wi-chat-col1 {
    max-height: 260px;
  }

  .wi-chat-col2 {
    height: 420px;
  }

  .wi-chat-col3 {
    max-height: 300px;
  }
}
