.ba-chat {
    --ba-primary: #00c194;
    --ba-secondary: #07c196;
    --ba-bg: #f7f9f9;
    --ba-bubble-user: #00c194;
    --ba-bubble-bot: #ffffff;
    --ba-text: #1f2933;
    --ba-muted: #788593;
    --ba-border: #e5e9ea;

    display: flex;
    flex-direction: column;
    max-width: 720px;
    height: 620px;
    max-height: 80vh;
    margin: 0 auto;
    background: var(--ba-bg);
    border: 1px solid var(--ba-border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.ba-chat__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--ba-primary), var(--ba-secondary));
    color: #fff;
    flex-shrink: 0;
}

.ba-chat__avatar {
    font-size: 22px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
}

.ba-chat__title {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.3;
}

.ba-chat__subtitle {
    font-size: 12px;
    opacity: 0.85;
}

.ba-chat__close {
    margin-left: auto;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    border-radius: 50%;
    color: var(--ba-primary, #00c194);
    font-size: 22px;
    line-height: 1;
    font-weight: 400;
    font-family: Arial, Helvetica, sans-serif;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}

.ba-chat__close span {
    display: block;
    margin-top: -2px;
}

.ba-chat__close:hover {
    background: #fff;
    transform: scale(1.06);
}

/* ---- Floating launcher (IDE-style docked chat) ---- */

.ba-launcher {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #00c194, #07c196);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
    z-index: 999998;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.ba-launcher:hover {
    transform: scale(1.06);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

.ba-launcher__icon-open,
.ba-launcher__icon-close {
    line-height: 1;
}

.ba-launcher__icon-open {
    font-size: 24px;
}

.ba-launcher__icon-close {
    display: none;
    font-size: 30px;
    font-weight: 300;
    font-family: Arial, Helvetica, sans-serif;
    margin-top: -3px;
}

.ba-launcher.is-open .ba-launcher__icon-open {
    display: none;
}

.ba-launcher.is-open .ba-launcher__icon-close {
    display: block;
}

.ba-chat--floating {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    height: 100vh;
    max-height: 100vh;
    width: 400px;
    max-width: 92vw;
    margin: 0;
    border-radius: 0;
    border-top: none;
    border-bottom: none;
    border-right: none;
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.18);
    z-index: 999999;
    transform: translateX(100%);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.28s ease, opacity 0.2s ease, visibility 0s linear 0.28s;
}

.ba-chat--floating.is-open {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
    transition: transform 0.28s ease, opacity 0.2s ease, visibility 0s linear 0s;
}

@media (max-width: 600px) {
    .ba-launcher {
        right: 16px;
        bottom: 16px;
    }
}

.ba-chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.ba-msg {
    display: flex;
    flex-direction: column;
    max-width: 82%;
    animation: ba-pop 0.18s ease-out;
}

.ba-msg--user {
    align-self: flex-end;
    align-items: flex-end;
}

.ba-msg--bot {
    align-self: flex-start;
    align-items: flex-start;
}

.ba-msg__bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.ba-msg--user .ba-msg__bubble {
    background: var(--ba-bubble-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ba-msg--bot .ba-msg__bubble {
    background: var(--ba-bubble-bot);
    color: var(--ba-text);
    border: 1px solid var(--ba-border);
    border-bottom-left-radius: 4px;
}

.ba-msg--error .ba-msg__bubble {
    background: #fdecea;
    color: #b3261e;
    border-color: #f6cac6;
}

.ba-msg__bubble p {
    margin: 0 0 8px;
}

.ba-msg__bubble p:last-child {
    margin-bottom: 0;
}

.ba-msg__bubble ul,
.ba-msg__bubble ol {
    margin: 0 0 8px;
    padding-left: 20px;
}

.ba-msg__bubble ul:last-child,
.ba-msg__bubble ol:last-child {
    margin-bottom: 0;
}

.ba-msg__bubble li {
    margin-bottom: 2px;
}

.ba-msg__bubble strong {
    font-weight: 700;
}

.ba-msg__bubble code {
    background: rgba(0, 0, 0, 0.06);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 12.5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.ba-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 12px 14px;
    background: var(--ba-bubble-bot);
    border: 1px solid var(--ba-border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.ba-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ba-muted);
    opacity: 0.5;
    animation: ba-bounce 1.2s infinite ease-in-out;
}

.ba-typing span:nth-child(2) { animation-delay: 0.15s; }
.ba-typing span:nth-child(3) { animation-delay: 0.3s; }

.ba-listings {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
    margin-top: 10px;
    width: 100%;
}

.ba-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    background: #fff;
    border: 1px solid var(--ba-border);
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    font: inherit;
    text-align: left;
    padding: 0;
    cursor: pointer;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.ba-card:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.ba-card__thumb {
    width: 100%;
    height: 120px;
    object-fit: cover;
    background: #e5e9ea;
}

.ba-card__body {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ba-card__price {
    font-weight: 700;
    font-size: 15px;
    color: var(--ba-text);
}

.ba-card__title {
    font-size: 12.5px;
    color: var(--ba-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ba-card__meta {
    font-size: 11.5px;
    color: var(--ba-muted);
}

.ba-card__cta {
    margin-top: 4px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--ba-primary);
}

.ba-chat__composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    background: #fff;
    border-top: 1px solid var(--ba-border);
    flex-shrink: 0;
}

.ba-chat__input {
    flex: 1;
    box-sizing: border-box;
    resize: none;
    border: 1px solid var(--ba-border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    min-height: 40px;
    max-height: 100px;
    overflow-y: auto;
    color: var(--ba-text);
}

.ba-chat__input:focus {
    outline: none;
    border-color: var(--ba-primary);
}

.ba-chat__send {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: var(--ba-primary);
    color: #fff;
    cursor: pointer;
    transition: background 0.15s ease, opacity 0.15s ease;
}

/* Pure-CSS right-pointing arrow — no font glyph or SVG dependency. */
.ba-chat__send::before {
    content: '';
    display: block;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 10px solid currentColor;
    margin-left: 3px;
}

.ba-chat__send:hover {
    background: var(--ba-secondary);
}

.ba-chat__send:disabled {
    opacity: 0.5;
    cursor: default;
}

@keyframes ba-pop {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes ba-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

@media (max-width: 600px) {
    .ba-chat {
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        max-width: 100%;
    }

    .ba-chat--floating {
        width: 100%;
    }
}

/* ---- In-chat listing detail (for listings without a synced page yet) ---- */

.ba-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 26, 30, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000000;
}

.ba-modal {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-height: 85vh;
    overflow-y: auto;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.ba-modal__close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    border-radius: 50%;
    color: #1f2933;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    z-index: 1;
}

.ba-modal__close span {
    display: block;
    margin-top: -2px;
}

.ba-modal__photo {
    width: 100%;
    height: 220px;
    object-fit: cover;
    background: #e5e9ea;
    display: block;
}

.ba-modal__body {
    padding: 16px 18px 20px;
}

.ba-modal__price {
    font-size: 20px;
    font-weight: 700;
    color: #1f2933;
}

.ba-modal__title {
    font-size: 14px;
    color: #1f2933;
    margin-top: 2px;
}

.ba-modal__meta {
    font-size: 12.5px;
    color: #788593;
    margin-top: 6px;
}

.ba-modal__remarks {
    font-size: 13.5px;
    line-height: 1.6;
    color: #1f2933;
    margin: 14px 0 0;
    white-space: pre-wrap;
}
