/**
 * CHAT BUBBLE N8N - CSS
 * Version: 2.8 - Added Welcome Screen
 */

/* -- Bong bóng chat -- */
#cbn8n-bubble {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background-color: #2563eb;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9998;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#cbn8n-bubble:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.5);
}

#cbn8n-bubble img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* -- Cửa sổ chat chính -- */
#cbn8n-window {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 320px;
    max-width: 90vw;
    height: 400px; /* Chiều cao cố định để layout ổn định */
    max-height: 75vh;
    background-color: #ffffff;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    box-sizing: border-box;
}

/* -- Header -- */
#cbn8n-header {
    background-color: #2563eb;
    color: white;
    height: 54px !important; 
    min-height: 54px !important;
    padding: 0 16px !important;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    flex-shrink: 0; /* Không bị co lại */
}

.cbn8n-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 16px;
    line-height: 1;
}

.cbn8n-header-left strong {
    color: white !important;
    font-family: inherit;
    margin: 0;
    padding: 0;
}

#cbn8n-close-btn {
    background: transparent !important;
    border: none !important;
    color: white !important;
    font-size: 24px !important;
    line-height: 1 !important;
    cursor: pointer;
    padding: 0 !important;
    margin: 0 !important;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.9;
    transition: opacity 0.2s;
    box-shadow: none !important;
}

#cbn8n-close-btn:hover {
    opacity: 1;
}

/* ========================================
   NEW: WELCOME SCREEN
   ======================================== */
#cbn8n-welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px 20px;
    text-align: center;
    background-color: #fff;
}

.cbn8n-welcome-avatar {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    border: 3px solid #fff;
}

.cbn8n-welcome-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cbn8n-welcome-title {
    font-size: 20px;
    font-weight: 700;
    color: #1f2937;
    margin: 0 0 10px 0 !important;
}

.cbn8n-welcome-text {
    font-size: 14px;
    color: #6b7280;
    margin: 0 0 25px 0 !important;
    line-height: 1.5;
    max-width: 280px;
}

#cbn8n-connect-btn {
    background-color: #2563eb;
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 50px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background-color 0.2s, transform 0.1s;
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2);
}

#cbn8n-connect-btn:hover {
    background-color: #1d4ed8;
    transform: translateY(-1px);
}

#cbn8n-connect-btn:active {
    transform: translateY(1px);
}

/* ========================================
   CHAT INTERFACE CONTAINER
   ======================================== */
#cbn8n-chat-interface {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100%;
    overflow: hidden; /* Quan trọng để scrollbar hoạt động đúng */
}

/* -- Khu vực tin nhắn -- */
#cbn8n-messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#cbn8n-messages::-webkit-scrollbar {
    width: 6px;
}
#cbn8n-messages::-webkit-scrollbar-thumb {
    background-color: #e0e0e0;
    border-radius: 3px;
}

.cbn8n-message {
    padding: 10px 16px;
    border-radius: 18px;
    max-width: 85%;
    line-height: 1.5;
    word-wrap: break-word;
    font-size: 14px;
}

.bot-message {
    background-color: #f3f4f6;
    color: #1f2937;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.user-message {
    background-color: #2563eb;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* -- Khu vực nhập liệu -- */
#cbn8n-input-container {
    padding: 15px 20px 20px 20px;
    background-color: #fff;
    border-top: 1px solid #f0f0f0;
    position: relative;
    box-sizing: border-box;
    flex-shrink: 0; /* Không bị co lại */
}

.cbn8n-input-wrapper {
    position: relative;
    width: 100%;
    height: 44px;
    display: flex;
    align-items: center;
}

#cbn8n-input {
    width: 100%;
    height: 100% !important;
    border: 1px solid #d1d5db !important;
    border-radius: 22px !important;
    padding: 0 45px 0 20px !important;
    font-size: 14px !important;
    outline: none;
    color: #374151;
    background: #fff !important;
    box-shadow: none !important;
    margin: 0 !important;
    line-height: normal !important;
}

#cbn8n-input:focus {
    border-color: #2563eb !important;
}

#cbn8n-send-btn {
    position: absolute !important;
    right: 6px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 32px !important;
    height: 32px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10;
    box-shadow: none !important;
}

#cbn8n-send-btn:hover {
    background-color: #f3f4f6 !important;
}

#cbn8n-send-btn svg {
    width: 20px;
    height: 20px;
    stroke: #9ca3af;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: stroke 0.2s;
    display: block;
}

#cbn8n-input:focus + #cbn8n-send-btn svg,
#cbn8n-send-btn:hover svg {
    stroke: #2563eb;
}

/* Style phụ trợ */
.cbn8n-message-image {
    max-width: 100%;
    border-radius: 12px;
    margin-top: 5px;
    cursor: pointer;
}

.cbn8n-typing-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #6b7280;
    margin: 0 2px;
    animation: cbn8n-blink 1.4s infinite both;
}
@keyframes cbn8n-blink {
    0% { opacity: 0.2; }
    20% { opacity: 1; }
    100% { opacity: 0.2; }
}