:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --border: #e1e0d9;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #5b9a1f;          /* verde Braschlor (botões) */
  --accent-ink: #ffffff;
  --series-1: #2a78d6;        /* Faturamento */
  --series-2: #eb6834;        /* Recebido */
  --danger: #d03b3b;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --border: #2c2c2a;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --accent: #7cbf3a;
    --accent-ink: #0b0b0b;
    --series-1: #3987e5;
    --series-2: #d95926;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --border: #2c2c2a; --text: #f0efec;
  --text-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --accent: #7cbf3a; --accent-ink: #0b0b0b; --series-1: #3987e5; --series-2: #d95926;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.4; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 24px;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--accent);
  color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; }
.brand h1 { font-size: 18px; margin: 0; }
.login-card p.sub { color: var(--text-2); margin: 0 0 20px; font-size: 14px; }
label { display: block; font-size: 13px; color: var(--text-2); margin: 12px 0 4px; }
input[type=email], input[type=password] {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg);
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn { width: 100%; margin-top: 20px; padding: 12px; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; }
.btn:disabled { opacity: .6; cursor: wait; }
.erro { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 1em; }

/* ---------- Painel ---------- */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--surface);
  border-bottom: 1px solid var(--border); padding: 10px 16px; display: flex;
  align-items: center; gap: 12px; }
.topbar .brand { margin: 0; flex: 1; min-width: 0; }
.topbar .brand h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-btn { background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; font-size: 13px; color: var(--text-2); }

main { max-width: 1100px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
main > *, #conteudo { min-width: 0; }
.filtros { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filtros select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); }
.atualizado { color: var(--muted); font-size: 12px; margin-left: auto; }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 760px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.kpi .rotulo { color: var(--text-2); font-size: 13px; }
.kpi .valor { font-size: clamp(17px, 4.6vw, 22px); overflow-wrap: anywhere; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .detalhe { color: var(--muted); font-size: 12px; margin-top: 2px; }

.cards { display: grid; gap: 16px; }
@media (min-width: 900px) { .cards { grid-template-columns: 1fr 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; min-width: 0; }
.card h2 { font-size: 15px; margin: 0; }
.card .sub { color: var(--muted); font-size: 12px; margin: 2px 0 10px; }
.legenda { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.legenda span::before { content: ""; display: inline-block; width: 10px; height: 10px;
  border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: var(--c); }
svg.grafico { width: 100%; height: auto; display: block; overflow: visible; }
#g-meses, #g-top { width: 100%; }
svg text { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
svg text.valor-barra { fill: var(--text-2); }

.tabela-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child, th:nth-child(2), td:nth-child(2) { text-align: left; }
td:nth-child(2) { max-width: 240px; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
th { color: var(--text-2); font-weight: 600; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface); }
th[aria-sort]::after { content: " ▾"; }
th[aria-sort="ascending"]::after { content: " ▴"; }
tfoot td { font-weight: 650; border-top: 1px solid var(--axis); border-bottom: 0; }

.tooltip { position: fixed; pointer-events: none; z-index: 20; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px;
  box-shadow: 0 4px 16px rgb(0 0 0 / .12); max-width: 260px; }
.tooltip b { display: block; margin-bottom: 4px; }
.tooltip .linha { display: flex; justify-content: space-between; gap: 12px; }
.tooltip .linha i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 6px; background: var(--c); }

.carregando { text-align: center; color: var(--muted); padding: 40px 0; }

.f-datas { display: flex; gap: 8px; flex-wrap: wrap; }
.f-datas label { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; color: var(--text-2); }
.f-datas input { padding: 7px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.periodo-texto { font-size: 13px; color: var(--text-2); margin-top: -6px; }

.btn-atualizar { display: inline-flex; align-items: center; gap: 6px; color: var(--text); border-color: var(--accent); }
.btn-atualizar:disabled { opacity: .7; cursor: wait; }
.btn-atualizar.girando svg { animation: girar 0.9s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn-atualizar.girando svg { animation: none; } }
.aviso { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 20px rgb(0 0 0 / .2); max-width: calc(100vw - 32px); }
.aviso.erro { background: var(--danger); color: #fff; }

/* ---------- Logo Braschlor ---------- */
.logo img { display: block; height: auto; width: 100%; }
.login-logo { width: 220px; max-width: 80%; margin: 0 auto 16px; }
.login-titulo { font-size: 18px; text-align: center; margin: 0 0 4px; }
.login-card p.sub { text-align: center; }
.logo-topo { width: 118px; flex: none; }
.brand-titulo { font-weight: 650; font-size: 15px; color: var(--text-2); padding-left: 10px;
  border-left: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 460px) { .brand-titulo { display: none; } }
