/* ============================================================
   LPZ Matériaux — Layer mobile-first (app-like)
   S'applique uniquement < 900px. N'altère pas le desktop.
   ============================================================ */

/* Variables mobile-only (en plus de celles de styles.css) */
:root {
  --m-bottomnav-h: 64px;
  --m-topbar-h: 56px;
  --m-radius: 14px;
  --m-shadow-card: 0 1px 2px rgba(0,0,0,.04), 0 2px 6px rgba(0,0,0,.05);
  --m-shadow-sticky: 0 -8px 24px rgba(0,0,0,.08);
}

/* Drawer & bottom nav existent dans le DOM pour tous les viewports
   mais sont masqués au-delà de 900px */
.m-drawer-bg, .m-drawer, .m-bottom-nav, .m-topbar-search-trigger, .m-menu-btn {
  display: none;
}

/* ============================================================
   < 900px — Activation du shell mobile
   ============================================================ */
@media (max-width: 899px) {

  /* ---- TOPBAR (cache la barre annonce et compacte le header) ---- */
  .topbar { display: none; }

  .header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
  }
  .header-inner {
    flex-wrap: nowrap !important;
    padding: 10px 0 !important;
    gap: 10px;
    min-height: var(--m-topbar-h);
  }
  .logo small { display: none; }
  .logo { font-size: 17px; gap: 8px; }
  .logo-mark { width: 32px; height: 32px; font-size: 14px; }

  /* La grosse search inline est masquée — remplacée par une icône qui ouvre la search en overlay */
  .header .search { display: none; }

  /* On ne garde dans le header que panier + menu + (compte si connecté) */
  .header-actions {
    margin-left: auto;
    gap: 4px;
  }
  .header-actions .iconbtn {
    padding: 8px 10px;
    font-size: 0;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .header-actions .iconbtn .badge {
    font-size: 11px;
    margin-left: 0;
  }
  /* On cache les boutons textuels secondaires (déconnexion, créer compte, admin) — ils sont dans le drawer */
  .header-actions .iconbtn[href*="deconnexion"],
  .header-actions .iconbtn[href*="inscription"],
  .header-actions .iconbtn[href*="connexion"],
  .header-actions .iconbtn[href*="admin"] {
    display: none;
  }
  /* Compte (si connecté) reste mais en icône */
  .header-actions .iconbtn[href*="espace-client"] {
    font-size: 0;
  }
  .header-actions .iconbtn[href*="espace-client"]::before {
    content: "👤";
    font-size: 18px;
  }
  /* Panier en icône avec badge */
  .header-actions .iconbtn[aria-label="Panier"] {
    font-size: 0;
    background: var(--brand);
    color: #fff;
    border-radius: 999px;
    position: relative;
  }
  .header-actions .iconbtn[aria-label="Panier"]::before {
    content: "🛒";
    font-size: 18px;
  }
  .header-actions .iconbtn[aria-label="Panier"] .badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: var(--accent);
    color: var(--ink);
    border: 2px solid #fff;
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    font-size: 10px;
    line-height: 14px;
    padding: 0 4px;
  }

  /* Bouton menu (hamburger) à gauche du logo */
  .m-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-size: 22px;
    border-radius: 10px;
    cursor: pointer;
    margin-right: -2px;
  }
  .m-menu-btn:active { background: var(--bg); }

  /* Bouton search dans le header */
  .m-topbar-search-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-size: 18px;
    border-radius: 10px;
    cursor: pointer;
  }
  .m-topbar-search-trigger:active { background: var(--bg); }

  /* ---- NAV horizontale supprimée mobile (remplacée par bottom nav) ---- */
  .nav { display: none; }

  /* ---- DRAWER ---- */
  .m-drawer-bg {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  .m-drawer-bg.open { opacity: 1; pointer-events: auto; }

  .m-drawer {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(86vw, 320px);
    background: #fff;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.2,.7,.2,1);
    box-shadow: 4px 0 24px rgba(0,0,0,.12);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .m-drawer.open { transform: translateX(0); }

  .m-drawer-head {
    padding: 18px 18px 14px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .m-drawer-head .logo { font-size: 17px; }
  .m-drawer-close {
    width: 36px;
    height: 36px;
    border: 0;
    background: var(--bg);
    border-radius: 10px;
    font-size: 20px;
    cursor: pointer;
  }

  .m-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 8px;
  }
  .m-drawer-body a, .m-drawer-body button {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 14px;
    font-size: 16px;
    color: var(--ink);
    text-decoration: none;
    border-radius: 10px;
    border: 0;
    background: transparent;
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
  }
  .m-drawer-body a:active, .m-drawer-body button:active { background: var(--bg); }
  .m-drawer-body a.active { color: var(--brand); background: rgba(198,81,28,.06); font-weight: 700; }
  .m-drawer-body .m-section-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    padding: 18px 14px 6px;
    font-weight: 700;
  }
  .m-drawer-foot {
    padding: 14px 18px calc(14px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    font-size: 13px;
    color: var(--muted);
  }

  /* ---- BOTTOM NAV ---- */
  .m-bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 80;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 8px rgba(0,0,0,.04);
  }
  .m-bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 8px 4px;
    color: var(--muted);
    text-decoration: none;
    font-size: 10px;
    font-weight: 600;
    min-height: var(--m-bottomnav-h);
    position: relative;
  }
  .m-bottom-nav a .ico {
    font-size: 22px;
    line-height: 1;
  }
  .m-bottom-nav a.active {
    color: var(--brand);
  }
  .m-bottom-nav a.active::before {
    content: "";
    position: absolute;
    top: 6px;
    width: 4px;
    height: 4px;
    border-radius: 999px;
    background: var(--brand);
  }
  .m-bottom-nav a:active {
    background: rgba(0,0,0,.04);
  }

  /* Padding global du body pour ne pas masquer le contenu sous la bottom nav */
  body {
    padding-bottom: calc(var(--m-bottomnav-h) + env(safe-area-inset-bottom));
  }

  /* ---- SEARCH OVERLAY ---- */
  .m-search-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: #fff;
    z-index: 110;
    padding-top: env(safe-area-inset-top);
  }
  .m-search-overlay.open { display: flex; flex-direction: column; }
  .m-search-overlay-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
  }
  .m-search-overlay-head input {
    flex: 1;
    height: 44px;
    border: 0;
    background: var(--bg);
    border-radius: 10px;
    padding: 0 14px;
    font-size: 16px;
    font-family: inherit;
    color: var(--ink);
  }
  .m-search-overlay-head input:focus { outline: 2px solid var(--brand); }
  .m-search-overlay-head button {
    width: 40px;
    height: 40px;
    border: 0;
    background: transparent;
    font-size: 20px;
    border-radius: 10px;
    cursor: pointer;
  }
  .m-search-hint {
    padding: 18px;
    color: var(--muted);
    font-size: 14px;
  }

  /* ---- HOME : hero compact + search prominent ---- */
  .hero { padding: 24px 0 36px !important; border-radius: 0 0 var(--m-radius) var(--m-radius); }
  .hero h1 { font-size: 26px !important; line-height: 1.15; }
  .hero .lead { font-size: 15px; }
  .hero-badges { gap: 6px; }
  .hero-badge { font-size: 11px; padding: 4px 10px; }

  /* Search prominent sous le hero (insérée par index.php OU via fallback CSS) */
  .m-home-search {
    margin: 16px 0 8px;
    padding: 0 16px;
  }
  .m-home-search form {
    display: flex;
    gap: 8px;
    background: #fff;
    border: 1.5px solid var(--line);
    border-radius: 14px;
    padding: 6px 6px 6px 14px;
    box-shadow: var(--m-shadow-card);
  }
  .m-home-search input {
    flex: 1;
    border: 0;
    height: 44px;
    font-size: 16px;
    font-family: inherit;
    background: transparent;
    color: var(--ink);
  }
  .m-home-search input:focus { outline: none; }
  .m-home-search button {
    height: 44px;
    padding: 0 16px;
    border: 0;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
  }

  /* ---- SECTIONS générales : padding réduit ---- */
  .section { padding: 32px 0 !important; }
  .section-head h2 { font-size: 22px; }
  .section-head p { font-size: 14px; }

  /* ---- GRILLE PRODUITS : 2 colonnes par défaut mobile ---- */
  .products {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }
  .product {
    border-radius: var(--m-radius);
    box-shadow: var(--m-shadow-card);
  }
  .product .media, .product .media-img { aspect-ratio: 1/1; padding: 14px; }
  .product .info { padding: 12px 12px 14px; gap: 4px; }
  .product .name {
    font-size: 14px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.6em;
  }
  .product .cat { font-size: 11px; }
  .product .price-row { margin-top: 4px; }
  .product .price { font-size: 16px; }
  .product .price-u { font-size: 11px; }
  /* Le bouton "Ajouter" inline est trop petit en mobile : on le fait pleine largeur */
  .product .cart-btn {
    position: static !important;
    margin: 8px 12px 12px;
    width: calc(100% - 24px);
    height: 38px;
    border-radius: 10px;
    font-size: 13px;
    background: var(--brand);
    color: #fff;
  }

  /* ---- GRILLE CATÉGORIES : 2 colonnes ---- */
  .cats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }
  .cat-card {
    padding: 18px 14px !important;
    border-radius: var(--m-radius);
    box-shadow: var(--m-shadow-card);
  }
  .cat-card h3 { font-size: 15px; }
  .cat-card p { font-size: 12px; }
  .cat-card .ico { width: 44px; height: 44px; font-size: 22px; }

  /* ---- USP : une ligne scrollable horizontalement ---- */
  .usp {
    display: flex !important;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 10px;
    padding: 12px 16px;
    -webkit-overflow-scrolling: touch;
  }
  .usp::-webkit-scrollbar { display: none; }
  .usp-item {
    flex: 0 0 78%;
    scroll-snap-align: start;
    border-right: 0 !important;
    background: var(--bg);
    border-radius: 12px;
    padding: 14px;
  }

  /* ---- FICHE PRODUIT ---- */
  .product-detail {
    grid-template-columns: 1fr !important;
    gap: 18px !important;
  }
  .gallery-main {
    aspect-ratio: 1/1;
    border-radius: var(--m-radius) !important;
  }
  .product-info h1 {
    font-size: 22px !important;
    line-height: 1.2;
  }
  .product-info .price-big { font-size: 26px !important; }
  /* Form add-to-cart : on cache les boutons du form principal en mobile,
     car le sticky CTA en bas les remplace */
  .product-info form .qty-control { margin-bottom: 8px; }
  .product-info form .btn-primary,
  .product-info form .btn-ghost { width: 100%; height: 48px; font-size: 15px; }
  .product-info form > div[style*="flex-wrap"] {
    flex-direction: column;
  }

  /* ---- STICKY ADD-TO-CART (mobile only) ---- */
  .m-sticky-cta {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--m-bottomnav-h) + env(safe-area-inset-bottom));
    background: rgba(255,255,255,.97);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    box-shadow: var(--m-shadow-sticky);
    padding: 12px 14px;
    z-index: 70;
    display: flex;
    gap: 8px;
    align-items: center;
  }
  .m-sticky-cta .m-sticky-price {
    flex: 0 0 auto;
    line-height: 1.1;
  }
  .m-sticky-cta .m-sticky-price .price {
    font-weight: 800;
    font-size: 17px;
    color: var(--ink);
    display: block;
  }
  .m-sticky-cta .m-sticky-price .unit {
    font-size: 11px;
    color: var(--muted);
  }
  .m-sticky-cta button[type="submit"] {
    flex: 1;
    height: 48px;
    border: 0;
    border-radius: 12px;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    font-family: inherit;
  }
  .m-sticky-cta button[type="submit"]:active { background: var(--brand-dark); }
  .m-sticky-cta a.m-sticky-quote {
    flex: 0 0 auto;
    height: 48px;
    padding: 0 14px;
    border-radius: 12px;
    background: var(--bg);
    color: var(--ink);
    font-weight: 700;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    border: 1px solid var(--line);
  }
  /* Quand sticky CTA présent : on ajoute du padding au body pour éviter le recouvrement */
  body.has-sticky-cta {
    padding-bottom: calc(var(--m-bottomnav-h) + 72px + env(safe-area-inset-bottom));
  }

  /* ---- PANIER mobile : cards au lieu d'un tableau ---- */
  table.cart-table { display: block; }
  table.cart-table thead { display: none; }
  table.cart-table tbody, table.cart-table tr { display: block; }
  table.cart-table tr {
    border: 1px solid var(--line);
    border-radius: var(--m-radius);
    margin-bottom: 12px;
    padding: 12px;
    background: #fff;
    box-shadow: var(--m-shadow-card);
  }
  table.cart-table td {
    display: flex;
    justify-content: space-between;
    border: 0 !important;
    padding: 6px 0 !important;
  }
  table.cart-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    font-size: 13px;
  }

  /* ---- FOOTER : compact ---- */
  .footer-grid {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
  }
  .footer-bottom {
    flex-direction: column;
    gap: 6px;
    text-align: center;
    font-size: 12px;
  }

  /* ---- TOUCH TARGETS minimum ---- */
  .btn, .iconbtn, button {
    min-height: 44px;
  }

  /* ---- INPUTS : 16px pour éviter zoom Safari ---- */
  input[type="text"], input[type="search"], input[type="email"],
  input[type="tel"], input[type="password"], input[type="number"],
  textarea, select {
    font-size: 16px !important;
  }
}

/* ============================================================
   < 600px — phones serrés : 1 colonne pour catégories
   ============================================================ */
@media (max-width: 599px) {
  .cats { grid-template-columns: 1fr !important; }
  /* Produits restent en 2 colonnes pour la densité */
}

/* ============================================================
   Animations désactivées si l'utilisateur les refuse
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .m-drawer, .m-drawer-bg { transition: none; }
}
