/* Floating chat widget — site-wide.
 * State machine on #vmarket-chat[data-state] drives panel visibility + FAB icon swap.
 * Mobile: panel fills viewport. Desktop: 380x560 pinned bottom-right. */

#vmarket-chat {
    position: fixed;
    right: 16px;
    bottom: 16px;
    /* Above project modals (z-index ~999) but below toast/system overlays. */
    z-index: 9000;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.45;
    color: #222;
}

/* ---------- FAB ---------- */

.vmarket-chat-fab {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #1e88e5, #0d47a1);
    color: #fff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.vmarket-chat-fab:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28); }
.vmarket-chat-fab:focus { outline: 2px solid #1e88e5; outline-offset: 2px; }

.vmarket-chat-fab-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.vmarket-chat-fab-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: #e53935;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

/* Hide FAB while panel is open (avoid double-anchor). */
#vmarket-chat[data-state="open"] .vmarket-chat-fab {
    transform: scale(0.6);
    opacity: 0;
    pointer-events: none;
}

/* ---------- Panel ---------- */

.vmarket-chat-panel {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 32px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    transition: transform 0.22s ease, opacity 0.22s ease;
}

#vmarket-chat[data-state="open"] .vmarket-chat-panel {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* ---------- Header ---------- */

.vmarket-chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, #1e88e5, #0d47a1);
    color: #fff;
}

.vmarket-chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.vmarket-chat-header-text { flex: 1; min-width: 0; line-height: 1.2; }
.vmarket-chat-header-name { display: block; font-weight: 600; font-size: 14px; }
.vmarket-chat-header-status { display: block; font-size: 11px; opacity: 0.82; }
.vmarket-chat-header-status::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 4px;
    border-radius: 50%;
    background: #4caf50;
    vertical-align: middle;
}

.vmarket-chat-header-actions { display: flex; gap: 4px; }

.vmarket-chat-clear,
.vmarket-chat-close {
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease;
}
.vmarket-chat-clear:hover,
.vmarket-chat-close:hover { background: rgba(255, 255, 255, 0.28); }

/* ---------- Body ---------- */

.vmarket-chat-body {
    flex: 1;
    padding: 14px;
    overflow-y: auto;
    background: #f7f8fa;
    scroll-behavior: smooth;
}

.vmarket-chat-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 10px;
    animation: vmarket-chat-msg-in 0.18s ease;
}

.vmarket-chat-msg-bot   { justify-content: flex-start; }
.vmarket-chat-msg-user  { justify-content: flex-end; }

.vmarket-chat-bubble {
    max-width: 78%;
    padding: 9px 12px;
    border-radius: 14px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.vmarket-chat-msg-bot  .vmarket-chat-bubble {
    background: #fff;
    color: #222;
    border: 1px solid #e3e6eb;
    border-bottom-left-radius: 4px;
}
.vmarket-chat-msg-user .vmarket-chat-bubble {
    background: #1e88e5;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.vmarket-chat-bubble p { margin: 0 0 6px; }
.vmarket-chat-bubble p:last-child { margin-bottom: 0; }
.vmarket-chat-bubble a { color: inherit; text-decoration: underline; }
.vmarket-chat-bubble ul { margin: 4px 0 4px 18px; padding: 0; }
.vmarket-chat-bubble code { background: rgba(0, 0, 0, 0.06); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
.vmarket-chat-bubble pre { background: rgba(0, 0, 0, 0.06); padding: 8px; border-radius: 6px; overflow-x: auto; }

/* Chip / option buttons */
.vmarket-chat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 8px 0;
}
.vmarket-chat-chip {
    padding: 6px 10px;
    border: 1px solid #1e88e5;
    border-radius: 14px;
    background: #fff;
    color: #1e88e5;
    font-size: 12.5px;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
    text-align: left;
}
.vmarket-chat-chip:hover { background: #1e88e5; color: #fff; }
.vmarket-chat-chip:disabled { opacity: 0.5; cursor: not-allowed; }

/* Typing indicator (3 dots) */
.vmarket-chat-typing { display: inline-flex; gap: 3px; padding: 8px 0; }
.vmarket-chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9aa4ad;
    animation: vmarket-chat-bounce 1.1s infinite ease-in-out;
}
.vmarket-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.vmarket-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes vmarket-chat-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1; }
}
@keyframes vmarket-chat-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Input footer ---------- */

.vmarket-chat-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e3e6eb;
    background: #fff;
}

.vmarket-chat-textarea {
    flex: 1;
    min-height: 36px;
    max-height: 110px;
    padding: 8px 12px;
    border: 1px solid #cfd5dc;
    border-radius: 18px;
    background: #f7f8fa;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    outline: none;
}
.vmarket-chat-textarea:focus { border-color: #1e88e5; background: #fff; }

.vmarket-chat-send {
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #1e88e5;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease;
}
.vmarket-chat-send:hover  { background: #1565c0; }
.vmarket-chat-send:disabled { background: #b0bec5; cursor: not-allowed; }

/* ---------- Mobile ---------- */

@media (max-width: 600px) {
    #vmarket-chat { right: 12px; bottom: 100px; }

    .vmarket-chat-panel {
        position: fixed;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        transform-origin: bottom center;
    }
}
