/* ============================================================
   LotoInsight RD - Design System CSS
   Mobile First PWA - Inspired by the orange UI mockup
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700;800;900&display=swap');

:root {
  --orange-50:  #FFF7F3;
  --orange-100: #FFE8DB;
  --orange-200: #FFD0B5;
  --orange-300: #FFB088;
  --orange-400: #FF8C4A;
  --orange-500: #FF6B35;
  --orange-600: #E85D04;
  --orange-700: #C04A02;
  --orange-800: #9D3A00;
  --orange-900: #7A2D00;

  --white:  #FFFFFF;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;

  --success: #10B981;
  --warning: #F59E0B;
  --danger:  #EF4444;
  --info:    #3B82F6;

  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow:    0 4px 12px rgba(0,0,0,.10);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.14);
  --shadow-orange: 0 4px 20px rgba(255,107,53,.30);

  --font: 'Nunito', system-ui, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);
  --nav-height:  68px;
}

/* RESET & BASE */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
/* Prevenir zoom con doble tap en toda la app */
* { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
  height: 100%;
  height: -webkit-fill-available;
}
body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-800);
  height: 100%;
  height: -webkit-fill-available;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── APP SHELL ── */
#app {
  max-width: 430px;
  margin: 0 auto;
  height: 100dvh;
  height: -webkit-fill-available;
  background: var(--white);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* clave para iOS: evita que el viewport se expanda */
}

/* ── HEADER / TOP BAR ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--white);
  padding: calc(var(--safe-top) + 12px) 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--gray-100);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.app-header .logo {
  font-size: 1.25rem;
  font-weight: 900;
  color: var(--gray-900);
  letter-spacing: -0.5px;
}
.app-header .logo span { color: var(--orange-500); }

.btn-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--gray-100);
  color: var(--gray-700);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all .2s;
  font-size: 1.1rem;
  position: relative;
}
.btn-icon:active { transform: scale(.92); }
.btn-icon .badge-dot {
  position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--orange-500);
  border: 2px solid var(--white);
}

/* ── PAGE CONTENT ── */
.page-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch; /* smooth scroll iOS */
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
}

/* ── BOTTOM NAV ── */
/* iOS fix: position sticky at bottom of flex container, NOT fixed */
.bottom-nav {
  position: relative; /* no fixed — vive dentro del flex de #app */
  width: 100%;
  background: var(--white);
  border-top: 1px solid var(--gray-100);
  display: flex;
  padding: 8px 0 calc(env(safe-area-inset-bottom, 0px) + 8px);
  z-index: 200;
  box-shadow: 0 -4px 20px rgba(0,0,0,.06);
  flex-shrink: 0; /* no se comprime */
}

.nav-item {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px;
  cursor: pointer;
  border: none; background: none;
  color: var(--gray-400);
  font-size: .65rem;
  font-family: var(--font);
  font-weight: 600;
  transition: color .2s;
  padding: 4px 0;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.nav-item .nav-icon {
  font-size: 1.3rem;
  transition: transform .2s;
}
.nav-item.active {
  color: var(--orange-500);
}
.nav-item.active .nav-icon {
  transform: scale(1.1);
}

/* ── CARDS ── */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-100);
  overflow: hidden;
}
.card-orange {
  background: linear-gradient(135deg, var(--orange-500) 0%, var(--orange-600) 100%);
  color: var(--white);
  box-shadow: var(--shadow-orange);
}
.card-body { padding: 16px; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  font-family: var(--font);
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all .2s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(.96); }

.btn-primary {
  background: var(--orange-500);
  color: var(--white);
  border-radius: var(--radius-full);
  padding: 14px 28px;
  font-size: 1rem;
  box-shadow: var(--shadow-orange);
  width: 100%;
}
.btn-primary:hover { background: var(--orange-600); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-outline {
  background: transparent;
  color: var(--orange-500);
  border: 2px solid var(--orange-500);
  border-radius: var(--radius-full);
  padding: 12px 24px;
  font-size: .95rem;
  width: 100%;
}

.btn-ghost {
  background: var(--gray-100);
  color: var(--gray-700);
  border-radius: var(--radius-full);
  padding: 10px 20px;
  font-size: .9rem;
}

.btn-sm { padding: 8px 16px; font-size: .85rem; }
.btn-danger { background: var(--danger); color: var(--white); border-radius: var(--radius-full); padding: 10px 20px; }

/* ── INPUTS ── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-label { font-size: .85rem; font-weight: 700; color: var(--gray-600); text-transform: uppercase; letter-spacing: .4px; }
.form-control {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 1rem;
  color: var(--gray-800);
  background: var(--white);
  transition: border-color .2s;
  outline: none;
}
.form-control:focus { border-color: var(--orange-500); box-shadow: 0 0 0 3px rgba(255,107,53,.12); }
.form-control.error { border-color: var(--danger); }
.form-hint { font-size: .8rem; color: var(--gray-400); }
.form-error { font-size: .8rem; color: var(--danger); font-weight: 600; }

/* ── SELECT ── */
.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239CA3AF' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 44px;
}

/* ── NUMBER BALLS ── */
.number-ball {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: .95rem;
  cursor: default;
  transition: transform .15s, box-shadow .15s;
  user-select: none;
  flex-shrink: 0;
}
.number-ball.default {
  background: var(--white);
  color: var(--gray-700);
  border: 2px solid var(--gray-200);
}
.number-ball.selected {
  background: var(--orange-500);
  color: var(--white);
  border: 2px solid var(--orange-500);
  box-shadow: var(--shadow-orange);
  transform: scale(1.08);
}
.number-ball.caliente {
  background: linear-gradient(135deg, #FF6B35, #E85D04);
  color: var(--white);
  border: none;
}
.number-ball.frio {
  background: linear-gradient(135deg, #60A5FA, #3B82F6);
  color: var(--white);
  border: none;
}
.number-ball.sorpresa {
  background: linear-gradient(135deg, #A78BFA, #7C3AED);
  color: var(--white);
  border: none;
}
.number-ball.selectable {
  cursor: pointer;
}
.number-ball.selectable:active { transform: scale(.88); }

/* ── LOTO GRID ── */
.loto-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  padding: 12px;
}
.loto-grid .number-ball {
  width: 100%; height: 0; padding-bottom: 100%;
  font-size: .8rem;
  position: relative;
}
.loto-grid .number-ball span {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}

/* ── TICKETS ── */
.ticket {
  background: var(--white);
  border: 2px solid var(--gray-100);
  border-radius: var(--radius-lg);
  padding: 16px;
  position: relative;
  margin-bottom: 12px;
  overflow: hidden;
}
.ticket::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--orange-500);
}
.ticket-numbers {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 10px 0 8px;
}
.ticket-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── TREND BADGES ── */
.trend-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.trend-badge.caliente { background: rgba(255,107,53,.12); color: var(--orange-600); }
.trend-badge.frio     { background: rgba(59,130,246,.12); color: #1D4ED8; }
.trend-badge.sorpresa { background: rgba(124,58,237,.12); color: #5B21B6; }
.trend-badge.normal   { background: var(--gray-100); color: var(--gray-500); }

/* ── CHIPS / TABS ── */
.chip-group { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip-group::-webkit-scrollbar { display: none; }
.chip {
  padding: 8px 16px;
  border-radius: var(--radius-full);
  border: 2px solid var(--gray-200);
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s;
  background: var(--white);
  color: var(--gray-600);
}
.chip.active {
  background: var(--orange-500);
  border-color: var(--orange-500);
  color: var(--white);
  box-shadow: var(--shadow-orange);
}

/* ── BOTTOM SHEET ── */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
  backdrop-filter: blur(4px);
}
.sheet-backdrop.open { opacity: 1; pointer-events: all; }

.bottom-sheet {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%) translateY(100%);
  width: 100%; max-width: 430px;
  background: var(--white);
  border-radius: 24px 24px 0 0;
  z-index: 400;
  transition: transform .35s cubic-bezier(.34,1.56,.64,1);
  max-height: 90dvh;
  overflow-y: auto;
  padding-bottom: calc(var(--safe-bottom) + 20px);
}
.bottom-sheet.open { transform: translateX(-50%) translateY(0); }
.sheet-handle {
  width: 40px; height: 4px;
  background: var(--gray-200);
  border-radius: var(--radius-full);
  margin: 12px auto 0;
}
.sheet-header {
  padding: 16px 20px 12px;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--gray-900);
  border-bottom: 1px solid var(--gray-100);
}

/* ── TOAST ── */
#toast-container {
  position: fixed;
  top: calc(var(--safe-top) + 70px);
  left: 50%; transform: translateX(-50%);
  width: calc(100% - 40px); max-width: 390px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 14px 18px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: .9rem;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px;
  animation: slideDown .3s ease;
}
.toast.success { background: var(--success); color: var(--white); }
.toast.error   { background: var(--danger);  color: var(--white); }
.toast.info    { background: var(--info);    color: var(--white); }
.toast.warning { background: var(--warning); color: var(--white); }

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── SKELETON LOADER ── */
.skeleton {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius);
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── SECTION HEADERS ── */
.section-title {
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--gray-900);
  letter-spacing: -.3px;
}
.section-subtitle {
  font-size: .82rem;
  color: var(--gray-400);
  font-weight: 500;
}

/* ── AVATAR ── */
.avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--orange-400), var(--orange-600));
  color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.avatar.lg { width: 72px; height: 72px; font-size: 1.6rem; }

/* ── RESULT PREVIEW ── */
.result-numbers-row {
  display: flex; gap: 8px; justify-content: center;
  flex-wrap: wrap;
  padding: 16px;
}
.result-numbers-row .number-ball { width: 52px; height: 52px; font-size: 1.1rem; }

/* ── STATS BAR ── */
.stat-bar-wrap { margin-bottom: 8px; }
.stat-bar-label { display: flex; justify-content: space-between; font-size: .8rem; margin-bottom: 4px; }
.stat-bar-track {
  height: 6px; background: var(--gray-100);
  border-radius: var(--radius-full); overflow: hidden;
}
.stat-bar-fill {
  height: 100%; background: var(--orange-500);
  border-radius: var(--radius-full);
  transition: width .8s ease;
}

/* ── SPLASH SCREEN ── */
#splash {
  position: fixed; inset: 0;
  background: linear-gradient(160deg, #FF6B35 0%, #E85D04 100%);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 9999;
  transition: opacity .5s;
}
#splash.hide { opacity: 0; pointer-events: none; }
#splash .splash-logo {
  font-size: 2.4rem; font-weight: 900; color: var(--white);
  letter-spacing: -1px; margin-bottom: 8px;
}
#splash .splash-sub {
  color: rgba(255,255,255,.75); font-size: .9rem; font-weight: 600;
}
#splash .splash-loader {
  margin-top: 40px; width: 40px; height: 40px;
  border: 3px solid rgba(255,255,255,.3);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── AUTH PAGES ── */
.auth-page {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: 24px 24px calc(var(--safe-bottom) + 24px);
}
.auth-logo {
  font-size: 1.8rem; font-weight: 900; text-align: center;
  margin: 40px 0 8px;
  color: var(--gray-900);
}
.auth-logo span { color: var(--orange-500); }
.auth-sub {
  text-align: center; color: var(--gray-400);
  font-size: .9rem; margin-bottom: 32px;
}

/* ── DIVIDER ── */
.divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--gray-200); }
.divider span { font-size: .8rem; color: var(--gray-400); font-weight: 600; }

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
}
.empty-state .empty-icon { font-size: 3.5rem; margin-bottom: 16px; opacity: .6; }
.empty-state h3 { font-size: 1.1rem; font-weight: 800; color: var(--gray-700); margin-bottom: 8px; }
.empty-state p  { font-size: .9rem; color: var(--gray-400); }

/* ── RANKING ── */
.rank-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-100);
}
.rank-item:last-child { border: none; }
.rank-number {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: .85rem;
  background: var(--gray-100); color: var(--gray-500);
  flex-shrink: 0;
}
.rank-number.gold   { background: #FEF3C7; color: #D97706; }
.rank-number.silver { background: #F1F5F9; color: #64748B; }
.rank-number.bronze { background: #FEF0E7; color: #C2410C; }

/* ── FLOATING ACTION BTN ── */
.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  right: 20px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--orange-500);
  color: var(--white);
  border: none;
  font-size: 1.5rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-orange);
  cursor: pointer;
  z-index: 150;
  transition: transform .2s;
}
.fab:active { transform: scale(.9); }

/* ── UTILS ── */
.text-orange { color: var(--orange-500); }
.text-muted  { color: var(--gray-400); font-size: .85rem; }
.text-sm     { font-size: .85rem; }
.text-xs     { font-size: .75rem; }
.fw-bold     { font-weight: 700; }
.fw-black    { font-weight: 900; }
.p-16        { padding: 16px; }
.p-20        { padding: 20px; }
.gap-8       { gap: 8px; }
.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.w-full      { width: 100%; }
.mt-8        { margin-top: 8px; }
.mt-16       { margin-top: 16px; }
.mt-24       { margin-top: 24px; }
.mb-16       { margin-bottom: 16px; }
.rounded-full { border-radius: var(--radius-full); }

/* ── SCROLL CUSTOM ── */
::-webkit-scrollbar { width: 0; height: 0; }
* { scrollbar-width: none; }

/* ── PULSE ANIMATION ── */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.05); }
}
.pulse { animation: pulse 2s infinite; }

/* ── SAFE AREA ── */
.pb-safe { padding-bottom: calc(var(--safe-bottom) + 16px); }
.pt-safe { padding-top: calc(var(--safe-top) + 12px); }
