body.chat-open {
}

body.chat-open.mobile {
    overflow: hidden;
    touch-action: none;
}

.chat-floating-button {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;

    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;

    background: var(--bt-primary);
    color: #fff;

    display: flex;
    align-items: center;
    justify-content: center;

    font-size: 1.375rem;
    cursor: pointer;

    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.25);
    transition: background 0.2s ease, transform 0.2s ease;
    z-index: 10000;
}

.chat-floating-button:hover {
    transform: scale(1.05);
}

.chat-floating-button.pending {
    background: var(--bt-warning);
}

.chat-floating-button.active {
    background: var(--bt-accent);
}

.chat-overlay {
    position: fixed;
    bottom: 6rem;
    right: 1.5rem;

    width: 21.25rem;
    height: 28.75rem;

    background: var(--bg-surface);
    color: var(--bt-text);

    border-radius: 0.75rem;
    border: 1px solid var(--border-faint);
    box-shadow: 0 0 0.2rem 0rem #4da3ff;

    display: flex;
    flex-direction: column;

    overflow: hidden;
    z-index: 10000;

    opacity: 0;
    transform: translateY(20px) scale(0.98);
    pointer-events: none;

    transition:
        opacity 0.25s ease,
        transform 0.25s ease;

    will-change: transform, opacity;
}

.chat-overlay.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.chat-overlay.hidden {
    display: none;
}

.chat-header {
    background: var(--border-faint);
    color: var(--text-main);

    padding: 0.75rem 1rem;

    display: flex;
    align-items: center;
    justify-content: space-between;

    font-size: 0.875rem;
    font-weight: 600;
}

.chat-header button {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.125rem;
    cursor: pointer;
}

.chat-body {
    flex: 1;
    padding: 0.75rem;

    background: var(--bg-surface);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overscroll-behavior: contain;
}

.chat-message {
    max-width: 80%;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    line-height: 1.4;
    word-break: break-all;
}

.chat-message.mine {
    align-self: flex-end;
}

.chat-message.theirs {
  align-self: flex-start;
}

.chat-message.system {
    align-self: center;
    background: transparent;
    color: var(--bg-system);
    font-size: 0.75rem;
}

.chat-message.user {
    background: var(--bg-user);
    color: #fff;
}

.chat-message.guest {
    background: var(--bg-guest);
    color: #fff;
}

.chat-message.tech {
    background: var(--bg-tech);
    border: 1px solid var(--bt-border);
}

.chat-input {
    display: flex;
    gap: 0.5rem;

    padding: 0.75rem;

    background: var(--border-faint);
}

.chat-input input {
    flex: 1;
    padding: 0.5rem 0.625rem;
    border-radius: 0.375rem;
    border: 1px solid var(--border-faint);
    font-size: 0.8125rem;
    background: var(--bg-slate);
    color: var(--text-main);
}

.chat-input input:focus {
    outline: none;
    border-color: var(--border-accent);
}

.chat-input button {
    padding: 0.5rem 0.75rem;

    border-radius: 0.375rem;
    border: none;

    background: var(--bt-primary);
    color: #fff;

    font-size: 0.8125rem;
    cursor: pointer;
}

.chat-input button:hover {
    background: var(--bt-accent);
}

@media (max-width: 480px) {
    .chat-overlay.open {
        transform: translateY(0);
    }

    .chat-overlay {
        bottom: 0;
        right: 0;
        left: 0;

        width: 100vw;
        height: 100dvh;

        border-radius: 0;
        transform: translateY(100%);
    }

    .chat-header {
        padding: 1rem;
        font-size: 1rem;
    }

    .chat-input {
        padding: 1rem;
    }

    .chat-input input {
        font-size: 1rem;
    }
}