/* Ensure the main form is a flex container and controls its children */
form.searchform {
    display: flex;
    flex-wrap: nowrap; /* Forces elements to stay on one line, preventing wrapping */
    align-items: center; /* Vertically align items in the middle */
    gap: 8px; /* Spacing between the search box, image button, and search icon */
    margin-bottom: 20px;
    box-sizing: border-box; /* Include padding and border in element's total width and height */
    /* You might need to adjust the form's max-width or width depending on your theme's header/container. */
    /* Example: max-width: 500px; or width: 100%; */
}

/* Style the existing search input field */
form.searchform input[type="search"].search-field {
    flex-grow: 1; /* Allows the search input to take up most available space */
    min-width: 100px; /* Ensures it doesn't become too small */
    padding: 8px 15px; /* Adjust padding to match the button's visual height */
    height: 38px; /* Set a consistent height for visual alignment with the button */
    box-sizing: border-box;
    /* Add/adjust border-radius, border, background-color to match your theme's default input */
}

/* Container for our custom upload button */
.wc-image-upload-controls {
    display: flex; /* Keeps button content centered */
    align-items: center;
    flex-shrink: 0; /* Prevents this button group from shrinking */
    margin-top: 5px; /* A 5px top margin to nudge it down */
}

/* Style for the custom upload button (label) */
.wc-image-search-button-custom-upload-btn {
    display: inline-flex; /* Use inline-flex for vertical centering of text */
    justify-content: center; /* Center "Image" text horizontally */
    align-items: center; /* Center "Image" text vertically */
    padding: 6px 12px; /* Reduced padding for a smaller button */
    height: 38px; /* Match the height of the search field for alignment */
    background-color: #0073aa; /* WordPress blue */
    color: #fff;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-weight: bold;
    text-align: center;
    text-decoration: none;
    transition: background-color 0.3s ease, transform 0.1s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    white-space: nowrap;
    font-size: 0.85em; /* Smaller font size for compactness */
    box-sizing: border-box;
}

.wc-image-search-button-custom-upload-btn:hover {
    background-color: #005177;
    transform: translateY(-1px);
}

.wc-image-search-button-custom-upload-btn:active {
    transform: translateY(0);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.2);
}

/* This hides the actual file input element */
#wc-image-search-button-file-input {
    display: none;
}

/* Style the existing search submit button (the magnifying glass icon) */
form.searchform button.search-submit {
    flex-shrink: 0; /* Prevents the button from shrinking */
    padding: 0 15px; /* Adjust padding to make it compact around the icon */
    height: 38px; /* Match the height of other elements */
    box-sizing: border-box;
    /* Your theme might already style this button to be an icon. */
}

/* --- Styles for Loading Indicator --- */
form.searchform.image-search-loading {
    position: relative; /* Needed for positioning the spinner */
    opacity: 0.8; /* Slightly dim the form during loading */
    pointer-events: none; /* Disable interaction */
}

form.searchform.image-search-loading:after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #0073aa; /* WordPress blue */
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 10; /* Ensure it's above other elements */
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* --- End Styles for Loading Indicator --- */


/* Responsive adjustments */
@media (max-width: 768px) {
    form.searchform {
        flex-wrap: wrap; /* Allow wrapping on smaller screens */
        justify-content: center; /* Center elements when they wrap */
    }
    form.searchform input[type="search"].search-field {
        width: 100%; /* Take full width when stacked */
        margin-bottom: 10px; /* Space before next element when stacked */
    }

    .wc-image-upload-controls {
        width: auto; /* Allow button to take its natural width */
        margin-bottom: 10px; /* Space before the submit button when stacked */
        justify-content: center; /* Ensure button is centered if its container is full width */
        margin-top: 0; /* Reset top margin when stacking */
    }

    form.searchform button.search-submit {
        width: 100%; /* Make submit button full width when stacked */
    }
}

@media (max-width: 480px) {
    /* No additional changes needed here, as the above media query handles most mobile stacking. */
}
