:root {
  --ink: #16211c;
  --green: #0f4c3a;
  --green-2: #1f7a5c;
  --paper: #f4f6f5;
  --card: #ffffff;
  --line: #e3e8e6;
  --muted: #7b8a84;
  --accent: #123f30;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: Inter, system-ui, sans-serif; font-size: 14px;
}
.num, .card .v, table td.num { font-family: Montserrat, sans-serif; font-variant-numeric: tabular-nums; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--green-2); }
.brand h1 { font-size: 15px; font-weight: 500; margin: 0; }
.brand strong { font-weight: 700; }
.meta { display: flex; align-items: center; gap: 10px; }
.pill { font-size: 12px; color: var(--muted); background: var(--paper); border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 12px; cursor: pointer; font: inherit; }
.btn:hover { background: var(--paper); }

/* Tabs */
.tabs { display: flex; gap: 4px; padding: 0 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.tab { border: none; background: none; padding: 12px 14px; cursor: pointer; font: inherit; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--ink); border-bottom-color: var(--green); font-weight: 600; }

main { max-width: 1320px; margin: 0 auto; padding: 18px; }
.page { display: none; }
.page.active { display: block; }

.band { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-weight: 700; letter-spacing: .5px; margin-bottom: 14px; }

/* Cards — flex centrado p/ linhas equilibradas (5+4 em vez de 7+2) */
.cards { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-bottom: 14px; }
.card { flex: 1 1 180px; max-width: 240px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; overflow: hidden; }
.card .k { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .v { font-size: 20px; font-weight: 800; margin-top: 6px; white-space: nowrap; }
.card.hl { background: var(--green); color: #fff; }
.card.hl .k { color: #cfe8df; }
.card.warn .v { color: #b23b3b; }

/* Panels + layout */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; margin-bottom: 14px; }
.panel { min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
/* painéis soltos (filhos diretos da página) ganham o mesmo respiro vertical
   que .grid-2/.cards; os painéis dentro de .grid-2 usam o gap e não são afetados */
.page > .panel { margin-bottom: 14px; }
.panel h2 { font-size: 13px; font-weight: 600; margin: 0 0 12px; color: var(--accent); }
.chart-wrap { position: relative; height: 260px; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
.chart-wrap.tall { height: 320px; }
.chart-inner { position: relative; height: 100%; min-width: 100%; }

/* Gauges (semicírculo, estilo Looker) */
.gauges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; align-items: end; }
.gauge { text-align: center; }
.gwrap { position: relative; height: 96px; }
.gwrap canvas { position: absolute; inset: 0; }
.gwrap .gc { position: absolute; left: 0; right: 0; bottom: 4px; font-family: Montserrat; font-size: 16px; font-weight: 700; color: var(--ink); }
.gauge .g-lbl { font-size: 10.5px; line-height: 1.25; color: var(--muted); margin-top: 6px; }

/* Tables */
.table-wrap { overflow-x: auto; max-width: 100%; }
table { min-width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
th { background: var(--ink); color: #fff; font-weight: 600; font-size: 12px; }
td.num, th.num { text-align: right; }

/* Lead score */
.ls-head { display: grid; grid-template-columns: minmax(0, 200px) minmax(0, 1fr); gap: 14px; margin-bottom: 14px; align-items: start; }
.filtros { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; min-width: 0; }
.filtros label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 3px; min-width: 0; }
.filtros select, .filtros input { font: inherit; padding: 8px; border: 1px solid var(--line); border-radius: 8px; width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; background: var(--card); }

/* Breakdown por plataforma — um bloco por plataforma, estilo Looker:
   logo + scorecards no topo; tabela do gerenciador + tabela do Active lado a lado */
.bd-grid { display: flex; flex-direction: column; gap: 18px; }
.bd-block { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.bd-top { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 12px 16px; background: var(--paper); border-bottom: 1px solid var(--line); }
.bd-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; min-width: 140px; }
.bd-brand img { width: 26px; height: 26px; object-fit: contain; }
.bd-kpis { display: flex; gap: 12px; flex: 1; justify-content: flex-end; flex-wrap: wrap; }
.bd-kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 20px; text-align: center; min-width: 140px; }
.bd-kpi .k { font-size: 10px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); }
.bd-kpi .v { font-family: Montserrat; font-weight: 800; font-size: 17px; margin-top: 3px; }
.bd-tables { display: grid; grid-template-columns: minmax(0, 2.4fr) minmax(0, 1fr); }
.bd-tables > div:first-child { border-right: 1px solid var(--line); }
.bd-scroll { max-height: 420px; overflow-y: auto; overflow-x: hidden; }
.bd-block table { width: 100%; font-size: 12px; }
.bd-block th, .bd-block td { padding: 6px 8px; white-space: nowrap; }
.bd-block td:first-child, .bd-block th:first-child { padding-left: 12px; }
.bd-block thead th { position: sticky; top: 0; }
.bd-block tfoot td { font-weight: 700; background: var(--paper); position: sticky; bottom: 0; border-top: 2px solid var(--line); }
@media (max-width: 900px) { .bd-tables { grid-template-columns: minmax(0, 1fr); } .bd-tables > div:first-child { border-right: none; border-bottom: 1px solid var(--line); } }
.bd-card tfoot td { font-weight: 700; background: var(--paper); position: sticky; bottom: 0; border-top: 2px solid var(--line); }

/* Categoria: tabela + gráfico */
.cat-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: center; }
.cat-split .chart-wrap { height: 230px; }
@media (max-width: 820px) { .cat-split { grid-template-columns: minmax(0, 1fr); } }

/* ==================== MOBILE ==================== */
@media (max-width: 900px) {
  /* tabelas do breakdown com scroll lateral no celular */
  .bd-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .bd-tables > div:first-child table { min-width: 560px; }
  .bd-tables > div:last-child table { min-width: 240px; }
  .bd-top { gap: 12px; }
  .bd-kpis { justify-content: flex-start; }
  .bd-kpi { flex: 1 1 auto; min-width: 92px; padding: 8px 12px; }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  main { padding: 12px; }
  .band { padding: 9px 12px; font-size: 13px; }

  /* topbar enxuta */
  .topbar { padding: 10px 12px; }
  .brand h1 { font-size: 12px; line-height: 1.25; }
  .brand .dot { width: 10px; height: 10px; }

  /* abas com alvo de toque ≥44px e roláveis */
  .tabs { padding: 0 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab { min-height: 44px; padding: 11px 12px; white-space: nowrap; }
  .btn { min-height: 40px; }

  /* scorecards: 2 por linha (menos empilhado, mais harmônico) */
  .cards { gap: 10px; }
  .card { flex: 1 1 calc(50% - 5px); max-width: none; padding: 12px 14px; }
  .card .k { font-size: 10px; }
  .card .v { font-size: 18px; }

  /* medidores compactos: 2×2 no celular (minmax evita estourar a coluna) */
  .gauges { gap: 10px 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gauge { min-width: 0; }
  .gwrap { height: 92px; }
  .gwrap .gc { font-size: 15px; }
  .gauge .g-lbl { font-size: 10.5px; line-height: 1.25; overflow-wrap: anywhere; }

  /* gráficos com scroll lateral e um pouco mais altos p/ caber a barra */
  .chart-wrap { height: 290px; }
  .chart-wrap.tall { height: 330px; }
  .chart-inner { min-width: 560px; }
  .cat-split .chart-inner { min-width: 440px; }

  .panel { padding: 12px; }
  .panel h2 { font-size: 13px; }
}

.muted { color: var(--muted); }
.foot { padding: 10px 20px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }

@media (max-width: 820px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .ls-head { grid-template-columns: minmax(0, 1fr); }
  .brand h1 { font-size: 13px; }
}
