/* =====================================================================
   Painel de afiliados — mesmo desenho do painel de referência (claro, cinzas + verde esmeralda)
   ===================================================================== */
:root {
  --bg: #f9fafb; --side: #ffffff; --card: #ffffff; --soft: #f9fafb; --hover: #f3f4f6;
  --line: #e5e7eb; --line-2: #d1d5db;
  --ink: #111827; --ink-2: #374151; --muted: #6b7280; --faint: #9ca3af;
  --accent: #059669; --accent-2: #10b981; --accent-soft: #ecfdf5; --accent-line: #a7f3d0;
  --bad: #dc2626; --bad-soft: #fef2f2; --warn: #d97706; --warn-soft: #fffbeb;
  --radius: 14px;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0b0f14; --side: #0f141a; --card: #121820; --soft: #0f141a; --hover: #18202a;
  --line: #1f2937; --line-2: #2b3644;
  --ink: #f3f4f6; --ink-2: #d1d5db; --muted: #9ca3af; --faint: #6b7280;
  --accent: #34d399; --accent-2: #10b981; --accent-soft: rgba(16, 185, 129, .12); --accent-line: rgba(16, 185, 129, .35);
  --bad: #f87171; --bad-soft: rgba(248, 113, 113, .1); --warn: #fbbf24; --warn-soft: rgba(251, 191, 36, .1);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: 'Inter', ui-sans-serif, system-ui, sans-serif; font-size: 14px; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.hidden { display: none !important; }

/* ---------- Estrutura ---------- */
.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.app > div { min-width: 0; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--side); border-right: 1px solid var(--line); z-index: 30; }
.brand { display: flex; align-items: center; justify-content: space-between; gap: 10px; height: 64px; padding: 0 16px 0 20px; }
.brand b { font-size: 17px; font-weight: 700; letter-spacing: -.01em; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand img { max-height: 28px; max-width: 150px; object-fit: contain; }
.nav { flex: 1; overflow-y: auto; padding: 8px 12px; display: grid; align-content: start; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; height: 40px; padding: 10px 12px; border-radius: 6px; font-size: 14px; font-weight: 600; color: var(--muted); transition: background .15s, color .15s; }
.nav a:hover { background: var(--hover); color: var(--ink); }
.nav a.active { background: var(--hover); color: var(--ink); }
.nav a .count { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 11px; display: grid; place-items: center; }
.side-foot { padding: 12px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.theme-sw { display: flex; gap: 4px; padding: 3px; border-radius: 8px; border: 1px solid var(--line); width: max-content; }
.theme-sw button { width: 30px; height: 26px; display: grid; place-items: center; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; }
.theme-sw button.on { background: var(--accent-2); color: #fff; }
.theme-sw svg.i { width: 15px; height: 15px; }
.me-card { padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--soft); display: grid; gap: 10px; }
.me-card .row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.me-card b { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.me-card small { display: block; font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.tag { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 6px; font-size: 11px; font-weight: 600; background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line); white-space: nowrap; }
.tag.gray { background: var(--hover); color: var(--muted); border-color: var(--line); }
.tag.red { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.tag.amber { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.main { min-width: 0; padding: 24px; }
.topbar-m { display: none; }
.backdrop { display: none; }

/* ---------- Cabeçalho da página ---------- */
.ph { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.ph h1 { margin: 0; font-size: 22px; font-weight: 700; color: var(--ink); }
.ph p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.ph .acts { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
@media (max-width: 640px) { .ph .sync { display: none; } }
.sync { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 12px; color: var(--muted); }
.sync svg.i { width: 14px; height: 14px; }

/* ---------- Botões e campos ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--hover); }
.btn svg.i { width: 16px; height: 16px; }
.btn-p { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn-p:hover { background: var(--accent); border-color: var(--accent); }
.btn-ghost { border-color: transparent; background: none; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon { width: 36px; padding: 0; }
.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.in, .sel { height: 38px; width: 100%; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); outline: none; font-size: 14px; }
textarea.in { height: auto; padding: 10px 12px; }
.in:focus, .sel:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--accent-soft); }
.form { display: grid; gap: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- Filtros ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.pill { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-size: 13px; }
.pill select { border: 0; background: none; outline: none; font-weight: 500; cursor: pointer; padding-right: 2px; }
.pill .lbl { font-weight: 600; }
.pill .chip-in { display: inline-flex; align-items: center; height: 24px; padding: 0 8px; border-radius: 6px; background: var(--hover); font-size: 12px; }
.balance { display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-size: 13px; margin-bottom: 16px; }
.balance b { font-weight: 700; }
.balance.neg b { color: var(--bad); }

/* ---------- Cartões ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.card + .card { margin-top: 16px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-h h3 { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; }
.card-h h3 svg.i { color: var(--accent); }
.card-h p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.sec { display: flex; align-items: center; justify-content: space-between; margin: 26px 0 10px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.sec a { font-size: 13px; font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--accent); }
.kgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kgrid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.k { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.k.hl { border-color: #fbbf24; box-shadow: 0 0 0 1px #fbbf24 inset; }
.k .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.k .lab { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; min-width: 0; }
.k .lab svg.i { width: 14px; height: 14px; color: var(--faint); }
.k .val { margin-top: 8px; font-size: 22px; font-weight: 700; letter-spacing: -.01em; overflow-wrap: anywhere; }
.k .val.neg { color: var(--bad); }
.k .sub { margin-top: 4px; font-size: 12px; color: var(--muted); }
.k .split { display: flex; gap: 24px; margin-top: 14px; font-size: 12px; color: var(--muted); }
.k .split b { display: block; margin-top: 2px; font-size: 13px; color: var(--ink); font-weight: 600; }
.k .split i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent-2); margin-right: 5px; vertical-align: 1px; }
.var { display: inline-flex; align-items: center; height: 20px; padding: 0 6px; border-radius: 6px; font-size: 11px; font-weight: 600; white-space: nowrap; border: 1px solid; }
.var.up { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }
.var.down { color: var(--bad); background: var(--bad-soft); border-color: #fecaca; }
.var.flat { color: var(--muted); background: var(--hover); border-color: var(--line); }
[data-theme="dark"] .var.down { border-color: transparent; }

/* ---------- Link de tracking ---------- */
.linkbox { display: flex; gap: 10px; align-items: stretch; }
.linkbox .code { flex: 1; min-width: 0; padding: 12px; border-radius: 4px; border: 1px solid var(--line); background: var(--soft); font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 14px; color: var(--ink); word-break: break-all; min-height: 104px; }
.linkbox .btns { display: grid; gap: 6px; align-content: start; }
.mb { margin-bottom: 10px; }

/* ---------- Tabelas ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { height: 38px; padding: 0 12px; border: 0; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent-2); }
.tbl-w { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; padding: 10px 12px; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t tr:last-child td { border-bottom: 0; }
table.t .num { text-align: right; font-variant-numeric: tabular-nums; }
table.t td.neg, .neg { color: var(--bad); }
table.t td.pos { color: var(--accent); }
table.t .mono { font-family: ui-monospace, monospace; font-size: 12px; }
.empty { padding: 36px 12px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; }

/* ---------- Comissões por dia ---------- */
details.day { border: 1px solid var(--line); border-radius: 10px; background: var(--card); margin-bottom: 8px; }
details.day summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; cursor: pointer; list-style: none; font-weight: 600; }
details.day summary::-webkit-details-marker { display: none; }
details.day summary small { font-weight: 500; color: var(--muted); }
details.day .rows { border-top: 1px solid var(--line); }

/* ---------- Valores ocultos ---------- */
body.masked .money { filter: blur(7px); user-select: none; }

/* ---------- Entrar / Cadastro ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-box { width: 100%; max-width: 420px; }
.auth-box.wide { max-width: 560px; }
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-brand b { font-size: 22px; font-weight: 700; }
.auth-brand img { max-height: 40px; max-width: 200px; }
.auth-brand p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.auth .card h2 { margin: 0 0 4px; font-size: 18px; }
.auth .card > p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.auth .alt { margin-top: 14px; text-align: center; font-size: 13px; color: var(--muted); }
.auth .alt a { color: var(--accent); font-weight: 600; }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 13px; line-height: 1.5; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Modal, avisos ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(17, 24, 39, .45); display: grid; place-items: center; padding: 16px; z-index: 100; }
.modal { position: relative; width: 100%; max-width: 440px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 24px; box-shadow: 0 20px 50px rgba(0, 0, 0, .18); }
.modal h3 { margin: 0 0 4px; font-size: 17px; }
.modal > p { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.modal .x { position: absolute; top: 14px; right: 14px; border: 0; background: none; color: var(--muted); cursor: pointer; }
.qr { display: grid; place-items: center; gap: 10px; }
.qr img { width: 240px; height: 240px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 200; }
.toast { padding: 12px 14px; border-radius: 10px; background: var(--ink); color: var(--card); font-size: 13px; box-shadow: 0 10px 30px rgba(0, 0, 0, .2); max-width: 340px; }
.toast.error { background: var(--bad); color: #fff; }
.toast.success { background: var(--accent-2); color: #fff; }

/* ---------- Celular ---------- */
@media (max-width: 1200px) { .kgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  body.menu .side { transform: none; }
  body.menu .backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 25; }
  .topbar-m { display: flex; align-items: center; gap: 10px; height: 56px; padding: 0 12px; background: var(--side); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
  .topbar-m b { font-weight: 700; }
  .main { padding: 16px; }
  .kgrid.three { grid-template-columns: 1fr; }
  .linkbox { flex-direction: column; }
  .linkbox .btns { grid-auto-flow: column; justify-content: start; }
}
@media (max-width: 560px) { .kgrid { grid-template-columns: 1fr; } .grid2 { grid-template-columns: 1fr; } .card { padding: 18px; } }
