/* ============================================================
   دانش‌نامهٔ لوما — تم تک‌رنگ (Monochromatic) حرفه‌ای، RTL
   ============================================================ */

@font-face {
  font-family: 'Vazirmatn';
  src: url('assets/fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('assets/fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

/* ---------- متغیرها: مقیاس خاکستری ---------- */
:root {
  --g-0:  #ffffff;
  --g-25: #fafafa;
  --g-50: #f4f4f5;
  --g-100:#e9e9eb;
  --g-200:#d4d4d8;
  --g-300:#b8b8bd;
  --g-400:#8a8a91;
  --g-500:#63636a;
  --g-600:#47474d;
  --g-700:#2f2f34;
  --g-800:#1c1c1f;
  --g-900:#0e0e10;

  --bg:        var(--g-25);
  --surface:   var(--g-0);
  --surface-2: var(--g-50);
  --text:      var(--g-900);
  --text-soft: var(--g-600);
  --muted:     var(--g-400);
  --border:    var(--g-100);
  --border-2:  var(--g-200);
  --accent:    var(--g-900);
  --accent-ink:var(--g-0);
  --ring:      rgba(14,14,16,.14);
  --shadow:    0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.18);
  --radius:    14px;
  --radius-sm: 9px;
  --maxw:      1440px;
  --tap:       0 0 0 3px var(--ring);
  /* رنگ اصلی منتخب کاربر (پیش‌فرض: خالی → مونوکروم) */
  --primary:     var(--accent);
  --primary-ink: var(--accent-ink);
  /* منحنی‌های حرکت */
  --ease:      cubic-bezier(.22,.61,.36,1);
  --ease-out:  cubic-bezier(.16,1,.3,1);
}

/* وقتی کاربر رنگ سفارشی انتخاب کند، accent به آن گره می‌خورد (هر دو تم) */
:root[data-accent="custom"] {
  --accent:     var(--primary);
  --accent-ink: var(--primary-ink);
  --ring:       color-mix(in srgb, var(--primary) 32%, transparent);
}

@media (min-width: 1700px) { :root { --maxw: 1560px; } }

[data-theme="dark"] {
  --bg:        var(--g-900);
  --surface:   var(--g-800);
  --surface-2: #161619;
  --text:      var(--g-25);
  --text-soft: var(--g-300);
  --muted:     var(--g-400);
  --border:    #29292e;
  --border-2:  #34343a;
  --accent:    var(--g-25);
  --accent-ink:var(--g-900);
  --ring:      rgba(255,255,255,.16);
  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.4);
  --shadow-lg: 0 16px 56px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: 'Vazirmatn', system-ui, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.003em;
}
.wrap { max-width: var(--maxw); margin-inline: auto; padding-inline: 24px; }

h1,h2,h3 { font-weight: 700; line-height: 1.35; margin: 0; }
a { color: inherit; }
.muted { color: var(--muted); font-weight: 400; font-size: .85em; }

/* ---------- موتور انیمیشن: ورود ترتیبی (stagger) ---------- */
.reveal { opacity: 0; }
.reveal.in {
  animation: revealUp .5s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 45ms);
  will-change: opacity, transform;
}
@keyframes revealUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}
/* تعویض نرم تم/رنگ — فقط روی سطوح کلیدی (نه *) برای جلوگیری از jank */
.site-header, .card, .recent-card, .sr-item, .chip, .btn, .prov-btn, .icon-btn,
.kb-banner, .badge, .search-box input, .sort-control select, .modal, .color-panel {
  transition-property: background-color, border-color, color, box-shadow, transform;
  transition-duration: .25s; transition-timing-function: var(--ease);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important;
      transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .reveal { opacity: 1; transform: none; }
}

/* ---------- دکمه‌ها ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: inherit; font-size: 14px; font-weight: 700;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s, color .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-solid { background: var(--accent); color: var(--accent-ink); }
.btn-solid:hover { opacity: .9; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-2); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--g-300); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; padding: 0; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border-2);
  color: var(--text); cursor: pointer; font-size: 17px;
}
.icon-btn:hover { background: var(--surface-2); }
.link-btn {
  background: none; border: none; color: var(--text-soft); cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 700; text-decoration: underline;
  text-underline-offset: 3px; padding: 4px 6px;
}
.link-btn:hover { color: var(--text); }
:focus-visible { outline: none; box-shadow: var(--tap); border-radius: 8px; }

/* ---------- هدر ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 16px; }
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 11px; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 21px;
  background: var(--accent); color: var(--accent-ink);
  font-family: 'Segoe UI', sans-serif; letter-spacing: 0;
}
.brand-text h1 { font-size: 19px; }
.brand-sub { margin: 0; font-size: 12.5px; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 9px; }
.header-actions .sep-v { width: 1px; height: 26px; background: var(--border-2); margin-inline: 2px; }
.built-at { font-size: 12px; color: var(--muted); white-space: nowrap; }
@media (max-width: 620px) { .built-at, .brand-sub { display: none; } }

.theme-icon-light { display: none; }
.theme-icon-dark { display: inline; }
[data-theme="dark"] .theme-icon-light { display: inline; }
[data-theme="dark"] .theme-icon-dark { display: none; }

/* ---------- انتخاب‌گر رنگ اصلی ---------- */
.color-wrap { position: relative; }
.color-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
  box-shadow: 0 0 0 1.5px var(--border-2);
}
.color-panel {
  position: absolute; inset-inline-end: 0; top: calc(100% + 10px); z-index: 70;
  width: 248px; padding: 16px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--border-2); box-shadow: var(--shadow-lg);
  animation: popIn .22s var(--ease-out);
}
@keyframes popIn { from { opacity: 0; transform: translateY(-6px) scale(.97); } to { opacity: 1; transform: none; } }
.color-panel h4 { font-size: 13px; margin: 0 0 12px; color: var(--text-soft); }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 9px; margin-bottom: 14px; }
.swatch {
  width: 100%; aspect-ratio: 1; border-radius: 50%; cursor: pointer; padding: 0;
  border: 2px solid transparent; box-shadow: inset 0 0 0 1px var(--border-2);
  position: relative; transition: transform .15s var(--ease);
}
.swatch:hover { transform: scale(1.12); }
.swatch[aria-pressed="true"] { border-color: var(--text); }
.swatch[aria-pressed="true"]::after {
  content: '✓'; position: absolute; inset: 0; display: grid; place-items: center;
  color: #fff; font-size: 12px; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,.5);
}
.swatch.mono { box-shadow: inset 0 0 0 1px var(--border-2); }
.color-custom { display: flex; align-items: center; gap: 10px; }
.color-custom label { font-size: 12.5px; color: var(--text-soft); flex: 1; }
.color-custom input[type="color"] {
  width: 40px; height: 30px; padding: 0; border: 1px solid var(--border-2);
  border-radius: 8px; background: var(--surface); cursor: pointer;
}

/* ---------- نوار ابزار ---------- */
.toolbar { margin-top: 30px; display: flex; flex-direction: column; gap: 16px; }
.search-box { position: relative; display: flex; align-items: center; }
.search-icon {
  position: absolute; inset-inline-start: 16px; font-size: 19px; color: var(--muted); pointer-events: none;
}
.search-box input {
  width: 100%; font-family: inherit; font-size: 15px; color: var(--text);
  padding: 14px 48px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border-2);
  transition: border-color .15s, box-shadow .15s;
}
.search-box input:focus { border-color: var(--g-400); box-shadow: var(--tap); }
.search-box input::placeholder { color: var(--muted); }
.search-clear {
  position: absolute; inset-inline-end: 14px; background: var(--surface-2);
  border: none; border-radius: 50%; width: 24px; height: 24px; cursor: pointer;
  color: var(--text-soft); font-size: 12px;
}
.toolbar-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  padding: 7px 14px; border-radius: 999px;
  background: var(--surface); color: var(--text-soft); border: 1px solid var(--border-2);
  transition: all .15s;
}
.chip:hover { border-color: var(--g-300); }
.chip[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.sort-control { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-soft); }
.sort-control select {
  font-family: inherit; font-size: 13px; font-weight: 700; color: var(--text);
  padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border-2); cursor: pointer;
}

/* ---------- بنر پرسش از کل دانش‌نامه ---------- */
.kb-banner {
  margin-top: 30px; padding: 24px 26px; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
  box-shadow: var(--shadow);
}
.kb-banner h2 { font-size: 18px; margin-bottom: 3px; }
.kb-banner p { margin: 0; font-size: 13.5px; opacity: .82; }
.kb-banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.kb-banner .prov-btn {
  background: color-mix(in srgb, var(--accent-ink) 14%, transparent);
  color: var(--accent-ink); border-color: transparent;
}
.kb-banner .prov-btn:hover { background: color-mix(in srgb, var(--accent-ink) 24%, transparent); }

/* ---------- عناوین بخش ---------- */
.section-title { font-size: 17px; margin: 42px 0 18px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.select-helpers { display: flex; gap: 4px; }

/* ---------- نوار به‌تازگی به‌روزشده ---------- */
.recent-strip {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(248px, 1fr);
  gap: 16px; overflow-x: auto; padding-bottom: 10px; scroll-snap-type: x mandatory;
}
.recent-card {
  scroll-snap-align: start; padding: 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); cursor: pointer;
}
.recent-card:hover { border-color: var(--border-2); transform: translateY(-3px); box-shadow: var(--shadow); }
.recent-card .rc-cat { font-size: 11px; color: var(--muted); font-weight: 700; }
.recent-card h3 { font-size: 14.5px; margin: 6px 0; }
.recent-card .rc-time { font-size: 12px; color: var(--text-soft); }

/* ---------- گرید اسناد ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 18px; }
.card {
  position: relative; padding: 20px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 14px;
}
.card:hover { border-color: var(--border-2); box-shadow: var(--shadow); transform: translateY(-3px); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.card-top { display: flex; align-items: flex-start; gap: 12px; }
.card-check {
  appearance: none; flex: none; width: 22px; height: 22px; margin-top: 2px;
  border: 1.5px solid var(--border-2); border-radius: 7px; cursor: pointer;
  background: var(--surface); transition: all .15s; position: relative;
}
.card-check:hover { border-color: var(--g-400); }
.card-check:checked { background: var(--accent); border-color: var(--accent); }
.card-check:checked::after {
  content: '✓'; position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--accent-ink); font-size: 13px; font-weight: 700;
}
.card-head { flex: 1; min-width: 0; }
.card-badges { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.badge {
  font-size: 10.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border);
}
.badge.ext { text-transform: uppercase; letter-spacing: .04em; }
.badge.conf { background: var(--g-800); color: var(--g-25); border-color: var(--g-700); }
[data-theme="dark"] .badge.conf { background: var(--g-100); color: var(--g-900); border-color: var(--g-200); }
.card h3 { font-size: 15.5px; line-height: 1.4; }
.card-summary { font-size: 13px; color: var(--text-soft); margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-top: auto; padding-top: 4px; }
.card-meta .dot { opacity: .5; }
.card-actions { display: flex; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.card-actions .btn { flex: 1; justify-content: center; }

/* ---------- نتایج جست‌وجو ---------- */
.search-list { display: flex; flex-direction: column; gap: 10px; }
.sr-item {
  padding: 14px 16px; border-radius: var(--radius-sm); background: var(--surface);
  border: 1px solid var(--border); cursor: pointer;
}
.sr-item:hover { border-color: var(--border-2); }
.sr-item h4 { font-size: 14.5px; margin: 0 0 4px; }
.sr-item .sr-snippet { font-size: 13px; color: var(--text-soft); }
.sr-item mark { background: var(--g-200); color: var(--text); padding: 0 2px; border-radius: 3px; }
[data-theme="dark"] .sr-item mark { background: var(--g-600); color: var(--g-25); }
.empty-state { text-align: center; color: var(--muted); padding: 40px; }

/* ---------- نوار انتخاب چسبان ---------- */
.selection-bar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 60;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(14px); border-top: 1px solid var(--border-2);
  box-shadow: 0 -8px 32px rgba(0,0,0,.1); animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.selection-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 14px; flex-wrap: wrap; }
.selection-info { font-size: 14px; display: flex; align-items: center; gap: 10px; }
.selection-info strong { font-size: 17px; }
.selection-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sel-label { font-size: 13px; color: var(--muted); font-weight: 700; }
.provider-btns { display: flex; gap: 7px; flex-wrap: wrap; }
.prov-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  padding: 8px 13px; border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); border: 1px solid var(--border-2);
  transition: all .15s;
}
.prov-btn:hover { background: var(--surface-2); border-color: var(--g-400); transform: translateY(-2px); }
.prov-btn:active { transform: translateY(0) scale(.97); }
.chip:active { transform: scale(.96); }
.icon-btn:active { transform: scale(.93); }
.prov-btn .pv-logo { width: 16px; height: 16px; flex: none; }
.sep { width: 1px; height: 24px; background: var(--border-2); margin-inline: 4px; }

/* ---------- مودال ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: rgba(8,8,10,.46); backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  padding: 24px; animation: fade .28s var(--ease);
}
.modal-overlay.closing { animation: fadeOut .2s var(--ease) forwards; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
.modal {
  width: min(1040px, 100%); max-height: 90vh; display: flex; flex-direction: column;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border-radius: var(--radius); border: 1px solid var(--border-2);
  box-shadow: var(--shadow-lg); overflow: hidden;
  animation: modalIn .34s var(--ease-out);
}
.modal-overlay.closing .modal { animation: modalOut .2s var(--ease) forwards; }
@keyframes modalIn { from { opacity: 0; transform: scale(.96) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes modalOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: scale(.97) translateY(6px); } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-title-group h3 { font-size: 17px; }
.modal-meta { font-size: 12px; color: var(--muted); }
.modal-head-actions { display: flex; align-items: center; gap: 8px; }
.modal-body { display: flex; gap: 0; overflow: hidden; flex: 1; }
.modal-toc {
  flex: none; width: 220px; border-inline-start: 1px solid var(--border);
  overflow-y: auto; padding: 18px 16px; font-size: 13px; background: var(--surface-2);
}
.modal-toc a { display: block; color: var(--text-soft); text-decoration: none; padding: 4px 8px; border-radius: 6px; margin-bottom: 2px; }
.modal-toc a:hover { background: var(--surface); color: var(--text); }
.modal-toc a.lvl-3 { padding-inline-start: 20px; font-size: 12px; }
.modal-toc:empty { display: none; }
.modal-content { flex: 1; overflow-y: auto; padding: 24px 28px; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); flex-wrap: wrap; background: var(--surface-2); }
@media (max-width: 720px) { .modal-toc { display: none; } }

/* ---------- markdown ---------- */
.markdown-body { line-height: 1.85; }
.markdown-body h1 { font-size: 24px; margin: 8px 0 16px; }
.markdown-body h2 { font-size: 20px; margin: 28px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.markdown-body h3 { font-size: 16.5px; margin: 22px 0 10px; }
.markdown-body h4 { font-size: 15px; margin: 18px 0 8px; }
.markdown-body p { margin: 0 0 14px; }
.markdown-body ul, .markdown-body ol { padding-inline-start: 24px; margin: 0 0 14px; }
.markdown-body li { margin-bottom: 6px; }
.markdown-body a { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
.markdown-body code { font-family: ui-monospace, monospace; background: var(--surface-2); padding: 2px 6px; border-radius: 5px; font-size: .9em; }
.markdown-body pre { background: var(--surface-2); padding: 14px; border-radius: var(--radius-sm); overflow-x: auto; border: 1px solid var(--border); }
.markdown-body pre code { background: none; padding: 0; }
.markdown-body blockquote { margin: 0 0 14px; padding: 4px 16px; border-inline-start: 3px solid var(--border-2); color: var(--text-soft); }
.markdown-body table { border-collapse: collapse; width: 100%; margin: 0 0 16px; font-size: 13.5px; display: block; overflow-x: auto; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border-2); padding: 8px 12px; text-align: right; }
.markdown-body th { background: var(--surface-2); font-weight: 700; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.markdown-body img { max-width: 100%; border-radius: var(--radius-sm); }

/* ---------- toast ---------- */
.toast-wrap { position: fixed; bottom: 90px; inset-inline: 0; z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--g-900); color: var(--g-25); padding: 11px 18px; border-radius: 999px;
  font-size: 13.5px; font-weight: 700; box-shadow: var(--shadow-lg); animation: toastIn .25s ease;
  max-width: 90vw;
}
[data-theme="dark"] .toast { background: var(--g-25); color: var(--g-900); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- فوتر ---------- */
.site-footer { margin-top: 56px; padding-block: 24px; border-top: 1px solid var(--border); }
.site-footer p { margin: 0; font-size: 12.5px; color: var(--muted); text-align: center; }

/* ---------- اسکرول‌بار ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--g-400); }

@media (max-width: 560px) {
  .selection-actions { width: 100%; }
  .card-actions { flex-wrap: wrap; }
}
