/**
 * AO Search App - Minimal Theme-Inheriting CSS
 * 
 * This CSS ONLY handles the search overlay layout.
 * All product card styling is inherited from WoodMart theme.
 * 
 * @package Appearance_Overrides
 * @version 5.0.0
 */

/* ========================================
   CSS Variables - Only for overlay UI
======================================== */
:root {
    --ao-overlay-bg: #fff;
    --ao-header-bg: #fff;
    --ao-body-bg: #f5f5f5;
    --ao-border-color: #e5e5e5;
    --ao-grid-gap: 20px;
}

/* ========================================
   Overlay - Full Screen
======================================== */
.ao-search-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: var(--ao-overlay-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: aoFadeIn 0.15s ease-out;
}

.ao-search-panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: var(--ao-overlay-bg);
    overflow: hidden;
}

@keyframes aoFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

body.ao-search-open {
    overflow: hidden !important;
}

/* ========================================
   Search Header
======================================== */
.ao-search-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--ao-header-bg);
    border-bottom: 1px solid var(--ao-border-color);
    flex-shrink: 0;
}

@media (min-width: 768px) {
    .ao-search-header {
        padding: 16px 24px;
    }
}

@media (min-width: 1024px) {
    .ao-search-header {
        padding: 16px 32px;
    }
}

/* Search Input - Use theme colors */
.ao-search-input-container {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--wd-bgcolor-shop, #f5f5f5);
    border: 1px solid var(--ao-border-color);
    border-radius: var(--wd-form-brd-radius, 0);
    padding: 0 14px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.ao-search-input-container:focus-within {
    border-color: var(--wd-primary-color, #333);
    box-shadow: 0 0 0 1px var(--wd-primary-color, #333);
}

.ao-search-icon-svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    color: #999;
}

.ao-search-input {
    flex: 1;
    height: 44px;
    padding: 0;
    font-size: 16px;
    font-family: inherit;
    border: none;
    background: transparent;
    outline: none;
    color: inherit;
}

.ao-search-input::placeholder {
    color: #999;
}

.ao-search-input::-webkit-search-cancel-button {
    display: none;
}

/* Clear Button */
.ao-clear-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: #e0e0e0;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: #666;
    font-size: 14px;
    transition: background 0.15s;
}

.ao-clear-btn:hover {
    background: #ccc;
    color: #333;
}

/* Close Button - Match theme style */
.ao-close-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--ao-border-color);
    border-radius: var(--wd-form-brd-radius, 0);
    cursor: pointer;
    color: #666;
    font-size: 24px;
    font-weight: 300;
    transition: all 0.15s;
}

.ao-close-btn:hover {
    background: #f5f5f5;
    color: #333;
}

.ao-close-text,
.ao-close-key {
    display: none;
}

/* Loading Spinner */
.ao-search-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e0e0e0;
    border-top-color: var(--wd-primary-color, #333);
    border-radius: 50%;
    animation: aoSpin 0.6s linear infinite;
}

@keyframes aoSpin {
    to { transform: rotate(360deg); }
}

/* ========================================
   Search Body
======================================== */
.ao-search-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: var(--ao-body-bg);
}

@media (min-width: 768px) {
    .ao-search-body {
        padding: 20px 24px;
    }
}

@media (min-width: 1024px) {
    .ao-search-body {
        padding: 24px 32px;
    }
}

.ao-search-body > * {
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
}

.ao-search-content {
    max-width: 1400px;
    margin: 0 auto;
}

/* ========================================
   Popular/Trending Searches
======================================== */
.ao-popular-searches,
.ao-popular-section,
.ao-trending-section {
    margin-bottom: 20px;
}

.ao-popular-searches h4,
.ao-popular-section h4,
.ao-trending-section h4 {
    margin: 0 0 10px;
    font-size: 12px;
    font-weight: 500;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ao-popular-tags,
.ao-popular-list,
.ao-trending-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ao-popular-tag,
.ao-popular-term {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    background: #fff;
    border: 1px solid var(--ao-border-color);
    border-radius: var(--wd-form-brd-radius, 0);
    font-size: 13px;
    color: #333;
    cursor: pointer;
    transition: all 0.15s;
}

.ao-popular-tag:hover,
.ao-popular-term:hover {
    background: var(--wd-primary-color, #333);
    border-color: var(--wd-primary-color, #333);
    color: #fff;
}

.ao-trending-term {
    background: var(--wd-primary-color, #333);
    border-color: var(--wd-primary-color, #333);
    color: #fff;
}

/* ========================================
   Search Results
======================================== */
.ao-search-results {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Category Chips */
.ao-category-suggestions,
.ao-category-section {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--ao-border-color);
}

.ao-suggestions-label {
    font-size: 12px;
    font-weight: 500;
    color: #888;
    text-transform: uppercase;
}

.ao-category-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    background: #fff;
    border: 1px solid var(--ao-border-color);
    border-radius: var(--wd-form-brd-radius, 0);
    font-size: 12px;
    color: #555;
    cursor: pointer;
    transition: all 0.15s;
}

.ao-category-chip:hover {
    background: var(--wd-primary-color, #333);
    border-color: var(--wd-primary-color, #333);
    color: #fff;
}

.ao-cat-count {
    font-size: 10px;
    color: #999;
    background: #f0f0f0;
    padding: 1px 4px;
    border-radius: 2px;
}

.ao-category-chip:hover .ao-cat-count {
    background: rgba(255,255,255,0.2);
    color: #fff;
}

/* ========================================
   Search Toolbar
======================================== */
.ao-search-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--ao-border-color);
    margin-bottom: 16px;
}

.ao-results-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ao-results-count {
    font-size: 13px;
    color: #666;
}

.ao-results-count strong {
    color: #333;
}

.ao-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ao-engine-badge {
    display: inline-flex;
    padding: 3px 8px;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    border-radius: 2px;
}

.ao-engine-meili {
    background: #ff2277;
    color: #fff;
}

.ao-engine-cache {
    background: #16a34a;
    color: #fff;
}

.ao-search-time {
    font-size: 11px;
    color: #999;
}

.ao-view-all-link {
    font-size: 12px;
    padding: 6px 12px;
    background: var(--wd-primary-color, #333);
    color: #fff;
    text-decoration: none;
    border-radius: var(--wd-form-brd-radius, 0);
    transition: opacity 0.15s;
}

.ao-view-all-link:hover {
    opacity: 0.85;
    color: #fff;
}

/* ========================================
   Product Grid - MINIMAL, inherits WoodMart
======================================== */
.ao-instant-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--ao-grid-gap) !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    list-style: none !important;
}

@media (min-width: 576px) {
    .ao-instant-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

@media (min-width: 992px) {
    .ao-instant-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

@media (min-width: 1200px) {
    .ao-instant-grid {
        grid-template-columns: repeat(5, 1fr) !important;
    }
}

/* Reset any width constraints on products */
.ao-instant-grid .product,
.ao-instant-grid .wd-product {
    width: 100% !important;
    margin: 0 !important;
    float: none !important;
}

/* Ensure images work in grid context */
.ao-instant-grid .product-image-link {
    display: block;
    position: relative;
}

.ao-instant-grid .product-image-link img {
    width: 100%;
    height: auto;
}

/* No-image placeholder */
.ao-instant-grid .ao-no-image {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    background: #f5f5f5;
    color: #999;
    font-size: 12px;
}

/* ========================================
   Loading State
======================================== */
.ao-loading-more {
    display: flex;
    justify-content: center;
    padding: 24px;
}

.ao-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e0e0e0;
    border-top-color: var(--wd-primary-color, #333);
    border-radius: 50%;
    animation: aoSpin 0.8s linear infinite;
}

/* ========================================
   No Results
======================================== */
.ao-no-results {
    text-align: center;
    padding: 48px 20px;
}

.ao-no-results-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    color: #ccc;
}

.ao-no-results h3 {
    margin: 0 0 8px;
    font-size: 16px;
    color: #333;
}

.ao-no-results p {
    margin: 0;
    font-size: 14px;
    color: #888;
}

/* ========================================
   Cart Toast
======================================== */
.ao-cart-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #1f2937;
    color: #fff;
    padding: 12px 16px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 1000001;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.2s, transform 0.2s;
    max-width: 320px;
    font-size: 13px;
}

.ao-cart-toast.ao-toast-show {
    opacity: 1;
    transform: translateY(0);
}

.ao-toast-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: #22c55e;
    border-radius: 50%;
    font-size: 12px;
    flex-shrink: 0;
}

.ao-toast-text {
    flex: 1;
    line-height: 1.3;
}

.ao-toast-link {
    color: var(--wd-primary-color, #60a5fa);
    text-decoration: none;
    font-weight: 500;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .ao-cart-toast {
        left: 12px;
        right: 12px;
        bottom: 12px;
        max-width: none;
    }
}

/* ========================================
   Price Loading (B2B)
======================================== */
.ao-price-skeleton {
    display: inline-block;
    width: 50px;
    height: 16px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: aoShimmer 1.5s infinite;
    border-radius: 2px;
}

@keyframes aoShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.ao-price-updated {
    animation: aoPriceFlash 0.4s ease;
}

@keyframes aoPriceFlash {
    0% { background-color: rgba(34, 197, 94, 0.15); }
    100% { background-color: transparent; }
}

/* ========================================
   Mobile Responsive
======================================== */
@media (max-width: 767px) {
    .ao-search-overlay {
        height: 100dvh;
    }
    
    .ao-search-header {
        padding: 10px 12px;
        gap: 10px;
    }
    
    .ao-close-btn {
        width: 40px;
        height: 40px;
    }
    
    .ao-search-input {
        font-size: 16px; /* Prevent iOS zoom */
    }
    
    .ao-search-body {
        padding: 12px;
    }
    
    .ao-search-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
}

/* Touch devices - disable hover effects */
@media (hover: none) {
    .ao-instant-grid .product:hover {
        transform: none;
        box-shadow: none;
    }
}

/* ========================================
   Search History
======================================== */
.ao-search-history {
    background: #fff;
    border-radius: var(--wd-form-brd-radius, 0);
    padding: 10px 12px;
    margin-bottom: 12px;
    border: 1px solid var(--ao-border-color);
}

.ao-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.ao-history-label {
    font-size: 11px;
    color: #888;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ao-history-clear {
    font-size: 11px;
    color: #999;
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 4px;
}

.ao-history-clear:hover {
    color: #333;
}

.ao-history-items {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ao-history-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: #f5f5f5;
    border-radius: var(--wd-form-brd-radius, 0);
    font-size: 12px;
    color: #555;
    cursor: pointer;
    transition: background 0.15s;
}

.ao-history-item:hover {
    background: #e5e5e5;
}

/* ========================================
   Print - Hide overlay
======================================== */
@media print {
    .ao-search-overlay {
        display: none !important;
    }
}
