﻿/* ==========================================================================
   layout.css
   Design System - Application Shell
   --------------------------------------------------------------------------
   Global styles for the app shell: header, sidebar navigation, main content
   area, footer and profile popover.

   Why global and not Blazor scoped CSS (.razor.css):
     - Scoped CSS cannot be shared between products.
     - Scoped CSS needs ::deep to reach inside MudBlazor components.
     - Global classes under the "ds-" prefix are reusable and safe, because
       every MudBlazor selector below is nested under a ds- parent class and
       cannot leak into other screens.

   Rules:
     - Every value comes from tokens.css.
     - Logical properties only, so Arabic RTL and English LTR both work.
     - Interactive targets are at least 44 x 44 px.

   Contents:
     1. Header
     2. Sidebar and navigation
     3. Main content area
     4. Footer
     5. Profile popover
   ========================================================================== */


/* ==========================================================================
   1. HEADER
   Markup:
     <MudAppBar Class="ds-header" Fixed="true" Elevation="0"> ... </MudAppBar>
   Order (start to end): menu toggle, brand link, search, action group.
   Action group: language, sync, divider, theme, notifications, avatar.
   ========================================================================== */

.mud-appbar .mud-toolbar-appbar {
    block-size: var(--size-header-height);
    min-block-size: var(--size-header-height);
}

.mud-appbar.ds-header {
    --mud-appbar-height: var(--size-header-height);
    /* Header-only values, defined once so the controls always match */
    background-color: var(--color-bg-shell);
    color: var(--color-text-inverse);
    box-shadow: none;
    border-block-end: var(--border-width-thin) solid var(--color-border-on-shell);
    --ds-sync-bg: var(--color-bg-surface);
    --ds-sync-bg-hover: var(--color-bg-primary-soft);
    --ds-sync-border: transparent;
}

.theme-dark .mud-appbar.ds-header {
    --ds-sync-bg: var(--color-bg-primary-soft);
    --ds-sync-bg-hover: var(--color-bg-primary-soft-hover);
    --ds-sync-border: var(--color-border-primary);
}

/* Icon-only buttons on the dark header (menu, theme, notifications).
   .mud-button-root raises specificity above the global MudIconButton color rule in mudblazor-overrides.css. */
.ds-header .ds-header__icon-btn.mud-button-root.mud-icon-button {
    --mud-palette-action-default-hover: var(--color-bg-on-shell-hover);
    min-inline-size: var(--size-touch-target-min);
    min-block-size: var(--size-touch-target-min);
    color: var(--color-text-inverse);
    border-radius: var(--radius-md);
}

    .ds-header .ds-header__icon-btn.mud-button-root.mud-icon-button:hover {
        background-color: var(--color-bg-on-shell-hover);
    }

    .ds-header .ds-header__icon-btn.mud-button-root.mud-icon-button:focus-visible {
        outline: var(--focus-ring-width) solid var(--color-text-inverse);
        outline-offset: var(--focus-ring-offset);
    }

/* Brand: logo link to the home page. The text name is screen-reader only. */
.ds-header__brand {
    display: inline-flex;
    align-items: center;
    min-block-size: var(--size-touch-target-min);
    margin-inline-start: var(--space-2);
    color: var(--color-text-inverse);
    border-radius: var(--radius-md);
}

    .ds-header__brand:focus-visible {
        outline: var(--focus-ring-width) solid var(--color-text-inverse);
        outline-offset: var(--focus-ring-offset);
    }

.ds-header__logo {
    display: block;
    block-size: var(--size-icon-xl);
    inline-size: auto;
}

/* Fills the gap on small screens, where the search box is hidden */
.ds-header__spacer {
    flex: 1 1 auto;
}

/* Command search box. Hidden below 960px (breakpoint below). */
.ds-header__search {
    display: none;
    align-items: center;
    gap: var(--space-3);
    flex: 1 1 auto;
    max-inline-size: var(--size-header-search-max);
    block-size: var(--size-header-control);
    margin-inline: auto;
    padding-inline: var(--space-3);
    background-color: var(--color-bg-on-shell);
    border: var(--border-width-thin) solid var(--color-border-on-shell-input);
    border-radius: var(--radius-md);
    color: var(--color-text-inverse);
}

    .ds-header__search:focus-within {
        outline: var(--focus-ring-width) solid var(--color-text-inverse);
        outline-offset: var(--focus-ring-offset);
    }

.ds-header__search-input {
    flex: 1 1 auto;
    min-inline-size: 0;
    padding: 0;
    background: transparent;
    border: 0;
    outline: none;
    font-family: inherit;
    font-size: var(--font-size-sm);
    color: inherit;
}

    .ds-header__search-input::placeholder {
        color: var(--color-text-on-shell-muted);
        opacity: 1;
    }

/* Keyboard shortcut chip: a soft translucent pill, not a dark box.
   Background and shadow are set explicitly because global kbd styles
   (for example Bootstrap) would otherwise paint it dark. */
.ds-header__kbd {
    display: inline-flex;
    align-items: center;
    padding: var(--space-0-5) var(--space-2);
    background-color: var(--color-bg-on-shell-kbd);
    border: var(--border-width-thin) solid var(--color-border-on-shell-kbd);
    border-radius: var(--radius-xs);
    box-shadow: none;
    font-family: var(--font-family-base);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    line-height: var(--line-height-normal);
    color: var(--color-text-inverse);
    /* Keeps "Ctrl K" in Latin order inside Arabic text */
    direction: ltr;
    unicode-bidi: isolate;
}

@media (min-width: 960px) {
    .ds-header__search {
        display: flex;
    }

    .ds-header__spacer {
        display: none;
    }
}

.ds-header__actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

/* Rectangular text buttons (language, sync): 38px visible height.
   Ripples stay clipped inside the button. */
.ds-header .ds-header__btn.mud-button-root {
    position: relative;
    overflow: hidden;
    block-size: var(--size-header-control);
    min-block-size: 0;
    padding-block: 0;
    padding-inline: var(--space-3-5);
    border-radius: var(--radius-md);
    font-family: var(--font-family-base);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    line-height: var(--line-height-snug);
    text-transform: none;
    box-shadow: none;
}


    /* Icon sits at the inline-start, with one gap between icon and text */
    .ds-header .ds-header__btn.mud-button-root .mud-button-label {
        gap: var(--space-2);
    }

    .ds-header .ds-header__btn.mud-button-root .mud-button-icon-start {
        margin-inline: 0;
    }

    .ds-header .ds-header__btn.mud-button-root .mud-icon-root {
        inline-size: var(--size-icon-md);
        block-size: var(--size-icon-md);
    }

    .ds-header .ds-header__btn.mud-button-root:focus-visible {
        outline: var(--focus-ring-width) solid var(--color-text-inverse);
        outline-offset: var(--focus-ring-offset);
    }

/* Outlined: transparent with a light border (language) */
.ds-header .ds-header__btn--outline.mud-button-root {
    background-color: transparent;
    border: var(--border-width-thin) solid var(--color-border-on-shell);
    color: var(--color-text-inverse);
}

    .ds-header .ds-header__btn--outline.mud-button-root:hover {
        background-color: var(--color-bg-on-shell-hover);
    }

/* Vertical divider between the button groups */
.ds-header .ds-divider--vertical {
    border-inline-start-color: var(--color-border-on-shell);
}

/* Profile avatar: white circle with the first letter of the user name */
.ds-header__avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    inline-size: var(--size-touch-target-min);
    block-size: var(--size-touch-target-min);
    padding: 0;
    background-color: var(--color-bg-surface);
    border: 0;
    border-radius: var(--radius-full);
    font-family: inherit;
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
    cursor: pointer;
}

    .ds-header__avatar:hover {
        background-color: var(--color-bg-primary-soft);
    }

    .ds-header__avatar:focus-visible {
        outline: var(--focus-ring-width) solid var(--color-text-inverse);
        outline-offset: var(--focus-ring-offset);
    }

/* Sync button: white surface with status-aware text and icon.
   Status classes come from GetSyncIconClass():
   default = idle (primary), --success, --warning (syncing / pending), --danger (error). */
.ds-header .ds-header__sync.mud-button-root {
    background-color: var(--ds-sync-bg);
    border: var(--border-width-thin) solid var(--ds-sync-border);
    color: var(--color-text-primary);
    font-weight: var(--font-weight-semibold);
}

    .ds-header .ds-header__sync.mud-button-root:hover {
        background-color: var(--color-bg-primary-soft);
    }

    .ds-header .ds-header__sync.mud-button-root .mud-icon-root {
        color: inherit;
    }

.ds-header .ds-header__sync--success.mud-button-root {
    color: var(--color-status-success-text);
}

    .ds-header .ds-header__sync--success.mud-button-root:hover {
        background-color: var(--color-status-success-soft);
    }

.ds-header .ds-header__sync--warning.mud-button-root {
    background-color: var(--color-status-warning-fill);
    border-color: var(--color-status-warning-border);
    color: var(--color-status-warning-text);
}

    .ds-header .ds-header__sync--warning.mud-button-root:hover {
        background-color: var(--color-status-warning-border);
    }

.ds-header .ds-header__sync--danger.mud-button-root {
    background-color: var(--color-status-danger-fill);
    border-color: var(--color-status-danger-border);
    color: var(--color-status-danger-text);
}

    .ds-header .ds-header__sync--danger.mud-button-root:hover {
        background-color: var(--color-status-danger-border);
    }

/* Prevent MudBlazor default fill from turning stroke icons into black blobs */
.ds-header .mud-icon-root.mud-svg-icon g[fill="none"] {
    fill: none !important;
}


/* ==========================================================================
   2. SIDEBAR AND NAVIGATION
   Markup:
     <MudDrawer Class="ds-sidebar" Width="var(--size-sidebar-width)" ...>
       <NavMenu />
     </MudDrawer>
   NavMenu root:
     <div class="ds-nav">
       <MudNavMenu Class="ds-nav__menu"> ... <MudDivider Class="ds-nav__divider" /> ... </MudNavMenu>
     </div>
   Spacing between items comes from CSS, so the markup needs no "mt-3" classes.
   ========================================================================== */
.mud-drawer.ds-sidebar {
    background-color: var(--color-bg-surface) !important;
    color: var(--color-text-foreground) !important;
    border-inline-end: var(--border-width-thin) solid var(--color-border-default) !important;
    box-shadow: none !important;
}

    .mud-drawer.ds-sidebar .mud-drawer-content {
        display: flex;
        flex-direction: column;
        block-size: 100%;
    }

/* Sidebar nav root. A plain container: no surface, shadow or radius of its own,
   so the drawer background shows through and nothing looks like a floating card.
   flex-shrink is 0 so the nav grows with its content when a group expands;
   the drawer content then scrolls instead of the links overflowing a fixed box.
   min-block-size keeps it full height when the list is short, so the divider
   can still push the utility groups to the bottom. */
.ds-nav {
    display: flex;
    flex-direction: column;
    flex: 1 0 auto;
    min-block-size: 100%;
    padding-block: var(--space-6) var(--space-4); /* Breathing room above the first item */
    padding-inline: var(--space-3);
    background-color: transparent;
    border-radius: 0;
    box-shadow: none;
}

    /* Must be a flex column so the divider can push the bottom section down.
       flex-grow fills .ds-nav; it must not shrink below its content. */
    .ds-nav .mud-navmenu.ds-nav__menu {
        display: flex;
        flex-direction: column;
        flex: 1 0 auto;
        padding: 0;
    }

    /* Space between top-level and nested items */
    .ds-nav .mud-nav-item,
    .ds-nav .mud-nav-group {
        margin-block-end: var(--space-1);
    }

    /* Base style for links and group headers */
    .ds-nav .mud-nav-link {
        display: flex;
        align-items: center;
        min-block-size: var(--size-touch-target-min);
        padding-block: var(--space-2);
        padding-inline: var(--space-3);
        border-radius: var(--radius-md) !important;
        font-size: var(--font-size-md);
        font-weight: var(--font-weight-medium);
        line-height: var(--line-height-snug);
        color: var(--color-text-secondary) !important;
        transition: background-color var(--duration-fast) var(--easing-standard), color var(--duration-fast) var(--easing-standard);
    }

        .ds-nav .mud-nav-link .mud-nav-link-text {
            margin-inline-start: var(--space-3) !important;
            margin-inline-end: 0 !important;
            font-family: var(--font-family-base);
            font-size: inherit;
            font-weight: inherit;
            color: inherit !important;
        }

        /* Hover state */
        .ds-nav .mud-nav-link:hover:not(.active) {
            background-color: var(--color-bg-surface-hover) !important;
            color: var(--color-text-foreground) !important;
        }

        .ds-nav .mud-nav-link:focus-visible {
            outline: var(--focus-ring-width) solid var(--focus-ring-color);
            outline-offset: calc(var(--focus-ring-width) * -1);
        }

        /* Selected item: soft tint background with strong primary text and icon */
        .ds-nav .mud-nav-link.active:not(.mud-nav-link-disabled) {
            background-color: var(--color-bg-selected) !important;
            color: var(--color-text-primary) !important;
            font-weight: var(--font-weight-bold) !important;
        }

        /* Icons inside nav links */
        .ds-nav .mud-nav-link .mud-nav-link-icon {
            color: var(--color-text-muted) !important;
            margin-inline: 0 !important;
            inline-size: var(--size-icon-md);
            block-size: var(--size-icon-md);
        }

        .ds-nav .mud-nav-link:hover:not(.active) .mud-nav-link-icon {
            color: var(--color-text-secondary) !important;
        }

        .ds-nav .mud-nav-link.active:not(.mud-nav-link-disabled) .mud-nav-link-icon {
            color: var(--color-text-primary) !important;
        }

    /* Prevents MudBlazor's default SVG fill from filling the stroke paths of custom icons */
    .ds-nav .mud-icon-root.mud-svg-icon g[fill="none"] {
        fill: none !important;
    }

    /* Expand/collapse chevron on MudNavGroup */
    .ds-nav .mud-nav-link-expand-icon {
        color: var(--color-text-muted) !important;
        margin-inline-start: auto !important;
        margin-inline-end: 0 !important;
    }

    /* Sub-items inside an expanded group: indented, matching readable `--font-size-md` */
    .ds-nav .mud-collapse-container .mud-nav-link {
        padding-inline-start: var(--space-6) !important;
        font-size: var(--font-size-md) !important;
    }

        .ds-nav .mud-collapse-container .mud-nav-link .mud-nav-link-text {
            font-size: var(--font-size-md) !important;
        }



    /* Push the divider and the 3 utility groups immediately below it to the bottom of the sidebar */
    .ds-nav .ds-nav__divider,
    .ds-nav hr.ds-nav__divider.mud-divider {
        flex-shrink: 0;
        inline-size: 100%;
        block-size: 0 !important;
        margin-block-start: auto !important;
        margin-block-end: var(--space-2) !important;
        padding: 0 !important;
        border: 0 !important;
        border-block-start: var(--border-width-thin) solid var(--color-border-default) !important;
        background-color: transparent !important;
        opacity: 1 !important;
    }

        /* Ensure the group immediately following the divider stays snug right under the line */
        .ds-nav .ds-nav__divider + .mud-nav-group,
        .ds-nav .ds-nav__divider + .mud-nav-item {
            margin-block-start: 0 !important;
        }

/* Desktop Mini-Rail State (68px width when collapsed on >= 960px) */
.mud-drawer.mud-drawer--closed.mud-drawer-mini-md,
.mud-drawer.mud-drawer--closed.mud-drawer-mini-lg {
    inline-size: var(--size-sidebar-rail) !important;
    overflow-x: hidden !important;
}

.mud-drawer.mud-drawer--closed .ds-nav .mud-nav-link-text,
.mud-drawer.mud-drawer--closed .ds-nav .mud-nav-link-expand-icon,
.mud-drawer.mud-drawer--closed .ds-nav .mud-collapse-entering,
.mud-drawer.mud-drawer--closed .ds-nav .mud-collapse-entered,
.mud-drawer.mud-drawer--closed .ds-nav .mud-nav-group > .mud-collapse-container {
    display: none !important;
}

.mud-drawer.mud-drawer--closed .ds-nav .mud-nav-link {
    justify-content: center !important;
    inline-size: var(--size-touch-target-min) !important;
    block-size: var(--size-touch-target-min) !important;
    min-block-size: var(--size-touch-target-min) !important;
    margin-inline: auto !important;
    padding: 0 !important;
    border-radius: var(--radius-lg) !important;
}


/* ==========================================================================
   3. MAIN CONTENT AREA
   Markup:
     <MudMainContent Class="ds-main">
       <div class="ds-content">@Body</div>
       <OesLayoutFooter />
     </MudMainContent>
   ========================================================================== */
.mud-main-content.ds-main {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    min-block-size: 100vh;
    min-block-size: 100dvh;
    background-color: var(--color-bg-background);
}

.ds-content {
    flex: 1 1 auto;
    min-inline-size: 0;
    padding-block: var(--space-6);
    padding-inline: var(--space-4);
}

@media (min-width: 600px) {
    .ds-content {
        padding-inline: var(--space-6);
    }
}

@media (min-width: 960px) {
    .ds-content {
        padding-block: var(--space-12) var(--space-8);
        padding-inline: var(--space-10);
    }
}


/* ==========================================================================
   4. FOOTER
   Markup:
     <footer class="ds-footer">
       <p class="ds-footer__text">...</p>
       <p class="ds-footer__text">...</p>
     </footer>
   The first text sits on the start side and the second on the end side.
   ========================================================================== */
.ds-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
    padding-block: var(--space-3);
    padding-inline: var(--space-4);
    background-color: var(--color-bg-background);
    border-block-start: var(--border-width-thin) solid var(--color-border-default);
}

.ds-footer__text {
    margin: 0;
    font-size: var(--font-size-xs);
    line-height: var(--line-height-normal);
    color: var(--color-text-muted);
}

@media (min-width: 600px) {
    .ds-footer {
        padding-inline: var(--space-6);
    }
}

@media (min-width: 960px) {
    .ds-footer {
        padding-inline: var(--space-10);
    }
}


/* ==========================================================================
   5. PROFILE POPOVER
   Markup:
     <MudPopover Class="ds-profile-popover" ...>
       <div @onclick:stopPropagation="true">
         <MudCard Class="ds-profile" Elevation="0"> ... </MudCard>
       </div>
     </MudPopover>
     <div class="ds-popover-backdrop" @onclick="ClosePopover"></div>
   ========================================================================== */
.ds-profile-popover {
    z-index: var(--z-modal);
    max-block-size: 100vh;
    overflow: visible;
}

/* Invisible layer that closes the popover when the user clicks outside it */
.ds-popover-backdrop {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-modal) - 1);
    background: transparent;
    cursor: default;
}

.mud-card.ds-profile {
    position: fixed;
    inset-block-start: calc(var(--size-header-height) + var(--space-2));
    inset-inline-end: var(--space-2);
    inline-size: min(var(--size-profile-popover), calc(100vw - var(--space-4)));
    max-block-size: 80vh;
    max-block-size: 80dvh;
    overflow: hidden auto;
    background-color: var(--color-bg-surface);
    border: var(--border-width-thin) solid var(--color-border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.ds-profile__header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-6) var(--space-4);
    background: linear-gradient(135deg, var(--color-accent-9), var(--color-accent-12));
    color: var(--color-text-inverse);
}

.ds-profile__avatar-wrap {
    position: relative;
}

.ds-profile__avatar {
    display: block;
    inline-size: var(--size-avatar-xl);
    block-size: var(--size-avatar-xl);
    border: var(--border-width-thick) solid var(--color-border-on-shell);
    border-radius: var(--radius-full);
    object-fit: cover;
}

/* Online status dot (decorative) */
.ds-profile__status {
    position: absolute;
    inset-block-end: var(--space-1);
    inset-inline-start: var(--space-1);
    inline-size: var(--size-icon-md);
    block-size: var(--size-icon-md);
    background-color: var(--color-status-success-bar);
    border: var(--border-width-thick) solid var(--color-bg-surface);
    border-radius: var(--radius-full);
}

.ds-profile__name {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-snug);
    text-align: center;
    overflow-wrap: anywhere;
}

.ds-profile__body {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4);
}

.ds-profile__row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background-color: var(--color-bg-surface-subtle);
    border: var(--border-width-thin) solid var(--color-border-default);
    border-radius: var(--radius-lg);
}

.ds-profile__row-text {
    flex: 1 1 auto;
    min-inline-size: 0;
}

.ds-profile__label {
    margin: 0;
    font-size: var(--font-size-xs);
    line-height: var(--line-height-normal);
    color: var(--color-text-muted);
}

.ds-profile__value {
    margin: 0;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    line-height: var(--line-height-normal);
    color: var(--color-text-foreground);
    overflow-wrap: anywhere;
}

/* Log out: an icon plus a text label, so it never relies on color alone */
.ds-profile__logout {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    inline-size: 100%;
    min-block-size: var(--size-touch-target-min);
    padding: var(--space-3);
    background-color: var(--color-status-danger-soft);
    border: var(--border-width-thin) solid var(--color-status-danger-border);
    border-radius: var(--radius-lg);
    font-family: inherit;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-status-danger-text);
    text-align: start;
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--easing-standard);
}

    .ds-profile__logout:hover {
        background-color: var(--color-status-danger-fill);
    }

    .ds-profile__logout:focus-visible {
        outline: var(--focus-ring-width) solid var(--focus-ring-color-danger);
        outline-offset: var(--focus-ring-offset);
    }

/* Remove default MudPopover white box/shadow behind our custom card */
.ds-profile-popover.mud-popover {
    background: transparent !important;
    box-shadow: none !important;
}

/* Keeps the LTR email under its Arabic label on the right side while preserving
   character order. The text direction is LTR here, so "end" is the right edge. */
[dir="rtl"] .ds-profile__value.u-ltr-isolate,
.rtl .ds-profile__value.u-ltr-isolate {
    text-align: end;
}

/* =========================================================
   Page header
   Title + subtitle at inline-start, compact action bar at inline-end.
   Works with plain elements or MudText (both selectors are matched), so a
   bare <h1> never falls back to the browser's 32px default.
   Markup:
     <header class="ds-page-header">
       <div class="ds-page-header__text">
         <h1 class="ds-page-title">إضافة اختبار</h1>
         <p class="ds-page-subtitle">...</p>
       </div>
       <div class="ds-page-header__actions">
         Size.Small outlined buttons, groups split by <span class="ds-vsep"></span>
       </div>
     </header>
   ========================================================= */
.ds-page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-block-end: var(--space-2);
}

.ds-page-header__text {
    min-inline-size: 0;
}

.ds-page-header__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

/* Breadcrumb trail (NmrPageHeader Breadcrumbs): a full-width first row above the title */
.ds-page-header__crumbs {
    flex: 1 1 100%;
    min-inline-size: 0;
}

/* Title row (NmrPageHeader TitleMeta): the h1 followed by inline badges (code, status) */
.ds-page-header__title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
}

.ds-page-header__meta {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

:is(.ds-page-title, .mud-typography.ds-page-title) {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    line-height: var(--line-height-tight);
    color: var(--color-text-foreground);
}

:is(.ds-page-subtitle, .mud-typography.ds-page-subtitle) {
    margin-block: var(--space-1) 0;
    margin-inline: 0;
    font-size: var(--font-size-xs);
    line-height: var(--line-height-normal);
    color: var(--color-text-muted);
}

/* =========================================================
   Pane header (title + subtitle at inline-start, tools at inline-end)
   Used by MudPaper panes that are not MudCards (split pane, builder columns).
   Markup:
     <div class="ds-pane-header">
       <div class="ds-pane-header__text">
         <MudText HtmlTag="h2" Class="ds-pane-title">...</MudText>
         <MudText Class="ds-pane-subtitle">...</MudText>
       </div>
       <div class="ds-pane-header__tools"> search + filter toggle </div>
     </div>
   ========================================================= */
.ds-pane-header {
    display: flex;
    flex-shrink: 0;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3) var(--space-4);
    padding: var(--space-5) var(--space-6);
    /* The header owns the separator line, so panes need no <MudDivider /> */
    border-block-end: var(--border-width-thin) solid var(--color-border-divider);
}

    /* Stacked header: rows (title row, search, progress) stretch full width */
    .ds-pane-header.ds-pane-header--stack {
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: stretch;
        gap: var(--space-3);
    }

    /* Compact header (Section 20 pool column) */
    .ds-pane-header.ds-pane-header--compact {
        padding: var(--space-4);
    }

.ds-pane-header__text {
    min-inline-size: 0;
}

.ds-pane-header__tools {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    min-inline-size: 0;
}

.mud-typography.ds-pane-title {
    margin: 0;
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-bold);
    line-height: var(--line-height-snug);
    color: var(--color-text-foreground);
}

    .mud-typography.ds-pane-title.ds-pane-title--sm {
        font-size: var(--font-size-sm);
    }

.mud-typography.ds-pane-subtitle {
    margin-block: var(--space-1) 0;
    margin-inline: 0;
    font-size: var(--font-size-xs);
    line-height: var(--line-height-normal);
    color: var(--color-text-muted);
}

/* =========================================================
   Split pane
   Main column + fixed side panel from 960px up.
   Children are MudPaper panels.
   ========================================================= */
.ds-split-pane {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-5);
    /* Each pane keeps its own height; one pane never stretches the other.
       Both lists share --size-picker-list, so the cards still line up. */
    align-items: start;
}

@media (min-width: 960px) {
    .ds-split-pane {
        grid-template-columns: minmax(0, 1fr) var(--size-side-panel-width);
    }
}

/* Wide side column (question review: metadata + review log): 480px instead of 368px */
@media (min-width: 960px) {
    .ds-split-pane.ds-split-pane--wide {
        grid-template-columns: minmax(0, 1fr) var(--size-side-panel-lg);
    }
}

/* Stretch: cards in the same grid row share one height (2 x 2 review grid).
   Put the cards themselves in the grid, in reading order: main, side, main, side.
   Each card becomes a flex column so its content area takes the spare height. */
.ds-split-pane.ds-split-pane--stretch {
    align-items: stretch;
}

    .ds-split-pane.ds-split-pane--stretch > .mud-card {
        display: flex;
        flex-direction: column;
        min-block-size: 0;
    }

        .ds-split-pane.ds-split-pane--stretch > .mud-card > .mud-card-content {
            flex: 1 1 auto;
            min-block-size: 0;
        }

/* Fill: this card takes the row height set by its neighbour (block-size 0 + min-block-size 100%),
   and an activity scroll region inside fills the rest (review log beside the decision card).
   From 960px only: below that the cards stack and the scroll region keeps its 352px cap. */
@media (min-width: 960px) {
    .ds-split-pane.ds-split-pane--stretch > .mud-card.ds-split-pane__fill {
        block-size: 0;
        min-block-size: 100%;
    }

        .ds-split-pane.ds-split-pane--stretch > .mud-card.ds-split-pane__fill > .mud-card-content {
            display: flex;
            flex-direction: column;
        }

        .ds-split-pane.ds-split-pane--stretch > .mud-card.ds-split-pane__fill .ds-activity-scroll {
            flex: 1 1 auto;
            min-block-size: 0;
            max-block-size: none;
        }
}

/* =========================================================
   4:5 two-column workspace
   .ds-builder       Exam Step 4: source pool at inline-start, exam sections
                      at inline-end (applied to MudDropContainer's root).
   .ds-preview-split Question Step 4: layout options at inline-start,
                      student preview at inline-end.
   ========================================================= */
.ds-builder,
.ds-preview-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-6);
    align-items: start;
}

@media (min-width: 960px) {
    .ds-builder,
    .ds-preview-split {
        grid-template-columns: minmax(0, 4fr) minmax(0, 5fr);
    }
}

/* Column header bars share one height so both columns line up.
   Content inside is compact (36px controls). */
.ds-builder__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    min-block-size: var(--size-touch-target-min);
}

.ds-builder__bar-label {
    margin: 0;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    line-height: var(--line-height-snug);
    color: var(--color-text-foreground);
}

/* =========================================================
   Wizard host (MudStepperExtended used as a step engine only)
   The wizard pages render their own step rail (.ds-stepper-wrap) and footer,
   so the native stepper header and action row are hidden. The component keeps
   doing the real work: step switching, PreventStepChangeAsync and Loading.
   Markup:
     <MudStepperExtended Class="ds-wizard-host"
                         ActionClass="ds-wizard-native-actions" ...>
   !important is required: MudExtensions writes the header layout as an inline
   style, and the action row carries MudBlazor's .d-flex (display: flex !important).
   ========================================================= */
.ds-wizard-host > div:first-child:not([class]), /* MudExtensions <= 8.2: unnamed header block */
.ds-wizard-host .mud-stepper-inner-header-extended, /* MudExtensions >= 8.3 */
.ds-wizard-host .ds-wizard-native-actions,
.ds-wizard-native-actions {
    display: none !important;
}

/* =========================================================
   Master-detail
   Master column (exam models) uses the sidebar width token (280px);
   each column has a header bar (__head) and a padded body (__body).
   Markup:
     <div class="ds-master-detail">
       <section class="ds-master-detail__master">
         <div class="ds-master-detail__head">icon + label</div>
         <div class="ds-master-detail__body"> ... </div>
       </section>
       <section class="ds-master-detail__detail"> same structure </section>
     </div>
   ========================================================= */
.ds-master-detail {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    overflow: hidden;
    background-color: var(--color-bg-surface);
    border: var(--border-width-thin) solid var(--color-border-default);
    border-radius: var(--radius-lg);
}

.ds-master-detail__master,
.ds-master-detail__detail {
    display: flex;
    flex-direction: column;
    min-inline-size: 0;
}

.ds-master-detail__master {
    border-block-end: var(--border-width-thin) solid var(--color-border-default);
}

/* Rows inside a body (model buttons, section panels) never stretch vertically */
.ds-master-detail__body > * {
    flex: 0 0 auto;
}

.ds-master-detail__head {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: var(--space-2);
    min-block-size: var(--size-control-lg);
    padding-block: var(--space-3);
    padding-inline: var(--space-5);
    border-block-end: var(--border-width-thin) solid var(--color-border-divider);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-snug);
    color: var(--color-text-foreground);
}

    .ds-master-detail__head .mud-icon-root {
        font-size: var(--size-icon-sm);
        color: var(--color-text-secondary);
    }

.ds-master-detail__body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: var(--space-3);
    min-block-size: 0;
    padding: var(--space-4);
}

@media (min-width: 960px) {
    .ds-master-detail {
        grid-template-columns: var(--size-sidebar-width) minmax(0, 1fr);
    }

    .ds-master-detail__master {
        border-block-end: 0;
        border-inline-end: var(--border-width-thin) solid var(--color-border-default);
    }

    .ds-master-detail__detail .ds-master-detail__body {
        min-block-size: calc(var(--space-24) * 2);
    }
}

/* =========================================================
   Action bar (NmrActionBar)
   Page-level bar under the content: status or progress text at inline-start,
   buttons at inline-end (secondary first, primary last). Wraps on narrow screens.
   ds-action-bar--sticky pins it to the bottom of the viewport on long pages.
   ========================================================= */
.ds-action-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3) var(--space-4);
    padding-block: var(--space-6) 0;
}

.ds-action-bar__start {
    min-inline-size: 0;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    line-height: var(--line-height-snug);
    color: var(--color-text-foreground);
}

.ds-action-bar__end {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    margin-inline-start: auto;
}

.ds-action-bar.ds-action-bar--sticky {
    position: sticky;
    inset-block-end: 0;
    z-index: var(--z-sticky);
    padding-block: var(--space-3);
    background-color: var(--color-bg-background);
    border-block-start: var(--border-width-thin) solid var(--color-border-default);
}