/* ============================================================
   LIVE CHAT WIDGET - Premium Glassmorphism Style
   ============================================================ */

/* Chat Toggle Button */
.livechat-toggle {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #17b2a6 0%, #129087 100%);
    border: none;
    cursor: pointer;
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 32px rgba(23, 178, 166, 0.45),
                0 0 0 0 rgba(23, 178, 166, 0.4);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    animation: chatPulse 2.5s infinite;
}

.livechat-toggle:hover {
    transform: scale(1.12);
    box-shadow: 0 12px 40px rgba(23, 178, 166, 0.55);
    animation: none;
}

.livechat-toggle svg {
    width: 30px;
    height: 30px;
    fill: white;
    transition: transform 0.3s ease;
}

.livechat-toggle.active svg.chat-icon { display: none; }
.livechat-toggle.active svg.close-icon { display: block; }
.livechat-toggle:not(.active) svg.chat-icon { display: block; }
.livechat-toggle:not(.active) svg.close-icon { display: none; }

.livechat-toggle .unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    background: #ff5252;
    border-radius: 50%;
    color: white;
    font-size: 11px;
    font-weight: 800;
    display: none;
    align-items: center;
    justify-content: center;
    border: 3px solid white;
    animation: badgeBounce 0.5s ease;
}

.livechat-toggle .unread-badge.show {
    display: flex;
}

@keyframes chatPulse {
    0% { box-shadow: 0 8px 32px rgba(23, 178, 166, 0.45), 0 0 0 0 rgba(23, 178, 166, 0.4); }
    70% { box-shadow: 0 8px 32px rgba(23, 178, 166, 0.45), 0 0 0 15px rgba(23, 178, 166, 0); }
    100% { box-shadow: 0 8px 32px rgba(23, 178, 166, 0.45), 0 0 0 0 rgba(23, 178, 166, 0); }
}

@keyframes badgeBounce {
    0% { transform: scale(0); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* Chat Window */
.livechat-window {
    position: fixed;
    bottom: 110px;
    right: 30px;
    width: 400px;
    max-height: 580px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 24px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.18),
                0 0 0 1px rgba(0, 0, 0, 0.05);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.livechat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Chat Header */
.livechat-header {
    background: linear-gradient(135deg, #17b2a6 0%, #0d9488 50%, #129087 100%);
    padding: 22px 24px;
    display: flex;
    align-items: center;
    gap: 14px;
    position: relative;
    overflow: hidden;
}

.livechat-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 150px;
    height: 150px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
}

.livechat-header::after {
    content: '';
    position: absolute;
    bottom: -30%;
    left: -10%;
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
}

.livechat-avatar {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    position: relative;
    z-index: 1;
    border: 2px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.livechat-avatar .online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: #4ade80;
    border-radius: 50%;
    border: 2px solid white;
    animation: onlinePulse 2s infinite;
}

@keyframes onlinePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.livechat-info {
    flex: 1;
    position: relative;
    z-index: 1;
}

.livechat-info h4 {
    color: white;
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 3px;
    letter-spacing: -0.3px;
}

.livechat-info span {
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 5px;
}

.livechat-info span .status-dot {
    width: 7px;
    height: 7px;
    background: #4ade80;
    border-radius: 50%;
    display: inline-block;
}

.livechat-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.livechat-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* Chat Body */
.livechat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    max-height: 340px;
    min-height: 280px;
    background: linear-gradient(180deg, #f8fffe 0%, #f0faf9 100%);
    scroll-behavior: smooth;
}

.livechat-body::-webkit-scrollbar {
    width: 5px;
}

.livechat-body::-webkit-scrollbar-track {
    background: transparent;
}

.livechat-body::-webkit-scrollbar-thumb {
    background: rgba(23, 178, 166, 0.2);
    border-radius: 10px;
}

.livechat-body::-webkit-scrollbar-thumb:hover {
    background: rgba(23, 178, 166, 0.4);
}

/* Messages */
.chat-message {
    display: flex;
    margin-bottom: 16px;
    animation: msgFadeIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message.visitor {
    justify-content: flex-end;
}

.chat-message.bot,
.chat-message.admin {
    justify-content: flex-start;
}

.msg-bubble {
    max-width: 78%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    position: relative;
    word-wrap: break-word;
}

.chat-message.visitor .msg-bubble {
    background: linear-gradient(135deg, #17b2a6, #0d9488);
    color: white;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 12px rgba(23, 178, 166, 0.25);
}

.chat-message.bot .msg-bubble,
.chat-message.admin .msg-bubble {
    background: white;
    color: #334155;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.msg-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 5px;
    display: block;
}

.chat-message.visitor .msg-time {
    text-align: right;
    color: rgba(255, 255, 255, 0.7);
}

.msg-sender {
    font-size: 11px;
    font-weight: 700;
    color: #17b2a6;
    margin-bottom: 4px;
    display: block;
}

/* Typing indicator */
.typing-indicator {
    display: none;
    padding: 12px 20px;
    margin-bottom: 16px;
}

.typing-indicator.show {
    display: flex;
    align-items: center;
    gap: 8px;
}

.typing-indicator span {
    font-size: 12px;
    color: #94a3b8;
    font-style: italic;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 7px;
    height: 7px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
    font-size: 0;
}

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

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Chat Footer / Input */
.livechat-footer {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    gap: 10px;
}

.livechat-input {
    flex: 1;
    border: 2px solid #e2e8f0;
    border-radius: 14px;
    padding: 12px 16px;
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    outline: none;
    transition: all 0.3s ease;
    background: #f8fafc;
    resize: none;
    max-height: 80px;
    min-height: 44px;
    line-height: 1.4;
}

.livechat-input:focus {
    border-color: #17b2a6;
    background: white;
    box-shadow: 0 0 0 3px rgba(23, 178, 166, 0.1);
}

.livechat-input::placeholder {
    color: #94a3b8;
}

.livechat-send {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(135deg, #17b2a6, #0d9488);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(23, 178, 166, 0.3);
}

.livechat-send:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 18px rgba(23, 178, 166, 0.45);
}

.livechat-send:active {
    transform: scale(0.95);
}

.livechat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.livechat-send svg {
    width: 20px;
    height: 20px;
    fill: white;
    transform: rotate(-30deg);
}

/* Quick Replies */
.quick-replies {
    padding: 10px 20px 6px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    background: white;
    border-top: 1px solid rgba(0, 0, 0, 0.04);
}

.quick-reply-btn {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1.5px solid #e2e8f0;
    background: white;
    color: #475569;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Inter', sans-serif;
    white-space: nowrap;
}

.quick-reply-btn:hover {
    border-color: #17b2a6;
    color: #17b2a6;
    background: rgba(23, 178, 166, 0.05);
    transform: translateY(-1px);
}

/* Date Separator */
.chat-date-sep {
    text-align: center;
    margin: 16px 0;
    position: relative;
}

.chat-date-sep span {
    background: #f0faf9;
    padding: 4px 16px;
    font-size: 11px;
    color: #94a3b8;
    font-weight: 600;
    position: relative;
    z-index: 1;
    border-radius: 20px;
    border: 1px solid rgba(0,0,0,0.05);
}

/* Powered By */
.livechat-powered {
    text-align: center;
    padding: 8px;
    font-size: 10px;
    color: #cbd5e1;
    background: white;
    font-weight: 500;
    letter-spacing: 0.3px;
}

.livechat-powered strong {
    color: #17b2a6;
    font-weight: 700;
}

/* Responsive & Mobile Optimization */
@media (max-width: 580px) {
    .livechat-window {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        right: 0;
        bottom: 0;
        border-radius: 0;
        z-index: 100000;
        transform: translateY(100%) scale(1);
    }

    .livechat-window.open {
        transform: translateY(0) scale(1);
    }

    .livechat-toggle {
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
    }

    .livechat-toggle svg {
        width: 26px;
        height: 26px;
    }

    .livechat-header {
        padding: 16px 20px;
        border-radius: 0;
    }

    .livechat-body {
        max-height: none;
        flex: 1;
    }

    .livechat-footer {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .quick-replies {
        padding: 8px 16px;
    }
}

/* Fix for very small screens or landscape */
@media (max-height: 500px) and (max-width: 580px) {
    .livechat-window {
        height: 100%;
    }
    .livechat-body {
        min-height: 0;
    }
}
