:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --border: #e3e1dc;
  --accent: #e5484d;
  --accent-ink: #ffffff;
  --accent-soft: #fdeceb;
  --price: #c4271f;
  --ok: #1f7a4d;
  --ok-soft: #e4f4ea;
  --info: #2457a6;
  --info-soft: #e7eefb;
  --warn-soft: #fff4d9;
  --warn: #8a5a00;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .04);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --surface: #1e1e1c;
    --surface-2: #2a2a27;
    --text: #ecebe7;
    --muted: #a3a19b;
    --border: #34332f;
    --accent: #f2555a;
    --accent-soft: #3a1f1f;
    --price: #ff7a70;
    --ok: #5fcf95;
    --ok-soft: #173126;
    --info: #8ab4ff;
    --info-soft: #1b2740;
    --warn-soft: #382c10;
    --warn: #f0c060;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans JP", sans-serif;
}
a { color: var(--info); }
img { max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---- Thanh trên cùng ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; gap: 16px; padding-top: 10px; padding-bottom: 10px; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); flex-shrink: 0; }
.logo-mark {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; letter-spacing: -.5px;
}
.logo-text { display: flex; flex-direction: column; font-weight: 700; line-height: 1.15; }
.logo-text small { font-weight: 400; color: var(--muted); font-size: 12px; }
.search { flex: 1; display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; min-width: 0; }
.search input[type=search] {
  flex: 1; min-width: 0; height: 40px; padding: 0 14px;
  border: 1.5px solid var(--border); border-radius: 10px; background: var(--bg);
}
.search input[type=search]:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.qvi { flex-basis: 100%; font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }

main { padding-top: 20px; padding-bottom: 32px; min-height: 60vh; outline: none; }
.footer { color: var(--muted); font-size: 13px; padding-bottom: 32px; border-top: 1px solid var(--border); padding-top: 16px; }

/* ---- Trang chủ ---- */
.hero { text-align: center; padding: 40px 0 24px; }
.hero h1 { font-size: clamp(24px, 4vw, 36px); margin: 0 0 8px; letter-spacing: -.5px; }
.hero p { color: var(--muted); margin: 0 auto; max-width: 620px; }
.section-title { font-size: 17px; margin: 28px 0 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text);
  font-size: 14px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); }
.chip .count { color: var(--muted); font-size: 12px; }
.chip small { color: var(--muted); }

/* ---- Thanh công cụ tìm kiếm ---- */
.results-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.results-head h1 { font-size: 20px; margin: 0; }
.filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; margin-bottom: 12px;
}
.filters select, .filters input {
  height: 36px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding: 0 10px;
}
.filters input[type=number] { width: 110px; }
.filters .sep { flex: 1; }

/* ---- Lưới sản phẩm ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.card {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; text-decoration: none; color: var(--text); box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card-img { position: relative; aspect-ratio: 1; background: var(--surface-2); }
.card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-badges { position: absolute; left: 6px; top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card-title { font-size: 14px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card-orig { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-price { margin-top: auto; padding-top: 6px; }
.price { color: var(--price); font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.vnd { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.card-meta { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--muted); }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11px; font-weight: 600;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.badge-buy { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-ship { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-store { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-new { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.badge-closed { background: var(--surface-2); color: var(--muted); }

.pager { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 24px; }

/* ---- Trang sản phẩm ---- */
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 12px; display: flex; flex-wrap: wrap; gap: 4px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.item { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.gallery { position: sticky; top: 84px; }
.gallery-main {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  aspect-ratio: 1; display: grid; place-items: center; overflow: hidden; cursor: zoom-in;
}
.gallery-main img { width: 100%; height: 100%; object-fit: contain; }
.gallery-main .nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 50%;
  border: none; background: rgba(0, 0, 0, .45); color: #fff; font-size: 22px; cursor: pointer;
}
.gallery-main .nav.prev { left: 10px; }
.gallery-main .nav.next { right: 10px; }
.gallery-count { position: absolute; right: 10px; bottom: 10px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; margin-top: 10px; }
.thumbs button { padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; aspect-ratio: 1; background: var(--surface-2); cursor: pointer; }
.thumbs button.active { border-color: var(--accent); }
.thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.item-title { font-size: 22px; line-height: 1.35; margin: 0 0 6px; letter-spacing: -.2px; }
.item-orig { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.price-box { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px; border-radius: 10px; background: var(--surface-2); margin: 12px 0; }
.price-box .label { font-size: 12px; color: var(--muted); }
.price-box .price { font-size: 24px; }
.countdown { font-weight: 600; font-variant-numeric: tabular-nums; }
.countdown.soon { color: var(--price); }
.facts { width: 100%; border-collapse: collapse; font-size: 14px; }
.facts th, .facts td { text-align: left; padding: 7px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.facts th { width: 38%; color: var(--muted); font-weight: 500; padding-right: 12px; }
.facts tr:last-child th, .facts tr:last-child td { border-bottom: none; }
.facts .orig { display: block; color: var(--muted); font-size: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: -4px 0 14px; overflow-x: auto; }
.tab {
  border: none; background: none; padding: 8px 14px; cursor: pointer; color: var(--muted); font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); }
.desc-text { white-space: pre-wrap; word-break: break-word; font-size: 15px; line-height: 1.7; }
.desc-html { overflow-x: auto; word-break: break-word; font-size: 14px; }
.desc-html img { height: auto; }
.desc-html table { max-width: 100%; }
.bilingual { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bilingual .col { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.7; }
.bilingual .col:last-child { color: var(--muted); }
.desc-images { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 16px; }
.desc-images img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; cursor: zoom-in; background: var(--surface-2); }

.notice { padding: 10px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 14px; margin-bottom: 12px; }
.notice a { color: inherit; font-weight: 600; }
.error-box { text-align: center; padding: 48px 16px; }
.error-box h2 { margin: 0 0 8px; }

/* ---- Trạng thái tải ---- */
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-card { height: 330px; border-radius: var(--radius); }
.loading-line { height: 14px; margin: 8px 0; }

/* ---- Hộp thoại & xem ảnh lớn ---- */
.dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); padding: 20px; width: min(420px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dialog h2 { margin: 0 0 14px; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 14px; }
.field input { height: 38px; border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; background: var(--bg); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin-bottom: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 12px; }

.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .92); display: grid; place-items: center; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 94vw; max-height: 90vh; object-fit: contain; }
.lightbox button { position: absolute; border: none; background: rgba(255, 255, 255, .12); color: #fff; cursor: pointer; border-radius: 50%; width: 48px; height: 48px; font-size: 26px; }
.lb-close { top: 14px; right: 14px; font-size: 20px !important; }
.lb-prev { left: 14px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 14px; top: 50%; transform: translateY(-50%); }
.lb-count { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); color: #ddd; font-size: 13px; }

@media (max-width: 860px) {
  .item { grid-template-columns: 1fr; }
  .gallery { position: static; }
  .bilingual { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; gap: 10px; }
  .logo-text small, .hide-sm { display: none; }
  .search { order: 3; flex-basis: 100%; }
  #settings-btn { margin-left: auto; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card-body { padding: 8px 10px 10px; }
  .price { font-size: 15px; }
  .price-box { grid-template-columns: 1fr; }
  .filters input[type=number] { width: 90px; }
  .item-title { font-size: 19px; }
}
