/* =============================================
   NovoMier Rifa App — Design System
   Mobile-first · WCAG 2.1 AA
   ============================================= */

:root {
  /* Brand */
  --color-brand:         #3730A3;
  --color-brand-hover:   #4F46E5;
  --color-brand-active:  #312E81;
  --color-accent:        #D97706;

  /* Tablero estados */
  --color-libre-bg:      #DCFCE7;
  --color-libre-text:    #15803D;
  --color-libre-border:  #86EFAC;
  --color-sold-bg:       #FEE2E2;
  --color-sold-text:     #B91C1C;
  --color-sold-border:   #FCA5A5;

  /* Selección de número (formulario de venta) */
  --color-sel-bg:        #3730A3;
  --color-sel-text:      #FFFFFF;
  --color-sel-border:    #312E81;

  /* Neutros */
  --color-bg:            #F3F4F6;
  --color-surface:       #FFFFFF;
  --color-border:        #E5E7EB;
  --color-text:          #111827;
  --color-text-muted:    #6B7280;

  /* Mensajes */
  --color-ok-bg:         #F0FDF4;
  --color-ok-text:       #15803D;
  --color-ok-border:     #16A34A;
  --color-err-bg:        #FFF1F2;
  --color-err-text:      #BE123C;
  --color-err-border:    #E11D48;
  --color-info-bg:       #EFF6FF;
  --color-info-text:     #1D4ED8;
  --color-info-border:   #3B82F6;

  /* Tipografía */
  --font-sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', monospace;

  /* Espaciado */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px;
  --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;

  /* Radios */
  --r-sm:   6px;
  --r-md:   8px;
  --r-lg:   12px;
  --r-card: 16px;

  /* Sombras */
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
}

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

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

body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
}

/* ─── NAV ────────────────────────────────────── */
.nav {
  background: var(--color-brand);
  color: #fff;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-4);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.nav-brand {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.nav-brand .nav-emoji { font-size: 1.3rem; }

.nav-user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: .875rem;
}

.nav-user a {
  color: #C7D2FE;
  text-decoration: none;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r-sm);
  transition: background .15s;
}
.nav-user a:hover { background: rgba(255,255,255,.15); color: #fff; }

.nav-admin-badge {
  background: var(--color-accent);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  letter-spacing: .03em;
  text-transform: uppercase;
}

/* ─── MAIN ───────────────────────────────────── */
main {
  max-width: 1140px;
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-4);
  /* Evita que barras fijas (leyenda, venta-action) tapen el contenido inferior */
  padding-bottom: calc(var(--sp-5) + 80px);
}

h1 { font-size: 1.75rem; font-weight: 800; line-height: 1.2; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1rem;    font-weight: 600; margin: var(--sp-5) 0 var(--sp-2); }

/* ─── LOGIN ──────────────────────────────────── */
.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100dvh;
  padding: var(--sp-4);
  background: linear-gradient(135deg, #EEF2FF 0%, #F3F4F6 60%, #FEF3C7 100%);
}

.login-card {
  background: var(--color-surface);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(0,0,0,.04);
  padding: var(--sp-8);
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  margin-bottom: var(--sp-6);
}
.login-logo .emoji { font-size: 3rem; line-height: 1; display: block; margin-bottom: var(--sp-3); }
.login-logo h1 { font-size: 1.4rem; color: var(--color-brand); }
.login-logo p  { color: var(--color-text-muted); font-size: .875rem; margin-top: var(--sp-1); }

/* ─── FORMS ──────────────────────────────────── */
.form-stack { display: flex; flex-direction: column; gap: var(--sp-4); }

.field { display: flex; flex-direction: column; gap: var(--sp-1); }
.field label { font-weight: 600; font-size: .9rem; color: var(--color-text); }

input[type=text],
input[type=password],
input[type=tel],
input[type=date] {
  border: 1.5px solid var(--color-border);
  border-radius: var(--r-md);
  padding: .65rem .875rem;
  font-size: 1rem;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
input:focus {
  outline: none;
  border-color: var(--color-brand-hover);
  box-shadow: 0 0 0 3px rgba(79,70,229,.18);
}
input::placeholder { color: var(--color-text-muted); }

/* ─── BOTONES ────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  background: var(--color-brand);
  color: #fff;
  border: none;
  border-radius: var(--r-md);
  padding: .7rem 1.4rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, transform .1s;
  min-height: 44px;
  white-space: nowrap;
}
.btn:hover  { background: var(--color-brand-hover); }
.btn:active { background: var(--color-brand-active); transform: translateY(1px); }

.btn-secondary {
  background: transparent;
  color: var(--color-brand);
  border: 1.5px solid var(--color-brand);
}
.btn-secondary:hover { background: #EEF2FF; }

.btn-sm { padding: .4rem .85rem; font-size: .85rem; min-height: 36px; }

.btn-danger { background: #DC2626; }
.btn-danger:hover { background: #B91C1C; }

.btn-full { width: 100%; }

/* ─── MENSAJES ───────────────────────────────── */
.msg {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  border-left: 4px solid;
  font-size: .9375rem;
  margin-bottom: var(--sp-4);
}
.msg-ok    { background: var(--color-ok-bg);  color: var(--color-ok-text);  border-color: var(--color-ok-border); }
.msg-error { background: var(--color-err-bg); color: var(--color-err-text); border-color: var(--color-err-border); }
.msg-info  { background: var(--color-info-bg);color: var(--color-info-text);border-color: var(--color-info-border); }

/* ─── TABLERO ────────────────────────────────── */
.tablero-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.progress-wrap {
  width: 100%;
  margin-top: var(--sp-2);
}

.progress-track {
  height: 10px;
  background: var(--color-border);
  border-radius: 5px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--color-brand-hover);
  border-radius: 5px;
  transition: width .4s ease;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: .8rem;
  color: var(--color-text-muted);
  margin-top: var(--sp-1);
}

/* Grid del tablero */
.tablero {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 5px;
  margin-bottom: 60px; /* espacio para la leyenda sticky */
}

@media (min-width: 400px)  { .tablero { grid-template-columns: repeat(9, 1fr); } }
@media (min-width: 560px)  { .tablero { grid-template-columns: repeat(12, 1fr); } }
@media (min-width: 1024px) { .tablero { grid-template-columns: repeat(17, 1fr); } }

/* Chip de número */
.numero {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  min-height: 2rem; /* garantiza ≥ 32px para legibilidad WCAG en móvil */
  border-radius: var(--r-sm);
  border: 1.5px solid transparent;
  font-family: var(--font-mono);
  font-size: .78rem;
  font-weight: 700;
  cursor: default;
  transition: transform .1s;
}

.libre {
  background: var(--color-libre-bg);
  color: var(--color-libre-text);
  border-color: var(--color-libre-border);
}

.vendido {
  background: var(--color-sold-bg);
  color: var(--color-sold-text);
  border-color: var(--color-sold-border);
}

.vendido:hover { transform: scale(1.08); cursor: help; }

.num-x {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 7px;
  font-family: var(--font-sans);
  line-height: 1;
  opacity: .75;
}

/* Leyenda sticky */
.tablero-leyenda {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(6px);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--sp-6);
  padding: var(--sp-3) var(--sp-4);
  font-size: .875rem;
  font-weight: 600;
  z-index: 50;
}

.leyenda-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: var(--sp-2);
}
.leyenda-dot.libre   { background: var(--color-libre-text); }
.leyenda-dot.vendido { background: var(--color-sold-text); }

/* ─── TABLERO ADMIN (con buscador) ──────────── */
/* Reutiliza .tablero pero los chips ocultos no rompen el grid */
.tablero-admin .numero[style*="display: none"] { display: none !important; }

/* ─── FORMULARIO DE VENTA ────────────────────── */
.venta-steps {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

@media (min-width: 768px) {
  .venta-steps {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
  .venta-step-full { grid-column: 1 / -1; }
}

.venta-step {
  background: var(--color-surface);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}

.step-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.step-num {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--color-brand);
  color: #fff;
  font-size: .8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-title { font-weight: 700; font-size: 1rem; }

/* Selector de números (venta) — WCAG 2.5.5: mínimo 44×44 px de área táctil
   En móvil usamos 5 columnas para garantizar ~65 px por chip en 360px de pantalla */
.selector-numeros {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;   /* gap ≥8px ayuda a evitar activaciones accidentales */
}

@media (min-width: 400px)  { .selector-numeros { grid-template-columns: repeat(6, 1fr); } }
@media (min-width: 560px)  { .selector-numeros { grid-template-columns: repeat(8, 1fr); } }
@media (min-width: 768px)  { .selector-numeros { grid-template-columns: repeat(10, 1fr); } }
@media (min-width: 1024px) { .selector-numeros { grid-template-columns: repeat(14, 1fr); } }

.num-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  border: 1.5px solid var(--color-libre-border);
  background: var(--color-libre-bg);
  color: var(--color-libre-text);
  font-family: var(--font-mono);
  font-size: .875rem;   /* ligeramente más grande para legibilidad */
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: background .12s, color .12s, border-color .12s, opacity .2s, transform .1s;
  /* Garantía de área táctil WCAG 2.5.5 (44×44 px) */
  min-height: 52px;
  min-width: 44px;
  padding: var(--sp-2);
}

.num-btn input[type=checkbox] { display: none; }

.num-btn:hover { border-color: var(--color-brand); }

.num-btn.seleccionado {
  background: var(--color-sel-bg);
  color: var(--color-sel-text);
  border-color: var(--color-sel-border);
  transform: scale(1.08);
}

.num-btn.bloqueado {
  opacity: .35;
  cursor: not-allowed;
}

.num-check {
  position: absolute;
  top: 2px; right: 3px;
  font-size: 7px;
  line-height: 1;
  display: none;
}
.num-btn.seleccionado .num-check { display: block; }

/* Resumen de precio */
.precio-resumen {
  background: var(--color-info-bg);
  border: 1.5px solid var(--color-info-border);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  color: var(--color-info-text);
  font-weight: 700;
  font-size: 1.05rem;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.precio-resumen:empty { display: none; }

/* Acción sticky al pie */
.venta-action {
  position: sticky;
  bottom: 0;
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(6px);
  border-top: 1px solid var(--color-border);
  padding: var(--sp-3) var(--sp-4);
  margin: 0 calc(-1 * var(--sp-4));
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  flex-wrap: wrap;
  z-index: 50;
}

/* ─── STATS ADMIN ────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

@media (min-width: 768px) { .stats { grid-template-columns: repeat(4, 1fr); } }

.stat-card {
  background: var(--color-surface);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--color-accent);
  line-height: 1;
  margin-bottom: var(--sp-1);
}

.stat-label {
  font-size: .8125rem;
  color: var(--color-text-muted);
  font-weight: 500;
}

/* ─── ADMIN LINKS ────────────────────────────── */
.admin-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}

@media (min-width: 640px) { .admin-links { grid-template-columns: repeat(4, 1fr); } }

.admin-link-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--r-lg);
  padding: var(--sp-5) var(--sp-3);
  text-decoration: none;
  color: var(--color-brand);
  font-weight: 600;
  font-size: .9rem;
  text-align: center;
  transition: border-color .15s, box-shadow .15s, background .15s;
  min-height: 80px;
}
.admin-link-card:hover {
  border-color: var(--color-brand-hover);
  box-shadow: var(--shadow-sm);
  background: #EEF2FF;
}
.admin-link-card .link-icon { font-size: 1.5rem; }

/* ─── TABLAS ─────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  font-size: .9rem;
}

thead th {
  background: var(--color-brand);
  color: #fff;
  font-weight: 600;
  padding: .65rem .875rem;
  text-align: left;
  font-size: .8125rem;
  letter-spacing: .03em;
  text-transform: uppercase;
  white-space: nowrap;
}

tbody td {
  padding: .6rem .875rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #F9FAFB; }

/* Badge de estado (vendedores) */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-ok  { background: var(--color-libre-bg); color: var(--color-libre-text); }
.badge-off { background: var(--color-err-bg);   color: var(--color-sold-text); }

/* ─── FORMULARIO NUEVA VENTA INLINE (admin) ── */
.form-row {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  align-items: flex-end;
}
.form-row .field { flex: 1; min-width: 140px; }

/* ─── SECCIÓN CON CARD ───────────────────────── */
.section-card {
  background: var(--color-surface);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  margin-bottom: var(--sp-5);
}

/* ─── PAGE HEADER ────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
}

/* ─── HINT ───────────────────────────────────── */
.hint { font-size: .85rem; color: var(--color-text-muted); }

/* ─── FIELDSET ───────────────────────────────── */
fieldset { border: none; }
legend { font-weight: 700; font-size: 1rem; margin-bottom: var(--sp-2); }

/* ─── TOGGLE SWITCH ─────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  font-weight: 600;
  cursor: pointer;
}

input[type=checkbox][role=switch] {
  appearance: none;
  width: 44px; height: 24px;
  border-radius: 12px;
  background: var(--color-border);
  border: none;
  cursor: pointer;
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}
input[type=checkbox][role=switch]::after {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  top: 3px; left: 3px;
  transition: left .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
input[type=checkbox][role=switch]:checked { background: var(--color-brand); }
input[type=checkbox][role=switch]:checked::after { left: 23px; }

/* ─── BANNER PRUEBAS ────────────────────────── */
.banner-pruebas {
  background: #FEF3C7;
  border-bottom: 2px solid #F59E0B;
  color: #92400E;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  font-size: .9rem;
  font-weight: 500;
}
.banner-pruebas-link {
  margin-left: auto;
  color: #92400E;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.banner-pruebas-link:hover { text-decoration: underline; }

.nav-pruebas-badge {
  background: #F59E0B;
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  letter-spacing: .03em;
}

.section-pruebas { border: 1.5px solid var(--color-border); }
.section-pruebas.pruebas-activo {
  border-color: #F59E0B;
  background: #FFFBEB;
}

/* ─── BANNER CERRADO ─────────────────────────── */
.banner-cerrado {
  background: var(--color-err-bg);
  border: 1.5px solid var(--color-err-border);
  border-radius: var(--r-lg);
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
  color: var(--color-err-text);
  font-weight: 600;
}
.banner-cerrado .banner-icon { font-size: 1.5rem; }

/* ─── SORTEO ─────────────────────────────────── */
.premio-card {
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.premio-card.estado-recogido { border-color: var(--color-libre-border); background: var(--color-libre-bg); }
.premio-card.estado-pendiente { border-color: var(--color-border); }
.premio-card.estado-sorteado  { border-color: var(--color-accent); background: #FFFBEB; }

.premio-orden {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-muted);
}

.premio-nombre { font-size: 1.15rem; font-weight: 800; }
.premio-desc   { font-size: .875rem; color: var(--color-text-muted); }

.ganador-box {
  background: #FFF7ED;
  border: 2px solid var(--color-accent);
  border-radius: var(--r-md);
  padding: var(--sp-4);
}
.ganador-numero {
  font-family: var(--font-mono);
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--color-accent);
  line-height: 1;
  margin-bottom: var(--sp-1);
}
.ganador-nombre  { font-size: 1.1rem; font-weight: 700; }
.ganador-telefono { font-size: .9rem; color: var(--color-text-muted); }
.ganador-vendedor { font-size: .8rem; color: var(--color-text-muted); margin-top: var(--sp-1); }

.premios-grid {
  display: grid;
  gap: var(--sp-4);
}
@media (min-width: 640px) { .premios-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .premios-grid { grid-template-columns: repeat(3, 1fr); } }

.estado-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 3px 10px;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 700;
}
.estado-pendiente { background: #F3F4F6; color: var(--color-text-muted); }
.estado-sorteado  { background: #FEF3C7; color: #92400E; }
.estado-recogido  { background: var(--color-libre-bg); color: var(--color-libre-text); }
