:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e0da;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #1f8a4c;
  --warn: #b26b00;
  --bad: #c2362f;
  --seq-0: #cde2fb;
  --seq-1: #86b6ef;
  --seq-2: #3987e5;
  --seq-3: #1c5cab;
  --seq-4: #0d366b;
  --zero: #b9b7b0;
  --cat-1: #2a78d6; --cat-2: #eb6834; --cat-3: #1baf7a; --cat-4: #eda100;
  --div-neg: #e34948; --div-mid: #f0efec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #383835;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --accent: #3987e5;
    --seq-0: #184f95;
    --seq-1: #256abf;
    --seq-2: #3987e5;
    --seq-3: #86b6ef;
    --seq-4: #cde2fb;
    --zero: #5a5955;
    --cat-1: #3987e5; --cat-2: #d95926; --cat-3: #199e70; --cat-4: #c98500;
    --div-neg: #e66767; --div-mid: #383835;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #383835;
  --text: #ffffff; --text-2: #c3c2b7; --text-3: #8f8e86; --accent: #3987e5;
  --seq-0: #184f95; --seq-1: #256abf; --seq-2: #3987e5; --seq-3: #86b6ef; --seq-4: #cde2fb; --zero: #5a5955;
  --cat-1: #3987e5; --cat-2: #d95926; --cat-3: #199e70; --cat-4: #c98500; --div-neg: #e66767; --div-mid: #383835;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.hidden { display: none !important; }

/* Topo */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1000;
}
.brand { font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; color: var(--text); }
.brand .marca-mapa { color: var(--accent); margin-left: -8px; }
.brand .logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; color: #fff; font-size: 13px; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { padding: 6px 10px; border-radius: 6px; color: var(--text-2); }
.topbar nav a.ativo, .topbar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.topbar .user { color: var(--text-2); font-size: 13px; display: flex; gap: 12px; align-items: center; }

.container { max-width: 1280px; margin: 0 auto; padding: 24px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.duo { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .grid.duo { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card > h2 + * { margin-top: 12px; }
.kpi .rotulo { font-size: 12px; color: var(--text-2); }
.kpi .valor { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.01em; }
.kpi .detalhe { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* Formulários */
label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.campo + .campo { margin-top: 12px; }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primario, .btn.primario { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primario:hover { filter: brightness(1.08); }
button.perigo { color: var(--bad); }
button.sm, .btn.sm { padding: 4px 9px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
.erro { color: var(--bad); font-size: 13px; min-height: 18px; }
.ok { color: var(--good); font-size: 13px; }

/* Tabelas */
.tabela-wrap { overflow: auto; max-height: 520px; border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; color: var(--text-2); font-size: 12px; z-index: 1; cursor: default; }
th[data-ord] { cursor: pointer; user-select: none; }
th[data-ord]:hover { color: var(--text); }
tbody tr:hover { background: var(--surface-2); }
tr.clicavel { cursor: pointer; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.badge.pago { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.badge.pendente { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.badge.cancelado { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.badge.admin { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }

/* Barras horizontais (série única) */
.barras { display: grid; gap: 6px; }
.barra { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 70px; gap: 10px; align-items: center; font-size: 13px; }
.barra .nome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.barra .trilho { height: 14px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.barra .preench { height: 100%; background: var(--seq-2); border-radius: 0 4px 4px 0; min-width: 2px; }
.barra .val { text-align: right; font-variant-numeric: tabular-nums; }

/* Mapa */
#mapa { height: 560px; border-radius: 8px; border: 1px solid var(--border); z-index: 0; }
.legenda { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--text-2); }
.legenda .sw { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: -2px; margin-right: 4px; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); }
.leaflet-popup-content { font: 13px/1.4 system-ui, sans-serif; margin: 12px 14px; min-width: 240px; }
.leaflet-popup-content table { font-size: 12px; }
.leaflet-popup-content th, .leaflet-popup-content td { padding: 3px 6px; }
.popup-secoes { max-height: 200px; overflow: auto; margin-top: 8px; }

/* Mapa no modo escuro: escurece só os tiles, não os marcadores */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }
}
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }

/* Abas */
.abas { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.abas button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--text-2); padding: 8px 12px; }
.abas button.ativo { color: var(--text); border-bottom-color: var(--accent); }

/* Modal */
.modal-fundo { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 2000; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; padding: 20px; width: min(520px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal h2 { margin-bottom: 14px; }
.modal .acoes { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(400px, 100%); }

.vazio { padding: 28px; text-align: center; color: var(--text-2); }
.cand-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.cand-item:last-child { border-bottom: 0; }
.cand-num { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); min-width: 54px; }

@media (max-width: 640px) {
  .container { padding: 16px; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  #mapa { height: 420px; }
}

.avatar { display: inline-grid; place-items: center; background: var(--surface-2); color: var(--text-2); font-weight: 650; }

/* Comparativo */
.chips-cand { display: flex; gap: 12px; flex-wrap: wrap; }
.chip-cand { display: flex; gap: 12px; align-items: center; padding: 12px 30px 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); min-width: 240px; position: relative; }
.chip-cand .tot { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chip-cand .x { position: absolute; top: 6px; right: 6px; border: 0; background: none; padding: 2px 6px; color: var(--text-3); }
.chip-add { border: 1.5px dashed var(--border); background: transparent; min-width: 200px; justify-content: center; color: var(--text-2); cursor: pointer; font: inherit; }
.chip-add:hover { border-color: var(--accent); color: var(--accent); }
.sw-cat { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: 0; margin-right: 4px; }
.badge.lidera { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.badge.perde { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.badge.apertado { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.grupos { display: grid; gap: 10px; }
.grupo { display: grid; grid-template-columns: minmax(90px, 170px) 1fr; gap: 10px; align-items: center; font-size: 13px; }
.grupo .nome { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grupo .linhas { display: grid; gap: 2px; }
.grupo .lin { display: grid; grid-template-columns: 1fr 56px; gap: 8px; align-items: center; }
.grupo .bar { height: 8px; border-radius: 0 3px 3px 0; min-width: 1px; }
.grupo .v { text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--text-2); }
.placar { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; }
.placar b { font-size: 22px; font-variant-numeric: tabular-nums; display: block; }

/* Pagamento Pix */
.pix-box { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.pix-qr { width: 190px; height: 190px; padding: 8px; background: #fff; border-radius: 12px; border: 1px solid var(--border); flex: none; }
.pix-qr svg { width: 100%; height: 100%; display: block; }
.pix-passos { margin: 14px 0 0; padding-left: 20px; color: var(--text-2); font-size: 13px; display: grid; gap: 4px; }

.pix-aguardando { margin-top: 12px; font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.pix-pulso { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); animation: pulso 1.4s ease-in-out infinite; }
@keyframes pulso { 0%, 100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.1); } }
@media (prefers-reduced-motion: reduce) { .pix-pulso { animation: none; } }
