/* Modern Taxonomy Search Styles */
.taxonomy-search-container {
    position: relative;
    max-width: 800px; /* Increased max-width for the new design */
    margin: 24px auto; /* Centered */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.taxonomy-search-form {
    position: relative;
    display: flex; /* Use flexbox for alignment */
    background: none; /* No background for the form container itself */
    padding: 0; /* No padding */
    border-radius: 50px; /* Main border-radius for the overall shape */
    box-shadow: none; /* No shadow on the form container */
    transition: none; /* No transition */
}

.taxonomy-search-form:hover {
    box-shadow: none;
    transform: none;
}

.taxonomy-search-form:focus-within {
    box-shadow: none;
    transform: none;
}

.taxonomy-input-wrapper {
    flex-grow: 1; /* Takes up available space */
    position: relative;
    display: flex;
    align-items: center;
    background: white; /* White background for the input area */
    border-radius: 50px 0 0 50px; /* Rounded left side */
    padding: 0 24px 0 20px; /* Padding for icon and text */
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1); /* Subtle shadow for input area */
    border: 1px solid #e0e0e0; /* Light border */
    transition: all 0.3s ease;
}

.taxonomy-input-wrapper:focus-within {
    border-color: #f26e21; /* Orange border on focus */
    box-shadow: 0 0 0 3px rgba(242, 110, 33, 0.2); /* Orange focus shadow */
}

.taxonomy-search-icon {
    display: flex;
    align-items: center;
    margin-right: 12px; /* Space between icon and input */
}

.taxonomy-search-icon svg {
    width: 24px;
    height: 24px;
    stroke: #999999; /* Grey color for the icon */
}

#taxonomy-search-input {
    flex-grow: 1; /* Takes up remaining space */
    padding: 16px 0; /* Vertical padding */
    border: none;
    border-radius: 0; /* Remove border-radius here */
    font-size: 16px;
    font-weight: 500;
    outline: none;
    background: transparent; /* Transparent background */
    color: #333;
    transition: none;
    box-sizing: border-box;
}

#taxonomy-search-input::placeholder {
    color: #999;
    font-weight: 400;
}

#taxonomy-search-input:focus {
    background: transparent;
    color: #333;
    border: none; /* Handled by .taxonomy-input-wrapper */
    box-shadow: none; /* Handled by .taxonomy-input-wrapper */
}

.taxonomy-search-button {
    flex-shrink: 0; /* Don't shrink */
    background: #f26e21; /* Brand orange background */
    color: white;
    padding: 16px 32px; /* Padding for button text */
    border: none;
    border-radius: 0 50px 50px 0; /* Rounded right side */
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.1s ease;
    outline: none;
    box-shadow: 0 8px 32px rgba(242, 110, 33, 0.25); /* Shadow matching brand */
}

.taxonomy-search-button:hover {
    background: #e35113; /* Darker orange on hover */
    box-shadow: 0 10px 36px rgba(242, 110, 33, 0.35);
}

.taxonomy-search-button:focus {
    background: #e35113; /* Darker orange on hover */
    box-shadow: 0 10px 36px rgba(242, 110, 33, 0.35);
}

.taxonomy-search-form:focus-within .taxonomy-search-button {
    border-left: 1px solid #f26e21; /* Add a border to connect with the focused input */
}

/* Removed old search icon styles */
.taxonomy-search-form::after {
    display: none;
}

.taxonomy-search-loading {
    position: absolute;
    right: 120px; /* Adjust position relative to the button */
    top: 50%;
    transform: translateY(-50%);
    color: #f26e21;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 3; /* Ensure it's above other elements */
}

.taxonomy-search-loading::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid #fbd4ad;
    border-top: 2px solid #f26e21;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Hide search button when loading */
.taxonomy-search-loading ~ .taxonomy-search-button {
    opacity: 0;
    pointer-events: none;
}

/* Adjust search input padding when loading */
.taxonomy-search-loading ~ .taxonomy-input-wrapper #taxonomy-search-input {
    padding-right: 50px; /* Make space for loading indicator */
}

/* General search results styles (reverted to original background) */
.taxonomy-search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: white;
    border-radius: 16px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: 0 20px 64px rgba(0, 0, 0, 0.12), 
                0 12px 24px rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: slideDown 0.3s ease-out;
}

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

.taxonomy-search-results::-webkit-scrollbar {
    width: 4px;
}

.taxonomy-search-results::-webkit-scrollbar-track {
    background: transparent;
}

.taxonomy-search-results::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 16px;
}

.taxonomy-search-results::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.2);
}


.taxonomy-search-result-item {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06); /* Restored original border */
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 16px;
}

.taxonomy-search-result-item:hover {
    background: transparent; /* Revert background to transparent */
}

.taxonomy-search-result-item:last-child {
    border-bottom: none; /* Keep last item without border */
}

.taxonomy-search-result-item.selected {
    background: linear-gradient(135deg, #f26e21 0%, #e35113 100%) !important;
    color: white;
    transform: translateX(8px);
}

.taxonomy-result-name {
    font-weight: 600;
    font-size: 16px;
    color: #1a202c;
    margin-bottom: 4px;
    line-height: 1.4;
}

.taxonomy-search-result-item.selected .taxonomy-result-name {
    color: white;
}

.taxonomy-result-image {
    flex-shrink: 0;
    width: 56px;
    height: 56px;
    border-radius: 12px;
    overflow: hidden;
    background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
}

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

.taxonomy-search-result-item:hover .taxonomy-result-image {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.taxonomy-search-result-item:hover .taxonomy-result-image img {
    transform: scale(1.1);
}

.taxonomy-search-result-item.selected .taxonomy-result-image {
    box-shadow: 0 6px 20px rgba(255, 255, 255, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.taxonomy-result-content {
    flex: 1;
    min-width: 0;
}

.taxonomy-result-parent {
    font-size: 13px;
    color: #f26e21;
    margin-bottom: 4px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.taxonomy-result-parent::before {
    content: '📍';
    font-size: 11px;
    opacity: 0.8;
}

.taxonomy-search-result-item.selected .taxonomy-result-parent {
    color: rgba(255, 255, 255, 0.9);
}

.taxonomy-search-result-item:hover .taxonomy-result-parent {
    color: #f26e21; /* Keeping brand color on hover */
}

.taxonomy-result-count {
    font-size: 12px;
    color: #a0aec0;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.taxonomy-result-count::before {
    content: '✈️';
    font-size: 12px;
    opacity: 0.8;
}

.taxonomy-search-result-item.selected .taxonomy-result-count {
    color: rgba(255, 255, 255, 0.8);
}

.taxonomy-search-result-item:hover .taxonomy-result-count {
    color: #a0aec0; /* Keeping original grey on hover */
}

.taxonomy-no-results {
    padding: 32px 20px; /* Reverted to original padding */
    text-align: center;
    color: #a0aec0; /* Reverted to original color */
    font-style: italic; /* Reverted to original font-style */
    font-size: 15px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%); /* Reverted background */
}

.taxonomy-no-results::before {
    content: '🔍'; /* Reverted icon */
    display: block; /* Reverted display */
    font-size: 32px;
    margin-bottom: 12px; /* Reverted margin */
    opacity: 0.5; /* Reverted opacity */
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .taxonomy-search-container {
        margin: 16px auto; /* Centered */
        max-width: 100%;
    }

    .taxonomy-search-form {
        display: flex; /* Ensure it's a flex container */
        flex-direction: row; /* Keep it in a row for mobile, but only one element (input wrapper) visible */
        border-radius: 50px; /* Fully rounded form */
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1); /* Subtle shadow for the overall form */
        background: white; /* Ensure background is white for the input */
        border: 1px solid #e0e0e0; /* Light border for the overall form */
        overflow: hidden; /* Ensure rounded corners clip content */
    }

    .taxonomy-input-wrapper {
        flex-grow: 1; /* Takes full width */
        border-radius: 50px; /* Fully rounded */
        padding: 14px 20px; /* Adjusted padding for mobile */
        border: none; /* Remove individual border, handled by .taxonomy-search-form */
        box-shadow: none; /* Remove individual shadow */
    }

    .taxonomy-input-wrapper:focus-within {
        border-color: transparent; /* Border handled by .taxonomy-search-form focus */
        box-shadow: none; /* Shadow handled by .taxonomy-search-form focus */
    }

    .taxonomy-search-form:focus-within {
        border-color: #f26e21; /* Orange border on focus for the whole form */
        box-shadow: 0 0 0 3px rgba(242, 110, 33, 0.2); /* Orange focus shadow */
    }

    #taxonomy-search-input {
        padding: 0;
        font-size: 15px;
    }

    .taxonomy-search-button {
        display: none; /* Hide the orange search button on mobile */
    }

    .taxonomy-search-loading {
        right: 20px; /* Adjust loading position for mobile */
        top: 50%; /* Keep centered vertically */
        bottom: auto;
        transform: translateY(-50%);
    }

    /* Hide search button when loading (already hidden, but good practice) */
    .taxonomy-search-loading ~ .taxonomy-search-button {
        opacity: 0;
        pointer-events: none;
    }

    /* Adjust search input padding when loading for mobile */
    .taxonomy-search-loading ~ .taxonomy-input-wrapper #taxonomy-search-input {
        padding-right: 50px; /* Make space for loading indicator */
    }
    
    .taxonomy-search-results {
        border-radius: 12px;
        max-height: 300px;
    }
    
    .taxonomy-search-result-item {
        padding: 14px 16px;
        gap: 12px;
    }
    
    .taxonomy-result-image {
        width: 48px;
        height: 48px;
        border-radius: 10px;
    }
    
    .taxonomy-result-name {
        font-size: 15px;
    }
    
    .taxonomy-result-parent {
        font-size: 12px;
    }
    
    .taxonomy-result-count {
        font-size: 11px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .taxonomy-input-wrapper {
        background: #2d3748;
        border-color: rgba(255, 255, 255, 0.1);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    }

    .taxonomy-input-wrapper:focus-within {
        border-color: #f26e21;
        box-shadow: 0 0 0 3px rgba(242, 110, 33, 0.4);
    }

    .taxonomy-search-icon svg {
        stroke: #a0aec0;
    }

    #taxonomy-search-input {
        color: #f7fafc;
    }
    
    #taxonomy-search-input::placeholder {
        color: #a0aec0;
    }
    
    .taxonomy-search-results {
        background: #2d3748;
        box-shadow: 0 20px 64px rgba(0, 0, 0, 0.3), 
                    0 12px 24px rgba(0, 0, 0, 0.2);
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .taxonomy-search-result-item {
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    }
    
    .taxonomy-result-name {
        color: #f7fafc;
    }
    
    .taxonomy-result-image {
        background: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
    }
    
    .taxonomy-no-results {
        color: #cbd5e0;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    .taxonomy-search-form,
    .taxonomy-search-form:hover,
    .taxonomy-search-form:focus-within,
    .taxonomy-input-wrapper,
    .taxonomy-input-wrapper:focus-within,
    #taxonomy-search-input,
    .taxonomy-search-loading,
    .taxonomy-search-results,
    .taxonomy-search-result-item,
    .taxonomy-search-result-item:hover,
    .taxonomy-search-result-item.selected,
    .taxonomy-result-image,
    .taxonomy-result-image img,
    .taxonomy-search-button,
    .taxonomy-search-button:hover,
    .taxonomy-search-button:active {
        transition: none !important;
    }
}