/*
 * Widget chat khách hàng — đặt góc dưới-phải trên desktop (floating-contact
 * đang ở top:50% nên không đụng), chuyển sang góc dưới-TRÁI trên mobile để
 * không chồng lên floating-contact + bottom-bar vốn đã chiếm dày đặc bên
 * phải/dưới cùng (xem hctclient01-consultation-contact.css).
 */
.hctclient01-chat-widget {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 120;
}

/*
 * Nút "Chat ngay" dạng viên thuốc (pill) — tham khảo nút Chat Ngay của
 * misa.vn (icon tròn trắng + chữ đậm, badge số tròn ở góc), thay cho nút
 * tròn trơn cũ vì bị phản hồi là không đủ nổi bật để khách chú ý.
 */
.hctclient01-chat-widget__toggle {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 52px;
    padding: 0 20px 0 8px;
    border: 0;
    border-radius: 999px;
    background: var(--hctclient01-color-primary);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 8px 22px rgba(0, 0, 0, .22);
    transition: transform .2s ease, box-shadow .2s ease;
    animation: hctclient01ChatToggleBounce 2.6s ease-in-out infinite;
}

.hctclient01-chat-widget__toggle:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 12px 28px rgba(0, 0, 0, .28);
    animation-play-state: paused;
}

.hctclient01-chat-widget__toggle-icon {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #fff;
    color: var(--hctclient01-color-primary);
}

.hctclient01-chat-widget__toggle-label {
    font-size: 14px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .02em;
    white-space: nowrap;
}

@keyframes hctclient01ChatToggleBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

@media (prefers-reduced-motion: reduce) {
    .hctclient01-chat-widget__toggle {
        animation: none;
    }
}

.hctclient01-chat-widget__badge {
    position: absolute;
    top: -6px;
    right: -6px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: #dc2626;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 0 0 2px #fff;
    animation: hctclient01ChatBadgePulse 1s ease-in-out infinite;
}

@keyframes hctclient01ChatBadgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/*
 * Có tin trả lời mới (nhân viên/AI) trong lúc panel đang đóng -> viền nút
 * toggle nháy mạnh thêm 1 lớp, phân biệt rõ với animation nhấp nhô nhẹ mặc
 * định (luôn chạy, không phân biệt trạng thái đọc) — tắt ngay khi mở panel.
 */
.hctclient01-chat-widget__toggle.has-new-reply {
    animation: hctclient01ChatToggleBounce 2.6s ease-in-out infinite, hctclient01ChatToggleRing 1s ease-in-out infinite;
}

@keyframes hctclient01ChatToggleRing {
    0%, 100% { box-shadow: 0 8px 22px rgba(0, 0, 0, .22), 0 0 0 0 rgba(220, 38, 38, .5); }
    50% { box-shadow: 0 8px 22px rgba(0, 0, 0, .22), 0 0 0 8px rgba(220, 38, 38, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .hctclient01-chat-widget__badge {
        animation: none;
    }

    .hctclient01-chat-widget__toggle.has-new-reply {
        animation: none;
    }
}

.hctclient01-chat-widget__panel {
    position: absolute;
    right: 0;
    bottom: 66px;
    display: flex;
    flex-direction: column;
    width: min(360px, calc(100vw - 32px));
    height: min(520px, calc(100vh - 140px));
    overflow: hidden;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 16px 48px rgba(0, 0, 0, .22);
}

.hctclient01-chat-widget__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    padding: 14px 12px 14px 18px;
    background: var(--hctclient01-color-primary);
    color: #fff;
    font-weight: 700;
}

.hctclient01-chat-widget__minimize {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .18);
    color: #fff;
    cursor: pointer;
    transition: background .15s ease;
}

.hctclient01-chat-widget__minimize:hover {
    background: rgba(255, 255, 255, .3);
}

.hctclient01-chat-widget__body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
}

.hctclient01-chat-widget__empty {
    padding: 10px 14px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid #e5e7eb;
    color: #475569;
    font-size: 13px;
    align-self: flex-start;
    max-width: 85%;
}

.hctclient01-chat-widget__bubble-row {
    display: flex;
}

.hctclient01-chat-widget__bubble-row.is-user {
    justify-content: flex-end;
}

.hctclient01-chat-widget__bubble-row.is-reply {
    justify-content: flex-start;
}

.hctclient01-chat-widget__bubble {
    max-width: 82%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.hctclient01-chat-widget__bubble-row.is-user .hctclient01-chat-widget__bubble {
    background: var(--hctclient01-color-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.hctclient01-chat-widget__bubble-row.is-reply .hctclient01-chat-widget__bubble {
    background: #fff;
    color: #0f172a;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}

.hctclient01-chat-widget__form {
    display: flex;
    flex: 0 0 auto;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}

.hctclient01-chat-widget__input {
    flex: 1;
    max-height: 90px;
    padding: 9px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    resize: none;
    font: inherit;
    font-size: 13px;
    line-height: 1.4;
}

.hctclient01-chat-widget__input:focus {
    outline: 2px solid var(--hctclient01-color-primary);
    outline-offset: 1px;
}

.hctclient01-chat-widget__send {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: var(--hctclient01-color-primary);
    color: #fff;
    cursor: pointer;
}

.hctclient01-chat-widget__send:disabled {
    opacity: .5;
    cursor: not-allowed;
}

@media (max-width: 767px) {
    .hctclient01-chat-widget {
        right: auto;
        left: 10px;
        bottom: calc(72px + env(safe-area-inset-bottom, 0) + 14px);
    }

    /* Màn hình nhỏ: vẫn giữ dạng pill + chữ (không thu về icon tròn), chỉ
     * giảm kích thước cho vừa — trước đây ẩn hẳn chữ, bị phản hồi không cần
     * thu gọn kiểu đó, chỉ cần chỉnh cỡ chữ phù hợp mobile. */
    .hctclient01-chat-widget__toggle {
        height: 46px;
        padding: 0 16px 0 6px;
        gap: 8px;
    }

    .hctclient01-chat-widget__toggle-icon {
        width: 32px;
        height: 32px;
    }

    .hctclient01-chat-widget__toggle-label {
        font-size: 12px;
    }

    .hctclient01-chat-widget__panel {
        right: auto;
        left: 0;
        bottom: 58px;
        width: min(340px, calc(100vw - 20px));
        height: min(70vh, 480px);
    }

    /*
     * iOS Safari tự động zoom trang khi focus vào input có font-size < 16px
     * — trước đây 13px nên mỗi lần bấm nhập tin nhắn là cả trang bị phóng to
     * đột ngột. Chỉ cần đúng 16px là đủ tắt hành vi này, không cần disable
     * zoom toàn trang (ảnh hưởng accessibility).
     */
    .hctclient01-chat-widget__input {
        font-size: 16px;
    }
}
