/* --- بارگذاری فونت استاندارد وب --- */
@import url('https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/Vazirmatn-font-face.css');

html, body {
    margin: 0; padding: 0; box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    line-height: 1.7em; transition: background-color 0.3s, color 0.3s;
}

body {
    background-color: #F3F7F3; /* رنگ پیش‌فرض روز */
    padding: 20px;
}

/* این محدودیت عرض فقط برای صفحات مقاله اعمال می‌شود، نه صفحه اصلی دانشنامه
   (صفحه اصلی چیدمان و عرض خودش را دارد و نباید بهم بریزد) */
#write, body.vf-article-page {
    max-width: 46em;
    margin: 0 auto !important;
    padding: 40px 25px 120px 25px !important;
    direction: rtl;
    text-align: right;
    box-sizing: border-box;
}

body, p, h1, h2, h3, h4, h5, h6, ul, ol, li, blockquote, table, figcaption, .footnote, .md-meta, .md-link, .md-url {
    direction: rtl; text-align: right;
}

body, #write {
    font-family: "B Mitra", "B Nazanin", "Vazirmatn", "Segoe UI", sans-serif;
}

code, pre, tt, .md-code, .codeblock {
    direction: ltr; text-align: left; unicode-bidi: embed;
    font-family: monospace; font-size: 0.9em; padding: 2px 6px; border-radius: 4px;
}

blockquote {
    border-left: none; padding-left: 0; margin-left: 0; margin-right: 0;
    padding-right: 16px; font-style: italic; margin-bottom: 1.5em;
}

h1, h2, h3, h4, h5, h6 { font-weight: bold; margin-bottom: 1em; }
h1 { font-size: 1.85em; margin-top: 1.5em; padding-bottom: 0.5em; }
h2 { font-size: 1.45em; margin-top: 1.8em; }
p { margin-bottom: 1.5em; }
ul, ol { margin: 0 20px 1.5em 0; padding: 0; }
ul li { list-style-type: disc; margin-bottom: 0.5em; }
ol li { list-style-type: decimal; margin-bottom: 0.5em; }
table { width: 100%; margin-bottom: 1.5em; border-collapse: collapse; }
th, td { padding: 10px; text-align: right; }

/* --- قالب روز (Newsprint) --- */
body.light-theme { background-color: #F3F7F3; color: #333333; }
.light-theme h1 { border-bottom: 1px solid #c5c5c5; color: #1f0909; }
.light-theme blockquote { border-right: 4px solid #aaa; color: #656565; background: rgba(0,0,0,0.01); }
.light-theme code, .light-theme .md-fences { background-color: #dadada; color: #1f0909; }
.light-theme thead { background-color: #dadada; }
.light-theme tr:nth-child(even) { background: #e8e7e7; }
.light-theme td, .light-theme th { border: 1px solid #c5c5c5; }
.light-theme a { color: #065588; text-decoration: none; }

/* --- قالب شب (Night) --- */
body.dark-theme { background-color: #1C2520; color: #DDE5DD; }
.dark-theme h1 { border-bottom: 1px solid #334237; color: #ffffff; }
.dark-theme blockquote { border-right: 4px solid #4e6355; color: #a5b3a9; background: rgba(255,255,255,0.02); }
.dark-theme code, .dark-theme .md-fences { background-color: #26332b; color: #ffffff; }
.dark-theme table, .dark-theme table tr, .dark-theme table td, .dark-theme table th {
    color: #DDE5DD !important;
    background-color: transparent !important;
}
.dark-theme thead, .dark-theme table th {
    background-color: #2c3a32 !important;
    color: #ffffff !important;
    font-weight: 600;
}
.dark-theme tr:nth-child(even), .dark-theme table tbody tr:nth-child(even) {
    background: #202b25 !important;
}
.dark-theme tr:nth-child(odd), .dark-theme table tbody tr:nth-child(odd) {
    background: #1C2520 !important;
}
.dark-theme td, .dark-theme th {
    border: 1px solid #43574a !important;
}
.dark-theme a { color: #8cd7a3; text-decoration: none; }

/* --- استایل باکس دکمه‌های شناور پایین صفحه --- */
.action-bar {
    position: fixed; bottom: 25px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 15px; background: rgba(255, 255, 255, 0.9);
    padding: 10px 20px; border-radius: 50px; z-index: 99999;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1); border: 1px solid rgba(0,0,0,0.05);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    align-items: center; transition: background 0.3s, border-color 0.3s;
}

body.dark-theme .action-bar {
    background: rgba(28, 37, 32, 0.95); border-color: rgba(255,255,255,0.05);
}

/* استایل مشترک دکمه‌های دایره‌ای نوار شناور */
#theme-toggle-btn, #search-toggle-btn, #toc-toggle-btn, #bookmark-toggle-btn {
    background: none; border: none; font-size: 1.5rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.2s; outline: none; padding: 5px;
}
#theme-toggle-btn:hover, #search-toggle-btn:hover, #toc-toggle-btn:hover, #bookmark-toggle-btn:hover { transform: scale(1.15); }
#bookmark-toggle-btn.active { color: #f5b301; }

#forum-redirect-btn, #flashcard-redirect-btn {
    display: flex; align-items: center; justify-content: center;
    text-decoration: none; font-size: 1.5rem; transition: transform 0.2s; padding: 5px;
}
#forum-redirect-btn:hover, #flashcard-redirect-btn:hover { transform: scale(1.15); }


/* ====================================================================
   موتور جستجوی سراسری دانشنامه: مودال، نتایج، هایلایت
   ==================================================================== */

.vf-search-overlay {
    position: fixed; inset: 0; z-index: 100000;
    background: rgba(0,0,0,0.45);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 8vh 16px 16px 16px;
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s ease;
}
.vf-search-overlay.open {
    opacity: 1; pointer-events: auto;
}

.vf-search-panel {
    width: 100%; max-width: 640px;
    background: #ffffff; color: #333333;
    border-radius: 16px; overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    display: flex; flex-direction: column;
    max-height: 78vh;
    transform: translateY(-10px);
    transition: transform 0.2s ease;
}
.vf-search-overlay.open .vf-search-panel { transform: translateY(0); }

body.dark-theme .vf-search-panel {
    background: #1C2520; color: #DDE5DD;
}

.vf-search-header {
    display: flex; align-items: center; gap: 10px;
    padding: 16px 18px; border-bottom: 1px solid #e5e5e5;
}
body.dark-theme .vf-search-header { border-bottom-color: #334237; }

#vf-search-input {
    flex: 1; font-size: 1.05rem; padding: 10px 14px;
    border: 1px solid #dadada; border-radius: 10px; outline: none;
    direction: rtl; text-align: right; font-family: inherit;
    background: #fff; color: #333;
}
body.dark-theme #vf-search-input {
    background: #26332b; color: #fff; border-color: #334237;
}

#vf-search-refresh, #vf-search-close {
    background: none; border: none; font-size: 1.1rem; cursor: pointer;
    color: inherit; opacity: 0.6; padding: 6px;
}
#vf-search-refresh:hover, #vf-search-close:hover { opacity: 1; }

.vf-search-status {
    padding: 4px 18px; font-size: 0.85rem; color: #888; min-height: 18px;
}
body.dark-theme .vf-search-status { color: #a5b3a9; }

.vf-index-progress {
    display: none;
    padding: 2px 18px 8px 18px; font-size: 0.75rem; color: #aaa;
}
body.dark-theme .vf-index-progress { color: #6f7d73; }

/* قفل اسکرول پس‌زمینه هنگام باز بودن مودال جستجو */
body.vf-modal-open { overflow: hidden; }

.vf-search-results {
    list-style: none; margin: 0; padding: 0 8px 12px 8px;
    overflow-y: auto;
}

.vf-result-item {
    padding: 12px 14px; margin: 4px 6px; border-radius: 10px;
    cursor: pointer; transition: background 0.15s;
}
.vf-result-item:hover, .vf-result-item.active { background: #F3F7F3; }
body.dark-theme .vf-result-item:hover, body.dark-theme .vf-result-item.active { background: #26332b; }

.vf-result-title {
    font-weight: 600; font-size: 1rem; margin-bottom: 3px;
}
.vf-result-group {
    font-size: 0.8rem; color: #4e6355; margin-bottom: 4px;
}
body.dark-theme .vf-result-group { color: #8cd7a3; }

.vf-result-snippet {
    font-size: 0.88rem; color: #666; line-height: 1.6;
}
body.dark-theme .vf-result-snippet { color: #a5b3a9; }

.vf-search-results mark,
.vf-result-title mark {
    background: #ffe08a; color: #1f0909; padding: 0 2px; border-radius: 3px;
}
body.dark-theme .vf-search-results mark,
body.dark-theme .vf-result-title mark {
    background: #8cd7a3; color: #1C2520;
}

/* هایلایت عبارت جستجو‌شده هنگام باز شدن صفحه مقصد */
.vf-page-highlight {
    background: #ffe08a; color: #1f0909;
    padding: 0 3px; border-radius: 3px;
}
body.dark-theme .vf-page-highlight {
    background: #8cd7a3; color: #1C2520;
}

/* مورد فعلاً انتخاب‌شده هنگام حرکت بین موارد هایلایت */
.vf-page-highlight-active {
    background: #ff9e2c; color: #1f0909;
    box-shadow: 0 0 0 2px #ff9e2c;
}
body.dark-theme .vf-page-highlight-active {
    background: #4e6355; color: #ffffff;
    box-shadow: 0 0 0 2px #4e6355;
}

/* نوار شناور ناوبری بین موارد هایلایت‌شده در صفحه مقاله */
.vf-page-nav {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
    z-index: 100001;
    display: flex; align-items: center; gap: 10px;
    background: rgba(255,255,255,0.95); padding: 8px 16px; border-radius: 50px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15); border: 1px solid rgba(0,0,0,0.05);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    font-size: 0.95rem; direction: ltr;
}
body.dark-theme .vf-page-nav {
    background: rgba(28, 37, 32, 0.95); border-color: rgba(255,255,255,0.05); color: #DDE5DD;
}

.vf-page-nav button {
    background: none; border: none; cursor: pointer; font-size: 1rem;
    color: inherit; opacity: 0.75; padding: 2px 6px;
}
.vf-page-nav button:hover { opacity: 1; }

.vf-nav-count { font-variant-numeric: tabular-nums; min-width: 3.5em; text-align: center; }


/* ====================================================================
   پنل «فهرست بخش‌ها»‌ی هم‌گروه (باز شونده با دکمه 📑)
   ==================================================================== */
.vf-toc-panel {
    position: fixed; inset: 0; z-index: 100000;
    background: rgba(0,0,0,0.45);
    display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
    padding: 8vh 16px 16px 16px;
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s ease;
}
.vf-toc-panel.open { opacity: 1; pointer-events: auto; }

/* محتوای innerHTML پنل (هدر + لیست) داخل یک کارت واحد قرار می‌گیرد */
.vf-toc-header, .vf-toc-list {
    width: 100%; max-width: 560px;
    background: #ffffff; color: #333333;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    box-sizing: border-box;
}
body.dark-theme .vf-toc-header, body.dark-theme .vf-toc-list {
    background: #1C2520; color: #DDE5DD;
}

.vf-toc-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 18px; border-bottom: 1px solid #e5e5e5;
    font-weight: 700; font-size: 1.05rem;
    border-radius: 16px 16px 0 0;
}
body.dark-theme .vf-toc-header { border-bottom-color: #334237; }

.vf-toc-header .vf-toc-close {
    background: none; border: none; font-size: 1.1rem; cursor: pointer;
    color: inherit; opacity: 0.6; padding: 6px;
}
.vf-toc-header .vf-toc-close:hover { opacity: 1; }

.vf-toc-list {
    border-radius: 0 0 16px 16px;
    list-style: none; margin: 0; padding: 8px; max-height: 62vh; overflow-y: auto;
}

.vf-toc-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; margin: 2px 0; border-radius: 10px;
    text-decoration: none; color: inherit;
    transition: background 0.15s;
}
.vf-toc-link:hover { background: #F3F7F3; }
body.dark-theme .vf-toc-link:hover { background: #26332b; }

.vf-toc-link.current {
    background: #eaf2ea; font-weight: 700;
}
body.dark-theme .vf-toc-link.current {
    background: #26332b; color: #8cd7a3;
}

.vf-toc-num {
    flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
    background: #dadada; color: #333;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 700;
}
.vf-toc-link.current .vf-toc-num { background: #4e6355; color: #fff; }
body.dark-theme .vf-toc-num { background: #334237; color: #DDE5DD; }
body.dark-theme .vf-toc-link.current .vf-toc-num { background: #8cd7a3; color: #1C2520; }

.vf-toc-title { font-size: 0.95rem; line-height: 1.5; }


/* ====================================================================
   کارت‌های «بخش قبلی / بخش بعدی» پایین هر مقاله
   ==================================================================== */
.vf-prevnext {
    display: flex; gap: 14px; margin-top: 50px; padding-top: 24px;
    border-top: 1px solid #e5e5e5;
}
body.dark-theme .vf-prevnext { border-top-color: #334237; }

.vf-pn-card {
    flex: 1; display: flex; flex-direction: column; gap: 6px;
    padding: 16px 18px; border-radius: 14px;
    background: #ffffff; border: 1px solid #e5e5e5;
    text-decoration: none; color: inherit;
    transition: transform 0.15s, box-shadow 0.15s;
}
.vf-pn-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,0.08); }
body.dark-theme .vf-pn-card { background: #202b25; border-color: #334237; }
body.dark-theme .vf-pn-card:hover { box-shadow: 0 8px 20px rgba(0,0,0,0.25); }

.vf-pn-next { text-align: right; align-items: flex-end; }
.vf-pn-prev { text-align: left; align-items: flex-start; }

.vf-pn-label {
    font-size: 0.8rem; color: #4e6355; font-weight: 600;
}
body.dark-theme .vf-pn-label { color: #8cd7a3; }

.vf-pn-title {
    font-size: 0.98rem; font-weight: 600; line-height: 1.5;
}

.vf-pn-empty { border: none; background: none; box-shadow: none; }

@media (max-width: 600px) {
    .vf-prevnext { flex-direction: column; }
}

/* ====================================================================
   نوار شناور آبشاری بالای صفحه‌ی مقاله (VFDeptNav)
   ==================================================================== */
.vf-top-nav {
    position: fixed; top: 0; left: 0; right: 0; z-index: 9998;
    background: rgba(255,255,255,0.95); backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(0,0,0,0.07);
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}
body.dark-theme .vf-top-nav {
    background: rgba(28,37,32,0.97);
    border-bottom-color: rgba(255,255,255,0.07);
}

.vf-top-nav-inner {
    display: flex; gap: 2px; overflow-x: auto; padding: 8px 16px;
    max-width: 1100px; margin: 0 auto;
}
.vf-top-nav-loading { font-size: .82rem; color: #8b8b8b; padding: 6px 10px; white-space: nowrap; }

.vf-top-nav-item { position: relative; flex-shrink: 0; }
.vf-top-nav-btn {
    background: none; border: none; cursor: pointer; white-space: nowrap;
    font-family: inherit; font-size: .85rem; font-weight: 700; color: #1C2520;
    padding: 6px 12px; border-radius: 8px; transition: background .15s;
}
body.dark-theme .vf-top-nav-btn { color: #DDE5DD; }
.vf-top-nav-btn:hover { background: rgba(0,0,0,0.06); }
body.dark-theme .vf-top-nav-btn:hover { background: rgba(255,255,255,0.09); }

.vf-top-nav-panel {
    position: absolute; top: 100%; right: 0; margin-top: 6px;
    background: #fff; border-radius: 10px; box-shadow: 0 10px 28px rgba(0,0,0,0.14);
    border: 1px solid rgba(0,0,0,0.07);
    min-width: 230px; max-width: 300px;
    opacity: 0; visibility: hidden; transform: translateY(-6px);
    transition: opacity .15s ease, transform .15s ease, visibility .15s;
    z-index: 20;
}
body.dark-theme .vf-top-nav-panel { background: #202b25; border-color: rgba(255,255,255,0.09); }
.vf-top-nav-item:hover > .vf-top-nav-panel,
.vf-top-nav-item.force-open > .vf-top-nav-panel { opacity: 1; visibility: visible; transform: translateY(0); pointer-events: auto; }

.vf-top-nav-panel-l2 { padding: 6px; }
.vf-top-nav-subitem { position: relative; }
.vf-top-nav-subbtn {
    display: block; width: 100%; text-align: right; background: none; border: none; cursor: pointer;
    font-family: inherit; font-size: .85rem; color: inherit; padding: 9px 10px; border-radius: 6px;
}
.vf-top-nav-subbtn:hover { background: rgba(0,0,0,0.06); }
body.dark-theme .vf-top-nav-subbtn:hover { background: rgba(255,255,255,0.09); }

.vf-top-nav-panel-l3 {
    top: 0; right: 100%; margin-top: 0; margin-right: 6px;
    display: none;
}
.vf-top-nav-panel-l3.open { display: block; opacity: 1; visibility: visible; transform: none; }

.vf-top-nav-items { max-height: 360px; overflow-y: auto; padding: 8px; }
.vf-top-nav-group-label { font-size: .78rem; font-weight: 800; color: #4e6355; padding: 9px 8px 4px; }
body.dark-theme .vf-top-nav-group-label { color: #8cd7a3; }
.vf-top-nav-link {
    display: block; padding: 7px 8px; border-radius: 6px; text-decoration: none;
    font-size: .85rem; line-height: 1.4; color: #065588;
}
.vf-top-nav-link:hover { background: rgba(0,0,0,0.06); text-decoration: underline; }
body.dark-theme .vf-top-nav-link { color: #8cd7a3; }
body.dark-theme .vf-top-nav-link:hover { background: rgba(255,255,255,0.09); }
.vf-top-nav-empty { font-size: .8rem; color: #8b8b8b; padding: 10px 8px; }

@media (max-width: 640px) {
    .vf-top-nav-inner { padding: 6px 10px; }
    .vf-top-nav-panel, .vf-top-nav-panel-l3 { min-width: 200px; max-width: 82vw; }
    .vf-top-nav-panel-l3 { position: fixed; top: auto; right: 8px; left: 8px; margin: 0; max-width: none; }
}
