/* ===========================================================================
   ช้อปช่วยติ่ง — Catalog styles
   Mobile-first, soft fan/idol palette, Thai-friendly typography
   =========================================================================== */
:root {
  --bg: #fbf7fb;
  --surface: #ffffff;
  --ink: #2a2430;
  --ink-soft: #6b6475;
  --line: #efe6ef;
  --accent: #e25fa4;        /* pink (borders/hover/fills) */
  --accent-ink: #b3346f;    /* deep pink — AA-readable as text on white & the header gradient */
  --accent-2: #8b6df0;      /* purple */
  --accent-soft: #fce7f1;
  --sell: #1f9d6b;          /* WTS green */
  --buy: #d98324;           /* WTB amber */
  --shadow: 0 2px 10px rgba(120, 70, 120, .08);
  --shadow-lg: 0 8px 28px rgba(120, 70, 120, .16);
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: rgba(226, 95, 164, .18); }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}
.wrap { width: 100%; max-width: 1140px; margin: 0 auto; padding: 0 14px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
a { color: inherit; }

/* ---------- Header ---------- */
.site-header {
  background: linear-gradient(135deg, #fff0f7 0%, #f1ecff 100%);
  border-bottom: 1px solid var(--line);
  padding: 18px 0 16px;
}
.site-header .wrap {
  display: flex; flex-wrap: wrap; gap: 8px 16px;
  align-items: flex-end; justify-content: space-between;
}
.brand h1 { margin: 0; font-size: 1.45rem; font-weight: 700; letter-spacing: -.2px; }
.brand-sub {
  font-size: .82rem; font-weight: 600; color: var(--accent-2);
  background: #fff; padding: 2px 9px; border-radius: 999px; margin-left: 4px;
  vertical-align: middle; box-shadow: var(--shadow);
}
.tagline { margin: 6px 0 0; color: var(--ink-soft); font-size: .9rem; max-width: 60ch; }
.header-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; margin-left: auto; }
.community-link {
  font-weight: 600; font-size: .9rem; color: var(--accent-ink);
  text-decoration: underline; white-space: nowrap;
}
.updated { font-size: .76rem; color: var(--ink-soft); }
.views {
  font-size: .78rem; color: var(--ink-soft); display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px 11px;
  box-shadow: var(--shadow); white-space: nowrap;
}
.views b { color: var(--accent-ink); font-weight: 700; }
.views[hidden] { display: none; }
/* "Supported by AiROVA" — inline partner credit next to the brand title */
.supported-by { display: inline-flex; align-items: center; gap: 6px; vertical-align: middle; margin-left: 8px; white-space: nowrap; }
.supported-label { font-size: .72rem; font-weight: 500; color: var(--ink-soft); letter-spacing: .2px; white-space: nowrap; }
.airova-logo { height: 26px; width: auto; display: block; }

/* ---------- Top disclaimer notice (small, above the sticky search bar) ---------- */
.top-notice {
  margin: 12px 0 0; padding: 9px 13px;
  font-size: .74rem; line-height: 1.5; color: var(--ink-soft);
  background: var(--accent-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

/* ---------- Controls ---------- */
.controls { margin-top: 16px; }
.search-row {
  display: flex; gap: 8px; align-items: stretch;
  position: sticky; top: 0; z-index: 20;
  background: var(--bg); margin: 0 -14px; padding: 8px 14px;
  box-shadow: 0 6px 14px -10px rgba(120, 70, 120, .5);
}
.search-box {
  position: relative; flex: 1 1 auto; display: flex; align-items: center;
  background: var(--surface); border: 1.5px solid var(--line);
  border-radius: 999px; padding: 0 10px; box-shadow: var(--shadow);
  transition: border-color .15s;
}
.search-box:focus-within { border-color: var(--accent); }
.search-icon { font-size: .95rem; opacity: .7; }
#searchInput {
  flex: 1; border: 0; outline: 0; background: transparent;
  font: inherit; padding: 11px 8px; color: var(--ink); min-width: 0;
}
.clear-btn {
  border: 0; background: var(--line); color: var(--ink-soft); flex: 0 0 auto;
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: .8rem;
  display: flex; align-items: center; justify-content: center;
}
.sort-box select, .filter-toggle {
  font: inherit; font-weight: 600; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); border-radius: 999px;
  padding: 0 14px; height: 100%; min-height: 44px; cursor: pointer; box-shadow: var(--shadow);
}
.sort-box select { -webkit-appearance: none; appearance: none; padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%236b6475' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.filter-toggle { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.filter-toggle[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
.active-count {
  background: var(--accent); color: #fff; font-size: .72rem; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 999px; padding: 0 5px;
  display: inline-flex; align-items: center; justify-content: center;
}
.active-count[hidden] { display: none; }

/* ---------- Facets ---------- */
.facets { display: none; flex-direction: column; gap: 12px; margin-top: 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.facets.open { display: flex; }
.sheet-head { display: none; }   /* only shown as a sheet header on mobile */
.facet-backdrop { display: none; position: fixed; inset: 0; background: rgba(20, 12, 24, .45); z-index: 39; }
.facet-group h3 {
  margin: 0 0 8px; font-size: .82rem; font-weight: 700; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .4px;
}
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  font: inherit; font-size: .85rem; font-weight: 500; cursor: pointer;
  border: 1.5px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 999px; padding: 8px 14px; min-height: 38px; transition: all .12s;
  white-space: nowrap; display: inline-flex; align-items: center;
}
.chip:active { border-color: var(--accent); }
.chip .cnt { color: var(--ink-soft); font-size: .78rem; margin-left: 3px; }
.chip[aria-pressed="true"] {
  background: var(--accent-soft); border-color: var(--accent); color: #b03377; font-weight: 600;
}
.chip[aria-pressed="true"] .cnt { color: var(--accent); }

/* ---------- Result bar ---------- */
.result-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  margin: 16px 2px 12px; gap: 8px 10px; }
.result-count { font-size: .9rem; color: var(--ink-soft); font-weight: 500; }
.result-count b { color: var(--ink); }
.result-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.per-page { display: inline-flex; align-items: center; gap: 6px; }
.per-page-label { font-size: .8rem; color: var(--ink-soft); font-weight: 500; white-space: nowrap; }
.per-page select {
  font: inherit; font-size: .85rem; font-weight: 600; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); border-radius: 999px; cursor: pointer;
  box-shadow: var(--shadow); -webkit-appearance: none; appearance: none;
  padding: 6px 28px 6px 12px; min-height: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%236b6475' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.reset-btn {
  font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
  color: var(--accent); background: none; border: 0; padding: 4px 2px; text-decoration: underline;
}

/* ---------- Grid & cards ---------- */
.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
}
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow);
  transition: transform .14s, box-shadow .14s; scroll-margin-top: 96px;
}
.card:active { box-shadow: var(--shadow-lg); }
.card-media {
  position: relative; aspect-ratio: 1 / 1; background: var(--accent-soft);
  cursor: zoom-in; overflow: hidden;
}
.card-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-media .noimg {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 4px; color: var(--accent-2); font-size: .8rem; cursor: pointer;
  text-align: center; padding: 8px;
  background: repeating-linear-gradient(45deg,#fbeef6,#fbeef6 10px,#f6e7fb 10px,#f6e7fb 20px);
}
.badge-status {
  position: absolute; top: 8px; left: 8px; font-size: .72rem; font-weight: 700;
  padding: 3px 9px; border-radius: 999px; color: #fff; box-shadow: var(--shadow);
}
.badge-status.sell { background: var(--sell); }
.badge-status.buy { background: var(--buy); }
.badge-imgcount {
  position: absolute; bottom: 8px; right: 8px; font-size: .72rem; font-weight: 600;
  background: rgba(0,0,0,.55); color: #fff; padding: 2px 8px; border-radius: 999px;
}
/* sold-out: flagged (never removed) — dim the card + corner tag */
.badge-soldout {
  position: absolute; top: 8px; right: 8px; font-size: .72rem; font-weight: 800;
  padding: 3px 9px; border-radius: 999px; color: #fff; letter-spacing: .3px;
  background: #6b7280; box-shadow: var(--shadow); z-index: 2;
}
.card.is-soldout .card-media { filter: grayscale(.55) opacity(.62); }
.card.is-soldout .card-price { color: var(--ink-soft); text-decoration: line-through; }
.card-body { padding: 11px 12px 12px; display: flex; flex-direction: column; gap: 7px; flex: 1; }
.card-title { font-size: .92rem; font-weight: 600; line-height: 1.35; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-price { font-size: 1rem; font-weight: 700; color: var(--accent-ink); margin: 0; }
.card-desc { font-size: .84rem; color: var(--ink-soft); margin: 0; line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 2px; }
.tag {
  font-size: .74rem; font-weight: 600; padding: 5px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid transparent; line-height: 1.4; min-height: 34px;
  display: inline-flex; align-items: center;
}
.tag.artist { background: #efe9ff; color: #5b3fcc; }
.tag.brand  { background: #fdeef6; color: #a4356f; }
.tag.type   { background: #e9f6f0; color: #157a52; }
.tag:active { border-color: currentColor; }
.card-foot { display: flex; align-items: center; justify-content: space-between;
  margin-top: auto; padding-top: 4px; gap: 6px; }
.seller { font-size: .8rem; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.seller b { color: var(--ink); font-weight: 600; }
.view-btn {
  flex: 0 0 auto; font-size: .82rem; font-weight: 700; text-decoration: none;
  background: var(--ink); color: #fff; padding: 0 16px; border-radius: 999px;
  white-space: nowrap; transition: background .14s;
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
}
.view-btn:active { background: var(--accent); }
.time-ago { font-size: .76rem; color: var(--ink-soft); }

/* ---------- Pagination ---------- */
.pager {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 6px; margin: 26px auto 6px;
}
.pager[hidden] { display: none; }
.pager-btn {
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
  min-width: 40px; height: 40px; padding: 0 12px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 10px; box-shadow: var(--shadow);
  display: inline-flex; align-items: center; justify-content: center;
  transition: border-color .12s, background .12s, color .12s;
}
.pager-btn:disabled { opacity: .4; cursor: default; box-shadow: none; }
.pager-btn.is-current { background: var(--accent); border-color: var(--accent); color: #fff; cursor: default; }
.pager-edge { font-size: 1.15rem; }
.pager-gap { color: var(--ink-soft); padding: 0 2px; align-self: flex-end; }
.pager-info { flex-basis: 100%; text-align: center; margin-top: 8px; font-size: .8rem; color: var(--ink-soft); }

/* ---------- Back-to-top FAB ---------- */
.to-top {
  position: fixed; right: 14px; bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 30; width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; box-shadow: var(--shadow-lg);
  font-size: 1.3rem; cursor: pointer; transition: transform .12s, opacity .2s;
  display: flex; align-items: center; justify-content: center;
}
.to-top:active { transform: scale(.92); }
.to-top[hidden] { display: none; }

/* ---------- Empty & footer ---------- */
.empty { text-align: center; padding: 50px 16px; color: var(--ink-soft); }
.empty p { font-size: 1.05rem; margin-bottom: 14px; }
.site-footer { margin-top: 36px; border-top: 1px solid var(--line); background: var(--surface);
  padding: 18px 0 calc(40px + env(safe-area-inset-bottom)); }
.site-footer p { margin: 0 0 6px; font-size: .82rem; color: var(--ink-soft); }
.disclaimer { font-size: .76rem; }

/* ---------- Lightbox / gallery ---------- */
.lightbox { position: fixed; inset: 0; background: rgba(20,12,24,.88); z-index: 50;
  display: flex; align-items: center; justify-content: center; touch-action: pan-y;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom)); }
.lightbox[hidden] { display: none; }   /* override UA [hidden] correctly */
.lightbox img { max-width: 100%; max-height: 84vh; border-radius: 10px; box-shadow: var(--shadow-lg); }
.lb-close { position: absolute; z-index: 2;
  top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18);
  color: #fff; font-size: 1.2rem; cursor: pointer; }
.lb-nav { position: absolute; z-index: 2; top: 50%; transform: translateY(-50%);
  width: 46px; height: 46px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18);
  color: #fff; font-size: 1.6rem; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center; }
.lb-prev { left: 10px; }
.lb-next { right: 10px; }
.lb-nav[hidden] { display: none; }
.lb-count { position: absolute; z-index: 2; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom)); background: rgba(0,0,0,.55); color: #fff;
  font-size: .82rem; font-weight: 600; padding: 4px 12px; border-radius: 999px; }
.lb-count[hidden] { display: none; }

/* ---------- Hover effects only where a real pointer exists (avoids sticky :hover on touch) ---------- */
@media (hover: hover) {
  .card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
  .chip:hover { border-color: var(--accent); }
  .tag:hover { border-color: currentColor; }
  .view-btn:hover { background: var(--accent); }
  .pager-btn:not(:disabled):not(.is-current):hover { border-color: var(--accent); color: var(--accent); }
  .to-top:hover { background: var(--accent-ink); }
  .filter-toggle:hover { border-color: var(--accent); }
}

/* ---------- Responsive ---------- */
@media (min-width: 640px) {
  .brand h1 { font-size: 1.7rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 18px; }
  .card-title { font-size: 1rem; }
}

/* Phones & large phones: stack controls, turn filters into a bottom-sheet */
@media (max-width: 600px) {
  /* mobile-first header: brand stacked over a full-width meta row (logo left · links/views right) */
  .site-header { padding: 14px 0 14px; }
  .site-header .wrap { flex-direction: column; align-items: stretch; gap: 10px; }
  .header-meta { flex-flow: row wrap; align-items: center; justify-content: flex-end; gap: 6px 14px; width: 100%; margin: 0; }

  .search-row { flex-wrap: wrap; }
  .search-box { flex: 1 1 100%; order: -1; }
  .sort-box { flex: 1 1 0; min-width: 0; }
  .sort-box select { width: 100%; }
  .filter-toggle { flex: 0 0 auto; }

  body.sheet-open { overflow: hidden; }
  .facet-backdrop:not([hidden]) { display: block; }
  .facets.open {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; margin: 0;
    max-height: 78vh; overflow: auto; border-radius: 18px 18px 0 0; border: 0;
    z-index: 40; box-shadow: var(--shadow-lg);
    padding: 0 14px calc(16px + env(safe-area-inset-bottom));
  }
  .facets.open .sheet-head {
    display: flex; align-items: center; gap: 10px; justify-content: space-between;
    position: sticky; top: 0; z-index: 1; background: var(--surface);
    margin: 0 -14px 12px; padding: 12px 14px 10px; border-bottom: 1px solid var(--line);
  }
  .sheet-title { font-weight: 700; font-size: 1rem; flex: 1; }
  .sheet-x { border: 0; background: var(--line); color: var(--ink); flex: 0 0 auto;
    width: 38px; height: 38px; border-radius: 50%; font-size: 1rem; cursor: pointer; }
  .sheet-done { font: inherit; font-weight: 700; border: 0; background: var(--accent); color: #fff;
    border-radius: 999px; padding: 0 18px; min-height: 40px; cursor: pointer; flex: 0 0 auto; }
}

@media (max-width: 420px) {
  .grid { gap: 11px; }
  .sort-box select { padding: 0 28px 0 12px; font-size: .85rem; }
}

/* ---------- Respect reduced-motion preference ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
