/* ============================================================
   EntityPicker - أداة البحث والاختيار الشاملة
   تصميم احترافي متوافق مع Bootstrap 5 + RTL
   ============================================================ */

/* ─── الحاوية الرئيسية ─── */
.ep-wrapper {
    position: relative;
    width: 100%;
}

/* ─── مجموعة الإدخال ─── */
.ep-input-group {
    display: flex;
    align-items: stretch;
    border: 1.5px solid #dee2e6;
    border-radius: 8px;
    /* overflow: hidden; تمت إزالته للسماح للقائمة المنسدلة بالظهور */
    overflow: visible;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: #fff;
}

/* الحفاظ على انحناء الأطراف للأزرار الأولى والأخيرة داخل الحقل */
.ep-input-group > *:first-child {
    border-start-start-radius: 7px;
    border-end-start-radius: 7px;
}
.ep-input-group > *:last-child {
    border-start-end-radius: 7px;
    border-end-end-radius: 7px;
}

.ep-input-group:focus-within {
    border-color: var(--bs-primary, #0d6efd);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.12);
}

/* زر البحث / الأيقونة */
.ep-search-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    background: transparent;
    border: none;
    border-inline-end: 1.5px solid #dee2e6;
    color: #6c757d;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.ep-search-btn:hover {
    background: rgba(13, 110, 253, 0.07);
    color: var(--bs-primary, #0d6efd);
}

/* حقل الكتابة */
.ep-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 8px 12px;
    font-size: 0.92rem;
    background: transparent;
    color: #212529;
    min-width: 0;
}

.ep-input::placeholder {
    color: #adb5bd;
}

/* حقل عرض القيمة المختارة (readonly) */
.ep-display-field {
    flex: 1;
    border: none;
    outline: none;
    padding: 8px 10px;
    font-size: 0.92rem;
    background: #f8f9fa;
    color: #495057;
    border-inline-start: 1.5px solid #dee2e6;
    cursor: default;
    min-width: 80px;
    font-weight: 500;
}

/* زر المسح */
.ep-clear-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    margin: auto 6px;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: #adb5bd;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.1s ease;
    flex-shrink: 0;
}

.ep-clear-btn:hover {
    color: #dc3545;
    background: #ffeeee;
}

.ep-clear-btn:active {
    transform: scale(0.9);
}

/* زر العمليات المخصصة (أيقونة مدمجة) */
.ep-op-btn, .ep-ops-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    background: transparent;
    border: none;
    border-inline-start: 1.5px solid #dee2e6;
    color: #6c757d;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
    text-decoration: none;
}

.ep-op-btn:hover, .ep-ops-toggle:hover {
    background: rgba(13, 110, 253, 0.07);
    color: var(--bs-primary, #0d6efd);
}

.ep-ops-dropdown {
    display: flex;
}

/* مؤشر التحميل */
.ep-spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid #dee2e6;
    border-top-color: var(--bs-primary, #0d6efd);
    border-radius: 50%;
    animation: ep-spin 0.7s linear infinite;
    flex-shrink: 0;
    margin: auto 10px;
}

.ep-wrapper.ep-loading .ep-spinner {
    display: block;
}

@keyframes ep-spin {
    to { transform: rotate(360deg); }
}

/* ─────────────────────────────────────────
   وضع Dropdown - قائمة النتائج المنسدلة
───────────────────────────────────────── */
.ep-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    inset-inline-start: 0;
    inset-inline-end: 0;
    z-index: 1055;
    background: #fff;
    border: 1.5px solid #dee2e6;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.08);
    overflow: hidden;
    display: none;
    animation: ep-slideDown 0.18s ease-out;
    max-height: 320px;
    overflow-y: auto;
}

.ep-dropdown.ep-open {
    display: block;
}

@keyframes ep-slideDown {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* جدول النتائج */
.ep-dropdown-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.ep-dropdown-table thead th {
    position: sticky;
    top: 0;
    background: #f1f3f9;
    color: #495057;
    font-weight: 600;
    padding: 8px 12px;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1px solid #dee2e6;
    z-index: 1;
}

.ep-dropdown-table tbody tr {
    cursor: pointer;
    transition: background 0.12s;
    border-bottom: 1px solid #f0f0f0;
}

.ep-dropdown-table tbody tr:last-child {
    border-bottom: none;
}

.ep-dropdown-table tbody tr:hover,
.ep-dropdown-table tbody tr.ep-highlighted {
    background: rgba(13, 110, 253, 0.08);
}

.ep-dropdown-table tbody tr.ep-highlighted {
    background: rgba(13, 110, 253, 0.14);
}

.ep-dropdown-table tbody td {
    padding: 9px 12px;
    color: #212529;
}

/* حالة لا توجد نتائج */
.ep-no-results {
    padding: 24px 16px;
    text-align: center;
    color: #9ca3af;
    font-size: 0.9rem;
}

.ep-no-results i {
    display: block;
    font-size: 1.8rem;
    margin-bottom: 8px;
    opacity: 0.5;
}

/* ─────────────────────────────────────────
   وضع Modal - الشاشة المنبثقة الفاخرة
───────────────────────────────────────── */
.ep-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9990;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: ep-fadeIn 0.2s ease;
}

@keyframes ep-fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.ep-modal-dialog {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.2), 0 4px 16px rgba(0,0,0,0.1);
    width: min(780px, 96vw);
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: ep-slideUp 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes ep-slideUp {
    from { opacity: 0; transform: scale(0.94) translateY(20px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* رأس المودال */
.ep-modal-header {
    background: linear-gradient(135deg, var(--bs-primary, #0d6efd) 0%, #0a58ca 100%);
    padding: 20px 24px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.ep-modal-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(45deg, rgba(255,255,255,0.08), transparent);
    pointer-events: none;
}

.ep-modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: 0.3px;
}

.ep-modal-close {
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    font-size: 1.1rem;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

.ep-modal-close:hover {
    background: rgba(255,255,255,0.25);
}

/* جسم المودال */
.ep-modal-body {
    padding: 20px 24px;
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* أشرطة التصفية السريعة (Filter Tabs) */
.ep-filter-tabs {
    display: inline-flex;
    align-items: center;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 10px;
    gap: 4px;
    margin-bottom: 14px;
    flex-wrap: wrap;
    border: 1px solid #e2e8f0;
    width: fit-content;
}

.ep-filter-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    font-size: 0.88rem;
    font-weight: 500;
    color: #64748b;
    background: transparent;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
    outline: none;
    line-height: 1.4;
}

.ep-filter-tab:hover {
    color: #1e293b;
    background: rgba(255, 255, 255, 0.6);
}

.ep-filter-tab.ep-tab-active {
    background: #ffffff;
    color: var(--bs-primary, #0d6efd);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
}

.ep-filter-tab .ep-tab-icon {
    display: inline-flex;
    align-items: center;
    font-size: 0.95em;
}

/* حقل البحث داخل المودال */
.ep-modal-search-wrap {
    position: relative;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.ep-modal-search-input {
    width: 100%;
    border: 2px solid var(--bs-primary, #0d6efd);
    border-radius: 50px;
    padding: 12px 48px 12px 20px;
    font-size: 1rem;
    outline: none;
    transition: box-shadow 0.2s;
    color: #212529;
}

[dir="rtl"] .ep-modal-search-input {
    padding: 12px 20px 12px 48px;
}

.ep-modal-search-input:focus {
    box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.18);
}

.ep-modal-search-icon {
    position: absolute;
    top: 50%;
    inset-inline-end: 18px;
    transform: translateY(-50%);
    color: var(--bs-primary, #0d6efd);
    font-size: 1.1rem;
    pointer-events: none;
}

.ep-modal-search-spinner {
    position: absolute;
    top: 50%;
    inset-inline-end: 18px;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    border: 2px solid #dee2e6;
    border-top-color: var(--bs-primary, #0d6efd);
    border-radius: 50%;
    animation: ep-spin 0.7s linear infinite;
    display: none;
}

.ep-modal-loading .ep-modal-search-icon { display: none; }
.ep-modal-loading .ep-modal-search-spinner { display: block; }

/* حاوية جدول المودال */
.ep-modal-table-wrap {
    flex: 1;
    overflow-y: auto;
    border: 1.5px solid #dee2e6;
    border-radius: 10px;
    background: #fff;
    min-height: 280px;
    max-height: 380px;
}

.ep-modal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.ep-modal-table thead th {
    position: sticky;
    top: 0;
    background: #f8f9fa;
    color: #6c757d;
    font-weight: 700;
    padding: 12px 16px;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #dee2e6;
    z-index: 1;
}

.ep-modal-table tbody tr {
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid #f0f0f0;
}

.ep-modal-table tbody tr:last-child {
    border-bottom: none;
}

.ep-modal-table tbody tr:hover {
    background: rgba(13, 110, 253, 0.06);
}

.ep-modal-table tbody tr.ep-modal-highlighted {
    background: rgba(13, 110, 253, 0.12) !important;
}

.ep-modal-table tbody td {
    padding: 12px 16px;
    color: #212529;
    font-weight: 400;
}

.ep-modal-table tbody td:first-child {
    font-weight: 600;
    color: #0d6efd;
}

/* حالة فارغة في المودال */
.ep-modal-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #9ca3af;
    height: 100%;
    min-height: 200px;
}

.ep-modal-empty i {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.4;
}

.ep-modal-empty h6 {
    font-weight: 700;
    margin-bottom: 4px;
    color: #6b7280;
}

/* تذييل المودال */
.ep-modal-footer {
    padding: 14px 24px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    font-size: 0.82rem;
    color: #6c757d;
    gap: 12px;
}

.ep-modal-footer .ep-kbd-hint {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

kbd.ep-kbd {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    padding: 2px 7px;
    font-size: 0.78rem;
    box-shadow: 0 2px 0 #dee2e6;
    font-family: inherit;
    color: #495057;
}

kbd.ep-kbd-primary {
    background: var(--bs-primary, #0d6efd);
    border-color: var(--bs-primary, #0d6efd);
    color: #fff;
    box-shadow: 0 2px 0 #0a58ca;
}

.ep-result-count {
    font-weight: 700;
    color: var(--bs-primary, #0d6efd);
}

/* ─────────────────────────────────────────────────────────────
   ─── أنماط ميزة الإضافة السريعة (Add New) ───
   ───────────────────────────────────────────────────────────── */

/* زر الإضافة في حالة عدم وجود نتائج */
.ep-add-new-btn {
    margin-top: 12px;
    padding: 6px 16px;
    font-size: 0.9rem;
    border-radius: 20px;
    background: #e7f1ff;
    color: var(--bs-primary, #0d6efd);
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s, color 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ep-add-new-btn:hover {
    background: var(--bs-primary, #0d6efd);
    color: #fff;
}

.ep-add-new-btn:active {
    transform: scale(0.95);
}

/* Footer الثابت في أسفل القائمة المنسدلة */
.ep-dropdown-footer {
    position: sticky;
    bottom: 0;
    background: #fafafa;
    border-top: 1px solid #e9ecef;
    padding: 10px;
    display: flex;
    justify-content: center;
    z-index: 10;
}

.ep-dropdown-footer .ep-add-new-btn {
    margin-top: 0;
    width: 100%;
    justify-content: center;
    border-radius: 6px;
}

/* شاشة الإضافة المنبثقة (Iframe Overlay) */
.ep-iframe-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: ep-fade-in 0.25s forwards;
    padding: 20px;
}

.ep-iframe-dialog {
    background: #fff;
    width: 100%;
    max-width: 800px;
    height: 90vh;
    border-radius: 12px;
    box-shadow: 0 15px 50px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: ep-slide-down 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.ep-iframe-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.ep-iframe-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #212529;
    display: flex;
    align-items: center;
}

.ep-iframe-body {
    flex: 1;
    position: relative;
    background: #fdfdfd;
}

.ep-iframe-body iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

.ep-iframe-loader {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: #6c757d;
}
