/* Exam Codifica Hub — عدّة الواجهة المشتركة: حالات السحب، ومقابض التحريك، وحلقات التركيز.
   ملف منفصل كما exam-window.css و exam-lock.css: إضافات على الواجهة وحدها، فلا تُلمس
   theme.css العام ولا يخاطر أي شيء آخر في المنصة.

   الألوان من رموز --panel-* لا من رموز الصفحة: عناصر القوائم تعيش على لوحات بيضاء
   بنصّ داكن في الوضعين، ورمز الصفحة (--text) يعطي أبيض على أبيض في الوضع النهاري. */

/* ---------- مخفي بصريًا وظاهر لقارئ الشاشة ---------- */
.ui-visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- حاوية قابلة لإعادة الترتيب ---------- */
.ui-sortable { position: relative; }

/* ---------- مقبض التحريك: ثلاث نقاط، ويظهر عند المرور أو التركيز ---------- */
.ui-grip {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    width: 22px;
    height: 30px;
    padding: 0 6px;
    margin-inline-end: 6px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    cursor: grab;
    opacity: .45;
    transition: opacity .12s ease, background .12s ease;
    touch-action: none;   /* شرط عمل السحب باللمس: لا تمرير للصفحة أثناء التحريك */
    flex: none;
}
.ui-grip span {
    display: block;
    width: 100%;
    height: 2px;
    border-radius: 2px;
    background: var(--panel-text-dim, #8a7678);
}
.ui-sortable [role="listitem"]:hover .ui-grip,
.ui-sortable [role="listitem"]:focus-within .ui-grip { opacity: 1; background: var(--panel-soft-2, #f7f0f0); }
.ui-grip:active { cursor: grabbing; }

/* مقبض محرّر الأسئلة القائم (⠿): نضيف له سلوك المسكّة لا شكله، فلا يتغيّر المنظر. */
.qed-handle {
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    padding-inline: 4px;
}
.qed-handle:active { cursor: grabbing; }

/* ---------- حالة الالتقاط (لوحة المفاتيح أو بداية السحب) ---------- */
.ui-sortable [role="listitem"].ui-grabbed {
    outline: 3px solid var(--primary, #d92b3f);
    outline-offset: 2px;
    border-radius: 10px;
    background: var(--panel-soft, #faf6f6);
}

/* ---------- حالة السحب الفعلي ---------- */
.ui-sortable [role="listitem"].ui-dragging {
    opacity: .92;
    box-shadow: 0 14px 34px rgba(2, 8, 20, .28);
    border-radius: 10px;
    z-index: 5;
    position: relative;
}

/* ---------- حلقة التركيز: لا يبقى عنصر بلا أثر مرئي للمفاتيح ---------- */
/* :focus-visible لا :focus — وإلا ظهرت الحلقة عند كل نقرة فأرة أيضًا */
.ui-sortable [role="listitem"]:focus-visible,
.ui-editable:focus-visible,
.ui-grip:focus-visible {
    outline: 3px solid var(--primary, #d92b3f);
    outline-offset: 2px;
}

/* ---------- تحرير في مكانه ---------- */
.ui-editable {
    border-radius: 8px;
    cursor: text;
    transition: background .12s ease, box-shadow .12s ease;
}
.ui-editable:hover { background: var(--panel-soft, #faf6f6); box-shadow: inset 0 0 0 1px var(--panel-border, #eddede); }
.ui-editable.ui-editing {
    background: var(--panel-bg, #ffffff);
    box-shadow: inset 0 0 0 2px var(--primary, #d92b3f);
    outline: none;
    padding-inline: 6px;
}

/* ---------- حقل التحرير المُقايَض (للأزرار التي لا تقبل contenteditable) ---------- */
.ui-inline-input {
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    line-height: 1.5;
    color: var(--panel-text, #1a0c0f);
    background: var(--panel-bg, #ffffff);
    border: 2px solid var(--primary, #d92b3f);
    border-radius: 8px;
    padding: 6px 10px;
    max-width: 100%;
    text-align: start;
    direction: rtl;
}
.ui-inline-input:focus-visible { outline: 3px solid var(--primary, #d92b3f); outline-offset: 1px; }

/* العنصر أثناء التحرير لا يجب أن يبدو زرًّا قابلًا للنقر */
.ui-editable.ui-editing {
    cursor: text;
    background: var(--panel-bg, #ffffff);
    box-shadow: inset 0 0 0 2px var(--primary, #d92b3f);
    border-radius: 8px;
}
.ui-editable.ui-editing::after { content: none; }

/* ---------- الخطّاف: تلميح صغير يشرح ما لا يُرى ---------- */
.ui-hint {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: var(--panel-text-muted, #6b5a5c);
}
.ui-hint kbd {
    font-family: inherit;
    font-size: 11.5px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 5px;
    border: 1px solid var(--panel-border, #eddede);
    background: var(--panel-soft-2, #f7f0f0);
    color: var(--panel-text, #1a0c0f);
}

/* ---------- رابط تجاوز إلى المحتوى ---------- */
/* مخفيّ حتى يُبلَغ بـTab، وحينها يظهر فوق كل شيء. لا يزحم البصر ولا يُحذف. */
.ui-skip-link {
    position: fixed;
    top: 8px;
    inset-inline-start: 50%;
    transform: translateX(50%) translateY(-200%);
    z-index: 1000000;
    padding: 10px 18px;
    border-radius: 0 0 10px 10px;
    background: var(--primary, #d92b3f);
    color: var(--on-accent, #0d0305);
    font-weight: 700;
    text-decoration: none;
    transition: transform .15s ease;
}
.ui-skip-link:focus-visible,
.ui-skip-link:focus {
    transform: translateX(50%) translateY(0);
    outline: 3px solid var(--panel-text, #1a0c0f);
    outline-offset: 2px;
}

/* ---------- لوحة التنقّل الموحّدة (Ctrl+K) ---------- */
/* فوق الصفحة كطبقة المنع، وتحت تنبيه المراقبة الرسمي (1000000). */
.ui-cmd-overlay {
    position: fixed;
    inset: 0;
    z-index: 900000;
    background: rgba(26, 12, 15, .62);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 12vh 16px 16px;
    overflow-y: auto;
}

.ui-cmd-panel {
    width: 100%;
    max-width: 620px;
    background: var(--panel-bg);
    color: var(--panel-text);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 20px 60px rgba(2, 8, 20, .45);
}

.ui-cmd-input {
    width: 100%;
    min-height: 46px;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 1rem;
    color: var(--panel-text);
    background: var(--panel-soft, #faf6f6);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
}
.ui-cmd-input:focus-visible { outline: 3px solid var(--primary, #d92b3f); outline-offset: 1px; }
.ui-cmd-input::placeholder { color: var(--panel-text-dim, #8a7678); }

.ui-cmd-list {
    list-style: none;
    margin: 10px 0 6px;
    padding: 0;
    max-height: 46vh;
    overflow-y: auto;
}

.ui-cmd-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 44px;
    padding: 8px 12px;
    border-radius: 9px;
    cursor: pointer;
    color: var(--panel-text);
}
/* المؤشّر على العنصر النشط، لا لون واحد لكل العناصر */
.ui-cmd-item.is-active {
    background: var(--primary, #d92b3f);
    color: var(--on-accent, #0d0305);
}
.ui-cmd-item.is-active .ui-cmd-group { color: var(--on-accent, #0d0305); opacity: .85; }

.ui-cmd-label { font-weight: 600; }
.ui-cmd-group { font-size: 12.5px; color: var(--panel-text-muted, #6b5a5c); }
.ui-cmd-empty { padding: 14px 12px; color: var(--panel-text-muted, #6b5a5c); text-align: center; }

/* زرّ الفتح في الترويسة: يظهر النصّ على الشاشات الواسعة ويبقى الرمز وحده على الجوال */
.ui-cmd-trigger { display: inline-flex; align-items: center; gap: 6px; }
.ui-cmd-trigger-text { font-size: 13px; }

@media (max-width: 640px) {
    .ui-cmd-overlay { padding: 8vh 10px 10px; }
    .ui-cmd-trigger-text { display: none; }
}

@media (max-width: 640px) {
    /* حدّ اللمس المريح 44px على الجوال */
    .ui-grip { width: 30px; height: 44px; opacity: .7; }
    .ui-sortable [role="listitem"] { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
    .ui-grip, .ui-editable { transition: none; }
}


/* ---------- شارة تغطية المخرجات في مكتبة الاختبارات ---------- */
/* قراءة الحال من لونها وحدها لا تكفي: النصّ نفسه يقول «غير مقيس» — واللون يسرّع المسح. */
.ui-coverage {
    display: inline-block;
    margin-inline-start: 8px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.7;
    vertical-align: middle;
    border: 1px solid var(--panel-border, #e5e0e0);
    color: var(--panel-text-muted, #6b5b5b);
    background: var(--panel-soft, #faf7f7);
}
.ui-coverage.is-ready { border-color: #1e7d4f; color: #165c39; background: #e9f6ef; }
.ui-coverage.is-unmeasured { border-color: #a8641e; color: #7d4610; background: #fdf3e6; }
.ui-coverage.is-partial { border-color: #a8641e; color: #6b4a12; background: #fdf7ec; }
.ui-coverage.is-empty { opacity: .8; }
