/* ============================================
   AYLA Chat Widget - JODai AI Customer Assistant
   ============================================ */

:root {
    --ayla-primary: #2E75B6;
    --ayla-primary-dark: #1B5A94;
    --ayla-primary-light: #E8F0FE;
    --ayla-accent: #E67E22;
    --ayla-bg: #FFFFFF;
    --ayla-bg-dark: #F5F7FA;
    --ayla-text: #1A1A1A;
    --ayla-text-light: #666666;
    --ayla-border: #E0E4E8;
    --ayla-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    --ayla-radius: 16px;
    --ayla-radius-sm: 12px;
    --ayla-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Toggle Button ---- */
#ayla-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--ayla-primary);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(46, 117, 182, 0.4);
    z-index: 99998;
    transition: var(--ayla-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

#ayla-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(46, 117, 182, 0.5);
}

#ayla-toggle.active {
    transform: rotate(0deg);
}

#ayla-toggle svg {
    width: 28px;
    height: 28px;
    fill: white;
    transition: var(--ayla-transition);
}

#ayla-toggle .ayla-close-icon {
    display: none;
}

#ayla-toggle.active .ayla-chat-icon {
    display: none;
}

#ayla-toggle.active .ayla-close-icon {
    display: block;
}

/* Notification badge */
#ayla-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--ayla-accent);
    color: white;
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

#ayla-badge.show {
    display: flex;
    animation: aylaPulse 2s infinite;
}

@keyframes aylaPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* ---- Chat Window ---- */
#ayla-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: var(--ayla-bg);
    border-radius: var(--ayla-radius);
    box-shadow: var(--ayla-shadow);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: var(--ayla-transition);
}

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

/* ---- Header ---- */
.ayla-header {
    background: linear-gradient(135deg, var(--ayla-primary), var(--ayla-primary-dark));
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.ayla-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.ayla-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ayla-avatar svg {
    width: 26px;
    height: 26px;
    fill: white;
}

.ayla-header-info {
    flex: 1;
    min-width: 0;
}

.ayla-header-name {
    color: white;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
}

.ayla-header-status {
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ayla-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ADE80;
    animation: aylaDotPulse 2s infinite;
}

@keyframes aylaDotPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.ayla-header-actions {
    display: flex;
    gap: 8px;
}

.ayla-header-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--ayla-transition);
    padding: 0;
}

.ayla-header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.ayla-header-btn svg {
    width: 16px;
    height: 16px;
    fill: white;
}

/* ---- Messages Area ---- */
.ayla-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

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

.ayla-messages::-webkit-scrollbar-thumb {
    background: var(--ayla-border);
    border-radius: 4px;
}

/* ---- Message Bubbles ---- */
.ayla-msg {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: aylaFadeIn 0.3s ease;
}

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

.ayla-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ayla-msg.assistant {
    align-self: flex-start;
}

.ayla-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.ayla-msg.assistant .ayla-msg-avatar {
    background: var(--ayla-primary-light);
    color: var(--ayla-primary);
}

.ayla-msg.user .ayla-msg-avatar {
    background: var(--ayla-bg-dark);
    color: var(--ayla-text-light);
}

.ayla-msg-bubble {
    padding: 12px 16px;
    border-radius: var(--ayla-radius-sm);
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.ayla-msg.assistant .ayla-msg-bubble {
    background: var(--ayla-bg-dark);
    color: var(--ayla-text);
    border-bottom-left-radius: 4px;
}

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

/* Markdown in messages */
.ayla-msg-bubble p { margin: 0 0 8px; }
.ayla-msg-bubble p:last-child { margin-bottom: 0; }
.ayla-msg-bubble strong { font-weight: 600; }
.ayla-msg-bubble ul, .ayla-msg-bubble ol { margin: 4px 0; padding-left: 20px; }
.ayla-msg-bubble li { margin-bottom: 4px; }
.ayla-msg-bubble a { color: var(--ayla-primary); text-decoration: underline; }
.ayla-msg.user .ayla-msg-bubble a { color: #E8F0FE; }
.ayla-msg-bubble code {
    background: rgba(0,0,0,0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

/* ---- Typing Indicator ---- */
.ayla-typing {
    display: none;
    align-self: flex-start;
    padding: 12px 20px;
    background: var(--ayla-bg-dark);
    border-radius: var(--ayla-radius-sm);
    border-bottom-left-radius: 4px;
    gap: 4px;
    align-items: center;
    margin-left: 40px;
}

.ayla-typing.show {
    display: flex;
}

.ayla-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ayla-primary);
    animation: aylaTyping 1.4s infinite;
}

.ayla-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ayla-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes aylaTyping {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

/* ---- Quick Replies ---- */
.ayla-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 16px;
    background: var(--ayla-bg);
    border-top: 1px solid var(--ayla-border);
    flex-shrink: 0;
}

.ayla-quick-btn {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid var(--ayla-primary);
    background: white;
    color: var(--ayla-primary);
    font-size: 13px;
    cursor: pointer;
    transition: var(--ayla-transition);
    white-space: nowrap;
}

.ayla-quick-btn:hover {
    background: var(--ayla-primary);
    color: white;
}

/* ---- Input Area ---- */
.ayla-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--ayla-border);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
    background: var(--ayla-bg);
}

.ayla-input-wrapper {
    flex: 1;
    position: relative;
}

#ayla-input {
    width: 100%;
    border: 1px solid var(--ayla-border);
    border-radius: var(--ayla-radius-sm);
    padding: 12px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: var(--ayla-transition);
    max-height: 120px;
    min-height: 44px;
    line-height: 1.4;
    box-sizing: border-box;
}

#ayla-input:focus {
    border-color: var(--ayla-primary);
    box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.12);
}

#ayla-input::placeholder {
    color: var(--ayla-text-light);
}

#ayla-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--ayla-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--ayla-transition);
    padding: 0;
}

#ayla-send:hover {
    background: var(--ayla-primary-dark);
    transform: scale(1.05);
}

#ayla-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

#ayla-send svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* ---- Powered By ---- */
.ayla-powered {
    text-align: center;
    padding: 6px;
    font-size: 11px;
    color: var(--ayla-text-light);
    background: var(--ayla-bg-dark);
    flex-shrink: 0;
}

/* ---- Mobile Responsive ---- */
@media (max-width: 480px) {
    #ayla-window {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    #ayla-toggle {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .ayla-msg {
        max-width: 90%;
    }
}

/* ---- Dark mode support ---- */
@media (prefers-color-scheme: dark) {
    :root {
        --ayla-bg: #1E1E2E;
        --ayla-bg-dark: #2A2A3E;
        --ayla-text: #E0E0E0;
        --ayla-text-light: #999;
        --ayla-border: #3A3A4E;
    }

    .ayla-msg.assistant .ayla-msg-bubble {
        background: var(--ayla-bg-dark);
    }

    #ayla-input {
        background: var(--ayla-bg-dark);
        color: var(--ayla-text);
    }

    .ayla-quick-btn {
        background: var(--ayla-bg-dark);
        border-color: var(--ayla-primary);
    }
}
