/* ==========================================================================
   Panel shell (Panel overhaul, 2026-09): sidebar, top bar and content area, on
   the AAB tokens. New class names (pnl-*), so the old theme's .sidebar / .top-bar
   rules (core/_legacy.css) and app.css no longer apply to the shell.

   >= 1024px  sidebar in the page flow, sticky
   <  1024px  sidebar is a drawer behind the menu button (tablets need the width
              for tables); the AAB tile doubles as the home link
   <  768px   search collapses to an icon and opens across the top bar
   ========================================================================== */

.pnl-shell {
    --pnl-sidebar-width: 256px;
    --topbar-height: 60px;          /* also read by the template builder's sticky toolbar */
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--aab-bg);
}

/* --- Sidebar ---------------------------------------------------------------- */
.pnl-sidebar {
    position: sticky;
    top: 0;
    flex: 0 0 var(--pnl-sidebar-width);
    width: var(--pnl-sidebar-width);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--aab-surface);
    border-right: 1px solid var(--aab-line);
    z-index: var(--z-chrome);
}

.pnl-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--aab-space-2);
    padding: var(--aab-space-5) var(--aab-space-4) var(--aab-space-4) var(--aab-space-5);
}

.pnl-brand-link {
    display: flex;
    align-items: center;
    gap: var(--aab-space-3);
    min-width: 0;
    border-radius: var(--aab-radius-sm);
    color: var(--aab-text);
    text-decoration: none;
}

.pnl-brand-link:hover { text-decoration: none; }

/* The brand moment: the AAB wordmark on logo red, as on the app's splash. */
.pnl-brand-tile {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--aab-radius-sm);
    background: var(--aab-brand-ui);
    color: var(--aab-on-brand);
}

.pnl-brand-product {
    font-family: var(--aab-font-display);
    font-size: var(--aab-fs-title-s);
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}

/* --- The organisation's brand after sign-in (#287, Layout/ShellBrand.razor) ------
   Its colour arrives as --org-accent-light / -dark on .pnl-shell (MainLayout), only for the
   themes where it passes the contrast check (Core BrandAccent); otherwise the theme's accent.
   Owner 2026-10-27: the colour goes on the logo tile, the active menu item and a top accent
   line; buttons keep the platform colour. Without an organisation colour the line is not drawn. */
.pnl-shell {
    --brand-accent: var(--org-accent-light, var(--aab-accent));
    --brand-on-accent: var(--org-on-accent-light, var(--aab-on-accent));
    --brand-accent-soft: var(--org-accent-soft-light, var(--aab-accent-soft));
    --brand-accent-text: var(--org-accent-text-light, var(--aab-accent-text));
    --brand-line: var(--org-accent-light, transparent);
}

[data-theme="dark"] .pnl-shell {
    --brand-accent: var(--org-accent-dark, var(--aab-accent));
    --brand-on-accent: var(--org-on-accent-dark, var(--aab-on-accent));
    --brand-accent-soft: var(--org-accent-soft-dark, var(--aab-accent-soft));
    --brand-accent-text: var(--org-accent-text-dark, var(--aab-accent-text));
    --brand-line: var(--org-accent-dark, transparent);
}

/* While the organisation is fetched: the place is kept, nothing flashes. */
.pnl-brand-tile.pnl-brand-pending {
    background: var(--aab-surface-2);
}

/* No logo: the organisation's initials on its colour, its name beside them. */
.pnl-brand-tile.pnl-org-monogram {
    background: var(--brand-accent);
    color: var(--brand-on-accent);
    font-family: var(--aab-font-display);
    font-size: 19px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.02em;
}

.pnl-brand-product.pnl-org-name,
.pnl-brand-product.pnl-platform-name {
    min-width: 0;
    font-size: var(--aab-fs-lead);
    line-height: 1.15;
    white-space: normal;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
}

/* The logo from Bedrijfsgegevens is made for white paper (the PDF header): it sits on a white
   plate in both themes, so a JPEG's white box or dark lettering never clashes with the shell. */
.pnl-org-logo {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    max-width: 208px;
    height: 56px;
    padding: 6px 10px;
    border-radius: var(--aab-radius-sm);
    background: #FFFFFF;
    box-shadow: inset 0 0 0 1px var(--aab-line);
}

.pnl-org-logo img,
.pnl-platform-logo {
    display: block;
    width: auto;
    max-width: 100%;
    height: auto;
    max-height: 100%;
    object-fit: contain;
}

.pnl-platform-logo {
    max-width: 208px;
    max-height: 44px;
}

.pnl-sidebar-org {
    padding: 0 var(--aab-space-4) var(--aab-space-3);
}

/* --- Navigation ------------------------------------------------------------- */
.pnl-nav {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--aab-space-5);
    padding: var(--aab-space-2) var(--aab-space-3) var(--aab-space-5);
}

.pnl-nav-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Team and Instellingen sit apart from the daily work (#232). */
.pnl-nav-group--apart {
    padding-top: var(--aab-space-4);
    border-top: 1px solid var(--aab-line);
}

.pnl-nav-label {
    padding: 0 var(--aab-space-3) var(--aab-space-1);
    font-size: var(--aab-fs-caption);
    font-weight: 700;
    color: var(--aab-text-3);
}

.pnl-nav-link {
    display: flex;
    align-items: center;
    gap: var(--aab-space-3);
    min-height: var(--aab-target);
    padding: 0 var(--aab-space-3);
    border-radius: var(--aab-radius-sm);
    color: var(--aab-text-2);
    font-size: var(--aab-fs-body);
    font-weight: 600;
    text-decoration: none;
    transition: background-color var(--aab-duration-fast) var(--aab-ease-standard),
                color var(--aab-duration-fast) var(--aab-ease-standard);
}

.pnl-nav-link > i {
    width: 20px;
    flex-shrink: 0;
    text-align: center;
    font-size: 1.05rem;
    color: var(--aab-text-3);
}

.pnl-nav-link:hover {
    background: var(--aab-surface-2);
    color: var(--aab-text);
    text-decoration: none;
}

.pnl-nav-link.active {
    background: var(--brand-accent-soft);
    color: var(--brand-accent-text);
}

.pnl-nav-link.active > i { color: var(--brand-accent-text); }

.pnl-nav-link:focus-visible,
.pnl-icon-btn:focus-visible,
.pnl-brand-link:focus-visible,
.pnl-user-link:focus-visible {
    outline: 3px solid var(--aab-accent);
    outline-offset: 2px;
}

.pnl-nav-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pnl-nav-count {
    flex-shrink: 0;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--aab-radius-pill);
    background: var(--aab-surface-2);
    color: var(--aab-text-2);
    font-size: var(--aab-fs-caption);
    font-weight: 700;
}

.pnl-nav-count--warn {
    background: var(--aab-warn-soft);
    color: var(--aab-warn);
}

/* --- Sidebar footer: who is signed in, sign out, version --------------------- */
.pnl-sidebar-footer {
    padding: var(--aab-space-3) var(--aab-space-3) var(--aab-space-4);
    border-top: 1px solid var(--aab-line);
}

.pnl-user {
    display: flex;
    align-items: center;
    gap: var(--aab-space-1);
}

.pnl-user-link {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: var(--aab-space-3);
    padding: var(--aab-space-2);
    border-radius: var(--aab-radius-sm);
    color: var(--aab-text);
    text-decoration: none;
}

.pnl-user-link:hover {
    background: var(--aab-surface-2);
    text-decoration: none;
}

.pnl-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--aab-radius-pill);
    background: var(--aab-accent-soft);
    color: var(--aab-accent-text);
    font-size: var(--aab-fs-small);
    font-weight: 700;
}

.pnl-user-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.pnl-user-name,
.pnl-user-role {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pnl-user-name {
    font-size: var(--aab-fs-small);
    font-weight: 700;
}

.pnl-user-role {
    font-size: var(--aab-fs-caption);
    color: var(--aab-text-2);
}

.pnl-version {
    padding: var(--aab-space-1) var(--aab-space-2) 0;
    font-size: 11px;
    color: var(--aab-text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Profile menu (#232): the account items behind the name ------------------ */
.pnl-usermenu {
    position: relative;
    flex-direction: column;
    align-items: stretch;
}

/* A button now, not a link: undo the old theme's button fill, keep the row look. */
.pnl-shell .pnl-usermenu .pnl-user-link {
    width: 100%;
    border: none;
    background: transparent;
    box-shadow: none;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.pnl-shell .pnl-usermenu .pnl-user-link:hover,
.pnl-usermenu.is-open .pnl-user-link {
    background: var(--aab-surface-2);
}

.pnl-usermenu-caret {
    margin-left: auto;
    flex-shrink: 0;
    color: var(--aab-text-3);
    font-size: var(--aab-fs-caption);
}

.pnl-usermenu-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: var(--aab-space-2);
    padding: var(--aab-space-1);
    border: 1px solid var(--aab-line);
    border-radius: var(--aab-radius-sm);
    background: var(--aab-surface);
}

.pnl-usermenu-item {
    display: flex;
    align-items: center;
    gap: var(--aab-space-3);
    min-height: var(--aab-target);
    padding: 0 var(--aab-space-3);
    border-radius: var(--aab-radius-sm);
    color: var(--aab-text-2);
    font-size: var(--aab-fs-small);
    font-weight: 600;
    text-decoration: none;
}

.pnl-usermenu-item > span:not(.pnl-nav-count) { flex: 1 1 auto; }

.pnl-usermenu-item > i {
    width: 20px;
    text-align: center;
    color: var(--aab-text-3);
}

.pnl-usermenu-item:hover {
    background: var(--aab-surface-2);
    color: var(--aab-text);
    text-decoration: none;
}

.pnl-usermenu-item:focus-visible {
    outline: 3px solid var(--aab-accent);
    outline-offset: 2px;
}

.pnl-usermenu-item--apart {
    margin-top: var(--aab-space-1);
    border-top: 1px solid var(--aab-line);
    border-radius: 0 0 var(--aab-radius-sm) var(--aab-radius-sm);
}

/* "Uitloggen" is a POST form now, not a link (#288). The form steps out of the menu's layout
   and its button looks like the links above it: scoped under .pnl-shell to outrank the old
   theme's button[type="submit"] fill, border, centring and nowrap (0,1,1). */
.pnl-usermenu-form { display: contents; }

.pnl-shell button.pnl-usermenu-item {
    display: flex;
    justify-content: flex-start;
    gap: var(--aab-space-3);
    width: 100%;
    min-height: var(--aab-target);
    padding: 0 var(--aab-space-3);
    border: 0;
    border-radius: var(--aab-radius-sm);
    background: transparent;
    color: var(--aab-text-2);
    font: inherit;
    font-size: var(--aab-fs-small);
    font-weight: 600;
    line-height: inherit;
    text-align: left;
    white-space: normal;
    transition: none;
}

.pnl-shell button.pnl-usermenu-item:hover {
    background: var(--aab-surface-2);
    color: var(--aab-text);
}

.pnl-shell button.pnl-usermenu-item:focus-visible { box-shadow: none; }

.pnl-shell button.pnl-usermenu-item--apart {
    border-top: 1px solid var(--aab-line);
    border-radius: 0 0 var(--aab-radius-sm) var(--aab-radius-sm);
}

/* --- Icon buttons (top bar, drawer, sign out) ---------------------------------
   Scoped under .pnl-shell to outrank the old theme's button[type="button"] fill and border. */
.pnl-shell .pnl-icon-btn {
    position: relative;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--aab-target);
    height: var(--aab-target);
    padding: 0;
    border: none;
    border-radius: var(--aab-radius-sm);
    background: transparent;
    box-shadow: none;
    color: var(--aab-text-2);
    font-size: 1.15rem;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--aab-duration-fast) var(--aab-ease-standard),
                color var(--aab-duration-fast) var(--aab-ease-standard);
}

.pnl-shell .pnl-icon-btn:hover {
    background: var(--aab-surface-2);
    color: var(--aab-text);
    text-decoration: none;
}

.pnl-count-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--aab-radius-pill);
    background: var(--aab-accent);
    color: var(--aab-on-accent);
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
}

/* --- Main column and top bar ------------------------------------------------- */
.pnl-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.pnl-topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-chrome);
    display: flex;
    align-items: center;
    gap: var(--aab-space-2);
    height: var(--topbar-height);
    padding: 0 var(--aab-space-6);
    background: var(--aab-bg);
    border-bottom: 1px solid var(--aab-line);
    /* The organisation's top accent line (#287); transparent without an organisation colour. */
    box-shadow: inset 0 3px 0 var(--brand-line);
}

.pnl-topbar-search {
    flex: 0 1 440px;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: var(--aab-space-2);
}

.pnl-topbar-search > .quick-search-container {
    flex: 1 1 auto;
    min-width: 0;
}

.pnl-topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--aab-space-1);
}

/* Shown only below the breakpoints further down. Scoped under .pnl-shell: the old theme's
   button[type="button"] rule (0,1,1) would otherwise show them on desktop. */
.pnl-shell .pnl-menu-btn,
.pnl-shell .pnl-topbar-brand,
.pnl-shell .pnl-search-btn,
.pnl-shell .pnl-search-close,
.pnl-shell .pnl-nav-close,
.pnl-shell .pnl-backdrop {
    display: none;
}

.pnl-content {
    flex: 1 0 auto;
    width: 100%;
    max-width: var(--content-max-width, 1400px);
    min-width: 0;
    margin: 0 auto;
    padding: var(--aab-space-6) var(--aab-space-7) var(--aab-space-8);
}

.pnl-content:focus { outline: none; }

/* A page that fills the screen (the template builder; the map has its own rule in map-global.css,
   #271): its root carries .pnl-fill. The content area already takes the height left in the main
   column (flex 1 0 auto above); as a flex column it hands all of it to that root, which the page's
   own CSS passes on to the part that fills. So whatever stands between the top bar and the page
   (the Platform-operator bar, the environment banner, session and MFA warnings) only makes the page
   shorter. A calc(100vh - top bar) cannot know about those bars and ran past the bottom. */
.pnl-content:has(> .pnl-fill) {
    display: flex;
    flex-direction: column;
}

.pnl-content > .pnl-fill {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
}

/* --- Below 1024px: the sidebar becomes a drawer -------------------------------- */
@media (max-width: 1023.98px) {
    .pnl-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(320px, 86vw);
        height: auto;
        z-index: var(--z-modal);
        border-right: none;
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform var(--aab-duration-base) var(--aab-ease-exit),
                    visibility 0s linear var(--aab-duration-base);
    }

    .is-nav-open .pnl-sidebar {
        transform: none;
        visibility: visible;
        box-shadow: var(--shadow-xl);
        transition: transform var(--aab-duration-slow) var(--aab-ease-enter);
    }

    .pnl-shell .pnl-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: var(--z-modal-backdrop);
        background: var(--aab-overlay);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--aab-duration-base) var(--aab-ease-standard);
    }

    .is-nav-open .pnl-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .pnl-shell .pnl-nav-close,
    .pnl-shell .pnl-menu-btn,
    .pnl-shell .pnl-topbar-brand {
        display: inline-flex;
    }

    .pnl-topbar-brand .pnl-brand-tile {
        width: 34px;
        height: 34px;
    }

    /* The organisation's brand in the top bar (#287): room for the actions on a phone. */
    .pnl-shell .pnl-topbar-brand {
        align-items: center;
        gap: var(--aab-space-2);
        min-width: 0;
        max-width: min(200px, 42vw);
        color: var(--aab-text);
        text-decoration: none;
    }

    .pnl-topbar-brand .pnl-org-monogram {
        flex-shrink: 0;
        font-size: 15px;
    }

    .pnl-topbar-brand .pnl-org-name,
    .pnl-topbar-brand .pnl-platform-name {
        font-size: var(--aab-fs-small);
    }

    .pnl-topbar-brand .pnl-org-logo {
        height: 42px;
        max-width: 100%;
        padding: 4px 8px;
    }

    .pnl-topbar-brand .pnl-platform-logo {
        max-width: 100%;
        max-height: 34px;
    }

    .pnl-topbar {
        padding: 0 var(--aab-space-3);
    }

    .pnl-content {
        padding: var(--aab-space-5) var(--aab-space-5) var(--aab-space-8);
    }
}

/* --- Below 768px: search behind an icon ---------------------------------------- */
@media (max-width: 767.98px) {
    .pnl-topbar-search {
        display: none;
    }

    .pnl-shell .pnl-search-btn {
        display: inline-flex;
    }

    .is-search-open .pnl-topbar-search {
        display: flex;
        position: absolute;
        inset: 0;
        z-index: 1;
        padding: 0 var(--aab-space-3);
        background: var(--aab-bg);
    }

    .pnl-shell.is-search-open .pnl-search-close {
        display: inline-flex;
    }

    .pnl-content {
        padding: var(--aab-space-4) var(--aab-gutter) var(--aab-space-8);
    }
}

/* Profile photo over a round avatar's initials (AvatarPhoto, owner 2026-10-15). The photo covers
   the circle; the initials underneath show when there is none or it does not load. */
:where(.pnl-avatar, .km-av):has(> .avatar-photo) {
    position: relative;
    overflow: hidden;
}

.avatar-photo {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    object-fit: cover;
}
