/* The signed-in shell (Components/Layout/MainLayout.razor + NavMenu.razor): a sidebar with the brand bar and the
   nav, and an account row over the content. The two top bars only line up while they
   agree on a height, so both read --topbar-height (nocturne.css). */

.page {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

main {
    flex: 1;
    min-width: 0;
}

/* ---- brand lockup: a tooth badge + two-line name ---- */

.brand-lockup {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none;
    min-width: 0;
}

.brand-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    flex-shrink: 0;
    background-color: color-mix(in srgb, var(--color-accent) 12%, var(--color-surface));
    box-shadow: 0 0 0 1px var(--color-divider);
}

.brand-logo svg {
    width: 1.5rem;
    height: 1.5rem;
    fill: var(--color-accent);
}

.brand-text {
    display: flex;
    flex-direction: column;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.15rem;
    line-height: 1.1;
    letter-spacing: -0.015em;
    white-space: nowrap;
}

.brand-name { color: var(--color-text); }
.brand-accent { color: var(--color-accent); }

/* ---- theme toggle: round, icon-only ---- */

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    color: var(--color-text);
    background-color: color-mix(in srgb, var(--color-accent) 10%, var(--color-surface));
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.theme-toggle:hover {
    background-color: color-mix(in srgb, var(--color-accent) 18%, var(--color-surface));
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* Same three states as nocturne.css: an explicit data-theme wins; with none, the OS
   preference decides. */
.theme-icon-moon { display: none; }
:root[data-theme="dark"] .theme-icon-sun { display: none; }
:root[data-theme="dark"] .theme-icon-moon { display: block; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-icon-sun { display: none; }
    :root:not([data-theme="light"]) .theme-icon-moon { display: block; }
}

/* ---- sidebar ---- */

.sidebar {
    background-color: var(--color-bg);
    border-right: 1px solid var(--color-divider);
}

.sidebar .top-row {
    position: relative;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding-left: 1rem;
    background-color: var(--color-bg);
    border-bottom: 1px solid var(--color-divider);
}

/* The phone menu button, round like the theme toggle. It is a checkbox with
   appearance:none, so it can't hold an inline <svg> — the icon is a background image,
   and a data-URI SVG can't use currentColor, hence one image per theme. */
.navbar-toggler {
    appearance: none;
    cursor: pointer;
    width: 2.75rem;
    height: 2.75rem;
    position: absolute;
    top: calc((var(--topbar-height) - 2.75rem) / 2);
    right: 1rem;
    border: 0;
    border-radius: 50%;
    background-color: color-mix(in srgb, var(--color-accent) 10%, var(--color-surface));
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3e%3cpath fill='none' stroke='%2318261e' stroke-linecap='round' stroke-width='2' d='M4.5 7h15M4.5 12h15M4.5 17h15'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 1.25rem;
    transition: background-color 0.15s ease;
}

.navbar-toggler:hover,
.navbar-toggler:checked {
    background-color: color-mix(in srgb, var(--color-accent) 18%, var(--color-surface));
}

.navbar-toggler:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

:root[data-theme="dark"] .navbar-toggler {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3e%3cpath fill='none' stroke='%23e5ede8' stroke-linecap='round' stroke-width='2' d='M4.5 7h15M4.5 12h15M4.5 17h15'/%3e%3c/svg%3e");
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .navbar-toggler {
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3e%3cpath fill='none' stroke='%23e5ede8' stroke-linecap='round' stroke-width='2' d='M4.5 7h15M4.5 12h15M4.5 17h15'/%3e%3c/svg%3e");
    }
}

.nav-scrollable {
    display: none;
    background: var(--color-bg);
    padding: 0.75rem 0.5rem 1rem;
}

.navbar-toggler:checked ~ .nav-scrollable {
    display: block;
}

.sidebar .nav {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0;
}

.sidebar .nav-item {
    padding-bottom: 0.35rem;
    width: 100%;
}

.sidebar .nav-item:first-of-type { padding-top: 1.25rem; }
.sidebar .nav-item:last-of-type { padding-bottom: 1.25rem; }

.sidebar .nav-link {
    box-sizing: border-box;
    color: color-mix(in srgb, var(--color-text) 75%, transparent);
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 0.65rem;
    line-height: 1.4;
    padding: 0.85rem 1.1rem;
    margin: 0.15rem 0.5rem;
    font-weight: 500;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: calc(100% - 1rem);
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar .nav-link svg {
    flex: none;
    width: 1.1rem;
    height: 1.1rem;
    color: var(--color-accent);
}

.sidebar .nav-link.active {
    background: color-mix(in srgb, var(--color-accent) 14%, var(--color-surface));
    color: var(--color-accent);
    font-weight: 600;
    border-left: 0.25rem solid var(--color-accent);
    padding-left: calc(1.1rem - 0.25rem);
}

.sidebar .nav-link:hover {
    background: color-mix(in srgb, var(--color-accent) 12%, transparent);
    color: var(--color-text);
}

.sidebar .nav-link:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* ---- account row over the content ---- */

main > .top-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
    height: var(--topbar-height);
    background-color: var(--color-surface);
    border-bottom: 1px solid var(--color-divider);
}

.top-row-actions {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-left: auto;
    flex-shrink: 0;
}

.top-row-divider {
    width: 1px;
    height: 1.5rem;
    background-color: var(--color-divider);
}

.top-row-form {
    display: flex;
    margin: 0;
}

.top-row-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.35rem 0;
    border: 0;
    background: none;
    color: color-mix(in srgb, var(--color-text) 72%, transparent);
    font: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.top-row-link:hover { color: var(--color-link-hover); }

.top-row-link:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

.top-row-link svg { flex-shrink: 0; }

.top-row-link.active {
    color: var(--color-accent);
    font-weight: 600;
}

.top-row-link.active::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -0.3rem;
    height: 3px;
    border-radius: 3px;
    background-color: var(--color-accent);
}

.content {
    padding-top: 1.1rem;
    padding-bottom: 2rem;
}

@media (max-width: 480px) {
    .brand-lockup { gap: 0.45rem; }
    .brand-logo { width: 2.25rem; height: 2.25rem; }
    .brand-text { font-size: 0.9rem; }
    .theme-toggle { width: 2.25rem; height: 2.25rem; }
    .theme-icon { width: 18px; height: 18px; }

    .top-row-actions { gap: 0.75rem; }
    .top-row-divider { display: none; }

    /* Icons only on phones. Visually hidden, not display:none, so "My profile" and
       "Log out" stay the accessible names of their controls. */
    .top-row-label {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
}

@media (min-width: 641px) {
    .page { flex-direction: row; }

    .sidebar {
        width: 300px;
        max-width: 100%;
        height: 100vh;
        position: sticky;
        top: 0;
    }

    .navbar-toggler { display: none; }

    .nav-scrollable {
        display: block;
        height: calc(100vh - var(--topbar-height));
        overflow-y: auto;
        /* Let the sidebar plate show through. Below this width the panel is a
           dropdown over the page and has to stay opaque. */
        background: transparent;
    }

    main > .top-row {
        position: sticky;
        top: 0;
        z-index: 1;
    }

    main > .top-row, .content {
        padding-left: 2rem !important;
        padding-right: 1.5rem !important;
    }
}

/* Blazor's "unhandled error" bar (MainLayout); blazor.web.js shows it. */
#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;
}

/* ── Chrome artwork ───────────────────────────────────────────────────────
   Three background plates: a bloom entering the account row from the left, the
   sidebar art anchored to its bottom, and a page wash behind the content. Each is
   raster art on a solid ground, so light and dark are separate images, declared for
   the media query *and* the explicit toggle so the toggle wins in both directions.
   The page wash has no dark plate; dark keeps the flat ground. */

main > .top-row {
    background-image: url("/images/topbar-light.png");
    background-repeat: no-repeat;
    background-position: left center;
    background-size: cover;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) main > .top-row {
        background-image: url("/images/topbar-dark.png");
    }
}

:root[data-theme="dark"] main > .top-row {
    background-image: url("/images/topbar-dark.png");
}

/* Desktop only: below 641px the sidebar is a header and the content one narrow column,
   and a fixed attachment is a scroll-performance trap on phones. */
@media (min-width: 641px) {
    .sidebar {
        background-image: url("/images/nav-light.png");
        background-repeat: no-repeat;
        background-position: bottom center;
        background-size: cover;
    }

    :root[data-theme="dark"] .sidebar {
        background-image: url("/images/nav-dark.png");
    }

    .content {
        /* The wash is clipped to this box, so a short page would show only a sliver. */
        min-height: calc(100vh - var(--topbar-height));
        background-image: url("/images/dashboard.png");
        background-repeat: no-repeat;
        background-position: bottom right;
        background-size: cover;
        background-attachment: fixed;
    }

    :root[data-theme="dark"] .content {
        background-image: none;
    }
}

@media (min-width: 641px) and (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .sidebar {
        background-image: url("/images/nav-dark.png");
    }

    :root:not([data-theme="light"]) .content {
        background-image: none;
    }
}
