/* ==========================================================================
   CHATBOT KỊCH BẢN CỐ ĐỊNH — Bộ Cứu Hộ Vibe Code
   Chỉ dùng lại biến màu đã khai báo trong styles.css (:root).
   Không khai báo màu mới.

   Xếp tầng ở góc dưới phải (từ dưới lên):
     mobile-sticky-cta (z 90) → zalo-float (z 900) → nút chat (z 930)
     → cửa sổ chat (z 940)
   ========================================================================== */

/* --------------------------------------------------------------------------
   NÚT MỞ CHAT (đặt phía trên nút Zalo, không đè lên nhau)
   -------------------------------------------------------------------------- */
.vbc-chat-launcher {
    position: fixed;
    bottom: 148px;
    right: 16px;
    z-index: 930;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    border: 1px solid var(--border-glow);
    border-radius: 999px;
    background: var(--primary);
    color: #ffffff;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 4px 16px var(--primary-glow);
    transition: var(--transition);
}

.vbc-chat-launcher:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--primary-glow);
}

.vbc-chat-launcher:focus-visible {
    outline: 2px solid var(--text-main);
    outline-offset: 3px;
}

.vbc-launcher-icon {
    font-size: 1.05rem;
}

/* Chấm báo có tin nhắn chờ — tắt sau khi khách mở chat lần đầu */
.vbc-launcher-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 3px var(--success-bg);
}

.vbc-chat-launcher.is-seen .vbc-launcher-dot {
    display: none;
}

/* Ẩn nút mở khi cửa sổ chat đang bật */
body.vbc-chat-open .vbc-chat-launcher {
    opacity: 0;
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   CỬA SỔ CHAT
   -------------------------------------------------------------------------- */
.vbc-chat-panel {
    position: fixed;
    bottom: 90px;
    right: 16px;
    z-index: 940;
    display: flex;
    flex-direction: column;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 130px);
    background: var(--bg-card);
    border: 1px solid var(--border-glow);
    border-radius: var(--radius-lg);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
    font-family: var(--font-sans);
    overflow: hidden;
    transform: translateY(12px) scale(0.98);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.22s ease, opacity 0.22s ease, visibility 0.22s;
}

.vbc-chat-panel.is-open {
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
}

/* --- Đầu cửa sổ --- */
.vbc-chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--bg-card-alt);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.vbc-header-avatar {
    font-size: 1.3rem;
    line-height: 1;
}

.vbc-header-text {
    flex: 1;
    min-width: 0;
}

.vbc-header-title {
    display: block;
    color: var(--text-main);
    font-size: 0.92rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vbc-header-status {
    display: block;
    color: var(--text-muted);
    font-size: 0.72rem;
    margin-top: 2px;
}

.vbc-header-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    transition: var(--transition);
}

.vbc-header-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-main);
}

.vbc-header-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* --- Khung tin nhắn --- */
.vbc-chat-log {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.vbc-chat-log::-webkit-scrollbar {
    width: 6px;
}

.vbc-chat-log::-webkit-scrollbar-thumb {
    background: var(--bg-card-hover);
    border-radius: 999px;
}

.vbc-msg {
    max-width: 88%;
    padding: 10px 13px;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    line-height: 1.55;
    white-space: pre-line;
    word-wrap: break-word;
    animation: vbc-pop 0.2s ease;
}

.vbc-msg strong {
    color: var(--text-main);
    font-weight: 700;
}

.vbc-msg-bot {
    align-self: flex-start;
    background: var(--bg-card-alt);
    border: 1px solid var(--border-color);
    color: var(--text-subtext);
    border-bottom-left-radius: var(--radius-sm);
}

.vbc-msg-user {
    align-self: flex-end;
    background: var(--primary);
    color: #ffffff;
    border-bottom-right-radius: var(--radius-sm);
}

.vbc-msg-user strong {
    color: #ffffff;
}

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

/* --- Chấm "đang gõ" --- */
.vbc-typing {
    align-self: flex-start;
    display: inline-flex;
    gap: 4px;
    padding: 12px 14px;
    background: var(--bg-card-alt);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    border-bottom-left-radius: var(--radius-sm);
}

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

.vbc-typing span:nth-child(2) { animation-delay: 0.18s; }
.vbc-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes vbc-blink {
    0%, 60%, 100% { opacity: 0.25; }
    30%           { opacity: 1; }
}

/* --- Khu nút bấm --- */
.vbc-chat-actions {
    flex-shrink: 0;
    max-height: 46%;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 10px 14px 12px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.vbc-chat-actions::-webkit-scrollbar {
    width: 6px;
}

.vbc-chat-actions::-webkit-scrollbar-thumb {
    background: var(--bg-card-hover);
    border-radius: 999px;
}

.vbc-actions-hint {
    color: var(--text-muted);
    font-size: 0.7rem;
    margin: 0 0 1px;
}

.vbc-opt {
    width: 100%;
    text-align: left;
    padding: 9px 12px;
    background: var(--bg-card-alt);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-subtext);
    font-family: var(--font-sans);
    font-size: 0.83rem;
    line-height: 1.4;
    cursor: pointer;
    transition: var(--transition);
}

.vbc-opt:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-glow);
    color: var(--text-main);
}

.vbc-opt:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Nút dẫn sang form danh sách chờ */
.vbc-opt-cta {
    display: block;
    text-align: center;
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
    font-weight: 700;
    font-size: 0.88rem;
    text-decoration: none;
    padding: 12px;
}

.vbc-opt-cta:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: #ffffff;
}

.vbc-cta-sub {
    display: block;
    font-size: 0.7rem;
    font-weight: 400;
    opacity: 0.85;
    margin-top: 3px;
}

/* Nút phụ: quay lại đầu kịch bản */
.vbc-opt-restart {
    background: transparent;
    border-style: dashed;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-align: center;
}

/* --------------------------------------------------------------------------
   ĐIỆN THOẠI (<768px)
   Cửa sổ không tràn màn hình, chừa chỗ cho thanh CTA dưới cùng.
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
    .vbc-chat-launcher {
        bottom: 136px;
        right: 14px;
        padding: 12px 14px;
        border-radius: 50%;
    }

    .vbc-launcher-label {
        display: none;
    }

    .vbc-chat-panel {
        left: 10px;
        right: 10px;
        bottom: 76px;
        width: auto;
        max-width: none;
        height: auto;
        max-height: none;
        top: 64px;
    }

    /* Mở chat thì tạm ẩn Zalo + thanh CTA cho đỡ chồng chéo */
    body.vbc-chat-open .zalo-float,
    body.vbc-chat-open .mobile-sticky-cta {
        opacity: 0;
        pointer-events: none;
    }

    .vbc-msg {
        max-width: 92%;
        font-size: 0.86rem;
    }
}

/* Màn hình rất thấp: ưu tiên chỗ cho tin nhắn */
@media (max-height: 620px) and (min-width: 768px) {
    .vbc-chat-panel {
        height: calc(100vh - 130px);
    }
}

/* --------------------------------------------------------------------------
   TÔN TRỌNG THIẾT LẬP GIẢM CHUYỂN ĐỘNG
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .vbc-chat-panel,
    .vbc-chat-launcher,
    .vbc-opt {
        transition: none;
    }

    .vbc-msg {
        animation: none;
    }

    .vbc-typing span {
        animation: none;
        opacity: 0.6;
    }
}
