/* =======================================================================
   CRM EnergyOn — sistema visual
   Adaptado do protótipo visual OpenDesign (Documents/Economildo/
   OpenDesign-CRM-EnergyOn) para PHP puro + CSS próprio. Sem framework,
   sem CDN, sem color-mix() (trocado por rgba() equivalentes para não
   depender de suporte recente de navegador).

   Classes em português (botao-*, cartao-info, tabela-contatos, ficha-*,
   indicadores, kanban...) seguem em uso pelas telas ainda não migradas
   para o novo sistema (Contatos, Painel) — usam os MESMOS tokens abaixo.
   Classes em inglês (sidebar, topbar, nav-item, card, btn-*, badge-*,
   kpi-*...) são o novo sistema compartilhado, fiel ao protótipo, usado a
   partir do Bloco 1 (sidebar/topbar) e nos próximos blocos.
   ======================================================================= */

:root {
  /* --- Cor: tokens do protótipo OpenDesign --- */
  --bg: #F2F4F7;
  --surface: #FFFFFF;
  --fg: #10213F;
  --muted: #667085;
  --muted-strong: #475569;
  --border: #E3E7ED;
  --border-strong: #C7CFDA;
  --accent: #16A870;
  --accent-soft: rgba(22, 168, 112, 0.14);
  --accent-strong: #138F5F;
  --fg-soft: rgba(16, 33, 63, 0.05);

  --navy: #0E2148;
  --navy-2: #17325F;

  --warn: #B4700A;
  --warn-soft: rgba(180, 112, 10, 0.14);
  --danger: #C6362E;
  --danger-soft: rgba(198, 54, 46, 0.12);
  --info: #2A63C7;
  --info-soft: rgba(42, 99, 199, 0.12);
  --purple: #6E4FC9;
  --purple-soft: rgba(110, 79, 201, 0.12);

  /* --- Tipografia (system fonts — sem CDN) --- */
  --font-display: 'Iowan Old Style', 'Charter', Georgia, 'Times New Roman', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: ui-monospace, 'JetBrains Mono', 'SF Mono', Menlo, monospace;

  /* --- Raio / sombra / layout --- */
  --radius: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(16, 33, 63, 0.06);
  --shadow-md: 0 8px 24px rgba(14, 33, 72, 0.12);
  --shadow-toast: 0 8px 24px rgba(14, 33, 72, 0.25);
  --shadow-modal: 0 24px 64px rgba(10, 20, 45, 0.35);
  --sidebar-w: 264px;
  --transicao: 0.15s ease;
}

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

html, body {
  height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: linear-gradient(160deg, var(--navy) 0%, #061530 55%, var(--navy-2) 100%);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

body.corpo-app {
  background: var(--bg);
  overflow-x: hidden;
}

img, svg { display: block; }
a { color: inherit; }
button { font: inherit; cursor: pointer; }
::selection { background: var(--accent-soft); }
p { text-wrap: pretty; }
h1, h2, h3, h4 { text-wrap: balance; margin: 0; }

svg.icone {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke: currentColor;
}

/* =======================================================================
   Tela de login
   ======================================================================= */

.pagina-login {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.marca {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
  font-family: var(--font-display);
  font-size: 1.9rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

.marca .energy { color: var(--surface); }
.marca .on { color: var(--accent); }

.subtitulo {
  text-align: center;
  color: rgba(255, 255, 255, 0.6);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0 0 28px;
}

.cartao {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  padding: 32px 28px;
}

.cartao h1 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0 0 20px;
  color: var(--navy);
  text-align: center;
}

.campo {
  margin-bottom: 18px;
}

.campo label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 6px;
}

.campo input[type="email"],
.campo input[type="password"],
.campo input[type="text"],
.campo input[type="datetime-local"],
.campo input[type="date"],
.campo textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  min-height: 44px;
  transition: border-color var(--transicao), background var(--transicao);
}

.campo textarea { min-height: 90px; resize: vertical; }

.campo input:focus,
.campo textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
  background: var(--surface);
}

.botao-entrar {
  width: 100%;
  min-height: 46px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transicao), transform var(--transicao);
  margin-top: 6px;
}

.botao-entrar:hover,
.botao-entrar:focus-visible {
  background: var(--accent-strong);
}

.botao-entrar:active {
  transform: translateY(1px);
}

.rodape-nota {
  text-align: center;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.55);
  margin-top: 20px;
}

.rodape-nota.alinhar-esquerda {
  text-align: left;
  color: var(--muted);
  margin: 0 0 10px;
}

/* =======================================================================
   Mensagens / alertas
   ======================================================================= */

.alerta {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.88rem;
  margin-bottom: 18px;
  border: 1px solid;
  line-height: 1.45;
}

.alerta-erro {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(198, 54, 46, 0.3);
}

.alerta-aviso {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: rgba(180, 112, 10, 0.3);
}

.alerta-sucesso {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: rgba(22, 168, 112, 0.3);
}

.alerta-info {
  background: var(--info-soft);
  color: var(--info);
  border-color: rgba(42, 99, 199, 0.3);
}

/* =======================================================================
   App shell — sidebar + topbar (fiel ao protótipo OpenDesign)
   ======================================================================= */

.app-shell {
  flex: 1;
  display: flex;
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 22px 18px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-mark svg { width: 19px; height: 19px; stroke: var(--navy); }

.brand-name {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.45);
  text-transform: uppercase;
}

.botao-fechar-sidebar {
  display: none;
  margin-left: auto;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius);
}

.botao-fechar-sidebar:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.sidebar-nav {
  flex: 1;
  padding: 10px 12px;
  overflow-y: auto;
}

.nav-section-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.35);
  padding: 16px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 9px;
  color: rgba(255, 255, 255, 0.68);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
  border-left: 3px solid transparent;
  position: relative;
  text-decoration: none;
  transition: background var(--transicao), color var(--transicao);
}

.nav-item svg { opacity: 0.9; }

.nav-item:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }

.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-left-color: var(--accent);
  font-weight: 600;
}

.nav-item-desabilitado {
  cursor: default;
  color: rgba(255, 255, 255, 0.4);
}

.nav-item-desabilitado:hover { background: transparent; color: rgba(255, 255, 255, 0.4); }

.nav-item span:first-of-type { flex: 1; }

.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: var(--navy);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}

.nav-badge-neutro {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.55);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-family: var(--font-body);
  font-size: 9.5px;
  font-weight: 700;
}

.sidebar-foot {
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
}

.user-chip-botao {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.user-chip-botao:hover { background: rgba(255, 255, 255, 0.07); }

.user-chip-texto {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-chip-texto .name {
  font-size: 13.5px;
  font-weight: 600;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip-texto .role {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12.5px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  flex-shrink: 0;
}

.avatar-sm { width: 26px; height: 26px; font-size: 10.5px; }
.avatar-lg { width: 52px; height: 52px; font-size: 17px; }

.perfil-menu {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 8px;
  z-index: 50;
}

.perfil-menu-info {
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}

.perfil-menu-nome {
  font-weight: 700;
  color: var(--navy);
  font-size: 0.88rem;
}

.perfil-menu-email {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.botao-sair {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--danger);
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: left;
}

.botao-sair:hover { background: var(--danger-soft); }

.perfil-menu-link {
  display: block;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--navy);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
}

.perfil-menu-link:hover { background: var(--border); }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 30;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 28px;
  overflow-x: hidden;
}

.menu-toggle {
  display: none;
  background: none;
  border: 0;
  padding: 6px;
  color: var(--fg);
  border-radius: var(--radius);
}

.menu-toggle:hover { background: var(--fg-soft); }

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 420px;
}

.search-wrap svg.icone {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--muted);
}

.search-input {
  width: 100%;
  padding: 9px 14px 9px 38px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  font-size: 13.5px;
  font-family: inherit;
  color: var(--fg);
}

.search-input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
  background: var(--surface);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  place-items: center;
  color: var(--fg);
  position: relative;
  flex-shrink: 0;
}

.icon-btn:hover { border-color: var(--fg); }
.icon-btn:focus-visible,
.nav-item:focus-visible,
.btn:focus-visible,
.search-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.page {
  flex: 1;
  padding: 28px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
  min-width: 0;
  overflow-x: hidden;
}

.page h1 { color: var(--navy); }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
  flex-wrap: wrap;
}

.page-title {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--navy);
}

.page-sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
  font-weight: 600;
}

@media (max-width: 920px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 20px 0 60px rgba(0, 0, 0, 0.25);
  }
  .menu-toggle { display: grid; place-items: center; }
  .search-wrap { display: none; }
  .page { padding: 18px; }
  .topbar { padding: 12px 16px; }
  .sidebar-backdrop:not([hidden]) { display: block; }
}

@media (min-width: 921px) {
  .sidebar-backdrop { display: none; }
}

/* =======================================================================
   Botões — sistema novo (btn/btn-*) e antigo (botao-*), mesmos tokens
   ======================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 600;
  letter-spacing: -0.005em;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transicao), border-color var(--transicao), color var(--transicao);
}

.btn svg.icone { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-secondary { background: var(--surface); color: var(--fg); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--fg); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; padding-inline: 10px; }
.btn-ghost:hover { color: var(--fg); background: var(--fg-soft); }
.btn-navy { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-navy:hover { background: var(--navy-2); border-color: var(--navy-2); }
.btn-sm { padding: 7px 13px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.botao-primario,
.botao-secundario,
.botao-perigo,
.botao-fantasma {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transicao), border-color var(--transicao), transform var(--transicao);
  line-height: 1.2;
}

.botao-primario svg.icone,
.botao-secundario svg.icone,
.botao-perigo svg.icone,
.botao-fantasma svg.icone { width: 16px; height: 16px; }

.botao-primario { background: var(--accent); color: #fff; }
.botao-primario:hover { background: var(--accent-strong); }
.botao-secundario { background: var(--surface); color: var(--navy); border-color: var(--border); }
.botao-secundario:hover { background: var(--bg); border-color: var(--border-strong); }
.botao-perigo { background: var(--surface); color: var(--danger); border-color: rgba(198, 54, 46, 0.3); }
.botao-perigo:hover { background: var(--danger-soft); }
.botao-fantasma { background: transparent; color: var(--navy); border-color: transparent; }
.botao-fantasma:hover { background: var(--fg-soft); }

.botao-primario:active, .botao-secundario:active,
.botao-perigo:active, .botao-fantasma:active { transform: translateY(1px); }

.botao-primario:disabled, .botao-secundario:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

/* =======================================================================
   Cabeçalho de página
   ======================================================================= */

.cabecalho-pagina {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.cabecalho-pagina h1 { margin: 0; font-family: var(--font-display); }
.cabecalho-pagina .cabecalho-descricao { color: var(--muted); font-size: 0.88rem; margin-top: 4px; }
.titulo-secao { color: var(--navy); font-size: 1.05rem; margin: 0 0 12px; }

/* Barra de ações da ficha (Editar/Cancelar/Salvar) — fica fixa logo abaixo da barra
   superior ao entrar em modo de edição, para os botões continuarem visíveis mesmo
   depois de rolar a tela até o Histórico. `top` é calculado em JS (altura real da
   .topbar), então some sozinha do fluxo normal quando não está em edição. */
.barra-acoes-fixa {
  position: sticky;
  z-index: 15;
  background: var(--bg);
  padding: 10px 0;
  transition: background 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  border: 1px solid transparent;
  border-radius: var(--radius);
}
.barra-acoes-fixa.modo-edicao {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow-md);
  padding: 14px 16px;
}

.funil-cabecalho {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 40px 0 28px;
  padding: 24px 28px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 100%);
  box-shadow: var(--shadow-md);
  transition: transform var(--transicao), box-shadow var(--transicao);
}

.funil-cabecalho:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-toast);
}

.funil-cabecalho-icone {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  background: var(--accent);
  display: grid;
  place-items: center;
  color: #fff;
}

.funil-cabecalho-icone svg.icone { width: 24px; height: 24px; }

.funil-cabecalho-texto h2 {
  margin: 0;
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
}

.funil-cabecalho-texto p {
  margin: 5px 0 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.85rem;
}

@media (max-width: 560px) {
  .funil-cabecalho { padding: 20px; }
}

/* =======================================================================
   Busca (página)
   ======================================================================= */

.form-busca { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

.form-busca input[type="text"] {
  flex: 1;
  min-width: 200px;
  padding: 10px 12px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.form-busca input[type="text"]:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

/* =======================================================================
   Cards
   ======================================================================= */

.card, .cartao-info {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
}

.cartao-info { color: var(--muted); }
.card-title { font-size: 15px; font-weight: 600; color: var(--navy); }

.card-cabecalho {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card-cabecalho h2, .card-cabecalho h3 { margin: 0; color: var(--navy); }

.estado-vazio {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
}

.estado-vazio svg.icone { width: 32px; height: 32px; color: var(--border-strong); margin-bottom: 12px; }
.estado-vazio h3 { color: var(--navy); margin: 0 0 6px; font-size: 1rem; }
.estado-vazio p { margin: 0 auto; max-width: 420px; font-size: 0.88rem; }

/* =======================================================================
   KPI cards (novo — usado a partir do Bloco do Dashboard)
   ======================================================================= */

.grid-kpi { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }

/* Modificador para linhas de 5 KPIs (Painel): cinco na mesma linha quando
   há espaço; quebra planejada 3+2 em telas médias, 2+2+1 em telas pequenas
   — nunca o 4+1 "solto" que sairia de um grid fixo de 4 colunas.
   minmax(0, ...) evita que uma coluna force overflow horizontal na página. */
.grid-kpi.grid-kpi-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }

@media (max-width: 980px) {
  .grid-kpi.grid-kpi-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .grid-kpi.grid-kpi-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-2-1 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; }
.kpi-card { display: flex; flex-direction: column; gap: 10px; min-height: 92px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.kpi-icon { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; }
.kpi-icon svg.icone { width: 16px; height: 16px; }
.kpi-value { font-family: var(--font-mono); font-size: 28px; font-weight: 600; letter-spacing: -0.02em; color: var(--navy); }
.kpi-nota { font-size: 12px; color: var(--muted); }

/* Cards clicáveis da área Leads (um kpi-card que também é link) */
.card-lead { text-decoration: none; color: inherit; transition: border-color var(--transicao), box-shadow var(--transicao), transform var(--transicao); }
.card-lead:hover { border-color: var(--accent); box-shadow: var(--shadow-md); transform: translateY(-1px); }

/* =======================================================================
   Tabela de listagem
   ======================================================================= */

.tabela-scroll {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

table.tabela-contatos, table.tabela-dados {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.tabela-contatos th, table.tabela-contatos td,
table.tabela-dados th, table.tabela-dados td {
  padding: 13px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.tabela-contatos th, table.tabela-dados th {
  color: var(--muted-strong);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg);
  font-weight: 700;
}

table.tabela-contatos tbody tr, table.tabela-dados tbody tr { transition: background var(--transicao); }
table.tabela-contatos tbody tr:hover, table.tabela-dados tbody tr:hover { background: var(--bg); }
table.tabela-contatos tr:last-child td, table.tabela-dados tr:last-child td { border-bottom: none; }
table.tabela-contatos a, table.tabela-dados a { color: var(--accent-strong); font-weight: 600; text-decoration: none; }
table.tabela-contatos a:hover, table.tabela-dados a:hover { text-decoration: underline; }

.sem-resultados { padding: 40px 20px; text-align: center; color: var(--muted); }

/* =======================================================================
   Badges / pills
   ======================================================================= */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge-success { background: var(--accent-soft); color: var(--accent-strong); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }
.badge-neutral { background: var(--fg-soft); color: var(--muted); }
.tag { display: inline-flex; align-items: center; padding: 3px 9px; border: 1px solid var(--border); border-radius: var(--radius-pill); font-size: 11.5px; color: var(--muted); }

.badge-azul { background: var(--info-soft); color: var(--info); border: 1px solid rgba(42, 99, 199, 0.25); border-radius: var(--radius-pill); padding: 3px 11px; font-size: 0.72rem; font-weight: 700; }
.badge-verde { background: var(--accent-soft); color: var(--accent-strong); border: 1px solid rgba(22, 168, 112, 0.25); border-radius: var(--radius-pill); padding: 3px 11px; font-size: 0.72rem; font-weight: 700; }
.badge-amarelo { background: var(--warn-soft); color: var(--warn); border: 1px solid rgba(180, 112, 10, 0.25); border-radius: var(--radius-pill); padding: 3px 11px; font-size: 0.72rem; font-weight: 700; }
.badge-vermelho { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(198, 54, 46, 0.25); border-radius: var(--radius-pill); padding: 3px 11px; font-size: 0.72rem; font-weight: 700; }
.badge-roxo { background: var(--purple-soft); color: var(--purple); border: 1px solid rgba(110, 79, 201, 0.25); border-radius: var(--radius-pill); padding: 3px 11px; font-size: 0.72rem; font-weight: 700; }
.badge-cinza { background: var(--fg-soft); color: var(--muted); border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 3px 11px; font-size: 0.72rem; font-weight: 700; }

.badge-duplicidade {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid rgba(180, 112, 10, 0.3);
  border-radius: var(--radius-pill);
  padding: 2px 10px;
  font-size: 0.72rem;
  font-weight: 700;
}

/* =======================================================================
   Paginação
   ======================================================================= */

.paginacao { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 16px; font-size: 0.88rem; color: var(--muted); }
.paginacao a { color: var(--navy); text-decoration: none; font-weight: 600; }
.paginacao a:hover { color: var(--accent-strong); }
.paginacao span.desabilitado { color: var(--border-strong); }

/* =======================================================================
   Formulários (novo/editar contato)
   ======================================================================= */

.form-contato {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 560px;
}

.campo select {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  min-height: 44px;
}

.campo select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.erro-campo { color: var(--danger); font-size: 0.82rem; margin-top: 4px; }
.campo input.com-erro, .campo select.com-erro, .campo textarea.com-erro { border-color: var(--danger); }

.acoes-cartao { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.item-oportunidade { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 10px; }
.acoes-form { display: flex; gap: 10px; margin-top: 24px; flex-wrap: wrap; }

.form-mudar-etapa { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 24px; }
.form-mudar-etapa select {
  padding: 10px 12px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  min-height: 42px;
}

.form-anotacao { margin-bottom: 20px; }
.form-anotacao textarea {
  width: 100%;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  resize: vertical;
}
.form-anotacao textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); background: var(--surface); }

/* =======================================================================
   Ficha de contato
   ======================================================================= */

.ficha-grade {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 16px;
}

.ficha-grade .item-label {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ficha-grade .item-valor { color: var(--navy); font-weight: 600; }
.ficha-secao { margin-bottom: 32px; }
.ficha-secao h2 { font-size: 1rem; color: var(--navy); margin-bottom: 12px; }

.lista-historico {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.lista-historico li { padding: 13px 16px; border-top: 1px solid var(--border); }
.lista-historico li:first-child { border-top: none; }
.lista-historico .item-meta { font-size: 0.76rem; color: var(--muted); margin-bottom: 3px; }

/* =======================================================================
   Painel: indicadores (classe antiga — Bloco do Dashboard vai migrar
   estes cards para .kpi-card)
   ======================================================================= */

.indicadores { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 28px; }

.indicador {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.indicador-icone {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  flex-shrink: 0;
}

.indicador-icone svg.icone { width: 20px; height: 20px; }
.indicador .indicador-valor { font-family: var(--font-mono); font-size: 1.7rem; font-weight: 600; color: var(--navy); line-height: 1.15; }
.indicador .indicador-rotulo { font-size: 0.76rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin-top: 2px; }

/* =======================================================================
   Painel: quadro Kanban (classe antiga — Bloco do Kanban vai refinar)
   ======================================================================= */

.kanban {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  align-items: start;
}

@media (max-width: 980px) {
  .kanban { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .kanban { grid-template-columns: minmax(0, 1fr); }
}

.coluna-kanban {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: box-shadow var(--transicao), transform var(--transicao);
}

.coluna-kanban:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.coluna-cabecalho {
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--border);
}

.coluna-cabecalho span:first-child {
  font-weight: 700;
  color: var(--navy);
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.coluna-cabecalho .contagem {
  flex-shrink: 0;
  color: var(--muted);
  font-weight: 700;
  font-family: var(--font-mono);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 3px 12px;
  font-size: 0.76rem;
  line-height: 1.4;
}

.coluna-corpo { padding: 10px; display: flex; flex-direction: column; gap: 8px; }

.cartao-oportunidade {
  display: block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 13px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transicao), transform var(--transicao), box-shadow var(--transicao), background var(--transicao);
}

.cartao-oportunidade:hover {
  border-color: var(--accent);
  background: var(--surface);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.cartao-oportunidade .nome-contato,
.cartao-oportunidade .titulo-oportunidade {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cartao-oportunidade .nome-contato { font-weight: 700; color: var(--navy); font-size: 0.88rem; }
.cartao-oportunidade .titulo-oportunidade { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.cartao-oportunidade .meta-oportunidade { font-size: 0.72rem; color: var(--muted); margin-top: 9px; display: flex; flex-direction: column; gap: 4px; }
.cartao-oportunidade .meta-oportunidade span { display: flex; align-items: center; gap: 5px; min-width: 0; }
.cartao-oportunidade .meta-oportunidade svg.icone { width: 13px; height: 13px; flex-shrink: 0; color: var(--muted); }
.cartao-oportunidade .meta-texto { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.coluna-vazia {
  padding: 26px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 0.76rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.coluna-vazia svg.icone { width: 22px; height: 22px; color: var(--border-strong); }


/* =======================================================================
   Listas de atividade / retorno / barras (novo — Bloco do Dashboard)
   ======================================================================= */

.activity-row { display: flex; gap: 12px; padding: 13px 0; border-top: 1px solid var(--border); }
.activity-row:first-child { border-top: 0; padding-top: 2px; }
.activity-ic { width: 32px; height: 32px; border-radius: 8px; background: var(--fg-soft); display: grid; place-items: center; flex-shrink: 0; }
.activity-ic svg.icone { width: 15px; height: 15px; color: var(--muted); }
.activity-body { flex: 1; min-width: 0; }
.activity-title { font-size: 13.5px; font-weight: 500; }
.activity-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.activity-time { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); white-space: nowrap; }

.return-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--border); }
.return-row:first-child { border-top: 0; padding-top: 2px; }
.return-date { width: 52px; text-align: center; flex-shrink: 0; }
.return-date .d { font-family: var(--font-mono); font-size: 17px; font-weight: 700; line-height: 1; color: var(--navy); }
.return-date .m { font-family: var(--font-mono); font-size: 10px; color: var(--muted); text-transform: uppercase; }
.return-body { flex: 1; min-width: 0; }
.return-name { font-size: 13.5px; font-weight: 600; }
.return-meta { font-size: 12px; color: var(--muted); margin-top: 1px; }

.bar-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.bar-label { width: 158px; flex-shrink: 0; font-size: 12px; color: var(--fg); font-weight: 500; line-height: 1.25; }
.bar-track { flex: 1; height: 9px; background: var(--fg-soft); border-radius: var(--radius-pill); overflow: hidden; }
.bar-fill { height: 100%; border-radius: var(--radius-pill); background: var(--accent); }
.bar-val { width: 46px; text-align: right; font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); flex-shrink: 0; }

.divider { border: 0; border-top: 1px solid var(--border); margin: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* =======================================================================
   Modais (reutilizável)
   ======================================================================= */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 21, 48, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}

.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-cabecalho { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-cabecalho h2 { margin: 0; font-family: var(--font-display); font-size: 1.1rem; color: var(--navy); }
.modal-fechar { background: transparent; border: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: var(--radius); display: flex; }
.modal-fechar:hover { background: var(--fg-soft); color: var(--navy); }
.modal-corpo { padding: 22px; overflow-y: auto; }
.modal-rodape { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* =======================================================================
   Toast (novo — usado a partir dos próximos blocos)
   ======================================================================= */

.toast-host { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--navy); color: #fff; padding: 12px 16px; border-radius: var(--radius);
  font-size: 13px; box-shadow: var(--shadow-toast); display: flex; align-items: center; gap: 10px;
  max-width: 320px;
}
.toast svg.icone { width: 15px; height: 15px; color: var(--accent); flex-shrink: 0; }

/* =======================================================================
   Barra de filtros (Clientes ativos, Campanhas & Cupons)
   ======================================================================= */

.barra-filtros {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 18px;
}

.barra-filtros .filtro-busca {
  flex: 1 1 240px;
  min-width: 200px;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.barra-filtros .filtro-busca:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.barra-filtros .filtro-select {
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  min-height: 42px;
}

.filtro-data-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}

.filtro-data-label input[type="date"] {
  padding: 9px 10px;
  font-family: inherit;
  font-size: 0.88rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

/* =======================================================================
   Responsivo — ajustes finos
   ======================================================================= */

@media (max-width: 1180px) {
  .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .grid-2, .grid-2-1 { grid-template-columns: minmax(0, 1fr); }
  .indicadores { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 420px) {
  .cartao { padding: 26px 20px; }
  .marca { font-size: 1.6rem; }
  table.tabela-contatos th, table.tabela-contatos td,
  table.tabela-dados th, table.tabela-dados td { white-space: normal; }
}

/* Verificação em duas etapas (configurar_2fa.php) */
.chave-2fa code { display: inline-block; font-size: 1.15rem; letter-spacing: 1px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); word-break: break-all; }
.uri-2fa { word-break: break-all; font-size: 0.8rem; }
.codigos-recuperacao { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; padding: 0; list-style: none; margin: 12px 0 16px; }
.codigos-recuperacao code { font-size: 1rem; letter-spacing: 1px; }

/* Conta Investidor (body.somente-leitura): só aparência — quem barra de verdade é o servidor
   (AuthService::investidorPode recusa todo POST). Formulários de gravação somem; os que também
   mostram dados (.form-leitura) ficam visíveis, sem botões e com os campos travados (JS no rodapé). */
.somente-leitura form[method="post" i]:not(.form-leitura):not(.form-sair),
.somente-leitura .form-leitura button,
.somente-leitura .form-leitura [type="submit"],
.somente-leitura .so-admin { display: none !important; }
.aviso-somente-leitura { margin-bottom: 16px; }
