.app-navigation {
    border-bottom: 1px solid #e5e7eb;
}
.wegweiser {
    --wegweiser-footer-offset: min(var(--visible-footer-height, 0px), max(0px, calc(100dvh - var(--navbar-height, 64px) - 8rem)));
    bottom: var(--wegweiser-footer-offset, 0px);
    margin-bottom: max(1rem, env(safe-area-inset-bottom));
}
.wegweiser-panel {
    max-height: calc(100dvh - var(--navbar-height, 64px) - var(--wegweiser-footer-offset, 0px) - 6rem);
}

.app-navigation a:focus-visible,
.app-navigation button:focus-visible,
.app-footer a:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 3px;
}

.app-navigation [aria-current] {
    color: #1d4ed8;
    background: #eff6ff;
}

.nav-split {
    display: flex;
    align-items: center;
}

.nav-split:has(.nav-dropdown-toggle) > a {
    padding-right: 0.375rem;
}

.nav-split:has(.nav-dropdown-toggle) {
    border-radius: 8px;
    color: #4b5563;
}

.app-navigation .nav-split:has(.nav-dropdown-toggle) > :is(a, .nav-dropdown-toggle) {
    background: transparent;
    color: inherit;
}

.nav-split:has(.nav-dropdown-toggle):is(:hover, :focus-within, :has(> a[aria-current]), :has(> .nav-dropdown-toggle[aria-expanded="true"])) {
    background: #eff6ff;
    color: #2563eb;
}

.nav-dropdown-toggle {
    display: inline-flex;
    min-width: 32px;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: #4b5563;
}

.nav-dropdown-toggle:hover,
.nav-dropdown-toggle[aria-expanded="true"] {
    background: #eff6ff;
    color: #1d4ed8;
}

[data-nav-disclosure][aria-expanded="true"] > svg:last-child,
.mobile-toolbox > button[aria-expanded="true"] > svg:last-child,
.mobile-create > button[aria-expanded="true"] > svg:last-child,
.mobile-account > button[aria-expanded="true"] > svg:last-child {
    transform: rotate(180deg);
}

.nav-dropdown-panel {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 50;
    min-width: 14rem;
    padding: 0.375rem;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 12px 24px -12px rgb(15 23 42 / 24%);
}

.nav-dropdown-panel--right {
    right: 0;
    left: auto;
}

.nav-dropdown-panel a {
    min-height: 40px;
    border-radius: 6px;
}

.nav-search-field:focus-within {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.nav-search-field input::placeholder {
    color: #6b7280;
}

.skip-link {
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 100000;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    background: #1d4ed8;
    color: #fff;
    transform: translateY(-160%);
}

.skip-link:focus {
    transform: none;
    outline: 2px solid #fff;
    outline-offset: 2px;
}

#main-content {
    scroll-margin-top: calc(var(--navbar-height, 64px) + 1rem);
}

#main-content:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: -2px;
}

html.dark .app-navigation,
html.dark .nav-dropdown-panel {
    border-color: #334155;
}

html.dark .nav-dropdown-panel {
    background: #1e293b;
}

html.dark .nav-dropdown-toggle {
    color: #cbd5e1;
}

html.dark .nav-split:has(.nav-dropdown-toggle) {
    color: #cbd5e1;
}

html.dark .nav-split:has(.nav-dropdown-toggle):is(:hover, :focus-within, :has(> a[aria-current]), :has(> .nav-dropdown-toggle[aria-expanded="true"])) {
    background: #334155;
    color: #93c5fd;
}

html.dark .app-navigation [aria-current],
html.dark .nav-dropdown-toggle:hover,
html.dark .nav-dropdown-toggle[aria-expanded="true"] {
    background: #1e3a5f;
    color: #93c5fd;
}

html.dark .app-navigation a:focus-visible,
html.dark .app-navigation button:focus-visible,
html.dark .app-footer a:focus-visible,
html.dark .nav-search-field:focus-within {
    outline-color: #93c5fd;
}

html.dark .nav-search-field input::placeholder {
    color: #cbd5e1;
}

@media (max-width: 1023px) {
    .mobile-menu {
        max-height: calc(100dvh - var(--navbar-height, 56px));
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .app-navigation .mobile-menu-button,
    .mobile-menu button,
    .mobile-menu a {
        min-height: 44px;
    }

    .app-navigation .mobile-menu-button {
        min-width: 44px;
    }
}

@media (max-width: 767px) {
    .app-footer--launchers {
        padding-bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 639px) {
    #toggle-sidebar {
        top: calc(var(--navbar-height, 3.5rem) / 2);
        right: calc(2rem + 28px);
        left: calc(2rem + 16px);
        z-index: 1060;
        display: flex;
        min-width: 0;
        min-height: 44px;
        padding: 4px 8px;
        border-radius: 8px;
        box-shadow: none;
        transition: background-color 150ms ease-out, color 150ms ease-out;
    }

    #toggle-sidebar > div {
        flex-direction: row;
        justify-content: center;
        gap: 6px;
    }

    #toggle-sidebar .toggle-sidebar-text {
        writing-mode: horizontal-tb;
        white-space: normal;
        line-height: 1.25;
        letter-spacing: normal;
    }

    #toggle-sidebar .underline-blue {
        text-decoration: none;
    }

    #toggle-sidebar[aria-expanded="true"],
    #toggle-sidebar:hover {
        background-color: #eff6ff !important;
        color: #1d4ed8 !important;
    }

    #toggle-sidebar:focus-visible {
        outline: 2px solid #2563eb;
        outline-offset: 2px;
    }

    html.dark #toggle-sidebar[aria-expanded="true"],
    html.dark #toggle-sidebar:hover {
        background-color: #1e3a5f !important;
        color: #93c5fd !important;
    }

    html.dark #toggle-sidebar:focus-visible {
        outline-color: #93c5fd;
    }
}

@media (max-width: 639px) {
    .chat-launchers {
        position: fixed;
        left: max(12px, env(safe-area-inset-left));
        bottom: max(12px, env(safe-area-inset-bottom));
        z-index: 60;
        display: flex;
        align-items: flex-end;
        gap: 8px;
        max-width: calc(100vw - max(12px, env(safe-area-inset-left)) - max(12px, env(safe-area-inset-right)));
        pointer-events: none;
    }
    body .chat-launchers #toggleChatHistory,
    .chat-launchers > [data-mcp-selector] {
        position: static;
        pointer-events: auto;
    }
    .chat-launchers [data-mcp-toggle] {
        min-width: 44px;
        min-height: 44px;
        padding: 8px;
        gap: 6px;
        font-size: 0.8125rem;
        line-height: 1.25;
    }
    .chat-launchers [data-mcp-toggle] > svg {
        width: 20px;
        height: 20px;
        flex: none;
    }
    .chat-launchers #globalMcpToolPopover {
        left: 0;
        width: min(22rem, calc(100vw - max(12px, env(safe-area-inset-left)) - max(12px, env(safe-area-inset-right))));
    }
    body #toggleChatHistory,
    body #wegweiserToggle {
        max-width: calc((100vw - max(12px, env(safe-area-inset-left)) - max(12px, env(safe-area-inset-right)) - 8px) / 2);
        min-height: 44px;
        padding: 8px 4px;
        gap: 4px 6px;
        flex-wrap: wrap;
        justify-content: center;
    }

    body #toggleChatHistory {
        left: max(12px, env(safe-area-inset-left));
        bottom: max(12px, env(safe-area-inset-bottom));
    }

    .wegweiser {
        right: max(12px, env(safe-area-inset-right));
        margin-bottom: max(12px, env(safe-area-inset-bottom));
    }

    body:has(> .wegweiser:not([hidden])) > .chat-launchers {
        flex-wrap: wrap-reverse;
        max-width: calc((100vw - max(12px, env(safe-area-inset-left)) - max(12px, env(safe-area-inset-right)) - 8px) / 2);
    }

    #toggleChatHistory > svg,
    #wegweiserToggle > svg {
        width: 20px;
        height: 20px;
        flex: none;
    }

    #toggleChatHistory > span,
    #wegweiserToggle > span {
        font-size: 0.8125rem;
        line-height: 1.25;
        white-space: nowrap;
    }

    .wegweiser-panel {
        width: min(24rem, calc(100vw - 24px));
        max-height: calc(100dvh - var(--navbar-height, 3.5rem) - var(--wegweiser-footer-offset, 0px) - 6rem);
    }

    html {
        scroll-padding-bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px));
    }
}

/* The update dialog stays inside the viewport while its release list scrolls. */
body:has(#whats-new-modal[open]) { overflow: hidden; }
.whats-new-modal {
    width: min(38rem, calc(100% - 2rem));
    max-width: none;
    max-height: calc(100dvh - 2rem);
    margin: auto;
    padding: 0;
    border: 0;
    border-radius: 16px;
    background: #fff;
    color: #0f172a;
    box-shadow: 0 24px 64px -20px rgb(15 23 42 / 40%);
}
.whats-new-modal[open] { display: flex; flex-direction: column; }
.whats-new-modal::backdrop { background: rgb(15 23 42 / 55%); }
.whats-new-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    flex: none;
}
.whats-new-header h2 { margin: 0; font-size: 1.5rem; font-weight: 650; line-height: 1.25; }
.whats-new-header p { margin: 0.375rem 0 0; color: #64748b; font-size: 0.875rem; }
.whats-new-header button {
    display: inline-flex;
    width: 44px;
    height: 44px;
    flex: none;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: #475569;
}
.whats-new-header button:hover { background: #f1f5f9; }
.whats-new-scroll { min-height: 0; padding: 1.25rem; overflow-y: auto; overscroll-behavior: contain; overflow-wrap: anywhere; }
.whats-new-releases { display: grid; gap: 1.25rem; margin: 0 0 1.5rem; padding: 0; list-style: none; }
.whats-new-releases h3 { margin: 0 0 0.25rem; font-weight: 600; }
.whats-new-scroll p { margin: 0; color: #475569; line-height: 1.6; }
.whats-new-scroll > p { font-size: 0.875rem; }
.whats-new-actions { display: flex; justify-content: flex-end; padding: 1rem 1.25rem; border-top: 1px solid #e2e8f0; flex: none; }
.whats-new-modal :focus-visible { outline: 2px solid #2563eb; outline-offset: -3px; }
html.dark .whats-new-modal { background: #1e293b; color: #f1f5f9; }
html.dark :is(.whats-new-header, .whats-new-actions) { border-color: #334155; }
html.dark :is(.whats-new-header p, .whats-new-scroll p, .whats-new-header button) { color: #cbd5e1; }
html.dark .whats-new-header button:hover { background: #334155; }
html.dark .whats-new-modal :focus-visible { outline-color: #93c5fd; }

.library-results .collection-card { overflow-wrap: anywhere; }
.library-results .collection-card svg { flex-shrink: 0; }
.library-search { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; }
.library-search input { flex: 1 1 14rem; width: 100%; min-width: 0; }
.library-search button { flex: 0 0 auto; }
.library-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.library-filter-label { flex: 0 0 100%; font-size: 0.875rem; font-weight: 500; }
.library-filter select { flex: 1 1 12rem; max-width: 24rem; min-width: 0; }
.library-pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.5rem; margin-top: 2rem; }
.library-pagination a { min-height: 44px; }
.library-page-number { color: #475569; font-size: 0.875rem; }
html.dark .library-page-number { color: #cbd5e1; }
@media (max-width: 639px) {
    .whats-new-header, .whats-new-scroll, .whats-new-actions { padding: 20px; }
    .whats-new-header { gap: 12px; }
    .whats-new-actions .ui-button { width: 100%; padding-inline: 12px; }
}

.app-navigation .suggestions-dropdown {
    z-index: 80;
    max-height: min(24rem, calc(100dvh - var(--navbar-height, 56px) - 5rem));
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    overflow-wrap: anywhere;
}

.library-search-summary { overflow-wrap: anywhere; }

@media (min-width: 1024px) {
    .app-navigation [data-nav-header] > div {
        height: auto;
        min-height: 4rem;
        flex-wrap: wrap;
        gap: 0.25rem 0.75rem;
        padding-block: 0.5rem;
    }
    .app-navigation [data-nav-header] > div > .lg\:space-x-3 {
        min-width: 0;
        max-width: 100%;
        flex-wrap: wrap;
        gap: 0.5rem 0.75rem;
    }
    .app-navigation [data-nav-header] > div > .lg\:space-x-3 > :not([hidden]) ~ :not([hidden]) {
        margin-left: 0;
        margin-right: 0;
    }
}

@media (max-width: 639px) {
    .wegweiser-panel { padding: 20px; }
    .wegweiser-panel h2 { min-width: 0; overflow-wrap: anywhere; }
    .wegweiser-panel header button { min-width: 44px; min-height: 44px; flex: none; }
    .wegweiser-panel footer { flex-wrap: wrap; }
}
