/* ==========================================================================
   PARAPHARMACIE E-COMMERCE MAROC - MASTER RESPONSIVE STYLESHEET
   100% Mobile Optimized • Touch Friendly • Zero Layout Shifts • Full RTL
   ========================================================================== */

/* Universal mobile safeguard: No horizontal overflow */
html, body {
  overflow-x: hidden;
  max-width: 100%;
  position: relative;
}

/* iOS Safari Input Auto-Zoom Prevention */
@media (max-width: 768px) {

  .reviews-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
  input,
  select,
  textarea,
  .form-control,
  .search-input {
    font-size: 16px !important;
  }
}

/* ==========================================================================
   TABLET BREAKPOINT (max-width: 1024px)
   ========================================================================== */
@media (max-width: 1024px) {
  .hero-grid {
    grid-template-columns: 1fr;
    gap: var(--space-xl);
    text-align: center;
  }

  .hero-content {
    max-width: 100%;
    margin-inline: auto;
  }

  .hero-cta {
    justify-content: center;
  }

  .hero-banner-card {
    max-width: 520px;
    margin-inline: auto;
  }

  .footer-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .newsletter-inner {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .newsletter-form {
    max-width: 500px;
    margin-inline: auto;
  }

  .catalog-layout {
    grid-template-columns: 240px 1fr;
    gap: var(--space-lg);
  }
}

/* ==========================================================================
   MOBILE BREAKPOINT (max-width: 768px)
   ========================================================================== */
@media (max-width: 768px) {

  /* Space for Mobile Bottom Navigation Bar */
  body {
    padding-bottom: 74px !important;
  }

  /* --- 1. Top Announcement Bar --- */
  .announcement-bar {
    padding: 6px 0;
  }

  .announcement-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    gap: 8px;
    font-size: 0.74rem;
  }

  .announcement-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    font-size: 0.72rem;
  }

  /* KEEP Language Switcher visible and crisp on mobile! */
  .announcement-actions {
    display: flex !important;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
  }

  .announcement-actions > span:first-child,
  .topbar-contacts {
    display: none; /* Hide phone in top bar on small screens to prevent overflow */
  }

  .lang-switch {
    display: flex !important;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    font-weight: 700;
  }

  .lang-btn {
    padding: 2px 7px;
    font-size: 0.72rem;
    border-radius: 4px;
  }

  /* --- 2. Site Header --- */
  .header-main {
    padding: 10px 0;
    gap: 10px;
    flex-wrap: wrap;
  }

  .logo-img {
    height: 38px;
    max-width: 190px;
  }

  .brand-text-block h1 {
    font-size: 1.15rem;
  }

  .brand-text-block span {
    font-size: 0.58rem;
    letter-spacing: 0.1em;
  }

  .search-wrapper {
    order: 3;
    width: 100%;
    margin-top: 4px;
  }

  .search-box {
    height: 42px;
  }

  .mobile-menu-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    cursor: pointer;
  }

  /* --- 3. Mobile Offcanvas Navigation Menu --- */
  .site-nav {
    display: none;
  }

  .site-nav.active,
  .site-nav.mobile-active {
    display: flex !important;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    max-width: 86vw;
    height: 100vh;
    height: 100dvh;
    background: #ffffff;
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.3);
    z-index: 3000;
    padding: 20px 16px;
    overflow-y: auto;
    animation: slideInMobileNav 0.28s ease forwards;
  }

  html[dir="rtl"] .site-nav.active,
  html[dir="rtl"] .site-nav.mobile-active {
    left: auto;
    right: 0;
    animation: slideInMobileNavRtl 0.28s ease forwards;
  }

  @keyframes slideInMobileNav {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
  }

  @keyframes slideInMobileNavRtl {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
  }

  .mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(3px);
    z-index: 2999;
    display: none;
  }

  .mobile-nav-backdrop.active {
    display: block;
  }

  .mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 14px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--color-border);
  }

  .nav-list {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    width: 100%;
  }

  .nav-link {
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border-bottom: none;
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .nav-link:hover, .nav-link.active {
    background-color: var(--color-secondary-soft);
    color: var(--color-primary-dark);
  }

  /* --- 4. Hero Section on Mobile --- */
  .hero {
    padding: var(--space-lg) 0;
  }

  .hero-title {
    font-size: 1.65rem;
    line-height: 1.25;
  }

  .hero-desc {
    font-size: 0.88rem;
    line-height: 1.6;
  }

  .hero-cta {
    flex-direction: column;
    gap: 10px;
    width: 100%;
  }

  .hero-cta .btn {
    width: 100%;
  }

  .hero-banner-card img {
    height: 280px;
  }

  /* --- 5. Products Grids (2 per row on Mobile) --- */
  .grid-cols-4,
  .grid-cols-3,
  .products-grid,
  #featuredProductsGrid,
  #bestSellersGrid,
  #promoProductsGrid,
  #productsCatalogGrid,
  #relatedProductsGrid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  .product-card {
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  }

  .product-thumb {
    height: 145px !important;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    position: relative;
  }

  .product-thumb img {
    max-height: 100%;
    width: auto;
    max-width: 100%;
    object-fit: contain;
  }

  .product-badges {
    top: 6px;
    left: 6px;
    gap: 4px;
  }

  html[dir="rtl"] .product-badges {
    left: auto;
    right: 6px;
  }

  .product-badges .badge {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
  }

  .product-info {
    padding: 8px !important;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 1;
  }

  .product-brand {
    font-size: 0.68rem !important;
    font-weight: 700;
    margin-bottom: 2px;
  }

  .product-title {
    font-size: 0.82rem !important;
    height: 2.5em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.25;
    margin-bottom: 6px !important;
  }

  .product-price-row {
    margin-bottom: 8px !important;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .price-current {
    font-size: 0.95rem !important;
    font-weight: 800;
  }

  .price-old {
    font-size: 0.72rem !important;
  }

  .product-card-actions {
    gap: 4px !important;
  }

  .btn-add-cart {
    padding: 8px 6px !important;
    font-size: 0.78rem !important;
    font-weight: 700;
    border-radius: 6px;
  }

  .btn-quick-wa {
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .btn-quick-wa img {
    width: 18px !important;
    height: 18px !important;
  }

  /* --- 6. Category Cards (4 per row or 2 per row) --- */
  .categories-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 8px !important;
  }

  @media (max-width: 480px) {
    .categories-grid {
      grid-template-columns: repeat(4, 1fr) !important;
      gap: 6px !important;
    }
  }

  .category-card {
    padding: 8px 4px !important;
    border-radius: var(--radius-md);
  }

  .category-icon-box {
    font-size: 1.4rem !important;
    margin-bottom: 4px !important;
  }

  .category-name {
    font-size: 0.7rem !important;
    line-height: 1.15;
  }

  .category-count {
    display: none;
  }

  /* --- 7. Trust Features (Why Us) --- */
  .trust-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  .trust-card {
    padding: 12px 10px !important;
  }

  .trust-icon {
    font-size: 1.6rem !important;
    margin-bottom: 4px !important;
  }

  .trust-title {
    font-size: 0.85rem !important;
  }

  .trust-desc {
    font-size: 0.74rem !important;
    line-height: 1.4;
  }

  /* --- 8. Catalog Page (products.html) Mobile Drawer --- */
  .catalog-layout {
    grid-template-columns: 1fr !important;
    gap: var(--space-md) !important;
    padding: var(--space-md) 0 !important;
  }

  .filters-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    max-width: 86vw;
    height: 100vh;
    height: 100dvh;
    background: #ffffff;
    z-index: 3100;
    overflow-y: auto;
    padding: 24px 18px;
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.3);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: block;
  }

  html[dir="rtl"] .filters-sidebar {
    left: auto;
    right: 0;
    transform: translateX(100%);
  }

  .filters-sidebar.active {
    transform: translateX(0) !important;
  }

  .catalog-topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .mobile-filter-toggle-btn {
    display: inline-flex !important;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 700;
    border-radius: var(--radius-md);
    background: var(--color-secondary-soft);
    border: 1px solid var(--color-primary);
    color: var(--color-primary-dark);
    cursor: pointer;
  }

  /* --- 9. Checkout & Cart Page on Mobile --- */
  .checkout-layout,
  .cart-page-layout {
    grid-template-columns: 1fr !important;
    gap: var(--space-lg) !important;
    padding: var(--space-md) 0 !important;
  }

  .checkout-card {
    padding: var(--space-lg) var(--space-md);
  }

  .grid-cols-2 {
    grid-template-columns: 1fr !important;
    gap: var(--space-sm) !important;
  }

  .order-summary-box {
    position: static !important;
    padding: var(--space-md);
  }

  .cart-table th, .cart-table td {
    padding: 10px 8px;
    font-size: 0.8rem;
  }

  /* --- 10. Cart Slide-Over Drawer on Mobile --- */
  .cart-drawer {
    width: 100% !important;
    max-width: 100vw !important;
  }

  .cart-drawer-header {
    padding: 14px 16px;
  }

  .cart-drawer-body {
    padding: 12px;
  }

  .cart-drawer-footer {
    padding: 14px 16px 24px;
  }

  /* --- 11. Footer on Mobile --- */
  .footer-grid {
    grid-template-columns: 1fr !important;
    gap: var(--space-xl);
  }

  .footer-bottom {
    flex-direction: column;
    text-align: center;
    gap: 8px;
  }

  /* --- 12. Floating WhatsApp positioning on Mobile --- */
  .floating-whatsapp {
    bottom: 80px !important;
    right: 14px !important;
    width: 48px !important;
    height: 48px !important;
  }

  html[dir="rtl"] .floating-whatsapp {
    right: auto !important;
    left: 14px !important;
  }
}

/* ==========================================================================
   MODERN APP-LIKE MOBILE BOTTOM NAVIGATION BAR
   ========================================================================== */
.mobile-bottom-bar {
  display: none;
}

@media (max-width: 768px) {
  .mobile-bottom-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 62px;
    background: #ffffff;
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
    z-index: 1500;
    justify-content: space-around;
    align-items: center;
    padding: 0 4px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .bottom-bar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 600;
    flex: 1;
    height: 100%;
    background: none;
    border: none;
    cursor: pointer;
    gap: 3px;
    transition: color 0.2s ease, transform 0.15s ease;
    position: relative;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-bar-item:active,
  .bottom-bar-item.active {
    color: var(--color-primary);
    transform: scale(0.96);
  }

  .bottom-bar-item svg {
    width: 22px;
    height: 22px;
  }

  .bottom-bar-icon-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .bottom-cart-badge {
    position: absolute;
    top: -6px;
    right: -10px;
    background: var(--color-danger);
    color: #ffffff;
    font-size: 0.62rem;
    font-weight: 800;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    box-shadow: 0 2px 5px rgba(220, 53, 69, 0.4);
  }

  .bottom-bar-item.wa-item {
    color: var(--color-whatsapp-dark);
  }

  .bottom-bar-item.wa-item svg,
  .bottom-bar-item.wa-item img {
    width: 22px;
    height: 22px;
  }
}

/* ==========================================================================
   STICKY BUY BAR FOR PRODUCT DETAILS PAGE ON MOBILE
   ========================================================================== */
.mobile-sticky-buy-bar {
  display: none;
}

@media (max-width: 768px) {
  .mobile-sticky-buy-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #ffffff;
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.12);
    padding: 8px 12px;
    z-index: 1600;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: env(safe-area-inset-bottom, 8px);
  }

  .sticky-price-block {
    display: flex;
    flex-direction: column;
    min-width: 90px;
  }

  .sticky-price-val {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--color-text);
    line-height: 1.1;
  }

  .sticky-price-label {
    font-size: 0.65rem;
    color: var(--color-text-muted);
  }

  .sticky-actions-block {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    justify-content: flex-end;
  }

  .sticky-actions-block .btn-primary {
    flex: 1;
    padding: 10px 14px;
    font-size: 0.88rem;
    font-weight: 700;
  }

  .sticky-actions-block .btn-quick-wa {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: var(--radius-md);
    background: var(--color-whatsapp);
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
