/* ============================================================================
   UI3 - CHATBOX CSS
   Tubi AI PP2 Plugin
   
   Đường dẫn: tubi-ai-pp-2/ui3/css/ui3-chatbox.css
   ============================================================================ */

/* ========== WRAPPER ========== */
.tubi-ui3-wrap { 
    position: fixed; 
    bottom: 20px; 
    right: 20px; 
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ========== NÚT TOGGLE ========== */
.tubi-ui3-toggle {
    width: 48px; 
    height: 48px; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    background: #0000B3; 
    border: none; 
    border-radius: 50%;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25); 
    cursor: pointer; 
    transition: transform 0.3s ease;
    will-change: transform;
    position: relative;
}
.tubi-ui3-toggle::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.tubi-ui3-toggle:hover {
    transform: scale(1.05);
}
.tubi-ui3-toggle:hover::after {
    opacity: 1;
}
.tubi-ui3-wrap.is-open .tubi-ui3-toggle { 
    display: none; 
}
.tubi-ui3-toggle svg { 
    width: 24px; 
    height: 24px; 
    fill: white; 
}

/* ========== FIX NÚT TOGGLE - OVERRIDE THEME HELLO ========== */
/* Theme Hello ghi đè: border: 1px solid #c36 (màu đỏ ghê!) */
button.tubi-ui3-toggle,
.tubi-ui3-wrap button.tubi-ui3-toggle {
    width: 48px !important;
    height: 48px !important;
    border: none !important;
    border-radius: 50% !important;
    background: #0000B3 !important;  /* Xanh dương cờ Phật */
}

button.tubi-ui3-toggle svg,
.tubi-ui3-wrap button.tubi-ui3-toggle svg {
    width: 24px !important;
    height: 24px !important;
    position: relative !important;
    display: block !important;
}

/* ========== CHATBOX ========== */
.tubi-ui3-chatbox {
    width: 320px; 
    height: 500px; 
    background: white; 
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    display: none; 
    flex-direction: column; 
    overflow: hidden;
    overflow-x: hidden;
    pointer-events: auto;
}
.tubi-ui3-wrap.is-open .tubi-ui3-chatbox { 
    display: flex; 
}

/* ========== HEADER - TWITTER BLUE ========== */
.tubi-ui3-header {
    display: flex; 
    align-items: center; 
    justify-content: space-between;
    padding: 12px 16px; 
    background: #1DA1F2;
    color: white; 
}
.tubi-ui3-header-info { 
    display: flex; 
    align-items: center; 
    gap: 10px; 
}
.tubi-ui3-avatar { 
    width: 36px; 
    height: 36px; 
    background: white; 
    border-radius: 50%; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    overflow: hidden;
}
.tubi-ui3-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.tubi-ui3-title { 
    font-size: 18px; 
    font-weight: 700; 
    line-height: 1;
}
.tubi-ui3-close { 
    width: 32px; 
    height: 32px; 
    background: rgba(255,255,255,0.2); 
    border: none; 
    border-radius: 50%; 
    color: white; 
    font-size: 20px; 
    cursor: pointer; 
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.tubi-ui3-close:hover {
    background: rgba(255,255,255,0.3);
}

/* ========== FIX NÚT ĐÓNG - OVERRIDE THEME HELLO ========== */
/* Theme Hello ghi đè: button { border: 1px solid #c36; border-radius: 3px; }
   Cần !important để override */
#tubi-ui3-chatbox .tubi-ui3-close,
.tubi-ui3-wrap .tubi-ui3-close {
    border: none !important;
    border-radius: 50% !important;
    background: rgba(255,255,255,0.2) !important;
    width: 32px !important;
    height: 32px !important;
    padding: 0 !important;
}

#tubi-ui3-chatbox .tubi-ui3-close:hover,
.tubi-ui3-wrap .tubi-ui3-close:hover {
    background: rgba(255,255,255,0.3) !important;
    border: 1px solid rgba(255,255,255,0.5) !important;
}

/* ========== MESSAGES ========== */
.tubi-ui3-messages { 
    flex: 1; 
    overflow-y: auto; 
    overflow-x: hidden;
    padding: 16px; 
    background: #FAFAFA; 
}
.tubi-ui3-message { 
    display: flex; 
    gap: 8px; 
    margin-bottom: 16px; 
}
.tubi-ui3-message-avatar { 
    width: 32px; 
    height: 32px; 
    background: white; 
    border-radius: 50%; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}
.tubi-ui3-message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.tubi-ui3-message-bubble { 
    max-width: 75%; 
    padding: 10px 14px; 
    border-radius: 18px; 
    font-size: 16px; 
    line-height: 1.5; 
}
.tubi-ui3-message-bot .tubi-ui3-message-bubble { 
    background: #E8E8E8; 
    color: #333; 
    border-bottom-left-radius: 4px;
    max-width: calc(100% - 40px); /* Rộng bằng user, trừ avatar */
}
.tubi-ui3-message-user { 
    flex-direction: row-reverse; 
}
.tubi-ui3-message-user .tubi-ui3-message-bubble { 
    background: #1DA1F2;
    color: white; 
    border-bottom-right-radius: 4px;
}

/* ========== INPUT AREA ========== */
.tubi-ui3-input-area { 
    padding: 12px 16px; /* Giảm padding-bottom vì counter đã lên header */
    background: white; 
    border-top: 1px solid #E0E0E0; 
}
.tubi-ui3-input-wrapper { 
    display: flex; 
    gap: 10px; 
    align-items: flex-end; 
}
.tubi-ui3-input-container {
    flex: 1;
    position: relative;
}
.tubi-ui3-input { 
    width: 100%;
    min-height: 44px; 
    max-height: 100px;
    padding: 10px 16px; 
    border: 1px solid #E0E0E0; 
    border-radius: 22px; 
    font-size: 16px; 
    resize: none; 
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}
.tubi-ui3-input:focus {
    border-color: #1DA1F2;
}
.tubi-ui3-input.is-over-limit {
    border-color: #FF0000;
}
.tubi-ui3-input::placeholder {
    color: #999;
}
/* ========== BỘ ĐẾM KÝ TỰ ========== */
/* Di chuyển lên header (sau chữ "Lìinh") */
.tubi-ui3-header .tubi-ui3-char-counter {
    position: relative;
    display: inline-block;
    margin-left: 8px;
    font-size: 12px;
    color: rgba(255,255,255,0.8);
    font-weight: 400;
    vertical-align: middle;
    line-height: 1;
}

.tubi-ui3-header .tubi-ui3-char-counter.is-warning {
    color: #FFFF00;
    font-weight: 600;
}

.tubi-ui3-header .tubi-ui3-char-counter.is-over {
    color: #FF0000;
    font-weight: 700;
}

/* Ẩn counter cũ ở input (nếu vẫn còn trong DOM ban đầu) */
.tubi-ui3-input-container .tubi-ui3-char-counter {
    display: none;
}
.tubi-ui3-send { 
    width: 44px; 
    height: 44px; 
    background: #1DA1F2;
    border: none; 
    border-radius: 50%; 
    color: white; 
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, opacity 0.2s, transform 0.2s;
    will-change: transform;
}
.tubi-ui3-send:hover {
    background: #1a91da;
}

/* ========== FIX NÚT GỬI - OVERRIDE THEME HELLO ========== */
/* Theme Hello ghi đè: button { border-radius: 3px; border: 1px solid #c36; }
   Override + size cân bằng với textarea (44px) - Tăng specificity */
button#tubi-ui3-send,
#tubi-ui3-chatbox button.tubi-ui3-send,
.tubi-ui3-wrap button.tubi-ui3-send,
#tubi-ui3-chatbox .tubi-ui3-send,
.tubi-ui3-wrap .tubi-ui3-send {
    width: 44px !important;  /* ✅ Tăng từ 36px → 44px để cân bằng với textarea */
    height: 44px !important;  /* ✅ Tăng từ 36px → 44px để cân bằng với textarea */
    border-radius: 50% !important;
    border: none !important;
    background: #1DA1F2 !important;
    padding: 0 !important;
}

/* Hover - chỉ đổi màu xanh nhạt, KHÔNG đổi 5 màu */
button#tubi-ui3-send:hover,
#tubi-ui3-chatbox button.tubi-ui3-send:hover,
.tubi-ui3-wrap button.tubi-ui3-send:hover {
    background: #1a91da !important;
    transform: scale(1.05) !important;
}

/* Icon SVG đổi 5 màu CỜ PHẬT khi đang gửi (is-processing) */
.tubi-ui3-send.is-processing svg {
    animation: icon-rainbow 2s ease-in-out infinite;
}

@keyframes icon-rainbow {
    0%   { fill: #0000B3; } /* Xanh dương - Universal Compassion */
    20%  { fill: #FFFF00; } /* Vàng - Middle Path */
    40%  { fill: #FF0000; } /* Đỏ - Blessings */
    60%  { fill: #FFFFFF; } /* Trắng - Purity */
    80%  { fill: #FF8C00; } /* Cam - Wisdom */
    100% { fill: #FF8C00; }
}

/* Disabled state - giữ nguyên màu xám */
button#tubi-ui3-send:disabled,
#tubi-ui3-chatbox button.tubi-ui3-send:disabled,
.tubi-ui3-wrap button.tubi-ui3-send:disabled,
#tubi-ui3-chatbox .tubi-ui3-send:disabled,
.tubi-ui3-wrap .tubi-ui3-send:disabled {
    background: #CCCCCC !important;
    transform: none !important;
    box-shadow: none !important;
}
.tubi-ui3-send svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* ========== TRẠNG THÁI ĐANG XỬ LÝ ========== */
.tubi-ui3-send.is-processing {
    pointer-events: none;
}

/* ========== RESPONSIVE MOBILE ========== */
@media (max-width: 480px) {
    .tubi-ui3-wrap {
        bottom: 15px;
        right: 15px;
    }
    .tubi-ui3-wrap.is-open {
        bottom: 10px;
        right: 10px;
        left: 10px;
        top: auto;
    }
    .tubi-ui3-chatbox {
        width: calc(100vw - 20px);
        height: auto;
        max-height: 80vh;
        min-height: 300px;
        border-radius: 16px;
        position: relative;
        /* KHÔNG set display ở đây - giữ display: none mặc định */
    }
    .tubi-ui3-wrap.is-open .tubi-ui3-chatbox {
        display: flex;
        flex-direction: column;
    }
    .tubi-ui3-header {
        flex-shrink: 0;
    }
    .tubi-ui3-messages {
        flex: 1;
        min-height: 150px;
        max-height: calc(80vh - 130px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 10px;
    }
    .tubi-ui3-input-area {
        padding: 10px 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        background: #F8F9FA;
        flex-shrink: 0;
        border-top: 1px solid #E0E0E0;
        border-radius: 0 0 16px 16px;
    }
    .tubi-ui3-input {
        font-size: 22px; /* Tăng cỡ chữ để dễ nhìn */
        max-height: 60px;
    }
    .tubi-ui3-input-container {
        position: relative;
    }
    .tubi-ui3-char-counter {
        position: absolute;
        bottom: -16px;
        right: 5px;
        font-size: 11px;
    }
    .tubi-ui3-message-bubble {
        font-size: 22px;
        line-height: 1.5;
    }
}
