/* ==========================================================
   Painel Nexus — estilos (claro e escuro)
   ========================================================== */
:root {
  --bg: #f6f4fc;
  --surface: #ffffff;
  --surface-2: #f4f1fd;
  --ink: #150f2e;
  --text: #2b2447;
  --muted: #6a6486;
  --faint: #9a94b5;
  --line: rgba(30, 20, 70, .1);
  --line-strong: rgba(30, 20, 70, .18);
  --brand: #5a21d0;
  --brand-2: #7c4af0;
  --brand-text: #5a21d0;
  --tint: #ede6ff;
  --btn-grad: linear-gradient(135deg, #7c4af0, #5a21d0);
  --ok: #15803d;  --ok-bg: #dcfce7;
  --warn: #b45309; --warn-bg: #fef3c7;
  --bad: #be123c;  --bad-bg: #ffe4e6;
  --bar-a: #7c4af0; --bar-b: #f0a43a;
  --shadow-sm: 0 1px 2px rgba(30, 20, 70, .05), 0 6px 18px -8px rgba(30, 20, 70, .12);
  --shadow-lg: 0 30px 60px -20px rgba(30, 20, 70, .35);
  --font-head: "Montserrat", system-ui, "Segoe UI", sans-serif;
  --font-body: "Inter", system-ui, "Segoe UI", sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b0816;
  --surface: #151028;
  --surface-2: #1b1533;
  --ink: #f4f1ff;
  --text: #ded8f3;
  --muted: #a39dbf;
  --faint: #756f95;
  --line: rgba(255, 255, 255, .09);
  --line-strong: rgba(255, 255, 255, .18);
  --brand-text: #b79cff;
  --tint: rgba(143, 97, 246, .2);
  --ok: #4ade80;  --ok-bg: rgba(34, 197, 94, .16);
  --warn: #fbbf24; --warn-bg: rgba(245, 158, 11, .16);
  --bad: #fb7185;  --bad-bg: rgba(244, 63, 94, .16);
  --bar-a: #a98bff; --bar-b: #f5b95c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 18px -8px rgba(0, 0, 0, .5);
  --shadow-lg: 0 30px 60px -20px rgba(0, 0, 0, .8);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 .95rem/1.55 var(--font-body); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-family: var(--font-head); color: var(--ink); letter-spacing: -.02em; line-height: 1.15; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid rgba(124, 74, 240, .55); outline-offset: 2px; border-radius: 8px; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(700px 420px at 85% 0%, rgba(162, 115, 243, .28), transparent 65%), radial-gradient(600px 400px at 0% 100%, rgba(90, 33, 208, .18), transparent 65%), var(--bg); }
.login-card { width: min(420px, 100%); padding: 34px 30px; border-radius: 24px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg); }
.login-card .marca { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; color: var(--brand-text); font: 700 1.9rem/1 var(--font-head); letter-spacing: -.03em; }
.login-card .marca img { height: 30px; }
.login-card h1 { font-size: 1.45rem; }
.login-card p { margin: 8px 0 20px; color: var(--muted); }
.login-card .campo + .campo { margin-top: 14px; }
.login-card .btn { width: 100%; margin-top: 18px; padding: 13px; }
.erro-form { margin-top: 12px; min-height: 1.2em; color: var(--bad); font-size: .88rem; }

/* ---------- Estrutura ---------- */
.app { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--line); }
.side .marca { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: var(--brand-text); font: 700 1.6rem/1 var(--font-head); letter-spacing: -.03em; }
.side .marca img { height: 24px; }
.side .marca small { margin-left: auto; padding: 3px 8px; border-radius: 99px; background: var(--tint); color: var(--brand-text); font: 700 .62rem/1 var(--font-body); letter-spacing: .08em; text-transform: uppercase; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px; color: var(--muted); font-weight: 600; transition: background .2s, color .2s; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.on { background: var(--tint); color: var(--brand-text); }
.side-fim { margin-top: auto; display: grid; gap: 4px; }
.side-fim button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 14px; border: 0; border-radius: 12px; background: none; color: var(--muted); font-weight: 600; cursor: pointer; text-align: left; }
.side-fim button:hover { background: var(--surface-2); color: var(--ink); }
.main { min-width: 0; padding: 28px clamp(18px, 3vw, 40px) 70px; }
.topo { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 22px; }
.topo h1 { font-size: 1.75rem; font-weight: 800; }
.topo .sub { margin-top: 4px; color: var(--muted); font-size: .9rem; }
.acoes { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

@media (max-width: 900px) {
  .app { display: block; }
  .side { position: fixed; inset: auto 0 0 0; z-index: 30; width: 100%; max-width: 100vw; height: auto; flex-direction: row; align-items: stretch; gap: 2px; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); overflow: hidden; border-right: 0; border-top: 1px solid var(--line); }
  .side .marca, .side-fim .texto-sair { display: none; }
  .nav { display: flex; flex: 1 1 auto; min-width: 0; gap: 2px; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { flex: 1 0 auto; flex-direction: column; justify-content: center; gap: 3px; padding: 7px 8px; font-size: .64rem; white-space: nowrap; }
  .side-fim { flex: none; margin: 0; display: flex; gap: 0; }
  .side-fim button { width: auto; padding: 8px; justify-content: center; }
  .main { padding-bottom: 100px; }
}

/* ---------- Componentes ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 999px; border: 1px solid transparent; font-weight: 600; cursor: pointer; white-space: nowrap; transition: transform .15s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--btn-grad); color: #fff; box-shadow: 0 8px 20px -8px rgba(90, 33, 208, .7); }
.btn-ghost { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover { border-color: var(--brand-2); color: var(--brand-text); }
.btn-danger { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.btn-ok { background: var(--ok-bg); color: var(--ok); }
.btn-sm { padding: 6px 12px; font-size: .84rem; }
.btn-ico { padding: 7px; border-radius: 10px; }

.card { padding: 20px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.card h2 { font-size: 1.05rem; }
.card-topo { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.grade { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; align-items: start; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-21 { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .g-21 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 760px) { .g-2 { grid-template-columns: minmax(0, 1fr); } }

.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 18px; }
.kpi { display: grid; gap: 4px; padding: 18px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.kpi .linha { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: .84rem; font-weight: 600; }
.kpi .icone { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; background: var(--tint); color: var(--brand-text); }
.kpi .valor { font: 800 1.65rem/1.15 var(--font-head); color: var(--ink); letter-spacing: -.03em; }
.kpi .sub { color: var(--muted); font-size: .82rem; }
.kpi.bom .icone { background: var(--ok-bg); color: var(--ok); }
.kpi.alerta .icone { background: var(--bad-bg); color: var(--bad); }
.kpi.alerta .valor { color: var(--bad); }
.kpi.atencao .icone { background: var(--warn-bg); color: var(--warn); }
.neg { color: var(--bad) !important; }
.pos { color: var(--ok) !important; }

.selo { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 99px; font-size: .74rem; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.selo.ok { background: var(--ok-bg); color: var(--ok); }
.selo.warn { background: var(--warn-bg); color: var(--warn); }
.selo.bad { background: var(--bad-bg); color: var(--bad); }
.selo.info { background: var(--tint); color: var(--brand-text); }

.tabela-wrap { overflow-x: auto; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; }
th { padding: 12px 16px; text-align: left; color: var(--muted); font-size: .74rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; border-bottom: 1px solid var(--line); background: var(--surface-2); }
td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td .peq { display: block; color: var(--muted); font-size: .8rem; }
td .forte { font-weight: 600; color: var(--ink); }
td.acoes-c { text-align: right; white-space: nowrap; }
tfoot td { background: var(--surface-2); font-weight: 700; }
.vazio { padding: 44px 20px; text-align: center; color: var(--muted); }
.vazio b { display: block; margin-bottom: 4px; color: var(--ink); font-family: var(--font-head); font-size: 1.05rem; }

.barra-filtros { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.campo { display: grid; gap: 6px; font-size: .84rem; font-weight: 600; color: var(--ink); }
.campo .dica { color: var(--muted); font-weight: 400; font-size: .78rem; }
input, select, textarea { width: 100%; padding: 10px 13px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 400; transition: border-color .2s, box-shadow .2s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 4px rgba(124, 74, 240, .16); }
textarea { resize: vertical; min-height: 84px; }
.barra-filtros input[type="search"] { width: min(280px, 100%); }
.barra-filtros select { width: auto; }
.grupo-chips { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.grupo-chips button { padding: 6px 14px; border: 0; border-radius: 999px; background: none; color: var(--muted); font-size: .84rem; font-weight: 600; cursor: pointer; }
.grupo-chips button.on { background: var(--surface); color: var(--brand-text); box-shadow: var(--shadow-sm); }
.seletor-mes { display: inline-flex; align-items: center; gap: 4px; padding: 3px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line-strong); }
.seletor-mes span { min-width: 150px; text-align: center; font-weight: 700; color: var(--ink); }
.seletor-mes button { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; }
.seletor-mes button:hover { background: var(--tint); color: var(--brand-text); }

.resumo-fin { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.resumo-fin div { padding: 14px 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.resumo-fin small { display: block; color: var(--muted); font-size: .76rem; font-weight: 600; }
.resumo-fin b { font: 800 1.2rem/1.3 var(--font-head); color: var(--ink); }

/* Lista dos próximos vencimentos */
.lista { display: grid; grid-template-columns: minmax(0, 1fr); }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; padding-bottom: 0; }
.item .corpo { min-width: 0; flex: 1; }
.item .corpo b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); font-weight: 600; }
.item .corpo small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.item .valor { font-weight: 700; color: var(--ink); white-space: nowrap; }

/* Barras horizontais (receita por sistema) */
.hbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.hbar .linha { display: grid; gap: 5px; }
.hbar .topo-b { display: flex; justify-content: space-between; gap: 10px; font-size: .86rem; }
.hbar .trilho { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.hbar .trilho i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #a273f3, #5a21d0); }

/* Gráfico */
.grafico { display: block; width: 100%; max-width: 100%; height: auto; }
.grafico text { fill: var(--muted); font: 600 11px var(--font-body); }
.grafico .grade-l { stroke: var(--line); stroke-width: 1; }
.grafico .b-rec { fill: var(--bar-a); }
.grafico .b-des { fill: var(--bar-b); }
.legenda { display: flex; gap: 16px; margin-top: 8px; color: var(--muted); font-size: .82rem; }
.legenda i { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 3px; }

/* Sistemas (cartões) */
.sistemas { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.sistema { display: flex; flex-direction: column; gap: 10px; }
.sistema .cab { display: flex; align-items: center; gap: 12px; }
.sistema .tile { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--tint); color: var(--brand-text); }
.sistema h3 { font-size: 1.05rem; }
.sistema .preco { font: 800 1.35rem/1.1 var(--font-head); color: var(--ink); }
.sistema .preco small { color: var(--muted); font: 500 .8rem var(--font-body); }
.sistema p { color: var(--muted); font-size: .88rem; }
.sistema .selos { display: flex; flex-wrap: wrap; gap: 6px; }
.sistema .rod { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: .84rem; }
.sistema.inativo { opacity: .6; }

/* Modal */
.modal-fundo { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; background: rgba(10, 6, 30, .55); backdrop-filter: blur(3px); animation: surgir .15s ease; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 36px); display: flex; flex-direction: column; border-radius: 22px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg); }
.modal.largo { width: min(720px, 100%); }
.modal header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal header h2 { font-size: 1.15rem; }
.modal .corpo { padding: 20px 22px; overflow-y: auto; display: grid; gap: 14px; }
.modal footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); }
.modal footer .esq { margin-right: auto; }
.cols-2 { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .cols-2 { grid-template-columns: 1fr; } }
.chk { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.chk input { width: 18px; height: 18px; accent-color: var(--brand-2); }
details.traducao { border: 1px dashed var(--line-strong); border-radius: 14px; padding: 10px 14px; }
details.traducao summary { cursor: pointer; font-weight: 600; color: var(--brand-text); }
details.traducao .interno { display: grid; gap: 12px; margin-top: 12px; }
.sep { height: 1px; background: var(--line); margin: 4px 0; }

/* Aviso rápido */
#avisos { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: grid; gap: 8px; }
.aviso { max-width: 360px; padding: 12px 16px; border-radius: 14px; background: var(--ink); color: var(--bg); font-weight: 600; box-shadow: var(--shadow-lg); animation: surgir .2s ease; }
.aviso.erro { background: var(--bad); color: #fff; }
@media (max-width: 900px) { #avisos { bottom: 86px; } }

.config-bloco { max-width: 680px; }
.config-bloco + .config-bloco { margin-top: 18px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .82rem; word-break: break-all; color: var(--muted); }
.carregando { padding: 40px; text-align: center; color: var(--muted); }

@keyframes surgir { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Login com Google / modo de teste ---------- */
.google-btn { display: flex; justify-content: center; min-height: 44px; margin-top: 6px; }
.dev-login { margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--line-strong); }
.dev-login p { margin: 0 0 10px; font-size: .82rem; color: var(--muted); }
.dev-login .btn { margin-top: 12px; }

/* ---------- Pagamento online ---------- */
.aviso-auto { margin: 0 0 4px; padding: 10px 14px; border-radius: 12px; background: var(--tint); color: var(--brand-text); font-size: .86rem; font-weight: 500; }
.passos { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.passos li { display: flex; align-items: center; gap: 8px; }

.config-bloco.largo { max-width: 980px; }
.plats { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.plat { padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-2); display: grid; gap: 10px; align-content: start; }
.plat h3 { font-size: 1.05rem; margin: 0; }
