:root {
  --primary: #1976D2;
  --primary-dark: #1565C0;
  --primary-light: #E3F2FD;
  --text-primary: #212121;
  --text-secondary: #6D7588;
  --text-disabled: #AAB4C8;
  --border: #E5E7E9;
  --bg: #FFFFFF;
  --bg-grey: #F3F4F5;
  --danger: #E53935;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  --max: 1120px;
  --font: 'Open Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

/* App-gate open: freeze the page. scrollbar-gutter above keeps the layout
   from shifting when the scrollbar is removed; --sbw is a fallback for
   engines without scrollbar-gutter (older Safari). */
body.no-scroll { overflow: hidden; }
@supports not (scrollbar-gutter: stable) {
  body.no-scroll { padding-right: var(--sbw, 0px); }
}

body {
  margin: 0;
  background: var(--bg-grey);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

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

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 16px; }

/* ── Header ─────────────────────────────────────────────── */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.site-header .wrap {
  display: flex; align-items: center; gap: 16px;
  height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand img { width: 32px; height: 32px; border-radius: 7px; }
.brand span { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }

.search-box {
  flex: 1; display: flex; align-items: center; gap: 8px;
  background: var(--bg-grey);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 14px; height: 40px;
  max-width: 520px;
}
.search-box:focus-within { border-color: var(--primary); background: var(--bg); }
.search-box input {
  flex: 1; border: 0; outline: 0; background: transparent;
  font-size: 14px; color: var(--text-primary); min-width: 0;
}
.search-box svg { width: 18px; height: 18px; color: var(--text-secondary); flex-shrink: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px;
  border-radius: 999px; border: 1px solid transparent;
  font-size: 14px; font-weight: 700; cursor: pointer;
  white-space: nowrap; transition: filter .12s ease, background .12s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: var(--bg); color: var(--primary); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-grey); }
.btn-block { display: flex; width: 100%; }
.btn:disabled { background: var(--bg-grey); color: var(--text-disabled); cursor: default; border-color: var(--border); }
.btn svg { width: 18px; height: 18px; }

.header-cta { flex-shrink: 0; }
@media (max-width: 640px) {
  .site-header .wrap { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .search-box { order: 3; flex-basis: 100%; max-width: none; }
  .header-cta { margin-left: auto; }
  .header-cta .label-long { display: none; }
}

/* ── Hero ───────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
}
.hero .wrap { padding: 40px 16px 44px; }
.hero h1 { margin: 0 0 8px; font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.hero p { margin: 0 0 20px; opacity: .9; max-width: 46ch; }
.hero .btn-primary { background: #fff; color: var(--primary-dark); }
@media (min-width: 720px) { .hero h1 { font-size: 34px; } }

/* ── Category chips ─────────────────────────────────────── */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 16px 0; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 7px 14px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--text-secondary); cursor: pointer;
}
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Product grid ──────────────────────────────────────── */
.section-title { margin: 8px 0 14px; font-size: 17px; font-weight: 700; }
.grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(2, 1fr);
  padding-bottom: 32px;
}
@media (min-width: 560px) { .grid { gap: 12px; grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px) { .grid { grid-template-columns: repeat(4, 1fr); gap: 16px; } }
@media (min-width: 1040px) { .grid { grid-template-columns: repeat(5, 1fr); } }

.grid.is-busy { opacity: .65; }
.grid:not(.is-busy) > .card { animation: cardIn .2s ease both; }
@keyframes cardIn { from { opacity: 0; transform: translateY(4px); } }
.fade-in { animation: fadeIn .2s ease both; }
@keyframes fadeIn { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .grid:not(.is-busy) > .card, .fade-in { animation: none; }
  html { scroll-behavior: auto; }
}

.card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column;
  transition: box-shadow .14s ease, transform .14s ease, border-color .14s ease;
}
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); border-color: #d5dae0; }
.card .thumb {
  aspect-ratio: 1; background: var(--bg-grey);
  position: relative; overflow: hidden;
}
.card .thumb img, .card .thumb .ph {
  position: absolute; inset: 0; width: 100%; height: 100%;
}
.card .thumb img { object-fit: cover; }
.card .thumb .ph { display: flex; align-items: center; justify-content: center; color: var(--text-disabled); }
.card .thumb .ph svg { width: 34px; height: 34px; }
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.card .name {
  font-size: 13px; line-height: 1.35; color: var(--text-primary); min-height: 2.7em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .price { font-size: 15px; font-weight: 800; color: var(--text-primary); margin-top: auto; padding-top: 3px; }
.card .unit { font-size: 11px; font-weight: 600; color: var(--text-secondary); }
.card .meta {
  font-size: 11px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.skeleton { position: relative; overflow: hidden; background: var(--bg-grey); }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.6), transparent);
  transform: translateX(-100%); animation: shimmer 1.3s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
.sk-line { height: 10px; border-radius: 4px; }

.empty {
  text-align: center; color: var(--text-secondary);
  padding: 44px 20px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.empty svg { width: 40px; height: 40px; color: var(--text-disabled); margin: 0 auto 12px; }
.empty > img { display: block; margin: 0 auto; }
.empty .btn svg { width: 18px; height: 18px; color: inherit; margin: 0; }

.more-wrap { display: flex; justify-content: center; padding: 8px 0 40px; }

/* ── Product / store detail ────────────────────────────── */
.detail { padding: 0 0 40px; }
.detail-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 860px) {
  .detail-grid { grid-template-columns: minmax(0, 420px) 1fr; gap: 28px; align-items: start; }
}

.panel {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
@media (min-width: 560px) { .panel { padding: 20px; } }

.gallery { display: flex; flex-direction: column; gap: 8px; }
@media (min-width: 860px) { .gallery { position: sticky; top: 76px; } }
.gallery .main {
  aspect-ratio: 1; border-radius: var(--radius); overflow: hidden;
  background: var(--bg); border: 1px solid var(--border); position: relative;
}
.gallery .main img, .gallery .main .ph {
  position: absolute; inset: 0; width: 100%; height: 100%;
}
.gallery .main img { object-fit: cover; }
.gallery .main .ph { display: flex; align-items: center; justify-content: center; color: var(--text-disabled); }
.gallery .main .ph svg { width: 56px; height: 56px; }
.gallery .thumbs { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.gallery .thumbs::-webkit-scrollbar { display: none; }
.gallery .thumbs button {
  flex-shrink: 0; width: 56px; height: 56px; padding: 0;
  border-radius: 8px; overflow: hidden; cursor: pointer;
  background: var(--bg); border: 1px solid var(--border);
}
.gallery .thumbs button.active { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.gallery .thumbs img { width: 100%; height: 100%; object-fit: cover; }

.info h1 { margin: 0 0 12px; font-size: 19px; font-weight: 700; line-height: 1.35; }
@media (min-width: 560px) { .info h1 { font-size: 22px; } }
.price-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.price-row .now { font-size: 25px; font-weight: 800; color: var(--primary-dark); }
@media (min-width: 560px) { .price-row .now { font-size: 28px; } }
.price-row .was { font-size: 14px; color: var(--text-disabled); text-decoration: line-through; }
.price-sub { color: var(--text-secondary); font-size: 12px; }

.seller {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; margin: 16px 0 0;
  background: var(--bg-grey); border-radius: var(--radius);
}
.seller img, .seller .av {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover;
  background: var(--primary-light); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--primary); font-size: 15px;
}
.seller .s-name { font-weight: 700; font-size: 13px; }
.seller .s-meta { font-size: 12px; color: var(--text-secondary); margin-top: 1px; }
.seller a.s-open { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--primary); white-space: nowrap; }

.cta-stack { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.cta-note { font-size: 12px; color: var(--text-secondary); text-align: center; line-height: 1.5; }

.desc { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.desc h2 { font-size: 14px; font-weight: 700; margin: 0 0 8px; }
.desc .txt { color: var(--text-secondary); font-size: 13px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }

.specs { margin-top: 20px; padding-top: 4px; border-top: 1px solid var(--border); }
.specs .row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.specs .row:last-child { border-bottom: 0; }
.specs .row span:first-child { width: 120px; color: var(--text-secondary); flex-shrink: 0; }
.specs .row span:last-child { font-weight: 600; }

/* ── Store head ────────────────────────────────────────── */
.store-head { display: flex; flex-direction: column; gap: 14px; }
.store-head-top { display: flex; align-items: center; gap: 14px; }
.store-head .av, .store-head-top img {
  width: 56px; height: 56px; border-radius: 14px; object-fit: cover;
  background: var(--primary-light); color: var(--primary);
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px;
}
.store-head-info { min-width: 0; }
.store-head .s-name { font-size: 17px; font-weight: 700; line-height: 1.3; }
.store-head .s-meta { font-size: 12px; color: var(--text-secondary); margin-top: 3px; }
.store-desc {
  margin: 0; color: var(--text-secondary); font-size: 13px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}
@media (min-width: 560px) { .store-head .btn-block { align-self: flex-start; width: auto; padding: 0 28px; } }

/* ── App-gate modal ────────────────────────────────────── */
.gate-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16, 24, 40, .5);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
.gate-backdrop.open { opacity: 1; pointer-events: auto; }
@media (min-width: 560px) { .gate-backdrop { align-items: center; } }

.gate {
  background: var(--bg); width: 100%; max-width: 400px;
  border-radius: 16px 16px 0 0; padding: 24px 20px 20px;
  transform: translateY(16px); transition: transform .18s ease;
  text-align: center;
}
.gate-backdrop.open .gate { transform: none; }
@media (min-width: 560px) { .gate { border-radius: 16px; } }

.gate img.logo { width: 56px; height: 56px; border-radius: 12px; margin: 0 auto 14px; }
.gate h3 { margin: 0 0 6px; font-size: 17px; font-weight: 700; }
.gate p { margin: 0 0 18px; color: var(--text-secondary); font-size: 13px; }
.gate .actions { display: flex; flex-direction: column; gap: 10px; }
.gate .dismiss {
  margin-top: 4px; background: transparent; border: 0;
  color: var(--text-secondary); font-size: 13px; font-weight: 600; cursor: pointer; padding: 8px;
}

/* ── Footer ────────────────────────────────────────────── */
.site-footer {
  background: var(--bg); border-top: 1px solid var(--border);
  padding: 28px 0; margin-top: 8px;
}
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; }
.site-footer .links { display: flex; gap: 18px; flex-wrap: wrap; }
.site-footer a { color: var(--text-secondary); font-size: 13px; }
.site-footer a:hover { color: var(--primary); }
.site-footer .copy { color: var(--text-disabled); font-size: 12px; }

.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-secondary); font-size: 13px; font-weight: 600;
  padding: 16px 0 4px;
}
.back-link svg { width: 16px; height: 16px; }

.legal { padding: 24px; line-height: 1.7; }
.legal h1 { font-size: 24px; margin: 0 0 4px; }
.legal h2 { font-size: 17px; margin: 24px 0 8px; }
.legal p, .legal li { color: var(--text-secondary); }
.legal ul, .legal ol { padding-left: 20px; }
.legal .legal-updated { font-size: 13px; margin: 0 0 16px; }

.delete-form { display: grid; gap: 14px; margin-top: 20px; max-width: 420px; }
.delete-form label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--text-primary); }
.delete-form input[type="text"], .delete-form input[type="password"] {
  font: inherit; font-weight: 400; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); width: 100%;
}
.delete-form .check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.delete-result { font-size: 14px; min-height: 20px; }
.delete-result.ok { color: var(--text-secondary); }
.delete-result.fail { color: var(--danger); }
