/* ── KidzApp Global Styles ── */

* { -webkit-tap-highlight-color: transparent; box-sizing: border-box; }

body { font-family: 'Nunito', sans-serif; overscroll-behavior: none; }

/* Safe area for iOS notch */
.safe-bottom { padding-bottom: env(safe-area-inset-bottom); }
.safe-top    { padding-top:    env(safe-area-inset-top); }

/* ── Animations ───────────────────────────────── */
@keyframes slideUp   { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeIn    { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop       { 0%,100% { transform: scale(1); } 50% { transform: scale(1.15); } }
@keyframes shimmer   {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}
@keyframes confetti  {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(-120px) rotate(720deg); opacity: 0; }
}
@keyframes pulse-ring {
  0%   { transform: scale(.85); box-shadow: 0 0 0 0 rgba(124,58,237,.7); }
  70%  { transform: scale(1);   box-shadow: 0 0 0 12px rgba(124,58,237,0); }
  100% { transform: scale(.85); box-shadow: 0 0 0 0   rgba(124,58,237,0); }
}

.animate-slide-up  { animation: slideUp .3s ease both; }
.animate-fade-in   { animation: fadeIn  .25s ease both; }
.animate-pop       { animation: pop .25s ease; }
.animate-pulse-ring{ animation: pulse-ring 1.8s ease infinite; }

/* ── Skeleton loader ──────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}

/* ── Cards ────────────────────────────────────── */
.card {
  background: white;
  border-radius: 1.25rem;
  box-shadow: 0 2px 12px rgba(0,0,0,.06);
  padding: 1rem;
}

/* ── Task/Reward item ─────────────────────────── */
.task-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .85rem 1rem;
  background: white;
  border-radius: 1rem;
  box-shadow: 0 1px 6px rgba(0,0,0,.05);
  transition: transform .15s ease, box-shadow .15s ease;
  cursor: pointer;
}
.task-item:active { transform: scale(.97); }
.task-item.done   { opacity: .6; }

.task-icon {
  width: 44px; height: 44px;
  border-radius: .75rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

/* ── Point badge ──────────────────────────────── */
.points-badge {
  background: linear-gradient(135deg, #7C3AED, #A78BFA);
  color: white;
  border-radius: 999px;
  padding: .2rem .7rem;
  font-weight: 800;
  font-size: .8rem;
  white-space: nowrap;
}

/* ── Bottom nav item ──────────────────────────── */
.nav-item {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  cursor: pointer;
  color: #9CA3AF;
  transition: color .2s;
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  position: relative;
  padding: .25rem 0;
  border: none; background: none;
}
.nav-item.active   { color: #7C3AED; }
.nav-item .nav-dot {
  position: absolute;
  top: 6px; right: calc(50% - 18px);
  width: 8px; height: 8px;
  background: #EF4444;
  border-radius: 50%;
  border: 2px solid white;
}

/* ── Avatar circles ───────────────────────────── */
.avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
}

/* ── Modal / Bottom sheet ─────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .2s ease;
}
.modal-sheet {
  background: white;
  border-radius: 1.5rem 1.5rem 0 0;
  width: 100%; max-width: 480px;
  padding: 1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom));
  animation: slideUp .3s ease;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-handle {
  width: 40px; height: 4px;
  background: #E5E7EB;
  border-radius: 2px;
  margin: 0 auto .75rem;
}

/* ── Buttons ──────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font-weight: 800;
  border-radius: .875rem;
  padding: .75rem 1.5rem;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  border: none; outline: none;
  font-family: 'Nunito', sans-serif;
  font-size: .95rem;
}
.btn:active { transform: scale(.96); }
.btn-primary {
  background: linear-gradient(135deg, #7C3AED, #6D28D9);
  color: white;
  box-shadow: 0 4px 14px rgba(124,58,237,.4);
}
.btn-primary:active { box-shadow: 0 2px 6px rgba(124,58,237,.3); }
.btn-secondary {
  background: #F3F4F6;
  color: #374151;
}
.btn-success {
  background: linear-gradient(135deg, #10B981, #059669);
  color: white;
  box-shadow: 0 4px 14px rgba(16,185,129,.35);
}
.btn-danger { background: #FEE2E2; color: #DC2626; }
.btn-full   { width: 100%; }
.btn-sm     { padding: .45rem 1rem; font-size: .8rem; border-radius: .6rem; }

/* ── Form inputs ──────────────────────────────── */
.input {
  width: 100%;
  padding: .75rem 1rem;
  border: 2px solid #E5E7EB;
  border-radius: .875rem;
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  outline: none;
  transition: border-color .2s;
  background: white;
}
.input:focus { border-color: #7C3AED; }
.input::placeholder { color: #9CA3AF; font-weight: 500; }

/* ── intl-tel-input overrides ─────────────────── */
.iti { width: 100%; display: block; }

/* Input styling — padding-left is a fallback; JS overrides via element.style after measuring */
.iti__tel-input {
  width: 100% !important;
  padding-top: .75rem !important;
  padding-right: 1rem !important;
  padding-bottom: .75rem !important;
  padding-left: 110px;   /* safe fallback; JS sets exact value via offsetWidth */
  border: 2px solid #E5E7EB !important;
  border-radius: .875rem !important;
  font-family: 'Nunito', sans-serif !important;
  font-size: 1rem !important;
  font-weight: 600 !important;
  outline: none !important;
  transition: border-color .2s !important;
  background: white !important;
  box-sizing: border-box !important;
  color: #111827 !important;
}
.iti__tel-input:focus { border-color: #7C3AED !important; }
.iti__tel-input::placeholder { color: #9CA3AF !important; font-weight: 500 !important; }

/* Flag container sits absolute over the input's left side */
.iti__flag-container { z-index: 10; height: 100%; }

/* Flag button — keep library's flex layout, just adjust padding + border */
.iti__selected-country {
  padding: 0 8px 0 10px !important;
  border-right: 2px solid #E5E7EB !important;
  border-radius: .875rem 0 0 .875rem !important;
  background: #F9FAFB !important;
  height: 100%;
  gap: 5px !important;
}
/* The primary container already has display:flex from the library */
.iti__selected-country-primary { gap: 5px !important; }

/* Our injected dial-code span */
.kz-dial {
  font-family: 'Nunito', sans-serif;
  font-size: .85rem;
  font-weight: 800;
  color: #374151;
  white-space: nowrap;
  letter-spacing: -.01em;
}
/* Hide any library-rendered dial code (we control display ourselves) */
.iti__selected-dial-code { display: none !important; }
.iti__arrow { margin-left: 1px; opacity: .5; }

/* Dropdown list */
.iti__dropdown-content {
  border-radius: .875rem !important;
  border: 1px solid #E5E7EB !important;
  box-shadow: 0 8px 32px rgba(0,0,0,.15) !important;
  z-index: 9999 !important;
  overflow: hidden !important;
  min-width: 280px !important;
}
.iti__search-input {
  border: none !important;
  border-bottom: 1px solid #E5E7EB !important;
  border-radius: 0 !important;
  padding: .6rem .875rem !important;
  font-family: 'Nunito', sans-serif !important;
  font-size: .875rem !important;
  width: 100% !important;
  outline: none !important;
  font-weight: 600 !important;
  box-sizing: border-box !important;
}
.iti__search-input:focus { background: #faf5ff !important; }
.iti__country-list {
  max-height: 220px !important;
  overflow-y: auto !important;
}
.iti__country {
  padding: .5rem .875rem !important;
  font-size: .85rem !important;
  font-family: 'Nunito', sans-serif !important;
  font-weight: 600 !important;
}
.iti__country.iti__highlight,
.iti__country:hover { background: #f3f0ff !important; }
.iti__dial-code { color: #6B7280 !important; font-size: .8rem !important; }

/* Validation state borders */
.iti--error   .iti__tel-input { border-color: #F87171 !important; }
.iti--success .iti__tel-input { border-color: #4ADE80 !important; }

/* ── Status badges ────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-pending   { background: #FEF3C7; color: #D97706; }
.badge-submitted { background: #DBEAFE; color: #1D4ED8; }
.badge-approved  { background: #D1FAE5; color: #065F46; }
.badge-rejected  { background: #FEE2E2; color: #9B1C1C; }

/* ── Header gradient bars ─────────────────────── */
.page-header {
  background: linear-gradient(135deg, #7C3AED 0%, #5B21B6 100%);
  padding: 1.25rem 1.25rem .5rem;
  padding-top: calc(1.25rem + env(safe-area-inset-top));
  color: white;
}
.page-header.kid-header {
  background: linear-gradient(135deg, #10B981 0%, #065F46 100%);
}

/* ── Confetti burst ───────────────────────────── */
.confetti-piece {
  position: fixed;
  width: 10px; height: 10px;
  border-radius: 2px;
  animation: confetti 1s ease-out forwards;
  pointer-events: none;
  z-index: 9999;
}

/* ── Empty state ──────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 3rem 1rem;
  text-align: center;
  color: #9CA3AF;
}
.empty-state .empty-icon { font-size: 3.5rem; margin-bottom: .75rem; }

/* ── Desktop phone-frame layout ───────────────── */
@media (min-width: 640px) {
  html {
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4c1d95 100%);
    min-height: 100vh;
  }

  /* Subtle radial glows on the dark background */
  html::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
      radial-gradient(circle at 20% 30%, rgba(124,58,237,.25) 0%, transparent 40%),
      radial-gradient(circle at 80% 70%, rgba(91,33,182,.3)   0%, transparent 40%);
    pointer-events: none;
    z-index: 0;
  }

  body {
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    /* equal gap top and bottom so frame floats */
    padding: 24px 0;
  }

  /* The phone frame — fully rounded like a real phone */
  #app {
    position: relative;
    z-index: 1;
    width: 430px;
    flex-shrink: 0;
    /* Fixed height so everything clips inside */
    height: calc(100vh - 48px);
    border-radius: 40px;
    overflow: hidden;
    /*
     * transform creates a new containing block for position:fixed children,
     * so modals, bottom-nav, and loading-screen all clip within this frame
     * automatically — no per-element overrides needed.
     */
    transform: translateZ(0);
    box-shadow:
      0 0 0 2px #4c1d95,
      0 0 0 5px #312e81,
      0 0 80px rgba(0,0,0,.65),
      inset 0 0 0 1px rgba(255,255,255,.1);
    background: #f9fafb;
  }

  /* Page container fills frame height, scrolls internally */
  #page-container {
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /*
   * Tailwind's min-h-screen = 100vh, which overflows the fixed-height frame.
   * Map it to 100% of the container instead to eliminate the scroll.
   */
  .min-h-screen {
    min-height: 100% !important;
  }

  /* PWA banner sits above bottom-nav, inside frame */
  #pwa-install-banner {
    bottom: 90px;
    width: calc(430px - 2rem);
  }
}

/* ── PWA install banner ────────────────────────── */
#pwa-install-banner {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  width: min(400px, calc(100vw - 2rem));
  background: linear-gradient(135deg, #7C3AED, #5B21B6);
  color: white;
  border-radius: 1.25rem;
  padding: .875rem 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  box-shadow: 0 8px 32px rgba(124,58,237,.45);
  z-index: 1000;
  animation: slideUp .35s ease both;
}
#pwa-install-banner .pwa-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  flex-shrink: 0;
  background: rgba(255,255,255,.15);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
}
#pwa-install-banner .pwa-text { flex: 1; }
#pwa-install-banner .pwa-text strong { display: block; font-size: .9rem; font-weight: 800; }
#pwa-install-banner .pwa-text span   { font-size: .75rem; opacity: .85; }
#pwa-install-banner .pwa-install-btn {
  background: white;
  color: #7C3AED;
  border: none;
  border-radius: .75rem;
  padding: .45rem .9rem;
  font-weight: 800;
  font-size: .82rem;
  cursor: pointer;
  white-space: nowrap;
  font-family: 'Nunito', sans-serif;
}
#pwa-install-banner .pwa-dismiss {
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0 .25rem;
  line-height: 1;
}
