/* Tokens: dark por padrão; claro quando o sistema pedir. */
:root {
  --bg: #0b0f14; --panel: #151b23; --line: #232c38; --text: #e2e8f0; --muted: #8a96a6;
  --green: #22c55e; --amber: #f59e0b; --red: #ef4444; --blue: #60a5fa;
  --radius: 14px; --gutter: 16px;
  /* a logo é preta: no tema escuro é invertida para branco */
  --logo-filter: invert(1);
  /* escala de espaçamento: todo espaço interno e entre blocos usa estes passos */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f7fa; --panel: #ffffff; --line: #dde3ea; --text: #0f172a; --muted: #5b6676;
  }
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) { --logo-filter: none; }
}
:root[data-theme="light"] { --logo-filter: none; }
:root[data-theme="light"] {
  --bg: #f5f7fa; --panel: #ffffff; --line: #dde3ea; --text: #0f172a; --muted: #5b6676;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom);
  overflow-x: hidden;
}
a { color: var(--blue); }
/* Barra do app: ícone no lugar do nome, título da tela e ações à direita. */
.appbar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: var(--s2);
  min-height: 56px; padding: calc(var(--s2) + env(safe-area-inset-top)) var(--gutter) var(--s2);
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.appbar-title { flex: 1; min-width: 0; margin: 0; font-size: 1.05rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-icon { width: 32px; height: 32px; border-radius: 8px; flex: none; }
button.icon-btn {
  background: transparent; color: var(--text); border: 0; border-radius: 12px;
  min-width: 44px; min-height: 44px; padding: 0; display: inline-grid; place-items: center; flex: none;
}
button.icon-btn:hover { background: var(--line); }
.icon-btn svg, .drawer-nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Gaveta de navegação: lateral, com ícone e rótulo em cada item. */
dialog.drawer {
  margin: 0; top: 0; left: 0; right: auto; height: 100dvh; max-height: 100dvh;
  width: min(320px, 86vw); border-radius: 0 var(--radius) var(--radius) 0; border-left: 0;
  display: none; flex-direction: column; padding-bottom: env(safe-area-inset-bottom);
}
dialog.drawer[open] { display: flex; }
.drawer-nav { display: flex; flex-direction: column; gap: var(--s1); padding: var(--s3); }
.drawer-nav a {
  display: flex; align-items: center; gap: var(--s3); min-height: 52px; padding: 0 var(--s4);
  border-radius: 12px; color: var(--text); text-decoration: none; font-weight: 600;
}
.drawer-nav a:hover { background: var(--line); }
.drawer-nav a[aria-current="page"] { background: var(--line); color: var(--green); }
.drawer-nav .badge { margin-left: auto; }
.drawer-foot { margin-top: auto; padding: var(--s4); display: grid; gap: var(--s3); }
.spinner {
  width: 20px; height: 20px; flex: none; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--green);
  animation: spin .8s linear infinite;
}
/* O giro é indicador de progresso: continua mesmo com movimento reduzido. */
@media (prefers-reduced-motion: reduce) { .spinner { animation: spin 1.5s linear infinite !important; } }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; justify-content: center; gap: var(--s3); padding: var(--s5) 0; color: var(--muted); }
.busy {
  position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s4);
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.drawer-help { color: var(--blue); font-weight: 600; text-align: center; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.drawer-foot button { width: 100%; }
.conn { color: var(--muted); font-size: 12px; }
.conn.on { color: var(--green); }
.conn.off { color: var(--red); }
nav { margin-left: auto; display: flex; gap: 12px; flex-wrap: wrap; }
nav a { text-decoration: none; font-size: 14px; }
nav a.active { font-weight: 700; }
.view { padding: var(--gutter); max-width: 720px; margin: 0 auto; }
.muted { color: var(--muted); }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--s4); margin-bottom: var(--s3);
}
.card > h2, .card > h3 { margin: 0 0 var(--s2); }
.card > p, .dlg-body > p { margin: 0 0 var(--s3); }
.card > :last-child, .dlg-body > :last-child { margin-bottom: 0; }
/* linhas de texto dentro de um card (meta, saldo, legenda) respiram entre si */
.card > div + div { margin-top: var(--s1); }
/* card clicável (envelope) mantém o padding interno do card */
.card.tx-row { padding: var(--s4); border: 1px solid var(--line); border-left-width: 4px; border-radius: var(--radius); }
.card.tx-row + .card.tx-row { margin-top: 0; }
.view > :first-child { margin-top: 0; }
h3 { font-size: 1rem; }
.hero { font-size: 2rem; font-weight: 800; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); margin-bottom: var(--s3); }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(2, 1fr); } }
.env { border-left: 4px solid var(--line); }
.env.locked { opacity: .85; }
.env .label { font-size: 13px; color: var(--muted); }
.env .value { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 10px 0 6px; }
.bar > span { display: block; height: 100%; background: var(--green); width: 0; transition: width .4s ease; }
.bar.warn > span { background: var(--amber); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { padding: 10px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--green); } .neg { color: var(--red); }
form { display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input, select, button {
  font: inherit; padding: 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); min-height: 44px; max-width: 100%;
}
button { background: var(--green); color: #052e16; font-weight: 700; border: 0; cursor: pointer; }
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); padding: 12px 16px; border-radius: 12px;
  max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.chart-wrap { position: relative; height: 220px; }
.empty { text-align: center; padding: 24px 8px; }
.error { color: var(--red); }
[hidden] { display: none !important; }

/* ---- v2: classificação, relatórios e configuração em modal ---- */
.cfg { margin-left: auto; padding: 8px 12px; min-height: 36px; font-size: 14px; }
nav { margin-left: 0; }
.badge {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; font-size: 12px;
  background: var(--amber); color: #1f1300; text-align: center; font-weight: 700;
}
dialog {
  width: min(680px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--line); border-radius: 16px;
  background: var(--panel); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.55); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.dlg-head h2 { margin: 0; font-size: 1.1rem; }
.dlg-body { padding: 16px; overflow-y: auto; max-height: calc(100dvh - 150px); }
/* Configurações é uma tela (/configurar/<aba>): abas em links, que quebram linha em telas estreitas. */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 0 0; border-bottom: 1px solid var(--line); overflow: visible; }
.tabs a[role="tab"] {
  background: transparent; color: var(--muted); border: 0; border-bottom: 3px solid transparent; text-decoration: none;
  border-radius: 0; padding: 10px 8px; min-height: 44px; display: inline-flex; align-items: center; font-weight: 600; white-space: nowrap;
}
.tabs a[role="tab"][aria-selected="true"] { color: var(--text); border-bottom-color: var(--green); }
.tabs a[role="tab"]:focus-visible { outline: 3px solid var(--blue); outline-offset: -3px; }
.config-body { padding: var(--s4) 0; }
.back { margin: 0 0 var(--s3); font-size: 14px; }
.explain { border-left: 4px solid var(--line); }
.explain h3 { margin: 0 0 4px; font-size: 1rem; }
.explain p { margin: var(--s1) 0; font-size: 14px; }
.explain .example { color: var(--muted); font-size: 13px; }
.mix-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.mix-row input { width: 96px; text-align: right; }
.sum { font-weight: 700; font-variant-numeric: tabular-nums; }
.sum.ok { color: var(--green); } .sum.bad { color: var(--red); }
.cat-group { margin: 12px 0 4px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.cat-list { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
@media (max-width: 480px) { .cat-list { grid-template-columns: 1fr; } }
.cat-list label { display: flex; align-items: center; gap: 8px; color: var(--text); padding: 8px; border: 1px solid var(--line); border-radius: 10px; min-height: 44px; }
.cat-list input { min-height: 0; width: 18px; height: 18px; padding: 0; }
.tx-row { display: flex; justify-content: space-between; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--line); cursor: pointer; background: none; color: var(--text); width: 100%; text-align: left; font-weight: 400; min-height: 44px; }
.tx-row:hover { background: var(--line); }
.tx-row .meta { font-size: 13px; color: var(--muted); }
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); margin: 2px 4px 0 0; color: var(--muted); }
.chip.none { border-style: dashed; color: var(--amber); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { background: transparent; color: var(--muted); border: 0; border-radius: 0; min-height: 40px; font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--line); color: var(--text); }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s3); margin-bottom: var(--s3); }
@media (max-width: 480px) { .kpis { grid-template-columns: 1fr; } }
.kpis .card { margin: 0; text-align: center; }
.kpis .label { font-size: 12px; color: var(--muted); }
.kpis .value { font-size: 1.1rem; font-weight: 800; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.chart-tall { position: relative; height: 260px; }
.chart-bars { position: relative; height: max(160px, calc(var(--n, 4) * 34px)); }
.note { font-size: 13px; color: var(--muted); }
.empty-chart { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); text-align: center; padding: 12px; }
.danger { background: var(--red); color: #fff; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px;
  padding: 0 var(--s4); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); text-decoration: none; font-weight: 600;
}
.danger:disabled { background: var(--line); color: var(--muted); }

/* ---- acessibilidade ---- */
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
#view:focus { outline: none; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: var(--gutter); top: -100px; z-index: 10; background: var(--panel); color: var(--text); padding: 10px 14px; border: 1px solid var(--blue); border-radius: 10px; text-decoration: none; }
.skip-link:focus { top: 10px; }
.seg button { min-height: 44px; }
/* Movimento reduzido: sem transições nem animações (também poupa bateria e CPU). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
/* Contraste aumentado: o texto secundário fica mais forte, nunca mais fraco.
   No tema escuro ele clareia (medido: 10:1 sobre o painel); no claro, escurece. */
@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --line: #4b5563; --muted: #c2cad6; }
}
@media (prefers-contrast: more) and (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) { --line: #6b7685; --muted: #374151; }
}
:root[data-theme="dark"] { --line: #4b5563; }

/* ---- importação: área de arrastar e soltar ---- */
.dropzone {
  display: grid; justify-items: center; gap: var(--s2); text-align: center;
  border: 2px dashed var(--line); border-radius: var(--radius); padding: var(--s5) var(--s4);
}
.dropzone.over { border-color: var(--green); background: var(--line); }
.dropzone p { margin: 0; }
.dz-title { font-weight: 700; }
.dz-pick {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px;
  padding: 0 var(--s4); border-radius: 10px; background: var(--green); color: #052e16;
  font-weight: 700; cursor: pointer;
}
.dropzone label:has(input:focus-visible) { outline: 3px solid var(--blue); outline-offset: 2px; }

.demo-banner { border-left: 4px solid var(--amber); }

/* ---- marca ---- */
.app-icon, .login-logo { filter: var(--logo-filter); }

/* ---- tela de entrada ---- */
.login { max-width: 440px; margin: 0 auto; display: grid; gap: var(--s5); justify-items: center; text-align: center; }
.login-logo { width: 96px; height: 96px; }
.login h1 { font-size: 1.8rem; margin: 0; line-height: 1.2; }
.login-lead { color: var(--muted); margin: 0; font-size: 1.05rem; }
.login-card { width: 100%; text-align: left; margin: 0; }
.login-card h2 { font-size: 1rem; margin: 0 0 var(--s3); }
.login-card ol, .login-card ul { margin: 0; padding-left: 20px; display: grid; gap: var(--s2); }
.login-card li { color: var(--text); }
.login-card li span { color: var(--muted); }
/* botão oficial "Continuar com o Google": fundo branco e marca colorida, em qualquer tema */
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: var(--s3);
  width: 100%; min-height: 48px; padding: 0 var(--s4);
  background: #ffffff; color: #1f1f1f; border: 1px solid #747775; border-radius: 10px;
  font: 500 16px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; text-decoration: none;
}
.google-btn:hover { background: #f8f9fa; }
.google-btn svg { width: 18px; height: 18px; flex: none; }
.login-links { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); justify-content: center; font-size: 14px; }

/* identificação de quem está logado, no topo do menu */
.me { padding: var(--s4); border-bottom: 1px solid var(--line); }
.me-label { margin: 0 0 var(--s1); font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.me-name { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.me-email { margin: var(--s1) 0 0; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.me-planilha { margin: var(--s2) 0 0; font-size: 14px; color: var(--muted); }
.me-aviso { margin: var(--s2) 0 0; font-size: 14px; }
.me-link { display: inline-block; margin-top: var(--s2); font-size: 14px; color: var(--blue); }

/* Dica (tooltip) acessível: botão com texto visível; o balão é ligado ao botão. */
.tip { position: relative; display: inline-block; max-width: 100%; }
.tip-btn {
  background: transparent; color: var(--blue); padding: 0 var(--s1); min-height: 44px;
  font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
}
.tip-btn:hover { color: var(--text); }
.tip-panel {
  position: absolute; left: 0; top: calc(100% + 4px); z-index: 20; width: min(320px, 80vw);
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  padding: var(--s3) var(--s4); font-size: 14px; line-height: 1.5; font-weight: 400;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3); text-align: left;
}

/* Aviso de erro no meio da tela: calmo, claro, fecha com "Entendi" ou Escape. */
.erro-central {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  padding: var(--s4); background: rgba(5, 8, 12, .55);
}
.erro-cartao {
  width: min(380px, 100%); background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-left: 4px solid var(--red); border-radius: 16px;
  padding: var(--s5) var(--s5) var(--s4); box-shadow: 0 16px 40px rgba(0, 0, 0, .35);
}
.erro-titulo { font-size: 1.05rem; margin: 0 0 var(--s2); }
.erro-texto { margin: 0 0 var(--s4); color: var(--muted); line-height: 1.5; }
.erro-ok { width: 100%; }
/* Convites na tela Assinatura */
.convite-item { list-style: none; padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.convite-item code { display: block; overflow-wrap: anywhere; font-size: 14px; margin-bottom: var(--s2); }
.convite-item.usado { color: var(--muted); }
.convites-lista { padding: 0; margin: var(--s3) 0; }

/* Cartões de plano na landing (no lugar de tabela: lê bem em qualquer largura). */
.plano h3 { margin-bottom: 8px; }
.plano-preco { font-size: 1.6rem; font-weight: 800; margin: 0 0 8px; }
.plano p { margin: 0 0 8px; }

/* Planos da landing: destaque de desconto e do melhor custo por mês. */
.planos-cartoes { margin-top: var(--s4); }
.plano { position: relative; display: flex; flex-direction: column; gap: var(--s2); }
.plano-destaque { border-color: var(--green); box-shadow: 0 0 0 1px var(--green) inset; }
.selo {
  align-self: flex-start; margin: 0; padding: 4px 10px; border-radius: 999px;
  background: var(--green); color: #052e16; font-size: 12px; font-weight: 800;
}
.chip-desconto {
  align-self: flex-start; margin: 0; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--green); color: var(--green); font-size: 13px; font-weight: 700;
}
.plano-motivo { margin: 0; font-size: 14px; color: var(--muted); }
.beneficios-plano { margin-top: var(--s5); }
@media (min-width: 900px) { .planos-cartoes { grid-template-columns: repeat(4, 1fr); } }

/* Recibo: marca no topo e impressão só do recibo (ver renderRecibo em js/app.js). */
.recibo-topo { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.recibo-linha { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.recibo-rodape { margin-top: 16px; font-size: 13px; }
.pagamentos { list-style: none; padding: 0; margin: 12px 0 0; }
.pagamento-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
@media print {
  body * { visibility: hidden; }
  .recibo, .recibo * { visibility: visible; }
  .recibo { position: absolute; left: 0; top: 0; width: 100%; box-shadow: none; border: 0; }
  .no-print { display: none !important; }
}
