/*
 * Media.com application shell.
 *
 * One layout system for every signed-in surface. The rail sits near the left edge of the
 * window, the discovery column near the right edge, and the content is centred on the
 * window itself, not on the space left between two columns of different widths.
 *
 * How the centring works: three grid tracks, minmax(rail, 1fr) | content | minmax(right, 1fr).
 * The two outer tracks share the spare space equally, so the content's centre is the shell's
 * centre. When the window is too narrow for that, the rail keeps its width and the content
 * gives up a little symmetry rather than width. No absolute positioning anywhere, so columns
 * can never overlap.
 *
 * Variants come from the body class set in inc/Layout.php:
 *   default / workspace  wide centred workspace, no discovery column
 *   media-layout--social reading-width column, optional discovery column
 *   media-layout--browse wider centred column for profiles and card grids
 *   media-layout--reading column sized for long text
 *
 * Phones (900px and below) keep the existing app-style layout untouched.
 */

:root {
    --mx-shell-max: 1680px;
    --mx-gutter: clamp(24px, 2vw, 32px);
    --mx-gap: 32px;
    --mx-nav-w: 220px;
    --mx-nav-icon-w: 56px;
    --mx-aside-w: 290px;
    --mx-social-w: 720px;
    --mx-reading-w: 760px;
    --mx-browse-w: 1040px;
    --mx-workspace-w: 1280px;
    --mx-search-w: 440px;
    --mx-sticky-top: calc(var(--media-header-height, 60px) + 16px);
    --mx-bp-aside: 1280px; /* documentation only: the discovery column shows from here */
}

/* ------------------------------------------------------------------ desktop shell */

@media (min-width: 1025px) {
    .media-shell,
    .media-discover__layout,
    .media-settings__inner:has(> .media-settings__layout) {
        --mx-main: var(--mx-workspace-w);
        --mx-right-min: 0px;
        box-sizing: border-box;
        width: 100%;
        max-width: var(--mx-shell-max);
        margin-left: auto;
        margin-right: auto;
        padding-left: var(--mx-gutter);
        padding-right: var(--mx-gutter);
        column-gap: var(--mx-gap);
        grid-template-columns: minmax(var(--mx-nav-w), 1fr) minmax(0, var(--mx-main)) minmax(var(--mx-right-min), 1fr);
        justify-content: stretch;
    }

    body.media-layout--social :is(.media-shell, .media-discover__layout) { --mx-main: var(--mx-social-w); }
    body.media-layout--reading .media-shell { --mx-main: var(--mx-reading-w); }
    body.media-layout--browse .media-shell { --mx-main: var(--mx-browse-w); }

    /* Workspace (Studio, Account): the content runs from the rail to the header's right edge (Nov 2026). */
    body.media-layout--workspace :is(.media-shell, .media-settings__inner:has(> .media-settings__layout)) { grid-template-columns: var(--mx-nav-w) minmax(0, 1fr); }
    body.media-layout--workspace .media-shell > .media-shell__content { max-width: none; }

    /* Rail: pinned to the left edge of its track, so it sits near the window's edge. */
    .media-shell > .media-shell__nav,
    .media-discover__layout > .media-shell__nav,
    .media-settings__inner:has(> .media-settings__layout) > .media-settings__layout > :is(.media-shell__nav, .media-settings__nav) {
        grid-column: 1;
        justify-self: start;
        width: var(--mx-nav-w);
        box-sizing: border-box;
    }

    .media-shell > .media-shell__content,
    .media-shell--feed .mfeed__main,
    .media-discover__layout > .media-discover__main {
        grid-column: 2;
        width: 100%;
        min-width: 0;
    }

    /* Discovery column: pinned to the right edge of its track. */
    .media-shell--feed .mfeed__aside,
    .media-discover__layout > .media-discover__right {
        grid-column: 3;
        justify-self: end;
        width: var(--mx-aside-w);
    }
}

/* The discovery column needs its own room; until then the content keeps all of its width. */
@media (min-width: 1280px) {
    .media-shell:has(.mfeed__aside),
    .media-discover__layout:has(> .media-discover__right) { --mx-right-min: var(--mx-aside-w); }
}

@media (max-width: 1279px) {
    .media-shell--feed .mfeed__aside { display: none; }
}

@media (min-width: 1025px) and (max-width: 1279px) {
    .media-discover__layout > .media-discover__right { display: none; }
}

/* ------------------------------------------------------------------ sticky columns */

/*
 * Both side columns stay put under the header while the page scrolls, and scroll on their
 * own only when they are taller than the window. The page itself remains the one scroller.
 */
@media (min-width: 901px) {
    .media-shell > .media-shell__nav,
    .media-discover__layout > .media-shell__nav,
    .media-shell--feed .mfeed__aside,
    .media-discover__layout > .media-discover__right {
        position: sticky;
        top: var(--mx-sticky-top);
        align-self: start;
        max-height: calc(100vh - var(--mx-sticky-top) - 16px);
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        scrollbar-color: transparent transparent;
    }

    .media-shell > .media-shell__nav:hover,
    .media-discover__layout > .media-shell__nav:hover,
    .media-shell--feed .mfeed__aside:hover,
    .media-discover__layout > .media-discover__right:hover { scrollbar-color: var(--media-border, #dfe5ec) transparent; }
}

/* ------------------------------------------------------------------ tablet: icon rail */

/*
 * 901 to 1024px: an icon-only rail beside a centred content column. Replaces the scrolling
 * row of pills the rail used to become at this size.
 */
@media (min-width: 901px) and (max-width: 1024px) {
    .media-shell,
    .media-discover__layout {
        box-sizing: border-box;
        max-width: none;
        padding-left: 24px;
        padding-right: 24px;
        column-gap: 24px;
        grid-template-columns: var(--mx-nav-icon-w) minmax(0, 1fr);
    }

    .media-shell > .media-shell__nav,
    .media-discover__layout > .media-shell__nav { display: block; grid-column: 1; width: var(--mx-nav-icon-w); padding-top: 0; }

    .media-shell__nav .media-discover__nav { display: grid; overflow: visible; margin-bottom: 0; gap: 2px; }
    .media-shell__nav .media-discover__nav-link { justify-content: center; padding-left: 0; padding-right: 0; }
    .media-shell__nav .media-discover__nav-link span,
    .media-shell__nav .media-shell__group-label,
    .media-shell__nav .media-shell__trust,
    .media-shell__nav .media-discover__trust,
    .media-shell__nav .media-shell__rule { display: none; }
    /* No room for the Publishing toggle, so its destinations always show. */
    .media-shell__nav .media-shell__group[hidden] { display: grid !important; }
    .media-shell__nav .media-shell__group-row { display: none; }
    .media-shell__nav .media-shell__group--nested { margin: 0; padding-left: 0; }
    .media-shell__nav .media-shell__group--primary { margin-bottom: 0; }

    .media-shell > .media-shell__content,
    .media-shell--feed .mfeed__main,
    .media-discover__layout > .media-discover__main { grid-column: 2; min-width: 0; }

    body:is(.media-layout--social, .media-layout--reading) .media-shell > .media-shell__content,
    .media-shell--feed .mfeed__main,
    .media-discover__layout > .media-discover__main { width: 100%; max-width: var(--mx-social-w); justify-self: center; }

    .media-shell--feed .mfeed__aside,
    .media-discover__layout > .media-discover__right { display: none; }
}

/* ------------------------------------------------------------------ header */

/*
 * On shell pages the header uses the shell's width and gutters: the wordmark sits over the
 * rail, the search field on the window's centre line, the account controls over the
 * discovery column.
 */
@media (min-width: 1025px) {
    body.media-layout .media-header__inner,
    body:has(.media-shell__nav) .media-header__inner {
        box-sizing: border-box;
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, var(--mx-search-w)) minmax(0, 1fr);
        column-gap: var(--mx-gap);
        max-width: var(--mx-shell-max);
        padding-left: var(--mx-gutter);
        padding-right: var(--mx-gutter);
    }

    body.media-layout .media-header__inner > .media-logo,
    body:has(.media-shell__nav) .media-header__inner > .media-logo { justify-self: start; }

    body.media-layout .media-header__inner > .media-search,
    body:has(.media-shell__nav) .media-header__inner > .media-search { grid-column: 2; width: 100%; }

    body.media-layout .media-header__inner > .media-search .media-search__field,
    body:has(.media-shell__nav) .media-header__inner > .media-search .media-search__field { max-width: var(--mx-search-w); }

    body.media-layout .media-header__inner > .media-header__actions,
    body:has(.media-shell__nav) .media-header__inner > .media-header__actions { grid-column: 3; justify-self: end; margin-left: 0; }
}

/* ------------------------------------------------------------------ reading pages */

@media (min-width: 901px) {
    .media-shell--reading .media-written { padding-top: 0; }
    .media-shell--reading .media-written__inner { padding-left: 0; padding-right: 0; }
}

/* Phones read publications exactly as before: no rail, no shell spacing. */
@media (max-width: 900px) {
    .media-shell.media-shell--reading { display: block; padding: 0; }
    .media-shell--reading > .media-shell__nav { display: none; }
}

/* ------------------------------------------------------------------ portrait media in the Feed */

/* A portrait video sits on the column's centre line rather than against its left edge. */
@media (min-width: 641px) {
    .media-shell--feed .mfeed-card__media--portrait { width: 100%; margin-left: auto; margin-right: auto; }
}

/* ------------------------------------------------------------------ the rail */

/*
 * One row style for every destination and every group heading: icon, label and, for a
 * group, a chevron. 42px rows, 20px icons, 12px between icon and label, 10px corners.
 * The current page gets a very light blue background with a blue icon and label;
 * hover is a light grey wash with no change to the row's size.
 */
.media-shell__nav {
    --nav-text: #3c4655;
    --nav-text-strong: #1c2533;
    --nav-icon: #6b7480;
    --nav-hover: #f2f4f7;
    --nav-active-bg: #edf3ff;
    --nav-active: var(--media-primary, #0b5fff);
    --nav-rule: #e9edf2;
}

.media-shell__nav .media-discover__nav {
    display: grid;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.media-shell__nav .media-shell__group[hidden] { display: none; }

.media-shell__nav .media-discover__nav-link,
.media-shell__nav .media-shell__group-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    min-height: 42px;
    margin: 0;
    padding: 0 12px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--nav-text);
    font: inherit;
    font-size: 14.5px;
    font-weight: 500;
    line-height: 1.3;
    letter-spacing: 0;
    text-transform: none;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}

.media-shell__nav .media-discover__nav-link > span,
.media-shell__nav .media-shell__group-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.media-shell__nav .media-nav-icon {
    flex: none;
    width: 20px;
    height: 20px;
    color: var(--nav-icon);
    transition: color .15s ease;
}

.media-shell__nav .media-discover__nav-link:hover,
.media-shell__nav .media-shell__group-row:hover { background: var(--nav-hover); color: var(--nav-text-strong); }

.media-shell__nav .media-discover__nav-link:hover .media-nav-icon,
.media-shell__nav .media-shell__group-row:hover .media-nav-icon { color: var(--nav-text-strong); }

.media-shell__nav .media-discover__nav-link[aria-current="page"],
.media-shell__nav .media-discover__nav-link[aria-current="page"]:hover {
    background: var(--nav-active-bg);
    color: var(--nav-active);
    font-weight: 600;
}

.media-shell__nav .media-discover__nav-link[aria-current="page"] .media-nav-icon { color: var(--nav-active); }

.media-shell__nav .media-discover__nav-link:focus-visible,
.media-shell__nav .media-shell__group-row:focus-visible {
    outline: 2px solid var(--nav-active);
    outline-offset: -2px;
}

/* Group rows. */
.media-shell__nav .media-shell__chevron {
    flex: none;
    margin-left: auto;
    color: #9aa2ad;
    transition: transform .2s ease;
}

.media-shell__nav .media-shell__group-row[aria-expanded="true"] .media-shell__chevron { transform: rotate(90deg); }

/* A closed group still says where you are. */
.media-shell__nav .media-shell__section[data-nav-current] > .media-shell__group-row[aria-expanded="false"],
.media-shell__nav .media-shell__section[data-nav-current] > .media-shell__group-row[aria-expanded="false"] .media-nav-icon { color: var(--nav-active); }

.media-shell__nav .media-shell__group--primary { margin-bottom: 10px; }
.media-shell__nav .media-shell__section + .media-shell__section { margin-top: 2px; }
.media-shell__nav .media-shell__group--nested { margin: 2px 0 6px; padding-left: 12px; }

.media-shell__nav .media-shell__group.is-opening { animation: mx-nav-open .18s ease-out; }
.media-shell__nav .media-shell__group.is-closing { animation: mx-nav-close .14s ease-in forwards; }

@keyframes mx-nav-open {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: none; }
}

@keyframes mx-nav-close {
    from { opacity: 1; transform: none; }
    to { opacity: 0; transform: translateY(-4px); }
}

@media (prefers-reduced-motion: reduce) {
    .media-shell__nav .media-shell__group.is-opening,
    .media-shell__nav .media-shell__group.is-closing { animation: none; }
    .media-shell__nav .media-shell__chevron,
    .media-shell__nav .media-discover__nav-link,
    .media-shell__nav .media-shell__group-row { transition: none; }
}

/* Settings: its own row at the foot of the rail, under a hairline. */
.media-shell__nav .media-shell__rule {
    height: 0;
    margin: 8px 12px;
    border: 0;
    border-top: 1px solid var(--nav-rule);
}

/*
 * On a desktop the rail fills the window's height so Settings settles at the bottom. When
 * the window is too short for every row, the rail scrolls on its own instead of overlapping.
 */
@media (min-width: 1025px) {
    .media-shell > .media-shell__nav,
    .media-discover__layout > .media-shell__nav {
        display: flex;
        flex-direction: column;
        height: calc(100vh - var(--mx-sticky-top) - 16px);
        max-height: none;
    }

    .media-shell__nav .media-shell__nav-foot { margin-top: auto; padding-top: 8px; }
}

/* A one-destination group (Earnings) renders as a direct row, spaced like the group rows around it. */
.media-shell__nav .media-shell__group--single { margin: 2px 0 0; padding: 0; }

/* Chevrons sit beside their label (Nov 2026): 7px after the text, 13px, right when closed, down when open. The whole row stays clickable. */
.media-shell__group-row { justify-content: flex-start !important; }
.media-shell__group-row .media-shell__group-name { flex: 0 1 auto !important; margin-right: 0 !important; }
.media-shell__group-row .media-shell__chevron { width: 13px !important; height: 13px !important; margin-left: 7px !important; flex: 0 0 auto; align-self: center; position: static !important; }

/* Closer still: the row's 12px gap was adding to the margin. Net ~4px after the label. */
.media-shell__group-row .media-shell__chevron { margin-left: -8px !important; }

/* Footer rows line up with the header: same maximum width and gutters (Nov 2026). */
@media (min-width: 1025px) {
    body.media-layout .media-footer > .media-container,
    body:has(.media-shell__nav) .media-footer > .media-container {
        box-sizing: border-box;
        max-width: var(--mx-shell-max);
        padding-left: var(--mx-gutter);
        padding-right: var(--mx-gutter);
    }
}

/* Section heads with a landing page (Nov 2026 navigation brief): the label navigates, the chevron opens and closes. One full-row hover. */
.media-shell__nav .media-shell__group-head { display: flex; align-items: center; width: 100%; border-radius: 10px; transition: background-color .15s ease; }
.media-shell__nav .media-shell__group-head:hover { background: var(--nav-hover); }
.media-shell__nav .media-shell__group-head .media-shell__group-link { width: auto; flex: 0 1 auto; padding-right: 2px; background: transparent !important; }
.media-shell__nav .media-shell__group-toggle { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 28px; height: 28px; margin: 0 auto 0 0; padding: 0; border: 0; border-radius: 7px; background: transparent; color: #9aa2ad; cursor: pointer; transition: background-color .15s ease, color .15s ease; }
.media-shell__nav .media-shell__group-toggle:hover { background: #e6eaf0; color: var(--nav-text-strong); }
.media-shell__nav .media-shell__group-toggle:focus-visible { outline: 2px solid var(--nav-active); outline-offset: -2px; }
.media-shell__nav .media-shell__group-toggle .media-shell__chevron { width: 13px; height: 13px; margin: 0; transition: transform .18s ease; }
.media-shell__nav .media-shell__group-toggle[aria-expanded="true"] .media-shell__chevron { transform: rotate(90deg); }
.media-shell__nav .media-shell__section[data-nav-current]:has(.media-shell__group-toggle[aria-expanded="false"]) .media-shell__group-link,
.media-shell__nav .media-shell__section[data-nav-current]:has(.media-shell__group-toggle[aria-expanded="false"]) .media-shell__group-link .media-nav-icon { color: var(--nav-active); }
@media (min-width: 901px) and (max-width: 1024px) {
    .media-shell__nav .media-shell__group-head { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .media-shell__nav .media-shell__group-toggle .media-shell__chevron { transition: none; }
}
/* ------------------------------------------------------------------ wide social layout */

/*
 * Feed, Explore and Discussions on wide screens (Layout brief, 21 Nov 2026).
 *
 * One set of tokens for the three pages: the right column sits a gutter from the window edge,
 * the content column sits a fixed gap from it, and any space left over on very wide screens
 * goes between the rail and the content rather than to the right of the sidebar. Each page
 * keeps its own content width (Feed for media, Discussions for text, Explore fills).
 * Studio, Account and profile pages keep the default shell above.
 */
:root {
    --mx-wide-max: 2000px;
    --mx-wide-gutter: clamp(28px, 2.4vw, 44px);
    --mx-col-gap: 36px;
    --mx-side-w: 300px;
    --mx-feed-w: 720px;
    --mx-discuss-w: 860px;
}

/* Feed and Explore keep their original centred layout (JM, 21 Nov 2026); only Discussions uses this block. */
@media (min-width: 1280px) {
    .media-shell:has(> .media-shell__content > .mdisc-page) { grid-template-columns: var(--mx-nav-w) minmax(0, 1fr); }
    .media-shell:has(> .media-shell__content > .mdisc-page) > .media-shell__content { max-width: none; }
}

/* Wider screens give the reading columns a little more room before the slack goes to the left. */
/* Page width stays at the original 1680px cap (JM, 21 Nov 2026: the wider page felt too wide). */

/* Discussions between 1025 and 1279px: the page runs to the right gutter too, so its sidebar is not left floating. */
@media (min-width: 1025px) and (max-width: 1279px) {
    .media-shell:has(> .media-shell__content > .mdisc-page) { grid-template-columns: var(--mx-nav-w) minmax(0, 1fr); }
    .media-shell:has(> .media-shell__content > .mdisc-page) > .media-shell__content { max-width: none; }
}


/* Selected nav icons that fill (Discuss, 21 Nov 2026): the outline fills and inner strokes become cut-outs in the row colour. */
.media-shell__nav .media-discover__nav-link[aria-current="page"] .media-nav-icon .mni-fill { fill: currentColor; }
.media-shell__nav .media-discover__nav-link[aria-current="page"] .media-nav-icon .mni-cut { stroke: var(--nav-active-bg, #edf3ff); }
