/**
 * Mathpix to bbPress Importer — frontend styles.
 *
 * Layout aim: each imported topic page reads like a cracku.in question
 * card — clear Question / Solution / Answer hierarchy, no forum chrome
 * stealing attention or hurting the SEO content-to-chrome ratio.
 *
 * Default math renderer is KaTeX (synchronous, no FOUL). Selectors below
 * also cover MathJax 4 (`mjx-container`) and native MathML (`<math>`) so
 * switching renderers via the admin setting doesn't break layout.
 */

/* ============================================================
 *  Display equations — horizontal scroll on narrow screens.
 * ============================================================ */

/* KaTeX */
.bbp-topic-content .katex-display,
.bbp-reply-content .katex-display {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.4em 0;
    margin: 0.6em 0;
    -webkit-overflow-scrolling: touch;
}

.bbp-topic-content .katex-display > .katex,
.bbp-reply-content .katex-display > .katex {
    min-width: max-content;
    text-align: left !important;
}

/* Inline KaTeX */
.bbp-topic-content .katex:not(.katex-display *):not(.katex-display),
.bbp-reply-content .katex:not(.katex-display *):not(.katex-display) {
    vertical-align: middle;
}

/* MathJax 4 (fallback renderer) */
.bbp-topic-content mjx-container[display="true"],
.bbp-reply-content mjx-container[display="true"],
.bbp-topic-content .mbpi-math-display,
.bbp-reply-content .mbpi-math-display {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.4em 0;
    margin: 0.6em 0;
    -webkit-overflow-scrolling: touch;
}

.bbp-topic-content mjx-container[display="true"] mjx-math,
.bbp-reply-content mjx-container[display="true"] mjx-math {
    min-width: max-content;
}

.bbp-topic-content mjx-container:not([display="true"]),
.bbp-reply-content mjx-container:not([display="true"]) {
    vertical-align: middle;
    max-width: 100%;
}

/* Native MathML (rare — only when content embeds <math> tags directly) */
.bbp-topic-content math[display="block"],
.bbp-reply-content math[display="block"] {
    display: block;
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    padding: 0.25em 0;
    -webkit-overflow-scrolling: touch;
}

.bbp-topic-content math:not([display="block"]),
.bbp-reply-content math:not([display="block"]) {
    vertical-align: middle;
}

/* ============================================================
 *  Question / Solution / Answer cards.
 * ============================================================ */

.bbp-topic-content,
.bbp-reply-content {
    font-size: 1.05rem;
    line-height: 1.7;
    color: #1f2937;
}

.bbp-topic-content > *:first-child,
.bbp-reply-content > *:first-child { margin-top: 0; }

.bbp-topic-content > *:last-child,
.bbp-reply-content > *:last-child  { margin-bottom: 0; }

/* Headings injected above Solution / Answer replies. */
.bbp-topic-content h3.mbpi-solution-heading,
.bbp-reply-content h3.mbpi-solution-heading,
.bbp-topic-content h3.mbpi-answer-heading,
.bbp-reply-content h3.mbpi-answer-heading {
    margin: 0 0 0.6em;
    padding: 0 0 0.4em;
    font-size: 1.15em;
    font-weight: 600;
    border-bottom: 2px solid #e5e7eb;
    display: inline-block;
}

.bbp-topic-content h3.mbpi-solution-heading,
.bbp-reply-content h3.mbpi-solution-heading {
    color: #1d4ed8;
    border-bottom-color: #93c5fd;
}

.bbp-topic-content h3.mbpi-answer-heading,
.bbp-reply-content h3.mbpi-answer-heading {
    color: #047857;
    border-bottom-color: #6ee7b7;
}

/* ============================================================
 *  Download PDF button (appended after the question body on
 *  imported topic pages by download-handler.php).
 * ============================================================ */

.mbpi-download-wrap {
    margin-top: 1.25em;
    text-align: right;
}

/* bbPress core ships `#bbpress-forums div.bbp-reply-content a { background:
 * 0 0; display: inline; padding: 0; ... }` — specificity (1,1,2). The topic
 * body renders inside the reply loop on this theme, so a bare class selector
 * loses every declaration in that reset. The #bbpress-forums-prefixed
 * variants below outrank it at (1,2,2); the bare a.mbpi-download-btn keeps
 * the button styled on themes without the bbPress wrapper markup. */
a.mbpi-download-btn,
#bbpress-forums div.bbp-topic-content a.mbpi-download-btn,
#bbpress-forums div.bbp-reply-content a.mbpi-download-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    background: #1d4ed8;
    color: #fff !important;
    padding: 0.55em 1.1em;
    border-radius: 6px;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    transition: background 0.15s ease;
}

a.mbpi-download-btn:hover,
a.mbpi-download-btn:focus,
#bbpress-forums div.bbp-topic-content a.mbpi-download-btn:hover,
#bbpress-forums div.bbp-topic-content a.mbpi-download-btn:focus,
#bbpress-forums div.bbp-reply-content a.mbpi-download-btn:hover,
#bbpress-forums div.bbp-reply-content a.mbpi-download-btn:focus {
    background: #1e40af;
    color: #fff !important;
}

.mbpi-download-btn svg {
    flex: 0 0 auto;
}

@media (max-width: 640px) {
    .mbpi-download-wrap {
        text-align: center;
    }

    a.mbpi-download-btn,
    #bbpress-forums div.bbp-topic-content a.mbpi-download-btn,
    #bbpress-forums div.bbp-reply-content a.mbpi-download-btn {
        width: 100%;
        justify-content: center;
    }
}

@media print {
    .mbpi-download-wrap {
        display: none !important;
    }
}

/* ============================================================
 *  Tables converted from Mathpix \begin{tabular} / \begin{array}
 *  environments (mbpi_convert_latex_tables).
 * ============================================================ */

.mbpi-table-wrap {
    overflow-x: auto;
    margin: 0.9em 0;
    -webkit-overflow-scrolling: touch;
}

table.mbpi-table {
    border-collapse: collapse;
    margin: 0 auto;
    width: auto;
}

table.mbpi-table th,
table.mbpi-table td {
    border: 1px solid #9ca3af;
    padding: 0.45em 0.9em;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}

table.mbpi-table th {
    background: #f3f4f6;
    font-weight: 600;
}

/* ============================================================
 *  Figures (Mathpix snip images for graphs).
 * ============================================================ */

.bbp-topic-content img.mbpi-figure,
.bbp-reply-content img.mbpi-figure,
.bbp-topic-content img:not(.avatar),
.bbp-reply-content img:not(.avatar) {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0.75em auto;
    background: #fff;
    padding: 8px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* ============================================================
 *  Mobile polish.
 * ============================================================ */

@media (max-width: 640px) {
    .bbp-topic-content,
    .bbp-reply-content {
        font-size: 1rem;
        line-height: 1.65;
    }

    .bbp-topic-content .katex-display,
    .bbp-reply-content .katex-display,
    .bbp-topic-content mjx-container[display="true"],
    .bbp-reply-content mjx-container[display="true"],
    .bbp-topic-content .mbpi-math-display,
    .bbp-reply-content .mbpi-math-display {
        padding: 0.5em 0;
        scrollbar-width: thin;
    }

    .bbp-topic-content h3.mbpi-solution-heading,
    .bbp-reply-content h3.mbpi-solution-heading,
    .bbp-topic-content h3.mbpi-answer-heading,
    .bbp-reply-content h3.mbpi-answer-heading {
        font-size: 1.05em;
    }
}

/* ============================================================
 *  Strip bbPress chrome on imported topic pages.
 *
 *  Login/register links, the "no replies" notice, the inline login
 *  form, and per-reply meta (avatar + timestamp) all add visual
 *  noise without helping a visitor who landed here from a Google
 *  search. The `.mbpi-imported-topic` body class is added in PHP
 *  only when the topic has the `_mbpi_imported` post meta, so the
 *  rest of the forum is unaffected.
 * ============================================================ */

body.mbpi-imported-topic .bbpressloginlinks,
body.mbpi-imported-topic .bbp-no-reply,
body.mbpi-imported-topic .bbp-login-form,
body.mbpi-imported-topic .bbp-template-notice {
    display: none !important;
}

body.mbpi-imported-topic .bbp-reply-author,
body.mbpi-imported-topic .bbp-meta,
body.mbpi-imported-topic .reply-author-displayname,
body.mbpi-imported-topic .bbp-head-area {
    display: none !important;
}

/* Kadence theme injects a "Settings" gear icon (.bbpress-admin-settings-
 * container) after each reply for the post author. It overlaps with the
 * solution body on imported pages and adds noise for unauthenticated
 * search-engine visitors — hide it. */
body.mbpi-imported-topic .bbpress-admin-settings-container,
body.mbpi-imported-topic .kadence-settings-svg {
    display: none !important;
}

/* Give the imported topic body a small card framing on desktop. */
body.mbpi-imported-topic .bbp-topic-content,
body.mbpi-imported-topic .bbp-reply-content {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1.25em 1.5em;
    margin: 0.75em 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

@media (max-width: 640px) {
    body.mbpi-imported-topic .bbp-topic-content,
    body.mbpi-imported-topic .bbp-reply-content {
        padding: 1em;
        border-radius: 6px;
    }
}
