/**
 * Algolia Autocomplete - Cartzilla Theme Integration
 * 
 * This stylesheet provides Cartzilla-specific styling for Algolia Autocomplete components
 * to ensure seamless visual integration with the Cartzilla e-commerce template.
 * 
 * Based on:
 * - Cartzilla Electronics design patterns
 * - Bootstrap 5.3+ utilities
 * - Cartzilla icon font (ci-*)
 * 
 * @version 1.0.0
 */

/* ========================================================================
   Cartzilla Theme Variables
   ======================================================================== */

:root {
    /* Override Algolia default colors with Cartzilla theme colors */
    --aa-primary-color-rgb: 13, 110, 253; /* Bootstrap primary blue */
    --aa-text-color-rgb: 33, 37, 41; /* Bootstrap dark text */
    --aa-background-color-rgb: 255, 255, 255;
    --aa-input-background-color-rgb: 248, 249, 250; /* Bootstrap light background */
    --aa-selected-color-rgb: 13, 110, 253;
    --aa-selected-color-alpha: 0.08;
    --aa-panel-border-color-rgb: 222, 226, 230;
    --aa-panel-border-color-alpha: 1;
    --aa-input-border-color-rgb: 222, 226, 230;
    --aa-input-border-color-alpha: 1;
    --aa-panel-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15); /* Bootstrap shadow-lg */
    --aa-panel-max-height: 700px;
    
    /* Custom Algolia-specific variables for consistency */
    --algolia-primary: #0d6efd;
    --algolia-primary-hover: #0b5ed7;
    --algolia-success: #198754;
    --algolia-danger: #dc3545;
    --algolia-warning: #ffc107;
    --algolia-text: #212529;
    --algolia-text-muted: #6c757d;
    --algolia-border: #dee2e6;
    --algolia-light-bg: #f8f9fa;
    
    /* Gradient Colors */
    --algolia-gradient-start: #FFC400;
    --algolia-gradient-end: #FF7600;
    
    /* Border Radius */
    --algolia-border-radius: 0.375rem;
    --algolia-border-radius-sm: 0.25rem;
    --algolia-border-radius-lg: 0.5rem;
    --algolia-border-radius-pill: 50rem;
    
    /* Shadows */
    --algolia-shadow-sm: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    --algolia-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    --algolia-shadow-lg: 0 1rem 3rem rgba(0, 0, 0, 0.175);
    --algolia-shadow-primary: 0 2px 4px rgba(13, 110, 253, 0.3);
    --algolia-shadow-primary-hover: 0 4px 8px rgba(13, 110, 253, 0.4);
    --algolia-shadow-orange: 0 2px 4px rgba(255, 118, 0, 0.3);
    --algolia-shadow-orange-hover: 0 4px 8px rgba(255, 118, 0, 0.4);
    
    /* Spacing */
    --algolia-spacing-xs: 0.25rem;
    --algolia-spacing-sm: 0.5rem;
    --algolia-spacing: 0.75rem;
    --algolia-spacing-lg: 1rem;
    --algolia-spacing-xl: 1.5rem;
    
    /* Z-Index Layers */
    --algolia-z-panel: 9999;
    --algolia-z-modal: 10000;
    
    /* Typography */
    --algolia-font-size-sm: 0.875rem;
    --algolia-font-size-xs: 0.75rem;
    --algolia-font-weight-normal: 400;
    --algolia-font-weight-medium: 500;
    --algolia-font-weight-semibold: 600;
    --algolia-font-weight-bold: 700;
}

/* Dark mode support following Cartzilla patterns */
[data-bs-theme="dark"] {
    --aa-background-color-rgb: 33, 37, 41;
    --aa-input-background-color-rgb: 52, 58, 64;
    --aa-text-color-rgb: 248, 249, 250;
    --aa-panel-border-color-rgb: 73, 80, 87;
    --aa-input-border-color-rgb: 73, 80, 87;
}

/* ========================================================================
   Desktop Search Input (Cartzilla Style)
   ======================================================================== */

/* Main autocomplete container for desktop */
.algolia-search-cartzilla .aa-Form {
    width: 100%;
    background-color: transparent;
    border: none;
    box-shadow: none;
}

/* Input field following Cartzilla form-control styling */
.algolia-search-cartzilla .aa-Input {
    width: 100%;
    padding: 0.5rem 1rem 0.5rem 3rem; /* Space for search icon on left */
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: var(--bs-body-color);
    background-color: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 50rem; /* Cartzilla rounded-pill style */
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

/* For Electronics variant with white/light styling */
.navbar-dark .algolia-search-cartzilla .aa-Input,
.bg-dark .algolia-search-cartzilla .aa-Input {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.navbar-dark .algolia-search-cartzilla .aa-Input::placeholder,
.bg-dark .algolia-search-cartzilla .aa-Input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

/* Focus state following Bootstrap form-control:focus */
.algolia-search-cartzilla .aa-Input:focus {
    color: var(--bs-body-color);
    background-color: var(--bs-body-bg);
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Input submit button (hidden, accessibility only) */
.algolia-search-cartzilla .aa-SubmitButton {
    display: none;
}

/* Clear button styling to match Cartzilla */
.algolia-search-cartzilla .aa-ClearButton {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.25rem;
    height: 1.25rem;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--bs-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}

.algolia-search-cartzilla .aa-ClearButton:hover {
    color: var(--bs-body-color);
}

.algolia-search-cartzilla .aa-ClearButton svg {
    width: 1rem;
    height: 1rem;
}

/* ========================================================================
   Mobile Search Input (Cartzilla Style)
   ======================================================================== */

.algolia-search-cartzilla-mobile .aa-Form {
    width: 100%;
    background-color: transparent;
    border: none;
    box-shadow: none;
}

.algolia-search-cartzilla-mobile .aa-Input {
    width: 100%;
    padding: 0.625rem 1rem 0.625rem 3rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: var(--bs-body-color);
    background-color: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 50rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.algolia-search-cartzilla-mobile .aa-Input:focus {
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* ========================================================================
   Autocomplete Panel (Dropdown Results)
   ======================================================================== */

/* Main panel container following Cartzilla dropdown/card patterns */
.aa-Panel {
    z-index: 1050;;
    margin-top: 0.5rem;
    background-color: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem; /* Cartzilla rounded-3 */
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    overflow: hidden;
}


/* Source section (categories like Products, Categories, etc.) */
.aa-Source {
    margin-bottom: 0.5rem;
}

.aa-Source:last-child {
    margin-bottom: 0;
}

/* Source header */
.aa-SourceHeader {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-bottom: 1px solid #dee2e6;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--bs-secondary);
}

/* Results list */
.aa-List {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Individual result item following Cartzilla dropdown-item pattern */
.aa-Item {
    padding: 0.625rem 0.75rem;
    margin: 0;
    cursor: pointer;
    border-radius: 0.375rem; /* rounded-2 */
    transition: background-color 0.15s ease;
    color: var(--bs-body-color);
    text-decoration: none;
}

.aa-Item:hover,
.aa-Item[aria-selected="true"] {
    background-color: rgba(var(--aa-selected-color-rgb), var(--aa-selected-color-alpha));
}

/* Product result item layout */
.aa-ItemWrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.aa-ItemIcon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bs-light);
    border-radius: 0.375rem;
    overflow: hidden;
}

.aa-ItemIcon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.aa-ItemContent {
    flex: 1;
    min-width: 0; /* For text truncation */
}

.aa-ItemContentTitle {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--bs-body-color);
    margin-bottom: 0.125rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.aa-ItemContentDescription {
    font-size: 0.75rem;
    color: var(--bs-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Price display in results */
.aa-ItemContentPrice {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--bs-body-color);
    margin-top: 0.25rem;
}

.aa-ItemContentPrice .old-price {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--bs-secondary);
    text-decoration: line-through;
}

.aa-ItemContentPrice .sale-price {
    color: var(--bs-primary);
}

/* Hit highlighting (matched text) */
.aa-ItemContent mark {
    background-color: rgba(255, 235, 59, 0.4); /* Light yellow highlight */
    color: inherit;
    font-weight: 600;
    padding: 0;
}

/* ========================================================================
   Search Categories/Filters in Results
   ======================================================================== */

.aa-ItemContentCategory {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    background-color: var(--bs-light);
    border-radius: 50rem; /* pill shape */
    color: var(--bs-secondary);
    margin-top: 0.25rem;
}

/* ========================================================================
   Loading State
   ======================================================================== */

.aa-LoadingIndicator {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1rem;
    height: 1rem;
}

.aa-LoadingIndicator svg {
    width: 100%;
    height: 100%;
    animation: aa-spin 1s linear infinite;
}

@keyframes aa-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* ========================================================================
   Empty State / No Results
   ======================================================================== */

.aa-PanelLayout--empty {
    padding: 2rem 1rem;
    text-align: center;
}

.aa-PanelLayout--empty .aa-SourceNoResults {
    color: var(--bs-secondary);
    font-size: 0.875rem;
}

/* ========================================================================
   Footer Actions (View All Results, etc.)
   ======================================================================== */

.aa-SourceFooter {
    padding: 0.75rem;
    border-top: 1px solid var(--bs-border-color);
    background-color: var(--bs-light);
}

.aa-SourceFooter a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #fff;
    text-decoration: none;
    border-radius: 0.375rem;
    background: linear-gradient(to bottom, #FFC400, #FF7600);
    border: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 2px 4px rgba(255, 118, 0, 0.3);
}

.aa-SourceFooter a:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(255, 118, 0, 0.4);
    color: #fff;
}

/* ========================================================================
   Responsive Adjustments
   ======================================================================== */

/* Mobile panel adjustments */
@media (max-width: 991.98px) {
    .aa-Panel {
        max-height: 70vh;
        overflow-y: auto;
    }
    
    .aa-ItemIcon {
        width: 40px;
        height: 40px;
    }
}

/* Tablet and desktop */
@media (min-width: 992px) {
    .aa-Panel {
        width: 800px; /* Fixed width on desktop */
        max-width: 100%;
    }
}

@media (min-width: 1200px) {
    .aa-Panel {
        width: 900px; /* Larger on XL screens */
    }
}

@media (min-width: 1400px) {
    .aa-Panel {
        width: 1000px; /* Even larger on XXL screens */
    }
}

/* ========================================================================
   Detached Mode (Fullscreen on mobile)
   ======================================================================== */

.aa-DetachedContainer {
    background-color: var(--bs-body-bg);
    height: 100vh;
    overflow: hidden;
}

.aa-DetachedFormContainer {
    padding: 1rem;
    border-bottom: 1px solid var(--bs-border-color);
    background-color: var(--bs-body-bg);
}

.aa-DetachedCancelButton {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    color: var(--bs-primary);
    background: transparent;
    border: none;
    cursor: pointer;
    font-weight: 500;
}

.aa-DetachedCancelButton:hover {
    opacity: 0.8;
}

/* ========================================================================
   Cartzilla Icon Integration
   ======================================================================== */

/* Use Cartzilla icons where appropriate */
.aa-ItemIcon .ci-shopping-cart,
.aa-ItemIcon .ci-star,
.aa-ItemIcon .ci-tag {
    font-size: 1.5rem;
    color: var(--bs-secondary);
}

/* Badge styling for sale/new/etc */
.aa-ItemBadge {
    position: absolute;
    top: 0.25rem;
    left: 0.25rem;
    padding: 0.125rem 0.375rem;
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    border-radius: 0.25rem;
    background-color: var(--bs-primary);
    color: #fff;
}

.aa-ItemBadge.badge-new {
    background-color: var(--bs-success);
}

.aa-ItemBadge.badge-sale {
    background: linear-gradient(to bottom, #FFC400, #FF7600);
}

/* Gradient button for "View Details" / "Add to Cart" actions */
.algolia-search-cartzilla .aa-ItemAction,
.algolia-search-cartzilla .aa-product-action,
.aa-Panel .aa-show-all-button,
.aa-Panel .aa-full-search-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--algolia-spacing-sm) var(--algolia-spacing);
    font-size: var(--algolia-font-size-sm);
    font-weight: var(--algolia-font-weight-semibold);
    color: #fff;
    text-decoration: none;
    border-radius: var(--algolia-border-radius-sm);
    background: linear-gradient(to bottom, var(--algolia-gradient-start), var(--algolia-gradient-end));
    border: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: var(--algolia-shadow-orange);
    cursor: pointer;
}

.algolia-search-cartzilla .aa-ItemAction:hover,
.algolia-search-cartzilla .aa-product-action:hover,
.aa-Panel .aa-show-all-button:hover,
.aa-Panel .aa-full-search-button:hover {
    transform: translateY(-1px);
    box-shadow: var(--algolia-shadow-orange-hover);
    color: #fff;
}

/* ========================================================================
   Performance Optimizations
   ======================================================================== */

/* Hardware acceleration for smooth animations */
.aa-Panel,
.aa-Item {
    will-change: transform;
    transform: translateZ(0);
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    .aa-Input,
    .aa-Item,
    .aa-LoadingIndicator svg {
        transition: none;
        animation: none;
    }
}
