/*
 * Storefront components — docs/webshop 06 §15.4–15.10 + §5 (home).
 *
 * The `sh-` (shop) BEM component library: buttons, product card, price block,
 * badges, rating stars, product grid/rail, category tiles, and the home
 * landing sections (hero, trust strip, promo, B2B CTA, empty state).
 *
 * Mobile-first (min-width breakpoints per §3: sm 576, md 768, lg 1024, xl 1280).
 * Extends host theme-base.css (.container, .btn, .section-head, tokens) and
 * shop-tokens.css (--sh-*). Hand-authored, ?v= cache-busted, no preprocessor.
 */

/* =============================================================== *
 * Buttons (extend host .btn — §15.4)
 * =============================================================== */
.sh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sh-space-2);
  min-height: var(--sh-tap);
  padding: 0 var(--sh-space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.1;
  cursor: pointer;
  text-align: center;
  transition: background var(--sh-dur) var(--ease), color var(--sh-dur) var(--ease),
              border-color var(--sh-dur) var(--ease), transform var(--sh-dur) var(--ease);
}
.sh-btn--lg { min-height: 52px; padding-inline: var(--sh-space-6); font-size: 15px; }
.sh-btn--sm { min-height: 36px; padding-inline: var(--sh-space-3); font-size: 13px; }

/* Add-to-cart / primary buy button + state machine (§15.4). */
.sh-btn--buy {
  background: var(--c-blue);
  color: #fff;
  width: 100%;
}
.sh-btn--buy:hover { background: var(--c-blue-d); }
.sh-btn--buy.is-loading { opacity: .85; pointer-events: none; }
.sh-btn--buy.is-success { background: var(--sh-success); }
.sh-btn--buy.is-disabled,
.sh-btn--buy:disabled,
.sh-btn--buy[aria-disabled="true"] {
  background: var(--c-bg-soft);
  color: var(--c-muted);
  cursor: not-allowed;
}

.sh-btn--ghost { background: transparent; border-color: var(--c-border); color: var(--c-text); }
.sh-btn--ghost:hover { background: var(--c-bg-soft); }
.sh-btn--danger { background: transparent; border-color: var(--sh-danger); color: var(--sh-danger); }

/* Text link with trailing chevron (rail "view all"). */
.sh-btn--link {
  display: inline-flex;
  align-items: center;
  gap: var(--sh-space-1);
  color: var(--c-blue);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}
.sh-btn--link:hover { color: var(--c-blue-d); text-decoration: underline; }

/* Global visible focus for all shop interactive controls (never removed). */
.sh-home a:focus-visible,
.sh-home button:focus-visible,
.sh-btn:focus-visible,
.sh-card__link:focus-visible,
.sh-card__wish:focus-visible {
  outline: 2px solid var(--sh-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* =============================================================== *
 * Price block (§15.6)
 * =============================================================== */
.sh-price {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: var(--sh-space-2);
  font-variant-numeric: tabular-nums;
}
.sh-price__row { display: inline-flex; align-items: baseline; gap: var(--sh-space-2); flex-wrap: wrap; }
.sh-price__amount { font-size: 20px; font-weight: 700; color: var(--sh-price); }
.sh-price--lg .sh-price__amount { font-size: clamp(24px, 3vw, 28px); }
.sh-price--sm .sh-price__amount { font-size: 18px; }
.sh-price__from { font-size: 13px; font-weight: 500; color: var(--c-muted); }
/* Tax label — mandatory, explicit on every price surface (§15.6). */
.sh-price__tax { font-size: 12px; font-weight: 500; color: var(--c-muted); }
.sh-price__compare {
  font-size: 14px;
  color: var(--c-muted);
  text-decoration: line-through;
}
.sh-price__secondary { font-size: 12px; color: var(--c-muted); }
.sh-price.is-sale .sh-price__amount { color: var(--sh-sale); }
.sh-price--b2b .sh-price__amount { color: var(--sh-b2b); }

/* =============================================================== *
 * Badges (§15.9)
 * =============================================================== */
.sh-badges {
  position: absolute;
  inset-block-start: var(--sh-space-2);
  inset-inline-start: var(--sh-space-2);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sh-space-1);
  max-width: calc(100% - var(--sh-space-4));
  z-index: 2;
}
.sh-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--sh-radius-pill);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  background: var(--c-bg-soft);
  color: var(--c-text);
  white-space: nowrap;
}
.sh-badge--sale       { background: var(--sh-sale-bg);    color: var(--sh-sale); }
.sh-badge--new        { background: var(--sh-b2b-bg);     color: var(--sh-b2b); }
.sh-badge--low        { background: var(--sh-warning-bg); color: var(--sh-warning); }
/* P10.2c: darkened oos/preorder/backorder badge text to #475467 — the prior
   #667085 / --c-muted (#64748b) fell just under WCAG AA 4.5:1 on the light-grey
   badge backgrounds (#f2f4f7 / --c-bg-soft #f1f4f9 ≈ 4.3–4.4:1); #475467 is ~6.8:1. */
.sh-badge--oos        { background: #f2f4f7;              color: #475467; }
.sh-badge--b2b        { background: var(--sh-b2b-bg);     color: var(--sh-b2b); }
.sh-badge--bestseller { background: var(--sh-warning-bg); color: var(--sh-warning); }
.sh-badge--free-ship  { background: var(--sh-success-bg); color: var(--sh-success); }
.sh-badge--preorder,
.sh-badge--backorder  { background: var(--c-bg-soft);     color: #475467; }
.sh-badge--exclusive  { background: var(--c-navy);        color: #fff; }

/* =============================================================== *
 * Rating stars (§15.10)
 * =============================================================== */
.sh-stars { color: var(--sh-star); font-size: 13px; letter-spacing: 1px; }
.sh-stars .bi { vertical-align: middle; }

/* =============================================================== *
 * Product card (§15.5)
 * =============================================================== */
.sh-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--sh-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: box-shadow var(--sh-dur) var(--ease), transform var(--sh-dur) var(--ease);
}
.sh-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.sh-card__link { display: flex; flex-direction: column; color: inherit; height: 100%; }

.sh-card__media {
  position: relative;
  aspect-ratio: 4 / 5;
  background: var(--c-bg-soft);
  overflow: hidden;
}
.sh-card__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--sh-dur-slow) var(--ease);
}
.sh-card:hover .sh-card__img { transform: scale(1.04); }

.sh-card__body {
  display: flex;
  flex-direction: column;
  gap: var(--sh-space-1);
  padding: var(--sh-space-3);
  flex: 1 1 auto;
}
.sh-card__brand {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--c-muted);
}
.sh-card__title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--c-text);
  /* 2-line clamp */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sh-card__rating {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--c-muted);
}
.sh-card__rating strong { color: var(--c-text); }
.sh-card__desc {
  margin: 0;
  font-size: 13px;
  color: var(--c-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sh-card__actions {
  display: flex;
  align-items: stretch;
  gap: var(--sh-space-2);
  padding: 0 var(--sh-space-3) var(--sh-space-3);
}
.sh-card__actions .sh-card__add { flex: 1 1 auto; }
.sh-card__wish {
  flex: 0 0 auto;
  width: var(--sh-tap);
  height: var(--sh-tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--sh-surface);
  color: var(--c-muted);
  font-size: 18px;
  transition: color var(--sh-dur) var(--ease), border-color var(--sh-dur) var(--ease);
}
.sh-card__wish:hover { color: var(--sh-sale); border-color: var(--sh-sale); }
.sh-card__wish[aria-pressed="true"] { color: var(--sh-sale); border-color: var(--sh-sale); }
.sh-card__wish[aria-pressed="true"] .bi::before { content: "\f417"; } /* bi-heart-fill */

/* =============================================================== *
 * Product grid + horizontal rail (§15.3 / §5)
 * =============================================================== */
.sh-grid {
  display: grid;
  gap: var(--sh-space-3);
  grid-template-columns: repeat(auto-fill, minmax(clamp(150px, 45vw, 240px), 1fr));
}

/* Rail: horizontal scroll-snap on mobile → CSS grid on lg (§5). */
.sh-rail {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(70%, 1fr);
  gap: var(--sh-space-3);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--sh-space-2);
  scrollbar-width: thin;
}
.sh-rail > .sh-card { scroll-snap-align: start; }

/* =============================================================== *
 * Home sections (§5)
 * =============================================================== */
.sh-section { padding-block: var(--sh-space-7); }
.sh-section-head--row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: var(--sh-space-4);
}

/* Hero */
.sh-hero {
  background: linear-gradient(180deg, var(--c-bg-soft) 0%, var(--sh-surface) 100%);
  padding-block: var(--sh-space-7);
}
.sh-hero__inner { display: flex; flex-direction: column; gap: var(--sh-space-5); }
.sh-hero__title { margin-bottom: var(--sh-space-3); }
.sh-hero__sub { font-size: 17px; max-width: 56ch; }
.sh-hero__cta { display: flex; flex-wrap: wrap; gap: var(--sh-space-3); margin-top: var(--sh-space-5); }
.sh-hero__media { display: none; }
.sh-hero__media-inner {
  aspect-ratio: 16 / 10;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--c-blue) 0%, var(--c-navy) 100%);
  box-shadow: var(--shadow);
}

/* Trust strip */
.sh-trust {
  background: var(--sh-surface);
  border-block: 1px solid var(--c-border);
  padding-block: var(--sh-space-5);
}
.sh-trust__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sh-space-4);
}
.sh-trust__item {
  display: flex;
  align-items: center;
  gap: var(--sh-space-3);
  font-size: 14px;
  font-weight: 500;
  color: var(--c-text);
}
.sh-trust__item .bi { font-size: 22px; color: var(--c-blue); flex: 0 0 auto; }

/* Category tiles */
.sh-tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sh-space-3);
}
.sh-tile__link {
  display: flex;
  flex-direction: column;
  gap: var(--sh-space-2);
  color: inherit;
}
.sh-tile__media {
  display: block;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--c-bg-soft);
}
.sh-tile__img { width: 100%; height: 100%; object-fit: cover; transition: transform var(--sh-dur-slow) var(--ease); }
.sh-tile__link:hover .sh-tile__img { transform: scale(1.05); }
.sh-tile__name { font-size: 14px; font-weight: 600; text-align: center; }

/* Promo strip */
.sh-promo {
  display: flex;
  flex-direction: column;
  gap: var(--sh-space-4);
  padding: var(--sh-space-6);
  border-radius: var(--radius-lg);
  background: linear-gradient(120deg, var(--c-navy) 0%, var(--c-blue) 100%);
  color: #fff;
}
.sh-promo__eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; opacity: .85; }
.sh-promo__title { margin: var(--sh-space-2) 0; font-size: clamp(20px, 2.4vw, 28px); }
.sh-promo__sub { margin: 0; opacity: .9; }
.sh-promo .btn-primary { background: #fff; color: var(--c-navy); align-self: flex-start; }
.sh-promo .btn-primary:hover { background: var(--c-bg-soft); }

/* B2B CTA */
.sh-b2b-cta__box {
  display: flex;
  flex-direction: column;
  gap: var(--sh-space-4);
  padding: var(--sh-space-6);
  border-radius: var(--radius-lg);
  background: var(--sh-b2b);
  color: #fff;
}
.sh-b2b-cta__copy h2 { margin-bottom: var(--sh-space-2); }
.sh-b2b-cta__copy p { margin: 0; opacity: .92; }

/* Empty catalog notice */
.sh-empty__box {
  text-align: center;
  padding: var(--sh-space-8) var(--sh-space-4);
  border: 1px dashed var(--c-border);
  border-radius: var(--radius-lg);
  background: var(--c-bg-soft);
}
.sh-empty__box .bi { font-size: 40px; color: var(--c-muted); }
.sh-empty__box h2 { margin: var(--sh-space-3) 0 var(--sh-space-2); }

/* =============================================================== *
 * §12 Modal shell + skeletons + quick-view (audit #02)
 * =============================================================== *
 * shop-quickview.js gradi overlay iz koda (`.sh-modal` > `.sh-modal__scrim` +
 * `.sh-modal__dialog` > `__header`/`__body`) i skeleton u toku učitavanja, ali
 * te klase NIKAD nisu bile stilizovane ni u jednom fajlu teme — modal se zato
 * renderovao kao običan blok na dnu dokumenta (`position: static`, providan,
 * bez z-indexa). Ovo je taj nedostajući sloj.
 *
 * Ugovor sa JS-om (shop-quickview.js): otvoren = `hidden` skinut + `.is-open`
 * dodat u sljedećem frejmu; zatvaranje skida `.is-open`, čeka `transitionend`
 * (fallback 250ms) pa vraća `hidden`. Prelaz mora ostati ≤250ms da se sadržaj
 * ne obriše prije kraja animacije.
 *
 * NAPOMENA: u katalog režimu kartice ne emituju quick-view dugme (audit #02,
 * sh-product-card.php), pa je ovaj blok trenutno neaktivan — postoji da modal
 * bude ispravan onog dana kad se webshop upali. Unutrašnjost fragmenta
 * (`sh-pdp__*`, `sh-gallery__*`) živi u shop-pdp.css, koji PLP/pretraga/shop
 * home tada uslovno učitavaju. */
.sh-modal {
  position: fixed;
  inset: 0;
  z-index: var(--sh-z-modal);
  display: flex;
  align-items: flex-end;              /* mobile: bottom sheet; centriran od sm+ */
  justify-content: center;
  /* `.sh-modal` postavlja display:flex, pa UA pravilo `[hidden]{display:none}`
     gubi — bez ovog reda zatvoren modal ostaje vidljiv. */
}
.sh-modal[hidden] { display: none; }

.sh-modal__scrim {
  position: absolute;
  inset: 0;
  background: var(--sh-overlay);
  opacity: 0;
  transition: opacity var(--sh-dur) var(--ease, ease);
}
.sh-modal.is-open .sh-modal__scrim { opacity: 1; }

.sh-modal__dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: 92vh;
  background: var(--sh-surface);
  border-radius: var(--radius-lg, 12px) var(--radius-lg, 12px) 0 0;
  box-shadow: var(--shadow-lg, 0 -8px 30px rgba(0,0,0,.28));
  transform: translateY(16px);
  opacity: 0;
  transition: transform var(--sh-dur) var(--ease, ease),
              opacity var(--sh-dur) var(--ease, ease);
}
.sh-modal.is-open .sh-modal__dialog { transform: none; opacity: 1; }
.sh-modal__dialog:focus { outline: none; }
.sh-modal__dialog:focus-visible { outline: 2px solid var(--sh-focus); outline-offset: 2px; }

.sh-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sh-space-3);
  padding: var(--sh-space-4);
  border-bottom: 1px solid var(--c-border);
  flex: 0 0 auto;
}
.sh-modal__title {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
  /* Naslov stiže iz fragmenta i zna biti dug (marka + model + godina). */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sh-modal__close {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--sh-tap);
  height: var(--sh-tap);
  border: 0;
  background: transparent;
  color: var(--c-text);
  cursor: pointer;
  border-radius: var(--radius, 8px);
}
.sh-modal__close:hover { background: var(--sh-surface-2); }

.sh-modal__body {
  padding: var(--sh-space-4);
  overflow-y: auto;                   /* dijalog je fiksne visine, tijelo skroluje */
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
}

/* ----- Skeleton (stanje učitavanja dok fragment ne stigne) ----- */
.sh-quickview__loading { display: grid; gap: var(--sh-space-4); }
.sh-skeleton {
  display: block;
  border-radius: var(--radius, 8px);
  background: linear-gradient(90deg,
              var(--sh-surface-2) 25%,
              color-mix(in srgb, var(--sh-surface-2) 60%, var(--c-border)) 37%,
              var(--sh-surface-2) 63%);
  background-size: 400% 100%;
  animation: sh-skeleton-shimmer 1.4s ease infinite;
  min-height: 14px;
}
.sh-skeleton--gallery { aspect-ratio: 4 / 3; min-height: 180px; }
.sh-skeleton-lines { display: grid; gap: var(--sh-space-2); }
.sh-skeleton-lines .sh-skeleton:nth-child(1) { width: 70%; height: 22px; }
.sh-skeleton-lines .sh-skeleton:nth-child(2) { width: 40%; height: 18px; }
.sh-skeleton-lines .sh-skeleton:nth-child(3) { width: 90%; }
@keyframes sh-skeleton-shimmer {
  from { background-position: 100% 50%; }
  to   { background-position: 0 50%; }
}

/* ----- Fragment (shop/product/quickview.php) ----- */
.sh-quickview { display: grid; gap: var(--sh-space-5); }
.sh-quickview__gallery { min-width: 0; }
.sh-quickview__info { display: flex; flex-direction: column; gap: var(--sh-space-3); min-width: 0; }
.sh-quickview__title { margin: 0; font-size: 20px; line-height: 1.3; }
.sh-quickview__short { margin: 0; color: var(--c-muted); }
.sh-quickview__details {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: var(--sh-space-2);
  min-height: var(--sh-tap);
  text-decoration: underline;
}

@media (min-width: 576px) {
  /* Od tableta naviše modal je centriran prozor, ne bottom-sheet. */
  .sh-modal { align-items: center; padding: var(--sh-space-5); }
  .sh-modal__dialog {
    max-width: 960px;
    max-height: 85vh;
    border-radius: var(--radius-lg, 12px);
    transform: translateY(0) scale(.98);
  }
  .sh-modal.is-open .sh-modal__dialog { transform: none; }
}
@media (min-width: 1024px) {
  /* Galerija lijevo, kupovni panel desno — isti raspored kao puni PDP. */
  .sh-quickview { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: var(--sh-space-6); }
  .sh-quickview__loading { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; }
}

@media (prefers-reduced-motion: reduce) {
  /* JS ima `reduceMotion` granu koja zatvara odmah; ovdje samo gasimo prelaze. */
  .sh-modal__scrim,
  .sh-modal__dialog { transition: none; }
  .sh-skeleton { animation: none; }
}

/* =============================================================== *
 * Responsive (min-width, mobile-first — §3)
 * =============================================================== */
@media (min-width: 576px) {
  .sh-rail { grid-auto-columns: minmax(45%, 1fr); }
  .sh-tiles { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 768px) {
  .sh-trust__grid { grid-template-columns: repeat(4, 1fr); }
  .sh-rail { grid-auto-columns: minmax(31%, 1fr); }
  .sh-tiles { grid-template-columns: repeat(4, 1fr); }
  .sh-grid { gap: var(--sh-space-4); }
  .sh-promo,
  .sh-b2b-cta__box { flex-direction: row; align-items: center; justify-content: space-between; }
  .sh-promo .btn-primary,
  .sh-b2b-cta__box .btn { align-self: center; flex: 0 0 auto; }
}

@media (min-width: 1024px) {
  .sh-hero__inner {
    flex-direction: row;
    align-items: center;
  }
  .sh-hero__copy { flex: 1 1 55%; }
  .sh-hero__media { display: block; flex: 1 1 45%; }
  /* Rails become static grids on lg (no horizontal scroll — §5). */
  .sh-rail {
    grid-auto-flow: row;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-columns: auto;
    overflow: visible;
    scroll-snap-type: none;
  }
  .sh-tiles { grid-template-columns: repeat(6, 1fr); }
}

@media (min-width: 1280px) {
  .sh-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

/* Reduced motion — disable non-essential transforms (§15.18). */
@media (prefers-reduced-motion: reduce) {
  .sh-card,
  .sh-card__img,
  .sh-tile__img { transition: none; }
  .sh-card:hover { transform: none; }
  .sh-card:hover .sh-card__img,
  .sh-tile__link:hover .sh-tile__img { transform: none; }
}
