/* Conecta — design system compartilhado (ADM + Vendas) */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Plus+Jakarta+Sans:wght@600;700&display=swap');
@import url('conecta-design-tokens.css');

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

:root {
  --blue: var(--brand-600);
  --blue-dark: var(--brand-700);
  --blue-deep: var(--brand-800);
  --blue-soft: var(--brand-50);
  --green: var(--success);
  --green-soft: var(--success-soft);
  --red: var(--danger);
  --red-soft: var(--danger-soft);
  --yellow: var(--warning);
  --yellow-soft: var(--warning-soft);
  --gray-bg: var(--crm-page-bg);
  --gray-border: var(--crm-border);
  --gray-text: var(--neutral-500);
  --text: var(--neutral-900);
  --white: var(--neutral-0);
  --surface: var(--neutral-0);
  --surface-2: var(--neutral-50);
  /* --radius-* definidos em conecta-design-tokens.css — não realiasar aqui (quebra var()) */
  --radius: var(--radius-md);
  --shadow-sm: var(--elevation-1);
  --shadow: var(--elevation-1);
  --shadow-md: var(--elevation-2);
  --shadow-lg: var(--elevation-3);
  --font: var(--font-sans);
  --transition: var(--duration-normal) var(--ease-out);
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--gray-bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  font-size: var(--text-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.muted { color: var(--gray-text); font-size: .875rem; }

/* Tipografia */
h1, h2, h3 { line-height: 1.25; font-weight: 600; }
.page-title { font-size: 1.15rem; font-weight: 600; color: var(--text); }

/* Botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1rem; border-radius: var(--radius-md); cursor: pointer;
  font-size: var(--text-sm); font-weight: 600; font-family: inherit;
  border: 1px solid transparent; transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--duration-fast) var(--ease-out);
  letter-spacing: -.01em;
}
.btn:disabled { opacity: .48; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn-primary {
  background: linear-gradient(180deg, var(--brand-500) 0%, var(--brand-600) 100%);
  color: var(--white);
  box-shadow: 0 1px 2px rgba(37, 99, 235, .28), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--brand-600) 0%, var(--brand-700) 100%);
  box-shadow: 0 4px 14px rgba(37, 99, 235, .32);
}
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--gray-border);
  box-shadow: var(--elevation-1);
}
.btn-secondary:hover:not(:disabled) { background: var(--hover-bg-muted); border-color: var(--hover-border); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-sm { padding: 6px 11px; font-size: .8rem; border-radius: var(--radius-sm); }

/* Formulários */
input[type=text], input[type=password], input[type=tel], input[type=date], input[type=email],
select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--gray-border);
  border-radius: var(--radius); font-size: .9rem; font-family: inherit;
  background: var(--surface); color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, .14);
}
label, .field label, .field-label {
  display: block; font-size: .78rem; font-weight: 600;
  color: var(--gray-text); margin-bottom: .35rem;
}
.field { margin-bottom: .85rem; }

/* Cards & painéis */
.card {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 1.25rem 1.35rem; box-shadow: var(--shadow);
  border: 1px solid var(--gray-border); margin-bottom: 1.1rem;
}
.panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-border);
  box-shadow: var(--elevation-1);
  overflow: hidden;
}
.panel-head {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--gray-border);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); flex-wrap: wrap;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
}
.panel-title { font-size: var(--text-md); font-weight: 600; letter-spacing: -.02em; }
.panel-body { padding: var(--space-5); }
.panel-body--flush { padding: 0; }
.section-sub {
  font-size: .95rem; font-weight: 600; color: var(--text);
  margin: 0 0 .25rem;
}
.callout {
  padding: .9rem 1.1rem; border-radius: var(--radius);
  border: 1px solid var(--blue-soft); background: var(--blue-soft);
  margin-bottom: 1rem;
}
.callout strong { display: block; margin-bottom: .25rem; }

/* Tabelas */
.table-wrap, .sales-table-wrap {
  overflow-x: auto; background: var(--surface);
}
table, .sales-table { width: 100%; border-collapse: collapse; }
th, td, .sales-table th, .sales-table td {
  text-align: left; padding: 11px 14px;
  border-bottom: 1px solid var(--neutral-100); font-size: .875rem;
}
th, .sales-table th {
  background: var(--surface-2); color: var(--gray-text);
  font-weight: 600; font-size: .72rem;
  text-transform: uppercase; letter-spacing: .05em;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--hover-bg); }
tbody tr.active td { background: var(--blue-soft); }
.empty-row td { text-align: center; color: var(--gray-text); padding: 2rem !important; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: .2rem;
  padding: 3px 10px; border-radius: 20px;
  font-size: .72rem; font-weight: 600; line-height: 1.4;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-yellow { background: #fef3c7; color: #b45309; }
.badge-gray { background: #f1f3f4; color: var(--gray-text); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }

/* Modais */
.modal-overlay, .modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px);
  z-index: 200; align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.open, .modal-backdrop:not(.hidden) { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 1.35rem; width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg); border: 1px solid var(--gray-border);
}
.modal-head, .sale-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1rem;
}
.modal-close, .modal-x {
  background: none; border: none; font-size: 1.5rem; line-height: 1;
  color: var(--gray-text); cursor: pointer; padding: 4px 8px;
  border-radius: 8px; transition: background var(--transition), color var(--transition);
}
.modal-close:hover, .modal-x:hover { background: var(--hover-bg-muted); color: var(--text); }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }

/* Login — split premium */
.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
  background: var(--neutral-50);
}
@media (min-width: 900px) {
  .login-page { grid-template-columns: 1.1fr 1fr; }
}
.login-hero {
  display: none;
  position: relative;
  padding: 3rem;
  color: #fff;
  background: linear-gradient(145deg, #0c1222 0%, #1e3a8a 42%, #2563eb 100%);
  overflow: hidden;
}
@media (min-width: 900px) {
  .login-hero { display: flex; flex-direction: column; justify-content: flex-end; }
}
.login-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, .14), transparent 42%),
    radial-gradient(circle at 80% 0%, rgba(147, 197, 253, .25), transparent 35%);
  pointer-events: none;
}
.login-hero-inner { position: relative; z-index: 1; max-width: 28rem; }
.login-hero h1 {
  font-family: 'Plus Jakarta Sans', var(--font-sans);
  font-size: clamp(1.75rem, 3vw, 2.35rem);
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1.15;
  margin-bottom: .85rem;
}
.login-hero p { font-size: var(--text-md); color: rgba(255, 255, 255, .82); line-height: 1.6; }
.login-hero-badges {
  display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.5rem;
}
.login-hero-badge {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: .35rem .7rem;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .18);
  backdrop-filter: blur(8px);
}
.login-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}
.login-card {
  background: var(--surface);
  padding: 2.25rem 2rem 2rem;
  border-radius: var(--radius-xl);
  box-shadow: var(--elevation-3);
  border: 1px solid var(--gray-border);
  width: 100%;
  max-width: 400px;
}
.login-logo {
  display: block;
  max-width: 220px;
  width: 100%;
  height: auto;
  margin: 0 auto 1.5rem;
}
.login-card h1, .login-card h2 {
  text-align: center;
  color: var(--text);
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -.03em;
  margin-bottom: .35rem;
}
.login-card .login-sub { text-align: center; margin-bottom: 1.25rem; }
.login-card button { width: 100%; margin-top: .5rem; }
.login-error { color: var(--red); text-align: center; margin-top: .75rem; font-size: .875rem; }

/* Spinner & toast */
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--gray-border); border-top-color: var(--blue);
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
.toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 999;
  display: flex; flex-direction: column; gap: .5rem;
}
.toast {
  padding: .75rem 1.25rem; border-radius: var(--radius);
  font-size: .875rem; color: var(--white); box-shadow: var(--shadow-md);
  animation: slideIn .25s ease; max-width: 340px;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* View toggle */
.view-toggle {
  display: inline-flex; border: 1px solid var(--gray-border);
  border-radius: var(--radius); overflow: hidden; background: var(--surface);
}
.view-toggle-btn {
  background: transparent; color: var(--gray-text); border: none;
  border-radius: 0; padding: 7px 13px; font-size: .8rem; font-weight: 600; cursor: pointer;
}
.view-toggle-btn:hover { background: var(--hover-bg-muted); color: var(--text); }
.view-toggle-btn.active { background: var(--blue); color: var(--white); }

/* Progress */
.progress {
  height: 6px; background: #e8ecf1; border-radius: 99px;
  overflow: hidden; margin-top: .5rem;
}
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--green), #34a853); border-radius: 99px; transition: width .3s; }

/* Accordion */
.acc {
  border: 1px solid var(--gray-border); border-radius: var(--radius);
  margin: 1rem 0; background: var(--surface); overflow: hidden;
}
.acc summary {
  list-style: none; cursor: pointer; padding: .9rem 1.1rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; user-select: none; background: var(--surface-2);
  transition: background var(--transition);
}
.acc summary::-webkit-details-marker { display: none; }
.acc summary:hover { background: var(--hover-bg-strong); }
.acc-title { font-weight: 600; font-size: .95rem; }
.acc-right { display: flex; align-items: center; gap: .6rem; }
.acc-state { font-size: .72rem; padding: 3px 10px; border-radius: 20px; background: var(--yellow-soft); color: #9a6700; font-weight: 600; }
.acc-state--ok { background: var(--green-soft); color: var(--green); }
.acc-chev { color: var(--gray-text); transition: transform .2s; font-size: .85rem; }
.acc[open] > summary .acc-chev { transform: rotate(180deg); }
.acc[open] > summary { border-bottom: 1px solid var(--gray-border); }
.acc-body { padding: 1.1rem; }
.acc-save-row { display: flex; justify-content: flex-end; margin-top: .65rem; }

/* Upload */
.upload-zone {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 2.5rem 2rem; text-align: center;
  border: 2px dashed var(--gray-border); transition: border-color var(--transition), background var(--transition);
  cursor: pointer;
}
.upload-zone.drag-over { border-color: var(--blue); background: var(--blue-soft); }
.upload-zone .icon { font-size: 2.5rem; margin-bottom: .75rem; opacity: .85; }

/* Status pill */
.status-pill {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: 6px 14px; border-radius: 20px; font-size: .85rem; font-weight: 600;
}
.status-pill.connected { background: var(--green-soft); color: var(--green); }
.status-pill.disconnected { background: var(--red-soft); color: var(--red); }
.status-pill.logged_out { background: var(--red-soft); color: var(--red); }
.status-pill.qr_pending { background: var(--yellow-soft); color: #9a6700; }

/* ========== Tema escuro ========== */
html[data-theme="dark"] {
  color-scheme: dark;
  --blue-soft: #1e3a5f;
  --green-soft: #14352a;
  --red-soft: #3d2020;
  --yellow-soft: #3d3520;
  --gray-bg: #080d18;
  --gray-border: #2a3548;
  --gray-text: #94a3b8;
  --text: #e8eef7;
  --white: #f8fafc;
  --surface: #141c2b;
  --surface-2: #0f1522;
  --neutral-900: #e8eef7;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .25);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, .35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .45);
  --crm-page-bg: #0b1220;
  --crm-border: #334155;
  --crm-accent-soft: #1e3a5f;
}

html[data-theme="dark"] body {
  background: var(--gray-bg);
  color: var(--text);
}

html[data-theme="dark"] .login-page {
  background: linear-gradient(145deg, #0f172a 0%, #0b1220 50%, #111827 100%);
}

html[data-theme="dark"] .badge-gray { background: #334155; color: #cbd5e1; }
html[data-theme="dark"] .progress { background: #334155; }
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background: var(--surface-2);
  border-color: var(--gray-border);
  color: var(--text);
}
html[data-theme="dark"] .modal-overlay,
html[data-theme="dark"] .modal-backdrop {
  background: rgba(0, 0, 0, .62);
}
html[data-theme="dark"] .user-dd-item:hover { background: var(--hover-bg-muted); }
html[data-theme="dark"] .btn-secondary:hover:not(:disabled) { background: var(--hover-bg-muted); }
html[data-theme="dark"] .theme-pref-btn:hover { background: var(--hover-bg-muted); }
html[data-theme="dark"] .config-nav-btn:hover,
html[data-theme="dark"] #config-nav .config-nav-btn:hover { background: var(--hover-bg-muted); }
html[data-theme="dark"] .kpi-card:hover { border-color: var(--hover-border); }
html[data-theme="dark"] .crm-clickable-row:hover,
html[data-theme="dark"] .conversas-item:hover,
html[data-theme="dark"] .conversas-item.active { background: var(--hover-bg); }
html[data-theme="dark"] .pipeline-card:hover {
  border-color: var(--hover-border-accent);
  box-shadow: 0 4px 14px var(--hover-shadow-accent);
}
html[data-theme="dark"] .crm-vendas .sale-card:hover {
  border-color: var(--hover-border-accent);
  box-shadow: 0 8px 24px var(--hover-shadow-accent);
}

/* ========== Modo escuro — módulos remanescentes ========== */

/* Automações, webhooks, integrações */
html[data-theme="dark"] code {
  background: var(--surface-2);
  color: var(--text);
  padding: .1rem .35rem;
  border-radius: 4px;
}

/* Transmissão */
html[data-theme="dark"] .crm-adm .bc-progress { background: var(--neutral-300); }
html[data-theme="dark"] .crm-adm .bc-status--running { background: #1e3a5f; color: #93c5fd; }
html[data-theme="dark"] .crm-adm .bc-status--paused { background: #3d3520; color: #fcd34d; }
html[data-theme="dark"] .crm-adm .bc-status--completed { background: #14352a; color: #86efac; }
html[data-theme="dark"] .crm-adm .bc-status--draft { background: #243044; color: #cbd5e1; }
html[data-theme="dark"] .crm-adm .bc-status--cancelled,
html[data-theme="dark"] .crm-adm .bc-status--failed { background: #3d2020; color: #fca5a5; }
html[data-theme="dark"] .crm-adm .bc-status--scheduled { background: #2e2545; color: #c4b5fd; }

/* Configurações */
html[data-theme="dark"] .cfg-hero {
  background: linear-gradient(135deg, var(--surface) 0%, #1e3a5f 100%);
}
html[data-theme="dark"] .cfg-card,
html[data-theme="dark"] .cfg-aside,
html[data-theme="dark"] .cfg-stat {
  background: var(--surface);
}
html[data-theme="dark"] .import-preview-box {
  background: var(--surface-2);
}

/* Alertas e avisos */
html[data-theme="dark"] .dash-alert--warn {
  background: #3d3520;
  border-color: #b45309;
  color: #fcd34d;
}
html[data-theme="dark"] .badge-yellow {
  background: #3d3520;
  color: #fcd34d;
}

/* Relatórios */
html[data-theme="dark"] .rel-mode-nav {
  background: var(--surface-muted);
}
html[data-theme="dark"] .rel-mode-btn:hover {
  background: var(--hover-bg-muted);
  color: var(--text);
}
html[data-theme="dark"] .rel-mode-btn.active {
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
}

/* WhatsAppBot */
html[data-theme="dark"] .wa-mode-nav {
  background: var(--surface-muted);
}
html[data-theme="dark"] .wa-mode-btn:hover {
  background: var(--hover-bg-muted);
  color: var(--text);
}
html[data-theme="dark"] .wa-mode-btn.active {
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
}

html[data-theme="dark"] .rel-ranking-item--1 {
  background: linear-gradient(135deg, #3d3520, var(--surface));
  border-color: #f59e0b;
}

/* Pipeline / forecast */
html[data-theme="dark"] .forecast-card--primary {
  background: #1e3a5f;
  border-color: #2563eb;
}
html[data-theme="dark"] .forecast-card strong,
html[data-theme="dark"] .forecast-range-labels strong {
  color: var(--text);
}
html[data-theme="dark"] .forecast-status-hint--calibrating {
  background: #1e3a5f;
  border-color: #3b82f6;
  color: #93c5fd;
}
html[data-theme="dark"] .forecast-range-track { background: var(--neutral-300); }
html[data-theme="dark"] .score-pill,
html[data-theme="dark"] .score-pill--hot { background: #3d2020; color: #fca5a5; }
html[data-theme="dark"] .score-pill--warm { background: #3d3520; color: #fcd34d; }
html[data-theme="dark"] .score-pill--cold { background: #1e3a5f; color: #93c5fd; }
html[data-theme="dark"] .pipeline-score--hot { background: #3d2020; color: #fca5a5; }
html[data-theme="dark"] .pipeline-score--warm { background: #3d3520; color: #fcd34d; }
html[data-theme="dark"] .pipeline-score--cold { background: #1e3a5f; color: #93c5fd; }
html[data-theme="dark"] .pipeline-column--draft .pipeline-column-count { background: #243044; color: #94a3b8; }
html[data-theme="dark"] .pipeline-column--blocked .pipeline-column-count { background: #3d2020; color: #fca5a5; }
html[data-theme="dark"] .pipeline-column--documents .pipeline-column-count { background: #3d3520; color: #fcd34d; }
html[data-theme="dark"] .pipeline-column--ready .pipeline-column-count { background: #1e3a5f; color: #93c5fd; }
html[data-theme="dark"] .pipeline-column--sent .pipeline-column-count { background: #14352a; color: #86efac; }

/* Conversas (legado) — tokens WA em wa-inbox.css */

/* Onboarding */
html[data-theme="dark"] .onboard-banner {
  background: linear-gradient(135deg, #1e3a5f, var(--surface));
}

/* WhatsApp inbox — hovers extras (tokens em wa-inbox.css) */
html[data-theme="dark"] .crm-adm .wa-attach-menu button:hover { background: var(--wa-list-hover, #202c33); }
