/* ============================================================================
   AliothPress — Typography
   
   All text styling for public-facing pages.
   Headings, paragraphs, lists, blockquotes, code, links in prose.
   
   .ap-prose wraps user-generated content (posts, pages) and restores 
   natural spacing/styling that the reset removes.
   ============================================================================ */


/* ============================================================================
   1. HEADINGS (standalone, outside .ap-prose)
   ============================================================================ */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--ap-font-heading);
  font-weight: var(--ap-font-weight-bold);
  line-height: var(--ap-leading-tight);
  color: var(--ap-color-text);
}

h1 { font-size: var(--ap-text-4xl); }
h2 { font-size: var(--ap-text-3xl); }
h3 { font-size: var(--ap-text-2xl); }
h4 { font-size: var(--ap-text-xl); }
h5 { font-size: var(--ap-text-lg); }
h6 { font-size: var(--ap-text-base); font-weight: var(--ap-font-weight-semibold); }


/* ============================================================================
   2. PROSE — Rich content container
   
   Use class="ap-prose" on the wrapper of any user-authored content.
   Restores natural HTML styling (margins, lists, links) within.
   ============================================================================ */

.ap-prose {
  font-size: var(--ap-text-lg);
  line-height: var(--ap-leading-relaxed);
  color: var(--ap-color-text);
  overflow-wrap: break-word;
  word-break: break-word;
}

/* --- Vertical rhythm: consistent spacing between elements --- */
.ap-prose > * + * {
  margin-top: 1.25em;
}

/* --- Headings in prose --- */
.ap-prose h1 {
  font-size: var(--ap-text-4xl);
  margin-top: 2em;
  margin-bottom: 0.6em;
}

.ap-prose h2 {
  font-size: var(--ap-text-3xl);
  margin-top: 1.8em;
  margin-bottom: 0.5em;
  padding-bottom: 0.3em;
  border-bottom: var(--ap-border-width) solid var(--ap-color-border);
}

.ap-prose h3 {
  font-size: var(--ap-text-2xl);
  margin-top: 1.6em;
  margin-bottom: 0.4em;
}

.ap-prose h4 {
  font-size: var(--ap-text-xl);
  margin-top: 1.4em;
  margin-bottom: 0.4em;
}

.ap-prose h5,
.ap-prose h6 {
  margin-top: 1.2em;
  margin-bottom: 0.3em;
}

/* Remove top margin if heading is first child */
.ap-prose > :first-child {
  margin-top: 0;
}

/* --- Paragraphs --- */
.ap-prose p {
  margin-top: 1.25em;
  margin-bottom: 0;
}

/* --- Links in prose --- */
.ap-prose a:not(.ap-btn) {
  color: var(--ap-color-link);
  text-decoration: underline;
  text-decoration-color: var(--ap-color-primary-light);
  text-underline-offset: 2px;
  transition: text-decoration-color var(--ap-transition-fast),
              color var(--ap-transition-fast);
}

.ap-prose a:not(.ap-btn):hover {
  color: var(--ap-color-link-hover);
  text-decoration-color: var(--ap-color-link-hover);
}

/* --- Lists --- */
.ap-prose ul,
.ap-prose ol {
  padding-left: 1.5em;
  margin-top: 1em;
  margin-bottom: 1em;
}

.ap-prose ul {
  list-style-type: disc;
}

.ap-prose ol {
  list-style-type: decimal;
}

.ap-prose li {
  margin-top: 0.4em;
  padding-left: 0.25em;
}

.ap-prose li > ul,
.ap-prose li > ol {
  margin-top: 0.4em;
  margin-bottom: 0.4em;
}

/* --- Blockquotes --- */
.ap-prose blockquote {
  border-left: 4px solid var(--ap-color-primary);
  padding: var(--ap-space-4) var(--ap-space-6);
  margin: 1.5em 0;
  background: var(--ap-color-primary-subtle);
  border-radius: 0 var(--ap-radius-md) var(--ap-radius-md) 0;
  color: var(--ap-color-text-secondary);
  font-style: italic;
}

.ap-prose blockquote p {
  margin-top: 0.5em;
}

.ap-prose blockquote p:first-child {
  margin-top: 0;
}

/* --- Code --- */

/* Inline code only (NOT code inside <pre>). The `:not(pre) >` guard keeps
   the inline "pill" styling from leaking onto fenced code blocks. */
.ap-prose :not(pre) > code {
  font-family: var(--ap-font-mono);
  font-size: 0.875em;
  background: var(--ap-color-surface-alt);
  padding: 0.15em 0.4em;
  border-radius: var(--ap-radius-sm);
  color: var(--ap-color-accent);
}

/* Fenced code block. Follows the active theme via semantic tokens — same
   approach as the page-builder .ap-code-block, so posts and builder match
   in every theme and both light/dark modes. No fixed colors here. */
.ap-prose pre {
  background: var(--ap-color-surface);
  color: var(--ap-color-text);
  border: var(--ap-border-width) solid var(--ap-color-border);
  padding: var(--ap-space-5);
  border-radius: var(--ap-radius-md);
  overflow-x: auto;
  margin: 1.5em 0;
  line-height: 1.5;
}

.ap-prose pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
  font-size: var(--ap-text-sm);
}

/* Prism token palette for post/page content.
   Mirrors the page-builder .ap-code-block mapping and uses the same
   theme tokens, so colors adapt per theme and per light/dark mode. */
.ap-prose pre .token.comment,
.ap-prose pre .token.prolog,
.ap-prose pre .token.doctype,
.ap-prose pre .token.cdata {
  color: var(--ap-color-text-muted);
  font-style: italic;
}

.ap-prose pre .token.punctuation {
  color: var(--ap-color-text-secondary);
}

.ap-prose pre .token.property,
.ap-prose pre .token.tag,
.ap-prose pre .token.boolean,
.ap-prose pre .token.constant,
.ap-prose pre .token.symbol,
.ap-prose pre .token.deleted {
  color: var(--ap-color-error);
}

.ap-prose pre .token.selector,
.ap-prose pre .token.string,
.ap-prose pre .token.char,
.ap-prose pre .token.builtin,
.ap-prose pre .token.inserted,
.ap-prose pre .token.attr-value {
  color: var(--ap-color-success);
}

.ap-prose pre .token.operator,
.ap-prose pre .token.entity,
.ap-prose pre .token.url {
  color: var(--ap-color-info);
}

.ap-prose pre .token.atrule,
.ap-prose pre .token.keyword {
  color: var(--ap-color-accent);
}

.ap-prose pre .token.function,
.ap-prose pre .token.class-name {
  color: var(--ap-color-primary);
}

.ap-prose pre .token.number {
  color: var(--ap-color-warning);
}

.ap-prose pre .token.attr-name {
  color: var(--ap-color-warning);
}

.ap-prose pre .token.regex,
.ap-prose pre .token.important,
.ap-prose pre .token.variable {
  color: var(--ap-color-info);
}

/* --- Horizontal rule --- */
.ap-prose hr {
  border: none;
  border-top: var(--ap-border-width) solid var(--ap-color-border);
  margin: 2em 0;
}

/* --- Tables --- */
.ap-prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
  font-size: var(--ap-text-base);
}

.ap-prose th,
.ap-prose td {
  text-align: left;
  padding: var(--ap-space-3) var(--ap-space-4);
  border-bottom: var(--ap-border-width) solid var(--ap-color-border);
}

.ap-prose th {
  font-weight: var(--ap-font-weight-semibold);
  background: var(--ap-color-surface);
  border-bottom-width: 2px;
}

.ap-prose tbody tr:hover {
  background: var(--ap-color-surface);
}

/* --- Images in prose --- */
.ap-prose img {
  border-radius: var(--ap-radius-md);
  margin: 1.5em 0;
}

.ap-prose figure {
  margin: 1.5em 0;
}

.ap-prose figcaption {
  font-size: var(--ap-text-sm);
  color: var(--ap-color-text-muted);
  margin-top: var(--ap-space-2);
  text-align: center;
}

/* --- Strong, emphasis --- */
.ap-prose strong {
  font-weight: var(--ap-font-weight-semibold);
  color: var(--ap-color-text);
}

.ap-prose em {
  font-style: italic;
}

/* --- Abbreviations --- */
.ap-prose abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
}

/* --- Superscript, subscript (no layout shift) --- */
.ap-prose sup,
.ap-prose sub {
  font-size: 0.75em;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}

.ap-prose sup { top: -0.5em; }
.ap-prose sub { bottom: -0.25em; }


/* ============================================================================
   RTL SUPPORT — Arabic, Hebrew
   ============================================================================ */

/* Lists: flip padding direction */
[dir="rtl"] .ap-prose ul,
[dir="rtl"] .ap-prose ol {
  padding-left: 0;
  padding-right: 1.5em;
}

[dir="rtl"] .ap-prose li {
  padding-left: 0;
  padding-right: 0.25em;
}

/* Blockquote: border on the right side */
[dir="rtl"] .ap-prose blockquote {
  border-left: none;
  border-right: 4px solid var(--ap-color-primary);
  border-radius: var(--ap-radius-md) 0 0 var(--ap-radius-md);
}

/* Tables: text alignment */
[dir="rtl"] .ap-prose th,
[dir="rtl"] .ap-prose td {
  text-align: right;
}

/* Code: always LTR */
[dir="rtl"] .ap-prose pre,
[dir="rtl"] .ap-prose code {
  direction: ltr;
  text-align: left;
}

/* ============================================================
   AliothEditor alignment helpers
   ------------------------------------------------------------
   The admin editor marks alignment with classes instead of
   inline styles (so content never carries hardcoded styling).
   These classes are whitelisted by sanitize_html() and must be
   understood on the public side too.
   ============================================================ */
.ae-align-center { text-align: center; }
.ae-align-right  { text-align: right; }
[dir="rtl"] .ae-align-right { text-align: left; }
