.main-content:has(.agent-sidechat-layout) {
    overflow: hidden;
}

/* The fixed topbar creates its own stacking context below the side-chat.
   Lift it only while the profile menu is open so the menu can overlap the
   desktop chat without changing modal or mobile full-screen chat layering. */
@media (min-width: 768px) {
    body.agent-sidechat-open .topbar:has(.profile-dropdown .dropdown-menu.show) {
        z-index: 1051;
    }
}

.main-content:has(.agent-sidechat-layout) > .container-fluid {
    display: flex;
    min-height: 0;
    flex: 1 1 auto;
}

.content-body-container:has(> .agent-sidechat-layout) {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.agent-sidechat-layout {
    width: 100%;
    height: 100%;
    min-height: 0;
    flex-wrap: nowrap;
    overflow: hidden;
}

.agent-sidechat-main {
    height: 100%;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.agent-sidechat {
    position: relative;
    z-index: 1050;
    display: flex;
    width: clamp(320px, 32vw, 380px);
    min-width: 320px;
    max-width: 700px;
    height: 100%;
    min-height: 0;
    flex: 0 0 auto;
    flex-direction: column;
    align-self: stretch;
    overflow: hidden;
    border-left: 1px solid var(--primary-200);
    background: #fff;
    box-shadow: -8px 0 24px rgba(31, 32, 36, .08);
}

.agent-sidechat[hidden] { display: none !important; }

.agent-sidechat-resize-handle {
    position: absolute;
    inset: 0 auto 0 -3px;
    z-index: 20;
    width: 7px;
    cursor: ew-resize;
}

.agent-sidechat-resize-handle:hover,
.agent-sidechat-resize-handle:active {
    background: color-mix(in srgb, var(--primary-300) 55%, transparent);
}

.agent-sidechat-header {
    display: flex;
    min-height: 54px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .55rem .75rem;
    border-bottom: 1px solid var(--primary-200);
    background: var(--primary-50);
}

.agent-sidechat-title {
    color: var(--primary-950);
    font-size: .86rem;
    font-weight: 750;
}

.agent-sidechat-title i { margin-right: .35rem; }

.agent-sidechat-conversation-menu {
    width: min(20rem, calc(100vw - 2rem));
    max-height: min(26rem, 65dvh);
    overflow-y: auto;
}

.agent-sidechat-conversation-menu .dropdown-item {
    font-size: .8rem;
}

.agent-sidechat-body {
    display: grid;
    min-height: 0;
    flex: 1 1 auto;
    grid-template-rows: minmax(0, 1fr) auto;
    overflow: hidden;
}

.agent-sidechat-messages {
    min-width: 0;
    min-height: 0;
    padding: 1rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    overflow-anchor: none;
    scroll-behavior: smooth;
}

.agent-sidechat-welcome {
    display: grid;
    max-width: 28rem;
    margin: 10vh auto 0;
    place-items: center;
    color: #747985;
    text-align: center;
}

.agent-sidechat-welcome h2 {
    margin: .7rem 0 .25rem;
    color: #292b31;
    font-size: 1.1rem;
}

.agent-sidechat-welcome p {
    margin-bottom: .45rem;
    font-size: .86rem;
    line-height: 1.5;
}

.agent-sidechat-welcome small { font-size: .72rem; }

.agent-sidechat-mark {
    display: grid;
    width: 2.75rem;
    height: 2.75rem;
    place-items: center;
    border-radius: .85rem;
    background: var(--primary-100);
    color: var(--primary-800);
}

.agent-sidechat-composer-wrap {
    padding: .55rem .7rem max(.6rem, env(safe-area-inset-bottom));
    border-top: 1px solid #e4e5e9;
    background: #fff;
}

.agent-sidechat .agent-chat-composer {
    gap: .4rem;
    padding: .5rem;
    border-radius: .85rem;
}

.agent-sidechat .agent-chat-composer textarea {
    max-height: min(130px, 25dvh);
    font-size: .875rem;
}

.agent-sidechat .agent-chat-user-bubble { max-width: 88%; }
.agent-sidechat .agent-chat-message { margin-bottom: .9rem; }
.agent-sidechat .agent-chat-response-body { font-size: .9rem; }

.agent-sidechat-context {
    display: inline-flex;
    width: fit-content;
    max-width: 100%;
    align-items: center;
    gap: .3rem;
    margin: 0 .2rem .45rem;
    padding: .22rem .55rem;
    border-radius: 999px;
    background: #f2f3f5;
    color: #737884;
    font-size: .68rem;
}

.agent-sidechat-context.is-pinned {
    background: var(--primary-100);
    color: var(--primary-950);
    font-weight: 650;
}

.agent-sidechat-context button {
    display: inline-grid;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    opacity: .65;
    place-items: center;
}

.agent-sidechat-toggle {
    position: fixed;
    right: 1.5rem;
    bottom: max(1.5rem, env(safe-area-inset-bottom));
    z-index: 1040;
    display: inline-grid;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    box-shadow: 0 3px 12px rgba(50, 42, 18, .23);
    place-items: center;
}

.agent-sidechat-toggle:active { transform: scale(.94); }
body.agent-sidechat-open .agent-sidechat-toggle { display: none; }

body.agent-sidechat-resizing { cursor: ew-resize; user-select: none; }

@media (max-width: 767.98px) {
    .agent-sidechat {
        position: fixed;
        inset: 0;
        z-index: 1100;
        width: 100% !important;
        min-width: 0;
        max-width: none;
        height: 100dvh;
        min-height: 0;
        border-left: 0;
    }

    .agent-sidechat-resize-handle { display: none; }
    .agent-sidechat-header { padding-top: max(.55rem, env(safe-area-inset-top)); }
    .agent-sidechat-welcome { margin-top: 12dvh; }
}
