/* Modern Chatbot Styles - JoyBot Overhaul (Messenger Style) */
:root {
    --joybot-primary: #8b0000;
    --joybot-primary-gradient: linear-gradient(135deg, #8b0000 0%, #b30000 100%);
    --joybot-secondary: #f0f0f0;
    --joybot-accent: #ffc107;
    --joybot-text: #050505;
    --joybot-text-light: #65676b;
    --joybot-white: #ffffff;
    --joybot-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    --joybot-radius: 12px;
    --joybot-font: 'Poppins', 'Segoe UI', Helvetica, Arial, sans-serif;
}

/* --- Toggle Button --- */
#joybot-toggle-button {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 60px;
    height: 60px;
    background: var(--joybot-primary-gradient);
    border-radius: 50%;
    box-shadow: var(--joybot-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 9999;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

#joybot-toggle-button:hover {
    transform: scale(1.1);
}

#joybot-toggle-button i {
    color: var(--joybot-white);
    font-size: 28px;
}

@keyframes joybot-pulse {
    0% { box-shadow: 0 0 0 0 rgba(139, 0, 0, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(139, 0, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(139, 0, 0, 0); }
}

#joybot-toggle-button:not(:hover) {
    animation: joybot-pulse 2s infinite;
}

.joybot-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--joybot-accent);
    color: #000;
    font-size: 12px;
    font-weight: bold;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* --- Chat Window --- */
#joybot-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 420px;
    height: 650px;
    max-height: calc(100vh - 110px);
    background: var(--joybot-white);
    border-radius: var(--joybot-radius);
    box-shadow: var(--joybot-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
    font-family: var(--joybot-font);
    opacity: 1;
    transform: translateY(0);
    transition: all 0.3s ease;
    border: 1px solid rgba(0,0,0,0.1);
}

#joybot-window.hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

/* Minimized State */
#joybot-window.minimized {
    height: 60px !important;
    overflow: hidden;
    bottom: 20px;
    border-radius: 30px;
    width: 420px;
}

/* Maximized State */
#joybot-window.maximized {
    width: 90vw !important;
    height: 90vh !important;
    bottom: 20px;
    right: 20px;
    max-height: none;
    border-radius: var(--joybot-radius);
}

/* --- Header --- */
.joybot-header {
    background: var(--joybot-white);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--joybot-text);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    flex-shrink: 0;
    border-bottom: 1px solid #eee;
    height: 60px;
    box-sizing: border-box;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bot-avatar {
    width: 36px;
    height: 36px;
    background: var(--joybot-primary-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
}

.header-text h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}

.status {
    font-size: 12px;
    color: var(--joybot-text-light);
    display: flex;
    align-items: center;
    gap: 4px;
}

.status::before {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    background: #31a24c;
    border-radius: 50%;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-actions button {
    background: transparent;
    border: none;
    color: var(--joybot-primary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 16px;
}

.header-actions button:hover {
    background: rgba(0,0,0,0.05);
    transform: scale(1.1);
}

/* --- Body Container --- */
.joybot-body {
    flex: 1;
    background: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Messages Container - Scrollable */
#joybot-messages-container {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Chat Controls */
.chat-controls {
    display: flex;
    justify-content: center;
    padding: 8px 0;
}

.end-session-btn {
    background: none;
    border: none;
    color: var(--joybot-text-light);
    padding: 6px 12px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: underline;
}

.end-session-btn:hover {
    color: var(--joybot-primary);
}

/* --- Messages --- */
.message-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 4px;
}

.bot-wrapper {
    justify-content: flex-start;
}

.user-wrapper {
    justify-content: flex-end;
}

.message-avatar {
    width: 28px;
    height: 28px;
    background: var(--joybot-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    flex-shrink: 0;
}

.joybot-message {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    text-align: left;
}

.joybot-bot {
    background: var(--joybot-secondary);
    color: var(--joybot-text);
    border-bottom-left-radius: 4px;
}

.joybot-user {
    background: var(--joybot-primary);
    color: var(--joybot-white);
    border-bottom-right-radius: 4px;
}

/* --- Typing Indicator --- */
.joybot-typing-indicator {
    background: var(--joybot-secondary);
    padding: 12px 16px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 4px;
    width: fit-content;
    margin-left: 36px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #90949c;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* --- Quick Replies (Fixed at bottom of body) --- */
.joybot-quick-replies {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 10px 16px;
    scrollbar-width: none;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    flex-wrap: wrap;
    flex-shrink: 0;
    max-height: 120px;
}
.joybot-quick-replies::-webkit-scrollbar { display: none; }

/* Wrap chips in normal view, scroll in maximized */
#joybot-window:not(.maximized) .joybot-quick-replies {
    flex-wrap: wrap;
    overflow-y: auto;
}

#joybot-window.maximized .joybot-quick-replies {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: 60px;
}

.quick-reply-chip {
    background: transparent;
    color: var(--joybot-primary);
    border: 1px solid var(--joybot-primary);
    padding: 8px 16px;
    border-radius: 18px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    height: fit-content;
}

.quick-reply-chip:hover {
    background: var(--joybot-primary);
    color: var(--joybot-white);
    transform: translateY(-2px);
}

.quick-reply-chip i {
    margin-right: 6px;
}

/* --- Footer / Input --- */
.joybot-footer {
    padding: 12px 16px;
    background: var(--joybot-white);
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}

.input-container {
    display: flex;
    gap: 8px;
    background: #f0f2f5;
    padding: 10px 16px;
    border-radius: 24px;
    align-items: center;
}

#joybot-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 4px 8px;
    font-size: 14px;
    outline: none;
    color: var(--joybot-text);
}

#joybot-send-btn {
    background: transparent;
    color: var(--joybot-primary);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 18px;
    flex-shrink: 0;
}

#joybot-send-btn:hover {
    background: rgba(139, 0, 0, 0.1);
    transform: scale(1.1);
}

/* --- Responsive --- */
@media (max-width: 480px) {
    #joybot-window {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
        max-height: 100vh;
    }
    #joybot-toggle-button {
        bottom: 20px;
        right: 20px;
    }
}

.hidden { display: none !important; }
