/**
 * Agile-Ed Form Integration CSS
 * 
 * Common styles for Agile-Ed API integration with HubSpot forms
 * Includes form cropping fixes, autocomplete dropdown styling, and container overflow fixes
 * 
 * Usage:
 *   <link rel="stylesheet" href="/site/css/agile-ed-form-integration.css">
 */

/* Fix form being cropped at the bottom */
.form-holder,
.form-outer,
.form-div,
#form1 {
    overflow: visible !important;
    min-height: auto !important;
    padding-bottom: 40px !important;
}

.form-holder {
    overflow: visible !important;
}

.form-outer {
    overflow: visible !important;
    padding-bottom: 40px !important;
}

.form-div,
#form1 {
    overflow: visible !important;
    padding-bottom: 40px !important;
}

/* Ensure HubSpot form container doesn't get cropped */
.hs-form,
.hs-form form,
.hs-form-container {
    overflow: visible !important;
    padding-bottom: 40px !important;
}

/* Fix autocomplete dropdown being cut off */
.hs-form-field {
    overflow: visible !important;
}

.institution-autocomplete {
    z-index: 99999 !important;
    position: absolute !important;
    /* Height will be set dynamically based on number of results */
    max-height: 300px !important; /* Maximum height - shows ~5-6 items before scrolling */
    min-height: 108px !important; /* Minimum height - ensures 2 items look good */
    /* overflow-y will be set dynamically: 'auto' when scrolling needed, 'hidden' when not */
    overflow-x: hidden !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    padding-top: 8px !important; /* Top padding to ensure first item is fully visible */
    padding-bottom: 16px !important; /* Extra padding to ensure last item is fully visible when scrolling */
    box-sizing: border-box !important;
    top: auto !important; /* Will be set by JavaScript */
    left: 0 !important; /* Align with field */
    /* Ensure smooth scrolling and all items accessible */
    -webkit-overflow-scrolling: touch !important; /* Smooth scrolling on iOS */
    scroll-behavior: smooth !important;
}

/* Custom scrollbar styling for better appearance and to ensure content isn't hidden */
.institution-autocomplete::-webkit-scrollbar {
    width: 8px !important;
}

.institution-autocomplete::-webkit-scrollbar-track {
    background: #f1f1f1 !important;
    border-radius: 4px !important;
}

.institution-autocomplete::-webkit-scrollbar-thumb {
    background: #888 !important;
    border-radius: 4px !important;
}

.institution-autocomplete::-webkit-scrollbar-thumb:hover {
    background: #555 !important;
}

/* Firefox scrollbar styling */
.institution-autocomplete {
    scrollbar-width: thin !important;
    scrollbar-color: #888 #f1f1f1 !important;
}

/* Ensure parent containers don't clip autocomplete */
.hs-form-field,
.hs-form-field .input,
.hs-form-field .hs-input,
.hs-form,
.hs-form-container,
.form-div,
.form-outer,
.form-holder {
    overflow: visible !important;
    /* padding-bottom will be set dynamically via JavaScript based on dropdown height */
}

/* Additional containers that might clip the dropdown */
.hs-form-field .input,
.hs-form-field .hs-input,
.hs-form-field-wrapper,
.hs-form-field .hs-fieldtype-text,
.hs-form-field .hs-fieldtype-select {
    overflow: visible !important;
    position: relative !important; /* Ensure positioning context for absolute dropdown */
}

/* Ensure autocomplete items are fully visible */
.institution-autocomplete .autocomplete-item {
    padding: 12px 16px !important;
    min-height: auto !important;
    box-sizing: border-box !important;
}

/* Extra padding on last item to ensure it's fully visible when scrolling */
.institution-autocomplete .autocomplete-item:last-child {
    padding-bottom: 24px !important; /* Increased padding to ensure last item fully visible when scrolled to bottom */
    margin-bottom: 0 !important;
}

/* Ensure scrollbar doesn't hide content */
.institution-autocomplete {
    /* Add padding-right to account for scrollbar width */
    padding-right: 4px !important;
}

/* Ensure all items are accessible when scrolling */
.institution-autocomplete .autocomplete-item {
    /* Ensure items don't get cut off */
    min-height: 54px !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
}

/* Completely hide "Did you mean" validation messages */
.hs-form-field *:contains("Did you mean"),
.hs-form-field *:contains("did you mean"),
.hs-error-msgs *:contains("Did you mean"),
.hs-error-msgs *:contains("did you mean"),
.hs-main-font-element *:contains("Did you mean"),
.hs-main-font-element *:contains("did you mean"),
[class*="error"] *:contains("Did you mean"),
[class*="error"] *:contains("did you mean"),
[class*="suggestion"] *:contains("Did you mean"),
[class*="suggestion"] *:contains("did you mean") {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 0 !important;
    line-height: 0 !important;
    position: absolute !important;
    left: -9999px !important;
}

/* Mobile-specific styles */
@media only screen and (max-width: 767px) {
    /* Reduce gap between field and dropdown on mobile */
    .institution-autocomplete {
        margin-top: 4px !important; /* Reduced from 24px for mobile */
        height: 200px !important; /* Fixed height for consistent scrolling on mobile */
        max-height: 200px !important; /* Ensure it doesn't exceed 200px on mobile */
    }
    
    /* Dynamic padding will be set via JavaScript on mobile too */
    
    /* Ensure autocomplete items are touch-friendly on mobile */
    .institution-autocomplete .autocomplete-item {
        padding: 14px 16px !important; /* Slightly larger for touch */
        min-height: 44px !important; /* Minimum touch target size */
        font-size: 16px !important; /* Prevent zoom on iOS */
    }
    
    /* Better scrolling on mobile */
    .institution-autocomplete {
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
    }
    
    /* Ensure dropdown doesn't get cut off on mobile viewport */
    .institution-autocomplete {
        max-width: 100vw !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
    }
}

/* Tablet-specific adjustments */
@media only screen and (min-width: 768px) and (max-width: 1024px) {
    .institution-autocomplete {
        margin-top: 8px !important;
    }
    
    /* Dynamic padding will be set via JavaScript on tablet too */
}

/* Keep checkbox and product name on one line */
/* Override display: block !important rules that affect checkbox layout */
.hs-form-checkbox-display,
.hs-form-checkbox label,
.hs-form-checkbox .hs-form-checkbox-display,
li.hs-form-checkbox label,
li.hs-form-checkbox .hs-form-checkbox-display {
    display: flex !important;
    align-items: center !important;
    white-space: nowrap !important;
    flex-wrap: nowrap !important;
}

.hs-form-checkbox-display span,
.hs-form-checkbox label span,
.hs-form-checkbox .hs-form-checkbox-display span,
li.hs-form-checkbox label span,
li.hs-form-checkbox .hs-form-checkbox-display span {
    white-space: nowrap !important;
    display: inline-block !important;
}

/* Override display: block for checkbox inputs within labels */
.hs-form-checkbox-display input[type="checkbox"],
.hs-form-checkbox label input[type="checkbox"],
.hs-form-checkbox .hs-form-checkbox-display input[type="checkbox"],
li.hs-form-checkbox label input[type="checkbox"] {
    display: inline-block !important;
    flex-shrink: 0 !important;
    margin-right: 8px !important;
}
