/* ==========================================================================
   Ajax Product Search - Frontend Styles
   ========================================================================== */

/* CSS Variables (defaults - overridden by PHP) */
:root {
    --aps-bg-overlay: rgba(0, 0, 0, 0.95);
    --aps-bg-content: #ffffff;
    --aps-text-colour: #333333;
    --aps-accent-colour: #2563eb;
    --aps-close-colour: #ffffff;
    --aps-columns-desktop: 4;
    --aps-columns-tablet: 3;
    --aps-columns-mobile: 2;
}

/* ==========================================================================
   Popup Container
   ========================================================================== */

.aps-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2147483647 !important;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.aps-popup.aps-active {
    opacity: 1;
    visibility: visible;
}

/* Animation Variants */
.aps-popup.aps-animation-fade .aps-popup-container {
    transition: opacity 0.3s ease;
}

.aps-popup.aps-animation-slide .aps-popup-container {
    transform: translateY(-30px);
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.aps-popup.aps-animation-slide.aps-active .aps-popup-container {
    transform: translateY(0);
}

.aps-popup.aps-animation-scale .aps-popup-container {
    transform: scale(0.95);
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.aps-popup.aps-animation-scale.aps-active .aps-popup-container {
    transform: scale(1);
}

.aps-popup.aps-animation-none .aps-popup-container,
.aps-popup.aps-animation-none {
    transition: none;
}

/* Overlay */
.aps-popup-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--aps-bg-overlay);
}

/* ==========================================================================
   Popup Content Container
   ========================================================================== */

.aps-popup-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.aps-popup-content {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 50px 40px 40px;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    backdrop-filter: blur(3px);
}

.aps-search-input::placeholder {
    opacity: 1 !important;
    transition: none !important;
}

.aps-search-input:focus::placeholder {
    opacity: 1 !important;
    transition: none !important;
}

.aps-search-input:-webkit-autofill::placeholder {
    opacity: 1 !important;
}
.aps-results-count {
    font-size: 14px;
    color: var(--aps-text-colour);
    opacity: 0.7;
    margin-right: 16px;
}

@media (max-width: 768px) {
    .aps-results-count {
        font-size: 12px;
        margin-right: 12px;
    }
}

/* ==========================================================================
   Close Button
   ========================================================================== */

.aps-close {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 10;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 10px;
    color: var(--aps-close-colour);
    transition: transform 0.2s ease, opacity 0.2s ease;
    line-height: 1;
}

.aps-close:hover {
    transform: scale(1.1);
    opacity: 0.8;
    background: var(--aps-accent-colour);
    border-radius: 50%;
    color: wheat;
}

.aps-close:focus {
    outline: 2px solid var(--aps-accent-colour);
    outline-offset: 2px;
}

.aps-close svg {
    display: block;
}

/* ==========================================================================
   Search Input
   ========================================================================== */

.aps-search-wrapper {
    flex-shrink: 0;
    margin-bottom: 24px;
}

.aps-search-input-container {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--aps-bg-content);
    border-radius: 16px;
    padding: 0 24px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}

.aps-search-icon {
    flex-shrink: 0;
    color: #9ca3af;
    margin-right: 16px;
}

.aps-search-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 24px;
    font-weight: 600;
    color: var(--aps-text-colour);
    padding: 15px 0!important;
    outline: none;
    width: 100%;
    position: relative !important;
    z-index: 2147483647 !important;
}

.aps-search-input::placeholder {
    color: #5f646b;
    font-size: 18px;
}

.aps-search-input:focus {
    outline: none;
}

.aps-sort-wrapper {
    flex-shrink: 0;
    margin-top: 16px;
}

.aps-sort-select {
    background: transparent;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px 36px 12px 16px;
    font-size: 14px;
    color: var(--aps-text-colour);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    max-width: 250px;
}

.aps-sort-wrapper {
    display: none;
}

.aps-sort-wrapper.aps-visible {
    display: flex;
    justify-content: space-between;
    align-items: center;
    align-content: center;
    align-self: center;
}

.aps-sort-select:focus {
    outline: 2px solid var(--aps-accent-colour);
    outline-offset: 2px;
}

@media (max-width: 768px) {
    .aps-search-input-container {
        flex-wrap: wrap;
    }
    
    .aps-sort-wrapper {
        width: 100%;
        margin-left: 0;
        margin-top: 12px;
    }
    
    .aps-sort-select {
        width: 100%;
    }
}

.aps-clear-input {
    flex-shrink: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: #9ca3af;
    transition: color 0.2s ease;
    line-height: 1;
}

.aps-clear-input:hover {
    color: var(--aps-text-colour);
}

.aps-clear-input svg {
    display: block;
}

/* ==========================================================================
   Popular & Recent Searches
   ========================================================================== */

.aps-popular-searches,
.aps-recent-searches {
    flex-shrink: 0;
    margin-bottom: 24px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
}

.aps-suggestions-label {
    color: var(--aps-text-colour);
    font-size: 14px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-left:5px;
}

.aps-suggestions-list,
.aps-recent-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.aps-suggestion,
.aps-recent-item {
    background: rgb(230 230 230 / 73%);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50px;
    padding: 8px 18px;
    font-size: 14px;
    color: rgb(0 0 0 / 90%);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.aps-suggestion:hover,
.aps-recent-item:hover {
    background: var(--aps-accent-colour);
    border-color: var(--aps-accent-colour);
    color: #ffffff;
}

.aps-suggestion:focus,
.aps-recent-item:focus {
    outline: 2px solid var(--aps-accent-colour);
    outline-offset: 2px;
}

.aps-recent-item-wrapper {
    position: relative;
    display: inline-flex;
}

.aps-recent-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    padding: 0;
    background: rgba(0, 0, 0, 0.662);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    opacity: 1;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.aps-recent-item-wrapper:hover .aps-recent-remove {
    opacity: 1;
}

.aps-recent-remove:hover {
    background: #ef4444;
    color: #ffffff;
}

/* ==========================================================================
   Results Container
   ========================================================================== */

.aps-results-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 10px;
    margin-right: -10px;
}

/* Custom Scrollbar */
.aps-results-container::-webkit-scrollbar {
    width: 6px;
}

.aps-results-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.aps-results-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.aps-results-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

.aps-suggestion {
    transition: opacity 0.2s ease, transform 0.2s ease;
    }

.aps-suggestion.aps-hidden {
    display: none;
}

    .aps-suggestions-toggle {
        background: transparent;
        border: 1px solid rgba(255, 255, 255, 0.3);
        border-radius: 50px;
        padding: 8px 16px;
        font-size: 14px;
        color: var(--aps-text-colour);
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .aps-suggestions-toggle:hover {
    background: var(--aps-accent-colour);
    border-color: var(--aps-accent-colour);
    color: #ffffff;
    }

    @media (max-width: 768px) {
        .aps-suggestions-toggle {
            padding: 6px 14px;
            font-size: 13px;
        }
    }

.aps-product-card:has(.aps-badge-out-of-stock) .aps-product-price {
  display:none;
}

/* ==========================================================================
   Results Grid
   ========================================================================== */

.aps-results-grid {
    display: grid;
    grid-template-columns: repeat(var(--aps-columns-desktop), 1fr);
    gap: 24px;
}

/* ==========================================================================
   Product Card
   ========================================================================== */

.aps-product-card {
    background: var(--aps-bg-content);
    border-radius: 16px;
    overflow: hidden;
    text-decoration: none;
    color: var(--aps-text-colour);
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

.aps-product-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.aps-product-card:focus {
    outline: 3px solid var(--aps-accent-colour);
    outline-offset: 2px;
}

/* Product Image */
.aps-product-image {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    background: #f3f4f6;
}

.aps-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.aps-product-card:hover .aps-product-image img {
    transform: scale(1.05);
}

/* Badges */
.aps-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    z-index: 1;
}

.aps-badge-sale {
    background: var(--aps-accent-colour);
    color: #ffffff;
}

.aps-badge-out-of-stock {
    background: #6b7280;
    color: #ffffff;
    left: auto;
    right: 12px;
}

/* Product Info */
.aps-product-info {
    padding: 16px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.aps-product-name {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
    margin: 0 0 8px;
    color: var(--aps-text-colour);
    text-transform:capitalize;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.aps-product-price {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.aps-price-regular {
    font-size: 16px;
    font-weight: 700;
    color: var(--aps-text-colour);
}

.aps-price-regular.aps-has-sale {
    text-decoration: line-through;
    color: #9ca3af;
    font-weight: 400;
    font-size: 14px;
}

.aps-price-sale {
    font-size: 16px;
    font-weight: 700;
    color: var(--aps-accent-colour);
}

/* ==========================================================================
   Loading State
   ========================================================================== */

.aps-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--aps-accent-colour);
    gap: 16px;
}

.aps-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--aps-accent-colour);
    border-radius: 50%;
    animation: aps-spin 0.8s linear infinite;
}

@keyframes aps-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================================
   No Results
   ========================================================================== */

.aps-no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--aps-text-colour);
    text-align: center;
    gap: 16px;
}

.aps-no-results svg {
    opacity: 0.5;
}

.aps-no-results p {
    font-size: 16px;
    margin: 0;
    max-width: 400px;
}

/* ==========================================================================
   Product Animation
   ========================================================================== */

.aps-product-card {
    opacity: 0;
    transform: translateY(20px);
    animation: aps-fadeInUp 0.3s ease forwards;
}

@keyframes aps-fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Staggered animation delays */
.aps-product-card:nth-child(1) { animation-delay: 0.05s; }
.aps-product-card:nth-child(2) { animation-delay: 0.1s; }
.aps-product-card:nth-child(3) { animation-delay: 0.15s; }
.aps-product-card:nth-child(4) { animation-delay: 0.2s; }
.aps-product-card:nth-child(5) { animation-delay: 0.25s; }
.aps-product-card:nth-child(6) { animation-delay: 0.3s; }
.aps-product-card:nth-child(7) { animation-delay: 0.35s; }
.aps-product-card:nth-child(8) { animation-delay: 0.4s; }
.aps-product-card:nth-child(9) { animation-delay: 0.45s; }
.aps-product-card:nth-child(10) { animation-delay: 0.5s; }
.aps-product-card:nth-child(11) { animation-delay: 0.55s; }
.aps-product-card:nth-child(12) { animation-delay: 0.6s; }

/* ==========================================================================
   Focus Trap Indicator
   ========================================================================== */

.aps-product-card.aps-keyboard-focus {
    outline: 3px solid var(--aps-accent-colour);
    outline-offset: 2px;
}

/* ==========================================================================
   Screen Reader Text
   ========================================================================== */

.screen-reader-text {
    clip: rect(1px, 1px, 1px, 1px);
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
}

/* ==========================================================================
   Body Lock (when popup is open)
   ========================================================================== */

body.aps-popup-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* ==========================================================================
   Responsive Styles
   ========================================================================== */

/* Tablet */
@media (max-width: 1024px) {
    .aps-results-grid {
        grid-template-columns: repeat(var(--aps-columns-tablet), 1fr);
    }
    
    .aps-popup-content {
        padding: 50px 30px 30px;
    }
    
    .aps-search-input {
        font-size: 20px;
        padding: 15px 0!important;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .aps-results-grid {
        grid-template-columns: repeat(var(--aps-columns-mobile), 1fr);
        gap: 16px;
    }
    
    .aps-popup-content {
        padding: 30px 16px 16px;
    }
    
    .aps-close {
        top: 12px;
        right: 12px;
    }
    
    .aps-close svg {
        width: 28px;
        height: 28px;
    }
    
    .aps-search-input-container {
        padding: 0 16px;
        border-radius: 12px;
    }
    
    .aps-search-icon {
        width: 20px;
        height: 20px;
        margin-right: 12px;
    }
    
    .aps-search-input {
        font-size: 18px;
        padding: 10px 0!important;
    }

    .aps-search-input::placeholder {
    font-size: 15px;
    }
    
    .aps-suggestions-label {
        font-size: 12px;
        width: 100%;
        margin-bottom: 4px;
        font-weight:bolder;
    }
    
    .aps-popular-searches,
    .aps-recent-searches {
        gap: 8px;
        margin-bottom: 16px;
    }
    
    .aps-suggestion,
    .aps-recent-item {
        padding: 6px 12px;
        font-size: 12px;
    }

    
    .aps-product-info {
        padding: 12px;
    }
    
    .aps-product-name {
        font-size: 14px;
    }
    
    .aps-price-regular,
    .aps-price-sale {
        font-size: 14px;
    }
    
    .aps-badge {
        padding: 4px 8px;
        font-size: 10px;
        top: 8px;
        left: 8px;
    }
    
    .aps-badge-out-of-stock {
        right: 8px;
        left: auto;
    }
}

.aps-search-input {
    pointer-events: auto !important;
    user-select: auto !important;
    -webkit-user-select: auto !important;
    touch-action: auto !important;
}

/* Small mobile */
@media (max-width: 400px) {
    .aps-search-input {
        font-size: 16px;
    }
}
