/* ElitePlay AI Agent - Frontend Widget */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

#eliteplay-ai-root {
    --ep-primary: #6366f1;
    --ep-primary-rgb: 99,102,241;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    position: fixed;
    z-index: 999999;
}

/* Position variants */
#eliteplay-ai-root[data-position="bottom-right"] { bottom: 24px; right: 24px; }
#eliteplay-ai-root[data-position="bottom-left"]  { bottom: 24px; left: 24px; }

/* ─── DARK THEME (default) ─── */
#eliteplay-ai-root[data-theme="dark"] {
    --bg-chat:    #0f0f13;
    --bg-header:  #1a1a24;
    --bg-surface: #1e1e2a;
    --bg-bubble-user: rgba(var(--ep-primary-rgb), 0.85);
    --bg-bubble-bot:  #2a2a38;
    --text-primary:   #eeeef8;
    --text-secondary: #8888a8;
    --text-bubble-user: #ffffff;
    --text-bubble-bot:  #ddddf0;
    --border:     rgba(255,255,255,0.08);
    --shadow:     0 20px 60px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.06);
    --input-bg:   #16161e;
    --footer-bg:  #151520;
}

/* ─── LIGHT THEME ─── */
#eliteplay-ai-root[data-theme="light"] {
    --bg-chat:    #ffffff;
    --bg-header:  #f8f8ff;
    --bg-surface: #f0f0f8;
    --bg-bubble-user: var(--ep-primary);
    --bg-bubble-bot:  #f0f0f8;
    --text-primary:   #1a1a2e;
    --text-secondary: #6666a0;
    --text-bubble-user: #ffffff;
    --text-bubble-bot:  #1a1a2e;
    --border:     rgba(0,0,0,0.08);
    --shadow:     0 20px 60px rgba(0,0,0,0.2), 0 0 0 1px rgba(0,0,0,0.06);
    --input-bg:   #f8f8ff;
    --footer-bg:  #f4f4fc;
}

/* ─── FLOATING BUBBLE ─── */
.ep-chat-bubble {
    width: 60px; height: 60px;
    background: var(--ep-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 32px rgba(var(--ep-primary-rgb), 0.5), 0 2px 8px rgba(0,0,0,0.3);
    transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.3s;
    position: relative;
    outline: none;
}
.ep-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 40px rgba(var(--ep-primary-rgb), 0.65), 0 2px 8px rgba(0,0,0,0.3);
}
.ep-bubble-icon {
    width: 26px; height: 26px;
    color: #ffffff;
    transition: opacity 0.2s, transform 0.3s;
    position: absolute;
}
.ep-icon-close { opacity: 0; transform: rotate(-90deg); }
.ep-icon-chat  { opacity: 1; transform: rotate(0deg); }

#eliteplay-ai-root.ep-open .ep-icon-close { opacity: 1; transform: rotate(0deg); }
#eliteplay-ai-root.ep-open .ep-icon-chat  { opacity: 0; transform: rotate(90deg); }

/* Pulse animation */
.ep-chat-bubble::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    background: var(--ep-primary);
    opacity: 0;
    animation: ep-pulse 2.5s ease-out infinite;
}
@keyframes ep-pulse {
    0%   { opacity: 0.4; transform: scale(1); }
    100% { opacity: 0;   transform: scale(1.6); }
}

/* Notification badge */
.ep-notification-badge {
    position: absolute;
    top: -2px; right: -2px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px; height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid #fff;
    animation: ep-bounce 1s ease infinite alternate;
}
@keyframes ep-bounce { to { transform: translateY(-2px); } }
.ep-notification-badge.ep-hidden { display: none; }

/* ─── CHAT WINDOW ─── */
.ep-chat-window {
    position: absolute;
    width: 380px;
    height: 580px;
    background: var(--bg-chat);
    border-radius: 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.85) translateY(20px);
    transform-origin: bottom right;
    transition: opacity 0.3s, transform 0.3s cubic-bezier(0.34,1.1,0.64,1);
}

[data-position="bottom-left"] .ep-chat-window {
    transform-origin: bottom left;
    right: auto;
    left: 0;
}

#eliteplay-ai-root.ep-open .ep-chat-window {
    opacity: 1;
    pointer-events: all;
    transform: scale(1) translateY(0);
}

/* Position chat window above bubble */
[data-position="bottom-right"] .ep-chat-window { bottom: 76px; right: 0; }
[data-position="bottom-left"]  .ep-chat-window { bottom: 76px; left: 0; }

/* ─── HEADER ─── */
.ep-chat-header {
    background: var(--bg-header);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.ep-header-info { display: flex; align-items: center; gap: 12px; }
.ep-agent-avatar {
    position: relative;
    width: 44px; height: 44px;
    flex-shrink: 0;
}
.ep-avatar-img, .ep-avatar-initials {
    width: 44px; height: 44px;
    border-radius: 50%;
    object-fit: cover;
}
.ep-avatar-initials {
    background: var(--ep-primary);
    color: #fff;
    font-weight: 700;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ep-status-dot {
    position: absolute;
    bottom: 0; right: 0;
    width: 12px; height: 12px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid var(--bg-header);
}
.ep-agent-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
}
.ep-agent-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}
.ep-status-indicator {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #22c55e;
    animation: ep-blink 2s ease infinite;
}
@keyframes ep-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

.ep-header-actions { display: flex; gap: 4px; }
.ep-btn-icon {
    width: 32px; height: 32px;
    background: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background 0.2s, color 0.2s;
}
.ep-btn-icon:hover { background: var(--bg-surface); color: var(--text-primary); }
.ep-btn-icon svg { width: 16px; height: 16px; }

/* ─── MESSAGES AREA ─── */
.ep-messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}
.ep-messages-area::-webkit-scrollbar { width: 4px; }
.ep-messages-area::-webkit-scrollbar-track { background: transparent; }
.ep-messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ─── MESSAGE BUBBLES ─── */
.ep-message {
    display: flex;
    gap: 8px;
    animation: ep-msg-in 0.3s ease;
    max-width: 100%;
}
@keyframes ep-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ep-message.ep-msg-user  { flex-direction: row-reverse; }
.ep-message.ep-msg-bot   { flex-direction: row; }

.ep-msg-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    align-self: flex-end;
    overflow: hidden;
}
.ep-msg-avatar img  { width: 100%; height: 100%; object-fit: cover; }
.ep-msg-avatar .ep-avatar-initials {
    width: 28px; height: 28px;
    font-size: 11px;
}

.ep-msg-content { display: flex; flex-direction: column; gap: 4px; max-width: calc(100% - 44px); }
.ep-msg-user .ep-msg-content { align-items: flex-end; }

.ep-msg-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
}
.ep-msg-user .ep-msg-bubble {
    background: var(--bg-bubble-user);
    color: var(--text-bubble-user);
    border-bottom-right-radius: 4px;
}
.ep-msg-bot .ep-msg-bubble {
    background: var(--bg-bubble-bot);
    color: var(--text-bubble-bot);
    border-bottom-left-radius: 4px;
}

.ep-msg-time {
    font-size: 10px;
    color: var(--text-secondary);
    padding: 0 4px;
}

/* ─── SUGGESTIONS ─── */
.ep-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 16px 4px;
}
.ep-suggestion-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ep-suggestion-btn:hover {
    background: rgba(var(--ep-primary-rgb), 0.12);
    border-color: rgba(var(--ep-primary-rgb), 0.4);
    color: var(--ep-primary);
}

/* ─── TYPING INDICATOR ─── */
.ep-typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 16px 8px;
    animation: ep-msg-in 0.2s ease;
}
.ep-typing-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}
.ep-typing-bubble {
    background: var(--bg-bubble-bot);
    border-radius: 18px 18px 18px 4px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.ep-typing-bubble span {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: ep-type 1.2s ease infinite;
}
.ep-typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.ep-typing-bubble span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ep-type {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%            { transform: translateY(-6px); opacity: 1; }
}

/* ─── FOOTER / INPUT ─── */
.ep-chat-footer {
    background: var(--footer-bg);
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}
.ep-input-wrapper { flex: 1; }
.ep-message-input {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    color: var(--text-primary);
    font-family: inherit;
    resize: none;
    outline: none;
    line-height: 1.5;
    max-height: 120px;
    transition: border-color 0.2s;
    box-sizing: border-box;
}
.ep-message-input::placeholder { color: var(--text-secondary); }
.ep-message-input:focus { border-color: var(--ep-primary); }

.ep-send-btn, .ep-human-btn {
    width: 38px; height: 38px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}
.ep-send-btn {
    background: var(--ep-primary);
    color: #fff;
}
.ep-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.ep-send-btn:not(:disabled):hover {
    background: color-mix(in srgb, var(--ep-primary) 80%, black);
    transform: scale(1.05);
}
.ep-send-btn svg, .ep-human-btn svg { width: 17px; height: 17px; }

.ep-human-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.ep-human-btn:hover {
    border-color: #22c55e;
    color: #22c55e;
}

/* ─── BRANDING ─── */
.ep-branding {
    background: var(--footer-bg);
    text-align: center;
    padding: 5px 0 8px;
    font-size: 10px;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.ep-branding span { color: var(--ep-primary); font-weight: 600; }

/* ─── SYSTEM MESSAGES ─── */
.ep-system-msg {
    text-align: center;
    font-size: 11px;
    color: var(--text-secondary);
    padding: 4px 16px;
    animation: ep-msg-in 0.2s ease;
}

/* ─── ERROR MESSAGE ─── */
.ep-msg-error .ep-msg-bubble {
    background: rgba(239,68,68,0.12);
    border: 1px solid rgba(239,68,68,0.2);
    color: #ef4444;
}

/* ─── MOBILE RESPONSIVE ─── */
@media (max-width: 480px) {
    #eliteplay-ai-root[data-position="bottom-right"],
    #eliteplay-ai-root[data-position="bottom-left"] {
        bottom: 16px;
        right: 16px;
        left: 16px;
    }
    .ep-chat-window {
        width: calc(100vw - 32px);
        height: calc(100dvh - 100px);
        border-radius: 16px;
        bottom: 72px !important;
        right: 0 !important;
        left: 0 !important;
    }
    [data-position="bottom-left"] .ep-chat-window { left: 0 !important; }
    .ep-chat-bubble {
        position: absolute;
        bottom: 0;
        right: 0;
    }
    [data-position="bottom-right"] .ep-chat-bubble { right: 0; }
    [data-position="bottom-left"]  .ep-chat-bubble { left: 0; right: auto; }
}
