/* =====================================================
   KhojSelect — Custom Modern Searchable Dropdown
   Replaces Select2 on all public-facing pages
   ===================================================== */

.ks-wrapper {
    position: relative;
    width: 100%;
    font-family: inherit;
    font-size: 14px;
}

/* Trigger button */
.ks-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    min-height: 42px;
    padding: 9px 14px;
    background: #fff;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    transition: border-color .2s, box-shadow .2s;
    box-sizing: border-box;
}
.ks-trigger:hover { border-color: #e40001; }
.ks-trigger.ks-open {
    border-color: #e40001;
    box-shadow: 0 0 0 3px rgba(228,0,1,.10);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

/* Display area */
.ks-display {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    line-height: 1.4;
}
.ks-placeholder { color: #9ca3af; }
.ks-selected-text { color: #1f2937; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Multi-select tags */
.ks-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #fff0f0;
    color: #e40001;
    border: 1px solid #fecaca;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}
.ks-tag-remove {
    width: 14px; height: 14px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    transition: background .15s, color .15s;
    flex-shrink: 0;
}
.ks-tag-remove:hover { background: #e40001; color: #fff; }

/* Right side controls */
.ks-controls { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.ks-clear-btn {
    width: 18px; height: 18px;
    display: none;
    align-items: center; justify-content: center;
    border-radius: 50%;
    background: #e5e7eb;
    color: #6b7280;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    transition: background .15s, color .15s;
}
.ks-clear-btn:hover { background: #e40001; color: #fff; }
.ks-clear-btn.ks-visible { display: flex; }

.ks-arrow {
    color: #9ca3af;
    transition: transform .25s, color .25s;
    flex-shrink: 0;
}
.ks-trigger.ks-open .ks-arrow { transform: rotate(180deg); color: #e40001; }

/* ===== DROPDOWN PANEL ===== */
.ks-panel {
    position: absolute;
    top: 100%;
    left: 0; right: 0;
    background: #fff;
    border: 1.5px solid #e40001;
    border-top: none;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    box-shadow: 0 12px 40px rgba(0,0,0,.12);
    z-index: 9999;
    display: none;
    flex-direction: column;
    max-height: 340px;
    overflow: hidden;
}
.ks-panel.ks-open { display: flex; }

/* Search box inside panel */
.ks-search-wrap {
    padding: 10px 10px 8px;
    border-bottom: 1px solid #f3f4f6;
    background: #fff;
    flex-shrink: 0;
}
.ks-search-inner { position: relative; }
.ks-search-icon {
    position: absolute;
    left: 10px; top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    pointer-events: none;
}
.ks-search-input {
    width: 100%;
    padding: 8px 12px 8px 34px;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    background: #f9fafb;
    color: #374151;
    transition: border-color .2s, background .2s;
    box-sizing: border-box;
}
.ks-search-input:focus {
    border-color: #e40001;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(228,0,1,.08);
}
.ks-search-input::placeholder { color: #b0b7c3; }

/* Options list */
.ks-list {
    overflow-y: auto;
    flex: 1;
    padding: 6px;
}
.ks-list::-webkit-scrollbar { width: 4px; }
.ks-list::-webkit-scrollbar-track { background: transparent; }
.ks-list::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 4px; }
.ks-list::-webkit-scrollbar-thumb:hover { background: #e40001; }

/* Option items */
.ks-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: #374151;
    transition: background .15s, color .15s;
    user-select: none;
}
.ks-option:hover { background: #fff5f5; color: #e40001; }
.ks-option.ks-selected {
    background: #e40001;
    color: #fff;
    font-weight: 600;
}
.ks-option.ks-selected:hover { background: #c90000; }

/* Checkbox for multi */
.ks-checkbox {
    width: 16px; height: 16px;
    border: 2px solid #d1d5db;
    border-radius: 4px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    transition: all .15s;
}
.ks-option.ks-selected .ks-checkbox {
    border-color: transparent;
    background: rgba(255,255,255,.25);
}

/* No results */
.ks-no-results {
    padding: 20px 12px;
    text-align: center;
    color: #9ca3af;
    font-size: 13px;
}
.ks-no-results-icon { font-size: 24px; margin-bottom: 6px; }

/* Focus state for keyboard nav */
.ks-option.ks-focused { background: #fff5f5; color: #e40001; outline: none; }
.ks-option.ks-selected.ks-focused { background: #c90000; }

/* Disabled state */
.ks-wrapper.ks-disabled .ks-trigger {
    background: #f9fafb;
    cursor: not-allowed;
    opacity: .65;
}

/* Loading state (for future AJAX) */
.ks-loading {
    padding: 16px;
    text-align: center;
    color: #9ca3af;
    font-size: 13px;
}

/* Fit inside custom_input_design */
.custom_input_design + .ks-wrapper .ks-trigger,
.ks-trigger.custom_input_design {
    border-radius: 8px;
}

/* Override border-radius for filter sidebar multi-select */
.custom_rounded .ks-trigger { border-radius: 8px; }

/* Mobile: full-width panel on small screens */
@media (max-width: 640px) {
    .ks-panel { max-height: 260px; }
}

/* Animation */
@keyframes ks-fade-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ks-panel.ks-open { animation: ks-fade-in .18s ease; }
