/* ==========================================================================
   .content-body  —  typography for long-form CMS content on the PUBLIC site.

   This is what renders the rich text the admin editor produces. It lives in
   /public/assets/css next to the template's own stylesheets and is loaded with
   a plain <link> by the pages that need it, so the ported NAMU template's
   cascade is untouched: nothing here applies outside `.content-body`.

   THE RULE THAT MATTERS: every rule in here that changes how CONTENT looks must
   also exist in the editor's stylesheet (src/app/admin/admin.css, the
   `.rte .ProseMirror` block). When the two drift, the editor shows the author
   something the visitor will not see — which is the single most annoying class
   of bug in a CMS.

   Colours come from variables so the site's accent is set in one place. The
   accent follows the site theme colour (--bs-themecolor from color-red.css),
   so links, bullets and rules match the rest of the site.
   ========================================================================== */

.content-body {
  --cb-accent: var(--bs-themecolor, #dc3545);
  --cb-accent-2: var(--bs-themehovercolor, #ca2333);
  --cb-heading: #ffffff;
  --cb-ink: #c8c8d0;
  --cb-muted: #8b8b98;
  --cb-surface: #1c1c24;
  --cb-border: #2e2e38;
  --cb-mark: var(--bs-themecolor, #dc3545);
  /* Height of the sticky header, so an #anchor link does not land under it. */
  --cb-header-offset: 90px;

  color: var(--cb-ink);
}

/* ---------- Headings ------------------------------------------------------ */

.content-body h1,
.content-body h2,
.content-body h3,
.content-body h4,
.content-body h5,
.content-body h6 {
  color: var(--cb-heading);
  /* `balance` stops a heading leaving one word alone on its last line. */
  text-wrap: balance;
  scroll-margin-top: var(--cb-header-offset);
}

.content-body h1 {
  font-size: 1.85rem;
  font-weight: 800;
  line-height: 1.4;
  margin: 1.6em 0 0.6em;
  padding-bottom: 0.35em;
  border-bottom: 2px solid var(--cb-accent);
}
.content-body h2 {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.45;
  margin: 1.6em 0 0.55em;
  /* Logical properties throughout, so the bar sits on the correct side in RTL
     and would still be correct if a block were marked LTR. */
  padding-inline-start: 0.65em;
  border-inline-start: 3px solid var(--cb-accent);
}
.content-body h3 {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.5;
  margin: 1.4em 0 0.5em;
}
.content-body h4 {
  font-size: 1.08rem;
  font-weight: 700;
  margin: 1.2em 0 0.45em;
}
.content-body h5 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--cb-ink);
  margin: 1.1em 0 0.4em;
}
.content-body h6 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--cb-muted);
  letter-spacing: 0.04em;
  margin: 1em 0 0.35em;
}

/* ---------- Text --------------------------------------------------------- */

.content-body p {
  margin: 0 0 1.15em;
}

.content-body p,
.content-body li {
  line-height: 2;
  text-wrap: pretty;
  /* A long Latin URL inside Persian prose would otherwise push the column
     wider than the page. */
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* The first paragraph reads as a lead. Direct child only, so it does not fire
   on a block whose first child is a list or a figure. */
.content-body > p:first-of-type {
  font-size: 1.06em;
  color: #dcdce4;
}

.content-body strong,
.content-body b {
  color: var(--cb-heading);
  font-weight: 700;
}
.content-body em,
.content-body i {
  font-style: italic;
}
.content-body u {
  text-decoration-color: var(--cb-accent);
  text-underline-offset: 3px;
}
.content-body s,
.content-body del {
  color: var(--cb-muted);
}
.content-body small {
  color: var(--cb-muted);
  font-size: 0.86em;
}
.content-body sub,
.content-body sup {
  font-size: 0.75em;
}

.content-body mark {
  /* A gradient from halfway down, so it reads as a highlighter stroke rather
     than a filled box. */
  background: linear-gradient(180deg, transparent 55%, rgba(232, 185, 49, 0.35) 55%);
  color: var(--cb-heading);
  padding: 0 2px;
}

.content-body kbd {
  display: inline-block;
  padding: 1px 6px;
  font-size: 0.85em;
  font-family: 'JetBrains Mono', Consolas, monospace;
  background: var(--cb-surface);
  border: 1px solid var(--cb-border);
  border-bottom-width: 2px;
  border-radius: 4px;
  direction: ltr;
}

.content-body abbr[title] {
  text-decoration: underline dotted var(--cb-accent);
  cursor: help;
}

/* ---------- Links: all five states, so the affordance never disappears --- */

.content-body a {
  color: var(--cb-accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: rgba(232, 185, 49, 0.45);
  transition: color 0.15s, text-decoration-color 0.15s;
}
.content-body a:visited {
  color: #d7ad48;
}
.content-body a:hover {
  color: var(--cb-accent-2);
  text-decoration-color: var(--cb-accent-2);
}
.content-body a:focus-visible {
  outline: 2px solid var(--cb-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- Code --------------------------------------------------------- */

/* Code is ALWAYS left to right, whatever the surrounding text direction.
   `unicode-bidi: embed` keeps an identifier from being reordered inside a
   Persian sentence. */
.content-body code {
  background: var(--cb-surface);
  /* Lightened so small monospace text stays readable on the dark surface. */
  color: color-mix(in srgb, var(--cb-accent) 70%, #fff);
  font-size: 0.9em;
  padding: 1px 6px;
  border: 1px solid var(--cb-border);
  border-radius: 4px;
  font-family: 'JetBrains Mono', Consolas, monospace;
  direction: ltr;
  unicode-bidi: embed;
}

.content-body pre {
  background: #121218;
  color: #d4dcea;
  font-size: 0.85rem;
  line-height: 1.8;
  padding: 1rem 1.1rem;
  border-radius: 10px;
  border-inline-start: 3px solid var(--cb-accent);
  /* Its own scroll container, so a long line scrolls the block instead of the
     page. */
  overflow-x: auto;
  margin: 1.3em 0;
  direction: ltr;
  text-align: left;
  font-family: 'JetBrains Mono', Consolas, monospace;
}
.content-body pre code {
  background: transparent;
  border: 0;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

/* ---------- Quote -------------------------------------------------------- */

.content-body blockquote {
  position: relative;
  background: var(--cb-surface);
  border-inline-start: 3px solid var(--cb-accent);
  border-radius: 8px;
  padding: 0.85rem 1.1rem;
  margin: 1.4em 0;
  color: var(--cb-ink);
}
.content-body blockquote > :last-child {
  margin-bottom: 0;
}

/* ---------- Lists -------------------------------------------------------- */

.content-body ul,
.content-body ol {
  /* Logical, so the markers swap sides automatically in RTL. */
  padding-inline-start: 1.6em;
  margin: 0 0 1.15em;
}
.content-body ul {
  list-style: none;
}
.content-body ol {
  list-style: decimal;
}
.content-body ol > li::marker {
  color: var(--cb-accent);
  font-weight: 700;
}
.content-body li {
  margin: 0.35em 0;
  position: relative;
}
.content-body ul > li::before {
  content: '';
  position: absolute;
  inset-inline-start: -1.35em;
  top: 0.78em;
  width: 0.45em;
  height: 0.45em;
  border-radius: 50%;
  background: var(--cb-accent);
  pointer-events: none;
}

.content-body dl {
  margin: 1.2em 0;
}
.content-body dt {
  font-weight: 700;
  color: var(--cb-heading);
  margin-top: 0.7em;
}
.content-body dd {
  margin: 0 0 0.5em;
  padding-inline-start: 1em;
}

/* ---------- Table -------------------------------------------------------- */

.content-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.4em 0;
  font-size: 0.92rem;
  background: var(--cb-surface);
  border: 1px solid var(--cb-border);
  border-radius: 10px;
  overflow: hidden;
}
.content-body thead th {
  background: rgba(232, 185, 49, 0.12);
  color: var(--cb-heading);
  font-weight: 700;
  padding: 0.6rem 0.75rem;
  /* `start`, not `right`: correct in both directions. */
  text-align: start;
  border-bottom: 2px solid rgba(232, 185, 49, 0.35);
}
.content-body tbody td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--cb-border);
  text-align: start;
}
.content-body tbody tr:last-child td {
  border-bottom: 0;
}

/* On a phone the table scrolls inside its own box rather than widening the
   page. `white-space: nowrap` is what makes the scroll meaningful; without it
   the cells just squash. */
@media (max-width: 640px) {
  .content-body table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* ---------- Media -------------------------------------------------------- */

.content-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.content-body figure {
  margin: 1.5em 0;
  text-align: center;
}
.content-body figcaption {
  color: var(--cb-muted);
  font-size: 0.85rem;
  margin-top: 0.5em;
  padding-inline-start: 0.5em;
  border-inline-start: 2px solid var(--cb-accent);
  display: inline-block;
  text-align: start;
}

/* An embedded video, in a responsive 16:9 box. The editor stores no width or
   height on the iframe precisely so that this rule decides, which is what keeps
   a pasted `width="1200"` from breaking the layout on a phone. */
.content-body iframe {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  border: 0;
  border-radius: 10px;
  margin: 1.6em 0;
  background: #000;
}

.content-body hr {
  border: 0;
  height: 2px;
  width: 80px;
  margin: 2em auto;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--cb-accent), transparent);
}

.content-body ::selection {
  background: rgba(232, 185, 49, 0.25);
}

/* The "mobile-full" image class the editor's dialog sets.
   THIS RULE MUST BE IDENTICAL to the one in src/app/admin/admin.css, or the
   editor's preview and the live page disagree. */
@media (max-width: 768px) {
  .content-body img.img-mobile-full {
    width: 100% !important;
    height: unset !important;
  }
}
