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

:root {
  --bg:        #f1f4f9;
  --surface:   #ffffff;
  --border:    #e4e9f0;
  --header:    #1a0f3c;
  --primary:   #7c3aed;
  --primary-l: #ede9fe;
  --pink:      #db2777;
  --pink-l:    #fce7f3;
  --blue:      #2563eb;
  --blue-l:    #dbeafe;
  --green:     #059669;
  --green-l:   #d1fae5;
  --text:      #0f172a;
  --muted:     #64748b;
  --radius:    12px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
  --topbar-h:  60px;
  --tabnav-h:  44px;
}

html, body { height: 100%; }

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

/* ─── LOGIN ─────────────────────────────────────────── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a0f3c 0%, #4c1d95 50%, #831843 100%);
}

.login-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-brand { text-align: center; margin-bottom: 36px; }
.login-icon  { font-size: 36px; color: var(--primary); margin-bottom: 12px; }
.login-brand h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-brand p  { font-size: 13px; color: var(--muted); }

.field { margin-bottom: 18px; }
.field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.field input {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; outline: none;
  background: #fafafa; transition: border-color .2s;
}
.field input:focus { border-color: var(--primary); background: #fff; }

.login-error { color: #dc2626; font-size: 13px; min-height: 18px; margin-bottom: 8px; }

#login-btn {
  width: 100%; padding: 12px;
  background: var(--primary); color: #fff; border: none; border-radius: 8px;
  font-size: 15px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: background .2s; margin-top: 4px;
}
#login-btn:hover    { background: #6d28d9; }
#login-btn:disabled { opacity: .6; cursor: not-allowed; }

/* ─── DASHBOARD SCREEN ───────────────────────────────── */
#dashboard-screen {
  display: none;
  height: 100vh;
  flex-direction: column;
}
#dashboard-screen.visible { display: flex; }

/* ─── TOPBAR ─────────────────────────────────────────── */
.topbar {
  flex-shrink: 0;
  height: var(--topbar-h);
  background: var(--header);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  z-index: 30;
}

.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-logo  { color: #a78bfa; font-size: 20px; }
.topbar-title { color: #fff; font-weight: 600; font-size: 15px; }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-update { color: #94a3b8; font-size: 12px; }
.topbar-update strong { color: #cbd5e1; }
.topbar-user { color: #cbd5e1; font-size: 13px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn-refresh {
  background: rgba(255,255,255,.1); border: none; color: #a78bfa;
  font-size: 18px; width: 32px; height: 32px; border-radius: 8px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.btn-refresh:hover { background: rgba(255,255,255,.18); }

.btn-logout {
  background: rgba(220,38,38,.15); border: 1px solid rgba(220,38,38,.3);
  color: #fca5a5; padding: 5px 12px; border-radius: 8px;
  font-size: 13px; font-family: inherit; cursor: pointer; transition: background .2s;
}
.btn-logout:hover { background: rgba(220,38,38,.25); }

/* ─── TAB NAV ────────────────────────────────────────── */
.tab-nav {
  flex-shrink: 0;
  height: var(--tabnav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px; gap: 4px;
  z-index: 20;
}

.tab-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 14px; border: none; border-radius: 8px;
  background: none; color: var(--muted); font-size: 13px; font-weight: 500;
  font-family: inherit; cursor: pointer; transition: background .15s, color .15s;
}
.tab-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab-btn:hover { background: var(--bg); color: var(--text); }
.tab-btn.active { background: var(--primary-l); color: var(--primary); font-weight: 600; }

/* ─── TABS ───────────────────────────────────────────── */
#tab-dashboard { flex: 1; overflow-y: auto; }
#tab-conversas { flex: 1; overflow: hidden; }

/* ─── DASHBOARD MAIN ─────────────────────────────────── */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 24px 48px;
  position: relative;
}

.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(241,244,249,.7); backdrop-filter: blur(2px);
  z-index: 100; display: flex; align-items: center; justify-content: center;
}
.spinner {
  width: 38px; height: 38px;
  border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── KPI GRID ─────────────────────────────────────────── */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 14px; margin-bottom: 18px;
}
.kpi-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 18px 20px; display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow); border: 1px solid var(--border); transition: transform .15s;
}
.kpi-card:hover { transform: translateY(-2px); }
.kpi-icon { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.kpi-icon svg { width: 20px; height: 20px; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.kpi-purple { background: var(--primary-l); } .kpi-purple svg { stroke: var(--primary); }
.kpi-blue   { background: var(--blue-l); }    .kpi-blue svg   { stroke: var(--blue); }
.kpi-pink   { background: var(--pink-l); }    .kpi-pink svg   { stroke: var(--pink); }
.kpi-green  { background: var(--green-l); }   .kpi-green svg  { stroke: var(--green); }
.kpi-label { font-size: 11px; color: var(--muted); font-weight: 500; margin-bottom: 2px; }
.kpi-value { font-size: 26px; font-weight: 700; line-height: 1; }

/* ─── CHART CARDS ─────────────────────────────────────── */
.charts-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.charts-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.chart-card { background: var(--surface); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 18px; }
.chart-card:last-child { margin-bottom: 0; }
.chart-title { font-size: 13px; font-weight: 600; margin-bottom: 14px; }
.chart-wrap { position: relative; width: 100%; }
.chart-donut { max-height: 200px; display: flex; justify-content: center; }
.chart-donut canvas { max-height: 200px !important; }
.chart-line { max-height: 170px; }
.chart-line canvas { max-height: 170px !important; }

/* ─── TABLE ─────────────────────────────────────────────── */
.table-card { background: var(--surface); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.table-wrap { overflow-x: auto; margin-top: 4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { text-align: left; padding: 9px 12px; color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1.5px solid var(--border); white-space: nowrap; }
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 10px 12px; vertical-align: middle; }

/* badges */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 500; white-space: nowrap; }
.badge-novo               { background: #f1f5f9; color: #475569; }
.badge-qualificado        { background: #ede9fe; color: #5b21b6; }
.badge-agendamento_pendente { background: #fef3c7; color: #92400e; }
.badge-agendado           { background: #dbeafe; color: #1e40af; }
.badge-convertido         { background: #d1fae5; color: #065f46; }
.badge-perdido            { background: #fee2e2; color: #991b1b; }
.badge-baixo  { background: #f1f5f9; color: #475569; }
.badge-medio  { background: #ede9fe; color: #5b21b6; }
.badge-alto   { background: var(--pink-l); color: #9d174d; }
.badge-positivo   { background: #d1fae5; color: #065f46; }
.badge-neutro     { background: #f1f5f9; color: #475569; }
.badge-receoso    { background: #fef3c7; color: #92400e; }
.badge-resistente { background: #fee2e2; color: #991b1b; }
.badge-sim { background: #d1fae5; color: #065f46; }
.badge-nao { background: #f1f5f9; color: #475569; }
.muted-cell { color: var(--muted); font-style: italic; }

/* ═══════════════════════════════════════════════════════
   CONVERSAS
══════════════════════════════════════════════════════ */
.chat-layout {
  height: 100%;
  display: flex;
  background: var(--surface);
}

/* ─── SIDEBAR ─── */
.chat-sidebar {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-searchbar {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.search-wrap {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border-radius: 20px;
  padding: 7px 12px;
}
.search-wrap svg { width: 14px; height: 14px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; flex-shrink: 0; }
.search-wrap input { border: none; background: none; outline: none; font-size: 13px; font-family: inherit; width: 100%; color: var(--text); }
.search-wrap input::placeholder { color: var(--muted); }

.lead-list { flex: 1; overflow-y: auto; }

.lead-item {
  display: flex; align-items: center; gap: 11px;
  padding: 12px 14px; cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
  position: relative;
}
.lead-item:hover  { background: var(--bg); }
.lead-item.active { background: var(--primary-l); }

.lead-avatar {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary-l); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; letter-spacing: -.5px;
}
.lead-item.active .lead-avatar { background: #c4b5fd; }

.lead-item-body { flex: 1; min-width: 0; }
.lead-item-row1 { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 3px; }

.lead-item-name {
  font-size: 13px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 5px;
}

/* (i) button inline */
.btn-i {
  flex-shrink: 0;
  width: 16px; height: 16px; border-radius: 50%;
  border: 1.5px solid #94a3b8; background: none;
  color: #94a3b8; font-size: 9px; font-weight: 700; font-style: italic;
  font-family: Georgia, serif;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: border-color .15s, color .15s; line-height: 1;
  padding: 0;
}
.btn-i:hover { border-color: var(--primary); color: var(--primary); }

.lead-item-time { font-size: 11px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.lead-item.active .lead-item-time { color: var(--primary); }

.lead-item-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead-item-preview .preview-sender { font-weight: 500; }
.lead-item.active .lead-item-preview { color: #6d28d9; }

/* ─── CHAT MAIN ─── */
.chat-main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface);
}

.chat-placeholder {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: #cbd5e1;
}
.chat-placeholder svg { fill: none; stroke: #e2e8f0; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.chat-placeholder p { font-size: 13px; color: var(--muted); }

.chat-window { height: 100%; display: flex; flex-direction: column; }

.chat-win-header {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.chat-win-left { display: flex; align-items: center; gap: 12px; }
.chat-win-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--primary-l); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.chat-win-name { font-size: 14px; font-weight: 600; color: var(--text); }
.chat-win-sub  { font-size: 11px; color: var(--muted); margin-top: 1px; }

.btn-i-header {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid #cbd5e1; background: none;
  color: var(--muted); font-size: 13px; font-weight: 700;
  font-style: italic; font-family: Georgia, serif;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: border-color .15s, color .15s;
}
.btn-i-header:hover { border-color: var(--primary); color: var(--primary); }

/* ─── MESSAGES AREA ─── */
.messages-area {
  flex: 1; overflow-y: auto;
  padding: 16px 20px;
  background: #ede8e3;
  display: flex; flex-direction: column; gap: 2px;
}

/* date divider */
.date-divider {
  display: flex; align-items: center; justify-content: center;
  margin: 10px 0 8px;
}
.date-divider span {
  background: rgba(255,255,255,.85);
  color: #6b7280; font-size: 11px; font-weight: 500;
  padding: 3px 12px; border-radius: 20px;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

/* bubbles */
.msg { display: flex; }
.msg.from-lead  { justify-content: flex-start; }
.msg.from-ia, .msg.from-carol { justify-content: flex-end; }

.msg-bubble {
  max-width: 68%; padding: 8px 11px 6px;
  border-radius: 12px; word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
  position: relative;
}
.msg.from-lead .msg-bubble {
  background: #ffffff; color: var(--text);
  border-bottom-left-radius: 3px;
}
.msg.from-ia .msg-bubble {
  background: #ddd5fe; color: #1e0a5e;
  border-bottom-right-radius: 3px;
}
.msg.from-carol .msg-bubble {
  background: #fce7f3; color: #6b1637;
  border-bottom-right-radius: 3px;
}

.msg-sender {
  font-size: 10px; font-weight: 700;
  margin-bottom: 3px; letter-spacing: .01em;
}
.msg.from-ia    .msg-sender { color: var(--primary); }
.msg.from-carol .msg-sender { color: var(--pink); }

.msg-text { font-size: 13px; line-height: 1.5; }

.msg-time {
  font-size: 10px; text-align: right; margin-top: 4px;
  color: rgba(0,0,0,.35);
}

/* consecutive bubbles same sender — remove radius */
.msg.from-lead  + .msg.from-lead  .msg-bubble { border-top-left-radius: 4px; }
.msg.from-ia    + .msg.from-ia    .msg-bubble { border-top-right-radius: 4px; }
.msg.from-carol + .msg.from-carol .msg-bubble { border-top-right-radius: 4px; }

/* ─── LEAD INFO PANEL (modal) ─── */
.lip-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.35);
  display: flex; align-items: stretch; justify-content: flex-end;
}

.lip-panel {
  width: min(360px, 92vw);
  height: 100%; background: var(--surface);
  display: flex; flex-direction: column;
  box-shadow: -6px 0 30px rgba(0,0,0,.15);
  animation: slideFromRight .22s cubic-bezier(.25,.46,.45,.94);
  overflow: hidden;
}
@keyframes slideFromRight { from { transform: translateX(100%); } to { transform: translateX(0); } }

.lip-header {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 18px; border-bottom: 1px solid var(--border);
  background: var(--header); flex-shrink: 0;
}
.lip-header-avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: rgba(167,139,250,.25); color: #c4b5fd;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
}
.lip-header h3 { color: #fff; font-size: 15px; font-weight: 600; }
.lip-phone { color: #94a3b8; font-size: 12px; }
.lip-close {
  margin-left: auto; background: rgba(255,255,255,.1); border: none;
  color: #a78bfa; width: 30px; height: 30px; border-radius: 8px;
  cursor: pointer; font-size: 14px; transition: background .15s;
  flex-shrink: 0;
}
.lip-close:hover { background: rgba(255,255,255,.2); }

.lip-body { flex: 1; overflow-y: auto; padding: 4px 0 24px; }

.lip-section { padding: 16px 18px 4px; }
.lip-section-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); margin-bottom: 12px;
  display: flex; align-items: center; gap: 6px;
}
.lip-section-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.lip-row {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px; padding: 7px 0; border-bottom: 1px solid #f8fafc;
  font-size: 13px;
}
.lip-row:last-child { border-bottom: none; }
.lip-row-label { color: var(--muted); font-size: 12px; flex-shrink: 0; padding-top: 1px; }
.lip-row-val   { color: var(--text); text-align: right; font-weight: 500; }
.lip-row-val.muted { color: var(--muted); font-weight: 400; font-style: italic; }
.lip-tags { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }

/* ─── RESPONSIVE ─────────────────────────────────────── */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .main { padding: 14px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .charts-grid-2, .charts-grid-3 { grid-template-columns: 1fr; }
  .topbar-update, .topbar-user { display: none; }
  .chat-sidebar { width: 100%; }
  .chat-main { display: none; }
  .chat-sidebar.hidden { display: none; }
  .chat-main.visible { display: flex; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
