/* =============================================
   Live Chat — Frontend Widget Styles
   ============================================= */

/* CSS Custom Properties (set dynamically via JS) */
:root {
    --livechat-color: #6C5CE7;
    --livechat-color-light: #ede9fe;
    --livechat-color-dark: #5b4cdb;
}

/* ========================
   Chat Bubble (FAB)
   ======================== */
#livechat-bubble {
    position: fixed;
    bottom: 24px;
    z-index: 999999;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--livechat-color);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(108, 92, 231, 0.4), 0 0 0 0 rgba(108, 92, 231, 0.3);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s;
    animation: livechatPulse 3s ease-in-out infinite;
}

#livechat-bubble.right {
    right: 24px;
}

#livechat-bubble.left {
    left: 24px;
}

#livechat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(108, 92, 231, 0.5);
    animation: none;
}

#livechat-bubble svg {
    width: 28px;
    height: 28px;
    transition: transform 0.3s;
}

#livechat-bubble.open svg {
    transform: rotate(90deg) scale(0);
}

#livechat-bubble .livechat-close-icon {
    position: absolute;
    width: 20px;
    height: 20px;
    opacity: 0;
    transform: rotate(-90deg) scale(0);
    transition: all 0.3s;
}

#livechat-bubble.open .livechat-close-icon {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Unread badge */
#livechat-bubble-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    background: #ef4444;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    border: 2px solid #fff;
    transform: scale(0);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#livechat-bubble-badge.show {
    transform: scale(1);
}

@keyframes livechatPulse {
    0%, 100% {
        box-shadow: 0 4px 20px rgba(108, 92, 231, 0.4), 0 0 0 0 rgba(108, 92, 231, 0.3);
    }
    50% {
        box-shadow: 0 4px 20px rgba(108, 92, 231, 0.4), 0 0 0 12px rgba(108, 92, 231, 0);
    }
}

/* ========================
   Chat Window
   ======================== */
#livechat-window {
    position: fixed;
    bottom: 96px;
    z-index: 999998;
    width: 380px;
    height: 540px;
    max-height: calc(100vh - 120px);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.8) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s;
    transform-origin: bottom right;
}

#livechat-window.right {
    right: 24px;
    transform-origin: bottom right;
}

#livechat-window.left {
    left: 24px;
    transform-origin: bottom left;
}

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

/* Chat header */
.livechat-widget-header {
    background: var(--livechat-color);
    padding: 20px;
    color: #fff;
    position: relative;
    overflow: hidden;
}

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

.livechat-widget-header::after {
    content: '';
    position: absolute;
    bottom: -40px;
    left: -20px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
}

.livechat-widget-header-content {
    position: relative;
    z-index: 1;
}

.livechat-widget-agent-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.livechat-widget-agent-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.livechat-widget-agent-info h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}

.livechat-widget-agent-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    opacity: 0.85;
}

.livechat-widget-agent-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
}

.livechat-widget-subtitle {
    font-size: 13px;
    opacity: 0.8;
    margin: 0;
}

/* Messages container */
.livechat-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f9fafb;
}

.livechat-widget-messages::-webkit-scrollbar {
    width: 4px;
}

.livechat-widget-messages::-webkit-scrollbar-thumb {
    border-radius: 4px;
    background: #d0d5dd;
}

/* Message bubbles */
.livechat-widget-msg {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: livechatMsgIn 0.3s ease;
}

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

.livechat-widget-msg.agent {
    align-self: flex-start;
}

.livechat-widget-msg.visitor {
    align-self: flex-end;
}

.livechat-widget-msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.livechat-widget-msg.agent .livechat-widget-msg-bubble {
    background: #fff;
    color: #1d2327;
    border: 1px solid #e8e8e8;
    border-bottom-left-radius: 4px;
}

.livechat-widget-msg.visitor .livechat-widget-msg-bubble {
    background: var(--livechat-color);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.livechat-widget-msg-time {
    font-size: 11px;
    color: #8c8f94;
    margin-top: 3px;
    padding: 0 4px;
}

.livechat-widget-msg.visitor .livechat-widget-msg-time {
    align-self: flex-end;
}

/* Typing indicator */
.livechat-widget-typing {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    font-size: 12px;
    color: #8c8f94;
}

.livechat-widget-typing.show {
    display: flex;
}

.livechat-widget-typing-dots {
    display: flex;
    gap: 3px;
}

.livechat-widget-typing-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #8c8f94;
    animation: typingBubble 1.4s ease-in-out infinite;
}

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

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

@keyframes typingBubble {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* Pre-chat form */
.livechat-widget-prechat {
    padding: 28px 24px;
    background: #fff;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.livechat-prechat-icon {
    font-size: 28px;
    margin-bottom: 14px;
    line-height: 1;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--livechat-color-light), #f3f0ff);
    animation: livechatBounceIn 0.5s ease;
}

@keyframes livechatBounceIn {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.livechat-widget-prechat h4 {
    margin: 0 0 6px;
    font-size: 18px;
    font-weight: 700;
    color: #1d2327;
    text-align: center;
}

.livechat-widget-prechat p {
    margin: 0 0 22px;
    font-size: 13px;
    color: #8c8f94;
    text-align: center;
}

.livechat-prechat-field {
    width: 100%;
    margin-bottom: 14px;
}

.livechat-prechat-field label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #8c8f94;
    margin-bottom: 6px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.livechat-required {
    color: var(--livechat-color);
    font-weight: 700;
}

.livechat-widget-prechat input {
    width: 100%;
    padding: 13px 16px;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    box-sizing: border-box;
    transition: background 0.2s, box-shadow 0.2s;
    background: #f4f5f7;
    color: #1d2327;
}

.livechat-widget-prechat input:focus {
    background: #fff;
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.1), 0 2px 8px rgba(0, 0, 0, 0.04);
    outline: none;
}

.livechat-widget-prechat input::placeholder {
    color: #b8bcc4;
}

/* Error state */
.livechat-widget-prechat input.livechat-input-error {
    background: #fef2f2;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.08);
    animation: livechatShake 0.4s ease;
}

@keyframes livechatShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.livechat-prechat-error {
    margin: 8px 0 0;
    font-size: 12px;
    color: #ef4444;
    text-align: center;
    font-weight: 500;
    min-height: 16px;
}

.livechat-widget-prechat-btn {
    width: 100%;
    padding: 13px 16px;
    border: none;
    border-radius: 10px;
    background: var(--livechat-color);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    margin-top: 4px;
}

.livechat-widget-prechat-btn:hover {
    background: var(--livechat-color-dark);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.35);
}

.livechat-widget-prechat-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(108, 92, 231, 0.25);
}

.livechat-widget-prechat-btn svg {
    flex-shrink: 0;
}

/* Input area */
.livechat-widget-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #e8e8e8;
    background: #fff;
}

.livechat-widget-input textarea {
    flex: 1;
    border: 1px solid #e8e8e8;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 80px;
    line-height: 1.4;
    color: #1d2327;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.livechat-widget-input textarea:focus {
    border-color: var(--livechat-color);
    outline: none;
}

.livechat-widget-input textarea::placeholder {
    color: #b0b5bd;
}

.livechat-widget-send {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: var(--livechat-color);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, background 0.2s;
}

.livechat-widget-send:hover {
    transform: scale(1.05);
    background: var(--livechat-color-dark);
}

.livechat-widget-send svg {
    width: 18px;
    height: 18px;
}

/* Powered by footer */
.livechat-widget-footer {
    text-align: center;
    padding: 6px;
    font-size: 10px;
    color: #b0b5bd;
    background: #fff;
    border-top: 1px solid #f0f0f0;
}

/* Mobile responsive */
@media (max-width: 480px) {
    #livechat-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 80px);
        bottom: 72px;
        right: 8px !important;
        left: 8px !important;
        border-radius: 12px;
        max-height: none;
    }

    #livechat-bubble {
        bottom: 12px;
    }

    #livechat-bubble.right {
        right: 12px;
    }

    #livechat-bubble.left {
        left: 12px;
    }
}
