/*
 * CraftWorks Theme R1 — Layout & Component Overrides
 * M-WEB-THEME-R1 | Premium Modern Industrial Storefront
 */

/* ── Base overrides ── */
html {
  background-color: var(--cw-graphite);
}

body {
  background-color: var(--cw-graphite);
  color: var(--cw-text);
  line-height: var(--leading-thai);
  overflow-x: hidden;
}

/* Remove heavy glow from buttons */
.btn-primary {
  background-color: var(--btn-primary-bg);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  background-color: var(--btn-primary-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* ══════════════════════════════════════
   HEADER — 2-Row Layout (P0 Fix)
   Root cause: single-row flex squeezed logo,
   search, actions + search-tags into one band;
   mobile stacked column caused overlap.
   ══════════════════════════════════════ */

.top-navbar {
  background-color: var(--cw-graphite);
  border-bottom: var(--border-default);
  padding: var(--space-2) 0;
  font-size: var(--text-xs);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background-color: var(--cw-charcoal);
  border-bottom: var(--border-default);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-normal);
}

.site-header.scrolled {
  box-shadow: var(--shadow-md);
}

/* Row 1: Brand / Search / Actions */
.header-row-utility {
  border-bottom: var(--border-default);
}

.header-row-utility .header-row-inner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-6);
  min-height: var(--header-row1-height);
  padding-top: var(--space-3);
  padding-bottom: var(--space-3);
}

/* Logo */
.site-header .logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: var(--cw-text);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: var(--text-xl);
  letter-spacing: 0.02em;
  flex-shrink: 0;
  min-width: 0;
}

.site-header .logo-img {
  height: 40px;
  width: 40px;
  border-radius: var(--radius-md);
  border: var(--border-default);
  object-fit: contain;
}

.site-header .logo-text {
  white-space: nowrap;
  line-height: var(--leading-tight);
}

.site-header .logo .accent {
  color: var(--cw-copper);
}

.logo-attribution {
  display: block;
  font-size: 0.625rem;
  font-weight: 400;
  color: var(--cw-text-subtle);
  letter-spacing: 0.03em;
  line-height: var(--leading-normal);
  margin-top: 2px;
}

/* Search */
.site-header .search-wrapper {
  flex: 1;
  min-width: 0;
  max-width: 560px;
  justify-self: center;
  width: 100%;
  position: relative;
}

.site-header .search-box {
  display: flex;
  align-items: center;
  background: var(--cw-graphite);
  border: var(--border-strong);
  border-radius: var(--radius-md);
  padding: 2px;
  position: relative;
}

.site-header .search-box:focus-within {
  border-color: var(--cw-copper);
  box-shadow: none;
}

.site-header .search-box input {
  flex: 1;
  min-width: 0;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  line-height: var(--leading-thai);
}

#image-search-btn {
  background: transparent;
  color: var(--cw-text-muted);
  padding: var(--space-2);
  font-size: 0;
  height: auto;
  margin: 0;
  border-radius: var(--radius-sm);
  flex-direction: row;
  gap: 0;
}
#image-search-btn svg {
  width: 18px;
  height: 18px;
}
#image-search-btn:hover {
  background: rgba(255,255,255,0.05);
  transform: none;
  color: var(--cw-copper);
}

.search-box button#global-search-btn {
  background: var(--cw-copper);
  color: var(--cw-text);
  padding: 0 var(--space-4);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
  min-height: 36px;
}
.search-box button#global-search-btn:hover {
  background: var(--cw-copper-hover);
}

/* Hide search tags on header — move to nav row context */
.site-header .search-tags {
  display: none;
}

/* Header actions */
.header-actions-group {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-shrink: 0;
}

.header-action-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--cw-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-1);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  transition: color var(--transition-fast);
  min-width: 44px;
}

.header-action-item:hover {
  color: var(--cw-text);
}

.header-action-item .action-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.header-action-item .action-label {
  font-size: 0.625rem;
  white-space: nowrap;
}

/* Row 2: Primary Navigation */
.header-row-nav {
  background: var(--cw-charcoal);
}

.logo-text-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.primary-nav.desktop-nav li {
  list-style: none;
  flex-shrink: 0;
}

.header-row-nav .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.primary-nav.desktop-nav {
  display: flex;
  align-items: center;
  gap: var(--nav-gap);
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.primary-nav.desktop-nav::-webkit-scrollbar {
  display: none;
}

.primary-nav.desktop-nav a {
  color: var(--nav-link-color);
  text-decoration: none;
  font-size: var(--nav-link-size);
  font-weight: 500;
  padding: var(--space-2) 0;
  white-space: nowrap;
  line-height: var(--leading-thai);
  position: relative;
  transition: color var(--transition-fast);
  flex-shrink: 0;
}

.primary-nav.desktop-nav a:hover,
.primary-nav.desktop-nav a.active {
  color: var(--nav-link-active);
}

.primary-nav.desktop-nav a::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--cw-copper);
  transition: width var(--transition-fast);
}
.primary-nav.desktop-nav a:hover::after,
.primary-nav.desktop-nav a.active::after {
  width: 100%;
}

.nav-search-tags {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
  flex-shrink: 0;
  padding-left: var(--space-4);
}

.nav-search-tags .search-tag-label {
  font-size: var(--text-xs);
  color: var(--cw-text-subtle);
  white-space: nowrap;
}

.nav-search-tags .search-tag-link {
  font-size: var(--text-xs);
  color: var(--cw-text-muted);
  text-decoration: none;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  border: var(--border-default);
  white-space: nowrap;
  line-height: var(--leading-normal);
  transition: all var(--transition-fast);
}
.nav-search-tags .search-tag-link:hover {
  color: var(--cw-copper);
  border-color: var(--cw-copper);
}

/* Mobile menu toggle */
.mobile-nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  background: transparent;
  border: var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
  padding: 10px;
  flex-shrink: 0;
}

.mobile-nav-toggle span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--cw-text);
  transition: all var(--transition-fast);
}

.mobile-nav-toggle.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.mobile-nav-toggle.open span:nth-child(2) {
  opacity: 0;
}
.mobile-nav-toggle.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Mobile drawer */
.mobile-nav-menu {
  position: fixed;
  top: 0;
  right: -100%;
  width: min(320px, 85vw);
  height: 100vh;
  height: 100dvh;
  background: var(--cw-charcoal);
  z-index: 1001;
  padding: calc(var(--header-row1-height) + var(--space-8)) var(--space-6) var(--space-6);
  box-shadow: var(--shadow-lg);
  transition: right var(--transition-normal);
  border-left: var(--border-default);
  overflow-y: auto;
}

.mobile-nav-menu.open {
  right: 0;
}

.mobile-nav-menu ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.mobile-nav-menu a {
  display: block;
  color: var(--cw-text-muted);
  text-decoration: none;
  font-size: var(--text-base);
  font-weight: 500;
  padding: var(--space-3) var(--space-2);
  line-height: var(--leading-thai);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.mobile-nav-menu a:hover {
  color: var(--cw-text);
  background: rgba(255,255,255,0.04);
}

.mobile-nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}
.mobile-nav-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* Legacy header class compatibility */
.header {
  position: static;
  padding: 0;
  border: none;
  box-shadow: none;
  background: transparent;
}

.header-container {
  display: contents;
}

.header-actions-wrapper {
  display: contents;
}

/* ══════════════════════════════════════
   HERO — Premium Storefront
   ══════════════════════════════════════ */

.cw-hero {
  position: relative;
  min-height: 520px;
  display: flex;
  align-items: flex-end;
  padding: var(--space-16) var(--container-padding) var(--space-12);
  margin-bottom: var(--space-10);
  border-radius: var(--radius-xl);
  overflow: hidden;
  background-size: cover;
  background-position: center;
  border: var(--border-default);
}

.cw-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top,
    rgba(26, 29, 33, 0.95) 0%,
    rgba(26, 29, 33, 0.55) 45%,
    rgba(26, 29, 33, 0.25) 100%
  );
  z-index: 1;
}

.cw-hero-content {
  position: relative;
  z-index: 2;
  max-width: 640px;
}

.cw-hero-badge {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  background: var(--cw-gold-muted);
  border: 1px solid rgba(201, 162, 39, 0.35);
  color: var(--cw-gold);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-5);
}

.cw-hero h1 {
  font-size: clamp(2rem, 4vw, var(--text-5xl));
  font-weight: 700;
  line-height: var(--leading-tight);
  color: var(--cw-text);
  margin-bottom: var(--space-4);
}

.cw-hero-subtitle {
  font-size: var(--text-lg);
  color: var(--cw-text-muted);
  line-height: var(--leading-thai);
  margin-bottom: var(--space-8);
  max-width: 520px;
}

.cw-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: center;
}

.cw-hero-actions .btn-primary {
  padding: var(--space-3) var(--space-8);
  font-size: var(--text-base);
}

.cw-hero-actions .btn-secondary {
  border-color: var(--cw-border-strong);
  color: var(--cw-text-muted);
  padding: var(--space-3) var(--space-6);
}
.cw-hero-actions .btn-secondary:hover {
  color: var(--cw-text);
  border-color: var(--cw-text-muted);
}

/* Hero feature cards row */
.cw-hero-features {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-10);
}

.cw-feature-card {
  position: relative;
  min-height: 160px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background-size: cover;
  background-position: center;
  border: var(--border-default);
  display: flex;
  align-items: flex-end;
  padding: var(--space-5);
  text-decoration: none;
  color: var(--cw-text);
  transition: transform var(--transition-normal);
}

.cw-feature-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(26,29,33,0.9), rgba(26,29,33,0.3));
}

.cw-feature-card:hover {
  transform: translateY(-2px);
}

.cw-feature-card-content {
  position: relative;
  z-index: 1;
}

.cw-feature-card h3 {
  font-size: var(--text-base);
  font-weight: 600;
  line-height: var(--leading-thai);
  margin-bottom: var(--space-1);
}

.cw-feature-card p,
.cw-feature-card .banner-link {
  font-size: var(--text-xs);
  color: var(--cw-text-muted);
  line-height: var(--leading-thai);
}

.cw-feature-card .banner-link {
  color: var(--cw-copper);
  font-weight: 600;
}

/* Hide old banner grid when hero is present */
.banner-grid.cw-replaced {
  display: none;
}

/* ══════════════════════════════════════
   CATEGORY / QUICK ICONS
   ══════════════════════════════════════ */

.quick-icons {
  background: var(--cw-charcoal);
  border: var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-4);
  margin-bottom: var(--space-10);
  box-shadow: none;
  gap: var(--space-4);
}

.icon-item {
  width: auto;
  flex: 1 1 100px;
  min-width: 80px;
  max-width: 120px;
}

.icon-circle {
  width: 56px;
  height: 56px;
  background: var(--cw-graphite);
  border: var(--border-default);
  border-radius: var(--radius-lg);
  font-size: 1.5rem;
  margin-bottom: var(--space-2);
  transition: border-color var(--transition-fast), transform var(--transition-fast);
}

.icon-item:hover .icon-circle {
  border-color: var(--cw-copper);
  transform: translateY(-2px);
}

.icon-text {
  font-size: var(--text-xs);
  color: var(--cw-text-muted);
  line-height: var(--leading-thai);
}

/* ══════════════════════════════════════
   PRODUCT CARDS
   ══════════════════════════════════════ */

.section-header {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--cw-text);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-3);
  border-bottom: var(--border-default);
  letter-spacing: 0.02em;
}

.product-grid {
  gap: var(--space-5);
  margin-bottom: var(--space-12);
}

.product-card {
  background: var(--cw-charcoal);
  border: var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: box-shadow var(--transition-normal), transform var(--transition-normal);
}

.product-card:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-2px);
  border-color: var(--cw-border-strong);
}

.product-card .card-img-wrap {
  aspect-ratio: 4 / 3;
  overflow: hidden;
}

.product-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-normal);
}

.product-card:hover img {
  transform: scale(1.03);
}

.product-card .card-body {
  padding: var(--space-4);
}

.product-card .card-title {
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: var(--leading-thai);
  color: var(--cw-text);
  margin-bottom: var(--space-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-card .card-price {
  color: var(--cw-copper);
  font-weight: 700;
  font-size: var(--text-base);
  margin-bottom: var(--space-3);
}

.card-quote-btn {
  border-radius: var(--radius-md);
  background: transparent;
  border: var(--border-strong);
  color: var(--cw-text-muted);
  transition: all var(--transition-fast);
}
.card-quote-btn:hover {
  border-color: var(--cw-copper);
  color: var(--cw-copper);
  background: rgba(184, 115, 51, 0.08);
}

/* Trust features — cleaner cards */
.trust-features-section {
  margin-bottom: var(--space-10);
}

.trust-card {
  background: var(--cw-charcoal);
  border: var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: none;
}

.trust-card.glassmorphism {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.trust-icon-box {
  color: var(--cw-copper);
}

.trust-info h4 {
  font-size: var(--text-sm);
  line-height: var(--leading-thai);
}

.trust-info p {
  font-size: var(--text-xs);
  line-height: var(--leading-thai);
}

/* Footer brand update */
.footer-brand-info .footer-logo span {
  color: var(--cw-copper);
}

.footer-attribution {
  font-size: var(--text-xs);
  color: var(--cw-text-subtle);
  margin-top: var(--space-2);
  line-height: var(--leading-thai);
}

.main-container {
  margin-top: var(--space-8);
  padding: 0 var(--container-padding);
}

/* ══════════════════════════════════════
   RESPONSIVE — 1440 / 768 / 375
   ══════════════════════════════════════ */

@media (max-width: 1024px) {
  .nav-search-tags {
    display: none;
  }

  .primary-nav.desktop-nav {
    gap: var(--space-4);
  }
}

@media (max-width: 768px) {
  .top-navbar {
    display: none;
  }

  .header-row-utility .header-row-inner {
    grid-template-columns: auto 1fr auto auto;
    gap: var(--space-3);
    min-height: 56px;
    padding-top: var(--space-2);
    padding-bottom: var(--space-2);
  }

  .site-header .logo-text {
    font-size: var(--text-base);
  }

  .logo-attribution {
    display: none;
  }

  .site-header .logo-img {
    height: 32px;
    width: 32px;
  }

  /* Compact search — icon expands on focus */
  .site-header .search-wrapper {
    max-width: none;
    grid-column: 1 / -1;
    order: 10;
    display: none;
  }

  .site-header.search-expanded .search-wrapper {
    display: block;
    grid-column: 1 / -1;
    order: 10;
  }

  .header-action-search-toggle {
    display: flex;
  }

  .header-row-nav {
    display: none;
  }

  .mobile-nav-toggle {
    display: flex;
  }

  /* Hide verbose action labels on mobile */
  .header-action-item .action-label {
    display: none;
  }

  .header-actions-group {
    gap: var(--space-2);
  }

  .cw-hero {
    min-height: 400px;
    padding: var(--space-10) var(--space-4) var(--space-8);
  }

  .cw-hero-features {
    grid-template-columns: 1fr;
  }

  .quick-icons {
    justify-content: flex-start;
  }

  .icon-item {
    flex: 0 0 calc(25% - var(--space-3));
    min-width: 70px;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0 var(--space-4);
  }

  /* Mobile compact: CraftWorks / Search / Cart / Menu */
  #contact-admin-btn {
    display: none;
  }

  .icon-item {
    flex: 0 0 calc(33.333% - var(--space-2));
  }

  .cw-hero h1 {
    font-size: var(--text-2xl);
  }

  .cw-hero-subtitle {
    font-size: var(--text-sm);
  }

  .cw-hero-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .cw-hero-actions .btn {
    width: 100%;
    justify-content: center;
  }
}

/* Desktop: hide mobile-only controls */
@media (min-width: 769px) {
  .header-action-search-toggle {
    display: none;
  }

  .mobile-nav-overlay {
    display: none;
  }
}
