/* ==========================================================================
   QUIOSQUE DE SORTEIO — DESIGN SYSTEM & ESTILOS GERAIS
   Conforme especificações da Seção 5 de plano-arquitetura-quiosque.md
   ========================================================================== */

:root {
  --xfade: 350ms;
  --font-display: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  /* Cores e Gradientes */
  --color-bg: #000000;
  --color-surface: rgba(18, 22, 34, 0.85);
  --color-surface-border: rgba(255, 255, 255, 0.14);
  --color-primary: #f59e0b;
  --color-primary-glow: rgba(245, 158, 11, 0.45);
  --color-text-main: #ffffff;
  --color-text-sub: rgba(255, 255, 255, 0.75);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--color-bg);
  overflow: hidden;
  font-family: var(--font-body);
  color: var(--color-text-main);
  
  /* Endurecimento tátil para TV Touchscreen (Anti-gesto) */
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: none; /* Oculta cursor em tela quiosque */
}

/* Permitir cursor caso necessário em desenvolvimento através de classe */
body.dev-mode {
  cursor: default;
}

/* Palco fixo em tela cheia */
#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
  overflow: hidden;
}

/* ==========================================================================
   CAMADAS DE VÍDEO (Seções 1, 3 e 5)
   ========================================================================== */

video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

/* Camada 1: Idle — Sempre rodando no fundo */
#vIdle {
  z-index: 1;
}

/* Camada 2: Resultado (prêmio) — Fade-in sobre o Idle */
#vResult {
  z-index: 2;
  opacity: 0;
  transition: opacity var(--xfade, 350ms) cubic-bezier(0.4, 0, 0.2, 1);
  will-change: opacity;
}

#vResult.on {
  opacity: 1;
}

/* Camada 3: Flash de Transição (Máscara de luz para disfarçar cortes) */
#flash {
  position: absolute;
  inset: 0;
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
  z-index: 3;
}

#flash.pulse {
  animation: flash-anim 450ms ease-out forwards;
}

#flash.soft {
  animation-duration: 300ms;
  filter: opacity(0.5);
}

@keyframes flash-anim {
  0% {
    opacity: 0;
  }
  25% {
    opacity: 0.65;
  }
  100% {
    opacity: 0;
  }
}

/* ==========================================================================
   CAMADA 4: OVERLAYS DE UI (CTA, Card de Prêmio e Indicadores)
   ========================================================================== */

/* Botão Táctil Principal — "Toque para Girar" */
.cta {
  position: absolute;
  left: 50%;
  bottom: 13%; /* Ergonomia de toque na TV vertical (9:16) */
  transform: translateX(-50%) translateY(0);
  min-width: 420px;
  min-height: 124px;
  padding: 0 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  
  font-family: var(--font-display);
  font-size: 42px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #0b0f19;
  
  background: linear-gradient(135deg, #fcd34d 0%, #f59e0b 50%, #d97706 100%);
  border: 4px solid rgba(255, 255, 255, 0.6);
  border-radius: 64px;
  box-shadow: 
    0 12px 32px rgba(0, 0, 0, 0.5),
    0 0 50px var(--color-primary-glow),
    inset 0 2px 4px rgba(255, 255, 255, 0.7);
  
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease;
  z-index: 4;
  cursor: pointer;
}

/* Estado Visível e Ativo (Exclusivo para o estado IDLE) */
.cta.visible {
  opacity: 1;
  pointer-events: auto;
}

/* Efeito ao pressionar botão táctil */
.cta:active {
  transform: translateX(-50%) scale(0.96);
  box-shadow: 
    0 4px 16px rgba(0, 0, 0, 0.6),
    0 0 30px var(--color-primary-glow);
}

.cta-icon {
  font-size: 44px;
  line-height: 1;
}

.cta-text {
  text-transform: uppercase;
  font-size: 38px;
  font-weight: 800;
}

/* Pulso animado ao redor do botão no estado IDLE para atrair participante */
.cta-pulse {
  position: absolute;
  inset: -12px;
  border-radius: 76px;
  border: 3px solid rgba(245, 158, 11, 0.65);
  animation: cta-pulse-ring 2.4s cubic-bezier(0.24, 0, 0.38, 1) infinite;
  pointer-events: none;
}

@keyframes cta-pulse-ring {
  0% {
    transform: scale(0.96);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.06);
    opacity: 0.2;
  }
  100% {
    transform: scale(0.96);
    opacity: 0.8;
  }
}

/* Card HTML de Apresentação do Produto Sorteado (Reveal Overlay) */
.card {
  position: absolute;
  left: 50%;
  top: 10%;
  transform: translateX(-50%) translateY(-30px);
  min-width: 520px;
  max-width: min(80vw, calc(100vw - 96px)); /* Safe area lateral de 48px por lado */
  overflow-wrap: anywhere;
  padding: 28px 48px;
  
  background: var(--color-surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 2px solid var(--color-surface-border);
  border-radius: 28px;
  box-shadow: 
    0 24px 60px rgba(0, 0, 0, 0.7),
    0 0 40px rgba(245, 158, 11, 0.25);
  
  text-align: center;
  font-family: var(--font-display);
  font-size: 56px;
  font-weight: 800;
  color: #ffffff;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
  
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 4;
}

.card.on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==========================================================================
   TELA DE CARREGAMENTO INICIAL (#loading)
   ========================================================================== */

.loading {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at center, #1a2030 0%, #090b10 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99;
  transition: opacity 0.5s ease;
}

.loading.loaded {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.loading-spinner {
  width: 72px;
  height: 72px;
  border: 6px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spinner-rot 1s cubic-bezier(0.6, 0.2, 0.4, 0.8) infinite;
}

@keyframes spinner-rot {
  to {
    transform: rotate(360deg);
  }
}

.loading-title {
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #ffffff;
}

.loading-status {
  font-family: var(--font-body);
  font-size: 20px;
  font-weight: 500;
  color: var(--color-text-sub);
}

/* ==========================================================================
   PAINEL DO OPERADOR & ESTADO DE ESTOQUE ESGOTADO
   ========================================================================== */

.hidden {
  display: none !important;
}

/* Modal de Teclado Numérico para Acesso com PIN */
.operator-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  animation: op-fade-in 0.25s ease;
  cursor: default !important;
}

@keyframes op-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.operator-pin-card {
  background: #0f1422;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 32px;
  padding: 36px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: 
    0 24px 60px rgba(0, 0, 0, 0.9),
    0 0 50px rgba(245, 158, 11, 0.25);
  text-align: center;
  color: #fff;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.operator-pin-card.shake {
  animation: pin-shake 0.45s ease;
  border-color: #ef4444;
}

@keyframes pin-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-14px); }
  40%, 80% { transform: translateX(14px); }
}

.pin-icon {
  font-size: 38px;
  margin-bottom: 8px;
}

.pin-card-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #ffffff;
}

.pin-card-subtitle {
  font-size: 14px;
  color: var(--color-text-sub);
  margin-top: 4px;
}

.pin-display-container {
  margin: 24px 0 16px;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.pin-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.pin-dot.filled {
  background: var(--color-primary);
  border-color: var(--color-primary);
  box-shadow: 0 0 14px var(--color-primary-glow);
  transform: scale(1.15);
}

.pin-error-message {
  color: #f87171;
  font-size: 14px;
  font-weight: 600;
  margin-top: 10px;
  min-height: 20px;
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.pin-key {
  height: 64px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-key:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
}

.pin-key:active {
  background: var(--color-primary);
  color: #0b0f19;
  transform: scale(0.95);
}

.pin-key-action {
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-body);
}

.pin-cancel {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.pin-cancel:hover {
  background: rgba(239, 68, 68, 0.25);
}

.pin-backspace {
  font-size: 24px;
  color: #fbbf24;
}

/* Painel Administrativo Principal do Operador */
.operator-panel {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 24, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 100;
  color: #ffffff;
  padding: 36px 44px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  cursor: default !important;
}

.operator-layout {
  display: flex;
  flex-direction: column;
  gap: 28px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* Cabeçalho do Operador */
.operator-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  padding-bottom: 20px;
  flex-wrap: wrap;
  gap: 16px;
}

.operator-badge {
  display: inline-block;
  background: rgba(245, 158, 11, 0.2);
  border: 1px solid var(--color-primary);
  color: var(--color-primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: 6px;
  margin-bottom: 6px;
}

.operator-title {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.operator-subtitle {
  font-size: 15px;
  color: var(--color-text-sub);
}

.operator-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.status-chip {
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-indicator-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.chip-ok {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: #34d399;
}
.chip-ok .status-indicator-dot {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.chip-degraded {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #f87171;
}
.chip-degraded .status-indicator-dot {
  background: #ef4444;
  box-shadow: 0 0 8px #ef4444;
  animation: cta-pulse-ring 1.5s infinite;
}

.chip-state {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #e2e8f0;
}

.btn-operator-close {
  padding: 10px 22px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-operator-close:hover {
  background: rgba(239, 68, 68, 0.3);
  border-color: #ef4444;
}

/* Alertas de Estoque Zerado (Aviso Discreto para Operador) */
.operator-alerts-section {
  width: 100%;
}

.depleted-alert-card {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  background: rgba(239, 68, 68, 0.12);
  border: 2px solid rgba(239, 68, 68, 0.4);
  border-radius: 18px;
  padding: 18px 24px;
}

.depleted-alert-card .alert-icon {
  font-size: 28px;
  line-height: 1;
}

.depleted-alert-card .alert-title {
  font-size: 17px;
  font-weight: 800;
  color: #fca5a5;
  margin-bottom: 4px;
}

.depleted-alert-card .alert-desc {
  font-size: 14px;
  color: #e2e8f0;
  margin-bottom: 10px;
}

.depleted-tag-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.depleted-tag {
  background: #ef4444;
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 8px;
  text-transform: uppercase;
}

.healthy-status-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 14px;
  padding: 14px 20px;
  color: #6ee7b7;
  font-size: 14px;
  font-weight: 500;
}

.healthy-icon {
  font-size: 18px;
  font-weight: 800;
  color: #10b981;
}

/* Cards de Métricas */
.operator-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}

.metric-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-sub);
  margin-bottom: 8px;
}

.metric-value {
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.1;
}

.metric-total {
  font-size: 20px;
  color: var(--color-text-sub);
  font-weight: 500;
}

.metric-footnote {
  font-size: 13px;
  color: var(--color-text-sub);
  margin-top: 8px;
}

.text-danger {
  color: #ef4444 !important;
}

/* Grade de Produtos */
.operator-products-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.products-stock-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

.product-stock-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.product-stock-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.25);
}

.product-stock-card.card-depleted {
  border-color: rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.08);
}

.product-stock-card.card-low {
  border-color: rgba(245, 158, 11, 0.4);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.product-id-tag {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-primary);
  background: rgba(245, 158, 11, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
}

.product-card-name {
  font-size: 17px;
  font-weight: 700;
  margin-top: 4px;
}

.stock-badge {
  font-size: 11px;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 6px;
}

.badge-ok {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}
.badge-low {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
}
.badge-zero {
  background: rgba(239, 68, 68, 0.3);
  color: #f87171;
}

.stock-numbers {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 6px;
}

.current-stock {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 800;
}

.init-stock {
  font-size: 14px;
  color: var(--color-text-sub);
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.3s ease;
}

.fill-ok {
  background: #10b981;
}
.fill-low {
  background: #f59e0b;
}
.fill-zero {
  background: #ef4444;
}

/* Barra de Ações Administrativas */
.operator-actions-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)); /* Grade 2x2 para largura de 1080px */
  gap: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 24px;
  margin-top: auto;
}

.btn-op {
  width: 100%;
  min-width: 0;
  min-height: 64px;
  border-radius: 16px;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid transparent;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

.btn-op:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.btn-op:active {
  transform: scale(0.97);
}

.btn-op-danger {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}
.btn-op-danger:hover {
  background: #ef4444;
  color: #ffffff;
}

.btn-op-export {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.4);
  color: #93c5fd;
}
.btn-op-export:hover {
  background: #3b82f6;
  color: #ffffff;
}


.btn-op-restock {
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}
.btn-op-restock:hover {
  background: #10b981;
  color: #ffffff;
}

/* Estado de Todos os Produtos Esgotados (OUT_OF_STOCK_ALERT) */
body.all-out::after {
  content: "O sorteio de hoje está encerrado! Obrigado pela participação.";
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(80%, calc(100vw - 96px)); /* Safe area lateral de 48px por lado */
  max-width: 800px;
  padding: 48px;
  background: rgba(18, 22, 34, 0.9);
  backdrop-filter: blur(24px);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 32px;
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(32px, 4vw, 44px);
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
  color: #ffffff;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
  z-index: 50;
  pointer-events: none;
}
