/* ============================================================
   Nudge CRM — Estilos Globais
   Paleta: azul escuro #1B2E45 | laranja #E8623A | branco #fff | cinza #F5F5F2
   Fonte: DM Sans (Google Fonts)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');

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

:root {
  --azul:        #1B2E45;
  --azul-mid:    #243d5c;
  --azul-light:  #e8eef5;
  --laranja:     #E8623A;
  --laranja-h:   #d4542e;
  --branco:      #FFFFFF;
  --cinza:       #F5F5F2;
  --cinza-mid:   #e0e0dc;
  --cinza-dark:  #9a9a94;
  --texto:       #1B2E45;
  --texto-muted: #6b7280;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 1px 4px rgba(0,0,0,.1);
  --shadow-md:   0 4px 16px rgba(0,0,0,.12);
  --transition:  .18s ease;
}

html, body {
  height: 100%;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 14px;
  color: var(--texto);
  background: var(--cinza);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--cinza-mid); border-radius: 99px; }

/* ---------- Utilitários ---------- */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.w-full { width: 100%; }
.text-muted { color: var(--texto-muted); }
.text-sm { font-size: 12px; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.truncate { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-primary   { background: var(--laranja); color: #fff; }
.btn-primary:hover { background: var(--laranja-h); }
.btn-secondary { background: var(--cinza-mid); color: var(--texto); }
.btn-secondary:hover { background: #d0d0cc; }
.btn-ghost     { background: transparent; color: var(--texto-muted); }
.btn-ghost:hover { background: var(--cinza); color: var(--texto); }
.btn-danger    { background: #fee2e2; color: #dc2626; }
.btn-danger:hover { background: #fecaca; }
.btn-sm        { padding: 5px 10px; font-size: 12px; }
.btn-icon      { padding: 7px; border-radius: var(--radius-sm); }

/* ---------- Inputs ---------- */
.input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--cinza-mid);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--branco);
  color: var(--texto);
  transition: var(--transition);
  outline: none;
}
.input:focus { border-color: var(--laranja); box-shadow: 0 0 0 3px rgba(232,98,58,.12); }
.input::placeholder { color: var(--cinza-dark); }

textarea.input { resize: vertical; min-height: 72px; }

/* ---------- Badge de status ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
  text-transform: capitalize;
}
.badge-aberto     { background: #dbeafe; color: #1d4ed8; }
.badge-aguardando { background: #fef9c3; color: #92400e; }
.badge-resolvido  { background: #dcfce7; color: #15803d; }

/* ---------- Card ---------- */
.card {
  background: var(--branco);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ---------- Layout principal (sidebar + conteúdo) ---------- */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--azul);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 0;
  z-index: 10;
}

.sidebar-brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand .logo-text {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.sidebar-brand .tagline {
  font-size: 10px;
  font-weight: 400;
  color: rgba(255,255,255,.5);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.65);
  font-size: 13.5px;
  font-weight: 400;
  transition: var(--transition);
  cursor: pointer;
}

.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--laranja); color: #fff; font-weight: 500; }

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--laranja);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}

.user-name  { font-size: 13px; font-weight: 500; color: #fff; }
.user-role  { font-size: 11px; color: rgba(255,255,255,.45); }

.btn-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px;
  background: rgba(255,255,255,.07);
  border: none;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.55);
  font-size: 12px;
  margin-top: 6px;
  transition: var(--transition);
}
.btn-logout:hover { background: rgba(255,255,255,.13); color: #fff; }

/* ---------- Main content ---------- */
.main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.page-header {
  padding: 20px 28px;
  background: var(--branco);
  border-bottom: 1px solid var(--cinza-mid);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--azul);
}

.page-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
}

/* ---------- Dashboard ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--branco);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-label { font-size: 12px; color: var(--texto-muted); font-weight: 500; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--azul); line-height: 1; }
.stat-value.laranja { color: var(--laranja); }
.stat-sub   { font-size: 11px; color: var(--texto-muted); margin-top: 4px; }

/* ---------- Atendimentos — layout 3 colunas ---------- */
.atendimentos-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
  gap: 0;
}

/* Lista lateral */
.lista-atendimentos {
  width: 300px;
  min-width: 300px;
  background: var(--branco);
  border-right: 1px solid var(--cinza-mid);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.lista-header {
  padding: 16px;
  border-bottom: 1px solid var(--cinza-mid);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.filtros-status {
  display: flex;
  gap: 4px;
}

.filtro-btn {
  padding: 4px 10px;
  border: 1.5px solid var(--cinza-mid);
  border-radius: 99px;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  color: var(--texto-muted);
  transition: var(--transition);
}
.filtro-btn:hover  { border-color: var(--azul); color: var(--azul); }
.filtro-btn.active { background: var(--azul); border-color: var(--azul); color: #fff; }

.lista-scroll {
  flex: 1;
  overflow-y: auto;
}

.atendimento-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--cinza);
  cursor: pointer;
  transition: var(--transition);
}
.atendimento-item:hover  { background: var(--cinza); }
.atendimento-item.active { background: var(--azul-light); border-left: 3px solid var(--azul); }

.at-nome    { font-weight: 500; font-size: 13.5px; margin-bottom: 3px; }
.at-preview { font-size: 12px; color: var(--texto-muted); margin-bottom: 6px; }
.at-meta    { display: flex; align-items: center; justify-content: space-between; }

/* Área de chat */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--cinza);
}

.chat-header {
  background: var(--branco);
  padding: 14px 20px;
  border-bottom: 1px solid var(--cinza-mid);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-cliente-info h3  { font-size: 15px; font-weight: 600; }
.chat-cliente-info p   { font-size: 12px; color: var(--texto-muted); }

.chat-actions { display: flex; gap: 8px; }

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

.msg-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
  position: relative;
}

.msg-bubble.cliente {
  background: var(--branco);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}

.msg-bubble.agente {
  background: var(--azul);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

/* Bolha do agente IA — tom levemente diferente */
.msg-bubble.ia {
  background: #243d5c;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.msg-bubble.ia .msg-time { color: rgba(255,255,255,.45); text-align: right; }

/* Badge de origem da mensagem */
.msg-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 99px;
  margin-bottom: 4px;
}
.msg-badge.ia    { background: rgba(255,255,255,.15); color: rgba(255,255,255,.8); }
.msg-badge.human { background: rgba(255,255,255,.15); color: rgba(255,255,255,.8); }

/* Badge no header do chat */
.badge-ia {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  background: #e0f2fe;
  color: #0369a1;
  font-size: 11px;
  font-weight: 600;
}
.badge-humano {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  background: #dcfce7;
  color: #15803d;
  font-size: 11px;
  font-weight: 600;
}

/* Lead info no painel lateral */
.lead-info-box {
  background: var(--cinza);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 4px;
}
.lead-info-box label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--texto-muted);
  display: block;
  margin-bottom: 2px;
}
.lead-info-box p {
  font-size: 13px;
  font-weight: 500;
  color: var(--texto);
}

.msg-time {
  font-size: 10px;
  color: var(--cinza-dark);
  margin-top: 4px;
  display: block;
}
.msg-bubble.agente .msg-time { color: rgba(255,255,255,.55); text-align: right; }

.chat-input-area {
  background: var(--branco);
  padding: 14px 20px;
  border-top: 1px solid var(--cinza-mid);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input-area textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--cinza-mid);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
  transition: var(--transition);
}
.chat-input-area textarea:focus { border-color: var(--laranja); }

.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--laranja);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
}
.btn-send:hover { background: var(--laranja-h); }

/* Painel lateral direito — dados do cliente */
.painel-cliente {
  width: 280px;
  min-width: 280px;
  background: var(--branco);
  border-left: 1px solid var(--cinza-mid);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px;
}

.painel-section { margin-bottom: 24px; }
.painel-section h4 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--texto-muted);
  margin-bottom: 12px;
}

.painel-field { margin-bottom: 10px; }
.painel-field label { font-size: 11px; color: var(--texto-muted); display: block; margin-bottom: 2px; }
.painel-field p, .painel-field span { font-size: 13px; font-weight: 500; }

.metric-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--cinza);
}
.metric-item:last-child { border-bottom: none; }
.metric-label { font-size: 12px; color: var(--texto-muted); }
.metric-value { font-size: 14px; font-weight: 600; }

.historico-item {
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--cinza);
  margin-bottom: 6px;
  cursor: pointer;
  transition: var(--transition);
}
.historico-item:hover { background: var(--cinza-mid); }
.historico-item p { font-size: 11px; color: var(--texto-muted); }

/* Estado vazio */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--texto-muted);
  gap: 10px;
}
.chat-empty svg { opacity: .3; }
.chat-empty p   { font-size: 14px; }

/* ---------- Clientes ---------- */
.clientes-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}

.clientes-lista {
  flex: 1;
  overflow-y: auto;
  background: var(--branco);
  border-right: 1px solid var(--cinza-mid);
}

.cliente-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--cinza);
  cursor: pointer;
  transition: var(--transition);
}
.cliente-row:hover  { background: var(--cinza); }
.cliente-row.active { background: var(--azul-light); }

.cliente-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--azul-light);
  color: var(--azul);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.cliente-info-main { flex: 1; min-width: 0; }
.cliente-nome      { font-size: 13.5px; font-weight: 500; }
.cliente-sub       { font-size: 12px; color: var(--texto-muted); }
.cliente-count     { font-size: 12px; color: var(--texto-muted); text-align: right; }

.painel-detalhe-cliente {
  width: 380px;
  min-width: 380px;
  background: var(--branco);
  border-left: 1px solid var(--cinza-mid);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px;
}

.detalhe-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.detalhe-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--azul);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  flex-shrink: 0;
}

.detalhe-nome  { font-size: 17px; font-weight: 600; }
.detalhe-tel   { font-size: 13px; color: var(--texto-muted); }

.metricas-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.metrica-box {
  background: var(--cinza);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}
.metrica-box .val { font-size: 20px; font-weight: 700; color: var(--azul); }
.metrica-box .lbl { font-size: 10px; color: var(--texto-muted); margin-top: 2px; }

.historico-lista h4 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--texto-muted);
  margin-bottom: 12px;
}

.historico-card {
  border: 1px solid var(--cinza-mid);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
}
.historico-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.historico-card p   { font-size: 12px; color: var(--texto-muted); }

/* ---------- Login ---------- */
.login-page {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cinza);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--branco);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 40px 36px;
}

.login-brand { text-align: center; margin-bottom: 32px; }
.login-logo  { font-size: 28px; font-weight: 700; color: var(--azul); letter-spacing: -1px; }
.login-sub   { font-size: 12px; color: var(--texto-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 1px; }

.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { font-size: 12px; font-weight: 500; color: var(--texto); display: block; margin-bottom: 4px; }
.login-error { font-size: 12px; color: #dc2626; text-align: center; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--branco);
  border-radius: var(--radius);
  padding: 28px;
  width: 360px;
  box-shadow: var(--shadow-md);
}
.modal h3  { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: var(--azul);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: slideIn .2s ease;
}
.toast.success { background: #15803d; }
.toast.error   { background: #dc2626; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ---------- Loading ---------- */
.loading-dots::after {
  content: '...';
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0%, 100% { content: '.'; }
  33%       { content: '..'; }
  66%       { content: '...'; }
}

/* ---------- Responsividade mínima ---------- */
@media (max-width: 900px) {
  .painel-cliente, .painel-detalhe-cliente { display: none; }
  .sidebar { width: 60px; min-width: 60px; }
  .sidebar-brand .tagline, .nav-item span, .user-name, .user-role, .btn-logout { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .sidebar-brand { padding: 16px 10px; text-align: center; }
}
