/* =====================================================================
   Trust Gates — التصميم العصري (v2)
   CSS عادي فوق Filament (بدون Node/Tailwind build) — يعمل على أي استضافة.
   الألوان الأساسية تأتي من ثيم الشركة كمتغيرات --primary-50 … 950.
   ===================================================================== */

:root {
    --erp-radius: 16px;
    --erp-radius-sm: 11px;
    --erp-ink: #0f172a;
    --erp-muted: #64748b;
    --erp-line: rgb(15 23 42 / .07);
    --erp-card: rgb(255 255 255 / .86);
    --erp-shadow: 0 1px 2px rgb(15 23 42 / .04), 0 12px 32px -16px rgb(15 23 42 / .22);
    --erp-shadow-hover: 0 2px 4px rgb(15 23 42 / .05), 0 20px 40px -18px rgb(15 23 42 / .32);
    --erp-sidebar-from: color-mix(in oklab, var(--primary-950) 88%, #020617);
    --erp-sidebar-to: #0b1222;
}

.dark {
    --erp-ink: #e2e8f0;
    --erp-muted: #94a3b8;
    --erp-line: rgb(255 255 255 / .08);
    --erp-card: rgb(17 24 39 / .72);
    --erp-shadow: 0 1px 2px rgb(0 0 0 / .3), 0 14px 34px -18px rgb(0 0 0 / .7);
    --erp-shadow-hover: 0 2px 4px rgb(0 0 0 / .35), 0 22px 44px -18px rgb(0 0 0 / .8);
}

/* ---------- الخلفية ---------- */
.fi-body {
    background:
        radial-gradient(1100px 520px at 100% -8%, color-mix(in oklab, var(--primary-200) 45%, transparent), transparent 62%),
        radial-gradient(900px 520px at -12% 108%, color-mix(in oklab, var(--primary-100) 70%, transparent), transparent 60%),
        #f4f6fb;
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
}

.dark .fi-body {
    background:
        radial-gradient(1000px 520px at 100% -10%, color-mix(in oklab, var(--primary-900) 40%, transparent), transparent 60%),
        radial-gradient(800px 500px at -10% 110%, rgb(30 41 59 / .55), transparent 60%),
        #070b14;
    background-attachment: fixed;
}

/* ---------- الشريط الجانبي ---------- */
.fi-sidebar {
    background: linear-gradient(180deg, var(--erp-sidebar-from) 0%, var(--erp-sidebar-to) 100%) !important;
    border-inline-end: 1px solid rgb(255 255 255 / .06);
    box-shadow: 0 0 40px -20px rgb(2 6 23 / .6);
}

.fi-sidebar-header {
    background: transparent !important;
    border-color: rgb(255 255 255 / .08) !important;
    box-shadow: none !important;
}

.fi-sidebar .fi-logo,
.fi-sidebar .fi-tenant-menu-trigger,
.fi-sidebar .fi-tenant-menu-trigger-tenant-name {
    color: #fff !important;
}

.fi-sidebar .fi-tenant-menu-trigger-current-tenant-label {
    color: rgb(255 255 255 / .5) !important;
}

.fi-sidebar .fi-tenant-menu-trigger:hover {
    background: rgb(255 255 255 / .06) !important;
}

/* عناوين الأقسام (الحسابات، المشتريات، المخازن …): مميزة بوضوح عن عناصر القائمة */
.fi-sidebar-group + .fi-sidebar-group {
    margin-top: .5rem;
}

.fi-sidebar-group-btn {
    position: relative;
    padding: .6rem .8rem !important;
    margin-bottom: .2rem;
    border-radius: 12px;
    background: linear-gradient(90deg, rgb(255 255 255 / .02), color-mix(in oklab, var(--primary-400) 16%, transparent));
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / .05);
    cursor: pointer;
    transition: background .15s ease;
}

.fi-sidebar-group-btn::before {
    content: '';
    position: absolute;
    inset-inline-start: 0;
    top: 22%;
    bottom: 22%;
    width: 4px;
    border-radius: 4px;
    background: linear-gradient(180deg, #fbbf24, #f59e0b);
    box-shadow: 0 0 10px rgb(245 158 11 / .55);
}

.fi-sidebar-group-btn:hover {
    background: linear-gradient(90deg, rgb(255 255 255 / .04), color-mix(in oklab, var(--primary-400) 26%, transparent));
}

.fi-sidebar-group-label {
    color: #fcd34d !important;
    font-size: .95rem !important;
    font-weight: 800 !important;
    letter-spacing: 0;
    line-height: 1.4;
    text-shadow: 0 1px 8px rgb(245 158 11 / .25);
}

.fi-sidebar-group-btn .fi-icon,
.fi-sidebar-group-btn button {
    color: #fcd34d !important;
    opacity: .8;
}

.fi-sidebar-group-items {
    padding-inline-start: .35rem;
}

.fi-sidebar-item-btn {
    border-radius: var(--erp-radius-sm) !important;
    transition: background .15s ease, transform .15s ease;
}

.fi-sidebar-item-btn .fi-icon {
    color: rgb(255 255 255 / .5) !important;
}

.fi-sidebar-item-label {
    color: rgb(255 255 255 / .78) !important;
    font-weight: 500;
}

.fi-sidebar-item-btn:hover,
.fi-sidebar-item-btn:focus-visible {
    background: rgb(255 255 255 / .07) !important;
}

.fi-sidebar-item-btn:hover .fi-sidebar-item-label {
    color: #fff !important;
}

.fi-sidebar-item.fi-active > .fi-sidebar-item-btn {
    background: linear-gradient(135deg, var(--primary-500), var(--primary-700)) !important;
    box-shadow: 0 10px 24px -12px var(--primary-500), inset 0 1px 0 rgb(255 255 255 / .18);
}

.fi-sidebar-item.fi-active > .fi-sidebar-item-btn .fi-sidebar-item-label,
.fi-sidebar-item.fi-active > .fi-sidebar-item-btn .fi-icon {
    color: #fff !important;
}

.fi-sidebar-item-grouped-border-part {
    background: rgb(255 255 255 / .18) !important;
}

.fi-sidebar .fi-badge {
    background: rgb(255 255 255 / .12) !important;
    color: #fff !important;
    --tw-ring-color: transparent;
}

/* ---------- الشريط العلوي ---------- */
.fi-topbar {
    background: rgb(255 255 255 / .7) !important;
    backdrop-filter: blur(16px) saturate(1.5);
    -webkit-backdrop-filter: blur(16px) saturate(1.5);
    border-bottom: 1px solid var(--erp-line);
    box-shadow: none !important;
}

.dark .fi-topbar {
    background: rgb(7 11 20 / .65) !important;
}

/* ---------- العناوين ---------- */
.fi-header-heading {
    font-weight: 800 !important;
    letter-spacing: -.01em;
    color: var(--erp-ink);
}

/* ---------- البطاقات ---------- */
.fi-section,
.fi-ta-ctn,
.fi-wi-stats-overview-stat,
.fi-modal-window,
.fi-dropdown-panel,
.erp-report {
    border-radius: var(--erp-radius) !important;
    box-shadow: var(--erp-shadow), 0 0 0 1px var(--erp-line) !important;
    --tw-ring-color: transparent;
}

.fi-section,
.fi-ta-ctn,
.fi-wi-stats-overview-stat {
    background: var(--erp-card) !important;
    backdrop-filter: blur(8px);
}

.fi-section-header {
    border-color: var(--erp-line) !important;
}

/* بطاقات المؤشرات */
.fi-wi-stats-overview-stat {
    position: relative;
    overflow: hidden;
    transition: transform .2s ease, box-shadow .2s ease;
}

.fi-wi-stats-overview-stat::before {
    content: '';
    position: absolute;
    inset-inline: 0;
    top: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-300), var(--primary-600));
}

.fi-wi-stats-overview-stat:hover {
    transform: translateY(-3px);
    box-shadow: var(--erp-shadow-hover), 0 0 0 1px var(--erp-line) !important;
}

.fi-wi-stats-overview-stat-value {
    font-weight: 800 !important;
    letter-spacing: -.02em;
}

.fi-wi-stats-overview-stat-label {
    color: var(--erp-muted) !important;
    font-weight: 600;
}

/* ---------- الأزرار والحقول ---------- */
.fi-btn {
    border-radius: var(--erp-radius-sm) !important;
    font-weight: 600 !important;
    transition: transform .12s ease, box-shadow .2s ease, filter .2s ease;
}

.fi-btn.fi-color-primary:not(.fi-outlined) {
    background: linear-gradient(135deg, var(--primary-500), var(--primary-700)) !important;
    box-shadow: 0 8px 20px -10px var(--primary-600), inset 0 1px 0 rgb(255 255 255 / .2);
    color: #fff !important;
}

.fi-btn.fi-color-primary:not(.fi-outlined):hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
}

.fi-btn:active {
    transform: translateY(0) scale(.98);
}

.fi-input-wrp {
    border-radius: var(--erp-radius-sm) !important;
    transition: box-shadow .15s ease;
}

.fi-input-wrp:focus-within {
    box-shadow: 0 0 0 4px color-mix(in oklab, var(--primary-500) 18%, transparent) !important;
}

/* ---------- الجداول ---------- */
.fi-ta-header-cell {
    background: color-mix(in oklab, var(--primary-50) 55%, transparent) !important;
    font-weight: 700 !important;
    color: var(--erp-ink);
}

.dark .fi-ta-header-cell {
    background: rgb(255 255 255 / .03) !important;
}

.fi-ta-row {
    transition: background .12s ease;
}

.fi-ta-row:hover {
    background: color-mix(in oklab, var(--primary-50) 70%, transparent) !important;
}

.dark .fi-ta-row:hover {
    background: rgb(255 255 255 / .03) !important;
}

.fi-badge {
    border-radius: 999px !important;
    font-weight: 600;
}

/* ---------- التبويبات ---------- */
.fi-tabs {
    border-radius: var(--erp-radius) !important;
    background: var(--erp-card) !important;
    box-shadow: var(--erp-shadow), 0 0 0 1px var(--erp-line) !important;
}

.fi-tabs-item.fi-active {
    background: color-mix(in oklab, var(--primary-500) 12%, transparent) !important;
    border-radius: var(--erp-radius-sm);
}

/* ---------- صفحة الدخول ---------- */
.fi-simple-layout {
    background:
        radial-gradient(900px 600px at 85% 15%, color-mix(in oklab, var(--primary-300) 35%, transparent), transparent 60%),
        radial-gradient(700px 500px at 10% 90%, color-mix(in oklab, var(--primary-200) 40%, transparent), transparent 60%),
        #f4f6fb;
}

.dark .fi-simple-layout {
    background: radial-gradient(900px 600px at 85% 15%, color-mix(in oklab, var(--primary-900) 50%, transparent), transparent 60%), #070b14;
}

.fi-simple-main {
    border-radius: 22px !important;
    background: rgb(255 255 255 / .82) !important;
    backdrop-filter: blur(18px);
    box-shadow: 0 30px 60px -30px rgb(15 23 42 / .35), 0 0 0 1px var(--erp-line) !important;
}

.dark .fi-simple-main {
    background: rgb(15 23 42 / .75) !important;
}

.erp-auth-brand {
    display: none;
}

@media (min-width: 1024px) {
    .fi-simple-layout:has(.erp-auth-brand) .fi-simple-main-ctn {
        padding-inline-start: 46%;
    }

    .erp-auth-brand {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        position: fixed;
        inset-block: 1.25rem;
        inset-inline-start: 1.25rem;
        width: calc(46% - 2.5rem);
        padding: 3rem;
        border-radius: 28px;
        color: #fff;
        overflow: hidden;
        background:
            radial-gradient(600px 400px at 110% -10%, rgb(255 255 255 / .22), transparent 60%),
            radial-gradient(500px 360px at -20% 120%, color-mix(in oklab, var(--primary-300) 55%, transparent), transparent 60%),
            linear-gradient(150deg, var(--primary-600), var(--primary-900) 70%, #0b1222);
        box-shadow: 0 40px 80px -40px var(--primary-700);
        z-index: 1;
    }

    .erp-auth-brand::after {
        content: '';
        position: absolute;
        inset: 0;
        background-image: radial-gradient(rgb(255 255 255 / .12) 1px, transparent 1px);
        background-size: 22px 22px;
        mask-image: linear-gradient(180deg, #000, transparent 75%);
        pointer-events: none;
    }

    .erp-auth-brand h2 {
        font-size: 2.4rem;
        line-height: 1.25;
        font-weight: 800;
        margin: 0 0 1rem;
    }

    .erp-auth-brand p {
        opacity: .85;
        font-size: 1.05rem;
        line-height: 1.9;
        max-width: 34rem;
    }

    .erp-auth-features {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: .75rem;
        position: relative;
        z-index: 1;
    }

    .erp-auth-features div {
        display: flex;
        gap: .6rem;
        align-items: center;
        padding: .85rem 1rem;
        border-radius: 14px;
        background: rgb(255 255 255 / .1);
        border: 1px solid rgb(255 255 255 / .14);
        backdrop-filter: blur(6px);
        font-weight: 600;
    }

    .erp-auth-features svg {
        width: 1.35rem;
        height: 1.35rem;
        flex: none;
    }

    .erp-auth-mark {
        display: inline-flex;
        align-items: center;
        gap: .6rem;
        font-weight: 800;
        font-size: 1.2rem;
        position: relative;
        z-index: 1;
    }

    .erp-auth-mark span {
        width: 2.4rem;
        height: 2.4rem;
        border-radius: 12px;
        display: grid;
        place-items: center;
        background: rgb(255 255 255 / .16);
        border: 1px solid rgb(255 255 255 / .25);
    }
}

/* ---------- لوحة التحكم: الترحيب ---------- */
.erp-hero {
    position: relative;
    overflow: hidden;
    border-radius: 22px;
    padding: 1.6rem 1.8rem;
    color: #fff;
    background:
        radial-gradient(520px 300px at 105% -20%, rgb(255 255 255 / .22), transparent 60%),
        radial-gradient(420px 260px at -10% 130%, color-mix(in oklab, var(--primary-300) 50%, transparent), transparent 60%),
        linear-gradient(135deg, var(--primary-600), var(--primary-800));
    box-shadow: 0 24px 50px -28px var(--primary-700);
}

.erp-hero::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgb(255 255 255 / .1) 1px, transparent 1px);
    background-size: 20px 20px;
    mask-image: linear-gradient(270deg, #000, transparent 70%);
    pointer-events: none;
}

.erp-hero-top {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 1rem;
    position: relative;
    z-index: 1;
}

.erp-hero h2 {
    font-size: 1.6rem;
    font-weight: 800;
    margin: 0;
}

.erp-hero .erp-hero-sub {
    opacity: .85;
    margin-top: .25rem;
}

.erp-hero-date {
    text-align: end;
    opacity: .9;
    font-weight: 600;
}

.erp-quick {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
    margin-top: 1.25rem;
    position: relative;
    z-index: 1;
}

.erp-quick a {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .55rem .95rem;
    border-radius: 12px;
    background: rgb(255 255 255 / .14);
    border: 1px solid rgb(255 255 255 / .2);
    color: #fff;
    font-weight: 600;
    font-size: .9rem;
    transition: background .15s ease, transform .15s ease;
}

.erp-quick a:hover {
    background: rgb(255 255 255 / .24);
    transform: translateY(-1px);
}

.erp-quick svg {
    width: 1.1rem;
    height: 1.1rem;
}

/* ---------- المساعد الذكي ---------- */
.ai-shell {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (min-width: 1024px) {
    .ai-shell {
        grid-template-columns: 19rem 1fr;
        align-items: start;
    }

    .ai-side {
        position: sticky;
        top: 5rem;
    }
}

.ai-side {
    display: grid;
    gap: 1rem;
}

.ai-card {
    padding: 1rem;
    border-radius: var(--erp-radius);
    background: var(--erp-card);
    box-shadow: var(--erp-shadow), 0 0 0 1px var(--erp-line);
}

.ai-card-title {
    font-weight: 800;
    margin-bottom: .6rem;
}

.ai-muted {
    color: var(--erp-muted);
    font-size: .82rem;
}

.ai-providers {
    display: grid;
    gap: .4rem;
    margin-bottom: .6rem;
}

.ai-provider {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .55rem .7rem;
    border-radius: 12px;
    border: 1px solid var(--erp-line);
    cursor: pointer;
    font-weight: 600;
    transition: border-color .15s ease, background .15s ease;
}

.ai-provider input {
    display: none;
}

.ai-provider.is-active {
    border-color: var(--primary-500);
    background: color-mix(in oklab, var(--primary-500) 10%, transparent);
}

.ai-dot {
    width: .7rem;
    height: .7rem;
    border-radius: 999px;
}

.ai-dot-gemini { background: linear-gradient(135deg, #4285f4, #9b72cb, #d96570); }
.ai-dot-claude { background: #d97757; }
.ai-dot-openai { background: #10a37f; }

.ai-insight {
    display: flex;
    gap: .7rem;
    align-items: center;
    width: 100%;
    text-align: start;
    padding: .7rem .8rem;
    border-radius: 12px;
    border: 1px solid var(--erp-line);
    background: transparent;
    margin-top: .5rem;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease, transform .15s ease;
}

.ai-insight:not(.ai-insight-form):hover:not(:disabled) {
    border-color: var(--primary-400);
    background: color-mix(in oklab, var(--primary-500) 7%, transparent);
    transform: translateY(-1px);
}

.ai-insight:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.ai-insight-form {
    cursor: default;
}

.ai-insight strong {
    display: block;
}

.ai-insight small {
    display: block;
    color: var(--erp-muted);
}

.ai-insight-icon {
    width: 2.1rem;
    height: 2.1rem;
    padding: .45rem;
    border-radius: 10px;
    flex: none;
    color: var(--primary-600);
    background: color-mix(in oklab, var(--primary-500) 12%, transparent);
}

.ai-dates {
    display: flex;
    gap: .3rem;
    margin-top: .3rem;
}

.ai-dates input {
    width: 100%;
    min-width: 0;
    font-size: .75rem;
    padding: .2rem .3rem;
    border-radius: 8px;
    border: 1px solid var(--erp-line);
    background: transparent;
    color: inherit;
}

.ai-chat {
    display: flex;
    flex-direction: column;
    gap: .75rem;
    min-height: 70vh;
    padding: 1rem;
    border-radius: var(--erp-radius);
    background: var(--erp-card);
    box-shadow: var(--erp-shadow), 0 0 0 1px var(--erp-line);
}

.ai-thread {
    flex: 1;
    overflow-y: auto;
    max-height: 62vh;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: .25rem;
}

.ai-empty {
    margin: auto;
    text-align: center;
    max-width: 36rem;
}

.ai-empty h3 {
    font-size: 1.35rem;
    font-weight: 800;
    margin: .75rem 0 1rem;
}

.ai-orb {
    width: 4.5rem;
    height: 4.5rem;
    margin: 0 auto;
    border-radius: 999px;
    display: grid;
    place-items: center;
    color: #fff;
    background: radial-gradient(circle at 30% 30%, var(--primary-300), var(--primary-600) 60%, var(--primary-800));
    box-shadow: 0 16px 40px -14px var(--primary-600);
    animation: ai-float 4s ease-in-out infinite;
}

@keyframes ai-float {
    50% { transform: translateY(-6px); }
}

.ai-suggestions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: .5rem;
}

.ai-suggestions button {
    text-align: start;
    padding: .7rem .85rem;
    border-radius: 12px;
    border: 1px solid var(--erp-line);
    background: transparent;
    cursor: pointer;
    font-size: .9rem;
    transition: border-color .15s ease, background .15s ease;
}

.ai-suggestions button:hover {
    border-color: var(--primary-400);
    background: color-mix(in oklab, var(--primary-500) 7%, transparent);
}

.ai-msg {
    display: flex;
    gap: .6rem;
    align-items: flex-start;
}

.ai-msg-user {
    justify-content: flex-start;
    flex-direction: row-reverse;
}

.ai-bubble {
    max-width: min(46rem, 88%);
    padding: .75rem 1rem;
    border-radius: 16px;
    line-height: 1.9;
    white-space: normal;
}

.ai-msg-user .ai-bubble {
    color: #fff;
    background: linear-gradient(135deg, var(--primary-500), var(--primary-700));
    border-end-end-radius: 4px;
    white-space: pre-wrap;
}

.ai-msg-bot .ai-bubble {
    background: rgb(15 23 42 / .035);
    border: 1px solid var(--erp-line);
    border-start-start-radius: 4px;
}

.dark .ai-msg-bot .ai-bubble {
    background: rgb(255 255 255 / .04);
}

.ai-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 10px;
    display: grid;
    place-items: center;
    flex: none;
    color: #fff;
    background: linear-gradient(135deg, var(--primary-400), var(--primary-700));
}

.ai-meta {
    margin-top: .4rem;
    font-size: .72rem;
    color: var(--erp-muted);
    direction: ltr;
    text-align: end;
}

.ai-md h1, .ai-md h2, .ai-md h3 { font-weight: 800; margin: .6rem 0 .3rem; }
.ai-md h1 { font-size: 1.15rem; }
.ai-md h2 { font-size: 1.05rem; }
.ai-md h3 { font-size: 1rem; }
.ai-md ul { list-style: disc; padding-inline-start: 1.4rem; margin: .3rem 0; }
.ai-md ol { list-style: decimal; padding-inline-start: 1.4rem; margin: .3rem 0; }
.ai-md p { margin: .35rem 0; }
.ai-md strong { font-weight: 800; }
.ai-md table { border-collapse: collapse; margin: .5rem 0; font-size: .85rem; }
.ai-md th, .ai-md td { border: 1px solid var(--erp-line); padding: .3rem .5rem; }
.ai-md code { background: rgb(15 23 42 / .06); padding: 0 .3rem; border-radius: 5px; }

.ai-typing {
    display: flex;
    gap: .3rem;
    padding: 1rem;
}

.ai-typing span {
    width: .45rem;
    height: .45rem;
    border-radius: 999px;
    background: var(--primary-500);
    animation: ai-blink 1.2s infinite ease-in-out;
}

.ai-typing span:nth-child(2) { animation-delay: .15s; }
.ai-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes ai-blink {
    0%, 80%, 100% { opacity: .25; transform: scale(.8); }
    40% { opacity: 1; transform: scale(1); }
}

.ai-error {
    padding: .7rem 1rem;
    border-radius: 12px;
    background: rgb(220 38 38 / .08);
    color: rgb(185 28 28);
    font-weight: 600;
}

.dark .ai-error { color: rgb(252 165 165); }

.ai-composer {
    display: grid;
    gap: .5rem;
    padding: .6rem;
    border-radius: 16px;
    border: 1px solid var(--erp-line);
    background: rgb(255 255 255 / .6);
    transition: box-shadow .15s ease, border-color .15s ease;
}

.dark .ai-composer { background: rgb(255 255 255 / .03); }

.ai-composer:focus-within {
    border-color: var(--primary-400);
    box-shadow: 0 0 0 4px color-mix(in oklab, var(--primary-500) 15%, transparent);
}

.ai-composer textarea {
    width: 100%;
    resize: none;
    border: 0;
    outline: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    padding: .3rem .4rem;
}

.ai-composer-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: .75rem;
}

.ai-link {
    background: none;
    border: 0;
    color: var(--erp-muted);
    cursor: pointer;
    font-size: .85rem;
    text-decoration: underline;
}

/* ---------- حركة خفيفة عند فتح الصفحات ---------- */
@media (prefers-reduced-motion: no-preference) {
    .fi-main-ctn > .fi-main {
        /* backwards (لا both): بعد انتهاء الحركة لا يبقى أثر يحبس النوافذ المنبثقة تحت القائمة */
        animation: erp-rise .35s ease backwards;
    }

    @keyframes erp-rise {
        /* شفافية فقط: transform يجعل النوافذ المنبثقة محصورة داخل منطقة المحتوى */
        from { opacity: 0; }
        to { opacity: 1; }
    }
}

/* ---------- الطباعة: بدون الخلفيات، والصفحة تتدفق عادي على الورق ----------
   يلغي حاويات التمرير (direction: ltr / ارتفاع ثابت) والحركة؛ وإلا يُطبع المحتوى خارج الورقة أو شفافاً. */
@media print {
    html, body, .fi-body, .fi-layout, .fi-main-ctn, .fi-main {
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
    }
    .fi-body { background: #fff !important; }
    .fi-layout, .fi-main-ctn { display: block !important; }
    .fi-main-ctn, .fi-main-ctn > * { direction: rtl !important; }
    .fi-main-ctn { opacity: 1 !important; }
    .fi-main { animation: none !important; opacity: 1 !important; margin: 0 !important; max-width: none !important; }
    .erp-hero, .fi-sidebar, .fi-sidebar-close-overlay, .fi-topbar, .fi-topbar-ctn, .tg-cycle-btn, .tg-footer { display: none !important; }
}

/* ---------- شعار Trust Gates ---------- */
.tg-brand { display: inline-flex; align-items: center; height: 100%; }
.tg-logo { height: 100%; width: auto; max-width: 11rem; object-fit: contain; }
.tg-logo-dark { display: none; }
.dark .tg-logo-light { display: none; }
.dark .tg-logo-dark { display: inline-block; }
/* الشريط الجانبي داكن دائماً: الشعار الأبيض */
.fi-sidebar .tg-logo-light { display: none; }
.fi-sidebar .tg-logo-dark { display: inline-block; }
/* صفحة الدخول: شعار أكبر فوق النموذج */
.fi-simple-layout .fi-logo { height: 3.6rem !important; }

.erp-auth-logo { height: 4.2rem; width: auto; position: relative; z-index: 1; filter: drop-shadow(0 6px 18px rgb(0 0 0 / .25)); }
.erp-auth-tagline { position: relative; z-index: 1; margin-top: .4rem; font-size: .8rem; letter-spacing: .14em; text-transform: uppercase; opacity: .7; }
.tg-footer { text-align: center; font-size: .75rem; color: var(--erp-muted); padding: 1rem 0 .5rem; }
.tg-footer img { height: 1.1rem; display: inline-block; vertical-align: middle; margin-inline-end: .35rem; }

/* ---------- بوابتي ---------- */
.ess-hero { display: flex; gap: 1.1rem; align-items: center; padding: 1.4rem 1.6rem; border-radius: 22px; color: #fff;
    background: radial-gradient(500px 280px at 105% -20%, rgb(255 255 255 / .2), transparent 60%), linear-gradient(135deg, var(--primary-600), var(--primary-800));
    box-shadow: 0 24px 50px -28px var(--primary-700); }
.ess-hero h2 { font-size: 1.5rem; font-weight: 800; margin: 0; }
.ess-sub { opacity: .85; }
.ess-avatar { width: 4.2rem; height: 4.2rem; flex: none; border-radius: 18px; overflow: hidden; display: grid; place-items: center;
    font-size: 1.8rem; font-weight: 800; background: rgb(255 255 255 / .18); border: 2px solid rgb(255 255 255 / .35); }
.ess-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ess-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .55rem; }
.ess-chips span { padding: .2rem .65rem; border-radius: 999px; background: rgb(255 255 255 / .15); font-size: .8rem; }
.ess-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .8rem; }
.ess-kpis > div { padding: .9rem 1rem; border-radius: var(--erp-radius); background: var(--erp-card); box-shadow: var(--erp-shadow), 0 0 0 1px var(--erp-line); display: grid; }
.ess-kpis small { color: var(--erp-muted); font-weight: 600; }
.ess-kpis strong { font-size: 1.7rem; font-weight: 800; color: var(--primary-600); line-height: 1.3; }
.ess-kpis span { font-size: .8rem; color: var(--erp-muted); }
.ess-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr)); gap: 1rem; align-items: start; }
.ess-row { display: flex; justify-content: space-between; gap: .6rem; align-items: center; padding: .55rem 0; border-bottom: 1px solid var(--erp-line); }
.ess-row:last-child { border-bottom: 0; }
.ess-facts { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.ess-facts div { display: grid; }
.ess-facts small { color: var(--erp-muted); }

/* ---------- الهيكل التنظيمي ---------- */
.org-tree, .org-tree ul { list-style: none; margin: 0; padding: 0; }
.org-tree ul { padding-inline-start: 2rem; border-inline-start: 2px solid color-mix(in oklab, var(--primary-500) 25%, transparent); margin-inline-start: 1.2rem; }
.org-tree li { position: relative; padding: .35rem 0; }
.org-tree ul > li::before { content: ''; position: absolute; inset-inline-start: -2rem; top: 1.6rem; width: 1.8rem; border-top: 2px solid color-mix(in oklab, var(--primary-500) 25%, transparent); }
.org-card { display: inline-flex; gap: .65rem; align-items: center; padding: .55rem .8rem; border-radius: 14px; background: var(--erp-card);
    box-shadow: var(--erp-shadow), 0 0 0 1px var(--erp-line); min-width: 15rem; }
.org-card .org-av { width: 2.4rem; height: 2.4rem; border-radius: 12px; display: grid; place-items: center; color: #fff; font-weight: 800;
    background: linear-gradient(135deg, var(--primary-400), var(--primary-700)); overflow: hidden; flex: none; }
.org-card .org-av img { width: 100%; height: 100%; object-fit: cover; }
.org-card small { display: block; color: var(--erp-muted); }
.org-count { margin-inline-start: auto; font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; background: color-mix(in oklab, var(--primary-500) 12%, transparent); color: var(--primary-700); }

/* ---------- صندوق الاعتمادات ---------- */
.inbox-group { margin-bottom: 1rem; }
.inbox-item { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .6rem; align-items: center; padding: .7rem .9rem; border-radius: 14px;
    background: var(--erp-card); box-shadow: var(--erp-shadow), 0 0 0 1px var(--erp-line); margin-top: .5rem; }
.inbox-item small { color: var(--erp-muted); }

/* ---------- تحليلات الموارد البشرية ---------- */
.hra-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .8rem; }
.hra-kpis > div { padding: .9rem 1rem; border-radius: var(--erp-radius); background: var(--erp-card); box-shadow: var(--erp-shadow), 0 0 0 1px var(--erp-line); position: relative; overflow: hidden; }
.hra-kpis > div::before { content: ''; position: absolute; inset-inline: 0; top: 0; height: 3px; background: linear-gradient(90deg, var(--primary-300), var(--primary-600)); }
.hra-kpis small { display: block; color: var(--erp-muted); font-weight: 600; }
.hra-kpis strong { font-size: 1.6rem; font-weight: 800; }
.hra-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 1rem; margin-top: 1rem; }
.hra-bar { display: grid; grid-template-columns: 9rem 1fr 4.5rem; gap: .6rem; align-items: center; margin: .45rem 0; font-size: .85rem; }
.hra-bar .track { height: .65rem; border-radius: 999px; background: color-mix(in oklab, var(--primary-500) 10%, transparent); overflow: hidden; }
.hra-bar .fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary-400), var(--primary-700)); }
.hra-bar .val { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; }

/* ---------- التمرير (Scroll) على الكمبيوتر — واجهة عربية ----------
   القائمة الجانبية لها شريط تمرير خاص على الحافة اليمنى للشاشة،
   والشاشة المفتوحة لها شريط تمرير في المنتصف (بجوار القائمة) — فلا يختلطان. */
@media (min-width: 1024px) {
    html[dir="rtl"]:has(.fi-body-has-navigation),
    html[dir="rtl"] .fi-body-has-navigation {
        height: 100%;
        overflow: hidden;
    }

    html[dir="rtl"] .fi-body-has-navigation .fi-layout {
        height: calc(100dvh - 4rem);
        min-height: 0;
        overflow: hidden;
    }

    /* محتوى الشاشة: حاوية التمرير الوحيدة. ltr للحاوية فقط ليظهر الشريط بجوار القائمة */
    html[dir="rtl"] .fi-body-has-navigation .fi-main-ctn {
        height: 100%;
        overflow-y: auto;
        overflow-x: hidden;
        direction: ltr;
        scrollbar-gutter: stable;
    }

    html[dir="rtl"] .fi-body-has-navigation .fi-main-ctn > * {
        direction: rtl;
        flex-shrink: 0;
    }

    html[dir="rtl"] .fi-body-has-navigation .fi-main-ctn > .fi-main {
        height: auto;
        flex: 1 0 auto;
    }

    /* القائمة الجانبية: الشريط على الحافة اليمنى */
    html[dir="rtl"] .fi-sidebar-nav {
        direction: ltr;
    }

    html[dir="rtl"] .fi-sidebar-nav > * {
        direction: rtl;
    }
}

/* شكل أشرطة التمرير */
.fi-main-ctn,
.fi-sidebar-nav {
    scrollbar-width: thin;
}

.fi-main-ctn {
    scrollbar-color: color-mix(in oklab, var(--primary-500) 45%, transparent) transparent;
}

.fi-sidebar-nav {
    scrollbar-color: rgb(255 255 255 / .22) transparent;
}

.fi-sidebar-nav:hover {
    scrollbar-color: rgb(255 255 255 / .4) transparent;
}

/* ---------- اختيار الموقع على الخريطة ---------- */
.tg-map-picker { display: grid; gap: .6rem; }
.tg-map-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; }
.tg-map-search { flex: 1 1 18rem; display: flex; border-radius: 12px; overflow: hidden; box-shadow: 0 0 0 1px var(--erp-line), var(--erp-shadow); background: #fff; }
.dark .tg-map-search { background: rgb(255 255 255 / .05); }
.tg-map-search input { flex: 1; min-width: 0; border: 0; background: transparent; padding: .6rem .8rem; font: inherit; color: var(--erp-ink); outline: none; }
.tg-map-search input:focus { box-shadow: none; }
.tg-map-search button { padding: 0 1.1rem; border: 0; font: inherit; font-weight: 700; color: #fff; background: var(--primary-600); cursor: pointer; }
.tg-map-search button:hover { background: var(--primary-700); }
.tg-map-here { display: inline-flex; align-items: center; gap: .4rem; padding: .55rem 1rem; border-radius: 12px; font: inherit; font-weight: 700; cursor: pointer;
    color: var(--primary-700); background: color-mix(in oklab, var(--primary-500) 12%, transparent); border: 1px solid color-mix(in oklab, var(--primary-500) 30%, transparent); }
.dark .tg-map-here { color: var(--primary-300); }
.tg-map-here:hover { background: color-mix(in oklab, var(--primary-500) 20%, transparent); }
.tg-map-results { list-style: none; margin: 0; padding: .3rem; border-radius: 12px; background: var(--erp-card); box-shadow: 0 0 0 1px var(--erp-line), var(--erp-shadow); max-height: 14rem; overflow-y: auto; }
.tg-map-results button { width: 100%; text-align: start; padding: .5rem .6rem; border: 0; background: transparent; border-radius: 8px; font: inherit; font-size: .88rem; color: var(--erp-ink); cursor: pointer; }
.tg-map-results button:hover { background: color-mix(in oklab, var(--primary-500) 10%, transparent); }
.tg-map-message { margin: 0; font-size: .85rem; color: var(--primary-700); }
.dark .tg-map-message { color: var(--primary-300); }
.tg-map { height: 380px; border-radius: 14px; overflow: hidden; box-shadow: 0 0 0 1px var(--erp-line), var(--erp-shadow); z-index: 0; }
.tg-map-hint { margin: 0; font-size: .82rem; color: var(--erp-muted); }
@media (max-width: 640px) { .tg-map { height: 300px; } }
.ai-error { white-space: pre-line; }

/* ---------- الدورة المستندية ---------- */
.tg-cycle-btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem .9rem; border-radius: 12px; font: inherit; font-size: .88rem; font-weight: 700; cursor: pointer;
    color: var(--primary-700); background: color-mix(in oklab, var(--primary-500) 10%, transparent); border: 1px solid color-mix(in oklab, var(--primary-500) 28%, transparent); transition: background .15s; }
.tg-cycle-btn:hover { background: color-mix(in oklab, var(--primary-500) 18%, transparent); }
.dark .tg-cycle-btn { color: var(--primary-300); }
@media (max-width: 640px) { .tg-cycle-btn span { display: none; } .tg-cycle-btn { padding: .5rem; } }

.tg-cycle-tabs { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; padding-bottom: .8rem; border-bottom: 1px solid var(--erp-line); }
.tg-cycle-tabs button { display: inline-flex; align-items: center; gap: .35rem; padding: .4rem .75rem; border-radius: 999px; border: 1px solid var(--erp-line); background: transparent;
    font: inherit; font-size: .85rem; font-weight: 600; color: var(--erp-muted); cursor: pointer; }
.tg-cycle-tabs button:hover { color: var(--erp-ink); background: color-mix(in oklab, var(--primary-500) 7%, transparent); }
.tg-cycle-tabs button.is-active { color: #fff; border-color: transparent; background: linear-gradient(135deg, var(--primary-500), var(--primary-700)); box-shadow: 0 8px 18px -10px var(--primary-600); }
.tg-cycle-tab-icon { width: 1rem; height: 1rem; }
.tg-cycle-intro { margin: 0 0 1.1rem; color: var(--erp-muted); }

.tg-cycle-flow { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr)); gap: 1.4rem 2.2rem; }
.tg-step { position: relative; display: flex; }
.tg-step:not(:last-child)::after { content: '←'; position: absolute; inset-inline-end: -1.75rem; top: 1.35rem; font-size: 1.35rem; font-weight: 800; color: var(--primary-500); }
.tg-step-card { flex: 1; display: grid; align-content: start; gap: .5rem; padding: .9rem 1rem; border-radius: 16px; background: var(--erp-card);
    box-shadow: var(--erp-shadow), 0 0 0 1px var(--erp-line); border-top: 3px solid var(--primary-500); }
.tg-step.is-optional .tg-step-card { border-top-style: dashed; border-top-color: var(--erp-muted); }
.tg-step-card p { margin: 0; font-size: .87rem; line-height: 1.65; color: var(--erp-muted); }
.tg-step-head { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.tg-step-head strong { font-size: 1rem; color: var(--erp-ink); }
.tg-step-num { display: grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; font-size: .8rem; font-weight: 800; color: #fff;
    background: linear-gradient(135deg, var(--primary-400), var(--primary-700)); flex: none; }
.tg-step-icon { width: 1.25rem; height: 1.25rem; color: var(--primary-600); }
.dark .tg-step-icon { color: var(--primary-300); }
.tg-step-tag { font-size: .7rem; padding: .05rem .45rem; border-radius: 999px; background: rgb(100 116 139 / .14); color: var(--erp-muted); }
.tg-step-approvals { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
.tg-approval { display: inline-flex; align-items: center; gap: .25rem; padding: .15rem .5rem; border-radius: 999px; font-size: .74rem; font-weight: 700;
    color: #047857; background: rgb(16 185 129 / .12); }
.dark .tg-approval { color: #6ee7b7; }
.tg-arrow-sm { color: var(--erp-muted); font-size: .8rem; }
.tg-step-alt { font-size: .82rem; padding: .45rem .6rem; border-radius: 10px; background: rgb(245 158 11 / .1); color: var(--erp-ink); }
.tg-step-alt a { font-weight: 700; color: var(--primary-700); text-decoration: underline; }
.dark .tg-step-alt a { color: var(--primary-300); }
.tg-alt-label { display: inline-block; margin-inline-end: .3rem; font-size: .7rem; font-weight: 800; color: #b45309; }
.tg-step-link { justify-self: start; font-size: .8rem; font-weight: 700; color: var(--primary-600); }
.tg-step-link:hover { text-decoration: underline; }
.dark .tg-step-link { color: var(--primary-300); }

.tg-cycle-rules { margin-top: 1.3rem; padding: .9rem 1.1rem; border-radius: 14px; background: color-mix(in oklab, var(--primary-500) 7%, transparent);
    border-inline-start: 4px solid var(--primary-500); }
.tg-cycle-rules ul { margin: .4rem 0 0; padding-inline-start: 1.2rem; list-style: disc; display: grid; gap: .25rem; font-size: .88rem; }

@media (max-width: 640px) {
    .tg-cycle-flow { grid-template-columns: 1fr; gap: 1.9rem; }
    .tg-step:not(:last-child)::after { content: '↓'; inset-inline-end: auto; inset-inline-start: 50%; top: auto; bottom: -1.75rem; transform: translateX(50%); }
}
