﻿/* ===================================================
   Custom Select Dropdown Styles
   نسخه: 1.0
   تاریخ: 2025-02-06
   =================================================== */

.custom-select-wrapper {
    position: relative;
}

.custom-select-wrapper .custom-select-box {
    position: relative;
    cursor: pointer;
}

.custom-select-wrapper .selected-display {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    min-height: 38px;
    display: flex;
    align-items: center;
    transition: border-color 0.2s;
}

.custom-select-wrapper .selected-display:hover {
    border-color: #999;
}

.custom-select-wrapper .custom-select-box.active .selected-display {
    border-color: #4c9aff;
    box-shadow: 0 0 0 0.2rem rgba(76, 154, 255, 0.25);
}

.custom-select-wrapper .placeholder-text {
    color: #999;
}

.custom-select-wrapper .dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-top: 4px;
    z-index: 1050;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* باز شدن رو به بالا وقتی پایین جا نیست */
.custom-select-wrapper .custom-select-box.cs-drop-up .dropdown-content {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: 4px;
}

.custom-select-wrapper .custom-select-box.active .dropdown-content {
    display: block;
}

.custom-select-wrapper .search-box {
    padding: 8px;
    border-bottom: 1px solid #eee;
    position: relative;
}

.custom-select-wrapper .search-box i {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
}

.custom-select-wrapper .search-box input {
    padding-left: 32px;
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.custom-select-wrapper .search-box input:focus {
    outline: none;
    border-color: #4c9aff;
}

.custom-select-wrapper .options-container {
    overflow-y: auto;
    /* ✅ Max 6 items + scroll */
    max-height: 276px; /* 6 * 46px (item height with padding) */
}

.custom-select-wrapper .option-item {
    padding: 12px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid #e8e8e8;
    /* ✅ Checkbox + Text Layout */
    display: flex;
    gap: 12px;
    align-items: center;
    /* ✅ Light gray border for better separation */
    border-left: 3px solid transparent;
}

.custom-select-wrapper .option-item:last-child {
    border-bottom: none;
}

.custom-select-wrapper .option-item:hover {
    background: #f5f5f5;
    border-left-color: #ddd;
}

.custom-select-wrapper .option-item.selected {
    background: #e3f2fd;
    border-left-color: #2196F3;
}

/* ─── Pinned Option ─── */
.custom-select-wrapper .option-item.pinned-option {
    background: #f8f9fa;
    position: sticky;
    top: 0;
    z-index: 2;
    border-bottom: none;
}

.custom-select-wrapper .option-item.pinned-option:hover {
    background: #eef0f2;
}

.custom-select-wrapper .option-item.pinned-option.selected {
    background: #dde1e5;
}

.custom-select-wrapper .pinned-separator {
    height: 1px;
    background: #dee2e6;
    margin: 0 8px 2px 8px;
    position: sticky;
    top: 56px;
    z-index: 2;
}

.custom-select-wrapper .option-content {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.custom-select-wrapper .option-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.custom-select-wrapper .option-details {
    flex: 1;
    min-width: 0;
}

.custom-select-wrapper .option-title {
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.custom-select-wrapper .option-subtitle {
    font-size: 0.85em;
    color: #666;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
}

.custom-select-wrapper .option-subtitle span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.custom-select-wrapper .option-subtitle i {
    font-size: 0.9em;
}

/* Multi-Select Checkbox */
.custom-select-wrapper .option-checkbox {
    width: 20px;
    height: 20px;
    min-width: 20px;
    border: 2px solid #ccc;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: transparent;
    flex-shrink: 0;
    transition: all 0.2s;
    /* ✅ Checkmark inside */
    font-size: 12px;
    font-weight: bold;
    background: white;
}

.custom-select-wrapper .option-item.selected .option-checkbox {
    background: #2196F3;
    border-color: #2196F3;
    color: white;
}

/* ✅ Option Text Style */
.custom-select-wrapper .option-item .option-text {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Selected Tags (Multi-Select) */
.custom-select-wrapper .selected-tag {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    background: #e3f2fd;
    border-radius: 16px;
    font-size: 0.9em;
}

.custom-select-wrapper .selected-tag .remove-tag {
    cursor: pointer;
    color: #666;
    font-weight: bold;
    font-size: 1.2em;
    line-height: 1;
    transition: color 0.2s;
}

.custom-select-wrapper .selected-tag .remove-tag:hover {
    color: #f44336;
}

/* Scrollbar Styling */
.custom-select-wrapper .options-container::-webkit-scrollbar {
    width: 8px;
}

.custom-select-wrapper .options-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.custom-select-wrapper .options-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.custom-select-wrapper .options-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* بخش RTL/LTR Support ─────────────────────────────────────── */

/* RTL Support */
[dir="rtl"] .search-box i {
    left: auto;
    right: 16px;
}

[dir="rtl"] .search-box input {
    padding-left: 12px;
    padding-right: 32px;
}

/* ✅ RTL: Checkbox on right side - فقط برای option-item های ساده (checkbox + text) */
[dir="rtl"] .custom-select-wrapper .option-item:has(.option-checkbox):not(:has(.option-content)) {
    flex-direction: row-reverse;
}

[dir="rtl"] .custom-select-wrapper .option-item .option-text {
    text-align: right;
}

/* ✅ RTL: Badge remove on left */
[dir="rtl"] .filter-badge .badge-remove {
    margin-left: 0;
    margin-right: 4px;
}

/* Responsive */
@media (max-width: 768px) {
    .custom-select-wrapper .dropdown-content {
        position: fixed;
        top: auto !important;
        bottom: 0;
        left: 0;
        right: 0;
        margin: 0;
        border-radius: 16px 16px 0 0;
        max-height: 70vh;
        z-index: 10050;
    }

    .custom-select-wrapper .options-container {
        max-height: calc(70vh - 60px) !important;
    }

    .custom-select-wrapper .option-item {
        padding: 16px 12px;
    }

    .custom-select-wrapper .option-checkbox {
        width: 24px;
        height: 24px;
        min-width: 24px;
        font-size: 14px;
    }
}

/* ===================================================
   AJAX Select Styles (اضافه شده برای AJAX Support)
   =================================================== */

.custom-select-ajax-wrapper {
    position: relative;
}

.custom-select-ajax-box {
    position: relative;
    cursor: pointer;
}

.custom-select-ajax-box.active .dropdown-content {
    display: block;
}

/* باز شدن رو به بالا — AJAX */
.custom-select-ajax-wrapper.cs-drop-up .dropdown-content {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: 4px;
}

.ajax-results-container {
    padding: 4px;
}

.ajax-result-item {
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.2s;
    border-radius: 4px;
    margin-bottom: 4px;
}

.ajax-result-item:hover {
    background: #f5f5f5;
}

.ajax-result-item.selected {
    background: #e3f2fd;
    border: 1px solid #2196F3;
}

.ajax-result-item .option-content {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* ⭐⭐⭐ Checkbox for AJAX items */
.ajax-result-item .option-checkbox {
    width: 24px;
    height: 24px;
    border: 2px solid #ddd;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: transparent;
    flex-shrink: 0;
    transition: all 0.2s;
}

.ajax-result-item.selected .option-checkbox {
    background: #2196F3;
    border-color: #2196F3;
    color: white;
}

.ajax-result-item.selected .option-checkbox i {
    opacity: 1;
}

/* ⭐⭐⭐ Bulk Actions Bar (داخل Custom Select) - با scope محدود */
.custom-select-ajax-box .bulk-actions-bar {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid #eee;
    background: #f8f9fa;
}

.custom-select-ajax-box .btn-bulk-action {
    flex: 1;
    padding: 6px 12px;
    font-size: 0.875rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    color: #495057;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.custom-select-ajax-box .btn-bulk-action:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.custom-select-ajax-box .btn-bulk-action:active {
    transform: scale(0.98);
}

.custom-select-ajax-box .btn-bulk-action i {
    font-size: 0.875rem;
}

.custom-select-ajax-box .btn-select-all-ajax {
    border-color: #0d6efd;
    color: #0d6efd;
}

.custom-select-ajax-box .btn-select-all-ajax:hover {
    background: #0d6efd;
    color: white;
}

.custom-select-ajax-box .btn-clear-all-ajax {
    border-color: #6c757d;
    color: #6c757d;
}

.custom-select-ajax-box .btn-clear-all-ajax:hover {
    background: #6c757d;
    color: white;
}

/* Loading Animation */
.ajax-results-container .fa-spinner {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
