/**
 * BitStudio Virtual Try-On Extension Styles
 * Mobile-first responsive design
 */

/* Container and Button */
.bitstudio-tryon-container {
  position: relative;
  width: 100%;
  margin: 1rem 0;
  opacity: 0;
  transition: opacity 0.4s ease-out;
}

.bitstudio-tryon-container.bitstudio-visible {
  opacity: 1;
}

.bitstudio-tryon-button {
  width: 100%;
  padding: 0.875rem 1.25rem;
  background: var(--bitstudio-button-bg, var(--color-button-primary, #000));
  color: var(--color-button-primary-text, #fff);
  border: var(--bitstudio-button-border, none);
  border-radius: var(--bitstudio-button-radius, var(--button-radius, 0));
  font-size: var(--button-font-size, 1rem);
  font-weight: var(--button-font-weight, 500);
  line-height: var(--button-line-height, 1.5);
  text-transform: var(--button-text-transform, none);
  letter-spacing: var(--button-letter-spacing, normal);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.2s ease;
}

.bitstudio-tryon-button:hover:not(:disabled) {
  opacity: 0.9;
  transform: translateY(-1px);
}

.bitstudio-button-icon {
  position: absolute;
  right: 1.25rem;
  transition: transform 0.2s ease;
}

.bitstudio-tryon-button[aria-expanded="true"] .bitstudio-button-icon {
  transform: rotate(180deg);
}

/* Dropdown */
.bitstudio-tryon-dropdown {
  background: white;
  border: 1px solid #e5e5e5;
  border-radius: var(--bitstudio-button-radius, var(--button-radius, 0));
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  margin-top: 0.5rem;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.3s ease-out, opacity 0.2s ease-out;
  position: relative;
}

.bitstudio-tryon-dropdown[aria-hidden="false"] {
  max-height: 800px;
  opacity: 1;
  transition: max-height 0.3s ease-in, opacity 0.2s ease-in;
}

.bitstudio-dropdown-content {
  padding: 1.5rem;
}

/* Upload Area with CSS variables for customization */
.bitstudio-upload-area {
  margin-bottom: 1rem;
  --upload-button-border-style: dashed;
  --photo-aspect-ratio: 3/4; /* Default portrait */
  --photo-max-height: 120px;
  --photo-width-portrait: 90px;
  --photo-width-square: 80px;
}

/* Apply aspect ratio styles based on data attribute */
.bitstudio-upload-area[data-photo-aspect="square"] {
  --photo-aspect-ratio: 1/1;
}

.bitstudio-upload-area[data-photo-aspect="portrait"] {
  --photo-aspect-ratio: 3/4;
}

.bitstudio-upload-area[data-photo-aspect="auto"] {
  --photo-aspect-ratio: unset;
}

/* Apply border style based on data attribute */
.bitstudio-upload-area[data-border-style="solid"] {
  --upload-button-border-style: solid;
}

.bitstudio-upload-area[data-border-style="dotted"] {
  --upload-button-border-style: dotted;
}

.bitstudio-photos-container {
  width: 100%;
}

.bitstudio-photos-grid {
  display: flex;
  gap: 0.5rem;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: flex-start;
  padding: 0.5rem 0;
  min-height: 128px; /* Accommodate taller portrait photos */
  border-radius: 2px;
  transition: all 0.3s ease;
}

/* Alignment options */
.bitstudio-upload-area[data-alignment="left"] .bitstudio-photos-grid {
  justify-content: flex-start;
}

.bitstudio-photos-grid.drag-over {
  background: rgba(0, 0, 0, 0.05);
  border: 2px dashed var(--color-button-primary, #000);
  padding: calc(0.5rem - 2px) 0; /* Adjust padding to account for border */
}

.bitstudio-photo-item {
  position: relative;
  width: var(--photo-width-portrait);
  aspect-ratio: var(--photo-aspect-ratio);
  max-height: var(--photo-max-height);
  border: 2px solid transparent;
  border-radius: var(--bitstudio-card-radius, 4px);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
  background: transparent;
}

/* Square mode specific sizing */
.bitstudio-upload-area[data-photo-aspect="square"] .bitstudio-photo-item {
  width: var(--photo-width-square);
  height: var(--photo-width-square);
  aspect-ratio: unset;
}

/* Auto mode - preserve original aspect ratio */
.bitstudio-upload-area[data-photo-aspect="auto"] .bitstudio-photo-item {
  width: auto;
  height: auto;
  max-width: var(--photo-max-height);
  max-height: var(--photo-max-height);
  background: #f5f5f5;
}

.bitstudio-photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Use contain only for auto mode to preserve aspect ratio */
.bitstudio-upload-area[data-photo-aspect="auto"] .bitstudio-photo-item img {
  object-fit: contain;
  background: #f5f5f5;
}

.bitstudio-photo-item.selected {
  border-color: var(--color-button-primary, #000);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
}

.bitstudio-photo-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border: none;
  border-radius: 1px;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.bitstudio-photo-item:hover .bitstudio-photo-remove {
  opacity: 1;
}

/* Uploading state */
.bitstudio-photo-item.uploading {
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Adapt uploading state to aspect ratio */
.bitstudio-upload-area[data-photo-aspect="square"] .bitstudio-photo-item.uploading {
  width: var(--photo-width-square);
  height: var(--photo-width-square);
}

.bitstudio-upload-spinner {
  font-size: 0.75rem;
  color: #666;
  text-align: center;
}

.bitstudio-upload-new {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--photo-width-portrait);
  aspect-ratio: var(--photo-aspect-ratio);
  max-height: var(--photo-max-height);
  border: 2px var(--upload-button-border-style) #ccc;
  border-radius: var(--bitstudio-card-radius, 4px);
  cursor: pointer;
  transition: all 0.2s ease;
  background: rgba(250, 250, 250, 0.5);
}

/* Square mode specific sizing for upload button */
.bitstudio-upload-area[data-photo-aspect="square"] .bitstudio-upload-new {
  width: var(--photo-width-square);
  height: var(--photo-width-square);
  aspect-ratio: unset;
}

/* Auto mode for upload button */
.bitstudio-upload-area[data-photo-aspect="auto"] .bitstudio-upload-new {
  width: var(--photo-width-portrait);
  aspect-ratio: 3/4;
}

.bitstudio-upload-new:hover {
  border-color: var(--color-button-primary, #000);
  background: rgba(0, 0, 0, 0.02);
}

.bitstudio-photos-grid.drag-over .bitstudio-upload-new {
  border-color: var(--color-button-primary, #000);
  transform: scale(1.05);
}

.bitstudio-upload-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.bitstudio-upload-icon {
  color: #666;
}

.bitstudio-upload-text {
  font-size: 0.75rem;
  color: #666;
  text-align: center;
}

.bitstudio-upload-hint {
  font-size: 0.875rem;
  color: #666;
  text-align: center;
  margin: 0.5rem 0 0;
}

/* Generate Button */
.bitstudio-generate-button {
  width: 100%;
  padding: 0.875rem 1.25rem;
  background: var(--bitstudio-button-bg, var(--color-button-primary, #000));
  color: var(--color-button-primary-text, #fff);
  border: var(--bitstudio-button-border, none);
  border-radius: var(--bitstudio-button-radius, var(--button-radius, 0));
  font-size: var(--button-font-size, 1rem);
  font-weight: var(--button-font-weight, 500);
  line-height: var(--button-line-height, 1.5);
  text-transform: var(--button-text-transform, none);
  letter-spacing: var(--button-letter-spacing, normal);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.bitstudio-generate-button:hover:not(:disabled) {
  opacity: 0.9;
}

.bitstudio-generate-button:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* Disabled state for try-on dropdown trigger */
.bitstudio-generate-button:disabled {
  opacity: 0.6;
  pointer-events: none;
}

/* Progress (for try-on button) */
.bitstudio-progress-container {
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.bitstudio-progress-text {
  font-size: 0.875rem;
  color: #666;
  text-align: center;
}

/* Success Message */
.bitstudio-success {
  padding: 1rem;
  background: #d4edda;
  border: 1px solid #c3e6cb;
  border-radius: 2px;
  text-align: center;
}

.bitstudio-success p {
  color: #155724;
  margin: 0;
  font-size: 0.875rem;
  font-weight: 500;
}

/* Error */
.bitstudio-error {
  padding: 1rem;
  background: #fee;
  border: 1px solid #fcc;
  border-radius: 2px;
  text-align: center;
}

.bitstudio-error p {
  color: #c00;
  margin: 0 0 0.5rem;
}

.bitstudio-error-close {
  padding: 0.25rem 0.75rem;
  border: 1px solid #c00;
  background: white;
  color: #c00;
  border-radius: var(--button-radius, 0);
  font-size: 0.875rem;
  cursor: pointer;
}

/* Branding */
.bitstudio-branding {
  text-align: center;
  padding-top: 1rem;
  margin-top: 1rem;
  border-top: 1px solid #e5e5e5;
}

.bitstudio-branding img {
  opacity: 0.5;
  transition: opacity 0.2s ease;
  max-width: 60px;
  width: auto;
  height: auto;
  display: block;
  margin: 0 auto;
}

.bitstudio-branding a:hover img {
  opacity: 0.7;
}

/* Gallery Badge */
.bitstudio-gallery-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  background: var(--color-button-primary, #000);
  color: white;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  z-index: 10;
}

/* Gallery Block */
.bitstudio-gallery-container {
  margin: 2rem 0;
  position: relative;
  opacity: 0;
  transition: opacity 0.4s ease-out;
}

.bitstudio-gallery-container.bitstudio-visible {
  opacity: 1;
}


/* Masonry Item Wrapper */
.bitstudio-masonry-item {
  grid-column: span 1;
  align-self: start;
}

.bitstudio-gallery-title {
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.bitstudio-gallery-filter {
  margin-bottom: 1rem;
}

.bitstudio-gallery-filter label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.bitstudio-gallery-loading {
  text-align: center;
  padding: 2rem;
}


.bitstudio-gallery-grid {
  display: grid;
  grid-template-columns: repeat(var(--columns, 4), 1fr);
  gap: 8px;
  align-items: start;
}

.bitstudio-gallery-item {
  position: relative;
  overflow: hidden;
  background: var(--bitstudio-card-bg, #f5f5f5);
  align-self: start;
  border-radius: var(--bitstudio-card-radius, 0);
  border: var(--bitstudio-card-outline, none);
}

/* Fade-in animation for gallery images */
@keyframes bitstudioFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bitstudio-gallery-image {
  width: 100%;
  height: auto;
  opacity: 0;
  animation-duration: 300ms;
  animation-timing-function: ease-out;
  animation-fill-mode: forwards;
}

.bitstudio-gallery-image.bitstudio-fade-in {
  animation-name: bitstudioFadeIn;
  display: block;
  object-fit: cover;
  /* Optimize rendering for variable quality loading */
  backface-visibility: hidden;
  transform: translateZ(0);
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

.bitstudio-gallery-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.bitstudio-gallery-item:hover .bitstudio-gallery-overlay {
  opacity: 1;
}

.bitstudio-gallery-download {
  width: 40px;
  height: 40px;
  background: white;
  border: none;
  border-radius: 50%;
  font-size: 1.25rem;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.bitstudio-gallery-download:hover {
  transform: scale(1.1);
}

.bitstudio-gallery-product {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  color: white;
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
  border-radius: 2px;
  max-width: calc(100% - 20px);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Hero caption style override: standard caption below image */
.bitstudio-hero-container[data-caption-mode="caption"] .bitstudio-gallery-product,
.bitstudio-popup-hero[data-caption-mode="caption"] .bitstudio-gallery-product,
.bitstudio-hero-gallery-container[data-caption-mode="caption"] .bitstudio-gallery-product {
  position: static;
  bottom: auto;
  left: auto;
  transform: none;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  color: #111;
  padding: 6px 2px 0;
  max-width: 100%;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  font-size: 1rem; /* subheading size */
  font-weight: 600;
  line-height: 1.25;
}

.bitstudio-hero-container[data-caption-mode="caption"][data-caption-align="center"] .bitstudio-gallery-product,
.bitstudio-popup-hero[data-caption-mode="caption"][data-caption-align="center"] .bitstudio-gallery-product,
.bitstudio-hero-gallery-container[data-caption-mode="caption"][data-caption-align="center"] .bitstudio-gallery-product {
  text-align: center;
}

.bitstudio-hero-container[data-caption-mode="caption"][data-caption-align="left"] .bitstudio-gallery-product,
.bitstudio-popup-hero[data-caption-mode="caption"][data-caption-align="left"] .bitstudio-gallery-product,
.bitstudio-hero-gallery-container[data-caption-mode="caption"][data-caption-align="left"] .bitstudio-gallery-product {
  text-align: left;
}

/* Remove card chrome (bg/border) on hero items when using caption mode */
.bitstudio-popup-hero[data-caption-mode="caption"] .bitstudio-gallery-item,
.bitstudio-hero-gallery-container[data-caption-mode="caption"] .bitstudio-gallery-item,
.bitstudio-hero-container[data-caption-mode="caption"] .bitstudio-gallery-item {
  background: transparent;
  border: none;
}

.bitstudio-gallery-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: #666;
}

/* Responsive */
@media (min-width: 768px) {
  .bitstudio-tryon-dropdown {
    max-width: 400px;
    margin: 0.5rem auto 0;
  }
  
  .bitstudio-photos-grid {
    justify-content: center;
  }
  
  /* Grid columns handled by JavaScript */
}

@media (min-width: 1024px) {
  /* Grid columns handled by JavaScript */
}

/* Processing/Loading States */
.bitstudio-gallery-processing {
  position: relative;
  background: var(--bitstudio-processing-bg, #111111);
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 3/4;
  border-radius: var(--bitstudio-card-radius, 0);
  border: var(--bitstudio-card-outline, none);
}

.bitstudio-gallery-skeleton {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  width: 100%;
  height: 100%;
  min-height: 200px;
}


.bitstudio-gallery-status {
  margin-top: 1rem;
  font-size: 0.875rem;
  color: var(--bitstudio-processing-text, #ffffff);
  text-align: center;
}



/* Carousel Styles */
.bitstudio-gallery-carousel {
  display: block;
  text-decoration: none;
  color: inherit;
}

.bitstudio-carousel-wrapper {
  position: relative;
  overflow: hidden;
  touch-action: pan-y; /* Allow vertical scroll but handle horizontal swipes */
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bitstudio-carousel-wrapper img {
  transition: transform 0.3s ease;
  will-change: transform;
}

/* Processing state for carousel */
.bitstudio-gallery-carousel.processing .bitstudio-carousel-wrapper {
  background: var(--bitstudio-processing-bg, #111111);
  aspect-ratio: 3/4;
}

.bitstudio-gallery-carousel.processing .bitstudio-gallery-skeleton {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.bitstudio-carousel-prev,
.bitstudio-carousel-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: none;
  border-radius: 2px;
  font-size: 20px;
  color: white;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.bitstudio-carousel-prev {
  left: 10px;
}

.bitstudio-carousel-next {
  right: 10px;
}

.bitstudio-gallery-carousel:hover .bitstudio-carousel-prev,
.bitstudio-gallery-carousel:hover .bitstudio-carousel-next {
  opacity: 1;
}

.bitstudio-carousel-prev:hover,
.bitstudio-carousel-next:hover {
  background: rgba(0, 0, 0, 0.5);
  transform: translateY(-50%) scale(1.1);
}

.bitstudio-carousel-indicators {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 4px;
  z-index: 3;
}

.bitstudio-carousel-dot {
  width: 6px;
  height: 6px;
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.4);
  transition: all 0.2s ease;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.bitstudio-carousel-dot.active {
  background: rgba(255, 255, 255, 0.9);
}

/* Processing dots with pulsing animation */
.bitstudio-carousel-dot.processing {
  background: rgba(255, 255, 255, 0.4);
  animation: bitstudio-pulse 1.5s ease-in-out infinite;
}

.bitstudio-carousel-dot.processing.active {
  background: rgba(255, 255, 255, 0.9);
  animation: bitstudio-pulse-active 1.5s ease-in-out infinite;
}

@keyframes bitstudio-pulse {
  0%, 100% {
    opacity: 0.4;
  }
  50% {
    opacity: 0.8;
  }
}

@keyframes bitstudio-pulse-active {
  0%, 100% {
    opacity: 0.9;
  }
  50% {
    opacity: 0.5;
  }
}

/* Gallery Card Sizing - Only applies in stacked mode */
.bitstudio-gallery-size-small .bitstudio-masonry-item {
  grid-column: span 1;
}

.bitstudio-gallery-size-medium .bitstudio-masonry-item {
  grid-column: span 2;
}

.bitstudio-gallery-size-large .bitstudio-masonry-item {
  grid-column: span var(--columns, 4);
}

/* Ensure masonry items always span 1 column when not using size classes */
.bitstudio-masonry-item {
  grid-column: span 1;
}

/* Responsive adjustments for gallery sizing */
@media (max-width: 640px) {
  /* On small screens, medium and large both become full width */
  .bitstudio-gallery-size-medium .bitstudio-masonry-item,
  .bitstudio-gallery-size-large .bitstudio-masonry-item {
    grid-column: span var(--columns, 2);
  }
}

/* Mobile-specific carousel styles */
@media (max-width: 767px) {
  /* Hide navigation buttons on mobile */
  .bitstudio-carousel-prev,
  .bitstudio-carousel-next {
    display: none !important;
  }
  
  /* Keep dots small but add invisible touch targets */
  .bitstudio-carousel-dot {
    position: relative;
  }
  
  .bitstudio-carousel-dot::before {
    content: '';
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
  }
  
  /* Visual feedback during swipe */
  .bitstudio-carousel-wrapper {
    cursor: grab;
  }
  
  .bitstudio-carousel-wrapper:active {
    cursor: grabbing;
  }
}

/* Clickable Gallery Items */
.bitstudio-gallery-clickable {
  cursor: pointer;
}

.bitstudio-gallery-view {
  width: 40px;
  height: 40px;
  background: white;
  border: none;
  border-radius: 2px;
  cursor: pointer;
  transition: transform 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
}

.bitstudio-gallery-view:hover {
  transform: scale(1.1);
}

/* Modal Styles */
.bitstudio-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000001;
  display: none;
}

.bitstudio-modal.bitstudio-modal-open {
  display: block;
}

.bitstudio-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  cursor: pointer;
}

.bitstudio-modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: black;
  border-radius: 0;
  overflow: hidden;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
}

.bitstudio-modal-image-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: black;
  flex: 1;
  min-height: 0; /* Allow shrinking */
}

.bitstudio-modal-image {
  max-width: 100%;
  max-height: calc(90vh - 80px);
  object-fit: contain;
}

.bitstudio-modal-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 10px;
  pointer-events: none;
}

.bitstudio-modal-header button {
  pointer-events: auto;
}

.bitstudio-modal-header > div {
  display: flex;
  gap: 10px;
}

.bitstudio-modal-close,
.bitstudio-modal-download-float,
.bitstudio-modal-delete-float {
  width: 40px;
  height: 40px;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  color: white;
  border: none;
  border-radius: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.bitstudio-modal-close {
  font-size: 24px;
}

.bitstudio-modal-close:hover,
.bitstudio-modal-download-float:hover,
.bitstudio-modal-delete-float:hover {
  background: rgba(0, 0, 0, 0.5);
  transform: scale(1.1);
}

.bitstudio-modal-delete-float:hover {
  background: rgba(220, 53, 69, 0.8);
}


.bitstudio-modal-footer {
  padding: 0.75rem 1rem;
  background: white;
  text-align: center;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0; /* Don't shrink */
}

.bitstudio-modal-product-link {
  color: var(--color-button-primary, #000);
  text-decoration: none;
  font-size: 1rem;
  font-weight: 500;
  transition: opacity 0.2s ease;
}

.bitstudio-modal-product-link:hover {
  opacity: 0.7;
  text-decoration: underline;
}

.bitstudio-modal-product-name {
  display: inline-block;
}

/* Remove product banner from individual gallery items in product mode */
.bitstudio-gallery-container[data-gallery-mode="product"] .bitstudio-gallery-product,
.bitstudio-gallery-container[data-should-filter="true"] .bitstudio-gallery-product {
  display: none;
}

/* Modal Navigation Buttons */
.bitstudio-modal-prev,
.bitstudio-modal-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  color: white;
  border: none;
  border-radius: 2px;
  font-size: 28px;
  font-weight: 300;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s ease;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.bitstudio-modal-prev {
  left: 20px;
}

.bitstudio-modal-next {
  right: 20px;
}

/* Show on hover for desktop */
@media (hover: hover) {
  .bitstudio-modal-image-wrapper:hover .bitstudio-modal-prev,
  .bitstudio-modal-image-wrapper:hover .bitstudio-modal-next {
    opacity: 1;
  }
}

.bitstudio-modal-prev:hover,
.bitstudio-modal-next:hover {
  background: rgba(0, 0, 0, 0.5);
  transform: translateY(-50%) scale(1.1);
}

/* Always visible on mobile */
@media (max-width: 767px) {
  .bitstudio-modal-prev,
  .bitstudio-modal-next {
    opacity: 0.8;
    width: 44px;
    height: 44px;
    font-size: 24px;
  }
  
  .bitstudio-modal-prev {
    left: 10px;
  }
  
  .bitstudio-modal-next {
    right: 10px;
  }
}

/* Mobile modal adjustments */
@media (max-width: 767px) {
  .bitstudio-modal-content {
    max-width: 95vw;
    max-height: 95vh;
    width: auto;
    height: auto;
    border-radius: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  }
  
  .bitstudio-modal-image-wrapper {
    flex: 0 0 auto; /* Don't stretch, size to content */
  }
  
  .bitstudio-modal-image {
    max-width: 95vw;
    max-height: 75vh; /* Leave room for footer and buttons */
    width: auto;
    height: auto;
  }
  
  .bitstudio-modal-header {
    position: fixed; /* Keep buttons accessible when zoomed */
    top: 10px;
    left: 0;
    right: 0;
    z-index: 10001;
    padding: 0 10px;
  }
  
  .bitstudio-modal-footer {
    min-height: 40px;
    padding: 0.5rem;
  }
  
  .bitstudio-modal-product-link {
    font-size: 0.875rem; /* Slightly smaller text */
  }
  
  .bitstudio-modal-close,
  .bitstudio-modal-download-float,
  .bitstudio-modal-delete-float {
    width: 44px;
    height: 44px; /* Better touch targets */
    border-radius: 2px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); /* Better visibility */
  }
}

/* Login Overlay */
.bitstudio-login-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 2rem;
}

.bitstudio-login-content {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: var(--bitstudio-button-radius, 0px);
  padding: 2.5rem 2rem;
  text-align: center;
  max-width: 300px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.05);
}

.bitstudio-login-content p {
  margin: 0 0 1.5rem;
  color: #333;
  font-size: 0.875rem;
  line-height: 1.5;
  font-weight: 500;
}

.bitstudio-login-button {
  display: inline-block;
  padding: 0.75rem 2rem;
  background: var(--bitstudio-button-bg, rgba(0, 0, 0, 0.9));
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  color: white;
  text-decoration: none;
  border: var(--bitstudio-button-border, none);
  border-radius: var(--bitstudio-button-radius, var(--button-radius, 0));
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.bitstudio-login-button:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  color: white;
}

/* Popup Widget Styles */
.bitstudio-popup-widget {
  position: relative;
  z-index: 999999;
}

/* Floating trigger button */
.bitstudio-popup-trigger {
  position: fixed;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: var(--bitstudio-popup-bg, #111111);
  color: var(--bitstudio-popup-icon, #ffffff);
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 999999;
}

.bitstudio-popup-trigger:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* Position classes */
.bitstudio-popup-bottom-right {
  bottom: 20px;
  right: 20px;
}

.bitstudio-popup-bottom-left {
  bottom: 20px;
  left: 20px;
}

.bitstudio-popup-top-right {
  top: 20px;
  right: 20px;
}

.bitstudio-popup-top-left {
  top: 20px;
  left: 20px;
}

/* Popup overlay */
.bitstudio-popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.75);
  z-index: 1000000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.bitstudio-popup-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* Disable animation when auto-opening from saved state */
.bitstudio-popup-overlay.no-animate {
  transition: none !important;
}

/* Popup content - Slide-out tray */
.bitstudio-popup-content {
  position: fixed;
  right: 0;
  top: 0;
  height: 100vh;
  width: 520px; /* widen tray slightly for larger hero */
  max-width: 90vw;
  background-color: white;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.bitstudio-popup-content.no-animate {
  transition: none !important;
}

.bitstudio-popup-overlay.active .bitstudio-popup-content {
  transform: translateX(0);
}

/* Popup header */
.bitstudio-popup-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid #e5e5e5;
}

/* Product Selector: Available Products Row */
.bitstudio-product-selector {
  width: 100%;
  margin: 1rem 0;
}

.bitstudio-product-selector.bitstudio-product-selector-ready {
  display: block !important;
}

.bitstudio-product-selector-header {
  margin-bottom: 0.5rem;
}

.bitstudio-product-selector-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.bitstudio-product-selector-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0;
}

.bitstudio-product-selector-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  /* hide scrollbars cross-browser */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE 10+ */
}

.bitstudio-product-selector-row::-webkit-scrollbar { /* WebKit */
  display: none;
}

.bitstudio-product-selector-item {
  flex: 0 0 auto;
  width: 90px; /* portrait thumb width */
  cursor: pointer;
}

.bitstudio-product-selector-item .bitstudio-product-selector-image {
  width: 90px;
  aspect-ratio: 3/4; /* portrait */
  height: auto;
  border-radius: var(--bitstudio-card-radius, 6px);
  border: var(--bitstudio-card-outline, 1px solid #e5e5e5);
  overflow: hidden;
  background: #f6f6f6;
}

.bitstudio-product-selector-item .bitstudio-product-selector-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.bitstudio-product-selector-caption {
  font-size: 12px;
  color: #444;
  margin-top: 6px;
  max-width: 90px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bitstudio-popup-header-text {
  flex: 1;
}

.bitstudio-popup-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  color: #111111;
}

.bitstudio-popup-subtitle {
  font-size: 14px;
  color: #666666;
  margin: 6px 0 0 0;
  line-height: 1.4;
}

/* Removed stack toggle styles - no longer needed */

/* Close button */
.bitstudio-popup-close {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  border: none;
  background-color: transparent;
  color: #666666;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.bitstudio-popup-close:hover {
  background-color: #f5f5f5;
  color: #111111;
}

/* Popup body */
.bitstudio-popup-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Try-on section */
.bitstudio-popup-tryon {
  padding: 20px;
  border-bottom: 1px solid #e5e5e5;
  flex-shrink: 0;
  position: relative;
}

/* Hero section */
.bitstudio-popup-hero {
  padding: 20px;
  border-bottom: none;
  background: #ffffff;
}

/* Popup product selector section */
.bitstudio-popup-product-selector {
  padding: 20px;
  border-bottom: 1px solid #e5e5e5;
}

/* Collapsible header */
.bitstudio-product-selector-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: transparent;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.bitstudio-product-selector-toggle-text {
  font-size: 14px;
  font-weight: 600;
}

.bitstudio-product-selector-toggle-icon {
  transition: transform 0.2s ease;
}

.bitstudio-product-selector-toggle[aria-expanded="true"] .bitstudio-product-selector-toggle-icon {
  transform: rotate(180deg);
}

.bitstudio-product-selector-collapsible {
  margin-top: 6px; /* tighter gap under heading */
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.2s ease;
}

.bitstudio-product-selector-collapsible[aria-hidden="false"] {
  max-height: 520px; /* enough to show a few rows if wrapping */
  opacity: 1;
}

/* Slightly tighter section padding for collapsible variant */
.bitstudio-product-selector-collapsible-section {
  padding-top: 10px;
  padding-bottom: 4px;
}

.bitstudio-hero-gallery-container {
  width: 100%;
  max-width: 560px; /* allow hero to grow within wider tray */
  margin: 0 auto;
}

.bitstudio-popup-hero .bitstudio-gallery-grid {
  width: 100%;
}

.bitstudio-popup-hero .bitstudio-gallery-item {
  /* Inherits border-radius from base .bitstudio-gallery-item which uses CSS variables */
  overflow: hidden;
  position: relative;
}

.bitstudio-popup-hero .bitstudio-gallery-image {
  width: 100%;
  height: auto;
  display: block;
}

.bitstudio-popup-hero .bitstudio-hero-fallback .bitstudio-gallery-hero {
  position: relative;
}

.bitstudio-hero-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 100%);
  padding: 20px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.bitstudio-hero-caption {
  color: white;
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  margin: 0;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* Hero loading state */
.bitstudio-popup-hero .bitstudio-gallery-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: #666;
  text-align: center;
}

/* Gallery section */
.bitstudio-popup-gallery {
  padding: 20px;
  flex: 1;
  min-height: 200px;
  background-color: #fafafa;
  overflow-y: auto;
}

.bitstudio-popup-section-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  color: #111111;
}

.bitstudio-popup-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.bitstudio-stack-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  background: transparent;
  color: #666666;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
}

.bitstudio-stack-toggle:hover {
  border-color: #cccccc;
  color: #333333;
  background-color: #f5f5f5;
}

.bitstudio-stack-toggle:focus {
  border-color: #999999;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);
}

.bitstudio-stack-toggle svg {
  width: 16px;
  height: 16px;
}

/* Footer */
.bitstudio-popup-footer {
  padding: 16px 24px;
  border-top: 1px solid #e5e5e5;
  text-align: center;
}

/* Adjust existing styles in popup context */
.bitstudio-popup-widget .bitstudio-upload-area {
  margin-bottom: 16px;
}

/* Login overlay for popup */
.bitstudio-popup-widget .bitstudio-popup-login-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.98);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: 4px;
}

.bitstudio-popup-widget .bitstudio-popup-login-content {
  text-align: center;
  padding: 20px;
}

.bitstudio-popup-widget .bitstudio-popup-login-content p {
  margin-bottom: 16px;
  color: #666;
  font-size: 14px;
}

.bitstudio-popup-widget .bitstudio-popup-login-button {
  background-color: #111111;
  color: white;
  border: 1px solid #111111;
  padding: 10px 24px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.2s;
}

.bitstudio-popup-widget .bitstudio-popup-login-button:hover {
  background-color: #333;
  border-color: #333;
}

.bitstudio-popup-widget .bitstudio-generate-button {
  width: 100%;
  margin-bottom: 12px;
  padding: 10px 16px;
  font-size: 14px;
  background: var(--bitstudio-generate-bg, #111111);
  color: var(--bitstudio-generate-text, #ffffff);
}

.bitstudio-popup-widget .bitstudio-gallery-grid {
  position: relative;
  min-height: 150px;
  width: 100%;
  margin: 0;
}

/* Ensure proper alignment in popup gallery */
.bitstudio-popup-gallery .bitstudio-gallery-grid {
  width: 100%;
  margin: 0;
}

/* Full gallery mode on non-product pages */
.bitstudio-popup-gallery-full {
  background-color: transparent;
  padding-top: 24px;
}

/* Prevent gallery flickering during updates */
.bitstudio-popup-widget .bitstudio-gallery-item {
  transition: none !important; /* Disable animations during state updates */
}

.bitstudio-popup-widget .bitstudio-gallery-grid.updating {
  opacity: 0.8;
  pointer-events: none;
}

.bitstudio-popup-widget .bitstudio-gallery-loading {
  text-align: center;
  padding: 40px 20px;
}

/* Row Gallery (horizontal, scrollable, no visible scrollbar) */
.bitstudio-row-gallery {
  width: 100%;
  margin: 1rem 0;
}

.bitstudio-row-gallery.bitstudio-row-gallery-ready {
  display: block !important;
}

.bitstudio-row-gallery-viewport {
  position: relative;
}

.bitstudio-row-gallery-scroller {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  /* hide scrollbars */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE 10+ */
}

.bitstudio-row-gallery-scroller::-webkit-scrollbar { /* WebKit */
  display: none;
}

.bitstudio-row-gallery-item {
  flex: 0 0 auto;
  width: var(--bitstudio-row-card-width, 120px);
  cursor: default;
  border-radius: var(--bitstudio-card-radius, 0);
  border: var(--bitstudio-card-outline, none);
  background: var(--bitstudio-card-bg, #f5f5f5);
  overflow: hidden;
}

.bitstudio-row-image-wrapper {
  width: 100%;
  aspect-ratio: 3/4; /* portrait */
  height: auto;
  position: relative;
}

.bitstudio-row-image-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Row: show only dots on hover when present */
.bitstudio-row-gallery-item .bitstudio-carousel-indicators {
  opacity: 0;
  transition: opacity 0.2s ease;
}
.bitstudio-row-gallery-item:hover .bitstudio-carousel-indicators {
  opacity: 1;
}

/* Touch devices: no hover → keep dots visible */
@media (hover: none) and (pointer: coarse) {
  .bitstudio-row-gallery-item .bitstudio-carousel-indicators {
    opacity: 1;
  }
}

/* Scroll buttons (desktop only) */
.bitstudio-row-scroll-prev,
.bitstudio-row-scroll-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  background: var(--bitstudio-row-scroll-bg, rgba(0, 0, 0, 0.3));
  backdrop-filter: var(--bitstudio-row-scroll-backdrop, blur(24px));
  -webkit-backdrop-filter: var(--bitstudio-row-scroll-backdrop, blur(24px));
  border: none;
  border-radius: var(--bitstudio-row-scroll-radius, 2px);
  font-size: 20px;
  color: var(--bitstudio-row-scroll-color, #ffffff);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--bitstudio-row-scroll-shadow, 0 2px 4px rgba(0, 0, 0, 0.2));
}

/* Hover behavior handled later with not(:disabled) to avoid edge highlighting */

.bitstudio-row-scroll-prev {
  left: 8px;
}

.bitstudio-row-scroll-next {
  right: 8px;
}

.bitstudio-row-scroll-prev:hover,
.bitstudio-row-scroll-next:hover {
  transform: translateY(-50%) scale(1.1);
}

.bitstudio-row-scroll-prev:disabled,
.bitstudio-row-scroll-next:disabled {
  opacity: 0; /* do not show disabled as hint */
  cursor: default;
}

/* Affordance hints: when not at an edge, hint toward available scroll */
.bitstudio-row-gallery-viewport.hint-left .bitstudio-row-scroll-prev { opacity: 0.35; }
.bitstudio-row-gallery-viewport.hint-right .bitstudio-row-scroll-next { opacity: 0.35; }

/* On hover: show only available direction(s) at full opacity */
.bitstudio-row-gallery-viewport:hover .bitstudio-row-scroll-prev:not(:disabled),
.bitstudio-row-gallery-viewport:hover .bitstudio-row-scroll-next:not(:disabled) {
  opacity: 1;
}

@media (max-width: 767px) {
  .bitstudio-row-scroll-prev,
  .bitstudio-row-scroll-next {
    display: none !important;
  }
}

/* Mobile responsive */
@media (max-width: 768px) {
  .bitstudio-popup-trigger {
    width: 48px;
    height: 48px;
  }
  
  .bitstudio-popup-hero {
    padding: 15px;
  }
  
  .bitstudio-hero-caption {
    font-size: 14px;
    padding: 15px;
  }
  
  .bitstudio-popup-content {
    width: 100%;
    max-width: 100%;
  }
  
  .bitstudio-popup-body {
    flex-direction: column;
  }
  
  .bitstudio-popup-tryon {
    border-bottom: 1px solid #e5e5e5;
  }
}
