:root {
  --bg: #14161a;
  --bg-alt: #1c1f26;
  --card: #21242b;
  --card-hover: #262a33;
  --gold: #a855f7;
  --gold-dark: #8b3fe0;
  --text: #f1f2f4;
  --text-dim: #9aa0ab;
  --border: #2e323b;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Kanit', sans-serif;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
/* Pushes .site-footer to the bottom of the viewport on short pages instead of floating
   right under the content \u2014 <main> grows to fill leftover space, footer stays after it. */
main { flex: 1 0 auto; }

a { text-decoration: none; color: inherit; }
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; border: none; }

/* ===== HEADER ===== */
.site-header {
  background: var(--bg-alt);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.logo { display: flex; flex-direction: column; line-height: 1; flex-shrink: 0; }
.logo-main { font-size: 24px; font-weight: 700; color: var(--gold); letter-spacing: 1px; }
.logo-sub { font-size: 10px; letter-spacing: 3px; color: var(--text-dim); }
.logo-img { height: 40px; width: auto; display: block; }
.footer-logo .logo-img { height: 36px; }

.search-bar {
  flex: 1;
  max-width: 560px;
  display: flex;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 4px 4px 18px;
}
.search-bar input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}
.search-bar input::placeholder { color: var(--text-dim); }
.search-bar button {
  background: var(--gold);
  color: #14161a;
  border-radius: 999px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-actions { display: flex; align-items: center; gap: 20px; flex-shrink: 0; margin-left: auto; }
.header-link, .cart-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  transition: color .15s;
  white-space: nowrap;
}
.header-link:hover, .cart-link:hover { color: var(--gold); }
.cart-link { position: relative; }
.cart-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--gold);
  color: #14161a;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

/* ===== Cart page ===== */
.cart-empty { text-align: center; padding: 60px 24px; color: var(--text-dim); }
.cart-empty p { margin-bottom: 16px; font-size: 15px; }
.cart-list { display: flex; flex-direction: column; gap: 12px; }
.cart-row {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.cart-row .ph-box { width: 64px; height: 64px; flex-shrink: 0; border-radius: 8px; overflow: hidden; }
.cart-row-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.cart-row-name { font-size: 14px; color: var(--text); }
.cart-row-name:hover { color: var(--gold); }
.cart-row-price { font-size: 12.5px; color: var(--text-dim); }
.cart-qty { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.qty-btn {
  width: 26px; height: 26px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--card-hover);
  color: var(--text); font-size: 15px; cursor: pointer;
}
.qty-btn:hover { background: var(--gold); color: #14161a; }
.qty-val { min-width: 18px; text-align: center; font-size: 14px; }
.qty-btn:disabled { opacity: .4; cursor: not-allowed; }
.qty-btn:disabled:hover { background: var(--card-hover); color: var(--text); }
.cart-row-stock { font-size: 11.5px; color: var(--text-dim); }
.cart-row-total { width: 90px; text-align: right; font-size: 14px; font-weight: 600; color: var(--gold); flex-shrink: 0; }
.cart-remove {
  background: none; border: none; color: var(--text-dim); font-size: 16px;
  cursor: pointer; flex-shrink: 0; padding: 4px 8px;
}
.cart-remove:hover { color: #ef4444; }
.cart-summary {
  margin-top: 24px;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  text-align: center;
}
.cart-summary-row { display: flex; gap: 12px; font-size: 16px; font-weight: 600; }
.cart-note { font-size: 12px; color: var(--text-dim); text-align: center; max-width: 380px; }
.cart-code-box { width: 100%; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.cart-code-label { font-size: 12.5px; color: var(--text-dim); text-align: center; }
.cart-code-input {
  width: 100%;
  max-width: 320px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--gold);
  font-family: monospace;
  font-size: 14px;
  text-align: center;
}
@media (max-width: 720px) {
  .cart-row { flex-wrap: wrap; }
  .cart-row-info { order: 1; flex-basis: 100%; }
}

.main-nav { background: var(--bg); border-top: 1px solid var(--border); }
.nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  justify-content: center;
  gap: 28px;
  overflow-x: auto;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none;
}
.nav-inner::-webkit-scrollbar { display: none; } /* Chrome/Safari/Edge */
.nav-inner a {
  font-size: 14px;
  padding: 12px 2px;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all .15s;
}
.nav-inner a:hover, .nav-inner a.active {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

/* ===== HERO ===== */
.hero {
  max-width: 1280px;
  margin: 24px auto 0;
  padding: 0 24px;
  position: relative;
}
.hero-slide {
  background: linear-gradient(120deg, #23272f 0%, #1a1d23 100%);
  border-radius: 20px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 48px 56px;
  min-height: 280px;
  overflow: hidden;
}
.hero-text h1 {
  font-size: 34px;
  font-weight: 700;
  margin-bottom: 14px;
  line-height: 1.3;
  white-space: pre-line;
}
.hero-text p { color: var(--text-dim); margin-bottom: 22px; font-size: 15px; }
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--gold);
  color: #14161a;
  font-weight: 600;
  padding: 12px 26px;
  border-radius: 999px;
  font-size: 14px;
  transition: background .15s;
}
.btn-primary:hover { background: var(--gold-dark); }
.hero-image {
  position: relative;
  width: 320px;
  aspect-ratio: 4 / 3;
  flex-shrink: 0;
  border-radius: 14px;
  overflow: hidden;
}
/* position:absolute + inset:0 (not height:100%) — percentage heights don't reliably resolve
   against a parent whose height comes only from aspect-ratio in some browser engines. */
.hero-image img { position: absolute; inset: 0; border-radius: 14px; width: 100%; height: 100%; object-fit: cover; }
/* renderHero() wraps the img in a .ph-box (shared placeholder component), which only sets
   width:100% — its own height still collapses to 0 since the img inside is absolutely
   positioned (contributes nothing to auto content height). Pin it to fill .hero-image instead. */
.hero-image .ph-box { position: absolute; inset: 0; width: auto; border-radius: 14px; }

.hero-arrows { position: absolute; top: 50%; left: 0; right: 0; display: flex; justify-content: space-between; transform: translateY(-50%); padding: 0 8px; pointer-events: none; }
.hero-arrows button {
  pointer-events: all;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(20,22,26,0.7);
  color: #fff;
  font-size: 20px;
  border: 1px solid var(--border);
}
.hero-dots { display: flex; justify-content: center; gap: 8px; margin-top: 16px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); cursor: pointer; }
.dot.active { background: var(--gold); width: 22px; border-radius: 4px; }

/* ===== PROMO CARDS ===== */
.promo-cards {
  max-width: 1280px;
  margin: 24px auto 0;
  padding: 0 24px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.promo-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: transform .15s, background .15s;
}
.promo-card:hover { transform: translateY(-3px); background: var(--card-hover); }
.promo-thumb { margin-bottom: 10px; }
.promo-title { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.promo-title strong { color: var(--gold); }
.promo-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 12px; }
.promo-link { color: var(--gold); font-size: 13px; font-weight: 500; }

/* ===== SECTIONS ===== */
.section { max-width: 1280px; margin: 44px auto 0; padding: 0 24px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.section-head h2 { font-size: 20px; font-weight: 600; }
.see-all { color: var(--gold); font-size: 13px; }

/* categories — always a single sliding row (auto-marquee, see initMarquees() in site.js) at
   every screen size, not just mobile: fixed-width items + flex nowrap guarantee it overflows
   its box so there's always something to slide, instead of CSS grid which just fits everything
   and never moves. overflow-x:auto (not hidden) keeps manual swipe/drag working too. */
.category-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: 14px;
  overflow-x: auto;
  scrollbar-width: none; /* Firefox */
}
.category-grid::-webkit-scrollbar { display: none; } /* Chrome/Safari/Edge */
.category-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 10px;
  text-align: center;
  transition: background .15s, transform .15s;
  flex: 0 0 130px;
}
.category-item:hover { background: var(--card-hover); transform: translateY(-2px); }
.category-item span { font-size: 12.5px; color: var(--text-dim); display: block; margin-top: 8px; }

/* brand row — same always-sliding treatment as categories above. */
.brand-row {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  scrollbar-width: none; /* Firefox */
}
.brand-row::-webkit-scrollbar { display: none; } /* Chrome/Safari/Edge */
.brand-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 22px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-dim);
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.brand-item:hover { color: var(--gold); border-color: var(--gold); }

/* products */
.product-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px; }
.product-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: transform .15s, background .15s;
}
.product-card:hover { transform: translateY(-3px); background: var(--card-hover); }
.product-name { font-size: 13.5px; font-weight: 500; margin: 10px 0 6px; min-height: 38px; }
.product-desc {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.product-rating { font-size: 12px; color: var(--gold); margin-bottom: 10px; }
.product-bottom { display: flex; justify-content: space-between; align-items: center; }
.product-price { font-weight: 600; color: var(--gold); font-size: 15px; }
.add-cart {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 32px; height: 32px;
  color: var(--text);
  font-size: 14px;
}
.add-cart:hover { background: var(--gold); color: #14161a; }
.add-cart.out-of-stock, .add-cart:disabled { opacity: .5; cursor: not-allowed; background: none; }
.add-cart.out-of-stock:hover { background: none; color: inherit; }
.detail-stock { font-size: 13px; color: var(--text-dim); margin: 8px 0; }
.detail-stock.out { color: #ef4444; }

/* news */
.news-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.news-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background .15s;
}
.news-card:hover { background: var(--card-hover); }
.news-body { padding: 16px; }
.news-body p { font-size: 14px; margin-bottom: 8px; }
.news-date { font-size: 12px; color: var(--text-dim); }

/* knowledge */
.knowledge-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.knowledge-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: background .15s;
}
.knowledge-card:hover { background: var(--card-hover); }
.tag { display: inline-block; font-size: 11px; padding: 3px 10px; border-radius: 999px; margin-bottom: 10px; font-weight: 500; }
.tag.green { background: rgba(72,199,116,0.15); color: #48c774; }
.tag.yellow { background: rgba(168,85,247,0.15); color: var(--gold); }
.tag.red { background: rgba(224,80,80,0.15); color: #e05050; }
.knowledge-card p { font-size: 13.5px; }

/* ===== FOOTER ===== */
.site-footer { margin-top: 60px; background: var(--bg-alt); border-top: 1px solid var(--border); padding: 44px 24px 20px; }
.footer-grid { max-width: 1280px; margin: 0 auto; display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 32px; }
.footer-col h4 { font-size: 14px; margin-bottom: 14px; color: var(--text); }
.footer-col a, .footer-col p { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }
.footer-col a:hover { color: var(--gold); }
.brand-col p { max-width: 260px; margin-top: 10px; }
.footer-logo { margin-bottom: 4px; }
.qr-box { width: 64px; height: 64px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--text-dim); margin-top: 8px; }
.footer-bottom { max-width: 1280px; margin: 32px auto 0; padding-top: 18px; border-top: 1px solid var(--border); display: flex; justify-content: center; text-align: center; font-size: 12px; color: var(--text-dim); flex-wrap: wrap; gap: 8px; }

/* ===== SHARED IMAGE / "?" PLACEHOLDER BOX (same visual language as Dashboard) ===== */
.ph-box {
  position: relative;
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ph-box img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.ph-box .ph-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
}
.ph-box .qmark {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid currentColor;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  animation: phPulse 2.4s ease-in-out infinite;
}
@keyframes phPulse {
  0%, 100% { transform: scale(1); opacity: .75; }
  50% { transform: scale(1.08); opacity: 1; }
}
.ph-box .ph-txt { font-size: 10px; }

/* Aspect ratios below match the "แนะนำ WxH" upload hint shown in the dashboard for each
   section (data.js SECTIONS[...].imgHint) — height now derives from width instead of being a
   fixed px value, so an uploaded photo actually fills the card the way it looked when picked,
   not squished/cropped into an unrelated flat box. */
.cat-icon.ph-box, .promo-thumb.ph-box { aspect-ratio: 1 / 1; height: auto; margin-bottom: 8px; }
.promo-thumb.ph-box { width: 48px; margin: 0 0 10px; }
.brand-item .ph-box { width: 26px; height: 26px; flex-shrink: 0; }
.brand-item .ph-box .qmark { width: 18px; height: 18px; font-size: 10px; border-width: 1.5px; }
.brand-item .ph-box .ph-txt { display: none; }
.product-thumb.ph-box { aspect-ratio: 1 / 1; height: auto; } /* matches 800×800 product upload hint */
.news-thumb.ph-box { aspect-ratio: 16 / 9; height: auto; } /* matches 800×450 news upload hint */
.knowledge-card .ph-box { aspect-ratio: 4 / 3; height: auto; margin-bottom: 12px; } /* matches 600×450 knowledge hint */

/* ===== LIST / DETAIL / INFO PAGES ===== */
.page-head { max-width: 1280px; margin: 28px auto 0; padding: 0 24px; }
.page-head h1 { font-size: 24px; font-weight: 600; }
.breadcrumb { color: var(--text-dim); font-size: 13px; margin-bottom: 8px; }
.breadcrumb a { color: var(--gold); }
.filter-row { max-width: 1280px; margin: 16px auto 0; padding: 0 24px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filter-row select, .filter-row input {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 12px; font-family: inherit; font-size: 13px;
}
.filter-clear { color: var(--gold); font-size: 13px; }
.list-grid { max-width: 1280px; margin: 20px auto 60px; padding: 0 24px; display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px; }
.list-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.list-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.list-grid.cols-8 { grid-template-columns: repeat(8, 1fr); }
.empty-note { color: var(--text-dim); padding: 40px 0; text-align: center; }

.detail-wrap { max-width: 960px; margin: 28px auto 60px; padding: 0 24px; }
.detail-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; display: flex; gap: 28px; }
.detail-card .ph-box { width: 320px; aspect-ratio: 1 / 1; height: auto; flex-shrink: 0; } /* matches 800×800 product upload hint */
.detail-gallery { width: 320px; flex-shrink: 0; }
.detail-gallery-main { width: 100%; aspect-ratio: 1 / 1; height: auto; }
.detail-gallery-strip { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.detail-gallery-thumb {
  width: 56px; height: 56px; border-radius: 8px; overflow: hidden;
  border: 2px solid transparent; background: var(--bg-alt); flex-shrink: 0;
}
.detail-gallery-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.detail-gallery-thumb.active { border-color: var(--gold); }
@media (max-width: 720px) { .detail-gallery { width: 100%; } }
.detail-body h1 { font-size: 24px; margin-bottom: 10px; }
.detail-body .detail-meta { color: var(--text-dim); font-size: 13px; margin-bottom: 14px; }
.detail-body .detail-price { font-size: 22px; font-weight: 700; color: var(--gold); margin-bottom: 16px; }
.detail-body p { color: var(--text-dim); line-height: 1.7; margin-bottom: 10px; }
@media (max-width: 720px) { .detail-card { flex-direction: column; } .detail-card .ph-box { width: 100%; } }

/* Rich content rendered from the dashboard's Quill editor (news/knowledge full body) */
.rich-content { color: var(--text-dim); line-height: 1.7; }
.rich-content p { margin-bottom: 10px; }
.rich-content h1, .rich-content h2, .rich-content h3 { color: var(--text); margin: 16px 0 8px; }
.rich-content ul, .rich-content ol { margin: 0 0 10px 22px; }
.rich-content img { max-width: 100%; border-radius: 8px; margin: 10px 0; }
.rich-content a { color: var(--gold); text-decoration: underline; }
.rich-content blockquote { border-left: 3px solid var(--gold); padding-left: 12px; color: var(--text-dim); margin: 10px 0; }

.info-wrap { max-width: 820px; margin: 28px auto 60px; padding: 0 24px; }
.info-wrap h1 { font-size: 24px; margin-bottom: 18px; }
.info-wrap p { color: var(--text-dim); line-height: 1.8; margin-bottom: 14px; }
.info-wrap h2 { font-size: 16px; margin: 20px 0 8px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .product-grid { grid-template-columns: repeat(3, 1fr); }
  .knowledge-grid { grid-template-columns: repeat(2, 1fr); }
  .news-grid { grid-template-columns: repeat(2, 1fr); }
  .promo-cards { grid-template-columns: repeat(2, 1fr); }
  .footer-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 1024px) { .list-grid { grid-template-columns: repeat(3, 1fr) !important; } }
@media (max-width: 720px) {
  .list-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .header-inner { flex-wrap: wrap; }
  .header-actions { margin-left: auto; }
  .search-bar { order: 3; max-width: 100%; }
  .header-link span, .cart-link span { display: none; }
  .hero-slide { flex-direction: column; text-align: center; padding: 32px 24px; }
  .hero-image { width: 100%; max-width: 280px; }
  .hero-text h1 { font-size: 26px; }
  .product-grid { grid-template-columns: repeat(2, 1fr); }
  .news-grid, .knowledge-grid { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr; }

  /* .category-grid/.brand-row are flex-nowrap + overflow-x:auto at every width already (see
     base rules above) — smaller fixed item width here just fits more comfortably on a phone.
     -webkit-overflow-scrolling keeps touch-scrolling smooth on iOS. */
  .category-grid, .brand-row { -webkit-overflow-scrolling: touch; }
  .category-item { flex: 0 0 42%; }
  .nav-inner { justify-content: flex-start; }
}
