/*
================================================================
== TỆP: CSS/VIEW3D.CSS
== CHỨC NĂNG: Định dạng cho Popup hiển thị View 3D
================================================================
*/

/* 1. Lớp phủ nền mờ toàn màn hình */
.view3d-modal-overlay {
  display: none; /* Ẩn mặc định */
  position: fixed;
  z-index: 100001; /* Cao hơn các menu khác */
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  height: 100dvh; /* Safari: trừ thanh toolbar động */
  background-color: rgba(0, 0, 0, 0.85);
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

/* 2. Hiển thị popup khi có class 'active' */
.view3d-modal-overlay.active {
  display: flex;
}

/* 3. Khung nội dung chính của popup */
.view3d-modal-content {
  position: relative;
  background-color: rgba(192, 2, 7, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 25px;
  border: 2px solid #fff101;
  border-radius: 10px;
  width: 80%; /* Tăng chiều rộng để popup lớn hơn */
  height: 90vh; /* Fallback cho trình duyệt cũ */
  height: 90dvh; /* Safari: không bị thanh toolbar che */
  max-height: 95vh;
  max-height: 95dvh; /* Safari: không bị thanh toolbar che */
  box-shadow: 0 0 25px rgba(255, 241, 1, 0.5);
  animation: zoom-in 0.3s ease;
  display: flex;
  flex-direction: column;
}

/* 4. Nút đóng [X] */
.view3d-modal-close {
  position: absolute;
  top: 10px;
  right: 20px;
  color: white;
  font-size: 35px;
  line-height: 1;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.3s ease;
  z-index: 999; /* Tăng z-index cao để không bị model-viewer hay iframe đè lên */
}

.view3d-modal-close:hover {
  color: #fff101;
}

/* 5. Tiêu đề của popup */
.view3d-title {
  color: #fff101;
  font-size: 1.5rem;
  font-weight: bold;
  text-align: center;
  text-transform: uppercase;
  margin-bottom: 20px;
  border-bottom: 1px dashed rgba(255, 241, 1, 0.4);
  padding: 0 45px 15px 45px; /* Thêm padding trái/phải để tránh đè nút X */
}

/* 6. Khung chứa nội dung (iframe và mô tả) */
.view3d-container {
  display: flex;
  gap: 20px;
  flex-grow: 1;
  min-height: 0;
  overflow-x: hidden; /* Ngăn không cho nội dung tràn ra theo chiều ngang */
}

/* 7. Cột trái (chứa Iframe và nút chuyển) */
.view3d-left-col {
  flex: 2; /* Chiếm 2/3 chiều rộng */
  display: flex;
  flex-direction: column;
  gap: 15px; /* Khoảng cách giữa iframe và các nút */
  min-width: 0; /* QUAN TRỌNG: Ngăn cột này bị giãn ra bởi thanh cuộn sản phẩm bên trong */
}

/* 8. Khung chứa Iframe */
.view3d-iframe-container {
  flex-grow: 1; /* Iframe chiếm hết không gian còn lại của cột trái */
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background-image: url("../logo/logo.png");
  background-size: 80%; /* Hiển thị toàn bộ logo mà không bị cắt */
  background-repeat: no-repeat; /* Không lặp lại ảnh nền */
  background-position: center; /* Căn giữa logo */
  background-color: rgba(
    0,
    0,
    0,
    0.2
  )
  border: 1px solid rgba(255, 241, 1, 0.3);
  /* Nền mờ để model nổi bật hơn. */
  /* Ảnh chờ (poster) sẽ do thuộc tính `poster` của <model-viewer> quản lý. */
  background-color: rgba(0, 0, 0, 0.2);
}

.view3d-iframe-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Style cho model-viewer */
.view3d-iframe-container model-viewer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
  --poster-color: transparent; /* Nền trong suốt khi tải */
  --progress-bar-color: #fff101; /* Màu thanh loading */
}

/* 9. Khung chứa mô tả */
.view3d-desc {
  flex: 1; /* Chiếm 1/3 chiều rộng */
  color: #eeeeee;
  line-height: 1.6;
  overflow-y: auto; /* Cho phép cuộn nếu nội dung dài */
  padding-right: 10px;
  font-size: 0.95rem;
  display: flex;
  flex-direction: column;
}

/* Tiêu đề sản phẩm trong cột mô tả */
.view3d-desc h3#view3d-product-title {
  color: #fff101;
  font-size: 1.2rem;
  font-weight: bold;
  margin-bottom: 15px;
  padding-bottom: 10px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 241, 1, 0.3);
}

/* Đoạn văn mô tả sản phẩm */
.view3d-desc p#view3d-product-description {
  position: relative; /* Thêm để định vị cho ::after */
  margin-bottom: 10px;
  /* Giới hạn văn bản theo số dòng */
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 10
  ; /* Tăng giới hạn dòng để hiển thị nhiều nội dung hơn ban đầu */
  transition: -webkit-line-clamp 0.3s ease; /* Hiệu ứng mượt khi thay đổi */
}

/* Hiệu ứng mờ dần ở cuối văn bản khi chưa mở rộng, báo hiệu còn nội dung */
.view3d-desc p#view3d-product-description:not(.expanded)::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 50px;
  background: linear-gradient(to bottom, transparent, rgba(120, 2, 5, 0.9));
  pointer-events: none;
}

/* Khi có class 'expanded', hiển thị toàn bộ văn bản */
.view3d-desc p#view3d-product-description.expanded {
  -webkit-line-clamp: initial; /* Tắt giới hạn dòng */
  /* Quan trọng: Cho phép nội dung tràn ra khỏi box của chính nó, để container cha (.view3d-desc) có thể tạo thanh cuộn */
  overflow: visible;
}

/* Nút "Xem thêm / Thu gọn" */
.view3d-read-more-btn {
  background: none;
  border: none;
  color: #fff101;
  font-weight: bold;
  cursor: pointer;
  padding: 5px 0;
  margin-bottom: 15px;
  align-self: flex-start; /* Căn trái trong flex container */
  text-decoration: underline;
}

/* Khung thông tin liên hệ ở cuối */
.view3d-contact-info {
  margin-top: auto; /* Đẩy khối này xuống dưới cùng */
  padding-top: 15px;
  border-top: 1px dashed rgba(255, 241, 1, 0.4);
  flex-shrink: 0; /* Không bị co lại */
}

.view3d-contact-info h4 {
  color: #fff101;
  font-size: 1rem;
  margin-bottom: 15px;
  text-transform: uppercase;
  text-align: center;
}

.view3d-contact-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap; /* Cho phép các nút xuống hàng nếu không đủ không gian */
}

.contact-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  color: #fff101;
  background-color: rgba(192, 2, 7, 0.8);
  border: 1px solid #fff101;
  border-radius: 5px;
  text-decoration: none;
  font-weight: bold;
  font-size: 0.9rem;
  transition: all 0.3s ease;
  flex-grow: 1; /* Đổi từ 1 về 0 để nút không bị giãn ra toàn bộ chiều rộng khi rớt hàng */
  max-width: 200px;
}

.contact-button:hover {
  background-color: #fff101;
  color: #c00207;
}

/* Tùy chỉnh thanh cuộn cho mô tả */
.view3d-desc::-webkit-scrollbar {
  width: 6px;
}
.view3d-desc::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}
.view3d-desc::-webkit-scrollbar-thumb {
  background: #fff101;
  border-radius: 3px;
}

/* 10. Responsive cho màn hình nhỏ */
@media screen and (max-width: 768px) {
  .view3d-modal-content {
    padding: 50px 12px 15px 12px; /* Tăng padding-top để không bị nút X đè */
    width: 92%;
    /* Fallback cho trình duyệt cũ */
    height: 85vh;
    max-height: 85vh;
    /* dvh = Dynamic Viewport Height: tự trừ thanh địa chỉ & thanh công cụ Safari */
    height: 85dvh;
    max-height: 85dvh;
    overflow-y: auto; /* Cho phép cuộn toàn bộ popup trên mobile */
    box-sizing: border-box;
  }

  .view3d-title {
    font-size: 1.1rem;
    margin-bottom: 10px;
    padding: 0 35px 10px 35px;
  }

  .view3d-container {
    flex-direction: column;
    gap: 12px;
    overflow: visible; /* Không kẹp nội dung bên trong */
    min-height: 0;
    flex: none; /* Không dùng flex-grow để không giới hạn chiều cao */
  }

  .view3d-left-col {
    gap: 10px;
    flex: none;
  }

  .view3d-iframe-container {
    height: 38vh; /* Chiều cao cố định cho khung model 3D - đủ để xem */
    min-height: unset;
    flex-grow: 0;
  }

  .view3d-desc {
    padding-right: 0;
    overflow-y: visible; /* Không cuộn riêng, để popup cha cuộn */
    flex-shrink: 0; /* Không bị co lại - hiện đầy đủ nội dung */
  }

  /* Hiển thị toàn bộ mô tả, không clamp trên mobile để không bị ẩn "Xem thêm" */
  .view3d-desc p#view3d-product-description {
    -webkit-line-clamp: unset !important;
    display: block !important;
    overflow: visible !important;
    max-height: none !important;
  }

  /* Ẩn hiệu ứng mờ cuối đoạn văn trên mobile (không cần vì hiển thị hết) */
  .view3d-desc p#view3d-product-description:not(.expanded)::after {
    display: none;
  }

  /* Ẩn nút Xem thêm/Thu gọn trên mobile vì đã hiện hết nội dung */
  .view3d-read-more-btn {
    display: none !important;
  }

  .view3d-contact-info {
    margin-top: 15px;
  }

  .contact-button {
    font-size: 0.8rem;
    padding: 8px;
    flex-direction: column;
    gap: 4px;
  }
}


/* Animation được dùng trong .view3d-modal-content */
@keyframes zoom-in {
  from {
    transform: scale(0.5);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
