/**
 * Live Chat Widget Styles
 *
 * @package UniversalEcommercePWA
 */

/* =========================================================================
   Chat Widget Container
   ========================================================================= */
.uepwa-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: var(--font-primary);
    direction: rtl;
}

/* On mobile: show button, prevent JS from hiding it */
@media (max-width: 767px) {
    .uepwa-chat-widget {
        bottom: 76px;
    }

    /* Keep the floating chat button visible and functional on mobile */
    .uepwa-chat-button {
        opacity: 1 !important;
        display: block !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }
}

/* =========================================================================
   Chat Floating Button
   ========================================================================= */
.uepwa-chat-button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.uepwa-chat-button:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}

.uepwa-chat-button:active {
    transform: scale(0.96);
}

/* =========================================================================
   Chat Window — Desktop (fixed position, independent of parent)
   ========================================================================= */
.uepwa-chat-window {
    position: fixed;
    bottom: 88px;
    right: 20px;
    width: 360px;
    height: 480px;
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10000;
}

/* =========================================================================
   Chat Window — Mobile Full Screen
   ========================================================================= */
@media (max-width: 767px) {
    .uepwa-chat-window {
        inset: 0;
        width: auto;
        height: auto;
        border-radius: 0;
        bottom: 0;
        right: 0;
    }
}

/* Offset for WordPress admin bar */
@media (max-width: 767px) {
    .admin-bar .uepwa-chat-window {
        top: 46px;
    }
}

/* =========================================================================
   Chat Header
   ========================================================================= */
.uepwa-chat-header {
    background: var(--color-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.uepwa-chat-title {
    font-size: 15px;
    font-weight: 700;
    flex: 1;
}

.uepwa-chat-status {
    font-size: 11px;
    opacity: 0.85;
}

.uepwa-chat-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background var(--transition-fast);
    line-height: 1;
}

.uepwa-chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* =========================================================================
   Login Wall (replaces Welcome Form for guests)
   ========================================================================= */
.uepwa-chat-login-wall {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    text-align: center;
    background: var(--color-surface);
}

.uepwa-chat-login-wall__icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(var(--color-primary-rgb), 0.1);
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.uepwa-chat-login-wall__text {
    font-size: 14px;
    color: #666;
    margin-bottom: 20px;
    line-height: 1.6;
}

.uepwa-chat-login-btn {
    padding: 12px 32px;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-primary);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.uepwa-chat-login-btn:hover {
    background: var(--color-primary-dark);
}

/* =========================================================================
   Handoff Button (in header)
   ========================================================================= */
.uepwa-chat-handoff-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.uepwa-chat-handoff-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* =========================================================================
   AI Agent Message Styling
   ========================================================================= */
.uepwa-chat-message.ai_agent {
    align-items: flex-end;
}

.uepwa-chat-message.ai_agent .uepwa-chat-message-bubble {
    background: #f0f4ff;
    color: var(--color-text);
    border: 1px solid #d0d9f0;
    border-bottom-left-radius: 4px;
}

.uepwa-chat-ai-label {
    font-size: 11px;
    color: #7c8aaa;
    margin-bottom: 2px;
    font-weight: 600;
}

/* =========================================================================
   Chat Messages Area
   ========================================================================= */
.uepwa-chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: var(--color-surface);
}

.uepwa-chat-message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

.uepwa-chat-message.customer {
    align-items: flex-start;
}

.uepwa-chat-message.agent,
.uepwa-chat-message.system {
    align-items: flex-end;
}

.uepwa-chat-message-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.5;
}

.uepwa-chat-message.customer .uepwa-chat-message-bubble {
    background: var(--color-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.uepwa-chat-message.agent .uepwa-chat-message-bubble {
    background: #fff;
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 4px;
}

.uepwa-chat-message.system .uepwa-chat-message-bubble {
    background: transparent;
    color: #999;
    font-size: 12px;
    text-align: center;
    max-width: 100%;
}

.uepwa-chat-message-time {
    font-size: 10px;
    color: #aaa;
    margin-top: 4px;
}

/* =========================================================================
   Chat Input Area
   ========================================================================= */
.uepwa-chat-input-container {
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* iOS safe area for full-screen mode */
@media (max-width: 767px) {
    .uepwa-chat-input-container {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
}

.uepwa-chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--color-border);
    border-radius: 20px;
    font-family: var(--font-primary);
    font-size: 14px;
    outline: none;
    background: var(--color-surface);
    transition: border-color var(--transition-fast);
}

.uepwa-chat-input:focus {
    border-color: var(--color-primary);
}

.uepwa-chat-send {
    padding: 10px 18px;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: 20px;
    font-family: var(--font-primary);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background var(--transition-fast);
    white-space: nowrap;
}

.uepwa-chat-send:hover {
    background: var(--color-primary-dark);
}

.uepwa-chat-send:disabled {
    background: var(--color-border);
    cursor: not-allowed;
}

/* =========================================================================
   Online/Offline Indicator
   ========================================================================= */
.uepwa-chat-status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-left: 6px;
}

.uepwa-chat-status-indicator.online {
    background: var(--color-success);
}

.uepwa-chat-status-indicator.offline {
    background: var(--color-error);
}

/* =========================================================================
   Loading Animation
   ========================================================================= */
.uepwa-chat-loading {
    display: flex;
    justify-content: center;
    padding: 20px;
}

.uepwa-chat-loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #bbb;
    margin: 0 3px;
    animation: uepwa-chat-bounce 1.4s infinite ease-in-out both;
}

.uepwa-chat-loading-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.uepwa-chat-loading-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes uepwa-chat-bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}