/*
 * COMMAND 3100_062B — Storefront visual foundation
 * Canonical LAST layer for catalog pages (after theme-r2.css).
 * Scope: body.cw-r2 only. Does not redesign homepage/header/card markup.
 *
 * Breakpoints (literal px — custom properties are not used in @media):
 *   compact  <= 480px
 *   mobile   < 768px
 *   tablet   768px–1023px
 *   desktop  >= 1024px
 *   nav      900px (existing theme-r2 hamburger / pd-grid — keep)
 *
 * Legacy still in play (do not delete this phase):
 *   style.css, theme-r1.css, theme-r2.css, inline page CSS,
 *   extra widths 360/380/390/430/520/600/640/1199/1200/1280/1440
 */

/* ── Surfaces ── */
body.cw-r2 {
  background: var(--surface-page);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--type-body);
  line-height: var(--leading-thai);
}

body.cw-r2 .cw-surface-page { background: var(--surface-page); }
body.cw-r2 .cw-surface-elevated {
  background: var(--surface-elevated);
}
body.cw-r2 .cw-surface-card {
  background: var(--surface-card);
  border: 1px solid var(--border-standard);
  border-radius: var(--product-card-radius);
}
body.cw-r2 .cw-surface-subtle { background: var(--surface-subtle); }

/* ── Typography hierarchy (Outfit headings + Prompt body/Thai) ── */
body.cw-r2 .cw-type-display,
body.cw-r2 .cw-hero h1 {
  font-family: var(--font-heading);
  font-size: var(--type-display);
  font-weight: 700;
  line-height: var(--leading-tight);
  color: var(--text-primary);
}
body.cw-r2 .cw-type-h1 { font-family: var(--font-heading); font-size: var(--type-h1); font-weight: 700; line-height: var(--leading-tight); }
body.cw-r2 .cw-type-h2,
body.cw-r2 .cw-r2-section-head {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--text-primary);
}
body.cw-r2 .cw-type-h3 { font-family: var(--font-heading); font-size: var(--type-h3); font-weight: 600; }
body.cw-r2 .cw-type-body { font-family: var(--font-body); font-size: var(--type-body); line-height: var(--leading-thai); }
body.cw-r2 .cw-type-meta,
body.cw-r2 .cw-card-category {
  font-family: var(--font-body);
  font-size: var(--type-meta);
  color: var(--text-secondary);
  line-height: var(--leading-normal);
}
body.cw-r2 .cw-type-product-name,
body.cw-r2 .cw-card-title,
body.cw-r2 .product-card .p-title {
  font-family: var(--font-heading);
  font-size: var(--type-product-name);
  font-weight: 600;
  color: var(--text-primary);
  line-height: var(--leading-thai);
}
body.cw-r2 .cw-type-price,
body.cw-r2 .cw-price-effective {
  font-family: var(--font-heading);
  font-size: var(--type-price);
  font-weight: 700;
  color: var(--price-effective);
}

/* ── Buttons (visual only) ── */
body.cw-r2 .btn {
  min-height: var(--btn-height-md);
  padding-left: var(--btn-padding-x-md);
  padding-right: var(--btn-padding-x-md);
  font-weight: var(--btn-font-weight);
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}
body.cw-r2 .btn-sm {
  min-height: var(--btn-height-md);
  padding-left: var(--btn-padding-x-sm);
  padding-right: var(--btn-padding-x-sm);
  font-size: var(--text-sm);
}
body.cw-r2 .btn-md { min-height: var(--btn-height-md); }
body.cw-r2 .btn-lg {
  min-height: var(--btn-height-lg);
  padding-left: var(--btn-padding-x-lg);
  padding-right: var(--btn-padding-x-lg);
}
body.cw-r2 .btn-primary {
  background-color: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  box-shadow: var(--shadow-sm);
}
body.cw-r2 .btn-primary:hover {
  background-color: var(--btn-primary-hover);
  box-shadow: var(--shadow-md);
  transform: none;
}
body.cw-r2 .btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  border-color: var(--btn-secondary-border);
}
body.cw-r2 .btn-secondary:hover {
  background: rgba(245, 240, 232, 0.05);
  transform: none;
}
body.cw-r2 .btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
body.cw-r2 .btn:disabled,
body.cw-r2 .btn[disabled],
body.cw-r2 .btn.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}
@media (max-width: 767px) {
  body.cw-r2 .btn,
  body.cw-r2 .btn-sm,
  body.cw-r2 .btn-md {
    min-height: 44px;
  }
  body.cw-r2 .btn-lg { min-height: 48px; }
}

/* ── Product card hooks (062D can adopt; existing markup already matches) ── */
body.cw-r2 .cw-product-card,
body.cw-r2 .product-card {
  background: var(--surface-card);
  border-radius: var(--product-card-radius);
}
body.cw-r2 .cw-card-image,
body.cw-r2 .cw-cover-wrap {
  aspect-ratio: var(--product-image-ratio);
}
body.cw-r2 .cw-card-body { display: flex; flex-direction: column; gap: var(--space-2); }
body.cw-r2 .cw-card-cta-area,
body.cw-r2 .cw-card-actions { margin-top: auto; }

/* SKU / stock: style hooks only — empty nodes stay hidden (no fake data) */
body.cw-r2 .cw-card-sku:empty,
body.cw-r2 .cw-stock-status:empty,
body.cw-r2 .cw-promo-badge:empty {
  display: none;
}
body.cw-r2 .cw-card-sku {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}
body.cw-r2 .cw-stock-status {
  font-size: var(--text-xs);
  font-weight: 600;
}
body.cw-r2 .cw-stock-ready { color: var(--stock-ready-fg); }
body.cw-r2 .cw-stock-mto { color: var(--stock-mto-fg); }
body.cw-r2 .cw-stock-low { color: var(--stock-low-fg); }
body.cw-r2 .cw-stock-out { color: var(--stock-out-fg); }

/* ── Pricing visual safety (logic stays in JS/engine) ── */
body.cw-r2 .cw-price-reference,
body.cw-r2 .cw-price-compare {
  color: var(--price-reference);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: line-through;
}
body.cw-r2 .cw-price-normal,
body.cw-r2 .cw-card-price-numeric .cw-price-effective {
  color: var(--price-effective);
}
body.cw-r2 .cw-promo-badge,
body.cw-r2 .cw-sale-badge.cw-sale-discount {
  color: var(--price-promo-fg);
  background: var(--price-promo-bg);
  border: 1px solid var(--price-promo-border);
}
/* INCREASE must never look like a discount even if a compare node is present */
body.cw-r2 [data-price-mode="INCREASE"] .cw-price-compare,
body.cw-r2 [data-price-mode="INCREASE"] .cw-price-reference,
body.cw-r2 [data-price-mode="INCREASE"] .cw-sale-discount,
body.cw-r2 [data-price-mode="INCREASE"] .cw-promo-badge,
body.cw-r2 [data-price-mode="NORMAL"] .cw-price-compare,
body.cw-r2 [data-price-mode="NORMAL"] .cw-promo-badge {
  display: none;
}
body.cw-r2 .cw-card-price-quote .cw-price-effective {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--cw-copper);
  font-family: var(--font-body);
}

@media (max-width: 480px) {
  body.cw-r2 { --product-card-gap: var(--space-3); }
}
@media (max-width: 767px) {
  body.cw-r2 .product-grid,
  body.cw-r2 #product-grid-main {
    gap: var(--product-card-gap);
  }
}
@media (min-width: 768px) and (max-width: 1023px) {
  body.cw-r2 .cw-type-display { font-size: var(--type-h1); }
}
@media (min-width: 1024px) {
  body.cw-r2 .product-grid,
  body.cw-r2 #product-grid-main {
    gap: var(--space-6);
  }
}

/* ═══ COMMAND 3100_062C — Header + Homepage ═══ */
body.cw-r2 {
  overflow-x: hidden;
}
body.cw-r2 .cw-header-062c {
  min-height: 0;
}
body.cw-r2 .cw-header-062c .header-row-utility .header-row-inner {
  min-height: 64px;
  padding-top: var(--space-3);
  padding-bottom: var(--space-3);
}
body.cw-r2 .cw-header-062c .logo-img {
  height: 40px;
  width: 40px;
}
body.cw-r2 .primary-nav.desktop-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-6);
  justify-content: center;
}
body.cw-r2 .primary-nav.desktop-nav a {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  font-size: var(--text-sm);
  letter-spacing: 0.02em;
}
body.cw-r2 .primary-nav.desktop-nav a:focus-visible,
body.cw-r2 .mobile-nav-menu a:focus-visible,
body.cw-r2 .cw-header-cta:focus-visible,
body.cw-r2 .mobile-nav-toggle:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

body.cw-r2 .cw-hero-062c {
  min-height: 56vh;
  max-height: none;
  align-items: center;
  margin-bottom: var(--space-10);
}
body.cw-r2 .cw-hero-062c::before {
  background: linear-gradient(
    105deg,
    rgba(18, 20, 22, 0.62) 0%,
    rgba(18, 20, 22, 0.32) 52%,
    rgba(18, 20, 22, 0.12) 100%
  );
}
body.cw-r2 .cw-hero-062c.cw-image-overlay::after {
  background: linear-gradient(
    180deg,
    rgba(18, 20, 22, 0.18) 0%,
    rgba(18, 20, 22, 0.08) 55%,
    rgba(18, 20, 22, 0.28) 100%
  );
}
body.cw-r2 .cw-hero-062c .cw-hero-actions .btn-secondary {
  background: rgba(18, 20, 22, 0.28);
  border-color: rgba(245, 240, 232, 0.28);
}

body.cw-r2 .cw-shop-cat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-5);
}
body.cw-r2 .cw-shop-cat-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  background: var(--surface-card);
  border: 1px solid var(--border-standard);
  border-radius: var(--product-card-radius);
  overflow: hidden;
  min-height: 100%;
}
body.cw-r2 .cw-shop-cat-card:hover,
body.cw-r2 .cw-shop-cat-card:focus-visible {
  border-color: var(--cw-copper);
}
body.cw-r2 .cw-shop-cat-visual {
  aspect-ratio: var(--product-image-ratio);
  background-size: cover;
  background-position: center;
  background-color: var(--surface-subtle);
}
body.cw-r2 .cw-shop-cat-copy {
  padding: var(--space-4);
}
body.cw-r2 .cw-shop-cat-copy h3 {
  font-family: var(--font-heading);
  font-size: var(--text-base);
  margin: 0 0 var(--space-2);
  color: var(--text-primary);
}
body.cw-r2 .cw-shop-cat-copy p {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--leading-thai);
}

body.cw-r2 .cw-featured-section .cw-featured-grid {
  gap: var(--space-6);
}
body.cw-r2 .cw-featured-section .cw-cover-wrap {
  min-height: 0;
}
body.cw-r2 .cw-custom-made-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-4);
}
body.cw-r2 .cw-custom-made-copy .btn {
  min-height: 44px;
}
body.cw-r2 .cw-custom-made-steps {
  display: grid;
  gap: var(--space-4);
}
body.cw-r2 .cw-closer-actions {
  justify-content: center;
}
body.cw-r2 .main-footer .footer-grid {
  gap: var(--space-10);
}
body.cw-r2 .main-footer h4 {
  font-family: var(--font-heading);
  color: var(--text-primary);
  margin-bottom: var(--space-3);
}

@media (max-width: 1023px) {
  body.cw-r2 .cw-shop-cat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  body.cw-r2 .header-row-nav {
    display: none;
  }
  body.cw-r2 .mobile-nav-toggle {
    display: flex;
    width: 44px;
    height: 44px;
    min-height: 44px;
  }
}
@media (max-width: 767px) {
  body.cw-r2 .cw-hero-062c {
    min-height: 0;
    align-items: flex-end;
  }
  body.cw-r2 .cw-hero-062c .cw-hero-content {
    padding: var(--space-8) var(--space-4) var(--space-8);
  }
  body.cw-r2 .cw-hero-062c .cw-hero-subtitle {
    font-size: var(--text-base);
    margin-bottom: var(--space-5);
  }
  body.cw-r2 .cw-process-timeline {
    grid-template-columns: 1fr;
  }
  body.cw-r2 .cw-process-timeline .cw-process-step {
    border-top: none;
    border-left: 2px solid rgba(184, 115, 51, 0.45);
    padding-left: var(--space-4);
  }
  body.cw-r2 .cw-closer-actions {
    flex-direction: column;
    align-items: stretch;
  }
  body.cw-r2 .cw-closer-actions .btn {
    width: 100%;
    min-height: 44px;
  }
  body.cw-r2 .cw-mobile-sticky-cta .sticky-primary,
  body.cw-r2 .cw-mobile-sticky-cta a {
    min-height: 44px;
  }
}
@media (max-width: 480px) {
  body.cw-r2 .cw-header-cta {
    display: none;
  }
  body.cw-r2 .cw-shop-cat-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
  }
  body.cw-r2 .cw-shop-cat-copy {
    padding: var(--space-3);
  }
  body.cw-r2 .cw-hero-062c .cw-hero-actions .btn {
    min-height: 44px;
  }
}
@media (prefers-reduced-motion: reduce) {
  body.cw-r2 .cw-shop-cat-card,
  body.cw-r2 .cw-hero-062c {
    transition: none;
  }
}

/* ═══ COMMAND 3100_062D — Canonical product card + listing ═══ */
body.cw-r2 .product-card,
body.cw-r2 .cw-product-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  overflow: hidden;
}
body.cw-r2 .cw-listing-card-link {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
body.cw-r2 .product-card .cw-cover-wrap,
body.cw-r2 .cw-listing-cover {
  aspect-ratio: var(--product-image-ratio, var(--product-cover-ratio, 4 / 5));
  min-height: 0;
  overflow: hidden;
  background: var(--surface-subtle);
}
body.cw-r2 .product-card .cw-cover-img,
body.cw-r2 .product-card .p-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}
body.cw-r2 .cw-card-title,
body.cw-r2 .cw-card-title-clamp {
  font-family: var(--font-heading);
  font-weight: 650;
  color: var(--text-primary);
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}
body.cw-r2 .cw-card-category {
  font-size: var(--text-xs, 0.72rem);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
body.cw-r2 .cw-card-cta,
body.cw-r2 .card-detail-btn.cw-card-cta {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  pointer-events: none;
}
body.cw-r2 .cw-discovery-select.is-filtered {
  border-color: var(--cw-copper, #B87333);
  box-shadow: 0 0 0 1px rgba(184, 115, 51, 0.35);
}
body.cw-r2 .cw-listing-result-count,
body.cw-r2 .cw-listing-filter-state {
  margin: var(--space-3) 0 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
body.cw-r2.cw-listing-page #product-grid-main {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-6);
  align-items: stretch;
}
@media (max-width: 1279px) {
  body.cw-r2.cw-listing-page #product-grid-main {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (max-width: 1023px) {
  body.cw-r2.cw-listing-page #product-grid-main {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-4);
  }
}
@media (max-width: 767px) {
  body.cw-r2.cw-listing-page #product-grid-main {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
  }
  body.cw-r2 .cw-card-title-clamp {
    font-size: 0.92rem;
  }
  body.cw-r2 .cw-card-price-numeric .cw-price-effective {
    font-size: 1.05rem;
  }
}
@media (max-width: 480px) {
  body.cw-r2.cw-listing-page #product-grid-main {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
  }
  body.cw-r2 .cw-card-cta {
    font-size: 0.82rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
}
@media (max-width: 380px) {
  body.cw-r2.cw-listing-page #product-grid-main {
    grid-template-columns: 1fr;
  }
}
@media (hover: hover) and (pointer: fine) {
  body.cw-r2 .product-card .cw-cover-img {
    transition: transform 0.35s ease;
  }
  body.cw-r2 .product-card:hover .cw-cover-img {
    transform: scale(1.03);
  }
}
@media (prefers-reduced-motion: reduce) {
  body.cw-r2 .product-card .cw-cover-img {
    transition: none !important;
    transform: none !important;
  }
}
