.page {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

main {
    flex: 1;
    background-color: #eef2f7;
}

.sidebar {
    background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}

.top-row {
    background: linear-gradient(135deg, #1e3a5f 0%, #2c5282 100%);
    border-bottom: none;
    justify-content: space-between;
    min-height: 3.25rem;
    display: flex;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    position: relative;
    z-index: 1000;
}

.top-row-content {
    flex: 1;
    display: flex;
    align-items: center;
}

.top-row-help {
    display: flex;
    align-items: center;
    margin-left: auto;
}

.top-row-profile {
    position: relative;
    display: flex;
    align-items: center;
    margin-left: 0.5rem;
}

.icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1.1rem;
}

.icon-button:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    transform: scale(1.05);
}

/* Editor Toolbar in top-row */
.top-row .editor-toolbar {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

/* Toolbar divider for grouping */
.top-row .editor-toolbar .toolbar-divider {
    width: 1px;
    height: 1.5rem;
    background: rgba(255, 255, 255, 0.2);
    margin: 0 0.25rem;
}

.top-row .editor-toolbar .btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    border-radius: 5px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    text-shadow: none;
    box-shadow: none;
    line-height: 1.2;
}

.top-row .editor-toolbar .btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

.top-row .editor-toolbar .btn:active:not(:disabled) {
    transform: translateY(0);
}

.top-row .editor-toolbar .badge {
    background: rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.1rem 0.35rem;
    border-radius: 8px;
    font-size: 0.65rem;
    font-weight: 600;
    margin-left: 0.2rem;
}

/* Primary action - Save (most important when visible) */
.top-row .btn-success {
    background: #10b981;
    color: white;
}

.top-row .btn-success:hover:not(:disabled) {
    background: #059669;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4);
}

.top-row .btn-success:disabled {
    background: rgba(16, 185, 129, 0.4);
    color: rgba(255, 255, 255, 0.6);
    cursor: not-allowed;
    transform: none;
}

/* Secondary action - Validate */
.top-row .btn-warning {
    background: rgba(255, 255, 255, 0.95);
    color: #1e3a5f;
    font-weight: 600;
}

.top-row .btn-warning:hover:not(:disabled) {
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(255, 255, 255, 0.3);
}

.top-row .btn-warning:disabled {
    background: rgba(255, 255, 255, 0.5);
    color: rgba(30, 58, 95, 0.5);
    cursor: not-allowed;
    transform: none;
}

/* Tertiary actions - Download, Upload */
.top-row .btn-secondary {
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.18);
}

.top-row .btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    color: white;
}

/* Ghost/outline style for less prominent actions */
.top-row .btn-outline {
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.top-row .btn-outline:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.4);
    color: white;
}

.top-row .btn-icon {
    font-size: 0.85rem;
    opacity: 0.85;
}

.top-row .btn:hover .btn-icon {
    opacity: 1;
}

/* Edit Mode Toggle Switch */
.top-row .edit-mode-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.top-row .toggle-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.7);
    transition: color 0.2s ease;
    user-select: none;
}

.top-row .toggle-label.active {
    color: #ffffff;
    font-weight: 600;
}

.top-row .toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    cursor: pointer;
}

.top-row .toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.top-row .toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 22px;
    transition: 0.3s;
}

.top-row .toggle-slider::before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* The toggle is a submit button rather than a checkbox: MVC has no live binding, so switching mode
   is a form post. The "on" class stands in for the :checked state the Blazor markup relied on. */
.top-row button.toggle-switch {
    padding: 0;
    border: none;
    background: transparent;
}

.top-row .toggle-slider.on {
    background-color: #10b981;
}

.top-row .toggle-slider.on::before {
    transform: translateX(18px);
}

.top-row button.toggle-switch:focus-visible .toggle-slider {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
}

    .top-row a, .top-row .btn-link {
        white-space: nowrap;
        margin-left: 1.5rem;
        text-decoration: none;
        color: rgba(255, 255, 255, 0.9);
    }

    .top-row a:hover, .top-row .btn-link:hover {
        text-decoration: underline;
        color: #ffffff;
    }

    .top-row a:first-child {
        overflow: hidden;
        text-overflow: ellipsis;
    }

@media (max-width: 640.98px) {
    .top-row {
        justify-content: space-between;
    }

    .top-row a, .top-row .btn-link {
        margin-left: 0;
    }
}

@media (min-width: 641px) {
    .page {
        flex-direction: row;
    }

    .sidebar {
        width: 250px;
        height: 100vh;
        position: sticky;
        top: 0;
    }

    .top-row {
        position: sticky;
        top: 0;
        z-index: 1000;
    }

    .top-row.auth a:first-child {
        flex: 1;
        text-align: right;
        width: 0;
    }

    .top-row, article {
        padding-left: 2rem !important;
        padding-right: 1.5rem !important;
    }
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    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;
    }

/* --- NavMenu --- */
.navbar-toggler {
    appearance: none;
    cursor: pointer;
    width: 3.5rem;
    height: 2.5rem;
    color: white;
    position: absolute;
    top: 0.5rem;
    right: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.55%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") no-repeat center/1.75rem rgba(255, 255, 255, 0.1);
}

.navbar-toggler:checked {
    background-color: rgba(255, 255, 255, 0.5);
}

/* The sidebar has its own top-row: a dark overlay on the sidebar gradient, not the blue gradient
   of the main top-row above the content. Blazor kept these apart by scoping (MainLayout.razor.css
   vs NavMenu.razor.css); in one shared stylesheet this rule has to name the sidebar explicitly, or
   it overrides the main top-row as well. `background` (not `background-color`) so the gradient
   inherited from the .top-row rule above is cleared rather than painted on top of the overlay. */
.sidebar .top-row {
    height: 3.5rem;
    background: rgba(0, 0, 0, 0.4);
}

.sidebar .navbar-brand {
    font-size: 1.1rem;
}

.bi {
    display: inline-block;
    position: relative;
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.75rem;
    top: -1px;
    background-size: cover;
}

.bi-house-door-fill-nav-menu {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-house-door-fill' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5Z'/%3E%3C/svg%3E");
}

.bi-plus-square-fill-nav-menu {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-plus-square-fill' viewBox='0 0 16 16'%3E%3Cpath d='M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm6.5 4.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3a.5.5 0 0 1 1 0z'/%3E%3C/svg%3E");
}

.bi-list-nested-nav-menu {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-list-nested' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M4.5 11.5A.5.5 0 0 1 5 11h10a.5.5 0 0 1 0 1H5a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 1 3h10a.5.5 0 0 1 0 1H1a.5.5 0 0 1-.5-.5z'/%3E%3C/svg%3E");
}

.nav-item {
    font-size: 0.9rem;
    padding-bottom: 0.5rem;
}

    .nav-item:first-of-type {
        padding-top: 1rem;
    }

    .nav-item:last-of-type {
        padding-bottom: 1rem;
    }

    .nav-item .nav-link {
        color: #d7d7d7;
        background: none;
        border: none;
        border-radius: 4px;
        height: 3rem;
        display: flex;
        align-items: center;
        line-height: 3rem;
        width: 100%;
    }

.nav-item a.active {
    background-color: rgba(255,255,255,0.37);
    color: white;
}

.nav-item .nav-link:hover {
    background-color: rgba(255,255,255,0.1);
    color: white;
}

.nav-scrollable {
    display: none;
}

.navbar-toggler:checked ~ .nav-scrollable {
    display: block;
}

@media (min-width: 641px) {
    .navbar-toggler {
        display: none;
    }

    .nav-scrollable {
        /* Never collapse the sidebar for wide screens */
        display: block;

        /* Allow sidebar to scroll for tall menus */
        height: calc(100vh - 3.5rem);
        overflow-y: auto;
    }
}
