/* ============================================================
   layout.css — persistent app chrome: sidebar shell/nav/footer,
   main layout shell, topbar, page-body.
   Split out of the former monolithic site.css (Phase 1 foundation).
   ============================================================ */

.sidebar {
    position: fixed;
    top: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background:
        linear-gradient(160deg, rgba(var(--muted-rgb),.12) 0%, rgba(var(--muted-rgb),0) 40%),
        linear-gradient(0deg, rgba(var(--muted-rgb),.08) 0%, rgba(var(--muted-rgb),0) 55%),
        var(--sidebar);
    display: flex;
    flex-direction: column;
    z-index: 400;
    overflow: hidden;
    transition: width .2s ease;
}

/* Both classes resolve to the same logical rule — which physical side
   that becomes is decided entirely by dir="ltr"/"rtl" on <html>, not by
   which class name the server picked, so this single rule covers both. */
.sidebar-left, .sidebar-right {
    inset-inline-start: 0;
}

.sb-head {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 20px 18px;
    background: rgba(255,255,255,.03);
    border-bottom: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
}

.sb-logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    border: 1px solid rgba(var(--accent-rgb),.35);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* نظام له شعار صورة (Nucleus): الصورة تحمل بلاطتها فلا خلفية ولا إطار */
.sb-logo--img {
    background: none;
    border: 0;
    border-radius: 0;
}

.sb-logo--img img {
    display: block;
    width: 100%;
    height: 100%;
}

.sb-logo svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: white;
    stroke-width: 2.5;
}

.sb-brand {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sb-name {
    font-size: 1.8rem;
    line-height: 1.1;
    font-weight: 800;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sb-tagline {
    font-size: .65rem;
    color: rgba(255,255,255,.4);
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-top: 1px;
}

.switch-system-link {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 12px 14px 0;
    padding: 9px 12px;
    border-radius: 8px;
    background: rgba(255,255,255,.05);
    border: 1px solid rgba(255,255,255,.08);
    color: rgba(255,255,255,.6);
    font-size: .78rem;
    font-weight: 600;
    text-decoration: none;
    transition: all .15s;
    flex-shrink: 0;
}

.switch-system-link svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.switch-system-link:hover {
    background: rgba(255,255,255,.09);
    color: #fff;
    text-decoration: none;
}

.sb-nav {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
}

.sb-nav::-webkit-scrollbar {
    width: 3px;
}

.sb-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sb-nav::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,.1);
    border-radius: 3px;
}

.nav-section {
    margin-top: 4px;
}

.nav-label {
    padding: 10px 18px 5px;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: rgba(var(--accent-rgb),.75);
    user-select: none;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    margin: 2px 10px;
    border-radius: 8px;
    color: rgba(255,255,255,.55);
    text-decoration: none;
    font-size: .855rem;
    font-weight: 500;
    transition: all .15s;
    cursor: pointer;
    border-inline-start: 3px solid transparent;
}

.nav-item svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    transition: opacity .15s;
}

.nav-item:hover {
    background: rgba(255,255,255,.07);
    color: rgba(255,255,255,.9);
    text-decoration: none;
}

.nav-item.active {
    background: rgba(var(--accent-rgb),.14);
    color: #fff;
    border-inline-start: 2px solid var(--accent);
    padding-inline-start: 14px;
    font-weight: 600;
}

.nav-item.active svg {
    opacity: 1;
    color: var(--accent);
}

/* Collapsible nav group (generic — works for any parent menu with children) */
.nav-group {
    margin-top: 4px;
}

/* Thin gold divider between nav groups (skip the first — no divider above it) */
.nav-group + .nav-group,
.nav-section + .nav-group,
.nav-group + .nav-section {
    border-top: 1px solid rgba(var(--accent-rgb),.15);
    padding-top: 4px;
}

.nav-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: calc(100% - 20px);
    margin: 0 10px;
    padding: 9px 8px;
    background: none;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: rgba(var(--accent-rgb),.65);
    cursor: pointer;
    user-select: none;
    text-align: start;
    transition: color .15s, background-color .15s;
}

.nav-group-toggle:hover {
    color: rgba(var(--accent-rgb),.9);
    background: rgba(255,255,255,.05);
}

.nav-group-toggle:focus-visible {
    outline: 2px solid rgba(var(--accent-rgb),.6);
    outline-offset: -2px;
}

.nav-group.has-active > .nav-group-toggle {
    color: var(--accent);
}

.nav-group-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-caret {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    stroke: currentColor;
    margin-inline-start: 8px;
    transition: transform .2s ease;
}

/* Scoped with a direct-child combinator so a group's own caret/body react
   only to that group's own .collapsed state — not an ancestor's or a
   descendant's, which matters once groups are nested inside groups. */
.nav-group:not(.collapsed) > .nav-group-toggle .nav-caret {
    transform: rotate(180deg);
}

.nav-group-body {
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows .22s ease;
}

.nav-group.collapsed > .nav-group-body {
    grid-template-rows: 0fr;
}

.nav-group-inner {
    overflow: hidden;
    min-height: 0;
    opacity: 1;
    transition: opacity .18s ease;
}

.nav-group.collapsed > .nav-group-body > .nav-group-inner {
    opacity: 0;
}

/* Tree indentation: each nesting level adds its own guideline + indent,
   so depth is legible no matter how many levels a section ends up with. */
.nav-group .nav-group-inner {
    margin-inline-start: 22px;
    padding-inline-start: 10px;
    border-inline-start: 1px solid rgba(255,255,255,.07);
}

/* Fallback for browsers without animated grid-template-rows support */
@supports not (grid-template-rows: 1fr) {
    .nav-group-body {
        overflow: hidden;
        max-height: 1000px;
        transition: max-height .22s ease;
    }

    .nav-group.collapsed > .nav-group-body {
        max-height: 0;
    }
}

.sb-footer {
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,.06);
    background: rgba(0,0,0,.2);
    flex-shrink: 0;
}

.user-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 8px;
}

.user-av {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    border: 1px solid rgba(var(--accent-rgb),.35);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-size: .82rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: .68rem;
    color: rgba(255,255,255,.35);
    margin-top: 1px;
}

.logout-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,.25);
    cursor: pointer;
    padding: 7px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
}

.logout-btn:hover {
    color: var(--danger);
    background: rgba(239,68,68,.1);
}

/* ── قائمة حساب المستخدم (user-menu.js): الاسم والصورة زرّ بتذييل القائمة الجانبية يفتح بطاقة فوقه ── */
.sb-footer { position: relative; }

.user-trigger {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: 0;
    padding: 0;
    color: inherit;
    font: inherit;
    text-align: start;
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.user-trigger:hover .user-name { text-decoration: underline; }
.user-trigger:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.user-trigger .user-info { display: flex; flex-direction: column; }
.user-caret { color: rgba(255,255,255,.35); flex-shrink: 0; }
.user-trigger[aria-expanded="true"] .user-caret { transform: rotate(180deg); }
.user-av-img { object-fit: cover; padding: 0; }

.user-menu {
    position: absolute;
    inset-inline: 10px;
    bottom: calc(100% + 8px);
    z-index: 60;
    background: var(--surface);
    color: var(--text1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg, 0 12px 32px rgba(0,0,0,.28));
    overflow: hidden;
}
.user-menu[hidden] { display: none; }
/* تسجيل الخروج داخل قائمة الحساب (الشريط العلوي يخفي زر الخروج المستقل على الجوال) */
.um-logout { display: contents; }
.um-actions .um-action--danger, .um-actions .um-action--danger svg { color: var(--danger); }

.um-head { display: flex; align-items: center; gap: 12px; padding: 16px; background: var(--bg); border-bottom: 1px solid var(--border); }
.um-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    color: #fff; font-weight: 700; object-fit: cover; flex-shrink: 0;
}
.um-avatar-lg { width: 56px; height: 56px; font-size: 1.3rem; border: 2px solid var(--accent); }
.um-avatar-xl { width: 120px; height: 120px; font-size: 2.6rem; border: 3px solid var(--accent); }
.um-id { min-width: 0; }
.um-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.um-username { color: var(--text2); font-size: .8rem; direction: ltr; text-align: start; }
.um-role { display: inline-block; margin-top: 4px; padding: 1px 8px; border-radius: 10px; background: var(--accent-bg); color: var(--text1); font-size: .7rem; font-weight: 600; }

.um-facts { list-style: none; margin: 0; padding: 10px 16px; display: grid; gap: 8px; border-bottom: 1px solid var(--border); }
.um-facts li { display: flex; align-items: center; gap: 8px; font-size: .78rem; min-width: 0; }
.um-fact-ic { color: var(--muted); display: inline-flex; }
.um-fact-label { color: var(--text2); flex-shrink: 0; }
.um-fact-value { margin-inline-start: auto; font-weight: 600; text-align: end; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.um-fact-value small { color: var(--text2); font-weight: 400; }
/* فترة العمل: اسم وتواريخ وحالة تتراصّ عمودياً بدل قصّها بنقاط. */
.um-facts .um-fact--wrap { flex-wrap: wrap; }
.um-fact--wrap .um-fact-value { white-space: normal; overflow: visible; min-width: 0; flex: 1 0 100%; text-align: start; padding-inline-start: 24px; }
.um-period-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.um-period-range { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; font-size: .74rem; }
.um-period-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 2px; }
.um-period-meta small { white-space: nowrap; }

.um-actions { display: grid; padding: 6px; }
.um-action {
    display: flex; align-items: center; gap: 10px;
    background: none; border: 0; padding: 10px; border-radius: var(--radius-sm);
    color: var(--text1); font: inherit; font-size: .85rem; cursor: pointer; text-align: start;
}
.um-action:hover, .um-action:focus-visible { background: var(--accent-bg); outline: none; }
.um-action svg { color: var(--muted); }

/* نافذة تغيير الصورة */
.um-photo-preview { display: flex; justify-content: center; padding: 8px 0 12px; }
.um-hint { color: var(--text2); font-size: .8rem; text-align: center; margin: 0; }

.main-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    min-width: 0;
    width: -webkit-fill-available;
    flex: 1;
}

/* Both classes resolve to the same logical rule — the physical side that
   margin-inline-start becomes is decided by dir="ltr"/"rtl" on <html>, not
   by which class name the server picked, so one rule covers both. */
.main-wrap-ltr, .main-wrap-rtl {
    margin-inline-start: var(--sidebar-w);
}

.main-wrap-full {
    margin: 0;
}

.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 300;
    box-shadow: var(--shadow-xs);
    flex-shrink: 0;
}

.topbar-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.page-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text1);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: .75rem;
    color: var(--muted);
    flex-wrap: wrap;
}

.breadcrumb a {
    color: var(--muted);
    text-decoration: none;
    transition: color .15s;
}

.breadcrumb a:hover {
    color: var(--primary);
}

.breadcrumb .sep {
    font-size: .65rem;
}

.breadcrumb .current {
    color: var(--text2);
    font-weight: 500;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.lang-sw {
    display: flex;
    align-items: center;
    gap: 1px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    overflow: hidden;
}

.lang-sw a {
    padding: 5px 11px;
    font-size: .75rem;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    transition: all .15s;
}

.lang-sw a.on {
    background: var(--primary);
    color: #fff;
}

.page-body {
    flex: 1;
    padding: clamp(10px, 2vw, 16px);
    overflow-y: auto;
}

/* ============================================================
   Responsive shell — sidebar becomes an off-canvas overlay at <=1024px
   (iPad landscape and below); main content reclaims the full width.
   See tokens.css for the shared breakpoint scale this program uses.
   ============================================================ */

.sb-toggle-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text1);
    cursor: pointer;
    flex-shrink: 0;
}

.sb-toggle-btn svg {
    width: 18px;
    height: 18px;
}

.sb-toggle-btn:hover {
    background: var(--bg);
    border-color: var(--primary);
}

.sb-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 390;
}

@media (max-width: 1024px) {
    .sb-toggle-btn {
        display: inline-flex;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--shadow-lg);
    }

    /* Physical direction of the off-canvas slide follows dir="ltr"/"rtl",
       the same logical-property approach the rest of this file uses. */
    html[dir="rtl"] .sidebar {
        transform: translateX(100%);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    body.sidebar-open .sb-backdrop {
        display: block;
    }

    .main-wrap-ltr, .main-wrap-rtl {
        margin-inline-start: 0;
    }
}

@media (max-width: 640px) {
    .sidebar {
        width: min(85vw, 300px);
    }
}


/* رابط تخطّي للمحتوى (إمكانية الوصول) — يظهر عند التركيز بلوحة المفاتيح فقط. */
.skip-link { position: absolute; inset-inline-start: var(--space-3); top: -100px; z-index: 1000; padding: var(--space-2) var(--space-4); background: var(--primary); color: var(--accent); border-radius: var(--radius-sm); font-weight: var(--fw-semibold); text-decoration: none; }
.skip-link:focus { top: var(--space-3); }
