/* ==== B2B BULK ORDER MATRIX - Version 1.2.1 ==== */

/* ===== CSS CUSTOM PROPERTIES (theming) ===== */
:root {
    --b2b-header-bg:      #000000;
    --b2b-header-text:    #ffffff;
    --b2b-accent-color:   #000000;
    --b2b-accent-hover:   #333333;
}

/* Reset table defaults */
.matrix-table {
    border-collapse: collapse;
    border-spacing: 0;
    width: 100%;
    table-layout: fixed;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Ensure the bulk order modal button works */
a.bulk-order-trigger {
    cursor: pointer;
    color: #000000 !important;
    text-decoration: underline !important;
    font-weight: 600;
}

/* Fix Add to Cart buttons - remove disabled cursor and fix positioning */
.single-product .single_add_to_cart_button,
.single-product .buy-now-button,
.single-product button[name="add-to-cart"],
.single-product button.add-to-cart-button,
.single-product .nasa-buy-now {
    cursor: pointer !important;
    vertical-align: middle !important;
    margin-bottom: 0 !important;
}

.single-product .single_add_to_cart_button:disabled,
.single-product .buy-now-button:disabled,
.single-product button[name="add-to-cart"]:disabled,
.single-product .nasa-buy-now:disabled {
    cursor: pointer !important;
    opacity: 1 !important;
}

/* When modal is open */
body.bulk-order-open {
    overflow: hidden !important;
}

body.bulk-order-open .bulk-order-popup {
    display: block !important;
}

/* Table Container */
.matrix-table-container {
    max-width: 100%;
    max-height: 600px;
    overflow-x: auto;
    overflow-y: auto;
    margin-top: 16px;
    margin-bottom: 20px;
    border: 1px solid #eaeeae;
    border-radius: 8px;
    background: #fff;
    position: relative;
    scroll-behavior: smooth;
}

/* ==== TABLE HEADER ==== */
.matrix-table-head {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #f5f5f5 !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Header Cells */
.matrix-table-th {
    padding: 12px 8px !important;
    text-align: center !important;
    font-weight: 700;
    color: #000000 !important;
    border-bottom: 2px solid #000000;
    font-size: 12px !important;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
    background: #f5f5f5 !important;
    position: sticky;
    top: 0;
    z-index: 100;
    min-width: 100px;
    vertical-align: top !important;
    height: 50px;
    box-sizing: border-box;
    border-top: none !important;
    padding-top: 14px !important;
}

/* Color Column Header */
.matrix-table th.color-column {
    text-align: left !important;
    padding: 10px 12px !important;
    position: sticky;
    left: 0;
    top: 0;
    z-index: 150;
    background: #f5f5f5 !important;
    border-right: 2px solid #e0e0e0;
    min-width: 120px;
    max-width: 120px;
    font-weight: 700;
    color: #000000 !important;
    height: 50px;
    line-height: 1.2;
    display: table-cell !important;
    border-top: none !important;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
    vertical-align: middle !important;
}

/* Corner label showing both row and column attribute names */
.corner-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.corner-row-label {
    font-size: 11px;
    font-weight: 700;
    color: #000;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: block;
}

.corner-col-label {
    font-size: 10px;
    font-weight: 500;
    color: #777;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    display: block;
}

/* Ensure all table cells have same vertical alignment */
.matrix-table th,
.matrix-table td {
    vertical-align: middle !important;
    display: table-cell !important;
}

/* ==== TABLE BODY ==== */
.matrix-table tbody {
    background: #fff;
    position: relative;
}

/* Table Rows */
.matrix-table tr {
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s;
    display: table-row;
    height: 50px;
}

.matrix-table tr:hover {
    background-color: #fafafa;
}

/* ==== COLOR COLUMN ==== */
.color-column {
    min-width: 120px;
    max-width: 120px;
    background: #fafafa;
    border-right: 2px solid #e0e0e0;
    position: sticky;
    left: 0;
    z-index: 15;
    vertical-align: middle !important;
    padding: 0 !important;
    height: 100px;
}

.color-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 8px !important;
    min-height: 100px;
    height: 100%;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
}

.color-image {
    width: 50px !important;
    height: 50px !important;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    background: #f5f5f5;
    flex-shrink: 0;
}

.color-name {
    font-weight: 600;
    color: #333;
    font-size: 10px !important;
    line-height: 1.3;
    word-break: break-word;
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    width: 100%;
    text-align: center;
    margin: 0;
    padding: 0;
}

/* ==== QUANTITY CELLS ==== */
.qty-cell {
    min-width: 100px !important;
    max-width: 100px !important;
    padding: 8px 4px !important;
    text-align: center !important;
    vertical-align: middle !important;
    box-sizing: border-box;
    height: 100px;
}

.qty-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 6px;
    border-radius: 6px;
    background: #fff;
    border: 1px solid #e0e0e0;
    transition: all 0.2s;
    min-height: 85px;
    height: 100%;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

.qty-card:hover {
    border-color: #000000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Quantity Input */
.qty-input-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
}

/* Stepper wrapper */
.qty-stepper {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    gap: 0;
}

/* Stepper buttons */
.stepper-btn {
    width: 26px !important;
    height: 32px !important;
    min-width: 26px !important;
    flex-shrink: 0;
    background: #f0f0f0;
    border: 1px solid #000000;
    color: #000000;
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    padding: 0;
    user-select: none;
    box-sizing: border-box;
}

.stepper-btn:hover:not(:disabled) {
    background: #000000;
    color: #ffffff;
}

.stepper-btn:active:not(:disabled) {
    transform: scale(0.92);
}

.stepper-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.stepper-minus {
    border-radius: 6px 0 0 6px;
    border-right: none;
}

.stepper-plus {
    border-radius: 0 6px 6px 0;
    border-left: none;
}

.qty-input {
    width: 42px !important;
    height: 32px !important;
    text-align: center !important;
    border: 1px solid #000000 !important;
    border-radius: 0;
    font-size: 13px !important;
    font-weight: 700;
    color: #000000;
    background: #fff;
    padding: 0 3px;
    -moz-appearance: textfield;
    display: block !important;
    margin: 0 !important;
    box-sizing: border-box;
    transition: all 0.2s;
    flex-shrink: 0;
}

.qty-input:focus {
    outline: none;
    border-color: #000000 !important;
    box-shadow: none !important;
    z-index: 1;
    position: relative;
}

/* Hide spinner arrows */
.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Price Display */
.price-display {
    font-size: 11px !important;
    font-weight: 600;
    color: #444;
    margin-top: 3px;
    text-align: center !important;
    display: block !important;
    width: 100%;
    line-height: 1.2;
    white-space: nowrap;
    overflow: visible;
    word-break: keep-all;
    min-height: 16px;
    padding: 0 2px;
}

/* ===== BOTTOM HEADER ROW ===== */
.bottom-header-row {
    background: #f5f5f5 !important;
    border-top: 2px solid #000000;
    position: sticky;
    bottom: 0;
    z-index: 90;
    box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.05);
}

.bottom-header-cell {
    padding: 12px 8px !important;
    padding-top: 14px !important;
    font-size: 12px !important;
    text-transform: uppercase;
    font-weight: 700;
    color: #000000 !important;
    text-align: center !important;
    vertical-align: top !important;
    border-top: 2px solid #000000;
    background: #f5f5f5 !important;
    min-width: 100px;
    height: 50px;
    border-bottom: none !important;
    position: sticky;
    bottom: 0;
    z-index: 90;
}

.bottom-header-row .color-column {
    background: #f5f5f5 !important;
    text-align: left !important;
    padding: 10px 12px !important;
    font-weight: 700;
    color: #000000 !important;
    border-bottom: none !important;
    height: 50px;
    line-height: 1.2;
    position: sticky;
    left: 0;
    bottom: 0;
    z-index: 95;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
    vertical-align: middle !important;
}

/* ===== OUT OF STOCK STYLING ===== */
.qty-cell.out-of-stock .qty-card {
    opacity: 0.6;
    background: #f9f9f9;
    border-color: #ddd;
}

.qty-cell.out-of-stock .qty-input {
    border-color: #ccc !important;
    color: #999;
    background: #f5f5f5;
}

.qty-cell.out-of-stock .price-display {
    color: #999;
}

/* ===== POPUP STYLES ===== */
.bulk-order-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    display: none;
}

.bulk-order-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(2px);
}

.bulk-order-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 95%;
    max-width: 1200px;
    max-height: 90vh;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
}

.bulk-order-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    background: var(--b2b-header-bg, #000000);
    color: var(--b2b-header-text, #ffffff);
    flex-shrink: 0;
}

/* Logo in modal header */
.bulk-order-logo {
    height: 36px;
    max-width: 160px;
    width: auto;
    object-fit: contain;
    margin-right: 12px;
    vertical-align: middle;
    flex-shrink: 0;
}

.bulk-order-header-left {
    display: flex;
    align-items: center;
    gap: 0;
    min-width: 0;
}

.bulk-order-header h3 {
    margin: 0;
    font-size: 24px;
    color: var(--b2b-header-text, #ffffff);
    font-weight: 700;
    letter-spacing: 0.5px;
}

.bulk-order-close {
    background: none;
    border: none;
    color: var(--b2b-header-text, #ffffff);
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.bulk-order-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.bulk-order-body {
    padding: 30px;
    overflow-y: auto;
    max-height: calc(90vh - 140px);
    flex-grow: 1;
}

.bulk-order-info {
    display: flex;
    gap: 20px;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.product-thumbnail {
    flex-shrink: 0;
}

.product-thumbnail img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #eee;
    background: #f5f5f5;
}

.product-details {
    flex-grow: 1;
}

.product-title {
    margin: 0 0 8px 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
    line-height: 1.3;
}

.product-sku {
    margin: 0;
    color: #666;
    font-size: 14px;
    font-weight: 500;
}

.bulk-order-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    gap: 20px;
}

.totals-display {
    display: flex;
    gap: 30px;
    flex-grow: 1;
}

.total-products,
.total-amount {
    display: flex;
    flex-direction: column;
    min-width: 120px;
}

.total-label {
    font-size: 14px;
    color: #666;
    margin-bottom: 5px;
    font-weight: 500;
}

.total-value {
    font-size: 24px;
    font-weight: 700;
    color: #000000;
    line-height: 1.2;
}

.footer-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.clear-all-btn {
    background: transparent;
    color: #666;
    border: 1px solid #ccc;
    padding: 14px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.clear-all-btn:hover {
    background: #f5f5f5;
    border-color: #999;
    color: #333;
}

.export-csv-btn {
    background: transparent;
    color: #1a6b3a;
    border: 1px solid #1a6b3a;
    padding: 14px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.export-csv-btn:hover:not(:disabled) {
    background: #1a6b3a;
    color: #fff;
}

.export-csv-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.print-order-btn {
    background: transparent;
    color: #555;
    border: 1px solid #aaa;
    padding: 14px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.print-order-btn:hover:not(:disabled) {
    background: #f5f5f5;
    border-color: #555;
    color: #000;
}

.print-order-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.add-all-btn {
    background: var(--b2b-accent-color, #000000);
    color: white;
    border: none;
    padding: 14px 32px;
    font-size: 15px;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
    min-width: 160px;
    letter-spacing: 0.5px;
}

.add-all-btn:hover:not(:disabled) {
    background: var(--b2b-accent-hover, #333333);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.add-all-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* Loading Spinner */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--b2b-accent-color, #000000);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

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

/* Notification */
.bulk-notification {
    position: fixed;
    top: 30px;
    right: 30px;
    padding: 16px 24px;
    background: #28a745;
    color: white;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    z-index: 100000;
    max-width: 400px;
    font-size: 14px;
    font-weight: 500;
    animation: slideIn 0.3s ease;
}

.bulk-notification.error {
    background: #dc3545;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Scrollbar Styling */
.matrix-table-container::-webkit-scrollbar,
.bulk-order-body::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.matrix-table-container::-webkit-scrollbar-track,
.bulk-order-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.matrix-table-container::-webkit-scrollbar-thumb,
.bulk-order-body::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.matrix-table-container::-webkit-scrollbar-thumb:hover,
.bulk-order-body::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Force Hide WooCommerce Notices */
body.single-product .woocommerce-error,
body.single-product .woocommerce-message,
body.single-product .woocommerce-info,
body.single-product .woocommerce-notices-wrapper {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    opacity: 0 !important;
    position: absolute !important;
    z-index: -9999 !important;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    /* Modal container - use dvh to account for mobile browser chrome */
    .bulk-order-container {
        width: 100%;
        max-width: 100%;
        border-radius: 0;
        top: 0;
        left: 0;
        transform: none;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
    }

    /* Modal header */
    .bulk-order-header {
        padding: 14px 16px;
    }

    .bulk-order-header h3 {
        font-size: 18px;
    }

    .bulk-order-logo {
        height: 28px;
        max-width: 120px;
        margin-right: 8px;
    }

    .bulk-order-close {
        font-size: 26px;
        width: 34px;
        height: 34px;
    }

    /* Modal body - scrollable, footer is positioned absolutely */
    .bulk-order-body {
        padding: 16px;
        padding-bottom: 180px;
        max-height: none;
        overflow-y: auto;
        flex: 1 1 0;
        min-height: 0;
    }

    /* Product info */
    .bulk-order-info {
        gap: 12px;
        margin-bottom: 16px;
        padding-bottom: 14px;
        flex-shrink: 0;
    }

    .product-thumbnail img {
        width: 60px;
        height: 60px;
    }

    .product-title {
        font-size: 15px;
        margin-bottom: 4px;
    }

    .product-sku {
        font-size: 12px;
    }

    /* Matrix - scrolls within its own container */
    .matrix-table-container {
        border-radius: 6px;
        border-width: 1px;
        max-height: 45vh;
        overflow-y: auto;
    }

    .color-column {
        min-width: 100px !important;
        max-width: 100px !important;
    }

    .color-cell {
        flex-direction: column;
        text-align: center;
        gap: 6px;
        padding: 10px 6px !important;
        min-height: 90px;
        height: 90px;
    }

    .color-image {
        width: 40px !important;
        height: 40px !important;
    }

    .color-name {
        font-size: 9px !important;
    }

    .qty-cell {
        min-width: 85px !important;
        max-width: 85px !important;
        padding: 6px 2px !important;
        height: 90px;
    }

    .qty-card {
        min-height: 75px;
        height: 100%;
        padding: 6px 2px;
        gap: 4px;
    }

    .qty-stepper {
        flex-direction: column;
        width: auto;
        max-width: none;
        align-items: center;
    }

    .stepper-btn {
        width: 42px !important;
        min-width: 42px !important;
        height: 20px !important;
        font-size: 12px;
        border: 1px solid #000000 !important;
    }

    .stepper-minus {
        border-radius: 0 0 6px 6px !important;
        border-top: none !important;
        border-right: 1px solid #000000 !important;
        border-left: 1px solid #000000 !important;
        order: 2;
    }

    .stepper-plus {
        border-radius: 6px 6px 0 0 !important;
        border-bottom: none !important;
        border-right: 1px solid #000000 !important;
        border-left: 1px solid #000000 !important;
        order: 0;
    }

    .qty-input {
        width: 42px !important;
        height: 24px !important;
        font-size: 12px !important;
        border-radius: 0 !important;
        order: 1;
    }

    .price-display {
        font-size: 8px !important;
    }

    .moq-badge,
    .stock-badge {
        font-size: 7px;
        padding: 1px 4px;
    }

    .matrix-table th,
    .matrix-table-th,
    .bottom-header-cell {
        font-size: 11px !important;
        padding: 10px 6px !important;
        min-width: 85px;
        height: 40px;
    }

    .matrix-table th.color-column,
    .bottom-header-row .color-column {
        padding-left: 12px !important;
        height: 40px;
    }

    /* Footer - absolutely positioned at bottom of container */
    .bulk-order-footer {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        display: flex;
        flex-direction: column;
        gap: 14px;
        margin-top: 0;
        padding: 14px 16px;
        padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
        background: #fff;
        z-index: 50;
        border-top: 1px solid #eee;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
    }

    .totals-display {
        width: 100%;
        justify-content: space-between;
    }

    .total-value {
        font-size: 20px;
    }

    .footer-actions {
        width: 100%;
        display: grid !important;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 8px;
    }

    .footer-actions button {
        min-width: 0;
        padding: 10px 6px;
        font-size: 12px;
        white-space: nowrap;
    }

    .add-all-btn {
        min-width: 0 !important;
        grid-column: 1 / -1;
        order: -1;
        padding: 14px 10px !important;
        font-size: 14px !important;
    }

    /* PO / Notes */
    .po-notes-bar {
        padding: 10px 12px;
        flex-shrink: 0;
    }

    /* Search bar */
    .matrix-search-bar {
        flex-shrink: 0;
    }

    /* Templates */
    .template-bar {
        gap: 8px;
        flex-shrink: 0;
    }

    /* Tier pricing */
    .tier-pricing-bar {
        flex-shrink: 0;
    }

    /* Filter bar */
    .attribute-filter-bar {
        flex-shrink: 0;
    }

    .template-save-btn,
    .template-load-btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    .template-dropdown {
        min-width: 240px;
    }

    /* Tier pricing */
    .tier-pricing-bar {
        padding: 10px 12px;
        gap: 8px;
        font-size: 11px;
    }

    /* Search bar */
    .matrix-search-input {
        height: 34px;
        font-size: 12px;
    }
}

/* Extra Small Screens */
@media (max-width: 480px) {
    .bulk-order-body {
        padding: 12px;
    }

    .bulk-order-header {
        padding: 12px 14px;
    }

    .bulk-order-header h3 {
        font-size: 16px;
    }

    .bulk-order-logo {
        height: 24px;
        max-width: 100px;
    }

    .bulk-order-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .product-title {
        font-size: 14px;
    }

    .matrix-table-container {
        max-height: 40vh;
    }

    .color-column {
        min-width: 90px !important;
        max-width: 90px !important;
    }

    .color-cell {
        padding: 8px 6px !important;
        min-height: 85px;
        height: 85px;
    }

    .color-name {
        font-size: 8px !important;
    }

    .qty-cell {
        min-width: 76px !important;
        max-width: 76px !important;
        padding: 4px 2px !important;
        height: 85px;
    }

    .stepper-btn {
        width: 38px !important;
        min-width: 38px !important;
        height: 18px !important;
        font-size: 11px;
    }

    .qty-input {
        width: 38px !important;
        height: 22px !important;
        font-size: 11px !important;
    }

    .price-display {
        font-size: 7px !important;
    }

    .moq-badge,
    .stock-badge {
        font-size: 6px;
        padding: 1px 3px;
    }

    .matrix-table th,
    .matrix-table-th,
    .bottom-header-cell {
        font-size: 10px !important;
        min-width: 76px;
        height: 35px;
    }

    .footer-actions {
        grid-template-columns: 1fr 1fr 1fr;
        gap: 6px;
    }

    .footer-actions button {
        padding: 10px 4px;
        font-size: 11px;
    }

    .total-label {
        font-size: 12px;
    }

    .total-value {
        font-size: 18px;
    }

    .template-save-form {
        flex-direction: column;
        width: 100%;
    }

    .template-name-input {
        width: 100%;
    }
}

/* Accessibility */
.qty-input:focus-visible {
    outline: 2px solid #000000;
    outline-offset: 2px;
}

.add-all-btn:focus-visible {
    outline: 2px solid #000000;
    outline-offset: 2px;
}

.bulk-order-close:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .matrix-table th {
        border-bottom: 3px solid #000000;
    }

    .qty-input {
        border: 2px solid #000000 !important;
    }

    .add-all-btn {
        border: 2px solid transparent;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .bulk-order-popup,
    .bulk-order-container,
    .bulk-notification,
    .qty-card,
    .add-all-btn {
        transition: none !important;
        animation: none !important;
    }
}

/* ===== QUICK ROW SEARCH ===== */
.matrix-search-bar {
    margin-top: 4px;
    margin-bottom: 16px;
    padding: 14px 0 16px;
    border-bottom: 1px solid #ebebeb;
}

.matrix-search-field {
    position: relative;
}

.matrix-search-input {
    width: 100%;
    height: 36px;
    padding: 0 32px 0 10px;
    font-size: 13px;
    color: #333;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 6px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}

.matrix-search-input:focus {
    border-color: #000;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.07);
}

.matrix-search-input::placeholder {
    color: #bbb;
}

.matrix-search-clear {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 16px;
    line-height: 1;
    color: #aaa;
    cursor: pointer;
    padding: 0;
    transition: color 0.1s;
}

.matrix-search-clear:hover {
    color: #333;
}

/* ===== PO NUMBER / ORDER NOTES BAR ===== */
.po-notes-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 16px;
    margin-bottom: 0;
    padding: 12px 16px;
    background: #fafafa;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
}

.po-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 0 0 auto;
}

.po-field-notes {
    flex: 1 1 200px;
}

.po-field-label {
    font-size: 11px;
    font-weight: 700;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
    padding: 0;
    display: block;
}

.po-number-input,
.po-notes-input {
    height: 34px;
    padding: 0 10px;
    font-size: 13px;
    color: #000;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 6px;
    outline: none;
    transition: border-color 0.15s;
    box-sizing: border-box;
    min-width: 0;
}

.po-number-input {
    width: 200px;
}

.po-notes-input {
    width: 100%;
}

.po-number-input:focus,
.po-notes-input:focus {
    border-color: #000;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.08);
}

@media (max-width: 600px) {
    .po-notes-bar {
        flex-direction: column;
    }

    .po-number-input {
        width: 100%;
    }
}

/* ===== VARIATION IMAGE ZOOM ===== */
img.color-image {
    cursor: zoom-in;
}

.image-zoom-tooltip {
    position: fixed;
    z-index: 999999;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    width: 220px;
    height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.image-zoom-tooltip.visible {
    opacity: 1;
}

.zoom-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}

/* ===== ORDER TEMPLATES ===== */
.template-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    margin-bottom: 0;
}

.template-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.template-save-btn,
.template-load-btn {
    background: transparent;
    border: 1px solid #999;
    color: #444;
    padding: 7px 14px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.template-save-btn:hover,
.template-load-btn:hover:not(:disabled) {
    background: #f5f5f5;
    border-color: #555;
    color: #000;
}

.template-load-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.template-load-arrow {
    font-size: 9px;
    opacity: 0.7;
}

/* Save form */
.template-save-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.template-name-input {
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 13px;
    width: 220px;
    outline: none;
    transition: border-color 0.15s;
}

.template-name-input:focus {
    border-color: #000;
}

.template-save-confirm-btn {
    background: #000;
    color: #fff;
    border: none;
    padding: 7px 16px;
    font-size: 12px;
    font-weight: 700;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.template-save-confirm-btn:hover {
    background: #333;
}

.template-save-cancel-btn {
    background: transparent;
    color: #666;
    border: 1px solid #ccc;
    padding: 7px 14px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.template-save-cancel-btn:hover {
    border-color: #999;
    color: #333;
}

/* Load dropdown */
.template-load-wrap {
    position: relative;
}

.template-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 280px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    z-index: 1000;
    overflow: hidden;
}

.template-empty {
    padding: 14px 16px;
    font-size: 13px;
    color: #999;
    text-align: center;
}

.template-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid #f0f0f0;
    gap: 12px;
}

.template-item:last-child {
    border-bottom: none;
}

.template-item:hover {
    background: #fafafa;
}

.template-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.template-item-name {
    font-size: 13px;
    font-weight: 600;
    color: #222;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
}

.template-item-date {
    font-size: 10px;
    color: #999;
}

.template-item-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.template-apply-btn {
    background: #000;
    color: #fff;
    border: none;
    padding: 5px 12px;
    font-size: 11px;
    font-weight: 700;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}

.template-apply-btn:hover {
    background: #333;
}

.template-delete-btn {
    background: transparent;
    color: #cc0000;
    border: 1px solid #cc0000;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: all 0.15s;
}

.template-delete-btn:hover {
    background: #cc0000;
    color: #fff;
}

/* ===== ATTRIBUTE FILTER BAR (for 3+ attributes) ===== */
.attribute-filter-bar {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center !important;
    gap: 16px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: #f5f5f5;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.filter-item {
    display: flex !important;
    align-items: center !important;
    gap: 8px;
    margin: 0 !important;
    padding: 0 !important;
}

.filter-label {
    display: flex !important;
    align-items: center !important;
    height: 34px !important;
    font-size: 12px;
    font-weight: 700;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
    box-sizing: border-box !important;
    float: none !important;
}

.filter-select {
    height: 34px !important;
    padding: 0 28px 0 10px !important;
    font-size: 13px;
    font-weight: 600;
    color: #000;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23333'/%3E%3C/svg%3E") no-repeat right 10px center;
    border: 1px solid #000;
    border-radius: 6px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    min-width: 110px;
    margin: 0 !important;
    box-sizing: border-box !important;
}

.filter-select:focus {
    border-color: #000;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.1);
}

.filter-select:hover {
    border-color: #333;
}

@media (max-width: 768px) {
    .attribute-filter-bar {
        gap: 12px;
        padding: 10px 12px;
    }

    .filter-label {
        font-size: 11px;
        height: 30px !important;
    }

    .filter-select {
        font-size: 12px;
        height: 30px;
        min-width: 90px;
    }
}

/* ===== STOCK LEVEL BADGES ===== */
.stock-badge {
    font-size: 9px;
    font-weight: 700;
    border-radius: 3px;
    padding: 2px 5px;
    line-height: 1.4;
    white-space: nowrap;
    display: inline-block;
    letter-spacing: 0.2px;
    text-transform: uppercase;
}

.stock-low {
    color: #7a4500;
    background: #fff3cd;
    border: 1px solid #ffc107;
}

.stock-out {
    color: #721c24;
    background: #f8d7da;
    border: 1px solid #dc3545;
}

/* ===== MOQ (MINIMUM ORDER QUANTITY) STYLES ===== */
.moq-badge {
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    background: #555;
    border-radius: 3px;
    padding: 2px 5px;
    line-height: 1.4;
    white-space: nowrap;
    display: inline-block;
    letter-spacing: 0.2px;
}

/* Flash highlight when quantity snaps to MOQ */
@keyframes moqSnap {
    0%   { box-shadow: 0 0 0 3px rgba(255, 152, 0, 0.6); border-color: #ff9800; }
    100% { box-shadow: none; border-color: #000; }
}

.qty-input.moq-snapped {
    animation: moqSnap 0.8s ease forwards;
}

/* Red border on inputs violating MOQ */
.qty-input.moq-violation {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.25) !important;
}

/* ===== TIERED PRICING ===== */
.tier-pricing-bar {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding: 14px 16px;
    background: #fffbf0;
    border: 1px solid #f0c040;
    border-radius: 7px;
    font-size: 12px;
}

.tier-bar-label {
    font-weight: 700;
    color: #7a5200;
    white-space: nowrap;
    margin-right: 6px;
    display: inline-flex;
    align-items: center;
    line-height: 1;
    vertical-align: middle;
}

.tier-badge {
    background: #fff8e1;
    border: 1px solid #f0c040;
    color: #7a5200;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 11px;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    margin: 2px 4px 2px 0;
}

.tier-badge strong {
    font-weight: 700;
}

/* Price display when a tier discount is active */
.price-display.tier-active {
    color: #1a6b3a;
}

.price-display .tier-base-price {
    font-size: 9px;
    color: #aaa;
    font-weight: 400;
    margin-left: 2px;
    text-decoration: line-through;
}

/* Print Styles */
@media print {
    .bulk-order-popup,
    .bulk-order-overlay {
        display: none !important;
    }
}
