/* ============================================================================
   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: 60px; 
    height: 60px; 
    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: all 0.3s ease;
}
.tubi-ui3-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}
.tubi-ui3-wrap.is-open .tubi-ui3-toggle { 
    display: none; 
}
.tubi-ui3-toggle svg { 
    width: 32px; 
    height: 32px; 
    fill: white; 
}

/* ========== 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; 
}
.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);
}

/* ========== 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 24px 16px; /* Thêm padding bottom cho counter */
    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;
}
.tubi-ui3-char-counter {
    position: absolute;
    bottom: -18px;
    right: 10px;
    font-size: 12px;
    color: #999;
}
.tubi-ui3-char-counter.is-warning {
    color: #FF8C00;
}
.tubi-ui3-char-counter.is-over {
    color: #FF0000;
    font-weight: 600;
}
.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;
}
.tubi-ui3-send:hover {
    background: #1a91da;
}
.tubi-ui3-send:disabled {
    background: #CCCCCC;
    cursor: not-allowed;
    opacity: 0.6;
}
.tubi-ui3-send svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* ========== TRẠNG THÁI ĐANG XỬ LÝ ========== */
@keyframes tubi-pulse {
    0%, 100% { opacity: 1; background: #1DA1F2; }
    50% { opacity: 0.5; background: #0d8ddb; }
}
.tubi-ui3-send.is-processing {
    animation: tubi-pulse 1s ease-in-out infinite;
    pointer-events: none;
}
.tubi-ui3-send.is-processing:disabled {
    background: #1DA1F2;
    opacity: 1;
}

/* ========== 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;
    }
}
