/* ==========================================================================
   Brava Energia — Guia de Valuation · Design System (dark-first, CSS puro)
   Sem empacotadores: apenas CSS3. As variáveis abaixo são lidas também pelos
   scripts via getComputedStyle(...).getPropertyValue() (helper tok()).
   ========================================================================== */

/* ------------------------------------------------------------- 1. Tokens -- */
:root {
  /* Paleta corporativa dark */
  --bg: #0b0f19;            /* fundo da página            */
  --bg-2: #0e1420;          /* fundo de seções alternadas */
  --surface: #131a2a;       /* cards e painéis            */
  --surface-2: #1e293b;     /* cards elevados / hover     */
  --ink: #e6edf7;           /* texto principal            */
  --ink-2: #aab6c9;         /* texto secundário           */
  --muted: #7d8aa0;         /* rótulos e legendas         */
  --line: rgba(148, 163, 184, .14);   /* bordas sutis     */
  --line-strong: rgba(148, 163, 184, .28);
  --axis: rgba(148, 163, 184, .10);   /* grades de gráfico */

  /* Destaque em verde vibrante */
  --accent: #84cc16;
  --accent-hi: #a3e635;     /* hover / foco               */
  --accent-ink: #101605;    /* texto sobre o verde        */
  --accent-soft: rgba(132, 204, 22, .12);

  /* Semântica financeira */
  --up: #4ade80;
  --down: #f87171;
  --warn: #fbbf24;

  /* Série cromática dos gráficos (harmonizada com o dark) */
  --s1: #84cc16;  --s2: #38bdf8;  --s3: #f59e0b;  --s4: #a78bfa;
  --s5: #f472b6;  --s6: #34d399;  --s7: #fb7185;  --s8: #22d3ee;

  /* Tipografia (fontes já importadas no projeto) */
  --f-display: "Archivo", "Arial Narrow", Arial, sans-serif;
  --f-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;

  --fs-h1: 1.55rem;  --fs-h2: 1.05rem;  --fs-h3: .74rem;
  --fs-metric: 1.45rem;  --fs-body: .9rem;  --fs-small: .8rem;

  /* Cantos arredondados (6–8px, borda dura proibida) */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;

  /* Espaçamento estrutural — mesmo grid entre abas */
  --pad-card: 16px 18px;
  --pad-cell: 10px 12px;
  --gap-grid: 16px;

  /* Sombras sóbrias */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, .45);

  /* Tooltips */
  --tip-bg: #1e293b;
  --tip-ink: #e6edf7;
  --tip-w: 280px;
  color-scheme: dark;
}

/* Tema claro legado: só sobrescreve tokens, nunca regras */
:root[data-theme="light"] {
  --bg: #eef1f0; --bg-2: #e7ecea; --surface: #fcfcfb; --surface-2: #f3f5f4;
  --ink: #0d191b; --ink-2: #4a5759; --muted: #5f6a6a;
  --line: #e0e4e2; --line-strong: #c8cfcd; --axis: #d5dbd9;
  --accent: #4d7c0f; --accent-hi: #3f6212; --accent-ink: #ffffff;
  --accent-soft: rgba(101, 163, 13, .12);
  --up: #006300; --down: #c23030;
  --tip-bg: #0d191b; --tip-ink: #f2f5f4;
  color-scheme: light;
}

/* ------------------------------------------------------- 2. Reset leve -- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: var(--fs-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
p { margin: 0; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
.sobe { color: var(--up); }
.desce { color: var(--down); }

/* -------------------------------------------------- 3. Hierarquia tipográfica */
h1, h2, h3 { font-family: var(--f-display); font-stretch: 112%; margin: 0; text-wrap: balance; }
h1 { font-size: var(--fs-h1); font-weight: 750; letter-spacing: -.01em; }
h2 { font-size: var(--fs-h2); font-weight: 700; }
h3 {
  font-size: var(--fs-h3); font-weight: 650;
  text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-2);
}
.metrica {                      /* números financeiros */
  font-family: var(--f-mono);
  font-size: var(--fs-metric);
  font-weight: 500;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.rotulo { font-size: var(--fs-small); color: var(--muted); }

/* --------------------------------------------------- 4. Layout estrutural -- */
.wrap { max-width: 1360px; margin: 0 auto; padding: 20px 20px 56px; display: grid; gap: var(--gap-grid); }

/* Cards de dados: canto arredondado, borda sutil, sem parágrafo explicativo */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--pad-card);
  box-shadow: var(--shadow-1);
  min-width: 0;
}
.card--hero { background: linear-gradient(160deg, var(--surface-2), var(--surface)); }
.card__head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.card__head h3 { flex: 1; }
.card__foot {
  margin-top: 12px; padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: var(--fs-small); color: var(--muted);
}
.grade { display: grid; gap: var(--gap-grid); grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* Faixa de KPIs no topo */
.kpis {
  display: grid;
  grid-template-columns: minmax(230px, 1.5fr) repeat(auto-fit, minmax(128px, 1fr));
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}
.kpi { padding: 14px 18px; border-left: 1px solid var(--line); min-width: 0; }
.kpi:first-child { border-left: 0; background: var(--accent); color: var(--accent-ink); }
.kpi:first-child .rotulo { color: rgba(16, 22, 5, .75); }
.kpi .metrica { font-size: 1.15rem; display: block; margin-top: 2px; }

/* ---------------------------------------------------------- 5. Botões -- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--ink);
  font: 600 .85rem var(--f-body);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent-hi); }
.btn--primario { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primario:hover { background: var(--accent-hi); border-color: var(--accent-hi); color: var(--accent-ink); }

/* ---------------------------------------------------------- 6. Tabelas -- */
/* Divisórias finas de baixa opacidade — leitura em modo escuro */
.tabela { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tabela th {
  text-align: left; font-size: var(--fs-h3); font-weight: 650;
  text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted);
  padding: var(--pad-cell);
  border-bottom: 1px solid var(--line-strong);
}
.tabela td { padding: var(--pad-cell); border-bottom: 1px solid var(--line); }
.tabela tbody tr:last-child td { border-bottom: 0; }
.tabela tbody tr { transition: background .12s; }
.tabela tbody tr:hover { background: var(--accent-soft); }
.tabela .num { font-family: var(--f-mono); text-align: right; }

/* ---------------------------------------------------- 7. Ícones outline -- */
/* SVGs criados via createElementNS devem trazer a classe .ic (ver exemplo-grafico.js):
   traço padronizado, sem preenchimento, cor herdada. */
.ic {
  width: 18px; height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.ic--sm { width: 14px; height: 14px; }
.ic--pos { color: var(--up); }
.ic--neg { color: var(--down); }

/* --------------------------------------------------- 8. Sistema de tooltips -- */
/* 8a. Tooltip puro CSS: qualquer elemento com [data-tip] exibe balão no hover */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%; bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(4px);
  width: max-content; max-width: var(--tip-w);
  background: var(--tip-bg);
  color: var(--tip-ink);
  font: 400 .8rem/1.45 var(--f-body);
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-2);
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 60;
}
[data-tip]::before {                       /* seta do balão */
  content: "";
  position: absolute;
  left: 50%; bottom: calc(100% + 3px);
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--tip-bg);
  opacity: 0;
  transition: opacity .2s ease;
  z-index: 61;
  pointer-events: none;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after,
[data-tip]:hover::before, [data-tip]:focus-visible::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
[data-tip]:hover::before, [data-tip]:focus-visible::before { transform: translateX(-50%); }

/* Variação lateral para bordas da tela: use data-tip-side="right" */
[data-tip-side="right"]::after { left: calc(100% + 10px); bottom: auto; top: 50%; transform: translateY(-50%) translateX(-4px); }
[data-tip-side="right"]::before { left: calc(100% + 2px); bottom: auto; top: 50%; transform: translateY(-50%); border-top-color: transparent; border-right-color: var(--tip-bg); }
[data-tip-side="right"]:hover::after, [data-tip-side="right"]:focus-visible::after { transform: translateY(-50%) translateX(0); }

/* 8b. Botão "?" de ajuda (compatível com o sistema .ajuda/.balao do app.js) */
.ajuda {
  display: inline-grid; place-items: center;
  width: 16px; height: 16px;
  margin-left: 5px; padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  font: 600 .68rem var(--f-body);
  cursor: help;
  opacity: .85;
  transition: opacity .15s, background .15s, color .15s, border-color .15s;
  vertical-align: 1px;
}
.ajuda:hover, .ajuda:focus-visible, .ajuda[aria-expanded="true"] {
  opacity: 1;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* 8c. Balão rico posicionado por JS (textos longos, imagens — ver app.js) */
.balao {
  position: fixed;
  z-index: 130;
  background: var(--tip-bg);
  color: var(--tip-ink);
  font-size: .84rem; line-height: 1.45;
  padding: 10px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-2);
  max-height: 60vh; overflow: auto;
  transition: opacity .2s ease;
}
.balao.com-img { color: #fff; background-color: #170070; background-size: cover; background-position: center bottom; text-shadow: 0 1px 2px rgba(0, 0, 0, .55); min-height: 170px; padding-bottom: 80px; }
.balao.com-img b { color: #c8ff00; display: block; font-family: var(--f-display); letter-spacing: .02em; margin-bottom: 3px; }

/* ------------------------------------------------------ 9. Abas (tabs) -- */
/* Grid visual idêntico entre painéis — a transição só troca o conteúdo */
.abas { display: grid; gap: var(--gap-grid); }
.abas__nav { display: flex; flex-wrap: wrap; gap: 6px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.aba {
  padding: 8px 14px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-2);
  font: 600 .84rem var(--f-body);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.aba:hover { color: var(--accent-hi); background: var(--accent-soft); }
.aba[aria-selected="true"] {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}
.painel { display: grid; gap: var(--gap-grid); animation: entra .18s ease; }
@keyframes entra { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .painel { animation: none; }
  [data-tip]::after, [data-tip]::before, .balao { transition: none; }
}

/* -------------------------------------------------------- 10. Modais -- */
.modal {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  padding: 20px;
  max-width: min(640px, calc(100vw - 32px));
}
.modal::backdrop { background: rgba(4, 8, 16, .72); backdrop-filter: blur(3px); }

/* ------------------------------------------------- 11. Gráficos (canvas) -- */
.grafico-box {
  position: relative;
  height: 280px;
  padding: 8px 4px 0;
}
.grafico-box canvas { width: 100% !important; height: 100% !important; }

/* ------------------------------------------------------- 12. Utilidades -- */
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.no-q { display: none !important; }
.stack { display: grid; gap: var(--gap-grid); }
.linha { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
