/* --- Global Fixes for Layout --- */
.product-detail *, .product-detail *::before, .product-detail *::after {
  box-sizing: border-box;
}

/* --- Brand Variables --- */
:root {
  --primary-color: #d4a373; 
  --primary-hover: #bc8f63;
  --text-dark: #222222;
  --text-light: #777777;
  --light-bg: #f9f9f9;
  --border-color: #eaeaea;
  --danger: #d32f2f;
  --radius: 6px;
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.06);
  --transition: all 0.25s ease-in-out;
}

/* --- Main Layout --- */
.product-detail {
  padding: 3rem 2rem;
  max-width: 1300px;
  margin: 0 auto;
  background-color: #ffffff;
  overflow-x: hidden; /* Prevents horizontal scroll on the entire section */
}

.product-detail-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4rem;
  align-items: start;
}

/* CRITICAL FIX: min-width: 0 prevents the grid from expanding beyond the screen */
.product-gallery, .product-details {
  min-width: 0;
}

/* --- Product Gallery (Sticky on Desktop) --- */
.product-gallery {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: 2rem;
}

/* STRICT 1:1 SQUARE ASPECT RATIO */
.main-image {
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
  width: 100%;
  max-width: 100%; /* Keeps it inside parent */
  aspect-ratio: 1 / 1; /* Forces perfectly square container */
  background: var(--light-bg);
  position: relative;
}

.image-carousel {
  display: flex;
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -ms-overflow-style: none; /* IE and Edge */
  scrollbar-width: none; /* Firefox */
}

.image-carousel::-webkit-scrollbar {
  display: none; /* Chrome, Safari and Opera */
}

.carousel-slide {
  flex: 0 0 100%;
  width: 100%;
  max-width: 100%;
  height: 100%;
  object-fit: cover; /* Crops image to fit the square perfectly */
  scroll-snap-align: center;
}

.image-carousel img {
  min-width: 100%;
  display: block;
}

/* Explicit override to prevent global product-detail styles from forcing a fixed height */
.product-detail .main-image {
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  aspect-ratio: 1 / 1 !important;
}

.product-detail .main-image .image-carousel {
  aspect-ratio: 1 / 1 !important;
  min-height: 0 !important;
}

.product-detail .main-image .carousel-slide {
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
}

/* Thumbnails - Perfectly square */
.thumbnail-images {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  scrollbar-width: thin;
}

.thumbnail-images::-webkit-scrollbar {
  height: 6px;
}
.thumbnail-images::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 6px;
}

.thumbnail {
  width: 85px;
  height: 85px;
  aspect-ratio: 1 / 1;
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--light-bg);
}

.thumbnail:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.thumbnail.active {
  border-color: var(--primary-color);
}

/* --- Product Info --- */
.product-details {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.breadcrumb-detail { margin-bottom: -0.5rem; }

.category {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--primary-color);
  font-weight: 600;
}

.product-title {
  font-size: 2.2rem;
  color: var(--text-dark);
  font-weight: 600;
  line-height: 1.2;
}

.product-price-detail {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-color);
}

.price-current {
  font-size: 1.8rem;
  color: var(--text-dark);
  font-weight: 700;
}

.price-original {
  font-size: 1.2rem;
  color: var(--text-light);
  text-decoration: line-through;
}

.discount-badge {
  background: var(--danger);
  color: white;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 6px;
  letter-spacing: 0.5px;
}

.product-description {
  color: var(--text-light);
  line-height: 1.7;
  font-size: 1.05rem;
}

/* --- Variants --- */
.variants-section { margin-top: 1rem; }
.variants-section h3 {
  font-size: 1.05rem;
  margin-bottom: 1rem;
  color: var(--text-dark);
  font-weight: 600;
}

.variant-options { display: flex; gap: 1rem; flex-wrap: wrap; }
.variant-option input { display: none; }

.variant-box {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  background: white;
}

.variant-box:hover { border-color: var(--text-light); }

.variant-option input:checked + .variant-box {
  border-color: var(--primary-color);
  background: var(--light-bg);
  box-shadow: 0 0 0 1px var(--primary-color);
}

.variant-option input:disabled + .variant-box {
  opacity: 0.5;
  cursor: not-allowed;
  text-decoration: line-through;
}

.variant-preview {
  width: 30px;
  height: 30px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  object-fit: cover;
}

.variant-name {
  font-weight: 500;
  color: var(--text-dark);
  font-size: 0.95rem;
}

/* --- Cart Actions --- */
.cart-section {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: flex-start;
  margin-top: 1.5rem;
}

.cart-section > * {
  min-width: 0;
}

.quantity-selector {
  display: flex;
  align-items: center;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
  height: 48px;
}

.quantity-selector input {
  width: 60px;
  height: 100%;
  border: none;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-dark);
}

.btn-lg {
  height: 48px;
  padding: 0 2rem;
  font-weight: 600;
  font-size: 1rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  min-width: 180px;
}

.btn-primary { background: var(--primary-color); color: white; }
.btn-primary:hover { background: var(--primary-hover); box-shadow: var(--shadow-sm); }
.btn-secondary { background: white; color: var(--text-dark); border: 1px solid var(--border-color); }
.btn-secondary:hover { border-color: var(--primary-color); color: var(--primary-color); }
.btn-disabled { background: var(--border-color); color: var(--text-light); cursor: not-allowed; }

.wishlist-btn-detail {
  height: 48px;
  width: 48px;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-light);
  font-size: 1.2rem;
  transition: var(--transition);
  flex-shrink: 0;
}

.wishlist-btn-detail:hover, .wishlist-btn-detail.active {
  color: var(--danger);
  border-color: var(--danger);
}

/* --- Features --- */
.product-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1.5rem;
  padding-top: 2rem;
  margin-top: 1rem;
  border-top: 1px solid var(--border-color);
}
.feature { display: flex; align-items: flex-start; gap: 1rem; }
.feature i { font-size: 1.6rem; color: var(--primary-color); }
.feature h4 { font-size: 0.95rem; margin-bottom: 0.25rem; color: var(--text-dark); }
.feature p { font-size: 0.85rem; color: var(--text-light); margin: 0; }

/* --- Tabs Section --- */
.product-tabs {
  padding: 3rem 2rem;
  max-width: 1300px;
  margin: 2rem auto;
  background: var(--light-bg);
  border-radius: var(--radius);
}
.tabs-header {
  display: flex;
  gap: 2rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 2rem;
  flex-wrap: wrap;
}
.tab-btn {
  padding: 1rem 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-light);
  transition: var(--transition);
  position: relative;
}
.tab-btn.active { color: var(--primary-color); }
.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 3px;
  background: var(--primary-color);
  border-radius: 6px 6px 0 0;
}
.tab-pane { display: none; animation: fadeIn 0.4s ease; }
.tab-pane.active { display: block; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Related Products --- */
/* Related products layout uses canonical product card styles in public/css/shop.css */

/* --- Mobile Responsiveness --- */
@media (max-width: 1024px) {
  .product-detail-container {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
  .product-gallery { position: static; }
}

@media (max-width: 768px) {
  .product-detail { padding: 1.5rem 1rem; }
  .product-title { font-size: 1.8rem; }
  .cart-section {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
  }
  .quantity-selector {
    justify-content: center;
    flex: 0 0 100px;
    width: 100px;
  }
  .quantity-selector input { width: 100%; }
  .btn-lg {
    flex: 1 1 calc(50% - 0.5rem);
    width: auto;
    min-width: 120px;
  }
  .wishlist-btn-detail {
    width: 48px;
    flex: 0 0 48px;
  }
  .product-tabs { padding: 2rem 1rem; margin: 1rem; }
  .thumbnail-images { display: none; }
}

/* Product button mobile adjustments are defined in public/css/shop.css */