/**
 * TedPlas — mobile-pwa.css
 * Complète header.css + footer.css pour le support PWA
 * NE PAS dupliquer ce qui existe déjà dans ces fichiers
 * Inclure après footer.css dans toutes les pages
 */

/* ═══════════════════════════════════════════════════════════════
   VARIABLES MANQUANTES (alignées sur header.css)
═══════════════════════════════════════════════════════════════ */
:root {
  --pwa-safe-bottom: env(safe-area-inset-bottom, 0px);
  --pwa-safe-top:    env(safe-area-inset-top, 0px);
  --pwa-nav-h:       64px;
  /* Reprend la couleur orange existante */
  --pwa-orange:      #F66B0E;
}

/* ═══════════════════════════════════════════════════════════════
   BODY — espace pour la bottom nav mobile existante (footer.php)
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  body {
    padding-bottom: calc(var(--pwa-nav-h) + var(--pwa-safe-bottom)) !important;
  }
}

/* ═══════════════════════════════════════════════════════════════
   BOTTOM NAV MOBILE (footer.php — .mobile-bottom-nav)
   Amélioration de ce qui existe déjà
═══════════════════════════════════════════════════════════════ */
.mobile-bottom-nav {
  /* Support encoche iPhone / barre gestes Android */
  padding-bottom: var(--pwa-safe-bottom) !important;
  height: calc(var(--pwa-nav-h) + var(--pwa-safe-bottom)) !important;
}

/* ═══════════════════════════════════════════════════════════════
   GRILLE D'ANNONCES RESPONSIVE
═══════════════════════════════════════════════════════════════ */
.ads-grid {
  display: grid;
  gap: 16px;
}

@media (max-width: 480px)                            { .ads-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; } }
@media (min-width: 481px) and (max-width: 768px)     { .ads-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 769px) and (max-width: 1024px)    { .ads-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1025px)                           { .ads-grid { grid-template-columns: repeat(4, 1fr); } }

/* ── Carte annonce compacte sur petit écran ──────────────────── */
@media (max-width: 480px) {
  .ad-card { border-radius: 10px; overflow: hidden; }

  .ad-image-container { aspect-ratio: 1 / 1; }
  .ad-image { width: 100%; height: 100%; object-fit: cover; }

  .ad-content { padding: 8px !important; }

  .ad-title {
    font-size: 13px !important;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .ad-price { font-size: 14px !important; font-weight: 700; }

  /* Masquer le secondaire pour gagner de la place */
  .seller-info,
  .ad-meta { display: none !important; }

  .ad-location { display: inline-flex !important; font-size: 11px; }
}

/* ═══════════════════════════════════════════════════════════════
   CATÉGORIES — SCROLL HORIZONTAL SUR MOBILE
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .categories-grid {
    display: flex !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    gap: 10px !important;
    padding-bottom: 8px !important;
  }
  .categories-grid::-webkit-scrollbar { display: none; }

  .category-card {
    flex-shrink: 0 !important;
    width: 86px !important;
    flex-direction: column !important;
    align-items: center !important;
    text-align: center !important;
    padding: 12px 6px !important;
    border-radius: 12px !important;
  }
  .category-icon  { font-size: 26px !important; }
  .category-name  { font-size: 11px !important; }
  .category-count,
  .category-arrow { display: none !important; }
}

/* ═══════════════════════════════════════════════════════════════
   CAROUSEL ANNONCES EN VEDETTE
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .carousel-wrapper { position: relative; }
  .carousel-btn     { display: none !important; } /* navigation par swipe sur mobile */
  .ads-carousel {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 10px;
    scroll-snap-type: x mandatory;
  }
  .ads-carousel::-webkit-scrollbar { display: none; }
  .ads-carousel .ad-card {
    flex-shrink: 0;
    width: calc(50vw - 22px);
    scroll-snap-align: start;
  }
}

/* ═══════════════════════════════════════════════════════════════
   HERO BANNER
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .hero-banner  { margin: 0 -16px !important; border-radius: 0 !important; }
  .banner-image { width: 100%; height: 140px; object-fit: cover; }

  .sell-banner {
    margin: 10px 0 !important;
    padding: 14px !important;
    border-radius: 12px !important;
  }
  .sell-banner-content h2     { font-size: 17px !important; }
  .sell-banner-actions        { flex-direction: column !important; gap: 10px !important; }
  .sell-stats                 { justify-content: space-between !important; width: 100% !important; }
  .sell-floating-btn          { bottom: calc(var(--pwa-nav-h) + var(--pwa-safe-bottom) + 12px) !important; }
}

/* ═══════════════════════════════════════════════════════════════
   PAGE DÉTAIL ANNONCE
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .ad-detail-container { display: block !important; padding: 0 !important; }
  .ad-images-gallery   { border-radius: 0 !important; margin: 0 !important; }

  /* Barre d'actions sticky au-dessus de la bottom nav */
  .ad-detail-sidebar {
    position: fixed !important;
    bottom: calc(var(--pwa-nav-h) + var(--pwa-safe-bottom)) !important;
    left: 0 !important; right: 0 !important;
    background: var(--bg-white) !important;
    border-top: 1px solid var(--border-color) !important;
    border-radius: 0 !important;
    padding: 10px 16px !important;
    display: flex !important;
    gap: 10px !important;
    z-index: 800 !important;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.08) !important;
  }

  .btn-contact,
  .btn-buy {
    flex: 1;
    padding: 13px !important;
    font-size: 15px !important;
    border-radius: 999px !important;
    font-weight: 700 !important;
  }

  .ad-detail-content {
    padding: 14px !important;
    padding-bottom: calc(var(--pwa-nav-h) + var(--pwa-safe-bottom) + 80px) !important;
  }
}

/* ═══════════════════════════════════════════════════════════════
   MESSAGES / CHAT
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .messages-layout { display: block !important; }

  .messages-layout.in-chat .conversations-list { display: none !important; }
  .messages-layout.in-chat .chat-window        { display: flex !important; }

  .chat-window {
    display: none;
    flex-direction: column;
    height: calc(100dvh - 60px - var(--pwa-nav-h) - var(--pwa-safe-bottom));
  }
  .chat-messages { flex: 1; overflow-y: auto; padding: 14px; }

  .chat-input-area {
    padding: 10px 14px;
    padding-bottom: calc(10px + var(--pwa-safe-bottom));
    background: var(--bg-white);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    align-items: center;
  }
  .chat-input-area input {
    flex: 1;
    border-radius: 999px;
    padding: 10px 14px;
    font-size: 16px !important; /* évite zoom iOS */
    border: 1px solid var(--border-color);
    background: var(--bg-light-gray);
  }
}

/* ═══════════════════════════════════════════════════════════════
   FORMULAIRES (évite zoom iOS au focus)
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="tel"],
  input[type="number"],
  input[type="search"],
  select,
  textarea {
    font-size: 16px !important;
  }

  .form-grid-2 { grid-template-columns: 1fr !important; }

  /* Zone upload photos */
  .photos-upload-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .photo-upload-slot {
    aspect-ratio: 1;
    border-radius: 10px;
    border: 2px dashed var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    cursor: pointer;
    background: var(--bg-light-gray);
  }
}

/* ═══════════════════════════════════════════════════════════════
   WALLET & COMMANDES
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .wallet-balance { font-size: 30px !important; font-weight: 800 !important; }

  /* Tabs scrollables */
  .tabs-scroll {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 8px;
    padding: 0 16px 10px;
  }
  .tabs-scroll::-webkit-scrollbar { display: none; }

  .tab-pill {
    flex-shrink: 0;
    padding: 7px 16px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    background: var(--bg-light-gray);
    border: 1px solid var(--border-color);
    cursor: pointer;
    white-space: nowrap;
    color: var(--text-secondary);
    transition: all 0.2s;
  }
  .tab-pill.active {
    background: rgba(246,107,14,0.1);
    border-color: var(--primary-orange);
    color: var(--primary-orange);
  }
}

/* ═══════════════════════════════════════════════════════════════
   BANNIÈRE INSTALL PWA
═══════════════════════════════════════════════════════════════ */
#pwa-install-banner {
  display: none;
  position: fixed;
  bottom: calc(var(--pwa-nav-h) + var(--pwa-safe-bottom) + 10px);
  left: 14px;
  right: 14px;
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary-orange);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 8px 28px var(--shadow-medium);
  z-index: 2000;
  align-items: center;
  gap: 12px;
  animation: pwaSlideUp 0.35s ease;
}
#pwa-install-banner.show { display: flex; }

.pwa-install-icon { font-size: 34px; flex-shrink: 0; }
.pwa-install-text { flex: 1; }
.pwa-install-text strong { display: block; font-size: 14px; font-weight: 700; color: var(--text-dark); margin-bottom: 2px; }
.pwa-install-text span   { font-size: 12px; color: var(--text-secondary); }
.pwa-install-actions     { display: flex; gap: 8px; flex-shrink: 0; }

.btn-pwa-install {
  background: var(--primary-orange);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.btn-pwa-install:active { opacity: 0.85; }

.btn-pwa-dismiss {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

@keyframes pwaSlideUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ═══════════════════════════════════════════════════════════════
   BARRE OFFLINE/ONLINE
═══════════════════════════════════════════════════════════════ */
#pwa-network-bar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 9999;
  padding: 8px 16px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
}
#pwa-network-bar.offline { display: block; background: #FEF3C7; color: #92400E; }
#pwa-network-bar.online  { display: block; background: #D1FAE5; color: #065F46; }

/* ═══════════════════════════════════════════════════════════════
   UTILITAIRES
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .container { padding: 0 14px !important; }
  .hide-mobile { display: none !important; }
}

/* Fix pour le footer desktop sur mobile */
@media (max-width: 768px) {
  .tedplas-footer.desktop-only { display: none !important; }
}

/* Fix sidebar mobile — déjà dans header.css mais on s'assure du safe area */
.mobile-sidebar {
  padding-bottom: var(--pwa-safe-bottom) !important;
}

@media print {
  .mobile-bottom-nav,
  #pwa-install-banner,
  #pwa-network-bar { display: none !important; }
}