/* WC Item Status Responsive Styles */

/* Safety Center B2B specific product table fixes */
body.woocommerce div.product form.cart table.variations td.qty,
body.woocommerce div.product form.cart table.variations th.qty,
body.woocommerce div.product form.cart table td.qty,
body.woocommerce div.product form.cart table th.qty {
    width: 70px !important;
    min-width: 70px !important;
    max-width: 70px !important;
}

body.woocommerce .quantity .qty {
    width: 3.631em !important;
    text-align: center;
}

/* Specific fixes for the MONTE SIP SRC product and similar products with variation tables */
.product-type-variable .variations td.qty,
.product-type-variable .variations th.qty,
.qty-column,
table.variations td:last-child,
table.variations th:last-child,
.woocommerce div.product form.cart table td:last-child,
.woocommerce div.product form.cart table th:last-child {
    width: 70px !important;
    min-width: 70px !important;
    max-width: 70px !important;
    text-align: center !important;
}

/* Force table width to stay within container */
.woocommerce div.product form.cart table {
    width: 100% !important;
    table-layout: fixed !important;
    max-width: 100% !important;
}

/* Make the variation select inputs and price column not too wide */
.woocommerce div.product form.cart .variations select {
    max-width: 100%;
}

.woocommerce div.product form.cart table td:nth-child(3),
.woocommerce div.product form.cart table th:nth-child(3) {
    width: 110px !important;
}

/* Enforce quantity column size with !important to override other styles */
table.variations td.qty input,
table.variations td.qty input.qty,
.woocommerce .quantity input.qty {
    width: 3.5em !important;
    min-width: 3.5em !important;
}

/* Make the qty column slightly smaller at specific widths */
@media screen and (max-width: 1071px) and (min-width: 700px) {
    /* Make quantity column narrower at problematic width range */
    body.woocommerce div.product form.cart table td.qty,
    body.woocommerce div.product form.cart table th.qty,
    .woocommerce div.product form.cart table td:last-child,
    .woocommerce div.product form.cart table th:last-child,
    .qty-column {
        width: 50px !important;
        min-width: 50px !important;
        max-width: 50px !important;
        padding: 3px !important;
    }
    
    /* Make quantity inputs smaller */
    body.woocommerce .quantity .qty,
    .woocommerce .quantity .qty,
    .woocommerce div.product form.cart .quantity input {
        width: 2.5em !important;
        min-width: 2.5em !important;
        padding-left: 2px !important;
        padding-right: 2px !important;
    }
    
    /* Make variation column widths optimal */
    .woocommerce div.product form.cart .variations td.label,
    .woocommerce div.product form.cart .variations th.label {
        width: 80px !important;
    }
    
    .woocommerce div.product form.cart .variations td.value,
    .woocommerce div.product form.cart .variations th.value {
        width: auto !important;
    }
    
    /* Safety Center specific table */
    .woocommerce table.variations td.sku,
    .woocommerce table.variations th.sku {
        width: 110px !important;
        max-width: 110px !important;
    }
    
    .woocommerce table.variations td.price,
    .woocommerce table.variations th.price {
        width: 85px !important;
        max-width: 85px !important;
    }
}

/* Hide SKU column below 1150px */
@media screen and (max-width: 1150px) {
    /* Hide SKU column completely */
    .woocommerce div.product form.cart table td.sku,
    .woocommerce div.product form.cart table th.sku,
    table.variations td:nth-child(2),
    table.variations th:nth-child(2),
    .woocommerce.single-product table.variations td:nth-child(2),
    .woocommerce.single-product table.variations th:nth-child(2),
    .woocommerce .woocommerce-variation-add-to-cart td.sku,
    .woocommerce .woocommerce-variation-add-to-cart th.sku,
    .optimized-variations-table td:nth-child(2),
    .optimized-variations-table th:nth-child(2) {
        display: none !important;
    }
    
    /* Redistribute space to other columns */
    .woocommerce div.product form.cart table td.price,
    .woocommerce div.product form.cart table th.price,
    table.variations td:nth-child(3),
    table.variations th:nth-child(3) {
        width: auto !important;
    }
    
    /* Adjust column spacing now that SKU is hidden */
    .woocommerce div.product form.cart table,
    table.variations,
    .optimized-variations-table {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    /* Make variation column wider */
    .woocommerce div.product form.cart table td:first-child,
    .woocommerce div.product form.cart table th:first-child,
    table.variations td:first-child,
    table.variations th:first-child {
        width: auto !important;
        min-width: 80px !important;
    }
    
    /* Allow price column to take more space */
    .woocommerce div.product form.cart table td.price,
    .woocommerce div.product form.cart table th.price,
    table.variations td:nth-child(3),
    table.variations th:nth-child(3) {
        width: auto !important;
        min-width: 90px !important;
        text-align: right !important;
    }
    
    /* Keep qty column compact but visible */
    .woocommerce div.product form.cart table td.qty,
    .woocommerce div.product form.cart table th.qty,
    table.variations td:last-child,
    table.variations th:last-child {
        width: 60px !important;
        min-width: 60px !important;
        max-width: 60px !important;
        text-align: center !important;
        padding: 4px !important;
    }
}

/* Specific fix for the exact table shown in the screenshot at 1071x878 */
@media screen and (width: 1071px), screen and (width: 878px), screen and (max-width: 1071px) and (min-width: 878px) {
    /* Target the exact table structure in the screenshot */
    .woocommerce.single-product table.variations td.qty,
    .woocommerce.single-product table.variations th.qty,
    table.variations td:last-child,
    table.variations th:last-child {
        width: 50px !important;
        min-width: 50px !important;
        max-width: 50px !important;
        padding: 3px !important;
    }
    
    /* Make the quantity inputs in exact width range more compact */
    .woocommerce.single-product .quantity .qty,
    .optimized-variations-table .quantity .qty {
        width: 2.5em !important;
        min-width: 2.5em !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        text-align: center !important;
    }
    
    /* Apply table-layout: fixed to prevent columns from expanding */
    .woocommerce.single-product form.cart table.variations,
    table.variations,
    .optimized-variations-table {
        table-layout: fixed !important;
        width: 100% !important;
    }
}

/* Fix for product variation tables at all widths */
@media screen and (max-width: 1200px) {
    /* General responsive table improvements */
    .woocommerce div.product form.cart table,
    .woocommerce div.product form.cart .variations,
    .woocommerce table.shop_table,
    .woocommerce-page table.shop_table {
        display: table !important;
        overflow-x: visible !important;
        max-width: 100% !important;
        width: 100% !important;
    }
    
    /* Ensure proper cell alignment and sizing */
    .woocommerce div.product form.cart .variations td,
    .woocommerce div.product form.cart .variations th,
    .woocommerce table.shop_table td,
    .woocommerce table.shop_table th,
    .woocommerce-page table.shop_table td,
    .woocommerce-page table.shop_table th {
        vertical-align: middle !important;
        padding: 8px 5px !important;
    }
    
    /* Add horizontal scrolling for very small screens as a fallback */
    .woocommerce-page .product-quantity-wrapper {
        overflow-x: auto !important;
        max-width: 100% !important;
        padding-bottom: 10px !important;
    }
}

/* Fix for product variation tables at specific widths */
@media screen and (max-width: 1071px) and (min-width: 700px) {
    /* Product variation table fixes */
    table.variations,
    .woocommerce-variation-add-to-cart,
    form.cart table,
    .woocommerce div.product form.cart table {
        width: 100% !important;
        max-width: 100% !important;
        table-layout: fixed !important;
    }
    
    /* Make sure all columns fit */
    .woocommerce div.product form.cart table td,
    .woocommerce div.product form.cart table th {
        padding: 5px !important;
        word-break: break-word;
    }
    
    /* Fix quantity column specifically */
    .woocommerce div.product form.cart td.qty,
    .woocommerce div.product form.cart th.qty {
        width: 80px !important;
    }
    
    /* Make quantity inputs narrower but still usable */
    .woocommerce .quantity .qty {
        width: 3em !important;
        min-width: 3em !important;
    }
    
    /* SKU column can be narrower */
    .woocommerce div.product form.cart td.sku,
    .woocommerce div.product form.cart th.sku {
        width: 110px !important;
    }
}

/* Base styles for all screens */
.wcis-item-status-fields {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Orientation-specific classes added by JS */
.wcis-landscape {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
}

.wcis-portrait {
    flex-direction: column !important;
}

/* Add proper padding on admin pages */
body.wp-admin .wcis-item-status-fields {
    padding: 10px 5px;
}

/* Status select field */
.wcis-item-status-fields label {
    margin-bottom: 8px;
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
}

.wcis-item-status-fields .wcis-status-select {
    width: 100%;
    min-width: 200px;
    max-width: 100%;
}

/* Custom status text field */
.wcis-custom-status-label {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.wcis-custom-status-input {
    width: 100%;
    min-width: 200px !important;
    max-width: 100%;
}

/* Bulk Stock setup page */
.wcis-bulk-container {
    max-width: 100%;
    box-sizing: border-box;
    padding: 15px 10px;
}

.wcis-bulk-description {
    margin-bottom: 20px;
    max-width: 800px;
}

.wcis-bulk-controls {
    margin-bottom: 15px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 15px;
}

#wcis-bulk-status {
    padding: 5px 10px;
    border-radius: 3px;
    display: inline-block;
    min-height: 20px;
    min-width: 180px;
    font-weight: 500;
}

.wcis-bulk-log {
    width: 100%;
    max-width: 100%;
    margin-top: 12px;
    max-height: 260px;
    overflow: auto;
    background: #fff;
    padding: 12px;
    border: 1px solid #ccd0d4;
    border-radius: 3px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Responsive adjustments for the bulk tool */
@media screen and (max-width: 782px) {
    .wcis-bulk-container h1 {
        font-size: 22px;
        margin-bottom: 15px;
    }
    
    .wcis-bulk-description p {
        font-size: 14px;
    }
    
    .wcis-bulk-controls {
        flex-direction: column;
        align-items: flex-start;
    }
    
    #wcis-bulk-status {
        margin-top: 10px;
        padding: 8px;
        width: 100%;
        box-sizing: border-box;
    }
}

/* Responsive adjustments for different screen sizes */
@media screen and (max-width: 1200px) {
    .wcis-item-status-fields {
        flex-direction: column;
    }
    
    .wcis-item-status-fields label {
        width: 100%;
    }
    
    .wcis-status-select,
    .wcis-custom-status-input {
        width: 100%;
    }
}

/* Tablet portrait mode */
@media screen and (max-width: 768px) {
    .wcis-item-status-fields {
        padding: 5px 0;
        flex-direction: column;
    }
    
    .wcis-item-status-fields strong {
        margin-bottom: 8px;
        display: block;
        width: 100%;
    }
    
    /* Force full width */
    .wcis-item-status-fields label {
        width: 100%;
        box-sizing: border-box;
    }
    
    /* Class added by JS for mobile layouts */
    .wcis-mobile-layout label {
        margin-bottom: 12px;
    }
}

/* Tablet landscape mode */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    .wcis-item-status-fields {
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: flex-start;
        padding-right: 10px;
    }
    
    .wcis-item-status-fields strong {
        flex-basis: 100%;
        margin-bottom: 10px;
        font-size: 14px;
    }
    
    .wcis-item-status-fields label:first-of-type {
        margin-right: 10px;
        min-width: 220px;
        flex: 0 0 auto;
    }
    
    .wcis-item-status-fields label:last-of-type {
        flex: 1 1 auto;
    }
    
    /* Improve touch targets for dropdowns */
    .wcis-status-select {
        height: 36px;
    }
    
    /* Handle orientation changes */
    @media (orientation: landscape) {
        .wcis-item-status-fields {
            max-width: 100%;
            padding-right: 20px;
        }
    }
    
    /* Orientation-specific classes for tablets */
    .landscape-mode .wcis-item-status-fields {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
    }
    
    .portrait-mode .wcis-item-status-fields {
        display: flex;
        flex-direction: column;
    }
    
    .landscape-mode.wcis-bulk-container {
        padding-right: 15px;
    }
    
    .portrait-mode.wcis-bulk-container .wcis-bulk-controls {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .landscape-mode.wcis-bulk-container .wcis-bulk-controls {
        flex-direction: row;
    }
    
    /* Make sure everything fits in both orientations */
    .portrait-mode input, 
    .portrait-mode select {
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
    }
}

/* Make sure inputs are touch-friendly on tablets */
@media (hover: none) and (pointer: coarse) {
    .wcis-status-select,
    .wcis-custom-status-input,
    #wcis-run-bulk {
        min-height: 44px; /* Larger touch target */
        padding: 8px;
        font-size: 16px; /* Prevent iOS zoom on focus */
    }
    
    /* Improve tap targets for selects */
    select.wcis-status-select {
        padding-right: 30px; /* Space for dropdown arrow */
    }
    
    /* Better spacing in both orientations */
    @media (orientation: portrait) {
        .wcis-item-status-fields {
            padding: 10px 5px;
        }
    }
    
    @media (orientation: landscape) {
        .wcis-item-status-fields {
            padding: 8px 10px 8px 5px;
        }
    }
    
    /* Fix for iOS and Android zooming when focusing on inputs */
    .wcis-status-select,
    .wcis-custom-status-input {
        max-height: none;
    }
    
    /* Improved touch area for buttons */
    #wcis-run-bulk,
    .button,
    .button-primary {
        min-width: 100px;
    }
    
    /* Optimizations for WooCommerce order page tables */
    .touch-optimized {
        min-height: 44px !important;
        font-size: 16px !important;
    }
    
    .tablet-optimized {
        padding: 10px 5px !important;
        margin-top: 12px !important;
    }
    
    /* Order items table optimizations */
    table.woocommerce_order_items td {
        padding: 10px 8px !important;
    }
    
    .woocommerce_order_items .landscape-view td {
        padding-right: 12px !important;
    }
}
