:root {
  --bg: #0a0a0b;
  --surface: #131316;
  --surface-2: #1a1a20;
  --border: #26262e;
  --text: #f2f2f5;
  --muted: #8b8b96;

  /* dourado neon — cor de destaque do studio */
  --gold: #f5c518;
  --gold-bright: #ffdf5c;
  --gold-deep: #c99a06;
  --gold-soft: rgba(245, 197, 24, 0.13);
  --gold-line: rgba(245, 197, 24, 0.38);
  --on-gold: #14140a;

  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --blue: #38bdf8;
  --purple: #a78bfa;

  --radius: 14px;
  /* Fontes do sistema — nada baixado da rede, nada bloqueando a primeira pintura. */
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, sans-serif;
  --cond: "Barlow Condensed", "Oswald", "Segoe UI Variable Display", "Segoe UI Semibold", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Precisa vir com !important: as classes .app/.loading definem display e, sem isso,
   ganham do [hidden] do navegador — era o que deixava o "carregando" preso no topo. */
[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::selection { background: var(--gold); color: var(--on-gold); }

/* ── layout ───────────────────────────────────────────────────────────────── */
/* minmax(0,1fr) em vez de 1fr: trilha 1fr tem min-width auto e seria esticada
   pelo conteúdo mais largo (o menu rolável, as tabelas), estourando a página */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar, .main { min-width: 0; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--gold), var(--gold-bright));
  color: var(--on-gold);
  display: grid; place-items: center;
  font-family: var(--cond); font-weight: 700; font-size: 17px; letter-spacing: -0.5px;
  flex: none;
}
.brand-name { font-family: var(--cond); font-size: 21px; font-weight: 600; letter-spacing: 0.3px; text-transform: uppercase; }
.brand-sub { font-size: 10.5px; color: var(--muted); letter-spacing: 1.4px; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0; color: var(--muted);
  font: inherit; text-align: left;
  padding: 9px 11px; border-radius: 9px; cursor: pointer;
  white-space: nowrap;
  transition: background .12s, color .12s;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.active { background: var(--gold-soft); color: var(--gold); font-weight: 600; }
.nav .ico { width: 17px; text-align: center; font-size: 14px; flex: none; }
.nav .badge {
  margin-left: auto; background: var(--red); color: #fff;
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 999px;
}

.sidebar-foot { margin-top: auto; padding-top: 16px; display: grid; gap: 10px; }

.sync-box { padding: 11px; background: var(--surface-2); border-radius: 10px; font-size: 11px; color: var(--muted); }
.sync-box strong { color: var(--text); display: block; font-size: 11.5px; margin-bottom: 3px; }

.live { display: inline-flex; align-items: center; gap: 6px; margin-top: 7px; font-size: 10.5px; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); flex: none; }
.live.on .live-dot { animation: pulse 2s infinite; }
.live.off .live-dot { background: var(--muted); }
.live.sync .live-dot { background: var(--gold); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

.user-box {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; background: var(--surface-2); border-radius: 10px;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: var(--gold-soft); color: var(--gold);
  display: grid; place-items: center; font-weight: 700; font-size: 12px;
}
.user-box .nome { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-box .papel { font-size: 10.5px; color: var(--muted); }
.icon-btn {
  margin-left: auto; background: none; border: 0; color: var(--muted);
  cursor: pointer; font-size: 15px; padding: 4px; border-radius: 6px; line-height: 1;
}
.icon-btn:hover:not(:disabled) { color: var(--gold); background: rgba(255,255,255,.05); }
.icon-btn:disabled { opacity: .5; cursor: default; }

/* botão de atualizar: fica no cabeçalho, portanto visível em todas as telas */
.refresh { font-size: 18px; }
.refresh .refresh-ico { display: inline-block; }
.refresh.girando { color: var(--gold); }
.refresh.girando .refresh-ico { animation: spin 1s linear infinite; }

.main { padding: 26px 30px 60px; max-width: 1500px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; flex-wrap: wrap; }
h1 { font-family: var(--cond); font-size: 31px; font-weight: 600; letter-spacing: 0.2px; text-transform: uppercase; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

section.view { display: none; }
section.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ── cards ────────────────────────────────────────────────────────────────── */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(186px, 1fr)); margin-bottom: 20px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 17px 18px;
  min-width: 0;
}
.card h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.1px;
  color: var(--muted); font-weight: 600; margin-bottom: 14px;
}
.card h3 .hint { text-transform: none; letter-spacing: 0; font-weight: 400; color: #5f5f6b; margin-left: 6px; }

.kpi .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.9px; color: var(--muted); font-weight: 600; }
.kpi .value { font-family: var(--cond); font-size: 33px; font-weight: 600; line-height: 1.12; margin-top: 5px; letter-spacing: 0.3px; }
.kpi .value.sm { font-size: 26px; }
.kpi .foot { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.kpi.accent { border-color: var(--gold-line); background: linear-gradient(160deg, var(--gold-soft), var(--surface) 62%); }
.kpi.accent .value { color: var(--gold); }

.delta { font-size: 11.5px; font-weight: 600; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.delta.flat { color: var(--muted); }

/* ── charts ───────────────────────────────────────────────────────────────── */
/* min-width:0 impede que o canvas dimensionado pelo Chart.js estique a coluna */
.chart-wrap { position: relative; height: 260px; min-width: 0; }
.chart-wrap canvas { max-width: 100%; }
.chart-wrap.tall { height: 330px; }
.chart-wrap.short { height: 200px; }

/* ── tabelas ──────────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; max-height: 560px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--muted);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.8px; font-weight: 600;
  text-align: left; padding: 9px 11px; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 9px 11px; border-bottom: 1px solid rgba(38, 38, 46, 0.6); white-space: nowrap; }
tbody tr:hover { background: rgba(255, 255, 255, 0.022); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.name-cell { display: inline-block; max-width: 230px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.pill.ok { background: rgba(34, 197, 94, 0.14); color: var(--green); }
.pill.warn { background: rgba(245, 158, 11, 0.14); color: var(--amber); }
.pill.bad { background: rgba(239, 68, 68, 0.14); color: var(--red); }
.pill.mute { background: rgba(139, 139, 150, 0.14); color: var(--muted); }
.pill.info { background: rgba(56, 189, 248, 0.14); color: var(--blue); }
.pill.gold { background: var(--gold-soft); color: var(--gold); }

.risk-bar { display: inline-flex; align-items: center; gap: 7px; }
.risk-track { width: 52px; height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.risk-fill { height: 100%; border-radius: 3px; }

/* ── heatmap ──────────────────────────────────────────────────────────────── */
.heat { display: grid; grid-template-columns: 62px repeat(24, 1fr); gap: 2px; font-size: 9.5px; min-width: 660px; }
.heat .hlabel { color: var(--muted); display: flex; align-items: center; }
.heat .hhead { color: var(--muted); text-align: center; }
.heat .cell { aspect-ratio: 1; border-radius: 3px; background: var(--surface-2); }

.cohort-table td.c { text-align: center; font-weight: 600; font-size: 12px; border-radius: 4px; }

/* ── controles ────────────────────────────────────────────────────────────── */
.toolbar { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; margin-bottom: 13px; }
input[type="search"], input[type="text"], input[type="password"], select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: 9px; font: inherit; font-size: 15px; outline: none;
  width: 100%;
}
@media (min-width: 700px) {
  input[type="search"], input[type="text"], input[type="password"], select { font-size: 13px; padding: 7px 11px; }
}
input:focus, select:focus { border-color: var(--gold); }
.toolbar input[type="search"] { min-width: 200px; width: auto; flex: 1 1 200px; max-width: 320px; }
.toolbar select { width: auto; }

.btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 8px 13px; border-radius: 9px; font: inherit; font-size: 13px; cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--gold); color: var(--gold); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--on-gold); font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: var(--gold-bright); border-color: var(--gold-bright); color: var(--on-gold); }
.btn.danger:hover:not(:disabled) { border-color: var(--red); color: var(--red); }
.btn.block { width: 100%; padding: 12px; font-size: 15px; margin-top: 6px; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
/* link direto para o WhatsApp na fila de contato */
.btn.zap {
  text-decoration: none; display: inline-block;
  border-color: rgba(34,197,94,.45); color: var(--green);
  font-variant-numeric: tabular-nums;
}
.btn.zap::before { content: '💬 '; }
.btn.zap:hover { background: rgba(34,197,94,.12); border-color: var(--green); color: var(--green); }

/* ── folha de pagamento ───────────────────────────────────────────────────── */
input[type="month"], input[type="number"] {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 8px 10px; border-radius: 9px; font: inherit; font-size: 14px; outline: none;
  width: 100%; color-scheme: dark;
}
input[type="month"]:focus, input[type="number"]:focus { border-color: var(--gold); }

.campo { display: grid; gap: 4px; min-width: 0; }
.campo > span { font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }

.folha-barra { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.folha-barra .campo { flex: 0 0 190px; }
.folha-acoes { display: flex; gap: 8px; flex-wrap: wrap; flex: 1 1 auto; }

.pessoa { margin-bottom: 12px; }
.pessoa > summary {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; cursor: pointer;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); list-style: none;
}
.pessoa > summary::-webkit-details-marker { display: none; }
.pessoa > summary::before { content: '▸'; color: var(--muted); font-size: 12px; }
.pessoa[open] > summary::before { content: '▾'; color: var(--gold); }
.pessoa[open] > summary { border-radius: 12px 12px 0 0; border-bottom-color: transparent; }
.pessoa > summary:hover { border-color: var(--gold); }
.pessoa .pnome { font-weight: 650; min-width: 0; }
.pessoa .pliq { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--gold); }
.pessoa .corpo {
  border: 1px solid var(--border); border-top: 0; border-radius: 0 0 12px 12px;
  padding: 14px; background: var(--surface-2);
}
.pessoa .linhas { display: grid; gap: 3px; margin-bottom: 12px; }
.pessoa .linhas .l {
  display: grid; grid-template-columns: minmax(0,1fr) 90px 52px 96px; gap: 8px;
  font-size: 12.5px; padding: 4px 0; align-items: baseline;
}
.pessoa .linhas .l > :not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.pessoa .linhas .l.cab { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
.pessoa .linhas .l.somatorio { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 7px; font-weight: 700; }
.pessoa .edicao { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; align-items: end; }
.pessoa .edicao .estreito { max-width: 110px; }

.secao {
  font-size: 12px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted);
  font-weight: 700; margin: 26px 0 12px; padding-top: 18px; border-top: 1px solid var(--border);
}

/* DRE: primeira coluna fixa e números tabulares */
#tab-dre table td:not(:first-child), #tab-dre table th:not(:first-child),
#tab-projecao table td:not(:first-child), #tab-conciliacao table td:not(:first-child) {
  font-variant-numeric: tabular-nums;
}
#tab-dre tr.grupo td { font-weight: 700; background: var(--surface-2); }
#tab-dre tr.resultado td { font-weight: 700; border-top: 1px solid var(--border); }
#tab-dre tr.resultado.forte td { color: var(--gold); font-size: 1.05em; }
#tab-dre tr.conta td:first-child { padding-left: 26px; color: var(--muted); }
#tab-dre td[data-fin] { cursor: pointer; }
#tab-dre td[data-fin]:hover { background: rgba(245,197,24,.10); }
#tab-dre td.vazia { color: var(--muted); }
/* análise vertical: o % vive embaixo do valor, sem competir com ele */
.av { display: block; font-size: 10px; color: var(--muted); font-weight: 400; margin-top: 1px; }

/* célula editável do drill: trocar a conta contábil sem sair da lista */
.conta-edit { display: flex; gap: 5px; align-items: center; min-width: 210px; }
.conta-edit select { font-size: 12px; padding: 4px 6px; min-width: 0; flex: 1; }
.conta-edit .btn { flex: 0 0 auto; }
#tab-dre tr.resultado.forte .av { color: var(--gold); opacity: .75; }
.val-neg { color: var(--red); }
.val-pos { color: var(--green); }

@media (max-width: 700px) {
  .pessoa .linhas .l { grid-template-columns: minmax(0,1fr) 76px 84px; }
  .pessoa .linhas .l > .ref { display: none; }
  .folha-barra .campo { flex: 1 1 100%; }
}

/* ── filtro de data ───────────────────────────────────────────────────────── */
.filtro {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-bottom: 16px; padding: 12px 14px;
  position: sticky; top: 0; z-index: 40;
  max-width: 100%; min-width: 0;
}
.filtro .presets { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; max-width: 100%; }
.filtro .presets .btn.ativo {
  background: var(--gold); border-color: var(--gold); color: var(--on-gold); font-weight: 700;
}
.filtro .datas { display: flex; align-items: center; gap: 7px; }
.filtro .datas input {
  width: auto; padding: 5px 9px; font-size: 13px;
  color-scheme: dark; /* faz o seletor nativo de data nascer escuro */
}
.filtro .periodo-label { margin-left: auto; text-align: right; font-size: 12px; }

@media (max-width: 999px) {
  /* o cabeçalho já é sticky no mobile; dois sticky empilhados brigam por espaço */
  .filtro { position: static; }
}
@media (max-width: 620px) {
  .filtro { gap: 9px; }
  /* min-width:0 é obrigatório: sem ele o item flex não encolhe abaixo do conteúdo
     e a faixa de presets empurra a página inteira para o lado */
  .filtro .presets {
    width: 100%; min-width: 0; overflow-x: auto;
    flex-wrap: nowrap; padding-bottom: 2px; scrollbar-width: none;
  }
  .filtro .presets::-webkit-scrollbar { display: none; }
  .filtro .presets .btn { flex: none; }
  .filtro .datas { width: 100%; min-width: 0; }
  .filtro .datas input { flex: 1 1 0; min-width: 0; }
  .filtro .periodo-label { margin-left: 0; text-align: left; width: 100%; min-width: 0; }
}

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

.empty { color: var(--muted); font-size: 13px; padding: 26px 0; text-align: center; }
.note { font-size: 11.5px; color: var(--muted); margin-top: 10px; line-height: 1.5; }

/* ── boot / carregando ────────────────────────────────────────────────────── */
.loading {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: grid; place-content: center; justify-items: center;
  gap: 14px; color: var(--muted); text-align: center; padding: 24px;
}
.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--border); border-top-color: var(--gold);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── toast ────────────────────────────────────────────────────────────────── */
.toast-area {
  position: fixed; z-index: 200; right: 18px; bottom: 18px;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  padding: 11px 15px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  animation: slideIn .2s ease; max-width: min(90vw, 380px);
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── modal ────────────────────────────────────────────────────────────────── */
.modal-bg {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.65); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; width: min(440px, 100%);
  max-height: 90vh; overflow-y: auto;
}
.modal.wide { width: min(1020px, 100%); }
.modal h2 { font-family: var(--cond); font-size: 23px; text-transform: uppercase; margin-bottom: 14px; }

/* ── detalhamento dos KPIs ────────────────────────────────────────────────── */
.kpi-drill { cursor: pointer; transition: border-color .12s, transform .12s; }
.kpi-drill:hover, .kpi-drill:focus-visible {
  border-color: var(--gold-line); transform: translateY(-1px); outline: none;
}
.kpi-drill:hover .lupa, .kpi-drill:focus-visible .lupa { opacity: 1; }
.kpi .lupa {
  float: right; opacity: .35; font-size: 14px; line-height: 1;
  color: var(--gold); transition: opacity .12s;
}
.drill-como {
  background: var(--surface-2); border-left: 3px solid var(--gold);
  padding: 11px 13px; border-radius: 0 9px 9px 0;
  font-size: 13px; line-height: 1.55; color: #c9c9d1;
}
.drill-resumo { margin: 14px 0 10px; font-size: 13px; color: var(--muted); }
.drill-resumo strong { color: var(--text); }
.drill-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 9px; }
.modal label, form label {
  display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted); font-weight: 600; margin: 14px 0 5px;
}
.modal-acoes { display: flex; gap: 9px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }

.senha-gerada {
  background: var(--gold-soft); border: 1px dashed var(--gold-line);
  border-radius: 10px; padding: 13px; margin-top: 14px;
}
.senha-gerada code {
  display: block; font-size: 19px; font-weight: 700; color: var(--gold);
  letter-spacing: 1.5px; margin: 7px 0; word-break: break-all; font-family: ui-monospace, monospace;
}

/* ── login ────────────────────────────────────────────────────────────────── */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 30px 26px; width: min(400px, 100%);
}
.login-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 24px; }
.login-card h2 { font-family: var(--cond); font-size: 25px; text-transform: uppercase; letter-spacing: .5px; }
.login-nota { font-size: 13px; color: var(--muted); margin-top: 8px; line-height: 1.5; }
.login-dica { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.form-erro {
  background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.35); color: #fca5a5;
  padding: 10px 12px; border-radius: 9px; font-size: 13px; margin-top: 16px;
}

/* ── responsivo ───────────────────────────────────────────────────────────── */
@media (max-width: 999px) {
  .app { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: sticky; top: 0; z-index: 50;
    height: auto; padding: 10px 12px 0;
    border-right: 0; border-bottom: 1px solid var(--border);
    display: block;
  }
  .brand { padding: 0 0 10px; }
  .sidebar-foot { display: none; }

  .nav {
    flex-direction: row; gap: 6px;
    overflow-x: auto; scrollbar-width: none;
    padding-bottom: 10px; margin: 0 -12px; padding-left: 12px; padding-right: 12px;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav button { padding: 8px 12px; font-size: 13px; background: var(--surface-2); }
  .nav .ico { display: none; }

  .main { padding: 18px 14px 60px; }
  h1 { font-size: 26px; }
  /* minmax(0,1fr): sem isso a trilha cresce com o conteúdo e estoura a página */
  .cols-2, .cols-3 { grid-template-columns: minmax(0, 1fr); }
  .chart-wrap { height: 240px; }
  .chart-wrap.tall { height: 300px; }
}

@media (max-width: 620px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 13px 14px; border-radius: 12px; }
  .kpi .value { font-size: 26px; }
  .kpi .value.sm { font-size: 21px; }
  .kpi .label { font-size: 10px; }
  .kpi .foot { font-size: 10.5px; }
  .grid { gap: 10px; }

  .main { padding: 14px 11px 50px; }
  h1 { font-size: 23px; }
  .page-sub { font-size: 12px; }

  .chart-wrap { height: 220px; }
  .chart-wrap.short { height: 190px; }
  .chart-wrap.tall { height: 280px; }

  table { font-size: 12px; }
  thead th { font-size: 9.5px; padding: 7px 8px; }
  tbody td { padding: 7px 8px; }
  .name-cell { max-width: 130px; }
  .table-scroll { max-height: 440px; }

  /* colunas secundárias saem do caminho no celular */
  .hide-sm { display: none !important; }

  .toolbar { gap: 7px; }
  .toolbar input[type="search"] { max-width: none; flex: 1 1 100%; }
  .toast-area { right: 10px; left: 10px; bottom: 10px; align-items: stretch; }
  .toast { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* linha-memória da DRE: informa, não soma */
#tab-dre tr.memo td { font-style: italic; color: var(--muted); }
#tab-dre tr.memo td:first-child { padding-left: 26px; }

/* tabela que ocupa a largura toda do card, sem barra horizontal */
.tabela-larga { overflow-x: visible; }
.tabela-larga table { width: 100%; table-layout: fixed; }
.tabela-larga td, .tabela-larga th { overflow: hidden; text-overflow: ellipsis; }
.tabela-larga .name-cell { max-width: none; }

/* ── ordenação de coluna e ficha da aluna ─────────────────────────────────── */
.ord { cursor: pointer; user-select: none; white-space: nowrap; }
.ord:hover { color: var(--gold); }
.ord.ativa { color: var(--gold); }

.link-aluna {
  background: none; border: 0; padding: 0; font: inherit; color: var(--text);
  cursor: pointer; text-align: left; max-width: 190px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; display: block;
}
.link-aluna:hover { color: var(--gold); text-decoration: underline; }

.ficha-topo { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 6px; }
.ficha-foto { width: 92px; height: 92px; flex: none; }
.ficha-foto img, .ficha-iniciais {
  width: 92px; height: 92px; border-radius: 14px; object-fit: cover;
  border: 1px solid var(--border); background: var(--surface-2);
}
.ficha-iniciais {
  display: grid; place-items: center; font-family: var(--cond);
  font-size: 34px; font-weight: 600; color: var(--gold); background: var(--gold-soft);
}
.ficha-id { flex: 1 1 260px; min-width: 0; }
.ficha-nome { font-family: var(--cond); font-size: 25px; font-weight: 600; letter-spacing: .3px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ficha-acoes { display: flex; gap: 8px; margin-top: 9px; flex-wrap: wrap; align-items: center; }
.ficha-numeros { display: grid; grid-template-columns: repeat(2, minmax(120px, 1fr)); gap: 8px 18px; flex: 0 1 300px; }

.ficha-sec {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.1px; color: var(--muted);
  font-weight: 700; margin: 22px 0 10px; padding-top: 14px; border-top: 1px solid var(--border);
}
.ficha-grade { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 18px; }
.dado { min-width: 0; }
.dado > span { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.dado > strong { font-size: 13.5px; font-weight: 600; overflow-wrap: anywhere; }

/* histórico de acessos por mês, em barras — dá o ritmo de um olhar */
.ficha-barras { display: flex; gap: 6px; align-items: flex-end; height: 74px; margin-top: 14px; }
.ficha-barras .barra { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 4px; min-width: 0; }
.ficha-barras .haste { width: 100%; background: var(--gold); border-radius: 3px 3px 0 0; min-height: 3px; }
.ficha-barras span { font-size: 9px; color: var(--muted); }

@media (max-width: 700px) {
  .ficha-numeros { grid-template-columns: repeat(2, 1fr); flex: 1 1 100%; }
  .link-aluna { max-width: 130px; }
}

/* ── grade semanal ────────────────────────────────────────────────────────── */
table.grade { width: 100%; border-collapse: separate; border-spacing: 4px; }
table.grade th { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); text-align: center; padding: 4px; }
table.grade th.hora { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text); font-size: 11.5px; padding-right: 8px; }
table.grade td { vertical-align: top; padding: 0; min-width: 118px; }
table.grade td.vazia { background: var(--surface-2); border-radius: 8px; opacity: .35; }
.turma {
  display: grid; gap: 1px; padding: 7px 8px; border-radius: 8px; margin-bottom: 4px;
  background: var(--surface-2); border-left: 3px solid var(--muted); font-size: 11.5px;
}
.turma:last-child { margin-bottom: 0; }
.turma strong { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turma span { color: var(--muted); font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turma .ocup { font-variant-numeric: tabular-nums; }
.turma.ok { border-left-color: var(--green); }
.turma.warn { border-left-color: var(--amber); }
.turma.bad { border-left-color: var(--red); }
.turma[data-slot] { cursor: pointer; }
.turma[data-slot]:hover { background: var(--gold-soft); }
