/* The Admin Portal shell (issue #1116).
   ═══════════════════════════════════════════════════════════════════════
   The rail is chrome and the region is content (Styles/README.md section 1). The rail paints with
   --navy2, the fill of the navbar and the hero bands, which dark mode never re-points, so it reads
   as the same chrome in both themes. It is not --chrome-fill: that is in-content chrome, and it
   lifts to --blue in dark mode, which would make the rail brighter than the hero beside it. Its
   inks are the chrome pairs (--chrome-ink, --chrome-muted, --chrome-rule), which are dark-surface
   values in both themes. The region holds each screen exactly as it renders today, on the page's
   own surface tokens, so nothing here needs a dark-mode rule.

   Plain CSS, loaded from the layout after admin-panels.css and before theme-dark.css. Never named
   in the SCSS pipeline. Every selector is scoped to an admin-portal class, so it is inert on a page
   without the shell. A rule that colours a link or a heading carries two classes, so it outranks
   theme-dark.css's [data-bs-theme="dark"] a and h2 rules, which are (0,1,1).
*/

/* ── The app shell: the window never scrolls ─────────────────────────────
   On a page with the shell, the document is exactly the window's height and never scrolls, in
   either direction, at any width. The page is a flex column: the site header and anything above
   #main take their own height, and the shell takes what is left. Nothing measures the header or
   hard-codes its height, so the expanded phone menu and the staged-content notice push the shell
   down instead of overlapping it. The rail and the region each scroll inside themselves.

   Scoped with :has(.admin-portal), so the layout needs no class of its own and every other page is
   untouched. A browser without :has() keeps the ordinary scrolling page.

   The footer is left out of the portal page. It carries the copyright line, three social links
   and the reader's name, which the user menu already shows; inside the region's scroll it would
   sit under every screen, and below the shell it would take height from both scroll panes. */
html:has(.admin-portal) {
    height: 100%;
    overflow: hidden;
}

body:has(.admin-portal) {
    display: flex;
    flex-direction: column;
    height: 100vh;    /* fallback for a browser without dvh */
    height: 100dvh;   /* the visible height, so a phone's browser bar cannot push a scrollbar back */
    min-height: 0;    /* site.css gives body min-height: 100vh */
    overflow: hidden;
}

body:has(.admin-portal) > #wrapper {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;    /* the bundle gives #wrapper min-height: calc(100vh - 60px) */
}

body:has(.admin-portal) > .footer-vis {
    display: none;
}

/* #main is a container on every page; around the shell the rail runs to the window's edge, and
   #main is the column the shell fills. */
#main.admin-portal-main {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    max-width: none;
    padding-left: 0;
    padding-right: 0;
}

#main.admin-portal-main > .admin-portal {
    flex: 1 1 auto;
    min-height: 0;
}

.admin-portal {
    display: flex;
    flex-direction: column;
}

/* The region's scroll pane: the error line and the screen. Wide content, a grid among it, scrolls
   here and never in the window. */
.admin-portal__body {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--surface-rule) transparent;
}

.admin-portal__body::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.admin-portal__body::-webkit-scrollbar-track {
    background: transparent;
}

.admin-portal__body::-webkit-scrollbar-thumb {
    background: var(--surface-rule);
    border: 2px solid transparent;
    border-radius: 6px;
    background-clip: padding-box;
}

.admin-portal__region {
    min-width: 0;
}

/* ── The rail ─────────────────────────────────────────────────────────── */

/* Below lg the rail is an offcanvas; these are Bootstrap's own variables for its panel. The site
   header is sticky at z-index 2200 (site.css, --cp-header-h), above Bootstrap's 1045, so the open
   panel and its backdrop are raised over it, or the header paints over the panel's title and
   close button. */
.admin-portal__offcanvas {
    --bs-offcanvas-width: 18rem;
    --bs-offcanvas-bg: var(--navy2);
    --bs-offcanvas-color: var(--chrome-ink);
    --bs-offcanvas-zindex: 2310;
}

body:has(.admin-portal__offcanvas.show, .admin-portal__offcanvas.showing) > .offcanvas-backdrop {
    z-index: 2300;
}

/* The rail scrolls inside itself, with a slim scrollbar in the rail's own chrome. color-scheme
   dark stops the browser drawing a light native scrollbar on navy in the light theme. */
.admin-portal__rail,
.admin-portal__offcanvas .offcanvas-body {
    color-scheme: dark;
    scrollbar-width: thin;
    scrollbar-color: var(--chrome-control-border) transparent;
}

.admin-portal__rail::-webkit-scrollbar,
.admin-portal__offcanvas .offcanvas-body::-webkit-scrollbar {
    width: 8px;
}

.admin-portal__rail::-webkit-scrollbar-track,
.admin-portal__offcanvas .offcanvas-body::-webkit-scrollbar-track {
    background: transparent;
}

.admin-portal__rail::-webkit-scrollbar-thumb,
.admin-portal__offcanvas .offcanvas-body::-webkit-scrollbar-thumb {
    background: var(--chrome-control-border);
    border: 2px solid transparent;
    border-radius: 6px;
    background-clip: padding-box;
}

.admin-portal__offcanvas-header {
    border-bottom: 1px solid var(--chrome-rule);
}

.admin-portal__offcanvas .admin-portal__offcanvas-title {
    margin: 0;
    color: var(--chrome-ink);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.admin-portal__nav {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 1rem 0 1.5rem;
}

.admin-portal__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.admin-portal__rail .admin-portal__group-title {
    margin: 1.25rem 1rem 0.35rem;
    color: var(--chrome-muted);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.admin-portal__nav .admin-portal__link {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.4rem 1rem 0.4rem calc(1rem - 3px);
    border-left: 3px solid transparent;
    color: var(--chrome-ink);
    font-size: 0.95rem;
    line-height: 1.3;
    text-decoration: none;
}

.admin-portal__nav .admin-portal__link:hover,
.admin-portal__nav .admin-portal__link:focus-visible {
    background: var(--chrome-control-hover-bg);
    color: var(--chrome-ink);
}

.admin-portal__nav .admin-portal__link[aria-current="page"] {
    border-left-color: var(--accent);
    background: var(--chrome-control-hover-bg);
    font-weight: 600;
}

.admin-portal__nav .admin-portal__link--home {
    font-weight: 600;
}

.admin-portal__nav .admin-portal__icon {
    color: var(--chrome-muted);
}

.admin-portal__label {
    flex: 1 1 auto;
}

/* ── Below lg: the toggle above the region ───────────────────────────── */

.admin-portal .admin-portal__toggle {
    align-self: flex-start;
    flex: 0 0 auto;
    margin: 1rem 1rem 0;
    border: 1px solid var(--surface-rule);
    background: var(--surface-1);
    color: var(--surface-ink);
}

.admin-portal .admin-portal__toggle:hover,
.admin-portal .admin-portal__toggle:focus-visible {
    border-color: var(--surface-link);
    background: var(--surface-1);
    color: var(--surface-ink);
}

/* A swap that failed keeps the screen it was showing and says why here. */
.admin-portal .admin-portal__error {
    margin: 1rem 1rem 0;
    color: var(--surface-danger);
    font-weight: 600;
}

/* ── lg and up: the rail beside the region ───────────────────────────── */

@media (min-width: 992px) {
    .admin-portal {
        flex-direction: row;
        align-items: stretch;
    }

    /* Bootstrap makes offcanvas-lg static and transparent here, so the rail itself carries the
       fill and is the pane that scrolls. It is as tall as the shell, never the window, so it can
       neither run under the sticky header nor push the document past the window's height. */
    .admin-portal__rail {
        flex: 0 0 16rem;
        width: 16rem;
        min-height: 0;
        overflow-x: hidden;
        overflow-y: auto;
        background: var(--navy2);
        border-right: 1px solid var(--chrome-rule);
    }
}

/* ── The site header's bar at xxl, on the portal page ────────────────────
   From 1,400 px the bar is one nowrap row. An admin's right-hand cluster can run past the window,
   and on this page an overflowing bar is cut off, because the page does not scroll. The search
   field is the one item that can give way, so it may shrink to a floor. While the bar fits, these
   rules change nothing: each item keeps its own width, and only the minimum moves. */
@media (min-width: 1400px) {
    body:has(.admin-portal) .cp-navbar .navbar-collapse,
    body:has(.admin-portal) .cp-navbar .navbar-collapse > .d-flex,
    body:has(.admin-portal) .cp-navbar .navbar-collapse > .d-flex > form:first-child {
        min-width: 0;
    }

    body:has(.admin-portal) .cp-navbar .Header-Search-Bar {
        min-width: 6rem;
        flex-shrink: 1;
    }
}

/* ── The home's panels (issue #1120) ─────────────────────────────────────
   Needs attention, Portal health and Recent, under the home's hero. Content, so every rule is on
   the --surface-* tokens and is right in both themes with no second rule. The tiles are
   _HubModuleGrid's cards and the state chips are the existing .admin-badge family, so nothing here
   draws a card or a fill. A rule that colours a heading or a link carries two classes, so it
   outranks theme-dark.css's [data-bs-theme="dark"] h3 and a rules, which are (0,1,1). */

.admin-portal-home .admin-portal-home__failed {
    color: var(--surface-danger);
    font-weight: 600;
}

/* Portal health: one row per job, one line per server when the servers disagree. */
.admin-portal-health .admin-portal-health__job {
    color: var(--surface-ink);
    font-weight: 600;
}

.admin-portal-health .admin-portal-health__line + .admin-portal-health__line {
    margin-top: 0.35rem;
}

.admin-portal-health .admin-portal-health__server {
    display: inline-block;
    min-width: 6rem;
    margin-right: 0.5rem;
    color: var(--surface-muted);
    font-size: 0.85rem;
}

.admin-portal-health .admin-portal-health__detail {
    display: block;
    color: var(--surface-muted);
    font-size: 0.85rem;
    overflow-wrap: anywhere;
}

/* Late is a danger word with no fill: the palette has no warning pair, and --status-danger-ink is
   the ink for the danger FILL, never text on a content surface (#221). */
.admin-portal-health .admin-portal-health__state {
    font-size: 0.85rem;
    font-weight: 600;
}

.admin-portal-health .admin-portal-health__state--late {
    color: var(--surface-danger);
}

/* Off and Last run not recorded: nothing is wrong, so nothing is coloured. */
.admin-portal-health .admin-portal-health__state--quiet {
    color: var(--surface-muted);
    font-weight: 400;
}

/* Recent: the publications and today's totals side by side, stacked on a narrow screen. */
.admin-portal-recent {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
    gap: 1.5rem;
}

.admin-portal-recent .admin-portal-recent__title {
    margin: 0 0 0.6rem;
    color: var(--surface-ink);
    font-size: 0.95rem;
    font-weight: 600;
}

.admin-portal-recent .admin-portal-recent__link {
    color: var(--surface-link);
}

.admin-portal-recent .admin-portal-recent__link:hover,
.admin-portal-recent .admin-portal-recent__link:focus-visible {
    color: var(--surface-link-hover);
}

.admin-portal-recent__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.admin-portal-recent .admin-portal-recent__item {
    padding: 0.45rem 0;
    border-top: 1px solid var(--surface-rule);
}

.admin-portal-recent .admin-portal-recent__item:first-child {
    border-top: 0;
    padding-top: 0;
}

.admin-portal-recent .admin-portal-recent__detail,
.admin-portal-recent .admin-portal-recent__empty {
    display: block;
    color: var(--surface-muted);
    font-size: 0.85rem;
}

.admin-portal-recent__totals {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin: 0;
}

.admin-portal-recent .admin-portal-recent__total dt {
    color: var(--surface-muted);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.admin-portal-recent .admin-portal-recent__total dd {
    margin: 0;
    color: var(--surface-ink);
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.2;
}
