/* THIẾT LẬP BORDER-BOX BẮT BUỘC ĐỂ KHÔNG BỊ TRÀN KHUNG DO PADDING */
#chkv-widget * { box-sizing: border-box !important; }

#chkv-widget { position: fixed; bottom: 30px; right: 30px; z-index: 9999999; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
.chkv-custom-scroll::-webkit-scrollbar { width: 5px; }
.chkv-custom-scroll::-webkit-scrollbar-track { background: transparent; }
.chkv-custom-scroll::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 10px; }
.chkv-custom-scroll::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.3); }

/* Tooltip Mời gọi (Nâng cấp) */
#chkv-welcome-tooltip { position: absolute; bottom: 80px; right: 0; background: #fff; padding: 12px 20px; border-radius: 20px; border-bottom-right-radius: 4px; box-shadow: 0 4px 20px rgba(0,0,0,0.15); font-size: 14px; font-weight: 600; color: #2d3436; white-space: nowrap; opacity: 0; transform: translateY(10px); transition: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); pointer-events: none; z-index: 10;}
#chkv-welcome-tooltip.chkv-show { opacity: 1 !important; transform: translateY(0) !important; pointer-events: auto !important; cursor: pointer;}
#chkv-welcome-tooltip::after { content: ''; position: absolute; bottom: -6px; right: 20px; width: 12px; height: 12px; background: white; transform: rotate(45deg); box-shadow: 4px 4px 5px rgba(0,0,0,0.05); }

/* Nút mở Chat */
#chkv-button { position: relative; width: 65px; height: 65px; border-radius: 50%; background: linear-gradient(135deg, #1976d2, #2196F3); color: white; display: flex; justify-content: center; align-items: center; cursor: pointer; box-shadow: 0 6px 25px rgba(25,118,210,0.4); font-size: 30px; transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); z-index: 11;}
#chkv-button:hover { transform: scale(1.05) translateY(-5px); }
#chkv-button.chkv-hidden { display: none !important; }

#chkv-badge { display: none; position: absolute; top: -3px; right: -3px; background: #e74c3c; color: white; border-radius: 50%; padding: 3px 8px; font-size: 13px; font-weight: bold; border: 2px solid white; box-shadow: 0 2px 5px rgba(0,0,0,0.2); animation: pulseBadge 1.5s infinite; }
@keyframes pulseBadge { 0% { transform: scale(0.95); } 50% { transform: scale(1.1); } 100% { transform: scale(0.95); } }

/* Cửa sổ Chat FIXED LAYOUT (Flexbox) */
#chkv-window { 
    display: flex; flex-direction: column; opacity: 0; visibility: hidden; pointer-events: none; 
    transform: scale(0.9) translateY(20px); transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); 
    width: 360px; height: 620px; max-height: calc(100vh - 120px); 
    background: #fff; border-radius: 20px; box-shadow: 0 15px 50px rgba(0,0,0,0.2); 
    position: fixed; bottom: 110px; right: 30px; overflow: hidden; z-index: 9999999;
    border: 1px solid rgba(0,0,0,0.05); transform-origin: bottom right; 
}
#chkv-window.chkv-show { opacity: 1 !important; visibility: visible !important; pointer-events: auto !important; transform: scale(1) translateY(0) !important; }

.chkv-header { flex: 0 0 auto; background: linear-gradient(135deg, #1976d2, #1565C0); color: white; padding: 25px 20px 20px; text-align: left; display: flex; align-items: center; gap: 15px; position: relative;}
.chkv-header-avatar { position: relative; flex-shrink:0;}
.chkv-online-dot { position: absolute; bottom: 2px; right: 2px; width: 12px; height: 12px; background-color: #00E676; border: 2px solid #1976d2; border-radius: 50%; }

.chkv-header-text { flex: 1; }
.chkv-header-text h3 { margin: 0; font-size: 16px; font-weight: 700; color: #fff;}
.chkv-header-text p { margin: 4px 0 0; font-size: 12px; opacity: 0.9; display: flex; align-items: center; gap: 4px;}
.chkv-status-text-dot { width: 6px; height: 6px; background-color: #00E676; border-radius: 50%; display: inline-block; animation: blink 2s infinite;}
@keyframes blink { 0% { opacity: 1; } 50% { opacity: 0.4; } 100% { opacity: 1; } }

.chkv-header-icons { display: flex; gap: 8px; align-items: center;}
.chkv-icon-action { cursor: pointer; opacity: 0.7; transition: 0.2s; padding: 5px; display: flex; color:white;}
.chkv-icon-action:hover { opacity: 1; transform: scale(1.1);}
.chkv-icon-action.muted { opacity: 0.4; }

/* Pre-chat Form MKT Upgrade */
#chkv-prechat { flex: 1 1 auto; overflow-y: auto; padding: 30px 25px; display: flex; flex-direction: column; gap: 15px; background: #fdfdfd;}
.chkv-bot-greeting { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px;}
.bot-bubble { background: #f1f2f6; padding: 12px 16px; border-radius: 18px; border-top-left-radius: 4px; font-size: 14px; line-height: 1.5; color: #2d3436;}

.chkv-input-group { display: flex; flex-direction: column; gap: 6px; }
.chkv-input-group input { width: 100%; padding: 14px 16px; border: 1px solid #dfe6e9; border-radius: 12px; font-size: 14px; outline: none; transition: 0.2s; background: #fff; margin: 0;}
.chkv-input-group input:focus { border-color: #1976d2; box-shadow: 0 0 0 4px rgba(25,118,210,0.1);}
#chkv-start-btn { margin-top: 10px; padding: 16px; background: #1976d2; color: white; border: none; border-radius: 12px; cursor: pointer; font-weight: bold; font-size: 15px; transition: 0.2s; box-shadow: 0 4px 15px rgba(25,118,210,0.3);}
#chkv-start-btn:hover { background: #1565c0; transform: translateY(-2px);}

/* Khu vực Chat chính */
#chkv-chat-area { flex: 1 1 auto; display: none; flex-direction: column; overflow: hidden; background: #f4f5f7; min-height: 0; }
#chkv-chat-area.chkv-active { display: flex !important; }
.chkv-body { flex: 1 1 auto; overflow-y: auto; padding: 20px; min-height: 0; display: block; }

.chkv-msg-wrap { display: flex; gap: 10px; margin-bottom: 16px; width: 100%; animation: fadeIn 0.3s ease-out forwards; }
.msg-avatar { width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; object-fit: cover; border: 1px solid #eee; background: #fff; display: flex; justify-content: center; align-items: center; }
.msg-avatar.default-admin { background: linear-gradient(135deg, #1976d2, #1565C0); color: white; border: none; }
.msg-avatar.default-customer { background: #95a5a6; color: white; border: none; }
.msg-content { display: flex; flex-direction: column;}
.chkv-msg { padding: 12px 16px; border-radius: 20px; font-size: 14.5px; line-height: 1.4; word-wrap: break-word; max-width: 250px;}

.chkv-msg-wrap.admin { align-items: flex-end; justify-content: flex-start;}
.chkv-msg-wrap.admin .chkv-msg { background: #fff; color: #2d3436; border-bottom-left-radius: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.05);}

.chkv-msg-wrap.customer { justify-content: flex-end;}
.chkv-msg-wrap.customer .msg-content { align-items: flex-end;}
.chkv-msg-wrap.customer .chkv-msg { background: #1976d2; color: #fff; border-bottom-right-radius: 4px; box-shadow: 0 2px 5px rgba(25,118,210,0.2);}

/* Trạng thái Đã xem / Đã gửi */
.chkv-status-text { font-size: 11px; color: #b2bec3; margin-top: 4px; margin-right: 4px;}
.chkv-msg-pending .chkv-msg { opacity: 0.6; }

/* Typing indicator */
.chkv-typing-wrap { display: none; margin-top: 10px; margin-bottom: 0;}
.chkv-typing { display: flex; gap: 4px; padding: 12px 16px; background: #ffffff; border: 1px solid #e1e2e6; border-radius: 18px; width: fit-content; border-bottom-left-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,0.05);}
.chkv-typing span { width: 6px; height: 6px; background: #90949c; border-radius: 50%; animation: chkv-typing-bounce 1.4s infinite ease-in-out both; }
.chkv-typing span:nth-child(1) { animation-delay: -0.32s; }
.chkv-typing span:nth-child(2) { animation-delay: -0.16s; }
@keyframes chkv-typing-bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* Footer */
.chkv-footer { flex: 0 0 auto; padding: 15px; background: white; border-top: 1px solid #eee; display: flex; align-items: center; gap: 10px; }
.chkv-footer input { flex: 1; padding: 14px 20px; border: none; border-radius: 25px; outline: none; font-size: 14px; background: #f1f2f6; transition: 0.2s; margin: 0; box-sizing: border-box;}
.chkv-footer input:focus { background: #e3e6f0;}
.chkv-footer button { width: 45px; height: 45px; flex-shrink:0; border-radius: 50%; background: #1976d2; color: white; border: none; cursor: pointer; display: flex; justify-content: center; align-items: center; transition: 0.2s; padding: 0;}
.chkv-footer button:hover { background: #1565c0; transform: scale(1.05);}

.chkv-powered { flex: 0 0 auto; text-align: center; font-size: 10px; color: #ccc; padding-bottom: 5px; background: white; }