/* FLS Sorteio — paleta FLS (creme, marrom, bronze). Tema claro, escuro ou automático
   (segue o sistema; o botão de tema em theme.js grava a escolha em data-theme). */
:root {
  --bg: #f6f1ea;
  --surface: #ffffff;
  --surface-2: #fbf8f3;
  --line: #e6dccd;
  --line-strong: #d4c4ac;
  --text: #2b1a0e;
  --muted: #7a6654;
  --heading: #4a2712;
  --link: #6b3b1d;
  --primary: #4a2712;
  --primary-hover: #6b3b1d;
  --on-primary: #ffffff;
  --gold-btn: #a8732f;
  --gold-btn-hover: #91621f;
  --on-gold: #ffffff;
  --bronze: #a8732f;
  --bronze-soft: #f3e6d3;
  --focus-ring: rgba(168, 115, 47, 0.18);
  --ok: #2f7d4f;
  --ok-soft: #e3f2e8;
  --warn: #9a6a12;
  --warn-soft: #fbf0d9;
  --danger: #b03a2e;
  --danger-soft: #fbe7e4;
  --danger-line: #e3b3ac;
  --chip-neutral: #efe9e1;
  --toast: #4a2712;
  --backdrop: rgba(43, 26, 14, 0.45);
  --shadow: 0 1px 2px rgba(74, 39, 18, 0.06), 0 8px 24px rgba(74, 39, 18, 0.07);
  color-scheme: light;
  --radius: 14px;
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14100d;
    --surface: #1d1712;
    --surface-2: #241d17;
    --line: #3a2f25;
    --line-strong: #4f4033;
    --text: #f3ebe0;
    --muted: #b3a291;
    --heading: #f0d6ae;
    --link: #d9a866;
    --primary: #c9934f;
    --primary-hover: #d9a866;
    --on-primary: #1a120b;
    --gold-btn: #c9934f;
    --gold-btn-hover: #d9a866;
    --on-gold: #1a120b;
    --bronze: #c9934f;
    --bronze-soft: #3a2a19;
    --focus-ring: rgba(201, 147, 79, 0.28);
    --ok: #4ade80;
    --ok-soft: #163222;
    --warn: #f5d38a;
    --warn-soft: #3a2a17;
    --danger: #fca5a5;
    --danger-soft: #3d1a15;
    --danger-line: #6b2d25;
    --chip-neutral: #2e251d;
    --toast: #2e251d;
    --backdrop: rgba(0, 0, 0, 0.6);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #14100d;
  --surface: #1d1712;
  --surface-2: #241d17;
  --line: #3a2f25;
  --line-strong: #4f4033;
  --text: #f3ebe0;
  --muted: #b3a291;
  --heading: #f0d6ae;
  --link: #d9a866;
  --primary: #c9934f;
  --primary-hover: #d9a866;
  --on-primary: #1a120b;
  --gold-btn: #c9934f;
  --gold-btn-hover: #d9a866;
  --on-gold: #1a120b;
  --bronze: #c9934f;
  --bronze-soft: #3a2a19;
  --focus-ring: rgba(201, 147, 79, 0.28);
  --ok: #4ade80;
  --ok-soft: #163222;
  --warn: #f5d38a;
  --warn-soft: #3a2a17;
  --danger: #fca5a5;
  --danger-soft: #3d1a15;
  --danger-line: #6b2d25;
  --chip-neutral: #2e251d;
  --toast: #2e251d;
  --backdrop: rgba(0, 0, 0, 0.6);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  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.5 var(--sans);
}

[hidden] { display: none !important; }

a { color: var(--link); }

h1, h2, h3 { font-family: var(--serif); color: var(--heading); line-height: 1.2; margin: 0; }

button, input, textarea, select { font: inherit; color: inherit; }

/* ---------- marca ---------- */
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 42px; height: 42px; border-radius: 11px;
  background: #4a2712; color: #d9ad72;
  font: 700 15px/1 var(--serif); letter-spacing: 0.02em; flex: none;
}
.brand-title { margin: 0; font: 700 17px/1.2 var(--serif); color: var(--heading); }
.brand-subtitle { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- campos e botões ---------- */
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > span { font-size: 14px; font-weight: 600; color: var(--heading); }
.field input, .field textarea, .field select {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--line-strong); border-radius: 10px;
  background: var(--surface); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 84px; }
.field input:focus, .field textarea:focus {
  border-color: var(--bronze); box-shadow: 0 0 0 3px var(--focus-ring);
}
.field.invalid input { border-color: var(--danger); }
.field-error { margin: 0; font-size: 13px; color: var(--danger); }
.field-hint { margin: 0; font-size: 12.5px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1.5px solid transparent;
  font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s, opacity .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-gold { background: var(--gold-btn); color: var(--on-gold); }
.btn-gold:hover:not(:disabled) { background: var(--gold-btn-hover); }
.btn-ghost { background: var(--surface); border-color: var(--line-strong); color: var(--heading); }
.btn-ghost:hover:not(:disabled) { border-color: var(--bronze); }
.btn-danger { background: var(--surface); border-color: var(--danger-line); color: var(--danger); }
.btn-danger-solid { background: #b03a2e; color: #fff; }
.btn-danger-solid:hover:not(:disabled) { background: #962f25; }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-sm { padding: 6px 11px; font-size: 13.5px; border-radius: 8px; }
.btn-lg { padding: 15px 22px; font-size: 17px; border-radius: 12px; }
.btn-block { width: 100%; }

.form-error {
  margin: 0 0 14px; padding: 10px 12px; border-radius: 10px;
  background: var(--danger-soft); color: var(--danger); font-size: 14px;
}

/* ---------- página pública ---------- */
.public-page { min-height: 100vh; display: flex; flex-direction: column; }
.public-header { padding: 20px 16px 0; display: flex; justify-content: center; }
.public-main { flex: 1; width: 100%; max-width: 520px; margin: 0 auto; padding: 20px 16px 32px; }
.public-card {
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow);
  border: 1px solid var(--line); overflow: hidden;
}
.public-hero {
  padding: 26px 24px 22px; text-align: center;
  background: linear-gradient(160deg, #4a2712 0%, #5d3218 100%); color: #fff;
}
.public-hero .eyebrow {
  display: inline-block; margin-bottom: 10px; padding: 4px 12px; border-radius: 999px;
  background: rgba(217, 173, 114, 0.18); color: #d9ad72;
  font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
}
.public-hero h1 { color: #fff; font-size: 26px; }
.public-prize {
  margin: 14px auto 0; padding: 10px 14px; max-width: 380px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(217, 173, 114, 0.4);
  color: #fbeedd; font-size: 15px;
}
.public-prize strong { color: #d9ad72; }
.public-body { padding: 22px 24px 24px; }
.public-desc { margin: 0 0 18px; color: var(--muted); white-space: pre-line; }
.privacy-note { margin: 14px 0 0; font-size: 12.5px; color: var(--muted); text-align: center; }
.rules { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.rules summary { cursor: pointer; font-weight: 600; color: var(--heading); font-size: 14px; }
.rules-text { margin-top: 10px; font-size: 13.5px; color: var(--muted); white-space: pre-line; max-height: 320px; overflow: auto; }
.honeypot { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.state { padding: 34px 24px; text-align: center; }
.state-icon {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 50%;
  display: grid; place-items: center; font-size: 30px;
  background: var(--ok-soft); color: var(--ok);
}
.state-icon.neutral { background: var(--bronze-soft); color: var(--bronze); }
.state h2 { font-size: 22px; margin-bottom: 8px; }
.state p { margin: 0 auto; max-width: 360px; color: var(--muted); }
.public-footer { padding: 0 16px 24px; text-align: center; font-size: 12.5px; color: var(--muted); }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; padding: 28px 24px;
  background: var(--surface); border-radius: 18px; border: 1px solid var(--line); box-shadow: var(--shadow);
}
.login-card .brand { margin-bottom: 22px; }
.login-footnote { margin: 16px 0 0; text-align: center; font-size: 12.5px; color: var(--muted); }

/* ---------- painel ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }

.layout {
  display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 20px;
  max-width: 1280px; margin: 0 auto; padding: 20px;
}
.sidebar { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 86px; align-self: start; max-height: calc(100vh - 106px); overflow-y: auto; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.sidebar-head h2 { font-size: 18px; }
.raffle-list { display: flex; flex-direction: column; gap: 8px; }
.raffle-item {
  text-align: left; width: 100%; padding: 12px 14px; cursor: pointer;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px;
  display: grid; gap: 6px; transition: border-color .15s, box-shadow .15s;
}
.raffle-item:hover { border-color: var(--line-strong); }
.raffle-item.active { border-color: var(--bronze); box-shadow: 0 0 0 3px var(--focus-ring); }
.raffle-item-title { font-weight: 700; color: var(--heading); overflow-wrap: anywhere; }
.raffle-item-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip-aberto { background: var(--ok-soft); color: var(--ok); }
.chip-encerrado { background: var(--chip-neutral); color: var(--muted); }
.chip-rascunho { background: var(--warn-soft); color: var(--warn); }

.empty { padding: 22px; text-align: center; color: var(--muted); background: var(--surface); border: 1.5px dashed var(--line-strong); border-radius: 12px; }

.main { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-pad { padding: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h3 { font-size: 17px; }

.detail-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.detail-head h1 { font-size: 26px; overflow-wrap: anywhere; }
.detail-sub { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.public-link { margin-top: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.public-link code { padding: 4px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); color: var(--heading); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 18px; }
.stat { padding: 14px 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.stat-label { font-size: 12.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { margin-top: 4px; font: 700 26px/1.1 var(--serif); color: var(--heading); }

/* palco do sorteio */
.stage {
  padding: 28px 20px; text-align: center; border-radius: var(--radius);
  background: radial-gradient(ellipse at top, #6a3a1c 0%, #4a2712 60%, #351a0b 100%); color: #fff;
  position: relative; overflow: hidden;
}
.stage-label { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: #d9ad72; font-weight: 700; }
.stage-screen {
  margin: 16px auto 20px; max-width: 560px; min-height: 104px; padding: 18px;
  border-radius: 16px; background: rgba(0, 0, 0, 0.22); border: 1px solid rgba(217, 173, 114, 0.35);
  display: grid; place-items: center; gap: 4px;
}
.stage-name { font: 700 30px/1.15 var(--serif); color: #fff; overflow-wrap: anywhere; }
.stage-name.rolling { color: #f0dcc0; opacity: .85; }
.stage-name.revealed { color: #d9ad72; animation: pop .5s ease-out; }
.stage-extra { font-size: 14px; color: #eadbc6; }
.stage-controls { display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap; }
.stage-controls label { font-size: 14px; color: #eadbc6; display: flex; align-items: center; gap: 8px; }
.stage-controls input {
  width: 70px; padding: 9px 10px; border-radius: 10px; text-align: center;
  border: 1px solid rgba(217, 173, 114, 0.5); background: rgba(255, 255, 255, 0.1); color: #fff;
}
.stage-note { margin: 12px 0 0; font-size: 13px; color: #d9c7ad; }
.stage-note.warn { color: #ffd58a; }
@keyframes pop { 0% { transform: scale(.85); opacity: 0; } 60% { transform: scale(1.06); opacity: 1; } 100% { transform: scale(1); } }

.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; opacity: .9;
  animation: fall 1.8s ease-in forwards;
}
@keyframes fall { to { transform: translateY(420px) rotate(540deg); opacity: 0; } }

/* tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

.winner-pos {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: var(--bronze-soft); color: var(--heading); font: 700 15px/1 var(--serif);
}
tr.disqualified td { color: var(--muted); }
tr.disqualified .winner-name { text-decoration: line-through; }
.winner-name { font-weight: 700; color: var(--heading); }
.winner-contact { white-space: nowrap; }
.winner-contact a { display: block; }
.winner-contact a + a { font-size: 13px; color: var(--muted); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search { padding: 8px 12px; border: 1.5px solid var(--line-strong); border-radius: 10px; min-width: 220px; background: var(--surface); }
.search:focus { outline: none; border-color: var(--bronze); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }

/* diálogo */
dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 0; border: none; border-radius: 18px; box-shadow: 0 20px 60px rgba(43, 26, 14, 0.3);
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: var(--backdrop); }
.dialog-head { padding: 18px 22px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: 20px; }
.dialog-body { padding: 20px 22px 4px; overflow-y: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px 20px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  padding: 12px 18px; border-radius: 12px; background: var(--toast); color: #fff; border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 14px; max-width: calc(100vw - 32px);
}
.toast.error { background: #b03a2e; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .sidebar { position: static; max-height: none; overflow: visible; min-width: 0; }
  .raffle-list { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .raffle-item { min-width: 220px; }
}

@media (max-width: 560px) {
  .topbar { padding: 10px 16px; }
  .brand-subtitle { display: none; }
  .topbar .brand-title { font-size: 15px; }
  #user-name { display: none; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stats .stat:last-child { grid-column: span 2; }
  .stage-name { font-size: 24px; }
  .detail-head h1 { font-size: 22px; }
  .panel-pad { padding: 16px; }
  .search { min-width: 0; flex: 1; }
  .public-hero h1 { font-size: 23px; }
  .public-body { padding: 20px 18px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.empty-inset { margin: 16px; }
.desc-nome { margin-top: 0; font-weight: 600; color: var(--heading); }
.hint-gap { margin-bottom: 14px; }
#s-status { font-size: 20px; }

.exc-aviso { margin: 0 0 10px; padding: 10px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 14px; }

/* botão de tema */
.theme-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-btn svg .fill { fill: currentColor; stroke: none; }
.corner-theme { position: absolute; top: 16px; right: 16px; }
.public-header, .login-page { position: relative; }
@media (max-width: 560px) {
  .theme-btn .theme-label { display: none; }
  .theme-btn { width: 34px; padding: 6px 0; }
}

/* no escuro, a marca e o palco ganham um contorno para não sumir no fundo */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-mark,
  :root:not([data-theme="light"]) .stage,
  :root:not([data-theme="light"]) .public-hero { box-shadow: inset 0 0 0 1px rgba(217, 173, 114, 0.25); }
}
:root[data-theme="dark"] .brand-mark,
:root[data-theme="dark"] .stage,
:root[data-theme="dark"] .public-hero { box-shadow: inset 0 0 0 1px rgba(217, 173, 114, 0.25); }
