/* ════════════════════════════════════════════════════════════════════
   ALERTA BNMP · CRM — design system (claro)
   Contrato: todos os nomes de classe pré-existentes são mantidos
   (.kpi, .panel, .badge, .bar, .toolbar, .kpi-duo, .dl, .flash ...).
   Redesign (04/07/2026, tema claro) muda só os valores dos tokens e as
   regras que dependiam de cor hardcoded — a estrutura de classes é a
   mesma do tema dark anterior. Classes novas seguem aditivas: .topbar,
   .scrim, .delta, .nav-badge, .table-wrap, .table-cards, .grid-auto,
   .search-hero, .health-row, .health-item.
   ════════════════════════════════════════════════════════════════════ */

/* ── 1. Tokens ─────────────────────────────────────────────────────── */
:root {
  /* elevação claro (do fundo ao mais alto) */
  --bg: #f5f6f8;
  --surface-1: #ffffff;
  --surface-2: #ffffff;
  --surface-3: #eef0f4;

  /* compat com o CSS antigo (alguns templates usam direto) */
  --panel: var(--surface-2);
  --panel2: var(--surface-1);

  --border: #e3e5ea;
  --border-strong: #cdd1d9;

  /* hierarquia de texto */
  --text-1: #14161c;
  --text-2: #4b5163;
  --text-3: #8b909d;
  --text: var(--text-1);
  --muted: var(--text-3);

  --brand: #dc2626;
  --brand-bright: #ef4444;
  --brand-dim: #fee2e2;
  --green: #15803d;
  --blue: #1d4ed8;
  --purple: #6d28d9;
  --amber: #b45309;
  --red: #b91c1c;

  /* cores de gráfico (Chart.js lê via JS, ver templates) */
  --chart-line-1: #dc2626;
  --chart-line-1-fill: #dc262622;
  --chart-line-2: #15803d;
  --chart-line-2-fill: #15803d22;
  --chart-grid: #e3e5ea;
  --chart-tick: #8b909d;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-1: 0 1px 2px #0d0e1208;
  --shadow-2: 0 12px 28px #0d0e1214;

  --font-sans: "Inter", -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
}

/* ── 2. Reset + base ───────────────────────────────────────────────── */
* { box-sizing: border-box; }

html { scrollbar-color: var(--border-strong) transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-1);
  font: 14px/1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
code {
  background: #0d0e1208; border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 6px; font-size: 12px;
}

h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 4px; color: var(--text-1); }
h2 {
  font-size: 13px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-2); margin: 0 0 14px;
}
.subtitle { color: var(--text-3); font-size: 13px; margin: 0 0 22px; }
.muted { color: var(--text-3); }

/* ── 3. Layout ─────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
  z-index: 40;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.brand img { width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 13px; font-weight: 800; color: var(--text-1); letter-spacing: .02em; }
.brand-text span { font-size: 10px; color: var(--brand); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; overflow-y: auto; }
.sidebar nav a {
  padding: 9px 12px;
  color: var(--text-3);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 9px;
  transition: background .15s, color .15s;
}
.sidebar nav a:hover { color: var(--text-1); background: #0d0e1208; }
.sidebar nav a.on {
  color: var(--brand);
  background: linear-gradient(90deg, var(--brand-dim), transparent 85%);
  box-shadow: inset 3px 0 0 var(--brand);
  font-weight: 700;
}
.nav-badge {
  margin-left: auto;
  background: var(--amber); color: #fff;
  font-size: 10px; font-weight: 800;
  border-radius: 999px; padding: 1px 7px;
  line-height: 1.5;
}
.sidebar .sair {
  margin-top: auto; padding: 14px 20px; color: var(--text-3); font-size: 13px;
  border-top: 1px solid var(--border);
  transition: color .15s;
}
.sidebar .sair:hover { color: var(--red); }

/* "Sair" virou POST (o GET era CSRF-ável, auditoria 31/07/2026). O <form> passa
   a ser o filho do flex da sidebar, então é ele que leva o `margin-top:auto`; o
   <button> perde a aparência de botão e herda a de link. */
.sidebar .sair-form { margin-top: auto; display: block; }
.sidebar .sair {
  margin-top: 0; width: 100%; text-align: left;
  background: none; border: 0; border-top: 1px solid var(--border);
  font: inherit; cursor: pointer;
}

.content { flex: 1; padding: 28px 32px 48px; max-width: 1280px; min-width: 0; }

/* topbar mobile (escondida em desktop) */
.topbar {
  display: none;
  position: sticky; top: 0; z-index: 30;
  align-items: center; gap: 12px;
  padding: 10px 14px;
  background: #ffffffee;
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar img { width: 30px; height: 30px; border-radius: 50%; }
.topbar strong { font-size: 13px; font-weight: 800; color: var(--text-1); }
.hamburger {
  background: var(--surface-1); border: 1px solid var(--border); color: var(--text-1);
  border-radius: var(--radius-sm); padding: 6px 10px; font-size: 16px; cursor: pointer;
}
.scrim {
  display: none;
  position: fixed; inset: 0; z-index: 35;
  background: #14161c66;
}
body.drawer-open .scrim { display: block; }

/* ── 4. KPI cards ──────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi, .kpi-duo {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-1);
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.kpi:hover, .kpi-duo:hover { transform: translateY(-1px); border-color: var(--border-strong); box-shadow: var(--shadow-2); }

.kpi .label, .kpi-duo .label {
  font-size: 10.5px; color: var(--text-3); font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
}
.kpi .value {
  font-size: 27px; font-weight: 800; margin-top: 4px; letter-spacing: -0.02em;
  color: var(--text-1);
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}
.kpi .sub { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }
.kpi .value.green { color: var(--green); }
.kpi .value.amber { color: var(--amber); }
.kpi .value.blue  { color: var(--blue); }
.kpi .value.red   { color: var(--red); }
.kpi .value.brand { color: var(--brand); }
.kpi .sub.up { color: var(--green); }
.kpi .sub.down { color: var(--red); }

.delta { font-weight: 700; font-size: 11.5px; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }

.sparkline { margin-top: 8px; height: 38px; }
.sparkline canvas { width: 100% !important; height: 38px !important; }

/* KPI duplo: dinheiro + contagem lado a lado (financeiro) */
.kpi-duo { display: flex; flex-direction: column; gap: 6px; }
.kpi-duo .row { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.kpi-duo .money {
  font-size: 24px; font-weight: 800; letter-spacing: -0.02em; color: var(--text-1);
  font-feature-settings: "tnum"; font-variant-numeric: tabular-nums;
}
.kpi-duo .count { font-size: 13px; font-weight: 700; padding: 2px 9px; border-radius: 6px; background: #0d0e1208; }
.kpi-duo .count.green { background:#15803d18; color:var(--green); }
.kpi-duo .count.blue  { background:#1d4ed818; color:var(--blue); }
.kpi-duo .count.amber { background:#b4530918; color:var(--amber); }
.kpi-duo .count.red   { background:#b91c1c18; color:var(--red); }
.kpi-duo .sub { font-size: 11.5px; color: var(--text-3); }

/* ── 5. Painéis ────────────────────────────────────────────────────── */
.panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-1);
}
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; }
.grid-2.even { grid-template-columns: 1fr 1fr; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 12px; }

/* ── 6. Funil ──────────────────────────────────────────────────────── */
.funil-row { font-size: 13px; margin-bottom: 4px; color: var(--text-2); }
.funil-row .n {
  float: right; color: var(--text-1); font-weight: 700;
  font-feature-settings: "tnum"; font-variant-numeric: tabular-nums;
}
.bar { height: 8px; border-radius: 4px; margin-bottom: 13px; opacity: .85; }

/* ── 7. Tabelas ────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th {
  color: var(--text-3); font-weight: 700; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .05em;
  position: sticky; top: 0; background: var(--surface-2);
}
td {
  color: var(--text-2);
  font-feature-settings: "tnum"; font-variant-numeric: tabular-nums;
}
tbody tr { transition: background .1s; }
tbody tr:hover { background: #0d0e1206; }
tr:last-child td { border-bottom: none; }
td a { color: var(--blue); font-weight: 600; }
td a:hover { text-decoration: underline; }

/* tabelas curtas viram cards no mobile (usa td::before + data-th) */
@media (max-width: 767px) {
  .table-cards table, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards thead { display: none; }
  .table-cards tr {
    background: var(--surface-1); border: 1px solid var(--border);
    border-radius: var(--radius-sm); margin-bottom: 8px; padding: 6px 10px;
  }
  .table-cards td { border: none; padding: 4px 0; }
  .table-cards td[data-th]::before {
    content: attr(data-th) "  ";
    color: var(--text-3); font-size: 10.5px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .05em;
    display: inline-block; min-width: 90px;
  }
}

/* ── 8. Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
.badge.green { background: #15803d16; color: var(--green); border: 1px solid #15803d30; }
.badge.blue  { background: #1d4ed816; color: var(--blue);  border: 1px solid #1d4ed830; }
.badge.amber { background: #b4530916; color: var(--amber); border: 1px solid #b4530930; }
.badge.red   { background: #b91c1c16; color: var(--red);   border: 1px solid #b91c1c30; }
.badge.brand { background: var(--brand-dim); color: var(--brand); border: 1px solid #dc262630; }
.badge.gray  { background: #0d0e1210; color: var(--text-3); border: 1px solid var(--border); }
.badge.ok    { background: #15803d16; color: var(--green); border: 1px solid #15803d30; }
.badge.warn  { background: #b4530916; color: var(--amber); border: 1px solid #b4530930; }

/* ── 9. Forms / botões ─────────────────────────────────────────────── */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }

input, select, textarea {
  background: var(--surface-1); border: 1px solid var(--border); color: var(--text-1);
  border-radius: var(--radius-sm); padding: 8px 11px; font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-dim);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
textarea { width: 100%; min-height: 120px; resize: vertical; }

.btn {
  background: var(--brand); color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 9px 16px; font-weight: 700; cursor: pointer; font-size: 13px;
  transition: filter .15s, transform .1s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-dim), 0 0 0 1px var(--brand); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: var(--surface-1); border: 1px solid var(--border-strong); color: var(--text-1); font-weight: 600; }
.btn.ghost:hover { background: #0d0e1208; }
.btn.success { background: var(--green); color: #fff; }
.btn.danger { background: #fee2e2; color: var(--red); border: 1px solid #fca5a5; }

/* ── 10. Login ─────────────────────────────────────────────────────── */
.login-wrap {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px;
  background: var(--bg);
}
.login-card {
  width: 340px; max-width: 100%;
  background: var(--surface-1);
  border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px;
  box-shadow: var(--shadow-2);
}
.login-logo { display: block; margin: 0 auto 20px; width: 92px; height: 92px; border-radius: 50%; }
.login-title { text-align: center; font-size: 18px; font-weight: 800; color: var(--text-1); margin: 0 0 4px; }
.login-sub { text-align: center; color: var(--text-3); font-size: 12px; margin: 0 0 22px; }
.login-card input { width: 100%; margin-bottom: 12px; }
.login-card .btn { width: 100%; padding: 11px; font-size: 14px; }
.erro { color: var(--red); font-size: 13px; margin-bottom: 12px; text-align: center; }

/* ── 11. Detalhe / flash ───────────────────────────────────────────── */
.dl { display: grid; grid-template-columns: 160px 1fr; gap: 7px 14px; font-size: 13px; }
.dl dt { color: var(--text-3); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.flash { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13px; }
.flash.ok { background: #15803d10; border: 1px solid #15803d40; color: var(--green); }
.flash.err { background: #b91c1c10; border: 1px solid #b91c1c40; color: var(--red); }

/* ── 12. Busca em destaque (Home) e sinais de saúde ───────────────── */
.search-hero {
  display: flex; gap: 10px; margin-bottom: 18px;
}
.search-hero input {
  flex: 1; font-size: 14px; padding: 12px 14px;
}
.search-hero .btn { padding: 0 20px; }

.health-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.health-item {
  display: flex; align-items: center; gap: 7px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 14px; font-size: 12px; font-weight: 600; color: var(--text-2);
}
.health-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex-shrink: 0; }
.health-item.warn .dot { background: var(--amber); }
.health-item.bad .dot { background: var(--red); }

/* ── 13. Responsivo ────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .grid-2, .grid-2.even { grid-template-columns: 1fr 1fr; }
  .content { padding: 22px 20px 40px; }
}

@media (max-width: 767px) {
  .layout { flex-direction: column; }

  .topbar { display: flex; }

  /* sidebar vira drawer */
  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: 260px; height: 100vh; height: 100dvh;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-2);
    z-index: 50;
  }
  body.drawer-open .sidebar { transform: translateX(0); }

  .content { padding: 16px 14px 40px; }
  .grid-2, .grid-2.even { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi .value { font-size: 23px; }
  h1 { font-size: 19px; }

  .toolbar { gap: 8px; }
  .toolbar input, .toolbar select { flex: 1; min-width: 120px; }
  .search-hero { flex-direction: column; }

  /* tabelas largas: scroll horizontal decente */
  .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .dl { grid-template-columns: 120px 1fr; }
}

/* ── Modal de confirmação (confirmar.js) ───────────────────────────────
   Substitui o confirm()/prompt() nativo. Card centralizado; o <dialog>
   nativo dá Esc, trava de foco e camada superior sem JS.
   ELEMENTO ESPELHADO: o mesmo componente existe em portal/static/app.css
   com os tokens do portal (--surface/--line/--red). Mudou aqui, olhe lá. */
.cf-dlg {
  border: 0; padding: 0; background: transparent; color: var(--text-1);
  width: 100%; max-width: min(380px, calc(100vw - 32px)); margin: auto;
}
.cf-dlg::backdrop { background: #0d0e1273; }
.cf-card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-2), 0 24px 50px -20px #0d0e1240;
  padding: 18px; display: flex; flex-direction: column;
  animation: cf-entrada .2s cubic-bezier(.22, 1, .36, 1);
}
@keyframes cf-entrada { from { transform: scale(.94); opacity: 0 } to { transform: scale(1); opacity: 1 } }
.cf-seal {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  display: grid; place-items: center;
  background: var(--brand-dim); color: var(--brand); margin-bottom: 11px;
}
.cf-seal[hidden] { display: none; }
.cf-seal svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* `h2` global do CRM é uppercase + cinza (rótulo de seção). O título do modal
   é uma frase para o operador ler — precisa neutralizar as duas coisas, senão
   sai "REVOGAR O ACESSO DESTE USUÁRIO?" em cinza claro. */
.cf-title {
  margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.012em; line-height: 1.3;
  text-transform: none; color: var(--text-1);
}
.cf-msg { margin: 6px 0 0; font-size: 13.5px; color: var(--text-2); line-height: 1.5; }
.cf-msg[hidden] { display: none; }
.cf-campo { display: flex; flex-direction: column; gap: 5px; margin-top: 13px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.cf-campo[hidden] { display: none; }
.cf-campo textarea {
  font: inherit; font-size: 14px; font-weight: 400; color: var(--text-1); resize: vertical;
  background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px;
}
/* Borda + halo suave em vez de outline duro de 2px, que lia como erro. */
.cf-campo textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-dim); }
.cf-acts { display: flex; gap: 8px; margin-top: 16px; }
.cf-btn {
  flex: 1; appearance: none; font: inherit; font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 14px; transition: .15s;
}
.cf-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.cf-cancel { background: var(--surface-1); color: var(--text-1); border-color: var(--border-strong); }
.cf-cancel:hover { background: var(--surface-3); }
/* Neutro = escuro; destrutivo = vermelho da marca. O vermelho perde o peso
   se for usado também em "enviar mensagem" ou "confirmar PIX pago". */
.cf-ok { background: var(--text-1); color: #fff; }
.cf-ok:hover { opacity: .88; }
.cf-ok.destrutivo { background: var(--brand); color: #fff; }
.cf-ok.destrutivo:hover { background: var(--brand-bright); }
@media (max-width: 520px) { .cf-btn { min-height: 48px; } }
@media (prefers-reduced-motion: reduce) { .cf-card { animation: none; } }
