/* ============================================================
   DEVOBIN — Rich content styles (CKEditor 5 output)
   ------------------------------------------------------------
   محتوای بلند مقاله/پروژه/درس/دوره از CKEditor 5 می‌آید و مارک‌آپ
   مشخصی تولید می‌کند: figure.image، figure.table، pre>code.language-*،
   ul.todo-list، span.text-*، mark.marker-*، div[data-oembed-url] و … .
   این فایل همان کلاس‌ها را استایل می‌دهد تا خروجی ادیتور در سایت
   دقیقاً همان‌طور که نویسنده دیده رندر شود.

   ریشه‌ها: .rich-html (تزریق مستقیم HTML) و .ck-content (کلاسی که خود
   CKEditor روی محتوا می‌گذارد) — هر دو پشتیبانی می‌شوند.
   ============================================================ */

.rich-html,
.prose-body .ck-content {
  color: #44403c;
  font-size: 0.98rem;
  line-height: 2.05;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* ---------- تیترها ---------- */

.rich-html h1,
.rich-html h2,
.rich-html h3,
.rich-html h4,
.rich-html h5,
.rich-html h6 {
  color: var(--color-foreground, #1c1917);
  font-weight: 800;
  scroll-margin-top: 100px;
  line-height: 1.5;
}
.rich-html h1 { font-size: 1.7rem; margin-block: 2.5rem 1rem; }
.rich-html h2 { font-size: 1.45rem; margin-block: 2.5rem 1rem; }
.rich-html h3 { font-size: 1.18rem; font-weight: 700; margin-block: 2rem 0.75rem; }
.rich-html h4 { font-size: 1.02rem; font-weight: 700; margin-block: 1.6rem 0.5rem; }
.rich-html h5,
.rich-html h6 { font-size: 0.95rem; font-weight: 700; margin-block: 1.4rem 0.4rem; }

/* ---------- پاراگراف و لینک ---------- */

.rich-html p { margin-block: 1rem; }
.rich-html p:first-child { margin-block-start: 0; }
.rich-html p:last-child { margin-block-end: 0; }

.rich-html a {
  color: var(--color-accent, #f59e0b);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
}
.rich-html a:hover { color: #854d0e; }

.rich-html strong, .rich-html b { font-weight: 700; color: var(--color-foreground, #1c1917); }
.rich-html em, .rich-html i { font-style: italic; }
.rich-html u { text-underline-offset: 3px; }
.rich-html s { opacity: 0.7; }
.rich-html sub, .rich-html sup { font-size: 0.72em; }

/* ---------- فهرست‌ها ---------- */

.rich-html ul,
.rich-html ol {
  margin-block: 1rem;
  padding-inline-start: 1.6rem;
}
.rich-html ul { list-style: disc; }
.rich-html ol { list-style: decimal; }
.rich-html ul ul { list-style: circle; }
.rich-html ul ul ul { list-style: square; }
.rich-html li { margin-block: 0.4rem; }
.rich-html li::marker { color: var(--color-accent, #f59e0b); }
.rich-html li > p { margin-block: 0.3rem; }

/* چک‌لیست CKEditor 5 — ul.todo-list با label و checkbox */
.rich-html ul.todo-list {
  list-style: none;
  padding-inline-start: 0.25rem;
}
.rich-html ul.todo-list li { margin-block: 0.5rem; }
.rich-html ul.todo-list li::marker { content: ''; }
.rich-html .todo-list__label {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
}
.rich-html .todo-list__label > input[type="checkbox"] {
  margin-block-start: 0.5rem;
  width: 1rem;
  height: 1rem;
  accent-color: var(--color-accent, #f59e0b);
  flex: none;
  pointer-events: none;
}
/* CKEditor نسخه‌های جدید چک‌باکس را با span می‌سازد */
.rich-html .todo-list__label > span[contenteditable="false"] {
  flex: none;
  margin-block-start: 0.45rem;
}
.rich-html .todo-list__label__description { flex: 1; }
.rich-html ul.todo-list li:has(input:checked) .todo-list__label__description {
  opacity: 0.6;
  text-decoration: line-through;
}

/* ---------- نقل قول ---------- */

.rich-html blockquote {
  border-inline-start: 3px solid var(--color-accent, #f59e0b);
  background: var(--color-accent-tint, #fef3c7);
  padding: 1rem 1.25rem;
  border-start-end-radius: 0.75rem;
  border-end-end-radius: 0.75rem;
  color: #713f12;
  font-weight: 600;
  margin-block: 1.5rem;
  margin-inline: 0;
}
.rich-html blockquote p { margin: 0; }
.rich-html blockquote p + p { margin-block-start: 0.6rem; }

/* ---------- کد ---------- */

/* کد درون‌خطی — همیشه LTR حتی داخل متن فارسی */
.rich-html code:not(pre code) {
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: 0.82em;
  background: var(--color-muted, #f5f5f4);
  border: 1px solid var(--color-border-soft, #e7e5e4);
  padding: 0.1rem 0.4rem;
  border-radius: 0.4rem;
  direction: ltr;
  unicode-bidi: isolate;
  white-space: nowrap;
}

/* بلوک کد CKEditor 5: <pre><code class="language-python"> */
.rich-html pre {
  background: #171412;
  color: #e7e5e4;
  border-radius: 0.9rem;
  padding: 1.15rem 1.25rem;
  margin-block: 1.5rem;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
  position: relative;
  border: 1px solid #292524;
}
.rich-html pre code {
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: 0.83rem;
  line-height: 1.85;
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  white-space: pre;
  display: block;
  direction: ltr;
}

/* برچسب زبان — data-language را behaviors.js از کلاس language-* می‌خواند
   و روی <pre> می‌گذارد (attr() در content فقط با صفت خود عنصر کار می‌کند) */
.rich-html pre[data-language]::before {
  content: attr(data-language);
  position: absolute;
  inset-block-start: 0.55rem;
  inset-inline-start: 0.85rem;
  font-family: var(--font-mono, monospace);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #a8a29e;
  pointer-events: none;
}
.rich-html pre[data-language] { padding-block-start: 1.95rem; }

/* دکمه کپی که behaviors.js به بلوک کد اضافه می‌کند */
.rich-html .rich-copy {
  position: absolute;
  inset-block-start: 0.5rem;
  inset-inline-end: 0.5rem;
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border-radius: 0.5rem;
  border: 1px solid #3f3f46;
  background: rgba(255, 255, 255, 0.06);
  color: #d6d3d1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.rich-html .rich-copy:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.rich-html .rich-copy svg { width: 0.95rem; height: 0.95rem; }

/* جدول بدون figure که behaviors.js برای اسکرول افقی می‌پیچد */
.rich-html .rich-table-scroll {
  overflow-x: auto;
  margin-block: 1.75rem;
  -webkit-overflow-scrolling: touch;
}

/* ---------- تصویر ---------- */

/* CKEditor 5: <figure class="image"><img><figcaption> */
.rich-html figure {
  margin-block: 1.75rem;
  margin-inline: 0;
}
.rich-html figure.image { display: table; }
.rich-html img {
  max-width: 100%;
  height: auto;
  border-radius: 1rem;
  display: block;
}
.rich-html figure.image img { margin: 0; }
.rich-html figcaption {
  display: table-caption;
  caption-side: bottom;
  font-size: 0.82rem;
  color: var(--color-muted-foreground, #78716c);
  padding-block-start: 0.6rem;
  text-align: center;
  line-height: 1.8;
}

/* سبک‌های تصویر: تراز و اندازه */
.rich-html figure.image.image-style-block-align-left,
.rich-html figure.image.image-style-align-left {
  margin-inline: 0 auto;
  float: none;
}
.rich-html figure.image.image-style-block-align-right,
.rich-html figure.image.image-style-align-right {
  margin-inline: auto 0;
  float: none;
}
.rich-html figure.image.image-style-block-align-center,
.rich-html figure.image.image-style-align-center {
  margin-inline: auto;
}
/* تصویر شناور کنار متن — در RTL جهت‌ها معکوس می‌شوند */
.rich-html figure.image.image-style-side,
.rich-html figure.image.image_resized.image-style-side {
  float: inline-end;
  max-width: 50%;
  margin-inline-start: 1.5rem;
  margin-block-start: 0.5rem;
}
.rich-html figure.image.image-style-align-inline-start { float: inline-start; margin-inline-end: 1.5rem; }
.rich-html figure.image.image-style-align-inline-end { float: inline-end; margin-inline-start: 1.5rem; }

/* تصویر ریسایزشده — CKEditor عرض را در style می‌گذارد */
.rich-html figure.image.image_resized { max-width: 100%; }
.rich-html figure.image.image_resized img { width: 100%; }

/* تصویر درون‌خطی */
.rich-html span.image-inline,
.rich-html .image-inline img { display: inline-block; vertical-align: baseline; }

/* ---------- جدول ---------- */

/* CKEditor 5: <figure class="table"><table><tbody>... */
.rich-html figure.table {
  display: block;
  overflow-x: auto;
  margin-block: 1.75rem;
  -webkit-overflow-scrolling: touch;
}
.rich-html table {
  width: 100%;
  min-width: 32rem;
  border-collapse: collapse;
  font-size: 0.88rem;
  line-height: 1.85;
  background: var(--color-card, #fff);
  border: 1px solid var(--color-border-soft, #e7e5e4);
  border-radius: 0.9rem;
  overflow: hidden;
}
.rich-html table td,
.rich-html table th {
  border: 1px solid var(--color-border-soft, #e7e5e4);
  padding: 0.65rem 0.9rem;
  text-align: start;
  vertical-align: top;
  overflow-wrap: anywhere;
}
.rich-html table th {
  background: var(--color-muted, #f5f5f4);
  font-weight: 700;
  color: var(--color-foreground, #1c1917);
  white-space: nowrap;
}
.rich-html table tbody tr:nth-child(even) { background: rgba(0, 0, 0, 0.015); }
.rich-html table p { margin: 0; }
/* عنوان جدول (toggleTableCaption) */
.rich-html figure.table figcaption {
  display: block;
  caption-side: top;
  text-align: start;
  font-weight: 600;
  color: var(--color-foreground, #1c1917);
  font-size: 0.85rem;
  padding-block: 0 0.6rem;
}
/* رنگ/حاشیه سلول که TableCellProperties با style می‌گذارد باید حفظ شود */
.rich-html table td[style], .rich-html table th[style] { background-clip: padding-box; }

/* ---------- خط جداکننده ---------- */

.rich-html hr {
  border: none;
  border-top: 1px solid var(--color-border-soft, #e7e5e4);
  margin-block: 2.5rem;
}
/* HorizontalLine در CKEditor یک div است */
.rich-html div.page-break {
  border-top: 1px dashed var(--color-border, #d6d3d1);
  margin-block: 2.5rem;
  page-break-after: always;
}
.rich-html div.page-break__label { display: none; }

/* ---------- امبد رسانه ---------- */

/* previewsInData=true → <figure class="media"><div data-oembed-url><iframe> */
.rich-html figure.media,
.rich-html div[data-oembed-url] {
  margin-block: 1.75rem;
}
.rich-html figure.media iframe,
.rich-html div[data-oembed-url] iframe {
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  border: 1px solid var(--color-border-soft, #e7e5e4);
  border-radius: 1rem;
  display: block;
  background: var(--color-primary, #1c1917);
}
/* اگر امبد بدون پیش‌نمایش ذخیره شده باشد (تگ oembed) لینک نشان می‌دهیم */
.rich-html oembed { display: block; }
.rich-html oembed::after {
  content: attr(url);
  display: block;
  direction: ltr;
  font-family: var(--font-mono, monospace);
  font-size: 0.78rem;
  color: var(--color-accent, #f59e0b);
  background: var(--color-muted, #f5f5f4);
  border: 1px dashed var(--color-border, #d6d3d1);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  word-break: break-all;
}
.rich-html video {
  width: 100%;
  border-radius: 1rem;
  background: #000;
  display: block;
  margin-block: 1.75rem;
}

/* ---------- تراز متن ---------- */

.rich-html .text-start, .rich-html [style*="text-align:start"] { text-align: start; }
.rich-html .text-center { text-align: center; }
.rich-html .text-end { text-align: end; }
.rich-html .text-justify { text-align: justify; }

/* ---------- هایلایت و رنگ ---------- */

.rich-html mark {
  border-radius: 0.25rem;
  padding: 0.05em 0.2em;
  color: inherit;
}
.rich-html mark.marker-yellow { background: #fdfd77; }
.rich-html mark.marker-green { background: #8ff2a6; }
.rich-html mark.marker-pink { background: #ffa8d8; }
.rich-html mark.marker-blue { background: #94ddff; }
.rich-html mark.pen-red { background: transparent; color: #e91313; }
.rich-html mark.pen-green { background: transparent; color: #128a00; }

/* اندازه فونت CKEditor */
.rich-html .text-tiny { font-size: 0.7em; }
.rich-html .text-small { font-size: 0.85em; }
.rich-html .text-big { font-size: 1.2em; }
.rich-html .text-huge { font-size: 1.5em; }

/* ---------- فهرست تعریف ---------- */

.rich-html dl { margin-block: 1.25rem; }
.rich-html dt { font-weight: 700; color: var(--color-foreground, #1c1917); }
.rich-html dd { margin-inline-start: 1.25rem; margin-block-end: 0.75rem; }

/* ---------- پاک‌سازی float ---------- */

.rich-html::after {
  content: '';
  display: block;
  clear: both;
}

/* ---------- موبایل ---------- */

@media (max-width: 640px) {
  .rich-html { font-size: 0.94rem; line-height: 1.95; }
  .rich-html h1 { font-size: 1.4rem; }
  .rich-html h2 { font-size: 1.25rem; }
  .rich-html h3 { font-size: 1.08rem; }
  /* تصویر شناور در موبایل تمام‌عرض می‌شود تا متن خرد نشود */
  .rich-html figure.image.image-style-side,
  .rich-html figure.image.image-style-align-inline-start,
  .rich-html figure.image.image-style-align-inline-end {
    float: none;
    max-width: 100%;
    margin-inline: 0;
  }
  .rich-html figure.image.image_resized { width: 100% !important; }
  .rich-html pre { padding: 0.9rem 1rem; border-radius: 0.75rem; }
  .rich-html pre code { font-size: 0.76rem; }
  .rich-html table { font-size: 0.82rem; min-width: 26rem; }
  .rich-html table td, .rich-html table th { padding: 0.5rem 0.6rem; }
}

/* ---------- چاپ ---------- */

@media print {
  .rich-html pre { background: #f5f5f4; color: #1c1917; border-color: #d6d3d1; }
  .rich-html figure.media, .rich-html div[data-oembed-url] { display: none; }
  .rich-html a { text-decoration: none; }
  .rich-html a::after { content: ' (' attr(href) ')'; font-size: 0.75em; color: #78716c; }
}
