body {
    margin: 0;
    overflow: hidden;
}

.mud-main-content {
    padding-top: 0 !important;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-root {
    display: grid;
    grid-template: "main" 1fr / 1fr;
    height: 100vh;
    width: 100vw;
}

.app-loading-root {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
    background: var(--mud-palette-background);
}

.app-root > * {
    grid-area: main;
}

.global-progress-wrapper {
    pointer-events: none;
    z-index: 1300;
    align-self: start;
}

.global-progress-wrapper.hidden {
    opacity: 0;
}

ul {
    list-style: none;
}

.mud-tabs-relations {
    background-color: var(--mud-palette-background-gray);
}

.mud-tabs-relations .mud-tab {
    cursor: pointer;
}

.mud-tabs-relations .mud-tabs-panels {
    padding: 18px;
}

.custom-mud-data-grid {
    border: 1px solid var(--mud-palette-background-gray);
    border-radius: 4px;
}

/* Scroller = .mud-table-container : il ne contient QUE la table, pas le footer PagerContent
   (bouton Nouveau + pagination), qui est son frère dans la racine → le footer reste HORS de
   la zone de scroll. En mode resize MudBlazor impose au conteneur, en inline, width: max-content
   + overflow: clip pour SA mécanique ; on les override en !important pour en faire un vrai
   scroller borné des deux axes. 318 = drawer 300 + padding content-container ; 169 = header. */
.custom-mud-data-grid-object .mud-table-container {
    width: calc(100vw - 318px) !important;
    height: calc(100vh - 169px);
    overflow: auto !important;
}

/* La table se dimensionne à son contenu → elle déborde le conteneur borné → ascenseur
   horizontal. min-width: 100 % la fait remplir quand il y a peu de colonnes (pas de trou). */
.custom-mud-data-grid-object .mud-table-root {
    width: max-content;
    min-width: 100%;
}

.content-container .mud-grid,
.content-container .mud-grid-item {
    min-width: 0;
}

.custom-mud-data-grid-object .mud-table-body .mud-table-cell {
    max-width: 500px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-mud-data-grid-object .mud-table-child-content {
    max-width: 1px;
    padding: 0;
}

/* Redimensionnement de colonnes : MudBlazor étire la poignée (.mud-resizer) du header sur toute la
   hauteur de la grille (height inline dynamique) → la ligne bleue traverse toutes les lignes. On rogne
   la cellule d'en-tête (sticky = bloc conteneur de la poignée absolue) : poignée + bordure visibles
   uniquement dans le header. Le resize reste actionnable via le header.
   min-width: max-content → plancher de colonne = largeur du header sur une seule ligne (dérivé du
   contenu, rien en dur). min-width bat le width:Npx inline du resize : impossible d'écraser le
   header sur 2 lignes. Les cellules de données restent libres de s'ellipser. */
.custom-mud-data-grid-object .mud-table-head .mud-table-cell {
    overflow: hidden;
    min-width: max-content;
    white-space: nowrap;
}

.custom-mud-data-grid-relation .mud-table-container {
    height: auto;
    width: auto;
}

.custom-mud-table-footer {
    padding: 8px;
    height: 50px;
}

.custom-mud-empty-data-grid {
    height: calc(100vh - 18px);
}

.content-container {
    display: flex;
    padding: 8px;
    flex: 1;
    min-height: 0;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
}

.menu-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.menu-container .mud-drawer-header {
    flex-shrink: 0;
}

.menu-nav-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 8px;
}

.menu-workspace-section {
    flex-shrink: 0;
    padding-bottom: 8px;
}

.menu-types-section {
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    padding-bottom: 8px;
}

.menu-features-section {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 50%;
    padding-bottom: 8px;
}

.feature-header {
    flex-shrink: 0;
    padding-bottom: 8px;
}

.feature-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    min-height: 0;
}

.feature-item {
    padding: 4px 8px;
    border-radius: 8px;
    box-sizing: border-box;
    flex-shrink: 0;
}

.feature-item-content {
    min-width: 0;
    overflow: hidden;
}

.feature-item-label {
    min-width: 0;
    overflow: hidden;
}

.feature-item-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.type-header {
    flex-shrink: 0;
    padding-bottom: 8px;
}

.type-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.drawer-empty-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px;
    text-align: center;
}

.drawer-empty-hint-text {
    color: var(--mud-palette-text-secondary);
}

/* Floating "keep going" badge shown while the guided tour is paused (user is filling a drawer). Purely
   informational and non-blocking so it never interferes with the form / pickers underneath. */
.radio-tour-waiting {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%);
    z-index: 2000000000;
    pointer-events: none;
    display: flex;
    align-items: center;
    max-width: 90vw;
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text, #fff);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    animation: radio-tour-waiting-in 0.25s ease;
}

@keyframes radio-tour-waiting-in {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* Theme the Driver.js popovers to match MudBlazor (and follow light/dark via the palette variables).
   driver.css loads after app.css, so these need !important to win. */
.driver-popover {
    background-color: var(--mud-palette-surface) !important;
    color: var(--mud-palette-text-primary) !important;
    border-radius: 12px !important;
    padding: 16px 18px !important;
    max-width: 340px !important;
    box-shadow: var(--mud-elevation-8, 0 8px 24px rgba(0, 0, 0, 0.22)) !important;
    border: 1px solid var(--mud-palette-lines-default) !important;
}

.driver-popover * {
    font-family: 'Inter', ui-sans-serif, system-ui, "Segoe UI", sans-serif !important;
}

.driver-popover-title {
    color: var(--mud-palette-text-primary) !important;
    font-size: 1.05rem !important;
    font-weight: 600 !important;
    line-height: 1.35 !important;
}

.driver-popover-description {
    color: var(--mud-palette-text-secondary) !important;
    font-size: 0.875rem !important;
    line-height: 1.5 !important;
}

.driver-popover-progress-text {
    color: var(--mud-palette-text-secondary) !important;
    font-size: 0.75rem !important;
}

.driver-popover-close-btn {
    color: var(--mud-palette-text-secondary) !important;
}
.driver-popover-close-btn:hover,
.driver-popover-close-btn:focus {
    color: var(--mud-palette-text-primary) !important;
}

/* Buttons: primary "Next/Done" filled, "Previous" as a subtle text button. */
.driver-popover-footer button {
    border: none !important;
    border-radius: 8px !important;
    padding: 6px 14px !important;
    font-size: 0.8rem !important;
    font-weight: 500 !important;
    text-shadow: none !important;
    transition: background-color 0.15s ease, opacity 0.15s ease !important;
}

.driver-popover-next-btn {
    background-color: var(--mud-palette-primary) !important;
    color: var(--mud-palette-primary-text, #fff) !important;
}
.driver-popover-next-btn:hover,
.driver-popover-next-btn:focus {
    background-color: var(--mud-palette-primary-darken, var(--mud-palette-primary)) !important;
    opacity: 0.92 !important;
}

.driver-popover-prev-btn {
    background-color: transparent !important;
    color: var(--mud-palette-text-secondary) !important;
}
.driver-popover-prev-btn:hover,
.driver-popover-prev-btn:focus {
    background-color: var(--mud-palette-action-default-hover, rgba(0, 0, 0, 0.06)) !important;
    color: var(--mud-palette-text-primary) !important;
}

/* Arrow: recolour the visible side to the popover background so it stays a triangle. */
.driver-popover-arrow-side-left { border-left-color: var(--mud-palette-surface) !important; }
.driver-popover-arrow-side-right { border-right-color: var(--mud-palette-surface) !important; }
.driver-popover-arrow-side-top { border-top-color: var(--mud-palette-surface) !important; }
.driver-popover-arrow-side-bottom { border-bottom-color: var(--mud-palette-surface) !important; }

.tutorial-invite {
    position: relative;
    display: flex;
    align-items: center;
    gap: 20px;
    /* The quote above has a 3rem bottom margin (scoped CSS); pull the banner up to tighten the gap
       without changing the no-banner spacing. */
    margin: -1.75rem 0 16px;
    padding: 20px 24px;
    border-radius: 14px;
    border: 1px solid color-mix(in srgb, var(--mud-palette-primary) 35%, transparent);
    background: linear-gradient(
        135deg,
        color-mix(in srgb, var(--mud-palette-primary) 12%, transparent),
        color-mix(in srgb, var(--mud-palette-primary) 4%, transparent));
}

.tutorial-invite-close {
    position: absolute;
    top: 6px;
    right: 6px;
    color: var(--mud-palette-text-secondary);
}

.tutorial-invite-emoji {
    font-size: 2.25rem;
    line-height: 1;
    flex-shrink: 0;
    animation: tutorial-invite-bounce 2.4s ease-in-out infinite;
}

@keyframes tutorial-invite-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.tutorial-invite-body {
    flex-grow: 1;
    min-width: 0;
}

.tutorial-invite-title {
    font-weight: 600;
    line-height: 1.3;
    margin: 0 0 6px;
}

.tutorial-invite-text {
    color: var(--mud-palette-text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    margin: 0;
}

.tutorial-invite-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    padding-left: 8px;
}

@media (max-width: 700px) {
    .tutorial-invite {
        flex-direction: column;
        align-items: flex-start;
        gap: 14px;
    }

    .tutorial-invite-actions {
        align-self: stretch;
        justify-content: flex-end;
        padding-left: 0;
    }
}

.detail-container {
    padding: 8px;
}

.element-hover {
    opacity: 0;
}

.parent-hover:hover .element-hover {
    opacity: 1;
    transition: fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
}

.mud-collapse-container {
    transition: grid-template-rows 100ms ease-in-out !important;
}

.mud-dialog-width-sm {
    max-width: 700px !important;
}

/* Popups de confirmation (DialogMessageView) : la boîte s'étend selon le texte (fit-content) au lieu de
   remplir la MaxWidth, avec un plafond. Elle grandit donc avec un titre long et reste compacte sinon. */
.mud-dialog.mud-message-dialog-fit {
    width: fit-content !important;
    min-width: 320px;
    max-width: min(90vw, 640px) !important;
}

.mud-tab-badge {
    &.mud-badge-root {
        position: static;
        margin-left: 8px;

        .mud-badge-wrapper {
            position: static;
            width: auto;
            pointer-events: auto;
        }

        .mud-badge {
            position: static;
            display: inline-flex;
        }
    }
}

/**:focus {*/
/*    background-color: red !important;*/
/*}*/

/*.mud-switch .mud-icon-button:focus-within, .mud-icon-button:active {*/
/*    background-color: var(--mud-palette-primary) !important;*/
/*}*/

.custom-mud-treeview-item .mud-treeview-item-disabled {
    color: inherit !important;
    pointer-events: auto !important;
}

/* Header Card */
.header-card {
    background: var(--mud-palette-background-gray);
    border-radius: 12px;
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    position: relative;
    overflow: hidden;
}

.header-card-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    background: var(--mud-palette-action-default-hover);
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-card-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.header-card-title {
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-card-description {
    color: var(--mud-palette-text-secondary);
    font-size: 0.85rem;
}

.header-card-chip {
    background: var(--header-accent-color, var(--mud-palette-primary));
    color: #fff;
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.mud-chip-xs {
    height: 18px !important;
    padding: 2px 10px !important;
    font-size: 0.75rem !important;
    font-weight: 600 !important;
}

.mud-chip-xs .mud-chip-content {
    padding: 0 !important;
}

/* Header Search */
.header-search {
    min-width: 100px;
    width: 500px;
}

/* Dialog Header */
.dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 12px;
    margin-top: 12px;
    /* Ligne séparatrice pleine largeur sous le header, symétrique du border-top du footer. */
    border-bottom: 1px solid var(--mud-palette-divider);
}

.dialog-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dialog-header-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--mud-palette-action-default-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--mud-palette-primary);
}

.dialog-header-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-width: 0;
}

.dialog-header-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.dialog-header-subtitle {
    font-size: 0.8rem;
    color: var(--mud-palette-text-secondary);
}

.dialog-header-close {
    width: 40px !important;
    height: 40px !important;
    border-radius: 50%;
    background: transparent;
    opacity: 0.7;
    transition: all 0.2s ease;
}

.dialog-header-close:hover {
    opacity: 1;
    background: var(--mud-palette-action-default-hover);
}

/* Header de l'Historique : il a DEUX lignes (icône + titre, puis l'instance en dessous), donc le
   align-items: center de .dialog-header centrait la croix sur toute la hauteur. On la cale en haut :
   comme .dialog-header-close et .dialog-header-icon font tous deux 40×40, elle tombe pile sur la
   ligne du titre, sans décalage à ajuster. Scopé pour ne pas toucher les autres headers (une seule
   ligne titre/sous-titre), où le centrage reste correct. */
.dialog-header:has(.history-header) .dialog-header-close {
    align-self: flex-start;
}

/* Dialog Footer */
.dialog-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--mud-palette-divider);
    width: 100%;
}

/* CommandView content : default = scrollable mono-colonne ; with-stepper = layout horizontal rail/form */
.command-view-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.command-view-content.with-stepper {
    display: flex;
    flex-direction: row;
    padding: 0;
    overflow: hidden;
}

.command-view-content.with-stepper .command-view-form {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
}

/* Step de sélection d'objet (liste paginée) : le form devient flex column borné pour que SEULE la
   liste scrolle et que la pagination reste collée en bas (façon MudDataGrid), au lieu que tout le
   form scrolle. Ciblé via :has(.relation-select-field) — présent uniquement dans cette vue — pour
   ne PAS affecter les autres steps (ObjectAdd, onboarding…) qui gardent leur flux block scrollable. */
.command-view-content.with-stepper .command-view-form:has(.relation-select-field) {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Propage la hauteur à travers les wrappers Mud (CustomMudForm → .mud-form, MudFocusTrap →
   .mud-focus-trap) jusqu'à .relation-step-container, sinon la chaîne flex se casse et la liste ne
   peut pas scroller en interne. Ciblé via :has(.relation-select-field) → uniquement la step de sélection. */
.command-view-form:has(.relation-select-field) > .mud-form,
.command-view-form:has(.relation-select-field) .mud-form > .mud-focus-trap {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.header-search-field .mud-input-outlined-border {
    border-color: var(--mud-palette-lines-inputs) !important;
    border-radius: 8px !important;
}

/* User Section (Bottom Sidebar) */
.user-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-section-info {
    flex: 1;
    min-width: 0;
}

.user-section-name {
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-section-role {
    font-size: 12px;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-section-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.user-section-btn {
    color: var(--mud-palette-text-secondary) !important;
    transition: all 0.2s ease !important;
}

.user-section-btn:hover {
    color: var(--mud-palette-text-primary) !important;
    background: var(--mud-palette-action-default-hover) !important;
}

.user-section-btn.logout:hover {
    color: var(--mud-palette-error) !important;
    background: rgba(244, 67, 54, 0.12) !important;
}

/* Menu profil (popover du bouton en bas du drawer) */
/* La largeur est bornée à celle de l'ancre via RelativeWidth="DropdownWidth.Relative" sur le
   MudMenu (max-width = largeur de la ligne profil) : le popover ne déborde plus du drawer. */
/* Écart entre le popover et le bloc user. MudBlazor place le popover en position: absolute avec
   un `top` calculé en JS (bottom: auto) → un margin-bottom n'a aucun effet. On le remonte donc
   avec un transform, que MudBlazor n'utilise pas pour le placement (aucun risque d'écrasement). */
.profile-menu {
    transform: translateY(-24px);
}

/* Le wrapper d'activateur de MudMenu (.mud-menu-activator) se dimensionne à son contenu et les
   flex items ont min-width: auto → l'email long imposait sa largeur, rien ne s'ellipsait et le
   drawer débordait (ascenseur horizontal). On borne la chaîne pour laisser jouer les ellipses
   déjà présentes dans InstanceDisplay (.instance-title / .instance-details). */
.profile-menu-activator,
.profile-menu-activator .mud-menu-activator,
.profile-menu-activator .user-section {
    /* display: block indispensable : en niveau inline le wrapper se réduit autour de son contenu,
       et MudBlazor positionne le popover par rapport à CE wrapper → le menu s'ancrait sur le
       chevron. En bloc pleine largeur, l'ancre devient toute la ligne profil. */
    display: block;
    width: 100%;
    min-width: 0;
}

/* .user-section doit rester en flex (avatar + infos + chevron) malgré la règle ci-dessus. */
.profile-menu-activator .user-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Le chevron ne doit jamais être comprimé par le texte. */
.profile-menu-activator .user-section .mud-icon-button {
    flex-shrink: 0;
}

/* MudBlazor force `.mud-menu * { cursor: pointer }` sur TOUS ses descendants : le nom et l'email
   paraissaient donc cliquables alors que seul le chevron ouvre le menu. On remet le curseur par
   défaut sur le contenu de l'activateur… */
.profile-menu-activator .user-section,
.profile-menu-activator .user-section * {
    cursor: default;
}

/* …sauf sur le chevron, lui bien cliquable. */
.profile-menu-activator .user-section .mud-icon-button,
.profile-menu-activator .user-section .mud-icon-button * {
    cursor: pointer;
}

.profile-menu-header {
    padding: 6px 8px 10px;
}

/* Le form ne doit pas casser la mise en page du menu ; le bouton EST l'item de menu. */
.profile-menu-logout-form {
    display: contents;
}

.profile-menu-logout {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: transparent;
    border-radius: 8px;
    color: var(--mud-palette-error);
    font: inherit;
    cursor: pointer;
    text-align: left;
    transition: background-color 0.15s ease;
}

.profile-menu-logout:hover {
    background: rgba(166, 68, 92, 0.12);
}

/* Type List Items */
.type-item-content {
    min-width: 0;
    overflow: hidden;
}

.type-item-label {
    min-width: 0;
    overflow: hidden;
}

.type-item-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.type-list .mud-treeview-item .mud-treeview-item .mud-treeview-item-arrow {
    width: 0;
    min-width: 0;
}

.type-list .mud-treeview-item-content {
    border-radius: 8px;
}

.mud-input-control-boolean-input {
    width: fit-content;
}

/* ========== Feature Rule Card ========== */

.frule-card {
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 8px;
    padding: 14px 16px;
    transition: border-color 0.15s;
}

.frule-card:hover {
    border-color: var(--mud-palette-lines-inputs);
}

.frule-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 8px;
}

.frule-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.frule-icon {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.frule-icon.blocker {
    background: var(--mud-palette-error-hover);
    color: var(--mud-palette-error);
}

.frule-icon.action {
    background: var(--mud-palette-info-hover);
    color: var(--mud-palette-info);
}

.frule-name {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 1px;
}

.frule-desc {
    font-size: 11px;
    color: var(--mud-palette-text-secondary);
    font-weight: 300;
}

.frule-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.frule-badge {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 2px 8px;
    border-radius: 4px;
}

.frule-badge.blocker {
    color: var(--mud-palette-error);
    background: var(--mud-palette-error-hover);
}

.frule-badge.action {
    color: var(--mud-palette-info);
    background: var(--mud-palette-info-hover);
}

.frule-pseudo {
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--mud-palette-background-gray);
    border-radius: 6px;
    border: 1px solid var(--mud-palette-lines-default);
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    line-height: 1.6;
}

.frule-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--mud-palette-lines-default);
    font-size: 10px;
    color: var(--mud-palette-text-secondary);
}

.frule-meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.frule-card.disabled .frule-left { opacity: 0.55; }
.frule-card.disabled .frule-pseudo { opacity: 0.55; }
.frule-card.disabled .frule-meta { opacity: 0.55; }
.frule-card.disabled .frule-badge { opacity: 0.55; }

.frule-card.removed {
    opacity: 0.5;
    border-style: dashed;
}

/* ========== Condition Builder ========== */

.cb {
    background: var(--mud-palette-background-gray);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 8px;
    overflow: hidden;
}

.cb-block {
    border-bottom: 1px solid var(--mud-palette-lines-default);
    padding: 10px 14px;
}

.cb-block:last-of-type {
    border-bottom: none;
}

.cb-row {
    display: grid;
    grid-template-columns: 48px 1fr auto 1fr 24px;
    gap: 0 8px;
    grid-template-rows: auto auto;
    align-items: end;
}

.cb-toggle-wrapper {
    grid-column: 4;
    grid-row: 1;
    padding-bottom: 6px;
}

.cb-left-toggle-wrapper {
    grid-column: 2;
    grid-row: 1;
    padding-bottom: 6px;
}

.cb-toggle {
    display: flex;
    gap: 0;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 4px;
    overflow: hidden;
    width: fit-content;
}

.cb-toggle-btn {
    padding: 2px 10px;
    font-size: 10px;
    font-weight: 600;
    border: none;
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-disabled);
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 4px;
}

.cb-toggle-btn.active {
    background: rgba(68, 92, 166, 0.15);
    color: var(--mud-palette-secondary);
}

.cb-toggle-btn + .cb-toggle-btn {
    border-left: 1px solid var(--mud-palette-lines-default);
}

.cb-logic {
    grid-column: 1;
    grid-row: 2;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    color: var(--mud-palette-secondary);
}

.cb-logic-toggle {
    grid-column: 1;
    grid-row: 2;
    padding: 4px 0;
    font-size: 10px;
    font-weight: 700;
    border-radius: 4px;
    border: 1px solid rgba(95, 118, 190, 0.3);
    background: var(--mud-palette-surface);
    color: var(--mud-palette-secondary);
    cursor: pointer;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    width: 48px;
    text-align: center;
    align-self: center;
}

.cb-logic-toggle.or {
    color: var(--mud-palette-warning);
    border-color: var(--mud-palette-warning-hover);
    background: rgba(255, 183, 77, 0.12);
}

.cb-current-ref {
    grid-column: 4;
    grid-row: 2;
    padding: 8px 12px;
    border-radius: 6px;
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    font-size: 11px;
    font-weight: 600;
    color: var(--mud-palette-text-disabled);
    font-family: 'JetBrains Mono', monospace;
    width: 100%;
}

.cb-current-badge {
    padding: 4px 8px;
    border-radius: 4px;
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    font-size: 10px;
    font-weight: 600;
    color: var(--mud-palette-text-disabled);
    white-space: nowrap;
    flex-shrink: 0;
    font-family: 'JetBrains Mono', monospace;
}

.cb-val-duration {
    grid-column: 4;
    grid-row: 2;
    display: flex;
    align-items: center;
    gap: 6px;
}

.cb-val-current-field {
    grid-column: 4;
    grid-row: 2;
    display: flex;
    align-items: center;
    gap: 4px;
}

.cb-add {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-top: 1px solid var(--mud-palette-lines-default);
    cursor: pointer;
    color: var(--mud-palette-text-disabled);
    font-size: 12px;
    gap: 4px;
}

.cb-add:hover {
    background: var(--mud-palette-action-default-hover);
    color: var(--mud-palette-text-secondary);
}

.rules-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 10px;
}
.onboarding-root {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100vw;
    background: var(--mud-palette-background);
}

.onboarding-card {
    width: 100%;
    max-width: 960px;
}

.onboarding-logout {
    position: absolute;
    top: 16px;
    right: 24px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 4px;
}

.error-root {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100vw;
    background: var(--mud-palette-background);
    padding: 24px;
    box-sizing: border-box;
}

.error-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    max-width: 720px;
}

/* ---- Pont survol↔colonne de l'éditeur de cardinalité (RelationCardinalityEditor) ----
   Pur CSS (:has() + :hover), sans aucun événement Blazor : survoler un nom de type dans la phrase
   atténue la colonne DE/VERS opposée et illumine l'en-tête de sa propre colonne. Règles GLOBALES
   (non isolées) pour pouvoir traverser la frontière vue ↔ composant éditeur. */
.rce-col,
.rce-col-head {
    transition: opacity .16s, filter .16s, color .16s;
}

.rce-bridge-scope:has(.rce-label.bridge[data-side="from"]:hover) .rce-col[data-side="to"],
.rce-bridge-scope:has(.rce-label.bridge[data-side="to"]:hover) .rce-col[data-side="from"] {
    opacity: .42;
    filter: saturate(.7);
}

.rce-bridge-scope:has(.rce-label.bridge[data-side="from"]:hover) .rce-col[data-side="from"] .rce-col-head,
.rce-bridge-scope:has(.rce-label.bridge[data-side="to"]:hover) .rce-col[data-side="to"] .rce-col-head {
    color: var(--mud-palette-text-primary);
}

/* ... et contour sur les chips sélectionnées de la colonne survolée */
.rce-chip-selected {
    transition: box-shadow .16s, transform .16s;
}

.rce-bridge-scope:has(.rce-label.bridge[data-side="from"]:hover) .rce-col[data-side="from"] .rce-chip-selected,
.rce-bridge-scope:has(.rce-label.bridge[data-side="to"]:hover) .rce-col[data-side="to"] .rce-chip-selected {
    /* anneau = couleur de la chip éclaircie (teinte + saturation conservées) ; fallback clair si pas de couleur */
    box-shadow: 0 0 0 2px oklch(from var(--rce-chip-color, #ECE9E2) 0.85 c h), 0 6px 18px -6px rgba(0, 0, 0, .6);
    transform: translateY(-1px);
}

/* ========== Relation Explorer (détail de ligne : arbre + détail) ========== */
/* Trois colonnes (arbre | détail | actions), hauteur FIXE : l'arbre est virtualisé et a besoin d'un
   conteneur de scroll borné. Le td.mud-table-child-content a padding:0, on gère ici nos marges. */
.relation-explorer {
    display: grid;
    /* Arbre : largeur FIXE → identique d'une ligne dépliée à l'autre (colonnes alignées) et plafonnée
       (au-delà, ellipsis). Détail : 1fr (s'étend). Actions : 58px = largeur réelle rendue de la dernière
       colonne de la datagrid (40px déclarés + padding de cellule MudDataGrid). */
    grid-template-columns: 320px minmax(260px, 1fr) 58px;
    align-items: stretch;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 6px;
    /* Hauteur ADAPTATIVE : la grille épouse son contenu. Ce sont les COLONNES (arbre, détail) qui sont
       plafonnées (max-height) et scrollent en interne — un max-height sur la grille déborderait/clipperait
       la rangée. La virtualisation a juste besoin d'un viewport borné : le max-height de la colonne arbre. */
    overflow: hidden;
    background: var(--mud-palette-surface);
    margin: 12px;
}

/* Lignes de l'arbre virtualisé : hauteur uniforme, doit correspondre à l'ItemSize de <Virtualize> (36). */
.relation-tree-row {
    height: 36px;
    box-sizing: border-box;
}

/* En-tête de groupe RACINE épinglé. position: sticky borné à sa section → il reste en haut pendant le
   scroll de ses enfants, puis est « poussé » quand la section suivante arrive (effet natif, sans JS).
   Un SEUL scroll (.relation-explorer-tree) : la section est juste un bloc empilé, sans overflow propre. */
.relation-tree-sticky-header {
    position: sticky;
    top: 0;
    /* Au-dessus de tout le contenu virtualisé qui défile dessous (les composants Mud des nœuds peuvent
       créer leur propre empilement). */
    z-index: 10;
    /* Opaque (= fond de l'arbre) pour masquer les nœuds qui défilent dessous. */
    background: var(--mud-palette-background-gray);
}

/* Sentinelle de scroll infini en bas de l'arbre : zone observée + spinner pendant le chargement de page. */
.relation-tree-truncated {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 0;
    color: var(--mud-palette-text-disabled);
}

/* Chargement initial de l'explorer (expand de la ligne datagrid) : spinner centré. */
.relation-explorer-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    padding: 32px;
}

/* Spinner à la place du chevron pendant le chargement des enfants d'un nœud. Même gabarit 28×28 que le
   chevron (.relation-tree-chevron.mud-button-root) et le spacer → la ligne ne bouge pas à l'affichage. */
.relation-tree-chevron-loading {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.relation-tree-chevron-loading .mud-progress-circular {
    width: 18px;
    height: 18px;
}

.relation-explorer-tree {
    /* Viewport de scroll de la virtualisation : plafonné (adaptatif en deçà), scroll au-delà.
       PAS de padding vertical : l'en-tête sticky doit être flush en haut (sinon du contenu peut
       apparaître au-dessus dans l'espace du padding). */
    max-height: 600px;
    overflow-y: auto;
    min-height: 0;
    background: var(--mud-palette-background-gray);
    border-right: 1px solid var(--mud-palette-lines-default);
}

.relation-explorer-detail {
    /* Nuance distincte de la Surface (lignes de la grille) et du background-gray (arbre) : le
       détail se lit comme une carte de focus. color-mix conserve ce décalage dans les deux
       thèmes — il éclaircit en sombre, assombrit légèrement en clair — là où le #2E2E2C codé
       en dur ne valait que pour le thème sombre. */
    background: color-mix(in srgb, var(--mud-palette-surface) 94%, var(--mud-palette-text-primary));
    min-width: 0;
    /* Plafonné et scrollable indépendamment (champs longs) — même borne que l'arbre. */
    max-height: 600px;
    overflow-y: auto;
    min-height: 0;
}

/* Rien de sélectionné : le panneau se fond dans le fond (pas de carte), sans message. */
.relation-explorer-detail.empty {
    background: var(--mud-palette-surface);
}

.relation-explorer-empty {
    padding: 24px;
    color: var(--mud-palette-text-secondary);
    text-align: center;
}

/* --- En-têtes de groupe (RelationType) --- */
.relation-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--mud-palette-text-secondary);
}

/* Icônes de l'en-tête racine réduites pour coller au libellé minuscule (10px). Le chevron de repli est
   re-dimensionné par la règle dédiée plus bas (.relation-tree-row .relation-tree-chevron), de spécificité
   supérieure → il échappe à cette réduction. */
.relation-group-header .mud-icon-root {
    font-size: 12px;
}

.relation-group-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Conteneur flex direct de l'en-tête → l'auto-marge pousse le « + » tout à droite de la colonne
   (le MudIconButton est imbriqué dans un MudTooltip, donc l'auto-marge ne marche pas sur le bouton). */
.relation-add {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
}

/* Bouton « + » plein, forcé en cercle (MudIconButton Filled rend un carré arrondi par défaut). */
.relation-add-button.mud-button-root {
    border-radius: 50%;
}


/* --- Nœuds objet --- */
.relation-tree-node {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-right: 8px;
    border-left: 2px solid transparent;
    font-size: 13px;
    color: var(--mud-palette-text-primary);
}

.relation-tree-node:hover {
    background: var(--mud-palette-action-default-hover);
}

.relation-tree-node.selected {
    background: rgba(68, 92, 166, 0.15);
    border-left-color: var(--mud-palette-primary);
    font-weight: 500;
}

/* Chevron = MudIconButton compact (les events sur HTML brut ne se câblent pas ici → composants Mud). */
.relation-tree-chevron.mud-button-root {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    padding: 2px;
    color: var(--mud-palette-text-secondary);
}

/* Pas de fond propre au bouton (hover/focus/active) : seul le surlignage de ligne doit apparaître,
   sinon on a l'impression d'une « double sélection ». */
.relation-tree-chevron.mud-button-root:hover,
.relation-tree-chevron.mud-button-root:focus,
.relation-tree-chevron.mud-button-root:focus-visible,
.relation-tree-chevron.mud-button-root:active {
    background-color: transparent;
}

/* Chevron dimensionné explicitement → identique partout (repli d'en-tête racine ET dépli de nœud). Spécificité
   (0,3,0) volontairement supérieure aux règles de contexte `.relation-group-header .mud-icon-root` (12px) et
   `.relation-tree-node .mud-icon-root` (16px) — toutes deux (0,2,0) — pour gagner quel que soit l'ordre. */
.relation-tree-row .relation-tree-chevron .mud-icon-root {
    font-size: 20px;
}

/* Réservé quand le nœud est une feuille (aucun enfant visible) : garde l'alignement des libellés. */
.relation-tree-chevron-spacer {
    flex: 0 0 auto;
    width: 20px;
}

/* Menu d'actions (3 points) de la relation, à droite de la ligne ; affiché en permanence. */
.relation-tree-menu {
    flex: 0 0 auto;
}

/* Zone cliquable de sélection = MudButton déguisé en ligne d'arbre. */
.relation-tree-node-main.mud-button-root {
    flex: 1;
    min-width: 0;
    justify-content: flex-start;
    text-transform: none;
    font-weight: inherit;
    font-size: 13px;
    line-height: 1.3;
    color: var(--mud-palette-text-primary);
    /* padding-left réduit (2 au lieu de 8) : aligne l'icône du nœud sur celle des en-têtes de relation
       (chevron 28 + gap) → l'escalier d'indentation reste régulier de 16 px entre chaque niveau. */
    padding: 7px 8px 7px 2px;
}

/* Idem : pas de fond propre au bouton de ligne ; le survol/sélection est porté par .relation-tree-node. */
.relation-tree-node-main.mud-button-root:hover,
.relation-tree-node-main.mud-button-root:focus,
.relation-tree-node-main.mud-button-root:focus-visible,
.relation-tree-node-main.mud-button-root:active {
    background-color: transparent;
}

.relation-tree-node-content {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    width: 100%;
}

.relation-tree-node .mud-icon-root {
    font-size: 16px;
}

.relation-tree-node-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

/* Réserve en permanence la largeur du libellé en gras (copie invisible), pour que passer la ligne
   sélectionnée en bold ne recalcule pas la colonne max-content (plus de décalage). */
.relation-tree-node-label::after {
    content: attr(data-text);
    display: block;
    height: 0;
    overflow: hidden;
    visibility: hidden;
    font-weight: 500;
    white-space: nowrap;
}

.relation-tree-more {
    padding: 2px 8px 4px 0;
    font-size: 11px;
    font-style: italic;
    color: var(--mud-palette-text-disabled);
}

/* --- Détail (colonne droite) --- */
.relation-detail {
    padding: 16px 20px;
}

.relation-detail-header {
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

/* Réserve la hauteur d'une fiche à deux lignes (titre + description) : hauteur d'en-tête stable d'une
   sélection à l'autre, et — sans description — le titre seul reste centré face à l'avatar (align-items
   center sur .instance-display). */
.relation-detail-header .instance-display {
    min-height: 50px;
}

/* Colonne d'action de l'objet lié, en bout de détail : largeur fixe (= dernière colonne de la datagrid),
   fond plus sombre, pleine hauteur. */
.relation-explorer-actions {
    overflow: hidden; /* la colonne fait 40px (piste de grille) ; on borne le bouton à cette largeur */
    padding-top: 16px; /* aligne le haut de la zone sur le contenu du détail (.relation-detail padding) */
    background: var(--mud-palette-background-gray);
    border-left: 1px solid var(--mud-palette-lines-default);
}

/* Boîte de hauteur = en-tête (InstanceDisplay) : le 3-points y est centré → aligné sur le centre
   de l'avatar/nom, peu importe la hauteur totale du détail. */
.relation-explorer-actions-top {
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.relation-detail-section-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    color: var(--mud-palette-text-secondary);
    margin-bottom: 6px;
}

/* Informations (instance) et « Via {RelationType} » côte à côte ; repli en colonne si trop étroit. */
.relation-detail-sections {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 32px;
}

.relation-detail-section {
    flex: 1 1 260px;
    min-width: 0;
}

.relation-detail-via {
    display: flex;
    align-items: center;
    gap: 6px;
}

.relation-detail-via .mud-icon-root {
    font-size: 12px;
}

.relation-detail-fields {
    display: flex;
    flex-direction: column;
}

.relation-detail-field {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.relation-detail-field:last-child {
    border-bottom: none;
}

.relation-detail-field-label {
    font-size: 12px;
    color: var(--mud-palette-text-secondary);
}

.relation-detail-field-value {
    font-size: 13px;
}

/* --- Valeurs typées (FieldValueDisplay) --- */
.field-value-boolean {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
}

.field-value-boolean .mud-icon-root {
    font-size: 16px;
}

.field-value-boolean-yes {
    color: var(--mud-palette-success);
}

.field-value-boolean-no {
    color: var(--mud-palette-text-secondary);
}

.field-value-empty {
    color: var(--mud-palette-text-disabled);
    font-style: italic;
}
