.persistent-chat-root {
    --tenant-chat-panel-width: 380px;
    --tenant-chat-active-width: var(--tenant-chat-panel-width);
    --tenant-chat-fab-size: 2.75rem;
    --tenant-chat-layout-gap: 0.25rem;
    --tenant-chat-anchor: 1.25rem;

    position: fixed;
    right: var(--tenant-chat-anchor);
    bottom: var(--tenant-chat-anchor);
    z-index: 40;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-end;
    pointer-events: none;
}

.persistent-chat-root--dock {
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: var(--tenant-chat-active-width);
    padding: 0;
}

body.tenant-chat-fullscreen .persistent-chat-root {
    top: var(--tenant-chat-fullscreen-top, 0);
    left: var(--tenant-chat-fullscreen-left, 0);
    width: var(--tenant-chat-fullscreen-width, 100vw);
    height: var(--tenant-chat-fullscreen-height, 100vh);
    right: auto;
    bottom: auto;
    align-items: stretch;
    justify-content: stretch;
    pointer-events: auto;
}

body:not(.tenant-chat-fullscreen) .fi-main-ctn {
    transition: padding-right 0.25s ease;
}

body.tenant-chat-panel-open:not(.tenant-chat-fullscreen) .fi-main-ctn {
    padding-right: var(
        --tenant-chat-offset-x,
        calc(var(--tenant-chat-active-width) + var(--tenant-chat-layout-gap))
    );
}

body.tenant-chat-fab-visible:not(.tenant-chat-panel-open):not(.tenant-chat-fullscreen) .fi-main-ctn {
    padding-right: var(
        --tenant-chat-offset-x,
        calc(var(--tenant-chat-fab-size) + var(--tenant-chat-anchor) + var(--tenant-chat-layout-gap))
    );
}

.persistent-chat-root > .persistent-chat {
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-end;
    max-width: 100%;
}

.persistent-chat-root--dock > .persistent-chat,
body.tenant-chat-fullscreen .persistent-chat-root > .persistent-chat {
    width: 100%;
    height: 100%;
    align-items: stretch;
    justify-content: stretch;
}

.persistent-chat {
    position: relative;
    z-index: 1;
}

body.tenant-chat-fullscreen .persistent-chat {
    width: 100%;
    height: 100%;
}

.persistent-chat__fab {
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--tenant-chat-fab-size);
    height: var(--tenant-chat-fab-size);
    border-radius: 9999px;
    background: #2563eb;
    color: #fff;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    border: none;
    cursor: pointer;
}

.persistent-chat__fab:hover {
    filter: brightness(1.05);
}

.persistent-chat__fab svg {
    width: 1.375rem;
    height: 1.375rem;
}

.persistent-chat--expanded .persistent-chat__fab,
.persistent-chat--fullscreen .persistent-chat__fab {
    display: none !important;
}

.persistent-chat__panel {
    pointer-events: auto;
    box-sizing: border-box;
    width: var(--tenant-chat-active-width);
    height: min(427px, calc(100vh - 6rem));
    max-width: min(720px, calc(100vw - (var(--tenant-chat-anchor) * 2)));
    max-height: calc(100vh - (var(--tenant-chat-anchor) * 2) - 4rem);
    background: #f0f4f9;
    border: 1px solid #e5e7eb;
    border-radius: 1rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.persistent-chat-root--dock .persistent-chat__panel {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
    border-top: none;
    border-right: none;
    border-bottom: none;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08);
}

.persistent-chat__panel--resizing {
    user-select: none;
}

.persistent-chat__resize-handle--left {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 5;
    width: 0.375rem;
    cursor: ew-resize;
}

.persistent-chat-root--dock .persistent-chat__resize-handle--left {
    width: 0.5rem;
}

body.tenant-chat-resizing {
    user-select: none;
    cursor: ew-resize;
}

body.tenant-chat-resizing * {
    cursor: inherit;
}

.dark .persistent-chat__panel {
    background: #131314;
    border-color: #374151;
}

.persistent-chat__panel[x-cloak] {
    display: none !important;
}

.persistent-chat--fullscreen .persistent-chat__panel {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
    border: none;
    box-shadow: none;
}

.persistent-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem 0.25rem 1.125rem;
    min-height: 1.625rem;
    border-bottom: 1px solid rgba(229, 231, 235, 0.9);
    background: transparent;
    font-weight: 600;
    font-size: 0.75rem;
    line-height: 1.2;
    flex-shrink: 0;
}

.persistent-chat--fullscreen .persistent-chat__header {
    display: none;
}

.persistent-chat__header > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dark .persistent-chat__header {
    border-bottom-color: rgba(55, 65, 81, 0.9);
}

.persistent-chat__header-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.persistent-chat__header-actions button,
.persistent-chat__header-actions a {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1;
    color: #6b7280;
    padding: 0.125rem 0.375rem;
    text-decoration: none;
}

.persistent-chat__header-actions a:hover {
    color: #2563eb;
}

.persistent-chat__body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.persistent-chat:not(.persistent-chat--fullscreen) .persistent-chat__body .gemini-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0 !important;
    max-height: 100%;
    margin: 0;
    overflow: hidden;
}

.persistent-chat:not(.persistent-chat--fullscreen) .persistent-chat__body .gemini-chat__messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.75rem;
    scroll-padding-bottom: 1.5rem;
}

.persistent-chat:not(.persistent-chat--fullscreen) .persistent-chat__body .gemini-chat__messages-inner {
    padding-bottom: 1.5rem;
}

.persistent-chat:not(.persistent-chat--fullscreen) .persistent-chat__body .gemini-chat__empty {
    min-height: 0;
    flex: 1 1 auto;
    justify-content: flex-end;
    padding: 0.75rem 0 0;
}

.persistent-chat:not(.persistent-chat--fullscreen) .persistent-chat__body .gemini-chat__composer-wrap {
    position: sticky;
    bottom: 0;
    margin-top: auto;
    z-index: 3;
    flex-shrink: 0;
    padding: 0.5rem 0.75rem 0.75rem;
    background: #f0f4f9;
    border-top: 1px solid #e5e7eb;
}

.dark .persistent-chat:not(.persistent-chat--fullscreen) .persistent-chat__body .gemini-chat__composer-wrap {
    background: #131314;
    border-top-color: #374151;
}

.persistent-chat--fullscreen .persistent-chat__body .gemini-chat {
    min-height: 100%;
    height: 100%;
    margin: 0;
}

.persistent-chat--fullscreen .persistent-chat__body .gemini-chat__toolbar {
    display: flex;
}

.persistent-chat__body .gemini-chat {
    height: 100%;
    min-height: 0;
}

.persistent-chat:not(.persistent-chat--fullscreen) .persistent-chat__body .gemini-chat__toolbar {
    display: none;
}

.persistent-chat--expanded:not(.persistent-chat--fullscreen) .persistent-chat__body .gemini-chat__toolbar {
    display: flex;
    padding: 0.375rem 0.625rem;
    border-bottom: 1px solid rgba(229, 231, 235, 0.9);
}

.dark .persistent-chat--expanded:not(.persistent-chat--fullscreen) .persistent-chat__body .gemini-chat__toolbar {
    border-bottom-color: rgba(55, 65, 81, 0.9);
}

.persistent-chat__empty {
    padding: 1rem;
    font-size: 0.875rem;
    color: #6b7280;
}

.gemini-chat__tool-notice {
    margin: 0.5rem 0;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.75rem;
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.gemini-chat__tool-notice--error {
    background: #fef2f2;
    color: #991b1b;
    border-color: #fecaca;
}

@media (max-width: 1023px) {
    .persistent-chat-root {
        z-index: 25;
    }

    body.tenant-chat-mobile-immersive .persistent-chat-root--dock,
    body.tenant-chat-mobile-immersive.tenant-chat-fullscreen .persistent-chat-root {
        top: var(--tenant-chat-fullscreen-top, var(--topbar-height, 4rem));
        left: var(--tenant-chat-fullscreen-left, 0);
        width: var(--tenant-chat-fullscreen-width, 100vw);
        height: var(--tenant-chat-fullscreen-height, calc(100dvh - var(--topbar-height, 4rem)));
        right: auto;
        bottom: auto;
        padding: 0;
    }

    body.tenant-chat-mobile-immersive .persistent-chat-root--dock .persistent-chat__resize-handle--left {
        display: none;
    }

    body.tenant-chat-panel-open.tenant-chat-mobile-immersive:not(.tenant-chat-fullscreen) .fi-main-ctn {
        padding-right: 0;
    }

    body.tenant-chat-mobile-immersive .gemini-chat {
        min-height: 100%;
        height: 100%;
    }
}
