/* =============================================
   PRODUCT MODAL
   ============================================= */
.product-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
  backdrop-filter: blur(5px);
  padding: 20px;
}

.product-modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.product-modal-content {
  background: var(--white);
  width: 100%;
  max-width: 800px;
  max-height: 90vh;
  border-radius: var(--radius-lg);
  position: relative;
  overflow-y: auto;
  transform: scale(0.95) translateY(20px);
  transition: transform .4s cubic-bezier(.4, 0, .2, 1);
  padding: 40px;
  display: flex;
  flex-direction: column;
}

.product-modal-content.yarn-detail-modal {
  max-width: 1040px;
}

.product-modal-content::-webkit-scrollbar {
  width: 8px;
}

.product-modal-content::-webkit-scrollbar-thumb {
  background: var(--blue-light);
  border-radius: 999px;
}

.product-modal-overlay.active .product-modal-content {
  transform: scale(1) translateY(0);
}

.product-modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  background: var(--blue-pale);
  color: var(--blue-deep);
  border: none;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.product-modal-close:hover {
  background: var(--blue-main);
  color: var(--white);
  transform: rotate(90deg);
}

.product-modal-title {
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  color: var(--blue-deep);
  margin-bottom: 24px;
  text-align: center;
  border-bottom: 2px solid var(--blue-pale);
  padding-bottom: 16px;
}

.product-gallery {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.product-item {
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  background: var(--cream);
}

.product-item img {
  width: 100%;
  height: 220px;
  object-fit: cover;
  transition: transform .5s ease;
}

.product-item:hover img {
  transform: none;
}

.product-item h4 {
  padding: 12px 12px 4px 12px;
  text-align: center;
  font-size: .95rem;
  color: var(--text-dark);
  background: var(--cream);
}

.product-weight {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-mid);
  background: var(--cream);
  padding: 0 12px 8px 12px;
}

/* Wrapper ảnh để đặt badge lên trên */
.product-img-wrap {
  position: relative;
  overflow: hidden;
}

.product-img-button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
  text-align: inherit;
}

.product-img-button:focus-visible {
  outline: 3px solid var(--blue-main);
  outline-offset: -3px;
}

/* Badge hết hàng */
.product-stock-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: .5px;
}

/* Footer dưới card sản phẩm */
.product-item-footer {
  background: var(--cream);
  padding: 0 12px 14px 12px;
  display: flex;
  justify-content: center;
}

/* Nút nhắn Messenger */
.btn-messenger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #0084ff;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 16px;
  min-height: 44px;
  border-radius: 30px;
  text-decoration: none;
  transition: background .2s, transform .2s;
  white-space: nowrap;
}
.btn-messenger:hover {
  background: #006edb;
  transform: scale(1.04);
}

/* Ghi chú hết hàng */
.product-outstock-note {
  font-size: 0.78rem;
  color: var(--text-mid);
  font-style: italic;
  text-align: center;
  padding: 4px 0;
}

.product-image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 26, 42, 0.88);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility .2s ease;
}

.product-image-lightbox.active {
  opacity: 1;
  visibility: visible;
}

.product-image-lightbox-frame {
  width: min(100%, 980px);
  max-height: calc(100dvh - 88px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.product-image-lightbox-frame img {
  width: 100%;
  max-height: calc(100dvh - 140px);
  object-fit: contain;
  border-radius: 18px;
  background: var(--white);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .28);
}

.product-image-lightbox-frame figcaption {
  color: var(--white);
  font-weight: 700;
  text-align: center;
  line-height: 1.4;
}

.product-image-lightbox-close {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--white);
  color: var(--blue-deep);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-md);
}

.product-image-lightbox-close:focus-visible {
  outline: 3px solid var(--blue-main);
  outline-offset: 3px;
}

@media (hover: hover) and (pointer: fine) {
  .product-item:hover img {
    transform: scale(1.04);
  }

  .product-img-button:hover img {
    transform: scale(1.04);
  }
}

@media (min-width: 560px) {
  .product-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
  }

  .product-item img {
    height: 250px;
  }
}



/* =============================================
   FB ADS & MOBILE OPTIMIZATION
   ============================================= */

/* 1. Policy Modal */

/* 2. Policy Modal */
.policy-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 1100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.policy-modal.active { display: flex; }

.policy-modal-content {
  background: #fff;
  width: 100%;
  max-width: 700px;
  max-height: 85vh;
  border-radius: 24px;
  padding: 40px;
  position: relative;
  overflow-y: auto;
  animation: modalIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.policy-modal-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: #f4f7f7;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

#policyContent h2 { font-family: 'Playfair Display', serif; margin-bottom: 24px; color: var(--blue-deep); }
#policyContent h3 { margin: 24px 0 12px; font-size: 1.1rem; }
#policyContent p, #policyContent li { line-height: 1.7; color: var(--text-mid); margin-bottom: 12px; }

/* 3. Skeleton Loading */
.skeleton {
  background: #eee;
  background: linear-gradient(110deg, #ececec 8%, #f5f5f5 18%, #ececec 33%);
  border-radius: 8px;
  background-size: 200% 100%;
  animation: shine 1.5s linear infinite;
}

.skeleton-img { width: 100%; aspect-ratio: 1; border-radius: 16px; margin-bottom: 16px; }
.skeleton-text { height: 20px; width: 80%; margin-bottom: 10px; }
.skeleton-btn { height: 45px; width: 100%; border-radius: 100px; }

@keyframes shine { to { background-position-x: -200%; } }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 768px) {
  .footer { padding-bottom: 40px; }
  .float-buttons { bottom: 30px; }
}

/* 4. Product Modal Refinement */
.product-item-info {
  padding: 12px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.product-price-inline {
  font-weight: 700;
  color: var(--blue-main);
  font-size: 1.15rem;
  margin: 6px 0;
  width: 100%;
}

.product-title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 4px;
  width: 100%;
  flex-wrap: wrap; /* Tránh tràn trên màn hình siêu nhỏ */
}

.product-item h4 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-dark);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}

.product-weight {
  font-size: 0.75rem;
  color: var(--blue-main);
  background: var(--blue-pale);
  padding: 3px 8px;
  border-radius: 12px;
  white-space: nowrap;
  font-weight: 600;
  border: 1px solid var(--blue-light);
}

.yarn-line-card {
  cursor: pointer;
}

.yarn-card-count {
  margin-top: 6px;
  color: var(--text-mid);
  font-size: .78rem;
  font-weight: 600;
}

.yarn-view-colors-btn {
  border: 0;
  cursor: pointer;
}

.yarn-detail-view {
  display: grid;
  gap: 20px;
}

.yarn-back-btn {
  width: fit-content;
  border: 0;
  background: var(--blue-pale);
  color: var(--blue-deep);
  font-family: inherit;
  font-weight: 700;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.yarn-detail-layout {
  display: grid;
  grid-template-columns: minmax(260px, .95fr) minmax(280px, 1.05fr);
  gap: 24px;
  align-items: start;
}

.yarn-detail-image {
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.yarn-detail-image img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.yarn-detail-info {
  display: grid;
  gap: 14px;
}

.yarn-detail-info h3 {
  margin: 0;
  color: var(--text-dark);
  font-size: clamp(1.4rem, 3vw, 2rem);
  line-height: 1.2;
}

.yarn-detail-price {
  color: var(--blue-deep);
  font-size: 1.45rem;
  font-weight: 800;
}

.yarn-detail-description {
  margin: 0;
  color: var(--text-mid);
  line-height: 1.7;
}

.yarn-spec-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0 0 0 18px;
  color: var(--text-mid);
  line-height: 1.45;
}

.yarn-spec-list strong {
  color: var(--text-dark);
}

.yarn-selected-box {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--blue-light);
  border-radius: 12px;
  background: var(--blue-pale);
  color: var(--text-mid);
  font-size: .9rem;
}

.yarn-selected-box strong {
  color: var(--text-dark);
}

.yarn-contact-btn {
  width: fit-content;
}

.yarn-contact-btn.disabled {
  pointer-events: none;
  opacity: .6;
}

.yarn-color-section {
  display: grid;
  gap: 12px;
}

.yarn-color-section h4 {
  margin: 0;
  color: var(--text-dark);
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.yarn-color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(66px, 1fr));
  gap: 10px;
}

.yarn-color-option {
  display: grid;
  gap: 5px;
  padding: 5px;
  border: 2px solid var(--blue-light);
  border-radius: 8px;
  background: var(--white);
  color: var(--text-mid);
  font-family: inherit;
  font-size: .68rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}

.yarn-color-option img {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 5px;
  object-fit: cover;
}

.yarn-color-option.active {
  border-color: var(--blue-deep);
  box-shadow: 0 0 0 3px rgba(153, 204, 255, .35);
  transform: translateY(-1px);
}

.yarn-empty-variants,
.yarn-detail-loading {
  color: var(--text-mid);
  text-align: center;
  padding: 24px 12px;
}

@media (max-width: 720px) {
  .yarn-detail-layout {
    grid-template-columns: 1fr;
  }

  .yarn-color-grid {
    grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  }

  .yarn-contact-btn,
  .yarn-back-btn {
    width: 100%;
  }
}

/* 5. Search & Filter Tabs */
.modal-search-wrap {
  margin-bottom: 24px;
}

.search-box {
  position: relative;
  margin-bottom: 16px;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
}

.search-box input {
  width: 100%;
  padding: 14px 14px 14px 44px;
  border-radius: 12px;
  border: 1px solid var(--blue-light);
  font-family: inherit;
  font-size: 0.95rem;
  transition: var(--transition);
  background: var(--blue-pale);
}

.search-box input:focus {
  outline: none;
  border-color: var(--blue-main);
  background: var(--white);
  box-shadow: var(--shadow-sm);
}

.filter-tabs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none; /* Firefox */
}

.filter-tabs::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.filter-tab {
  white-space: nowrap;
  padding: 8px 18px;
  border-radius: 100px;
  background: var(--blue-pale);
  color: var(--text-mid);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
}

.filter-tab:hover {
  background: var(--blue-light);
}

.filter-tab.active {
  background: var(--blue-main);
  color: var(--white);
  box-shadow: 0 4px 12px rgba(153, 204, 255, 0.28);
}
