/* ========================================
   FlipIQ - Mobile UX Enhancements
   Fixes: layout shift, white space
   UX: hamburger, bottom bar, skeletons,
       button anims, toasts, lazy-load, footer
   ======================================== */

/* ========================================
   FIX: Mobile white space / layout shift
   ======================================== */

/* On mobile (<=768px), top navbar is hidden, so reduce .home padding-top */
@media (max-width: 768px) {
  .home {
    padding-top: 20px !important;
    padding-bottom: calc(100px + env(safe-area-inset-bottom)) !important;
  }

  /* scan page: ensure content doesn't hide behind bottom-nav */
  body.page-scan {
    padding-bottom: calc(100px + env(safe-area-inset-bottom)) !important;
  }
}

/* Fix body safe-area conflict: don't double-apply padding on mobile */
@media (max-width: 768px) {
  body {
    padding-top: 0 !important;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* ========================================
   A) HAMBURGER MENU (tablet 768-960px)
   ======================================== */

/* Hamburger button - shown on tablet where top navbar is visible but too narrow */
.menu-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px;
  z-index: 1001;
}

.menu-toggle span {
  display: block;
  width: 22px;
  height: 2.5px;
  background: #333;
  border-radius: 2px;
  transition: all 0.3s ease;
}

.menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}
.menu-toggle.active span:nth-child(2) {
  opacity: 0;
}
.menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

[data-theme="dark"] .menu-toggle span,
body.dark-mode .menu-toggle span {
  background: #e2e8f0;
}

@media (max-width: 960px) and (min-width: 769px) {
  .menu-toggle {
    display: flex;
  }
}

/* Menu overlay */
.menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.menu-overlay.active {
  display: block;
  opacity: 1;
}

/* ========================================
   B) BOTTOM ACTION BAR ON /SCAN
   ======================================== */

.scan-bottom-bar {
  display: none;
}

@media (max-width: 768px) {
  .scan-bottom-bar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 110;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    gap: 10px;
    align-items: center;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
  }

  .scan-bottom-bar .scan-bottom-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    background: #5b236e;
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(91, 35, 110, 0.3);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
  }

  .scan-bottom-bar .scan-bottom-btn:active {
    transform: scale(0.97);
  }

  .scan-bottom-bar .scan-bottom-btn svg {
    width: 20px;
    height: 20px;
  }

  /* Push content above bar */
  body.page-scan .scan-page {
    padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
  }

  /* Hide bottom-nav on scan page when scan-bottom-bar is shown */
  body.page-scan .bottom-nav {
    display: none !important;
  }

  [data-theme="dark"] .scan-bottom-bar,
  body.dark-mode .scan-bottom-bar {
    background: #1e293b;
    border-color: #334155;
  }
}

/* ========================================
   C) SKELETON LOADERS
   ======================================== */

.skeleton-card {
  background: #f3f4f6;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

.skeleton-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.5) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-thumb {
  width: 100%;
  aspect-ratio: 1;
  background: #e5e7eb;
}

.skeleton-line {
  height: 14px;
  margin: 10px;
  border-radius: 4px;
  background: #e5e7eb;
}

.skeleton-line--short {
  width: 60%;
}

/* Image skeleton: shown before image loads */
.img-skeleton {
  background: #e5e7eb;
  position: relative;
  overflow: hidden;
}

.img-skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.4) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
}

[data-theme="dark"] .skeleton-card,
body.dark-mode .skeleton-card {
  background: #1e293b;
}

[data-theme="dark"] .skeleton-thumb,
[data-theme="dark"] .skeleton-line,
body.dark-mode .skeleton-thumb,
body.dark-mode .skeleton-line {
  background: #334155;
}

/* ========================================
   D) BUTTON PRESS ANIMATIONS
   ======================================== */

@media (prefers-reduced-motion: no-preference) {
  .btn,
  .btn-primary,
  .btn-signup,
  .btn-login,
  .btn-new-ad,
  .fab-button,
  .generate-btn,
  .help-btn,
  .bottom-nav__item,
  .scan-bottom-btn {
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease, color 0.2s ease, border-color 0.2s ease !important;
  }

  .btn:active,
  .btn-primary:active,
  .btn-signup:active,
  .btn-login:active,
  .btn-new-ad:active,
  .fab-button:active,
  .generate-btn:active,
  .help-btn:active {
    transform: scale(0.97) !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1) !important;
  }

  .bottom-nav__item:active {
    transform: scale(0.93) !important;
  }
}

/* ========================================
   E) TOAST NOTIFICATIONS
   ======================================== */

#flipiq-toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 11000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 360px;
}

@media (max-width: 768px) {
  #flipiq-toast-container {
    top: auto;
    bottom: calc(100px + env(safe-area-inset-bottom));
    right: 12px;
    left: 12px;
    max-width: none;
    align-items: stretch;
  }
}

.flipiq-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #1f2937;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.flipiq-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.flipiq-toast.is-leaving {
  opacity: 0;
  transform: translateY(-12px);
}

.flipiq-toast--success {
  background: #059669;
}

.flipiq-toast--error {
  background: #dc2626;
}

.flipiq-toast--warn {
  background: #d97706;
  color: #000;
}

.flipiq-toast--info {
  background: #2563eb;
}

.flipiq-toast__icon {
  font-size: 18px;
  flex-shrink: 0;
  line-height: 1;
}

.flipiq-toast__text {
  flex: 1;
  min-width: 0;
}

.flipiq-toast__close {
  background: none;
  border: none;
  color: inherit;
  opacity: 0.7;
  font-size: 18px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
}

.flipiq-toast__close:hover {
  opacity: 1;
}

/* ========================================
   F) OFFLINE / SLOW CONNECTION BANNER
   ======================================== */

.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 12000;
  background: #d97706;
  color: #000;
  text-align: center;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}

.offline-banner.is-visible {
  transform: translateY(0);
}

/* ========================================
   G) LAZY-LOAD IMAGES + BLUR PLACEHOLDER
   ======================================== */

/* Override responsive-utils.css: don't hide lazy images, show blur placeholder */
img[loading="lazy"] {
  opacity: 1 !important;
  background: #e5e7eb;
  transition: filter 0.4s ease;
}

img[loading="lazy"].is-blur {
  filter: blur(10px);
}

img[loading="lazy"].is-loaded {
  filter: blur(0);
  background: transparent;
}

/* Feature icon wrap: always show (no lazy opacity issue) */
.feature-icon-wrap svg {
  color: #5b236e;
}

/* Store badge images: ensure visibility */
.store-badge img {
  opacity: 1 !important;
  visibility: visible !important;
}

/* ========================================
   H) FOOTER MOBILE CLEAN
   ======================================== */

@media (max-width: 768px) {
  .site-footer {
    margin-top: 60px;
  }

  .footer-bar {
    flex-direction: column;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
    min-height: auto;
  }

  .footer-bar p {
    white-space: normal;
    flex-direction: column;
    gap: 8px;
    text-align: center;
    font-size: 12px;
    line-height: 1.6;
  }

  .footer-bar a {
    font-size: 12px;
  }

  /* Cookie review button in footer */
  .cookie-review-btn {
    font-size: 11px;
    margin-top: 8px;
    opacity: 0.7;
  }

  /* Bottom CTA stores on mobile */
  .bottom-cta-stores {
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }

  .store-badge img {
    height: auto !important;
    width: min(200px, 70vw) !important;
    max-width: 70vw !important;
  }
}

/* Dark mode footer */
[data-theme="dark"] .footer-bar,
body.dark-mode .footer-bar {
  background: linear-gradient(135deg, #0f172a, #1e1b4b, #312e81);
}
