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

:root {
  --orange:       #ee4d2d;
  --orange-light: #fff2f0;
  --orange-mid:   #ffd5cc;
  --bg:           #f5f5f5;
  --white:        #fff;
  --border:       #e8e8e8;
  --text:         #222;
  --text-2:       #555;
  --text-3:       #999;
  --green:        #26aa63;
  --green-light:  #e8f9f0;
  --red:          #e53935;
  --radius:       6px;
  --shadow-card:  0 1px 4px rgba(0,0,0,.07), 0 0 0 1px var(--border);
  --shadow-hover: 0 4px 20px rgba(238,77,45,.13), 0 0 0 1px var(--orange);
}

html { font-size: 14px; }
body { font-family: 'Sarabun', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

/* ── TOPBAR ── */
.topbar {
  position: sticky;
  top: 56px;
  z-index: 40;
  background: var(--orange);
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
}

@media (min-width: 640px) {
  .topbar { top: 64px; }
}

.topbar-logo { font-family: 'Kanit', sans-serif; font-weight: 600; font-size: 16px; color: #fff; text-decoration: none; flex-shrink: 0; white-space: nowrap; }
.topbar-logo span { opacity: .75; font-weight: 400; font-size: 13px; margin-left: 6px; }

.search-wrap { flex: 1; display: flex; align-items: center; background: #fff; border-radius: var(--radius); overflow: hidden; height: 34px; }
.search-input { flex: 1; border: none; outline: none; padding: 0 10px; font-size: 13px; font-family: 'Sarabun', sans-serif; color: var(--text); background: transparent; min-width: 0; }
.search-input::placeholder { color: var(--text-3); }
.search-btn { flex-shrink: 0; width: 38px; height: 34px; background: var(--orange); border: none; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 13px; transition: background .15s; }
.search-btn:hover { background: #d9401f; }

/* ── FILTER STRIP ── */
.filter-strip {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  position: sticky;
  top: 52px;
  z-index: 20;
}
.filter-strip::-webkit-scrollbar { display: none; }

.sort-chip {
  flex-shrink: 0; font-size: 12px; font-family: 'Kanit', sans-serif; padding: 5px 14px;
  border-radius: 20px; border: 1px solid var(--border); background: var(--white);
  color: var(--text-2); cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: all .15s; display: inline-block;
}
.sort-chip.active, .sort-chip:hover { border-color: var(--orange); color: var(--orange); background: var(--orange-light); }
.sort-chip.active { font-weight: 500; }

.filter-divider { width: 1px; height: 18px; background: var(--border); flex-shrink: 0; }

.price-filter-btn {
  flex-shrink: 0; font-size: 12px; font-family: 'Kanit', sans-serif; padding: 5px 12px;
  border-radius: 20px; border: 1px solid var(--border); background: var(--white);
  color: var(--text-2); cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 5px;
  transition: all .15s; position: relative;
}
.price-filter-btn:hover, .price-filter-btn.active { border-color: var(--orange); color: var(--orange); background: var(--orange-light); }
.filter-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--orange); position: absolute; top: 2px; right: 2px; }

/* Price dropdown */
.price-dropdown {
  position: fixed; top: 108px; left: 50%; transform: translateX(-50%);
  width: calc(100% - 24px); max-width: 320px;
  background: var(--white); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,.1); z-index: 200; padding: 14px;
  display: none;
}
.price-dropdown.open { display: block; }
.price-dropdown-title { font-family: 'Kanit', sans-serif; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 10px; }
.price-inputs { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.price-input-wrap { flex: 1; position: relative; }
.price-input-wrap span { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--text-3); }
.price-input {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 7px 8px 7px 20px; font-size: 13px; outline: none;
  font-family: 'Sarabun', sans-serif;
}
.price-input:focus { border-color: var(--orange); }
.price-sep { color: var(--text-3); font-size: 12px; flex-shrink: 0; }
.price-btns { display: flex; gap: 6px; }
.btn-price-apply {
  flex: 1; padding: 8px; background: var(--orange); border: none; border-radius: var(--radius);
  color: #fff; font-family: 'Kanit', sans-serif; font-size: 13px; font-weight: 500; cursor: pointer;
}
.btn-price-apply:hover { background: #d9401f; }
.btn-price-clear {
  padding: 8px 14px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text-2); font-family: 'Kanit', sans-serif; font-size: 13px; cursor: pointer;
}
.btn-price-clear:hover { background: #eee; }

/* ── LAYOUT ── */
.page-wrap { max-width: 1120px; margin: 0 auto; }

/* ── BANNER ── */
.banner-wrap { overflow: hidden; background: #000; }
.banner-wrap img { width: 100%; height: auto; display: block; max-height: 200px; object-fit: cover; }
@media (min-width: 768px) { .banner-wrap img { max-height: 260px; } }

/* ── CONTENT AREA ── */
.content-area { display: flex; gap: 0; align-items: flex-start; }
@media (min-width: 768px) { .content-area { padding: 10px; gap: 10px; } }

/* ── SIDEBAR (desktop only) ── */
.sidebar { display: none; }
@media (min-width: 768px) {
  .sidebar { display: block; width: 200px; flex-shrink: 0; position: sticky; top: 108px; }
}

.sidebar-box {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 8px;
}
.sidebar-head {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  font-family: 'Kanit', sans-serif; font-size: 12px; font-weight: 500; color: var(--text);
  display: flex; align-items: center; gap: 6px;
}
.sidebar-head i { color: var(--orange); font-size: 11px; }

.sidebar-form { padding: 12px; }
.form-group { margin-bottom: 10px; }
.form-label { font-size: 11px; color: var(--text-3); margin-bottom: 4px; display: block; }
.form-control {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 8px; font-size: 12px; font-family: 'Sarabun', sans-serif; outline: none;
  background: var(--white);
}
.form-control:focus { border-color: var(--orange); }
.price-pair { display: flex; gap: 6px; }
.price-pair .form-control { padding-left: 18px; }
.price-pair-wrap { flex: 1; position: relative; }
.price-pair-wrap span { position: absolute; left: 6px; top: 50%; transform: translateY(-50%); font-size: 11px; color: var(--text-3); }

.btn-search {
  width: 100%; padding: 8px; background: var(--orange); border: none; border-radius: var(--radius);
  color: #fff; font-family: 'Kanit', sans-serif; font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background .15s;
}
.btn-search:hover { background: #d9401f; }
.btn-clear {
  width: 100%; padding: 7px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text-2); font-family: 'Kanit', sans-serif; font-size: 12px; cursor: pointer; margin-top: 5px;
  transition: background .15s;
}
.btn-clear:hover { background: #eee; }

.seller-cta {
  background: linear-gradient(135deg, #fff2f0 0%, #ffe8e3 100%);
  border: 1px solid var(--orange-mid); border-radius: var(--radius);
  padding: 14px 12px; text-align: center;
}
.seller-cta-title { font-family: 'Kanit', sans-serif; font-size: 12px; font-weight: 500; color: var(--orange); margin-bottom: 4px; }
.seller-cta-sub { font-size: 11px; color: var(--text-3); margin-bottom: 10px; line-height: 1.5; }
.btn-sell {
  display: block; padding: 8px; background: var(--orange); border-radius: var(--radius);
  color: #fff; font-family: 'Kanit', sans-serif; font-size: 12px; font-weight: 500; text-decoration: none;
  transition: background .15s;
}
.btn-sell:hover { background: #d9401f; }

/* ── MAIN CONTENT ── */
.main-col { flex: 1; min-width: 0; }

/* ── RESULT BAR ── */
.result-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--white); border-bottom: 1px solid var(--border);
}
@media (min-width: 768px) {
  .result-bar { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; }
}
.result-count { font-size: 12px; color: var(--text-3); }
.result-count strong { color: var(--text); font-weight: 500; }

/* ── PRODUCT GRID ── */
.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px; padding: 8px;
  background: var(--bg);
}
@media (min-width: 480px)  { .product-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 768px)  { .product-grid { grid-template-columns: repeat(3, 1fr); padding: 0; gap: 8px; background: transparent; } }
@media (min-width: 1024px) { .product-grid { grid-template-columns: repeat(4, 1fr); } }

/* ── PRODUCT CARD ── */
.p-card {
  background: var(--white);
  border-radius: 8px;
  overflow: hidden;
  display: block;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-card);
  transition: box-shadow .2s, transform .2s;
  position: relative;
}
.p-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

/* Image */
.p-img-wrap {
  position: relative;
  width: 100%;
  padding-top: 68%;
  overflow: hidden;
  background: #f9f9f9;
}
.p-img-wrap img {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  object-fit: cover;
  display: block;
  transition: transform .35s ease;
}
.p-card:hover .p-img-wrap img {
  transform: translate(-50%, -50%) scale(1.06);
}

/* ── BADGES ── */
.feat-badge {
  position: absolute; top: 0; left: 0;
  background: linear-gradient(90deg, #ff6b35, var(--orange));
  color: #fff;
  font-size: 9px; font-family: 'Kanit', sans-serif; font-weight: 600;
  padding: 3px 9px 3px 8px;
  border-radius: 0 0 8px 0;
  letter-spacing: .3px;
  box-shadow: 0 2px 6px rgba(238,77,45,.3);
}
.sold-badge {
  position: absolute; top: 0; left: 0;
  background: rgba(80,80,80,.85);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 9px; font-family: 'Kanit', sans-serif; font-weight: 600;
  padding: 3px 9px; border-radius: 0 0 8px 0;
}
/* เปอร์เซ็น discount badge บน image */
.discount-badge {
  position: absolute; top: 8px; right: 8px;
  background: var(--red);
  color: #fff;
  font-size: 10px; font-family: 'Kanit', sans-serif; font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  line-height: 1.6;
  box-shadow: 0 2px 8px rgba(229,57,53,.35);
  letter-spacing: .2px;
}
.view-badge {
  position: absolute; bottom: 6px; right: 6px;
  background: rgba(0,0,0,.45); color: #fff;
  font-size: 10px; padding: 2px 7px; border-radius: 20px;
  display: flex; align-items: center; gap: 3px;
  backdrop-filter: blur(2px);
}

/* ── CARD INFO ── */
.p-info { padding: 9px 10px 10px; }

.p-title {
  font-size: 12px; color: var(--text); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 35px; margin-bottom: 5px; font-weight: 500;
}

.p-seller {
  font-size: 11px; color: var(--text-3);
  display: flex; align-items: center; gap: 4px; margin-bottom: 4px;
}
.p-seller i { font-size: 10px; color: var(--orange); }

.p-rating {
  font-size: 11px; color: var(--text-3);
  display: flex; align-items: center; gap: 3px; margin-bottom: 6px;
}
.p-rating .star { color: #f5a623; font-size: 11px; }
.p-no-review { font-size: 10px; color: var(--text-3); margin-bottom: 6px; }

/* ── PRICE ROW ── */
.p-bottom {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding-top: 7px;
  border-top: 1px solid var(--border);
  gap: 4px;
}

.p-price-block {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

/* ราคาเดิม (ขีดฆ่า) */
.p-original-price {
  font-size: 10px;
  color: var(--text-3);
  text-decoration: line-through;
  line-height: 1.2;
  white-space: nowrap;
}

/* ราคาขาย */
.p-price {
  font-family: 'Kanit', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--orange);
  line-height: 1.1;
  white-space: nowrap;
}

/* เปอร์เซ็นลด (ใต้ราคา inline) */
.p-discount-pct {
  font-size: 10px;
  font-family: 'Kanit', sans-serif;
  font-weight: 600;
  color: var(--red);
  line-height: 1.2;
}

.p-view-btn {
  flex-shrink: 0;
  font-size: 11px;
  font-family: 'Kanit', sans-serif;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;

  color: #fff;
  border: none;

  transition: all .2s ease;
  white-space: nowrap;
  cursor: pointer;
}

/* =========================
   🟧 ปุ่มซื้อ
========================= */
.p-view-btn.buy {
  background: #ff6a00;
}

/* hover เฉพาะปุ่มซื้อ */
.p-card:hover .p-view-btn.buy {
  background: #e65c00;
  transform: scale(1.05);
}

/* =========================
   ⚪ ปุ่มขายแล้ว
========================= */
.p-view-btn.sold {
  background: #9ca3af; /* เทา */
  cursor: not-allowed;
  opacity: 0.9;
}

/* ไม่ให้ hover เด้ง */
.p-card:hover .p-view-btn.sold {
  background: #9ca3af;
  transform: none;
}
/* empty state */
.empty-state { grid-column: 1/-1; text-align: center; padding: 48px 16px; color: var(--text-3); }
.empty-state i { font-size: 36px; opacity: .2; display: block; margin-bottom: 12px; }
.empty-state p { font-size: 13px; }
.empty-state a { color: var(--orange); text-decoration: none; }

/* ── PAGINATION ── */
.pagination {
  display: flex; justify-content: center; gap: 4px; flex-wrap: wrap;
  padding: 16px 8px 8px;
}
@media (min-width: 768px) { .pagination { padding: 16px 0 0; } }
.page-btn {
  min-width: 32px; height: 32px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--white); border-radius: var(--radius);
  font-size: 13px; color: var(--text-2); text-decoration: none;
  transition: all .15s;
}
.page-btn:hover { border-color: var(--orange); color: var(--orange); }
.page-btn.active { background: var(--orange); border-color: var(--orange); color: #fff; font-weight: 500; }
.page-btn.disabled { opacity: .4; pointer-events: none; }
.page-sep { display: inline-flex; align-items: center; padding: 0 4px; color: var(--text-3); font-size: 13px; }

/* ── BOTTOM NAV ── */
.bottom-nav {
  display: flex;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 58px;
  background: var(--white);
  border-top: 1px solid var(--border);
  align-items: center;
  justify-content: space-around;
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(0,0,0,.07);
}
@media (min-width: 768px) { .bottom-nav { display: none; } }

.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--text-3); text-decoration: none;
  font-size: 10px; font-family: 'Kanit', sans-serif;
  padding: 0 8px; min-width: 52px;
  transition: color .15s;
}
.nav-item.active, .nav-item:hover { color: var(--orange); }
.nav-item i { font-size: 18px; }

/* ── ปุ่มลงขาย (กลาง bottom nav) ── */
.nav-sell-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  font-size: 10px;
  font-family: 'Kanit', sans-serif;
  color: var(--orange);
  font-weight: 600;
  min-width: 64px;
  margin-top: -18px; /* ดันขึ้น */
}
.nav-sell-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff6b35, var(--orange));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(238,77,45,.4);
  font-size: 20px;
  transition: transform .2s, box-shadow .2s;
}
.nav-sell-btn:active .nav-sell-icon {
  transform: scale(.93);
  box-shadow: 0 2px 8px rgba(238,77,45,.3);
}
.nav-sell-label {
  font-size: 9px;
  color: var(--orange);
  font-weight: 700;
  letter-spacing: .2px;
}

.main-wrap { padding-bottom: 70px; }
@media (min-width: 768px) { .main-wrap { padding-bottom: 0; } }

/* Price dropdown overlay */
.dd-overlay { position: fixed; inset: 0; z-index: 199; display: none; }
.dd-overlay.open { display: block; }

.cookie-banner {
    position: fixed;
    bottom: -120px;
    left: 0; right: 0;
    background: #1e293b;
    color: #e2e8f0;
    padding: 14px 20px;
    z-index: 9999;
    box-shadow: 0 -4px 20px rgba(0,0,0,.25);
    transition: bottom .4s cubic-bezier(.16,1,.3,1);
    border-top: 2px solid var(--orange);
}
.cookie-banner.show { bottom: 0; }

.cookie-content {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.cookie-text { flex: 1; font-size: 13px; line-height: 1.5; }

.cookie-actions { display: flex; gap: 8px; flex-shrink: 0; }

.btn-cookie-accept {
    background: var(--orange);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .2s;
}
.btn-cookie-accept:hover { opacity: .85; }

.btn-cookie-decline {
    background: transparent;
    color: #94a3b8;
    border: 1px solid #475569;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: color .2s;
}
.btn-cookie-decline:hover { color: #e2e8f0; }