/*
 * AdminCP shell: the fixed top bar, the sidebar beside it, and the content column between them.
 * docs/admin-navigation.md is the rulebook for what goes in which sidebar section; this file
 * only draws it.
 *
 * The whole layout is driven by two classes on <body>, set in template_base.twig:
 *
 *   .has-sidebar                     the shell is rendered. Absent on the admin login page and
 *                                    in the install wizard, which both reuse this stylesheet
 *                                    without a sidebar — so nothing here may indent `main`
 *                                    unless this class is present.
 *   .has-sidebar.sidebar-collapsed   desktop: the sidebar is an icon rail that widens back to
 *                                    full width while the pointer (or keyboard focus) is in it.
 *                                    Below 992px: the sidebar is off-canvas, behind a backdrop.
 *
 * Stacking order, chosen to sit under Bootstrap's modal (1055) and its backdrop (1050):
 * top bar 1040, sidebar 1035, sidebar backdrop 1030.
 */
:root {
    --ns-nav-h: 56px;
    --ns-sidebar-w: 264px;
    --ns-rail-w: 72px;
}

body {
    font-size: .875rem;
}

/*
 * Top bar
 */
.admin-navbar {
    height: var(--ns-nav-h);
    z-index: 1040;
    padding: 0 .5rem 0 .75rem;
    gap: .25rem;
    background-color: var(--bs-body-bg);
    border-bottom: 1px solid var(--bs-border-color);
}

.admin-navbar .navbar-brand {
    display: flex;
    align-items: center;
    padding: 0;
    margin: 0;
}

.admin-navbar .navbar-brand img {
    height: 28px;
    width: auto;
}

/* Two logo files, one per theme: the -dark one is the white wordmark, for dark backgrounds.
   Scoped to .navbar-brand so it can't reach the login page's own pair. */
.navbar-brand .logo-dark { display: none; }
[data-bs-theme="dark"] .navbar-brand .logo-light { display: none; }
[data-bs-theme="dark"] .navbar-brand .logo-dark { display: block; }

/* Round icon buttons: the sidebar toggle, "View site", the attention bell, the theme picker. */
.nav-icon-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background-color: transparent;
    color: var(--bs-secondary-color);
    font-size: 1rem;
    line-height: 1;
    transition: background-color .12s ease, color .12s ease;
}

.nav-icon-btn:hover,
.nav-icon-btn:focus-visible,
.nav-icon-btn.show {
    background-color: var(--bs-secondary-bg);
    color: var(--bs-emphasis-color);
}

/* The count on the bell. Positioned against the button, not in the flow, so the row of icons
   keeps an even rhythm whether or not anything needs attention. */
.nav-icon-btn .attention-count {
    position: absolute;
    top: 1px;
    inset-inline-end: 0;
    min-width: 1.05rem;
    padding: .15rem .25rem;
    font-size: .625rem;
    font-weight: 600;
    line-height: 1;
}

.admin-navbar .dropdown-menu {
    --bs-dropdown-border-color: var(--bs-border-color);
    box-shadow: var(--bs-box-shadow);
}

/* The account menu is sized by its contents, and a long admin email would otherwise widen it
   until it ran off the left of a phone the same way the attention menu did. Capping it also
   gives the .text-truncate on the name and email something to truncate against — in an
   auto-width dropdown there is no width to overflow, so the ellipsis never appears. */
.admin-menu-list { max-width: min(260px, calc(100vw - 1.5rem)); }

/* Attention menu: one row per thing waiting on the admin. Wider than a stock dropdown because
   every row is a title plus a line of explanation.

   The clipping is done here rather than with the .overflow-hidden utility on the element: that
   utility is !important, so it would win over overflow-y and the menu could never scroll. `hidden
   auto` still clips the rows to the menu's rounded corners. */
.attention-menu {
    width: 330px;
    max-height: calc(100vh - var(--ns-nav-h) - 1.5rem);
    overflow: hidden auto;
}

/* Mobile browsers count the collapsible URL bar in 100vh, so the menu could end up taller than
   the space it actually has. Ignored where dvh isn't supported, which is why the vh line stays. */
@supports (height: 100dvh) {
    .attention-menu { max-height: calc(100dvh - var(--ns-nav-h) - 1.5rem); }
}

/* The heading stays put while the rows scroll under it. */
.attention-menu .attention-head {
    position: sticky;
    top: 0;
    z-index: 1;
    background-color: var(--bs-dropdown-bg);
}

/* On a phone the bell isn't the last thing in the bar — the theme picker and the account menu
   sit to its right — so a 330px menu aligned to the bell's right edge starts off the left of the
   screen. Popper doesn't pull it back: its preventOverflow modifier defaults to the main axis
   only, and for a bottom-placed dropdown the horizontal one is the *alt* axis, which Bootstrap
   leaves switched off. A max-width can't fix that either, because the problem is where the menu
   starts, not how wide it is.

   So below sm the menu stops tracking the button and pins itself to the right edge of the screen
   instead, keeping its width where there's room for it and shrinking only on a narrow phone.
   Every property Popper writes inline (position, the inset longhands, transform) needs
   !important to be overridden. */
@media (max-width: 575.98px) {
    .attention-menu {
        position: fixed !important;
        top: calc(var(--ns-nav-h) + .25rem) !important;
        right: .75rem !important;
        bottom: auto !important;
        left: auto !important;
        width: min(330px, calc(100vw - 1.5rem));
        transform: none !important;
    }
}

.attention-item {
    display: flex;
    align-items: flex-start;
    gap: .7rem;
    padding: .55rem .9rem;
    white-space: normal;
}

.attention-item .attention-icon {
    flex: 0 0 2rem;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: .5rem;
    font-size: .85rem;
}

.attention-item .attention-title { font-weight: 500; line-height: 1.3; }
.attention-item .attention-sub {
    font-size: .78rem;
    line-height: 1.3;
    color: var(--bs-secondary-color);
}

.attention-item:hover .attention-sub,
.attention-item:focus .attention-sub { color: inherit; }

/* "Search or jump to", beside the brand: a button dressed as a field. The typing happens in the
   palette (App/Views/admin/_palette.twig), which is where the results are. */
.nav-search {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: clamp(220px, 28vw, 380px);
    height: 36px;
    margin-inline-start: 1.25rem;
    padding: 0 .4rem 0 .75rem;
    border: 1px solid var(--bs-border-color);
    border-radius: .5rem;
    background-color: var(--bs-tertiary-bg);
    color: var(--bs-secondary-color);
    font-size: .85rem;
    text-align: start;
    transition: border-color .12s ease, background-color .12s ease, color .12s ease;
}

.nav-search:hover,
.nav-search:focus-visible {
    border-color: var(--bs-secondary-color);
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
}

.nav-search-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Key caps, here and in the palette: Bootstrap's <kbd> is a dark chip, too loud for a hint. */
.nav-search-kbd,
.palette kbd {
    display: inline-block;
    min-width: 1.35rem;
    padding: .1rem .3rem;
    border: 1px solid var(--bs-border-color);
    border-bottom-width: 2px;
    border-radius: .3rem;
    background-color: var(--bs-body-bg);
    color: var(--bs-secondary-color);
    font-family: inherit;
    font-size: .7rem;
    font-weight: 500;
    line-height: 1.2;
    text-align: center;
}

.nav-search-kbd + .nav-search-kbd { margin-inline-start: -.3rem; }

/*
 * The palette. A Bootstrap modal pinned near the top rather than centred, so the field stays
 * where the eye left it while the list under it grows and shrinks with every keystroke.
 */
.palette-dialog {
    max-width: 640px;
    margin: 10vh auto 1rem;
    padding: 0 .75rem;
}

@media (max-width: 575.98px) {
    .palette-dialog { margin-top: .75rem; }
}

.palette {
    overflow: hidden;
    border: 1px solid var(--bs-border-color);
    border-radius: .75rem;
    box-shadow: var(--bs-box-shadow-lg);
}

.palette-head {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .25rem .75rem .25rem 1rem;
    border-bottom: 1px solid var(--bs-border-color);
}

.palette-head-icon { color: var(--bs-secondary-color); }

.palette-input {
    flex: 1;
    min-width: 0;
    height: 52px;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--bs-body-color);
    font-size: 1rem;
}

.palette-input::placeholder { color: var(--bs-secondary-color); }

.palette-esc {
    padding: .15rem .45rem;
    border: 1px solid var(--bs-border-color);
    border-radius: .3rem;
    background-color: transparent;
    color: var(--bs-secondary-color);
    font-size: .7rem;
    font-weight: 500;
}

.palette-esc:hover { color: var(--bs-body-color); }

.palette-list {
    max-height: min(60vh, 480px);
    overflow-y: auto;
    padding: .25rem .5rem .5rem;
    overscroll-behavior: contain;
}

.palette-group {
    padding: .65rem .5rem .3rem;
    color: var(--bs-secondary-color);
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.palette-item {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .45rem .5rem;
    border-radius: .5rem;
    color: var(--bs-body-color);
    text-decoration: none;
    scroll-margin: .5rem;
}

.palette-item.active {
    background-color: var(--bs-primary-bg-subtle);
    color: var(--bs-primary-text-emphasis);
}

.palette-icon {
    flex: 0 0 2rem;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: .5rem;
    background-color: var(--bs-secondary-bg);
    font-size: .85rem;
}

.palette-item.active .palette-icon:not([class*="-subtle"]) { background-color: var(--bs-body-bg); }

.palette-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.palette-label,
.palette-hint {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.palette-label { font-weight: 500; line-height: 1.3; }

.palette-label mark {
    padding: 0;
    background: none;
    color: inherit;
    font-weight: 700;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 2px;
    text-decoration-color: rgba(var(--bs-primary-rgb), .45);
}

.palette-hint {
    color: var(--bs-secondary-color);
    font-size: .78rem;
    line-height: 1.3;
}

.palette-item.active .palette-hint { color: inherit; opacity: .8; }

.palette-ext { color: var(--bs-secondary-color); font-size: .75rem; }

/* The ↵ marks the row Enter would open; it's only drawn on that one. */
.palette-enter {
    visibility: hidden;
    color: var(--bs-secondary-color);
    font-size: .85rem;
}

.palette-item.active .palette-enter { visibility: visible; color: inherit; }

.palette-empty {
    padding: 2.25rem 1rem;
    color: var(--bs-secondary-color);
    text-align: center;
}

.palette-foot {
    align-items: center;
    gap: 1rem;
    padding: .55rem 1rem;
    border-top: 1px solid var(--bs-border-color);
    background-color: var(--bs-tertiary-bg);
    color: var(--bs-secondary-color);
    font-size: .75rem;
}

.palette-foot kbd + kbd { margin-inline-start: .15rem; }

/* Signed-in admin, at the end of the bar. */
.admin-menu-btn {
    display: flex;
    align-items: center;
    gap: .5rem;
    max-width: 190px;
    padding: .25rem .6rem .25rem .25rem;
    border: 0;
    border-radius: 999px;
    background-color: transparent;
    color: var(--bs-body-color);
    transition: background-color .12s ease;
}

.admin-menu-btn:hover,
.admin-menu-btn:focus-visible,
.admin-menu-btn.show { background-color: var(--bs-secondary-bg); }

.admin-menu-btn .admin-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-avatar {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: .8rem;
    font-weight: 600;
}

/*
 * Footer
 *
 * Scoped to .admin-footer, not .footer, because the install wizard reuses this stylesheet and has
 * a footer of its own. Only the content-column indent (body.has-sidebar .footer, further down) is
 * shared, and the wizard never carries that class.
 */
.admin-footer {
    border-top: 1px solid var(--bs-border-color);
    background-color: var(--bs-tertiary-bg);
    font-size: .8125rem;
    color: var(--bs-secondary-color);
}

/* Links read as part of the footer text until hovered. The update badge keeps its own colours:
   Bootstrap's .text-bg-* are !important, so they win over this. */
.admin-footer a {
    color: inherit;
    text-decoration: none;
}

.admin-footer a:hover,
.admin-footer a:focus-visible { color: var(--bs-emphasis-color); }

.footer-version {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

/*
 * Sidebar
 */
.sidebar {
    position: fixed;
    top: var(--ns-nav-h);
    bottom: 0;
    left: 0;
    z-index: 1035;
    display: flex;
    flex-direction: column;
    width: var(--ns-sidebar-w);
    overflow: hidden;
    border-inline-end: 1px solid var(--bs-border-color);
    transition: width .2s ease, transform .2s ease, box-shadow .2s ease;
}

.sidebar-nav {
    flex: 1 1 auto;
    padding: .5rem 0 1.5rem;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--bs-border-color) transparent;
}

.sidebar-nav::-webkit-scrollbar { width: .4rem; }
.sidebar-nav::-webkit-scrollbar-thumb {
    background-color: var(--bs-border-color);
    border-radius: 10px;
}
.sidebar-nav:hover::-webkit-scrollbar-thumb { background-color: var(--bs-secondary-color); }

/* A section label, and the rule that replaces it in the rail (see the rail block below). */
.sidebar-heading {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .95rem 1.375rem .3rem;
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--bs-secondary-color);
}

.sidebar-nav > .nav > .sidebar-heading:first-child { padding-top: .25rem; }

.sidebar-heading .heading-rule {
    display: none;
    flex: 1 1 auto;
    height: 1px;
    background-color: var(--bs-border-color);
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    margin: .1rem .625rem;
    padding: .5rem .75rem;
    border-radius: .5rem;
    font-weight: 500;
    white-space: nowrap;
    color: var(--bs-secondary-color);
    transition: background-color .12s ease, color .12s ease;
}

/* Clear Cache is a form's button, not a link: drop the button chrome and fill the row like one. */
.sidebar button.nav-link {
    width: calc(100% - 1.25rem);
    border: 0;
    background-color: transparent;
    text-align: start;
}

.sidebar .nav-link:hover,
.sidebar .nav-link:focus-visible {
    background-color: var(--bs-secondary-bg);
    color: var(--bs-emphasis-color);
}

/* The page you are on. The inset bar is the only vertical accent in the panel that isn't a
   card's (docs/admin-accent-bars.md) — it marks position in a list, not a kind of number. */
.sidebar .nav-link.active {
    background-color: rgba(var(--bs-primary-rgb), .12);
    color: var(--bs-primary-text-emphasis);
    box-shadow: inset 3px 0 0 var(--bs-primary);
}

/* A collapsed group whose section you are inside: emphasised, but not the full pill, or the
   parent and the child both read as "you are here". */
.sidebar .nav-link.current {
    color: var(--bs-emphasis-color);
}

.sidebar .nav-link.current > .nav-icon { color: var(--bs-primary); }

.sidebar .nav-icon {
    flex: 0 0 1.25rem;
    width: 1.25rem;
    font-size: 1rem;
    text-align: center;
    color: var(--bs-secondary-color);
    transition: color .12s ease;
}

.sidebar .nav-link:hover > .nav-icon,
.sidebar .nav-link.active > .nav-icon { color: inherit; }

.sidebar .nav-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar .nav-caret {
    flex: 0 0 auto;
    font-size: .7rem;
    opacity: .55;
    transition: transform .2s ease;
}

.sidebar .nav-link[aria-expanded="true"] .nav-caret { transform: rotate(180deg); }

.sidebar .nav-badge {
    flex: 0 0 auto;
    padding: .2rem .4rem;
    font-size: .68rem;
    font-weight: 600;
}

/* A dot instead of a count, for rows where the number adds nothing (an add-on with an update). */
.sidebar .nav-dot {
    flex: 0 0 auto;
    width: .45rem;
    height: .45rem;
    border-radius: 50%;
    background-color: var(--bs-warning);
}

/* Children of a group, hung off a guide line so the nesting reads without deep indentation. */
.sidebar .nav-sub {
    position: relative;
    margin: .05rem .625rem .4rem 1.95rem;
    padding-inline-start: .6rem;
}

.sidebar .nav-sub::before {
    content: '';
    position: absolute;
    inset-inline-start: 0;
    top: .3rem;
    bottom: .3rem;
    width: 1px;
    background-color: var(--bs-border-color);
}

.sidebar .nav-sub .nav-link {
    margin: .05rem 0;
    padding: .375rem .6rem;
    font-weight: 400;
}

/* The guide line already marks where these sit, so the pill alone says which one is open. */
.sidebar .nav-sub .nav-link.active { box-shadow: none; }

.sidebar .nav-sub .nav-icon {
    flex-basis: 1rem;
    width: 1rem;
    font-size: .85rem;
}

/* Closes the sidebar on phones by tapping the page behind it. Replaces the blur that used to be
   put on `main` for the same job: a filter on an ancestor re-anchors position: fixed, which
   trapped every modal rendered inside the content column. */
.sidebar-backdrop {
    position: fixed;
    inset: var(--ns-nav-h) 0 0 0;
    z-index: 1030;
    background-color: rgba(0, 0, 0, .4);
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
}

/*
 * Content column
 */
[role="main"] {
    padding-top: calc(var(--ns-nav-h) + 1.5rem);
}

@media (min-width: 992px) {
    body.has-sidebar main,
    body.has-sidebar .footer {
        margin-inline-start: var(--ns-sidebar-w);
        transition: margin-inline-start .2s ease;
    }

    body.has-sidebar.sidebar-collapsed main,
    body.has-sidebar.sidebar-collapsed .footer {
        margin-inline-start: var(--ns-rail-w);
    }

    /* ---- Rail -------------------------------------------------------------------------- */
    body.sidebar-collapsed .sidebar { width: var(--ns-rail-w); }

    body.sidebar-collapsed .sidebar .nav-link {
        justify-content: center;
        padding-inline: .5rem;
    }

    body.sidebar-collapsed .sidebar .nav-label,
    body.sidebar-collapsed .sidebar .nav-caret,
    body.sidebar-collapsed .sidebar .nav-badge,
    body.sidebar-collapsed .sidebar .nav-dot,
    body.sidebar-collapsed .sidebar .nav-sub,
    body.sidebar-collapsed .sidebar-heading .heading-text { display: none; }

    /* With the labels gone, a section reads as a divider instead. */
    body.sidebar-collapsed .sidebar-heading { padding-inline: 1.125rem; }
    body.sidebar-collapsed .sidebar-heading .heading-rule { display: block; }

    /* A group whose section you are in keeps its marker while its children are hidden. */
    body.sidebar-collapsed .sidebar .nav-link.current {
        background-color: rgba(var(--bs-primary-rgb), .12);
        box-shadow: inset 3px 0 0 var(--bs-primary);
    }

    /* ---- Peek: the rail widens over the content while it has the pointer or focus, without
       moving the page underneath it, so nothing reflows while you aim at a link. ----------- */
    body.sidebar-collapsed .sidebar:hover,
    body.sidebar-collapsed .sidebar:focus-within {
        width: var(--ns-sidebar-w);
        box-shadow: .5rem 0 1.5rem rgba(0, 0, 0, .18);
    }

    body.sidebar-collapsed .sidebar:hover .nav-link,
    body.sidebar-collapsed .sidebar:focus-within .nav-link {
        justify-content: flex-start;
        padding-inline: .75rem;
    }

    body.sidebar-collapsed .sidebar:hover .nav-label,
    body.sidebar-collapsed .sidebar:focus-within .nav-label { display: block; }

    body.sidebar-collapsed .sidebar:hover .nav-caret,
    body.sidebar-collapsed .sidebar:focus-within .nav-caret,
    body.sidebar-collapsed .sidebar:hover .nav-badge,
    body.sidebar-collapsed .sidebar:focus-within .nav-badge,
    body.sidebar-collapsed .sidebar:hover .nav-dot,
    body.sidebar-collapsed .sidebar:focus-within .nav-dot,
    body.sidebar-collapsed .sidebar:hover .sidebar-heading .heading-text,
    body.sidebar-collapsed .sidebar:focus-within .sidebar-heading .heading-text { display: inline-block; }

    body.sidebar-collapsed .sidebar:hover .sidebar-heading,
    body.sidebar-collapsed .sidebar:focus-within .sidebar-heading { padding-inline: 1.375rem .35rem; }

    body.sidebar-collapsed .sidebar:hover .sidebar-heading .heading-rule,
    body.sidebar-collapsed .sidebar:focus-within .sidebar-heading .heading-rule { display: none; }

    /* Only groups that were open come back — .show and .collapsing are exactly the states
       Bootstrap's collapse leaves behind, so a closed group stays closed while peeking. */
    body.sidebar-collapsed .sidebar:hover .nav-sub.show,
    body.sidebar-collapsed .sidebar:hover .nav-sub.collapsing,
    body.sidebar-collapsed .sidebar:focus-within .nav-sub.show,
    body.sidebar-collapsed .sidebar:focus-within .nav-sub.collapsing { display: block; }

    body.sidebar-collapsed .sidebar:hover .nav-link.current,
    body.sidebar-collapsed .sidebar:focus-within .nav-link.current {
        background-color: transparent;
        box-shadow: none;
    }
}

@media (max-width: 991.98px) {
    /* Off-canvas: the sidebar covers the page instead of indenting it, and closes on a tap. */
    .sidebar {
        width: min(280px, 84vw);
        box-shadow: .5rem 0 1.5rem rgba(0, 0, 0, .18);
    }

    body.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
    }

    body.has-sidebar:not(.sidebar-collapsed) .sidebar-backdrop {
        opacity: 1;
        visibility: visible;
    }
}

/* Honour "reduce motion": the sidebar still opens and closes, it just doesn't slide. */
@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .sidebar-backdrop,
    .sidebar .nav-caret,
    body.has-sidebar main,
    body.has-sidebar .footer { transition: none; }
}

/*
 * Page-to-page transition. A cross-document View Transition: no JS and no framework, and a
 * browser without support (or with "reduce motion" on) simply navigates the way it always did.
 *
 * The shell is what makes a full page load feel like one: the top bar and the sidebar are named,
 * so they are carried across in place and only crossfade what actually changed (the active row,
 * a badge count). Only the content column moves. The old one is dropped rather than faded out:
 * a page left scrolled down would otherwise show its top half for a moment before the new one
 * came in. The root (background, footer) is swapped the same way, for the same reason.
 *
 * `main` is only named under .has-sidebar: the sign-in page and the install wizard load this
 * stylesheet too, and for them the whole thing reduces to an instant swap.
 */
@media (prefers-reduced-motion: no-preference) {
    @view-transition { navigation: auto; }

    .admin-navbar { view-transition-name: admin-navbar; }
    .sidebar { view-transition-name: admin-sidebar; }

    /* Only while a transition runs: a view-transition-name makes its element a stacking
       context, and a permanent one on `main` trapped every modal inside it (z-index 1055)
       under Bootstrap's backdrop, which is appended to <body> at 1050 — a dark page that
       wouldn't take a click. The top bar and sidebar are fixed with a z-index, so they were
       stacking contexts already and can keep theirs. Unnamed on the old page is fine too:
       its content is dropped (below) either way. */
    html:active-view-transition body.has-sidebar main { view-transition-name: admin-main; }

    ::view-transition-old(root),
    ::view-transition-old(admin-main) { display: none; }

    ::view-transition-new(root) { animation: none; }

    /* The column's size and position belong to the new page from the first frame. */
    ::view-transition-group(admin-main) { animation: none; }

    ::view-transition-new(admin-main) {
        animation: ns-page-in .22s cubic-bezier(.2, .7, .3, 1) both;
    }

    /* Snapshots paint in document order, which would put `main` over the shell whenever it
       starts scrolled (back/forward restores the position) or under the off-canvas sidebar. */
    ::view-transition-group(admin-navbar),
    ::view-transition-group(admin-sidebar) {
        z-index: 1;
        animation-duration: .15s;
    }
}

@keyframes ns-page-in {
    from { opacity: 0; transform: translateY(6px); }
}

/*
 * Load bar: the gap between the click and the next page arriving, which the transition above
 * can't cover (it starts once the new page is ready). Drawn by template_base.twig's script,
 * only after a short delay, so a fast page never flashes it. It creeps toward 90% and never
 * claims to finish: the next page replacing this one is the finish.
 */
.page-progress {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 1045;
    height: 2px;
    pointer-events: none;
    background-color: var(--bs-primary);
    opacity: 0;
    transform: scaleX(0);
    transform-origin: left;
}

.page-progress.is-loading {
    opacity: 1;
    transform: scaleX(.9);
    transition: opacity .15s ease, transform 8s cubic-bezier(.1, .8, .2, 1);
}

@media (prefers-reduced-motion: reduce) {
    .page-progress.is-loading {
        transform: scaleX(1);
        transition: none;
        animation: ns-progress-pulse 1.2s ease-in-out infinite;
    }
}

@keyframes ns-progress-pulse {
    50% { opacity: .35; }
}

/*
 * Card accent bars & KPI stat cards. See docs/admin-accent-bars.md for the rules (which edge,
 * which colour, when to use one). Shared by every core AdminCP page and every add-on's admin
 * fragment — add-ons no longer carry their own scoped copy of this block.
 */
.accent-top,
.accent-bottom,
.accent-start {
    --accent: var(--bs-primary);
}

.accent-top    { border-top: 3px solid var(--accent); }
.accent-bottom { border-bottom: 3px solid var(--accent); }
.accent-start  { border-inline-start: 3px solid var(--accent); }

.accent-primary   { --accent: var(--bs-primary); }
.accent-success   { --accent: var(--bs-success); }
.accent-info      { --accent: var(--bs-info); }
.accent-warning   { --accent: var(--bs-warning); }
.accent-danger    { --accent: var(--bs-danger); }
.accent-secondary { --accent: var(--bs-secondary); }

.stat-card .card-body {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    flex-shrink: 0;
}

.stat-label {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--bs-secondary-color);
    margin-bottom: .15rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.15;
    word-break: break-word;
}

.stat-sub {
    font-size: .8rem;
    color: var(--bs-secondary-color);
    margin-top: .2rem;
}

/*
 * Add-on admin fragment components: the at-a-glance strip, ranked lists, settings rows and the
 * save bar at the bottom of a settings form. Shared by every add-on's Views/admin/settings.twig
 * fragment. Each fragment's own wrapper class (.faucet-admin, .sl-admin, etc.) still scopes
 * whatever is genuinely specific to that add-on; only the identical, repeated pieces live here.
 */
.glance {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem 1.5rem;
    padding: .85rem 1rem;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius-lg);
    background-color: var(--bs-tertiary-bg);
}

.glance-item { display: flex; flex-direction: column; line-height: 1.25; }
.glance-item small { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--bs-secondary-color); }
.glance-item > span { font-weight: 600; }

.section-label {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--bs-secondary-color);
    margin: 0 0 .6rem;
}

.rank {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.9rem;
    height: 1.9rem;
    border-radius: 50%;
    font-weight: 600;
    font-size: .85rem;
    color: var(--bs-secondary-color);
}

.rank-1 { background-color: #f5c542; color: #3d2e00; }
.rank-2 { background-color: #c9ced6; color: #2b3035; }
.rank-3 { background-color: #d99a6c; color: #3a1f0b; }

.amount-sub { font-size: .8rem; color: var(--bs-secondary-color); }

/* Base layout only — a fragment that wants dividers between rows adds its own padding/
   border-bottom scoped under its wrapper class, since not every settings list uses them. */
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.setting-text { display: flex; flex-direction: column; gap: .15rem; cursor: pointer; margin: 0; }
.setting-title { font-weight: 500; }
.setting-desc { font-size: .825rem; color: var(--bs-secondary-color); line-height: 1.35; }

.setting-row .form-switch .form-check-input {
    width: 2.5em;
    height: 1.35em;
    margin: 0;
    cursor: pointer;
}

.save-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--bs-border-color);
}

.copy-value { font-family: var(--bs-font-monospace); font-size: .875em; word-break: break-all; }

/* Page-header avatar: the initial of whichever account the page is about — a user on the user
   details page, the signed-in admin on their own settings page. The colour classes come from the
   page, since they carry meaning there (a banned user goes danger). */
.page-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 600;
    flex-shrink: 0;
}

/* Flex/grid children default to min-width: auto, so a long word refuses to shrink and pushes the
   row wider than its card. Every page header that truncates a username or a title needs this. */
.min-w-0 { min-width: 0; }
/*
 * Toasts (notyf.open(), drawn by @admin/_toasts.twig)
 *
 * A neutral card rather than a slab of colour: the type is carried by the icon badge and the
 * countdown bar, both from the theme's own subtle/emphasis pairs, so every type stays readable in
 * light and dark alike. Pinned to the top-right corner, over the top bar (z-index above it).
 */
.admin-toasts {
    z-index: 1090;
    top: 0;
    right: 0;
    padding: 1rem;
    width: min(380px, 100%);
}

.admin-toast {
    /* On the toast, not the container: Bootstrap's .toast sets its own 1.5rem, and the gap
       (.toast-container > :not(:last-child)) reads the toast's value. */
    --bs-toast-spacing: .625rem;
    --toast-accent: var(--bs-info);
    --toast-accent-bg: var(--bs-info-bg-subtle);
    --toast-accent-fg: var(--bs-info-text-emphasis);
    position: relative;
    overflow: hidden;
    width: 100%;
    background-color: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color-translucent);
    border-radius: .75rem;
    box-shadow: 0 .5rem 1.5rem rgba(0, 0, 0, .12), 0 .125rem .25rem rgba(0, 0, 0, .06);
}

[data-bs-theme="dark"] .admin-toast {
    background-color: var(--bs-tertiary-bg);
    box-shadow: 0 .5rem 1.5rem rgba(0, 0, 0, .45);
}

.admin-toast-success { --toast-accent: var(--bs-success); --toast-accent-bg: var(--bs-success-bg-subtle); --toast-accent-fg: var(--bs-success-text-emphasis); }
.admin-toast-warning { --toast-accent: var(--bs-warning); --toast-accent-bg: var(--bs-warning-bg-subtle); --toast-accent-fg: var(--bs-warning-text-emphasis); }
.admin-toast-danger  { --toast-accent: var(--bs-danger);  --toast-accent-bg: var(--bs-danger-bg-subtle);  --toast-accent-fg: var(--bs-danger-text-emphasis); }

.admin-toast .toast-body {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
    padding: .875rem .75rem .875rem .875rem;
}

.admin-toast-icon {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background-color: var(--toast-accent-bg);
    color: var(--toast-accent-fg);
}

.admin-toast-message {
    flex: 1;
    min-width: 0;
    align-self: center;
    overflow-wrap: anywhere;
    color: var(--bs-emphasis-color);
}

.admin-toast .btn-close {
    flex-shrink: 0;
    font-size: .625rem;
    margin-top: .5rem;
}

/* Time left before it closes. Paused, with the timer, while the pointer or focus is on the toast. */
.admin-toast-progress {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    width: 100%;
    background-color: var(--toast-accent);
    transform-origin: left;
    animation: admin-toast-countdown var(--toast-delay, 5000ms) linear forwards;
}

.admin-toast.is-paused .admin-toast-progress { animation-play-state: paused; }

@keyframes admin-toast-countdown {
    to { transform: scaleX(0); }
}

/* Entering and leaving are animated from _toasts.twig (Web Animations), not here: leaving
   has to measure the toast's height to collapse the gap, which CSS can't animate to from auto. */

/*
 * Confirmation dialog (#adminConfirmModal, @admin/_confirm.twig). A status bar along the top and
 * a round icon over the title, both in the dialog's type colour — danger unless the trigger says
 * otherwise — so what kind of decision this is reads before the words do.
 */
.admin-confirm {
    --confirm-accent: var(--bs-danger);
    --confirm-accent-bg: var(--bs-danger-bg-subtle);
    --confirm-accent-fg: var(--bs-danger-text-emphasis);
    position: relative;
    overflow: hidden;
    border: 1px solid var(--bs-border-color-translucent);
    border-radius: .75rem;
}

.admin-confirm::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 4px;
    background-color: var(--confirm-accent);
}

.admin-confirm-primary { --confirm-accent: var(--bs-primary); --confirm-accent-bg: var(--bs-primary-bg-subtle); --confirm-accent-fg: var(--bs-primary-text-emphasis); }
.admin-confirm-success { --confirm-accent: var(--bs-success); --confirm-accent-bg: var(--bs-success-bg-subtle); --confirm-accent-fg: var(--bs-success-text-emphasis); }
.admin-confirm-info    { --confirm-accent: var(--bs-info);    --confirm-accent-bg: var(--bs-info-bg-subtle);    --confirm-accent-fg: var(--bs-info-text-emphasis); }
.admin-confirm-warning { --confirm-accent: var(--bs-warning); --confirm-accent-bg: var(--bs-warning-bg-subtle); --confirm-accent-fg: var(--bs-warning-text-emphasis); }

/* Above .modal-body, which Bootstrap makes position: relative and which comes later in the
   markup, so without a z-index it paints over the button and swallows its clicks. */
.admin-confirm .btn-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 2;
    font-size: .75rem;
}

.admin-confirm .modal-body {
    padding: 2rem 1.75rem 1.25rem;
    text-align: center;
}

.admin-confirm-icon {
    width: 3.5rem;
    height: 3.5rem;
    margin: 0 auto 1rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    background-color: var(--confirm-accent-bg);
    color: var(--confirm-accent-fg);
}

.admin-confirm-message {
    color: var(--bs-secondary-color);
    overflow-wrap: anywhere;
}

/* The consequences under the summary. Left-aligned in a panel of their own, since a list centred
   like the rest of the dialog puts every line's marker somewhere else. */
.admin-confirm-points {
    list-style: none;
    margin: 1rem 0 0;
    padding: .75rem 1rem;
    border-radius: var(--bs-border-radius);
    background-color: var(--bs-tertiary-bg);
    text-align: start;
    font-size: .875rem;
    overflow-wrap: anywhere;
}

.admin-confirm-points li {
    display: flex;
    gap: .5rem;
}

.admin-confirm-points li + li {
    margin-top: .375rem;
}

.admin-confirm-points li > i {
    flex: none;
    margin-top: .2rem;
    color: var(--confirm-accent-fg);
}

.admin-confirm .modal-footer {
    justify-content: center;
    gap: .5rem;
    padding: 0 1.75rem 1.75rem;
    border-top: 0;
}

.admin-confirm .modal-footer > .btn {
    flex: 1 1 0;
    margin: 0;
}
