/**
 * Algolia InstantSearch - Cartzilla Theme Integration
 * 
 * Styling for the full-screen search modal with filters, results, and pagination
 * following Cartzilla Electronics design patterns.
 * 
 * @version 1.0.0
 */

/* ========================================================================
   Search Overlay Modal
   ======================================================================== */

.algolia-search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    background-color: rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.algolia-search-overlay-content {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: var(--bs-body-bg);
    display: flex;
    flex-direction: column;
}

/* Close button styling with Cartzilla btn-close */
.algolia-close-search.btn-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 10001;
    background: transparent;
    width: auto;
    height: auto;
    padding: 0.5rem;
    font-size: 1.25rem;
    opacity: 0.8;
}

.algolia-close-search.btn-close:hover {
    opacity: 1;
}

/* Fallback für Close-Button ohne Bootstrap btn-close */
.algolia-close-search:not(.btn-close) {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 10001;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: #000;
    opacity: 0.8;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.375rem;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: opacity 0.15s ease, background-color 0.15s ease;
}

/* X-Symbol mit CSS erzeugen wenn nicht vorhanden */
.algolia-close-search:not(.btn-close)::before,
.algolia-close-search:not(.btn-close)::after {
    content: '';
    position: absolute;
    width: 1.25rem;
    height: 2px;
    background-color: currentColor;
    top: 50%;
    left: 50%;
}

.algolia-close-search:not(.btn-close)::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.algolia-close-search:not(.btn-close)::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

.algolia-close-search:not(.btn-close):hover {
    opacity: 1;
    background: rgba(255, 255, 255, 1);
}

[data-bs-theme="dark"] .algolia-close-search:not(.btn-close) {
    background: rgba(33, 37, 41, 0.9);
    color: #fff;
}

[data-bs-theme="dark"] .algolia-close-search:not(.btn-close):hover {
    background: rgba(33, 37, 41, 1);
}

/* ========================================================================
   Search Layout (Sidebar + Content)
   ======================================================================== */

.algolia-search-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.algolia-search-sidebar {
    width: 280px;
    flex-shrink: 0;
    overflow-y: auto;
    border-right: 1px solid var(--bs-border-color);
}

.algolia-search-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.algolia-search-header {
    flex-shrink: 0;
}

/* Scrollable results area */
.algolia-search-content > div:last-child {
    flex: 1;
    overflow-y: auto;
}

/* Mobile responsiveness */
@media (max-width: 991.98px) {
    .algolia-search-sidebar {
        display: none;
    }
}

/* ========================================================================
   Refinement Sections (Filters)
   ======================================================================== */

.algolia-refinement-section {
    /* Spacing handled by Bootstrap utilities */
}

.algolia-refinement-section h6 {
    font-weight: 600;
    color: var(--bs-body-color);
}

/* ========================================================================
   Algolia Widgets - Cartzilla Styling
   ======================================================================== */

/* SearchBox */
.ais-SearchBox-form {
    position: relative;
    display: flex;
    align-items: center;
}

.ais-SearchBox-input {
    width: 100%;
    padding: 0.5rem 2.5rem 0.5rem 1rem;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--bs-body-color);
    background-color: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.ais-SearchBox-input:focus {
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.ais-SearchBox-submit {
    display: none;
}

.ais-SearchBox-reset {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: var(--bs-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ais-SearchBox-reset:hover {
    color: var(--bs-body-color);
}

.ais-SearchBox-resetIcon {
    width: 0.875rem;
    height: 0.875rem;
}

.ais-SearchBox-loadingIndicator {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
}

.ais-SearchBox-loadingIcon {
    width: 1rem;
    height: 1rem;
    animation: spinner-border 0.75s linear infinite;
}

/* ========================================================================
   RefinementList (Category/Brand Filters)
   ======================================================================== */

.ais-RefinementList {
    font-size: 0.875rem;
}

.ais-RefinementList-searchBox {
    margin-bottom: 0.75rem;
}

.ais-RefinementList-searchBox .ais-SearchBox-input {
    font-size: 0.875rem;
    padding: 0.375rem 2.25rem 0.375rem 0.75rem;
    border-radius: 0.25rem;
}

.ais-RefinementList-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.ais-RefinementList-item {
    padding: 0.375rem 0;
}

.ais-RefinementList-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin: 0;
    transition: color 0.15s ease;
}

.ais-RefinementList-label:hover {
    color: var(--bs-primary);
}

.ais-RefinementList-checkbox {
    width: 1rem;
    height: 1rem;
    margin-right: 0.5rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.25rem;
    cursor: pointer;
    flex-shrink: 0;
}

.ais-RefinementList-checkbox:checked {
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
}

.ais-RefinementList-labelText {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ais-RefinementList-count {
    color: var(--bs-secondary);
    font-size: 0.75rem;
}

.ais-RefinementList-showMore {
    margin-top: 0.5rem;
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
    color: var(--bs-primary);
    background: transparent;
    border: 1px solid var(--bs-primary);
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ais-RefinementList-showMore:hover {
    background-color: var(--bs-primary);
    color: #fff;
}

/* ========================================================================
   RangeSlider (Price Filter)
   ======================================================================== */

.ais-RangeSlider {
    padding: 0.5rem 0;
}

.rheostat {
    overflow: visible;
    height: 3rem;
}

.rheostat-background {
    background-color: var(--bs-light);
    border: 1px solid var(--bs-border-color);
    position: relative;
    height: 4px;
    top: 50%;
    transform: translateY(-50%);
}

.rheostat-progress {
    background-color: var(--bs-primary);
    position: absolute;
    height: 4px;
    top: 50%;
    transform: translateY(-50%);
}

.rheostat-handle {
    background-color: #fff;
    border: 2px solid var(--bs-primary);
    border-radius: 50%;
    width: 1.25rem;
    height: 1.25rem;
    margin-left: -0.625rem;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.15s ease;
}

.rheostat-handle:hover,
.rheostat-handle:focus {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    outline: none;
}


.ais-RangeSlider .rheostat-handle {
    background-color: #fff;
    background-image: linear-gradient(-180deg, #fff, #fcfcfd);
    border: 1px solid #d6d6e7;
    border-radius: 2px;
    box-shadow: 0 1px 0 0 rgba(35, 38, 59, .05);
    height: 24px;
    margin-left: -6px;
    top: -11px;
    width: 12px
}

.ais-RangeSlider .rheostat-handle::before,
.ais-RangeSlider .rheostat-handle::after {
    background-color: #d6d6e7;
    content: "";
    height: 12px;
    position: absolute;
    top: 6px;
    width: 1px
}

.ais-RangeSlider .rheostat-handle::before {
    left: 4px
}

.ais-RangeSlider .rheostat-handle::after {
    right: 4px
}

.rheostat-tooltip {
    position: absolute;
    top: -2rem;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--bs-dark);
    color: #fff;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    white-space: nowrap;
    pointer-events: none;
}

/* ========================================================================
   ToggleRefinement (Availability)
   ======================================================================== */

.ais-ToggleRefinement-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin: 0;
}

.ais-ToggleRefinement-checkbox {
    width: 2.5rem;
    height: 1.5rem;
    margin-right: 0.75rem;
    appearance: none;
    background-color: var(--bs-secondary);
    border-radius: 1rem;
    position: relative;
    cursor: pointer;
    transition: background-color 0.15s ease;
    flex-shrink: 0;
}

.ais-ToggleRefinement-checkbox::before {
    content: '';
    position: absolute;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background-color: #fff;
    top: 0.125rem;
    left: 0.125rem;
    transition: left 0.15s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.ais-ToggleRefinement-checkbox:checked {
    background-color: var(--bs-success);
}

.ais-ToggleRefinement-checkbox:checked::before {
    left: 1.125rem;
}

.ais-ToggleRefinement-labelText {
    font-size: 0.875rem;
}

/* ========================================================================
   Stats (Results Count)
   ======================================================================== */

.ais-Stats {
    font-size: 0.875rem;
    color: var(--bs-secondary);
}

.ais-Stats-text {
    white-space: nowrap;
}

/* ========================================================================
   SortBy (Sorting Dropdown)
   ======================================================================== */

.ais-SortBy-select {
    padding: 0.375rem 2rem 0.375rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--bs-body-color);
    background-color: var(--bs-body-bg);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px 12px;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    appearance: none;
    cursor: pointer;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.ais-SortBy-select:focus {
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* ========================================================================
   Hits (Product Results)
   ======================================================================== */

.ais-Hits-list {
    list-style: none;
    padding: 0;
    margin: 0 -0.5rem;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.ais-Hits-item {
    /* Remove default list styling */
    list-style: none;
    padding: 0 0.5rem;
}

/* Product Card - Cartzilla theme already styles .product-card */
.ais-Hits-item .product-card {
    height: 100%;
    margin-bottom: 0;
    transition: background-color 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* Match Autocomplete hover effect */
.ais-Hits-item .product-card:hover {
    background-color: rgba(179, 173, 214, 0.205);
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

.ais-Hits-item .card-img-top {
    height: 150px;
    width: 100%;
    object-fit: contain;
    padding: 0.5rem;
    flex-shrink: 0;
}

.ais-Hits-item .card-body {
    padding: 0.5rem 0.75rem 3rem 0.75rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

.ais-Hits-item .card-img-top img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Text-clamp for 2 lines */
.ais-Hits-item .text-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 0.8125rem;
    line-height: 1.3;
    margin-bottom: 0.5rem;
}

/* Produkttitel kompakter */
.ais-Hits-item .product-title {
    font-size: 0.8125rem;
    line-height: 1.3;
    margin-bottom: 0.5rem;
    min-height: 2.1em;
    text-overflow: ellipsis;
}

/* Responsive: 2 columns on tablets */
@media (max-width: 991px) {
    .ais-Hits-list {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Responsive: 1 column on mobile */
@media (max-width: 575px) {
    .ais-Hits-list {
        grid-template-columns: 1fr;
    }
}

.hit-description {
    font-size: 0.8125rem;
    line-height: 1.5;
    color: var(--bs-secondary);
    margin-bottom: 0.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Highlight matched text */
.hit-description mark,
.hit-name mark,
.ais-Snippet-highlighted {
    background-color: 5rem;
}

.hit-stock {
    font-size: 0.7rem;
    font-weight: 500;
}

.hit-stock.in-stock {
    color: var(--bs-success);
}

.hit-stock.out-of-outstock {
    color: var(--bs-danger);
}

/* Preis kompakter */
.ais-Hits-item .product-price,
.ais-Hits-item .text-accent {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

/* Button kompakter und hidden by default */
/* Overlay legt sich über card-body Bereich */
.ais-Hits-item .card-body-hidden {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 10;
    border-radius: 0 0 0.375rem 0.375rem;
}

/* Glassy Background Overlay - initial versteckt (unten) */
.ais-Hits-item .card-body::before {
    display: none;
}

.hit-button,
.ais-Hits-item .card-body-hidden .btn {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #fff;
    text-decoration: none;
    border-radius: 0.25rem;
    background: linear-gradient(to bottom, #FFC400, #FF7600);
    border: none;
    box-shadow: 0 2px 4px rgba(255, 118, 0, 0.3);
    cursor: pointer;
    white-space: nowrap;
}

/* Sichtbar machen beim Hover */
.ais-Hits-item .product-card:hover .card-body-hidden,
.ais-Hits-item .card:hover .card-body-hidden {
    opacity: 1;
    visibility: visible;
}

/* Responsive grid adjustments */
@media (max-width: 767.98px) {
    .ais-Hits-list {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 1rem;
    }
}

@media (max-width: 575.98px) {
    .ais-Hits-list {
        grid-template-columns: 1fr;
    }
}

/* ========================================================================
   Pagination
   ======================================================================== */

.ais-Pagination {
    margin-top: 2rem;
}

.ais-Pagination-list {
    display: flex;
    flex-direction: row;
    list-style: none;
    padding: 0;
    margin: 0;
    gap: 0.25rem;
    justify-content: center;
}

.ais-Pagination-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2.5rem;
    height: 2.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: var(--bs-body-color);
    background-color: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    text-decoration: none;
    transition: all 0.15s ease;
    cursor: pointer;
}

.ais-Pagination-link:hover {
    background-color: var(--bs-light);
    border-color: var(--bs-border-color);
    color: var(--bs-body-color);
}

.ais-Pagination-item--selected .ais-Pagination-link {
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
    pointer-events: none;
}

.ais-Pagination-item--disabled .ais-Pagination-link {
    color: var(--bs-secondary);
    pointer-events: none;
    opacity: 0.6;
}

.ais-Pagination-item--previousPage .ais-Pagination-link,
.ais-Pagination-item--nextPage .ais-Pagination-link {
    font-size: 1.25rem;
    padding: 0.5rem;
}

/* ========================================================================
   No Results
   ======================================================================== */

.ais-Hits--empty {
    padding: 3rem 1rem;
    text-align: center;
}

.ais-Hits--empty p {
    font-size: 1.125rem;
    color: var(--bs-secondary);
    margin-bottom: 1rem;
}

/* ========================================================================
   Loading State
   ======================================================================== */

.ais-InfiniteHits--empty,
.ais-Hits--empty {
    padding: 2rem;
    text-align: center;
}

/* ========================================================================
   Dark Mode Support
   ======================================================================== */

[data-bs-theme="dark"] .algolia-search-overlay-content {
    background-color: var(--bs-dark);
}

[data-bs-theme="dark"] .hit-item {
    background-color: var(--bs-gray-900);
    border-color: var(--bs-gray-800);
}

[data-bs-theme="dark"] .hit-item:hover {
    box-shadow: 0 0.5rem 1rem rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .rheostat-background {
    background-color: var(--bs-gray-800);
    border-color: var(--bs-gray-700);
}

/* ========================================================================
   Mobile Optimizations
   ======================================================================== */

@media (max-width: 991.98px) {
    .algolia-search-header {
        position: sticky;
        top: 0;
        z-index: 10;
        background-color: var(--bs-body-bg);
        border-bottom: 1px solid var(--bs-border-color);
    }
    
    .algolia-search-sidebar {
        position: fixed;
        top: 0;
        left: -300px;
        width: 300px;
        height: 100vh;
        z-index: 1050;
        transition: left 0.3s ease;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    }
    
    .algolia-search-sidebar.show {
        left: 0;
    }
}

/* ========================================================================
   Utilities
   ======================================================================== */

/* Ensure smooth scrolling */
.algolia-search-content > div:last-child {
    scroll-behavior: smooth;
}

/* Accessibility improvements */
.ais-RefinementList-checkbox:focus,
.ais-ToggleRefinement-checkbox:focus,
.ais-SortBy-select:focus {
    outline: 2px solid var(--bs-primary);
    outline-offset: 2px;
}

/* Animation for results */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ais-Hits-item {
    animation: fadeIn 0.3s ease;
}
