/**
 * NSM Product Search - Styles
 * Version: 1.2.0 - NSM Branded (Kadence Theme Compatible)
 * 
 * Brand Colors:
 * - Primary Red: #c6030b
 * - Hover Red: #a50209
 * - Navy Blue: #002868
 * - Dark Gray: #282828
 * 
 * CHANGELOG v1.2.0:
 * - Fixed dropdown appearing behind header rows in Kadence theme
 * - Dropdown now uses fixed positioning to escape overflow:hidden containers
 * - Added JavaScript positioning support for accurate dropdown placement
 */

/* ==============================================
   SEARCH WRAPPER
   ============================================== */

.nsm-product-search-wrapper {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ==============================================
   SEARCH FORM
   ============================================== */

.nsm-search-form {
    position: relative;
}

.nsm-search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: #fff;
    border: 2px solid #d1d5db;
    border-radius: 4px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.nsm-search-input-wrapper:focus-within {
    border-color: #c6030b;
    box-shadow: 0 0 0 3px rgba(198, 3, 11, 0.15);
}

/* ==============================================
   SEARCH INPUT
   ============================================== */

.nsm-search-input {
    flex: 1;
    padding: 12px 80px 12px 16px;
    border: none;
    outline: none;
    font-size: 15px;
    line-height: 1.4;
    color: #333;
    background: transparent;
    min-width: 0;
}

.nsm-search-input::placeholder {
    color: #9ca3af;
}

.nsm-search-input::-webkit-search-cancel-button,
.nsm-search-input::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
}

/* ==============================================
   CLEAR BUTTON
   ============================================== */

.nsm-search-clear {
    position: absolute;
    right: 48px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: #d1d5db;
    border-radius: 50%;
    cursor: pointer;
    color: #fff;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nsm-search-clear:hover {
    background: #9ca3af;
}

/* ==============================================
   SUBMIT BUTTON
   ============================================== */

.nsm-search-submit {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 44px;
    padding: 0;
    border: none;
    background: #c6030b;
    border-radius: 0 2px 2px 0;
    cursor: pointer;
    color: #fff;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nsm-search-submit:hover {
    background: #a50209;
}

.nsm-search-submit svg {
    width: 18px;
    height: 18px;
}

/* ==============================================
   DROPDOWN - FIXED POSITIONING TO ESCAPE HEADER
   ============================================== */

.nsm-search-dropdown {
    /* Use fixed positioning to escape any overflow:hidden containers */
    position: fixed !important;
    /* Position will be set dynamically by JavaScript */
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15), 0 4px 8px rgba(0, 0, 0, 0.1);
    /* Maximum z-index to ensure it's above everything */
    z-index: 2147483647 !important;
    max-height: 480px;
    overflow: hidden;
    /* Smooth appearance */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
}

.nsm-search-dropdown.nsm-dropdown-visible {
    opacity: 1;
    visibility: visible;
}

.nsm-search-results {
    max-height: 430px;
    overflow-y: auto;
    overflow-x: hidden;
}

.nsm-search-results::-webkit-scrollbar {
    width: 6px;
}

.nsm-search-results::-webkit-scrollbar-track {
    background: #f9fafb;
}

.nsm-search-results::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.nsm-search-results::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* ==============================================
   RESULT ITEMS
   ============================================== */

.nsm-search-result-item {
    display: flex;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.nsm-search-result-item:last-child {
    border-bottom: none;
}

.nsm-search-result-item:hover {
    background-color: #f9fafb;
}

.nsm-search-result-item.selected {
    background-color: #fef2f2;
    border-left: 3px solid #c6030b;
}

/* Product image */
.nsm-result-image {
    flex-shrink: 0;
    width: 55px;
    height: 55px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nsm-result-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Product content */
.nsm-result-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

/* Product title */
.nsm-result-title {
    font-size: 14px;
    font-weight: 600;
    color: #c6030b;
    line-height: 1.3;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.nsm-result-title mark {
    background: #fef3c7;
    color: inherit;
    font-weight: 700;
    padding: 0 2px;
    border-radius: 2px;
}

/* SKU */
.nsm-result-sku {
    font-size: 12px;
    font-weight: 700;
    color: #374151;
    margin: 0;
}

.nsm-result-sku mark {
    background: #fef3c7;
    color: inherit;
    font-weight: 700;
    padding: 0 2px;
    border-radius: 2px;
}

/* Variation attributes */
.nsm-result-attributes {
    font-size: 11px;
    color: #6b7280;
    margin: 0;
    font-style: italic;
}

.nsm-result-attributes mark {
    background: #fef3c7;
    color: inherit;
    font-weight: 600;
    padding: 0 2px;
    border-radius: 2px;
    font-style: normal;
}

/* Stock status */
.nsm-result-stock {
    font-size: 11px;
    font-weight: 500;
    margin: 0;
}

.nsm-result-stock.in-stock {
    color: #059669;
}

.nsm-result-stock.out-of-stock {
    color: #c6030b;
}

/* Description */
.nsm-result-description {
    font-size: 12px;
    color: #6b7280;
    line-height: 1.4;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}

/* Price */
.nsm-result-price {
    font-size: 14px;
    font-weight: 700;
    color: #c6030b;
    margin: 2px 0 0 0;
}

.nsm-result-price del {
    color: #9ca3af;
    font-weight: 400;
    font-size: 12px;
}

.nsm-result-price ins {
    text-decoration: none;
}

/* ==============================================
   VIEW ALL LINK
   ============================================== */

.nsm-search-view-all {
    padding: 10px 14px;
    text-align: center;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
}

.nsm-view-all-link {
    color: #c6030b;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color 0.2s ease;
}

.nsm-view-all-link:hover {
    color: #a50209;
}

/* ==============================================
   NO RESULTS / ERROR STATES
   ============================================== */

.nsm-no-results,
.nsm-search-error {
    padding: 32px 16px;
    text-align: center;
}

.nsm-no-results-icon,
.nsm-error-icon {
    font-size: 40px;
    margin-bottom: 10px;
    opacity: 0.5;
}

.nsm-no-results-text,
.nsm-error-text {
    font-size: 15px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}

.nsm-no-results-hint,
.nsm-error-hint {
    font-size: 13px;
    color: #6b7280;
}

/* ==============================================
   LOADING SPINNER
   ============================================== */

.nsm-search-loading {
    position: absolute;
    right: 52px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
}

.nsm-loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top: 2px solid #c6030b;
    border-radius: 50%;
    animation: nsm-spin 0.8s linear infinite;
}

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

/* ==============================================
   MOBILE RESPONSIVE
   ============================================== */

@media (max-width: 768px) {
    .nsm-product-search-wrapper {
        max-width: 100%;
    }
    
    .nsm-search-input {
        font-size: 16px; /* Prevent iOS zoom */
        padding: 12px 70px 12px 12px;
    }
    
    .nsm-search-dropdown {
        max-height: 70vh;
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
    }
    
    .nsm-search-results {
        max-height: calc(70vh - 50px);
    }
    
    .nsm-search-result-item {
        padding: 10px 12px;
        gap: 10px;
    }
    
    .nsm-result-image {
        width: 48px;
        height: 48px;
    }
    
    .nsm-result-title {
        font-size: 13px;
    }
    
    .nsm-result-price {
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .nsm-result-description {
        display: none;
    }
    
    .nsm-result-image {
        width: 44px;
        height: 44px;
    }
}

/* ==============================================
   ACCESSIBILITY
   ============================================== */

.nsm-search-input:focus {
    outline: none;
}

.nsm-search-result-item:focus {
    outline: 2px solid #c6030b;
    outline-offset: -2px;
}

/* ==============================================
   REDUCED MOTION
   ============================================== */

@media (prefers-reduced-motion: reduce) {
    .nsm-search-input-wrapper,
    .nsm-search-result-item,
    .nsm-search-clear,
    .nsm-search-submit,
    .nsm-view-all-link,
    .nsm-search-dropdown {
        transition: none;
    }
    
    .nsm-loading-spinner {
        animation: none;
        border-top-color: #c6030b;
    }
}