/* مقالات بلاگ */
.blog-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 22px; margin: 24px 0;
}
.blog-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden; text-decoration: none; color: inherit;
  display: flex; flex-direction: column;
  transition: transform var(--t) var(--ease-out), box-shadow var(--t) var(--ease);
}
.blog-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); }
.blog-card-img { height: 180px; background: var(--gradient-soft); overflow: hidden; }
.blog-card-img img { width: 100%; height: 100%; object-fit: cover; }
.blog-img-ph { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.blog-card-body { padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.blog-card-body h3 { font-size: 1.05rem; line-height: 1.6; }
.blog-card-body p { color: var(--text-soft); font-size: 0.88rem; line-height: 1.9; }
.blog-readmore { color: var(--brand); font-weight: 700; font-size: 0.85rem; margin-top: auto; }

/* صفحهٔ مقاله */
.blog-article { max-width: 820px; margin: 28px auto; }
.blog-hero-img { width: 100%; border-radius: var(--radius-lg); margin-bottom: 22px; box-shadow: var(--shadow); }
.blog-article h1 { font-size: 1.7rem; font-weight: 800; line-height: 1.6; margin-bottom: 10px; }
.blog-meta { color: var(--text-muted); font-size: 0.82rem; margin-bottom: 24px; }
.blog-body { color: var(--text-soft); line-height: 2.2; font-size: 1rem; }
.blog-body p { margin-bottom: 16px; }
/* ============================================================
   بازطراحی صفحهٔ مقاله — الهام از سایت‌های مجله‌ای (دیجیاتو و مشابه)
   ============================================================ */

.blog-breadcrumb {
  margin: 18px auto 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
}
.blog-breadcrumb a { color: var(--text-muted); text-decoration: none; }
.blog-breadcrumb a:hover { color: var(--brand); }

/* هیرو تمام‌عرض با عنوان روی عکس */
.blog-hero {
  position: relative;
  width: 100%;
  height: 420px;
  margin-top: 14px;
  overflow: hidden;
}
.blog-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.blog-hero-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  background: linear-gradient(180deg, rgba(0,0,0,0) 40%, rgba(0,0,0,0.75) 100%);
}
.blog-hero-inner { padding-bottom: 32px; }
.blog-hero-inner h1 {
  color: #fff;
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.6;
  max-width: 820px;
  text-shadow: 0 2px 12px rgba(0,0,0,0.4);
}
.blog-title-plain {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.6;
  margin: 28px 0 0;
  max-width: 820px;
  margin-inline: auto;
}

/* خط اطلاعات نویسنده/تاریخ/زمان مطالعه + اشتراک‌گذاری */
.blog-byline {
  max-width: 820px;
  margin: 22px auto 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.blog-byline-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--gradient-brand);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  flex-shrink: 0;
}
.blog-byline-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.blog-byline-meta {
  display: flex; gap: 6px; align-items: center;
  font-size: 0.8rem; color: var(--text-muted);
}
.blog-byline-meta .dot { opacity: 0.5; }

.blog-share { display: flex; gap: 8px; }
.share-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-soft);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.share-btn:hover { background: var(--gradient-brand); color: #fff; border-color: transparent; }

/* تایپوگرافی بدنهٔ مقاله (خروجی CKEditor) */
.blog-body {
  max-width: 820px;
  margin: 28px auto 0;
  color: var(--text-soft);
  line-height: 2.2;
  font-size: 1.02rem;
}
.blog-body > *:first-child { margin-top: 0; }
.blog-body p { margin-bottom: 18px; }
.blog-body h2 {
  font-size: 1.35rem; font-weight: 800; color: var(--text);
  margin: 36px 0 16px;
  padding-right: 12px;
  border-right: 4px solid var(--brand);
}
.blog-body h3 {
  font-size: 1.15rem; font-weight: 700; color: var(--text);
  margin: 28px 0 14px;
}
.blog-body ul, .blog-body ol {
  margin: 0 0 18px 0;
  padding-right: 22px;
  display: flex; flex-direction: column; gap: 8px;
}
.blog-body a { color: var(--brand); text-decoration: underline; }
.blog-body img {
  border-radius: var(--radius-lg);
  margin: 20px 0;
  box-shadow: var(--shadow);
}
.blog-body blockquote {
  margin: 24px 0;
  padding: 16px 20px;
  background: var(--bg-soft);
  border-right: 4px solid var(--brand);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 600;
}
.blog-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
}
.blog-body table td, .blog-body table th {
  border: 1px solid var(--border);
  padding: 10px 12px;
  font-size: 0.9rem;
}

.blog-others-title { max-width: 820px; margin: 48px auto 0 !important; }
.blog-article .blog-grid { max-width: 820px; margin-inline: auto; }

@media (max-width: 768px) {
  .blog-hero { height: 260px; }
  .blog-hero-inner h1, .blog-title-plain { font-size: 1.35rem; }
  .blog-byline { flex-wrap: wrap; }
}

/* عکس اول مقاله و عنوان زیر آن */
.blog-hero {
  width: calc(100% - 32px);
  max-width: 820px;
  height: auto;
  margin: 24px auto 0;
  overflow: hidden;
}

.blog-hero > img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: var(--radius-lg);
}

.blog-hero-overlay {
  position: static;
  display: block;
  background: none;
}

.blog-hero-inner {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 20px 0 0;
}

.blog-hero-inner h1 {
  color: var(--text);
  font-size: 1.7rem;
  line-height: 1.7;
  text-shadow: none;
  text-align: right;
  margin: 0;
}

/* وسط‌چین شدن تصاویر داخل مقاله */
.blog-body img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 20px auto;
}

/* تصاویر دارای قاب در ویرایشگر */
.blog-body figure.image {
  float: none !important;
  max-width: 100%;
  margin: 20px auto !important;
}

.blog-body figure.image img {
  margin: 0 auto;
}

.blog-body figure.image figcaption {
  text-align: center !important;
}

@media (max-width: 768px) {
  .blog-hero {
    height: auto;
  }

  .blog-hero-inner h1 {
    font-size: 1.35rem;
  }
}

/* ============================================================
   بهینه‌سازی نهایی نمایش مقاله در موبایل
   فقط برای صفحه‌های تا 768px؛ دسکتاپ بدون تغییر می‌ماند
   ============================================================ */
@media (max-width: 768px) {
  .blog-article {
    width: 100%;
    max-width: 100%;
    margin: 16px auto 28px;
    padding-inline: 16px;
    box-sizing: border-box;
  }

  .blog-breadcrumb {
    margin-top: 12px;
    padding-inline: 2px;
    font-size: 0.78rem;
    gap: 6px;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
  }

  .blog-breadcrumb::-webkit-scrollbar { display: none; }

  .blog-hero {
    width: 100%;
    max-width: 100%;
    margin: 14px auto 0;
    border-radius: 14px;
  }

  .blog-hero > img {
    width: 100%;
    max-width: 100%;
    height: auto;
    object-fit: contain;
    border-radius: 14px;
  }

  .blog-hero-inner { padding-top: 14px; }

  .blog-hero-inner h1,
  .blog-title-plain {
    font-size: 1.32rem;
    line-height: 1.75;
    margin: 0;
    overflow-wrap: anywhere;
  }

  .blog-byline {
    width: 100%;
    max-width: 100%;
    margin-top: 14px;
    padding-bottom: 14px;
    gap: 10px;
    flex-wrap: wrap;
  }

  .blog-byline-avatar {
    width: 38px;
    height: 38px;
  }

  .blog-byline-info { min-width: 0; }

  .blog-byline-meta {
    flex-wrap: wrap;
    row-gap: 3px;
    font-size: 0.76rem;
  }

  .blog-share {
    width: 100%;
    justify-content: flex-start;
    margin-top: 4px;
  }

  .share-btn {
    width: 34px;
    height: 34px;
  }

  .blog-body {
    width: 100%;
    max-width: 100%;
    margin-top: 20px;
    font-size: 0.98rem;
    line-height: 2;
    overflow-wrap: break-word;
    word-break: normal;
  }

  .blog-body p { margin-bottom: 14px; }

  .blog-body h2 {
    font-size: 1.18rem;
    line-height: 1.75;
    margin: 28px 0 12px;
    padding-right: 10px;
    border-right-width: 3px;
  }

  .blog-body h3 {
    font-size: 1.06rem;
    line-height: 1.75;
    margin: 22px 0 10px;
  }

  .blog-body ul,
  .blog-body ol {
    padding-right: 20px;
    gap: 6px;
    margin-bottom: 14px;
  }

  .blog-body li { line-height: 1.95; }

  .blog-body img,
  .blog-body figure.image img {
    width: 100%;
    max-width: 100%;
    height: auto;
    border-radius: 12px;
  }

  .blog-body figure.image {
    width: 100% !important;
    max-width: 100% !important;
    margin: 16px auto !important;
  }

  .blog-body figure.image figcaption {
    font-size: 0.78rem;
    line-height: 1.7;
    padding-top: 6px;
  }

  .blog-body blockquote {
    margin: 18px 0;
    padding: 13px 14px;
    line-height: 1.9;
    font-size: 0.94rem;
  }

  .blog-body table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    margin: 16px 0;
  }

  .blog-body table td,
  .blog-body table th {
    min-width: 120px;
    padding: 9px 10px;
    font-size: 0.82rem;
    line-height: 1.7;
  }

  .blog-body a { overflow-wrap: anywhere; }

  .blog-others-title {
    margin-top: 34px !important;
    font-size: 1.2rem;
  }

  .blog-article .blog-grid {
    grid-template-columns: 1fr;
    gap: 16px;
    margin-top: 18px;
  }

  .blog-card-img { height: 200px; }
  .blog-card-body { padding: 15px; }
}

@media (max-width: 420px) {
  .blog-article { padding-inline: 12px; }

  .blog-hero-inner h1,
  .blog-title-plain { font-size: 1.22rem; }

  .blog-body {
    font-size: 0.96rem;
    line-height: 1.95;
  }

  .blog-body h2 { font-size: 1.12rem; }
  .blog-body h3 { font-size: 1.02rem; }
}

/* ===== Mobile Blog Final Fix ===== */
@media (max-width: 768px) {

  .blog-breadcrumb.container,
  .blog-article.container,
  .blog-hero-inner.container {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding-left: 18px !important;
    padding-right: 18px !important;
  }

  .blog-breadcrumb {
    margin-top: 12px !important;
    overflow: hidden;
  }

  .blog-breadcrumb span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .blog-article {
    margin: 14px auto 30px !important;
  }

  /* عکس اصلی مقاله */
  .blog-hero {
    width: calc(100% - 24px) !important;
    max-width: none !important;
    height: auto !important;
    margin: 14px 12px 0 !important;
    border-radius: 14px !important;
  }

  .blog-hero > img {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    object-fit: contain !important;
    margin: 0 !important;
    border-radius: 14px !important;
  }

  .blog-hero-inner {
    padding-top: 14px !important;
  }

  .blog-hero-inner h1,
  .blog-title-plain {
    font-size: 21px !important;
    line-height: 1.8 !important;
    margin: 0 !important;
  }

  /* اطلاعات مقاله */
  .blog-byline {
    width: 100% !important;
    margin: 14px 0 0 !important;
    padding: 0 0 14px !important;
    gap: 9px !important;
  }

  .blog-byline-avatar {
    display: none !important;
  }

  .blog-byline-info {
    min-width: 0 !important;
  }

  .blog-byline-meta {
    flex-wrap: wrap !important;
    font-size: 12px !important;
  }

  .blog-share {
    margin-right: auto !important;
    gap: 6px !important;
  }

  .share-btn {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
  }

  /* متن مقاله */
  .blog-body {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    margin: 20px 0 0 !important;
    padding: 0 !important;

    font-size: 16px !important;
    line-height: 2.05 !important;
  }

  .blog-body p {
    margin: 0 0 16px !important;
  }

  .blog-body h2 {
    font-size: 20px !important;
    line-height: 1.8 !important;
    margin: 28px 0 14px !important;
  }

  .blog-body h3 {
    font-size: 18px !important;
    line-height: 1.8 !important;
    margin: 22px 0 12px !important;
  }

  /* همه عکس‌های داخل مقاله */
  .blog-body img,
  .blog-body figure img,
  .blog-body figure.image img,
  .blog-body figure.image_resized img {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    margin: 0 auto !important;
  }

  .blog-body figure,
  .blog-body figure.image,
  .blog-body figure.image_resized {
    float: none !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 18px 0 !important;
  }

  .blog-body figure figcaption {
    padding: 7px 4px 0 !important;
    font-size: 12px !important;
    line-height: 1.7 !important;
  }

  /* جدول‌ها */
  .blog-body table {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  .blog-body table td,
  .blog-body table th {
    padding: 9px 10px !important;
    font-size: 13px !important;
  }

  .blog-body blockquote {
    margin: 18px 0 !important;
    padding: 14px !important;
  }
}

/* ===== Fix CKEditor image tables on mobile ===== */
@media (max-width: 768px) {

  /* فاصله بیشتر متن از لبه‌های موبایل */
  .blog-article.container {
    padding-left: 24px !important;
    padding-right: 24px !important;
  }

  .blog-body {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  /* جدولی که برای چیدن عکس توسط CKEditor ساخته شده */
  .blog-body table:has(img) {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    border: 0 !important;
    overflow: visible !important;
    white-space: normal !important;
    margin: 20px 0 !important;
  }

  .blog-body table:has(img) tbody,
  .blog-body table:has(img) tr:has(img),
  .blog-body table:has(img) td:has(img) {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .blog-body table:has(img) td:has(img) {
    border: 0 !important;
    padding: 0 !important;
  }

  /* حذف ردیف‌های خالی بالای عکس */
  .blog-body table:has(img) tr:not(:has(img)) {
    display: none !important;
  }

  /* خود عکس تمام عرض فضای مقاله */
  .blog-body table:has(img) img {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    margin: 0 auto !important;
    border-radius: 14px !important;
  }

  /* متن کمی جمع‌وجورتر و خواناتر */
  .blog-body p {
    font-size: 16px !important;
    line-height: 2 !important;
    text-align: right !important;
  }
}

.blog-body,
.blog-body :is(p, h1, h2, h3, h4, h5, h6,
              ul, ol, li, blockquote, table, td, th) {
  direction: rtl !important;
  text-align: right !important;
}

.blog-body :is(ul, ol) {
  padding-inline-start: 22px;
  padding-inline-end: 0;
}

.blog-body :is(pre, [lang="en"]) {
  direction: ltr !important;
  text-align: left !important;
 } 