/* ================================================================
   SG UI FIXES — v8.3.0
   Loaded after catalogue.css. Fixes card alignment (quote mode),
   mobile toolbar density, touch targets and filter-drawer polish.
   ================================================================ */

/* ────────────────────────────────────────────────────────────────
   1. PRODUCT CARD — equal heights, bottom-aligned CTA
   Problem: in quote mode there is no .sg-card__foot, so the
   "Ajouter au devis" button sat directly under the title and
   floated at a different height in every card.
   ──────────────────────────────────────────────────────────────── */

.sg-grid__inner > .sg-card,
.sg-shop__grid .sg-card { height: 100%; }

.sg-card__body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}

/* Title: fixed 3-line box so every card's CTA starts on the same line */
.sg-card:not(.sg-card--list) .sg-card__name {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  /* reserve exactly 3 lines */
  min-height: calc(3 * 1.35em);
}

/* Anything that ends the card gets pushed to the bottom */
.sg-card__body > .sg-card__foot,
.sg-card__body > .wcdd-btn,
.sg-card__body > .sgpw-btn-devis { margin-top: auto; }

/* Quote button inside a card: full-width block, consistent height.
   Colours stay owned by wcdd-frontend.css — this only fixes geometry. */
.sg-card__body > .wcdd-btn,
.sg-card__body .wcdd-btn--loop {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 9px 12px;
  margin: 0;
  box-sizing: border-box;
  font-size: 12.5px;
  line-height: 1.2;
}
.sg-card__body .wcdd-btn__icon,
.sg-card__body .wcdd-btn__check { flex: 0 0 auto; }
.sg-card__body .wcdd-btn__text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Busy state feedback */
.sg-card__body .wcdd-btn.is-busy { opacity: .6; pointer-events: none; }

/* Price row keeps its own baseline when both exist */
.sg-card__foot { padding-top: 8px; }
.sg-card__foot + .wcdd-btn { margin-top: 8px !important; }

/* Out-of-stock cards read as unavailable rather than broken */
.sg-card.is-oos .sg-card__img { opacity: .55; }


/* ────────────────────────────────────────────────────────────────
   2. GRID RHYTHM
   ──────────────────────────────────────────────────────────────── */

.sg-grid__inner { align-items: stretch; }

/* 2 columns is right for phones; 1 column below 340px is not — keep 2
   but tighten padding so nothing truncates. */
@media (max-width: 600px) {
  .sg-card__body { padding: 10px 10px 12px; gap: 5px; }
  .sg-card:not(.sg-card--list) .sg-card__name {
    font-size: 12.5px;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    min-height: calc(3 * 1.35em);
  }
  .sg-card__body .wcdd-btn--loop {
    min-height: 40px;
    font-size: 11.5px;
    padding: 8px;
    gap: 5px;
  }
  .sg-card__body .wcdd-btn__icon,
  .sg-card__body .wcdd-btn__check { width: 13px; height: 13px; }
}

/* Very narrow phones: drop the icon, keep the label readable */
@media (max-width: 380px) {
  .sg-card__body .wcdd-btn__icon { display: none; }
  .sg-card__body .wcdd-btn--loop { font-size: 11px; }
}


/* ────────────────────────────────────────────────────────────────
   3. MOBILE TOOLBAR — one clean row instead of a stacked column
   ──────────────────────────────────────────────────────────────── */

@media (max-width: 767px) {
  .sg-shop__toolbar {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "filter sort"
      "count  count";
    align-items: center;
    gap: 8px 10px;
    padding: 10px 12px;
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--sg-white, #fff);
    border-bottom: 1px solid var(--sg-border, #dde3ea);
  }
  .sg-shop__toolbar-left  { grid-area: filter; display: flex; align-items: center; }
  .sg-shop__toolbar-right { grid-area: sort; display: flex; justify-content: flex-end; gap: 8px; }
  .sg-shop__count {
    grid-area: count;
    margin: 0;
    font-size: 12px;
    color: var(--sg-muted, #718096);
  }
  .sg-shop__search-wrap { display: none; }  /* the header search bar already covers this */
  .sg-shop__sort-wrap   { flex: 1; min-width: 0; max-width: 190px; }
  .sg-shop__sort        { width: 100%; }

  /* Filter button reads as the primary control it is */
  .sg-shop__filter-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 0 14px;
    border-radius: var(--sg-pill, 999px);
    border: 1.5px solid var(--sg-border, #dde3ea);
    background: var(--sg-white, #fff);
    font-size: 13px;
    font-weight: 650;
    color: var(--sg-dark, #0d1b2a);
  }
  .sg-shop__filter-toggle:active { background: var(--sg-bg, #f7f9fb); }
  /* When filters are applied, make it obvious */
  .sg-shop__filter-toggle:has(.sg-shop__filter-badge:not([hidden])) {
    border-color: var(--sg-red, #e63128);
    color: var(--sg-red, #e63128);
  }
  .sg-shop__filter-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 999px;
    background: var(--sg-red, #e63128); color: #fff;
    font-size: 10.5px; font-weight: 700;
  }
}


/* ────────────────────────────────────────────────────────────────
   4. FILTER DRAWER — usable on a phone
   ──────────────────────────────────────────────────────────────── */

@media (max-width: 767px) {
  .sg-shop__sidebar {
    width: min(90vw, 340px) !important;
    display: flex;
    flex-direction: column;
    padding-bottom: 76px;              /* room for the apply bar */
    overscroll-behavior: contain;
  }
  .sg-shop__sidebar .sg-filters { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

  .sg-shop__sidebar-head {
    position: sticky; top: 0; z-index: 2;
    background: var(--sg-white, #fff);
    border-bottom: 1px solid var(--sg-border, #dde3ea);
  }
  .sg-shop__sidebar-close { min-width: 40px; min-height: 40px; }

  /* Bigger tap targets on every filter row */
  .sg-check-row,
  .sg-swatch-wrap { min-height: 40px; align-items: center; }
  .sg-panel__btn  { min-height: 46px; }

  /* Persistent "see results" bar so users know how to close the drawer */
  .sg-shop__sidebar::after {
    content: '';
    position: absolute; left: 0; right: 0; bottom: 0; height: 68px;
    background: linear-gradient(to top, var(--sg-white, #fff) 62%, transparent);
    pointer-events: none;
  }
}

/* Scroll lock when the drawer is open (paired with JS class) */
body.sg-drawer-open { overflow: hidden; }


/* ────────────────────────────────────────────────────────────────
   5. ACTIVE FILTER CHIPS — horizontal scroll instead of wrapping
   ──────────────────────────────────────────────────────────────── */

@media (max-width: 767px) {
  .sg-shop__chips,
  .sg-chips {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 10px 12px;
    scroll-snap-type: x proximity;
  }
  .sg-shop__chips::-webkit-scrollbar,
  .sg-chips::-webkit-scrollbar { display: none; }
  .sg-chip { flex: 0 0 auto; scroll-snap-align: start; }
}


/* ────────────────────────────────────────────────────────────────
   6. ACCESSIBILITY FLOOR
   ──────────────────────────────────────────────────────────────── */

.sg-card a:focus-visible,
.sg-card button:focus-visible,
.sg-panel__btn:focus-visible,
.sg-check-row:focus-within,
.wcdd-btn:focus-visible {
  outline: 2px solid var(--sg-red, #e63128);
  outline-offset: 2px;
  border-radius: var(--sg-r-sm, 6px);
}

/* Screen-reader-only checkbox must stay reachable by keyboard */
.sg-sr-only:focus-visible + .sg-checkbox,
.sg-sr-only:focus-visible + .sg-swatch {
  outline: 2px solid var(--sg-red, #e63128);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .sg-card,
  .sg-card__img,
  .wcdd-btn { transition: none !important; }
}


/* ────────────────────────────────────────────────────────────────
   7. LOADING STATE — keep layout stable while AJAX runs
   ──────────────────────────────────────────────────────────────── */

.sg-shop__grid.is-loading,
.sg-grid__inner.is-loading {
  opacity: .45;
  pointer-events: none;
  transition: opacity .18s ease;
}


/* ────────────────────────────────────────────────────────────────
   8. MOBILE DRAWER APPLY BAR (injected by shop.js)
   ──────────────────────────────────────────────────────────────── */

.sg-apply-bar { display: none; }

@media (max-width: 767px) {
  .sg-shop__sidebar::after { content: none; }   /* replaced by the real bar */

  .sg-apply-bar {
    display: flex;
    position: sticky;
    bottom: 0;
    z-index: 3;
    gap: 10px;
    margin-top: auto;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--sg-white, #fff);
    border-top: 1px solid var(--sg-border, #dde3ea);
    box-shadow: 0 -6px 18px rgba(13, 27, 42, .08);
  }
  .sg-shop__sidebar { padding-bottom: 0 !important; }

  .sg-apply-bar__clear,
  .sg-apply-bar__apply {
    min-height: 44px;
    border-radius: var(--sg-r, 8px);
    font-family: inherit;
    font-size: 13px;
    font-weight: 650;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .sg-apply-bar__clear {
    flex: 0 0 auto;
    padding: 0 14px;
    border: 1.5px solid var(--sg-border, #dde3ea);
    background: var(--sg-white, #fff);
    color: var(--sg-mid, #4a5568);
  }
  .sg-apply-bar__apply {
    flex: 1 1 auto;
    border: none;
    background: var(--sg-red, #e63128);
    color: #fff;
  }
  .sg-apply-bar__apply:active { transform: scale(.98); }
}
