/* ==========================================================================
   1. WIDGET LAYOUT (Cố định vị trí)
   ========================================================================== */
#n8n-chat-widget { 
    position: fixed !important; bottom: 35px !important; right: 20px !important; 
    z-index: 2147483646 !important; font-family: sans-serif !important; 
}
@media only screen and (max-width: 768px) {
    #n8n-chat-widget { bottom: 95px !important; right: 10px !important; }
}

/* Nút toggle (Mất nền) */
#chat-toggle { 
    width: 64px !important;
    height: 64px !important;
    min-width: 64px !important;
    min-height: 64px !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #0084ff !important; /* Đặt lại nền xanh */
    border: 0 !important;
    border-radius: 50% !important;
    cursor: pointer; 
    color: #ffffff; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-size: 26px; 
    box-shadow: 0 4px 15px rgba(0,132,255,0.4); 
    transition: 0.3s;
    position: fixed !important;
    bottom: 105px;
    right: 20px;
    z-index: 2147483646 !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    pointer-events: auto !important;
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
#chat-toggle > * { pointer-events: none !important; }
#chat-toggle:hover { transform: scale(1.05); }
/* Điều chỉnh lại vị trí widget cho mobile để không bị đè */
@media only screen and (max-width: 768px) {
    #chat-toggle { bottom: 135px !important; right: 10px !important; }
}

/* ==========================================================================
   2. CHAT WINDOW (Khung chat chính)
   ========================================================================== */
.ttc-window { 
    display: flex; width: 360px; height: 530px; background: #fff; 
    border-radius: 15px; flex-direction: column; margin-bottom: 15px; 
    box-shadow: 0 5px 25px rgba(0,0,0,0.2); overflow: hidden; border: 1px solid #ddd; 
    padding: 0 !important;
}
.ttc-window.ttc-window-expanded { width: min(720px, calc(100vw - 40px)); height: min(760px, calc(100vh - 100px)); }
.ttc-header { min-height: 44px; margin: 0 !important; padding: 7px 10px !important; background: #0084ff; color: #fff; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.ttc-header-actions { display: flex; align-items: center; gap: 2px; }
.ttc-window-action { width: 32px; height: 32px; margin: 0; padding: 0; border: 0; border-radius: 6px; color: #fff; background: transparent; cursor: pointer; font: 700 20px/1 sans-serif; }
.ttc-window-action:hover { background: rgba(255,255,255,0.16); }
.ttc-close { cursor: pointer; font-size: 20px; }

/* ==========================================================================
   3. CHAT CONTENT (Lịch sử hội thoại)
   ========================================================================== */
.ttc-content { flex: 1; overflow-y: auto; padding: 12px; font-size: 14px; background: #fafafa; }
.ttc-msg-box { margin: 6px 0; padding: 8px 12px; border-radius: 12px; max-width: 80%; line-height: 1.4; word-wrap: break-word; }
.ttc-msg-user { background: #0084ff; color: #fff; margin-left: auto; }
.ttc-msg-bot { background: #e0e0e0; color: #333; }

/* ==========================================================================
   4. TOOLBAR (Thanh công cụ - Ép sát 1 hàng)
   ========================================================================== */
.ttc-toolbar { 
    display: flex; align-items: center; justify-content: space-between; 
    padding: 2px 5px !important; background: #f8f9fa; border-bottom: 1px solid #eee; height: 30px; 
}
.ttc-group { display: flex; align-items: center; gap: 0px !important; }

/* Nút bấm (Tối ưu click area) */
.ttc-btn, .format-btn { 
    border: none; background: transparent; cursor: pointer; 
    padding: 4px 5px !important; border-radius: 3px; font-size: 18px !important; color: #444; 
    margin: 1px;
}
.ttc-btn:hover, .format-btn:hover { background: #dcdcdc; }

/* Kho icon (Ẩn hiện) */
.ttc-icon-list { display: none; flex-wrap: wrap; gap: 4px; padding: 6px; background: #fff; border-bottom: 1px solid #eee; font-size: 22px; }
.ttc-emoji-button { min-width: 30px; height: 30px; margin: 0; padding: 3px 4px !important; border: 0; border-radius: 3px; background: transparent; cursor: pointer; font-size: 18px !important; line-height: 1; }
.ttc-emoji-button:hover { background: #dcdcdc; }
.ttc-emoji-button img.emoji { width: 18px !important; height: 18px !important; margin: 0 !important; pointer-events: none; }
#ttc-more-emoji { margin-left: 2px !important; font-size: 18px !important; cursor: pointer; border:none; background:transparent; }
/* Thêm vào phần 4. TOOLBAR trong style.css */
.ttc-size-btn { 
    font-weight: bold; cursor: pointer; border: none; background: transparent; 
    padding: 2px 4px !important; font-size: 14px !important; color: #333; 
}
.ttc-size-btn:hover { background: #dcdcdc; }
#ttc-color-picker{font-size: 1px;}

/* ==========================================================================
   5. INPUT AREA (Ô nhập liệu)
   ========================================================================== */
.ttc-input-wrapper { display: flex; border-top: 1px solid #eee; background: #fff; align-items: center; padding: 4px; }
.ttc-footer { min-height: 0 !important; margin: 0 !important; padding: 0 !important; background: #fff; }
.ttc-editor { padding: 8px; outline: none; flex: 1; min-height: 20px; font-size: 14px; background: #fff; }
.ttc-editor:empty:before { content: attr(data-placeholder); color: #bbb; }
.ttc-btn-send { background: #0084ff; color: #fff; border: none; padding: 5px 10px; cursor: pointer; border-radius: 4px; font-size: 13px; font-weight: 600; margin-left: 5px; }
.ttc-btn-send:hover { background: #0073e6; }
/* ==========================================================================
   6. [NÂNG CẤP] CHUẨN HÓA KÍCH THƯỚC EMOJI & ẢNH (SIZE MEDIUM - CHUẨN UI)
   ========================================================================== */
/* 1. Nhắm vào class chung .ttc-msg-box để áp dụng cho cả User lẫn Bot/Admin */
.ttc-msg-box span.emoji,
.ttc-msg-box span.ttc-emoji,
.ttc-msg-box img.emoji {
    font-size: 30px !important;       /* Gấp 2 lần size chữ mặc định (15px * 2 = 30px) */
    width: 30px !important;           /* Khóa cứng chiều rộng nếu là dạng thẻ img */
    height: 30px !important;          /* Khóa cứng chiều cao */
    line-height: 1 !important;
    vertical-align: middle !important; /* Căn giữa hoàn hảo khi nằm xen kẽ với dòng chữ */
    display: inline-block !important;
    margin: 0 4px !important;
    transition: transform 0.2s ease;
}

/* 2. Hiệu ứng phóng to nhẹ khi khách hàng di chuột vào icon cho mượt mắt */
.ttc-msg-box span.emoji:hover,
.ttc-msg-box span.ttc-emoji:hover {
    transform: scale(1.15);
}
/* ==========================================================================
   7. [MỚI] HIỆU ỨNG CHỜ (TYPING) VÀ THU HÚT ICON
   ========================================================================== */
/* Hiệu ứng nhịp đập & Chấm đỏ thông báo cho Icon */
@keyframes ttc-pulse {
    0% { box-shadow: 0 0 0 0 rgba(0, 132, 255, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(0, 132, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 132, 255, 0); }
}

#chat-toggle {
    animation: ttc-pulse 2s infinite; 
    position: fixed !important;
}

#chat-toggle::after {
    content: "1"; position: absolute; top: -2px; right: -2px;
    background: #ff3b30; color: white; font-size: 11px; font-weight: bold;
    width: 18px; height: 18px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid #fff;
    pointer-events: none;
}

/* Hiệu ứng Đang gõ (Typing...) */
.ttc-typing {
    display: flex; align-items: center; gap: 4px; padding: 12px 16px; 
    background: #e0e0e0; border-radius: 12px; width: fit-content;
}
.ttc-typing span {
    width: 6px; height: 6px; background: #90949c; border-radius: 50%;
    animation: ttc-bounce 1.3s linear infinite;
}
.ttc-typing span:nth-child(2) { animation-delay: -1.1s; }
.ttc-typing span:nth-child(3) { animation-delay: -0.9s; }
@keyframes ttc-bounce { 50% { transform: translateY(-4px); } }
.ttc-chat-img {
    display: block;
    max-width: 220px;
    max-height: 220px;
    border-radius: 8px;
    margin-top: 6px;
    border: 1px solid rgba(0,0,0,0.12);
    object-fit: cover;
}

.ttc-chat-link,
.ttc-chat-file {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}

.ttc-msg-user .ttc-chat-link,
.ttc-msg-user .ttc-chat-file {
    color: #fff;
}

@media only screen and (max-width: 768px) {
    .ttc-window.ttc-window-expanded {
        width: calc(100vw - 20px);
        height: calc(100vh - 155px);
    }
}
