/*
 * Base — reset, kiểu chữ, khung nội dung, lưới, tiện ích dùng chung.
 * Phụ thuộc: tokens.css
 */

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6,
p, figure, blockquote, dl, dd {
  margin: 0;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--weight-bold);
  line-height: var(--leading-snug);
}

/* :where() để độ ưu tiên bằng 0, không đè margin/padding của class như .tg-scroll-x */
:where(ul[role="list"], ol[role="list"]) {
  margin: 0;
  padding: 0;
  list-style: none;
}

img,
picture,
video,
svg {
  display: block;
  max-width: 100%;
}

img {
  height: auto;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--color-brand);
  text-decoration: none;
}

a:hover {
  color: var(--color-brand-strong);
}

::placeholder {
  color: var(--color-placeholder);
  opacity: 1;
}

/* ---------- Focus khi dùng bàn phím ---------- */
:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.tg-on-dark :focus-visible {
  outline: var(--focus-ring-on-dark);
}

/* ---------- Giảm chuyển động ---------- */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Khung nội dung ---------- */
.tg-container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* 768–1023px vẫn là bố cục mobile, nội dung giới hạn chiều rộng */
@media (min-width: 768px) and (max-width: 1023px) {
  .tg-container--narrow-tablet {
    max-width: 720px;
  }
}

.tg-page {
  display: flex;
  flex-direction: column;
  gap: var(--section-gap);
  padding-block: var(--section-gap);
}

/* Khối đầu trang dính sát header (khối mở đầu trang chủ mobile) */
.tg-page--flush-top {
  padding-top: 0;
}

/* Trang có thanh dính đáy (bottom nav, thanh hành động): chừa chỗ ở cuối body,
   để cả main lẫn footer (nằm sau main) đều không bị thanh che */
@media (max-width: 1023px) {
  body:has(.tg-bottom-nav) {
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
  }

  body:has(.tg-action-bar) {
    padding-bottom: calc(var(--action-bar-height) + env(safe-area-inset-bottom, 0px));
  }
}

/* ---------- Lưới ---------- */
.tg-stack {
  display: flex;
  flex-direction: column;
  gap: var(--stack-gap, var(--space-3));
}

.tg-cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--cluster-gap, var(--space-2));
}

/* Lưới sản phẩm: 2 cột mobile, 3 cột từ 768px, 4 cột desktop (có thể ghi đè --grid-cols-desktop) */
.tg-grid-products {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2-5);
}

/* Thẻ bọc trong <li>: kéo cao bằng ô để thẻ cùng hàng dài bằng nhau (thẻ có giá gạch, dải Flash Sale cao hơn) */
.tg-grid-products > li > .tg-product-card {
  height: 100%;
}

@media (min-width: 768px) {
  .tg-grid-products {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-3);
  }
}

@media (min-width: 1024px) {
  .tg-grid-products {
    grid-template-columns: repeat(var(--grid-cols-desktop, 4), minmax(0, 1fr));
    gap: var(--space-4);
  }
}

/* Hàng cuộn ngang (chip, thẻ đánh giá trên mobile) */
.tg-scroll-x {
  display: flex;
  gap: var(--scroll-gap, var(--space-2));
  overflow-x: auto;
  /* overflow-x: auto kéo theo overflow-y: auto; lớp phủ vùng bấm 44px của chip (cao hơn chip) sẽ thành vùng cuộn dọc */
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  margin-inline: calc(var(--gutter) * -1);
  padding-inline: var(--gutter);
}

.tg-scroll-x::-webkit-scrollbar {
  display: none;
}

.tg-scroll-x > * {
  flex: none;
  scroll-snap-align: start;
}

/* ---------- Tiện ích ---------- */
.tg-sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tg-skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: var(--z-toast);
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-min);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-brand);
  color: var(--color-text-on-dark);
  font-weight: var(--weight-semibold);
  transform: translateY(-200%);
}

.tg-skip-link:focus {
  transform: none;
  color: var(--color-text-on-dark);
}

.tg-text-muted {
  color: var(--color-text-muted);
  font-size: var(--text-meta);
}

.tg-text-secondary {
  color: var(--color-text-secondary);
}

.tg-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tg-truncate {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tg-num {
  font-variant-numeric: tabular-nums;
}

/* Chỉ hiện ở mobile / chỉ hiện ở desktop */
@media (min-width: 1024px) {
  .tg-mobile-only {
    display: none !important;
  }
}

@media (max-width: 1023px) {
  .tg-desktop-only {
    display: none !important;
  }
}

/* Thanh quản trị WP (đã đăng nhập): cố định 32px ở desktop, 46px ở 601–782px; từ 600px trở xuống WP cho nó
   cuộn theo trang nên không cần chừa. Phần tử dính mép trên cộng thêm --admin-bar-h để không bị che;
   link neo (#reviews…) cuộn chừa ra cùng khoảng. */
:root:has(body.admin-bar) {
  --admin-bar-h: 32px;
}

@media (max-width: 782px) {
  :root:has(body.admin-bar) {
    --admin-bar-h: 46px;
  }
}

@media (max-width: 600px) {
  :root:has(body.admin-bar) {
    --admin-bar-h: 0px;
  }
}

html {
  scroll-padding-top: var(--admin-bar-h);
}
