/* ===== Telegram Chat Widget ===== */

/* Floating button — round avatar */
#tg-chat-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(43, 119, 204, 0.45);
    z-index: 9998;
    overflow: visible;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

#tg-chat-btn img {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    border: 3px solid #ffffff;
}

#tg-chat-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(43, 119, 204, 0.5);
}

#tg-chat-btn.tg-hidden {
    transform: scale(0);
    pointer-events: none;
}

/* Online dot */
.tg-online-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #35CC24;
    flex-shrink: 0;
}

#tg-chat-btn .tg-online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border: 2px solid #ffffff;
    box-sizing: border-box;
}

/* Chat panel */
#tg-chat-panel {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 350px;
    max-height: calc(100vh - 100px);
    max-height: calc(100dvh - 100px);
    background: #f5f6fa;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
    z-index: 9999;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0);
    transform-origin: bottom right;
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

#tg-chat-panel.tg-open {
    transform: scale(1);
    opacity: 1;
}

/* Header */
.tg-chat-header {
    background: linear-gradient(135deg, #2B77CC, #8455D4);
    color: #ffffff;
    padding: 14px 16px;
    border-radius: 10px 10px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.tg-agent-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tg-agent-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.5);
    flex-shrink: 0;
}

.tg-agent-meta {
    display: flex;
    flex-direction: column;
}

.tg-agent-name {
    font-family: 'Poppins', sans-serif;
    font-size: 15px;
    font-weight: 600;
}

.tg-agent-position {
    font-family: 'Poppins', sans-serif;
    font-size: 11px;
    opacity: 0.75;
    margin-top: 1px;
}

.tg-status-line {
    font-family: 'Poppins', sans-serif;
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
}

.tg-chat-close {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 26px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.tg-chat-close:hover {
    opacity: 1;
}

/* Messages area */
.tg-messages {
    padding: 14px 14px 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f5f6fa;
    overflow-y: auto;
    flex: 1;
}

/* Message bubbles */
.tg-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 18px;
    font-family: 'Poppins', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    animation: tg-bubble-in 0.3s ease;
}

.tg-bubble-in {
    background: #ffffff;
    color: #454754;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.tg-bubble-out {
    background: linear-gradient(135deg, #2B77CC, #8455D4);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}

.tg-bubble-row-out {
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 8px;
    width: 100%;
}

.tg-bubble-author {
    font-size: 11px;
    font-weight: 600;
    color: #8455D4;
    white-space: nowrap;
    flex-shrink: 0;
    padding-bottom: 4px;
}

@keyframes tg-bubble-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Typing indicator */
.tg-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #ffffff;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    width: fit-content;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.tg-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #8455D4;
    animation: tg-bounce 1.2s infinite ease-in-out;
}

.tg-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.tg-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes tg-bounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* Reply form */
.tg-chat-body {
    padding: 10px 14px 14px;
    background: #f5f6fa;
    border-top: 1px solid #e0e1eb;
}

.tg-chat-field {
    margin-bottom: 8px;
}

.tg-chat-field input,
.tg-chat-field textarea {
    width: 100%;
    padding: 9px 13px;
    border: 1px solid #E0E1EB;
    border-radius: 10px;
    font-family: 'Poppins', sans-serif;
    font-size: 14px;
    color: #454754;
    outline: none;
    background: #ffffff;
    transition: border-color 0.2s;
    box-sizing: border-box;
    resize: none;
}

.tg-chat-field input:focus,
.tg-chat-field textarea:focus {
    border-color: #8455D4;
}

.tg-chat-field textarea {
    min-height: 60px;
}

/* Send button */
#tg-send {
    width: 100%;
    padding: 11px;
    border: none;
    border-radius: 38px;
    background: linear-gradient(135deg, #2B77CC, #8455D4);
    color: #ffffff;
    font-family: 'Poppins', sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#tg-send:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

#tg-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Status */
.tg-status {
    margin-top: 8px;
    font-family: 'Poppins', sans-serif;
    font-size: 12px;
    text-align: center;
    min-height: 16px;
}

.tg-status.tg-success {
    color: #35CC24;
}

.tg-status.tg-error {
    color: #D65050;
}

.tg-status.tg-sending {
    color: #86889A;
}

/* Mobile */
@media (max-width: 640px) {
    #tg-chat-panel {
        width: calc(100% - 20px);
        right: 10px;
        bottom: 10px;
        max-height: calc(100vh - 20px);
        max-height: calc(100dvh - 20px);
    }

    #tg-chat-btn {
        bottom: 15px;
        right: 15px;
    }
}