/* ==========================================================================
   CATEDRAL CONVERSE — PLATAFORMA DE AUTOMAÇÃO MULTICANAL (VERSÃO LIGHT)
   Padrão: Minimalista Contemporâneo & SaaS Executivo de Alto Padrão
   Regra: 100% Versão Light (Fundo Branco/Claro, Tipografia Escura de Alto Contraste)
   WhatsApp Cloud API + Instagram Messaging API
   Catedral Digital OS • Especialista: Thiago Dutra
   ========================================================================== */

:root {
  /* Cores SaaS Versão Light */
  --bg-app: #F8FAFC;
  --bg-sidebar: #FFFFFF;
  --bg-surface: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-card-hover: #F1F5F9;
  --bg-subtle: #F1F5F9;

  --border-subtle: #E2E8F0;
  --border-focus: #2563EB;

  /* Canais Oficiais */
  --color-whatsapp: #16A34A;
  --color-whatsapp-light: #25D366;
  --color-whatsapp-soft: #F0FDF4;
  --color-whatsapp-border: #BBF7D0;

  --color-instagram: #E1306C;
  --color-instagram-grad: linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
  --color-instagram-soft: #FDF2F8;
  --color-instagram-border: #FBCFE8;

  --color-meta: #0084FF;

  /* Estados e Acentos */
  --color-accent: #2563EB;
  --color-accent-hover: #1D4ED8;
  --color-accent-soft: #EFF6FF;
  
  --color-success: #16A34A;
  --color-warning: #D97706;
  --color-danger: #DC2626;

  /* Tipografia de Altíssimo Contraste (WCAG AAA) */
  --text-main: #0F172A;       /* Carvão Titular */
  --text-dim: #334155;        /* Grafite Leitura */
  --text-muted: #64748B;      /* Cinza Metadados */

  /* Fontes */
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'Space Mono', monospace;

  /* Geometria & Sombras */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 9999px;
  --shadow-subtle: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-card: 0 4px 14px rgba(15, 23, 42, 0.06);
  --shadow-elevated: 0 10px 25px rgba(15, 23, 42, 0.09);
  --transition: all 0.2s ease-in-out;
}

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

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar Clean */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-app);
}
::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

/* Estrutura Master */
.platform-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar de Módulos (Versão Light) */
.platform-sidebar {
  width: 240px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 50;
  box-shadow: 2px 0 10px rgba(15, 23, 42, 0.02);
}

.sidebar-header {
  padding: 20px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #0084FF, #16A34A);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 4px 12px rgba(0, 132, 255, 0.25);
}

.sidebar-brand-title {
  font-weight: 800;
  font-size: 14.5px;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.sidebar-brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.sidebar-nav {
  list-style: none;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-dim);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
}

.nav-link svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
  flex-shrink: 0;
}

.nav-link:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}

.nav-link.active {
  background: var(--color-accent-soft);
  color: var(--color-accent);
  border-color: rgba(37, 99, 235, 0.25);
  font-weight: 700;
}

/* Status das Conexões na Base da Sidebar */
.sidebar-connections {
  padding: 16px 18px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #F8FAFC;
}

.connection-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 700;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--color-success);
  box-shadow: 0 0 6px rgba(22, 163, 74, 0.4);
}

/* Área de Trabalho Principal */
.platform-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  position: relative;
  background: var(--bg-app);
}

/* Topbar Superior */
.platform-topbar {
  height: 62px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

.topbar-title-section h2 {
  font-size: 17px;
  font-weight: 800;
  color: var(--text-main);
}

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

/* Telas / Módulos */
.module-view {
  display: none;
  width: 100%;
  height: calc(100vh - 62px);
  overflow-y: auto;
  position: relative;
}

.module-view.active {
  display: flex;
}

/* ==========================================================================
   MÓDULO 1: DASHBOARD (VERSÃO LIGHT)
   ========================================================================== */
#view-dashboard {
  flex-direction: column;
  padding: 24px;
  gap: 24px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
}

.stat-box {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-subtle);
  transition: var(--transition);
}

.stat-box:hover {
  border-color: #CBD5E1;
  box-shadow: var(--shadow-card);
  transform: translateY(-2px);
}

.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-number {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-main);
  font-family: var(--font-mono);
}

.stat-footer {
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
}

.stat-badge-positive {
  color: #16A34A;
  font-weight: 700;
}

/* Banner de Economia Funil API */
.savings-banner {
  background: linear-gradient(135deg, #F0FDF4 0%, #DCFCE7 100%);
  border: 1px solid #86EFAC;
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  box-shadow: var(--shadow-subtle);
}

.savings-info h3 {
  font-size: 17px;
  font-weight: 800;
  color: #166534;
  margin-bottom: 4px;
}

.savings-info p {
  font-size: 13.5px;
  color: #15803D;
  max-width: 680px;
  line-height: 1.55;
}

.savings-value {
  text-align: right;
}

.savings-value .amount {
  font-size: 30px;
  font-weight: 800;
  color: #166534;
  font-family: var(--font-mono);
}

/* ==========================================================================
   MÓDULO 2: VISUAL FLOW BUILDER (VERSÃO LIGHT)
   ========================================================================== */
#view-flow-builder {
  width: 100%;
  height: calc(100vh - 62px);
  overflow: hidden;
  position: relative;
  display: none;
}

#view-flow-builder.active {
  display: flex;
}

/* Toolbar Flutuante */
.builder-toolbar {
  position: absolute;
  top: 16px;
  left: 16px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 30;
  box-shadow: var(--shadow-card);
}

.builder-toolbar-btn {
  background: #F8FAFC;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 12.5px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
}

.builder-toolbar-btn:hover {
  background: #E2E8F0;
  border-color: #CBD5E1;
}

/* Canvas Pontilhado Light */
.flow-canvas-container {
  flex: 1;
  width: 100%;
  height: 100%;
  background-color: #F8FAFC;
  background-image: radial-gradient(rgba(100, 116, 139, 0.22) 1.2px, transparent 1.2px);
  background-size: 24px 24px;
  position: relative;
  overflow: auto;
  cursor: grab;
}

.flow-canvas-container:active {
  cursor: grabbing;
}

.flow-canvas-world {
  position: absolute;
  width: 3000px;
  height: 3000px;
  top: 0;
  left: 0;
}

.flow-connections-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.flow-wire {
  fill: none;
  stroke: #2563EB;
  stroke-width: 2.5;
  stroke-dasharray: 6 3;
  animation: flow-pulse 1.2s linear infinite;
}

@keyframes flow-pulse {
  to { stroke-dashoffset: -9; }
}

/* Nós Visuais no Canvas (Cards Brancos Nítidos) */
.flow-node {
  position: absolute;
  width: 290px;
  background: #FFFFFF;
  border: 1.5px solid #CBD5E1;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.08);
  z-index: 20;
  cursor: default;
  transition: box-shadow 0.2s ease;
  user-select: none;
}

.flow-node.selected {
  border-color: #2563EB;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25), 0 8px 26px rgba(15, 23, 42, 0.12);
}

.flow-node-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: move;
  background: #F8FAFC;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.flow-node-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
}

.badge-trigger {
  background: #FEF3C7;
  color: #B45309;
  border: 1px solid #FDE68A;
}

.badge-message {
  background: #EFF6FF;
  color: #1D4ED8;
  border: 1px solid #BFDBFE;
}

.badge-action {
  background: #F0FDF4;
  color: #15803D;
  border: 1px solid #BBF7D0;
}

.badge-delay {
  background: #FAF5FF;
  color: #7E22CE;
  border: 1px solid #E9D5FF;
}

.flow-node-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.flow-node-text {
  font-size: 13.5px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* Portas de Conexão */
.port {
  width: 14px;
  height: 14px;
  border-radius: var(--radius-pill);
  background: #FFFFFF;
  border: 2.5px solid #2563EB;
  position: absolute;
  cursor: crosshair;
  transition: var(--transition);
  z-index: 25;
}

.port:hover {
  transform: scale(1.3);
  background: #2563EB;
}

.port-input {
  top: 50%;
  left: -7px;
  transform: translateY(-50%);
}

.port-output {
  top: 50%;
  right: -7px;
  transform: translateY(-50%);
}

/* Painel Lateral de Propriedades (Inspector) */
.builder-inspector {
  width: 320px;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 30;
  padding: 22px;
  gap: 16px;
  overflow-y: auto;
  box-shadow: -2px 0 10px rgba(15, 23, 42, 0.02);
}

.inspector-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

/* ==========================================================================
   MÓDULO 3: LIVE CHAT (INBOX OMNICHANNEL - VERSÃO LIGHT)
   ========================================================================== */
#view-live-chat {
  width: 100%;
  height: calc(100vh - 62px);
  display: none;
}

#view-live-chat.active {
  display: flex;
}

.chat-list-panel {
  width: 320px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.chat-list-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-filter-tabs {
  display: flex;
  background: #F1F5F9;
  border-radius: var(--radius-sm);
  padding: 3px;
}

.chat-tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  padding: 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition);
}

.chat-tab-btn.active {
  background: #FFFFFF;
  color: var(--text-main);
  box-shadow: var(--shadow-subtle);
}

.chat-contact-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
}

.chat-contact-item {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: var(--transition);
}

.chat-contact-item:hover {
  background: #F8FAFC;
}

.chat-contact-item.active {
  background: #EFF6FF;
  border-left: 3.5px solid #2563EB;
}

.chat-contact-avatar {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-pill);
  background: #E2E8F0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--text-main);
  position: relative;
  flex-shrink: 0;
}

.channel-badge-icon {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #FFFFFF;
}

.badge-ig {
  background: #E1306C;
}

.badge-wpp {
  background: #16A34A;
}

.chat-contact-meta {
  flex: 1;
  min-width: 0;
}

.chat-contact-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.contact-name {
  font-weight: 700;
  color: var(--text-main);
  font-size: 14px;
}

.contact-time {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.contact-preview {
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Área de Mensagens */
.chat-conversation-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #F8FAFC;
}

.chat-top-header {
  height: 62px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-sidebar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.chat-messages-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #F8FAFC;
}

.msg-bubble {
  max-width: 65%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.5;
  position: relative;
}

.msg-incoming {
  align-self: flex-start;
  background: #FFFFFF;
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-subtle);
}

.msg-outgoing {
  align-self: flex-end;
  background: #2563EB;
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.msg-meta {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.8);
  text-align: right;
  margin-top: 4px;
  font-family: var(--font-mono);
}

.msg-incoming .msg-meta {
  color: var(--text-muted);
}

.chat-input-bar {
  padding: 16px 20px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Ficha do Lead */
.chat-lead-info {
  width: 290px;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border-subtle);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ==========================================================================
   MÓDULO 4: COMMENT-TO-DM (VERSÃO LIGHT)
   ========================================================================== */
#view-comment-dm {
  flex-direction: column;
  padding: 24px;
  gap: 24px;
}

.comment-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.comment-rule-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-subtle);
  transition: var(--transition);
}

.comment-rule-card:hover {
  border-color: #CBD5E1;
  box-shadow: var(--shadow-card);
}

/* ==========================================================================
   COMPONENTES GERAIS (BOTÕES, INPUTS, CARDS LIGHT)
   ========================================================================== */
.btn-primary {
  background: #2563EB;
  color: #FFFFFF;
  border: none;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
  background: #1D4ED8;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
  background: #FFFFFF;
  color: var(--text-dim);
  border: 1px solid var(--border-subtle);
  font-size: 13px;
  font-weight: 700;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: #F8FAFC;
  color: var(--text-main);
  border-color: #CBD5E1;
}

.form-control {
  width: 100%;
  background: #FFFFFF;
  border: 1.5px solid #CBD5E1;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
}

.form-control:focus {
  border-color: #2563EB;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
