/* ==========================================================================
   Article Render Stylesheet
   HooshAmoozan Block Editor Frontend Rendering
   Inspired by dicode.ir/mag - Clean, Minimal, RTL
   ========================================================================== */

/* Article Content Wrapper */
.article-content {
  max-width: 100%;
  font-size: 1.05rem;
  line-height: 2;
  color: var(--text-primary);
}

/* Backward compatibility for raw HTML legacy articles */
.article-content.legacy {
  line-height: 2;
}
.article-content.legacy h1,
.article-content.legacy h2,
.article-content.legacy h3,
.article-content.legacy h4,
.article-content.legacy h5,
.article-content.legacy h6 {
  font-weight: 800;
  margin: 32px 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  line-height: 1.5;
  color: var(--text-primary);
}
.article-content.legacy h4,
.article-content.legacy h5,
.article-content.legacy h6 {
  border-bottom: none;
}
.article-content.legacy p {
  margin: 0 0 16px;
  line-height: 2;
}
.article-content.legacy a {
  color: var(--accent-text);
  font-weight: 600;
  border-bottom: none;
  text-decoration: none;
  transition: color var(--duration) var(--ease);
}
.article-content.legacy a:hover {
  color: var(--accent-hover);
  font-weight: 700;
  text-decoration: none;
}
.article-content.legacy img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-lg);
  margin: 24px 0;
  background: var(--bg-elevated);
}
.article-content.legacy blockquote {
  margin: 24px 0;
  padding: 16px 20px;
  border-right: 3px solid var(--accent);
  background: var(--accent-muted);
  border-radius: var(--radius-md);
  font-style: italic;
  line-height: 1.8;
}
.article-content.legacy ul,
.article-content.legacy ol {
  margin: 16px 0;
  padding-right: 24px;
}
.article-content.legacy li {
  margin-bottom: 8px;
  line-height: 1.8;
}
.article-content.legacy pre {
  margin: 20px 0;
  padding: 16px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  direction: ltr;
  text-align: left;
}
.article-content.legacy code {
  font-family: 'Fira Code', monospace;
  font-size: 0.88rem;
}

/* Heading blocks */
.block-heading {
  font-weight: 800;
  margin: 32px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  line-height: 1.5;
  color: var(--text-primary);
}
h2.block-heading {
  font-size: 1.5rem;
}
h3.block-heading {
  font-size: 1.25rem;
}
h4.block-heading {
  font-size: 1.1rem;
  border-bottom: none;
}
.block-heading a {
  color: var(--accent-text);
  text-decoration: none;
}
.block-heading a:hover {
  color: var(--accent-hover);
  text-decoration: none;
}

/* Paragraph */
.block-paragraph {
  margin: 0 0 16px;
  line-height: 2;
  color: var(--text-primary);
}
.block-paragraph a {
  color: var(--accent-text);
  font-weight: 600;
  border-bottom: none;
  text-decoration: none;
  transition: color var(--duration) var(--ease);
}
.block-paragraph a:hover {
  color: var(--accent-hover);
  font-weight: 700;
  text-decoration: none;
}
.block-paragraph b,
.block-paragraph strong {
  font-weight: 700;
}

/* Image block */
.block-image {
  margin: 24px 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-elevated);
}
.block-image img {
  width: 100%;
  height: auto;
  display: block;
}
.block-image figcaption {
  padding: 10px 14px;
  font-size: 0.82rem;
  color: var(--text-tertiary);
  text-align: center;
}

/* Code block */
.block-code {
  margin: 24px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-surface);
}
.block-code .code-header {
  padding: 8px 14px;
  background: var(--bg-elevated);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border);
  font-family: monospace;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.block-code .copy-code-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-tertiary);
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  font-size: 0.74rem;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}
.block-code .copy-code-btn:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--accent);
}
.block-code .copy-code-btn.copied {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  border-color: rgba(34, 197, 94, 0.3);
}
.block-code pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  background: var(--bg-surface);
}
.block-code code {
  font-family: 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.88rem;
  line-height: 1.7;
  direction: ltr;
  text-align: left;
  display: block;
}

.inline-code {
  font-family: 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.85em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--accent-text);
  border: 1px solid var(--border);
  direction: ltr;
  display: inline-block;
}

/* Quote */
.block-quote {
  margin: 24px 0;
  padding: 16px 20px;
  border-right: 4px solid var(--accent);
  background: var(--accent-muted);
  border-radius: var(--radius-md);
}
.block-quote p {
  margin: 0;
  font-style: italic;
  line-height: 1.8;
  color: var(--text-primary);
}
.block-quote cite {
  display: block;
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--text-tertiary);
  font-style: normal;
}

/* List */
.block-list {
  margin: 18px 0;
  padding-right: 24px;
}
.block-list li {
  margin-bottom: 10px;
  line-height: 1.85;
  color: var(--text-primary);
}
ol.block-list {
  list-style: decimal;
}
ul.block-list {
  list-style: disc;
}

/* Callout */
.block-callout {
  margin: 24px 0;
  padding: 16px 20px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: flex-start;
  gap: 14px;
  border-right: 4px solid transparent;
}
.callout-icon {
  flex-shrink: 0;
  margin-top: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.callout-icon svg {
  width: 20px;
  height: 20px;
}
.callout-content {
  flex: 1;
  line-height: 1.85;
  font-size: 0.95rem;
  color: var(--text-primary);
}
.callout-info {
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-right: 4px solid #3b82f6;
  color: var(--accent-text);
}
.callout-warning {
  background: rgba(234, 179, 8, 0.08);
  border: 1px solid rgba(234, 179, 8, 0.25);
  border-right: 4px solid #eab308;
  color: #facc15;
}
.callout-tip {
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.25);
  border-right: 4px solid #22c55e;
  color: #4ade80;
}
.callout-danger {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-right: 4px solid #ef4444;
  color: #f87171;
}
[data-theme='light'] .callout-warning {
  color: #ca8a04;
}
[data-theme='light'] .callout-tip {
  color: #16a34a;
}
[data-theme='light'] .callout-danger {
  color: #dc2626;
}

/* Button block */
.block-button {
  margin: 24px 0;
}
.block-button .btn {
  padding: 12px 24px;
  font-size: 0.95rem;
}

/* Divider */
.block-divider {
  margin: 32px 0;
  border: none;
  border-top: 1px solid var(--border);
}

/* Embed */
.block-embed {
  margin: 24px 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  width: 100%;
}
.block-embed iframe,
.block-embed video {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: none;
  display: block;
}

/* Table */
.block-table {
  margin: 20px 0;
  overflow-x: auto;
}
.block-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.block-table th,
.block-table td {
  padding: 10px 14px;
  text-align: right;
  border: 1px solid var(--border);
}
.block-table th {
  background: var(--bg-elevated);
  font-weight: 700;
  font-size: 0.85rem;
}
.block-table td {
  background: var(--bg-surface);
}

/* FAQ */
.block-faq {
  margin: 20px 0;
}
.faq-item {
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.faq-item summary {
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.95rem;
  background: var(--bg-surface);
  transition: background var(--duration) var(--ease);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.faq-item summary::-webkit-details-marker {
  display: none;
}
.faq-item summary:hover {
  background: var(--bg-surface-hover);
}
.faq-item summary::after {
  content: '+';
  font-size: 1.2rem;
  color: var(--text-tertiary);
  transition: transform var(--duration) var(--ease);
}
.faq-item[open] summary::after {
  content: '−';
}
.faq-item p {
  padding: 14px 16px;
  margin: 0;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  line-height: 1.8;
  border-top: 1px solid var(--border);
}

/* Article Responsive Rules */
@media (max-width: 768px) {
  .article-content {
    font-size: 0.95rem;
    line-height: 1.85;
  }
  h2.block-heading {
    font-size: 1.25rem;
    margin: 24px 0 10px;
  }
  h3.block-heading {
    font-size: 1.1rem;
    margin: 20px 0 8px;
  }
  .block-file-download {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .block-file-download .btn {
    width: 100%;
  }
  .block-callout {
    padding: 14px;
    font-size: 0.88rem;
  }
  .block-table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .block-table table {
    min-width: 480px;
  }
}

/* ==========================================================================
   Table of Contents (فهرست مطالب)
   ========================================================================== */
.article-toc-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  margin-bottom: 28px;
  box-shadow: none;
  transition: all var(--duration) var(--ease);
}
.article-toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}
.article-toc-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-primary);
}
.article-toc-title svg {
  color: var(--accent-text);
}
.article-toc-title .toc-counter {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-text);
  background: var(--accent-muted);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}
.article-toc-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--duration) var(--ease);
}
.article-toc-toggle-btn:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}
.article-toc-toggle-btn .toc-chevron {
  transition: transform var(--duration) var(--ease);
}
.article-toc-card.collapsed .article-toc-toggle-btn .toc-chevron {
  transform: rotate(180deg);
}
.article-toc-body {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  max-height: 2000px;
  opacity: 1;
  overflow: hidden;
  transition: max-height 0.45s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease, margin-top 0.35s ease, padding-top 0.35s ease, border-color 0.35s ease;
}
.article-toc-card.collapsed .article-toc-body {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  padding-top: 0;
  border-top-color: transparent;
  pointer-events: none;
}
.article-toc-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.article-toc-list .toc-item a {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.92rem;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  transition: all 0.15s ease;
  line-height: 1.6;
}
.article-toc-list .toc-item a:hover {
  color: var(--accent-text);
  background: var(--accent-muted);
  transform: translateX(-4px);
}
.article-toc-list .toc-item.toc-h2 {
  font-weight: 700;
}
.article-toc-list .toc-item.toc-h3 {
  padding-right: 18px;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--text-tertiary);
}
.article-toc-list .toc-item .toc-bullet {
  font-family: monospace;
  color: var(--accent-text);
  font-size: 0.85rem;
  flex-shrink: 0;
}
.block-heading {
  scroll-margin-top: 90px;
}


/* 2026 media/glass fixes */
.article-content.legacy img,
.block-image img {
  width: 100% !important;
  height: auto !important;
  max-height: none !important;
  object-fit: contain !important;
  object-position: center !important;
}
.article-toc-card {
  background: linear-gradient(145deg, rgba(255,255,255,0.025), rgba(255,255,255,0)), var(--glass-surface, var(--bg-surface));
  border-color: var(--glass-border, var(--border));
  backdrop-filter: blur(14px) saturate(125%);
  -webkit-backdrop-filter: blur(14px) saturate(125%);
}

/* v14 table/media finishing: wrappers hug their actual content and never keep
   a phantom tail below the final row. */
.block-table {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  min-height: 0;
  margin: 20px 0;
  padding: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-gutter: auto;
}
.block-table table {
  width: 100%;
  margin: 0;
  padding: 0;
  border-spacing: 0;
  table-layout: auto;
}
.block-table tbody,
.block-table thead,
.block-table tr { height: auto; }
.block-table tr:last-child > td { border-bottom-width: 1px; }
.block-embed,
.block-embed > .aparat-embed-wrapper,
.block-embed > .aparat-container {
  width: 100%;
  max-width: 100%;
  margin-inline: 0;
}

/* v14 shared renderer: prevent the final block/table from leaving a visual tail
   inside article, video and product content cards. */
.article-content > :first-child {
  margin-top: 0;
}
.article-content > :last-child {
  margin-bottom: 0;
}
.article-content > .block-table:first-child {
  margin-top: 0;
}
.article-content > .block-table:last-child {
  margin-bottom: 0;
}
.block-table table > :last-child > tr:last-child > * {
  border-bottom-width: 1px;
}
