/* Suit Builder specific styles */

/* Container for each category swatches */
.swatch-panel {
  margin-bottom: 20px;
}

/* Grid of swatches */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid #ddd;
}

/* Each swatch button */
.swatch {
  display: block;
  width: 100%;
  padding: 0;
  border: 2px solid transparent;
  background: none;
  cursor: pointer;
}

.swatch img {
  width: 100%;
  height: 60px;
  object-fit: cover;
  display: block;
}

/* Hover state */
.swatch:hover {
  border-color: #999;
}

/* Selected state */
.swatch.selected {
  border-color: #0073e6;
}

/* Preview styling */
.preview-box {
  margin-bottom: 20px;
}
.preview-box img {
  width: 100%;
  max-width: 200px;
  height: auto;
  object-fit: cover;
  border: 1px solid #ddd;
}

.preview-name {
  margin-top: 8px;
  font-weight: bold;
}

/* Summary styles */
#summary-card ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
#summary-card li {
  margin-bottom: 4px;
}

/* Wizard step visibility */
.builder-step {
  display: none;
}
.builder-step.active {
  display: block;
}

/* Wizard navigation buttons */
.wizard-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  gap: 10px;
}
.wizard-nav button {
  padding: 10px 20px;
  font-size: 16px;
  cursor: pointer;
}
.wizard-nav button[disabled] {
  opacity: 0.5;
  cursor: default;
}

/* Suit preview adjustments */
#suitPreviewPanel {
  margin-bottom: 20px;
}
#suitPreviewPanel .preview-suit,
#suitPreviewPanel .preview-pants {
  background-size: cover;
  background-position: center;
}

/* Review summary styling */
.review-summary .review-item {
  margin-bottom: 8px;
}

/* New suit preview shape */
.suit-preview {
  position: relative;
  width: 100%;
  /* Maintain 3:4 aspect ratio similar to a suit silhouette */
  padding-bottom: 133%;
  max-width: 250px;
  margin: 0 auto 20px auto;
    background: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 8px;
  overflow: hidden;
}

.suit-texture {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-size: cover;
  background-position: center;
  /* Clip the texture to a suit-like silhouette */
  clip-path: polygon(25% 0, 75% 0, 100% 15%, 85% 60%, 70% 100%, 30% 100%, 15% 60%, 0 15%);
  /* Outline/shadow to define the suit shape */
  box-shadow: 0 0 0 2px #ddd, 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Optional overlay image (e.g., line art) sits above the texture */
.suit-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}


/* Swatch grid display and tile styling for builder */
.swatch-panel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  padding: 4px;
}

.swatch {
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  background: #f2f2f2;
}

.swatch img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.swatch:hover {
  border-color: #999;
}

.swatch.selected {
  border-color: #0073e6;
}

/* Suit preview shape override for suit silhouette */
.suit-preview {
  width: 100%;
  max-width: 420px;
  aspect-ratio: 3 / 4;
  position: relative;
  overflow: hidden;
  background: #f2f2f2;
  border: 2px solid rgba(0,0,0,0.18);
  border-radius: 16px;
}

.suit-texture {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: background-image 150ms ease;
  clip-path: polygon(25% 0, 75% 0, 100% 15%, 85% 60%, 70% 100%, 30% 100%, 15% 60%, 0 15%);
}

.suit-preview::after {
  content: "";
  position: absolute;
  inset: 10%;
  border: 2px solid rgba(0,0,0,0.22);
  border-radius: 20px;
  pointer-events: none;
}

.suit-preview::before {
  content: "Suit Preview";
  position: absolute;
  top: 12px;
  left: 12px;
  
  font-weight: 600;
  opacity: 0.7;
  pointer-events: none;
  
}

/* Apply suit silhouette to preview container */
/*
 * The original implementation applied the suit and liner textures directly to
 * the preview container as layered background images. This caused the fabric
 * to render as a rectangular patch behind the jacket overlay. To avoid
 * conflicting backgrounds and ensure the fabric only appears within the suit
 * silhouette, these properties are removed. The container now simply holds
 * CSS variables and positioning, while the actual textures are applied via
 * pseudo‑elements defined in the Layered suit preview implementation below.
 */
#preview-suit {
    /* Preserve CSS variables for suit and liner images */
    --ptd-suit-image: none;
    --ptd-liner-image: none;
    position: relative;
    /* Do not assign fabric/liner images directly to the container */
    background-image: none;
    background-color: transparent;
    /* Reset size/position/repeat to avoid unintended scaling */
    background-size: auto;
    background-position: initial;
    background-repeat: no-repeat;
    clip-path: none;
}

/*
 * Remove the early ::after rule that attempted to render the liner texture
 * directly on the container. The liner layer is now handled by the
 * dedicated pseudo‑element in the layered implementation below.
 */
#preview-suit::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image: none;
    pointer-events: none;
    clip-path: none;
    opacity: 1;
    z-index: 3;
    display: block;
    visibility: visible;
    mix-blend-mode: normal;
    filter: none;
}




/* Layered suit preview implementation (MVP) */

#preview-suit {
    /* Remove base backgrounds from the preview container */
    background-image: none !important;
    background-color: transparent !important;
}

#preview-suit::before {
    content: "";
    position: absolute;
    inset: 0;
    /* Dynamically apply selected fabric image */
    background-image: var(--ptd-suit-image);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    /* Clip the suit fabric to the jacket silhouette using the generated mask */
    -webkit-mask-image: url('/images/overlays/jacket_mask.png');
    mask-image: url('/images/overlays/jacket_mask.png');
    -webkit-mask-size: cover;
    mask-size: cover;
    -webkit-mask-position: center;
    mask-position: center;
    z-index: 1;
    /* Remove clip-path on the suit layer since mask handles the shape */
    -webkit-clip-path: none;
    clip-path: none;
    /* Ensure the fabric layer does not block clicks */
    pointer-events: none;
}

#preview-suit::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image: var(--ptd-liner-image);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    -webkit-mask-image: url('/images/overlays/liner_base.png');
    mask-image: url('/images/overlays/liner_base.png');
    -webkit-mask-size: cover;
    mask-size: cover;
    mask-repeat: no-repeat;
    /* Align mask to center to match the jacket overlay */
    -webkit-mask-position: center;
    mask-position: center;
    z-index: 2;
    /* Ensure the liner layer is also clipped to the jacket silhouette */
    -webkit-clip-path: polygon(25% 0, 75% 0, 100% 15%, 85% 60%, 70% 100%, 30% 100%, 15% 60%, 0 15%);
    clip-path: polygon(25% 0, 75% 0, 100% 15%, 85% 60%, 70% 100%, 30% 100%, 15% 60%, 0 15%);
    pointer-events: none;
}

#preview-suit .jacket-overlay {
    position: absolute;
    inset: 0;
    background-image: url('/images/overlays/jacket_base.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
    /* Apply realistic shading over the fabric without obscuring it */
    opacity: 0.55;
    mix-blend-mode: multiply;
    z-index: 3;
}

#preview-pants {
    display: none;
}

/* Hide legacy suitTexture element to prevent full-rectangle suit texture */
#suitTexture {
    /* Clear any fabric texture previously applied via background-image */
    background-image: none !important;
    /* Hide the element entirely since the new preview layers replace its role */
    display: none !important;
}

/* Removed the temporary overlay-visibility block after testing */
