/**
 * Imagelet Product Types - Frontend Styles
 * Gallery-style image upload UI
 */

/* ==========================================================================
   Global Product Page Styles (applies to all products)
   ========================================================================== */

/* Ensure product summary uses flexbox for reordering */
.single-product .entry-summary {
    display: flex;
    flex-direction: column;
}

/* Blocksy theme specific ordering */
/* Title first (order: 1) */
.single-product .entry-summary .product_title,
.single-product .entry-summary > h1 {
    order: 1;
    margin-bottom: 5px !important;
}

/* Caption/content block second (order: 2) */
.single-product .entry-summary .ct-product-content-block {
    order: 2;
    margin-top: 0 !important;
    margin-bottom: 5px !important;
}

/* Main price range - HIDDEN from product summary (not variation price) */
.single-product .entry-summary > .price,
.single-product .entry-summary > p.price {
    display: none !important;
}

/* Keep variation price visible */
.single-product .entry-summary .single_variation_wrap .price,
.single-product .entry-summary .woocommerce-variation-price .price {
    display: inline-block !important;
}

/* Stock info next to price - target the parent container */
.single-product .entry-summary .woocommerce-variation.single_variation {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    align-items: baseline !important;
    gap: 20px !important;
}

.single-product .entry-summary .woocommerce-variation-description:empty {
    display: none !important;
}

.single-product .entry-summary .woocommerce-variation-price,
.single-product .entry-summary .woocommerce-variation-availability {
    display: inline-block !important;
    margin: 0 !important;
    padding: 0 !important;
}

.single-product .entry-summary .woocommerce-variation-availability p {
    margin: 0 !important;
}

/* Quantity picker and Add to Cart button - same height and alignment */
.single-product .entry-summary .quantity {
    height: 48px !important;
}

.single-product .entry-summary .quantity input.qty {
    height: 48px !important;
}

.single-product .entry-summary .quantity .ct-qty-btn,
.single-product .entry-summary .quantity button,
.single-product .entry-summary .quantity .ct-increase,
.single-product .entry-summary .quantity .ct-decrease {
    height: 48px !important;
}

.single-product .entry-summary .single_add_to_cart_button {
    height: 48px !important;
    line-height: 1 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Add to Cart button takes remaining width */
.single-product .entry-summary .woocommerce-variation-add-to-cart,
.single-product .entry-summary form.cart .woocommerce-variation-add-to-cart {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: stretch !important;
    gap: 10px;
}

.single-product .entry-summary .single_add_to_cart_button {
    flex: 1 !important;
}

/* Divider fourth (order: 4) - AFTER price */
.single-product .entry-summary .ct-product-divider {
    order: 4;
}

/* Form/cart fifth (order: 5) */
.single-product .entry-summary .ct-product-add-to-cart,
.single-product .entry-summary form.cart,
.single-product .entry-summary .variations_form {
    order: 5;
}

/* Everything else after (order: 10) */
.single-product .entry-summary > * {
    order: 10;
}

/* ==========================================================================
   Variation Table Styles - Vertical Layout (applies to all products)
   ========================================================================== */

/* Make variation table rows display as vertical blocks */
.single-product .variations {
    border-spacing: 0 !important;
    border-collapse: collapse !important;
    margin: 0 !important;
}

.single-product .variations tbody {
    display: block !important;
}

.single-product .variations tr {
    display: flex !important;
    flex-direction: column !important;
    margin: 0 0 5px 0 !important;
    padding: 0 !important;
}

.single-product .variations tr:last-child {
    margin-bottom: 0 !important;
}

.single-product .variations th.label {
    text-align: left !important;
    padding: 0 0 2px 0 !important;
    margin: 0 !important;
    width: 100% !important;
    display: block !important;
}

.single-product .variations th.label label {
    font-weight: 400;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1.4 !important;
}

.single-product .variations td.value {
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
}

/* Custom Imagelet form specific - override all spacing */
.ipt-custom-imagelet-form .variations,
.ipt-custom-imagelet-form table.variations {
    margin: 0 !important;
    padding: 0 !important;
    border-spacing: 0 !important;
}

.ipt-custom-imagelet-form .variations tbody {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
}

.ipt-custom-imagelet-form .variations tr,
.ipt-custom-imagelet-form table.variations tr {
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
}

.ipt-custom-imagelet-form .variations tr:last-child,
.ipt-custom-imagelet-form table.variations tr:last-child {
    margin-bottom: 0 !important;
}

.ipt-custom-imagelet-form .variations th,
.ipt-custom-imagelet-form .variations td {
    padding: 0 !important;
    margin: 0 !important;
}

.ipt-custom-imagelet-form .variations th.label {
    padding-bottom: 2px !important;
}

/* Remove any spacing from the swatches container */
.single-product .ct-variation-swatches {
    margin: 0 !important;
    padding: 0 !important;
    gap: 8px !important;
    display: flex !important;
    flex-wrap: wrap !important;
}

/* Force remove any margin on swatch containers */
.single-product .ct-variation-swatches .ct-swatch-container {
    margin: 0 !important;
}

/* Blocksy theme specific - force vertical layout for variation swatches */
/* Only apply to non-custom-imagelet forms */
.single-product .variations_form:not(.ipt-custom-imagelet-form) .variations tbody {
    display: block !important;
}

.single-product .ct-variation-swatches,
.single-product .variable-items-wrapper {
    justify-content: flex-start !important;
}

/* Variation swatches - reset any existing borders on inner elements */
.single-product .ct-variation-swatches .ct-swatch-container .ct-swatch,
.single-product .ct-variation-swatches .ct-swatch-container .ct-swatch-content {
    border: none !important;
    background: transparent !important;
}

/* Unselected swatches - light gray border on container only */
.single-product .ct-variation-swatches .ct-swatch-container,
.single-product .variable-items-wrapper .variable-item {
    background: transparent !important;
    background-color: transparent !important;
    color: #333 !important;
    border: 1px solid #ddd !important;
    border-radius: 0 !important;
    padding: 0 !important;
    cursor: pointer !important;
}

/* Swatch inner content styling */
.single-product .ct-variation-swatches .ct-swatch-container .ct-swatch {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    height: 100% !important;
}

.single-product .ct-variation-swatches .ct-swatch-container .ct-swatch-content {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 8px 16px !important;
    border: none !important;
    background: transparent !important;
    font-size: 14px !important;
    font-weight: 400 !important;
    line-height: 1.4 !important;
    color: inherit !important;
}

/* Variation swatches - selected state uses darker gray border */
.single-product .ct-variation-swatches .ct-swatch-container.active,
.single-product .ct-variation-swatches .ct-swatch-container.selected,
.single-product .ct-variation-swatches .ct-swatch-container[aria-checked="true"],
.single-product .variable-items-wrapper .variable-item.selected,
.single-product .variable-items-wrapper .variable-item.active {
    background: transparent !important;
    background-color: transparent !important;
    color: #333 !important;
    border: 1px solid #555 !important;
}

/* Hover state */
.single-product .ct-variation-swatches .ct-swatch-container:hover,
.single-product .variable-items-wrapper .variable-item:hover {
    border-color: #999 !important;
}

/* ==========================================================================
   Upload Section Styles
   ========================================================================== */

/* Upload Section Container */
.ipt-upload-section {
    margin: 0 0 20px 0;
    padding: 0;
    overflow: visible;
}

/* Header with label, constraints, and remove all on same line */
.ipt-upload-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 0;
    flex-wrap: wrap;
}

/* Upload label - match WooCommerce variation label styling */
.ipt-upload-label {
    font-size: inherit;
    font-weight: 400;
    color: inherit;
}

.ipt-upload-constraints {
    font-size: 13px;
    color: #888;
}

.ipt-remove-all {
    font-size: 13px;
    color: #0073aa;
    text-decoration: none;
    cursor: pointer;
}

.ipt-remove-all:hover {
    text-decoration: underline;
    color: #005177;
}

.ipt-upload-description {
    font-size: 13px;
    color: #666;
    margin-bottom: 15px;
}

/* Gallery Wrapper with Navigation */
.ipt-upload-gallery-wrapper {
    position: relative;
    overflow: visible;
}

/* Container box around upload button and previews */
.ipt-upload-gallery {
    flex: 1;
    overflow: visible;
    position: relative;
    background: transparent;
    padding: 8px 0 0 0;
}

.ipt-upload-gallery-inner {
    display: flex;
    gap: 8px;
    transition: transform 0.3s ease;
    align-items: flex-start;
    overflow: visible;
    padding-top: 0;
}

/* Wrap mode: items wrap to multiple rows */
.ipt-upload-gallery.ipt-wrap-mode .ipt-upload-gallery-inner {
    flex-wrap: wrap;
}

/* Scroll mode: no wrap, use arrows to scroll */
.ipt-upload-gallery.ipt-scroll-mode .ipt-upload-gallery-inner {
    flex-wrap: nowrap;
}

.ipt-upload-gallery.ipt-scroll-mode {
    overflow: hidden;
}

/* Navigation Arrows - simple, positioned outside gallery */
.ipt-gallery-nav {
    display: none !important; /* Hidden by default */
    align-items: center;
    justify-content: center;
    width: 24px !important;
    height: 24px !important;
    min-width: 24px !important;
    min-height: 24px !important;
    border: none !important;
    border-radius: 0 !important;
    background: none !important;
    background-color: transparent !important;
    color: #999 !important;
    cursor: pointer;
    transition: color 0.2s ease;
    padding: 0 !important;
    margin: 0 !important;
    line-height: 1 !important;
    font-size: 0 !important;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    outline: none !important;
    box-shadow: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
}

.ipt-gallery-nav.ipt-gallery-prev {
    left: -30px;
}

.ipt-gallery-nav.ipt-gallery-next {
    right: -30px;
}

.ipt-gallery-nav.visible {
    display: flex !important;
}

.ipt-gallery-nav:hover {
    color: #333 !important;
    background: none !important;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

.ipt-gallery-nav:focus {
    outline: none !important;
    box-shadow: none !important;
    border: none !important;
}

.ipt-gallery-nav:active {
    background: none !important;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

.ipt-gallery-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.ipt-gallery-nav svg {
    width: 24px !important;
    height: 24px !important;
    stroke: currentColor !important;
    fill: none !important;
    display: block !important;
}

/* Upload Button Wrapper - box around button and label */
.ipt-upload-btn-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    padding: 2px;
    background: transparent;
    border: 1px solid #ddd;
    border-radius: 0;
    width: 100px;
    box-sizing: border-box;
}

/* Upload button - fills the box width */
.ipt-upload-add-btn {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    position: relative;
    border-radius: 50%;
    background: #333;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.ipt-upload-add-btn .ipt-upload-plus {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ipt-upload-add-btn:hover {
    background: #555;
    transform: scale(1.05);
}

.ipt-upload-add-btn:active {
    transform: scale(0.98);
}

.ipt-upload-plus {
    color: #fff;
}

.ipt-upload-plus svg {
    width: 28px;
    height: 28px;
}

.ipt-upload-btn-label {
    font-size: 11px;
    color: #666;
}

/* Preview Container - Safari compatible */
.ipt-upload-previews {
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-wrap: wrap;
    flex-wrap: wrap;
    gap: 8px;
    /* Ensure it participates correctly in parent flex layout */
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    flex: 1;
    min-width: 0;
}

/* When no items, don't take space */
.ipt-upload-previews:empty {
    display: none;
}

/* Individual Preview Item - box around entire item including filename */
.ipt-preview-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    padding: 2px;
    background: transparent;
    border: 1px solid #ddd;
    border-radius: 0;
    overflow: visible;
    width: 100px; /* Same as upload button wrapper */
    box-sizing: border-box;
}

/* Delete Button - positioned partially outside the box at top-right corner */
.ipt-preview-delete {
    position: absolute !important;
    top: -6px !important;
    right: -6px !important;
    width: 16px !important;
    height: 16px !important;
    min-width: 16px !important;
    min-height: 16px !important;
    border-radius: 50% !important;
    background: #000 !important;
    border: none !important;
    color: #fff !important;
    cursor: pointer;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0 !important;
    line-height: 1 !important;
    padding: 0 !important;
    transition: background 0.2s ease;
    z-index: 10;
    box-shadow: none !important;
}

/* Image wrapper - fills the box width */
.ipt-preview-image-wrapper {
    position: relative;
    width: 100%;
    /* Safari fallback for aspect-ratio */
    height: 0;
    padding-bottom: 100%; /* Creates 1:1 aspect ratio */
    border-radius: 0;
    overflow: hidden;
    background: #f5f5f5;
}

/* Modern browsers with aspect-ratio support */
@supports (aspect-ratio: 1 / 1) {
    .ipt-preview-image-wrapper {
        height: auto;
        padding-bottom: 0;
        aspect-ratio: 1 / 1;
    }
}

.ipt-preview-image-wrapper img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 0;
}

/* Modern browsers - remove position absolute when aspect-ratio is supported */
@supports (aspect-ratio: 1 / 1) {
    .ipt-preview-image-wrapper img {
        position: static;
    }
}

.ipt-preview-delete:hover {
    background: #c0392b !important;
}

.ipt-preview-delete svg {
    width: 12px !important;
    height: 12px !important;
    stroke: #fff !important;
    fill: none !important;
    display: block !important;
}

/* Image Name */
.ipt-preview-name {
    font-size: 11px;
    color: #666;
    width: 100%;
    max-width: 100%;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Loading State */
.ipt-preview-item.loading .ipt-preview-image-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.ipt-preview-item.loading .ipt-preview-image-wrapper img {
    opacity: 0.3;
}

.ipt-preview-item.loading .ipt-preview-image-wrapper::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    border: 2px solid #ddd;
    border-top-color: #333;
    border-radius: 50%;
    animation: ipt-spin 0.8s linear infinite;
}

@keyframes ipt-spin {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Error State */
.ipt-preview-item.error .ipt-preview-image-wrapper {
    border-color: #e74c3c;
}

/* Cart Thumbnails */
.ipt-cart-thumbnails {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    margin-top: 5px;
}

.ipt-cart-thumb img {
    transition: transform 0.2s ease;
}

.ipt-cart-thumb:hover img {
    transform: scale(1.1);
}

/* Cart Edit Link */
.ipt-cart-edit {
    margin-top: 8px;
}

.ipt-cart-edit-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: #0073aa;
    text-decoration: none;
}

.ipt-cart-edit-link:hover {
    text-decoration: underline;
    color: #005177;
}

/* Edit mode button styling */
.single_add_to_cart_button.ipt-edit-mode {
    background-color: #28a745 !important;
    border-color: #28a745 !important;
}

.single_add_to_cart_button.ipt-edit-mode:hover {
    background-color: #218838 !important;
    border-color: #1e7e34 !important;
}

/* Order Thumbnails */
.ipt-order-thumbnails {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.ipt-order-thumbnails img {
    transition: opacity 0.2s ease;
}

.ipt-order-thumbnails a:hover img {
    opacity: 0.8;
}

/* Conditional attribute visibility */
.ipt-attr-hidden {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Variation controls disabled state during restoration */
.ipt-restoring-options .variations {
    position: relative;
}

.ipt-restoring-options .variations::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.7);
    z-index: 100;
    pointer-events: all;
}

.ipt-restoring-options select[name^="attribute_"] {
    opacity: 0.5;
    pointer-events: none;
}

.ipt-restoring-options .ct-variation-swatches.ipt-disabled {
    opacity: 0.5;
    pointer-events: none;
}

.ipt-restoring-options .ct-swatch-container {
    cursor: not-allowed !important;
}

.ipt-restoring-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 13px;
    z-index: 101;
    white-space: nowrap;
}

/* Hidden state during restoration */
.ipt-restoring-hidden {
    display: none !important;
}

.ipt-restoring-message {
    padding: 20px;
    text-align: center;
    font-size: 14px;
    color: #666;
    background: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 4px;
    margin: 10px 0;
}

/* ==========================================================================
   Preview Compositor Styles (Gallery Injection Mode)
   ========================================================================== */

/* Loading state for gallery while compositing */
.woocommerce-product-gallery.ipt-loading-preview .ct-product-gallery-container {
    opacity: 0.5;
    pointer-events: none;
}

/* Composited images in gallery */
.ipt-composite-image {
    position: relative;
}

.ipt-composite-image img {
    width: 100%;
    height: auto;
    display: block;
}

/* Active preview indicator on upload thumbnails */
.ipt-preview-item.active-preview {
    border-color: #0073aa !important;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

.ipt-preview-item.active-preview::after {
    content: 'Preview';
    position: absolute;
    bottom: 22px;
    left: 0;
    right: 0;
    background: rgba(0, 115, 170, 0.9);
    color: #fff;
    font-size: 9px;
    text-align: center;
    padding: 2px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Clickable cursor for user content mode */
.ipt-preview-item:not(.loading) {
    cursor: pointer;
}

.ipt-preview-item:not(.loading):hover {
    border-color: #999;
}

@media (max-width: 767px) {
    .ipt-upload-header {
        flex-direction: column;
        gap: 4px;
    }

    .ipt-upload-gallery-wrapper {
        gap: 5px;
    }

    .ipt-gallery-nav {
        width: 28px;
        height: 28px;
    }

    .ipt-gallery-nav svg {
        width: 16px;
        height: 16px;
    }

    /* Keep same size as desktop for upload button and preview items */
    .ipt-upload-btn-wrapper,
    .ipt-preview-item {
        width: 100px !important;
        min-width: 100px !important;
    }

    .ipt-upload-add-btn {
        width: 96px !important;
        height: 96px !important;
    }

    .ipt-preview-image-wrapper {
        width: 96px !important;
        height: 96px !important;
    }

    .ipt-preview-name {
        max-width: 96px;
    }

    .ipt-preview-canvas-wrapper {
        max-width: 100%;
    }
}

/* ==========================================================================
   Upload Prompt Styles
   ========================================================================== */

/* Style for the upload prompt message shown when no images are uploaded */
.ipt-upload-prompt {
    color: #666;
    font-style: italic;
    font-size: 14px;
}
