/**
 * Search Autocomplete Styles
 * Works with both Algolia and Native WP search
 * Modern design with Bootstrap 5.3.3 Placeholder component
 *
 * @package Traveler_Child
 * @since 1.0.0
 */

/* Results container */
.pca-autocomplete-results,
.algolia-autocomplete .aa-dropdown-menu {
    /* Using fixed positioning to escape overflow:hidden containers */
    position: fixed !important;
    background: var(--color-background);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--color-border);
    margin-top: 4px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 999999 !important; /* Very high to ensure it's above everything */
    font-family: var(--font-body);
    /* Position will be set by JavaScript to align with input */

    /* Smooth appearance */
    animation: slideDown 0.2s ease-out;
    transform-origin: top;
}

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

/* Smooth scrolling in results */
.pca-autocomplete-results {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Result item */
.pca-result-item,
.aa-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--color-border);
    min-height: 56px;
    transition: background-color 0.15s ease, transform 0.1s ease;
    cursor: pointer;
}

.pca-result-item:last-of-type:not(.pca-see-all) {
    border-bottom: none;
}

/* Hover state - subtle lift effect */
.pca-result-item:hover,
.aa-item:hover,
.pca-result-item.pca-active,
.aa-item[aria-selected="true"] {
    background: var(--color-background-light);
    transform: translateX(2px);
}

/* Active state for keyboard navigation - more prominent */
.pca-result-item.pca-active {
    background: var(--color-background-muted);
    border-left: 3px solid var(--color-primary);
    padding-left: calc(var(--space-md) - 3px);
}

/* Thumbnail/Icon */
.pca-thumb,
.pca-icon,
.aa-thumb,
.aa-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 44px;
    overflow: hidden;
    background: var(--color-background-muted);
}

.pca-thumb img,
.aa-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pca-icon,
.aa-icon {
    color: var(--color-muted);
}

.pca-icon svg,
.aa-icon svg {
    width: 20px;
    height: 20px;
}

/* Text content */
.pca-text,
.aa-text {
    min-width: 0;
    flex: 1;
}

.pca-title,
.aa-title {
    font-weight: var(--weight-semibold);
    font-size: var(--fs-sm);
    line-height: var(--lh-snug);
    color: var(--color-heading);
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.pca-sub,
.aa-sub {
    display: block;
    margin-top: 2px;
    font-size: var(--fs-xs);
    color: var(--color-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Tail chevron - using SVG now for better rendering */
.pca-tail,
.aa-tail {
    opacity: 0.4;
    color: var(--color-muted);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.pca-result-item:hover .pca-tail,
.pca-result-item.pca-active .pca-tail {
    opacity: 0.7;
    transform: translateX(2px);
}

/* See all link */
.pca-see-all,
.aa-seeall {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-md);
    font-weight: var(--weight-semibold);
    font-size: var(--fs-sm);
    color: var(--color-primary);
    text-decoration: none;
    border-top: 1px solid var(--color-border);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.pca-see-all:hover,
.aa-seeall:hover {
    background: #eff6ff;
    color: var(--color-primary-hover);
}

.pca-see-all svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.pca-see-all strong {
    font-weight: var(--weight-bold);
}

/* Loading/Empty/Error states */
.pca-no-results,
.pca-error {
    padding: var(--space-2xl) var(--space-md);
    text-align: center;
    color: var(--color-muted);
}

.pca-no-results svg,
.pca-error svg {
    width: 32px;
    height: 32px;
    margin: 0 auto var(--space-md);
    opacity: 0.5;
}

.pca-no-results p,
.pca-error p {
    font-size: var(--fs-sm);
    margin: 0 0 var(--space-md);
    color: var(--color-muted);
}

.pca-browse-all {
    display: inline-flex;
    align-items: center;
    padding: var(--space-xs) var(--space-md);
    font-size: var(--fs-sm);
    font-weight: var(--weight-semibold);
    color: var(--color-primary);
    text-decoration: none;
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-md);
    transition: all 0.15s ease;
}

.pca-browse-all:hover {
    background: var(--color-primary);
    color: white;
}

/* Skeleton Loading State - Bootstrap Placeholder */
.pca-skeleton-loading {
    pointer-events: none;
}

.pca-skeleton-item {
    cursor: default;
    pointer-events: none;
}

.pca-skeleton-item:hover {
    background: transparent;
    transform: none;
}

/* Bootstrap Placeholder glow animation override for consistency */
.pca-skeleton-item .placeholder-glow .placeholder {
    animation: placeholder-glow 2s ease-in-out infinite;
}

@keyframes placeholder-glow {
    50% {
        opacity: 0.2;
    }
}

/* Skeleton thumb placeholder */
.pca-skeleton-item .pca-thumb .placeholder {
    background-color: var(--color-background-muted);
    border-radius: var(--radius-md);
}

/* Skeleton text placeholders */
.pca-skeleton-item .pca-text .placeholder {
    background-color: var(--color-background-muted);
    border-radius: var(--radius-sm);
    display: block;
}

.pca-skeleton-item .pca-title.placeholder {
    height: 14px;
    margin-bottom: 6px;
}

.pca-skeleton-item .pca-sub.placeholder {
    height: 12px;
}

/* Skeleton tail placeholder */
.pca-skeleton-item .pca-tail .placeholder {
    background-color: var(--color-background-muted);
    border-radius: 2px;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .pca-autocomplete-results,
    .algolia-autocomplete .aa-dropdown-menu {
        /* On mobile, allow taller dropdown */
        max-height: 60vh;
    }

    .pca-result-item,
    .aa-item {
        min-height: 64px;
        padding: var(--space-sm) var(--space-md);
        gap: var(--space-sm);
    }

    .pca-thumb,
    .pca-icon,
    .aa-thumb,
    .aa-icon {
        width: 48px;
        height: 48px;
        flex: 0 0 48px;
    }

    .pca-title,
    .aa-title {
        font-size: 15px;
    }

    .pca-sub,
    .aa-sub {
        font-size: 13px;
    }

    /* Larger touch targets */
    .pca-see-all,
    .aa-seeall {
        padding: var(--space-md) var(--space-lg);
        font-size: 15px;
    }
}

/* Focus visible for accessibility */
.pca-result-item:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .pca-autocomplete-results {
        animation: none;
    }

    .pca-result-item,
    .pca-tail,
    .pca-see-all {
        transition: none;
    }

    .pca-skeleton-item .placeholder-glow .placeholder {
        animation: none;
        opacity: 0.5;
    }
}

/* Scrollbar styling for better UX */
.pca-autocomplete-results::-webkit-scrollbar {
    width: 6px;
}

.pca-autocomplete-results::-webkit-scrollbar-track {
    background: transparent;
}

.pca-autocomplete-results::-webkit-scrollbar-thumb {
    background: var(--color-border-muted);
    border-radius: 3px;
}

.pca-autocomplete-results::-webkit-scrollbar-thumb:hover {
    background: var(--color-muted);
}
