/* theme-fix-product-buy.css: giá, phiên bản, khối mua, thanh dính (Agent B). Chỉ nạp trong template product. Scope .template-product.
   Đợt 2: giá + % (ceil) + tiết kiệm, phiên bản hết hàng, stepper 44px, nút #007FAE, 1 H1.
   Đợt 3: thanh dính mobile (≤768px, chỉ khi nút chính khuất), khung phải desktop, hết hàng disabled thật.
   Đợt 3b: .pd3-buy--two / .pd3-sticky--two (công tắc Liquid pd3_two_buttons).
   Dark: chỉ ≤768px dưới html[data-mobile-theme="dark"] (chuẩn SPEC v3). */

.template-product .pd3-buy,
.template-product .pd3-side,
.template-product .pd3-sticky {
  --pd3-ink: #0B1118;
  --pd3-muted: #66727D;
  --pd3-blue: #007FAE;
  --pd3-blue-hover: #006A92;
  --pd3-blue-soft: #E5F6FC;
  --pd3-red: #E32636;
  --pd3-sale: #BF1E2E;
  --pd3-sale-bg: #FFF2F4;
  --pd3-card: #FFFFFF;
  --pd3-surface: #F4F7F9;
  --pd3-surface-strong: #EAF0F3;
  --pd3-border: #DCE4E8;
  --pd3-focus: #007FAE;
  --pd3-link: #007FAE;
}
@media (max-width: 768px) {
  html[data-mobile-theme="dark"] .template-product .pd3-buy,
  html[data-mobile-theme="dark"] .template-product .pd3-side,
  html[data-mobile-theme="dark"] .template-product .pd3-sticky {
    --pd3-ink: #F1F6F8;
    --pd3-muted: #9BAAB4;
    --pd3-blue-soft: #0E2A38;
    --pd3-sale: #FF9BA8;
    --pd3-sale-bg: #291D25;
    --pd3-card: #121C25;
    --pd3-surface: #121C25;
    --pd3-surface-strong: #1A2731;
    --pd3-border: #2C3A45;
    --pd3-focus: #7DD3F5;
    --pd3-link: #7DD3F5;
  }
}

.template-product .pd3-buy .visually-hidden,
.template-product .pd3-side .visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); border: 0; white-space: nowrap;
}
.template-product .pd3-buy [hidden],
.template-product .pd3-side [hidden],
.template-product .pd3-sticky [hidden] { display: none !important; }

/* ---------- Tiêu đề (H1 duy nhất) ---------- */
.template-product .pd3-buy .pd3-buy__title {
  margin: 0 0 8px;
  color: var(--pd3-ink);
  font-size: 28px;
  line-height: 36px;
  font-weight: 700;
  letter-spacing: -.02em;
  text-transform: none;
}
.template-product .pd3-buy .pd3-buy__meta:empty { display: none; }
.template-product .pd3-buy .pd3-buy__soon {
  display: inline-block; margin: 4px 0; padding: 2px 10px; color: #fff; background: var(--pd3-sale); border-radius: 20px; font-size: 12px; font-weight: 700;
}

/* ---------- Giá ---------- */
.template-product .pd3-buy .pd3-price {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  margin: 14px 0 6px;
  font-variant-numeric: tabular-nums lining-nums;
}
.template-product .pd3-buy #ProductPrice,
.template-product .pd3-price__now {
  color: var(--pd3-ink);
  font-size: 28px;
  line-height: 34px;
  font-weight: 700;
  letter-spacing: -.02em;
}
.template-product .pd3-price__badge {
  display: inline-flex;
  align-items: center;
  align-self: center;
  padding: 3px 8px;
  color: #FFFFFF;
  background: var(--pd3-red);
  border-radius: 20px;
  font-size: 13px;
  line-height: 16px;
  font-weight: 700;
}
.template-product .pd3-price__was { color: var(--pd3-muted); font-size: 15px; line-height: 20px; font-weight: 500; }
.template-product .pd3-price__was s { color: inherit; }
.template-product .pd3-price__save { flex-basis: 100%; color: var(--pd3-sale); font-size: 14px; line-height: 20px; font-weight: 600; }

/* Bộ đếm (snippet chung, chỉ đổi màu/cỡ trong khối mua) */
.template-product .pd3-price__timer:not(:has(*)) { display: none; }
.template-product .pd3-buy .pd3-price__timer .sale-cycle-countdown {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0 6px;
  padding: 5px 10px;
  color: var(--pd3-sale) !important;
  background: var(--pd3-sale-bg) !important;
  border: 0 !important;
  border-radius: 8px;
  font-size: 12px;
  line-height: 16px;
}
.template-product .pd3-buy .pd3-price__timer .sale-cycle-countdown * { color: var(--pd3-sale) !important; }
.template-product .pd3-buy .pd3-price__timer .sale-cycle-countdown strong { font-size: 13px; font-variant-numeric: tabular-nums; }
.template-product .pd3-buy .pd3-price__timer .sale-cycle-countdown__separator { margin: 0 !important; }

/* ---------- Form ---------- */
.template-product .pd3-buy #AddToCartForm { display: block; margin: 0; }
.template-product .pd3-buy .pd3-buy__select { position: absolute; width: 1px; height: 1px; max-height: 0; overflow: hidden; visibility: hidden; }

/* Phiên bản */
.template-product .pd3-buy .pd3-buy__options { margin: 12px 0 0; }
.template-product .pd3-buy .pd3-opt { min-width: 0; margin: 0 0 14px; padding: 0; border: 0; }
.template-product .pd3-buy .pd3-opt__legend {
  width: auto; margin: 0 0 8px; padding: 0; color: var(--pd3-muted); border: 0;
  font-size: 14px; line-height: 20px; font-weight: 500; text-transform: none; letter-spacing: 0;
}
.template-product .pd3-buy .pd3-opt__current { color: var(--pd3-ink); font-weight: 600; }
.template-product .pd3-buy .pd3-opt__list { display: flex; flex-wrap: wrap; gap: 8px; }
.template-product .pd3-buy .pd3-opt__item { position: relative; margin: 0; }
.template-product .pd3-buy .pd3-opt__item .pd3-opt__input {
  position: absolute; top: 0; left: 0; width: 1px; height: 1px; margin: 0; padding: 0; opacity: 0; display: block;
}
.template-product .pd3-buy .pd3-opt__item .pd3-opt__label {
  position: relative;
  display: inline-flex;
  float: none;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 7px 14px;
  color: var(--pd3-ink);
  background: var(--pd3-card);
  border: 1px solid var(--pd3-border);
  border-radius: 10px;
  font-size: 14px;
  line-height: 18px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  text-transform: none;
}
.template-product .pd3-buy .pd3-opt__thumb { display: block; width: 28px; height: 28px; margin: -2px 0 -2px -6px; object-fit: contain; background: #FFFFFF; border-radius: 6px; }
.template-product .pd3-buy .pd3-opt__out { display: none; }
.template-product .pd3-buy .pd3-opt__input:checked + .pd3-opt__label {
  background: var(--pd3-blue-soft);
  border-color: var(--pd3-blue);
  box-shadow: inset 0 0 0 1px var(--pd3-blue);
  font-weight: 600;
}
.template-product .pd3-buy .pd3-opt__input:focus-visible + .pd3-opt__label { outline: 3px solid var(--pd3-focus); outline-offset: 3px; }
.template-product .pd3-buy .pd3-opt__item.is-soldout .pd3-opt__label {
  color: var(--pd3-muted);
  background-color: var(--pd3-surface);
  background-image: linear-gradient(to top right, transparent calc(50% - .5px), var(--pd3-border) calc(50% - .5px), var(--pd3-border) calc(50% + .5px), transparent calc(50% + .5px));
  border-style: dashed;
}
.template-product .pd3-buy .pd3-opt__item.is-soldout .pd3-opt__thumb { opacity: .55; }
.template-product .pd3-buy .pd3-opt__item.is-soldout .pd3-opt__out {
  display: inline-block; padding: 1px 6px; color: var(--pd3-muted); background: var(--pd3-surface-strong); border-radius: 6px; font-size: 11px; line-height: 14px; font-weight: 600;
}
.template-product .pd3-buy .pd3-buy__fixed { margin: 4px 0 14px; color: var(--pd3-muted); font-size: 14px; line-height: 20px; }
.template-product .pd3-buy .pd3-cap { display: inline-block; }
.template-product .pd3-buy .pd3-cap::first-letter { text-transform: uppercase; }
.template-product .pd3-buy .pd3-buy__fixed strong { color: var(--pd3-ink); font-weight: 600; }

/* Số lượng + yêu thích */
.template-product .pd3-buy .pd3-buy__row { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; }
.template-product .pd3-buy .pd3-buy__qty {
  display: inline-flex; align-items: stretch; height: 44px; overflow: hidden; background: var(--pd3-card); border: 1px solid var(--pd3-border); border-radius: 10px;
}
.template-product .pd3-buy .pd3-buy__step {
  width: 44px; height: 42px; margin: 0; padding: 0; color: var(--pd3-ink); background: transparent; border: 0; font-size: 20px; line-height: 42px; font-weight: 500; cursor: pointer;
}
.template-product .pd3-buy .pd3-buy__step:hover { background: var(--pd3-surface); }
.template-product .pd3-buy .pd3-buy__qty-input {
  width: 48px; height: 42px; margin: 0; padding: 0; color: var(--pd3-ink); background: transparent; border: 0; border-left: 1px solid var(--pd3-border); border-right: 1px solid var(--pd3-border); border-radius: 0;
  font-size: 16px; font-weight: 600; text-align: center; box-shadow: none; -moz-appearance: textfield;
}
.template-product .pd3-buy .pd3-buy__row .wishlist,
.template-product .pd3-buy .pd3-buy__row .product-quick-whistlist {
  display: inline-flex !important; width: 44px !important; height: 44px !important; min-width: 0 !important; align-items: center; justify-content: center;
  margin: 0 !important; padding: 0 !important; color: var(--pd3-muted) !important; background: var(--pd3-card) !important; border: 1px solid var(--pd3-border) !important; border-radius: 10px !important; box-shadow: none !important; font-size: 20px; line-height: 1;
}
.template-product .pd3-buy .pd3-buy__row .wishlist:hover { color: var(--pd3-red) !important; }

/* Nút mua */
.template-product .pd3-buy .pd3-buy__actions,
.template-product .pd3-side .pd3-side__actions { display: flex; gap: 10px; margin: 0; }
.template-product .pd3-buy .pd3-buy__actions { flex-wrap: wrap; }
.template-product .pd3-buy .pd3-buy__actions .pd3-buy__btn,
.template-product .pd3-buy .pd3-buy__actions #AddToCart { flex: 1 1 140px; }
.template-product .pd3-buy .pd3-buy__btn,
.template-product .pd3-buy #AddToCart,
.template-product .pd3-side .pd3-buy__btn,
.template-product .pd3-sticky .pd3-buy__btn {
  display: inline-flex;
  flex: 1 1 0;
  min-width: 0;
  max-width: none;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 !important;
  padding: 10px 16px;
  color: #FFFFFF;
  background: var(--pd3-blue);
  border: 1px solid var(--pd3-blue);
  border-radius: 10px;
  box-shadow: none;
  font-size: 16px;
  line-height: 20px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
  opacity: 1;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.template-product .pd3-buy .pd3-buy__btn:hover,
.template-product .pd3-buy #AddToCart:hover,
.template-product .pd3-side .pd3-buy__btn:hover,
.template-product .pd3-sticky .pd3-buy__btn:hover { color: #FFFFFF; background: var(--pd3-blue-hover); border-color: var(--pd3-blue-hover); }
.template-product .pd3-buy .pd3-buy__btn--ghost,
.template-product .pd3-side .pd3-buy__btn--ghost,
.template-product .pd3-sticky .pd3-buy__btn--ghost { color: var(--pd3-link); background: var(--pd3-card); border-color: var(--pd3-link); }
.template-product .pd3-buy .pd3-buy__btn--ghost:hover,
.template-product .pd3-side .pd3-buy__btn--ghost:hover,
.template-product .pd3-sticky .pd3-buy__btn--ghost:hover { color: var(--pd3-link); background: var(--pd3-surface); border-color: var(--pd3-link); }
.template-product .pd3-buy .pd3-buy__btn:focus-visible,
.template-product .pd3-side .pd3-buy__btn:focus-visible,
.template-product .pd3-sticky .pd3-buy__btn:focus-visible,
.template-product .pd3-buy .pd3-buy__step:focus-visible,
.template-product .pd3-buy .pd3-buy__qty-input:focus-visible,
.template-product .pd3-buy .wishlist:focus-visible,
.template-product .pd3-buy .pd3-buy__out a:focus-visible { outline: 3px solid var(--pd3-focus); outline-offset: 3px; }
.template-product .pd3-buy .pd3-buy__btn[aria-busy="true"],
.template-product .pd3-side .pd3-buy__btn[aria-busy="true"],
.template-product .pd3-sticky .pd3-buy__btn[aria-busy="true"] { cursor: progress; opacity: .75; }
.template-product .pd3-buy .pd3-buy__btn:disabled,
.template-product .pd3-buy #AddToCart:disabled,
.template-product .pd3-side .pd3-buy__btn:disabled,
.template-product .pd3-sticky .pd3-buy__btn:disabled {
  color: var(--pd3-muted);
  background: var(--pd3-surface-strong);
  border-color: var(--pd3-surface-strong);
  cursor: not-allowed;
  opacity: 1;
}
/* codex-polish ép chữ #071019 cho #AddToCart ở dark (4,1:1 trên #007FAE): trả lại chữ trắng 4,6:1 */
@media (max-width: 768px) {
  html[data-mobile-theme="dark"] .template-product .pd3-buy #AddToCart,
  html[data-mobile-theme="dark"] .template-product .pd3-buy #AddToCart span { color: #FFFFFF !important; }
  html[data-mobile-theme="dark"] .template-product .pd3-buy #AddToCart:disabled,
  html[data-mobile-theme="dark"] .template-product .pd3-buy #AddToCart:disabled span { color: var(--pd3-muted) !important; }
}
.template-product .pd3-buy #AddToCart i,
.template-product .pd3-buy #AddToCart .sprite-add-to-cart { display: none; }

.template-product .pd3-buy .pd3-buy__out { margin: 10px 0 0; color: var(--pd3-muted); font-size: 14px; line-height: 21px; }
.template-product .pd3-buy .pd3-buy__out a { color: var(--pd3-link); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.template-product .pd3-buy .pd3-buy__gift { margin: 0 0 12px; }

.template-product .pd3-buy .pd3-buy__nav { margin: 18px 0 0; font-size: 14px; }
.template-product .pd3-buy .pd3-buy__nav a { display: inline-block; padding: 12px 0; color: var(--pd3-link); }

/* ---------- Khung phải desktop (#detail-two) ---------- */
.template-product .pd3-side #detail-two {
  position: relative;
  top: 0 !important;
  max-height: calc(100vh - 220px);
  overflow: auto;
  margin: 0 !important;
  background: var(--pd3-card);
  border: 1px solid var(--pd3-border);
  border-radius: 14px;
  will-change: transform;
}
.template-product .pd3-side .pd3-side__title {
  display: -webkit-box; margin: 0; padding: 14px 14px 2px; overflow: hidden; color: var(--pd3-ink);
  font-size: 15px; line-height: 20px; font-weight: 700; -webkit-box-orient: vertical; -webkit-line-clamp: 3;
}
.template-product .pd3-side .pd3-side__sku { margin: 0; padding: 0 14px 10px; color: var(--pd3-muted); font-size: 12px; line-height: 16px; }
.template-product .pd3-side .pd3-side__sku:empty { display: none; }
.template-product .pd3-side .pd3-side__body { padding: 12px 14px 14px; background: var(--pd3-surface); border-top: 1px solid var(--pd3-border); }
.template-product .pd3-side .pd3-side__price { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.template-product .pd3-side .pd3-side__now { color: var(--pd3-ink); font-size: 22px; line-height: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.template-product .pd3-side .pd3-side__was { margin: 2px 0 0; color: var(--pd3-muted); font-size: 13px; line-height: 18px; }
.template-product .pd3-side .pd3-side__actions { flex-direction: column; gap: 8px; margin-top: 12px; }
.template-product .pd3-side .pd3-buy__btn { flex: 0 0 auto; width: 100%; min-height: 44px; font-size: 15px; }
.template-product .pd3-side .pd3-side__hotline { margin: 10px 0 0; color: var(--pd3-muted); font-size: 12px; line-height: 18px; }
.template-product .pd3-side .pd3-side__hotline a { display: block; color: var(--pd3-ink); font-size: 16px; line-height: 24px; font-weight: 700; }

/* ---------- Thanh dính đáy (mobile) ---------- */
.template-product .pd3-sticky { display: none; }

@media (max-width: 768px) {
  .template-product .pd3-buy .pd3-buy__title { font-size: 22px; line-height: 29px; }
  .template-product .pd3-buy #ProductPrice,
  .template-product .pd3-price__now { font-size: 26px; line-height: 32px; }
  .template-product .pd3-buy .pd3-buy__nav { display: none; }
  .template-product .pd3-buy .pd3-buy__actions .pd3-buy__btn,
  .template-product .pd3-buy .pd3-buy__actions #AddToCart { min-height: 50px; }

  /* Khối tĩnh #detail-two cũ (tên + giá + hotline lặp lại) và thanh cũ: ẩn, đã có thanh dính mới */
  .template-product .pd3-side,
  .template-product .detail-two-container { display: none !important; }

  .template-product .pd3-sticky {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 990;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px));
    background: var(--pd3-card);
    border-top: 1px solid var(--pd3-border);
    box-shadow: 0 -4px 16px rgba(11, 17, 24, .08);
    transform: translateY(110%);
    visibility: hidden;
    transition: transform .2s ease, visibility 0s linear .2s;
  }
  .template-product .pd3-sticky.is-on { transform: none; visibility: visible; transition: transform .2s ease, visibility 0s; }
  .template-product .pd3-sticky__price { display: flex; flex: 0 0 auto; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; }
  .template-product .pd3-sticky__now { color: var(--pd3-ink); font-size: 16px; line-height: 20px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .template-product .pd3-sticky .pd3-price__badge { padding: 1px 6px; font-size: 12px; line-height: 15px; }
  .template-product .pd3-sticky__actions { display: flex; flex: 1 1 auto; gap: 8px; min-width: 0; }
  .template-product .pd3-sticky .pd3-buy__btn { min-height: 44px; padding: 8px 12px; font-size: 15px; }
  .template-product .pd3-sticky--two .pd3-buy__btn { padding: 8px 8px; font-size: 14px; }

  html.pd3-has-sticky body.template-product { padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 359px) {
  .template-product .pd3-sticky { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .template-product .pd3-sticky--two .pd3-sticky__price .pd3-price__badge { display: none !important; }
  .template-product .pd3-sticky--two .pd3-buy__btn { font-size: 13px; padding: 8px 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .template-product .pd3-sticky { transition: none !important; }
}
