.titlebar {
    background: linear-gradient(90deg, #ffffff 10%, #f8fafc 90%);
    border-bottom: 1px solid #e1e8ed;
    box-shadow: 0 4px 20px rgba(0,0,0,0.03);
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 1050;
    padding-inline: 0.5rem;
}

.titlebar__side,
.titlebar__center,
.titlebar__brand,
.titlebar__heading {
    display: flex;
    align-items: center;
    min-width: 0;
}

.titlebar__side {
    flex: 0 0 auto;
}

.titlebar__side--start {
    min-width: 0;
}

.titlebar__side--has-toggle {
    min-width: 40px;
}

.titlebar__side--end {
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    max-width: min(64vw, 620px);
}

/* One ordered group in both layouts; the layout decides which actions are in it,
   not which of two groups renders. The end side used to hold both — two flex
   contexts that could not shrink into each other, which is what overlapped.
   Deliberately not a scroll container: that clips the search field and the
   notification panel. Overflow is what grouping is for, and the rail scrolls. */
.titlebar__actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    min-width: 0;
    max-width: 100%;
    padding-block: 0.2rem;
}

.titlebar__action-slot,
.titlebar__action-form {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    margin: 0;
}

.titlebar__actions .dlux-notifications {
    margin: 0 !important;
}


.titlebar__center {
    flex: 1 1 auto;
    min-width: 0;
}

.titlebar__brand {
    width: 100%;
    gap: 0.5rem;
}

.titlebar__heading {
    flex: 1 1 auto;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
}

/* A centred title is centred on the bar, not between its sides. Between the sides
   it moved whenever an action was added or changed width (weather's reading
   loading into its button, say). Only the heading is taken out of flow, so the
   logo keeps its place at the start. The action rail sets
   --dlux-titlebar-title-room to the width left free on both sides of the centre,
   and groups actions before that runs out, so the title truncates rather than
   running under an action. */
.titlebar[data-title-align="center"] .titlebar__heading {
    position: absolute;
    inset-block-start: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: max-content;
    max-width: var(--dlux-titlebar-title-room, 40vw);
}

.titlebar[data-title-align="center"] .titlebar__heading > * {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* The heading is centred on the bar above; the logo stays at the start, where
   it sat when the heading stretched across the centre. */
.titlebar[data-title-align="center"] .titlebar__brand {
    justify-content: flex-start;
}

.titlebar[data-title-align="center"] .titlebar__heading {
    align-items: center;
    text-align: center;
}

.titlebar[data-title-align="end"] .titlebar__brand {
    justify-content: flex-end;
}

.titlebar[data-title-align="end"] .titlebar__heading {
    align-items: flex-end;
    text-align: end;
}

.titlebar[data-title-align="start"] .titlebar__brand {
    justify-content: flex-start;
}

.titlebar[data-title-align="start"] .titlebar__heading {
    align-items: flex-start;
    text-align: start;
}

/* Align the name + scope row inside a (possibly full-width) truncated title. */
.titlebar[data-title-align="center"] .titlebar__title {
    justify-content: center;
}

.titlebar[data-title-align="end"] .titlebar__title {
    justify-content: flex-end;
}

.titlebar__title {
    color: #2c3e50;
    font-weight: 800;
    transition: all 0.3s;
    font-size: clamp(1.1rem, 1.4vw, 1.8rem);
    margin: 0;
    line-height: 1.18;
    padding-block: 0.06em 0.12em;
    display: flex;
    align-items: center;
    /* max-width caps the title to its column so a long title truncates instead of
       spilling over the home / user-hub buttons; min-width:0 lets the name shrink. */
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    flex-shrink: 1;
}

.titlebar__title-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.titlebar__title-scope {
    flex: 0 0 auto;
    white-space: nowrap;
}

/* Adaptive brand (toggled by dlux/titlebar/js/main.js): drop the scope suffix before the system
   name, and collapse an unreadably-narrow heading so the logo carries the brand. */
.titlebar__title--name-only .titlebar__title-scope {
    display: none;
}

.titlebar__heading--collapsed {
    display: none;
}

.titlebar__header-slot {
    min-width: 0;
}

.titlebar__header-slot:empty {
    display: none;
}

.titlebar[data-titlebar-show-logo="false"] .titlebar__logo {
    display: none;
}

.titlebar[data-titlebar-show-title="false"] .titlebar__title {
    display: none !important;
}

:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-show-home="false"] .dlux-titlebar-home {
    display: none;
}

:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-show-language-switcher="false"] .dlux-titlebar-lang-cycle {
    display: none;
}

.titlebar[data-title-size="sm"] .titlebar__title {
    font-size: clamp(1rem, 1.2vw, 1.4rem);
}

.titlebar[data-title-size="md"] .titlebar__title {
    font-size: clamp(1.1rem, 1.4vw, 1.8rem);
}

.titlebar[data-title-size="lg"] .titlebar__title {
    font-size: clamp(1.2rem, 1.8vw, 2.1rem);
}

.titlebar[data-titlebar-height="dense"] {
    height: calc(var(--header-height) - 8px);
}

.titlebar[data-titlebar-height="roomy"] {
    height: calc(var(--header-height) + 8px);
}

.titlebar[data-titlebar-surface="muted"] {
    background: linear-gradient(90deg, #f8fafc 10%, #eef2f7 90%);
}

.titlebar[data-titlebar-surface="glass"] {
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.72) 10%, rgba(248, 250, 252, 0.78) 90%);
    backdrop-filter: blur(12px);
}

.titlebar .btn-light {
    background-color: transparent !important;
    border: none !important;
    color: var(--primal) !important;
    font-weight: 600 !important;
    transition: all 0.2s ease;
    border-radius: 8px !important;
}

.titlebar .btn-light:hover {
    background-color: rgba(var(--primal-rgb), 0.08) !important;
    color: var(--primal) !important;
    transform: translateY(-1px);
}

.titlebar .login-title-btn {
    border: none !important;
}

.titlebar .login-title-btn:hover {
    border-color: rgba(var(--primal-rgb), 0.2) !important;
}

:is(.titlebar, .dlux-titlebar-rail) .dlux-titlebar-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--title);
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(var(--primal-rgb), 0.12);
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
    font-size: 1rem;
    flex: 0 0 auto;
    padding: 0;
}

:is(.titlebar, .dlux-titlebar-rail) button.dlux-titlebar-btn {
    appearance: none;
    cursor: pointer;
}

/* Search, theme and language used to sit outside the action group as loose
   siblings with no gap between them, so each carried its own margin. Inside the
   group those margins stack on top of the flex gap — a wider space between
   exactly these three and nothing else. They are ordinary actions now. */
.titlebar__actions .dlux-titlebar-lang-cycle,
.titlebar__actions .dlux-titlebar-theme-cycle,
.titlebar__actions .dlux-global-search {
    margin-inline: 0;
}

/* The user hub style decides which actions it offers; both sets render so the
   settings page can preview a style change without a round trip. */
.titlebar[data-titlebar-user-hub-style="dropdown"] [data-titlebar-action-scope="titlebar_actions"],
.dlux-titlebar-rail[data-titlebar-user-hub-style="dropdown"] [data-titlebar-action-scope="titlebar_actions"] {
    display: none !important;
}

/* The swatch reads as the current theme, the way the language action reads as
   the current language code. */
:is(.titlebar, .dlux-titlebar-rail) .dlux-titlebar-theme-cycle__dot {
    display: block;
    width: 0.85rem;
    height: 0.85rem;
    border-radius: 50%;
    border: 1px solid rgba(127, 127, 127, 0.45);
    background: var(--primal, #2363c3);
}

:is(.titlebar, .dlux-titlebar-rail) .dlux-titlebar-lang-cycle__code {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    line-height: 1;
    text-transform: uppercase;
}

:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-buttons-shape="square"] .dlux-titlebar-action,
:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-buttons-shape="square"] .dlux-titlebar-home,
:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-buttons-shape="square"] .dlux-notifications__trigger,
:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-buttons-shape="square"] .dlux-login-round,
:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-home-shape="square"] .dlux-titlebar-home,
:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-home-shape="square"] .dlux-notifications__trigger,
:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-home-shape="square"] .dlux-login-round {
    border-radius: 10px;
}

:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-buttons-shape="squircle"] .dlux-titlebar-action,
:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-buttons-shape="squircle"] .dlux-titlebar-home,
:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-buttons-shape="squircle"] .dlux-notifications__trigger,
:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-buttons-shape="squircle"] .dlux-login-round,
:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-home-shape="squircle"] .dlux-titlebar-home,
:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-home-shape="squircle"] .dlux-notifications__trigger,
:is(.titlebar, .dlux-titlebar-rail)[data-titlebar-home-shape="squircle"] .dlux-login-round {
    border-radius: 14px;
}

:is(.titlebar, .dlux-titlebar-rail) .dlux-titlebar-btn:hover,
:is(.titlebar, .dlux-titlebar-rail) .dlux-titlebar-btn:focus,
:is(.titlebar, .dlux-titlebar-rail) .dlux-titlebar-btn:focus-visible {
    color: var(--primal_dark);
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(var(--primal-rgb), 0.22);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
    outline: none;
}

:is(.titlebar, .dlux-titlebar-rail) .dlux-titlebar-home i,
:is(.titlebar, .dlux-titlebar-rail) .dlux-titlebar-action i,
:is(.titlebar, .dlux-titlebar-rail) .dlux-login-round i {
    font-size: 1rem;
    line-height: 1;
}

.titlebar__logo {
    height: 42px;
    width: auto;
    padding: 4px;
    border-radius: 8px;
    margin-inline-end: 10px;
    transition: all 0.3s;
}

.titlebar[data-titlebar-logo-treatment="plate"] .titlebar__logo {
    background:
        linear-gradient(135deg, rgba(var(--primal-rgb, 13, 110, 253), 0.1), transparent 58%),
        color-mix(in srgb, var(--hbody, #ffffff) 84%, transparent);
    border: 1px solid rgba(var(--primal-rgb, 13, 110, 253), 0.18);
    box-shadow:
        0 0.45rem 1.15rem rgba(15, 23, 42, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.32);
}

.titlebar[data-titlebar-logo-treatment="plate"][data-titlebar-logo-treatment-shape="soft"] .titlebar__logo {
    border-radius: 12px;
}

.titlebar[data-titlebar-logo-treatment="plate"][data-titlebar-logo-treatment-shape="pill"] .titlebar__logo {
    border-radius: 999px;
    padding-inline: 8px;
}

.titlebar[data-titlebar-logo-treatment="plate"][data-titlebar-logo-treatment-shape="square"] .titlebar__logo {
    border-radius: 4px;
}

.titlebar[data-titlebar-logo-treatment="halo"] .titlebar__logo {
    filter:
        drop-shadow(0 0 0.35rem rgba(var(--primal-rgb, 13, 110, 253), 0.42))
        drop-shadow(0 0.35rem 0.85rem rgba(15, 23, 42, 0.16));
}

.titlebar[data-titlebar-logo-treatment="contrast"] .titlebar__logo {
    filter:
        brightness(1.08)
        contrast(1.12)
        drop-shadow(0 1px 0 color-mix(in srgb, var(--hbody, #ffffff) 70%, transparent))
        drop-shadow(0 0.18rem 0.55rem rgba(15, 23, 42, 0.22));
}

.titlebar[data-sidebar-collapse-mode="locked_expanded"] .sidebar-toggle {
    display: none;
}

.titlebar .sidebar-toggle--desktop-disabled {
    display: none;
}

@media (max-width: 1099.98px) {
    .titlebar .sidebar-toggle--desktop-disabled {
        display: inline-flex !important;
    }

    .titlebar__side--mobile-toggle {
        min-width: 40px;
    }
}

.titlebar[data-titlebar-buttons-shape="square"] .sidebar-toggle {
    border-radius: 10px;
}

.titlebar[data-titlebar-buttons-shape="squircle"] .sidebar-toggle {
    border-radius: 14px;
}

/* ── Grouped actions ────────────────────────────────────────────────────────
   The end side carries two groups that do not share a flex context, and nothing
   inside either shrinks, so past a certain width they overlap instead of
   compressing — and the brand is squeezed out well before that. Grouping moves
   every optional action into one rail under the bar (dlux/titlebar/js/action_rail.js),
   leaving Home, the rail's own caret, and the user hub behind. */

.titlebar__constants {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    flex: 0 0 auto;
}

/* The user hub trigger used to sit inside the dropdown action group, which the
   Titlebar Actions layout hides wholesale. It stands on its own now, so that
   layout has to hide it by name. */
.titlebar[data-titlebar-user-hub-style="titlebar_actions"] .dlux-user-trigger {
    display: none;
}

/* Hidden until the actions are actually grouped. Specificity has to clear
   `:is(.titlebar, .dlux-titlebar-rail) .dlux-titlebar-btn`, which the caret now is. */
.titlebar:not([data-titlebar-actions-grouped="true"]) .dlux-titlebar-rail-toggle {
    display: none;
}

.dlux-titlebar-rail-toggle {
    position: relative;
}

.dlux-titlebar-rail-toggle i {
    transition: transform 0.25s ease;
}

.dlux-titlebar-rail-toggle[aria-expanded="true"] i {
    transform: rotate(180deg);
}

/* Grouped, the bell's badge is out of sight until the rail opens, so the caret
   that now stands in for it carries the unread state. */
.dlux-titlebar-rail-toggle[data-dlux-rail-alert="true"]::after {
    content: "";
    position: absolute;
    inset-block-start: -1px;
    inset-inline-end: -1px;
    width: 9px;
    height: 9px;
    border: 2px solid var(--hbody, #fff);
    border-radius: 50%;
    background: #dc2626;
}

/* The rail lives outside .titlebar on purpose: the bar is a z-index stacking
   context and its Glass surface sets a backdrop-filter, either of which would box
   in the notification panel and search field the rail now hosts. */
.dlux-titlebar-rail {
    --dlux-titlebar-rail-gap: 15px;
    position: fixed;
    top: calc(var(--header-height) + 10px);
    inset-inline-end: var(--dlux-titlebar-rail-gap);
    inset-inline-start: auto;
    /* Wide enough for every action it holds, and no wider. Where that does not
       fit, it wraps onto another line rather than scrolling: an action parked off
       the edge of a scroller is an action nobody finds. */
    width: max-content;
    max-width: calc(100vw - (var(--dlux-titlebar-rail-gap) * 2));
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: space-evenly;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid rgba(var(--primal-rgb), 0.12);
    border-radius: 18px;
    background: var(--table-row, #fff);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.16);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.dlux-titlebar-rail.is-grouped {
    display: flex;
}

.dlux-titlebar-rail.is-grouped.show {
    opacity: 1;
}

/* Inside the rail the actions space themselves evenly, so drop the margins they
   use to separate themselves along the bar. */
.dlux-titlebar-rail .dlux-titlebar-theme-cycle,
.dlux-titlebar-rail .dlux-titlebar-lang-cycle,
.dlux-titlebar-rail .dlux-notifications,
.dlux-titlebar-rail .titlebar__action-form {
    margin: 0;
}

/* Each toggle keeps its own panel, and the panel opens downward from the rail
   rather than from the top of the viewport — so it never covers the rail or the
   caret that opened it. Static wrappers hand the anchoring to the rail itself,
   which keeps a panel from running off the edge when its toggle sits near one. */
.dlux-titlebar-rail .dlux-notifications,
.dlux-titlebar-rail .dlux-global-search {
    position: static;
}

.dlux-titlebar-rail .dlux-notifications__panel,
.dlux-titlebar-rail .dlux-global-search.dlux-global-search--open .dlux-global-search__box {
    position: absolute;
    inset-block-start: calc(100% + 0.5rem);
    inset-inline: 0;
    width: auto;
    min-width: 0;
    max-width: none;
}

.dlux-titlebar-rail .dlux-global-search[data-global-search-mode] .dlux-global-search__results {
    position: absolute;
    inset-block-start: calc(100% + 3.15rem);
    inset-inline: 0;
    width: auto;
    max-width: none;
}

/* Opening search must not resize the titlebar. In flow, the field's own width
   pushed the brand aside as you typed; anchored to its toggle it overlays the row
   instead and the title never moves. The toggle stays put underneath — collapsing
   it left a hole where the button had been, and in the rail that hole sat among
   the other actions. */
.titlebar__actions .dlux-global-search[data-global-search-mode].dlux-global-search--open .dlux-global-search__toggle,
.dlux-titlebar-rail .dlux-global-search[data-global-search-mode].dlux-global-search--open .dlux-global-search__toggle {
    display: inline-flex;
}

/* Above the mobile breakpoint the always-visible field is never an icon: the
   toggle's `.dlux-titlebar-btn` display must not bring it back beside the field,
   and focusing the field keeps it in flow instead of re-anchoring it. */
@media (min-width: 768px) {
    :is(.titlebar__actions, .dlux-titlebar-rail) .dlux-global-search[data-global-search-mode="always"]:not(.dlux-global-search--open) .dlux-global-search__toggle,
    .titlebar__actions .dlux-global-search[data-global-search-mode="always"].dlux-global-search--open .dlux-global-search__toggle {
        display: none;
    }

    .titlebar__actions .dlux-global-search[data-global-search-mode="icon"].dlux-global-search--open .dlux-global-search__box {
        position: absolute;
        inset-block-start: 50%;
        inset-inline-end: calc(100% + 0.4rem);
        transform: translateY(-50%);
        z-index: 2;
    }
}

/* Narrow screens enforce what the settings only prefer: actions group behind the
   caret (decided in dlux/titlebar/js/action_rail.js, which the media query cannot
   do because it moves DOM), and the brand runs at the small size with a tighter
   logo whatever the configured title size says — the row still has to carry Home,
   the caret and the user hub. */
@media (max-width: 575.98px) {
    .titlebar[data-title-size] .titlebar__title {
        font-size: clamp(0.95rem, 3.4vw, 1.15rem);
    }

    .titlebar__logo {
        height: 32px;
        padding: 2px;
        margin-inline-end: 6px;
    }

    .dlux-titlebar-rail {
        --dlux-titlebar-rail-gap: 10px;
        top: calc(var(--header-height) + 8px);
        border-radius: 14px;
    }
}
