/**
 * Swatches Manager CSS
 * Styles for converting WooCommerce variation dropdowns to visual circles
 */

/* Loading state for AJAX variation loading */
.variations_form.sm-loading-variations {
    position: relative;
    opacity: 0.6;
    pointer-events: none;
}

.variations_form.sm-loading-variations::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #333;
    border-radius: 50%;
    animation: sm-spin 1s linear infinite;
    z-index: 1000;
}

@keyframes sm-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Lightweight placeholder before AJAX swatches are rendered */
.sm-swatches-mount {
    margin-top: 15px;
}

.sm-swatches-placeholder {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.sm-swatch-skeleton {
    display: inline-block;
    min-width: 52px;
    height: 40px;
    border-radius: 50px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e5e5e5 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: sm-skeleton 1.2s ease-in-out infinite;
}

.sm-swatches-loading-text {
    display: inline-block;
    margin-top: 8px;
    font-size: 12px;
    color: #777;
}

@keyframes sm-skeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Hide original WooCommerce variation dropdowns when swatches are present */
.variations .sm-original-select {
    display: none !important;
}

/* Ensure original selects are hidden but remain functional */
.variations .sm-swatches-container ~ select,
.variations .sm-swatches-container + .sm-original-select select {
    position: absolute !important;
    left: -9999px !important;
    opacity: 0 !important;
    pointer-events: none !important;
    width: 1px !important;
    height: 1px !important;
}

/* Main swatches container */
.sm-swatches-container {
    position: relative;
}

.sm-swatches-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
    align-items: center;
}

/* Individual swatch styling - Flexible pill/capsule shape */
.sm-swatch {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 8px 16px;
    border: 2px solid #ddd;
    border-radius: 50px;
    background-color: #f9f9f9;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: #333;
    box-sizing: border-box;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Swatch hover effect */
.sm-swatch:hover {
    border-color: #999;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background-color: #f0f0f0;
}

/* Selected swatch styling */
.sm-swatch.selected {
    border-color: #28a745 !important;
    border-width: 3px;
    background-color: #f8fff9;
    box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.2);
}

/* Swatch label - Optimized for pill shape */
.sm-swatch-label {
    display: block;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px; /* Reasonable max width for very long labels */
    flex: 1;
}

/* Checkbox indicator - Positioned for pill shape */
.sm-swatch-checkbox {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 18px;
    height: 18px;
    background-color: #28a745;
    color: white;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    line-height: 1;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 1;
}

/* Show checkbox when selected */
.sm-swatch.selected .sm-swatch-checkbox {
    display: flex;
}

/* Disabled/unavailable swatch styling */
.sm-swatch.disabled,
.sm-swatch.sm-swatch-disabled {
    opacity: 0.35;
    cursor: not-allowed !important;
    background-color: #f5f5f5;
    border-color: #e0e0e0;
    color: #999;
    /* pointer-events: none; - REMOVED to allow click events for error message display */
}

.sm-swatch.disabled:hover,
.sm-swatch.sm-swatch-disabled:hover {
    transform: none;
    box-shadow: none;
    border-color: #e0e0e0;
    background-color: #f5f5f5;
}

/* Strikethrough effect for disabled swatches */
.sm-swatch.sm-swatch-disabled .sm-swatch-label {
    text-decoration: line-through;
    opacity: 0.6;
}

/* Hidden input field */
.sm-hidden-input {
    display: none !important;
}

/* Loading state */
.sm-swatches-container.loading .sm-swatch {
    pointer-events: none;
    opacity: 0.6;
}

.sm-swatches-container.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #333;
    border-radius: 50%;
    animation: sm-spin 1s linear infinite;
}

@keyframes sm-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive design */
@media (max-width: 768px) {
    .sm-swatch {
        min-width: 40px;
        height: 40px;
        padding: 6px 14px;
        font-size: 12px;
    }

    .sm-swatches-wrapper {
        gap: 6px;
    }
}

@media (max-width: 480px) {
    .sm-swatch {
        min-width: 35px;
        height: 35px;
        padding: 5px 12px;
        font-size: 11px;
    }

    .sm-swatches-wrapper {
        gap: 5px;
    }

    .sm-swatch-checkbox {
        width: 14px;
        height: 14px;
        font-size: 9px;
    }
}

/* Color-based swatches (if attribute contains color information) */
.sm-swatch[data-color] {
    border-width: 1px;
}

.sm-swatch[data-color] .sm-swatch-label {
    display: none;
}

.sm-swatch[data-color]:hover {
    border-width: 2px;
}

.sm-swatch[data-color].selected {
    border-width: 3px;
}

/* Size-based swatches styling */
.sm-swatch[data-attribute*="size"] .sm-swatch-label,
.sm-swatch[data-attribute*="Size"] .sm-swatch-label {
    font-weight: 600;
    text-transform: uppercase;
}

/* Integration with WooCommerce variation form */
.variations .label {
    vertical-align: top;
}

/* Clear floats */
.sm-swatches-container::after {
    content: "";
    display: table;
    clear: both;
}

/* Accessibility improvements */
.sm-swatch:focus {
    outline: 2px solid #005fcc;
    outline-offset: 2px;
}

.sm-swatch[aria-pressed="true"] {
    border-color: #28a745;
    background-color: #f8fff9;
}

/* Animation for selection */
.sm-swatch.selected {
    animation: sm-select-pulse 0.3s ease-out;
}

@keyframes sm-select-pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

/* Responsive design for different screen sizes */
@media (max-width: 768px) {
    .sm-swatch {
        min-width: 35px;
        height: 35px;
        padding: 6px 12px;
        font-size: 13px;
    }

    .sm-swatches-wrapper {
        gap: 8px;
    }

    .sm-swatch-checkbox {
        width: 16px;
        height: 16px;
        font-size: 10px;
        top: -10px;
        right: -10px;
    }
}

@media (max-width: 480px) {
    .sm-swatch {
        min-width: 46px;
        height: 46px;
        font-size: 15px;
    }

    .sm-swatches-wrapper {
        gap: 10px;
    }

    .sm-swatch-label {
        max-width: 150px;
    }
}

/* Large screens - allow more generous spacing */
@media (min-width: 1200px) {
    .sm-swatch {
        min-width: 45px;
        height: 45px;
        padding: 10px 18px;
        font-size: 15px;
    }

    .sm-swatches-wrapper {
        gap: 12px;
    }
}

/* Success message styling */
.sm-success-message {
    display: none;
    margin-top: 15px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
    border: 1px solid #c3e6cb;
    border-left: 4px solid #28a745;
    border-radius: 8px;
    color: #155724;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.1);
    animation: sm-slide-in 0.4s ease-out;
    position: relative;
    overflow: hidden;
}



.sm-success-message.show {
    display: block;
}

.sm-success-message .sm-success-icon {
    display: inline-block;
    margin-right: 8px;
    font-size: 16px;
    color: #28a745;
    animation: sm-bounce 0.6s ease-out;
}

.sm-success-message .sm-product-name {
    font-weight: 600;
    color: #0f5132;
}

/* Success message animations */
@keyframes sm-slide-in {
    0% {
        opacity: 0;
        transform: translateY(-10px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes sm-bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-4px);
    }
    60% {
        transform: translateY(-2px);
    }
}



/* Auto-hide animation */
.sm-success-message.fade-out {
    animation: sm-fade-out 0.5s ease-in forwards;
}

@keyframes sm-fade-out {
    0% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* Error message styling (for out-of-stock notifications) */
.sm-error-message {
    display: none;
    margin-top: 15px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
    border: 1px solid #f5c6cb;
    border-left: 4px solid #dc3545;
    border-radius: 8px;
    color: #721c24;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.1);
    animation: sm-slide-in 0.4s ease-out;
    position: relative;
    overflow: hidden;
}

.sm-error-message.show {
    display: block;
}

.sm-error-message .sm-error-text {
    display: inline-block;
    color: #721c24;
}

/* Error message fade-out animation */
.sm-error-message.fade-out {
    animation: sm-fade-out 0.5s ease-in forwards;
}

/* WooCommerce in-stock availability message styling */
.woocommerce-variation-availability .stock.in-stock {
    margin: 15px 0 15px 0 !important;
    padding: 12px 16px !important;
    background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%) !important;
    border: 1px solid #c3e6cb !important;
    border-left: 4px solid #28a745 !important;
    border-radius: 8px !important;
    color: #155724 !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.1) !important;
    animation: sm-slide-in 0.4s ease-out !important;
    position: relative !important;
    overflow: hidden !important;
}

/* Add checkmark icon before in-stock text */
.woocommerce-variation-availability .stock.in-stock::before {
    content: '✓';
    display: inline-block;
    margin-right: 8px;
    font-size: 16px;
    color: #28a745;
    font-weight: bold;
}

/* Out-of-stock message styling (for consistency) */
.woocommerce-variation-availability .stock.out-of-stock {
    margin: 15px 0 0 0 !important;
    padding: 12px 16px !important;
    background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%) !important;
    border: 1px solid #f5c6cb !important;
    border-left: 4px solid #dc3545 !important;
    border-radius: 8px !important;
    color: #721c24 !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.1) !important;
    animation: sm-slide-in 0.4s ease-out !important;
    position: relative !important;
    overflow: hidden !important;
}

/* Add X icon before out-of-stock text */
.woocommerce-variation-availability .stock.out-of-stock::before {
    content: '✗';
    display: inline-block;
    margin-right: 8px;
    font-size: 16px;
    color: #dc3545;
    font-weight: bold;
}

/* Responsive success message */
@media (max-width: 768px) {
    .sm-success-message {
        margin-top: 12px;
        padding: 10px 14px;
        font-size: 13px;
    }

    .sm-success-message .sm-success-icon {
        font-size: 14px;
        margin-right: 6px;
    }

    .sm-error-message {
        margin-top: 12px;
        padding: 10px 14px;
        font-size: 13px;
    }

    .woocommerce-variation-availability .stock.in-stock,
    .woocommerce-variation-availability .stock.out-of-stock {
        margin-top: 12px !important;
        padding: 10px 14px !important;
        font-size: 13px !important;
    }

    .woocommerce-variation-availability .stock.in-stock::before,
    .woocommerce-variation-availability .stock.out-of-stock::before {
        font-size: 14px;
        margin-right: 6px;
    }
}

@media (max-width: 480px) {
    .sm-success-message {
        margin-top: 10px;
        padding: 8px 12px;
        font-size: 12px;
        border-radius: 6px;
    }

    .sm-error-message {
        margin-top: 10px;
        padding: 8px 12px;
        font-size: 12px;
        border-radius: 6px;
    }

    .woocommerce-variation-availability .stock.in-stock,
    .woocommerce-variation-availability .stock.out-of-stock {
        margin-top: 10px !important;
        padding: 8px 12px !important;
        font-size: 12px !important;
        border-radius: 6px !important;
    }
}

/* Wholesale unit price styling - matches WooCommerce variation price */
.woocommerce-variation-price .price + .price {
    display: inline;
    font-size: 0.9em;
    opacity: 0.8;
    font-weight: normal;
}

.woocommerce-variation-price .price + .price .woocommerce-Price-amount {
    font-size: inherit;
    font-weight: inherit;
}

/* ========================================
   LOOP/ARCHIVE PAGE SWATCHES STYLING
   ======================================== */

/* Main container for loop swatches */
.sm-loop-swatches-container {
    margin: 10px 0 5px 0;
    padding: 0;
    clear: both;
}

.sm-loop-swatches-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    align-items: center;
}

/* Individual loop swatch styling - Match single product page swatches */
.sm-loop-swatch {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 8px 16px;
    border: 2px solid #ddd;
    border-radius: 50px;
    background-color: #f9f9f9;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: #333;
    box-sizing: border-box;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Loop swatch hover effect - Match single product page */
.sm-loop-swatch:hover {
    border-color: #999;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background-color: #f0f0f0;
}

/* Selected loop swatch styling - Match single product page with green border */
.sm-loop-swatch.selected {
    border-color: #28a745 !important;
    border-width: 3px;
    background-color: #f8fff9;
    box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.2);
}

/* Loop swatch label - Match single product page */
.sm-loop-swatch-label {
    display: block;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    flex: 1;
}

/* Checkbox indicator for loop swatches - Match single product page */
.sm-loop-swatch-checkbox {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 18px;
    height: 18px;
    background-color: #28a745;
    color: white;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    line-height: 1;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 1;
}

/* Show checkbox when loop swatch is selected */
.sm-loop-swatch.selected .sm-loop-swatch-checkbox {
    display: flex;
}

/* Disabled/unavailable loop swatch */
.sm-loop-swatch.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background-color: #f5f5f5;
    border-color: #e0e0e0;
}

.sm-loop-swatch.disabled:hover {
    transform: none;
    box-shadow: none;
    border-color: #e0e0e0;
}

/* Responsive design for loop swatches - Match single product page */
@media (max-width: 768px) {
    .sm-loop-swatch {
        min-width: 35px;
        height: 35px;
        padding: 6px 12px;
        font-size: 13px;
    }

    .sm-loop-swatches-wrapper {
        gap: 8px;
    }

    .sm-loop-swatch-checkbox {
        width: 16px;
        height: 16px;
        font-size: 10px;
        top: -10px;
        right: -10px;
    }
}

@media (max-width: 480px) {
    .sm-loop-swatch {
        min-width: 30px;
        height: 32px;
        padding: 5px 10px;
        font-size: 12px;
    }

    .sm-loop-swatches-wrapper {
        gap: 6px;
    }

    .sm-loop-swatch-label {
        max-width: 150px;
    }
}

/* Integration with WooCommerce product loop */
.woocommerce ul.products li.product .sm-loop-swatches-container {
    margin-top: 8px;
    margin-bottom: 8px;
}

/* Animation for loop swatch selection */
.sm-loop-swatch.selected {
    animation: sm-loop-select-pulse 0.3s ease-out;
}

@keyframes sm-loop-select-pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.08);
    }
    100% {
        transform: scale(1);
    }
}

/* Loading state for loop swatches */
.sm-loop-swatches-container.loading .sm-loop-swatch {
    pointer-events: none;
    opacity: 0.5;
}

/* Ensure price displays inline (not as column) and centered */
.woocommerce ul.products li.product .price {
    display: block;
    text-align: center;
}

/* Remove nested price span styling issues */
.woocommerce ul.products li.product .price .price {
    display: inline;
    font-size: inherit;
}

/* Add to cart button states on loop pages */
.woocommerce ul.products li.product .button.loading {
    opacity: 0.6;
    cursor: wait;
}

.woocommerce ul.products li.product .button.added {
    background-color: #28a745 !important;
    border-color: #28a745 !important;
    color: white !important;
    position: relative;
    overflow: hidden;
    z-index: 1;
}

/* Progress bar animation - shows countdown until button resets */
.woocommerce ul.products li.product .button.added::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0;
    background-color: #1e7e34; /* Darker green for progress bar */
    z-index: -1;
    animation: progressBar 1s linear forwards;
}

/* Keyframe animation - fills button from left to right in 1.5 seconds */
@keyframes progressBar {
    0% {
        width: 0%;
    }
    100% {
        width: 100%;
    }
}
