/* ===== Reset & Base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --red:        #d62828;
  --red-dark:   #a31f1f;
  --navy:       #1a1f2c;
  --ink:        #1a1f2c;
  --gray-600:   #5b6470;
  --gray-300:   #c8cdd5;
  --gray-100:   #f0f2f5;
  --bg:         #f2f4f7;
  --white:      #ffffff;
  --green:      #1a7a4a;
  --green-bg:   #dcf5e8;
  --whatsapp:   #25d366;
  --whatsapp-d: #128c7e;
  --radius-lg:  20px;
  --radius-md:  12px;
  --shadow:     0 12px 40px rgba(26,31,44,0.12);
  --shadow-sm:  0 4px 16px rgba(26,31,44,0.08);
}

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button, a { font-family: inherit; }
a         { text-decoration: none; color: inherit; }

/* ===== Header ===== */
.header {
  background: var(--white);
  border-bottom: 4px solid var(--red);
  padding: 12px 20px;
  flex-shrink: 0;
}
.header__inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
.header__logo-img {
  height: 56px;
  width: auto;
  display: block;
  flex-shrink: 0;
}
.header__brand {
  border-left: 2px solid var(--gray-300);
  padding-left: 18px;
}
.header__logo {
  display: block;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--navy);
  line-height: 1.2;
}
.header__logo strong { color: var(--red); }
.header__tag {
  display: block;
  font-size: 11px;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 3px;
}

/* ===== Main ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 24px;
  gap: 20px;
}

/* ===== Editor de premios inline ===== */
.pep-panel {
  width: 100%;
  max-width: 440px;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px 22px 24px;
  text-align: left;
  margin-bottom: 4px;
}
.pep-panel[hidden] { display: none; }

.pep-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--gray-100);
}
.pep-header h3 { font-size: 15px; font-weight: 800; color: var(--navy); }

.pep-close-btn {
  background: none; border: none; cursor: pointer;
  font-size: 12.5px; font-weight: 600;
  color: var(--gray-600); padding: 5px 10px; border-radius: 8px;
  transition: background .15s, color .15s;
}
.pep-close-btn:hover { background: var(--gray-100); color: var(--navy); }

.pep-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1.5px solid var(--gray-100);
  border-radius: var(--radius-md); margin-bottom: 8px;
  transition: border-color .15s;
}
.pep-card:hover { border-color: var(--gray-300); }

.pep-swatch {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0; box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.pep-info  { flex: 1; min-width: 0; }
.pep-name  { font-size: 13.5px; font-weight: 700; color: var(--navy); }
.pep-lbl   { font-size: 12px; color: var(--gray-600); }
.pep-lbl strong { color: var(--navy); }
.pep-btns-row { display: flex; gap: 5px; }
.pep-btns-row .btn--sm { padding: 4px 9px; min-height: 28px; font-size: 11.5px; }

.pep-form {
  margin-top: 16px; padding: 15px;
  background: var(--gray-100); border-radius: var(--radius-md);
}
.pep-form h4 { font-size: 13.5px; font-weight: 800; color: var(--navy); margin-bottom: 10px; }

.pep-preview-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.pep-preview {
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0; background: var(--gray-300);
  box-shadow: 0 2px 8px rgba(0,0,0,.12); transition: background .2s;
}
.pep-preview-lbl { font-size: 12.5px; color: var(--gray-600); font-weight: 600; }

.pep-grid {
  display: grid; grid-template-columns: 90px 1fr;
  gap: 8px; margin-bottom: 10px;
}
.pep-wide { grid-column: 1 / -1; }

.pep-field label {
  display: block; font-size: 12px; font-weight: 600; color: var(--navy); margin-bottom: 3px;
}
.pep-field label small { font-weight: 400; color: var(--gray-600); }

.pep-field input[type="text"] {
  width: 100%; min-height: 38px; padding: 8px 11px; font-size: 14px;
  border: 2px solid var(--gray-300); border-radius: 9px;
  background: var(--white); color: var(--ink); transition: border-color .15s;
  -webkit-appearance: none;
}
.pep-field input[type="text"]:focus {
  outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(214,40,40,.10);
}
.pep-field input[type="color"] {
  width: 100%; height: 38px; padding: 3px;
  border: 2px solid var(--gray-300); border-radius: 9px;
  background: var(--white); cursor: pointer;
}
.pep-error {
  font-size: 12.5px; color: var(--red-dark); background: #fff5f5;
  border-radius: 8px; padding: 6px 10px; margin-bottom: 8px;
}
.pep-btns { display: flex; gap: 8px; }

/* ===== Card ===== */
.card {
  width: 100%;
  max-width: 440px;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px 28px 28px;
}

.card__icon-wrap { text-align: center; margin-bottom: 12px; }
.card__big-icon  { font-size: 48px; line-height: 1; }

.card h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--navy);
  margin-bottom: 8px;
  line-height: 1.25;
}
.subtitle {
  color: var(--gray-600);
  font-size: 14.5px;
  margin-bottom: 24px;
  line-height: 1.5;
}

/* ===== Form fields ===== */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  min-height: 52px;
  padding: 13px 16px;
  font-size: 16px;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius-md);
  background: var(--gray-100);
  color: var(--ink);
  transition: border-color .18s, background .18s, box-shadow .18s;
  -webkit-appearance: none;
}
.field input:focus {
  outline: none;
  border-color: var(--red);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(214,40,40,.12);
}
.field input.invalid {
  border-color: var(--red-dark);
  background: #fff5f5;
}
.field__error {
  display: block;
  min-height: 18px;
  font-size: 12.5px;
  color: var(--red-dark);
  margin-top: 4px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 13px 22px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 15.5px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: background .18s, transform .12s, box-shadow .18s;
  -webkit-tap-highlight-color: transparent;
}
.btn--full    { width: 100%; }
.btn--sm      { min-height: 38px; font-size: 13px; padding: 7px 16px; }

.btn--primary { background: var(--red); color: var(--white); }
.btn--primary:hover  { background: var(--red-dark); }
.btn--primary:active { transform: scale(.97); }

.btn--whatsapp { background: var(--whatsapp); color: var(--white); }
.btn--whatsapp:hover  { background: var(--whatsapp-d); }
.btn--whatsapp:active { transform: scale(.97); }

.btn--ghost {
  background: var(--white);
  color: var(--navy);
  border-color: var(--gray-300);
}
.btn--ghost:hover  { border-color: var(--navy); }

.btn--danger {
  background: var(--white);
  color: var(--red-dark);
  border-color: var(--gray-300);
}
.btn--danger:hover { border-color: var(--red-dark); }

.link-btn {
  background: none;
  border: none;
  color: var(--gray-600);
  font-size: 13.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 6px 0;
  display: block;
  margin: 12px auto 0;
  text-align: center;
  width: fit-content;
}
.link-btn:hover { color: var(--navy); }

/* Spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Badges ===== */
.badge {
  display: inline-block;
  font-size: 12.5px;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 50px;
  margin-bottom: 14px;
}
.badge--green { background: var(--green-bg); color: var(--green); }

/* ===== Comprobante ===== */
.card--success { text-align: center; }
.card--success h2 {
  font-size: 21px;
  font-weight: 800;
  color: var(--navy);
  margin-bottom: 6px;
}

.ticket {
  background: var(--gray-100);
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-md);
  padding: 20px 16px 14px;
  margin: 18px 0 22px;
}
.ticket__code {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--red);
  line-height: 1;
  margin-bottom: 8px;
}
.ticket__hint {
  font-size: 12px;
  color: var(--gray-600);
}

.action-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 4px;
}

/* Indicador de sincronización */
.sync-status {
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 8px;
  margin: 10px 0 14px;
  text-align: center;
}
.sync-status--ok   { background: var(--green-bg); color: var(--green); }
.sync-status--warn { background: #fff8e1; color: #7a5900; }

/* ===== Cuenta regresiva ===== */
.countdown-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  background: rgba(255,255,255,0.25);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 800;
  margin-left: 6px;
}

/* ===== Ruleta ===== */
.card--ruleta { text-align: center; max-width: 500px; padding-left: 20px; padding-right: 20px; }
.card--ruleta h2 {
  font-size: 22px;
  font-weight: 800;
  color: var(--navy);
  margin-bottom: 6px;
}

.wheel-wrap {
  position: relative;
  display: inline-block;
  margin: 20px auto 22px;
}
.wheel-pointer {
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left:  14px solid transparent;
  border-right: 14px solid transparent;
  border-top:   26px solid var(--red);
  z-index: 2;
  filter: drop-shadow(0 2px 4px rgba(214,40,40,.4));
}

#wheelCanvas {
  display: block;
  border-radius: 50%;
  box-shadow: var(--shadow);
}

/* ===== Modal premio ===== */
.premio-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16,18,28,.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.premio-overlay[hidden] { display: none; }

.premio-modal {
  position: relative;
  background: var(--white);
  border-radius: 28px;
  padding: 40px 32px 32px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  overflow: hidden;
  animation: popIn .45s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes popIn {
  from { opacity:0; transform: scale(.7); }
  to   { opacity:1; transform: scale(1); }
}

.premio-emoji {
  font-size: 80px;
  line-height: 1;
  margin-bottom: 14px;
  animation: float 1.4s ease-in-out infinite alternate;
}
@keyframes float {
  from { transform: translateY(0); }
  to   { transform: translateY(-12px); }
}

.premio-modal h2 {
  font-size: 26px;
  font-weight: 800;
  color: var(--navy);
  margin-bottom: 4px;
}
.premio-modal p { color: var(--gray-600); font-size: 14px; margin-bottom: 4px; }
.premio-nombre {
  font-size: 26px;
  font-weight: 900;
  color: var(--red);
  margin: 8px 0 18px;
  line-height: 1.2;
}
.hint {
  font-size: 13px;
  color: var(--gray-600);
  margin-bottom: 16px;
  line-height: 1.5;
}

.premio-modal .btn { margin-top: 10px; }

/* Confetti burst */
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti-piece {
  position: absolute;
  width: 8px;
  height: 12px;
  opacity: 0;
  animation: confettiFall 1.8s ease-out forwards;
}
@keyframes confettiFall {
  0%   { opacity:1; transform: translateY(-20px) rotate(0deg); }
  100% { opacity:0; transform: translateY(320px) rotate(720deg); }
}

/* ===== Login de inicio ===== */
.card--login { text-align: center; }
.card--login h1 { text-align: left; }
.card--login .subtitle { text-align: left; }

.login-error {
  font-size: 13px;
  color: var(--red-dark);
  background: #fff5f5;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 14px;
  text-align: left;
}

/* ===== FAB botón organizador (✏ siempre visible tras login) ===== */
.fab-premios {
  position: fixed;
  bottom: 22px;
  right: 22px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--white);
  border: none;
  font-size: 18px;
  cursor: pointer;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(26,31,44,.35);
  transition: background .18s, transform .12s;
  -webkit-tap-highlight-color: transparent;
}
.fab-premios[hidden] { display: none; }
.fab-premios:hover  { background: var(--red); }
.fab-premios:active { transform: scale(.93); }

/* ===== Overlay de autenticación ===== */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16,18,28,.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.auth-overlay[hidden] { display: none; }

.auth-modal {
  background: var(--white);
  border-radius: 20px;
  padding: 32px 28px 28px;
  max-width: 340px;
  width: 100%;
  animation: popIn .35s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.auth-modal h3 { font-size: 18px; font-weight: 800; color: var(--navy); margin-bottom: 4px; }
.auth-modal > p { font-size: 13.5px; color: var(--gray-600); margin-bottom: 20px; }

.auth-field { margin-bottom: 14px; }
.auth-field label {
  display: block; font-size: 12.5px; font-weight: 600; color: var(--navy); margin-bottom: 5px;
}
.auth-field input {
  width: 100%; min-height: 46px; padding: 11px 14px; font-size: 15px;
  border: 2px solid var(--gray-300); border-radius: 10px;
  background: var(--gray-100); color: var(--ink); transition: border-color .15s;
  -webkit-appearance: none;
}
.auth-field input:focus {
  outline: none; border-color: var(--red); background: var(--white);
  box-shadow: 0 0 0 3px rgba(214,40,40,.12);
}
.auth-error {
  font-size: 13px; color: var(--red-dark); background: #fff5f5;
  border-radius: 8px; padding: 8px 12px; margin-bottom: 14px;
}
.auth-btns { display: flex; gap: 10px; margin-top: 16px; }
.auth-btns .btn { flex: 1; }

/* ===== Overlay editor de premios ===== */
.premios-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16,18,28,.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 250;
  padding: 16px;
  backdrop-filter: blur(4px);
}
.premios-overlay[hidden] { display: none; }

.premios-modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: popIn .35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.premios-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1.5px solid var(--gray-100);
  flex-shrink: 0;
}
.premios-hdr h3 { font-size: 16px; font-weight: 800; color: var(--navy); }

.btn-premios-close {
  background: none; border: none; cursor: pointer; font-size: 18px;
  color: var(--gray-600); padding: 4px 8px; border-radius: 8px;
  transition: background .15s, color .15s; line-height: 1;
}
.btn-premios-close:hover { background: var(--gray-100); color: var(--navy); }

.premios-body { flex: 1; overflow-y: auto; padding: 14px 18px; }
.premios-form {
  padding: 14px 18px 18px;
  border-top: 1.5px solid var(--gray-100);
  flex-shrink: 0;
  overflow-y: auto;
  max-height: 55dvh;
}

/* Tarjetas de premio en el editor */
.pe-card {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border: 1.5px solid var(--gray-100);
  border-radius: var(--radius-md); background: var(--white);
  margin-bottom: 8px; transition: border-color .15s;
}
.pe-card:hover { border-color: var(--gray-300); }
.pe-swatch {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0; box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.pe-info { flex: 1; min-width: 0; }
.pe-name  { font-size: 14px; font-weight: 700; color: var(--navy); }
.pe-label { font-size: 12px; color: var(--gray-600); }
.pe-label strong { color: var(--navy); }
.pe-btns { display: flex; gap: 6px; }
.pe-btns .btn--sm { padding: 5px 10px; min-height: 30px; font-size: 12px; }

/* Formulario de premio inline */
.premios-form h4 { font-size: 14px; font-weight: 800; color: var(--navy); margin-bottom: 12px; }
.pef-preview-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.pef-preview {
  width: 50px; height: 50px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; flex-shrink: 0; box-shadow: 0 3px 10px rgba(0,0,0,.15);
  transition: background .2s; background: var(--gray-300);
}
.pef-preview-lbl { font-size: 13px; color: var(--gray-600); font-weight: 600; }

.pef-grid {
  display: grid; grid-template-columns: 100px 1fr;
  gap: 10px; margin-bottom: 10px;
}
.pef-wide { grid-column: 1 / -1; }
.pef-field label {
  display: block; font-size: 12px; font-weight: 600; color: var(--navy); margin-bottom: 4px;
}
.pef-field label small { font-weight: 400; color: var(--gray-600); }
.pef-field input[type="text"] {
  width: 100%; min-height: 40px; padding: 9px 12px; font-size: 14px;
  border: 2px solid var(--gray-300); border-radius: 10px;
  background: var(--white); color: var(--ink); transition: border-color .15s;
  -webkit-appearance: none;
}
.pef-field input[type="text"]:focus {
  outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(214,40,40,.12);
}
.pef-field input[type="color"] {
  width: 100%; height: 40px; padding: 3px;
  border: 2px solid var(--gray-300); border-radius: 10px;
  background: var(--white); cursor: pointer;
}
.pef-error {
  font-size: 12.5px; color: var(--red-dark); background: #fff5f5;
  border-radius: 8px; padding: 7px 12px; margin-bottom: 10px;
}
.pef-btns { display: flex; gap: 8px; }

/* ===== Panel (shared: used in panel.html) ===== */
.panel {
  max-width: 900px;
  margin: 14px auto 0;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  text-align: left;
}
.panel__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panel__head h3 { font-size: 15px; font-weight: 700; color: var(--navy); }
.panel__actions { display: flex; gap: 8px; }
.panel__tableWrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.panel__table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.panel__table th,
.panel__table td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--gray-100);
  white-space: nowrap;
}
.panel__table th  { color: var(--gray-600); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.panel__table tr:last-child td { border-bottom: none; }
.panel__empty td  { text-align: center; color: var(--gray-600); padding: 24px; white-space: normal; }
.panel__note      { font-size: 12px; color: var(--gray-600); margin-top: 10px; }

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .card { padding: 26px 18px 22px; }
  .ticket__code { font-size: 23px; letter-spacing: 1.5px; }
  .panel__head  { flex-direction: column; align-items: stretch; }
  .panel__actions .btn { flex: 1; }
}
@media (max-width: 360px) {
  .card__big-icon { font-size: 38px; }
  .card h1 { font-size: 19px; }
  .pep-grid { grid-template-columns: 1fr; }
  .pep-wide { grid-column: auto; }
}
