/**
 * Colour Swatches Frontend Styles
 *
 * @package PrintShopStudio
 */

/* Swatches Wrapper */
.pss-colour-swatches-wrapper {
    margin-bottom: 20px;
}

.pss-swatch-label {
    display: block;
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 14px;
    color: #333;
}

.pss-selected-colour {
    font-weight: normal;
    color: #666;
}

/* Swatch Container */
.pss-colour-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

/* Swatch Button */
.pss-swatch-button {
    padding: 0;
    border: 2px solid #ddd;
    background: none;
    cursor: pointer;
    position: relative;
    border-radius: 50%;
    transition: transform 0.15s, border-color 0.15s;
    width: 36px !important;
    height: 36px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Ensure white swatches are visible */
.pss-swatch-button.pss-simple-swatch {
    border: 2px solid #ddd;
    border-radius: 50%;
    box-shadow: none;
    width: 36px !important;
    height: 36px !important;
}

.pss-swatch-button:hover {
    transform: scale(1.05);
    border-color: #999;
}

.pss-swatch-button:focus {
    outline: none;
    border-color: #666;
}

/* Selected state */
.pss-swatch-button.selected {
    transform: scale(1.0);
    border-color: #1d2327;
    box-shadow: none;
}

.pss-swatch-button.selected .pss-colour-swatch {
    border-color: #1d2327;
}

/* Simple swatch selected state */
.pss-swatch-button.pss-simple-swatch.selected {
    border-color: #1d2327;
    box-shadow: none;
}

/* Checkmark for selected swatches */
.pss-swatch-button.selected::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 18px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
    pointer-events: none;
    z-index: 1;
}

/* For light coloured swatches, use dark checkmark */
.pss-swatch-button.pss-light-swatch.selected::after {
    color: #333;
    text-shadow: none;
}

.pss-swatch-button.out-of-stock {
    opacity: 0.4;
    cursor: not-allowed;
}

.pss-swatch-button.out-of-stock::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: #d63638;
    transform: rotate(-45deg);
}

/* Colour Swatch Element */
.pss-colour-swatch {
    display: block;
    width: 44px;
    height: 44px;
    border-radius: 6px;
    border: 2px solid #ddd;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* Tooltip */
.pss-swatch-button[title] {
    position: relative;
}

.pss-swatch-button::before {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 5px 10px;
    background: #1d2327;
    color: #fff;
    font-size: 12px;
    white-space: nowrap;
    border-radius: 4px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
    margin-bottom: 5px;
}

.pss-swatch-button:hover::before {
    opacity: 1;
    visibility: visible;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .pss-colour-swatches {
        gap: 10px;
    }

    /* Ensure minimum 44px touch target */
    .pss-swatch-button {
        min-width: 44px;
        min-height: 44px;
    }

    .pss-colour-swatch {
        min-width: 44px !important;
        min-height: 44px !important;
    }

    /* Hide hover tooltips on touch devices */
    .pss-swatch-button::before {
        display: none;
    }
}

/* Size-based colour availability */
.pss-swatch-button.unavailable-for-size {
    opacity: 0.3;
    position: relative;
}

.pss-swatch-button.unavailable-for-size::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #999;
    transform: rotate(-45deg);
}

/* Selected colour display */
.pss-colour-display {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 4px;
}

.pss-colour-display .pss-colour-swatch {
    flex-shrink: 0;
}

.pss-colour-display .pss-colour-name {
    font-weight: 500;
}

/* Animation for swatch selection */
@keyframes pss-swatch-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1.05); }
}

.pss-swatch-button.just-selected {
    animation: pss-swatch-pulse 0.3s ease-out;
}

/* Two-tone swatch specific styles */
.pss-swatch-twotone {
    overflow: hidden;
}

/* Pattern swatch specific styles */
.pss-swatch-pattern {
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
}

/* Loading state */
.pss-colour-swatches.loading {
    opacity: 0.5;
    pointer-events: none;
}

.pss-colour-swatches.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #2271b1;
    border-top-color: transparent;
    border-radius: 50%;
    animation: pss-spin 0.8s linear infinite;
}

@keyframes pss-spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   Simple Product Options (PSS Attributes)
   ============================================ */

.pss-simple-product-options {
    margin-bottom: 20px;
}

.pss-simple-colours,
.pss-simple-sizes {
    margin-bottom: 20px;
}

.pss-option-label {
    display: block;
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 14px;
}

.pss-selected-colour-name,
.pss-selected-size-name {
    font-weight: 400;
    color: #333;
}

/* Size buttons */
.pss-size-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pss-size-button {
    padding: 10px 16px;
    border: 2px solid #e5e5e5;
    border-radius: 4px;
    background: #fff;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 50px;
    text-align: center;
}

.pss-size-button:hover {
    border-color: #999;
    background: #f9f9f9;
}

.pss-size-button.selected {
    border-color: #333;
    background: #333;
    color: #fff;
}

.pss-size-button .pss-size-adj {
    display: block;
    font-size: 11px;
    font-weight: 400;
    opacity: 0.7;
    margin-top: 2px;
}

.pss-size-button.selected .pss-size-adj {
    color: rgba(255, 255, 255, 0.8);
}

/* Simple colour swatches */
.pss-simple-swatch {
    position: relative;
}

.pss-simple-swatch.selected::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 16px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* Dynamic price display */
.pss-dynamic-price {
    padding: 15px;
    background: #f9f9f9;
    border-radius: 4px;
    margin-top: 15px;
}

.pss-price-label {
    font-weight: 600;
    margin-right: 10px;
}

.pss-calculated-price {
    font-size: 20px;
    font-weight: 700;
    color: #333;
}

.pss-calculated-price .woocommerce-Price-amount {
    font-size: inherit;
    font-weight: inherit;
}

/* Mobile adjustments */
@media (max-width: 600px) {
    .pss-size-button {
        padding: 12px 14px;
        min-width: 44px;
    }
    
    .pss-calculated-price {
        font-size: 18px;
    }
}

/* ============================================
   Size Matrix (Bulk Order Layout)
   ============================================ */

.pss-size-matrix-wrapper {
    margin: 20px 0;
    overflow-x: auto;
}

/* Size Grid - Flexbox layout that wraps horizontally */
.pss-size-grid {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    align-items: stretch;
}

.pss-size-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 0 0 auto;
    width: 58px;
}

.pss-size-item .pss-size-label {
    font-weight: 600;
    font-size: 13px;
    text-align: center;
    color: #333;
    margin-bottom: 4px;
    min-height: 36px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
}

.pss-size-item .pss-size-price-adj {
    font-size: 10px;
    font-weight: 500;
    color: #c45500;
    line-height: 1.2;
}

/* Unavailable size styling (from availability matrix) */
.pss-size-item.pss-size-unavailable {
    opacity: 0.4;
    pointer-events: none;
    position: relative;
}

.pss-size-item.pss-size-unavailable::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 80%;
    height: 2px;
    background: #d63638;
    transform: translate(-50%, -50%) rotate(-45deg);
    border-radius: 1px;
}

.pss-size-item.pss-size-unavailable .pss-size-label {
    text-decoration: line-through;
    color: #999;
}

.pss-size-item.pss-size-unavailable .pss-size-qty-input {
    background: #f5f5f5;
    cursor: not-allowed;
}

.pss-size-matrix-wrapper .pss-option-label {
    display: block;
    font-weight: 600;
    margin-bottom: 12px;
    font-size: 14px;
    color: #333;
}

/* Keep old table styles for backwards compatibility */
.pss-size-matrix {
    width: auto;
    border-collapse: separate;
    border-spacing: 4px 0;
    border: none;
}

.pss-size-matrix th {
    background: transparent;
    padding: 8px 6px;
    font-weight: 600;
    font-size: 13px;
    text-align: center;
    border: none;
    min-width: 55px;
    color: #333;
}

.pss-size-matrix th .pss-size-price-adj {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: #c45500;
    margin-top: 2px;
}

.pss-size-matrix td {
    padding: 6px;
    text-align: center;
    border: none;
    vertical-align: middle;
}

.pss-size-qty-input {
    width: 50px;
    height: 40px;
    padding: 8px 4px;
    text-align: center;
    border: 2px solid #ccc;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    background-color: #fff;
    -moz-appearance: textfield;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

.pss-size-qty-input::placeholder {
    color: #bbb;
    font-weight: 400;
}

.pss-size-qty-input::-webkit-outer-spin-button,
.pss-size-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.pss-size-qty-input:hover {
    border-color: #999;
}

.pss-size-qty-input:focus {
    outline: none;
    border-color: #2271b1;
    box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.2);
    background-color: #fff;
}

/* Highlight inputs with quantity > 0 */
.pss-size-qty-input.has-quantity {
    background-color: #e8f4fc;
    border-color: #2271b1;
    color: #1d2327;
}

/* Simple product options container */
.pss-simple-product-options {
    margin-bottom: 20px;
}

.pss-simple-colours {
    margin-bottom: 20px;
}

.pss-simple-colours .pss-option-label {
    display: block;
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 14px;
}

.pss-simple-colours .pss-colour-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

/* Mobile adjustments for matrix */
@media (max-width: 600px) {
    .pss-size-matrix th {
        padding: 6px 4px;
        font-size: 11px;
        min-width: 45px;
    }
    
    .pss-size-qty-input {
        width: 42px;
        height: 36px;
        padding: 6px 2px;
        font-size: 14px;
    }
}

/* ============================================
   PSS Notice Styles
   ============================================ */

.pss-notice {
    padding: 15px 20px;
    margin-bottom: 20px;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.5;
}

.pss-notice-success {
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.pss-notice-success .pss-view-cart-link {
    display: inline-block;
    margin-left: 10px;
    font-weight: 600;
    color: #155724;
    text-decoration: underline;
}

.pss-notice-success .pss-view-cart-link:hover {
    color: #0d3d14;
}

.pss-notice-error {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.pss-notice-info {
    background-color: #d1ecf1;
    border: 1px solid #bee5eb;
    color: #0c5460;
}

/* ============================================
   Button Loading State
   ============================================ */

.single_add_to_cart_button.loading {
    position: relative;
    opacity: 0.7;
    pointer-events: none;
}

.single_add_to_cart_button.loading::after {
    content: '';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: pss-spin 0.8s linear infinite;
}

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

/* ============================================
   Total Quantity Display
   ============================================ */

.pss-bulk-summary {
    margin: 12px 0 0 0;
    padding: 0;
    background: transparent;
    font-size: 14px;
}

.pss-bulk-summary .pss-total-label {
    font-weight: 600;
    margin-right: 5px;
}

.pss-total-quantity {
    font-weight: 700;
    color: #2271b1;
}

/* Hide default WooCommerce quantity input when using PSS bulk matrix */
.pss-simple-product-options ~ .quantity,
.pss-simple-product-options + .quantity,
form.cart:has(.pss-simple-product-options) > .quantity,
.pss-hidden-quantity,
.quantity:has(.pss-hidden-quantity) {
    display: none !important;
}

