html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    /* Radzen 11.3.2's own theme CSS only sets this (":root:has(.rz-layout) body { color:
       var(--rz-text-color); background-color: var(--rz-body-background-color); ... }") when the
       page uses Radzen's own <RadzenLayout>. This app uses its own hand-rolled .app-layout shell
       instead, so that selector never matches and plain text (headings, paragraphs, labels —
       anything outside a themed Radzen component) silently fell back to the browser default black
       text color. That's invisible in the light theme (black-on-white) but unreadable in
       standard-dark (black-on-near-black) — this is the actual root cause of the "page headings
       and body text stay dark on dark background" defect. Body background is already handled by
       a separate, unscoped decorative rule in the same theme CSS, so only color needs setting
       here. */
    color: var(--rz-text-color);
}

.app-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        "header header"
        "sidebar content"
        "footer footer";
    min-height: 100vh;
    transition: grid-template-columns 0.15s ease;
}

.app-nav-toggle-state {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.app-nav-toggle-state:checked ~ .app-layout {
    grid-template-columns: 0 1fr;
}

.app-nav-toggle-state:checked ~ .app-layout .app-sidebar {
    padding-left: 0;
    padding-right: 0;
    overflow: hidden;
    border-right-width: 0;
}

.app-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    margin-right: 0.5rem;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
}

.app-nav-toggle:hover {
    background: rgba(255, 255, 255, 0.12);
}

.app-header {
    grid-area: header;
    position: relative;
    z-index: 1300;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    min-width: 0;
    padding: 0.5rem 1rem;
    /* Deliberately the same always-dark background/light text as RadzenPanelMenu's own sidebar
       (--rz-sidebar-background-color / --rz-sidebar-color are white in BOTH the standard and
       standard-dark themes — Radzen's sidebar is designed to stay dark regardless of the active
       theme), so the header stays readable without needing per-theme overrides. */
    background: var(--rz-sidebar-background-color);
    color: var(--rz-sidebar-color);
}

.app-header .app-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.app-header .app-logo {
    height: 28px;
}

.app-header .app-title {
    font-weight: 600;
    font-size: 1.1rem;
}

.app-header .app-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    flex-shrink: 1;
}

.app-header .app-brand {
    min-width: 0;
    flex-shrink: 1;
}

.app-header .app-username {
    font-size: 0.9rem;
}

.app-header .app-console-link {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.7rem;
    border-radius: 6px;
    background: linear-gradient(135deg, var(--rz-primary), var(--rz-primary-light));
    color: var(--rz-on-primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.8rem;
}

.app-sidebar {
    grid-area: sidebar;
    /* Same always-dark background/light text as .app-header above, and as RadzenPanelMenu's own
       item colors — keeps the search box's surrounding rail (outside the RadzenPanelMenu itself)
       consistent with it in both themes instead of showing through the ambient (theme-dependent)
       body background. */
    background: var(--rz-sidebar-background-color);
    color: var(--rz-sidebar-color);
    border-right: 1px solid var(--rz-border-color);
    overflow-y: auto;
    padding: 0.5rem;
}

.app-sidebar .app-search {
    padding: 0.25rem 0.25rem 0.75rem;
}

.app-content {
    grid-area: content;
    padding: 1rem;
    overflow: auto;
    min-width: 0;
}

.app-footer {
    grid-area: footer;
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    color: var(--rz-text-secondary-color);
    border-top: 1px solid var(--rz-border-color);
}

.nav-disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: default;
}

.text-danger {
    color: var(--rz-danger);
}

/* Manage/Endpoint & Manage/DataStore pages (phase 1): Radzen's standard-base theme ships
   rz-display-flex, rz-mb-, rz-p- etc. utility classes but no flex-wrap or monospace helper. */
.rz-flex-wrap {
    flex-wrap: wrap;
}

.font-monospace {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 900px) {
    .app-layout,
    .app-nav-toggle-state:checked ~ .app-layout {
        grid-template-columns: 0 1fr;
    }

    .app-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 260px;
        z-index: 1200;
        transform: translateX(-100%);
        transition: transform 0.15s ease;
        box-shadow: 0 0 24px rgba(0, 0, 0, 0.35);
        padding-top: 3.5rem;
    }

    .app-nav-toggle-state:checked ~ .app-layout .app-sidebar {
        transform: none;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        overflow-y: auto;
        border-right-width: 1px;
    }

    .app-footer {
        flex-direction: column;
        gap: 0.15rem;
    }
}

@media (max-width: 640px) {
    .app-header {
        padding: 0.4rem 0.6rem;
        gap: 0.35rem;
    }

    .app-header .app-title {
        display: none;
    }

    .app-header .app-user {
        gap: 0.35rem;
        min-width: 0;
    }

    .app-header .app-username {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 8rem;
        font-size: 0.8rem;
    }

    .app-header .app-console-link {
        padding: 0.3rem 0.45rem;
        font-size: 0.7rem;
    }

    .app-content {
        padding: 0.6rem;
    }
}

.app-content .rz-tabview-nav {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: thin;
}

.app-content .rz-tabview-nav li {
    flex: 0 0 auto;
}

.app-content .rz-datatable,
.app-content .rz-data-grid {
    max-width: 100%;
}

.app-content img {
    max-width: 100%;
    height: auto;
}

.app-content .rz-display-flex {
    flex-wrap: wrap;
}

.app-content .rz-button,
.app-content .rz-label,
.app-content .rz-chkbox,
.rz-dialog .rz-button,
.rz-dialog .rz-label,
.rz-dialog .rz-chkbox {
    flex-shrink: 0;
}

.rz-dialog .rz-display-flex {
    flex-wrap: wrap;
}

.app-content .rz-tabview-left {
    min-width: 0;
}

@media (max-width: 640px) {
    .rz-dialog {
        max-width: calc(100vw - 1.5rem);
    }

    .app-content .rz-tabview-left {
        flex-direction: column;
    }

    .app-content .rz-tabview-left > .rz-tabview-nav {
        flex-direction: row;
    }

    .app-content .rz-tabview-left > .rz-tabview-panels {
        width: 100%;
    }
}
