/* AI Chat Widget - CHOGACH.VN */
#cg-ai-chat-root {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9999;
    font-family: inherit;
}

.cg-ai-chat-button {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 1px solid rgba(239, 68, 68, 0.50);
    background: linear-gradient(135deg, #ef4444, #f87171);
    color: #ffffff;

    display: flex;
    align-items: center;
    justify-content: center;

    box-shadow:
        0 18px 40px rgba(239, 68, 68, 0.32),
        0 0 0 0 rgba(239, 68, 68, 0.32);

    cursor: pointer;
    transition: 0.22s ease;
    animation: cgAiChatPulse 2.2s ease-in-out infinite;
}

.cg-ai-chat-button:hover {
    transform: translateY(-2px) scale(1.04);
    background: linear-gradient(135deg, #f87171, #fca5a5);
}

.cg-ai-chat-panel.is-open~.cg-ai-chat-button {
    animation: none;
}

@keyframes cgAiChatPulse {

    0%,
    100% {
        box-shadow:
            0 18px 40px rgba(239, 68, 68, 0.32),
            0 0 0 0 rgba(239, 68, 68, 0.32);
    }

    50% {
        box-shadow:
            0 18px 42px rgba(239, 68, 68, 0.42),
            0 0 0 11px rgba(239, 68, 68, 0);
    }
}

.cg-ai-chat-button .bi {
    font-size: 23px;
    line-height: 1;
}

/* Bong bóng chủ động mời khách bắt đầu hội thoại */
.cg-ai-proactive {
    position: absolute;
    right: 62px;
    bottom: 4px;
    z-index: 2;

    width: min(245px, calc(100vw - 110px));
    min-height: 44px;
    padding: 10px 13px;

    border: 1px solid rgba(226, 232, 240, 0.92);
    border-radius: 14px;

    background: #ffffff;
    color: #0f172a;

    font: inherit;
    font-size: 13px;
    font-weight: 800;
    line-height: 1.4;
    text-align: left;

    box-shadow: 0 12px 34px rgba(15, 23, 42, 0.22);
    cursor: pointer;

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    transform: translateX(8px) scale(0.98);

    transition:
        opacity 0.22s ease,
        visibility 0.22s ease,
        transform 0.22s ease,
        box-shadow 0.22s ease;
}

.cg-ai-proactive::after {
    content: '';
    position: absolute;
    right: -7px;
    bottom: 16px;

    width: 14px;
    height: 14px;

    background: #ffffff;
    border-top: 1px solid rgba(226, 232, 240, 0.92);
    border-right: 1px solid rgba(226, 232, 240, 0.92);

    transform: rotate(45deg);
}

.cg-ai-proactive.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0) scale(1);
}

.cg-ai-proactive:hover {
    box-shadow: 0 14px 38px rgba(15, 23, 42, 0.28);
}

.cg-ai-proactive:focus-visible {
    outline: 2px solid #ef4444;
    outline-offset: 3px;
}

.cg-ai-chat-panel.is-open~.cg-ai-proactive {
    display: none;
}

.cg-ai-chat-panel {
    position: absolute;
    right: 0;
    bottom: 74px;
    width: min(370px, calc(100vw - 24px));
    height: min(560px, calc(100vh - 140px));
    background: #0f172a;
    border: 1px solid rgba(16, 185, 129, 0.55);
    border-radius: 22px;
    box-shadow:
        0 25px 80px rgba(0, 0, 0, 0.55),
        0 0 0 1px rgba(16, 185, 129, 0.08);
    overflow: hidden;
    display: none;
    flex-direction: column;
    resize: both;
    min-width: 340px;
    min-height: 440px;
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 120px);
}

.cg-ai-chat-panel.is-open {
    display: flex;
}

.cg-ai-chat-header {
    padding: 5px 5px;

    background: linear-gradient(135deg,
            #047857,
            #065f46);

    border-bottom: 1px solid rgba(110, 231, 183, 0.35);

    display: flex;
    align-items: center;
    justify-content: space-between;

    box-shadow: 0 6px 18px rgba(5, 150, 105, 0.20);
}

.cg-ai-chat-title {
    color: #ffffff;
}

.cg-ai-chat-status {
    color: #d1fae5;
}

.cg-ai-chat-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cg-ai-chat-avatar {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 50%;
    overflow: hidden;

    background: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.2);
}

.cg-ai-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    padding: 4px;
}

.cg-ai-chat-title {
    font-weight: 900;
    color: #f8fafc;
    font-size: 14px;
}

.cg-ai-chat-status {
    color: #94a3b8;
    font-size: 12px;
    margin-top: 2px;
}

.cg-ai-chat-close {
    border: 0;
    background: rgba(15, 23, 42, 0.75);
    color: #cbd5e1;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    cursor: pointer;
}

.cg-ai-chat-close:hover {
    background: rgba(148, 163, 184, 0.18);
    color: #fff;
}

.cg-ai-chat-messages {
    flex: 1;
    padding: 14px;
    overflow-y: auto;
    background:
        radial-gradient(circle at top left,
            rgba(16, 185, 129, 0.10),
            transparent 32%),
        #111827;
}

.cg-ai-msg {
    max-width: 86%;
    margin-bottom: 10px;
    padding: 10px 12px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.55;
    white-space: pre-wrap;
}

.cg-ai-msg.bot {
    background: rgba(15, 23, 42, 0.95);
    color: #e2e8f0;
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-bottom-left-radius: 5px;
}

.cg-ai-msg.user {
    margin-left: auto;
    background: #10b981;
    color: #020617;
    font-weight: 600;
    border-bottom-right-radius: 5px;
}

.cg-ai-chat-suggestions {
    padding: 5px 5px;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    border-top: 1px solid rgba(15, 23, 42, 0.95);
}

.cg-ai-suggestion {
    flex: 0 0 auto;
    border: 1px solid rgba(16, 185, 129, 0.3);
    background: rgba(16, 185, 129, 0.08);
    color: #a7f3d0;
    border-radius: 999px;
    padding: 7px 11px;
    font-size: 12px;
    cursor: pointer;
}

.cg-ai-suggestion:hover {
    background: rgba(16, 185, 129, 0.16);
}

.cg-ai-chat-form {
    padding: 9px;
    display: flex;
    gap: 8px;
    border-top: 1px solid rgba(16, 185, 129, 0.16);
    background: #0f172a;
}

.cg-ai-chat-input {
    flex: 1;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: #0f172a;
    color: #f8fafc;
    border-radius: 14px;
    padding: 11px 12px;
    font-size: 13px;
    outline: none;
}

.cg-ai-chat-input:focus {
    border-color: rgba(16, 185, 129, 0.75);
}

.cg-ai-chat-send {
    width: 44px;
    border: 0;
    border-radius: 14px;
    background: #10b981;
    color: #020617;
    cursor: pointer;
    font-weight: 900;
}

.cg-ai-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.cg-ai-typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.cg-ai-typing i {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 999px;
    animation: cgAiTyping 1s infinite ease-in-out;
}

#cg-ai-typing {
    padding: 5px 8px;
    margin-bottom: 5px;
    line-height: 1;
    border-radius: 10px;
}

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

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

.cg-ai-chat-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.cg-ai-chat-fullscreen {
    border: 0;
    background: rgba(15, 23, 42, 0.75);
    color: #cbd5e1;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    cursor: pointer;
}

.cg-ai-chat-fullscreen:hover {
    background: rgba(148, 163, 184, 0.18);
    color: #fff;
}

.cg-ai-chat-panel.is-fullscreen {
    position: fixed;
    inset: 12px;
    right: 12px;
    bottom: 12px;
    width: auto !important;
    height: auto !important;
    max-width: none;
    max-height: none;
    resize: none;
    z-index: 10000;
}

.cg-ai-chat-panel {
    resize: none;
}

.cg-ai-chat-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 25px;
    height: 25px;
    z-index: 3;
    border: 0;
    border-radius: 22px 0 10px 0;
    background: rgba(16, 185, 129, 0.16);
    color: #6ee7b7;
    cursor: nwse-resize;
    font-size: 17px;
    line-height: 1;
    touch-action: none;
    user-select: none;
}

.cg-ai-chat-resize-handle:hover {
    background: rgba(16, 185, 129, 0.28);
    color: #ffffff;
}

.cg-ai-chat-header {
    position: relative;
}

.cg-ai-chat-brand {
    margin-left: 20px;
}

.cg-ai-chat-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;

    margin-top: 5px;
    padding: 7px 11px;

    border-radius: 8px;
    background: #eef7f1;
    border: 1px solid #b8dfc6;

    color: #167340;
    font-weight: 600;
    font-size: 13px;
    line-height: 1.3;

    text-decoration: none;
    transition: 0.2s ease;
}

.cg-ai-chat-link:hover {
    background: #dff1e5;
    color: #0d5f32;
    text-decoration: none;
}

.cg-ai-chat-link:focus-visible {
    outline: 2px solid #22c55e;
    outline-offset: 2px;
}

/* Danh sách sản phẩm dạng grid trong phản hồi AI */
.cg-ai-product-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));

    margin-top: 8px;
    justify-items: start;
}

.cg-ai-product-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 7px;
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.72);
    text-decoration: none;
    color: inherit;
    overflow: hidden;
}

.cg-ai-product-card:hover {
    border-color: rgba(16, 185, 129, 0.5);
    background: rgba(16, 185, 129, 0.08);
}

.cg-ai-product-image {
    width: 100%;
    height: 92px;
    display: block;
    object-fit: cover;
    border-radius: 7px;
    background: #0f172a;
}

.cg-ai-product-info {
    min-width: 0;
    padding-top: 6px;
}

.cg-ai-product-name {
    color: #f8fafc;
    font-size: 11px;
    font-weight: 800;
    line-height: 1.35;

    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

.cg-ai-product-meta {
    margin-top: 4px;
    color: #94a3b8;
    font-size: 10px;
    line-height: 1.35;

    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

@media (max-width: 380px) {
    .cg-ai-product-list {
        grid-template-columns: 1fr;
    }

    .cg-ai-product-image {
        height: 110px;
    }
}

@keyframes cgAiTyping {

    0%,
    80%,
    100% {
        opacity: 0.35;
        transform: translateY(0);
    }

    40% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

@media (max-width: 640px) {

    #cg-ai-chat-root {
        right: 20px;
        bottom: 20px;
    }

    .cg-ai-chat-panel {
        right: 0;
        bottom: 60px;
        width: calc(100vw - 24px);
        height: min(560px, calc(100vh - 120px));
    }

}

.cg-ai-call-button {
    position: absolute;
    right: 0;
    bottom: 62px;

    width: 50px;
    height: 50px;
    box-sizing: border-box;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 50%;
    border: 1px solid rgba(249, 115, 22, 0.45);

    background: linear-gradient(135deg, #f97316, #fb923c);
    color: #ffffff;
    text-decoration: none;

    box-shadow: 0 18px 40px rgba(249, 115, 22, 0.28);

    cursor: pointer;
    transition: 0.22s ease;
}

.cg-ai-call-button:hover {
    transform: translateY(-2px) scale(1.04);
    background: linear-gradient(135deg, #fb923c, #fdba74);
}

.cg-ai-call-button .material-symbols-rounded {
    font-size: 24px;
    line-height: 1;
}

.cg-ai-chat-panel.is-open~.cg-ai-call-button {
    display: none;
}

.cg-ai-zalo-button {
    position: absolute;
    right: 0;
    bottom: 124px;

    width: 50px;
    height: 50px;
    box-sizing: border-box;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 50%;
    border: 1px solid rgba(0, 104, 255, 0.45);

    background: linear-gradient(135deg, #0068ff, #2f80ff);
    color: #ffffff;
    text-decoration: none;

    box-shadow: 0 18px 40px rgba(0, 104, 255, 0.28);

    cursor: pointer;
    transition: 0.22s ease;

    font-size: 10px;
    font-weight: 900;
    line-height: 1;
}

.cg-ai-zalo-button:hover {
    transform: translateY(-2px) scale(1.04);
    background: linear-gradient(135deg, #1677ff, #5a9cff);
}

.cg-ai-zalo-button span {
    display: block;
    line-height: 1;
}

.cg-ai-chat-panel.is-open~.cg-ai-zalo-button {
    display: none;
}

.cg-ai-chat-button .bi-robot {
    font-size: 26px;
    line-height: 1;
}

.cg-ai-chat-mic {
    position: relative;

    width: 44px;
    min-width: 44px;
    height: 44px;

    border: 0;
    border-radius: 14px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: #334155;
    color: #f8fafc;

    cursor: pointer;

    user-select: none;
    -webkit-user-select: none;

    -webkit-touch-callout: none;
    touch-action: none;

    -webkit-tap-highlight-color: transparent;

    transition:
        background 0.2s ease,
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.cg-ai-chat-mic * {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    pointer-events: none;
}

.cg-ai-chat-mic:hover {
    background: #475569;
}

.cg-ai-chat-mic.recording {
    background: #ef4444;
    color: #ffffff;

    transform: scale(1.08);

    box-shadow:
        0 0 0 6px rgba(239, 68, 68, 0.18),
        0 8px 24px rgba(239, 68, 68, 0.35);

    animation: cgAiMicPulse 0.9s infinite;
}

.cg-ai-chat-mic .cg-ai-mic-icon {
    font-size: 22px;
    line-height: 1;
}

.cg-ai-mic-label {
    position: absolute;

    right: 52px;
    top: 50%;
    transform: translateY(-50%) translateX(5px);

    padding: 8px 11px;
    border-radius: 10px;

    background: rgba(239, 68, 68, 0.96);
    color: #ffffff;

    font-size: 12px;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.35);

    transition:
        opacity 0.18s ease,
        visibility 0.18s ease,
        transform 0.18s ease;
}

.cg-ai-chat-mic.recording .cg-ai-mic-label {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) translateX(0);
}

.cg-ai-chat-mic:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

@keyframes cgAiMicPulse {

    0%,
    100% {
        box-shadow:
            0 0 0 4px rgba(239, 68, 68, 0.15),
            0 8px 24px rgba(239, 68, 68, 0.3);
    }

    50% {
        box-shadow:
            0 0 0 10px rgba(239, 68, 68, 0.05),
            0 8px 28px rgba(239, 68, 68, 0.42);
    }
}

/* ========================================================
   NÚT NGHE PHẢN HỒI AI
======================================================== */

.cg-ai-msg-content {
    min-width: 0;
}

.cg-ai-msg-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
}

.cg-ai-speak-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;

    min-height: 28px;
    padding: 4px 9px;

    border: 1px solid rgba(16, 185, 129, 0.32);
    border-radius: 999px;

    background: rgba(16, 185, 129, 0.08);
    color: #a7f3d0;

    font-size: 11px;
    font-weight: 700;
    line-height: 1;

    cursor: pointer;
    transition:
        background 0.18s ease,
        border-color 0.18s ease,
        color 0.18s ease,
        transform 0.18s ease;
}

.cg-ai-speak-btn .material-symbols-rounded {
    font-size: 16px;
    line-height: 1;
}

.cg-ai-speak-btn:hover {
    border-color: rgba(16, 185, 129, 0.72);
    background: rgba(16, 185, 129, 0.18);
    color: #ecfdf5;
    transform: translateY(-1px);
}

.cg-ai-speak-btn.is-speaking {
    border-color: #10b981;
    background: #10b981;
    color: #020617;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
}

.cg-ai-speak-btn:disabled {
    cursor: not-allowed;
    opacity: 0.4;
}

.cg-ai-msg.user .cg-ai-msg-actions {
    display: none;
}

@media (max-width: 640px) {
    .cg-ai-speak-btn {
        min-height: 30px;
        padding: 5px 10px;
    }
}

.cg-ai-speak-btn.is-loading {
    opacity: 0.75;
    cursor: wait;
}

@media (prefers-reduced-motion: reduce) {

    .cg-ai-chat-button,
    .cg-ai-chat-mic.recording {
        animation: none !important;
    }

    .cg-ai-proactive {
        transition: none;
    }
}