/**
 * EMCA Product Importer - Frontend Styles
 * Version: 2.0.0
 */

/* Table wrapper */
.emca-product-table-wrap {
    margin: 20px 0;
    overflow-x: auto;
}

/* Main product table */
.emca-product-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow: hidden;
    border: none;
}

.emca-product-table th,
.emca-product-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.emca-product-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #333;
    position: sticky;
    top: 0;
    white-space: nowrap;
}

.emca-product-table tbody tr:hover {
    background: #f8f9fa;
}

/* DESKTOP: Hide mobile-only cells */
.emca-product-table .mobile-only-cell {
    display: none;
}

/* Highlighted row */
.emca-product-table tbody tr.emca-row-highlight {
    background: #fff8e1 !important;
    animation: emca-highlight-pulse 2s ease-in-out;
}

.emca-product-table tbody tr.emca-row-highlight td {
    background: #fff8e1;
    border-top: 2px solid #ffc107;
    border-bottom: 2px solid #ffc107;
}

.emca-product-table tbody tr.emca-row-highlight td:first-child {
    border-left: 3px solid #ffc107;
}

.emca-product-table tbody tr.emca-row-highlight td:last-child {
    border-right: 3px solid #ffc107;
}

.emca-product-table tbody tr.emca-row-highlight .sku-cell {
    font-weight: bold;
    color: #856404;
}

@keyframes emca-highlight-pulse {
    0% { background: #ffc107; }
    50% { background: #fff8e1; }
    100% { background: #fff8e1; }
}

.emca-product-table tbody tr:last-child td {
    border-bottom: none;
}

/* SKU cell - DESKTOP */
.emca-product-table .sku-cell {
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

/* SKU main and meta structure - DESKTOP */
.emca-product-table .sku-main {
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

.emca-product-table .sku-meta {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed #e0e0e0;
}

.emca-product-table .sku-meta .meta-item {
    display: block;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 12px;
    font-weight: 400;
    color: #666;
    line-height: 1.5;
}

.emca-product-table .sku-meta .meta-item strong {
    color: #28a745;
}

/* Price cells */
.emca-product-table .price-cell {
    text-align: right;
    white-space: nowrap;
    font-weight: 500;
    color: #2271b1;
}

/* Stock cell */
.emca-product-table .stock-cell {
    text-align: center;
    font-weight: 500;
}

/* Cart cell */
.emca-product-table .cart-cell {
    white-space: nowrap;
}

/* Knurled Nut indicators */
.kn-yes {
    display: inline-block;
    background: #28a745;
    color: #fff;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
}

.kn-no {
    display: inline-block;
    background: #6c757d;
    color: #fff;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
}

/* Tooltip */
.emca-tooltip-cell {
    position: relative;
}

.emca-tooltip {
    display: inline-block;
    cursor: help;
    border-bottom: 1px dotted #666;
    position: relative;
    padding: 2px 6px;
    background: #f0f0f0;
    border-radius: 3px;
    font-weight: 500;
}

.emca-tooltip:hover {
    background: #e0e0e0;
}

.emca-tooltip::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 1000;
    margin-bottom: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.emca-tooltip::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #333;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 1001;
    margin-bottom: -4px;
}

.emca-tooltip:hover::after,
.emca-tooltip:hover::before {
    opacity: 1;
    visibility: visible;
}

/* Quantity wrapper */
.qty-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-right: 10px;
}

.qty-btn {
    width: 28px;
    height: 28px;
    border: 1px solid #ddd;
    background: #f8f9fa;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: #333;
}

.qty-btn:hover {
    background: #e9ecef;
    border-color: #ccc;
}

.qty-btn:active {
    background: #ddd;
}

.qty-input {
    width: 50px;
    height: 28px;
    text-align: center;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 14px;
    -moz-appearance: textfield;
}

.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.qty-input:focus {
    outline: none;
    border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
}

/* Add to cart button */
.add-to-cart-btn {
    padding: 8px 16px;
    background: #2271b1;
    color: #fff;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.add-to-cart-btn:hover {
    background: #135e96;
}

.add-to-cart-btn:active {
    transform: scale(0.98);
}

.add-to-cart-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.add-to-cart-btn.added {
    background: #28a745;
    color: #fff;
}

.add-to-cart-btn.adding {
    opacity: 0.7;
    pointer-events: none;
}

/* ============================================
   MOBILE RESPONSIVE - CARD LAYOUT
   ============================================ */
@media screen and (max-width: 768px) {
    
    .emca-product-table-wrap {
        margin: 15px 0;
        overflow: visible;
    }
    
    .emca-product-table {
        display: block !important;
        border: none !important;
        box-shadow: none !important;
        background: transparent !important;
    }
    
    .emca-product-table thead {
        display: none !important;
    }
    
    .emca-product-table tbody {
        display: block !important;
    }
    
    /* === CARD STYLE === */
    .emca-product-table tbody tr {
        display: block !important;
        background: #fff !important;
        border: 1px solid #e0e0e0 !important;
        border-radius: 10px !important;
        margin-bottom: 20px !important;
        padding: 0 !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06) !important;
        overflow: hidden !important;
    }
    
    .emca-product-table tbody tr:last-child {
        margin-bottom: 0 !important;
    }
    
    .emca-product-table tbody tr:hover {
        background: #fff !important;
    }
    
    /* Highlighted card */
    .emca-product-table tbody tr.emca-row-highlight {
        border: 2px solid #ffc107 !important;
        background: #fffef5 !important;
    }
    
    .emca-product-table tbody tr.emca-row-highlight td {
        background: transparent !important;
        border-top: none !important;
        border-left: none !important;
        border-right: none !important;
    }
    
    /* === ALL CELLS AS ROWS === */
    .emca-product-table tbody td {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 12px 20px !important;
        margin: 0 !important;
        border: none !important;
        border-bottom: 1px solid #f0f0f0 !important;
        text-align: right !important;
        font-size: 14px !important;
        color: #333 !important;
        background: #fff !important;
        box-sizing: border-box !important;
        width: 100% !important;
    }
    
    .emca-product-table tbody td::before {
        content: attr(data-label);
        font-weight: 500 !important;
        color: #00a0a0 !important;
        text-align: left !important;
        margin-right: 15px !important;
        flex-shrink: 0 !important;
    }
    
    /* MOBILE: Show mobile-only cells */
    .emca-product-table tbody td.mobile-only-cell {
        display: flex !important;
    }
    
    /* MOBILE: Hide the nested sku-meta (we use mobile-only-cell instead) */
    .emca-product-table tbody .sku-meta {
        display: none !important;
    }
    
    /* Part Number - header style */
    .emca-product-table tbody td.sku-cell {
        background: #f8f9fa !important;
        border-bottom: 1px solid #e0e0e0 !important;
        padding: 15px 20px !important;
        white-space: normal !important;
    }
    
    .emca-product-table tbody td.sku-cell::before {
        font-weight: 600 !important;
    }
    
    /* SKU main on mobile - just show the part number */
    .emca-product-table tbody .sku-main {
        font-family: 'Courier New', Courier, monospace !important;
        font-size: 15px !important;
        font-weight: 700 !important;
        color: #333 !important;
    }
    
    /* Price */
    .emca-product-table tbody td.price-cell {
        color: #00a0a0 !important;
        font-weight: 600 !important;
    }
    
    /* Stock */
    .emca-product-table tbody td.stock-cell {
        border-bottom: 1px solid #e0e0e0 !important;
    }
    
    /* Tooltip */
    .emca-product-table tbody td.emca-tooltip-cell .emca-tooltip {
        background: #e8f5e9 !important;
        color: #2e7d32 !important;
        font-weight: 600 !important;
        padding: 4px 10px !important;
        border-radius: 4px !important;
    }
    
    .emca-product-table tbody .emca-tooltip::after {
        bottom: auto;
        top: 100%;
        margin-top: 8px;
        margin-bottom: 0;
    }
    
    .emca-product-table tbody .emca-tooltip::before {
        bottom: auto;
        top: 100%;
        margin-top: -4px;
        margin-bottom: 0;
        border-top-color: transparent;
        border-bottom-color: #333;
    }
    
    /* ================================
       CART CELL
       ================================ */
    .emca-product-table tbody td.cart-cell {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 20px !important;
        background: #fff !important;
        border-top: none !important;
        border-bottom: none !important;
        margin-top: 40px !important;
        margin-bottom: 40px !important;
    }
    
    .emca-product-table tbody td.cart-cell::before {
        display: none !important;
        content: none !important;
    }
    
    .emca-product-table tbody td.cart-cell .qty-wrapper {
        display: flex !important;
        flex-direction: row !important;
        justify-content: center !important;
        align-items: center !important;
        margin-bottom: 15px !important;
        margin-right: 0 !important;
        gap: 10px !important;
        width: auto !important;
    }
    
    .emca-product-table tbody td.cart-cell .qty-btn {
        width: 44px !important;
        height: 44px !important;
        font-size: 20px !important;
        border-radius: 6px !important;
        background: #fff !important;
        border: 1px solid #ddd !important;
        color: #333 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    .emca-product-table tbody td.cart-cell .qty-input {
        width: 60px !important;
        height: 44px !important;
        font-size: 16px !important;
        text-align: center !important;
        border: 1px solid #ddd !important;
        border-radius: 6px !important;
        background: #fff !important;
        margin: 0 !important;
    }
    
    .emca-product-table tbody td.cart-cell .add-to-cart-btn {
        width: auto !important;
        min-width: 200px !important;
        max-width: 100% !important;
        padding: 14px 30px !important;
        font-size: 15px !important;
        font-weight: 600 !important;
        border-radius: 6px !important;
        background: #00a0a0 !important;
        color: #fff !important;
        border: none !important;
        display: block !important;
    }
    
    .emca-product-table tbody td.cart-cell .add-to-cart-btn:hover {
        background: #008b8b !important;
    }
    
    /* Badges - Mobile */
    .kn-yes {
        background: #00a0a0 !important;
        color: #fff !important;
        padding: 5px 14px !important;
        border-radius: 4px !important;
        font-size: 12px !important;
    }
    
    .kn-no {
        background: #6c757d !important;
        color: #fff !important;
        padding: 5px 14px !important;
        border-radius: 4px !important;
        font-size: 12px !important;
    }
}

/* Very small screens */
@media screen and (max-width: 480px) {
    .emca-product-table tbody tr {
        margin-bottom: 20px !important;
        border-radius: 8px !important;
    }
    
    .emca-product-table tbody td {
        padding: 15px 15px !important;
        font-size: 13px !important;
    }
    
    .emca-product-table tbody td::before {
        font-size: 13px !important;
    }
    
    .emca-product-table tbody td.sku-cell {
        padding: 14px 15px !important;
    }
    
    .emca-product-table tbody .sku-main {
        font-size: 14px !important;
    }
    
    .emca-product-table tbody td.cart-cell {
        padding: 18px 15px !important;
        margin-top: 40px !important;
        margin-bottom: 40px !important;
    }
    
    .emca-product-table tbody td.cart-cell .qty-btn {
        width: 40px !important;
        height: 40px !important;
        font-size: 18px !important;
    }
    
    .emca-product-table tbody td.cart-cell .qty-input {
        width: 55px !important;
        height: 40px !important;
        font-size: 15px !important;
    }
    
    .emca-product-table tbody td.cart-cell .add-to-cart-btn {
        padding: 12px 24px !important;
        font-size: 14px !important;
        min-width: 180px !important;
    }
}

/* Print styles */
@media print {
    .qty-wrapper,
    .add-to-cart-btn,
    .mobile-only-cell {
        display: none !important;
    }
    
    .emca-product-table {
        box-shadow: none;
        font-size: 10pt;
    }
    
    .emca-product-table th,
    .emca-product-table td {
        padding: 6px 8px;
        border: 1px solid #333;
    }
}

/* ============================================
   STOCK ERROR NOTIFICATION STYLES
   ============================================ */

#emca-notice-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    pointer-events: none;
}

.emca-notice {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 600px;
    width: 100%;
    padding: 16px 20px;
    margin-bottom: 10px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transform: translateY(-100%);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: auto;
}

.emca-notice.emca-notice-visible {
    transform: translateY(0);
    opacity: 1;
}

.emca-notice-error {
    border-left: 4px solid #dc3545;
    background: #fff5f5;
}

.emca-notice-success {
    border-left: 4px solid #28a745;
    background: #f0fff4;
}

.emca-notice-warning {
    border-left: 4px solid #ffc107;
    background: #fffbf0;
}

.emca-notice-info {
    border-left: 4px solid #17a2b8;
    background: #f0f9ff;
}

.emca-notice-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.emca-notice-message {
    flex: 1;
    font-size: 14px;
    line-height: 1.5;
    color: #333;
}

.emca-notice-error .emca-notice-message {
    color: #721c24;
}

.emca-notice-success .emca-notice-message {
    color: #155724;
}

.emca-notice-warning .emca-notice-message {
    color: #856404;
}

.emca-notice-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.emca-notice-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

/* ============================================
   CART INDICATOR STYLES
   ============================================ */

.stock-cell {
    position: relative;
}

.stock-cell .stock-qty {
    display: inline-block;
}

.stock-cell .cart-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    padding: 3px 8px;
    background: #e8f5e9;
    border-radius: 12px;
    font-size: 12px;
    color: #2e7d32;
    font-weight: 500;
}

.stock-cell .cart-indicator .cart-icon {
    font-size: 14px;
}

.stock-cell.has-cart-items .stock-qty {
    color: #666;
}

/* Max reached state */
.cart-cell.max-stock-reached {
    background: #f8f9fa;
}

.qty-wrapper.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.qty-wrapper.disabled .qty-btn {
    cursor: not-allowed;
    background: #eee;
}

.qty-wrapper.disabled .qty-input {
    background: #f5f5f5;
    color: #999;
}

/* Max reached button */
.add-to-cart-btn.max-reached {
    background: #28a745 !important;
    color: #fff !important;
    cursor: default !important;
    opacity: 1 !important;
}

.add-to-cart-btn.max-reached:hover {
    background: #28a745 !important;
}

/* Max hint tooltip */
.max-hint {
    position: absolute;
    background: #333;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    margin-left: 8px;
    white-space: nowrap;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Mobile adjustments for notification */
@media screen and (max-width: 768px) {
    #emca-notice-container {
        padding: 5px;
    }
    
    .emca-notice {
        padding: 14px 16px;
        gap: 10px;
        border-radius: 6px;
    }
    
    .emca-notice-icon {
        font-size: 20px;
    }
    
    .emca-notice-message {
        font-size: 13px;
    }
    
    .emca-notice-close {
        font-size: 20px;
        width: 26px;
        height: 26px;
    }
    
    /* Cart indicator on mobile */
    .stock-cell .cart-indicator {
        display: flex;
        margin-left: 0;
        margin-top: 6px;
    }
    
    /* Max reached button on mobile */
    .emca-product-table tbody td.cart-cell .add-to-cart-btn.max-reached {
        background: #28a745 !important;
        min-width: 180px !important;
    }
}