/*
 * Giỏ hàng (M4/D4), giỏ trống (M4e/D4e). Đặc tả: docs/plans/11-dac-ta-wireframe.md mục 2.1, 2.2.
 * Phụ thuộc: shop.css
 */

/* =========================================================
   Danh sách sản phẩm
   Mobile: ô tick | ảnh 80px | tên / phân loại + số lượng / giá
   ========================================================= */
.tg-cart-items {
  padding-block: var(--space-1);
}

.tg-cart-item {
  display: grid;
  grid-template-columns: 24px 80px minmax(0, 1fr) auto;
  grid-template-areas:
    "check img name name"
    "check img variant qty"
    "check img price price";
  align-items: center;
  column-gap: var(--space-2-5);
  row-gap: var(--space-1-5);
  padding-block: var(--space-3);
}

.tg-cart-item + .tg-cart-item {
  border-top: 1px solid var(--color-divider);
}

.tg-cart-item__check {
  grid-area: check;
  justify-content: center;
  min-height: var(--tap-min);
}

.tg-cart-item__img {
  grid-area: img;
  align-self: start;
  overflow: hidden;
  width: 80px;
  height: 80px;
  border-radius: var(--radius-md);
  background: var(--color-surface-alt);
}

.tg-cart-item__img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tg-cart-item__info {
  grid-area: name;
  min-width: 0;
}

.tg-cart-item__name {
  overflow: hidden;
  font-size: var(--text-14);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tg-cart-item__name a {
  color: var(--color-text);
}

.tg-cart-item__variant {
  grid-area: variant;
  justify-self: start;
  padding: 2px var(--space-2);
  border-radius: var(--radius-xs);
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-size: var(--text-meta);
}

.tg-cart-item__qty {
  grid-area: qty;
}

.tg-cart-item__price {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  grid-area: price;
  --price-size: var(--text-15);
}

/* Giá sỉ: tag viền xanh nhạt; dòng nhắc chữ xanh đậm, bấm là đặt số lượng bằng ngưỡng (wireframe M4/D4) */
.tg-cart-item__tag {
  border: 1px solid var(--color-border-brand);
  background: none;
  color: var(--color-brand-strong);
  font-size: var(--text-12);
}

.tg-cart-item__nudge {
  display: flex;
  grid-column: 3 / -1;
  align-items: center;
  gap: var(--space-1);
  min-height: var(--tap-min);
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-brand-strong);
  font-size: var(--text-meta);
  text-align: left;
  --icon-size: 14px;
}

.tg-cart-item__nudge span {
  flex: 1;
}

/* Giỏ chỉ có một số lượng: phân loại trống thì số lượng vẫn nằm bên phải */
.tg-cart-item:not(:has(.tg-cart-item__variant)) .tg-cart-item__qty {
  grid-column: 3 / 5;
  justify-self: end;
}

.tg-cart-item__remove,
.tg-cart-item__similar {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0;
  border: 0;
  background: none;
  font-size: var(--text-14);
  text-align: left;
}

.tg-cart-item__remove {
  color: var(--color-text);
}

.tg-cart-item__similar {
  color: var(--color-brand-strong);
}

/* Đang gửi thao tác giỏ (cart.js): mờ nhẹ, chặn bấm chồng */
.tg-cart.is-busy .tg-cart-items,
.tg-cart.is-busy .tg-cart-bar__sum {
  opacity: 0.6;
  pointer-events: none;
}

/* =========================================================
   Thanh tổng: mobile dính đáy hai hàng
   ========================================================= */
.tg-cart-bar {
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-2);
}

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

.tg-cart-bar__tags {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-1-5);
  min-width: 0;
}

.tg-cart-bar__choose {
  color: var(--color-brand);
}

.tg-cart-bar__offer .tg-icon {
  color: var(--color-brand-strong);
}

.tg-cart-bar__main {
  display: flex;
  align-items: center;
  gap: var(--space-2-5);
}

.tg-cart-bar__all {
  flex: none;
  font-size: var(--text-meta);
}

.tg-cart-bar__sum {
  flex: 1;
  min-width: 0;
  text-align: right;
}

.tg-cart-bar__total {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-1);
  font-size: var(--text-body-sm);
}

.tg-cart-bar__total .tg-money {
  font-size: var(--text-17);
}

.tg-cart-bar__detail {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: var(--tap-min);
  margin-block: calc((var(--tap-min) - 24px) / -2);
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-text-muted);
  --icon-size: 16px;
}

.tg-cart-bar__saving {
  font-size: var(--text-meta);
}

.tg-cart-bar__saving strong {
  color: var(--color-brand-strong);
}

.tg-cart-bar__buy {
  flex: none;
  min-height: 46px;
  padding-inline: var(--space-4);
}

.tg-cart-bar__remove {
  min-height: var(--tap-min);
  padding: 0 var(--space-2);
  border: 0;
  background: none;
  color: var(--color-text);
  font-size: var(--text-15);
}

/* Chừa chỗ cuối trang cho thanh tổng (cao hơn thanh hành động thường khi có dòng Ưu đãi) */
@media (max-width: 1023px) {
  body:has(.tg-cart-bar__offer) {
    padding-bottom: calc(var(--action-bar-height) + 44px + env(safe-area-inset-bottom, 0px));
  }
}

/* Bảng chi tiết tổng tiền (mũi tên cạnh số Tổng) */
.tg-money-table > div {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-14);
}

.tg-money-table dt {
  color: var(--color-text-muted);
}

.tg-money-table__total {
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.tg-money-table__total dt {
  color: var(--color-text);
  font-weight: var(--weight-semibold);
}

/* =========================================================
   Giỏ trống
   ========================================================= */
.tg-cart-empty {
  padding-block: var(--space-6);
}

.tg-cart-empty__icon {
  width: 72px;
  height: 72px;
  background: var(--color-brand-soft);
  color: var(--color-brand);
  --icon-size: 32px;
}

.tg-cart-empty .tg-empty__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-self: stretch;
  max-width: none;
}

.tg-cart-empty .tg-empty__actions .tg-btn {
  min-height: 46px;
}

/* =========================================================
   Desktop: bảng 7 cột, thanh tổng dính đáy trong khung 1240px
   ========================================================= */
@media (min-width: 1024px) {
  .tg-cart-head,
  .tg-cart-item {
    grid-template-columns: 40px 80px minmax(0, 1fr) 200px 150px 150px 130px 130px;
    column-gap: var(--space-3);
  }

  .tg-cart-head {
    display: grid;
    align-items: center;
    padding-block: var(--space-3);
    color: var(--color-text-muted);
    font-size: var(--text-14);
  }

  .tg-cart-head__product {
    grid-column: span 2;
    color: var(--color-text);
  }

  .tg-cart-head > :last-child {
    text-align: center;
  }

  .tg-cart-items {
    padding-block: 0;
  }

  .tg-cart-item {
    grid-template-areas: "check img name variant price qty total actions";
    padding-block: var(--space-4);
  }

  .tg-cart-item__name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    font-size: var(--text-15);
    white-space: normal;
  }

  .tg-cart-item__variant {
    padding: 0;
    background: none;
    font-size: var(--text-meta);
  }

  .tg-cart-item__info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
  }

  /* D4: tag nền xanh nhạt dưới tên; dòng nhắc là dải xanh nhạt dưới cả dòng */
  .tg-cart-item__tag {
    border: 0;
    background: var(--color-brand-soft-alt);
    font-weight: var(--weight-semibold);
  }

  .tg-cart-item__nudge {
    grid-column: 2 / -1;
    min-height: 36px;
    padding: 0 var(--space-3);
    background: var(--color-brand-soft-alt);
    font-size: var(--text-meta);
  }

  .tg-cart-item__nudge span {
    flex: none;
  }

  .tg-cart-item__price {
    --price-size: var(--text-15);
  }

  .tg-cart-item:not(:has(.tg-cart-item__variant)) .tg-cart-item__qty {
    grid-column: auto;
    justify-self: start;
  }

  .tg-cart-item__total {
    grid-area: total;
  }

  .tg-cart-item__total .tg-money {
    font-size: var(--text-16);
    font-weight: var(--weight-semibold);
  }

  .tg-cart-item__actions {
    display: flex;
    grid-area: actions;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
  }

  .tg-cart-item__actions > * {
    text-align: center;
  }

  .tg-cart-bar {
    position: sticky;
    inset: auto;
    bottom: 0;
    width: calc(100% - 2 * var(--gutter));
    max-width: calc(var(--container-max) - 2 * var(--gutter));
    margin: var(--section-gap) auto 0;
    padding: var(--space-4) var(--space-6);
    border: 1px solid var(--color-border-warm);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sheet);
  }

  /* D4: hàng ưu đãi canh phải: icon, "Ưu đãi", nhãn mã, "Chọn hoặc nhập mã" */
  .tg-cart-bar__offer {
    justify-content: flex-end;
    gap: var(--space-3);
    border-bottom-style: dashed;
    font-size: var(--text-15);
  }

  .tg-cart-bar__tags {
    flex: none;
  }

  .tg-cart-bar__all {
    font-size: var(--text-15);
  }

  .tg-cart-bar__total {
    font-size: var(--text-15);
  }

  .tg-cart-bar__total .tg-money {
    font-size: var(--text-24);
  }

  .tg-cart-bar__saving {
    font-size: var(--text-14);
  }

  .tg-cart-bar__buy {
    width: 210px;
    min-height: 48px;
  }

  .tg-cart-empty {
    padding-block: var(--space-10);
  }

  .tg-cart-empty__icon {
    width: 96px;
    height: 96px;
    --icon-size: 44px;
  }

  .tg-cart-empty .tg-empty__title {
    font-size: var(--text-20);
  }

  .tg-cart-empty .tg-empty__text {
    max-width: 60ch;
    font-size: var(--text-15);
  }

  .tg-cart-empty .tg-empty__actions {
    flex-direction: row;
    justify-content: center;
    align-self: center;
  }

  .tg-cart-empty .tg-empty__actions .tg-btn {
    width: 200px;
  }

  .tg-cart-empty .tg-cart-empty__reorder {
    border-color: var(--color-brand);
    background: var(--color-brand-tint);
  }
}

/* Ghi chú giá dưới món: Flash Sale theo suất, giảm mua cả quy trình (inc/pricing.php) */
.tg-cart-item__note {
  display: block;
  font-size: var(--text-meta);
  color: var(--color-red);
}
