:root {
  --blue: #0b3d91;
  --blue-2: #1565c0;
  --gold: #c9a227;
  --gold-2: #f4d35e;
  --bg: #f3f5f9;
  --card: #fff;
  --text: #1c2333;
  --muted: #667085;
  --line: #d0d5dd;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--blue-2); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }
.loading { padding: 60px; text-align: center; color: var(--muted); }

/* ---------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--blue); color: #fff;
  padding: calc(env(safe-area-inset-top) + 6px) 14px 6px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; }
.topbar .brand img { width: 36px; height: 36px; border-radius: 50%; background: #fff; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a {
  color: #dbe6ff; text-decoration: none; padding: 7px 11px; border-radius: 8px; font-size: 14px;
}
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,.15); color: #fff; }
.topbar .user { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #dbe6ff; }
.live i { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(22,163,74,.6); animation: pulse 2s infinite; }
.live.off i { background: var(--bad); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(22,163,74,.6); } 70% { box-shadow: 0 0 0 8px rgba(22,163,74,0); } 100% { box-shadow: 0 0 0 0 rgba(22,163,74,0); } }
.btn.menu-btn { display: none; }

@media (max-width: 820px) {
  .btn.menu-btn { display: inline-flex; }
  .topbar nav { display: none; flex-basis: 100%; flex-direction: column; }
  .topbar.open nav { display: flex; }
}

/* ---------- layout */
.view { max-width: 1500px; margin: 0 auto; padding: 18px 14px 60px; }
.page-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 14px; }
.page-title h1 { font-size: 22px; margin: 0; flex: 1; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; border: 1px solid #e6e9ef; }
.card h2 { margin: 0 0 12px; font-size: 17px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 14px; overflow-x: auto; overflow-y: hidden; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; font-weight: 600; }
.tabs a.active { color: var(--blue); border-color: var(--gold); }

/* ---------- forms */
label { display: block; font-size: 13px; font-weight: 600; color: #344054; margin-bottom: 4px; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-2); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--blue); vertical-align: middle; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; margin: 0; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f2f4f7; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #082d6b; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #1c1400; }
.btn.danger { color: var(--bad); border-color: #f5c2c2; }
.btn.danger:hover { background: #fff1f1; }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef2ff; color: var(--blue); }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.gold { background: #fdf3c4; color: #7a5b00; }
.progress { height: 6px; background: #e5e7eb; border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ok); }

/* ---------- tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid #eaecf0; text-align: left; vertical-align: middle; }
table.list th { font-size: 12px; text-transform: uppercase; color: var(--muted); background: #f9fafb; }
table.perm { border-collapse: collapse; width: 100%; }
table.perm th, table.perm td { border: 1px solid #eaecf0; padding: 6px 8px; text-align: center; font-size: 13px; }
table.perm td:first-child, table.perm th:first-child { text-align: left; font-weight: 600; }

/* ---------- planilhas (sheet) */
.sheet { background: #fff; border: 1px solid #c8cdd6; border-radius: 6px; padding: 14px; }
.sheet-head { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; margin-bottom: 10px; }
.sheet-head img { height: 74px; }
.sheet-head .t1 { font-size: 17px; font-weight: 800; text-align: center; color: #111; }
.sheet-head .t2 { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 6px; font-weight: 600; }
table.xl { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.xl th, table.xl td { border: 1px solid #333; padding: 3px 5px; text-align: center; vertical-align: middle; }
table.xl th { background: #f2f2f2; font-weight: 700; white-space: pre-line; font-size: 11.5px; line-height: 1.2; }
table.xl th.grp { background: #dbe5f1; }
table.xl th.cat { background: #fff; font-size: 13px; text-align: left; }
table.xl td.name { text-align: left; min-width: 180px; font-weight: 600; }
table.xl td.total { font-weight: 800; background: #fffbe6; min-width: 54px; }
table.xl td.place { font-weight: 800; min-width: 48px; }
table.xl td input, table.xl td select {
  width: 64px; padding: 5px 4px; text-align: center; border-radius: 4px; border: 1px solid #b9c0cc; font-size: 14px;
}
table.xl td select { width: 70px; }
table.xl td input.err { border-color: var(--bad); background: #fff1f1; }
table.xl td input.saved { background: #ecfdf3; }
table.xl tr.p1 td.place { background: #ffe58a; }
table.xl tr.p2 td.place { background: #e5e7eb; }
table.xl tr.p3 td.place { background: #f3c9a0; }
.sheet-foot { display: grid; grid-template-columns: 1.2fr 1.5fr 1fr; border: 1px solid #333; border-top: 0; font-size: 12.5px; }
.sheet-foot > div { padding: 6px 8px; border-right: 1px solid #333; min-height: 64px; }
.sheet-foot > div:last-child { border-right: 0; }
.sheet-foot b { display: block; margin-bottom: 4px; }
.sig-img { max-height: 56px; max-width: 100%; }
.sigs { display: flex; gap: 12px; flex-wrap: wrap; }
.sigs figure { margin: 0; text-align: center; font-size: 11px; }
.critique { border: 1px solid #333; border-top: 0; padding: 6px 8px; font-size: 12.5px; }
.critique textarea { min-height: 80px; margin-top: 4px; }
.critique .txt { white-space: pre-wrap; min-height: 60px; }
.sheet-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.lockbar { padding: 8px 12px; border-radius: 8px; background: #fef3c7; color: #7a4a00; margin-bottom: 10px; font-weight: 600; }
.lockbar.ok { background: #dcfce7; color: #166534; }
.rank-foot { margin-top: 10px; font-size: 13px; }
.rank-foot table { border-collapse: collapse; min-width: 340px; }
.rank-foot td { border: 1px solid #333; padding: 4px 8px; }

/* ---------- editor de campos */
.crit-row { display: grid; grid-template-columns: 30px 1fr 150px 90px auto; gap: 8px; align-items: start; padding: 8px 0; border-bottom: 1px dashed #e4e7ec; }
.crit-row textarea { min-height: 52px; }
.crit-row .n { font-weight: 700; color: var(--muted); padding-top: 8px; }
.judge-pick { display: flex; flex-direction: column; gap: 6px; }
.judge-pick .item { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border: 1px solid #eaecf0; border-radius: 8px; }
@media (max-width: 700px) {
  .crit-row { grid-template-columns: 1fr 1fr; }
  .crit-row .n { display: none; }
  .crit-row textarea { grid-column: 1 / -1; }
}

/* ---------- resultados ao vivo */
.results-head { background: linear-gradient(135deg, var(--blue), #062a66); color: #fff; border-radius: var(--radius); padding: 18px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.results-head img { height: 64px; background: #fff; border-radius: 8px; padding: 4px; }
.results-head h1 { margin: 0; font-size: 22px; }
.results-head .sub { opacity: .85; }
.results-head select { color: var(--text); }
.res-cat { margin-bottom: 18px; }
.res-cat h2 { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.podium { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.podium .pod { flex: 1; min-width: 180px; border-radius: 10px; padding: 12px; color: #1c1400; }
.podium .pod.p1 { background: linear-gradient(135deg, #ffe58a, #f4c430); }
.podium .pod.p2 { background: linear-gradient(135deg, #f1f3f5, #c9ced6); }
.podium .pod.p3 { background: linear-gradient(135deg, #f7d5b5, #d99a62); }
.podium .pod .pl { font-size: 26px; font-weight: 900; }
.podium .pod .nm { font-weight: 800; }
.podium .pod .sc { font-size: 20px; font-weight: 800; }
table.res td.score { font-weight: 800; font-size: 16px; }
.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: #fff3a3; } to { background: transparent; } }
body.tv .topbar { display: none; }
body.tv .view { max-width: none; }
body.tv table.res { font-size: 20px; }

/* ---------- modal / toast */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 14px; }
.modal .box { background: #fff; border-radius: 14px; width: min(760px, 100%); max-height: 92vh; overflow: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal .box.sm { width: min(440px, 100%); }
.modal h2 { margin-top: 0; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.toasts { position: fixed; bottom: calc(env(safe-area-inset-bottom) + 14px); left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; max-width: 90vw; }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }
.sigpad { border: 2px dashed #98a2b3; border-radius: 8px; width: 100%; height: 200px; touch-action: none; background: #fff; }

/* ---------- login / instalar */
.auth { max-width: 420px; margin: 7vh auto; }
.auth .logo { width: 100%; max-width: 360px; display: block; margin: 0 auto 18px; }
.install-box { text-align: center; }
.install-box img.app { width: 96px; height: 96px; border-radius: 22px; box-shadow: var(--shadow); }
.install-box ol { text-align: left; line-height: 1.8; }
.ios-share { display: inline-block; width: 20px; height: 20px; vertical-align: -4px; }

/* ---------- impressão */
.print-only { display: none; }
@media print {
  @page { size: A4 landscape; margin: 8mm; }
  body { background: #fff; font-size: 11px; }
  .topbar, .tabs, .sheet-tools, .no-print, .toasts, .modal, .lockbar { display: none !important; }
  .view { padding: 0; max-width: none; }
  .sheet { border: 0; padding: 0; }
  .print-only { display: block; }
  table.xl td input, table.xl td select { border: 0; width: auto; padding: 0; font-size: 12px; -webkit-appearance: none; appearance: none; background: transparent; }
  .critique textarea { border: 0; padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
}
