/* =============================================================================
 * Rahkar — CMS / content pages  (cms/page.tpl, cms/category.tpl, cms/sitemap.tpl)
 * -----------------------------------------------------------------------------
 * WHY THIS FILE EXISTS
 * The CMS surface («درباره ما», «قوانین», «حریم خصوصی» …) was the last classic
 * leftover: cms/page.tpl dumped {$cms.content} straight into
 * `#content.page-content.card.card-block` with NO theme CSS registered for the
 * `cms` page. The only thing painting it was the classic base theme.css:
 *
 *     #content { padding:1rem; background:#fff; font-size:.875rem; color:#7a7a7a }
 *
 * …i.e. 14px grey text running the full 1676px container width, Bootstrap card
 * chrome, unconstrained <video>/<img> (the about page ships a 100%×100% video),
 * and heading sizes from three different sources fighting each other. Hence the
 * "توهم‌توهم" look.
 *
 * WHAT IT DOES
 *   1. `.rh-cms`     — the page shell: a centred reading column (760px measure)
 *                      with an optional sticky in-page table of contents.
 *   2. `.rh-prose`   — the typography contract for admin-authored HTML. This is
 *                      the important part: the BO editor emits bare
 *                      <p>/<h2>/<ul>/<img>/<table>/<video>, so every one of them
 *                      is styled here, keyed on the design tokens.
 *   3. `.rh-cms-grid`— CMS-category card grid + the sitemap columns.
 *
 * Loaded on page_name `cms` and `sitemap` (config/theme.yml, priority 60 — after
 * the classic theme.css at 50, so plain selectors here win on source order).
 * Selectors that must beat classic's `#content` ID rule are written as
 * `#content.rh-cms` (1,1,0 > 1,0,0); everything else out-specifies by targeting
 * the element directly (a direct rule always beats an inherited value).
 *
 * RTL: logical properties only — no physical left/right, no *_rtl.css pair.
 * ========================================================================== */

.rh-cms {
  /* Reading measure. 760px == --wp--style--global--content-size, the same
     column the rest of the theme uses for constrained text. */
  --rh-cms-measure: 760px;
  --rh-cms-toc-w: 226px;
  /* Sticky offset: #header (sticky, ~56px) + breathing room. Also the
     scroll-margin for heading anchors so a TOC jump doesn't hide the heading
     under the header. */
  --rh-cms-sticky-top: calc(84px + var(--rh-topbar-offset, 0px));

  /* Column gap between the TOC rail and the text (desktop only). */
  --rh-cms-gap: clamp(2rem, 4vw, 4rem);

  /* One flexible column; the reading measure is capped on the GRID itself
     rather than baked into the track, so the track stays a plain 1fr and the
     two-column desktop variant below only has to re-declare the cap. */
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  inline-size: 100%;
  max-inline-size: var(--rh-cms-measure);
  margin-block: clamp(1.25rem, 4vw, var(--wp--preset--spacing--60));
  margin-inline: auto;
}

/* Neutralise the classic `#content` rule (padding/background/grey 14px text)
   and the .card chrome, in case a module re-adds those classes. */
#content.rh-cms,
.rh-cms.card {
  padding: 0;
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  color: var(--wp--preset--color--text, #1a1d23);
  font-size: var(--wp--preset--font-size--base, 1rem);
  margin-bottom: 0;
}

/* ---------------------------------------------------------------------------
 *  Page head — title + optional lede
 *  Zara-light: size carries the hierarchy, not weight. A hairline rule closes
 *  the header block instead of a boxed banner.
 * ------------------------------------------------------------------------- */
.rh-cms__head {
  grid-column: 1;
  padding-block-end: clamp(1rem, 3vw, 1.75rem);
  margin-block-end: clamp(1.5rem, 4vw, 2.5rem);
  border-block-end: 1px solid var(--wp--preset--color--border, #e2e4e9);
}

.rh-cms__title {
  margin: 0;
  font-size: var(--wp--preset--font-size--3xl, 1.875rem);
  font-weight: var(--rh-fw-heading, 300);
  line-height: 1.3;
  color: var(--wp--preset--color--contrast, #0f1115);
}

.rh-cms__lede {
  margin: 0.75rem 0 0;
  max-inline-size: 62ch;
  font-size: var(--wp--preset--font-size--md, 1.0625rem);
  font-weight: var(--rh-fw-base, 300);
  line-height: 1.9;
  color: var(--wp--preset--color--text-muted, #5b6271);
}

/* ---------------------------------------------------------------------------
 *  Table of contents (built by assets/js/cms-page.js from the h2/h3 in .rh-prose)
 *  Mobile: a collapsed <details> between the title and the body.
 *  Desktop ≥1080px: a sticky column beside the text (inline-start = right in RTL).
 *  Without JS the <nav> simply never exists — the page stays a single column.
 * ------------------------------------------------------------------------- */
.rh-cms__toc {
  grid-column: 1;
  margin-block-end: clamp(1.5rem, 4vw, 2rem);
  border: 1px solid var(--wp--preset--color--border, #e2e4e9);
  border-radius: var(--wp--custom--radius--lg, 0.75rem);
  background: var(--wp--preset--color--surface, #f7f7f8);
}

.rh-cms__toc-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  cursor: pointer;
  list-style: none;
  font-size: var(--wp--preset--font-size--sm, 0.875rem);
  font-weight: var(--rh-fw-strong, 400);
  color: var(--wp--preset--color--text, #1a1d23);
}
.rh-cms__toc-summary::-webkit-details-marker { display: none; }

.rh-cms__toc-summary svg {
  inline-size: 18px;
  block-size: 18px;
  flex: none;
  color: var(--wp--preset--color--text-muted, #5b6271);
  transition: transform 200ms ease;
}
.rh-cms__toc-summary svg:last-child { margin-inline-start: auto; }
.rh-cms__toc[open] .rh-cms__toc-summary svg:last-child { transform: rotate(180deg); }

.rh-cms__toc-list {
  margin: 0;
  padding: 0 1rem 0.9rem;
  list-style: none;
}

.rh-cms__toc-list a {
  display: block;
  padding: 0.4rem 0;
  border-inline-start: 2px solid transparent;
  padding-inline-start: 0.75rem;
  font-size: var(--wp--preset--font-size--sm, 0.875rem);
  font-weight: var(--rh-fw-base, 300);
  line-height: 1.7;
  color: var(--wp--preset--color--text-muted, #5b6271);
  transition: color 150ms ease, border-color 150ms ease;
}
.rh-cms__toc-list a:hover { color: var(--wp--preset--color--text, #1a1d23); }

/* Nested h3 entries sit one notch in. */
.rh-cms__toc-list .is-sub a {
  padding-inline-start: 1.5rem;
  font-size: var(--wp--preset--font-size--xs, 0.75rem);
}

/* Scroll-spy state (cms-page.js). */
.rh-cms__toc-list a.is-current {
  border-inline-start-color: var(--wp--preset--color--primary, #6dbdba);
  color: var(--wp--preset--color--contrast, #0f1115);
}

/* ---------------------------------------------------------------------------
 *  Body + footer placement
 * ------------------------------------------------------------------------- */
.rh-cms__content { grid-column: 1; min-inline-size: 0; }

/* The two CMS hooks are usually unhooked, so the <footer> is normally an empty
   (whitespace-only) element — `:empty` would NOT match it. Hanging the top gap
   off the first real child instead means an unused footer costs zero height. */
.rh-cms__foot { grid-column: 1; }
.rh-cms__foot > :first-child { margin-block-start: clamp(2rem, 6vw, 3.5rem); }

/* Desktop two-column layout, only when the TOC actually got built. */
@media (min-width: 1080px) {
  .rh-cms[data-rh-toc="on"] {
    grid-template-columns: var(--rh-cms-toc-w) minmax(0, 1fr);
    column-gap: var(--rh-cms-gap);
    max-inline-size: calc(var(--rh-cms-measure) + var(--rh-cms-toc-w) + var(--rh-cms-gap));
  }
  .rh-cms[data-rh-toc="on"] .rh-cms__head    { grid-column: 2; grid-row: 1; }
  .rh-cms[data-rh-toc="on"] .rh-cms__content { grid-column: 2; grid-row: 2; }
  .rh-cms[data-rh-toc="on"] .rh-cms__foot    { grid-column: 2; grid-row: 3; }

  .rh-cms[data-rh-toc="on"] .rh-cms__toc {
    grid-column: 1;
    grid-row: 2;
    position: sticky;
    inset-block-start: var(--rh-cms-sticky-top);
    max-block-size: calc(100vh - var(--rh-cms-sticky-top) - 2rem);
    overflow-y: auto;
    margin-block-end: 0;
    border: 0;
    border-inline-start: 1px solid var(--wp--preset--color--border, #e2e4e9);
    border-radius: 0;
    background: none;
    overscroll-behavior: contain;
  }
  /* On desktop the box is always open — the summary row becomes a quiet label. */
  .rh-cms[data-rh-toc="on"] .rh-cms__toc-summary {
    padding: 0 0 0.6rem 0;
    cursor: default;
    pointer-events: none;
    color: var(--wp--preset--color--text-muted, #5b6271);
    font-size: var(--wp--preset--font-size--xs, 0.75rem);
  }
  .rh-cms[data-rh-toc="on"] .rh-cms__toc-summary svg:last-child { display: none; }
  .rh-cms[data-rh-toc="on"] .rh-cms__toc-list { padding: 0; }
}

/* =============================================================================
 *  .rh-prose — typography for admin-authored HTML
 * -----------------------------------------------------------------------------
 *  Everything the BO (TinyMCE) can emit gets a home here. Persian needs a much
 *  looser leading than Latin: 2.0 at 1.0625rem is the comfortable setting for
 *  Vazirmatn — the single biggest reason the old pages read as a wall of text.
 * ========================================================================== */
.rh-prose {
  font-size: var(--wp--preset--font-size--md, 1.0625rem);
  font-weight: var(--rh-fw-base, 300);
  line-height: 2;
  color: var(--wp--preset--color--text, #1a1d23);
  overflow-wrap: break-word;
  text-align: start;
}

/* Vertical rhythm: one spacing rule for every direct child, then the
   exceptions. Avoids the "every element ships its own margin" chaos. */
.rh-prose > * { margin-block: 0 1.15em; }
.rh-prose > *:last-child { margin-block-end: 0; }

/* ---- Headings ----------------------------------------------------------- */
.rh-prose h1,
.rh-prose h2,
.rh-prose h3,
.rh-prose h4,
.rh-prose h5,
.rh-prose h6 {
  margin-block: 2em 0.6em;
  font-weight: var(--rh-fw-strong, 400);
  line-height: 1.5;
  color: var(--wp--preset--color--contrast, #0f1115);
  scroll-margin-block-start: var(--rh-cms-sticky-top, 84px);
}
.rh-prose > :first-child { margin-block-start: 0; }

/* The page title is the h1. Admin content often ships its own stray <h1>
   (copy-pasted from elsewhere) — clamp it to the h2 step so it can never
   out-shout the real title. */
.rh-prose h1,
.rh-prose h2 { font-size: var(--wp--preset--font-size--xl, 1.5rem); }
.rh-prose h3 { font-size: var(--wp--preset--font-size--lg, 1.25rem); }
.rh-prose h4 { font-size: var(--wp--preset--font-size--md, 1.125rem); }
.rh-prose h5,
.rh-prose h6 {
  font-size: var(--wp--preset--font-size--base, 1rem);
  color: var(--wp--preset--color--text-muted, #5b6271);
}

/* ---- Paragraphs --------------------------------------------------------- */
.rh-prose p { margin-block: 0 1.15em; }
/* TinyMCE leaves empty <p></p> spacers behind; they'd double the rhythm. */
.rh-prose p:empty { display: none; }

/* Opening paragraph reads as a lede when it starts the page. */
.rh-prose > p:first-child {
  font-size: var(--wp--preset--font-size--lg, 1.25rem);
  line-height: 1.9;
  color: var(--wp--preset--color--text-muted, #5b6271);
}

.rh-prose strong,
.rh-prose b {
  font-weight: var(--rh-fw-strong, 400);
  color: var(--wp--preset--color--contrast, #0f1115);
}

.rh-prose small { font-size: var(--wp--preset--font-size--sm, 0.875rem); }

/* ---- Links -------------------------------------------------------------- */
.rh-prose a:not(.rh-btn) {
  color: var(--wp--preset--color--primary-dark, #4f9b98);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.28em;
  text-decoration-color: color-mix(in srgb, var(--wp--preset--color--primary, #6dbdba) 45%, transparent);
  transition: color 150ms ease, text-decoration-color 150ms ease;
}
.rh-prose a:not(.rh-btn):hover {
  color: var(--wp--preset--color--contrast, #0f1115);
  text-decoration-color: currentColor;
}

/* ---- Lists -------------------------------------------------------------- */
.rh-prose ul,
.rh-prose ol {
  margin-block: 0 1.3em;
  padding-inline-start: 1.35em;
}
.rh-prose li { margin-block-end: 0.5em; padding-inline-start: 0.25em; }
.rh-prose li:last-child { margin-block-end: 0; }
.rh-prose ul { list-style: none; padding-inline-start: 1.1em; }
.rh-prose ul > li { position: relative; }
.rh-prose ul > li::before {
  content: "";
  position: absolute;
  inset-inline-start: -1.1em;
  inset-block-start: 0.85em;
  inline-size: 5px;
  block-size: 5px;
  border-radius: 50%;
  background: var(--wp--preset--color--primary, #6dbdba);
}
.rh-prose ol { list-style: decimal; }
.rh-prose ol > li::marker {
  color: var(--wp--preset--color--text-muted, #5b6271);
  font-weight: var(--rh-fw-strong, 400);
}
/* Nested lists tighten up. */
.rh-prose li > ul,
.rh-prose li > ol { margin-block: 0.5em 0; }

/* ---- Media -------------------------------------------------------------- *
 *  The BO editor writes width/height ATTRIBUTES and often an inline
 *  `style="width:100%;height:100%"` (see the about page's <video>). An inline
 *  style beats a plain CSS rule, so the block-size reset needs !important —
 *  the one place in this sheet where that's unavoidable.
 */
.rh-prose img,
.rh-prose video,
.rh-prose iframe {
  display: block;
  max-inline-size: 100%;
  block-size: auto !important;
  margin-inline: auto;
  border-radius: var(--wp--custom--radius--lg, 0.75rem);
}
.rh-prose video,
.rh-prose iframe {
  inline-size: 100%;
  aspect-ratio: 16 / 9;
  block-size: auto;
  background: var(--wp--preset--color--muted, #eceef1);
}
/* An image that is the sole content of a paragraph shouldn't inherit the text
   line-height as extra space underneath. */
.rh-prose p > img:only-child { margin-block: 0.5em; }

.rh-prose figure { margin-block: 0 1.5em; }
.rh-prose figcaption {
  margin-block-start: 0.6em;
  font-size: var(--wp--preset--font-size--sm, 0.875rem);
  color: var(--wp--preset--color--text-muted, #5b6271);
  text-align: center;
}

/* ---- Quotes, rules, code ------------------------------------------------ */
.rh-prose blockquote {
  margin-block: 1.5em;
  margin-inline: 0;
  padding: 0.25em 1.1em;
  border-inline-start: 2px solid var(--wp--preset--color--primary, #6dbdba);
  color: var(--wp--preset--color--text-muted, #5b6271);
}
.rh-prose blockquote > :last-child { margin-block-end: 0; }

.rh-prose hr {
  margin-block: clamp(2rem, 5vw, 3rem);
  border: 0;
  border-block-start: 1px solid var(--wp--preset--color--border, #e2e4e9);
}

.rh-prose code,
.rh-prose kbd {
  padding: 0.15em 0.4em;
  border-radius: var(--wp--custom--radius--sm, 0.25rem);
  background: var(--wp--preset--color--muted, #eceef1);
  font-family: var(--wp--preset--font-family--mono);
  font-size: 0.875em;
  direction: ltr;
  unicode-bidi: embed;
}
.rh-prose pre {
  padding: 1rem 1.15rem;
  overflow-x: auto;
  border-radius: var(--wp--custom--radius--md, 0.5rem);
  background: var(--wp--preset--color--muted, #eceef1);
  direction: ltr;
}
.rh-prose pre code { padding: 0; background: none; }

/* ---- Tables ------------------------------------------------------------- *
 *  cms-page.js wraps every .rh-prose <table> in .rh-prose__scroll so a wide
 *  size/price table scrolls inside its own box instead of blowing out the page.
 */
.rh-prose__scroll {
  margin-block: 0 1.5em;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--wp--preset--color--border, #e2e4e9);
  border-radius: var(--wp--custom--radius--md, 0.5rem);
}
.rh-prose table {
  inline-size: 100%;
  border-collapse: collapse;
  font-size: var(--wp--preset--font-size--sm, 0.875rem);
  line-height: 1.8;
}
.rh-prose th,
.rh-prose td {
  padding: 0.7rem 0.9rem;
  border-block-end: 1px solid var(--wp--preset--color--border, #e2e4e9);
  text-align: start;
  vertical-align: middle;
}
.rh-prose th {
  background: var(--wp--preset--color--surface, #f7f7f8);
  font-weight: var(--rh-fw-strong, 400);
  color: var(--wp--preset--color--contrast, #0f1115);
  white-space: nowrap;
}
.rh-prose tr:last-child td { border-block-end: 0; }

/* Editor-authored inline sizing on tables/cells fights the responsive box. */
.rh-prose table[width],
.rh-prose td[width],
.rh-prose th[width] { inline-size: auto; }

/* =============================================================================
 *  CMS category page (cms/category.tpl) + sitemap (cms/sitemap.tpl)
 * ========================================================================== */

/* Card grid of sub-categories / pages. */
.rh-cms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.75rem;
  margin-block: 0 clamp(1.5rem, 4vw, 2.5rem);
  padding: 0;
  list-style: none;
}

.rh-cms-grid__label {
  margin-block: 0 0.9rem;
  font-size: var(--wp--preset--font-size--sm, 0.875rem);
  font-weight: var(--rh-fw-strong, 400);
  color: var(--wp--preset--color--text-muted, #5b6271);
}

.rh-cms-card {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1rem 1.15rem;
  border: 1px solid var(--wp--preset--color--border, #e2e4e9);
  border-radius: var(--wp--custom--radius--lg, 0.75rem);
  background: var(--wp--preset--color--base, #fff);
  color: var(--wp--preset--color--text, #1a1d23);
  font-size: var(--wp--preset--font-size--base, 1rem);
  font-weight: var(--rh-fw-base, 300);
  line-height: 1.6;
  text-decoration: none;
  transition: border-color 150ms ease, background-color 150ms ease, transform 150ms ease;
}
.rh-cms-card:hover {
  border-color: var(--wp--preset--color--primary, #6dbdba);
  background: var(--wp--preset--color--surface, #f7f7f8);
  color: var(--wp--preset--color--contrast, #0f1115);
  transform: translateY(-1px);
}
/* The chevron is authored pointing inline-end (left, in RTL) in the template. */
.rh-cms-card svg {
  inline-size: 18px;
  block-size: 18px;
  flex: none;
  margin-inline-start: auto;
  color: var(--wp--preset--color--text-muted, #5b6271);
  transition: color 150ms ease;
}
.rh-cms-card:hover svg { color: var(--wp--preset--color--primary-dark, #4f9b98); }

/* Sitemap — four link columns, same hairline language as the rest. */
.rh-sitemap {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: clamp(1.5rem, 4vw, 2.5rem);
}
.rh-sitemap__col h2 {
  margin: 0 0 0.9rem;
  padding-block-end: 0.6rem;
  border-block-end: 1px solid var(--wp--preset--color--border, #e2e4e9);
  font-size: var(--wp--preset--font-size--base, 1rem);
  font-weight: var(--rh-fw-strong, 400);
  color: var(--wp--preset--color--contrast, #0f1115);
}
.rh-sitemap ul { margin: 0; padding: 0; list-style: none; }
.rh-sitemap ul.nested { padding-inline-start: 0.9rem; margin-block-start: 0.25rem; }
.rh-sitemap li { margin-block-end: 0.35rem; }
.rh-sitemap a {
  display: inline-block;
  padding-block: 0.15rem;
  font-size: var(--wp--preset--font-size--sm, 0.875rem);
  font-weight: var(--rh-fw-base, 300);
  color: var(--wp--preset--color--text-muted, #5b6271);
  text-decoration: none;
}
.rh-sitemap a:hover { color: var(--wp--preset--color--primary-dark, #4f9b98); }

/* Empty state (a category with no pages yet). */
.rh-cms__empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--wp--preset--color--text-muted, #5b6271);
  font-size: var(--wp--preset--font-size--sm, 0.875rem);
}

/* =============================================================================
 *  Print — legal pages get printed a lot ("قوانین", "شرایط استفاده").
 * ========================================================================== */
@media print {
  #header,
  #footer,
  .rh-bottom-nav,
  .breadcrumb,
  .rh-cms__toc { display: none !important; }

  .rh-cms { display: block; margin: 0; }
  .rh-prose { font-size: 11pt; line-height: 1.8; color: #000; }
  .rh-prose a:not(.rh-btn) { color: #000; text-decoration: underline; }
  .rh-prose h1, .rh-prose h2, .rh-prose h3 { break-after: avoid; }
  .rh-prose img, .rh-prose video, .rh-prose iframe { break-inside: avoid; }
}
