/* CiCC AI Chat Widget — Floating Button + Modal */
:root {
    --cicc-primary: #1a237e;
    --cicc-primary-light: #283593;
    --cicc-bg: #ffffff;
    --cicc-bg-bot: #f0f4ff;
    --cicc-bg-user: #1a237e;
    --cicc-text: #1e293b;
    --cicc-text-light: #64748b;
    --cicc-border: #e2e8f0;
    --cicc-shadow: 0 4px 24px rgba(0,0,0,.12);
    --cicc-radius: 16px;
    --cicc-max-width: 400px;
}

/* FAB Group — 1 nút Chat AI, thẳng hàng với Back to Top */
.cicc-fab-group {
    position: fixed;
    right: 20px;              /* Cùng right với back-to-top của theme */
    bottom: 105px;            /* Dời lên trên cho back-to-top lộ ra (theme: bottom:40px) */
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 8px;
    z-index: 999999;
}
.cicc-fab {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    font-size: 22px;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
    cursor: pointer;
    transition: transform .2s, box-shadow .2s;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.cicc-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
/* Tooltip gợi ý xoay vòng */
.cicc-tooltip {
    position: absolute;
    right: 68px;
    bottom: 8px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 8px 16px;
    white-space: nowrap;
    font-size: 13px;
    color: #1e293b;
    box-shadow: 0 4px 16px rgba(0,0,0,.1);
    cursor: pointer;
    animation: cicc-tip-in .4s ease;
    z-index: 999998;
    user-select: none;
    transition: opacity .3s;
}
.cicc-tooltip:hover {
    background: #f0f4ff;
    border-color: #1a237e;
}
.cicc-tooltip-arrow {
    position: absolute;
    right: -8px;
    bottom: 12px;
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-left: 8px solid #e2e8f0;
}
.cicc-tooltip-arrow::after {
    content: '';
    position: absolute;
    top: -7px;
    left: -9px;
    width: 0;
    height: 0;
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
    border-left: 7px solid #fff;
}
@keyframes cicc-tip-in {
    from { opacity: 0; transform: translateX(10px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Chat — nổi bật nhất */
.cicc-fab-chat {
    background: linear-gradient(135deg, #1a237e, #283593);
    color: #fff;
    width: 58px;
    height: 58px;
    font-size: 24px;
}
.cicc-fab-chat.active {
    box-shadow: 0 4px 16px rgba(26,35,126,.4);
}

/* Modal */
.cicc-ai-modal {
    position: fixed;
    bottom: 175px;             /* Phía trên FAB (105px) + khoảng cách */
    right: 20px;               /* Cùng right với FAB + back-to-top */
    width: var(--cicc-max-width);
    max-height: 600px;
    background: var(--cicc-bg);
    border-radius: var(--cicc-radius);
    box-shadow: var(--cicc-shadow);
    z-index: 999998;
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.cicc-ai-modal.show {
    display: flex;
    animation: cicc-slide-up .3s ease;
}
@keyframes cicc-slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Header */
.cicc-ai-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: linear-gradient(135deg, #1a237e, #283593);
    color: #fff;
}
.cicc-ai-title {
    font-weight: 600;
    font-size: 15px;
}
.cicc-ai-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.cicc-ai-status {
    font-size: 10px;
    color: #22c55e;
}
.cicc-ai-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    opacity: .8;
}
.cicc-ai-close:hover { opacity: 1; }

/* Messages area */
.cicc-ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
    min-height: 300px;
    max-height: 450px;
}

/* Individual message */
.cicc-ai-msg {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    animation: cicc-msg-in .3s ease;
}
@keyframes cicc-msg-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.cicc-ai-msg-user {
    flex-direction: row-reverse;
}
.cicc-ai-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.cicc-ai-msg-bot .cicc-ai-avatar {
    background: #e0e7ff;
}
.cicc-ai-msg-user .cicc-ai-avatar {
    background: #1a237e;
}
.cicc-ai-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--cicc-text);
    white-space: pre-wrap;
    word-break: break-word;
}
.cicc-ai-msg-bot .cicc-ai-bubble {
    background: var(--cicc-bg-bot);
    border-bottom-left-radius: 4px;
}
.cicc-ai-msg-user .cicc-ai-bubble {
    background: var(--cicc-bg-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Streaming cursor */
.cicc-ai-streaming .cicc-ai-bubble::after {
    content: '▌';
    animation: cicc-blink .8s infinite;
}
@keyframes cicc-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Input area */
.cicc-ai-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--cicc-border);
    background: var(--cicc-bg);
}
.cicc-ai-input {
    flex: 1;
    border: 1px solid var(--cicc-border);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    resize: none;
    font-family: inherit;
    line-height: 1.4;
    max-height: 120px;
}
.cicc-ai-input:focus {
    border-color: var(--cicc-primary);
}
.cicc-ai-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--cicc-primary);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cicc-ai-send:disabled {
    opacity: .4;
    cursor: not-allowed;
}
.cicc-ai-send:not(:disabled):hover {
    background: var(--cicc-primary-light);
}

/* Typing indicator */
.cicc-ai-typing {
    display: none;
}
.cicc-ai-typing.active {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    background: var(--cicc-bg-bot);
    border-radius: 12px;
    width: fit-content;
    margin-bottom: 16px;
    margin-left: 42px;
}
.cicc-ai-typing span {
    width: 8px;
    height: 8px;
    background: var(--cicc-text-light);
    border-radius: 50%;
    animation: cicc-bounce 1.4s infinite ease-in-out;
}
.cicc-ai-typing span:nth-child(1) { animation-delay: 0s; }
.cicc-ai-typing span:nth-child(2) { animation-delay: .2s; }
.cicc-ai-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes cicc-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Responsive */
@media (max-width: 480px) {
    .cicc-ai-modal {
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
    .cicc-fab-group {
        bottom: 16px;
        right: 12px;
    }
    .cicc-ai-modal {
        right: 12px;
        bottom: 145px;
    }
}
