/* ═══════════════════════════════════════════════════════════════════════════
 * mobile.css — Camada base mobile-first
 *
 * Carregue ESTE css imediatamente após app.css em todas as páginas.
 * Aplica fixes globais pra que o site funcione bem em smartphones modernos:
 *   • Safe-area insets (notch / dynamic island / Android nav bar)
 *   • Touch targets ≥ 44px (Apple HIG / Material Design)
 *   • Input font 16px (evita zoom forçado no iOS)
 *   • Scroll suave + momentum
 *   • overscroll-behavior contained
 *   • Tap highlight transparente
 *   • Prevenção de seleção acidental em UI elements
 * ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --mobile-nav-height: 64px;
  --tap-target: 44px;
}

/* ── Reset global mobile ──────────────────────────────────────────────── */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

body {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  text-rendering: optimizeLegibility;
}

/* Inputs nunca devem causar zoom no iOS — font mínimo 16px */
input, select, textarea, button {
  font-size: max(16px, 1rem);
  -webkit-appearance: none;
  appearance: none;
  font-family: inherit;
}
input[type="checkbox"], input[type="radio"] { -webkit-appearance: auto; appearance: auto; }

/* Permite seleção em conteúdo (textos), mas não em UI */
button, a, nav, header, footer, .navbar, .navbar *,
.mobile-app-nav, .mobile-app-nav *,
.spot-action-btn, .filter-pill, .quick-pill, .mood-pill,
.nearby-pill, .nav-link, .lang-current, .lang-option,
.nav-cart-btn, .nav-weather, .nav-login-link, .nav-signup-link,
.nav-account-link, .nav-logout-btn, .nav-dropdown-trigger, .dropdown-item,
.whatsapp-button, .souvi-chat-open, .souvi-fab,
.btn, .cta, .cart-drawer-checkout, .cart-qty-btn, .cart-item-remove,
.allow-notif, .close-notif {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

p, h1, h2, h3, h4, h5, h6, .selectable, article, .copy {
  -webkit-user-select: text;
  user-select: text;
}

/* ── Touch targets ────────────────────────────────────────────────────── */
@media (pointer: coarse), (max-width: 768px) {
  button, [role="button"], a.btn, .filter-pill, .quick-pill, .mood-pill,
  .nearby-pill, .pill, .nav-link, input[type="submit"], input[type="button"] {
    min-height: var(--tap-target);
  }

  /* Pills mantêm aparência compacta mas com área de toque maior */
  .filter-pill, .quick-pill, .mood-pill, .nearby-pill {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  /* Links em listas precisam de área generosa */
  nav a, footer a { padding-block: 6px; min-height: 36px; display: inline-flex; align-items: center; }

  /* Mobile nav bottom: respeita safe-area */
  .mobile-app-nav {
    padding-bottom: max(var(--safe-bottom), 8px);
    padding-left: max(var(--safe-left), 8px);
    padding-right: max(var(--safe-right), 8px);
  }
  .mobile-app-link {
    min-height: 56px;
    -webkit-tap-highlight-color: rgba(15, 91, 69, 0.08);
  }
}

/* ── Safe-area pra elementos fixos ────────────────────────────────────── */
.navbar { padding-top: var(--safe-top); }
.notif-bar { padding-top: max(var(--safe-top), 10px); }

/* WhatsApp + Souvi FABs precisam respeitar safe-area-bottom */
.whatsapp-button {
  bottom: calc(26px + var(--safe-bottom)) !important;
}
.souvi-chat-open {
  bottom: calc(100px + var(--safe-bottom)) !important;
}

/* Quando a mobile-app-nav está visível, FABs sobem pra não tampar */
@media (max-width: 640px) {
  body:has(.mobile-app-nav) .whatsapp-button {
    bottom: calc(var(--mobile-nav-height) + 16px + var(--safe-bottom)) !important;
  }
  body:has(.mobile-app-nav) .souvi-chat-open {
    bottom: calc(var(--mobile-nav-height) + 90px + var(--safe-bottom)) !important;
  }
}

/* ── Body padding quando mobile-app-nav presente ──────────────────────── */
/* Só aplica em ≤640px (mesmo breakpoint que mostra o bottom nav). */
@media (max-width: 640px) {
  body:has(.mobile-app-nav) {
    padding-bottom: calc(var(--mobile-nav-height) + var(--safe-bottom));
  }
}

/* ── Imagens responsivas ──────────────────────────────────────────────── */
img, video, picture, svg {
  max-width: 100%;
  height: auto;
}
img[loading="lazy"] { background: rgba(0, 0, 0, 0.04); }

/* ── Modais e drawers: bloqueia scroll do body ───────────────────────── */
body.no-scroll {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* ── PWA standalone — esconde elementos que não fazem sentido em app ─── */
@media (display-mode: standalone) {
  /* Esconde links de "instalar como app" pois já está instalado */
  .install-prompt, .pwa-install-banner { display: none !important; }
  /* Esconde links externos do navegador no footer (opcional) */
  body { user-select: none; }
  p, h1, h2, h3, h4, h5, h6, article, .copy { user-select: text; }
}

/* ── Banner de instalação A2HS ──────────────────────────────────────── */
.install-prompt {
  position: fixed;
  bottom: calc(var(--mobile-nav-height) + 16px + var(--safe-bottom));
  left: 12px;
  right: 12px;
  background: #fff;
  color: #10232f;
  border: 1px solid #e5ded2;
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 20px 50px rgba(8, 20, 28, 0.18);
  z-index: 1090;
  transform: translateY(120%);
  transition: transform .35s cubic-bezier(.22,1,.36,1);
}
.install-prompt.is-visible { transform: translateY(0); }
.install-prompt[hidden] { display: none !important; }
.install-prompt-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #0f5b45, #1f4f86);
  border-radius: 12px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.5rem;
  font-weight: 800;
}
.install-prompt-text {
  flex: 1;
  min-width: 0;
}
.install-prompt-text strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.3;
  color: #10232f;
}
.install-prompt-text small {
  display: block;
  font-size: 0.78rem;
  color: #5d6c78;
  margin-top: 2px;
  line-height: 1.3;
}
.install-prompt-btn {
  background: linear-gradient(135deg, #0f5b45, #0a3d2e);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 800;
  font-size: 0.84rem;
  cursor: pointer;
  flex-shrink: 0;
  min-height: 40px;
  box-shadow: 0 4px 12px rgba(15, 91, 69, 0.3);
}
.install-prompt-close {
  background: transparent;
  border: 0;
  color: #8590a0;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 8px;
  min-width: 32px;
  min-height: 32px;
  border-radius: 50%;
}
.install-prompt-close:hover { background: rgba(0,0,0,.05); color: #10232f; }

/* ── Pull-to-refresh indicator ──────────────────────────────────────── */
.ptr-indicator {
  position: fixed;
  top: calc(var(--safe-top) + 8px);
  left: 50%;
  transform: translate(-50%, -100%);
  background: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  box-shadow: 0 8px 24px rgba(8, 20, 28, 0.16);
  font-size: 0.84rem;
  font-weight: 700;
  color: #0f5b45;
  z-index: 9000;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transition: opacity .2s, transform .25s cubic-bezier(.22,1,.36,1);
  pointer-events: none;
}
.ptr-indicator.is-pulling { opacity: 1; transform: translate(-50%, 0); }
.ptr-indicator.is-refreshing { opacity: 1; transform: translate(-50%, 0); }
.ptr-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(15, 91, 69, 0.2);
  border-top-color: #0f5b45;
  border-radius: 50%;
  animation: ptr-spin 0.7s linear infinite;
}
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* ── Push notification opt-in banner ────────────────────────────────── */
.push-optin {
  position: fixed;
  top: calc(var(--safe-top) + 12px);
  left: 12px;
  right: 12px;
  background: #fff;
  border-radius: 14px;
  border: 1px solid #e5ded2;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 12px 32px rgba(8, 20, 28, 0.14);
  z-index: 1100;
  transform: translateY(-150%);
  transition: transform .35s cubic-bezier(.22,1,.36,1);
}
.push-optin.is-visible { transform: translateY(0); }
.push-optin[hidden] { display: none !important; }
.push-optin-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}
.push-optin-text {
  flex: 1;
  min-width: 0;
  font-size: 0.86rem;
  line-height: 1.3;
  color: #10232f;
}
.push-optin-text strong { display: block; font-weight: 800; margin-bottom: 2px; }
.push-optin-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.push-optin-allow,
.push-optin-deny {
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  min-height: 36px;
}
.push-optin-allow { background: #0f5b45; color: #fff; }
.push-optin-deny { background: transparent; color: #8590a0; }

/* ── Snappy swiper para galerias ────────────────────────────────────── */
.swiper-track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  gap: 12px;
  padding: 0 12px;
}
.swiper-track::-webkit-scrollbar { display: none; }
.swiper-track > * {
  scroll-snap-align: start;
  flex-shrink: 0;
}

/* ── Skeleton loaders pra placeholder durante load ──────────────────── */
.skeleton {
  background: linear-gradient(90deg, #f0eae0 25%, #faf7f0 50%, #f0eae0 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: 8px;
}
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

/* ── Estado: usuário com touch (não-mouse) ──────────────────────────── */
@media (hover: none) {
  *:hover { transition: none !important; }
}

/* ── Quando o teclado está aberto no Android ────────────────────────── */
@media (max-height: 500px) and (orientation: portrait) {
  .mobile-app-nav { display: none; }
  body { padding-bottom: 0 !important; }
}

/* Prevencao de overflow horizontal sem quebrar wheel scroll vertical.
   NUNCA colocar overflow-x: hidden no html — em Chrome com scroll-behavior:
   smooth, isso bloqueia scroll por touchpad (deltaY wheel) silenciosamente.
   Aplicar SO no body, e usar `clip` em vez de `hidden`. */
html { overflow-y: auto; }
body { overflow-x: clip; }

/* ════════════════════════════════════════════════════════════════════════
 * MOBILE REFINEMENTS (auditoria visual #188)
 * Fixes globais pra paginas que nao tem mobile override proprio.
 * Aplicar apos todos os CSS de pagina via cascade order.
 * ════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {

  /* ── Heros: encolher h1 que nao tem clamp/mobile override ──────────── */
  .dicas-hero h1,
  .catalog-hero h1,
  .stores-hero h1,
  .checkout-hero h1,
  .product-detail h1,
  .city-products-hero h1 {
    font-size: clamp(1.5rem, 5.5vw, 2rem) !important;
    line-height: 1.2;
  }

  /* Hero subtitle/eyebrow geral encolhe tambem */
  .dicas-hero p,
  .catalog-hero p,
  .stores-hero p,
  .rot-hero p,
  .checkout-hero p,
  .loja-hero p {
    font-size: 0.92rem;
    line-height: 1.5;
  }

  /* Eyebrows menores */
  .dicas-eyebrow,
  .catalog-eyebrow,
  .stores-eyebrow,
  .loja-eyebrow,
  .rot-eyebrow,
  .sobre-eyebrow,
  .reseller-eyebrow { font-size: 0.66rem; letter-spacing: 0.12em; }

  /* ── Paddings gigantes (60px) viram 28px no mobile ─────────────────── */
  .catalog-hero,
  .catalog-empty,
  .dicas-hero,
  .stores-hero,
  .city-products-hero,
  .reseller-hero,
  .sobre-hero { padding-left: 18px !important; padding-right: 18px !important; }

  /* Heros com padding vertical excessivo */
  .catalog-hero { padding-top: 28px !important; padding-bottom: 24px !important; }
  .dicas-hero { padding-top: 28px !important; padding-bottom: 24px !important; }
  .stores-hero { padding-top: 28px !important; padding-bottom: 24px !important; }

  /* ── Filter pills wrappers — scroll horizontal limpo ───────────────── */
  .filter-group,
  .quick-filters,
  .mood-filters,
  .catalog-filters .filter-group,
  .dicas-tabs,
  .profile-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
    scroll-snap-type: x proximity;
    padding-bottom: 4px;
  }
  .filter-group::-webkit-scrollbar,
  .quick-filters::-webkit-scrollbar,
  .mood-filters::-webkit-scrollbar,
  .dicas-tabs::-webkit-scrollbar,
  .profile-tabs::-webkit-scrollbar { display: none; }
  .filter-pill, .quick-pill, .mood-pill, .nearby-pill {
    flex-shrink: 0;
    scroll-snap-align: start;
  }

  /* ── Card grids — single column abaixo de 480px ────────────────────── */
  .product-grid,
  .stores-grid,
  .catalog-grid,
  .dest-combines-grid,
  .dest-products-grid,
  .sw-prods {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* ── CTAs bottom — uma coluna sempre ───────────────────────────────── */
  .loja-bottom-cta,
  .catalog-bottom-cta,
  .dicas-bottom-cta,
  .rot-bottom-cta {
    grid-template-columns: 1fr !important;
    gap: 12px;
    margin-left: 14px !important;
    margin-right: 14px !important;
  }
  .loja-cta-card,
  .catalog-cta-card,
  .dicas-cta-card,
  .rot-cta-card {
    flex-wrap: wrap;
    padding: 14px 16px !important;
  }
  .loja-cta-btn,
  .catalog-cta-btn,
  .dicas-cta-btn,
  .rot-cta-btn {
    width: 100%;
    text-align: center;
    margin-top: 6px;
  }

  /* ── Modal genericos: full screen menos navbar e respira ───────────── */
  .sw-modal,
  .catalog-modal-content,
  .spot-modal,
  .spot-rating-modal {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: 90vh !important;
    border-radius: 18px 18px 0 0 !important;
    margin-top: auto !important;
  }
  .sw-modal-overlay,
  .catalog-modal,
  .spot-modal-overlay,
  .spot-rating-modal-bg {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  /* ── Tipografia geral, melhor leitura ─────────────────────────────── */
  main p, main li { line-height: 1.6; }

  /* ── Footer: respira mais ───────────────────────────────────────── */
  footer .footer-content {
    grid-template-columns: 1fr !important;
    gap: 20px;
    padding: 24px 18px !important;
  }
}

/* ── Viewport realmente pequeno (iPhone SE etc) ─────────────────────── */
@media (max-width: 380px) {
  .loja-hero h1,
  .dicas-hero h1,
  .catalog-hero h1,
  .stores-hero h1 { font-size: 1.4rem !important; }
  .nav-cart-btn { padding: 8px 10px; font-size: 0.85rem; }
  .souvi-chat-open { width: 54px; height: 54px; }
  .whatsapp-button { width: 54px; height: 54px; }
}

/* ════════════════════════════════════════════════════════════════════════
 * MOBILE BOTTOM NAV (estilo Instagram/AirBnB) — fica fixa no rodapé
 * Substitui a navbar topo no mobile. Desktop ignora (display:none).
 * ════════════════════════════════════════════════════════════════════════ */
.mobile-app-nav {
  display: none;
}

@media (max-width: 640px) {
  .mobile-app-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 200;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid rgba(15, 91, 69, 0.10);
    box-shadow: 0 -4px 20px rgba(2, 32, 58, 0.08);
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    padding: 6px 4px;
    padding-bottom: max(var(--safe-bottom), 8px);
    height: auto;
    min-height: var(--mobile-nav-height, 64px);
    font-family: 'Manrope', system-ui, sans-serif;
  }
  .mobile-app-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-decoration: none;
    color: #6f7e8a;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 6px 4px;
    border-radius: 12px;
    background: transparent;
    border: 0;
    cursor: pointer;
    font-family: inherit;
    transition: color .15s, background .15s, transform .1s;
    min-height: 56px;
    position: relative;
  }
  .mobile-app-link:hover { background: rgba(15, 91, 69, 0.04); }
  .mobile-app-link:active { transform: scale(0.94); }
  .mobile-app-link[aria-current="page"],
  .mobile-app-link.active {
    color: #0f5b45;
    font-weight: 800;
  }
  .mobile-app-link[aria-current="page"]::before,
  .mobile-app-link.active::before {
    content: '';
    position: absolute;
    top: 3px;
    width: 26px;
    height: 3px;
    background: #0f5b45;
    border-radius: 999px;
  }
  .mobile-app-icon {
    font-size: 1.4rem;
    line-height: 1;
    font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
    position: relative;
  }
  .mobile-app-link[aria-current="page"] .mobile-app-icon,
  .mobile-app-link.active .mobile-app-icon {
    transform: translateY(-1px);
  }
  
  .mobile-cart-badge {
    position: absolute;
    top: -4px; right: -8px;
    background: #d65a4a;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 800;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    padding: 0 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid #fff;
    line-height: 1;
  }
  .mobile-cart-badge[hidden] { display: none !important; }
}
