/**
 * Property Search Widget v2 - Base Styles
 * 
 * @package EstatifyMLS
 * @version 2.0.0
 */

/* ===== CSS Custom Properties ===== */
.emls-property-search-v2 {
    /* Colors */
    --emls-v2-primary: #007cba;
    --emls-v2-primary-hover: #005a87;
    --emls-v2-text: #333333;
    --emls-v2-text-light: #666666;
    --emls-v2-border: #dddddd;
    --emls-v2-bg: #ffffff;
    --emls-v2-bg-hover: #f5f5f5;
    --emls-v2-bg-alt: #fafafa;
    --emls-v2-shadow: rgba(0, 0, 0, 0.1);
    
    /* Typography */
    --emls-v2-font-sm: 14px;
    --emls-v2-font-md: 16px;
    --emls-v2-font-lg: 18px;
    --emls-v2-line-height: 1.5;
    
    /* Spacing */
    --emls-v2-gap-xs: 4px;
    --emls-v2-gap-sm: 8px;
    --emls-v2-gap-md: 16px;
    --emls-v2-gap-lg: 24px;
    --emls-v2-gap-xl: 32px;
    
    /* Dimensions */
    --emls-v2-field-height: 48px;
    --emls-v2-dropdown-max: 300px;
    --emls-v2-border-radius: 4px;
    
    /* Transitions */
    --emls-v2-transition: 200ms ease;
    
    /* Z-index layers */
    --emls-v2-z-dropdown: 100;
    --emls-v2-z-spinner: 50;
}

/* ===== Main Wrapper ===== */
.emls-property-search-v2 {
    position: relative;
    width: 100%;
    box-sizing: border-box;
}

.emls-property-search-v2 *,
.emls-property-search-v2 *::before,
.emls-property-search-v2 *::after {
    box-sizing: inherit;
}

/* ===== Form Layout ===== */
.emls-v2-search__form {
    display: flex;
    flex-direction: column;
    gap: var(--emls-v2-gap-md);
    width: 100%;
}

.emls-v2-search__fields {
    display: flex;
    flex-wrap: wrap;
    gap: var(--emls-v2-gap-sm);
    width: 100%;
}

/* ===== Field Wrapper ===== */
.emls-v2-field {
    position: relative;
    flex: 0 0 var(--emls-v2-field-width, 100%);
    width: var(--emls-v2-field-width, 100%);
    max-width: var(--emls-v2-field-width, 100%);
    min-width: 0;
}

.emls-v2-field--submit {
    flex: 0 0 var(--emls-v2-field-width, 100%);
    width: var(--emls-v2-field-width, 100%);
    max-width: var(--emls-v2-field-width, 100%);
    align-self: flex-end;
}

/* ===== Gap Compensation for Flexbox ===== */
/* 
 * For 4 items with 3 gaps @ 8px = 24px total gap space
 * Each item subtracts: (its % / 100%) × 24px
 */
.emls-v2-field[style*="width:10%"],
.emls-v2-field[style*="width: 10%"] { 
    flex-basis: calc(10% - 2.4px) !important; 
    width: auto !important;
    max-width: none !important;
}
.emls-v2-field[style*="width:15%"],
.emls-v2-field[style*="width: 15%"] { 
    flex-basis: calc(15% - 3.6px) !important; 
    width: auto !important;
    max-width: none !important;
}
.emls-v2-field[style*="width:20%"],
.emls-v2-field[style*="width: 20%"] { 
    flex-basis: calc(20% - 4.8px) !important; 
    width: auto !important;
    max-width: none !important;
}
.emls-v2-field[style*="width:25%"],
.emls-v2-field[style*="width: 25%"] { 
    flex-basis: calc(25% - 6px) !important; 
    width: auto !important;
    max-width: none !important;
}
.emls-v2-field[style*="width:30%"],
.emls-v2-field[style*="width: 30%"] { 
    flex-basis: calc(30% - 7.2px) !important; 
    width: auto !important;
    max-width: none !important;
}
.emls-v2-field[style*="width:33%"],
.emls-v2-field[style*="width: 33%"] { 
    flex-basis: calc(33% - 7.92px) !important; 
    width: auto !important;
    max-width: none !important;
}
.emls-v2-field[style*="width:40%"],
.emls-v2-field[style*="width: 40%"] { 
    flex-basis: calc(40% - 9.6px) !important; 
    width: auto !important;
    max-width: none !important;
}
.emls-v2-field[style*="width:50%"],
.emls-v2-field[style*="width: 50%"] { 
    flex-basis: calc(50% - 12px) !important; 
    width: auto !important;
    max-width: none !important;
}
.emls-v2-field[style*="width:60%"],
.emls-v2-field[style*="width: 60%"] { 
    flex-basis: calc(60% - 14.4px) !important; 
    width: auto !important;
    max-width: none !important;
}
.emls-v2-field[style*="width:66%"],
.emls-v2-field[style*="width: 66%"] { 
    flex-basis: calc(66% - 15.84px) !important; 
    width: auto !important;
    max-width: none !important;
}
.emls-v2-field[style*="width:70%"],
.emls-v2-field[style*="width: 70%"] { 
    flex-basis: calc(70% - 16.8px) !important; 
    width: auto !important;
    max-width: none !important;
}
.emls-v2-field[style*="width:75%"],
.emls-v2-field[style*="width: 75%"] { 
    flex-basis: calc(75% - 18px) !important; 
    width: auto !important;
    max-width: none !important;
}
.emls-v2-field[style*="width:80%"],
.emls-v2-field[style*="width: 80%"] { 
    flex-basis: calc(80% - 19.2px) !important; 
    width: auto !important;
    max-width: none !important;
}
.emls-v2-field[style*="width:90%"],
.emls-v2-field[style*="width: 90%"] { 
    flex-basis: calc(90% - 21.6px) !important; 
    width: auto !important;
    max-width: none !important;
}
.emls-v2-field[style*="width:100%"],
.emls-v2-field[style*="width: 100%"] { 
    flex-basis: 100% !important; 
    width: auto !important;
    max-width: none !important;
}

/* Prevent flex properties from overriding our calculations */
.emls-v2-field[style*="width:"] {
    flex-grow: 0 !important;
    flex-shrink: 0 !important;
    min-width: 0 !important;
}

.emls-v2-field__label {
    display: block;
    margin-bottom: var(--emls-v2-gap-xs);
    font-size: var(--emls-v2-font-sm);
    font-weight: 600;
    color: var(--emls-v2-text);
    line-height: 1.3;
}

/* ===== Input Fields ===== */
.emls-v2-field__input,
.emls-v2-field__select {
    width: 100%;
    height: var(--emls-v2-field-height);
    padding: 0 var(--emls-v2-gap-md);
    font-size: var(--emls-v2-font-sm);
    color: var(--emls-v2-text);
    background: var(--emls-v2-bg);
    border: 1px solid var(--emls-v2-border);
    border-radius: var(--emls-v2-border-radius);
    transition: border-color var(--emls-v2-transition), box-shadow var(--emls-v2-transition);
}

.emls-v2-field__input:focus,
.emls-v2-field__select:focus {
    outline: none;
    border-color: var(--emls-v2-primary);
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.1);
}

.emls-v2-field__input::placeholder {
    color: var(--emls-v2-text-light);
}

/* ===== Custom Dropdown ===== */
.emls-v2-dropdown {
    position: relative;
    width: 100%;
}

.emls-v2-dropdown__trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: var(--emls-v2-field-height);
    padding: 0 var(--emls-v2-gap-md);
    font-size: var(--emls-v2-font-sm);
    color: var(--emls-v2-text);
    background: var(--emls-v2-bg);
    border: 1px solid var(--emls-v2-border);
    border-radius: var(--emls-v2-border-radius);
    cursor: pointer;
    transition: border-color var(--emls-v2-transition), box-shadow var(--emls-v2-transition);
}

.emls-v2-dropdown__trigger:hover {
    border-color: var(--emls-v2-primary);
}

.emls-v2-dropdown.is-open .emls-v2-dropdown__trigger {
    border-color: var(--emls-v2-primary);
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.1);
}

.emls-v2-dropdown__label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.emls-v2-dropdown.has-selection .emls-v2-dropdown__label {
    color: var(--emls-v2-primary);
    font-weight: 500;
}

.emls-v2-dropdown__arrow {
    flex-shrink: 0;
    margin-left: var(--emls-v2-gap-sm);
    font-size: 12px;
    color: var(--emls-v2-text-light);
    transition: transform var(--emls-v2-transition);
}

.emls-v2-dropdown.is-open .emls-v2-dropdown__arrow {
    transform: rotate(180deg);
}

.emls-v2-dropdown__menu {
    position: absolute;
    top: calc(100% + var(--emls-v2-gap-xs));
    left: 0;
    right: 0;
    z-index: var(--emls-v2-z-dropdown);
    display: none;
    max-height: var(--emls-v2-dropdown-max);
    overflow-y: auto;
    background: var(--emls-v2-bg);
    border: 1px solid var(--emls-v2-border);
    border-radius: var(--emls-v2-border-radius);
    box-shadow: 0 4px 12px var(--emls-v2-shadow);
}

.emls-v2-dropdown.is-open .emls-v2-dropdown__menu {
    display: block;
}

.emls-v2-dropdown__search {
    position: sticky;
    top: 0;
    padding: var(--emls-v2-gap-sm);
    background: var(--emls-v2-bg);
    border-bottom: 1px solid var(--emls-v2-border);
}

.emls-v2-dropdown__search-input {
    width: 100%;
    padding: var(--emls-v2-gap-sm);
    font-size: var(--emls-v2-font-sm);
    border: 1px solid var(--emls-v2-border);
    border-radius: var(--emls-v2-border-radius);
}

.emls-v2-dropdown__search-input:focus {
    outline: none;
    border-color: var(--emls-v2-primary);
}

.emls-v2-dropdown__clear {
    padding: var(--emls-v2-gap-sm) var(--emls-v2-gap-md);
    font-size: var(--emls-v2-font-sm);
    color: var(--emls-v2-primary);
    text-align: center;
    cursor: pointer;
    border-bottom: 1px solid var(--emls-v2-border);
    transition: background var(--emls-v2-transition);
}

.emls-v2-dropdown__clear:hover {
    background: var(--emls-v2-bg-hover);
}

.emls-v2-dropdown__group {
    border-bottom: 1px solid var(--emls-v2-border);
}

.emls-v2-dropdown__group:last-child {
    border-bottom: none;
}

.emls-v2-dropdown__group-label {
    padding: var(--emls-v2-gap-sm) var(--emls-v2-gap-md);
    font-size: var(--emls-v2-font-sm);
    font-weight: 600;
    color: var(--emls-v2-text-light);
    background: var(--emls-v2-bg-alt);
}

.emls-v2-dropdown__option {
    display: flex;
    align-items: center;
    padding: var(--emls-v2-gap-sm) var(--emls-v2-gap-md);
    cursor: pointer;
    transition: background var(--emls-v2-transition);
}

.emls-v2-dropdown__option:hover {
    background: var(--emls-v2-bg-hover);
}

.emls-v2-dropdown__option input[type="checkbox"],
.emls-v2-dropdown__option input[type="radio"] {
    margin-right: var(--emls-v2-gap-sm);
    cursor: pointer;
}

.emls-v2-dropdown__option label {
    flex: 1;
    font-size: var(--emls-v2-font-sm);
    color: var(--emls-v2-text);
    cursor: pointer;
    user-select: none;
}

/* ===== Range Slider ===== */
.emls-v2-range {
    padding: var(--emls-v2-gap-md);
    background: var(--emls-v2-bg-alt);
    border: 1px solid var(--emls-v2-border);
    border-radius: var(--emls-v2-border-radius);
}

.emls-v2-range__labels {
    display: flex;
    justify-content: space-between;
    margin-bottom: var(--emls-v2-gap-sm);
    font-size: var(--emls-v2-font-sm);
    font-weight: 600;
    color: var(--emls-v2-text);
}

.emls-v2-range__slider {
    margin: var(--emls-v2-gap-md) 0;
}

/* jQuery UI Slider Customization */
.emls-v2-range .ui-slider {
    position: relative;
    height: 6px;
    background: var(--emls-v2-border);
    border: none;
    border-radius: 3px;
}

.emls-v2-range .ui-slider-range {
    position: absolute;
    height: 100%;
    background: var(--emls-v2-primary);
    border-radius: 3px;
}

.emls-v2-range .ui-slider-handle {
    position: absolute;
    top: 50%;
    width: 18px;
    height: 18px;
    margin-top: -9px;
    margin-left: -9px;
    background: var(--emls-v2-primary);
    border: 2px solid var(--emls-v2-bg);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px var(--emls-v2-shadow);
    transition: transform var(--emls-v2-transition), box-shadow var(--emls-v2-transition);
}

.emls-v2-range .ui-slider-handle:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 6px var(--emls-v2-shadow);
}

.emls-v2-range .ui-slider-handle:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.3);
}

.emls-v2-range__inputs {
    display: flex;
    gap: var(--emls-v2-gap-sm);
    margin-top: var(--emls-v2-gap-md);
}

.emls-v2-range__input {
    flex: 1;
    height: 40px;
    padding: 0 var(--emls-v2-gap-sm);
    font-size: var(--emls-v2-font-sm);
    text-align: center;
    border: 1px solid var(--emls-v2-border);
    border-radius: var(--emls-v2-border-radius);
    background: var(--emls-v2-bg);
}

.emls-v2-range__input:focus {
    outline: none;
    border-color: var(--emls-v2-primary);
}

.emls-property-search-v2 .emls-v2-submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    height: var(--emls-v2-field-height);
    padding: 0 var(--emls-v2-gap-lg);
    font-size: var(--emls-v2-font-md);
    font-weight: 600;
    color: var(--emls-v2-button-text-color, #ffffff);
    background-color: var(--emls-v2-button-bg-color, var(--emls-v2-primary));
    border: none;
    border-radius: var(--emls-v2-border-radius);
    box-sizing: border-box;
    cursor: pointer;
    transition: background-color var(--emls-v2-transition), transform var(--emls-v2-transition);
}

.emls-property-search-v2 .emls-v2-submit:hover {
    color: var(--emls-v2-button-text-color-hover, var(--emls-v2-button-text-color, #ffffff));
    background-color: var(--emls-v2-button-bg-color-hover, var(--emls-v2-primary-hover));
    transform: translateY(-1px);
}

.emls-property-search-v2 .emls-v2-submit:active {
    transform: translateY(0);
}

.emls-property-search-v2 .emls-v2-submit:disabled,
.emls-property-search-v2 .emls-v2-submit.is-loading {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ===== Loading Spinner ===== */
.emls-property-search-v2.is-loading {
    pointer-events: none;
}

.emls-property-search-v2.is-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--emls-v2-z-spinner);
    background: rgba(255, 255, 255, 0.7);
}

.emls-v2-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: calc(var(--emls-v2-z-spinner) + 1);
    transform: translate(-50%, -50%);
}

.emls-v2-spinner__icon {
    display: block;
    width: 40px;
    height: 40px;
    border: 3px solid var(--emls-v2-border);
    border-top-color: var(--emls-v2-primary);
    border-radius: 50%;
    animation: emls-v2-spin 1s linear infinite;
}

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

/* ===== Search Results ===== */
.emls-v2-results {
    margin-top: var(--emls-v2-gap-lg);
}

.emls-v2-results__grid {
    display: grid;
    grid-template-columns: repeat(var(--emls-v2-columns, 3), 1fr);
    gap: var(--emls-v2-gap-md);
}

.emls-v2-error {
    padding: var(--emls-v2-gap-lg);
    text-align: center;
    color: #d63638;
    background: #fcf0f1;
    border: 1px solid #d63638;
    border-radius: var(--emls-v2-border-radius);
}

.emls-v2-no-results {
    padding: var(--emls-v2-gap-xl);
    text-align: center;
    color: var(--emls-v2-text-light);
    font-size: var(--emls-v2-font-md);
}

/* ===== Property Card (Simple Grid Fallback) ===== */
.emls-v2-property-card {
    position: relative;
    background: var(--emls-v2-bg);
    border: 1px solid var(--emls-v2-border);
    border-radius: var(--emls-v2-border-radius);
    overflow: hidden;
    transition: box-shadow var(--emls-v2-transition), transform var(--emls-v2-transition);
}

.emls-v2-property-card:hover {
    box-shadow: 0 4px 12px var(--emls-v2-shadow);
    transform: translateY(-2px);
}

.emls-v2-property-card a {
    display: block;
    color: inherit;
    text-decoration: none;
}

.emls-v2-property-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.emls-v2-property-card h3 {
    margin: var(--emls-v2-gap-md);
    font-size: var(--emls-v2-font-md);
    font-weight: 600;
    color: var(--emls-v2-text);
}

.emls-v2-property__price {
    margin: 0 var(--emls-v2-gap-md);
    font-size: var(--emls-v2-font-lg);
    font-weight: 700;
    color: var(--emls-v2-primary);
}

.emls-v2-property__details {
    margin: var(--emls-v2-gap-sm) var(--emls-v2-gap-md);
    font-size: var(--emls-v2-font-sm);
    color: var(--emls-v2-text);
}

.emls-v2-property__location {
    margin: 0 var(--emls-v2-gap-md) var(--emls-v2-gap-md);
    font-size: var(--emls-v2-font-sm);
    color: var(--emls-v2-text-light);
}

/* ===== Pagination ===== */
.emls-v2-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--emls-v2-gap-xs);
    margin-top: var(--emls-v2-gap-lg);
}

.emls-v2-pagination__link,
.emls-v2-pagination__current {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 var(--emls-v2-gap-sm);
    font-size: var(--emls-v2-font-sm);
    font-weight: 500;
    text-decoration: none;
    border-radius: var(--emls-v2-border-radius);
    transition: all var(--emls-v2-transition);
}

.emls-v2-pagination__link {
    color: var(--emls-v2-text);
    background: var(--emls-v2-bg);
    border: 1px solid var(--emls-v2-border);
}

.emls-v2-pagination__link:hover {
    background: var(--emls-v2-bg-hover);
    border-color: var(--emls-v2-primary);
}

.emls-v2-pagination__current {
    color: #ffffff;
    background: var(--emls-v2-primary);
    border: 1px solid var(--emls-v2-primary);
}

.emls-v2-pagination__ellipsis {
    padding: 0 var(--emls-v2-gap-xs);
    color: var(--emls-v2-text-light);
}

.emls-v2-pagination__prev,
.emls-v2-pagination__next {
    font-size: 16px;
}

/* ===== Accessibility ===== */
@media (prefers-reduced-motion: reduce) {
    .emls-property-search-v2 *,
    .emls-property-search-v2 *::before,
    .emls-property-search-v2 *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible styles */
.emls-v2-field__input:focus-visible,
.emls-v2-field__select:focus-visible,
.emls-v2-dropdown__trigger:focus-visible,
.emls-v2-submit:focus-visible {
    outline: 2px solid var(--emls-v2-primary);
    outline-offset: 2px;
}

/* Screen reader only */
.emls-v2-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;
}
