/* Identidade visual Petruz: verde da marca, cinzas neutros, superfícies planas. */
:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #eef1ef;
  --text: #1c2320;
  --muted: #5b6761;
  --border: #d8dfdb;
  --primary: #00813b;
  --primary-2: #01a048;
  --primary-soft: #e3f3e9;
  --on-primary: #ffffff;
  --brand-dark: #17201b;
  --ok: #12703a;
  --ok-soft: #e3f3e9;
  --warn: #965a00;
  --warn-soft: #fcf0d9;
  --bad: #b42318;
  --bad-soft: #fdeceb;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 28, 24, .06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111412;
    --surface: #181c1a;
    --surface-2: #212623;
    --text: #e6eae7;
    --muted: #98a39d;
    --border: #2c322f;
    --primary: #3cc274;
    --primary-2: #01a048;
    --primary-soft: #16301f;
    --on-primary: #07130b;
    --ok: #4fcf88;
    --ok-soft: #14301f;
    --warn: #f0b24a;
    --warn-soft: #33270f;
    --bad: #f2867c;
    --bad-soft: #3a1714;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100dvh;
}
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }
.center { text-align: center; }
.right { text-align: right; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }
.grow { flex: 1; }

/* Layout */
.wrap { max-width: 1180px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 520px; margin: 0 auto; padding: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card.flat { box-shadow: none; }

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar .wrap { display: flex; align-items: center; gap: 14px; padding-top: 10px; padding-bottom: 10px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; min-width: 0; }
.brand img { display: block; height: 26px; width: auto; }
.brand-sep { width: 1px; height: 24px; background: var(--border); flex: none; }
.brand-app { display: flex; flex-direction: column; font-weight: 600; font-size: .95rem; line-height: 1.15; white-space: nowrap; }
.brand-app small { font-weight: 400; font-size: .78rem; color: var(--muted); }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
/* Menu do RH: marca, evento e conta na 1ª linha; abas em linha própria, quebrando se faltar espaço (nenhuma fica oculta). */
.topbar .tabs { order: 10; flex: 1 0 100%; margin-left: -12px; }
.topbar .tabs ~ #selEvento { margin-left: auto; min-width: 0; }
.topbar .wrap:has(.tabs) { row-gap: 4px; padding-bottom: 0; }
.tabs button {
  border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  padding: 10px 12px 9px; border-radius: 0; cursor: pointer; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); border-bottom-color: var(--primary-2); }

/* Forms */
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 9px 11px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-2) 20%, transparent); }
input.big { font-size: 1.45rem; padding: 13px 15px; text-align: center; letter-spacing: .04em; font-weight: 600; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary-2); vertical-align: -3px; margin-right: 6px; }
.check { font-weight: 500; display: flex; align-items: flex-start; gap: 2px; }
.field { margin-bottom: 12px; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.hint { font-size: .82rem; color: var(--muted); margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 6px;
  padding: 9px 16px; cursor: pointer; background: var(--primary); color: var(--on-primary);
  text-decoration: none; transition: background-color .12s, filter .12s;
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.lg { font-size: 1.1rem; padding: 13px 20px; }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); filter: none; }
.btn.ok { background: #12703a; color: #fff; }
.btn.bad { background: #b42318; color: #fff; }
.btn.warn { background: #a35f00; color: #fff; }
.btn.link { background: none; border: 0; color: var(--primary); padding: 4px 6px; }

/* Badges */
.badge {
  display: inline-block; font-size: .76rem; font-weight: 600; padding: 2px 8px; border-radius: 4px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--surface-2); color: var(--text); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .78rem; font-weight: 600; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
td.actions { white-space: nowrap; text-align: right; }

/* KPIs */
.kpi { padding: 16px; }
.kpi .v { font-size: 1.9rem; font-weight: 650; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .85rem; font-weight: 600; }
.kpi .s { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: #7d8a83; border-radius: 2px; }
.bar > i.ok { background: var(--primary-2); }
.bars-row { display: grid; grid-template-columns: minmax(110px, 180px) 1fr auto; gap: 10px; align-items: center; padding: 6px 0; font-size: .9rem; }
.bar.stacked { position: relative; height: 12px; }
.bar.stacked > i { position: absolute; left: 0; top: 0; }

/* Alerts */
.alert { padding: 11px 14px; border-radius: 6px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-left-width: 4px; }
.alert.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); border-left-color: var(--ok); }
.alert.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); border-left-color: var(--warn); }
.alert.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); border-left-color: var(--bad); }

/* Toasts */
#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; width: min(92vw, 440px); }
.toast {
  background: #1c2320; color: #fff; padding: 11px 16px; border-radius: 6px; box-shadow: 0 4px 14px rgba(0, 0, 0, .2);
  font-weight: 500; animation: pop .16s ease-out; border-left: 4px solid #7d8a83;
}
.toast.ok { border-left-color: var(--primary-2); }
.toast.bad { border-left-color: #e5483b; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

/* Modal */
.overlay {
  position: fixed; inset: 0; background: rgba(12, 16, 14, .55);
  display: grid; place-items: center; z-index: 100; padding: 16px; overflow-y: auto;
}
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; width: min(100%, 520px); padding: 22px; box-shadow: 0 10px 30px rgba(0, 0, 0, .18); max-height: 92dvh; overflow-y: auto; }
.modal.wide { width: min(100%, 760px); }
.modal h2 { margin-bottom: 14px; }
.modal .foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

/* Login em página inteira: nada do sistema aparece antes de autenticar */
body.auth-pending > :not(.login-page):not(.overlay):not(#toasts) { visibility: hidden; }
body.auth-pending .overlay { background: var(--bg); }
.login-page { position: fixed; inset: 0; z-index: 90; display: grid; grid-template-columns: minmax(340px, 5fr) 7fr; background: var(--bg); overflow-y: auto; }
.login-side {
  position: relative; overflow: hidden; background: var(--brand-dark); color: #fff;
  display: flex; flex-direction: column; justify-content: space-between; gap: 40px; padding: 48px 56px;
  border-top: 6px solid var(--primary-2);
}
.login-side > * { position: relative; z-index: 1; }
.login-side-logo { height: 46px; width: auto; display: block; align-self: flex-start; object-fit: contain; }
.modal-logo { display: block; margin-bottom: 18px; }
.modal-logo img { height: 30px; width: auto; display: block; }
.login-side h1 { font-size: clamp(1.7rem, 2.5vw, 2.4rem); font-weight: 600; margin: 0 0 12px; letter-spacing: -.01em; }
.login-side p { margin: 0; color: rgba(255, 255, 255, .72); font-size: 1.05rem; max-width: 34ch; }
.login-side small { color: rgba(255, 255, 255, .5); font-size: .82rem; }
.login-side .login-mark { position: absolute; z-index: 0; right: -90px; bottom: -90px; width: 380px; height: auto; opacity: .05; pointer-events: none; }
.login-main { display: grid; place-items: center; padding: 48px 24px; }
.login-form { width: min(100%, 380px); display: grid; gap: 18px; }
.login-form h2 { font-size: 1.6rem; margin: 0 0 4px; }
.login-sub { color: var(--muted); margin: 0; }
.login-form input { padding: 11px 12px; font-size: 1rem; }
.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 86px; }
.pass-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: 0; border-radius: 4px; padding: 6px 9px; cursor: pointer;
  font: inherit; font-size: .85rem; font-weight: 600; color: var(--primary);
}
.pass-toggle:hover { background: var(--surface-2); }
.login-help { font-size: .86rem; color: var(--muted); margin: 6px 0 0; padding-top: 16px; border-top: 1px solid var(--border); }
@media (max-width: 760px) {
  .login-page { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .login-side { padding: 22px 20px; gap: 12px; flex-direction: row; align-items: center; justify-content: flex-start; }
  .login-side-logo { height: 30px; }
  .login-side h1 { font-size: 1rem; font-weight: 600; margin: 0; padding-left: 12px; border-left: 1px solid rgba(255, 255, 255, .2); }
  .login-side p, .login-side small, .login-side .login-mark { display: none; }
  .login-main { place-items: start center; padding: 32px 16px 40px; }
}

/* Colaborador (página pública) */
.hero {
  background: var(--brand-dark); color: #fff; padding: 20px 16px 62px; text-align: center;
  border-top: 4px solid var(--primary-2);
}
.hero-logo { display: block; height: 30px; width: auto; margin: 0 auto 16px; }
.hero h1 { font-size: 1.6rem; margin-bottom: 6px; }
.hero .meta { color: rgba(255, 255, 255, .8); font-size: .95rem; }
.hero .company { text-transform: uppercase; letter-spacing: .08em; font-size: .74rem; font-weight: 600; color: rgba(255, 255, 255, .65); margin-bottom: 8px; }
.lift { margin-top: -44px; }
.person { display: flex; gap: 14px; align-items: center; }
.avatar {
  width: 52px; height: 52px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-weight: 650; font-size: 1.15rem;
}
.ticket { text-align: center; }
.ticket .qr { background: #fff; padding: 12px; border-radius: 8px; display: inline-block; border: 1px solid var(--border); }
.ticket .qr img { display: block; width: min(68vw, 280px); height: auto; image-rendering: pixelated; }
.ticket .code { font-family: var(--mono); font-size: 1.7rem; font-weight: 700; letter-spacing: .22em; }
.steps { display: flex; gap: 6px; justify-content: center; margin: 14px 0 0; }
.steps i { width: 28px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .25); }
.steps i.on { background: var(--primary-2); }

/* Portaria */
.scanner { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 1 / 1; max-height: 62dvh; margin: 0 auto; width: 100%; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame {
  position: absolute; inset: 14%; border-radius: 10px; pointer-events: none;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .4); border: 2px solid rgba(255, 255, 255, .9);
}
.scanner .msg { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; padding: 24px; text-align: center; }
.result { border-radius: var(--radius); padding: 22px; text-align: center; color: #fff; }
.result.ok { background: #12703a; }
.result.warn { background: #a35f00; }
.result.bad { background: #b42318; }
.result .icon { font-size: 3rem; line-height: 1; }
.result .title { font-size: 1.8rem; font-weight: 700; letter-spacing: .02em; margin: 6px 0; }
.result .name { font-size: 1.4rem; font-weight: 600; }
.result .extra { opacity: .95; margin-top: 4px; }
.result .guests { display: inline-block; margin-top: 10px; background: rgba(255, 255, 255, .2); padding: 5px 12px; border-radius: 4px; font-weight: 600; }
.result .btn { margin-top: 14px; }
.result .btn.light { background: #fff; color: #12703a; }
.result .btn.outline { background: transparent; border-color: rgba(255, 255, 255, .7); color: #fff; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .92rem; }
.feed li:last-child { border: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.ok { background: var(--primary-2); } .dot.warn { background: #d18a00; } .dot.bad { background: #d8382c; }

/* Sorteio (admin) */
.draw-stage { text-align: center; padding: 26px 18px; }
.draw-stage .winner { font-size: 1.9rem; font-weight: 700; margin: 8px 0 2px; }
.hash { font-family: var(--mono); font-size: .78rem; word-break: break-all; background: var(--surface-2); padding: 8px 10px; border-radius: 4px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: .92rem; align-items: start; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; min-width: 0; }
.check-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--border); }
.check-item:last-child { border: 0; }
.check-item .mark { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex: none; background: var(--muted); }
.check-item .mark.ok { background: #12703a; } .check-item .mark.bad { background: #b42318; }

.empty { text-align: center; color: var(--muted); padding: 34px 12px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary-2); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .wrap { padding: 12px; }
  h1 { font-size: 1.3rem; }
  .kpi .v { font-size: 1.6rem; }
  .hide-sm { display: none; }
  .topbar .tabs ~ #selEvento { flex: 1 1 0; margin-left: 0; }
  .brand img { height: 22px; }
}
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
}

/* ---- Lista de contingência da portaria (só existe na impressão) */
#printArea { display: none; }
@media print {
  @page { size: A4 portrait; margin: 11mm 9mm; }
  body.printing { background: #fff !important; color: #000; }
  body.printing > :not(#printArea) { display: none !important; }
  body.printing #printArea { display: block; color: #111; font: 9.5pt/1.3 "Segoe UI", system-ui, sans-serif; }
  #printArea * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pl-head { display: flex; align-items: center; gap: 12pt; padding-bottom: 6pt; border-bottom: 2.5pt solid #01a048; }
  .pl-head img { height: 24pt; width: auto; }
  .pl-tit { font-size: 14pt; font-weight: 700; }
  .pl-info { margin: 6pt 0 2pt; }
  .pl-passos { margin: 4pt 0 8pt; padding-left: 14pt; }
  .pl-passos li { margin: 1pt 0; }
  .pl-table { width: 100%; border-collapse: collapse; }
  .pl-table thead { display: table-header-group; }
  .pl-table th { text-align: left; font-size: 8pt; text-transform: uppercase; letter-spacing: .3pt; border-bottom: 1.2pt solid #111; padding: 3pt 4pt; }
  .pl-table td { border-bottom: .5pt solid #9a9a9a; padding: 3.5pt 4pt; vertical-align: middle; }
  .pl-table tr { break-inside: avoid; }
  .pl-letra td { background: #e9eeeb; font-weight: 700; padding: 2pt 4pt; border-bottom: .5pt solid #9a9a9a; }
  .pl-box { width: 30pt; text-align: center; font-size: 13pt; line-height: 1; }
  .pl-cod { font-family: Consolas, "Courier New", monospace; font-weight: 700; font-size: 10.5pt; letter-spacing: 1pt; white-space: nowrap; }
  .pl-num { text-align: center; white-space: nowrap; }
  .pl-hora { width: 50pt; border-left: .5pt solid #9a9a9a; }
  .pl-extra { margin: 12pt 0 4pt; break-before: avoid; }
  .pl-branco td { height: 17pt; border-left: .5pt solid #9a9a9a; }
  .pl-branco td:first-child { border-left: 0; width: 45%; }
  .pl-conf { margin-top: 10pt; font-size: 8pt; color: #444; text-align: center; }
}
