/* =============================================
 * Dynamic Search - Dropdown Overlay Styles
 * Designed to integrate with Cartzilla / Bootstrap themes
 * ============================================= */

/* Dropdown container */
#dynamic-search-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 50%;
    transform: translateX(-50%);
    z-index: 1050;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 0.5rem;
    box-shadow: 0 0.25rem 1.5rem rgba(0, 0, 0, 0.15);
    max-height: 80vh;
    overflow-y: auto;
    min-width: 800px;
    width: max-content;
    max-width: 1000px;
}

/* Light scrollbar styling */
#dynamic-search-dropdown::-webkit-scrollbar,
.ds-left::-webkit-scrollbar,
.ds-right::-webkit-scrollbar {
    width: 6px;
}

#dynamic-search-dropdown::-webkit-scrollbar-track,
.ds-left::-webkit-scrollbar-track,
.ds-right::-webkit-scrollbar-track {
    background: #f8f9fa;
    border-radius: 3px;
}

#dynamic-search-dropdown::-webkit-scrollbar-thumb,
.ds-left::-webkit-scrollbar-thumb,
.ds-right::-webkit-scrollbar-thumb {
    background: #dee2e6;
    border-radius: 3px;
}

#dynamic-search-dropdown::-webkit-scrollbar-thumb:hover,
.ds-left::-webkit-scrollbar-thumb:hover,
.ds-right::-webkit-scrollbar-thumb:hover {
    background: #ced4da;
}

/* Firefox scrollbar */
#dynamic-search-dropdown,
.ds-left,
.ds-right {
    scrollbar-width: thin;
    scrollbar-color: #dee2e6 #f8f9fa;
}

#dynamic-search-dropdown.ds-open {
    display: block;
    animation: fade-up 0.25s ease-in-out;
}

@keyframes fade-up {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Background overlay */
#dynamic-search-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
}

#dynamic-search-overlay.ds-active {
    display: block;
}

/* Search input wrapper */
.ds-search-wrapper {
    position: relative;
    z-index: 1050;
}

/* Mobile header (hidden by default, shown on mobile when search is active) */
.ds-mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1060;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: #fff;
    border-bottom: 1px solid #e5e5e5;
}

/* =============================================
 * Two-column layout (desktop)
 * ============================================= */
.ds-results {
    display: flex;
    padding: 0;
}

.ds-left {
    flex: 0 0 280px;
    border-right: 1px solid #e5e5e5;
    padding: 1.25rem 1.5rem;
    max-height: 70vh;
    overflow-y: auto;
}

.ds-right {
    flex: 1;
    padding: 1.25rem 1.5rem;
    min-width: 500px;
    max-height: 70vh;
    overflow-y: auto;
}

/* Section titles */
.ds-section-title {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #6c757d;
    text-transform: uppercase;
    margin: 0 0 0.75rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e5e5e5;
}

.ds-section {
    margin-bottom: 1.75rem;
}

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

/* =============================================
 * Suggestions
 * ============================================= */
.ds-suggestion {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0;
    color: #212529;
    text-decoration: none;
    font-size: 0.875rem;
    line-height: 1.4;
    transition: color 0.15s;
}

.ds-suggestion:hover {
    color: #000;
    text-decoration: none;
}

.ds-suggestion strong {
    font-weight: 600;
}

.ds-icon {
    flex-shrink: 0;
    color: #6c757d;
    font-size: 1rem;
}

/* =============================================
 * Categories
 * ============================================= */
.ds-category {
    display: block;
    padding: 0.5rem 0;
    color: #212529;
    text-decoration: none;
    font-size: 0.875rem;
    line-height: 1.4;
    transition: color 0.15s;
}

.ds-category:hover {
    color: #000;
    text-decoration: none;
}

.ds-category strong {
    font-weight: 600;
}

.ds-more {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #212529;
    text-decoration: none;
    transition: color 0.15s;
}

.ds-more:hover {
    color: #000;
}

/* =============================================
 * Pages (with info icon)
 * ============================================= */
.ds-page {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0;
    color: #212529;
    text-decoration: none;
    font-size: 0.875rem;
    line-height: 1.4;
    transition: color 0.15s;
}

.ds-page:hover {
    color: #000;
    text-decoration: none;
}

.ds-page strong {
    font-weight: 600;
}

/* =============================================
 * Product grid (desktop: 3 columns)
 * ============================================= */
.ds-products-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.ds-product {
    display: block;
    text-decoration: none;
    color: #212529;
    transition: transform 0.2s;
}

.ds-product:hover {
    text-decoration: none;
    transform: translateY(-2px);
}

.ds-product-img {
    aspect-ratio: 1;
    background: #f8f9fa;
    border-radius: 0.375rem;
    overflow: hidden;
    margin-bottom: 0.75rem;
    border: 1px solid #e5e5e5;
}

.ds-product-img img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 0.5rem;
}

.ds-product-name {
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.4;
    color: #212529;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 0.25rem;
}

.ds-product-desc {
    font-size: 0.6875rem;
    color: #6c757d;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 0.25rem;
}

.ds-product-brand {
    font-size: 0.75rem;
    color: #6c757d;
    margin-bottom: 0.375rem;
}

.ds-product-price {
    font-size: 0.875rem;
    font-weight: 600;
    color: #212529;
}

.ds-price-sale {
    color: #dc3545;
    font-weight: 700;
}

.ds-price-original {
    color: #999;
    text-decoration: line-through;
    font-size: 0.75rem;
    font-weight: 400;
    margin-left: 0.25rem;
}

.ds-sale-badge {
    display: inline-block;
    margin-top: 0.375rem;
    padding: 0.2rem 0.5rem;
    background: #dc3545;
    color: #fff;
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    border-radius: 0.25rem;
    letter-spacing: 0.02em;
}

/* View All button */
.ds-view-all {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1.25rem;
    padding: 0.75rem 1.25rem;
    background: #212529;
    color: #fff;
    text-align: center;
    text-decoration: none;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    transition: all 0.15s;
}

.ds-view-all:hover {
    background: #000;
    color: #fff;
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.15);
}

/* Mobile dropdown container */
#dynamic-search-dropdown-mobile {
    display: none;
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    z-index: 1060;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 0.5rem;
    box-shadow: 0 0.25rem 1.5rem rgba(0, 0, 0, 0.15);
    max-height: 70vh;
    overflow-y: auto;
}

#dynamic-search-dropdown-mobile.ds-open {
    display: block;
    animation: fade-up 0.25s ease-in-out;
}

#dynamic-search-dropdown-mobile .ds-results {
    flex-direction: column;
}

#dynamic-search-dropdown-mobile .ds-left {
    flex: none;
    border-right: none;
    border-bottom: 1px solid #e5e5e5;
}

#dynamic-search-dropdown-mobile .ds-right {
    flex: none;
    min-width: unset;
}

#dynamic-search-dropdown-mobile .ds-products-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

/* =============================================
 * Mobile styles (< 768px)
 * ============================================= */
@media (max-width: 767.98px) {
    #dynamic-search-dropdown {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border: none;
        border-radius: 0;
        max-height: 100vh;
        padding-top: 60px; /* space for fixed search bar */
        animation: none;
    }

    #dynamic-search-dropdown-mobile .ds-products-grid {
        grid-template-columns: 1fr;
    }

    /* Mobile search bar (fixed at top) */
    .ds-mobile-header {
        display: flex;
    }

    /* Single column layout */
    .ds-results {
        flex-direction: column;
    }

    .ds-left {
        flex: none;
        border-right: none;
        border-bottom: 1px solid #e5e5e5;
    }

    .ds-right {
        flex: none;
    }

    /* Products: single column list */
    .ds-products-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .ds-product {
        display: flex;
        gap: 0.75rem;
        align-items: flex-start;
    }

    .ds-product-img {
        flex: 0 0 90px;
        width: 90px;
        height: 90px;
        margin-bottom: 0;
    }

    .ds-product-info {
        flex: 1;
        min-width: 0;
    }

    .ds-product-name {
        font-size: 0.875rem;
    }
}

/* =============================================
 * Prevent body scroll when search is open (mobile)
 * ============================================= */
body.ds-search-active {
    overflow: hidden;
}

@media (min-width: 768px) {
    body.ds-search-active {
        overflow: auto;
    }

    .ds-mobile-header {
        display: none !important;
    }
}

/* Dark mode support (Cartzilla) */
@media (prefers-color-scheme: dark) {
    [data-bs-theme="dark"] #dynamic-search-dropdown,
    [data-bs-theme="dark"] .ds-mobile-header {
        background: #1f1f1f;
        border-color: #2d2d2d;
    }

    [data-bs-theme="dark"] .ds-left {
        border-right-color: #2d2d2d;
    }

    [data-bs-theme="dark"] .ds-section-title {
        color: #adb5bd;
        border-bottom-color: #2d2d2d;
    }

    [data-bs-theme="dark"] .ds-suggestion,
    [data-bs-theme="dark"] .ds-category,
    [data-bs-theme="dark"] .ds-page,
    [data-bs-theme="dark"] .ds-more,
    [data-bs-theme="dark"] .ds-product-name {
        color: #e9ecef;
    }

    [data-bs-theme="dark"] .ds-suggestion:hover,
    [data-bs-theme="dark"] .ds-category:hover,
    [data-bs-theme="dark"] .ds-page:hover,
    [data-bs-theme="dark"] .ds-more:hover {
        color: #fff;
    }

    [data-bs-theme="dark"] .ds-icon,
    [data-bs-theme="dark"] .ds-product-brand {
        color: #6c757d;
    }

    [data-bs-theme="dark"] .ds-product-img {
        background: #2d2d2d;
        border-color: #3d3d3d;
    }

    [data-bs-theme="dark"] .ds-view-all {
        background: #f8f9fa;
        color: #212529;
    }

    [data-bs-theme="dark"] .ds-view-all:hover {
        background: #fff;
        color: #000;
    }
}
