.chat-shell {
    --keyboard-offset: 0px;
    display: grid;
    gap: 16px;
    min-width: 0;
}

.chat-shell section,
.chat-shell form {
    margin: 0;
}

.chat-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 0 2px;
}

.chat-topbar h1 {
    margin: 0;
}

.chat-identity-pill {
    flex: 0 0 auto;
    padding: 5px 9px;
    color: var(--identity-color);
    background: #0b1017;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-weight: 900;
}

.chat-notice:empty {
    display: none;
}

.chat-notice {
    position: sticky;
    top: 56px;
    z-index: 12;
    padding: 8px 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.chat-notice.is-error {
    color: #e5a1a1;
}

.chat-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 230px;
    align-items: stretch;
    gap: 14px;
    min-width: 0;
}

.chat-workspace.has-rooms {
    grid-template-columns: minmax(280px, 0.72fr) 210px minmax(380px, 1fr);
}

.chat-panel,
.sidebar-card {
    min-width: 0;
    background: linear-gradient(180deg, rgba(20, 26, 35, 0.96), rgba(11, 16, 23, 0.96));
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
}

.chat-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: min(72vh, 700px);
    min-height: 440px;
    padding: 10px;
    min-width: 0;
}

.panel-title,
.sidebar-heading,
.room-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line-soft);
}

.panel-title {
    display: flex;
    justify-content: space-between;
}

.panel-title h2,
.sidebar-heading h3,
.room-panel-header h2 {
    margin: 0;
}

.panel-title small {
    color: var(--muted);
    font-size: 0.76rem;
}

.sidebar-heading h3 {
    font-size: 0.78rem;
    letter-spacing: 0.04em;
}

.message-list {
    min-height: 0;
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 7px 0;
    scrollbar-color: var(--line) transparent;
}

.chat-message {
    --sender-color: var(--accent-strong);
    box-sizing: border-box;
    display: flex;
    align-items: baseline;
    gap: 7px;
    width: 100%;
    min-height: 28px;
    margin: 0;
    padding: 6px 10px;
    border-bottom: 1px solid rgba(196, 212, 228, 0.1);
    border-radius: 0 !important;
    min-width: 0;
}

.message-time {
    flex: 0 0 auto;
    color: var(--muted-2);
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.74rem;
}

.message-time.is-author-online {
    color: var(--ic-online, #35c46a);
    font-weight: 800;
}

.message-copy {
    display: flex;
    align-items: baseline;
    gap: 4px;
    min-width: 0;
}

.message-sender {
    flex: 0 0 auto;
    min-height: 0;
    padding: 0;
    color: var(--sender-color);
    background: transparent;
    border: 0;
    font-size: 0.82rem;
    font-weight: 900;
}

.message-sender:hover {
    color: var(--text-strong);
    background: transparent;
}

.message-separator {
    color: var(--muted-2);
}

.message-text {
    min-width: 0;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.chat-composer {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    box-sizing: border-box;
    height: 40px;
    min-height: 40px;
    margin-top: 8px;
    padding: 0 12px;
    background: #2d2d2d;
    border: 1px solid rgb(63, 63, 63);
    border-radius: 10px;
    box-shadow: none;
    position: sticky;
    bottom: var(--keyboard-offset, 0px);
    z-index: 3;
    transition: border-color 160ms ease;
}

.chat-composer:focus-within {
    border-color: rgb(110, 110, 110);
    box-shadow: none;
}

.chat-composer label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.chat-composer input[name="message"] {
    flex: 1 1 auto;
    margin: 0;
    min-width: 0;
    height: 100%;
    min-height: 0;
    padding: 0 !important;
    color: #fff;
    background: transparent !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    outline: 0 !important;
    font: inherit;
}

.chat-composer input[name="message"]:focus {
    box-shadow: none !important;
}

.chat-composer input[name="message"]::placeholder {
    color: rgba(255, 255, 255, 0.65);
}

.chat-send-button {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 28px;
    min-width: 28px;
    height: 100%;
    min-height: 0;
    padding: 0 !important;
    margin: 0;
    color: var(--muted);
    background: transparent !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    outline: 0 !important;
    cursor: pointer;
    transition: color 160ms ease;
}

.chat-send-button:hover,
.chat-send-button:focus-visible {
    color: var(--text-strong);
    background: transparent !important;
    box-shadow: none !important;
    transform: none;
}

.chat-send-button:disabled {
    cursor: not-allowed;
    opacity: 0.46;
}

.chat-send-icon {
    width: 18px;
    height: 18px;
    fill: transparent;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: fill 160ms ease, stroke 160ms ease;
}

.chat-send-icon path {
    fill: transparent;
    stroke: #9a9a9a;
    transition: fill 160ms ease, stroke 160ms ease;
}

.chat-composer input[name="message"]:focus ~ .chat-send-button .chat-send-icon path,
.chat-composer input[name="message"]:valid ~ .chat-send-button .chat-send-icon path,
.chat-send-button:hover .chat-send-icon path,
.chat-send-button:focus-visible .chat-send-icon path {
    fill: transparent;
    stroke: #fff;
}

.chat-composer small,
.sidebar-heading span,
.empty-copy {
    color: var(--muted);
}

.chat-sidebar {
    display: grid;
    align-content: start;
    gap: 14px;
    min-width: 0;
}

.sidebar-card {
    padding: 10px;
}

.sidebar-heading {
    margin-bottom: 7px;
}

.active-user-list,
.room-directory,
.invitation-list,
.room-members,
.join-request-list {
    display: grid;
    gap: 5px;
}

.active-user,
.room-directory-item,
.invitation-item,
.room-member,
.join-request-item {
    padding: 7px 8px;
    background: #0b1017;
    border: 1px solid var(--line-soft);
    border-left: 3px solid var(--line);
    border-radius: var(--radius);
}

.active-user {
    width: 100%;
    justify-content: start;
    color: var(--user-color);
    font-size: 0.82rem;
    overflow-wrap: anywhere;
    text-align: left;
}

.active-user:hover {
    color: var(--text-strong);
    background: var(--surface-hover);
}

.active-user-static {
    display: flex;
    align-items: center;
    min-height: 28px;
    color: var(--user-color);
    cursor: default;
    opacity: 0.86;
}

.active-user-static:hover {
    color: var(--user-color);
    background: #0b1017;
}

.room-directory-item,
.invitation-item,
.join-request-item {
    display: grid;
    gap: 5px;
}

.room-directory-item small,
.invitation-item small {
    color: var(--muted);
}

.small-action,
.room-leave,
.secondary-action {
    min-height: 28px;
    padding: 4px 7px;
    color: var(--text);
    background: #0b1017;
    border: 1px solid var(--line);
    font-size: 0.76rem;
}

.room-stage {
    grid-column: 3;
    grid-row: 1;
    display: flex;
    gap: 14px;
    min-width: 0;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
}

.room-stage:empty {
    display: none;
}

.room-panel {
    flex: 0 0 100%;
    width: 100%;
    scroll-snap-align: start;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.room-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.room-members-menu {
    position: relative;
}

.room-members-menu summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 0.78rem;
}

.room-members-menu[open] .room-members {
    position: absolute;
    z-index: 5;
    right: 0;
    width: 190px;
    margin-top: 6px;
    padding: 7px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.room-member {
    color: var(--member-color);
    font-size: 0.78rem;
}

.join-request-list {
    max-height: 96px;
    overflow-y: auto;
    padding: 6px 0;
    border-bottom: 1px solid var(--line-soft);
}

.guest-note {
    text-align: center;
}

.user-menu {
    width: min(340px, calc(100% - 20px));
    padding: 14px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.user-menu-note {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.84rem;
}

.user-menu::backdrop {
    background: rgba(0, 0, 0, 0.62);
}

.dialog-close-form,
.invite-form {
    padding: 0;
    background: transparent;
    border: 0;
}

.dialog-close-form {
    display: flex;
    justify-content: end;
}

.dialog-close {
    min-height: 26px;
    padding: 3px 7px;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--line);
    font-size: 0.72rem;
}

.invite-form {
    display: grid;
    gap: 6px;
    margin-top: 9px;
}

.invite-form input {
    margin: 0;
}

.empty-copy {
    margin: 0;
    font-size: 0.78rem;
}

@media (max-width: 1020px) {
    .chat-workspace.has-rooms {
        grid-template-columns: minmax(240px, 0.65fr) minmax(360px, 1fr);
    }

    .chat-workspace.has-rooms .chat-sidebar {
        display: none;
    }

    .room-stage {
        grid-column: 2;
    }
}

@media (max-width: 760px) {
    .chat-topbar {
        align-items: start;
        flex-direction: column;
    }

    .chat-workspace,
    .chat-workspace.has-rooms {
        grid-template-columns: 1fr;
        max-width: 100%;
    }

    .chat-panel {
        height: min(620px, calc(100dvh - 126px - var(--keyboard-offset, 0px)));
        min-height: min(360px, calc(100dvh - 126px - var(--keyboard-offset, 0px)));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .chat-composer {
        margin: 8px 0 max(8px, env(safe-area-inset-bottom));
        padding: 0 12px;
        background: #2d2d2d;
    }

    .chat-composer input,
    .chat-composer button,
    .user-menu input,
    .invite-form input {
        font-size: 16px;
    }

    .chat-workspace.has-rooms .room-stage {
        grid-column: 1;
        grid-row: 1;
    }

    .chat-workspace.has-rooms .global-chat-panel {
        grid-row: 2;
    }

    .chat-sidebar {
        grid-row: 3;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .chat-workspace.has-rooms .chat-sidebar {
        display: grid;
    }

    .room-stage {
        display: grid;
        grid-column: auto;
        gap: 14px;
        overflow-x: visible;
        scroll-snap-type: none;
    }

    .room-panel {
        width: 100%;
    }
}

@media (max-width: 520px) {
    .chat-sidebar {
        grid-template-columns: 1fr;
    }

    .chat-message {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        gap: 4px;
        font-size: 0.84rem;
    }

    .chat-send-button {
        width: 28px;
        min-width: 28px;
    }
}

@media (max-width: 360px) {
    .chat-panel {
        min-height: 330px;
    }

    .chat-send-button {
        width: 28px;
        min-width: 28px;
    }
}

/* Mobile chat switcher */
.mobile-chat-switcher {
    display: none;
}

.mobile-chat-drawer[hidden] {
    display: none !important;
}

@media (max-width: 760px) {
    .mobile-chat-switcher {
        position: sticky;
        top: 62px;
        z-index: 24;
        display: grid;
        gap: 8px;
        min-width: 0;
    }

    .mobile-chat-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        width: 100%;
        min-height: 48px;
        padding: 8px 10px;
        color: var(--text);
        background:
            linear-gradient(180deg, rgba(24, 32, 44, 0.95), rgba(8, 12, 18, 0.96)),
            rgba(8, 12, 18, 0.92);
        border: 1px solid rgba(196, 212, 228, 0.15);
        border-radius: 16px;
        box-shadow: 0 12px 28px rgba(0, 0, 0, 0.32), 0 1px 0 rgba(255, 255, 255, 0.035) inset;
        text-align: left;
    }

    .mobile-chat-toggle span:first-child {
        display: grid;
        gap: 2px;
        min-width: 0;
    }

    .mobile-chat-toggle small,
    .mobile-chat-section h2,
    .mobile-chat-target small,
    .mobile-chat-room-option small,
    .mobile-chat-invite small {
        color: var(--muted);
    }

    .mobile-chat-toggle small {
        font-size: 0.72rem;
        font-weight: 850;
        letter-spacing: 0.06em;
        text-transform: uppercase;
    }

    .mobile-chat-toggle strong {
        overflow: hidden;
        color: var(--text-strong);
        font-size: 1rem;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-chat-badge {
        display: inline-grid;
        place-items: center;
        min-width: 26px;
        height: 26px;
        padding: 0 7px;
        color: #071018;
        background: var(--accent-strong);
        border-radius: 999px;
        font-size: 0.78rem;
        font-weight: 950;
    }

    .mobile-chat-drawer {
        display: grid;
        gap: 10px;
        max-height: min(68dvh, 520px);
        overflow-y: auto;
        padding: 12px;
        background:
            linear-gradient(180deg, rgba(20, 28, 40, 0.96), rgba(6, 9, 14, 0.98)),
            rgba(6, 9, 14, 0.94);
        border: 1px solid rgba(196, 212, 228, 0.14);
        border-radius: 18px;
        box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(18px);
    }

    .mobile-chat-section {
        display: grid;
        gap: 7px;
        min-width: 0;
    }

    .mobile-chat-section + .mobile-chat-section {
        padding-top: 10px;
        border-top: 1px solid var(--line-soft);
    }

    .mobile-chat-section h2 {
        margin: 0;
        font-size: 0.76rem;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .mobile-chat-list {
        display: grid;
        gap: 7px;
        min-width: 0;
    }

    .mobile-chat-target,
    .mobile-chat-room-option,
    .mobile-chat-invite {
        display: grid;
        gap: 4px;
        min-width: 0;
        padding: 9px 10px;
        color: var(--text);
        background: rgba(8, 13, 19, 0.62);
        border: 1px solid var(--line-soft);
        border-radius: 14px;
        text-align: left;
    }

    .mobile-chat-target {
        width: 100%;
    }

    .mobile-chat-target:hover,
    .mobile-chat-target:focus-visible,
    .mobile-chat-target.is-active {
        color: var(--text-strong);
        background: rgba(152, 164, 179, 0.12);
        border-color: rgba(196, 212, 228, 0.24);
    }

    .mobile-chat-target strong,
    .mobile-chat-room-option strong,
    .mobile-chat-invite strong {
        overflow-wrap: anywhere;
    }

    .mobile-chat-target small,
    .mobile-chat-room-option small,
    .mobile-chat-invite small {
        display: block;
        margin-top: 2px;
        font-size: 0.78rem;
    }

    .mobile-chat-room-option {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
    }

    .mobile-chat-invite {
        grid-template-columns: minmax(0, 1fr);
    }

    .mobile-chat-invite-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    .mobile-chat-drawer .small-action {
        min-height: 34px;
        padding: 6px 9px;
        border-radius: 999px;
        font-size: 0.82rem;
    }

    .chat-workspace.has-rooms .global-chat-panel {
        grid-row: 1;
    }

    .chat-workspace.has-rooms .room-stage {
        grid-row: 2;
    }

    .chat-sidebar,
    .chat-workspace.has-rooms .chat-sidebar {
        display: none;
    }

    .room-panel {
        scroll-margin-top: 128px;
    }

    .global-chat-panel {
        scroll-margin-top: 128px;
    }
}

@media (max-width: 420px) {
    .mobile-chat-room-option {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .mobile-chat-room-option .small-action {
        width: 100%;
    }
}

/* Mobile app-style chat shell */
@media (max-width: 760px) {
    body.chat-page {
        height: 100dvh;
        overflow: hidden;
    }

    body.chat-page .site-nav {
        flex: 0 0 auto;
    }

    body.chat-page .site-main {
        flex: 1 1 auto;
        display: flex;
        width: 100%;
        min-height: 0;
        margin: 0;
        overflow: hidden;
    }

    body.chat-page footer {
        display: none;
    }

    .chat-shell {
        position: relative;
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        gap: 0;
        width: 100%;
        height: 100%;
        min-height: 0;
        overflow: hidden;
        background: linear-gradient(180deg, rgba(10, 15, 22, 0.98), rgba(5, 8, 12, 0.98));
    }

    .chat-topbar {
        display: none;
    }

    .chat-notice {
        position: absolute;
        top: 58px;
        right: 10px;
        left: 10px;
        z-index: 45;
        border-radius: 12px;
        box-shadow: 0 14px 36px rgba(0, 0, 0, 0.34);
    }

    .mobile-chat-switcher {
        position: relative;
        top: auto;
        z-index: 40;
        flex: 0 0 auto;
        display: block;
        min-width: 0;
        padding: 8px 10px;
        background: rgba(6, 10, 15, 0.96);
        border-bottom: 1px solid var(--line-soft);
    }

    .mobile-chat-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        width: 100%;
        min-height: 42px;
        padding: 8px 10px;
        color: var(--text-strong);
        background: rgba(152, 164, 179, 0.07);
        border: 1px solid rgba(196, 212, 228, 0.14);
        border-radius: 12px;
        box-shadow: none;
        text-align: left;
    }

    .mobile-chat-toggle:hover,
    .mobile-chat-toggle:focus-visible {
        color: var(--text-strong);
        background: rgba(152, 164, 179, 0.1);
        border-color: rgba(196, 212, 228, 0.24);
    }

    .mobile-chat-current {
        min-width: 0;
        overflow: hidden;
        font-size: 0.98rem;
        font-weight: 950;
        line-height: 1.2;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-chat-meta {
        display: inline-flex;
        flex: 0 0 auto;
        align-items: center;
        gap: 8px;
    }

    .mobile-chat-badge {
        display: inline-grid;
        place-items: center;
        min-width: 24px;
        height: 24px;
        padding: 0 7px;
        color: #180606;
        background: var(--danger);
        border: 1px solid rgba(255, 190, 190, 0.28);
        border-radius: 999px;
        font-size: 0.76rem;
        font-weight: 950;
        line-height: 1;
    }

    .mobile-chat-chevron {
        position: relative;
        width: 18px;
        height: 18px;
        color: var(--muted);
        transition: transform 160ms ease, color 160ms ease;
    }

    .mobile-chat-chevron::before {
        content: "";
        position: absolute;
        left: 50%;
        top: 43%;
        width: 8px;
        height: 8px;
        border-right: 2px solid currentColor;
        border-bottom: 2px solid currentColor;
        transform: translate(-50%, -50%) rotate(45deg);
    }

    .mobile-chat-switcher.is-open .mobile-chat-chevron {
        color: var(--text-strong);
        transform: rotate(180deg);
    }

    .mobile-chat-drawer {
        position: absolute;
        top: calc(100% + 6px);
        right: 10px;
        left: 10px;
        z-index: 50;
        display: grid;
        gap: 10px;
        max-height: min(72dvh, calc(100dvh - 72px));
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 12px;
        background: rgba(11, 16, 23, 0.98);
        border: 1px solid rgba(196, 212, 228, 0.16);
        border-radius: 16px;
        box-shadow: 0 22px 60px rgba(0, 0, 0, 0.54);
        backdrop-filter: blur(18px);
    }

    .mobile-chat-drawer-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        min-width: 0;
    }

    .mobile-chat-drawer-head h2,
    .mobile-chat-section h2 {
        margin: 0;
        color: var(--muted);
        font-size: 0.76rem;
        font-weight: 900;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .mobile-chat-close {
        min-height: 30px;
        padding: 5px 9px;
        color: var(--muted);
        background: transparent;
        border: 1px solid var(--line-soft);
        border-radius: 999px;
        font-size: 0.78rem;
    }

    .mobile-chat-section {
        display: grid;
        gap: 7px;
        min-width: 0;
    }

    .mobile-chat-section + .mobile-chat-section {
        padding-top: 9px;
        border-top: 1px solid var(--line-soft);
    }

    .mobile-chat-list {
        display: grid;
        gap: 7px;
        min-width: 0;
    }

    .mobile-chat-target,
    .mobile-chat-room-option,
    .mobile-chat-invite {
        min-width: 0;
        color: var(--text);
        background: rgba(6, 10, 15, 0.72);
        border: 1px solid var(--line-soft);
        border-radius: 12px;
    }

    .mobile-chat-target {
        display: grid;
        width: 100%;
        padding: 9px 10px;
        text-align: left;
    }

    .mobile-chat-target.is-active,
    .mobile-chat-room-option.is-active {
        color: var(--text-strong);
        background: rgba(152, 164, 179, 0.12);
        border-color: rgba(196, 212, 228, 0.28);
    }

    .mobile-chat-target strong,
    .mobile-chat-room-option strong,
    .mobile-chat-invite strong {
        display: block;
        overflow-wrap: anywhere;
    }

    .mobile-chat-target small,
    .mobile-chat-room-option small,
    .mobile-chat-invite small {
        display: block;
        margin-top: 2px;
        color: var(--muted);
        font-size: 0.78rem;
    }

    .mobile-chat-room-option {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
        padding: 8px;
    }

    .mobile-chat-open-room {
        padding: 0;
    }

    .mobile-chat-open-room .mobile-chat-target {
        background: transparent;
        border: 0;
        border-radius: 12px 0 0 12px;
    }

    .mobile-chat-invite {
        display: grid;
        gap: 8px;
        padding: 9px 10px;
    }

    .mobile-chat-invite-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 7px;
    }

    .mobile-chat-drawer .small-action,
    .mobile-chat-login {
        min-height: 34px;
        padding: 6px 10px;
        color: var(--text-strong);
        background: rgba(152, 164, 179, 0.08);
        border: 1px solid var(--line-soft);
        border-radius: 999px;
        font-size: 0.82rem;
    }

    .chat-workspace,
    .chat-workspace.has-rooms {
        position: relative;
        flex: 1 1 auto;
        display: block;
        min-width: 0;
        min-height: 0;
        overflow: hidden;
    }

    .chat-sidebar,
    .chat-workspace.has-rooms .chat-sidebar {
        display: none !important;
    }

    .room-stage {
        display: contents;
    }

    .chat-panel,
    .room-panel {
        display: none;
        width: 100%;
        height: 100%;
        min-height: 0;
        padding: 0;
        overflow: hidden;
        background: transparent;
        border: 0;
        border-radius: 0;
    }

    .chat-panel.is-mobile-active,
    .room-panel.is-mobile-active {
        display: grid;
        grid-template-rows: minmax(0, 1fr) auto;
    }

    .room-panel.is-mobile-active {
        grid-template-rows: minmax(0, 1fr) auto;
    }

    .panel-title,
    .room-panel-header {
        display: none;
    }

    .join-request-list {
        z-index: 2;
        grid-row: 1;
        align-self: start;
        max-height: 92px;
        margin: 0 10px;
        padding: 8px 0;
        overflow-y: auto;
    }

    .message-list {
        min-width: 0;
        min-height: 0;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 10px 0 6px;
        scrollbar-gutter: stable;
    }

    .room-panel .message-list {
        grid-row: 1;
    }

    .room-panel .chat-composer {
        grid-row: 2;
    }

    .chat-message {
        display: block;
        min-width: 0;
        min-height: 0;
        padding: 7px 10px;
        border-bottom: 1px solid rgba(196, 212, 228, 0.1);
        font-size: 0.9rem;
        line-height: 1.42;
        overflow-wrap: anywhere;
    }

    .message-time {
        display: inline;
        margin-right: 4px;
        font-size: 0.72rem;
    }

    .message-copy {
        display: inline;
        min-width: 0;
    }

    .message-sender {
        display: inline;
        max-width: 100%;
        overflow-wrap: anywhere;
        font-size: 0.84rem;
        vertical-align: baseline;
    }

    .message-separator {
        display: inline;
        margin-right: 3px;
    }

    .message-text {
        display: inline;
        overflow-wrap: anywhere;
        word-break: normal;
    }

    .chat-composer {
        position: static;
        z-index: auto;
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        gap: 10px;
        height: 40px;
        min-height: 40px;
        margin: 8px 10px max(8px, env(safe-area-inset-bottom));
        padding: 0 12px;
        background: #2d2d2d;
        border: 1px solid rgb(63, 63, 63);
        border-radius: 10px;
        box-shadow: none;
        transform: translateZ(0);
    }

    .chat-composer input[name="message"] {
        min-width: 0;
        height: 100%;
        min-height: 0;
        margin: 0;
        padding: 0 !important;
        color: #fff;
        background: transparent !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        font-size: 16px;
        line-height: 1.25;
    }

    .chat-send-button {
        flex: 0 0 auto;
        width: 28px;
        min-width: 28px;
        height: 100%;
        min-height: 0;
    }

    .chat-composer small {
        min-height: 1em;
        color: var(--muted-2);
        font-size: 0.72rem;
        line-height: 1.2;
    }

    .user-menu input,
    .invite-form input {
        font-size: 16px;
    }
}

@media (max-width: 420px) {
    .mobile-chat-room-option,
    .mobile-chat-open-room {
        grid-template-columns: 1fr;
    }

    .mobile-chat-open-room .mobile-chat-target {
        border-radius: 12px 12px 0 0;
    }
}

/* Focused mobile chat containment and compact composer state */
.chat-composer .sr-only {
    min-height: 0;
}

@media (max-width: 760px) {
    body.chat-page {
        position: fixed;
        inset: 0;
        width: 100%;
        min-height: 0;
        overscroll-behavior: none;
    }

    body.chat-page .site-main {
        height: auto;
    }

    .chat-shell {
        max-height: 100%;
        overscroll-behavior: none;
    }

    .chat-workspace,
    .chat-workspace.has-rooms,
    .chat-panel,
    .room-panel {
        max-width: 100%;
        overflow-x: hidden;
    }

    .message-list {
        flex: 1 1 auto;
        -webkit-overflow-scrolling: touch;
    }

    .chat-composer {
        gap: 10px;
        padding: 0 12px;
    }

    .chat-composer .sr-only {
        position: absolute;
        min-height: 0;
    }

    .chat-composer input[name="message"]:disabled {
        opacity: 1;
        color: var(--muted);
        -webkit-text-fill-color: var(--muted);
    }

    .room-stage {
        position: absolute;
        inset: 0;
        display: block;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    .room-stage:not(.is-mobile-active-stage) {
        display: none !important;
    }

    .chat-panel,
    .room-panel {
        position: absolute;
        inset: 0;
        max-width: 100%;
    }

    .chat-panel:not(.is-mobile-active),
    .room-panel:not(.is-mobile-active) {
        display: none !important;
    }

    .chat-panel.is-mobile-active,
    .room-panel.is-mobile-active {
        display: grid !important;
    }

    .room-panel .join-request-list {
        display: none !important;
    }

    .mobile-chat-request {
        background: rgba(8, 13, 19, 0.62);
    }

    .mobile-chat-request .small-action,
    .mobile-chat-invite .small-action {
        min-height: 32px;
        padding: 5px 10px;
        border-radius: 10px;
    }
}

@media (max-width: 760px) {
    .mobile-chat-drawer {
        gap: 8px;
        padding: 10px;
        border-color: rgba(196, 212, 228, 0.14);
        border-radius: 14px;
    }

    .mobile-chat-section {
        gap: 5px;
    }

    .mobile-chat-section + .mobile-chat-section {
        padding-top: 8px;
    }

    .mobile-chat-list {
        gap: 0;
    }

    .mobile-chat-target,
    .mobile-chat-room-row,
    .mobile-online-user,
    .mobile-chat-invite {
        min-width: 0;
        color: var(--text);
        background: transparent;
        border: 0;
        border-bottom: 1px solid rgba(196, 212, 228, 0.1);
        border-radius: 0;
    }

    .mobile-chat-target {
        min-height: 44px;
        padding: 8px 2px;
    }

    .mobile-chat-target.is-active,
    .mobile-chat-room-row.is-active {
        color: var(--text-strong);
        background: rgba(152, 164, 179, 0.1);
        border: 1px solid rgba(196, 212, 228, 0.2);
        border-radius: 12px;
    }

    .mobile-chat-target.is-active {
        padding-inline: 8px;
    }

    .mobile-chat-room-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
        min-height: 48px;
        padding: 8px 2px;
    }

    .mobile-chat-room-row.is-active {
        padding-inline: 8px;
        margin-block: 2px;
    }

    .mobile-chat-room-copy,
    .mobile-online-copy,
    .mobile-chat-invite > span {
        display: grid;
        gap: 2px;
        min-width: 0;
    }

    .mobile-chat-room-copy strong,
    .mobile-online-copy strong,
    .mobile-chat-invite strong {
        overflow-wrap: anywhere;
        color: var(--text-strong);
        font-size: 0.92rem;
        line-height: 1.18;
    }

    .mobile-chat-room-copy small,
    .mobile-online-copy small,
    .mobile-chat-invite small {
        margin: 0;
        color: var(--muted);
        font-size: 0.75rem;
        line-height: 1.2;
    }

    .mobile-chat-room-actions,
    .mobile-chat-invite-actions {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 6px;
        min-width: 0;
    }

    .mobile-online-user {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        align-items: center;
        gap: 8px;
        width: 100%;
        font: inherit;
        min-height: 44px;
        padding: 7px 2px;
        cursor: pointer;
        text-align: left;
    }

    .mobile-online-user:hover,
    .mobile-online-user:focus-visible {
        color: var(--text-strong);
        background: rgba(152, 164, 179, 0.07);
    }

    .mobile-online-avatar {
        display: inline-grid;
        place-items: center;
        width: 28px;
        height: 28px;
        color: #071018;
        background: var(--user-color, var(--accent));
        border: 1px solid rgba(255, 255, 255, 0.16);
        border-radius: 50%;
        font-size: 0.76rem;
        font-weight: 900;
    }

    img.mobile-online-avatar {
        object-fit: cover;
        padding: 0;
        color: transparent;
        background: #0b1017;
    }

    .mobile-chat-invite {
        display: grid;
        gap: 7px;
        padding: 8px 2px;
    }

    .mobile-chat-invite-actions {
        justify-content: start;
        flex-wrap: wrap;
    }

    .mobile-chat-drawer .small-action,
    .mobile-chat-login {
        width: auto;
        min-width: 0;
        min-height: 30px;
        padding: 5px 9px;
        border-radius: 999px;
        font-size: 0.78rem;
        line-height: 1.1;
        white-space: nowrap;
    }

    .mobile-chat-drawer .small-action.is-primary-subtle,
    .mobile-online-invite {
        color: var(--text-strong);
        background: rgba(152, 164, 179, 0.1);
        border-color: rgba(196, 212, 228, 0.2);
    }

    .mobile-chat-drawer .small-action.is-danger-subtle {
        color: #f3b8b8;
        background: rgba(239, 68, 68, 0.08);
        border-color: rgba(239, 68, 68, 0.24);
    }
}

@media (max-width: 380px) {
    .mobile-chat-room-row {
        align-items: start;
    }

    .mobile-chat-room-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
    }
}

/* Desktop chat tabs and unified sidebar */
.chat-main-stack,
.chat-tabs {
    min-width: 0;
}

.chat-tabs {
    display: none;
}

@media (min-width: 761px) {
    .chat-workspace,
    .chat-workspace.has-rooms {
        grid-template-columns: minmax(0, 1fr) minmax(280px, 320px);
        align-items: stretch;
        gap: 14px;
    }

    .chat-main-stack,
    .chat-sidebar-panel {
        min-height: 440px;
        height: min(72vh, 700px);
    }

    .chat-main-stack {
        display: grid;
        grid-template-rows: auto minmax(0, 1fr);
        min-width: 0;
        padding: 10px;
        overflow: hidden;
        background: linear-gradient(180deg, rgba(20, 26, 35, 0.96), rgba(11, 16, 23, 0.96));
        border: 1px solid var(--line);
        border-radius: var(--radius-lg);
    }

    .chat-tabs {
        display: flex;
        gap: 6px;
        min-width: 0;
        overflow-x: auto;
        padding: 0 0 8px;
        border-bottom: 1px solid var(--line-soft);
        scrollbar-width: thin;
    }

    .chat-tab {
        flex: 0 0 auto;
        max-width: 190px;
        min-height: 32px;
        padding: 6px 10px;
        overflow: hidden;
        color: var(--muted);
        background: transparent;
        border: 1px solid transparent;
        border-radius: 999px;
        font-size: 0.84rem;
        font-weight: 850;
        line-height: 1.15;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .chat-tab:hover,
    .chat-tab:focus-visible,
    .chat-tab.is-active {
        color: var(--text-strong);
        background: var(--ic-accent-soft, rgba(152, 164, 179, 0.1));
        border-color: rgba(196, 212, 228, 0.26);
    }

    .chat-main-stack > .chat-panel,
    .chat-main-stack > .room-stage {
        grid-column: 1;
        grid-row: 2;
        min-height: 0;
    }

    .chat-main-stack .chat-panel,
    .chat-main-stack .room-panel {
        display: none;
        width: 100%;
        height: 100%;
        min-height: 0;
        padding: 9px 0 0;
        overflow: hidden;
        background: transparent;
        border: 0;
        border-radius: 0;
    }

    .chat-main-stack .chat-panel.is-active-chat,
    .chat-main-stack .room-panel.is-active-chat {
        display: grid;
        grid-template-rows: auto minmax(0, 1fr) auto;
    }

    .chat-main-stack .room-stage {
        display: block;
        min-width: 0;
        overflow: hidden;
        scroll-snap-type: none;
    }

    .chat-main-stack .room-stage:not(.is-active-stage) {
        display: none;
    }

    .chat-main-stack .room-panel {
        flex: none;
        scroll-snap-align: unset;
    }

    .room-panel .join-request-list {
        display: none;
    }

    .chat-sidebar-panel,
    .chat-workspace.has-rooms .chat-sidebar-panel {
        display: flex;
        flex-direction: column;
        align-content: stretch;
        gap: 0;
        min-width: 0;
        overflow: hidden;
        background: linear-gradient(180deg, rgba(20, 26, 35, 0.96), rgba(11, 16, 23, 0.96));
        border: 1px solid var(--line);
        border-radius: var(--radius-lg);
    }

    .chat-sidebar-section {
        position: relative;
        display: flex;
        flex-direction: column;
        gap: 8px;
        min-height: 0;
        padding: 12px;
    }

    .chat-sidebar-section + .chat-sidebar-section {
        padding-top: 14px;
        border-top: 0;
    }

    .chat-sidebar-section + .chat-sidebar-section::before {
        content: "";
        position: absolute;
        top: 0;
        right: 12px;
        left: 12px;
        height: 1px;
        background: rgba(196, 212, 228, 0.1);
    }

    .chat-sidebar-panel .sidebar-heading {
        margin-bottom: 0;
        padding-bottom: 0;
        border-bottom: 0;
    }

    .chat-sidebar-panel .sidebar-heading h3 {
        color: var(--muted);
        font-size: 0.72rem;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .chat-online-section {
        flex: 1 1 50%;
    }

    .chat-rooms-section {
        flex: 0 1 30%;
    }

    .chat-invitations-section {
        flex: 0 1 24%;
    }

    .active-user-list,
    .room-directory,
    .invitation-list {
        display: grid;
        align-content: start;
        gap: 3px;
        min-height: 0;
        overflow-y: auto;
        scrollbar-width: thin;
    }

    .active-user-list {
        flex: 1 1 auto;
    }

    .active-user-row,
    .chat-room-row,
    .invitation-item {
        min-width: 0;
        padding: 7px 8px;
        background: transparent;
        border: 0;
        border-radius: 10px;
    }

    .active-user-row {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        align-items: center;
        gap: 8px;
        width: 100%;
        font: inherit;
        color: var(--text);
        background: transparent;
        cursor: pointer;
        text-align: left;
    }

    .active-user-row:hover,
    .active-user-row:focus-visible {
        color: var(--text-strong);
        background: rgba(152, 164, 179, 0.07);
        border-radius: 10px;
    }

    .active-user-avatar {
        display: inline-grid;
        place-items: center;
        flex: 0 0 auto;
        width: 28px;
        height: 28px;
        color: #071018;
        background: var(--user-color, var(--accent));
        border: 1px solid rgba(255, 255, 255, 0.16);
        border-radius: 50%;
        font-size: 0.76rem;
        font-weight: 900;
    }

    img.active-user-avatar {
        object-fit: cover;
        padding: 0;
        color: transparent;
        background: #0b1017;
    }

    .active-user-copy,
    .chat-room-copy,
    .invitation-copy {
        display: grid;
        gap: 2px;
        min-width: 0;
    }

    .active-user-copy strong,
    .chat-room-copy strong,
    .invitation-copy strong {
        overflow: hidden;
        color: var(--text-strong);
        font-size: 0.88rem;
        line-height: 1.18;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .active-user-copy small,
    .chat-room-copy small,
    .invitation-copy small {
        color: var(--muted);
        font-size: 0.74rem;
        line-height: 1.2;
    }

    .chat-room-row,
    .invitation-item {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
    }

    .chat-room-row.is-active {
        margin-block: 2px;
        padding: 7px 8px;
        background: var(--ic-accent-soft, rgba(152, 164, 179, 0.1));
        border: 1px solid rgba(196, 212, 228, 0.18);
        border-radius: 12px;
    }

    .chat-room-actions,
    .invitation-actions {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 5px;
    }

    .chat-sidebar-panel .small-action {
        width: auto;
        min-width: 0;
        min-height: 28px;
        padding: 4px 8px;
        border-radius: 999px;
        font-size: 0.76rem;
        line-height: 1.1;
        white-space: nowrap;
    }

    .chat-sidebar-panel .small-action.is-primary-subtle,
    .active-user-invite {
        color: var(--text-strong);
        background: rgba(152, 164, 179, 0.1);
        border-color: rgba(196, 212, 228, 0.2);
    }

    .chat-sidebar-panel .small-action.is-danger-subtle {
        color: #f3b8b8;
        background: rgba(239, 68, 68, 0.08);
        border-color: rgba(239, 68, 68, 0.24);
    }
}

@media (max-width: 760px) {
    .chat-main-stack {
        position: relative;
        width: 100%;
        height: 100%;
        min-width: 0;
        min-height: 0;
        overflow: hidden;
    }
}

@media (max-width: 760px) {
    .mobile-online-section {
        gap: 6px;
    }

    .mobile-chat-section-toggle {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        width: 100%;
        min-height: 38px;
        overflow: hidden;
        padding: 8px 10px;
        color: var(--muted);
        background: rgba(6, 10, 15, 0.72);
        border: 1px solid rgba(196, 212, 228, 0.14);
        border-radius: 12px;
        box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.015);
        font: inherit;
        font-size: 0.88rem;
        font-weight: 850;
        letter-spacing: 0;
        text-align: left;
        text-transform: none;
    }

    .mobile-chat-section-toggle::before {
        content: "";
        position: absolute;
        inset: 8px auto 8px 0;
        width: 3px;
        background: rgba(225, 139, 139, 0.72);
        border-radius: 0 999px 999px 0;
    }

    .mobile-chat-section-toggle > span:first-child {
        display: inline-flex;
        align-items: baseline;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-chat-section-toggle [data-mobile-online-count] {
        flex: 0 0 auto;
        margin-left: 2px;
        color: var(--danger);
        font-size: 0.82em;
        font-weight: 900;
    }

    .mobile-chat-section-toggle:hover,
    .mobile-chat-section-toggle:focus-visible,
    .mobile-chat-section-toggle[aria-expanded="true"] {
        color: var(--text-strong);
        background: rgba(225, 139, 139, 0.08);
        border-color: rgba(225, 139, 139, 0.28);
    }

    body.chat-page .mobile-online-section .mobile-chat-section-toggle {
        border-color: rgba(196, 212, 228, 0.14);
    }

    body.chat-page .mobile-online-section .mobile-chat-section-toggle:hover,
    body.chat-page .mobile-online-section .mobile-chat-section-toggle:focus-visible,
    body.chat-page .mobile-online-section .mobile-chat-section-toggle[aria-expanded="true"] {
        border-color: rgba(225, 139, 139, 0.28);
    }

    .mobile-chat-section-chevron {
        position: relative;
        flex: 0 0 auto;
        width: 18px;
        height: 18px;
        color: currentColor;
        transition: transform 160ms ease;
    }

    .mobile-chat-section-chevron::before {
        content: "";
        position: absolute;
        left: 50%;
        top: 43%;
        width: 8px;
        height: 8px;
        border-right: 2px solid currentColor;
        border-bottom: 2px solid currentColor;
        transform: translate(-50%, -60%) rotate(45deg);
    }

    .mobile-chat-section-toggle[aria-expanded="true"] .mobile-chat-section-chevron {
        transform: rotate(180deg);
    }

    .mobile-online-list[hidden] {
        display: none !important;
    }

    body.chat-page .mobile-online-list {
        gap: 2px;
        padding-top: 2px;
    }

    body.chat-page .mobile-online-list .mobile-online-user {
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 8px;
        min-height: 40px;
        padding: 6px 8px;
        color: var(--text);
        background: transparent;
        border: 1px solid transparent;
        border-bottom-color: rgba(196, 212, 228, 0.09);
        border-radius: 10px;
    }

    body.chat-page .mobile-online-list .mobile-online-user::after {
        content: "";
        width: 7px;
        height: 7px;
        background: var(--ic-online, #35c46a);
        border-radius: 999px;
        box-shadow: 0 0 0 2px rgba(53, 196, 106, 0.12);
    }

    body.chat-page .mobile-online-list .mobile-online-user:hover,
    body.chat-page .mobile-online-list .mobile-online-user:focus-visible {
        color: var(--text-strong);
        background: rgba(152, 164, 179, 0.06);
        border-color: rgba(196, 212, 228, 0.14);
    }

    body.chat-page .mobile-online-list .mobile-online-user.is-current-user {
        color: var(--text-strong);
        background: linear-gradient(90deg, rgba(225, 139, 139, 0.11), rgba(152, 164, 179, 0.04));
        border-color: rgba(225, 139, 139, 0.24);
        border-radius: 10px;
        box-shadow: inset 2px 0 0 rgba(225, 139, 139, 0.58);
    }

    body.chat-page .mobile-online-list .mobile-online-avatar {
        width: 26px;
        height: 26px;
        border-color: rgba(255, 255, 255, 0.18);
        box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.035);
        font-size: 0.72rem;
    }

    body.chat-page .mobile-online-list img.mobile-online-avatar {
        object-fit: cover;
    }

    body.chat-page .mobile-online-list .mobile-online-copy {
        gap: 1px;
    }

    body.chat-page .mobile-online-list .mobile-online-copy strong {
        overflow: hidden;
        color: var(--text-strong);
        font-size: 0.88rem;
        line-height: 1.18;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body.chat-page .mobile-online-list .mobile-online-copy small {
        color: var(--muted);
        font-size: 0.72rem;
        line-height: 1.15;
    }

    body.chat-page .mobile-online-list .mobile-online-user.is-current-user .mobile-online-copy small {
        justify-self: start;
        padding: 1px 6px;
        color: #f3b8b8;
        background: rgba(225, 139, 139, 0.1);
        border: 1px solid rgba(225, 139, 139, 0.22);
        border-radius: 999px;
        font-size: 0.68rem;
        font-weight: 850;
    }
}

@media (max-width: 760px) {
    body.chat-page .chat-composer {
        height: 44px;
        min-height: 44px;
        margin: 8px 10px max(10px, calc(env(safe-area-inset-bottom, 0px) + 2px));
        padding: 0 12px;
    }

    body.chat-page .chat-composer input[name="message"],
    body.chat-page .chat-composer textarea {
        font-size: 16px;
        line-height: 1.3;
    }
}
