/* header-search.css - Search Specific Styles */

/* Search Container */
.site-search {
    flex: 1;
    margin: 0; /* Reset margin if needed */
    position: relative;
    z-index: 100; /* Ensure search is above category nav */
}

.header-search-container {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
}

/* Search Icon */
.search-icon-wrapper {
    position: absolute;
    left: 20px;
    top: 50%; /* Center vertically */
    transform: translateY(-50%); /* Fine-tune vertical centering */
    z-index: 1;
    display: flex;
    align-items: center;
    pointer-events: none;
}

.search-icon {
    width: 20px;
    height: 20px;
    color: var(--color-dark-blue); /* Use variable */
}

/* Search Input */
.header-search-input {
    font-family: var(--font-primary); /* Ensure font consistency */
    width: 100%;
    padding: 16px 20px 16px 50px; /* Left padding for icon */
    border: 1px solid #e1e4e7;
    border-radius: 10px;
    font-size: 16px;
    background-color: #eeeff2;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
}

.header-search-input::placeholder {
    font-size: 16px;
    color: rgba(24, 50, 103, 0.6); /* #183267 with 60% opacity */
}

.header-search-input:focus {
    outline: none;
    border-color: var(--color-medium-blue); /* Use variable */
    box-shadow: 0 0 0 3px rgba(30, 49, 99, 0.2); /* Use variable color */
}

/* Dark Overlay */
.search-active-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.3);
    z-index: 90; /* Below search dropdown, above other content */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* Dropdown Container */
.search-results-dropdown {
    position: absolute;
    top: calc(100% + 10px); /* Spacing from input */
    left: 50%;
    transform: translateX(-50%);
    width: 800px;
    max-width: 90vw; /* Prevent overflow on smaller viewports */
    background: var(--color-white);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 100; /* Same as search container */
    max-height: 80vh; /* Limit height */
    overflow-y: auto; /* Allow scrolling */
    display: none; /* Hidden by default, shown by JS */
}

/* Search Results Header (Mobile Only) */
.search-results-header {
    display: none; /* Hidden by default, shown in media query */
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    text-align: center;
    border-radius: 8px 8px 0 0;
    background: #eeeff2;
}

.search-results-header a {
    color: var(--color-medium-blue);
    text-decoration: none;
    font-size: 14px;
}

.search-results-header a:hover {
    text-decoration: underline;
}

/* Grid Layout */
.search-results-grid {
    display: grid;
    grid-template-columns: 2fr 1fr; /* Product/Category split */
    gap: 20px;
    padding: 20px;
}

/* Section Headers */
.product-results h3,
.category-results h3 {
    font-size: 14px;
    color: #666;
    margin: 0 0 15px 0;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

/* Product Results */
.product-results {
    border-right: 1px solid #eee;
    padding-right: 20px;
}

.product-result {
    display: grid;
    grid-template-columns: 50px 1fr 24px;
    gap: 12px;
    align-items: center;
    padding: 10px;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.2s ease;
    border-radius: 4px; /* Add subtle rounding */
}

.product-result:hover {
    background-color: #f8f8f8;
}

/* --- IMAGE FIX INCORPORATED --- */
.product-image {
    width: 50px;
    height: 50px;
    flex-shrink: 0;
    background-color: var(--color-white);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* ADD THIS NEW RULE for the link */
.product-image a {
    display: block; /* Make the link behave like a block */
    width: 100%;    /* Make it fill the container width */
    height: 100%;   /* Make it fill the container height */
}

/* Image style remains the same */
.product-image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center center;
}

.product-info { min-width: 0; }
.product-result .favorite-button {
    grid-column: 3;
    justify-self: end;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
}
.product-result .favorite-button svg { width: 20px; height: 20px; stroke: #0a2140; fill: none; }
.product-result .favorite-button.is-favorite svg { fill: #d51625; stroke: #d51625; }

.product-title {
    font-size: 14px;
    margin-bottom: 4px;
    color: var(--color-heading);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-meta {
    display: flex;
    gap: 15px;
    font-size: 12px;
    color: #666;
}

/* Category Results */
.category-results {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.category-result {
    display: flex;
    justify-content: space-between;
    align-items: center; /* Vertically align text */
    padding: 8px;
    text-decoration: none;
    color: var(--color-heading);
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.category-result:hover {
    background-color: #f8f8f8;
}

.category-name { /* Allow category name to wrap if needed */
    flex-grow: 1;
    padding-right: 10px; /* Space before count */
}

.category-count {
    color: #666;
    font-size: 12px;
    flex-shrink: 0; /* Prevent count from shrinking */
}

/* Search Results Footer (Desktop) */
.search-results-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    text-align: center;
    background: var(--color-white); /* Match dropdown background */
    border-radius: 0 0 8px 8px; /* Round bottom corners */
}

.search-results-footer a {
    color: var(--color-medium-blue);
    text-decoration: none;
    font-size: 14px;
}

.search-results-footer a:hover {
    text-decoration: underline;
}

/* No Results */
.no-results {
    padding: 20px;
    text-align: center;
    color: #666;
    font-size: 14px;
    grid-column: 1 / -1; /* Span across grid if needed */
}

/* Responsive Search Styles */
@media (max-width: 1024px) {
    .search-results-dropdown {
        width: 600px; /* Adjust dropdown width */
    }

    .site-search {
        margin: 0 20px; /* Adjust search margin */
    }
}

@media (max-width: 768px) {
    .search-icon-wrapper {
        left: 15px;
    }

    .header-search-input {
        padding-left: 45px;
        font-size: 16px; /* Ensure minimum font size */
    }

    .site-search {
        order: 3; /* Place search below logo/nav on mobile */
        flex: 0 0 100%;
        margin: 15px 0 0; /* Add top margin */
        min-width: 100%;
    }

    .search-results-header {
        display: block; /* Show mobile header */
    }

    .search-results-footer {
        display: none; /* Hide desktop footer */
    }

    .search-results-grid {
        grid-template-columns: 1fr; /* Single column layout */
        gap: 20px; /* Adjust gap */
    }

    .product-results {
        border-right: none; /* Remove border */
        padding-right: 0;
        border-bottom: 1px solid #eee; /* Add bottom border */
        padding-bottom: 20px;
    }

    .search-results-dropdown {
        left: 0;
        right: 0;
        transform: none;
        width: 100%;
        max-width: 100%;
        top: calc(100% + 5px); /* Adjust spacing */
    }

    /* Adjust image size for mobile search results if needed */
    .search-results-dropdown .product-result .product-image {
        width: 50px;
        height: 50px;
    }
}