/*
 * News pages - /news and /admin/news - drawn with the page shell's tokens.
 *
 * Everything is scoped under body.shell so the file is inert on a classic page, and every colour,
 * radius and gutter is a --shell-*/--sl-*/--brand-* token, so the dark theme and an application's
 * own Bootstrap build reach it without this file knowing about either.
 */

/* ── /news ─────────────────────────────────────────────────────────── */

/* The reading column is the CARD, not the text inside it: a card at container width with prose
   capped at 72ch leaves half of every card empty, which reads as a layout mistake rather than as a
   measure. The card is sized to the measure instead, and an image is free to use the whole of it. */
body.shell .news-page {
    max-width: 1000px;
}

body.shell .news-hero {
    margin-bottom: 28px;
}

body.shell .news-hero h1 {
    font-size: 26px;
    font-weight: 650;
    letter-spacing: -0.02em;
    color: var(--sl-900);
    margin: 0 0 6px;
}

body.shell .news-hero-sub {
    margin: 0;
    font-size: 13.5px;
    color: var(--sl-500);
}

body.shell .news-layout {
    display: grid;
    grid-template-columns: 148px minmax(0, 760px);
    justify-content: start;
    gap: 32px;
    align-items: start;
}

/* the year rail */
body.shell .news-years {
    position: sticky;
    top: calc(var(--shell-topbar-h) + 16px);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

body.shell .news-years-label {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sl-400);
    padding: 0 10px 8px;
}

body.shell .news-year-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 10px;
    border-radius: var(--shell-radius);
    border-left: 2px solid transparent;
    font-size: 13px;
    font-weight: 500;
    color: var(--sl-600);
    text-decoration: none;
    transition: background-color .12s, color .12s;
}

body.shell .news-year-link:hover {
    background: var(--sl-surface-2);
    color: var(--sl-800);
}

body.shell .news-year-link.active {
    background: var(--brand-50);
    border-left-color: var(--brand-600);
    color: var(--brand-700);
    font-weight: 650;
}

body.shell .news-year-count {
    font-size: 11px;
    font-weight: 600;
    color: var(--sl-500);
    background: var(--sl-100);
    border-radius: 999px;
    padding: 1px 7px;
}

body.shell .news-year-link.active .news-year-count {
    background: var(--brand-100);
    color: var(--brand-700);
}

/* year sections */
body.shell .news-year + .news-year {
    margin-top: 34px;
}

body.shell .news-year-heading {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--sl-400);
    margin: 0 0 14px;
}

body.shell .news-year-heading::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--sl-border);
}

/* an article */
body.shell .news-card {
    position: relative;
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 18px;
    background: var(--sl-surface);
    border: 1px solid var(--sl-border);
    border-radius: var(--shell-radius-lg);
    padding: 20px 22px;
    transition: border-color .12s, box-shadow .12s;
}

body.shell .news-card + .news-card {
    margin-top: 12px;
}

body.shell .news-card:hover {
    border-color: var(--sl-border-strong);
    box-shadow: 0 1px 3px rgba(15, 23, 42, .06);
}

body.shell .news-card:target {
    border-color: var(--brand-600);
    box-shadow: 0 0 0 3px var(--brand-100);
}

body.shell .news-card-date {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 2px;
    border-right: 1px solid var(--sl-border);
    margin-right: -4px;
}

body.shell .news-card-day {
    font-size: 22px;
    font-weight: 650;
    line-height: 1;
    color: var(--sl-800);
}

body.shell .news-card-mon {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--brand-600);
    margin-top: 4px;
}

body.shell .news-card-title {
    font-size: 16px;
    font-weight: 650;
    color: var(--sl-900);
    margin: 0 0 4px;
    padding-right: 74px;
    letter-spacing: -0.01em;
}

body.shell .news-card-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 11.5px;
    color: var(--sl-400);
    margin-bottom: 12px;
}

/* ── the article body: making editor output read well ────────────────
 *
 * Everything inside .news-body is Quill output written by a non-technical author, rendered with
 * utext. We cannot change what is stored - years of entries already exist - so the whole of the
 * typography has to be recoverable from CSS alone. Four things about the stored HTML drive this
 * block, and each of them is visible in the entries currently on /news:
 *
 *   1. Heading LEVEL carries no meaning. The same rank is written <h4> in one entry, <h2><strong>
 *      in the next and <h3> in a third; an <h2> at browser size is bigger than the article's own
 *      title. So level is ignored: every heading gets one look, and rank is expressed by the two
 *      kinds below rather than by the tag.
 *
 *   2. A paragraph whose whole content is bold IS a heading - <p><strong>Materials Portal API
 *      </strong></p> is how every sub-section in the release notes is written. Styling it as a
 *      paragraph is why those articles read as a wall of text. :has() picks it out; shell.css
 *      already relies on :has(), so this is not a new requirement of the browser.
 *
 *   3. Empty blocks are the author's paragraph breaks. Quill writes <p></p>, <p><br></p> and even
 *      <h3></h3> where the author pressed Enter twice. Rendered, they stack random 12-24px gaps.
 *      They are removed and the rhythm is set by margins instead, which is the only way it can be
 *      the same in every entry.
 *
 *   4. Nothing constrains the measure. A release note at container width runs to 200 characters a
 *      line, which is roughly twice what is comfortable to read.
 */

body.shell .news-body {
    /* A second cap, under the card's own. The card is already sized to the measure, but a wide
       viewport, a product that widens the card, or the admin preview must not stretch the line. */
    max-width: 74ch;
    font-size: 14px;
    line-height: 1.75;
    color: var(--sl-700);
    /* Stops a heading or a headline breaking to leave one word on the last line. */
    text-wrap: pretty;
    overflow-wrap: break-word;
}

body.shell .news-body > *:first-child { margin-top: 0 !important; }
body.shell .news-body > *:last-child { margin-bottom: 0 !important; }

/* 3. the author's blank lines - removed, so the margins below are the only source of rhythm */
body.shell .news-body > p:empty,
body.shell .news-body > h1:empty,
body.shell .news-body > h2:empty,
body.shell .news-body > h3:empty,
body.shell .news-body > h4:empty,
body.shell .news-body > h5:empty,
body.shell .news-body > h6:empty,
body.shell .news-body > p:has(> br:only-child) {
    display: none;
}

body.shell .news-body p {
    margin: 0 0 14px;
}

/* The opening paragraph, whatever it is, sets the tone of the entry: a touch larger and darker, so
   every article - long or short, well written or not - starts with something that reads as a lede.
   :first-of-type would lose to a leading empty <p>, which is why it is written by exclusion. */
body.shell .news-body > p:not(:empty):first-of-type {
    font-size: 15px;
    line-height: 1.65;
    color: var(--sl-800);
    margin-bottom: 18px;
}

/* 1. a section heading - any level, one look */
body.shell .news-body h1,
body.shell .news-body h2,
body.shell .news-body h3,
body.shell .news-body h4,
body.shell .news-body h5,
body.shell .news-body h6 {
    font-size: 15px;
    font-weight: 650;
    line-height: 1.35;
    letter-spacing: -0.01em;
    color: var(--sl-900);
    margin: 30px 0 10px;
    padding-bottom: 7px;
    border-bottom: 1px solid var(--sl-border);
    text-wrap: balance;
}

/* The author often bolds the heading text as well; the heading is already bold. */
body.shell .news-body :is(h1, h2, h3, h4, h5, h6) strong,
body.shell .news-body :is(h1, h2, h3, h4, h5, h6) b {
    font-weight: inherit;
}

body.shell .news-body :is(h1, h2, h3, h4, h5, h6) em {
    font-style: normal;
    color: var(--sl-500);
    font-weight: 500;
}

/* 2. a bold-only paragraph is a sub-heading, not prose.
      The class is set by news.js, not by p:has(> strong:only-child): :only-child counts ELEMENT
      children, so that selector also matches <p>Our improved <strong>user interface</strong> now
      includes ...</p> and sets the whole sentence in bold. */
body.shell .news-body > p.news-subhead {
    font-size: 13.5px;
    font-weight: 650;
    color: var(--sl-800);
    margin: 20px 0 6px;
    letter-spacing: -0.005em;
}

body.shell .news-body > p.news-subhead strong,
body.shell .news-body > p.news-subhead b {
    font-weight: inherit;
}

/* A sub-heading straight after a section heading should not open a second gap. */
body.shell .news-body :is(h1, h2, h3, h4, h5, h6) + p.news-subhead {
    margin-top: 12px;
}

/* …and a section heading opening the entry, or following the lede, keeps its distance modest. */
body.shell .news-body > *:first-child:is(h1, h2, h3, h4, h5, h6) {
    margin-top: 0;
}

body.shell .news-body strong,
body.shell .news-body b {
    font-weight: 650;
    color: var(--sl-900);
}

body.shell .news-body em { color: var(--sl-600); }

/* Lists. The release notes are mostly lists, and they are always introduced by the sentence above
   them - so that sentence keeps its list close, and the list is set with its own marker rather
   than the browser's, which sits too far out at this measure. */
body.shell .news-body ul,
body.shell .news-body ol {
    margin: 0 0 16px;
    padding-left: 0;
    list-style: none;
}

body.shell .news-body li {
    position: relative;
    padding-left: 20px;
    margin-bottom: 7px;
}

body.shell .news-body li:last-child { margin-bottom: 0; }

body.shell .news-body ul > li::before {
    content: "";
    position: absolute;
    left: 5px;
    top: 0.62em;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--brand-500);
}

body.shell .news-body ol { counter-reset: news-ol; }

body.shell .news-body ol > li {
    counter-increment: news-ol;
    padding-left: 26px;
}

body.shell .news-body ol > li::before {
    content: counter(news-ol) ".";
    position: absolute;
    left: 0;
    top: 0;
    font-variant-numeric: tabular-nums;
    font-weight: 650;
    color: var(--brand-600);
}

body.shell .news-body li > ul,
body.shell .news-body li > ol { margin: 7px 0 0; }

/* the lead-in sentence stays with its list */
body.shell .news-body p:has(+ ul),
body.shell .news-body p:has(+ ol) { margin-bottom: 8px; }

body.shell .news-body a {
    color: var(--brand-700);
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-thickness: 1px;
    text-decoration-color: var(--brand-200);
}

body.shell .news-body a:hover { text-decoration-color: var(--brand-600); }

/* An external link says so, so a reader knows the tab is about to change. */
body.shell .news-body a[target="_blank"]::after {
    content: "\F03CC";                    /* mdi-open-in-new */
    font-family: "Material Design Icons";
    font-size: 0.8em;
    margin-left: 3px;
    opacity: .5;
    text-decoration: none;
    vertical-align: 1px;
}

body.shell .news-body blockquote {
    margin: 0 0 16px;
    padding: 4px 0 4px 16px;
    border-left: 3px solid var(--brand-200);
    color: var(--sl-600);
    font-style: italic;
}

body.shell .news-body hr {
    border: 0;
    border-top: 1px solid var(--sl-border);
    margin: 24px 0;
}

body.shell .news-body code,
body.shell .news-body .ql-code-block {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.88em;
    background: var(--sl-100);
    border-radius: var(--shell-radius-sm);
    padding: 1px 5px;
}

/* ── media ───────────────────────────────────────────────────────────
 *
 * An author pastes a screenshot at its natural size and as a data: URI. It is constrained here, and
 * it is allowed to break out of the text measure, because a 16:9 screenshot at 72ch is unreadable.
 */

/* Media may use the whole width of the card even though the prose stops at its measure - a 16:9
   screenshot set to 74ch is unreadable. No width: max-content: it sizes to what the content wants
   and a wide table then hangs out past the card. */
body.shell .news-body :is(img, figure, table) {
    max-width: 100%;
}

/* Height matters as much as width. Authors paste portrait document scans - a standard page at
   860px wide is over 1200px tall and pushes everything after it off the screen - so an image is
   capped on both axes and centred in whatever room is left. */
body.shell .news-body img {
    display: block;
    max-width: 100%;
    max-height: 460px;
    width: auto;
    height: auto;
    margin: 20px 0;
    border: 1px solid var(--sl-border);
    border-radius: var(--shell-radius);
    background: var(--sl-surface-2);
}

body.shell .news-body figure { margin: 20px 0; }
body.shell .news-body figure img { margin: 0 0 8px; }

body.shell .news-body figcaption {
    font-size: 12px;
    color: var(--sl-500);
    line-height: 1.5;
    max-width: 72ch;
}

/* Two or three images side by side without the author having to build a table. */
body.shell .news-body table {
    border-collapse: collapse;
    font-size: 13px;
    margin: 0 0 18px;
    width: auto;
}

body.shell .news-body table th,
body.shell .news-body table td {
    border: 1px solid var(--sl-border);
    padding: 7px 12px;
    text-align: left;
}

body.shell .news-body table th {
    background: var(--sl-surface-2);
    font-weight: 650;
    color: var(--sl-800);
}

/* ── the read-more clamp ────────────────────────────────────────────
 *
 * A release note runs to 600 words, and five of them expanded is a page nobody scrolls to the end
 * of. An entry longer than the threshold is cut at a fixed height with a fade and opens in place.
 *
 * It is not a <details>: a browser hides every non-summary child of a closed one, so there is no
 * way to show the first 200px of the article in it. news.js wraps a long entry in .news-more and
 * appends the button; with the script blocked nothing is wrapped and every entry renders in full,
 * which is the behaviour /news has today.
 */

body.shell .news-more {
    position: relative;
}

body.shell .news-more-toggle {
    -webkit-appearance: none;
    appearance: none;
    background: none;
    border: 0;
    padding: 0;
}

body.shell .news-more:not(.is-open) .news-body {
    max-height: 200px;
    overflow: hidden;
}

body.shell .news-more-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin: 12px 0 0;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--brand-600);
    cursor: pointer;
    user-select: none;
}

body.shell .news-more-toggle:hover { color: var(--brand-700); }

/* The fade sits on the toggle rather than on the body: the body has overflow:hidden, and a fade
   drawn inside it is clipped away at exactly the edge it is there to soften. */
body.shell .news-more:not(.is-open) .news-more-toggle::before {
    content: "";
    position: absolute;
    left: 0;
    right: -600px;
    bottom: 100%;
    height: 72px;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0), var(--sl-surface));
    pointer-events: none;
}

body.shell .news-more-toggle:focus-visible {
    outline: 2px solid var(--brand-600);
    outline-offset: 3px;
    border-radius: var(--shell-radius-sm);
}

body.shell .news-more-toggle i {
    font-size: 15px;
    transition: transform .15s;
}

body.shell .news-more.is-open .news-more-toggle i { transform: rotate(180deg); }
body.shell .news-more-toggle .news-more-less { display: none; }
body.shell .news-more.is-open .news-more-toggle .news-more-less { display: inline; }
body.shell .news-more.is-open .news-more-toggle .news-more-all { display: none; }

/* A short entry gets no toggle at all - the page only wraps one whose text passes the threshold. */

/* The permalink and the edit link, in the corner of a card. They are quiet until the card is
   hovered or something inside them takes focus: on an administrator's screen they otherwise sit
   beside every headline on the page, and only an administrator sees the edit one at all. */
body.shell .news-card-actions {
    position: absolute;
    top: 14px;
    right: 14px;
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity .12s;
}

body.shell .news-card:hover .news-card-actions,
body.shell .news-card-actions:focus-within {
    opacity: 1;
}

body.shell .news-card-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--shell-radius);
    color: var(--sl-500);
    text-decoration: none;
    font-size: 15px;
}

body.shell .news-card-action:hover {
    background: var(--sl-surface-2);
    color: var(--brand-600);
}

/* empty state */
body.shell .news-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 64px 24px;
    background: var(--sl-surface);
    border: 1px dashed var(--sl-border-strong);
    border-radius: var(--shell-radius-lg);
}

body.shell .news-empty i {
    font-size: 34px;
    color: var(--sl-300);
    margin-bottom: 12px;
}

body.shell .news-empty h2 {
    font-size: 16px;
    font-weight: 650;
    color: var(--sl-700);
    margin: 0 0 4px;
}

body.shell .news-empty p {
    font-size: 13px;
    color: var(--sl-500);
    margin: 0;
}

@media (max-width: 991.98px) {
    body.shell .news-layout {
        grid-template-columns: minmax(0, 1fr);
        gap: 18px;
    }

    body.shell .news-years {
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
        padding-bottom: 4px;
    }

    body.shell .news-years-label { display: none; }

    body.shell .news-year-link {
        border-left: 0;
        border: 1px solid var(--sl-border);
        padding: 5px 12px;
    }

    body.shell .news-year-link.active {
        border-color: var(--brand-200);
    }
}

@media (max-width: 575.98px) {
    body.shell .news-card {
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
        padding: 16px;
    }

    body.shell .news-card-date {
        flex-direction: row;
        align-items: baseline;
        gap: 6px;
        border-right: 0;
        border-bottom: 1px solid var(--sl-border);
        padding-bottom: 8px;
        margin-right: 0;
    }

    body.shell .news-card-day { font-size: 16px; }
    body.shell .news-card-title { padding-right: 0; }
    body.shell .news-card-actions { opacity: 1; position: static; justify-content: flex-end; }
}

/* ── /admin/news ───────────────────────────────────────────────────── */

body.shell .news-search {
    position: relative;
    min-width: 280px;
}

body.shell .news-search i {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--sl-400);
    font-size: 15px;
    pointer-events: none;
}

body.shell .news-search input {
    padding-left: 32px;
    height: 32px;
    font-size: 13px;
}


body.shell .news-admin-table th:last-child,
body.shell .news-admin-table td:last-child {
    text-align: right;
    white-space: nowrap;
}

body.shell .news-admin-title {
    font-weight: 600;
    color: var(--sl-900);
    text-decoration: none;
}

body.shell .news-admin-title:hover { color: var(--brand-600); }

body.shell .news-admin-excerpt {
    display: block;
    font-size: 12px;
    color: var(--sl-500);
    margin-top: 2px;
    max-width: 70ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* An entry with no summary. It is not an error - /news falls back to the first line of the
   article - but it is worth seeing at a glance which entries were written without one. */
body.shell .news-admin-missing {
    color: var(--bs-danger, #dc3545);
}

body.shell .news-admin-missing i {
    font-size: 13px;
    vertical-align: -1px;
}

body.shell .news-admin-id {
    font-variant-numeric: tabular-nums;
    font-size: 12px;
    color: var(--sl-400);
}

body.shell .news-admin-date {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

body.shell .news-admin-date small {
    display: block;
    color: var(--sl-400);
    font-size: 11px;
}

body.shell .news-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1px solid transparent;
    border-radius: var(--shell-radius);
    background: none;
    color: var(--sl-500);
    font-size: 16px;
    text-decoration: none;
}

body.shell .news-icon-btn:hover {
    background: var(--sl-surface-2);
    border-color: var(--sl-border);
    color: var(--sl-800);
}

body.shell .news-icon-btn.danger:hover {
    background: var(--bs-danger-bg-subtle, #fdecec);
    border-color: #f5c2c7;
    color: var(--bs-danger, #dc3545);
}

/* the editor */
body.shell .news-editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 20px;
    align-items: start;
}

body.shell .news-editor-side {
    position: sticky;
    top: calc(var(--shell-topbar-h) + 16px);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* The editor frame - the div Quill's toolbar and container are mounted into. These rules are what
   stop the snow theme looking like a different application: it ships its own greys, its own border
   radius and 13px Helvetica. */
body.shell .news-editor-frame {
    border: 1px solid var(--sl-border);
    border-radius: var(--shell-radius);
    overflow: hidden;
    background: var(--sl-surface);
}

body.shell .news-editor .ql-editor {
    min-height: 420px;
    padding: 16px 18px;
    font-size: 13.5px;
    line-height: 1.7;
    color: var(--sl-800);
}

/* The editor shows the author's own structure - it is not the place to apply the reading scale;
   that is what the preview below is for. It only has to be legible and not look foreign. */

body.shell .news-editor .ql-toolbar.ql-snow {
    border-color: var(--sl-border);
    border-radius: var(--shell-radius) var(--shell-radius) 0 0;
    background: var(--sl-surface-2);
}

body.shell .news-editor .ql-container.ql-snow {
    border-color: var(--sl-border);
    border-radius: 0 0 var(--shell-radius) var(--shell-radius);
    background: var(--sl-surface);
    font-family: inherit;
    font-size: 13.5px;
}

body.shell .news-editor .ql-editor {
    min-height: 460px;
}

body.shell .news-hint {
    font-size: 11.5px;
    color: var(--sl-500);
    margin-top: 5px;
}

body.shell .news-counter {
    font-variant-numeric: tabular-nums;
}

/* The preview sits under the editor at the width /news actually uses. Squeezed into the 320px
   settings column it showed six-word lines and every heading wrapping, which is not what a reader
   gets and made authors format around a problem that does not exist. */
body.shell .news-preview {
    margin-top: 20px;
    border: 1px solid var(--sl-border);
    border-radius: var(--shell-radius-lg);
    background: var(--sl-ground);
    padding: 16px;
    max-width: 800px;
}

body.shell .news-preview-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sl-400);
    margin-bottom: 10px;
}

@media (max-width: 1199.98px) {
    body.shell .news-editor {
        grid-template-columns: minmax(0, 1fr);
    }

    body.shell .news-editor-side {
        position: static;
    }
}
