/* ================================================================
   دليل الاستخدام — صفحات عامة مستقلة عن لوحة الإدارة
   نفس هوية النظام: كحلي للهيكل وذهبي للعنصر النشط، مع وضع داكن تلقائي.
   ================================================================ */

:root {
    --d-bg: #f4f6f9;
    --d-surface: #ffffff;
    --d-sunken: #f0f3f7;
    --d-line: #dfe5ed;
    --d-fg: #16202e;
    --d-soft: #46566c;
    --d-muted: #66758a;
    --d-navy: #11203a;
    --d-navy-2: #1a2f4f;
    --d-gold: #cda233;
    --d-gold-strong: #9c7614;
    --d-gold-soft: #f8f1dc;
    --d-link: #1d4f91;
    --d-tip: #14794b;
    --d-tip-bg: #e9f6ef;
    --d-info: #175cd3;
    --d-info-bg: #eaf1fd;
    --d-warn: #9a5b07;
    --d-warn-bg: #fdf3e3;
    --d-danger: #b42318;
    --d-danger-bg: #fdeeed;
    --d-code-bg: #eef1f6;
    --d-shadow: 0 1px 2px rgba(17, 32, 58, .06), 0 4px 16px rgba(17, 32, 58, .05);
    --d-radius: 12px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --d-bg: #0c1422;
        --d-surface: #121d30;
        --d-sunken: #0f192a;
        --d-line: #24334c;
        --d-fg: #e6ecf5;
        --d-soft: #b5c2d6;
        --d-muted: #8c9bb2;
        --d-navy: #0a1220;
        --d-navy-2: #15243c;
        --d-gold: #e0b84a;
        --d-gold-strong: #e8c665;
        --d-gold-soft: #2b2512;
        --d-link: #8fb8ff;
        --d-tip: #5fd29a;
        --d-tip-bg: #10291e;
        --d-info: #8fb8ff;
        --d-info-bg: #13233f;
        --d-warn: #f0b860;
        --d-warn-bg: #2d2210;
        --d-danger: #ff8b80;
        --d-danger-bg: #331614;
        --d-code-bg: #1b2840;
        --d-shadow: 0 1px 2px rgba(0, 0, 0, .3);
        color-scheme: dark;
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-padding-top: 80px; }

body.docs {
    margin: 0;
    background: var(--d-bg);
    color: var(--d-fg);
    font-family: "Segoe UI", "Noto Kufi Arabic", "Noto Sans Arabic", "Dubai", Tahoma, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.85;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body.docs a { color: var(--d-link); text-underline-offset: 3px; }
body.docs a:hover { color: var(--d-gold-strong); }
body.docs :focus-visible { outline: 3px solid var(--d-gold); outline-offset: 2px; border-radius: 4px; }

.skip-link {
    position: absolute; inset-inline-start: 16px; top: -60px; z-index: 100;
    background: var(--d-gold); color: #1a1405 !important; padding: 8px 14px; border-radius: 8px; font-weight: 700;
}
.skip-link:focus { top: 8px; }

/* ── الشريط العلوي ── */
.docs-top {
    position: sticky; top: 0; z-index: 50;
    background: var(--d-navy);
    color: #fff;
    border-bottom: 3px solid var(--d-gold);
}
.docs-top-in {
    max-width: 1400px; margin: 0 auto; padding: 10px 16px;
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.docs-brand { display: inline-flex; align-items: center; gap: 10px; color: #fff !important; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.docs-brand-mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--d-gold); color: #1a1405; }
.docs-brand-mark svg { width: 20px; height: 20px; }
.docs-top-links { margin-inline-start: auto; display: flex; gap: 6px; align-items: center; }
.docs-top-links a { color: #c9d5e6 !important; text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: .92rem; }
.docs-top-links a:hover { background: rgba(255, 255, 255, .08); color: #fff !important; }
.docs-top-links a.docs-top-cta { background: var(--d-gold); color: #1a1405 !important; font-weight: 700; }
.docs-top-links a.docs-top-cta:hover { background: #e0b84a; }

/* ── الصفحة الرئيسية للدليل ── */
.docs-home { max-width: 1180px; margin: 0 auto; padding: 0 16px 48px; }
.home-hero { text-align: center; padding: 44px 0 28px; }
.home-hero h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); font-weight: 800; margin: 0 0 10px; color: var(--d-fg); }
.home-hero > p { max-width: 720px; margin: 0 auto 22px; color: var(--d-soft); }
.home-search { position: relative; max-width: 640px; margin: 0 auto; }
.home-search svg { position: absolute; inset-inline-start: 16px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--d-muted); pointer-events: none; }
.home-search input {
    width: 100%; font: inherit; font-size: 1.05rem;
    padding: 14px 16px; padding-inline-start: 48px;
    border: 1.5px solid var(--d-line); border-radius: 14px;
    background: var(--d-surface); color: var(--d-fg); box-shadow: var(--d-shadow);
}
.home-search input:focus { outline: none; border-color: var(--d-gold); box-shadow: 0 0 0 4px color-mix(in srgb, var(--d-gold) 25%, transparent); }
.home-start { margin-top: 16px !important; font-size: .95rem; color: var(--d-muted) !important; }

.home-group { margin-top: 28px; }
.home-group h2 { font-size: .95rem; font-weight: 700; color: var(--d-muted); margin: 0 0 12px; letter-spacing: 0; }
.home-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 14px; }
.home-card {
    display: flex; gap: 14px; align-items: flex-start;
    padding: 16px; border-radius: var(--d-radius);
    background: var(--d-surface); border: 1px solid var(--d-line); box-shadow: var(--d-shadow);
    color: var(--d-fg) !important; text-decoration: none;
    transition: border-color .15s, transform .15s;
}
.home-card:hover { border-color: var(--d-gold); transform: translateY(-1px); }
.home-card-icon { flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 11px; background: var(--d-gold-soft); color: var(--d-gold-strong); }
.home-card-icon svg { width: 24px; height: 24px; }
.home-card-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.home-card-text strong { font-size: 1.02rem; }
.home-card-text span { font-size: .9rem; color: var(--d-soft); line-height: 1.65; }
.home-empty { text-align: center; color: var(--d-muted); margin-top: 32px; }

/* ── هيكل صفحة الشرح ── */
.docs-shell {
    max-width: 1400px; margin: 0 auto; padding: 24px 16px 40px;
    display: grid; gap: 28px;
    grid-template-columns: 250px minmax(0, 1fr) 220px;
    grid-template-areas: "nav main toc";
    align-items: start;
}
.docs-nav { grid-area: nav; position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow-y: auto; }
.docs-main { grid-area: main; min-width: 0; }
.docs-toc { grid-area: toc; position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow-y: auto; }

.docs-nav summary { font-weight: 700; cursor: pointer; padding: 8px 0; color: var(--d-fg); }
.docs-nav-group h2 { font-size: .8rem; font-weight: 700; color: var(--d-muted); margin: 14px 0 4px; }
.docs-nav ul { list-style: none; margin: 0; padding: 0; }
.docs-nav li a {
    display: block; padding: 6px 12px; border-radius: 8px;
    color: var(--d-soft) !important; text-decoration: none; font-size: .93rem; line-height: 1.5;
    border-inline-start: 3px solid transparent;
}
.docs-nav li a:hover { background: var(--d-sunken); color: var(--d-fg) !important; }
.docs-nav li a.active { background: var(--d-gold-soft); color: var(--d-fg) !important; font-weight: 700; border-inline-start-color: var(--d-gold); }

.docs-toc h2 { font-size: .8rem; font-weight: 700; color: var(--d-muted); margin: 6px 0 8px; }
.docs-toc ol { list-style: none; margin: 0; padding: 0; border-inline-start: 2px solid var(--d-line); }
.docs-toc a { display: block; padding: 4px 12px; margin-inline-start: -2px; border-inline-start: 2px solid transparent; color: var(--d-muted) !important; text-decoration: none; font-size: .87rem; line-height: 1.5; }
.docs-toc a:hover { color: var(--d-fg) !important; }
.docs-toc a.active { color: var(--d-fg) !important; border-inline-start-color: var(--d-gold); font-weight: 600; }

.docs-crumbs { font-size: .85rem; color: var(--d-muted); display: flex; gap: 8px; flex-wrap: wrap; }
.docs-crumbs a { color: var(--d-muted) !important; }
.doc-head h1 { font-size: clamp(1.5rem, 3.2vw, 2.1rem); font-weight: 800; margin: 6px 0 6px; line-height: 1.4; }
.doc-lead { font-size: 1.08rem; color: var(--d-soft); margin: 0 0 8px; }

/* ── محتوى الشرح ── */
.doc { max-width: 78ch; }
.doc h2 {
    font-size: 1.35rem; font-weight: 800; margin: 2.2em 0 .6em; padding-top: .6em;
    border-top: 1px solid var(--d-line); line-height: 1.45;
}
.doc h2:first-child { border-top: 0; margin-top: 1.2em; padding-top: 0; }
.doc h3 { font-size: 1.1rem; font-weight: 700; margin: 1.6em 0 .4em; }
.doc p, .doc ul, .doc ol { margin: 0 0 1em; }
.doc ul, .doc ol { padding-inline-start: 1.4em; }
.doc li { margin: .25em 0; }
.doc li > ul, .doc li > ol { margin: .25em 0 .4em; }
.doc strong { font-weight: 700; }
.doc code {
    font-family: ui-monospace, Consolas, "Cascadia Mono", monospace; font-size: .88em;
    background: var(--d-code-bg); color: var(--d-fg); padding: .1em .4em; border-radius: 5px;
    direction: ltr; unicode-bidi: isolate; overflow-wrap: anywhere;
}
.doc pre {
    direction: ltr; text-align: left; background: var(--d-code-bg); color: var(--d-fg);
    padding: 14px 16px; border-radius: 10px; overflow-x: auto; font-size: .88rem; line-height: 1.6; margin: 0 0 1.2em;
    max-width: 100%;
}
.doc pre code { background: none; padding: 0; font-size: inherit; }
.doc kbd {
    display: inline-block; min-width: 1.9em; text-align: center;
    font-family: ui-monospace, Consolas, monospace; font-size: .82em; font-weight: 700;
    padding: .05em .45em; border-radius: 6px; direction: ltr;
    background: var(--d-surface); color: var(--d-fg);
    border: 1px solid var(--d-line); border-bottom-width: 3px;
}
.doc .ui { font-weight: 700; color: var(--d-fg); }
.doc .ui::before { content: "«"; color: var(--d-muted); font-weight: 400; }
.doc .ui::after { content: "»"; color: var(--d-muted); font-weight: 400; }
.doc .path { font-weight: 600; }

/* خطوات مرقّمة */
.doc ol.steps { list-style: none; padding: 0; counter-reset: step; margin: 0 0 1.4em; }
.doc ol.steps > li {
    counter-increment: step; position: relative;
    padding: 2px 0 14px; padding-inline-start: 46px; margin: 0;
}
.doc ol.steps > li::before {
    content: counter(step); position: absolute; inset-inline-start: 0; top: 0;
    width: 30px; height: 30px; border-radius: 50%;
    display: grid; place-items: center; font-weight: 800; font-size: .9rem;
    background: var(--d-navy-2); color: #fff;
}
.doc ol.steps > li:not(:last-child)::after {
    content: ""; position: absolute; inset-inline-start: 14px; top: 34px; bottom: 2px; width: 2px; background: var(--d-line);
}

/* تنبيهات */
.callout {
    margin: 0 0 1.2em; padding: 12px 16px; border-radius: 10px;
    border: 1px solid transparent; border-inline-start-width: 5px;
    background: var(--d-info-bg); border-color: color-mix(in srgb, var(--d-info) 25%, transparent); border-inline-start-color: var(--d-info);
}
.callout > :last-child { margin-bottom: 0; }
.callout > b:first-child, .callout > p:first-child > b:first-child { color: var(--d-info); }
.callout.tip { background: var(--d-tip-bg); border-color: color-mix(in srgb, var(--d-tip) 25%, transparent); border-inline-start-color: var(--d-tip); }
.callout.tip > b:first-child, .callout.tip > p:first-child > b:first-child { color: var(--d-tip); }
.callout.warn { background: var(--d-warn-bg); border-color: color-mix(in srgb, var(--d-warn) 25%, transparent); border-inline-start-color: var(--d-warn); }
.callout.warn > b:first-child, .callout.warn > p:first-child > b:first-child { color: var(--d-warn); }
.callout.danger { background: var(--d-danger-bg); border-color: color-mix(in srgb, var(--d-danger) 25%, transparent); border-inline-start-color: var(--d-danger); }
.callout.danger > b:first-child, .callout.danger > p:first-child > b:first-child { color: var(--d-danger); }

/* جداول */
.doc .tbl { width: 100%; overflow-x: auto; margin: 0 0 1.2em; }
.doc table { width: 100%; border-collapse: collapse; font-size: .93rem; background: var(--d-surface); border-radius: 10px; overflow: hidden; border: 1px solid var(--d-line); }
.doc th, .doc td { padding: 9px 12px; border-bottom: 1px solid var(--d-line); text-align: start; vertical-align: top; }
.doc th { background: var(--d-sunken); font-weight: 700; white-space: nowrap; }
.doc tr:last-child td { border-bottom: 0; }

/* بطاقات صغيرة داخل الشرح */
.doc .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 12px; margin: 0 0 1.2em; }
.doc .card-s { background: var(--d-surface); border: 1px solid var(--d-line); border-radius: 10px; padding: 12px 14px; }
.doc .card-s b { display: block; margin-bottom: 2px; }
.doc .card-s span { font-size: .92rem; color: var(--d-soft); }

/* مخطط تدفق بسيط */
.doc .flow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 1.2em; }
.doc .flow span { background: var(--d-surface); border: 1px solid var(--d-line); border-radius: 10px; padding: 6px 12px; font-weight: 600; font-size: .93rem; }
.doc .flow i { font-style: normal; color: var(--d-muted); }

/* أسئلة قابلة للطي */
.doc details.qa { background: var(--d-surface); border: 1px solid var(--d-line); border-radius: 10px; margin: 0 0 10px; }
.doc details.qa summary { cursor: pointer; padding: 12px 16px; font-weight: 700; list-style-position: inside; }
.doc details.qa[open] summary { border-bottom: 1px solid var(--d-line); }
.doc details.qa > div { padding: 12px 16px 4px; }

/* السابق / التالي */
.doc-pager { max-width: 78ch; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--d-line); }
.doc-pager a {
    display: flex; flex-direction: column; padding: 12px 16px; border-radius: 10px;
    border: 1px solid var(--d-line); background: var(--d-surface); text-decoration: none; color: var(--d-fg) !important;
}
.doc-pager a:hover { border-color: var(--d-gold); }
.doc-pager small { color: var(--d-muted); font-size: .8rem; }
.doc-pager span { font-weight: 700; }
.doc-pager-next { text-align: left; grid-column: 2; }
.doc-pager-next small::after { content: " ←"; }
.doc-pager-prev small::before { content: "→ "; }

.docs-foot { border-top: 1px solid var(--d-line); padding: 20px 16px 28px; text-align: center; color: var(--d-muted); font-size: .9rem; }

/* ── شاشات متوسطة: الفهرس فوق المحتوى ── */
@media (max-width: 1199.98px) {
    .docs-shell { grid-template-columns: 240px minmax(0, 1fr); grid-template-areas: "nav toc" "nav main"; row-gap: 0; }
    .docs-toc { position: static; max-height: none; background: var(--d-surface); border: 1px solid var(--d-line); border-radius: 10px; padding: 8px 14px 10px; margin-bottom: 8px; }
    .docs-toc ol { columns: 2; column-gap: 20px; border: 0; }
    .docs-toc a { border: 0; padding: 3px 0; margin: 0; }
}

/* ── الموبايل: عمود واحد ── */
@media (max-width: 991.98px) {
    html { scroll-padding-top: 70px; }
    .docs-shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "nav" "toc" "main"; gap: 12px; padding-top: 14px; }
    .docs-nav { position: static; max-height: none; background: var(--d-surface); border: 1px solid var(--d-line); border-radius: 10px; padding: 2px 14px; }
    .docs-nav details[open] { padding-bottom: 10px; }
    .docs-toc ol { columns: 1; }
    .doc h2 { font-size: 1.2rem; }
    .doc-pager { grid-template-columns: 1fr; }
    .doc-pager-next { grid-column: 1; }
    .docs-top-links a:not(.docs-top-cta) { display: none; }
}

@media (max-width: 420px) {
    body.docs { font-size: 15.5px; }
    .doc ol.steps > li { padding-inline-start: 40px; }
    .doc ol.steps > li::before { width: 28px; height: 28px; }
    .doc ol.steps > li:not(:last-child)::after { inset-inline-start: 13px; }
}

@media print {
    .docs-top, .docs-nav, .docs-toc, .doc-pager, .docs-foot, .skip-link { display: none !important; }
    .docs-shell { display: block; padding: 0; }
    body.docs { background: #fff; color: #000; }
}
