/**
 * ===============================================================
 * CommerceBuild Quick Order Form Styles
 * ===============================================================
 */

/* Base Form Container */
#wqo-quick-order-form {
    position: relative;
    max-width: 100%;
    z-index: 10;
}

#wqo-products-table {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

/* Product Rows */
.wqo-product-row {
    display: flex;
    padding: 1rem;
    align-items: center;
    border-bottom: 1px solid #f3f4f6;
    animation: fadeIn 0.3s ease-out;
    background: #ffffff;
    flex-direction: row;
    align-content: center;
    flex-wrap: nowrap;
    justify-content: flex-start;
    transition: background-color 0.15s ease;
}

.wqo-product-row:hover {
    background: #fafafa;
}

.wqo-product-row:first-child {
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

.wqo-product-row:last-child {
    border-bottom: none;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
}

.wqo-header-row {
    font-weight: 700;
    background: #f9fafb;
    color: #374151;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.wqo-header-row:hover {
    background: #f9fafb;
}

.wqo-product-row > div,
.wqo-product-row > button {
    padding: 0 10px;
}

.wqo-product-row > div:nth-child(1) {
    flex: 0 0 35%;
}

.wqo-product-row > div:nth-child(n+2):nth-child(-n+6) {
    flex: 0 0 13%;
}

/* Product Info Display */
.wqo-product-info {
    display: flex;
    align-items: center;
}

.wqo-product-image {
    max-width: 50px;
    max-height: 50px;
    margin-right: 10px;
}

.wqo-product-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 6px;
    border: 1px solid #f3f4f6;
}

.wqo-product-details {
    display: flex;
    flex-direction: column;
}

.wqo-product-sku {
    font-size: 0.9em;
    color: #6b7280;
}

/* Legacy stock status fallback */
.tomselect-result-product__stockstatus {
    color: #374151;
    margin-left: 5px;
}

.tomselect-result-product__unit {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.tomselect-result-product__unit span {
    display: block;
}

/* Action Buttons */
.wqo-add-to-cart,
.wqo-remove-from-cart {
    border: none;
    padding: 10px 20px;
    margin: 5px 0;
    border-radius: 6px;
    height: 42px;
    line-height: 22px;
    transition: all 0.15s ease;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    width: 100%;
    position: relative;
    min-width: 110px;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.wqo-add-to-cart {
    background-color: var(--wp--preset--color--primary, var(--wc-primary, oklch(37.2% 0.044 257.287)));
    color: var(--wp--preset--color--base, var(--wc-primary-contrast, #fff));
    border-color: var(--wp--preset--color--primary, var(--wc-primary, oklch(37.2% 0.044 257.287)));
    transition: all 0.2s ease-in-out;
}

.wqo-add-to-cart.success {
    background: #10b981 !important;
    color: #ffffff;
    pointer-events: none;
    box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.3), 0 2px 4px -1px rgba(16, 185, 129, 0.2);
}

.wqo-add-to-cart .checkmark {
    display: inline-block;
    font-size: 1.2em;
    font-weight: bold;
    margin-right: 4px;
    animation: checkmarkPop 0.3s ease-out;
}

@keyframes checkmarkPop {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.wqo-add-to-cart:hover {
    background-color: var(--wp--preset--color--primary-hover, var(--wc-primary-hover, oklch(27.9% 0.041 260.031)));
    color: var(--wp--preset--color--base, var(--wc-primary-contrast, #fff));
    border-color: var(--wp--preset--color--primary-hover, var(--wc-primary-hover, oklch(27.9% 0.041 260.031)));
}

.wqo-add-to-cart:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.wqo-remove-from-cart {
    background: #ef4444;
    color: #ffffff;
}

.wqo-remove-from-cart:hover {
    background: #dc2626;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transform: translateY(-1px);
}

.wqo-remove-from-cart:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.wqo-add-to-cart.loading,
.wqo-remove-from-cart.loading {
    color: transparent !important;
    pointer-events: none;
}

.wqo-add-to-cart .spinner,
.wqo-remove-from-cart .spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #ffffff;
    animation: spin 0.8s linear infinite;
    display: none;
}

.wqo-add-to-cart.loading .spinner,
.wqo-remove-from-cart.loading .spinner {
    display: block;
}

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

/* Unit Display */
.wqo-unit {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    font-size: 0.85em;
    line-height: 1.2;
    position: relative;
    margin-bottom: 16px;
}

.wqo-unit span {
    text-align: left;
}

/* Price Display */
.wqo-price {
    display: flex;
    flex-direction: column;
    color: #059669;
    font-weight: 600;
}

.wqo-extended-price {
    font-size: 0.875rem;
    color: #059669;
    font-weight: 700;
    display: block;
    margin-top: 4px;
}

.wqo-available-value,
.wqo-quantity-available,
.wqo-price-value,
.wqo-price > span {
    color: inherit;
    display: inline-block;
    white-space: nowrap;
    font-family: "Inconsolata", "Fira Mono", "Source Code Pro", Monaco, Consolas, "Lucida Console", monospace;
    font-weight: 600;
}

.wqo-price > span {
    color: inherit;
}

.wqo-unit-value {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.row-item {
    display: block;
    margin-bottom: 8px;
}

.purchasing-content,
.sales-content {
    display: inline-block;
}

/* Pills */
.wqo-pill {
    background-color: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding-left: 8px;
    margin: 5px;
    justify-content: space-between;
    display: flex;
    align-items: center;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.wqo-pill-inner {
    display: inline-block;
    padding: 4px 12px;
    margin-left: 8px;
    font-weight: 600;
    background-color: var(--wp--preset--color--primary, var(--wc-primary, oklch(37.2% 0.044 257.287)));
    color: var(--wp--preset--color--base, var(--wc-primary-contrast, #fff));
    border-radius: 4px;
    font-family: "Inconsolata", "Fira Mono", "Source Code Pro", Monaco, Consolas, "Lucida Console", monospace;
}

/* When pill-inner is standalone (no .wqo-pill wrapper) */
.wqo-unit-value > .wqo-pill-inner:first-child {
    margin-left: 0;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

.wqo-product-row.removing {
    animation: fadeOut 0.3s ease-out;
}

/* Label Visibility */
.wqo-header-row label,
.wqo-product-row:not(.wqo-header-row) label {
    display: none;
}

/* Quantity Input */
.wqo-quantity input[type="number"] {
    width: 100%;
    min-width: 100px;
    padding: 12px 14px;
    font-size: 1rem;
    line-height: 1.5;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background-color: #f9fafb;
    appearance: none;
    box-sizing: border-box;
    font-family: "Inconsolata", "Fira Mono", "Source Code Pro", Monaco, Consolas, "Lucida Console", monospace;
    font-weight: 600;
    transition: all 0.2s ease;
}

.wqo-quantity input[type="number"]:focus {
    border-color: #4f46e5;
    background-color: #ffffff;
    outline: none;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Quantity change visual feedback */
.wqo-quantity {
    position: relative;
}

.wqo-quantity-input.qty-increase {
    border-color: #10b981 !important;
    background-color: #d1fae5 !important;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.wqo-quantity-input.qty-decrease {
    border-color: #ef4444 !important;
    background-color: #fee2e2 !important;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

/* Quantity input spinner */
.wqo-quantity-spinner {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top-color: #4f46e5;
    animation: wqo-spin 0.6s linear infinite;
    pointer-events: none;
}

@keyframes wqo-spin {
    to {
        transform: translateY(-50%) rotate(360deg);
    }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    #wqo-quick-order-form {
        padding: 0;
    }

    #wqo-products-table {
        display: block !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }

    .wqo-product-row {
        display: flex !important;
        flex-direction: column !important;
    }

    .wqo-header-row {
        display: none !important;
    }

    .wqo-product-row > div {
        width: 100%;
        position: relative;
        padding: 0 16px;
    }

    .wqo-product-row input[type="number"],
    .wqo-product-row select {
        width: 100%;
        padding: 12px;
        font-size: 1rem;
        border: 1px solid #d1d5db;
        border-radius: 6px;
        box-sizing: border-box;
        background-color: #ffffff;
    }

    .wqo-header-row label,
    .wqo-product-row:not(.wqo-header-row) label {
        display: block;
        font-weight: 800;
        line-height: 1.8rem;
    }

    input[type="number"],
    input[type="text"] {
        padding: 14px;
        border: 1px solid #e5e7eb;
        border-radius: 6px;
        background: #ffffff;
        font-size: 1rem;
        margin: 0;
    }

    .wqo-product-search {
        margin-bottom: 16px;
    }

    .wqo-action-buttons {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .wqo-product-row img {
        height: auto;
    }
}

/**
 * ===============================================================
 * TomSelect Dropdown Styles
 * ===============================================================
 */

.ts-dropdown {
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    border: 1px solid #e5e7eb;
    margin-top: 5px;
    overflow: hidden;
    background: #ffffff;
}

.ts-dropdown .option {
    padding: 12px 15px;
    border-bottom: 1px solid #f3f4f6;
    transition: background-color 0.15s ease;
    white-space: normal;
}

.ts-dropdown .option:last-child {
    border-bottom: none;
}

.ts-dropdown .option:hover,
.ts-dropdown .active {
    background-color: #f9fafb;
    color: #111827;
}

/* Product Result Layout */
.tomselect-result-product {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
}

.tomselect-result-product__image {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
    border: 1px solid #e5e7eb;
}

.tomselect-result-product__meta {
    flex: 1;
    min-width: 0;
}

.tomselect-result-product__title {
    font-size: 1rem;
    font-weight: 600;
    color: #111827;
    margin: 0 0 5px 0;
    line-height: 1.3;
}

.tomselect-result-product__title .uom-value {
    font-weight: 400;
    font-size: 0.9em;
    color: #6b7280;
    margin-left: 5px;
}

.tomselect-result-product__attributes {
    font-size: 0.85em;
    color: #6b7280;
    font-style: italic;
    margin-top: 4px;
    line-height: 1.4;
}

.tomselect-result-product__details {
    margin-top: 8px;
}

.tomselect-result-product__price {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 1.1rem;
    font-weight: 700;
    color: #059669;
}

.tomselect-result-product__price .price-loading {
    font-size: 0.9rem;
    font-weight: 400;
    color: #6b7280;
    font-style: italic;
}

/**
 * ===============================================================
 * Stock Status Pills
 * ===============================================================
 */
.wqo-stock-pill {
    display: inline-block;
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.wqo-stock-pill.wqo-stock-pill--in-stock {
    background-color: #d1fae5;
    color: #065f46;
}

.wqo-stock-pill.wqo-stock-pill--out-of-stock {
    background-color: #fee2e2;
    color: #991b1b;
}

.wqo-stock-pill.wqo-stock-pill--backorder {
    background-color: #fef3c7;
    color: #92400e;
}
