/* -----------------------------------------------------------
   Muah Muah � AI Chatbot Widget � css/chatbot.css
   Follows the 8px grid system, CSS variables, and
   prefers-reduced-motion rule from the site design system.
   ----------------------------------------------------------- */

/* -- Widget Root Variables ------------------------------- */
:root {
    --chat-primary:      #8E8E8E;
    --chat-accent:       #FFFFFF;
    --chat-bg:           #0F0F0F;
    --chat-surface:      #1A1A1A;
    --chat-surface-2:    #222222;
    --chat-border:       rgba(255, 255, 255, 0.1);
    --chat-text:         #FFFFFF;
    --chat-muted:        #A0A0A0;
    --chat-bubble-user:  linear-gradient(135deg, #8E8E8E, #B8B8B8);
    --chat-bubble-bot:   #1E1E1E;
    --chat-glow:         rgba(142, 142, 142, 0.25);
    --chat-shadow:       0 32px 64px rgba(0, 0, 0, 0.6);
    --chat-radius:       20px;
    --chat-radius-msg:   18px;
    --chat-z:            9999;
    --chat-transition:   all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

/* -- Toggle Bubble --------------------------------------- */
#mrko-chat-toggle {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8E8E8E, #FFFFFF);
    border: none;
    cursor: pointer;
    z-index: var(--chat-z);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 32px var(--chat-glow), 0 2px 8px rgba(0,0,0,0.4);
    transition: var(--chat-transition);
    outline: none;
    overflow: hidden;
}

#mrko-chat-toggle::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8E8E8E, #ffffff80);
    z-index: -1;
    animation: chat-pulse 2.5s ease-in-out infinite;
}

#mrko-chat-toggle:hover {
    transform: scale(1.12) translateY(-4px);
    box-shadow: 0 16px 48px var(--chat-glow), 0 4px 16px rgba(0,0,0,0.5);
}

#mrko-chat-toggle:focus-visible {
    outline: 3px solid var(--chat-primary);
    outline-offset: 4px;
}

.chat-toggle-icon,
.chat-toggle-close {
    position: absolute;
    font-size: 1.5rem;
    color: #000;
    transition: var(--chat-transition);
    line-height: 1;
}

.chat-toggle-icon { opacity: 1; transform: scale(1) rotate(0deg); }
.chat-toggle-close { opacity: 0; transform: scale(0.5) rotate(-90deg); }

#mrko-chat-toggle.is-open .chat-toggle-icon {
    opacity: 0;
    transform: scale(0.5) rotate(90deg);
}
#mrko-chat-toggle.is-open .chat-toggle-close {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

/* Notification badge */
#mrko-chat-toggle .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: #ff4757;
    border-radius: 50%;
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: badge-pop 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    font-family: 'Inter', sans-serif;
}

/* -- Chat Window ----------------------------------------- */
#mrko-chat-window {
    position: fixed;
    bottom: 112px;
    right: 32px;
    width: 380px;
    max-height: 580px;
    border-radius: var(--chat-radius);
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    z-index: var(--chat-z);
    overflow: hidden;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);

    /* Hidden state */
    opacity: 0;
    transform: translateY(24px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.23, 1, 0.32, 1),
                transform 0.35s cubic-bezier(0.23, 1, 0.32, 1);
}

#mrko-chat-window.is-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* -- Chat Header ----------------------------------------- */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: linear-gradient(135deg, #141414, #1A1A1A);
    border-bottom: 1px solid var(--chat-border);
    flex-shrink: 0;
    position: relative;
}

.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8E8E8E, #FFFFFF);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: #000;
    flex-shrink: 0;
    box-shadow: 0 0 16px var(--chat-glow);
}

.chat-header-info {
    flex: 1;
}

.chat-header-name {
    font-family: 'Playfair Display', serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--chat-text);
    letter-spacing: 0.5px;
}

.chat-header-status {
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    color: var(--chat-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ed573;
    animation: status-pulse 2s ease-in-out infinite;
    flex-shrink: 0;
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.chat-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--chat-surface-2);
    border: 1px solid var(--chat-border);
    color: var(--chat-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    transition: var(--chat-transition);
}

.chat-header-btn:hover {
    background: var(--chat-primary);
    color: #000;
    border-color: transparent;
}

#mrko-wa-btn:hover {
    background: #25D366;
    color: #fff;
    border-color: transparent;
}

.chat-header-btn:focus-visible {
    outline: 2px solid var(--chat-primary);
    outline-offset: 2px;
}

/* -- Messages Area --------------------------------------- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: var(--chat-surface-2) transparent;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--chat-surface-2);
    border-radius: 4px;
}

/* -- Message Bubbles ------------------------------------- */
.chat-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: msg-appear 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}

.chat-message.user { flex-direction: row-reverse; }

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
}

.msg-avatar.bot-avatar {
    background: linear-gradient(135deg, #8E8E8E, #C0C0C0);
    color: #000;
}

.msg-avatar.user-avatar {
    background: var(--chat-surface-2);
    color: var(--chat-muted);
    border: 1px solid var(--chat-border);
}

.msg-bubble {
    max-width: 78%;
    padding: 12px 16px;
    border-radius: var(--chat-radius-msg);
    font-family: 'Inter', sans-serif;
    font-size: 0.88rem;
    line-height: 1.55;
    word-break: break-word;
    position: relative;
}

.chat-message.bot .msg-bubble {
    background: var(--chat-bubble-bot);
    color: var(--chat-text);
    border: 1px solid var(--chat-border);
    border-bottom-left-radius: 4px;
}

.chat-message.user .msg-bubble {
    background: var(--chat-bubble-user);
    color: #000;
    font-weight: 500;
    border-bottom-right-radius: 4px;
}

.msg-time {
    font-size: 0.65rem;
    color: var(--chat-muted);
    margin-top: 4px;
    display: block;
    opacity: 0.7;
}

.chat-message.user .msg-time { text-align: right; }

/* -- Typing Indicator ------------------------------------ */
.typing-indicator {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: msg-appear 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}

.typing-dots {
    background: var(--chat-bubble-bot);
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius-msg);
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    display: flex;
    gap: 5px;
    align-items: center;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--chat-muted);
    border-radius: 50%;
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* -- Suggested Prompts ----------------------------------- */
.chat-suggestions {
    padding: 0 16px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
}

.suggestion-chip {
    background: var(--chat-surface-2);
    border: 1px solid var(--chat-border);
    color: var(--chat-muted);
    border-radius: 50px;
    padding: 6px 14px;
    font-size: 0.75rem;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: var(--chat-transition);
    white-space: nowrap;
}

.suggestion-chip:hover {
    background: var(--chat-primary);
    color: #000;
    border-color: transparent;
    transform: translateY(-1px);
}

.suggestion-chip:focus-visible {
    outline: 2px solid var(--chat-primary);
    outline-offset: 2px;
}

/* -- Input Area ------------------------------------------ */
.chat-input-area {
    padding: 12px 16px 16px;
    border-top: 1px solid var(--chat-border);
    background: var(--chat-surface);
    flex-shrink: 0;
}

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--chat-surface-2);
    border: 1px solid var(--chat-border);
    border-radius: 50px;
    padding: 8px 8px 8px 16px;
    transition: var(--chat-transition);
}

.chat-input-row:focus-within {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(142, 142, 142, 0.15);
}

#mrko-chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--chat-text);
    font-family: 'Inter', sans-serif;
    font-size: 0.88rem;
    resize: none;
    max-height: 80px;
    line-height: 1.5;
    scrollbar-width: none;
    padding: 4px 0;
}

#mrko-chat-input::placeholder { color: var(--chat-muted); }
#mrko-chat-input::-webkit-scrollbar { display: none; }

#mrko-chat-send, #mrko-chat-mic {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8E8E8E, #C0C0C0);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    color: #000;
    transition: var(--chat-transition);
    flex-shrink: 0;
}

#mrko-chat-mic {
    background: transparent;
    color: var(--chat-muted);
}

#mrko-chat-mic:hover {
    color: var(--chat-text);
    transform: scale(1.1);
}

#mrko-chat-mic.recording {
    color: #ff4757;
    animation: mic-pulse 1.5s infinite;
}

@keyframes mic-pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

#mrko-chat-send:hover {
    transform: scale(1.1);
    background: linear-gradient(135deg, #A0A0A0, #FFFFFF);
    box-shadow: 0 4px 16px var(--chat-glow);
}

#mrko-chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

#mrko-chat-send:focus-visible {
    outline: 2px solid var(--chat-primary);
    outline-offset: 2px;
}

.chat-footer-note {
    text-align: center;
    font-size: 0.62rem;
    color: var(--chat-muted);
    margin-top: 8px;
    font-family: 'Inter', sans-serif;
    opacity: 0.6;
}

/* -- Welcome / Error State ------------------------------- */
.chat-welcome {
    text-align: center;
    padding: 24px 16px;
}

.chat-welcome-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.chat-welcome h3 {
    font-family: 'Playfair Display', serif;
    font-size: 1.1rem;
    color: var(--chat-text);
    margin-bottom: 8px;
}

.chat-welcome p {
    font-size: 0.8rem;
    color: var(--chat-muted);
    line-height: 1.5;
    font-family: 'Inter', sans-serif;
}

/* -- Animations ------------------------------------------ */
@keyframes chat-pulse {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50%       { opacity: 0.2; transform: scale(1.15); }
}

@keyframes status-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

@keyframes typing-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40%            { transform: translateY(-6px); opacity: 1; }
}

@keyframes msg-appear {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes badge-pop {
    from { transform: scale(0); }
    to   { transform: scale(1); }
}

/* -- Reduced Motion -------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    #mrko-chat-toggle::before,
    .status-dot,
    .typing-dots span {
        animation: none !important;
    }
    .chat-message,
    .typing-indicator,
    #mrko-chat-window,
    #mrko-chat-toggle,
    .suggestion-chip,
    .chat-header-btn,
    #mrko-chat-send {
        transition: none !important;
        animation: none !important;
    }
}

/* -- Responsive ------------------------------------------ */
@media (max-width: 480px) {
    #mrko-chat-window {
        width: calc(100vw - 32px);
        right: 16px;
        bottom: 96px;
        max-height: 70vh;
    }
    #mrko-chat-toggle {
        right: 16px;
        bottom: 16px;
    }
}
