:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #121826;
  --muted: #5d6676;
  --border: #e1e5eb;
  --primary: #1f3f6e;
  --primary-2: #2c5a9a;
  --on-primary: #ffffff;
  --focus: #2c7be5;
  --bad: #b42318;  --bad-bg: #fef3f2;  --bad-bd: #fecdca;
  --warn: #9a4a05; --warn-bg: #fffaeb; --warn-bd: #fedf89;
  --info: #175cd3; --info-bg: #eff6ff; --info-bd: #c7dcfb;
  --ok: #067647;   --ok-bg: #ecfdf3;   --ok-bd: #abefc6;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b111b; --surface: #131b28; --surface-2: #1a2433; --text: #e8edf5; --muted: #9aa6b8; --border: #263244;
    --primary: #6e9fe6; --primary-2: #8db4ee; --on-primary: #0b111b; --focus: #8db4ee;
    --bad: #fda29b; --bad-bg: #3a1513; --bad-bd: #6b2520;
    --warn: #fec84b; --warn-bg: #352708; --warn-bd: #5c430d;
    --info: #84adff; --info-bg: #102445; --info-bd: #1e3a6a;
    --ok: #75e0a7; --ok-bg: #0c2c1d; --ok-bd: #145236;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b111b; --surface: #131b28; --surface-2: #1a2433; --text: #e8edf5; --muted: #9aa6b8; --border: #263244;
  --primary: #6e9fe6; --primary-2: #8db4ee; --on-primary: #0b111b; --focus: #8db4ee;
  --bad: #fda29b; --bad-bg: #3a1513; --bad-bd: #6b2520;
  --warn: #fec84b; --warn-bg: #352708; --warn-bd: #5c430d;
  --info: #84adff; --info-bg: #102445; --info-bd: #1e3a6a;
  --ok: #75e0a7; --ok-bg: #0c2c1d; --ok-bd: #145236;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
body.no-scroll { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: 8px; }

.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.txt-bad { color: var(--bad); display: flex; gap: 4px; align-items: center; }
.txt-warn { color: var(--warn); display: flex; gap: 4px; align-items: center; }
.txt-bad .ic, .txt-warn .ic { width: 14px; height: 14px; }

/* ---------- topo ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: var(--primary); color: #fff;
}
.topbar { background: #1f3f6e; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 8px; }
.brand div { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand span { font-size: .78rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 4px; }
.topbar .icon-btn { color: #fff; }
.topbar .icon-btn.on { background: rgb(255 255 255 / 22%); color: #ffe58a; }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px 24px; outline: none; }
.page-title { font-size: 1.45rem; margin: 8px 0 12px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.page-title .muted { font-size: 1rem; font-weight: 500; }

/* ---------- navegação inferior ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: .7rem; font-weight: 600; min-width: 0;
}
.tabbar a .ic { width: 24px; height: 24px; }
.tabbar a[aria-current="page"] { color: var(--primary); }
.tabbar a[aria-current="page"] .ic { stroke-width: 2.4; }

/* ---------- cartões, listas ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin: 0 0 12px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 8px; font-size: 1.02rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
.list { display: flex; flex-direction: column; }
.list.card { padding: 4px 14px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 52px; padding: 8px 0; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }
.row-btn { background: none; border: 0; border-bottom: 1px solid var(--border); width: 100%; text-align: left; cursor: pointer; }
.row-btn:active { background: var(--surface-2); }
.row-btn.blocked { opacity: .8; }
.row-btn.sugerido { background: var(--ok-bg); border-radius: 10px; padding-inline: 8px; }
.row-btn.inativo { opacity: .55; }
.vcol { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.person { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.pname { font-weight: 600; }
.nick { font-size: .78em; font-weight: 500; color: var(--muted); white-space: nowrap; }
.party {
  display: inline-flex; align-items: center; gap: 5px; font-size: .74rem; font-weight: 700; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
}
.party i { width: 8px; height: 8px; border-radius: 50%; background: var(--pc); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: .76rem; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.chip-ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-bd); }
.chip-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-bd); }
.chip-bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-bd); }
.chip-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 8px 14px; cursor: pointer; font-weight: 600; }
.chip-btn.on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

/* ---------- alertas ---------- */
.alert {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; margin: 0 0 10px; border: 1px solid;
}
.alert > .ic { margin-top: 2px; width: 22px; height: 22px; }
.alert-body { min-width: 0; flex: 1; }
.alert strong { display: block; }
.alert p { margin: 2px 0 0; font-size: .92rem; }
.alert .art { display: inline-block; margin-top: 6px; font-size: .74rem; font-weight: 700; opacity: .85; letter-spacing: .02em; }
.alert .btn { margin-top: 8px; }
.alert-bloqueio { background: var(--bad-bg); border-color: var(--bad-bd); color: var(--bad); }
.alert-atencao { background: var(--warn-bg); border-color: var(--warn-bd); color: var(--warn); }
.alert-info { background: var(--info-bg); border-color: var(--info-bd); color: var(--info); }
.alert-ok { background: var(--ok-bg); border-color: var(--ok-bd); color: var(--ok); }
.alert p, .alert .small { color: var(--text); }

/* ---------- botões, formulários ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 16px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 650; cursor: pointer; text-decoration: none; text-align: center; user-select: none;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:not(:disabled):active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-bd); }
.btn-warn { background: var(--warn); color: #fff; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .88rem; border-radius: 10px; }
.btn-block { display: flex; width: 100%; margin: 0 0 10px; }
.btn-row { display: flex; gap: 8px; margin-bottom: 10px; }
.btn-row > * { flex: 1; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
  background: transparent; border: 0; color: var(--muted); cursor: pointer; text-decoration: none;
}
.icon-btn:active { background: var(--surface-2); }
.input {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); font-size: 16px; /* evita zoom no iOS */
}
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: .88rem; font-weight: 600; }
.field .input { font-weight: 400; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toggle-row { cursor: pointer; justify-content: flex-start; }
.toggle-row > span:not(.switch):not(.person) { flex: 1; font-size: .92rem; }
.toggle-row .person { flex: 1; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  flex: none; width: 46px; height: 28px; border-radius: 999px; background: var(--border); position: relative; transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 30%); transition: transform .15s;
}
.toggle-row input:checked ~ .switch { background: var(--ok); }
.toggle-row input:checked ~ .switch::after { transform: translateX(18px); }
.toggle-row input:focus-visible ~ .switch { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- segmentos e etapas ---------- */
.segmented {
  display: flex; gap: 4px; padding: 4px; margin: 0 0 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  flex: 1 0 auto; min-height: 40px; padding: 6px 12px; border: 0; border-radius: 9px; background: transparent;
  font-weight: 600; font-size: .9rem; color: var(--muted); cursor: pointer; white-space: nowrap; position: relative;
}
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 6px; vertical-align: middle; }
.dot-bloqueio { background: var(--bad); }
.dot-atencao { background: var(--warn); }
.dot-ok { background: var(--ok); }

.stepper { list-style: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 0; margin: 0 0 12px; }
.stepper li { min-width: 0; color: var(--muted); }
.stepper .step {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; width: 100%; min-height: 64px;
  padding: 6px 2px; border: 0; border-radius: 12px; background: none; color: inherit; font: inherit; font-size: .72rem;
  cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.stepper .step:active { background: var(--surface); }
.stepper .step:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.stepper li.viewing .step { background: var(--surface); box-shadow: inset 0 0 0 2px var(--primary); color: var(--text); }
[id^="cand-"] { scroll-margin-top: 76px; }
.stepper .num {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  background: var(--surface); border: 2px solid var(--border);
}
.stepper .num .ic { width: 16px; height: 16px; }
.stepper .lbl { font-weight: 600; line-height: 1.15; }
.stepper .who { font-size: .68rem; line-height: 1.15; color: var(--ok); font-weight: 600; max-width: 100%; overflow-wrap: anywhere; }
.stepper .who small { display: block; font-size: .62rem; font-weight: 500; color: var(--muted); }
.stepper li.current { color: var(--text); }
.stepper li.current .num { border-color: var(--primary); color: var(--primary); }
.stepper li.done .num { background: var(--ok); border-color: var(--ok); color: #fff; }

.now-voting { margin: 4px 0 12px; }
.now-voting h2 { margin: 0; font-size: 1.3rem; }
.eyebrow { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }

/* ---------- escolha do resultado ---------- */
.vote-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.vote-btn {
  position: relative; min-height: 72px; padding: 10px 10px 10px 16px; border-radius: 14px; cursor: pointer; text-align: left;
  border: 2px solid var(--pc); background: var(--surface); display: flex; flex-direction: column; justify-content: center; gap: 2px;
  box-shadow: inset 6px 0 0 var(--pc);
}
.vote-btn:active { background: var(--surface-2); transform: scale(.98); }
.vote-btn.sel { background: var(--ok-bg); border-color: var(--ok); box-shadow: inset 6px 0 0 var(--ok); padding-right: 44px; }
.vote-btn.invalid { border: 2px dashed var(--bad-bd); box-shadow: none; background: var(--bad-bg); }
.vote-btn.invalid .vb-party { color: var(--bad); display: flex; gap: 4px; align-items: center; }
.vote-btn.invalid .ic { width: 14px; height: 14px; }
.vb-name { font-weight: 800; font-size: 1rem; line-height: 1.15; overflow-wrap: anywhere; }
.vb-nick { font-size: .78rem; color: var(--muted); font-weight: 600; line-height: 1.15; }
.vb-party { font-size: .76rem; color: var(--muted); font-weight: 700; }
.vb-ord {
  position: absolute; top: 6px; right: 8px; min-width: 30px; height: 26px; padding: 0 6px; border-radius: 999px;
  display: grid; place-items: center; background: var(--ok); color: #fff; font-weight: 800; font-size: .85rem;
}
.card.highlight { border: 2px solid var(--ok); }
.card.viewing { box-shadow: 0 0 0 2px var(--primary); }

.result-row { justify-content: flex-start; flex-wrap: wrap; }
.rr-cargo { width: 120px; flex: none; font-size: .85rem; color: var(--muted); font-weight: 600; }
.plain-ol { margin: 0 0 6px; padding-left: 20px; }
.rules { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: .92rem; }
.rules dt { font-weight: 700; color: var(--primary); white-space: nowrap; }
.rules dd { margin: 0; }
.credito { margin: 18px 0 4px; text-align: center; font-size: .78rem; color: var(--muted); }
.report pre { white-space: pre-wrap; margin: 0; font: .9rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.log { display: flex; flex-direction: column; gap: 6px; max-height: 380px; overflow: auto; }
.log-row { display: grid; grid-template-columns: 92px 1fr; gap: 8px; font-size: .84rem; padding: 6px 8px; border-radius: 8px; background: var(--surface-2); border-left: 4px solid var(--border); }
.log-row time { color: var(--muted); }
.log-bloqueio { border-left-color: var(--bad); }
.log-atencao { border-left-color: var(--warn); }
.log-ok { border-left-color: var(--ok); }
.log-info { border-left-color: var(--info); }

/* ---------- sheet (modal inferior) ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgb(0 0 0 / 45%); animation: fade .15s ease-out; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; max-height: 88dvh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom);
  animation: up .2s ease-out; outline: none; max-width: 720px; margin: 0 auto;
}
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 8px auto 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px 4px 16px; }
.sheet-head h2 { font-size: 1.1rem; margin: 0; }
.sheet-body { overflow: auto; padding: 4px 16px 12px; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 10px 16px; border-top: 1px solid var(--border); }
.sheet-foot .btn-row { margin: 0; }
@keyframes up { from { transform: translateY(30%); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s;
  display: flex; gap: 8px; align-items: flex-start; max-width: min(92vw, 560px); width: max-content;
  padding: 12px 14px; border-radius: 12px; background: #1d2939; color: #fff; font-size: .92rem; box-shadow: 0 8px 24px rgb(0 0 0 / 25%);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-bloqueio { background: #b42318; }
.toast-atencao { background: #93370d; }
.toast-ok { background: #067647; }

@media (min-width: 768px) {
  .tabbar { max-width: 720px; margin: 0 auto; border: 1px solid var(--border); border-bottom: 0; border-radius: 16px 16px 0 0; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

@media print {
  .topbar, .tabbar, .btn, .btn-row, .segmented, .toast, .sheet, .skip { display: none !important; }
  body { background: #fff; color: #000; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .log { max-height: none; }
}

/* textos escuros sobre fundos claros no tema escuro */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-warn, :root:not([data-theme="light"]) .vb-ord { color: #1a1000; }
}
:root[data-theme="dark"] .btn-warn, :root[data-theme="dark"] .vb-ord { color: #1a1000; }
