/* ================================Chatbot UI — Clean Modern Edition================================*/
:root {
    --accent-1: #6f46c6;
    --accent-2: #b794f4;
    --accent-3: #ff6b81;
    --muted: #8892a7;
    --radius: 14px;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    font-family: Inter, system-ui, sans-serif;
}

/* ======================= Floating Launcher Button ======================= */
.chatbot-launcher {
    position: fixed !important;
    right: 20px;
    bottom: 20px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow);
    z-index: 999999999;
    transition: transform .2s ease, opacity .2s ease;
}

.chatbot-launcher:hover {
    transform: translateY(-4px);
}

/* ======================= Chat Popup Panel ======================= */
/* Responsive chatbot panel — replace the old .chatbot block */
.chatbot {
    position: fixed !important;
    right: 20px;
    bottom: 20px;
    /* giữ khoảng cách an toàn với launcher */
    width: min(420px, calc(100% - 40px));
    /* tối đa 420px, nhưng co lại trên màn nhỏ */
    max-width: calc(100% - 40px);
    height: auto;
    max-height: 80vh;
    /* không vượt quá 80% chiều cao màn */
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    border-radius: var(--radius);
    border: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999999998;

    /* animation / smooth visibility */
    transition: transform .22s cubic-bezier(.2, .9, .3, 1), opacity .18s ease;
    transform-origin: bottom right;
    will-change: transform, opacity;
}

/* Hidden state via aria (no display:none): preserves layout & avoids reflow */
.chatbot[aria-hidden="true"] {
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px) scale(.995);
}

/* Visible state */
.chatbot[aria-hidden="false"] {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* ======================= Header ======================= */
.chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.6);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.chatbot-header>div {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.chatbot-header .title {
    font-size: 16px;
    font-weight: 700;
    color: #111;
}

.chatbot-header .subtitle {
    font-size: 13px;
    color: var(--muted);
}

/* Close button */
.close-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.12);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease;
    margin-left: auto;
}

.close-btn:hover {
    background: #f1f1f1;
}

/* ======================= Messages Body ======================= */
.chatbot-body {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chatbot-empty {
    text-align: center;
    padding: 28px 0;
    color: var(--muted);
}

/* Message container */
.chatbot-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.user-message {
    justify-content: flex-end;
}

.message-icon {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
}

.message-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.45;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

.user-message .message-bubble {
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    color: white;
    border: none;
    box-shadow: 0 4px 16px rgba(111, 70, 198, 0.18);
}

/* Typing indicator */
.typing-indicator span {
    width: 6px;
    height: 6px;
    display: inline-block;
    background: #cbd5e1;
    border-radius: 999px;
    animation: blink 1s infinite;
    margin-right: 4px;
}

.typing-indicator span:nth-child(2) {
    animation-delay: .15s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: .3s;
}

@keyframes blink {

    0%,
    100% {
        opacity: .2;
    }

    50% {
        opacity: 1;
    }
}

/* ======================= Footer Input ======================= */
.chatbot-footer {
    padding: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    gap: 10px;
    background: rgba(255, 255, 255, 0.6);
}

.chat-input {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    resize: none;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    background: #fff;
}

.chat-send {
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    color: white;
    border: none;
    border-radius: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(111, 70, 198, 0.2);
}

/* ======================= Mobile ======================= */
/* Mobile tweak: nếu bạn dùng left/right 5px trên mobile, nó sẽ vẫn được override bởi media query */
@media (max-width: 640px) {
    .chatbot {
        left: 5px !important;
        right: 5px !important;
        width: auto !important;
        max-width: none !important;
        bottom: 5px !important;
        max-height: 70vh !important;
        border-radius: 16px 16px 0 0 !important;
    }
}

/* ======================= Dark Mode ======================= */
@media (prefers-color-scheme: dark) {
    .chatbot {
        background: rgba(14, 16, 22, 0.9);
        border: 1px solid rgba(255, 255, 255, 0.05);
    }

    .chatbot-header .title {
        color: white;
    }

    .chatbot-header .subtitle {
        color: var(--muted);
    }

    .message-bubble {
        background: #0f1a2b;
        border-color: rgba(255, 255, 255, 0.06);
        color: #dce7ff;
        box-shadow: none;
    }

    .user-message .message-bubble {
        background: linear-gradient(135deg, #5334b8, #8d74e6);
    }

    .chat-input {
        background: rgba(255, 255, 255, 0.07);
        border-color: rgba(255, 255, 255, 0.08);
        color: #e9eeff;
    }
}