.vgs-search-form {
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 15px;
    width: 100%;
    margin: 0 auto;
    padding: 0;
    box-sizing: border-box;
}

/* When location field is disabled, category field should take more space */
.vgs-search-form:not(:has(.vgs-location-field)) .vgs-category-field {
    flex-grow: 1;
}

.vgs-category-field,
.vgs-location-field {
    min-width: 0;
    flex-shrink: 1;
    box-sizing: border-box;
}

.vgs-category-select,
.vgs-location-input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.vgs-location-field {
    position: relative;
    display: flex;
    align-items: center;
}

.vgs-location-input {
    width: 100%;
    padding: 8px 40px 8px 10px !important;
    border: 1px solid var(--ts-border-color, #e3e3e3);
    border-radius: 6px;
    background: var(--ts-input-bg, #fff);
    font-size: 14px;
    color: var(--ts-color-black, #242629);
    line-height: 1.5;
    transition: padding 0.2s ease;
}

/* Adjust padding when input has value (clear button is visible) */
.vgs-location-input:not(:placeholder-shown) {
    padding: 8px 40px 8px 30px !important;
}

.vgs-location-input:focus {
    outline: none;
    border-color: var(--ts-accent-color, #0069ff);
}

.vgs-use-location {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    padding: 5px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.vgs-use-location i {
    font-size: 18px;
    width: 1em;
    height: 1em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.vgs-use-location svg {
    width: 1em;
    height: 1em;
}

.vgs-use-location:hover {
    opacity: 1;
}

.vgs-use-location:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.vgs-use-location:hover .vgs-location-button-text {
    color: var(--ts-accent-hover-color, #004dc4);
}

.vgs-location-field-with-text .vgs-location-input {
    padding-right: 140px !important; /* Make space for the button with text */
}

.vgs-search-submit {
    padding: 10px 20px;
    background-color: var(--ts-accent-color, #0069ff);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 42px;
    flex-shrink: 0;
}

.vgs-search-submit:hover {
    background-color: var(--ts-accent-hover-color, #004dc4);
}

.vgs-search-submit i,
.vgs-search-submit svg {
    font-size: 16px;
    width: 1em;
    height: 1em;
    color: #ffffff;
}

.vgs-search-submit span {
    line-height: 1;
}

/* Select2 customization */
.select2-container--default .select2-selection--single {
    height: 42px !important;
    border: 1px solid var(--ts-border-color, #e3e3e3) !important;
    border-radius: 6px !important;
    background: var(--ts-input-bg, #fff) !important;
    display: flex !important;
    align-items: center !important;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 42px !important;
    padding-left: 15px !important;
    padding-right: 30px !important;
    color: var(--ts-color-black, #242629) !important;
    font-size: 14px !important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 42px !important;
    width: 30px !important;
    top: 0 !important;
}

/* Dropdown styling */
.select2-dropdown {
    border-color: var(--ts-border-color, #e3e3e3) !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
    margin-top: 1px !important;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
    padding: 8px !important;
    border-color: var(--ts-border-color, #e3e3e3) !important;
    border-radius: 4px !important;
}

.select2-container--default .select2-results__option {
    padding: 8px 15px !important;
    font-size: 14px !important;
}

/* Optgroup styling */
.select2-container--default .select2-results__group {
    padding: 10px 15px !important;
    font-weight: 600 !important;
    background: var(--ts-dropdown-hover-bg, #f6f6f6) !important;
}

/* Customize Google Places Autocomplete dropdown */
.pac-container {
    margin-top: 5px;
    border-radius: 6px;
    border: 1px solid var(--ts-border-color, #e3e3e3);
    box-shadow: 0 2px 7px rgb(0 0 0 / 10%);
    font-family: inherit;
}

.pac-item {
    padding: 10px 15px;
    font-size: 14px;
    border-top: 1px solid var(--ts-border-color, #e3e3e3);
    cursor: pointer;
}

.pac-item:first-child {
    border-top: none;
}

.pac-item:hover {
    background-color: var(--ts-dropdown-hover-bg, #f6f6f6);
}

.pac-item-query {
    font-size: inherit;
    padding-right: 5px;
}

.pac-matched {
    font-weight: 600;
}

/* Category option styling */
.vgs-category-option {
    display: flex;
    align-items: center;
    gap: 8px;
}

.vgs-category-icon {
    font-size: 18px;
    width: 1em;
    height: 1em;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ts-accent-color, #0069ff);
}

/* Line Awesome specific adjustments */
.vgs-category-icon.las {
    font-size: 20px;
}

/* Font Awesome specific adjustments */
.vgs-category-icon.fas {
    font-size: 16px;
}

.vgs-category-text {
    flex: 1;
}

/* Select2 adjustments for icons */
.select2-container--default .select2-selection--single {
    display: flex;
    align-items: center;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    display: flex;
    align-items: center;
    gap: 8px;
}

.select2-results__option {
    padding: 8px 15px !important;
}

/* Error styling */
.vgs-error-message {
    color: var(--ts-danger-color, #ef4444);
    font-size: 13px;
    margin-top: 5px;
    padding: 0 5px;
}

.select2-container--default .select2-selection--single.vgs-error {
    border-color: var(--ts-danger-color, #ef4444) !important;
}

.select2-container--default .select2-selection--single.vgs-error:hover,
.select2-container--default .select2-selection--single.vgs-error:focus {
    border-color: var(--ts-danger-color, #ef4444) !important;
    box-shadow: 0 0 0 1px var(--ts-danger-color, #ef4444) !important;
}

/* Smooth transitions for error states */
.select2-container--default .select2-selection--single {
    transition: all 0.15s ease-in-out !important;
}

.vgs-error-message {
    animation: slideDown 0.2s ease-out;
}

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

/* Override Select2 default highlight colors */
.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: var(--ts-dropdown-hover-bg, #f6f6f6) !important;
    color: var(--ts-color-black, #242629) !important;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] .vgs-category-icon {
    color: var(--ts-color-black, #242629) !important;
}

/* Group header styling */
.select2-container--default .select2-results__group {
    background-color: var(--ts-dropdown-hover-bg, #f6f6f6) !important;
    color: var(--ts-color-black, #242629) !important;
}

.vgs-location-button-text {
    font-size: 14px;
    white-space: nowrap;
    font-weight: 500;
    transition: color 0.3s ease;
}

/* Hide text on mobile if needed */
@media (max-width: 768px) {
    .vgs-location-button-text {
        display: none;
    }
    .vgs-search-form {
        flex-wrap: wrap;
    }
    .vgs-category-field,
    .vgs-location-field {
        width: 100% !important;
    }
}

/* Post result styling */
.select2-results__option .vgs-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
}

.vgs-post-image {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
}

.vgs-post-title {
    font-size: 14px;
    color: var(--ts-color-black, #242629);
    font-weight: 500;
    line-height: 1.2;
    /* Prevent long titles from breaking layout */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 300px;
}

/* Category result styling */
.vgs-category-icon {
    font-size: 16px;
    width: 20px;
    color: var(--ts-color-black, #242629);
    opacity: 0.5;
}

.vgs-category-text {
    font-size: 14px;
    color: var(--ts-color-black, #242629);
}

/* Selected item styling */
.select2-selection__rendered .vgs-option {
    display: flex;
    align-items: center;
    gap: 8px;
}

.select2-selection__rendered .vgs-post-image {
    width: 24px;
    height: 24px;
}

/* Loading states */
.vgs-search-form.is-loading .vgs-search-submit {
    opacity: 0.7;
    cursor: not-allowed;
    position: relative;
    pointer-events: none;
}

.vgs-search-form.is-loading .vgs-search-submit .vgs-spinner {
    display: inline-block;
}

.vgs-spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: vgs-spin 0.6s linear infinite;
    margin-right: 8px;
}

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

/* Add this to hide the select until initialized */
.vgs-category-select:not(.select2-hidden-accessible) {
    visibility: hidden;
    height: 42px; /* Match the height of Select2 to prevent layout shift */
}

/* Loading State Base Styles */
.vgs-category-field {
    position: relative;
    height: 42px;
    display: block;
}

/* Loading Placeholder */
.vgs-loading-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 42px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 5px;
    padding: 8px 12px;
    z-index: 10;
    display: none; /* Hidden by default */
}

/* Show loading placeholder when loading */
.vgs-loading .vgs-loading-placeholder {
    display: block;
}

/* Loading animation elements */
.vgs-loading-select {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    height: 100%;
}

.vgs-loading-text {
    flex: 1;
    height: 16px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading-pulse 1.5s infinite;
    border-radius: 4px;
}

.vgs-loading-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading-pulse 1.5s infinite;
}

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

/* Hide Select2 during loading */
.vgs-loading .select2-container,
.vgs-loading .vgs-category-select {
    opacity: 0 !important;
    visibility: hidden !important;
}

/* Transitions */
.select2-container,
.vgs-category-select,
.vgs-loading-placeholder {
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
}

/* Add this class when the widget is initializing */
.vgs-search-form.initializing .vgs-category-field {
    min-height: 42px; /* Maintain height during load */
}

/* Add styles for the no results link */
.vgs-no-results {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 0;
}

.vgs-no-results-link {
    color: var(--ts-accent-color, #0069ff);
    font-size: 14px;
    text-decoration: none;
    transition: color 0.3s ease;
}

.vgs-no-results-link:hover {
    color: var(--ts-accent-hover-color, #004dc4);
    text-decoration: underline;
}

/* Make Select2 container full width */
.select2.select2-container {
    width: 100% !important;
}

/* Adjust dropdown width */
.select2-container--default .select2-dropdown {
    min-width: 100%;
    max-width: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .vgs-search-form {
        flex-wrap: wrap;
    }
    
    .vgs-category-field,
    .vgs-location-field {
        width: 100% !important;
    }

    .vgs-search-submit {
        width: 100%;
        justify-content: center;
    }
}

/* Update the clear button styles */
.select2-container--default .select2-selection--single .select2-selection__clear {
    margin-right: 0 !important; /* Override Select2's default margin */
    margin-left: 10px;
    color: var(--ts-color-black, #242629);
    opacity: 0.5;
    transition: opacity 0.3s ease;
}

.select2-container--default .select2-selection--single .select2-selection__clear:hover {
    opacity: 1;
}

/* Dynamic placeholder styling */
.select2-selection__placeholder {
    transition: opacity 0.3s ease;
}

.select2-selection__placeholder.fade-out {
    opacity: 0;
}

.select2-selection__placeholder.fade-in {
    opacity: 1;
}

/* Add this to your existing CSS */
.vgs-category-field.initializing {
    opacity: 0;
}

.vgs-category-field {
    opacity: 1;
    transition: opacity 0.3s ease;
}

/* Hide Select2 container initially */
.select2-container {
    opacity: 1 !important; /* Force visibility */
}

/* Show Select2 container when initialized */
.select2-container.select2-ready {
    opacity: 1;
}

/* Hide original select */
.vgs-category-select {
    display: none;
}

/* Select2 container styles */
.select2-container {
    display: block !important;
    width: 100% !important;
}

/* Make submit button auto-width */
.vgs-search-submit {
    flex: none;
}

/* Responsive behavior */
@media (max-width: 768px) {
    .vgs-category-field,
    .vgs-location-field {
        width: 100% !important;
    }
}

/* Popular terms styling */
.vgs-popular-terms,
.vgs-recent-searches {
    border-top: 1px solid var(--ts-border-color, #e3e3e3);
}

.vgs-popular-terms-title,
.vgs-recent-searches-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--ts-text-color-light, #666);
    margin-bottom: 8px;
}

.vgs-popular-terms-list,
.vgs-recent-searches-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.vgs-popular-term,
.vgs-recent-search {
    font-size: 13px;
    padding: 4px 10px;
    background-color: var(--ts-dropdown-hover-bg, #f6f6f6);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.vgs-popular-term:hover,
.vgs-recent-search:hover {
    background-color: var(--ts-primary-color, #0069ff);
    color: #fff;
}

/* Recent searches header */
.vgs-recent-searches-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.vgs-clear-history {
    font-size: 12px;
    color: var(--ts-text-color-light, #666);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: color 0.2s ease;
}

.vgs-clear-history:hover {
    color: var(--ts-danger-color, #ef4444);
}
/* Select2 message and dropdown content styling */
.select2-results__message {
    font-size: 13px !important;
    color: var(--ts-text-color-light, #666) !important;
    padding: 10px 0 !important;
    margin: 0 !important;
}

.vgs-dropdown-content {
    padding: 0 !important;
    margin: 0 !important;
}

/* Ensure consistent text size */
.select2-results__options {
    font-size: 13px !important;
}

/* Override any Select2 default padding */
.select2-results {
    padding: 0 !important;
}

.select2-results__options {
    padding: 0 !important;
    margin: 0 !important;
    max-height: 250px !important;
}

/* Ensure consistent styling for all dropdown items */
.select2-results__option {
    font-size: 13px !important;
    padding: 8px 15px !important;
    margin: 0 !important;
}

/* Location field clear button */
.vgs-location-field {
    position: relative;
}

.vgs-location-clear {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 0;
    width: 16px;
    height: 16px;
    cursor: pointer;
    opacity: 0.5;
    display: none;
    color: #666;
    font-size: 16px;
    line-height: 1;
}

.vgs-location-clear::before {
    content: "×";
    display: block;
}

.vgs-location-clear:hover {
    opacity: 0.8;
}

.vgs-location-input:not(:placeholder-shown) + .vgs-location-clear {
    display: block;
}

/* Adjust location input padding to accommodate clear button */
.vgs-location-input {
    padding-right: 35px !important;
}

/* Rest of your existing styles... */

/* Footer Select2 dropdown positioning fixes */
/* Ensure high z-index for footer dropdowns */
.select2-dropdown {
    z-index: 999999 !important;
}

/* Fix positioning when dropdown opens upward (common in footer) */
.select2-dropdown--above {
    margin-bottom: 0 !important;
    border-top-left-radius: 4px !important;
    border-top-right-radius: 4px !important;
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    border-bottom: none !important;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1) !important;
}

/* Footer context detection and improved positioning */
footer .select2-dropdown,
.footer .select2-dropdown,
[class*="footer"] .select2-dropdown {
    z-index: 999999 !important;
    max-height: 200px !important;
}

footer .select2-dropdown--above,
.footer .select2-dropdown--above,
[class*="footer"] .select2-dropdown--above {
    margin-bottom: 2px !important;
    transform: translateY(-2px);
}

/* Ensure dropdown appears above footer content */
footer .select2-container,
.footer .select2-container,
[class*="footer"] .select2-container {
    z-index: 999998 !important;
}

/* Fix Select2 container positioning in footer */
footer .select2-container--default.select2-container--open,
.footer .select2-container--default.select2-container--open,
[class*="footer"] .select2-container--default.select2-container--open {
    z-index: 999998 !important;
}

/* Improve dropdown positioning when at bottom of viewport */
.select2-dropdown--below {
    border-top: 1px solid #aaa !important;
}

/* Better handling for dropdowns that flip direction */
.select2-container--default .select2-selection--single {
    position: relative;
    z-index: 999997;
}

/* Responsive footer dropdown adjustments */
@media (max-width: 768px) {
    footer .select2-dropdown,
    .footer .select2-dropdown,
    [class*="footer"] .select2-dropdown {
        max-height: 150px !important;
        margin-bottom: 5px !important;
    }
    
    footer .select2-dropdown--above,
    .footer .select2-dropdown--above,
    [class*="footer"] .select2-dropdown--above {
        margin-bottom: 5px !important;
        transform: translateY(-5px);
    }
}

/* Additional positioning fixes for sticky footers */
.select2-container--open .select2-dropdown {
    position: fixed !important;
}

/* Ensure dropdown doesn't get cut off by page boundaries */
.select2-dropdown {
    overflow: visible !important;
}

.select2-results__options {
    overflow-y: auto !important;
}

/* Fix for dropdowns in bottom sections of the page */
.select2-container--default.select2-container--below .select2-selection--single {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.select2-container--default.select2-container--above .select2-selection--single {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

/* Better visual separation for upward dropdowns */
.select2-dropdown--above {
    margin-top: 0 !important;
    border-top: 1px solid #aaa !important;
}

/* Ensure proper spacing and visual hierarchy */
.select2-container {
    position: relative;
}

/* Force proper stacking order for footer elements */
footer .vgs-search-form,
.footer .vgs-search-form,
[class*="footer"] .vgs-search-form {
    position: relative;
    z-index: 999996;
}

/* JavaScript-applied footer dropdown class for enhanced styling */
.select2-dropdown.vgs-footer-dropdown {
    z-index: 999999 !important;
    position: fixed !important;
    border-radius: 6px !important;
    border: 1px solid #ddd !important;
    background: #fff !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

.select2-dropdown.vgs-footer-dropdown.select2-dropdown--above {
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15) !important;
    border-bottom: 1px solid #ddd !important;
    margin-bottom: 2px !important;
}

/* Improved visual connection between select and dropdown in footer */
.vgs-footer-dropdown + .select2-container .select2-selection--single {
    border-color: #ddd !important;
}

/* Ensure footer dropdown content is properly styled */
.select2-dropdown.vgs-footer-dropdown .select2-results__options {
    max-height: 200px !important;
    overflow-y: auto !important;
}

/* Responsive footer dropdown improvements */
@media (max-width: 768px) {
    .select2-dropdown.vgs-footer-dropdown {
        max-height: 180px !important;
        border-radius: 4px !important;
    }
    
    .select2-dropdown.vgs-footer-dropdown .select2-results__options {
        max-height: 150px !important;
    }
}

/* Disabled location field styles */
.vgs-field-group.vgs-disabled {
    opacity: 0.7;
    position: relative;
}

.vgs-field-group.vgs-disabled .vgs-location-input {
    background-color: #f5f5f5 !important;
    color: #666 !important;
    cursor: not-allowed !important;
    border-color: #ccc !important;
}

.vgs-field-group.vgs-disabled .vgs-location-input:focus {
    border-color: #ccc !important;
    box-shadow: none !important;
    outline: none !important;
}

.vgs-location-error {
    display: block;
    margin-top: 5px;
    color: #666 !important;
    font-size: 11px !important;
    font-style: italic;
}

/* Debug message styles */
.vgs-debug-info {
    background: #f0f8ff;
    border: 1px solid #1e90ff;
    padding: 8px 12px;
    margin: 10px 0;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
    color: #0066cc;
}

.vgs-error-info {
    background: #fff5f5;
    border: 1px solid #ff6b6b;
    padding: 8px 12px;
    margin: 10px 0;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
    color: #cc0000;
}

/* Prevent duplicate forms and improve positioning */
.vgs-search-form {
    position: relative !important;
}

.vgs-category-field {
    position: relative !important;
}

/* Enhanced Select2 dropdown positioning */
.select2-dropdown {
    z-index: 9999 !important;
    position: absolute !important;
}

/* Fix for dropdowns appearing in wrong location */
.select2-dropdown.select2-dropdown--below {
    position: absolute !important;
    left: auto !important;
    right: auto !important;
}

/* Ensure dropdown aligns with its parent */
.vgs-category-field .select2-dropdown {
    min-width: 100% !important;
    max-width: none !important;
    width: auto !important;
}

/* Fix for extremely mispositioned dropdowns */
.select2-dropdown[style*="left: 0px"], 
.select2-dropdown[style*="left:0px"] {
    left: auto !important;
    position: absolute !important;
}

/* Prevent duplicate widget rendering issues */
.vgs-search-form.vgs-search-initialized ~ .vgs-search-form {
    display: none !important;
}

/* Improved dropdown container positioning */
.select2-container--open .select2-dropdown {
    position: absolute !important;
    z-index: 9999 !important;
} 