/*
   ─────────────────────────────────────────────────────────────
   ٤ · الهياكل
   ─────────────────────────────────────────────────────────────
   ثلاثة أغلفة لثلاث حالات استخدام مختلفة جذريًا:
   الموقع العام والمتعلّم · لوحة الإدارة · قاعة التعلّم المركّزة.
*/

/* ══════════════════════════════════════════
   الترويسة العامة
   ══════════════════════════════════════════ */

.site-header {
    position: sticky;
    inset-block-start: 0;
    z-index: var(--z-header);
    background: var(--surface-veil);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--line);
}

.site-header__inner {
    display: flex;
    align-items: center;
    gap: var(--s-5);
    min-height: var(--header-h);
}

/* ─── الشعار ─── */

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--s-3);
    flex: none;
    color: var(--text);
    font-weight: var(--fw-black);
    font-size: var(--t-md);
    letter-spacing: -.01em;
}

.brand:hover { color: var(--text); text-decoration: none; }

/* الشعار صورة لا حرف مرسوم: نسختان — واحدة للأسطح الفاتحة وأخرى للداكنة —
   تُرسمان معًا وتُخفى واحدة بالـ CSS، لأن السمة تُبدَّل بزرّ في الصفحة نفسها
   فلا يكفي وسيط prefers-color-scheme. */

.logo {
    display: inline-flex;
    align-items: center;
    flex: none;
    line-height: 0;
}

.logo__img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* العلامة وحدها — مقاس المربّع القديم نفسه كي لا تتزحزح الترويسة */
.logo--mark { width: 2rem; height: 2rem; }

.logo--sm { width: 1.5rem; height: 1.5rem; }

/* الكلمة بخط الشعار وألوانه: ترتفع بارتفاع سطر النص الذي حلّت محلّه */
.logo--word { width: auto; height: 1.1rem; }
.logo--sm-word { width: auto; height: .95rem; }
.logo--word .logo__img { width: auto; height: 100%; }

/* الشعار الكامل (المربّع والكلمة): يرتفع بنسبته لا بمقاس ثابت */
.logo--full { width: 7rem; height: auto; }
.logo--full .logo__img { height: auto; }

.logo__img--dark { display: none; }

[data-theme='dark'] .logo__img--light { display: none; }
[data-theme='dark'] .logo__img--dark { display: block; }

/* سطح قطبيته معكوسة عن السمة — الفوتر داكن في الوضع الفاتح وفاتح في الداكن،
   فيلزمه الشعار المقابل لا الموافق للسمة. */
.logo--invert .logo__img--light { display: none; }
.logo--invert .logo__img--dark { display: block; }

[data-theme='dark'] .logo--invert .logo__img--light { display: block; }
[data-theme='dark'] .logo--invert .logo__img--dark { display: none; }

.brand__text { line-height: 1; }

/* بقي المُعدِّل لأن القوالب تستدعيه، ولم يعد يقلب شيئًا:
   قاعة التعلّم صارت تتبع السمة، فالشعار فيها هو الشعار نفسه. */
.brand--invert { color: var(--text); }
.brand--invert:hover { color: var(--text); }

/* ─── التنقّل الرئيسي ─── */

.site-nav {
    display: flex;
    align-items: center;
    gap: var(--s-1);
    list-style: none;
    margin: 0;
    padding: 0;
}

.site-nav__link {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-sm);
    font-size: var(--t-ui);
    font-weight: var(--fw-medium);
    color: var(--text-2);
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

.site-nav__link:hover { background: var(--n-100); color: var(--text); text-decoration: none; }
.site-nav__link.is-active { color: var(--p-700); background: var(--p-50); font-weight: var(--fw-semibold); }

.site-header__actions {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    margin-inline-start: auto;
}


/* ─── زرّ الحساب المثبَّت ─── */

/*
   الدخول والخروج خارج القائمة المطوية عمدًا: على الموبايل كل ما في
   .site-header__collapse يختفي خلف زرّ القائمة، والخروج تحديدًا يُطلب
   في لحظة واحدة ولا يُبحث عنه في قائمتين.
*/
.site-header__auth {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    margin-inline-start: auto;
    flex: none;
}

/* على الشاشة الكبيرة يجلس في آخر الشريط بعد بقية الأدوات */
@media (min-width: 992px) {
    .site-header__auth { order: 20; margin-inline-start: var(--s-3); }
}

.site-header__auth form { margin: 0; }

/* الشاشة الضيّقة: الأيقونة وحدها — الاسم البديل يبقى للقارئ الآلي */
@media (max-width: 420px) {
    .site-header__auth-label { display: none; }
    .site-header__auth-btn { padding-inline: var(--s-2); }
}

/* ─── قائمة المستخدم ─── */

.user-menu { position: relative; }

.user-menu__trigger {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-1) var(--s-2) var(--s-1) var(--s-1);
    background: none;
    border: 1px solid var(--line);
    border-radius: var(--r-pill);
    cursor: pointer;
    font-family: inherit;
    font-size: var(--t-sm);
    font-weight: var(--fw-medium);
    color: var(--text-2);
    transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}

html[dir='rtl'] .user-menu__trigger { padding: var(--s-1) var(--s-1) var(--s-1) var(--s-2); }

.user-menu__trigger:hover { border-color: var(--line-strong); background: var(--surface); }
.user-menu__trigger[aria-expanded='true'] { border-color: var(--p-300); background: var(--p-50); }

.user-menu__name { max-width: 9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.menu {
    position: absolute;
    inset-block-start: calc(100% + var(--s-2));
    inset-inline-end: 0;
    z-index: var(--z-drawer);
    min-width: 15rem;
    padding: var(--s-2);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: var(--sh-3);
    list-style: none;
    margin: 0;
}

.menu[hidden] { display: none; }

.menu__label {
    padding: var(--s-2) var(--s-3);
    font-size: var(--t-xs);
    font-weight: var(--fw-semibold);
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.menu__item { margin: 0; }

.menu__link {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    width: 100%;
    padding: var(--s-2) var(--s-3);
    border: 0;
    border-radius: var(--r-sm);
    background: none;
    font-family: inherit;
    font-size: var(--t-ui);
    font-weight: var(--fw-medium);
    color: var(--text-2);
    text-align: start;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease);
}

.menu__link:hover { background: var(--n-50); color: var(--text); text-decoration: none; }
.menu__link .icon { color: var(--text-faint); }
.menu__link--danger { color: var(--err-600); }
.menu__link--danger:hover { background: var(--err-50); color: var(--err-700); }

.menu__sep { height: 1px; background: var(--line); margin: var(--s-2) 0; }

/* ─── مبدّل اللغة ─── */

.lang-switch { display: inline-flex; }

.lang-switch__button {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    min-height: var(--control-h-sm);
    padding-inline: var(--s-3);
    background: none;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    font-family: inherit;
    font-size: var(--t-sm);
    font-weight: var(--fw-semibold);
    color: var(--text-2);
    cursor: pointer;
    transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.lang-switch__button:hover { background: var(--n-100); color: var(--text); }
.lang-switch__button .icon { color: var(--text-faint); }

/* ─── مبدّل السمة ─── */

.theme-switch { position: relative; display: inline-flex; }

.theme-switch__trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--control-h-sm);
    height: var(--control-h-sm);
    padding: 0;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--r-control);
    color: var(--text-2);
    cursor: pointer;
    transition: background-color var(--dur) var(--ease),
                border-color var(--dur) var(--ease),
                color var(--dur) var(--ease);
}

.theme-switch__trigger:hover { background: var(--n-100); color: var(--text); }
.theme-switch__trigger[aria-expanded='true'] { background: var(--p-50); border-color: var(--p-200); color: var(--accent); }

/* الوجهان مرسومان معًا ويظهر أحدهما: التبديل بلا إعادة رسم الأيقونة.
   الفاتح هو المبدئي فيصحّ العرض حتى قبل أن تُكتب السمة على الجذر. */
.theme-switch__face { line-height: 0; }
.theme-switch__face--light { display: inline-flex; }
.theme-switch__face--dark { display: none; }

[data-theme='dark'] .theme-switch__face--light { display: none; }
[data-theme='dark'] .theme-switch__face--dark { display: inline-flex; }

.menu--compact { min-width: 11rem; }

/* الخيار الجاري: علامة صحّ بدل تظليل ثقيل يزاحم بقية القائمة */
.menu__link.is-active {
    background: var(--p-50);
    color: var(--p-800);
    font-weight: var(--fw-semibold);
}

.menu__link.is-active .icon { color: var(--accent); }

/* ─── زر القائمة على الجوّال ─── */

.nav-toggle {
    display: none;
    /* مايتضغطش في صف الترويسة على موبايل ٣٢٠px — يفضل هدف لمس كامل */
    flex: none;
    align-items: center;
    justify-content: center;
    width: var(--control-h);
    height: var(--control-h);
    background: none;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    color: var(--text-2);
    cursor: pointer;
}

.nav-toggle:hover { background: var(--n-50); }

@media (max-width: 991px) {
    .nav-toggle { display: inline-flex; margin-inline-start: var(--s-2); }
    .site-header__actions { margin-inline-start: 0; }

    .site-header__collapse {
        display: none;
        flex-basis: 100%;
        order: 10;
        padding-block: var(--s-4);
        border-top: 1px solid var(--line);
    }

    .site-header__collapse.is-open { display: block; }
    .site-header__inner { flex-wrap: wrap; }

    .site-nav { flex-direction: column; align-items: stretch; gap: 0; }
    .site-nav__link { padding: var(--s-3); }

    .site-header__collapse .site-header__actions {
        flex-wrap: wrap;
        margin-block-start: var(--s-4);
        padding-block-start: var(--s-4);
        border-top: 1px solid var(--line);
    }
}

@media (min-width: 992px) {
    .site-header__collapse {
        display: flex !important;
        align-items: center;
        gap: var(--s-5);
        flex: 1;
    }
}

/* ══════════════════════════════════════════
   عنوان الصفحة
   ══════════════════════════════════════════ */

.page-head {
    display: flex;
    align-items: flex-end;
    gap: var(--s-5);
    flex-wrap: wrap;
    margin-bottom: var(--s-6);
}

.page-head__body { flex: 1; min-width: min(100%, 20rem); }

.page-head__title {
    font-size: var(--t-2xl);
    font-weight: var(--fw-bold);
    letter-spacing: -.01em;
    margin: 0;
    color: var(--text);
}

.page-head__subtitle {
    margin: var(--s-2) 0 0;
    color: var(--text-muted);
    font-size: var(--t-ui);
}

.page-head__actions { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }

.section-head {
    display: flex;
    align-items: baseline;
    gap: var(--s-4);
    flex-wrap: wrap;
    margin-bottom: var(--s-5);
}

.section-head__title {
    font-size: var(--t-xl);
    font-weight: var(--fw-bold);
    margin: 0;
}

.section-head__link { margin-inline-start: auto; font-size: var(--t-ui); font-weight: var(--fw-medium); }

/* ══════════════════════════════════════════
   التذييل
   ══════════════════════════════════════════ */

.site-footer {
    margin-top: auto;
    background: var(--n-950);
    color: var(--n-300);
    padding-block: var(--s-9) var(--s-5);
    font-size: var(--t-ui);
}

.site-footer__grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) repeat(4, minmax(0, 1fr));
    gap: var(--s-7) var(--s-5);
}

@media (max-width: 767px) {
    .site-footer__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .site-footer__brand-col { grid-column: 1 / -1; }
}

.site-footer .brand { color: var(--n-0); margin-bottom: var(--s-3); }

.site-footer__tagline { color: var(--n-400); max-width: 34ch; line-height: var(--lh-snug); }

.site-footer__social { display: flex; gap: var(--s-3); list-style: none; padding: 0; margin: var(--s-4) 0 0; }
.site-footer__social a {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: var(--n-900);
    color: var(--n-300);
}
.site-footer__social a:hover { background: var(--n-800); color: var(--n-0); }
.site-footer__social .icon { width: 1.1rem; height: 1.1rem; }

.site-footer__heading {
    font-size: var(--t-xs);
    font-weight: var(--fw-semibold);
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--n-500);
    margin-bottom: var(--s-3);
}

.site-footer__links { list-style: none; padding: 0; margin: 0; }
.site-footer__links li { margin-bottom: var(--s-2); }
.site-footer__links a { color: var(--n-300); font-weight: var(--fw-regular); }
.site-footer__links a:hover { color: var(--n-0); text-decoration: none; }

.site-footer__bottom {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: var(--s-3) var(--s-5);
    margin-top: var(--s-8);
    padding-top: var(--s-5);
    border-top: 1px solid var(--ink-line);
    color: var(--n-500);
    font-size: var(--t-sm);
}

.site-footer__bottom a { color: var(--n-500); }
.site-footer__bottom a:hover { color: var(--n-200); text-decoration: none; }

/* ══════════════════════════════════════════
   غلاف لوحة الإدارة
   ══════════════════════════════════════════ */

.console {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100vh;
    flex: 1;
    background: var(--canvas);
}

.console-sidebar {
    position: sticky;
    inset-block-start: 0;
    align-self: start;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-inline-end: 1px solid var(--line);
    z-index: var(--z-sticky);
}

.console-sidebar__head {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    height: var(--header-h);
    padding-inline: var(--s-5);
    border-bottom: 1px solid var(--line);
    flex: none;
}

.console-sidebar__nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--s-5) var(--s-3);
}

.console-sidebar__group { margin-bottom: var(--s-6); }
.console-sidebar__group:last-child { margin-bottom: 0; }

.console-sidebar__label {
    padding-inline: var(--s-3);
    margin-bottom: var(--s-2);
    font-size: var(--t-2xs);
    font-weight: var(--fw-bold);
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-faint);
}

.console-sidebar__list { list-style: none; padding: 0; margin: 0; }
.console-sidebar__list li { margin-bottom: 2px; }

.console-link {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-sm);
    font-size: var(--t-ui);
    font-weight: var(--fw-medium);
    color: var(--text-2);
    transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.console-link .icon { color: var(--text-faint); transition: color var(--dur-fast) var(--ease); }
.console-link:hover { background: var(--n-50); color: var(--text); text-decoration: none; }
.console-link:hover .icon { color: var(--text-2); }

.console-link.is-active {
    background: var(--p-50);
    color: var(--p-800);
    font-weight: var(--fw-semibold);
}

.console-link.is-active .icon { color: var(--p-600); }

.console-link__count {
    margin-inline-start: auto;
    font-size: var(--t-xs);
    font-weight: var(--fw-semibold);
    font-variant-numeric: tabular-nums;
    color: var(--text-faint);
    background: var(--n-100);
    border-radius: var(--r-pill);
    padding: .1em .55em;
}

.console-sidebar__foot {
    flex: none;
    padding: var(--s-3);
    border-top: 1px solid var(--line);
}

.console-account {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    width: 100%;
    padding: var(--s-2) var(--s-3);
    background: none;
    border: 0;
    border-radius: var(--r-sm);
    font-family: inherit;
    font-size: var(--t-ui);
    font-weight: var(--fw-medium);
    color: var(--text-2);
    text-align: start;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease);
}

.console-account:hover { background: var(--n-50); color: var(--text); }
.console-account .icon { margin-inline-start: auto; color: var(--text-faint); }

/* قائمة تفتح لأعلى — لأنها ملتصقة بأسفل الشريط الجانبي */
.menu--up {
    inset-block-start: auto;
    inset-block-end: calc(100% + var(--s-2));
    inset-inline: 0;
    min-width: 0;
}

/* ─── شريط اللوحة العلوي ─── */

.console-topbar {
    position: sticky;
    inset-block-start: 0;
    z-index: var(--z-header);
    display: flex;
    align-items: center;
    gap: var(--s-4);
    min-height: var(--header-h);
    padding-inline: var(--s-6);
    background: var(--surface-veil);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--line);
}

.console-topbar__title {
    font-size: var(--t-md);
    font-weight: var(--fw-semibold);
    margin: 0;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.console-topbar__actions { margin-inline-start: auto; display: flex; align-items: center; gap: var(--s-2); }

.console-main { min-width: 0; display: flex; flex-direction: column; }

.console-body {
    flex: 1;
    padding: var(--s-6);
    max-width: 1440px;
    width: 100%;
}

@media (max-width: 1199px) {
    .console-body { padding: var(--s-5); }
}

/* ─── اللوحة على الشاشات الصغيرة: درج جانبي ─── */

@media (max-width: 991px) {
    .console { grid-template-columns: minmax(0, 1fr); }

    .console-sidebar {
        position: fixed;
        inset-block: 0;
        inset-inline-start: 0;
        width: min(var(--sidebar-w), 84vw);
        transform: translateX(var(--drawer-hidden, -105%));
        transition: transform var(--dur-slow) var(--ease);
        box-shadow: var(--sh-4);
        z-index: var(--z-drawer);
    }

    html[dir='rtl'] .console-sidebar { --drawer-hidden: 105%; }

    .console-sidebar.is-open { transform: translateX(0); }

    .console-scrim {
        position: fixed;
        inset: 0;
        z-index: calc(var(--z-drawer) - 1);
        background: var(--scrim);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--dur-slow) var(--ease);
    }

    .console-scrim.is-open { opacity: 1; pointer-events: auto; }
    .console-body { padding: var(--s-4); }
    .console-topbar { padding-inline: var(--s-4); }
}

@media (min-width: 992px) {
    .console-toggle, .console-scrim { display: none !important; }
}

/* ══════════════════════════════════════════
   غلاف قاعة التعلّم المركّزة
   ══════════════════════════════════════════
   كان سطحًا داكنًا ثابتًا لا يتبع أحدًا. صار يتبع السمة مثل بقية
   المنصة: من يذاكر نهارًا لا يُدفع إلى شاشة سوداء، ومن يذاكر ليلًا
   لا يخرج من الداكن حين يفتح الدرس. الفيديو وحده يبقى بإطار أسود. */

.focus-body {
    background: var(--d-900);
    color: var(--d-text);
    min-height: 100vh;
}

.focus-topbar {
    position: sticky;
    inset-block-start: 0;
    z-index: var(--z-header);
    display: flex;
    align-items: center;
    gap: var(--s-4);
    min-height: 56px;
    padding-inline: var(--s-5);
    background: var(--d-800);
    border-bottom: 1px solid var(--d-line);
}

.focus-topbar__back {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    font-size: var(--t-ui);
    font-weight: var(--fw-medium);
    color: var(--d-text-2);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-sm);
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

.focus-topbar__back:hover { background: var(--d-700); color: var(--d-text); text-decoration: none; }

.focus-topbar__context {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--t-sm);
    color: var(--d-muted);
}

.focus-topbar__end { margin-inline-start: auto; display: flex; align-items: center; gap: var(--s-3); }
