/**
 * Filter Inputs - jedinstveni CSS za sve input polja u filterima
 * Uključuje: native select/input, custom-select (autocomplete), filter-select, X dugmad, filter-has-value
 * Učitati zajedno sa filter-forms.css na stranicama sa filterima.
 */

/* ========== Filter section - stilovi za input/select u filter kontekstu ========== */
.filter-section .filter-bar select,
.filter-section .filter-bar input[type="date"],
.filter-section .filter-bar input[type="text"],
.filter-section .filter-bar input[type="search"],
.filter-section .filter-bar .date-input-clearable-wrapper input,
.filter-section .filter-bar .filter-select .select-trigger,
.filter-section .filter-bar .filter-multiselect .multiselect-trigger,
.filter-section .filter-bar .custom-select .custom-select-button,
.filter-section .filter-form .filter-select .select-trigger,
.filter-section .filter-form .filter-multiselect .multiselect-trigger,
.filter-section .filter-form .custom-select .custom-select-button {
    height: 44px;
}
.filter-section .filter-bar .filter-select .select-trigger,
.filter-section .filter-bar .filter-multiselect .multiselect-trigger,
.filter-section .filter-form select,
.filter-section .filter-form input[type="date"],
.filter-section .filter-form input[type="text"],
.filter-section .filter-form input[type="search"],
.filter-section .filter-form .date-input-clearable-wrapper input,
.filter-section .filter-form .filter-select .select-trigger,
.filter-section .filter-form .filter-multiselect .multiselect-trigger,
.filter-section .filter-bar .custom-select .custom-select-button,
.filter-section .filter-form .custom-select .custom-select-button {
    padding: 0.75rem 1rem;
    border: 2px solid #3b82f6;
    border-radius: 6px;
    font-size: 1rem;
    background: #fff;
    min-height: 44px;
    height: 44px;
    line-height: 1.5;
    box-sizing: border-box;
}

.filter-section .filter-bar select,
.filter-section .filter-bar input[type="text"],
.filter-section .filter-bar input[type="search"],
.filter-section .filter-form select,
.filter-section .filter-form input[type="text"],
.filter-section .filter-form input[type="search"] {
    min-width: 180px;
}

.filter-section .filter-bar select:hover,
.filter-section .filter-bar input:hover,
.filter-section .filter-bar .date-input-clearable-wrapper input:hover,
.filter-section .filter-bar .filter-select .select-trigger:hover,
.filter-section .filter-bar .filter-multiselect .multiselect-trigger:hover,
.filter-section .filter-form select:hover,
.filter-section .filter-form input:hover,
.filter-section .filter-form .date-input-clearable-wrapper input:hover,
.filter-section .filter-form .filter-select .select-trigger:hover,
.filter-section .filter-form .filter-multiselect .multiselect-trigger:hover,
.filter-section .filter-bar .custom-select .custom-select-button:hover,
.filter-section .filter-form .custom-select .custom-select-button:hover {
    border-color: #2563eb;
}

.filter-section .filter-bar select:focus,
.filter-section .filter-bar input:focus,
.filter-section .filter-bar .date-input-clearable-wrapper input:focus,
.filter-section .filter-bar .filter-select .select-trigger:focus,
.filter-section .filter-bar .filter-multiselect .multiselect-trigger:focus,
.filter-section .filter-form select:focus,
.filter-section .filter-form input:focus,
.filter-section .filter-form .date-input-clearable-wrapper input:focus,
.filter-section .filter-form .filter-select .select-trigger:focus,
.filter-section .filter-form .filter-multiselect .multiselect-trigger:focus,
.filter-section .filter-bar .custom-select .custom-select-button:focus,
.filter-section .filter-form .custom-select .custom-select-button:focus {
    outline: none;
    border-color: #1d4ed8;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* ========== X ikonica - dugme za čišćenje ========== */
.filter-clear-btn,
.select-clear-btn,
.date-clear-btn,
.custom-select-clear {
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #64748b;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.filter-clear-btn:hover,
.select-clear-btn:hover,
.date-clear-btn:hover,
.custom-select-clear:hover {
    background: transparent;
    color: #475569;
}

/* Autocomplete - spinner pri učitavanju (remote search) */
.custom-select-loading .custom-select-button {
    position: relative;
}
.custom-select-loading .custom-select-button::after {
    content: '';
    position: absolute;
    right: 2.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1rem;
    height: 1rem;
    border: 2px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: custom-select-spin 0.6s linear infinite;
}
@keyframes custom-select-spin {
    to { transform: translateY(-50%) rotate(360deg); }
}
.custom-select-loading .custom-select-options-list {
    position: relative;
    min-height: 2rem;
}
.custom-select-loading .custom-select-options-list:empty::before {
    content: '';
    display: block;
    width: 1.25rem;
    height: 1.25rem;
    margin: 0.75rem auto;
    border: 2px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: custom-select-spin 0.6s linear infinite;
}

/* Select sa X - native select */
.select-with-clear-wrapper {
    position: relative;
    display: block;
    width: 100%;
}

.select-with-clear-wrapper select {
    padding-right: 3.5rem;
    width: 100%;
    box-sizing: border-box;
}

.select-clear-btn {
    position: absolute;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
}

/* Date input sa X */
.date-input-clearable-wrapper {
    position: relative;
    display: inline-block;
}

.date-input-clearable-wrapper .flatpickr-input,
.date-input-clearable-wrapper input[data-flatpickr],
.date-input-clearable-wrapper input {
    padding-right: 2.25rem;
}

.date-clear-btn {
    position: absolute;
    right: 0.35rem;
    top: 50%;
    transform: translateY(-50%);
}

/* Date wrapper u filterima - puna širina, usklađen layout */
.filter-section .filter-bar .date-input-clearable-wrapper,
.filter-section .filter-form .date-input-clearable-wrapper,
.filter-group .date-input-clearable-wrapper,
.filter-form .date-pair .date-input-clearable-wrapper {
    display: block;
    width: 100%;
    min-width: 140px;
    flex: 1 1 auto;
}

.filter-section .filter-bar .date-input-clearable-wrapper input,
.filter-section .filter-form .date-input-clearable-wrapper input,
.filter-group .date-input-clearable-wrapper input,
.filter-form .date-pair .date-input-clearable-wrapper input {
    width: 100%;
    min-height: 44px;
    padding-right: 2.25rem;
    box-sizing: border-box;
}

/* Custom select (autocomplete) i filter-select - X je u buttonu */
.custom-select-clear,
.filter-select .select-clear-btn {
    position: static;
    transform: none;
    flex-shrink: 0;
}

/* ========== Filter has value - samo promena boje, bez promene dimenzija ========== */
.filter-has-value .custom-select-button,
.filter-has-value .select-trigger,
.filter-has-value.form-input,
.filter-has-value.filter-multiselect .multiselect-trigger,
select.filter-has-value,
input.filter-has-value,
.date-input-clearable-wrapper.filter-has-value input,
/* Flatpickr: kada datum ima vrednost, stilizuj i alt input (vidljiv) */
.filter-item:has(input.filter-has-value) input.flatpickr-input {
    border: 2px solid #0284c7 !important;
    background: #f0f9ff !important;
}

.filter-has-value .custom-select-button:focus,
.filter-has-value .select-trigger:focus,
.filter-has-value.filter-multiselect .multiselect-trigger:focus,
select.filter-has-value:focus,
input.filter-has-value:focus,
.date-input-clearable-wrapper.filter-has-value input:focus,
.filter-item:has(input.filter-has-value) input.flatpickr-input:focus {
    border-color: #0369a1 !important;
}

label.checkbox-inline.filter-has-value {
    padding: 0.4rem 0.75rem;
    border: 2px solid #0284c7;
    border-radius: 6px;
    background: #f0f9ff;
    font-weight: 600;
}

/* ========== Custom Select (autocomplete) - searchable dropdown ========== */
.custom-select,
.form-autocomplete {
    position: relative;
    min-width: 200px;
    width: 100%;
    box-sizing: border-box;
}

/* .custom-select-button base u buttons.css */

.custom-select-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

.custom-select-options {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.12);
    display: none;
    z-index: 20;
    overflow: hidden;
    box-sizing: border-box;
}

.custom-select-options-list {
    max-height: 200px;
    overflow-y: auto;
}

.custom-select-no-results {
    padding: 0.75rem;
    color: #64748b;
    font-size: 0.9rem;
    text-align: left;
}

.custom-select.open .custom-select-options {
    display: block;
}

.custom-select-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    text-align: left;
}

.custom-select-option:hover {
    background: #f8fafc;
}

.custom-option-name {
    flex: 1;
    min-width: 0;
}

.custom-option-count,
.custom-select-count {
    color: #64748b;
    font-weight: 600;
    white-space: nowrap;
    margin-left: auto;
}

.custom-select .custom-select-button,
.custom-select .custom-select-label,
.custom-select .custom-select-option,
.custom-select .custom-select-search,
.custom-select .custom-select-no-results {
    text-align: left !important;
}

/* ========== Native select (bez data-autocomplete) - appearance:none, strelica, text-align:left ========== */
/* Samo obični selecti - data-autocomplete zadržava svoj postojeći izgled */
.filter-section .filter-bar select:not([data-autocomplete]),
.filter-section .filter-form select:not([data-autocomplete]) {
    appearance: none;
    cursor: pointer;
    color: #0f172a;
    text-align: left;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-color: #fff;
    padding: 0.625rem 2.25rem 0.625rem 1rem;
    line-height: 1.5;
    height: 44px;
    min-height: 44px;
    box-sizing: border-box;
}
.filter-section .filter-bar select:not([data-autocomplete]):hover,
.filter-section .filter-form select:not([data-autocomplete]):hover {
    border-color: #2563eb;
}
.filter-section .filter-bar select:not([data-autocomplete]):focus,
.filter-section .filter-form select:not([data-autocomplete]):focus {
    outline: none;
    border-color: #1d4ed8;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* ========== data-autocomplete i filter-select-native - originalni izgled (ne dira) ========== */
.filter-section .filter-bar select[data-autocomplete],
.filter-section .filter-form select[data-autocomplete],
.filter-section .filter-bar select.filter-select-native,
.filter-section .filter-form select.filter-select-native {
    appearance: none;
    cursor: pointer;
    color: #0f172a;
    text-align: left;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-color: #fff;
    padding-top: 0.45rem;
    padding-bottom: 0.8rem;
    padding-left: 1rem;
    padding-right: 2.25rem;
    line-height: 1.5;
    height: 44px;
    min-height: 44px;
    box-sizing: border-box;
}
.filter-section .filter-bar select[data-autocomplete]:hover,
.filter-section .filter-form select[data-autocomplete]:hover,
.filter-section .filter-bar select.filter-select-native:hover,
.filter-section .filter-form select.filter-select-native:hover {
    border-color: #2563eb;
}
.filter-section .filter-bar select[data-autocomplete]:focus,
.filter-section .filter-form select[data-autocomplete]:focus,
.filter-section .filter-bar select.filter-select-native:focus,
.filter-section .filter-form select.filter-select-native:focus {
    outline: none;
    border-color: #1d4ed8;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Select sa X (data-clearable) - više mesta za dugme */
.filter-section .select-with-clear-wrapper select {
    padding-right: 3.5rem;
}

/* ========== select[data-autocomplete] svuda (van .filter-section) - isti izgled pre učitavanja JS ========== */
select[data-autocomplete] {
    appearance: none;
    cursor: pointer;
    color: #0f172a;
    text-align: left;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-color: #fff;
    padding-top: 0.45rem;
    padding-bottom: 0.8rem;
    padding-left: 1rem;
    padding-right: 2.25rem;
    line-height: 1.5;
    min-height: 44px;
    height: 44px;
    box-sizing: border-box;
    border: 2px solid #3b82f6;
    border-radius: 6px;
    font-size: 1rem;
}
select[data-autocomplete]:hover {
    border-color: #2563eb;
}
select[data-autocomplete]:focus {
    outline: none;
    border-color: #1d4ed8;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* ========== Filter Select - searchable dropdown (KIF, Documents) ========== */
.filter-select-native-wrap {
    position: relative;
    min-width: 0;
    width: 100%;
    flex: 1 1 0;
    box-sizing: border-box;
}

.filter-select {
    position: relative;
    min-width: 0;
    width: 100%;
    flex: 1 1 0;
    box-sizing: border-box;
}

.filter-select .select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border: 2px solid #3b82f6;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    width: 100%;
    min-height: 44px;
    height: 44px;
    font-size: 1rem;
    box-sizing: border-box;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.filter-select .select-trigger .select-label,
.filter-select .select-trigger > span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

.filter-select .select-trigger:hover {
    border-color: #2563eb;
}

.filter-select .select-trigger::after {
    content: '▼';
    font-size: 0.65rem;
    color: #64748b;
    margin-left: 0.25rem;
}

.filter-select.open .select-options {
    display: block;
}

.filter-select .select-options {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.12);
    display: none;
    z-index: 100;
    overflow: hidden;
    box-sizing: border-box;
}

/* Search input - filter-select i custom-select */
.filter-select .select-search,
.custom-select .custom-select-search {
    padding: 0.5rem 0.75rem;
    border: none;
    border-bottom: 1px solid #e2e8f0;
    width: 100%;
    box-sizing: border-box;
    font-size: 0.95rem;
    font-family: inherit;
    color: #0f172a;
    background: #fff;
    min-height: 38px;
    line-height: 1.5;
    text-align: left;
    border-radius: 8px 8px 0 0;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.filter-select .select-search:focus,
.custom-select .custom-select-search:focus {
    outline: none;
    border-bottom-color: #3b82f6;
    box-shadow: 0 1px 0 0 #3b82f6;
}

.filter-select .select-search::placeholder,
.custom-select .custom-select-search::placeholder {
    color: #94a3b8;
}

.filter-select .select-search:hover,
.custom-select .custom-select-search:hover {
    border-bottom-color: #cbd5e1;
}

.filter-select .select-list {
    max-height: 220px;
    overflow-y: auto;
}

.filter-select .select-option {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    text-align: left;
}

.filter-select .select-option:hover {
    background: #f1f5f9;
}

.filter-select .select-no-results {
    padding: 0.75rem;
    color: #64748b;
    font-size: 0.9rem;
    text-align: left;
    display: none;
}

.filter-select .select-no-results.visible {
    display: block;
}

/* Modal - dropdown ne sme biti širi od inputa */
.modal-overlay .filter-select,
.modal-overlay .custom-select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.modal-overlay .filter-select .select-options,
.modal-overlay .custom-select .custom-select-options {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    left: 0;
    right: 0;
    box-sizing: border-box;
}

.modal-overlay .filter-select-native-wrap,
.modal-overlay .select-with-clear-wrapper {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

/* Veći razmak između X i strelice - lakši tap na mobilnom */
.filter-section .custom-select .custom-select-button {
    gap: 0.75rem;
}

/* Override - filter-select i custom-select pune širine u filter kontekstu */
.filter-bar .filter-select,
.filter-bar .custom-select,
.filter-form .filter-select,
.filter-form .custom-select,
.filter-item .filter-select,
.filter-item .custom-select {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
}

/* filter-item sa owner-search-select/custom-select - šira min širina za autocomplete (nazivi firmi)
   Uvek ista min-width (240px) da input ne raste nakon izbora vrednosti */
.filter-bar .filter-row .filter-item:has(.filter-select),
.filter-bar .filter-row .filter-item:has(.custom-select),
.filter-bar .filter-row .filter-item:has(.filter-multiselect),
.filter-bar .filter-row .filter-item:has(.filter-select-native-wrap),
.filter-bar .filter-row .filter-item:has(select[data-clearable]),
.filter-bar .filter-row .filter-item:has(select[data-replace-with-filter-select]),
.filter-form .filter-item:has(.filter-select),
.filter-form .filter-item:has(.custom-select),
.filter-form .filter-item:has(.filter-multiselect),
.filter-form .filter-item:has(.filter-select-native-wrap),
.filter-form .filter-item:has(select[data-clearable]),
.filter-form .filter-item:has(select[data-replace-with-filter-select]) {
    min-width: 240px !important;
}

/* ========== Filter multiselect (status, tip, itd.) ========== */
.filter-multiselect {
    position: relative;
    min-width: 0;
    width: 100%;
    flex: 1 1 0;
    box-sizing: border-box;
}
.filter-multiselect .multiselect-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border: 2px solid #3b82f6;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    width: 100%;
    min-height: 44px;
    height: 44px;
    font-size: 1rem;
    box-sizing: border-box;
    transition: border-color 0.2s ease, background-color 0.2s ease;
    font-family: inherit;
    text-align: left;
}
.filter-multiselect .multiselect-trigger:hover {
    border-color: #2563eb;
}
.filter-multiselect .multiselect-trigger::after {
    content: '▼';
    font-size: 0.65rem;
    color: #64748b;
    margin-left: 0.25rem;
}
.filter-multiselect .multiselect-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.filter-multiselect .multiselect-clear {
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #64748b;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}
.filter-multiselect .multiselect-clear:hover {
    color: #475569;
}
.filter-multiselect.open .multiselect-dropdown {
    display: block;
}
.filter-multiselect .multiselect-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    min-width: 180px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.12);
    display: none;
    z-index: 100;
    padding: 0.5rem 0;
    box-sizing: border-box;
}
.filter-multiselect .multiselect-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    margin: 0;
    font-weight: normal;
}
.filter-multiselect .multiselect-option:hover {
    background: #f1f5f9;
}
.filter-multiselect .multiselect-option input {
    margin: 0;
    cursor: pointer;
}

/* ========== Responsive - filter controls ========== */
@media (max-width: 828px) {
    .custom-select.filter-control,
    .select-with-clear-wrapper,
    .filter-select-native-wrap {
        min-width: 0 !important;
        width: 100% !important;
        max-width: none !important;
    }
    .select-with-clear-wrapper select {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }
}

@media (max-width: 540px) {
    .custom-select.filter-control,
    .select-with-clear-wrapper,
    .filter-select-native-wrap {
        min-width: 0 !important;
        width: 100% !important;
        max-width: none !important;
    }
    .select-with-clear-wrapper select {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }
}

