.app-shell {
    --app-shell-lift: 1.1rem;
}

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) var(--content-width) var(--rail-width);
    align-items: start;
    gap: var(--sidebar-gap);
    justify-content: center;
    width: min(var(--app-shell-width), calc(100% - 2rem));
    margin: calc(var(--app-shell-lift) * -1) auto 0;
    margin-top: -50px !important;
}

.app-main {
    grid-column: 2;
    justify-self: stretch;
    width: 100%;
    max-width: var(--content-width);
    min-width: 0;
}

.sidebar,
.right-rail {
    position: sticky;
    top: 0;
    align-self: start;
}

.sidebar {
    grid-column: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    width: 200px;
    max-width: 200px;
    min-width: 0;
    height: calc(100svh - var(--app-shell-lift));
    min-height: calc(100svh - var(--app-shell-lift));
    max-height: calc(100svh - var(--app-shell-lift));
    overflow: hidden;
    padding: 0.15rem 0 0.2rem;
    scrollbar-gutter: auto;
}

.sidebar,
.sidebar__top,
.sidebar__bottom,
.sidebar-nav,
.sidebar form,
.sidebar .brand-block,
.sidebar .nav-link,
.sidebar .nav-link--button {
    box-sizing: border-box;
    max-width: 100%;
    min-width: 0;
    overflow-x: clip;
}

.sidebar__top,
.sidebar__bottom,
.sidebar-nav,
.column-shell,
.comment-stack,
.list-stack,
.feed-stack,
.drawer__body,
.flash-stack {
    display: grid;
    gap: 1rem;
}

.feed-stack {
    gap: 0.72rem;
}

.sidebar-nav {
    gap: 0.3rem;
    align-content: start;
    grid-auto-rows: min-content;
}

.sidebar__bottom {
    gap: 0.55rem;
}

.column-shell,
.column-shell > *,
.feed-stack,
.comment-stack,
.list-stack,
[data-search-results],
[data-feed-list],
[data-profile-posts] {
    width: 100%;
    min-width: 0;
}

.sidebar__brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    margin-bottom: 0.35rem;
}

.sidebar__top {
    gap: 0.8rem;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    padding-bottom: 0.35rem;
    align-content: start;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.sidebar__top::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.sidebar__bottom {
    margin-top: auto;
    padding-top: 0.55rem;
    flex: 0 0 auto;
    transform: translateY(-20px);
}

.sidebar .nav-link,
.sidebar .nav-link--button {
    max-width: 100%;
    min-width: 0;
    min-height: 3rem;
    overflow: hidden;
    padding: 0.68rem 0.92rem;
}

.sidebar .brand-block {
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
}

.sidebar .nav-link span:not(.badge),
.sidebar .nav-link--button span,
.sidebar .brand-block div {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar .badge {
    flex: none;
    margin-left: auto;
}

.sidebar svg,
.sidebar .icon {
    flex: 0 0 auto;
}

.sidebar__identity {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-soft);
    padding: 0.25rem 0.35rem;
}

.sidebar__identity strong {
    display: block;
    color: var(--text);
    font-size: 0.95rem;
}

.sidebar__identity small {
    color: var(--text-muted);
}

.sidebar__identity-mark {
    display: inline-grid;
    place-items: center;
    width: 1.8rem;
    height: 1.8rem;
    border-radius: 999px;
    background: rgba(255, 214, 102, 0.14);
    color: #ffcf64;
}

.right-rail {
    grid-column: 3;
    justify-self: stretch;
    display: flex;
    flex-direction: column;
    width: 200px;
    max-width: 200px;
    min-width: 0;
    min-height: calc(100svh - var(--app-shell-lift));
}

.right-rail__spacer {
    display: none;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    width: 100%;
}

.page-header--stacked,
.page-header--feed {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
    align-items: stretch;
    width: 100%;
}

.page-header--stacked > *,
.page-header--feed > * {
    width: 100%;
    min-width: 0;
}

.subpage-bar {
    display: flex;
    align-items: center;
}

.rail-footer {
    align-self: flex-start;
    max-width: var(--rail-width);
    margin-top: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem 0.9rem;
    color: var(--text-muted);
    font-size: 0.82rem;
    line-height: 1.45;
    padding: 0 0.1rem 0.35rem;
}

.mobile-nav {
    position: fixed;
    right: 0.85rem;
    bottom: calc(0.8rem + env(safe-area-inset-bottom));
    left: 0.85rem;
    z-index: 17;
    display: none;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.35rem;
    padding: 0.52rem;
    border: 0;
    border-radius: 999px;
    background: var(--surface);
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    opacity: 1;
    visibility: visible;
    transition: opacity var(--transition-base), transform var(--transition-base), visibility var(--transition-base);
}

body[data-bs-theme="light"] .mobile-nav {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.56), transparent 62%),
        rgba(255, 255, 255, 0.62);
}

.compose-fab {
    position: fixed;
    right: max(1.25rem, calc((100vw - var(--app-shell-width)) / 2 + 0.25rem));
    bottom: calc(1.25rem + env(safe-area-inset-bottom));
    z-index: 16;
    display: none;
    place-items: center;
    width: 3.9rem;
    height: 3.9rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    opacity: 1;
    visibility: visible;
    cursor: pointer;
    transition: opacity var(--transition-base), transform var(--transition-base), visibility var(--transition-base), box-shadow var(--transition-base);
}

.compose-fab:hover {
    transform: translateY(-0.18rem) scale(1.03);
    box-shadow: none;
}

.compose-fab svg {
    width: 1.45rem;
    height: 1.45rem;
}

body.has-open-dialog .mobile-nav,
body.has-open-dialog .compose-fab,
body.has-open-drawer .mobile-nav,
body.has-open-drawer .compose-fab,
body.has-open-sheet .mobile-nav,
body.has-open-sheet .compose-fab {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(1rem);
}

.drawer {
    position: fixed;
    top: 0.85rem;
    right: 0.85rem;
    bottom: 0.85rem;
    z-index: 22;
    width: min(420px, calc(100vw - 2rem));
    padding: 1.05rem;
    border: 0;
    border-radius: 28px;
    background: var(--surface);
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    opacity: 0;
    transform: translateX(14px);
    visibility: hidden;
    pointer-events: none;
    transition: transform var(--transition-base), opacity var(--transition-base), visibility var(--transition-base);
}

body[data-bs-theme="light"] .drawer {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.48), transparent 48%),
        rgba(255, 255, 255, 0.70);
}

.drawer.is-open {
    opacity: 1;
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
}

.drawer__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.9rem;
}

.drawer__actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.drawer__body {
    max-height: calc(100% - 4.5rem);
    overflow: auto;
    padding-right: 0.15rem;
}

.dialog-shell {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 23;
    display: grid;
    width: fit-content;
    max-width: calc(100vw - 2rem);
    max-height: calc(100vh - 2rem);
    margin: 0;
    overflow: hidden;
    overscroll-behavior: contain;
    padding: 0;
    border: 0;
    border-radius: 36px;
    background: var(--surface);
    color: var(--text);
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(1.08);
    transition: opacity 180ms ease, transform 200ms ease, visibility 180ms ease;
}

body[data-bs-theme="light"] .dialog-shell {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.52), transparent 52%),
        rgba(255, 255, 255, 0.76);
}

.dialog-shell[open] {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.dialog-shell.is-closing {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.04);
}

.dialog-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 6;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 50%;
    background: #222224;
    color: #fff;
    box-shadow: none;
}

.dialog-close svg {
    width: 18px;
    height: 18px;
}

body[data-bs-theme="light"] .dialog-close {
    border-color: rgba(15, 23, 42, 0.08);
    background: rgba(255, 255, 255, 0.9);
    color: #697181;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}

body[data-bs-theme="light"] .dialog-close:hover {
    background: #ffffff;
    color: #121722;
}

.dialog-content {
    padding: 0;
    max-height: calc(100vh - 2rem);
    min-height: 0;
    overflow: hidden;
}

.dialog-shell.dialog-shell--support {
    top: 50%;
    right: auto;
    bottom: auto;
    left: 50%;
    width: min(520px, calc(100vw - 1.25rem));
    height: auto;
    min-height: 0;
    max-width: calc(100vw - 1.25rem);
    max-height: calc(100dvh - 1.25rem);
    border-radius: 30px;
    transform: translate(-50%, -50%) scale(1.08);
}

.dialog-shell.dialog-shell--support[open] {
    transform: translate(-50%, -50%) scale(1);
}

.dialog-shell.dialog-shell--support.is-closing {
    transform: translate(-50%, -50%) scale(1.03);
}

.dialog-shell.dialog-shell--support .dialog-content {
    width: 100%;
    height: auto;
    min-height: 0;
    max-height: calc(100dvh - 1.25rem);
    overflow: hidden;
}

.dialog-shell.dialog-shell--support .dialog-content > .support-modal {
    width: 100%;
    height: auto;
    min-height: 0;
}

.dialog-loading {
    display: grid;
    place-items: center;
    min-height: min(52vh, 420px);
    padding: 2rem 1.25rem;
}

.dialog-shell.has-select-open,
.dialog-shell.has-select-open .dialog-content,
.dialog-shell.has-select-open .settings-dialog {
    overflow: hidden;
}

.dialog-toast-stack {
    position: absolute;
    top: 1rem;
    right: 4rem;
    z-index: 3;
    display: grid;
    gap: 0.65rem;
    width: min(320px, calc(100% - 5.5rem));
}

@media (min-width: 921px) {
    .dialog-shell:has(.settings-dialog) {
        width: 960px;
        max-width: none;
    }

    .dialog-shell:has(.settings-dialog) .dialog-content {
        width: 960px;
        max-width: none;
    }

    .dialog-shell:has(.connections-modal) {
        width: 420px;
        max-width: none;
    }

    .dialog-shell:has(.connections-modal) .dialog-content {
        width: 420px;
        max-width: none;
    }

    .dialog-shell:has(.premium-dialog) {
        width: 460px;
        max-width: none;
    }

    .dialog-shell:has(.premium-dialog) .dialog-content {
        width: 460px;
        max-width: none;
    }

    .dialog-shell:has(.report-dialog) {
        width: 560px;
        max-width: none;
    }

    .dialog-shell:has(.report-dialog) .dialog-content {
        width: 560px;
        max-width: none;
    }

    .dialog-shell:has(.post-editor-dialog) {
        width: 640px;
        max-width: none;
    }

    .dialog-shell:has(.post-editor-dialog) .dialog-content {
        width: 640px;
        max-width: none;
    }
}

.admin-shell {
    display: grid;
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
    gap: 1.5rem;
    width: min(1320px, calc(100% - 3rem));
    margin: 0 auto;
    padding: 1.5rem 0 2rem;
}

.admin-sidebar {
    position: sticky;
    top: 1.5rem;
    align-self: start;
    display: grid;
    gap: 1rem;
    min-height: calc(100vh - 3rem);
    padding: 1.2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--surface);
}

.admin-main {
    display: grid;
    gap: 1rem;
}

.auth-stage {
    min-height: 100vh;
    display: grid;
    place-items: center;
}

@media (max-width: 1180px) {
    .app-shell {
        grid-template-columns: var(--sidebar-width) var(--content-width);
        width: min(var(--app-shell-two-column-width), calc(100% - 2rem));
    }

    .right-rail {
        display: none;
    }
}

@media (max-width: 920px) {
    .app-shell,
    .admin-shell {
        grid-template-columns: minmax(0, 1fr);
        width: min(100%, calc(100% - 1rem));
        gap: 1rem;
        --app-shell-lift: 0rem;
        margin-top: 0;
        padding-top: 0.2rem;
    }

    .sidebar,
    .admin-sidebar {
        display: none;
    }

    .mobile-nav,
    .compose-fab {
        display: grid;
    }

    .compose-fab {
        place-items: center;
        right: 1.25rem;
        bottom: calc(6rem + env(safe-area-inset-bottom));
    }

    .app-shell {
        padding-bottom: calc(9.25rem + env(safe-area-inset-bottom));
    }

    .app-main,
    .right-rail {
        grid-column: 1;
    }

    .app-main {
        max-width: none;
        padding-bottom: calc(1.75rem + env(safe-area-inset-bottom));
    }

    .drawer {
        top: auto;
        right: 0.75rem;
        bottom: 5.8rem;
        left: 0.75rem;
        width: auto;
        max-height: min(68vh, 720px);
        transform: translateY(16px);
    }

    .drawer.is-open {
        transform: translateY(0);
    }

    .dialog-shell {
        position: fixed;
        top: 0.5rem;
        right: 0.5rem;
        bottom: calc(0.5rem + env(safe-area-inset-bottom));
        left: 0.5rem;
        width: calc(100vw - 1rem);
        height: calc(100dvh - 1rem - env(safe-area-inset-bottom));
        min-height: 0;
        max-width: none;
        max-height: none;
        margin: 0;
        border-radius: 32px;
        transform: translateY(24px);
    }

    .dialog-shell[open] {
        transform: translateY(0);
    }

    .dialog-content {
        height: 100%;
        max-height: none;
        min-height: 0;
        overflow: hidden;
    }

    .dialog-content > * {
        width: 100%;
        height: 100%;
        min-height: 0;
    }
}

@media (hover: none) and (pointer: coarse) {
    .app-shell,
    .admin-shell {
        grid-template-columns: minmax(0, 1fr);
        width: min(100%, calc(100% - 1rem));
        gap: 1rem;
        --app-shell-lift: 0rem;
        margin-top: 0;
        padding-top: 0.2rem;
    }

    .sidebar,
    .admin-sidebar,
    .right-rail {
        display: none;
    }

    .mobile-nav,
    .compose-fab {
        display: grid;
    }

    .compose-fab {
        place-items: center;
        right: 1.25rem;
        bottom: calc(6rem + env(safe-area-inset-bottom));
    }

    .app-shell {
        padding-bottom: calc(9.25rem + env(safe-area-inset-bottom));
    }

    .app-main,
    .right-rail {
        grid-column: 1;
    }

    .app-main {
        max-width: none;
        padding-bottom: calc(1.75rem + env(safe-area-inset-bottom));
    }

    .drawer {
        top: auto;
        right: 0.75rem;
        bottom: 5.8rem;
        left: 0.75rem;
        width: auto;
        max-height: min(68vh, 720px);
        transform: translateY(16px);
    }

    .drawer.is-open {
        transform: translateY(0);
    }

    .dialog-shell {
        position: fixed;
        top: 0.5rem;
        right: 0.5rem;
        bottom: calc(0.5rem + env(safe-area-inset-bottom));
        left: 0.5rem;
        width: calc(100vw - 1rem);
        height: calc(100dvh - 1rem - env(safe-area-inset-bottom));
        min-height: 0;
        max-width: none;
        max-height: none;
        margin: 0;
        border-radius: 32px;
        transform: translateY(24px);
    }

    .dialog-shell[open] {
        transform: translateY(0);
    }

    .dialog-content {
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        min-height: 0;
        overflow: hidden;
    }

    .dialog-content > * {
        width: 100%;
        height: 100%;
        min-height: 0;
    }
}
