/* ==========================================================================
   The rich text editor surface
   --------------------------------------------------------------------------
   Lifted out of sh-admin-content.css when the forums started using the
   same <x-rich-editor> component. The editor is no longer an admin-only
   thing, so its rules cannot live in an admin-only file — a member page
   would either render it unstyled or have to pull two thousand lines of
   admin CSS it has no other use for.

   The class names are unchanged (`sh-ac-*`), so no view and no line of
   sh-editor.js had to move with them. Every page that renders the
   toolbar loads this file; `RichTextEditorTest` fails if one forgets.
   ========================================================================== */


/* -- Editor -------------------------------------------------------------- */

/* The toolbar sits inside the field's border, so the two read as one control. */
.sh-ac-editor {
    border: 1px solid var(--sh-border-strong);
    border-radius: var(--sh-radius-sm);
    overflow: hidden;
    transition: border-color var(--sh-dur-fast) var(--sh-ease),
        box-shadow var(--sh-dur-fast) var(--sh-ease);
}

.sh-ac-editor:focus-within {
    border-color: var(--sh-primary-600);
    box-shadow: var(--sh-shadow-focus);
}

/* How tall the writing area starts.
   132px was the height of a *comment* box, and it was inherited by the
   article editor without anyone checking — so Content opened barely
   taller than the Excerpt box beneath it, which is three lines of
   summary. An article is not written three lines at a time.

   One token, so the plain textarea and the editable surface that
   replaces it are always the same height and the field does not jump
   when the script finishes loading. It grows with the room available
   rather than being one number everywhere. */
.sh-ac-editor {
    --sh-ac-editor-min: 280px;
    --sh-ac-editor-max: 70vh;
}

/* The wrapper owns the frame now; the textarea inside must not draw a second. */
.sh-ac-editor-input {
    border: 0;
    border-radius: 0;
    min-height: var(--sh-ac-editor-min);
    resize: vertical;
}

.sh-ac-editor-input:focus {
    box-shadow: none;
}

/* -- The editable surface ------------------------------------------------- */

/* Once `sh-editor.js` has upgraded the field, the textarea is still the
   thing that submits — it is simply not the thing anybody types into.
   `display: none` rather than `.sh-sr-only`, because it must not be
   reachable by tab: two controls for one value is a confusing form. */
.sh-ac-editor.is-rte .sh-ac-editor-source {
    display: none;
}

.sh-ac-rte {
    min-height: var(--sh-ac-editor-min);
    /* Scrolls inside itself rather than growing without limit, so the
       toolbar stays in reach on a long article instead of scrolling
       off the top of the window. */
    max-height: var(--sh-ac-editor-max);
    overflow-y: auto;
    padding: var(--sh-sp-3);
    font-size: var(--sh-fs-sm);
    line-height: var(--sh-lh-relaxed);
    color: var(--sh-text);
    background: var(--sh-surface);
    /* `break-word`, never `anywhere` — a pasted URL must not be allowed
       to drop the column's min-content width to one character. */
    overflow-wrap: break-word;
}

.sh-ac-rte:focus {
    outline: none;
}

/* A contenteditable has no placeholder of its own, so the attribute the
   script copies off the textarea is drawn here. `:empty` alone is not
   enough: an editor that has been typed in and cleared keeps a `<br>`. */
.sh-ac-rte:empty::before,
.sh-ac-rte:has(> p:only-child:empty)::before,
.sh-ac-rte:has(> br:only-child)::before {
    content: attr(data-sh-rte-placeholder);
    color: var(--sh-text-subtle);
    pointer-events: none;
}

/* The editor shows what the article will look like, so these mirror the
   article page rather than inheriting the admin form's flat text. */
.sh-ac-rte > :first-child {
    margin-top: 0;
}

.sh-ac-rte > :last-child {
    margin-bottom: 0;
}

.sh-ac-rte p {
    margin: 0 0 var(--sh-sp-3);
}

.sh-ac-rte h2,
.sh-ac-rte h3,
.sh-ac-rte h4 {
    margin: var(--sh-sp-4) 0 var(--sh-sp-2);
    font-weight: var(--sh-fw-bold);
    line-height: var(--sh-lh-tight);
    color: var(--sh-text-strong);
}

.sh-ac-rte h2 {
    font-size: var(--sh-fs-xl);
}

.sh-ac-rte h3 {
    font-size: var(--sh-fs-lg);
}

.sh-ac-rte h4 {
    font-size: var(--sh-fs-base);
}`, so a list typed in
   here has to ask for its markers back — otherwise pressing Bulleted
   list appears to do nothing at all. */
.sh-ac-rte ul,
.sh-ac-rte ol {
    margin: 0 0 var(--sh-sp-3);
    padding-inline-start: var(--sh-sp-5);
}

.sh-ac-rte ul {
    list-style: disc;
}

.sh-ac-rte ol {
    list-style: decimal;
}

.sh-ac-rte li {
    margin-bottom: var(--sh-sp-1);
}

.sh-ac-rte blockquote {
    margin: 0 0 var(--sh-sp-3);
    padding-inline-start: var(--sh-sp-3);
    border-inline-start: 3px solid var(--sh-primary-500);
    color: var(--sh-text-muted);
}

.sh-ac-rte a {
    color: var(--sh-primary-600);
    text-decoration: underline;
}

.sh-ac-rte code {
    padding: 0.1em 0.35em;
    border-radius: var(--sh-radius-xs);
    font-family: var(--sh-font-mono);
    font-size: 0.9em;
    background: var(--sh-surface-sunken);
}

/* Media the author has placed is governed by `.sh-media` in
   sh-components.css, which the published page loads too — so what is
   sized here is what a reader gets. These rules are only for content
   written before that existed: `:not(.sh-media)` keeps them from
   beating a width class, which `.sh-ac-rte iframe { width: 100% }`
   would have done every time. */
.sh-ac-rte img:not(.sh-media),
.sh-ac-rte iframe:not(.sh-media) {
    max-width: 100%;
    border-radius: var(--sh-radius-sm);
}

.sh-ac-rte iframe:not(.sh-media) {
    aspect-ratio: 16 / 9;
    width: 100%;
    border: 0;
}

/* -- Selecting a picture or a video -------------------------------------- */

/* Clicking one selects it and opens the second toolbar row. The outline
   is how you know which one the controls are about when there are
   several in a long article. */
.sh-ac-rte .is-selected {
    outline: 2px solid var(--sh-primary-500);
    outline-offset: 2px;
}

/* A video cannot be clicked while its player is live — the iframe eats
   the event — so a selected one is made inert and the click lands. */
.sh-ac-editor.is-placing .sh-ac-rte iframe {
    pointer-events: none;
}

.sh-ac-mediabar {
    display: none;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--sh-sp-3);
    padding: var(--sh-sp-2) var(--sh-sp-3);
    border-top: 1px solid var(--sh-border);
    background: var(--sh-surface-alt);
}

.sh-ac-editor.is-placing .sh-ac-mediabar {
    display: flex;
}

.sh-ac-mediabar-group {
    display: flex;
    align-items: center;
    gap: var(--sh-sp-2);
}

.sh-ac-mediabar-label {
    font-size: var(--sh-fs-xs);
    font-weight: var(--sh-fw-medium);
    color: var(--sh-text-muted);
    white-space: nowrap;
}

/* Fixed width so the number changing from 100 to 50 does not shuffle
   the slider sideways under the pointer mid-drag. */
.sh-ac-mediabar-value {
    min-width: 4ch;
    font-family: var(--sh-font-mono);
    font-size: var(--sh-fs-xs);
    color: var(--sh-text-strong);
}

.sh-ac-mediabar-range {
    width: 160px;
    accent-color: var(--sh-primary-600);
}

.sh-ac-mediabar-spacer {
    margin-inline-start: auto;
}

/* A pressed toolbar button, so the bar reports the text under the caret. */
.sh-ac-toolbar .sh-icon-btn.is-active {
    color: var(--sh-primary-700);
    background: var(--sh-primary-50);
}

/* An image upload is the one action here that takes a visible moment, so
   the editor says so rather than appearing to have ignored the click. */
.sh-ac-editor.is-busy {
    position: relative;
}

.sh-ac-editor.is-busy::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    background: var(--sh-surface-veil);
}

.sh-ac-editor.is-busy .sh-ac-rte {
    pointer-events: none;
}

.sh-ac-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sh-sp-2);
    flex-wrap: wrap;
    padding: var(--sh-sp-2);
    border-top: 1px solid var(--sh-border);
    background: var(--sh-surface-alt);
}

.sh-ac-toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-wrap: wrap;
}

/* The CTA colours live in sh-components.css: the admin preview and the
   live ad on the member panel must paint from the same four classes, and
   the member panel never loads this stylesheet. */

/* ==========================================================================
   Create / Edit Page
   ========================================================================== */

.sh-ac-blockpick {
    width: auto;
    min-width: 132px;
    margin-inline-end: var(--sh-sp-2);
}

/* `.sh-select-sm` moved to sh-components.css: three admin screens that
   load only sh-admin-modules.css were using it, so the rule never
   applied and the select rendered full size with its longest label
   clipped. Anything two surfaces share belongs in the shared file. */

/* Full-screen editor. Fixed rather than a dialog: the field keeps its name
   and value, so the form still submits whatever state it is left in. */
.sh-ac-editor.is-expanded {
    position: fixed;
    inset: 0;
    z-index: var(--sh-z-modal);
    display: flex;
    flex-direction: column;
    border-radius: 0;
    background: var(--sh-surface);
}

.sh-ac-editor.is-expanded .sh-ac-editor-input {
    flex: 1 1 auto;
    resize: none;
}

/* The editable surface caps its own height for the inline case; full
   screen is the one place that cap is wrong. */
.sh-ac-editor.is-expanded .sh-ac-rte {
    flex: 1 1 auto;
    max-height: none;
}

/* Toolbar above the field rather than below it, as in the design. */
.sh-ac-toolbar-top {
    border-top: 0;
    border-bottom: 1px solid var(--sh-border);
}

@media (min-width: 768px) {
    /* A tablet has the room, and an article wants it. */
    .sh-ac-editor {
        --sh-ac-editor-min: 380px;
    }
}


@media (min-width: 1280px) {
    .sh-ac-editor {
        --sh-ac-editor-min: 480px;
    }
}

/* A reply box is not an article. The height is already a token, so a
   modifier re-points it rather than restating the rules. */
.sh-ac-editor-compact {
    --sh-ac-editor-min: 140px;
    --sh-ac-editor-max: 420px;
}
