/* ============================================
   Parsexpress — PWA / iOS Specific Styles
   استایل‌های مخصوص PWA و آیفون
   ============================================ */

/* ── Safe Area Variables ──────────────────── */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

/* ── Smooth Momentum Scrolling (iOS) ─────── */
html {
  -webkit-overflow-scrolling: touch;
  -webkit-text-size-adjust: 100%;
}

/* ── Disable tap highlight on iOS ──────────  */
* {
  -webkit-tap-highlight-color: transparent;
}
button, a, [role="button"] {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ── Bottom Navigation — Safe Area ─────────  */
.mobile-bottom-nav {
  padding-bottom: max(var(--sab), 12px);
  /* Ensure nav sits above iOS home indicator */
}
.mobile-bottom-nav ul {
  padding-bottom: 0;
}

/* ── Header — Status Bar Safe Area ─────────
   In standalone PWA mode the status bar
   overlaps the fixed header on iOS.           */
@media all and (display-mode: standalone) {
  .header {
    padding-top: var(--sat);
  }
  body {
    /* Body should account for status bar */
    padding-top: 0;
  }
  /* Push page content below the now-taller header */
  .hero,
  main > *:first-child,
  .section:first-of-type {
    /* The header handles its own padding now */
  }
}

/* ── Fix 100vh on iOS ───────────────────────
   Use dvh (dynamic viewport height) so
   it accounts for the Safari toolbar.         */
.hero {
  min-height: clamp(280px, 70dvh, 680px);
}
.hero-slide {
  min-height: clamp(280px, 70dvh, 680px);
}

/* Fallback for browsers that don't support dvh */
@supports not (height: 1dvh) {
  .hero,
  .hero-slide {
    min-height: clamp(280px, 70vh, 680px);
  }
}

/* ── Cart Drawer — Safe Area ────────────── */
.cart-overlay {
  padding-bottom: var(--sab);
}
.cart-panel {
  padding-bottom: max(var(--sab), 16px);
}

/* ── Modal Drawers — Safe Area ──────────── */
.mobile-drawer {
  padding-bottom: max(var(--sab), 24px);
}

/* ── Auth Modal — Safe Area ─────────────── */
.modal {
  padding-bottom: max(var(--sab), 24px);
}

/* ── Prevent Content Under Notch ─────────── */
.header-inner {
  padding-left: max(var(--sal), 16px);
  padding-right: max(var(--sar), 16px);
}
.container {
  padding-left: max(var(--sal), var(--space-md));
  padding-right: max(var(--sar), var(--space-md));
}

/* ── iOS Install Banner ─────────────────── */
#pwa-install-banner {
  position: fixed;
  bottom: max(var(--sab), 80px); /* sits above bottom nav */
  left: 16px;
  right: 16px;
  z-index: 9999;
  transform: translateY(120%);
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
}
#pwa-install-banner.pwa-banner-visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: all;
}

.pwa-banner-inner {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 20px;
  padding: 16px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.05) inset,
    0 0 40px rgba(212, 175, 55, 0.08);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: relative;
}

.pwa-banner-icon {
  flex-shrink: 0;
}
.pwa-banner-icon img {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.pwa-banner-content {
  flex: 1;
  min-width: 0;
}

.pwa-banner-title {
  font-family: var(--font-body, 'Inter', sans-serif);
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
  line-height: 1.3;
}

[dir="rtl"] .pwa-banner-title {
  font-family: var(--font-fa, 'Vazirmatn', sans-serif);
}

.pwa-banner-body {
  font-size: 12px;
  color: rgba(255,255,255,0.65);
  line-height: 1.5;
  margin-bottom: 10px;
}

.pwa-banner-steps {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11px;
  color: #D4AF37;
  font-weight: 600;
}

.pwa-step {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(212, 175, 55, 0.12);
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: 20px;
  padding: 4px 10px;
}

.pwa-share-icon {
  width: 13px;
  height: 13px;
  stroke: #D4AF37;
  flex-shrink: 0;
}

.pwa-step-arrow {
  color: rgba(212,175,55,0.5);
  font-size: 12px;
}

/* Android install action buttons */
.pwa-banner-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.pwa-install-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #B22222, #8B0000);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  min-height: 36px;
  box-shadow: 0 4px 14px rgba(178, 34, 34, 0.45);
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.pwa-install-btn:active {
  transform: scale(0.96);
  box-shadow: 0 2px 8px rgba(178, 34, 34, 0.3);
}

.pwa-later-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  font-size: 12px;
  cursor: pointer;
  padding: 8px 4px;
  min-height: 36px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s;
}
.pwa-later-btn:hover { color: rgba(255,255,255,0.8); }

/* Manual hint button (when native prompt not available) */
.pwa-manual-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.85);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.pwa-manual-btn:active {
  background: rgba(255,255,255,0.15);
}

/* Android vs iOS caret visibility */
#pwa-install-banner[data-platform="android"] .pwa-banner-caret {
  display: none;
}
#pwa-install-banner[data-platform="ios"] .pwa-banner-caret {
  display: block;
}

.pwa-banner-close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.7);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  cursor: pointer;
  padding: 0;
  min-height: unset;
}
.pwa-banner-close:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

/* Caret arrow pointing down */
.pwa-banner-caret {
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid rgba(212, 175, 55, 0.35);
  margin: 0 auto;
  position: relative;
}
.pwa-banner-caret::before {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-top: 9px solid #1a1a2e;
  top: -11px;
  left: -9px;
}

/* ── PWA Splash / Loading Screen ───────────
   Applied when launched from Home Screen.   */
@media all and (display-mode: standalone) {
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: #080C10;
    z-index: 99999;
    opacity: 1;
    animation: pwa-splash-fade 0.6s ease 0.5s forwards;
    pointer-events: none;
  }
}

@keyframes pwa-splash-fade {
  to { opacity: 0; pointer-events: none; }
}

/* ── Overscroll Color (iOS Chrome) ─────── */
html {
  background-color: #080C10;
  overscroll-behavior-y: contain;
}

/* ── Focus Styles for Touch Devices ────── */
@media (hover: none) and (pointer: coarse) {
  .btn:hover {
    transform: none !important;
  }
  .btn:active {
    transform: scale(0.97) !important;
    transition: transform 0.1s ease !important;
  }
  .product-card:hover {
    transform: none !important;
  }
  .product-card:active {
    transform: scale(0.98) !important;
  }
  .category-card:hover {
    transform: none !important;
  }
  .category-card:active {
    transform: scale(0.97) !important;
  }
  .nav-btn:hover {
    transform: none !important;
  }
}

/* ── Larger Tap Targets on Mobile ──────── */
@media (max-width: 768px) {
  .nav-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 10px 14px;
  }
  .mobile-bottom-nav ul li a {
    padding: 10px 4px;
    min-height: 56px;
  }
  .cart-close {
    min-width: 44px;
    min-height: 44px;
  }
  .modal-close {
    min-width: 44px;
    min-height: 44px;
  }
}

/* ── iOS Input Zoom Prevention ──────────
   Prevents Safari from zooming when
   tapping on inputs (font-size >= 16px)  */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="search"],
select,
textarea {
  font-size: max(16px, 1em);
  -webkit-appearance: none;
  border-radius: var(--radius-sm, 8px);
}

/* ── Notch-aware padding for full-bleed sections ── */
.hero {
  padding-left: var(--sal);
  padding-right: var(--sar);
}
.stats-strip {
  padding-left: max(var(--sal), 0px);
  padding-right: max(var(--sar), 0px);
}

/* ── PWA mode: hide browser-styled scrollbars ── */
@media all and (display-mode: standalone) {
  ::-webkit-scrollbar { display: none; }
  * { scrollbar-width: none; }
}

/* ═══════════════════════════════════════════════════════════
   APP MODE — حالت اپ
   ───────────────────────────────────────────────────────────
   Everything below applies ONLY when the PWA is launched from
   the home screen. In a normal browser tab the site keeps its
   full website appearance, untouched.

   Goal: strip the website furniture (promo strip, secondary nav,
   SEO footer, desktop search) and leave a single app bar on top
   and a tab bar at the bottom — the shape a native app has.
   ═══════════════════════════════════════════════════════════ */
@media all and (display-mode: standalone) {

  /* ── 1. Remove website-only furniture ─────────────────── */
  .header-promo-bar,          /* marketing strip above the logo */
  .nav-menu,                  /* secondary category bar — the tab bar covers it */
  .footer,                    /* long SEO footer with 4 link columns */
  #pwa-install-banner {       /* never prompt to install inside the installed app */
    display: none !important;
  }

  /* The theme toggle is website chrome; the app follows one look. */
  .nav-actions .nav-btn[onclick*="toggleTheme"] {
    display: none !important;
  }

  /* ── 2. Compact app bar ───────────────────────────────── */
  .header {
    /* Sits under the status bar, which iOS draws over the page. */
    padding-top: var(--sat);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 20px rgba(0, 0, 0, .45);
  }
  .header::after { opacity: .25; }          /* soften the gradient hairline */

  .header-inner {
    padding: 8px 14px;
    gap: 10px;
  }

  /* The wide desktop search field becomes the 🔍 button + overlay,
     exactly like the phone layout, at every width. */
  .header-inner .search-bar { display: none !important; }
  .nav-actions .mobile-only { display: flex !important; }
  .nav-actions .hide-mobile { display: none !important; }

  .logo img { width: 34px; height: 34px; }
  .logo-texts { line-height: 1.25; }
  .logo-text-ru { font-size: 14px; }
  .logo-text-fa { font-size: 12px; }

  .nav-actions { gap: 4px; }
  .nav-actions .nav-btn {
    min-width: 42px;
    min-height: 42px;
    padding: 8px 10px;
    border-radius: 12px;
    font-size: 18px;
  }

  /* ── 3. Tab bar on every screen size ──────────────────── */
  /* In a browser this nav only appears under 768px. Installed on an
     iPad it must stay — a tab bar is the app's primary navigation. */
  .mobile-bottom-nav { display: block !important; }

  /* There is no <main> element in these pages, so the bottom padding
     has to live on <body>, otherwise the tab bar covers the last card. */
  body {
    padding-bottom: calc(68px + var(--sab)) !important;
  }

  /* ── 4. Calmer, shorter hero ──────────────────────────── */
  /* A full-height marketing hero is a landing-page device. In the app
     the products should be reachable without scrolling past a poster. */
  .hero,
  .hero-slide {
    min-height: clamp(180px, 34dvh, 300px);
  }
  .hero-arrow { display: none; }            /* swipe instead of arrows */

  .section { padding-top: 26px; padding-bottom: 26px; }
  .section:first-of-type { padding-top: 18px; }

  /* ── 5. Native touch behaviour ────────────────────────── */
  /* Chrome should not be selectable or long-press-copyable — that is
     the clearest tell that something is a web page and not an app. */
  .header,
  .mobile-bottom-nav,
  .nav-actions,
  .section-title,
  .logo {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
  /* …but real content stays selectable. */
  .product-card p,
  .product-title,
  .product-price,
  .footer-contact-item,
  input, textarea {
    -webkit-user-select: text;
    user-select: text;
  }

  /* Stop the whole page rubber-banding behind the app bar. */
  html, body {
    overscroll-behavior: none;
  }
}

/* iOS below 13 does not support the display-mode media query. pwa-install.js
   adds .app-mode to <html> in that case, and these mirror the essentials. */
html.app-mode .header-promo-bar,
html.app-mode .nav-menu,
html.app-mode .footer,
html.app-mode #pwa-install-banner {
  display: none !important;
}
html.app-mode .mobile-bottom-nav { display: block !important; }
html.app-mode body { padding-bottom: calc(68px + var(--sab)) !important; }
html.app-mode .header { padding-top: var(--sat); }
