/* Instant WooCommerce Search Styles */

/* CSS Custom Properties for Dynamic Styling */
.iws-search-container {
    --iws-form-width: 100%;
    --iws-form-height: 50px;
    --iws-form-border-radius: 25px;
    --iws-form-border-color: #e0e0e0;
    --iws-form-border-width: 2px;
    --iws-form-bg-color: #ffffff;
    --iws-input-text-color: #333333;
    --iws-placeholder-color: #999999;
    --iws-icon-color: #666666;
    --iws-icon-size: 20px;
    --iws-button-bg-color: #0073aa;
    --iws-button-hover-bg-color: #005177;
    --iws-button-border-radius: 50%;
    --iws-font-family: inherit;
    --iws-font-size: 14px;
}

/* Search Form Styles */
.iws-search-container {
    position: relative;
    width: var(--iws-form-width);
    max-width: 400px;
    transition: all 0.3s ease;
}

/* Icon-only mode */
.iws-search-container.iws-icon-only {
    max-width: var(--iws-form-height);
    width: var(--iws-form-height);
}

.iws-search-container.iws-icon-only .iws-search-input {
    display: none !important;
}

.iws-search-container.iws-icon-only .iws-search-submit {
    border-radius: var(--iws-button-border-radius) !important;
    width: var(--iws-form-height) !important;
    height: var(--iws-form-height) !important;
    min-width: var(--iws-form-height) !important;
    position: relative !important;
    right: 0 !important;
    top: 0 !important;
    transform: none !important;
}

.iws-search-container.iws-icon-only .iws-search-input-wrapper {
    width: var(--iws-form-height);
    height: var(--iws-form-height);
    border-radius: var(--iws-button-border-radius) !important;
}

.iws-search-form {
    position: relative;
    font-family: var(--iws-font-family);
    font-size: var(--iws-font-size);
}

.iws-search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--iws-form-bg-color);
    border: var(--iws-form-border-width) solid var(--iws-form-border-color);
    border-radius: var(--iws-form-border-radius);
    overflow: hidden;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    height: var(--iws-form-height);
}

.iws-search-input-wrapper:focus-within {
    border-color: #007cba;
    box-shadow: 0 0 0 2px rgba(0, 124, 186, 0.1);
}

.iws-search-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: var(--iws-font-size);
    font-family: var(--iws-font-family);
    line-height: 1.4;
    padding: 0 15px;
    background: transparent;
    color: var(--iws-input-text-color);
    height: 100%;
}

.iws-search-input::placeholder {
    color: var(--iws-placeholder-color);
}

.iws-search-submit {
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(var(--iws-form-height) - 10px);
    height: calc(var(--iws-form-height) - 10px);
    margin: 5px;
    background: var(--iws-button-bg-color);
    border: none;
    border-radius: var(--iws-button-border-radius);
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    padding: 0;
}

.iws-search-submit:hover {
    background: var(--iws-button-hover-bg-color);
    transform: scale(1.05);
}

.iws-search-submit:active {
    transform: scale(0.95);
}

/* Search Icon Styles */
.iws-search-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--iws-icon-size);
    height: var(--iws-icon-size);
}

.iws-search-icon.iws-svg-icon {
    color: var(--iws-icon-color);
}

.iws-search-icon.iws-svg-icon svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    fill: currentColor;
}

.iws-search-icon.iws-custom-icon {
    max-width: var(--iws-icon-size);
    max-height: var(--iws-icon-size);
    width: auto;
    height: auto;
    object-fit: contain;
}

.iws-search-icon {
    width: var(--iws-icon-size);
    height: var(--iws-icon-size);
}

/* Overlay Styles with CSS Custom Properties */
.iws-overlay {
    --iws-overlay-bg-color: rgba(0, 0, 0, 0.8);
    --iws-content-bg-color: #ffffff;
    --iws-heading-color: #333333;
    --iws-text-color: #666666;
    --iws-overlay-border-radius: 8px;
    --iws-overlay-max-width: 1200px;
    --iws-heading-font-size: 18px;
    
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--iws-overlay-bg-color);
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.iws-overlay.active {
    opacity: 1;
    visibility: visible;
}

.iws-overlay-content {
    position: relative;
    background: var(--iws-content-bg-color);
    width: 100%;
    height: 100%;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border-radius: var(--iws-overlay-border-radius);
    max-width: var(--iws-overlay-max-width);
    margin: 0 auto;
    color: var(--iws-text-color);
    font-family: var(--iws-font-family);
}

/* Desktop: 80% screen height layout */
@media (min-width: 769px) {
    .iws-overlay-content {
        margin: 5vh auto;
        border-radius: var(--iws-overlay-border-radius);
        max-height: 80vh;
        width: 90%;
    }
}

/* Search Header */
.iws-search-header {
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    background: rgba(248, 249, 250, 0.8);
}

.iws-search-header .iws-search-input-wrapper {
    max-width: none;
    border-radius: var(--iws-form-border-radius);
}

.iws-search-header .iws-search-input {
    font-size: calc(var(--iws-font-size) + 4px);
    line-height: 1.5;
}

.iws-close-search {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--iws-text-color);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.3s ease;
    z-index: 1000;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.iws-close-search:hover {
    background: #f0f0f0;
    color: #333;
}

/* Results Container */
.iws-search-results {
    height: calc(80vh - 100px);
    overflow-y: auto;
}

.iws-results-container {
    padding: 20px;
}

/* Desktop Grid Layout: 3 columns */
@media (min-width: 769px) {
    .iws-results-grid {
        display: grid;
        grid-template-columns: 25% 50% 25%; /* 1fr 2fr 1fr */
        gap: 10px;
        height: 100%;
    }
    
    .iws-suggestions-column {
        order: 1;
    }
    
    .iws-products-column {
        order: 2;
    }
    
    .iws-content-column {
        order: 3;
    }
}

/* Mobile Layout: Single column */
@media (max-width: 768px) {
    .iws-results-grid {
        display: flex;
        flex-direction: column;
		gap:20px;
    }
    
    .iws-products-column {
        order: 1; /* Products first on mobile */
    }
    
    .iws-suggestions-column {
        order: 2; /* Suggestions second */
    }
    
    .iws-content-column {
        order: 3; /* Content last */
    }
    
    .iws-search-results {
        height: calc(100svh - 80px);
		padding-bottom: 30px;
    }
    
    .iws-results-container {
        padding: 15px;
    }
}

/* Section Styles */
.iws-section {
    margin-bottom: 30px;
}

.iws-section:last-child {
    margin-bottom: 0;
}

.iws-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.iws-section h3 {
    font-size: var(--iws-heading-font-size);
    font-weight: 600;
    color: var(--iws-heading-color);
    margin: 0 0 15px 0;
    letter-spacing: 0.5px;
    font-family: var(--iws-font-family);
}

/* Desktop: Larger section headers */
@media (min-width: 769px) {
    .iws-section h3 {
        font-size: calc(var(--iws-heading-font-size) + 2px);
        margin: 0 0 20px 0;
    }
}

/* Mobile: Smaller section headers */
@media (max-width: 768px) {
    .iws-section h3 {
        font-size: var(--iws-heading-font-size);
        margin: 0 0 15px 0;
    }
}

.iws-view-all-products {
    font-size: 14px;
    color: #007cba;
    text-decoration: none;
    font-weight: 500;
}

.iws-view-all-products:hover {
    color: #005a87;
}

/* Products Grid */
.iws-products-grid {
    display: grid;
    gap: 5px;
}

/* Desktop: 4 columns in middle section */
@media (min-width: 769px) {
    .iws-products-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 5px;
    }
}

/* Mobile: 2 columns full width */
@media (max-width: 768px) {
    .iws-products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 5px;
    }
}

/* Small mobile: 2 columns with smaller gap */
@media (max-width: 480px) {
    .iws-products-grid {
        gap: 5px;
    }
}

.iws-product-item {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
}

.iws-product-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    text-decoration: none;
    color: inherit;
}

.iws-product-image {
    width: 100%;
    aspect-ratio: 1; /* Square images */
    object-fit: cover;
    border: none;
    border-radius: 0;
    margin: 0;
    display: block;
}

.iws-product-details {
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Desktop: More padding in details */
@media (min-width: 769px) {
    .iws-product-details {
        padding: 15px;
    }
}

/* Mobile: Less padding */
@media (max-width: 768px) {
    .iws-product-details {
        padding: 10px;
    }
}

.iws-product-title {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
    line-height: 1.3;
    text-align: center;
}

.iws-product-price {
    font-size: 16px;
    font-weight: 600;
    color: black;
    text-align: center;
    margin-top: auto;
}

.iws-product-price del {
    color: #999;
    font-weight: 400;
    margin-right: 5px;
}

/* Desktop: Slightly larger text */
@media (min-width: 769px) {
    .iws-product-title {
        font-size: 15px;
    }
    
    .iws-product-price {
        font-size: 17px;
    }
}

/* Mobile: Smaller text */
@media (max-width: 768px) {
    .iws-product-title {
        font-size: 13px;
        margin-bottom: 6px;
    }
    
    .iws-product-price {
        font-size: 15px;
    }
}

/* Suggestions List */
.iws-suggestions-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Desktop: More spacing for suggestions */
@media (min-width: 769px) {
    .iws-suggestions-list {
        gap: 12px;
    }
    
    .iws-suggestions-column, .iws-products-column {
        background: #f8f9fa;
        padding: 20px;
        border-radius: 8px;
        height: fit-content;
    }
    
    .iws-content-column {
        background: #f8f9fa;
        padding: 20px;
        border-radius: 8px;
        height: fit-content;
    }
}

/* Mobile: Compact suggestions */
@media (max-width: 768px) {
    .iws-suggestions-list {
        gap: 8px;
    }
    
    .iws-suggestions-column,
    .iws-content-column {
        background: #f8f9fa;
        padding: 15px;
        border-radius: 8px;
    }
}

.iws-suggestion-item {
    padding: 10px 0;
    color: #666;
    text-decoration: none;
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
    transition: color 0.3s ease;
}

.iws-suggestion-item:hover {
    color: #007cba;
    text-decoration: none;
}

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

/* Content List */
.iws-content-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Desktop: More spacing */
@media (min-width: 769px) {
    .iws-content-list {
        gap: 15px;
    }
}

/* Mobile: Compact spacing */
@media (max-width: 768px) {
    .iws-content-list {
        gap: 10px;
    }
}

.iws-content-item {
    text-decoration: none;
    color: inherit;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
}

.iws-content-item:hover {
    text-decoration: none;
    color: inherit;
}

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

.iws-content-title {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
    line-height: 1.3;
}

.iws-content-item:hover .iws-content-title {
    color: #007cba;
}

.iws-content-excerpt {
    font-size: 13px;
    color: #666;
    line-height: 1.4;
}

.iws-content-type {
    display: inline-block;
    background: #f0f0f0;
    color: #666;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 3px;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Loading State */
.iws-loading {
    text-align: center;
    padding: 40px 20px;
}

.iws-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f0f0f0;
    border-top: 3px solid #007cba;
    border-radius: 50%;
    animation: iws-spin 1s linear infinite;
    margin: 0 auto 15px;
}

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

/* No Results State */
.iws-no-results {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {
    .iws-search-header {
        padding: 15px;
    }
    
    .iws-search-header .iws-search-input {
        font-size: 16px;
        padding: 0px 10px;
    }
    
    .iws-section-header {
        flex-direction: row;
        align-items: flex-start;
        gap: 10px;
    }
}

/* Small Mobile Responsive */
@media (max-width: 480px) {
    .iws-results-container {
        padding: 10px;
    }
    
    .iws-suggestions-column,
    .iws-content-column {
        padding: 12px;
    }
}

/* Theme Integration */
.woocommerce .iws-search-container {
    margin-bottom: 20px;
}

/* Accessibility */
.iws-search-input:focus,
.iws-search-submit:focus,
.iws-close-search:focus {
    outline: 2px solid #ccc;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .iws-overlay {
        background: rgba(0, 0, 0, 0.95);
    }
    
    .iws-search-input-wrapper {
        border-color: #333;
    }
    
    .iws-product-item {
        border-color: #333;
    }
}

/* Product Category Styling */
.iws-content-product_category .iws-content-type {
    background: #e8f4fd;
    color: #0073aa;
    border: 1px solid #c3e4f5;
}

.iws-content-product_category:hover .iws-content-type {
    background: #0073aa;
    color: white;
}

.iws-content-product_category .iws-content-title {
    position: relative;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .iws-overlay,
    .iws-product-item,
    .iws-search-input-wrapper,
    .iws-spinner {
        transition: none;
        animation: none;
    }
}
::-webkit-search-cancel-button {
    -webkit-appearance: none;
}
