0

[Series 100 Bài Học HTML/CSS Thực Chiến - Bài 97]: Thiết Kế Giao Diện "Trợ Lý Ảo Shopee AI Chatbot" (Conversational Shopping UI) Gợi Ý Sản Phẩm Theo Ngân Sách Bằng CSS Thuần

Chào mừng anh em đã bước sang Bài 97 — chỉ còn đúng 3 bài cuối cùng là hoàn tất trọn bộ 100 Bài Học Làm Chủ HTML/CSS Qua Dự Án Clone Shopee!

Ở Bài 96, chúng ta đã chinh phục kỹ thuật in ấn giấy A4 bằng @media print cho Hóa Đơn Điện Tử VAT & Phiếu Giao Hàng SPX. Hôm nay, chúng ta sẽ bắt kịp xu hướng công nghệ nóng nhất của thương mại điện tử hiện đại: Giao Diện "Trợ Lý Ảo Shopee AI Chatbot" (Conversational Shopping UI) — nơi người mua chỉ cần chọn ngân sách hoặc nhu cầu, AI sẽ lập tức trả về danh sách sản phẩm phù hợp nhất ngay trong luồng chat!

Thay vì phải lọc hàng chục bộ lọc phức tạp, trải nghiệm mua sắm hội thoại (Conversational Commerce) rút ngắn thời gian tìm đồ xuống còn 3 giây. Trong Bài 97, chúng ta sẽ chinh phục 4 kỹ thuật CSS thuần thực chiến:

  1. Chuyển Đổi Kịch Bản Hội Thoại Theo Ngân Sách Bằng :has() (Dưới ₫500k | ₫500k – ₫1Tr | Trên ₫1Tr): Khi người dùng bấm vào một chip câu hỏi nhanh (Quick Prompt), cả bong bóng câu hỏi của người dùng lẫn câu trả lời kèm thẻ sản phẩm của Shopee AI lập tức biến đổi tương ứng mà không cần một dòng JavaScript nào!

  2. Hiệu Ứng "Shopee AI Đang Phân Tích..." (Typing Indicator Dots): Ba chấm tròn nhấp nhô mượt mà bằng @keyframes aiTypingBounce kết hợp animation-delay lệch pha (0s, 0.15s, 0.3s).

  3. Thẻ Sản Phẩm Gợi Ý Nhúng Trong Bong Bóng Chat (Rich Product Card): Trình bày ảnh sản phẩm, giá bán, nhãn "AI Khuyên Dùng" và lý do phù hợp ngay bên trong khung tin nhắn.

  4. Cột Gợi Ý Nhu Cầu Nhanh & Tương Thích 100% Dark Mode (Bài 55).

1. Giải phẫu Giao Diện Shopee AI Chatbot (Conversational Shopping UI)

Hãy quan sát mô hình ứng dụng Trợ lý AI trong Thương mại điện tử — nơi hội thoại tự nhiên kết hợp trực tiếp với thẻ sản phẩm trực quan giúp người mua ra quyết định nhanh hơn:

image.png

Trong Bài 97, toàn bộ khu vực Trợ Lý Ảo Shopee AI (.shopee-ai-section) được tổ chức theo bố cục 2 cột cân đối (30rem Cột chọn Ngân sách & Nhu cầu nhanh bên trái | 1fr Khung Hội Thoại Shopee AI trực quan bên phải):

Plaintext

|<---------- 300px Chọn Ngân Sách & Nhu Cầu ---------->|<------------ 1fr Khung Hội Thoại Shopee AI ------------>|
+------------------------------------------------------+---------------------------------------------------------+
|  ✨ SHOPEE AI — TRỢ LÝ MUA SẮM THÔNG MINH            |  🤖 Shopee AI Assistant      ● Đang trực tuyến (···)    |
|                                                      +---------------------------------------------------------+
|  CHỌN NGÂN SÁCH TƯ VẤN (CSS Radio):                  |  [🤖] Xin chào! Bạn đang tìm gear công nghệ tầm giá nào?|
|  ( ) Dưới ₫500.000 (Chuột, Phụ kiện)                 |                                                         |
|  (●) ₫500.000 – ₫1.000.000 (Bàn phím cơ)             |      [👤] Tìm giúp mình bàn phím cơ tầm 500k – 1 triệu! |
|  ( ) Trên ₫1.000.000 (Cao cấp / Gaming)              |                                                         |
|                                                      |  [🤖] Dưới đây là 2 mẫu bán chạy nhất phân khúc 500k-1Tr|
|  MẸO HỎI NHANH:                                      |       +----------------------+ +----------------------+ |
|  • So sánh AULA F75 Pro vs F99                       |       | [📦] AULA F75 Pro    | | [📦] AULA WIN68 HE   | |
|  • Tìm mã Freeship 0Đ hôm nay                        |       | ₫850.000 · ★ 4.9     | | ₫749.000 · ★ 4.8     | |
|                                                      |       | [ Xem Chi Tiết ]     | | [ Xem Chi Tiết ]     | |
|                                                      |       +----------------------+ +----------------------+ |
|                                                      +---------------------------------------------------------+
|                                                      |  [ Nhập câu hỏi cho Shopee AI...          ] [ Gửi ➤ ]   |
+------------------------------------------------------+---------------------------------------------------------+
Kỹ thuật CSS trong Bài 97 Khai báo cốt lõi Tác dụng thực chiến
Hoán đổi kịch bản chat theo ngân sách
(:has())
.shopee-ai-section:has(#ai-budget-mid:checked) .ai-thread--mid { display: flex; } Chỉ cần bấm chọn 1 trong 3 mức ngân sách ở cột trái, toàn bộ luồng hội thoại và thẻ sản phẩm gợi ý bên phải tự động đổi mượt mà kèm hiệu ứng fadeIn!
3 chấm đang gõ lệch pha
(@keyframes aiTypingBounce)
.ai-dot:nth-child(2) { animation-delay: 0.15s; } Tạo nhịp sóng mềm mại cho trạng thái AI đang hoạt động mà chỉ tốn vài dòng CSS, chạy hoàn toàn trên GPU (transform: translateY).
Bo góc bất đối xứng cho bong bóng chat Bot: border-radius: 0.4rem 1.4rem 1.4rem 1.4rem;
User: border-radius: 1.4rem 0.4rem 1.4rem 1.4rem;
Mẹo kinh điển của UI Chat (Messenger, Zalo, ChatGPT): vát nhọn đúng góc hướng về phía người nói để mắt người đọc phân biệt ngay ai đang nói!

2. Thực hành: Code Giao Diện "Trợ Lý Ảo Shopee AI Chatbot" (index.html & main.css)

Bước 1: Bổ sung HTML Khối Trợ Lý Ảo Shopee AI (.shopee-ai-section) vào index.html

Hãy mở file index.html, tìm đến bên trong <div class="shopee-container grid-container"> (ngay bên dưới khối Hóa Đơn Điện Tử VAT của Bài 96) và chèn toàn bộ cấu trúc Bài 97: Trợ Lý Ảo Shopee AI Chatbot dưới đây:

HTML

        <!-- ================================================================= -->
        <!-- BÀI 97: TRỢ LÝ ẢO SHOPEE AI CHATBOT (CONVERSATIONAL SHOPPING UI)  -->
        <!-- ================================================================= -->
        <section class="shopee-ai-section">
            
            <!-- Hệ thống 3 nút Radio chọn kịch bản tư vấn theo ngân sách -->
            <input type="radio" name="ai-budget" id="ai-budget-low" class="ai-ctrl-input">
            <input type="radio" name="ai-budget" id="ai-budget-mid" class="ai-ctrl-input" checked>
            <input type="radio" name="ai-budget" id="ai-budget-high" class="ai-ctrl-input">

            <!-- 1. BỐ CỤC 2 CỘT: CHỌN NGÂN SÁCH (TRÁI) | KHUNG CHAT AI (PHẢI) -->
            <div class="ai-layout">
                
                <!-- CỘT TRÁI: CHỌN NGÂN SÁCH & GỢI Ý CÂU HỎI NHANH -->
                <aside class="ai-sidebar">
                    <div class="ai-brand-head">
                        <span class="ai-spark-icon"><i class="fa-solid fa-wand-magic-sparkles"></i></span>
                        <div>
                            <h2 class="ai-brand-title">Shopee AI</h2>
                            <span class="ai-brand-sub">Trợ lý chọn đồ theo ngân sách</span>
                        </div>
                    </div>

                    <div class="ai-prompt-group" role="radiogroup" aria-label="Chọn mức ngân sách tư vấn">
                        <span class="ai-side-label">1. Chọn mức ngân sách của bạn:</span>

                        <label for="ai-budget-low" class="ai-budget-card ai-budget-card--low">
                            <span class="ai-b-icon"><i class="fa-solid fa-piggy-bank"></i></span>
                            <div>
                                <strong>Dưới ₫500.000</strong>
                                <span>Chuột Gaming, Phụ kiện bàn làm việc</span>
                            </div>
                        </label>

                        <label for="ai-budget-mid" class="ai-budget-card ai-budget-card--mid">
                            <span class="ai-b-icon"><i class="fa-solid fa-keyboard"></i></span>
                            <div>
                                <strong>₫500.000 – ₫1.000.000</strong>
                                <span>Bàn phím cơ 3 Mode, Tai nghe không dây</span>
                            </div>
                        </label>

                        <label for="ai-budget-high" class="ai-budget-card ai-budget-card--high">
                            <span class="ai-b-icon"><i class="fa-solid fa-crown"></i></span>
                            <div>
                                <strong>Trên ₫1.000.000</strong>
                                <span>Máy tính bảng, Gear Cao Cấp Mall</span>
                            </div>
                        </label>
                    </div>

                    <div class="ai-tips-card">
                        <strong><i class="fa-solid fa-lightbulb"></i> Khả năng của Shopee AI:</strong>
                        <ul>
                            <li>Lọc sản phẩm Shopee Mall đánh giá trên 4.8★</li>
                            <li>Tự động tính giá sau khi áp Voucher &amp; Freeship</li>
                            <li>Gợi ý gói trả góp 0% SPayLater phù hợp</li>
                        </ul>
                    </div>
                </aside>

                <!-- ========================================================= -->
                <!-- CỘT PHẢI: KHUNG HỘI THOẠI SHOPEE AI & THẺ SẢN PHẨM NHÚNG  -->
                <!-- ========================================================= -->
                <div class="ai-chat-window">
                    
                    <!-- Header Khung Chat & Trạng thái 3 chấm đang hoạt động -->
                    <header class="ai-chat-header">
                        <div class="ai-bot-profile">
                            <span class="ai-bot-avatar"><i class="fa-solid fa-robot"></i></span>
                            <div>
                                <strong>Trợ Lý Mua Sắm Shopee AI</strong>
                                <span class="ai-bot-status">
                                    <span class="ai-typing-dots" aria-hidden="true">
                                        <i></i><i></i><i></i>
                                    </span>
                                    Sẵn sàng tư vấn 24/7
                                </span>
                            </div>
                        </div>

                        <span class="ai-model-pill">Smart Match v2.6</span>
                    </header>

                    <!-- Luồng Tin Nhắn Hội Thoại (Tự đổi theo 3 mức ngân sách bằng :has()!) -->
                    <div class="ai-chat-body">
                        
                        <!-- Tin nhắn chào mặc định của AI -->
                        <div class="ai-msg ai-msg--bot">
                            <span class="ai-msg-av"><i class="fa-solid fa-robot"></i></span>
                            <div class="ai-bubble ai-bubble--bot">
                                Xin chào <strong>minh_hieu_dev</strong>! Hãy chọn mức ngân sách ở cột bên trái để mình lọc ngay những sản phẩm công nghệ đáng mua nhất hôm nay nhé.
                            </div>
                        </div>

                        <!-- ===================================================== -->
                        <!-- KỊCH BẢN 1: NGÂN SÁCH DƯỚI ₫500.000                   -->
                        <!-- ===================================================== -->
                        <div class="ai-thread ai-thread--low">
                            <div class="ai-msg ai-msg--user">
                                <div class="ai-bubble ai-bubble--user">
                                    Tư vấn giúp mình phụ kiện công nghệ ngon bổ rẻ tầm giá <strong>dưới ₫500.000</strong> nhé!
                                </div>
                            </div>

                            <div class="ai-msg ai-msg--bot">
                                <span class="ai-msg-av"><i class="fa-solid fa-robot"></i></span>
                                <div class="ai-bubble ai-bubble--bot ai-bubble--rich">
                                    <p>Với ngân sách <strong>dưới ₫500.000</strong>, mình đề xuất 2 lựa chọn bán chạy nhất trên Shopee Mall (đều đang được Freeship 0Đ):</p>

                                    <div class="ai-prod-grid">
                                        <article class="ai-prod-card">
                                            <img src="https://placehold.co/220x150/00bfa5/ffffff?text=AULA+SC580" alt="Chuột AULA SC580" class="ai-prod-img">
                                            <div class="ai-prod-info">
                                                <span class="ai-match-tag">98% Phù hợp</span>
                                                <h4>Chuột Gaming AULA SC580 3 Mode Siêu Nhẹ 58g</h4>
                                                <div class="ai-prod-meta">
                                                    <strong>₫389.000</strong>
                                                    <span>★ 4.9</span>
                                                </div>
                                                <a href="#" class="btn btn--primary ai-prod-btn">Xem Sản Phẩm</a>
                                            </div>
                                        </article>

                                        <article class="ai-prod-card">
                                            <img src="https://placehold.co/220x150/2563eb/ffffff?text=Hub+Type-C+7in1" alt="Hub Type-C 7 in 1" class="ai-prod-img">
                                            <div class="ai-prod-info">
                                                <span class="ai-match-tag">95% Phù hợp</span>
                                                <h4>Bộ Chia Cổng UGREEN USB-C 7-in-1 HDMI 4K</h4>
                                                <div class="ai-prod-meta">
                                                    <strong>₫449.000</strong>
                                                    <span>★ 4.9</span>
                                                </div>
                                                <a href="#" class="btn btn--primary ai-prod-btn">Xem Sản Phẩm</a>
                                            </div>
                                        </article>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- ===================================================== -->
                        <!-- KỊCH BẢN 2: NGÂN SÁCH ₫500.000 – ₫1.000.000 (Mặc định) -->
                        <!-- ===================================================== -->
                        <div class="ai-thread ai-thread--mid">
                            <div class="ai-msg ai-msg--user">
                                <div class="ai-bubble ai-bubble--user">
                                    Gợi ý giúp mình bàn phím cơ 3 Mode gõ êm trong tầm <strong>₫500.000 – ₫1.000.000</strong>!
                                </div>
                            </div>

                            <div class="ai-msg ai-msg--bot">
                                <span class="ai-msg-av"><i class="fa-solid fa-robot"></i></span>
                                <div class="ai-bubble ai-bubble--bot ai-bubble--rich">
                                    <p>Phân khúc <strong>₫500k – ₫1Tr</strong> hiện có 2 mẫu bàn phím cơ quốc dân được anh em lập trình viên đánh giá cao nhất:</p>

                                    <div class="ai-prod-grid">
                                        <article class="ai-prod-card">
                                            <img src="https://placehold.co/220x150/ee4d2d/ffffff?text=AULA+F75+Pro" alt="AULA F75 Pro" class="ai-prod-img">
                                            <div class="ai-prod-info">
                                                <span class="ai-match-tag">AI Khuyên Dùng #1</span>
                                                <h4>Bàn Phím Cơ AULA F75 Pro 3 Mode Mạch Xuôi</h4>
                                                <div class="ai-prod-meta">
                                                    <strong>₫850.000</strong>
                                                    <span>★ 4.9</span>
                                                </div>
                                                <a href="#" class="btn btn--primary ai-prod-btn">Xem Sản Phẩm</a>
                                            </div>
                                        </article>

                                        <article class="ai-prod-card">
                                            <img src="https://placehold.co/220x150/7c3aed/ffffff?text=AULA+WIN68+HE" alt="AULA WIN68 HE" class="ai-prod-img">
                                            <div class="ai-prod-info">
                                                <span class="ai-match-tag">Tối ưu Gaming</span>
                                                <h4>Bàn Phím Từ Tính AULA WIN68 HE Rapid Trigger</h4>
                                                <div class="ai-prod-meta">
                                                    <strong>₫749.000</strong>
                                                    <span>★ 4.8</span>
                                                </div>
                                                <a href="#" class="btn btn--primary ai-prod-btn">Xem Sản Phẩm</a>
                                            </div>
                                        </article>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- ===================================================== -->
                        <!-- KỊCH BẢN 3: NGÂN SÁCH TRÊN ₫1.000.000                 -->
                        <!-- ===================================================== -->
                        <div class="ai-thread ai-thread--high">
                            <div class="ai-msg ai-msg--user">
                                <div class="ai-bubble ai-bubble--user">
                                    Mình có ngân sách <strong>trên ₫1.000.000</strong>, muốn tìm thiết bị cao cấp chính hãng có trả góp 0%!
                                </div>
                            </div>

                            <div class="ai-msg ai-msg--bot">
                                <span class="ai-msg-av"><i class="fa-solid fa-robot"></i></span>
                                <div class="ai-bubble ai-bubble--bot ai-bubble--rich">
                                    <p>Đây là 2 siêu phẩm Shopee Mall hỗ trợ <strong>Trả góp 0% SPayLater (6 tháng)</strong> và bảo hành chính hãng 12 tháng:</p>

                                    <div class="ai-prod-grid">
                                        <article class="ai-prod-card">
                                            <img src="https://placehold.co/220x150/f59e0b/ffffff?text=iPad+Air+M2" alt="Apple iPad Air M2" class="ai-prod-img">
                                            <div class="ai-prod-info">
                                                <span class="ai-match-tag">Trả góp 0% · ₫2Tr/tháng</span>
                                                <h4>Apple iPad Air M2 11" Wi-Fi 128GB Chính Hãng VN/A</h4>
                                                <div class="ai-prod-meta">
                                                    <strong>₫12.000.000</strong>
                                                    <span>★ 5.0</span>
                                                </div>
                                                <a href="#" class="btn btn--primary ai-prod-btn">Xem Sản Phẩm</a>
                                            </div>
                                        </article>

                                        <article class="ai-prod-card">
                                            <img src="https://placehold.co/220x150/0f172a/ffffff?text=Sony+WH-1000XM5" alt="Sony WH-1000XM5" class="ai-prod-img">
                                            <div class="ai-prod-info">
                                                <span class="ai-match-tag">Chống ồn hàng đầu</span>
                                                <h4>Tai Nghe Chụp Tai Chống Ồn Sony WH-1000XM5</h4>
                                                <div class="ai-prod-meta">
                                                    <strong>₫6.490.000</strong>
                                                    <span>★ 4.9</span>
                                                </div>
                                                <a href="#" class="btn btn--primary ai-prod-btn">Xem Sản Phẩm</a>
                                            </div>
                                        </article>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>

                    <!-- Thanh Nhập Câu Hỏi Ở Đáy Khung Chat -->
                    <form class="ai-chat-inputbar" onsubmit="return false;">
                        <input type="text" class="ai-input-field" placeholder="Hỏi Shopee AI bất kỳ điều gì (VD: So sánh AULA F75 Pro và F99)...">
                        <button type="submit" class="btn btn--primary ai-send-btn">
                            <i class="fa-solid fa-paper-plane"></i> Gửi
                        </button>
                    </form>

                </div>

            </div>

        </section>

Bước 2: Viết CSS cho Shopee AI Chatbot & Hiệu Ứng 3 Chấm Đang Gõ trong ./assets/css/main.css

Hãy mở file main.css, cuộn xuống dưới cùng và bổ sung đoạn code CSS của Bài 97 dưới đây:

CSS

/* Bổ sung vào cuối file ./assets/css/main.css */

/* --- BÀI 97: TRỢ LÝ ẢO SHOPEE AI CHATBOT (CONVERSATIONAL SHOPPING UI) --- */

@keyframes aiTypingBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
    40%           { transform: translateY(-0.35rem); opacity: 1; }
}

.shopee-ai-section {
    background-color: var(--white-color);
    margin-top: 2rem;
    border-radius: 4px;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.ai-ctrl-input {
    display: none;
}

/* 1. Bố cục 2 cột: Cột chọn Ngân sách (Trái) | Khung Chat AI (Phải) */
.ai-layout {
    display: grid;
    grid-template-columns: 31rem 1fr;
    min-height: 54rem;
}

.ai-sidebar {
    background-color: var(--bg-elevated, #f8f9fa);
    border-right: 1px solid var(--border-subtle, #eeeeee);
    padding: 2.2rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.ai-brand-head {
    display: flex;
    align-items: center;
    gap: 1.2rem;
}

.ai-spark-icon {
    width: 4.4rem;
    height: 4.4rem;
    border-radius: 1.2rem;
    background-image: linear-gradient(135deg, #ee4d2d 0%, #7c3aed 100%);
    color: #ffffff;
    font-size: 1.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-brand-title {
    font-size: 1.85rem;
    font-weight: 800;
    color: var(--text-primary);
}

.ai-brand-sub {
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.ai-side-label {
    display: block;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.04rem;
}

.ai-prompt-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.ai-budget-card {
    display: flex;
    align-items: center;
    gap: 1.2rem;
    padding: 1.2rem 1.4rem;
    border: 1.5px solid var(--border-subtle, #e2e8f0);
    border-radius: 8px;
    background-color: var(--white-color);
    cursor: pointer;
    user-select: none;
    transition: all 0.18s ease;
}

.ai-budget-card:hover {
    border-color: var(--shopee-primary);
}

.ai-b-icon {
    width: 3.6rem;
    height: 3.6rem;
    border-radius: 8px;
    background-color: var(--bg-elevated, #f3f4f6);
    color: var(--shopee-primary);
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-budget-card strong {
    display: block;
    font-size: 1.4rem;
    color: var(--text-primary);
    margin-bottom: 0.2rem;
}

.ai-budget-card span {
    font-size: 1.15rem;
    color: var(--text-secondary);
}

/* Highlight thẻ ngân sách đang chọn */
#ai-budget-low:checked  ~ .ai-layout .ai-budget-card--low,
#ai-budget-mid:checked  ~ .ai-layout .ai-budget-card--mid,
#ai-budget-high:checked ~ .ai-layout .ai-budget-card--high {
    border-color: var(--shopee-primary);
    background-color: var(--bg-soft-accent, #fffbf8);
    box-shadow: 0 4px 12px rgba(238, 77, 45, 0.12);
}

#ai-budget-low:checked  ~ .ai-layout .ai-budget-card--low .ai-b-icon,
#ai-budget-mid:checked  ~ .ai-layout .ai-budget-card--mid .ai-b-icon,
#ai-budget-high:checked ~ .ai-layout .ai-budget-card--high .ai-b-icon {
    background-color: var(--shopee-primary);
    color: #ffffff;
}

.ai-tips-card {
    margin-top: auto;
    padding: 1.4rem;
    border-radius: 8px;
    background-color: var(--white-color);
    border: 1px dashed var(--border-subtle, #dcdcdc);
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.ai-tips-card strong {
    display: block;
    color: var(--text-primary);
    margin-bottom: 0.7rem;
}

.ai-tips-card i {
    color: #f59e0b;
    margin-right: 0.4rem;
}

.ai-tips-card ul {
    padding-left: 1.6rem;
    list-style: disc;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    line-height: 1.75rem;
}

/* ================================================================= */
/* 2. KHUNG HỘI THOẠI SHOPEE AI & 3 CHẤM ĐANG GÕ                     */
/* ================================================================= */
.ai-chat-window {
    display: flex;
    flex-direction: column;
    background-color: var(--white-color);
}

.ai-chat-header {
    padding: 1.6rem 2.2rem;
    border-bottom: 1px solid var(--border-subtle, #eeeeee);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.2rem;
}

.ai-bot-profile {
    display: flex;
    align-items: center;
    gap: 1.2rem;
}

.ai-bot-avatar {
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    background-image: linear-gradient(135deg, #4f46e5 0%, #ee4d2d 100%);
    color: #ffffff;
    font-size: 1.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-bot-profile strong {
    display: block;
    font-size: 1.5rem;
    color: var(--text-primary);
}

.ai-bot-status {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.2rem;
    color: #00bfa5;
    font-weight: 500;
}

/* 3 chấm tròn nhấp nhô lệch pha (Typing Indicator Dots) */
.ai-typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.ai-typing-dots i {
    display: block;
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background-color: #00bfa5;
    animation: aiTypingBounce 1.2s ease-in-out infinite;
}

.ai-typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.ai-typing-dots i:nth-child(3) { animation-delay: 0.3s; }

.ai-model-pill {
    font-family: monospace;
    font-size: 1.15rem;
    font-weight: 600;
    color: #7c3aed;
    background-color: rgba(124, 58, 237, 0.1);
    padding: 0.3rem 1rem;
    border-radius: 2rem;
}

/* Thân luồng hội thoại */
.ai-chat-body {
    flex: 1;
    padding: 2.2rem;
    display: flex;
    flex-direction: column;
    gap: 1.6rem;
    background-color: var(--bg-elevated, #f9fafb);
}

/* Chuyển đổi 3 kịch bản hội thoại bằng :has()! */
.ai-thread {
    display: none;
    flex-direction: column;
    gap: 1.6rem;
    animation: fadeIn ease 0.28s;
}

.shopee-ai-section:has(#ai-budget-low:checked)  .ai-thread--low,
.shopee-ai-section:has(#ai-budget-mid:checked)  .ai-thread--mid,
.shopee-ai-section:has(#ai-budget-high:checked) .ai-thread--high {
    display: flex;
}

.ai-msg {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.ai-msg--user {
    justify-content: flex-end;
}

.ai-msg-av {
    width: 3.2rem;
    height: 3.2rem;
    border-radius: 50%;
    background-color: #4f46e5;
    color: #ffffff;
    font-size: 1.35rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Bong bóng chat bo góc bất đối xứng */
.ai-bubble {
    max-width: 82%;
    padding: 1.2rem 1.6rem;
    font-size: 1.35rem;
    line-height: 2rem;
}

.ai-bubble--bot {
    background-color: var(--white-color);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle, #e5e7eb);
    border-radius: 0.4rem 1.4rem 1.4rem 1.4rem;
}

.ai-bubble--user {
    background-image: linear-gradient(135deg, #ee4d2d 0%, #ff7337 100%);
    color: #ffffff;
    border-radius: 1.4rem 0.4rem 1.4rem 1.4rem;
}

.ai-bubble--rich {
    max-width: 92%;
    width: 100%;
}

.ai-bubble--rich > p {
    margin-bottom: 1.4rem;
}

/* Lưới 2 Thẻ Sản Phẩm Gợi Ý Nhúng Trong Bong Bóng Chat */
.ai-prod-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.4rem;
}

.ai-prod-card {
    border: 1px solid var(--border-subtle, #e5e7eb);
    border-radius: 8px;
    overflow: hidden;
    background-color: var(--bg-elevated, #fafafa);
    display: flex;
    flex-direction: column;
    transition: transform 0.18s ease, border-color 0.18s ease;
}

.ai-prod-card:hover {
    transform: translateY(-0.2rem);
    border-color: var(--shopee-primary);
}

.ai-prod-img {
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
}

.ai-prod-info {
    padding: 1.2rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.ai-match-tag {
    align-self: flex-start;
    font-size: 1.05rem;
    font-weight: 700;
    color: #00bfa5;
    background-color: rgba(0, 191, 165, 0.12);
    padding: 0.15rem 0.8rem;
    border-radius: 2rem;
    margin-bottom: 0.6rem;
}

.ai-prod-info h4 {
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.85rem;
    margin-bottom: 0.8rem;
}

.ai-prod-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-top: auto;
    margin-bottom: 1rem;
    font-variant-numeric: tabular-nums;
}

.ai-prod-meta strong {
    font-size: 1.65rem;
    color: var(--shopee-primary);
}

.ai-prod-meta span {
    font-size: 1.2rem;
    color: #f59e0b;
    font-weight: 600;
}

.ai-prod-btn {
    width: 100%;
    height: 3.4rem;
    font-size: 1.25rem;
    font-weight: 600;
}

/* Thanh Nhập Câu Hỏi Dưới Đáy Khung Chat */
.ai-chat-inputbar {
    padding: 1.4rem 2.2rem;
    border-top: 1px solid var(--border-subtle, #eeeeee);
    background-color: var(--white-color);
    display: flex;
    gap: 1rem;
}

.ai-input-field {
    flex: 1;
    height: 4.2rem;
    padding: 0 1.4rem;
    border: 1px solid var(--border-subtle, #dcdcdc);
    border-radius: 2.4rem;
    font-size: 1.35rem;
    color: var(--text-primary);
    background-color: var(--bg-elevated, #f5f5f5);
    outline: none;
}

.ai-input-field:focus {
    border-color: var(--shopee-primary);
    background-color: var(--white-color);
}

.ai-send-btn {
    height: 4.2rem;
    padding: 0 2.2rem;
    border-radius: 2.4rem;
    font-size: 1.35rem;
    font-weight: 600;
    gap: 0.6rem;
}

Bước 3: Bổ sung quy tắc Responsive cho Shopee AI Chatbot trong ./assets/css/responsive.css

Trên màn hình Tablet (từ 1023px trở xuống) và Điện thoại (từ 739px trở xuống), chúng ta chuyển bố cục 2 cột sang xếp chồng dọc và hạ lưới sản phẩm trong bong bóng chat xuống 1 cột gọn gàng:

CSS

/* Bổ sung vào cuối khối @media (max-width: 1023px) trong ./assets/css/responsive.css */
    .ai-layout {
        grid-template-columns: 1fr;
    }

    .ai-sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border-subtle, #eeeeee);
    }

/* Bổ sung vào cuối khối @media (max-width: 739px) trong ./assets/css/responsive.css */
    .ai-sidebar,
    .ai-chat-header,
    .ai-chat-body,
    .ai-chat-inputbar {
        padding: 1.4rem;
    }

    .ai-prod-grid {
        grid-template-columns: 1fr;
    }

    .ai-bubble {
        max-width: 100%;
    }

3. Giải mã dòng code: 3 Điểm sáng Kỹ thuật trong Bài 97

  1. Chuyển đổi đồng bộ cả câu hỏi User lẫn câu trả lời AI bằng :has():

    • Ba khối .ai-thread--low, .ai-thread--mid, .ai-thread--high đóng gói trọn vẹn cả tin nhắn của người mua và phản hồi kèm 2 thẻ sản phẩm của AI. Khi bấm chọn mức ngân sách ở cột trái, toàn bộ cuộc hội thoại tự động cập nhật mượt mà như đang trò chuyện trực tiếp với AI thật!
  2. Hiệu ứng 3 chấm đang gõ nhẹ nhàng (.ai-typing-dots):

    • Chỉ dùng transform: translateY(-0.35rem) kết hợp animation-delay: 0.15s và 0.3s trên 3 thẻ <i> nhỏ, không gây reflow bố cục và giữ FPS luôn ổn định.
  3. Bong bóng chat giàu nội dung (.ai-bubble--rich):

    • Kết hợp văn bản tư vấn ngắn gọn với lưới 2 thẻ sản phẩm có nhãn "AI Khuyên Dùng #1" và nút hành động trực tiếp giúp tối ưu trải nghiệm Conversational Shopping.

4. Bài tập trải nghiệm thực tế & Hẹn gặp ở 3 Bài Cuối Cùng (Bài 98–100)!

Hãy lưu lại toàn bộ các file (index.html, main.css, responsive.css) và nhấn F5 trên trình duyệt!

  1. Cuộn tới khu vực TRỢ LÝ ẢO SHOPEE AI CHATBOT (Bài 97):

    • Thử bấm lần lượt 3 mức ngân sách Dưới ₫500.000 →\rightarrow ₫500.000 – ₫1.000.000 →\rightarrow Trên ₫1.000.000 ở cột trái: Quan sát luồng hội thoại và 2 thẻ sản phẩm gợi ý bên phải tự động đổi ngay lập tức!

    • Thử bật Dark Mode (Bài 55) để kiểm tra độ tương phản của bong bóng chat và thẻ sản phẩm nhúng.

Ở Bài 98 (chỉ còn 3 bài nữa là cán đích 100/100!), chúng ta sẽ cùng xây dựng Trang "Shopee Design System & Style Guide" — tổng hợp toàn bộ bảng màu (Color Tokens), Typography, hệ thống nút bấm và Component tái sử dụng của dự án chuẩn Frontend chuyên nghiệp!


All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí