/* PWA + mobile app shell */
:root {
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  padding-bottom: var(--safe-bottom);
}

/* Mobile header */
.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  position: relative;
  z-index: 201;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.menu-toggle span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform .2s, opacity .2s;
}

.menu-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle.open span:nth-child(2) { opacity: 0; }
.menu-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.mobile-drawer {
  display: none;
  position: fixed;
  inset: 0;
  top: calc(64px + var(--safe-top));
  background: rgba(15, 23, 42, 0.22);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 190;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}

.mobile-drawer.open {
  opacity: 1;
  pointer-events: auto;
}

.mobile-drawer-panel {
  background: rgba(255, 255, 255, 0.68);
  backdrop-filter: blur(22px) saturate(1.45);
  -webkit-backdrop-filter: blur(22px) saturate(1.45);
  padding: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow:
    0 16px 40px rgba(15, 23, 42, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  border-radius: 0 0 20px 20px;
  transform: translateY(-100%);
  transition: transform .28s ease;
}

.mobile-drawer.open .mobile-drawer-panel {
  transform: translateY(0);
}

.mobile-nav-links {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.mobile-nav-links a {
  display: block;
  padding: .85rem 1rem;
  border-radius: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.mobile-nav-links a:hover,
.mobile-nav-links a.active {
  background: rgba(227, 30, 36, 0.1);
  border-color: rgba(227, 30, 36, 0.12);
  color: var(--primary);
}

/* Install prompt */
.pwa-install-banner {
  display: none;
  position: fixed;
  bottom: calc(var(--safe-bottom) + 12px);
  left: 1rem;
  right: 1rem;
  background: #1a1a2e;
  color: white;
  padding: 1rem;
  border-radius: var(--radius);
  z-index: 250;
  box-shadow: var(--shadow);
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.pwa-install-banner.show { display: flex; }

.pwa-install-banner p { font-size: .9rem; flex: 1; min-width: 180px; }

.pwa-install-actions { display: flex; gap: .5rem; }

.pwa-install-actions .btn-outline {
  color: white;
  border-color: #4b5563;
  background: transparent;
}

/* Offline page */
.offline-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  padding-bottom: var(--safe-bottom);
}

.offline-card {
  text-align: center;
  background: white;
  padding: 2.5rem 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 400px;
}

.offline-icon { font-size: 3rem; margin-bottom: 1rem; }
.offline-card h1 { font-size: 1.25rem; margin-bottom: .5rem; }
.offline-card p { color: var(--text-muted); margin-bottom: 1.5rem; }
.offline-card .btn { margin: .25rem; }

/* Responsive enhancements */
@media (max-width: 768px) {
  .site-header {
    padding-top: var(--safe-top);
    z-index: 300;
  }

  .mobile-drawer {
    z-index: 290;
  }

  .header-inner {
    height: 56px;
    gap: .5rem;
  }

  .logo { font-size: 1.15rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .header-end .header-chat-btn,
  .header-end .header-user-btn {
    display: none !important;
  }

  .header-chat-label { display: none; }

  .header-user-label { display: none; }

  .header-chat-btn {
    padding: 0.45rem;
    width: 40px;
    height: 40px;
    justify-content: center;
    border-radius: 50%;
  }

  .header-user-btn {
    padding: 0.45rem;
    width: 40px;
    height: 40px;
    justify-content: center;
    border-radius: 50%;
  }

  .main-nav { display: none; }

  .menu-toggle { display: flex; }

  .mobile-drawer {
    display: block;
    top: calc(56px + var(--safe-top));
  }

  .page-home .mobile-drawer {
    top: calc(52px + var(--safe-top));
  }

  /* صفحه اصلی: هدر روی Hero — فضای بالا */
  .page-home main {
    padding-top: 0;
  }

  .page-home .header-inner {
    height: 52px;
  }

  .section { padding: 1.5rem 0; }

  .search-row {
    grid-template-columns: 1fr;
    gap: .5rem;
    padding: .65rem;
  }

  .search-row .btn-primary { width: 100%; }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: .5rem;
  }

  .section-header h2 { font-size: 1.35rem; }

  .car-grid:not(.home-car-grid) {
    grid-template-columns: repeat(2, 1fr);
    gap: .75rem;
  }

  .car-card-body { padding: .75rem; }

  .car-card-body h3 { font-size: .85rem; }

  .car-price { font-size: .9rem; }

  .car-meta { font-size: .75rem; }

  .why-grid { grid-template-columns: 1fr; }

  .why-card { padding: 1.5rem; }

  .contact-buttons { flex-direction: column; }

  .contact-buttons .btn { width: 100%; }

  .highlights-grid { grid-template-columns: 1fr; }

  .detail-section { padding: 1.25rem; }

  .footer-grid { grid-template-columns: 1fr; gap: 1.25rem; }

  .site-footer {
    padding-top: 2rem;
    padding-bottom: calc(1.5rem + var(--safe-bottom));
  }

  .site-footer h3 { font-size: 1.05rem; }
  .site-footer h4 { font-size: 0.9rem; }
  .site-footer p,
  .site-footer li { font-size: 0.88rem; }

  .footer-bottom {
    padding-top: 1rem;
    font-size: 0.8rem;
  }

  .pagination { flex-wrap: wrap; }
}

@media (max-width: 380px) {
  .car-grid:not(.home-car-grid) { grid-template-columns: 1fr; }
}

@media (min-width: 769px) {
  body { padding-bottom: 0; }
  .pwa-install-banner { bottom: 1rem; }
}

@media (display-mode: standalone) {
  .pwa-install-banner { display: none !important; }
  .site-header { padding-top: var(--safe-top); }
}
