:root {
    --ml-font-sans: "Inter", "Segoe UI", "Helvetica Neue", Arial, sans-serif;

    --ml-color-bg-canvas: #f4f7fb;
    --ml-color-bg-surface: #ffffff;
    --ml-color-bg-surface-muted: #f8fafc;
    --ml-color-bg-sidebar: #0f1f2e;

    --ml-color-text-primary: #112336;
    --ml-color-text-secondary: #516171;
    --ml-color-text-on-dark: #ecf2f8;

    --ml-color-border-subtle: #d8e0e8;
    --ml-color-border-strong: #c0ccd8;

    --ml-color-brand-600: #1f6fb2;
    --ml-color-brand-700: #185f97;

    --ml-color-success: #166d3b;
    --ml-color-warning: #975f12;
    --ml-color-danger: #a42828;
    --ml-color-info: #186ea6;

    --ml-space-1: 0.25rem;
    --ml-space-2: 0.5rem;
    --ml-space-3: 0.75rem;
    --ml-space-4: 1rem;
    --ml-space-6: 1.5rem;
    --ml-space-8: 2rem;

    --ml-radius-sm: 0.375rem;
    --ml-radius-md: 0.5rem;
    --ml-radius-lg: 0.75rem;

    --ml-shadow-soft: 0 2px 8px rgba(9, 30, 66, 0.08);
    --ml-shadow-subtle: 0 1px 2px rgba(9, 30, 66, 0.1);
}

html, body {
    margin: 0;
    font-family: var(--ml-font-sans);
    background: var(--ml-color-bg-canvas);
    color: var(--ml-color-text-primary);
}

h1:focus {
    outline: none;
}

:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--ml-color-brand-600) 75%, white);
    outline-offset: 2px;
}

.mud-button-root:focus-visible,
.mud-icon-button:focus-visible,
.mud-nav-link:focus-visible,
.mud-input-control:focus-within {
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--ml-color-brand-600) 35%, white);
    border-radius: var(--ml-radius-sm);
}

a, .btn-link {
    color: var(--ml-color-brand-600);
}

.btn-primary {
    color: #fff;
    background-color: var(--ml-color-brand-600);
    border-color: var(--ml-color-brand-600);
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--ml-color-brand-700);
    border-color: var(--ml-color-brand-700);
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

.content {
    padding-top: var(--ml-space-6);
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid red;
}

.validation-message {
    color: var(--ml-color-danger);
}

.ml-page-header {
    margin-bottom: var(--ml-space-6);
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--ml-space-4);
}

.ml-page-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.ml-page-subtitle {
    margin-top: var(--ml-space-2);
    margin-bottom: 0;
    color: var(--ml-color-text-secondary);
}

.ml-surface {
    background: var(--ml-color-bg-surface);
    border: 1px solid var(--ml-color-border-subtle);
    border-radius: var(--ml-radius-lg);
    box-shadow: var(--ml-shadow-soft);
}

.ml-surface-body {
    padding: var(--ml-space-6);
}

.ml-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--ml-space-3);
    margin-bottom: var(--ml-space-4);
    align-items: center;
}

/* User directory and future list pages: table shell (column stack: custom toolbar, then table) */
.ml-mudtable-list-shell {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
    border-radius: var(--ml-radius-md);
    background: var(--ml-color-bg-surface);
}

.ml-dept-table .ml-dept-table-cell-selected {
    background: color-mix(in srgb, var(--mud-palette-primary) 18%, transparent);
    cursor: pointer;
}

/* Toolbar is rendered *above* the table (not in ToolBarContent) to avoid layout/z-index with Mud’s internal .mud-table-toolbar. */
.ml-mudtable-toolbar--above {
    position: relative;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    border-bottom: 1px solid var(--ml-color-border-subtle);
    background: var(--ml-color-bg-surface);
}

/* -------------------------------------------------------------------------
   User table toolbar: mobile-first (stable narrow layouts), then wide desktop
   ------------------------------------------------------------------------- */

/* Single column: Create user, then filter block (avoids cramping two grid cols on tablets) */
.ml-mudtable-toolbar {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
    row-gap: var(--ml-space-3);
    column-gap: var(--ml-space-4);
    width: 100%;
    max-width: 100%;
    padding: var(--ml-space-3) var(--ml-space-4);
    box-sizing: border-box;
}

.ml-mudtable-toolbar-start {
    justify-self: start;
}

.ml-mudtable-toolbar-create {
    flex: 0 0 auto;
}

/* Row 1: checkbox + role. Row 2: search full width (no chaotic flex-wrap). */
.ml-mudtable-toolbar-filters {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    column-gap: var(--ml-space-3);
    row-gap: var(--ml-space-3);
    align-items: center;
    min-width: 0;
    width: 100%;
}

.ml-mudtable-toolbar-filters .ml-mudtable-toolbar-check-cell {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    align-self: center;
}

.ml-mudtable-toolbar-filters .ml-mudtable-toolbar-role-shell {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

.ml-mudtable-toolbar-filters .ml-mudtable-toolbar-search-wrap {
    grid-column: 1 / -1;
    grid-row: 2;
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

.ml-mudtable-toolbar-filters .ml-mudtable-toolbar-search-wrap .mud-text-field,
.ml-mudtable-toolbar-filters .ml-mudtable-toolbar-search-wrap .mud-input-control {
    width: 100%;
    max-width: 100%;
}

.ml-mudtable-toolbar-check {
    margin: 0;
    white-space: nowrap;
    align-self: center;
}

/*
 * Role MudSelect: root .mud-select gets flex from Mud; shell constrains width.
 * Narrow: fluid in grid cell. Wide: see desktop block below.
 */
.ml-mudtable-toolbar-role-shell {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.ml-mudtable-toolbar-filters .ml-mudtable-toolbar-role-shell .mud-select {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    flex: 0 1 auto;
    flex-grow: 0;
    flex-basis: auto;
}

/* Search: no flex-basis grow on small screens (was flex: 1 1 200px) */
.ml-mudtable-toolbar-search {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    flex: none;
}

/*
 * Under 1200px: when there is no middle select filter, keep
 * Checkbox «Показувати архів» and search field on one row instead of stacking.
 * Pages with .ml-mudtable-toolbar-role-shell keep the 2-row grid (checkbox + select | search).
 */
@media (max-width: 1199.98px) {
    .ml-mudtable-toolbar-filters:not(:has(.ml-mudtable-toolbar-role-shell)) {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        gap: var(--ml-space-3);
        min-width: 0;
    }

    .ml-mudtable-toolbar-filters:not(:has(.ml-mudtable-toolbar-role-shell)) .ml-mudtable-toolbar-check-cell {
        grid-column: unset;
        grid-row: unset;
        flex: 0 0 auto;
    }

    .ml-mudtable-toolbar-filters:not(:has(.ml-mudtable-toolbar-role-shell)) .ml-mudtable-toolbar-search-wrap {
        grid-column: unset;
        grid-row: unset;
        flex: 1 1 0;
        min-width: 0;
        width: auto;
        max-width: none;
    }
}

/*
 * Desktop: outer toolbar must use row flex, not 2-col grid – grid + "auto" was collapsing /
 * painting the button and the role select in the same band (overlap). Inner uses flex + min-width:0.
 */
@media (min-width: 1200px) {
    .ml-mudtable-list-shell .ml-mudtable-toolbar {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: flex-start;
        gap: var(--ml-space-4);
        min-width: 0;
    }

    .ml-mudtable-list-shell .ml-mudtable-toolbar-start {
        flex: 0 0 auto;
        flex-shrink: 0;
    }

    .ml-mudtable-list-shell .ml-mudtable-toolbar-filters {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: flex-end;
        gap: var(--ml-space-3);
        flex: 1 1 0;
        min-width: 0;
        width: auto;
    }

    .ml-mudtable-toolbar-filters .ml-mudtable-toolbar-check-cell,
    .ml-mudtable-toolbar-filters .ml-mudtable-toolbar-role-shell,
    .ml-mudtable-toolbar-filters .ml-mudtable-toolbar-search-wrap {
        grid-column: unset;
        grid-row: unset;
    }

    .ml-mudtable-toolbar-filters .ml-mudtable-toolbar-check-cell {
        flex: 0 0 auto;
    }

    .ml-mudtable-list-shell .ml-mudtable-toolbar-role-shell {
        flex: 0 0 auto;
        width: 16rem;
        max-width: min(100%, 16rem);
        min-width: 10rem;
    }

    .ml-mudtable-list-shell .ml-mudtable-toolbar-filters .ml-mudtable-toolbar-search-wrap {
        flex: 0 1 24rem;
        min-width: 0;
        max-width: 24rem;
        width: 100%;
    }

    .ml-mudtable-toolbar-search {
        min-width: 0;
    }
}

.ml-inline-alert {
    border-radius: var(--ml-radius-md);
    border: 1px solid transparent;
    padding: var(--ml-space-3) var(--ml-space-4);
    margin-bottom: var(--ml-space-4);
}

.ml-inline-alert-error {
    color: var(--ml-color-danger);
    border-color: #efc0c0;
    background: #fdf0f0;
}

.ml-inline-alert-info {
    color: var(--ml-color-info);
    border-color: #bddff2;
    background: #edf7fd;
}

.ml-validation-summary ul {
    margin-top: var(--ml-space-2);
}

.ml-empty-state {
    border: 1px dashed var(--ml-color-border-strong);
    border-radius: var(--ml-radius-md);
    background: var(--ml-color-bg-surface-muted);
    color: var(--ml-color-text-secondary);
    padding: var(--ml-space-6);
}

.ml-status-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    padding: 0.15rem 0.55rem;
    line-height: 1.2;
    border: 1px solid transparent;
}

.ml-status-badge-active {
    color: var(--ml-color-success);
    border-color: #b8dec8;
    background: #eff8f3;
}

.ml-status-badge-archived {
    color: var(--ml-color-text-secondary);
    border-color: var(--ml-color-border-strong);
    background: #eef2f7;
}

.ml-table {
    margin-bottom: 0;
}

.ml-table thead th {
    color: var(--ml-color-text-secondary);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    border-bottom-color: var(--ml-color-border-strong);
}

.ml-table td {
    vertical-align: middle;
}

.ml-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--ml-space-4);
}

.ml-form-grid-full {
    grid-column: 1 / -1;
}

.ml-help-text {
    display: block;
    margin-top: var(--ml-space-2);
    color: var(--ml-color-text-secondary);
    font-size: 0.875rem;
}

.ml-user-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--ml-space-3);
}

.ml-user-stat-card {
    background: var(--ml-color-bg-surface);
    border: 1px solid var(--ml-color-border-subtle);
    border-radius: var(--ml-radius-md);
    padding: var(--ml-space-4);
}

.ml-user-stat-label {
    color: var(--ml-color-text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ml-user-stat-value {
    font-size: 1.45rem;
    font-weight: 700;
    margin-top: 0.2rem;
}

.role-checkbox-line {
    padding: 0.1rem 0;
}

.ml-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(8, 18, 35, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--ml-space-4);
    z-index: 1200;
}

.ml-modal-card {
    width: min(100%, 28rem);
    background: var(--ml-color-bg-surface);
    border: 1px solid var(--ml-color-border-subtle);
    border-radius: var(--ml-radius-lg);
    box-shadow: 0 8px 24px rgba(9, 30, 66, 0.12);
    padding: var(--ml-space-6);
}

.page {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--ml-color-bg-sidebar);
    color: var(--ml-color-text-on-dark);
    border-right: 1px solid #1e3144;
}

.sidebar .navbar-brand,
.sidebar .nav-link {
    color: var(--ml-color-text-on-dark);
}

.sidebar .nav-link.active,
.sidebar .nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.09);
    border-radius: var(--ml-radius-sm);
}

main {
    min-width: 0;
}

.ml-top-row {
    min-height: 64px;
    background: var(--ml-color-bg-surface);
    border-bottom: 1px solid var(--ml-color-border-subtle);
}

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

    #blazor-error-ui .dismiss {
        cursor: pointer;
        position: absolute;
        right: 0.75rem;
        top: 0.5rem;
    }

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "Сталася помилка."
    }

.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem auto;
}

    .loading-progress circle {
        fill: none;
        stroke: #e0e0e0;
        stroke-width: 0.6rem;
        transform-origin: 50% 50%;
        transform: rotate(-90deg);
    }

        .loading-progress circle:last-child {
            stroke: #1b6ec2;
            stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
            transition: stroke-dasharray 0.05s ease-in-out;
        }

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

    .loading-progress-text:after {
        content: var(--blazor-load-percentage-text, "Завантаження");
    }

code {
    color: #c02d76;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
    text-align: start;
}

@media (max-width: 991.98px) {
    .ml-form-grid {
        grid-template-columns: 1fr;
    }

    .page {
        grid-template-columns: 1fr;
    }

    .ml-user-stats {
        grid-template-columns: 1fr;
    }
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: var(--ml-space-6);
    background: #f4f7fb;
}

.auth-card-shell {
    width: min(100%, 28rem);
}

.auth-card {
    background: var(--ml-color-bg-surface);
    border: 1px solid var(--ml-color-border-subtle);
    border-radius: 1rem;
    box-shadow: 0 6px 18px rgba(12, 32, 54, 0.1);
    padding: 2rem;
}

.auth-brand {
    font-size: 0.9rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ml-color-brand-600);
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.auth-title {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 700;
}

.auth-subtitle {
    color: var(--ml-color-text-secondary);
    margin-top: 0.35rem;
    margin-bottom: 1.5rem;
}

.auth-password-toggle {
    min-width: 4.75rem;
}

.auth-caps-lock-hint {
    color: var(--ml-color-warning);
    font-size: 0.875rem;
    margin-top: -0.35rem;
    margin-bottom: 0.75rem;
}

.auth-login-options {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.auth-option-note {
    color: var(--ml-color-text-secondary);
    font-size: 0.8125rem;
}

.auth-submit {
    min-height: 2.75rem;
}

.mud-main-content {
    padding-top: 0 !important;
}

.mud-nav-link-text {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    line-height: 1.5;
}

.ml-senior-nav-warnings-hot .mud-nav-link-text {
    color: var(--mud-palette-warning) !important;
    font-weight: 600;
}

.ml-drawer-action {
    justify-content: flex-start;
    text-transform: none;
    min-height: 40px;
    padding-inline: 16px;
    border-radius: 0;
    color: var(--mud-palette-text-primary);
}