/*
 * Question content: one look for question HTML everywhere it is shown.
 *
 * CANONICAL COPY: newHelloCode/public/assets/question-content.css
 * Identical copy: clap-frontend/src/styles/question-content.css
 *   (check: `npm run check:question-css` in clap-frontend; it fails if the two differ)
 *
 * Used by: the HugeRTE editor (content_css, body class "question-content"), the Blade question
 * preview / show page / attempt review, and RichContent in clap-frontend (student exam screen,
 * school-admin question bank, student report review, exam instructions).
 *
 * Fonts: IBM Plex Sans Arabic (Arabic + Latin) and JetBrains Mono, loaded by each host page
 * (Google Fonts). Dark mode: Bootstrap's [data-bs-theme="dark"] or the "qc-dark" class (editor).
 * The base weight is normal on purpose: only <strong>/<b> (and headings) are bold, whatever the
 * container around it uses.
 */

.question-content {
    --qc-font: "IBM Plex Sans Arabic", system-ui, "Segoe UI", Roboto, sans-serif;
    --qc-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --qc-text: #1e293b;
    --qc-line: #d5dce6;
    --qc-th-bg: #f1f5f9;
    --qc-quote: #94a3b8;
    --qc-code-text: #0f172a;
    --qc-code-bg: #eef2f7;
    --qc-code-line: #d5dce6;
    --qc-pre-bg: #f6f8fa;

    font-family: var(--qc-font);
    font-weight: 400;
    font-style: normal;
    line-height: 1.75;
    color: var(--qc-text);
    overflow-wrap: anywhere;
}

[data-bs-theme="dark"] .question-content,
.question-content.qc-dark {
    --qc-text: #e2e8f0;
    --qc-line: #3a4556;
    --qc-th-bg: #1f2937;
    --qc-quote: #64748b;
    --qc-code-text: #e2e8f0;
    --qc-code-bg: #263042;
    --qc-code-line: #3a4556;
    --qc-pre-bg: #161d29;
}

/* The editor's iframe body is the content root */
body.question-content {
    margin: 0;
    padding: 0.75rem 1rem;
    background: #ffffff;
}
body.question-content.qc-dark {
    background: #111827;
}

/* ---------------------------------------------------------------- blocks */
.question-content > * {
    margin-top: 0;
    margin-bottom: 0;
}
.question-content > * + * {
    margin-top: 0.75rem;
}
.question-content p {
    margin: 0;
}
.question-content > p + p {
    margin-top: 0.35rem;
}

.question-content strong,
.question-content b {
    font-weight: 700;
}
.question-content em,
.question-content i {
    font-style: italic;
}
.question-content u {
    text-decoration: underline;
}

.question-content h3,
.question-content h4 {
    font-family: var(--qc-font);
    font-weight: 700;
    line-height: 1.4;
    color: inherit;
    margin: 0;
}
.question-content h3 {
    font-size: 1.25em;
}
.question-content h4 {
    font-size: 1.1em;
}

.question-content ul,
.question-content ol {
    margin: 0;
    padding-inline-start: 1.5em;
}
.question-content ul {
    list-style: disc;
}
.question-content ol {
    list-style: decimal;
}
.question-content li + li {
    margin-top: 0.25rem;
}

.question-content blockquote {
    margin: 0;
    padding-inline-start: 1rem;
    border-inline-start: 4px solid var(--qc-quote);
}

.question-content hr {
    border: 0;
    border-top: 1px solid var(--qc-line);
    margin: 1rem 0;
    opacity: 1;
}

/* ---------------------------------------------------------------- tables
   Centred unless the admin chose left/right (inline margin-left/right from the editor; the
   rendered HTML always has both, see QuestionHtml::forDisplay). When rendered, each table sits
   in .qc-table-wrap, the horizontal scroll box for small screens; the table keeps its own
   alignment inside it. The editor has no wrapper (its body is wide enough). */
.question-content table {
    border-collapse: collapse;
    margin-left: auto;
    margin-right: auto;
    max-width: 100%;
    font-size: 0.95em;
}
.question-content .qc-table-wrap {
    max-width: 100%;
    overflow-x: auto;
}
.question-content .qc-table-wrap > table {
    max-width: none;
}
.question-content th,
.question-content td {
    border: 1px solid var(--qc-line);
    padding: 0.4rem 0.75rem;
    text-align: inherit;
    vertical-align: top;
    overflow-wrap: normal;
}
.question-content th {
    background: var(--qc-th-bg);
    font-weight: 700;
}

/* ---------------------------------------------------------------- images */
.question-content img {
    display: inline-block;
    max-width: 100%;
    height: auto;
    border-radius: 0.375rem;
    vertical-align: middle;
}

/* ---------------------------------------------------------------- code
   Inline code is always left-to-right and isolated, so it never reorders the Arabic
   sentence around it. Code blocks keep every space and line (white-space: pre). */
.question-content code {
    font-family: var(--qc-mono);
    font-size: 0.9em;
    font-weight: 400;
    color: var(--qc-code-text);
    background: var(--qc-code-bg);
    border: 1px solid var(--qc-code-line);
    border-radius: 0.3rem;
    padding: 0.05em 0.35em;
    direction: ltr;
    unicode-bidi: isolate;
    /* one unbroken piece: never split across lines inside an Arabic sentence; a code line
       longer than the card scrolls instead of wrapping (keeps its indentation) */
    display: inline-block;
    max-width: 100%;
    overflow-x: auto;
    vertical-align: middle;
    white-space: pre;
    overflow-wrap: normal;
    line-height: 1.5;
}
.question-content strong code,
.question-content b code {
    font-weight: 700;
}

.question-content pre {
    direction: ltr;
    unicode-bidi: isolate;
    text-align: left;
    white-space: pre;
    overflow-x: auto;
    overflow-wrap: normal;
    tab-size: 4;
    font-family: var(--qc-mono);
    font-size: 0.9375rem;
    font-weight: 400;
    line-height: 1.6;
    color: var(--qc-code-text);
    background: var(--qc-pre-bg);
    border: 1px solid var(--qc-line);
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
}
.question-content pre code {
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
    display: inline;
    max-width: none;
    overflow: visible;
    vertical-align: baseline;
    line-height: inherit;
    white-space: inherit;
    overflow-wrap: normal;
}

/* The editor's code-sample plugin highlights code with Prism (.token spans, never saved). Students
   see plain code, so the editor does too. */
.question-content pre .token {
    color: inherit;
    background: none;
    font-style: inherit;
    font-weight: inherit;
}

/* ---------------------------------------------------------------- answer options
   Option HTML (smaller allowlist: text, inline code, code blocks, images). The option body
   shrinks inside its flex row so code and images can't push it wider than the card. */
.question-content.qc-option {
    flex: 1 1 auto;
    min-width: 0;
}
.question-content.qc-option > * + *,
.question-content.qc-option > p + p {
    margin-top: 0.35rem;
}
.question-content.qc-option pre {
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
}
body.question-content.qc-option {
    padding: 0.5rem 0.75rem;
}

/* Admin choices (inline style="text-align|color|background-color|margin|width") always win: this
   file sets no !important and no text-align on blocks. */

/* A paragraph that holds only inline code (one line of code typed as a paragraph) is a code
   line: left-to-right and left-aligned, even in an Arabic card. The class is added when the
   HTML is rendered (App\Support\QuestionHtml::forDisplay), since CSS can't tell code-only
   paragraphs from a sentence that has one code word. */
.question-content p.qc-code-line {
    direction: ltr;
    text-align: left;
}
