:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede9;
  --text: #1d1b19;
  --muted: #6d6863;
  --line: #e4e1dc;
  --accent: #c8322b;
  --accent-ink: #ffffff;
  --accent-tint: #fbeceb;
  --radius: 10px;
  --shadow: 0 6px 20px rgb(0 0 0 / 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131211;
    --surface: #1c1b19;
    --surface-2: #262422;
    --text: #f1eeea;
    --muted: #a29d97;
    --line: #302d2a;
    --accent: #f06a5f;
    --accent-ink: #1a0b0a;
    --accent-tint: #3a201d;
    --shadow: 0 6px 20px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

a { color: inherit; }
img { display: block; max-width: 100%; }
button, input, select { font: inherit; color: inherit; }

.container { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Header */

.site-header {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; gap: 16px; height: 64px; }
.logo { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; text-decoration: none; white-space: nowrap; }
.search { flex: 1; max-width: 520px; margin-left: auto; }
.search input {
  width: 100%; height: 40px; padding: 0 14px 0 38px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238a847e' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='5.5'/%3E%3Cpath d='m11 11 4 4'/%3E%3C/svg%3E") no-repeat 14px center;
}
.search input:focus { outline: none; border-color: var(--accent); }

main.container { padding-top: 24px; padding-bottom: 56px; min-height: 70vh; }

.status, .empty { grid-column: 1 / -1; padding: 64px 16px; text-align: center; color: var(--muted); }
.status code { padding: 2px 6px; border-radius: 4px; background: var(--surface-2); color: var(--text); }

/* Listing */

.list-view { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 32px; align-items: start; }

.categories {
  position: sticky; top: 88px;
  max-height: calc(100vh - 104px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}
.cat-group { display: flex; flex-direction: column; gap: 2px; margin-top: 16px; }
.cat-group-title {
  margin: 0 0 4px; padding: 0 10px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted);
}
.cat {
  display: flex; justify-content: space-between; gap: 8px; width: 100%;
  padding: 7px 10px; border: 0; border-radius: 8px; background: none;
  font-size: 14px; text-align: left; cursor: pointer;
}
.cat:hover { background: var(--surface-2); }
.cat.is-active { background: var(--accent-tint); color: var(--accent); font-weight: 600; }
.cat-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.cat.is-active .cat-count { color: inherit; }

.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.toolbar h1 { margin: 0; font-size: 22px; line-height: 1.3; letter-spacing: -0.01em; }
.result-count { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
.sort select { height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }

.card {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; transition: transform 0.15s, box-shadow 0.15s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card-img { position: relative; aspect-ratio: 1; background: var(--surface-2); }
.card-img img { width: 100%; height: 100%; object-fit: cover; }
.badge {
  position: absolute; top: 8px; left: 8px; padding: 2px 8px; border-radius: 999px;
  background: rgb(0 0 0 / 0.7); color: #fff; font-size: 12px;
}
.card-body { display: flex; flex: 1; flex-direction: column; gap: 6px; padding: 10px 12px 12px; }
.card-name {
  margin: 0; min-height: 2.8em; font-size: 14px; font-weight: 500; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-price { margin-top: auto; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.card-old-price { margin-top: -4px; font-size: 12px; color: var(--muted); text-decoration: line-through; font-variant-numeric: tabular-nums; }
.card-meta { overflow: hidden; font-size: 12px; color: var(--muted); white-space: nowrap; text-overflow: ellipsis; }

.more { display: flex; justify-content: center; margin-top: 28px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 22px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--text); }
.btn-primary { min-width: 220px; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { border-color: var(--accent); filter: brightness(1.06); }
.btn-messenger { min-width: 220px; background: #0866ff; border-color: #0866ff; color: #fff; }
.btn-messenger:hover { border-color: #0866ff; filter: brightness(1.08); }

/* Detail */

.breadcrumb { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; font-size: 14px; color: var(--muted); }
.breadcrumb a { text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }

.detail { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 40px; align-items: start; }

.gallery { position: sticky; top: 88px; }
.gallery-main {
  position: relative; aspect-ratio: 1; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
}
.gallery-main img { width: 100%; height: 100%; object-fit: contain; }
.nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: rgb(255 255 255 / 0.9); color: #111; box-shadow: var(--shadow);
  font-size: 24px; line-height: 1; cursor: pointer; opacity: 0; transition: opacity 0.15s;
}
.gallery-main:hover .nav, .nav:focus-visible { opacity: 1; }
@media (hover: none) { .nav { opacity: 1; } }
.prev { left: 10px; }
.next { right: 10px; }
.thumbs { display: flex; gap: 8px; margin-top: 10px; padding-bottom: 4px; overflow-x: auto; }
.thumb {
  flex: 0 0 64px; height: 64px; padding: 0; overflow: hidden;
  border: 2px solid transparent; border-radius: 8px; background: var(--surface-2); cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.is-active { border-color: var(--accent); }

.detail-name { margin: 0 0 16px; font-size: 24px; line-height: 1.35; letter-spacing: -0.01em; }
.price-box {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px;
  margin-bottom: 20px; padding: 14px 18px; border-radius: var(--radius); background: var(--accent-tint);
}
.price { font-size: 28px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.old-price { font-size: 16px; color: var(--muted); text-decoration: line-through; font-variant-numeric: tabular-nums; }

.tier { margin-bottom: 18px; }
.tier-label { margin-bottom: 8px; font-size: 14px; color: var(--muted); }
.tier-label strong { font-weight: 600; color: var(--text); }
.options { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  font-size: 14px; text-align: left; cursor: pointer;
}
.opt.has-img { padding: 4px 12px 4px 4px; }
.opt img { flex: none; width: 32px; height: 32px; border-radius: 5px; object-fit: cover; }
.opt:hover { border-color: var(--accent); }
.opt[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-tint); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.opt.is-out { border-style: dashed; color: var(--muted); }
.opt.is-out span { text-decoration: line-through; }

.stock { margin: 4px 0 18px; font-size: 14px; color: var(--muted); }
.stock.is-out { font-weight: 600; color: var(--accent); }

.actions { display: flex; flex-wrap: wrap; gap: 12px; }
.action-hint { margin: 10px 0 0; font-size: 13px; color: var(--muted); }

.specs {
  display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px;
  margin: 24px 0 0; padding-top: 20px; border-top: 1px solid var(--line); font-size: 14px;
}
.specs dt { color: var(--muted); }
.specs dd { margin: 0; overflow-wrap: anywhere; }

.copy-id {
  padding: 1px 6px; border: 1px dashed var(--line); border-radius: 4px; background: none;
  font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); cursor: copy;
}
.copy-id:hover { border-color: var(--accent); color: var(--text); }
.copy-id.is-copied::after { content: " ✓ Đã sao chép"; font-family: "Be Vietnam Pro", system-ui, sans-serif; color: var(--accent); }

.related { margin-top: 56px; }
.related h2 { margin: 0 0 16px; font-size: 20px; }

.site-footer { padding: 20px 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

/* Responsive */

@media (max-width: 899px) {
  .list-view { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .categories {
    position: static; max-height: none; flex-direction: row; gap: 8px;
    margin: 0 -16px; padding: 0 16px 4px; overflow-x: auto; scrollbar-width: none;
  }
  .cat-group { display: contents; }
  .cat-group-title { display: none; }
  .cat {
    flex: none; width: auto; padding: 6px 14px; white-space: nowrap;
    border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  }
  .cat.is-active { border-color: var(--accent); }
  .detail { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .gallery { position: static; }
}

@media (max-width: 520px) {
  .header-inner { gap: 10px; }
  .logo { font-size: 16px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card-body { padding: 8px 10px 10px; }
  .card-price { font-size: 14px; }
  .toolbar h1 { font-size: 19px; }
  .detail-name { font-size: 20px; }
  .price { font-size: 24px; }
  .actions .btn { width: 100%; }
}
