/* Rich text editor and rendered rich text.
 *
 * Split out of quaeriva.css so the administration panel can load exactly these
 * rules without inheriting the public theme's shell, which would restyle the
 * whole panel. Both stylesheets link this file; the panel maps the design
 * tokens below onto its own --admin-* palette in quaeriva-admin.css.
 *
 * Tokens used here: --line, --surface, --surface-soft, --ink, --ink-muted,
 * --muted, --teal, --teal-dark, --radius-md, --color-primary,
 * --color-surface-soft, --color-border, --danger.
 */

.rich-editor-wrap {
  display: grid;
  gap: 0;
  min-inline-size: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.rich-editor-wrap:focus-within {
  border-color: var(--teal);
  outline: .1875rem solid color-mix(in srgb, var(--teal-dark) 35%, transparent);
  outline-offset: .1875rem;
}
.rich-editor-toolbar {
  display: flex;
  flex-wrap: nowrap;
  gap: .4rem;
  align-items: center;
  min-inline-size: 0;
  overflow-x: auto;
  padding: .45rem;
  background: var(--surface-soft);
  border-block-end: 1px solid var(--line);
}
.rich-editor-group {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: .4rem;
  padding-inline-end: .55rem;
  border-inline-end: 1px solid var(--line);
}
.rich-editor-group:last-of-type {
  border-inline-end: 0;
  padding-inline-end: 0;
}
.rich-editor-button {
  min-inline-size: 2.25rem;
  min-block-size: 2.25rem;
  display: inline-grid;
  place-items: center;
  padding-inline: .45rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}
.rich-editor-button svg,
.rich-editor-source svg { flex: 0 0 auto; }
.rich-editor-button:hover,
.rich-editor-button:focus-visible {
  border-color: var(--teal);
  outline: none;
}
.rich-editor-button[aria-pressed="true"],
.rich-editor-source[aria-pressed="true"] {
  border-color: var(--teal);
  background: var(--teal);
  color: var(--surface);
}
.rich-editor-source {
  min-inline-size: 2.25rem;
  min-block-size: 2.25rem;
  padding-inline: .75rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  background: var(--surface-soft);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  white-space: nowrap;
}
.rich-editor-source:hover,
.rich-editor-source:focus-visible {
  border-color: var(--teal);
  outline: none;
}
.rich-editor-surface {
  min-block-size: 12rem;
  max-block-size: 28rem;
  overflow-y: auto;
  overflow-wrap: anywhere;
  padding: .85rem 1rem;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  cursor: text;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.7;
}
.rich-editor-surface:focus {
  outline: none;
}
.rich-editor-surface:empty::before {
  content: attr(data-placeholder);
  color: var(--ink-muted);
  pointer-events: none;
}
.rich-editor-surface > :first-child { margin-block-start: 0; }
.rich-editor-surface > :last-child { margin-block-end: 0; }
.rich-text {
  overflow-wrap: anywhere;
}
/* Heading hierarchy.
 *
 * The level has to be readable at a glance, not deduced by holding two
 * headings side by side, so each one carries a colour and a marker of its own
 * as well as a size. That matters most in a long Arabic answer, where a reader
 * skims for the section they want and size alone reads as noise.
 *
 * Only --color-primary, --color-secondary and --color-text are used for text:
 * all three are contrast-gated against light and dark surfaces by
 * tests/Theme/DarkModeContrastRegression.php. --color-accent is decorative
 * here -- bars and dots only -- so it never has to meet a contrast floor.
 *
 * Logical properties throughout, because the same rules render right-to-left.
 */
.rich-text h2,
.rich-text h3,
.rich-text h4,
.rich-text h5,
.rich-text h6 {
  line-height: 1.4;
  overflow-wrap: anywhere;
  scroll-margin-block-start: 5rem;
}

.rich-text h2 {
  display: flex;
  align-items: center;
  gap: .55rem;
  margin-block: 1.75em .6em;
  padding-block-end: .35rem;
  border-block-end: 1px solid var(--color-border, var(--line, #dce7e3));
  color: var(--color-primary, #0e6f5c);
  font-size: clamp(1.2rem, 2.4vw, 1.45rem);
  font-weight: 800;
}
.rich-text h2::before {
  content: "";
  flex: 0 0 auto;
  align-self: stretch;
  inline-size: .28rem;
  min-block-size: 1.2em;
  border-radius: 999px;
  background: var(--color-primary, #0e6f5c);
}

.rich-text h3 {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  margin-block: 1.5em .5em;
  color: var(--color-secondary, #3459e6);
  font-size: clamp(1.05rem, 2vw, 1.2rem);
  font-weight: 700;
}
.rich-text h3::before {
  content: "";
  flex: 0 0 auto;
  inline-size: .5rem;
  block-size: .5rem;
  border-radius: 50%;
  background: var(--color-accent, #c99a3b);
  transform: translateY(-.15em);
}

.rich-text h4 {
  margin-block: 1.3em .45em;
  color: var(--color-text, var(--ink, #173a36));
  font-size: 1.02rem;
  font-weight: 700;
}
.rich-text h4::after {
  content: "";
  display: block;
  inline-size: 2.2rem;
  block-size: 2px;
  margin-block-start: .3rem;
  border-radius: 999px;
  background: var(--color-accent, #c99a3b);
}

.rich-text h5,
.rich-text h6 {
  margin-block: 1.2em .4em;
  color: var(--color-muted, var(--ink-muted, #657975));
  font-size: .95rem;
  font-weight: 700;
}

/* The first heading of a body must not push the post away from its own title. */
.rich-text > :first-child {
  margin-block-start: 0;
}

/* A marker rendered inside a link or a small screen must never break the line
   box; the flex row does the alignment, so nothing else has to. */
@media (max-width: 30rem) {
  .rich-text h2 { gap: .4rem; }
  .rich-text h2::before { inline-size: .22rem; }
}
.rich-text blockquote {
  margin-block: 1rem;
  margin-inline: 0;
  padding-block: .75rem;
  padding-inline: 1rem;
  border-inline-start: 4px solid var(--color-primary, #3459e6);
  background: var(--color-surface-soft, #f5f7fb);
  border-radius: .65rem;
}
.rich-text pre {
  max-inline-size: 100%;
  overflow-x: auto;
  padding: 1rem;
  border-radius: .75rem;
  background: #101828;
  color: #f8fafc;
  direction: ltr;
  text-align: start;
}
.rich-text code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}
.rich-text :not(pre) > code {
  padding: .12em .35em;
  border-radius: .35rem;
  background: var(--color-surface-soft, #f5f7fb);
}
.rich-text a,
.comment-item a {
  overflow-wrap: anywhere;
}

@media (max-width: 40rem) {
  .rich-editor-toolbar { overflow-x: auto; flex-wrap: nowrap; }
  .rich-editor-group { flex-shrink: 0; }
}

.rich-editor-counter{display:block;margin-block-start:.4rem;color:var(--muted);font-size:.78rem;text-align:end}
.rich-editor-link-dialog{border:1px solid var(--line);border-radius:var(--radius,12px);padding:0;max-width:min(92vw,34rem);background:var(--surface);color:var(--ink);box-shadow:0 24px 64px rgba(15,23,42,.22)}
.rich-editor-link-dialog::backdrop{background:rgba(15,23,42,.42)}
.rich-editor-link-dialog form{display:grid;grid-template-columns:minmax(0,1fr) auto auto;gap:.6rem;align-items:center;padding:1rem}
.rich-editor-link-dialog input{min-width:0;width:100%}
.rich-editor-link-error{grid-column:1/-1;color:var(--danger,#b42318)}
@media (max-width: 35rem){.rich-editor-link-dialog form{grid-template-columns:1fr 1fr}.rich-editor-link-dialog input,.rich-editor-link-error{grid-column:1/-1}}

/* Embedded content images. Markdown carries no dimensions, so the box is
   constrained here; the reserved min-height limits the shift while the image
   loads without pretending to know its aspect ratio. */
.rich-text-image {
    max-inline-size: 100%;
    block-size: auto;
    min-block-size: 2rem;
    margin-block: .75rem;
    border: 1px solid var(--color-border, var(--line));
    border-radius: var(--radius-md, .75rem);
    background: var(--color-surface-soft, var(--surface-soft));
}
