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

/* 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 {
    margin: 10px 0;
    position: relative;
}

.sm-swatches-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 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 {
    opacity: 0.4;
    cursor: not-allowed;
    background-color: #f5f5f5;
    border-color: #e0e0e0;
}

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

/* 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 .value .sm-swatches-container {
    margin-top: 5px;
}

.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: 30px;
        height: 32px;
        padding: 5px 10px;
        font-size: 12px;
    }

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

    .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);
    }
}

/* 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;
    }
}

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

/* 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%;
    }
}
