/* ==========================================================================
   Eleição UPA — Sistema Visual Oficial (Mobile-First + TV Broadcast)
   Fontes: Bricolage Grotesque (Display) + Plus Jakarta Sans + JetBrains Mono
   Paleta: Verde IPB / Âmbar Luz / Ardósia Profunda / Papel Quente
   ========================================================================== */

:root {
  --font-display: 'Bricolage Grotesque', Georgia, serif;
  --font-sans: 'Plus Jakarta Sans', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Light App Tokens */
  --bg-page: #F5F2E9;
  --bg-surface: #FFFFFF;
  --bg-muted: #EBE6D9;
  --border-subtle: #DDD6C5;
  --border-strong: #BFB59F;

  --ink-primary: #0D2026;
  --ink-secondary: #3E545C;
  --ink-muted: #647980;

  --emerald: #0E7C56;
  --emerald-hover: #0A6344;
  --emerald-soft: #DEF5EB;
  --emerald-bright: #1CD48E;

  --amber: #D9820B;
  --amber-bright: #FBBF24;
  --amber-soft: #FEF3D6;

  --coral: #D9432B;
  --coral-hover: #B8331E;
  --coral-soft: #FDE7E3;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-sm: 0 2px 6px rgba(13, 32, 38, 0.06);
  --shadow-md: 0 8px 24px rgba(13, 32, 38, 0.09);

  /* TV Broadcast Dark Tokens */
  --tv-bg: #071419;
  --tv-surface: #0E222A;
  --tv-surface-hi: #14303B;
  --tv-border: rgba(255, 255, 255, 0.11);
  --tv-ink: #F5F7F6;
  --tv-ink-muted: #98B1B8;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  color: var(--ink-primary);
  background-color: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.theme-app {
  background-image:
    radial-gradient(circle at 12% 0%, rgba(14, 124, 86, 0.08) 0%, transparent 42%),
    radial-gradient(circle at 92% 14%, rgba(217, 130, 11, 0.09) 0%, transparent 38%);
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  margin: 0;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

p {
  margin: 0;
  line-height: 1.5;
}

button, a, select, input, textarea {
  font-family: inherit;
}

button, a, label[for] {
  cursor: pointer;
}

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
}

/* Containers & Layout */
.app-shell {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

.admin-shell {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 16px 64px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink-primary);
}

.brand-badge {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: #0D2026;
  color: var(--amber-bright);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  line-height: 1.1;
}

.brand-sub {
  font-size: 12px;
  color: var(--ink-muted);
}

/* Cards */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card + .card {
  margin-top: 14px;
}

.card-dark {
  background: #0D2026;
  color: #F5F7F6;
  border-color: #1A3944;
}

.card-dark .muted {
  color: #9CB4BC;
}

.muted {
  color: var(--ink-muted);
  font-size: 14px;
}

/* Pills & Badges */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.pill-emerald { background: var(--emerald-soft); color: #095C3F; }
.pill-amber { background: var(--amber-soft); color: #925204; }
.pill-coral { background: var(--coral-soft); color: #A62B17; }
.pill-dark { background: #0D2026; color: #F5F7F6; }
.pill-neutral { background: var(--bg-muted); color: var(--ink-secondary); }

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: pulseDot 1.6s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.75); }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.14s ease, background-color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
  user-select: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--emerald);
  color: #FFFFFF;
}
.btn-primary:hover:not(:disabled) { background: var(--emerald-hover); }

.btn-amber {
  background: var(--amber);
  color: #FFFFFF;
}
.btn-amber:hover:not(:disabled) { background: #BA6D06; }

.btn-coral {
  background: var(--coral);
  color: #FFFFFF;
}
.btn-coral:hover:not(:disabled) { background: var(--coral-hover); }

.btn-dark {
  background: #0D2026;
  color: #FFFFFF;
}
.btn-dark:hover:not(:disabled) { background: #16333D; }

.btn-outline {
  background: var(--bg-surface);
  color: var(--ink-primary);
  border-color: var(--border-strong);
}
.btn-outline:hover:not(:disabled) { background: var(--bg-muted); }

.btn-ghost {
  background: transparent;
  color: var(--ink-secondary);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-muted); }

.btn-sm {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.btn-lg {
  min-height: 54px;
  padding: 14px 24px;
  font-size: 16px;
}

.btn-block {
  width: 100%;
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-secondary);
}

.input, .select {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: #FFFFFF;
  color: var(--ink-primary);
  font-size: 15px;
  transition: border-color 0.15s ease;
}

.input:focus, .select:focus {
  border-color: var(--emerald);
}

.code-input {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.25em;
  min-height: 60px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: #FAF8F2;
}

.toggle-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--emerald);
  cursor: pointer;
}

/* Avatars */
.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  background: #0D2026;
  color: var(--amber-bright);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  flex-shrink: 0;
  overflow: hidden;
  border: 2px solid var(--border-subtle);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-lg { width: 72px; height: 72px; font-size: 24px; }
.avatar-xl { width: 104px; height: 104px; font-size: 32px; }

/* Candidate voting cards (Mobile) */
.candidate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

@media (max-width: 360px) {
  .candidate-grid { grid-template-columns: 1fr; }
}

.candidate-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 16px 12px;
  background: var(--bg-surface);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  transition: transform 0.16s ease, border-color 0.16s ease, background-color 0.16s ease;
  cursor: pointer;
}

.candidate-card:hover {
  border-color: var(--emerald);
  transform: translateY(-2px);
}

.candidate-card.selected {
  border-color: var(--emerald);
  background: var(--emerald-soft);
}

.candidate-photo {
  width: 96px;
  height: 96px;
  border-radius: 14px;
  object-fit: cover;
  background: #0D2026;
  color: var(--amber-bright);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 28px;
  overflow: hidden;
  margin-bottom: 10px;
  border: 2px solid rgba(13, 32, 38, 0.1);
}

.candidate-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.candidate-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  color: var(--ink-primary);
  line-height: 1.2;
}

.candidate-nick {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 2px;
}

/* 10-Second Countdown Banner */
.countdown-panel {
  background: #0D2026;
  color: #FFFFFF;
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  text-align: center;
}

.countdown-ring {
  width: 112px;
  height: 112px;
  margin: 14px auto 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle, rgba(242, 92, 67, 0.25) 0%, rgba(242, 92, 67, 0.04) 70%);
  border: 4px solid var(--coral);
  font-family: var(--font-mono);
  font-size: 40px;
  font-weight: 700;
  color: #FFD7CE;
}

.progress-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(13, 32, 38, 0.12);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--emerald);
  border-radius: 999px;
  transition: width 0.35s ease;
}

/* Admin Tabs */
.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px;
  background: var(--bg-muted);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

.tab-btn {
  flex: 1;
  min-width: fit-content;
  padding: 10px 14px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-secondary);
  font-weight: 700;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab-btn.active {
  background: var(--bg-surface);
  color: var(--ink-primary);
  box-shadow: var(--shadow-sm);
}

/* Admin Grid */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 780px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.participant-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.participant-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: #FCFBF8;
}

.participant-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.participant-name-wrap {
  min-width: 0;
}

.participant-name {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Camera capture box */
.camera-stage {
  position: relative;
  width: 100%;
  max-width: 300px;
  aspect-ratio: 1 / 1;
  margin: 0 auto 12px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #0D2026;
  border: 2px solid var(--border-strong);
  display: grid;
  place-items: center;
  color: #9CB4BC;
}

.camera-stage video,
.camera-stage img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* QR Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(7, 20, 25, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.qr-box {
  background: #FFFFFF;
  border: 2px solid #0D2026;
  border-radius: var(--radius-md);
  padding: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 12px auto;
}

/* Candidate selector chips in Admin */
.pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.pick-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: #FFFFFF;
  cursor: pointer;
  transition: border-color 0.14s ease, background 0.14s ease;
  text-align: left;
}

.pick-card.picked {
  border-color: var(--emerald);
  background: var(--emerald-soft);
}

.pick-card.already-elected {
  opacity: 0.72;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 400px);
  pointer-events: none;
}

.toast {
  background: #0D2026;
  color: #FFFFFF;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
  animation: toastIn 0.22s ease;
}

.toast-error { background: var(--coral); }
.toast-success { background: var(--emerald); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   TELÃO / TV BROADCAST MODE (/telao)
   ========================================================================== */
body.theme-tv {
  background-color: var(--tv-bg);
  color: var(--tv-ink);
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 18% 12%, rgba(28, 212, 142, 0.14) 0%, transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(251, 191, 36, 0.14) 0%, transparent 48%);
  overflow-x: hidden;
}

.tv-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: clamp(16px, 2.5vw, 36px);
  max-width: 1680px;
  margin: 0 auto;
  position: relative;
}

.tv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--tv-border);
  margin-bottom: clamp(18px, 2.5vw, 32px);
}

.tv-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.tv-logo {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--emerald);
  color: #FFFFFF;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
  box-shadow: 0 0 28px rgba(28, 212, 142, 0.25);
}

.tv-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.tv-footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--tv-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--tv-ink-muted);
  font-size: 14px;
}

/* TV Lobby Mosaic */
.tv-mosaic {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 14px;
  margin-top: 24px;
}

.tv-person-tile {
  background: var(--tv-surface);
  border: 1px solid var(--tv-border);
  border-radius: 14px;
  padding: 10px;
  text-align: center;
  animation: tilePop 0.35s ease backwards;
}

@keyframes tilePop {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

.tv-person-photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  background: #14303B;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 800;
  color: var(--amber-bright);
  margin-bottom: 8px;
}

.tv-person-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* TV Candidates Showcase */
.tv-candidates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 280px));
  justify-content: center;
  gap: 24px;
  margin-top: 28px;
}

.tv-cand-card {
  background: var(--tv-surface);
  border: 2px solid var(--tv-border);
  border-radius: 16px;
  padding: 18px;
  text-align: center;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.tv-cand-photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  background: #14303B;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 54px;
  font-weight: 800;
  color: var(--amber-bright);
  margin-bottom: 14px;
}

.tv-cand-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* TV Roulette Stage */
.roulette-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px 0;
}

.roulette-spotlight {
  position: relative;
  width: min(76vw, 340px);
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  overflow: hidden;
  border: 5px solid var(--amber-bright);
  background: var(--tv-surface-hi);
  box-shadow: 0 0 60px rgba(251, 191, 36, 0.28);
  display: grid;
  place-items: center;
  transition: transform 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
}

.roulette-spotlight.winner-locked {
  border-color: var(--emerald-bright);
  box-shadow: 0 0 90px rgba(28, 212, 142, 0.45);
  transform: scale(1.06);
}

.roulette-spotlight.alert-locked {
  border-color: var(--coral);
  box-shadow: 0 0 70px rgba(217, 67, 43, 0.4);
}

.roulette-spotlight img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.roulette-initials {
  font-family: var(--font-display);
  font-size: 96px;
  font-weight: 800;
  color: var(--amber-bright);
}

.roulette-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
}

.roulette-thumb {
  width: 72px;
  height: 72px;
  border-radius: 12px;
  overflow: hidden;
  border: 3px solid transparent;
  opacity: 0.42;
  transform: scale(0.92);
  transition: transform 0.08s ease, opacity 0.08s ease, border-color 0.08s ease;
  background: var(--tv-surface-hi);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--amber-bright);
}

.roulette-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.roulette-thumb.active {
  opacity: 1;
  transform: scale(1.14);
  border-color: var(--amber-bright);
  box-shadow: 0 0 24px rgba(251, 191, 36, 0.5);
}

/* Scoreboard on TV */
.tv-scoreboard {
  width: 100%;
  max-width: 960px;
  margin: 24px auto 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tv-score-row {
  display: grid;
  grid-template-columns: 60px 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-radius: 14px;
  background: var(--tv-surface);
  border: 1.5px solid var(--tv-border);
}

.tv-score-row.is-winner {
  border-color: var(--emerald-bright);
  background: rgba(28, 212, 142, 0.12);
}

.tv-score-bar-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  margin-top: 8px;
}

.tv-score-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--amber-bright);
}

.tv-score-row.is-winner .tv-score-bar-fill {
  background: var(--emerald-bright);
}

/* Confetti Canvas */
#confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 900;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Print Styles for Ata */
@media print {
  body { background: #FFFFFF !important; color: #000000 !important; }
  .no-print { display: none !important; }
  .card { box-shadow: none !important; border: 1px solid #CCC !important; break-inside: avoid; }
}
