/*
 * Ưu đãi (B04): thanh freeship ở giỏ, bảng Chọn ưu đãi (M5c/D5c), vé có ô chọn / chưa đủ điều kiện,
 * thẻ "Ưu đãi" ở thanh toán, trang Kho ưu đãi (M7/D7). Vé dùng component .tg-ticket (components.css).
 * Phụ thuộc: shop.css, shop-forms.css
 */

/* =========================================================
   Thanh freeship (M4: đầu thẻ sản phẩm; D4: thẻ riêng)
   ========================================================= */
.tg-freeship {
  margin-bottom: calc(-1 * var(--space-2));
  padding: var(--space-3) var(--space-3) 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.tg-freeship + .tg-cart-head + .tg-cart-items,
.tg-freeship + .tg-cart-items {
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.tg-freeship__row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "icon text more"
    "bar bar bar";
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2-5) var(--space-3);
  border: 0;
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--color-freeship) 10%, var(--color-surface));
  color: var(--color-text);
  font-size: var(--text-meta);
  text-align: left;
}

.tg-freeship__icon {
  display: flex;
  grid-area: icon;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-round);
  background: var(--color-freeship-strong);
  color: var(--color-text-on-dark);
  --icon-size: 15px;
}

.tg-freeship__text {
  grid-area: text;
}

.tg-freeship__text strong {
  color: var(--color-freeship-strong);
}

.tg-freeship__bar {
  display: block;
  grid-area: bar;
  overflow: hidden;
  height: 5px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--color-freeship) 25%, var(--color-surface));
}

.tg-freeship__bar span {
  display: block;
  height: 100%;
  background: var(--color-freeship-strong);
}

.tg-freeship__more {
  display: flex;
  grid-area: more;
  align-items: center;
  gap: var(--space-0-5);
  color: var(--color-freeship-strong);
  --icon-size: 14px;
}

/* =========================================================
   Vé ưu đãi: chưa đủ điều kiện, lựa chọn tốt nhất, sắp hết hạn
   ========================================================= */
.tg-voucher {
  --ticket-page-bg: var(--color-bg);
  cursor: default;
}

label.tg-voucher {
  cursor: pointer;
}

.tg-voucher .tg-ticket__title,
.tg-voucher .tg-ticket__desc,
.tg-voucher .tg-ticket__expiry {
  display: block;
}

.tg-voucher.is-disabled {
  --ticket-bg: var(--color-border-strong);
  cursor: default;
}

.tg-voucher.is-disabled .tg-ticket__title {
  color: var(--color-text-secondary);
}

.tg-voucher.is-best {
  border-color: var(--color-red);
}

.tg-ticket--freeship.is-best {
  border-color: var(--color-freeship-strong);
}

.tg-voucher__best {
  position: absolute;
  top: -1px;
  right: -1px;
  z-index: 1;
  padding: 1px var(--space-2);
  border-radius: 0 var(--radius-xl) 0 var(--radius-md);
  background: var(--color-red);
  color: var(--color-text-on-dark);
  font-size: var(--text-label);
  font-weight: var(--weight-bold);
}

.tg-ticket--freeship .tg-voucher__best {
  background: var(--color-freeship-strong);
}

.tg-voucher__note {
  overflow: hidden;
  color: var(--color-red-strong);
  font-size: var(--text-meta);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tg-voucher__soon {
  color: var(--color-red-strong);
  --icon-size: 13px;
}

.tg-voucher__used {
  display: flex;
  align-items: center;
  gap: var(--space-1-5);
  color: var(--color-red-strong);
  font-size: var(--text-meta);
}

.tg-voucher__used > span {
  position: relative;
  overflow: hidden;
  width: 64px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--color-red-soft);
}

.tg-voucher__used > span::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--used);
  background: var(--color-red);
}

.tg-voucher__radio {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--color-red);
}

.tg-ticket--freeship .tg-voucher__radio {
  accent-color: var(--color-freeship-strong);
}

/* =========================================================
   Bảng Chọn ưu đãi
   ========================================================= */
.tg-voucher-sheet .tg-sheet__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  background: var(--color-bg);
}

.tg-voucher-code {
  display: flex;
  flex-direction: column;
  gap: var(--space-1-5);
}

.tg-voucher-code__row {
  display: flex;
  gap: var(--space-2);
}

.tg-voucher-code__row .tg-input {
  flex: 1;
  min-width: 0;
  text-transform: uppercase;
}

.tg-voucher-code__row .tg-input::placeholder {
  text-transform: none;
}

.tg-voucher-code__ok {
  color: var(--color-brand-strong);
  font-size: var(--text-meta);
}

.tg-voucher-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  border: 0;
}

.tg-voucher-group__title {
  margin-bottom: var(--space-2);
  font-size: var(--text-15);
  font-weight: var(--weight-bold);
}

.tg-voucher-group__list,
.tg-wallet-list__items {
  display: flex;
  flex-direction: column;
  gap: var(--space-2-5);
  margin: 0;
  padding: 0;
  list-style: none;
}

.tg-voucher-sheet__foot {
  flex-wrap: wrap;
  align-items: center;
}

.tg-voucher-sheet__summary {
  flex-basis: 100%;
  color: var(--color-text-secondary);
  font-size: var(--text-meta);
}

.tg-voucher-sheet__foot .tg-btn--primary {
  flex: 1;
}

/* =========================================================
   Thẻ "Ưu đãi" ở thanh toán
   ========================================================= */
.tg-checkout-offer {
  padding-block: var(--space-1);
}

.tg-checkout-offer__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: var(--tap-min);
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-text);
  font-size: var(--text-14);
  text-align: left;
  --icon-size: 18px;
}

.tg-checkout-offer__row > .tg-icon:first-child {
  color: var(--color-brand-strong);
}

.tg-checkout-offer__tags {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-1-5);
}

.tg-checkout-offer__change {
  color: var(--color-brand);
}

/* =========================================================
   Kho ưu đãi (M7/D7)
   ========================================================= */
.tg-wallet-add {
  gap: var(--space-1-5);
}

.tg-wallet-tabs {
  margin-top: 0;
}

.tg-wallet-list {
  display: block;
}

@media (min-width: 1024px) {
  .tg-freeship {
    margin-bottom: 0;
    padding: 0;
    border-radius: var(--radius-xl);
    background: none;
  }

  .tg-freeship + .tg-cart-head + .tg-cart-items {
    border-radius: var(--radius-xl);
  }

  .tg-freeship__row {
    grid-template-columns: auto auto minmax(160px, 280px) 1fr;
    grid-template-areas: "icon text bar more";
    gap: var(--space-4);
    padding: var(--space-4) var(--space-6);
    border-radius: var(--radius-xl);
    font-size: var(--text-15);
  }

  .tg-freeship__bar {
    height: 6px;
  }

  .tg-freeship__more {
    justify-self: end;
    font-size: var(--text-14);
  }

  .tg-voucher-sheet {
    --dialog-width: 680px;
  }

  /* D5c: mã giảm giá trước, phí vận chuyển sau */
  .tg-voucher-group--discount {
    order: 1;
  }

  .tg-voucher-group--freeship {
    order: 2;
  }

  .tg-voucher-sheet .tg-sheet__body {
    background: var(--color-surface);
  }

  .tg-voucher-sheet .tg-voucher {
    --ticket-page-bg: var(--color-surface);
  }

  .tg-voucher-sheet__summary {
    flex: 1;
    flex-basis: auto;
  }

  .tg-voucher-sheet__foot .tg-btn {
    flex: none;
    min-width: 140px;
  }

  .tg-checkout-offer {
    padding: var(--space-4) var(--space-6);
  }

  .tg-checkout-offer__row {
    font-size: var(--text-16);
  }

  .tg-wallet-list__items {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
  }
}
