/* Vanilla Autocomplete CSS - No jQuery Dependencies */

/* Reset and base styles */
.vanilla-search-wrapper,
.vanilla-search-category-filter {
    box-sizing: border-box;
}

.vanilla-search-wrapper *,
.vanilla-search-category-filter * {
    box-sizing: border-box;
}

/* Search input focus states */
.vanilla-search-wrapper .search-input:focus {
    outline: none;
}

.vanilla-category-select:focus {
    outline: none;
}

/* Dropdown animations */
.autocomplete-dropdown {
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

.autocomplete-dropdown.tw-opacity-100 {
    pointer-events: all;
}

.autocomplete-dropdown:not(.tw-opacity-100) {
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
}

.autocomplete-dropdown.tw-opacity-100 {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Suggestion item hover states */
.suggestion-item {
    transition: background-color 0.15s ease;
}

.suggestion-item:hover,
.suggestion-item.selected {
    background-color: rgba(249, 250, 251, 1); /* tw-bg-gray-50 */
}

.suggestion-item.selected {
    background-color: rgba(239, 246, 255, 1); /* tw-bg-blue-50 */
}

/* Clear button states */
.clear-btn {
    transition: color 0.15s ease;
}

.clear-btn:hover {
    color: rgba(75, 85, 99, 1); /* tw-text-gray-600 */
}

/* Loading spinner animation */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spinner {
    animation: spin 1s linear infinite;
}

/* Search button hover states */
.search-filter-btn {
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.search-filter-btn:hover {
    background-color: rgba(29, 78, 216, 1); /* tw-bg-blue-700 */
}

.search-filter-btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(219, 234, 254, 1); /* tw-ring-blue-100 */
}

/* Visit button states */
.visit-btn {
    transition: color 0.15s ease;
}

.visit-btn:hover {
    color: rgba(37, 99, 235, 1); /* tw-text-blue-600 */
}

/* Category select styling */
.vanilla-category-select {
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
}

.vanilla-category-select:hover {
    border-color: rgba(209, 213, 219, 1); /* tw-border-gray-300 */
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.vanilla-category-select:focus {
    border-color: rgba(156, 163, 175, 1); /* tw-border-gray-400 */
    box-shadow: 0 0 0 2px rgba(243, 244, 246, 1); /* tw-ring-gray-100 */
}

/* Suggestion header styling */
.suggestion-header {
    background-color: rgba(249, 250, 251, 1); /* tw-bg-gray-50 */
    border-bottom: 1px solid rgba(229, 231, 235, 1); /* tw-border-gray-200 */
}

/* Highlighted text in suggestions */
.suggestion-item mark {
    background-color: rgba(254, 240, 138, 1); /* tw-bg-yellow-200 */
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
}

/* Responsive adjustments */
@media (max-width: 640px) {
    .vanilla-search-wrapper .search-input,
    .vanilla-category-select {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }
    
    .vanilla-search-wrapper .search-input {
        padding-left: 2.75rem; /* Account for search icon */
        padding-right: 2.75rem; /* Account for clear button */
    }
    
    .suggestion-item {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }
    
    .search-filter-btn {
        padding: 0.75rem 1.5rem;
        font-size: 0.875rem;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .vanilla-search-wrapper .search-input,
    .vanilla-category-select {
        border-width: 2px;
        border-color: rgba(55, 65, 81, 1); /* tw-border-gray-700 */
    }
    
    .autocomplete-dropdown {
        border-width: 2px;
        border-color: rgba(55, 65, 81, 1);
    }
    
    .suggestion-item:hover,
    .suggestion-item.selected {
        background-color: rgba(55, 65, 81, 1);
        color: white;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .autocomplete-dropdown,
    .suggestion-item,
    .clear-btn,
    .search-filter-btn,
    .visit-btn,
    .vanilla-category-select {
        transition: none;
    }
    
    .spinner {
        animation: none;
    }
}

/* Dark mode support (if using with WordPress dark mode themes) */
@media (prefers-color-scheme: dark) {
    .vanilla-search-dark .search-input,
    .vanilla-search-dark .vanilla-category-select {
        background-color: rgba(55, 65, 81, 1); /* tw-bg-gray-700 */
        border-color: rgba(75, 85, 99, 1); /* tw-border-gray-600 */
        color: rgba(249, 250, 251, 1); /* tw-text-gray-50 */
    }
    
    .vanilla-search-dark .autocomplete-dropdown {
        background-color: rgba(55, 65, 81, 1);
        border-color: rgba(75, 85, 99, 1);
    }
    
    .vanilla-search-dark .suggestion-item {
        color: rgba(249, 250, 251, 1);
    }
    
    .vanilla-search-dark .suggestion-item:hover,
    .vanilla-search-dark .suggestion-item.selected {
        background-color: rgba(75, 85, 99, 1);
    }
    
    .vanilla-search-dark .search-icon svg,
    .vanilla-search-dark .clear-btn svg {
        color: rgba(156, 163, 175, 1); /* tw-text-gray-400 */
    }
}

/* Print styles */
@media print {
    .autocomplete-dropdown,
    .search-filter-btn,
    .clear-btn {
        display: none !important;
    }
}

/* Focus visible for better accessibility */
.vanilla-search-wrapper .search-input:focus-visible,
.vanilla-category-select:focus-visible,
.search-filter-btn:focus-visible {
    outline: 2px solid rgba(59, 130, 246, 1); /* tw-blue-500 */
    outline-offset: 2px;
}

/* Smooth scrolling for dropdown */
.autocomplete-dropdown {
    scroll-behavior: smooth;
}

/* Loading state styles */
.loading-state {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: .5;
    }
}

/* Error state styles */
.suggestion-item.error {
    background-color: rgba(254, 242, 242, 1); /* tw-bg-red-50 */
    color: rgba(185, 28, 28, 1); /* tw-text-red-700 */
}

/* Success state styles */
.suggestion-item.success {
    background-color: rgba(240, 253, 244, 1); /* tw-bg-green-50 */
    color: rgba(21, 128, 61, 1); /* tw-text-green-700 */
}

/* Utility classes for JavaScript manipulation */
.hidden {
    display: none !important;
}

.visible {
    display: block !important;
}

/* Custom scrollbar for dropdown */
.autocomplete-dropdown::-webkit-scrollbar {
    width: 6px;
}

.autocomplete-dropdown::-webkit-scrollbar-track {
    background: rgba(243, 244, 246, 1); /* tw-bg-gray-100 */
}

.autocomplete-dropdown::-webkit-scrollbar-thumb {
    background: rgba(209, 213, 219, 1); /* tw-bg-gray-300 */
    border-radius: 3px;
}

.autocomplete-dropdown::-webkit-scrollbar-thumb:hover {
    background: rgba(156, 163, 175, 1); /* tw-bg-gray-400 */
}

/* Firefox scrollbar */
.autocomplete-dropdown {
    scrollbar-width: thin;
    scrollbar-color: rgba(209, 213, 219, 1) rgba(243, 244, 246, 1);
}

/* Ensure proper stacking order */
.vanilla-search-wrapper {
    z-index: 1;
}

.autocomplete-dropdown {
    z-index: 50;
}

/* Animation for suggestion items appearing */
.suggestion-item {
    animation: fadeInUp 0.2s ease forwards;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Delay animation for staggered effect */
.suggestion-item:nth-child(1) { animation-delay: 0.05s; }
.suggestion-item:nth-child(2) { animation-delay: 0.1s; }
.suggestion-item:nth-child(3) { animation-delay: 0.15s; }
.suggestion-item:nth-child(4) { animation-delay: 0.2s; }
.suggestion-item:nth-child(5) { animation-delay: 0.25s; }
.suggestion-item:nth-child(6) { animation-delay: 0.3s; }
.suggestion-item:nth-child(7) { animation-delay: 0.35s; }
.suggestion-item:nth-child(8) { animation-delay: 0.4s; }

/* Disable animations for reduced motion */
@media (prefers-reduced-motion: reduce) {
    .suggestion-item {
        animation: none;
    }
}

/* Form integration styles */
.vanilla-search-category-filter form {
    margin: 0;
}

.vanilla-search-category-filter .tw-flex {
    align-items: flex-end;
}

/* Button group styles for horizontal layout */
.vanilla-search-category-filter.horizontal .search-filter-btn {
    white-space: nowrap;
}

/* Vertical layout adjustments */
.vanilla-search-category-filter.vertical .search-filter-btn {
    width: 100%;
    justify-content: center;
}

/* Icon alignment */
.search-icon,
.clear-btn {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Ensure icons don't shrink */
.search-icon svg,
.clear-btn svg,
.visit-btn svg {
    flex-shrink: 0;
}

/* Type icon styling */
.suggestion-item .tw-flex-shrink-0 svg {
    flex-shrink: 0;
}

/* Truncate long suggestion text */
.suggestion-item .tw-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Ensure proper spacing in suggestion items */
.suggestion-item .tw-flex-1 {
    min-width: 0;
    flex: 1 1 0%;
}

/* Search filter button states */
.search-filter-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.search-filter-btn:disabled:hover {
    background-color: rgba(37, 99, 235, 1); /* Keep original blue color */
}

/* Loading overlay for search results */
.search-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* Suggestion item content alignment */
.suggestion-item .tw-justify-between {
    justify-content: space-between;
}

.suggestion-item .tw-space-x-2 > * + * {
    margin-left: 0.5rem;
}

/* Hover effects for interactive elements */
.visit-btn:hover svg {
    transform: scale(1.1);
    transition: transform 0.1s ease;
}

/* Clear button visibility */
.clear-btn.tw-hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

.clear-btn:not(.tw-hidden) {
    opacity: 1;
    pointer-events: all;
    transform: scale(1);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

/* Input field states */
.search-input::-webkit-search-cancel-button {
    display: none;
}

.search-input::-webkit-search-decoration {
    display: none;
}

/* Placeholder styling */
.search-input::placeholder,
.vanilla-category-select option:first-child {
    color: rgba(156, 163, 175, 1); /* tw-text-gray-400 */
}

/* Focus ring improvements */
.search-input:focus,
.vanilla-category-select:focus,
.search-filter-btn:focus {
    box-shadow: 0 0 0 2px rgba(243, 244, 246, 1); /* tw-ring-gray-100 */
}

/* Ensure dropdown appears above other content */
.vanilla-search-wrapper {
    position: relative;
    z-index: 1;
}

.autocomplete-dropdown {
    position: absolute;
    z-index: 1000;
}

/* Responsive text sizing */
@media (max-width: 768px) {
    .suggestion-header {
        font-size: 0.75rem;
        padding: 0.5rem 1rem;
    }
    
    .suggestion-item .tw-text-sm {
        font-size: 0.8125rem;
    }
    
    .suggestion-item .tw-text-xs {
        font-size: 0.6875rem;
    }
}

/* Improve touch targets on mobile */
@media (max-width: 640px) {
    .suggestion-item {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    .clear-btn,
    .visit-btn {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .search-filter-btn {
        min-height: 44px;
    }
}

/* Container max-width for very wide screens */
@media (min-width: 1536px) {
    .vanilla-search-category-filter {
        max-width: none;
    }
}

/* Print-friendly styles */
@media print {
    .vanilla-search-wrapper,
    .vanilla-search-category-filter {
        break-inside: avoid;
    }
    
    .search-input,
    .vanilla-category-select {
        border: 1px solid #000 !important;
        background: white !important;
        color: black !important;
    }
}

/* Accessibility improvements */
.suggestion-item[aria-selected="true"] {
    background-color: rgba(239, 246, 255, 1); /* tw-bg-blue-50 */
    outline: 2px solid rgba(59, 130, 246, 1); /* tw-blue-500 */
    outline-offset: -2px;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* High DPI display support */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .search-icon svg,
    .clear-btn svg,
    .visit-btn svg {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Custom focus styles for better visibility */
.vanilla-search-wrapper:focus-within .search-input {
    border-color: rgba(99, 102, 241, 1); /* tw-border-indigo-500 */
}

/* Animation cleanup */
.suggestion-item.removing {
    animation: fadeOutDown 0.2s ease forwards;
}

@keyframes fadeOutDown {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(10px);
    }
}

/* Ensure proper line height for text */
.suggestion-item {
    line-height: 1.5;
}

.suggestion-item .tw-text-sm {
    line-height: 1.4;
}

.suggestion-item .tw-text-xs {
    line-height: 1.3;
}

/* Final cleanup and overrides */
.vanilla-search-wrapper *,
.vanilla-search-category-filter * {
    box-sizing: border-box;
}

/* Ensure compatibility with common WordPress themes */
.vanilla-search-wrapper input,
.vanilla-search-category-filter select,
.vanilla-search-category-filter button {
    font-family: inherit;
    font-size: inherit;
}

/* Override theme button styles if needed */
.search-filter-btn {
    border: none !important;
    text-decoration: none !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Ensure dropdown positioning works in all contexts */
.vanilla-search-wrapper {
    position: relative !important;
}

.autocomplete-dropdown {
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    right: 0 !important;
} 