/* ============================================================
   CHAT WIDGET - THANHCLONE.COM (v2 - Mobile fix + Minimize)
   Font: Exo 2 | Theme: Light + Royal Blue
   ============================================================ */

.tc-chat-widget *, .tc-greeting * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Exo 2', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.tc-chat-widget {
    --tc-primary: #0D20AF;
    --tc-primary-light: #204AAC;
    --tc-bg: #F5F7FA;
    --tc-white: #FFFFFF;
    --tc-text: #1F2937;
    --tc-text-light: #6B7280;
    --tc-border: #E5E7EB;
    --tc-online: #10B981;
    --tc-offline: #9CA3AF;
    --tc-shadow: 0 10px 40px rgba(13, 32, 175, 0.15);
    --tc-shadow-lg: 0 20px 60px rgba(13, 32, 175, 0.25);
    position: fixed; bottom: 20px; right: 20px; z-index: 999999;
    font-size: 14px; line-height: 1.5; color: var(--tc-text);
}

/* === GREETING POPUP === */
.tc-greeting {
    position: fixed;
    bottom: 100px;
    right: 20px;
    z-index: 999998;
    background: white;
    border-radius: 16px;
    box-shadow: 0 15px 50px rgba(13, 32, 175, 0.25);
    padding: 16px 18px;
    max-width: 280px;
    transform: translateX(20px) scale(0.9);
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 2px solid #EEF2FF;
}
.tc-greeting.tc-show {
    transform: translateX(0) scale(1);
    opacity: 1;
    pointer-events: auto;
    animation: tc-greeting-bounce 2s ease-in-out 0.5s;
}
@keyframes tc-greeting-bounce {
    0%, 100% { transform: translateX(0) scale(1); }
    50% { transform: translateX(0) scale(1.03); }
}
.tc-greeting::after {
    content: '';
    position: absolute;
    bottom: -10px;
    right: 30px;
    width: 0; height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid white;
}
.tc-greeting-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--tc-primary);
    margin-bottom: 4px;
    font-family: 'Exo 2', sans-serif;
}
.tc-greeting-text {
    font-size: 13px;
    color: var(--tc-text-light);
    line-height: 1.4;
}
.tc-greeting-close {
    position: absolute;
    top: 6px; right: 6px;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: #F3F4F6;
    border: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: #9CA3AF;
    font-size: 14px;
    line-height: 1;
    transition: all 0.2s;
}
.tc-greeting-close:hover { background: #E5E7EB; color: #4B5563; }
.tc-greeting-content { cursor: pointer; padding-right: 20px; }

/* === BUBBLE === */
.tc-chat-bubble {
    width: 64px; height: 64px; border-radius: 50%;
    background: linear-gradient(135deg, var(--tc-primary), var(--tc-primary-light));
    box-shadow: var(--tc-shadow); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    animation: tc-bubble-pulse 2s infinite;
}
.tc-chat-bubble:hover { transform: scale(1.1); box-shadow: var(--tc-shadow-lg); }
.tc-chat-bubble svg { width: 32px; height: 32px; fill: white; }
@keyframes tc-bubble-pulse {
    0%, 100% { box-shadow: 0 10px 40px rgba(13,32,175,0.15), 0 0 0 0 rgba(13,32,175,0.5); }
    50% { box-shadow: 0 10px 40px rgba(13,32,175,0.15), 0 0 0 15px rgba(13,32,175,0); }
}
.tc-chat-badge {
    position: absolute; top: -4px; right: -4px;
    min-width: 22px; height: 22px; border-radius: 11px;
    background: #EF4444; color: white; font-size: 11px; font-weight: bold;
    display: none; align-items: center; justify-content: center;
    padding: 0 6px; border: 2px solid white;
    box-shadow: 0 2px 8px rgba(239,68,68,0.4);
}
.tc-chat-badge.tc-show { 
    display: flex; 
    animation: tc-badge-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes tc-badge-pop {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); opacity: 1; }
}

/* === WINDOW === */
.tc-chat-window {
    position: absolute; bottom: 80px; right: 0;
    width: 380px; height: 580px; max-height: calc(100vh - 120px);
    background: var(--tc-white); border-radius: 20px;
    box-shadow: var(--tc-shadow-lg);
    display: none; flex-direction: column; overflow: hidden;
    transform: scale(0.95) translateY(20px); opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.tc-chat-window.tc-open {
    display: flex; transform: scale(1) translateY(0); opacity: 1;
}

/* === HEADER === */
.tc-chat-header {
    background: linear-gradient(135deg, var(--tc-primary), var(--tc-primary-light));
    padding: 16px 20px; color: white;
    display: flex; align-items: center; gap: 12px; flex-shrink: 0;
}
.tc-chat-avatar {
    width: 44px; height: 44px; border-radius: 50%;
    background: white; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.tc-chat-avatar svg { width: 28px; height: 28px; }
.tc-chat-avatar::after {
    content: ''; position: absolute; bottom: 0; right: 0;
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--tc-online); border: 2px solid white;
    animation: tc-online-pulse 2s infinite;
}
.tc-chat-widget[data-status="offline"] .tc-chat-avatar::after { background: var(--tc-offline); animation: none; }
.tc-chat-widget[data-status="busy"] .tc-chat-avatar::after { background: #F59E0B; animation: none; }
.tc-chat-widget[data-status="busy"] .tc-chat-header-status { color: #FEF3C7; }
.tc-chat-widget[data-status="offline"] .tc-chat-header-status { color: #E5E7EB; }
@keyframes tc-online-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0.6); }
    50% { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
}
.tc-chat-header-info { flex: 1; min-width: 0; }
.tc-chat-header-title {
    font-family: 'Exo 2', sans-serif;
    font-size: 15px; font-weight: 700;
    margin-bottom: 2px; letter-spacing: 0.3px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    line-height: 1.2;
}
.tc-chat-header-status { 
    font-size: 11px; 
    opacity: 0.95;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Khi status dài (busy/away) → cho phép wrap 2 dòng gọn */
.tc-chat-widget[data-status="busy"] .tc-chat-header-status,
.tc-chat-widget[data-status="offline"] .tc-chat-header-status {
    white-space: normal;
    font-size: 11px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Header buttons (sound + minimize + close) - nhỏ gọn */
.tc-chat-minimize, .tc-chat-close, .tc-chat-sound {
    background: rgba(255,255,255,0.2); border: none;
    width: 28px; height: 28px; border-radius: 50%;
    color: white; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s; flex-shrink: 0;
    font-size: 13px;
}
.tc-chat-sound { margin-right: 2px; }
.tc-chat-minimize { margin-right: 2px; }
.tc-chat-minimize:hover, .tc-chat-close:hover, .tc-chat-sound:hover { background: rgba(255,255,255,0.35); }
.tc-chat-minimize svg { width: 16px; height: 16px; fill: white; }
.tc-chat-close svg { width: 14px; height: 14px; fill: white; }

/* Giảm padding header + avatar gọn hơn cho nhiều chỗ */
.tc-chat-header {
    padding: 12px 14px !important;
    gap: 10px !important;
}
.tc-chat-avatar {
    width: 40px !important;
    height: 40px !important;
}
.tc-chat-avatar svg { width: 26px !important; height: 26px !important; }

/* === BODY === */
.tc-chat-body {
    flex: 1; overflow-y: auto; background: var(--tc-bg);
    scrollbar-width: thin; scrollbar-color: #CBD5E1 transparent;
}
.tc-chat-body::-webkit-scrollbar { width: 6px; }
.tc-chat-body::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 3px; }

/* === SCREEN: LANGUAGE === */
.tc-screen-lang { padding: 40px 24px; text-align: center; display: none; }
.tc-screen-lang.tc-active { display: block; }
.tc-lang-icon {
    width: 80px; height: 80px; margin: 0 auto 20px;
    background: linear-gradient(135deg, var(--tc-primary), var(--tc-primary-light));
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.tc-lang-icon svg { width: 40px; height: 40px; fill: white; }
.tc-lang-title { font-size: 18px; font-weight: 600; margin-bottom: 24px; }
.tc-lang-buttons { display: flex; flex-direction: column; gap: 12px; max-width: 280px; margin: 0 auto; }
.tc-lang-btn {
    padding: 14px 20px; background: white;
    border: 2px solid var(--tc-border); border-radius: 12px;
    cursor: pointer; font-size: 15px; font-weight: 500; color: var(--tc-text);
    transition: all 0.2s; display: flex; align-items: center; justify-content: center; gap: 12px;
}
.tc-lang-btn:hover {
    border-color: var(--tc-primary); background: #EEF2FF;
    transform: translateY(-2px); box-shadow: 0 4px 12px rgba(13,32,175,0.1);
}
.tc-lang-btn svg { width: 28px; height: 20px; border-radius: 3px; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }

/* === SCREEN: FORM === */
.tc-screen-form { padding: 24px; display: none; }
.tc-screen-form.tc-active { display: block; }
.tc-form-title { font-size: 17px; font-weight: 700; margin-bottom: 4px; font-family: 'Exo 2', sans-serif; }
.tc-form-subtitle { font-size: 13px; color: var(--tc-text-light); margin-bottom: 20px; }
.tc-form-group { margin-bottom: 16px; }
.tc-form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.tc-form-label .tc-required { color: #EF4444; }
.tc-form-input, .tc-form-select {
    width: 100%; padding: 11px 14px;
    border: 2px solid var(--tc-border); border-radius: 10px;
    font-size: 14px; color: var(--tc-text); background: white;
    transition: border-color 0.2s; font-family: inherit;
}
.tc-form-input:focus, .tc-form-select:focus { outline: none; border-color: var(--tc-primary); }
.tc-form-input.tc-error, .tc-form-select.tc-error { border-color: #EF4444; }
.tc-form-hint { font-size: 11px; color: var(--tc-text-light); margin-top: 4px; }
.tc-form-error { font-size: 12px; color: #EF4444; margin-top: 4px; display: none; }
.tc-form-error.tc-show { display: block; }
.tc-form-submit {
    width: 100%; padding: 13px;
    background: linear-gradient(135deg, var(--tc-primary), var(--tc-primary-light));
    color: white; border: none; border-radius: 10px;
    font-size: 15px; font-weight: 600; font-family: 'Exo 2', sans-serif;
    cursor: pointer; transition: all 0.2s; margin-top: 8px;
}
.tc-form-submit:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(13,32,175,0.3); }
.tc-form-submit:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* === SCREEN: CHAT === */
.tc-screen-chat { display: none; flex-direction: column; height: 100%; }
.tc-screen-chat.tc-active { display: flex; }
.tc-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 10px;
}
.tc-msg {
    max-width: 80%; padding: 10px 14px; border-radius: 16px;
    font-size: 14px; word-wrap: break-word;
    animation: tc-msg-in 0.3s ease-out;
}
@keyframes tc-msg-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.tc-msg.tc-customer {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--tc-primary), var(--tc-primary-light));
    color: white; border-bottom-right-radius: 4px;
}
.tc-msg.tc-admin, .tc-msg.tc-bot {
    align-self: flex-start; background: white; color: var(--tc-text);
    border: 1px solid var(--tc-border); border-bottom-left-radius: 4px;
}
.tc-msg.tc-system {
    align-self: center; background: #EEF2FF; color: var(--tc-primary);
    font-size: 12px; text-align: center; border-radius: 12px; max-width: 90%;
}
.tc-typing {
    display: none; align-items: center; gap: 4px;
    padding: 10px 14px; background: white;
    border: 1px solid var(--tc-border); border-radius: 16px;
    border-bottom-left-radius: 4px; align-self: flex-start; max-width: 80px;
}
.tc-typing.tc-show { display: flex; }
.tc-typing span {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--tc-primary); animation: tc-typing 1.4s infinite;
}
.tc-typing span:nth-child(2) { animation-delay: 0.2s; }
.tc-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes tc-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-8px); opacity: 1; }
}
.tc-quick-actions {
    padding: 8px 16px; display: flex; gap: 8px; flex-wrap: wrap;
    border-top: 1px solid var(--tc-border); background: white; flex-shrink: 0;
}
.tc-quick-btn {
    padding: 7px 12px; background: white;
    border: 1.5px solid var(--tc-primary); border-radius: 16px;
    color: var(--tc-primary); font-size: 12px; font-weight: 500;
    cursor: pointer; transition: all 0.2s; white-space: nowrap;
    font-family: inherit;
}
.tc-quick-btn:hover { background: var(--tc-primary); color: white; }
.tc-input-area {
    padding: 12px 16px; background: white;
    border-top: 1px solid var(--tc-border);
    display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.tc-input-text {
    flex: 1; padding: 10px 14px;
    border: 1.5px solid var(--tc-border); border-radius: 20px;
    font-size: 14px; background: var(--tc-bg);
    transition: border-color 0.2s; font-family: inherit;
    resize: none; max-height: 100px; min-height: 40px;
}
.tc-input-text:focus { outline: none; border-color: var(--tc-primary); background: white; }
.tc-btn-send {
    width: 40px; height: 40px; border-radius: 50%;
    background: linear-gradient(135deg, var(--tc-primary), var(--tc-primary-light));
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: all 0.2s;
}
.tc-btn-send:hover { transform: scale(1.1); }
.tc-btn-send svg { width: 18px; height: 18px; fill: white; }

/* === CLOSED OVERLAY === */
.tc-closed-overlay {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
    background: white;
    border-top: 1px solid var(--tc-border);
    text-align: center;
    flex-shrink: 0;
}
.tc-closed-overlay.tc-show { display: flex; }
.tc-closed-icon {
    width: 56px; height: 56px; border-radius: 50%;
    background: #EEF2FF;
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; margin-bottom: 12px;
}
.tc-closed-title {
    font-weight: 700; font-size: 15px;
    color: var(--tc-primary); margin-bottom: 4px;
    font-family: 'Exo 2', sans-serif;
}
.tc-closed-text {
    font-size: 13px; color: var(--tc-text-light);
    margin-bottom: 16px; line-height: 1.4;
}
.tc-btn-newchat {
    padding: 11px 20px;
    background: linear-gradient(135deg, var(--tc-primary), var(--tc-primary-light));
    color: white; border: none; border-radius: 10px;
    font-size: 14px; font-weight: 600; cursor: pointer;
    font-family: 'Exo 2', sans-serif;
    transition: all 0.2s;
}
.tc-btn-newchat:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(13,32,175,0.3);
}
.tc-input-area.tc-disabled {
    opacity: 0.5;
    pointer-events: none;
}
.tc-quick-actions.tc-hide { display: none !important; }

/* === IMAGE UPLOAD === */
.tc-btn-attach {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--tc-bg); border: 1.5px solid var(--tc-border);
    color: var(--tc-primary); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: all 0.2s; font-size: 18px;
}
.tc-btn-attach:hover {
    background: var(--tc-primary); color: white; border-color: var(--tc-primary);
}
.tc-btn-attach svg { width: 18px; height: 18px; }

.tc-msg img.tc-msg-img {
    max-width: 100%; max-height: 200px; border-radius: 12px;
    cursor: pointer; display: block; margin: 4px 0;
    transition: transform 0.2s;
}
.tc-msg img.tc-msg-img:hover { transform: scale(1.02); }

.tc-upload-progress {
    align-self: flex-end; padding: 12px 16px;
    background: #EEF2FF; border-radius: 16px;
    color: var(--tc-primary); font-size: 12px;
    display: flex; align-items: center; gap: 8px;
}
.tc-upload-progress::before {
    content: ''; width: 14px; height: 14px;
    border: 2px solid var(--tc-primary); border-top-color: transparent;
    border-radius: 50%; animation: tc-spin 0.8s linear infinite;
}
@keyframes tc-spin { to { transform: rotate(360deg); } }

.tc-lightbox {
    position: fixed; inset: 0; background: rgba(0,0,0,0.9);
    z-index: 9999999; display: none; align-items: center; justify-content: center;
    cursor: zoom-out;
}
.tc-lightbox.tc-show { display: flex; }
.tc-lightbox img { max-width: 95vw; max-height: 95vh; border-radius: 8px; }

.tc-chat-body.tc-dragover {
    background: #EEF2FF !important;
    outline: 3px dashed var(--tc-primary); outline-offset: -8px;
}

/* === RESPONSIVE - MOBILE OPTIMIZED === */
/* Icon nhỏ hơn, tắt pulse, ẩn khi scroll (JS xử lý) */
@media (max-width: 768px) {
    .tc-chat-widget {
        bottom: 80px;
        right: 12px;
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s;
    }
    
    /* Header mobile: nhỏ gọn hơn */
    .tc-chat-header {
        padding: 10px 12px !important;
        gap: 8px !important;
    }
    .tc-chat-avatar {
        width: 36px !important;
        height: 36px !important;
    }
    .tc-chat-avatar svg { width: 22px !important; height: 22px !important; }
    .tc-chat-header-title { font-size: 14px !important; }
    .tc-chat-header-status { font-size: 10.5px !important; }
    .tc-chat-minimize, .tc-chat-close, .tc-chat-sound {
        width: 26px !important;
        height: 26px !important;
    }
    
    /* Icon nhỏ gọn hơn */
    .tc-chat-bubble {
        width: 48px;
        height: 48px;
        animation: none;
        box-shadow: 0 6px 20px rgba(13, 32, 175, 0.25);
    }
    .tc-chat-bubble svg { width: 24px; height: 24px; }
    .tc-chat-bubble:hover { transform: scale(1.05); }
    
    .tc-chat-badge {
        min-width: 18px; height: 18px;
        font-size: 10px; top: -2px; right: -2px;
        border-width: 1.5px;
    }
    
    .tc-chat-widget.tc-hidden-scroll {
        transform: translateX(100px);
        opacity: 0;
        pointer-events: none;
    }
    .tc-greeting.tc-hidden-scroll {
        transform: translateX(100px) scale(0.8) !important;
        opacity: 0 !important;
    }
    
    .tc-chat-window {
        width: calc(100vw - 24px);
        max-width: 400px;
        height: calc(100vh - 160px);
        max-height: 640px;
        bottom: 60px;
        right: 0;
    }
    
    .tc-greeting {
        right: 12px;
        bottom: 138px;
        max-width: calc(100vw - 48px);
        padding: 12px 14px;
    }
    .tc-greeting-title { font-size: 14px; }
    .tc-greeting-text { font-size: 12px; }
    .tc-greeting::after { right: 20px; }
}

/* Màn hình siêu hẹp < 380px: ẩn bớt nút để header không bị chật */
@media (max-width: 380px) {
    .tc-chat-window {
        position: fixed;
        top: 16px; bottom: 16px;
        left: 12px; right: 12px;
        width: auto; height: auto;
        max-height: none;
        border-radius: 16px;
    }
    /* Ẩn nút sound trên màn rất nhỏ để nhường chỗ cho text */
    .tc-chat-sound { display: none !important; }
    .tc-chat-header { gap: 6px !important; padding: 10px !important; }
    .tc-chat-header-status { font-size: 10px !important; }
}
