/*
 * Trang danh mục (templates/collection.bwt), mockup "Danh mục Laptop".
 * Mobile: chip nhanh, thanh Bộ lọc + Sắp xếp dính dưới header, lưới 2 cột, Xem thêm,
 * bảng lọc toàn màn hình. Desktop (64em): cột lọc 260px, lưới 4 cột, phân trang.
 */

.tpl-collection main { background: var(--color-surface-alt); }
.coll { padding-bottom: var(--space-7); }
.coll .crumbs { background: var(--color-surface); }
.coll-banner { margin: 0 var(--space-4) var(--space-3); }
.coll-banner:not(.cbanner--pair) { display: none; }

.coll-main { min-width: 0; display: flex; flex-direction: column; }

/* ---------- Tiêu đề, chip nhanh ---------- */

.coll-head {
  padding: 0 var(--space-4) var(--space-2);
  background: var(--color-surface);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 var(--space-2);
}
.coll-title { margin: 0; font-size: 1.25rem; line-height: var(--leading-tight); font-weight: var(--weight-strong); }
.coll-count { margin: 0; font-size: var(--text-sm); color: var(--color-text-muted); white-space: nowrap; }

.coll-quick { padding: 0 0 var(--space-3); background: var(--color-surface); display: flex; flex-direction: column; gap: var(--space-2); }
.coll-quick-list {
  list-style: none;
  margin: 0;
  padding: 2px var(--space-4);
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  scrollbar-width: none;
}
.coll-quick-list::-webkit-scrollbar { display: none; }
.coll-qchip {
  flex: none;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: var(--weight-strong);
  white-space: nowrap;
  cursor: pointer;
}
.coll-quick-list.is-brand .coll-qchip { border-radius: var(--radius-sm); }
.coll-qchip:hover { border-color: var(--color-border-strong); }
.coll-qchip[aria-pressed="true"] { border-color: var(--color-action); background: var(--color-action-bg); color: var(--color-action-hover); box-shadow: inset 0 0 0 1px var(--color-action); }

/* ---------- Thanh Bộ lọc + Sắp xếp ---------- */

.coll-bar {
  position: sticky;
  top: var(--header-compact-h);
  z-index: calc(var(--z-sticky) - 1);
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border-top: 1px solid var(--color-surface-sunken);
  border-bottom: 1px solid var(--color-border);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: var(--space-2);
}
.coll-filter-btn {
  height: var(--tap-min);
  border: 0;
  border-radius: var(--radius-sm);
  box-shadow: inset 0 0 0 1.5px var(--color-text);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-weight: var(--weight-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  cursor: pointer;
}
.coll-filter-btn .icon { width: 20px; height: 20px; }
.coll-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--color-action);
  color: var(--color-on-action);
  font-size: var(--text-xs);
  display: grid;
  place-items: center;
}
.coll-sort { position: relative; display: flex; }
.coll-sort-label {
  position: absolute;
  left: 12px; top: 3px;
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  pointer-events: none;
}
.coll-sort select {
  width: 100%;
  height: var(--tap-min);
  padding: 12px 32px 0 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23373D4E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center;
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
  appearance: none;
  cursor: pointer;
}
.coll-sort-tabs { display: none; }

/* ---------- Đang lọc ---------- */

.coll-applied { padding: var(--space-3) var(--space-4) 0; display: flex; flex-direction: column; gap: var(--space-2); }
.coll-found { margin: 0; font-size: var(--text-sm); color: var(--color-text-muted); }
.coll-found b { color: var(--color-text); }
.coll-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.coll-chip {
  height: 32px;
  padding: 0 4px 0 12px;
  border: 1px solid var(--color-action-border);
  border-radius: var(--radius-full);
  background: var(--color-action-bg);
  color: var(--color-action-hover);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: var(--weight-strong);
  display: flex;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.coll-chip .icon { width: 28px; height: 16px; }

.coll-link {
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-link);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: var(--weight-strong);
  cursor: pointer;
}
.coll-link:hover { color: var(--color-link-hover); text-decoration: underline; }
.coll-link[disabled] { color: var(--color-disabled); cursor: default; text-decoration: none; }

/* ---------- Lưới, Xem thêm, phân trang ---------- */

.coll-results { position: relative; padding: var(--space-3) var(--space-4) 0; transition: opacity var(--duration-fast); }
.coll-results.is-loading { opacity: .45; pointer-events: none; }
.coll-results.is-loading::after {
  content: "Đang tải sản phẩm…";
  position: absolute;
  top: 120px; left: 50%;
  transform: translateX(-50%);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  background: var(--color-inverse);
  color: var(--color-on-inverse-strong);
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
  box-shadow: var(--shadow-lg);
}
.coll-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
.coll-grid > li { min-width: 0; }
.coll-error { margin: 0 0 var(--space-3); padding: var(--space-3); border-radius: var(--radius-sm); background: var(--color-danger-bg); color: var(--color-danger); font-size: var(--text-sm); }

.coll-more { padding: var(--space-5) 0 0; display: flex; flex-direction: column; align-items: center; gap: var(--space-2); text-align: center; }
.coll-more-count { margin: 0; font-size: var(--text-sm); color: var(--color-text-muted); }
.coll-more-bar { width: 160px; height: 4px; border: 0; border-radius: 2px; background: var(--color-border); appearance: none; overflow: hidden; }
.coll-more-bar::-webkit-progress-bar { background: var(--color-border); }
.coll-more-bar::-webkit-progress-value { background: var(--color-action); }
.coll-more-bar::-moz-progress-bar { background: var(--color-action); }
.coll-more-btn { width: 100%; max-width: 360px; text-decoration: none; }
.coll-more-btn.is-busy { opacity: .6; pointer-events: none; }

.coll-pages { display: none; }

/* ---------- Không có kết quả, danh mục trống ---------- */

.coll-state {
  margin: var(--space-2) 0;
  padding: var(--space-6) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}
.coll-state > .icon { width: 40px; height: 40px; color: var(--color-text-subtle); }
.coll-state h2 { margin: 0; font-size: var(--text-lg); line-height: var(--leading-tight); }
.coll-state p { margin: 0; color: var(--color-text-muted); font-size: var(--text-sm); }
.coll-state-actions { width: 100%; max-width: 360px; margin-top: var(--space-2); display: grid; gap: var(--space-2); }
.coll-nr-list { list-style: none; width: 100%; max-width: 360px; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.coll-nr {
  width: 100%;
  min-height: var(--tap-min);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  cursor: pointer;
  text-align: left;
}
.coll-nr:hover { border-color: var(--color-border-strong); }
.coll-nr-n { flex: none; color: var(--color-link); }

/* ---------- Mô tả danh mục ---------- */

.coll-desc { margin: var(--space-6) var(--space-4) 0; padding: var(--space-4); border-radius: var(--radius-md); background: var(--color-surface); }
.coll-desc h2 { margin: 0 0 var(--space-2); font-size: var(--text-lg); line-height: var(--leading-tight); }
.coll-desc-body { font-size: var(--text-sm); }
.coll-desc-body { line-height: 1.6; }
.coll-desc-body.is-clamped { max-height: calc(4 * 1.6em); overflow: hidden; -webkit-mask-image: linear-gradient(#000 60%, transparent); mask-image: linear-gradient(#000 60%, transparent); }
.coll-desc-body > :first-child { margin-top: 0; }

/* ---------- Bảng lọc: mobile toàn màn hình ---------- */

html.coll-filter-open { overflow: hidden; }
.coll-scrim { display: none; }

.coll-filter:not(.is-open) { display: none; }
.coll-filter.is-open {
  position: fixed;
  inset: 0;
  z-index: var(--z-sheet);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
}
.coll-filter-head {
  flex: none;
  height: 56px;
  padding: 0 4px 0 var(--space-4);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.coll-filter-title { margin: 0; font-size: 1.125rem; font-weight: var(--weight-strong); }
.coll-filter-sel { font-size: 0.8125rem; color: var(--color-text-muted); }
.coll-filter-sel b { font-weight: var(--weight-regular); }
.coll-filter-head .coll-link { display: none; }
.coll-filter-close {
  margin-left: auto;
  width: var(--tap-min);
  height: var(--tap-min);
  border: 0;
  background: transparent;
  color: var(--color-text);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.coll-filter-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.coll-filter-foot {
  flex: none;
  padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--color-border);
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: var(--space-2);
}

.coll-group { border-bottom: 1px solid var(--color-surface-sunken); }
.coll-group summary {
  min-height: 52px;
  padding: 0 var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  list-style: none;
  cursor: pointer;
  font-weight: var(--weight-strong);
}
.coll-group summary::-webkit-details-marker { display: none; }
.coll-group-sum {
  margin-left: auto;
  max-width: 50%;
  font-size: 0.8125rem;
  font-weight: var(--weight-regular);
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.coll-group[open] .coll-group-sum { display: none; }
.coll-group summary .icon { flex: none; width: 20px; height: 20px; color: var(--color-text-muted); transition: transform var(--duration-fast); }
.coll-group[open] summary .icon { margin-left: auto; transform: rotate(180deg); }
.coll-group fieldset { margin: 0; padding: 0 var(--space-4) var(--space-4); border: 0; min-width: 0; }

.coll-opts { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.coll-opt { position: relative; display: flex; }
.coll-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.coll-opt span {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.8125rem;
  font-weight: var(--weight-strong);
  display: flex;
  align-items: center;
  cursor: pointer;
}
.coll-opt input:checked + span { border-color: var(--color-action); background: var(--color-action-bg); color: var(--color-action-hover); box-shadow: inset 0 0 0 1px var(--color-action); }
.coll-opt input:focus-visible + span { outline: 3px solid var(--color-focus); outline-offset: 2px; }
.coll-opts-more { margin-top: var(--space-2); }

/* ---------- Desktop ---------- */

/* ---------- Danh mục Flash sale: khối đầu trang đỏ + đồng hồ, không bộ lọc ---------- */

.fs-hero {
  position: relative;
  overflow: hidden;
  margin: 0 var(--space-4) var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: linear-gradient(120deg, var(--red-800) 0%, var(--red-600) 55%, var(--red-500) 100%);
  color: #fff;
  display: grid;
  gap: var(--space-3);
}
/* Tia sét mờ trang trí góc phải */
.fs-hero::after {
  content: "";
  position: absolute;
  right: -24px; top: -30px;
  width: 180px; height: 240px;
  background: rgb(255 255 255 / 0.08);
  clip-path: polygon(55% 0, 15% 55%, 45% 55%, 30% 100%, 85% 38%, 55% 38%, 75% 0);
  pointer-events: none;
}
.fs-hero-text { position: relative; z-index: 1; min-width: 0; }
.fs-hero-kicker {
  margin: 0 0 var(--space-1);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px 2px 6px;
  border-radius: var(--radius-full);
  background: #FFD84D;
  color: var(--red-800);
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  letter-spacing: .06em;
  text-transform: uppercase;
}
.fs-hero-kicker .icon { width: 16px; height: 16px; }
.fs-hero-title { margin: 0; font-size: 1.5rem; line-height: var(--leading-tight); font-weight: var(--weight-strong); }
.fs-hero-sub { margin: var(--space-1) 0 0; font-size: var(--text-sm); opacity: .92; }
.fs-clock { position: relative; z-index: 1; }
.fs-clock[hidden], .fs-ended[hidden], .fs-box[hidden] { display: none; }
.fs-clock-label { margin: 0 0 6px; font-size: var(--text-xs); font-weight: var(--weight-strong); text-transform: uppercase; letter-spacing: .04em; opacity: .9; }
.fs-clock-boxes { margin: 0; display: flex; gap: 6px; }
.fs-box {
  min-width: 48px;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--red-700);
  display: grid; justify-items: center;
  line-height: 1.1;
}
.fs-box b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.fs-box small { font-size: 11px; color: var(--color-text-muted); }
.fs-ended { position: relative; z-index: 1; margin: 0; font-size: var(--text-sm); font-weight: var(--weight-strong); }
.fs-hero.is-ended { background: linear-gradient(120deg, var(--gray-900), #3a3f4f); }
.fs-hero.is-ended .fs-hero-kicker { background: #fff; color: var(--gray-900); }

.coll.is-flash .coll-head { padding-top: var(--space-2); }
.coll.is-flash .coll-title { font-size: var(--text-base); }
.coll.is-flash .coll-results .pcard { box-shadow: inset 0 3px 0 var(--red-500); }


@media (min-width: 64em) {
  .coll { max-width: var(--page-max); margin: 0 auto; padding: 0 var(--page-gutter) var(--space-7); }
  .coll .crumbs { background: transparent; }
  .coll-banner { margin: 0 0 var(--space-4); }
  .coll-banner:not(.cbanner--pair) { display: block; }
  .coll-banner.cbanner--pair { display: flex; }
  .fs-hero { margin: 0 0 var(--space-4); padding: var(--space-5) var(--space-6); grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--space-5); }
  .fs-hero::after { right: 18%; width: 220px; height: 300px; top: -40px; }
  .fs-hero-title { font-size: 2rem; }
  .fs-hero-sub { font-size: var(--text-base); }
  .fs-box { min-width: 64px; padding: 8px 6px; }
  .fs-box b { font-size: 1.75rem; }
  .coll.is-flash .coll-title { font-size: var(--text-lg); }

  .coll-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: var(--space-5); align-items: start; }
  .coll-layout:not(:has(.coll-filter)) { grid-template-columns: minmax(0, 1fr); }

  /* Cột lọc */
  .coll-filter:not(.is-open) {
    position: sticky;
    top: calc(var(--header-compact-h) + var(--space-4));
    max-height: calc(100vh - var(--header-compact-h) - var(--space-6));
    overflow-y: auto;
    padding: var(--space-2) var(--space-4) var(--space-4);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    display: block;
  }
  .coll-filter-head { height: auto; padding: var(--space-2) 0; justify-content: space-between; }
  .coll-filter-title { font-size: var(--text-base); }
  .coll-filter-sel, .coll-filter-close, .coll-filter-foot { display: none !important; }
  .coll-filter-head .coll-link { display: block; }
  .coll-filter-body { overflow: visible; }
  .coll-group summary { min-height: 48px; padding: 0; font-size: var(--text-sm); }
  .coll-group fieldset { padding: 0 0 var(--space-3); }
  .coll-opts { flex-direction: column; flex-wrap: nowrap; gap: 0; }
  .coll-opt { align-items: center; gap: 10px; min-height: 32px; font-size: var(--text-sm); color: var(--color-text); cursor: pointer; }
  .coll-opt input { position: static; opacity: 1; width: 18px; height: 18px; margin: 0; accent-color: var(--color-action); cursor: pointer; }
  .coll-opt span, .coll-opt input:checked + span { min-height: 0; padding: 0; border: 0; background: none; box-shadow: none; color: inherit; font-size: inherit; font-weight: var(--weight-regular); }
  .coll-opt input:focus-visible + span { outline: 0; }

  /* Cột phải */
  .coll-head { padding: 0 0 var(--space-2); background: transparent; }
  .coll-title { font-size: var(--text-2xl); }
  .coll-quick { padding: 0 0 var(--space-3); background: transparent; flex-direction: row; flex-wrap: wrap; }
  .coll-quick-list { padding: 0; flex-wrap: wrap; overflow: visible; }
  .coll-quick-list.is-brand { display: none; }

  .coll-bar { position: static; padding: var(--space-2) 0; background: transparent; border: 0; border-bottom: 1px solid var(--color-border); display: flex; }
  .coll-filter-btn, .coll-sort { display: none; }
  .coll-sort-tabs { display: flex; align-items: center; gap: var(--space-1); }
  .coll-sort-tabs-label { margin-right: var(--space-2); font-size: var(--text-sm); color: var(--color-text-muted); }
  .coll-sort-tabs button {
    height: 36px;
    padding: 0 12px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: var(--weight-strong);
    cursor: pointer;
  }
  .coll-sort-tabs button:hover { background: var(--color-surface); }
  .coll-sort-tabs button[aria-pressed="true"] { background: var(--color-action-bg); color: var(--color-action-hover); }

  .coll-applied { padding: var(--space-3) 0 0; flex-direction: row; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
  .coll-results { padding: var(--space-3) 0 0; }
  .coll-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-3); }
  .coll-grid .pcard { padding: 10px; }
  .coll-grid .pcard:hover { border-color: var(--color-action); box-shadow: var(--shadow-sm); }

  .coll-more { display: none; }
  .coll-pages { padding-top: var(--space-5); display: flex; justify-content: center; gap: var(--space-2); }
  .coll-pg {
    min-width: 40px;
    height: 40px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    box-shadow: inset 0 0 0 1px var(--color-border);
    color: var(--color-text);
    font-weight: var(--weight-strong);
    text-decoration: none;
    display: grid;
    place-items: center;
  }
  a.coll-pg:hover { box-shadow: inset 0 0 0 1px var(--color-border-strong); color: var(--color-action-hover); }
  .coll-pg.is-current { background: var(--color-action); color: var(--color-on-action); box-shadow: none; }
  .coll-pg.is-gap { background: transparent; box-shadow: none; }
  .coll-pg .icon { width: 20px; height: 20px; }

  .coll-state { padding: var(--space-7) var(--space-5); }
  .coll-state-actions { grid-template-columns: 1fr 1fr; max-width: 420px; }
  .coll-desc { margin: var(--space-6) 0 0; padding: var(--space-5); }
}