/* ==========================================================================
   Forums
   --------------------------------------------------------------------------
   The board, a forum's thread list, and a discussion.

   Narrowest-first, and sized by **container** rather than viewport. A
   forum row carries four things — icon, title, counts, latest poster —
   which is three too many for a narrow column, so by default they stack
   and the counts become one quiet line under the title.

   The widening rules at the bottom are `@container`, not `@media`, on
   purpose: the centre column here is about 628px at a 1280 viewport
   with both rails on, and narrower again if a page asks for fewer
   columns. Keyed on the window, the four-track row and the four-up
   tiles both fired while the column was half the width they need, and
   the tile labels painted outside their cards.

   Loaded by the forum pages only, via @push('app-styles'). It sits on top
   of sh-community.css, which supplies the surface these pages live on.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Breadcrumb
   -------------------------------------------------------------------------- */

.sh-fm-crumbs {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--sh-sp-1);
    font-size: var(--sh-fs-sm);
    color: var(--sh-text-muted);
}

.sh-fm-crumbs a {
    color: var(--sh-text-muted);
    text-decoration: none;
}

.sh-fm-crumbs a:hover {
    color: var(--sh-primary-600);
    text-decoration: underline;
}

.sh-fm-crumbs svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    opacity: 0.6;
}

/* --------------------------------------------------------------------------
   The board's counted tiles
   -------------------------------------------------------------------------- */

/* The board's own query container. Scoped with `:has()` so only the
   forum pages gain containment — `.sh-community` is shared with groups,
   events, pages and the marketplace. */
.sh-community:has(.sh-fm-stats) {
    container: shboard / inline-size;
}

/* Two or four, never three. `auto-fit` counts its own tracks, which is
   right in general and wrong for a fixed set of four tiles: at 628px it
   gave three across with "Contributors" wrapped onto a row of its own.
   A viewport query was worse still — it switched to four at 768 while
   the column was 628, leaving each tile 148px and the label painting
   outside its card. */
.sh-fm-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sh-sp-3);
}

.sh-fm-stat {
    display: flex;
    align-items: center;
    gap: var(--sh-sp-3);
    padding: var(--sh-sp-4);
    background: var(--sh-surface);
    border: 1px solid var(--sh-border);
    border-radius: var(--sh-radius-lg);
}

/* A span with no display is an inline box, so the two lines inside
   would run together on one. */
.sh-fm-stat-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* `min-width: 0` above lets the box shrink; it does not stop a long
   word painting outside it. These do. */
.sh-fm-stat-value,
.sh-fm-stat-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sh-fm-stat-value {
    font-size: var(--sh-fs-xl);
    font-weight: var(--sh-fw-bold);
    color: var(--sh-text-strong);
    line-height: 1.1;
}

.sh-fm-stat-label {
    font-size: var(--sh-fs-sm);
    color: var(--sh-text-muted);
}

/* --------------------------------------------------------------------------
   A list of forums, and a list of threads
   -------------------------------------------------------------------------- */

/* A query container, so the rows inside size themselves against the
   column they are in rather than the window. The same reasoning as
   `.sh-widget`, and the fix for the same bug Related Reels and the
   inbox thread pane both had: measure the pane, not the viewport. */
.sh-fm-list {
    container-type: inline-size;
    list-style: none;
    margin: 0;
    padding: 0;
}

.sh-fm-row,
.sh-fm-thread {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: var(--sh-sp-3);
    padding: var(--sh-sp-4);
    border-top: 1px solid var(--sh-border);
}

.sh-fm-list > :first-child {
    border-top: 0;
}

.sh-fm-row:hover,
.sh-fm-thread:hover {
    background: var(--sh-surface-sunken);
}

/* A pinned thread is marked by a rule down its edge rather than a
   background: the hover tint already owns the background, and two
   tints fighting reads as a rendering fault. */
.sh-fm-thread.is-pinned {
    border-inline-start: 3px solid var(--sh-primary-500);
}

.sh-fm-row-icon {
    flex-shrink: 0;
}

.sh-fm-row-body,
.sh-fm-thread-body {
    display: flex;
    flex-direction: column;
    gap: var(--sh-sp-1);
    min-width: 0;
}

.sh-fm-row-title,
.sh-fm-thread-title {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--sh-sp-2);
    font-size: var(--sh-fs-base);
    font-weight: var(--sh-fw-semibold);
    color: var(--sh-text-strong);
    text-decoration: none;
    /* break-word, never `anywhere` — the latter drops min-content to a
       single character and starves the column, which has caused three
       separate bugs in this codebase. */
    overflow-wrap: break-word;
}

.sh-fm-row-title:hover,
.sh-fm-thread-title:hover {
    color: var(--sh-primary-600);
}

.sh-fm-row-text,
.sh-fm-thread-meta {
    font-size: var(--sh-fs-sm);
    color: var(--sh-text-muted);
    overflow-wrap: break-word;
}

.sh-fm-thread-flags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sh-sp-1);
}

.sh-fm-thread-flags:empty {
    display: none;
}

.sh-fm-thread-flags .sh-badge svg {
    width: 12px;
    height: 12px;
}

/* On a phone the counts are one quiet line under the title rather than
   a column of their own. */
.sh-fm-row-counts,
.sh-fm-thread-counts {
    grid-column: 2;
    display: flex;
    flex-wrap: wrap;
    gap: var(--sh-sp-3);
    font-size: var(--sh-fs-sm);
    color: var(--sh-text-muted);
}

.sh-fm-count {
    display: inline-flex;
    align-items: baseline;
    gap: var(--sh-sp-1);
}

.sh-fm-count strong {
    color: var(--sh-text-strong);
}

/* With no column of its own the latest poster sits under the title
   beside the counts, rather than being dropped. On a forum row it is
   the only place that information appears at all, and hiding it left
   a wide empty gap down the middle of every row. */
.sh-fm-row-latest,
.sh-fm-thread-latest {
    grid-column: 2;
    display: flex;
    align-items: center;
    gap: var(--sh-sp-2);
    min-width: 0;
}

.sh-fm-row-latest-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
    font-size: var(--sh-fs-sm);
}

.sh-fm-row-when {
    color: var(--sh-text-muted);
    font-size: var(--sh-fs-xs);
}

/* --------------------------------------------------------------------------
   A discussion and its replies
   -------------------------------------------------------------------------- */

/* The opening post, set apart from the replies below it: an accent rule
   down the leading edge, so the question is findable after scrolling
   back up a long thread. */
.sh-fm-post {
    border-inline-start: 3px solid var(--sh-primary-500);
}

.sh-fm-post-head {
    display: flex;
    align-items: center;
    gap: var(--sh-sp-3);
}

.sh-fm-post-who {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1 1 0;
}

.sh-fm-post-name {
    font-weight: var(--sh-fw-semibold);
    color: var(--sh-text-strong);
    text-decoration: none;
}

.sh-fm-post-name:hover {
    color: var(--sh-primary-600);
}

.sh-fm-post-when {
    font-size: var(--sh-fs-sm);
    color: var(--sh-text-muted);
}

.sh-fm-post-actions {
    display: flex;
    align-items: center;
    gap: var(--sh-sp-1);
    flex-shrink: 0;
}

/* The accepted-answer button, once it has been awarded. */
.sh-fm-post-actions .sh-icon-btn.is-active {
    color: var(--sh-success-600);
}

.sh-fm-post-title {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--sh-sp-2);
    margin: var(--sh-sp-4) 0 var(--sh-sp-3);
    font-size: var(--sh-fs-2xl);
    font-weight: var(--sh-fw-bold);
    letter-spacing: -0.02em;
    color: var(--sh-text-strong);
    overflow-wrap: break-word;
}

.sh-fm-post-title .sh-badge svg {
    width: 12px;
    height: 12px;
}

.sh-fm-post-body {
    font-size: var(--sh-fs-base);
    line-height: 1.7;
    color: var(--sh-text);
    overflow-wrap: break-word;
}

.sh-fm-post-body p {
    margin: 0 0 var(--sh-sp-3);
}

.sh-fm-post-body p:last-child {
    margin-bottom: 0;
}

/* The global reset is `ul, ol { list-style: none }`, so without this a
   list typed into a reply renders as unmarked paragraphs — the same
   trap the Updates changelog and the rich-text editor both hit. */
.sh-fm-post-body ul,
.sh-fm-post-body ol {
    list-style: revert;
    padding-inline-start: var(--sh-sp-6);
    margin: 0 0 var(--sh-sp-3);
}

.sh-fm-post-body a {
    color: var(--sh-primary-600);
}

.sh-fm-reply {
    margin-top: var(--sh-sp-3);
}

.sh-fm-reply.is-best {
    border-color: var(--sh-success-500);
}

.sh-fm-best-flag {
    display: flex;
    align-items: center;
    gap: var(--sh-sp-2);
    margin: 0 0 var(--sh-sp-3);
    font-size: var(--sh-fs-sm);
    font-weight: var(--sh-fw-semibold);
    color: var(--sh-success-700);
}

.sh-fm-best-flag svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.sh-fm-signin {
    text-align: center;
    color: var(--sh-text-muted);
}

/* ==========================================================================
   Wider columns
   --------------------------------------------------------------------------
   Container queries, not media queries. A container query adds no
   specificity, so these must come after every plain `.sh-fm-*` rule or
   source order decides it — the trap the widget container block
   documents.
   ========================================================================== */

/* Enough room to put the counts beside the title instead of under it. */
@container (min-width: 520px) {
    .sh-fm-row,
    .sh-fm-thread {
        grid-template-columns: auto minmax(0, 1fr) auto;
        align-items: center;
    }

    .sh-fm-row-counts,
    .sh-fm-thread-counts {
        grid-column: auto;
        justify-content: flex-end;
        gap: var(--sh-sp-4);
        text-align: end;
    }

    .sh-fm-thread-counts {
        display: grid;
        grid-template-columns: repeat(2, 72px);
        gap: var(--sh-sp-2);
    }

    .sh-fm-count {
        flex-direction: column;
        align-items: center;
        gap: 0;
    }
}

/* Only now does the latest poster earn a column of its own. Below this
   the title would be squeezed to a couple of words, which is what made
   the rows read as broken. */
@container (min-width: 760px) {
    .sh-fm-row,
    .sh-fm-thread {
        grid-template-columns: auto minmax(0, 1fr) auto 172px;
    }

    .sh-fm-row-latest,
    .sh-fm-thread-latest {
        grid-column: auto;
    }
}

/* Four tiles across, once each one has room for its label. */
@container shboard (min-width: 700px) {
    .sh-fm-stats {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}
