/* Wonda Chat Widget Styles - Space Optimized */
:root {
    --wonda-primary: #0073aa;
    --wonda-text: #333;
    --wonda-bg: #fff;
    --wonda-user-bg: #e3f2fd;
    --wonda-bot-bg: #f1f3f5;
    --wonda-border: #e2e8f0;
    --wonda-shadow: 0 10px 25px rgba(0,0,0,0.1);
    --wonda-radius: 16px;
}

/* Widget container */
#wonda-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#wonda-chat-widget[data-position="bottom-left"] {
    right: auto;
    left: 20px;
}

/* Chat bubble */
#wonda-chat-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--wonda-primary);
    cursor: pointer;
    box-shadow: var(--wonda-shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 30px;
}

#wonda-chat-bubble:hover {
    transform: scale(1.05);
    box-shadow: 0 15px 30px rgba(0,115,170,0.2);
}

#wonda-chat-bubble::after {
    content: "💬";
}

/* Chat window */
#wonda-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--wonda-bg);
    border-radius: var(--wonda-radius);
    box-shadow: var(--wonda-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
    border: 1px solid var(--wonda-border);
}

#wonda-chat-widget[data-position="bottom-left"] #wonda-chat-window {
    right: auto;
    left: 0;
}

#wonda-chat-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Header (unchanged) */
.wonda-header {
    padding: 8px 10px;
    background: var(--wonda-primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.wonda-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.wonda-title img.wonda-logo {
    height: 20px;
    width: auto;
}

.wonda-header-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.wonda-close, .wonda-menu-button, .wonda-human-escalation {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.wonda-close:hover, .wonda-menu-button:hover, .wonda-human-escalation:hover {
    background: rgba(255,255,255,0.2);
}

.wonda-close {
    font-size: 24px;
    line-height: 1;
}

/* Menu dropdown */
.wonda-menu-container {
    position: relative;
}

.wonda-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.15);
    min-width: 150px;
    margin-top: 5px;
    display: none;
    overflow: hidden;
    border: 1px solid var(--wonda-border);
    z-index: 1000;
}

.wonda-dropdown.active {
    display: block;
}

.wonda-dropdown-item {
    padding: 10px 15px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #333;
    font-size: 14px;
}

.wonda-dropdown-item:hover {
    background: #f5f5f5;
}

.wonda-dropdown-item .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
}

/* Messages area - more compact */
.wonda-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px 12px;  /* Reduced from 20px */
    display: flex;
    flex-direction: column;
    gap: 12px;            /* Slightly reduced gap */
    scroll-behavior: smooth;
}

.wonda-message {
    max-width: 85%;
    padding: 10px 14px;   /* Reduced from 12px 16px */
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 14px;
    position: relative;
}

.wonda-message.user-message {
    background: var(--wonda-user-bg);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.wonda-message.bot-message {
    background: var(--wonda-bot-bg);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message-content {
    margin-bottom: 4px;
}

.message-content p {
    margin: 0 0 6px 0;    /* Reduced bottom margin */
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content a {
    color: var(--wonda-primary);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content pre {
    background: #2d3748;
    color: #e2e8f0;
    padding: 8px;          /* Reduced from 10px */
    border-radius: 8px;
    overflow-x: auto;
    font-size: 12px;
    margin: 8px 0;
}

.message-time {
    font-size: 10px;
    color: #999;
    text-align: right;
    margin-top: 4px;
}

/* Typing indicator */
.wonda-typing-indicator {
    display: flex;
    gap: 5px;
    padding: 10px 14px;    /* Reduced from 12px 16px */
    background: var(--wonda-bot-bg);
    border-radius: 18px;
    align-self: flex-start;
    margin-bottom: 8px;     /* Reduced from 10px */
}

/* --- FIX: Add span styles and animation --- */
.wonda-typing-indicator span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.wonda-typing-indicator span:nth-child(1) { animation-delay: 0s; }
.wonda-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.wonda-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.6; }
    40% { transform: scale(1); opacity: 1; }
}

/* Quick prompts */
.wonda-quick-prompts {
    padding: 8px 12px;      /* Reduced from 10px 20px */
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    border-top: 1px solid var(--wonda-border);
    background: #f9fafc;
}

.wonda-quick-prompt {
    background: white;
    border: 1px solid var(--wonda-primary);
    color: var(--wonda-primary);
    padding: 5px 10px;      /* Slightly smaller */
    border-radius: 30px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.wonda-quick-prompt:hover {
    background: var(--wonda-primary);
    color: white;
}

/* Input area - compact and button fixed */
.wonda-input-area {
    padding: 4px 8px;              /* Minimal padding around the whole bar */
    border-top: 1px solid var(--wonda-border);
    display: flex;
    gap: 6px;                      /* Tighter gap between textarea and button */
    background: #f9fafc;
    align-items: flex-end;
}

.wonda-input-area textarea {
    flex: 1;
    border: 1px solid var(--wonda-border);
    border-radius: 18px;
    padding: 4px 10px;             /* Reduced top/bottom padding to 4px */
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.3;              /* Slightly tighter line-height */
    max-height: 100px;
    outline: none;
    transition: border-color 0.2s;
    min-height: 32px;              /* Lower minimum height */
    vertical-align: middle;        /* Ensure content aligns properly */
    box-sizing: border-box;        /* Include padding in height calculation */
}

.wonda-input-area textarea:focus {
    border-color: var(--wonda-primary);
}

.wonda-input-area .wonda-send {
    background: var(--wonda-primary);
    color: white;
    border: none;
    border-radius: 18px;
    padding: 0 12px;               /* Slightly narrower button */
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    height: 32px;                  /* Match textarea min-height for alignment */
    line-height: 32px;             /* Center text vertically */
    font-size: 14px;
    white-space: nowrap;
    flex-shrink: 0;
}

.wonda-input-area .wonda-send:hover {
    background: #005a87;
}

.wonda-input-area .wonda-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* System announcement */
.wonda-announcement {
    background: #fff3cd;
    color: #856404;
    padding: 8px 16px;
    font-size: 12px;
    text-align: center;
    border-bottom: 1px solid #ffeeba;
}

/* Dark mode support */
.wonda-dark {
    --wonda-bg: #1a202c;
    --wonda-text: #e2e8f0;
    --wonda-user-bg: #2d3748;
    --wonda-bot-bg: #2d3748;
    --wonda-border: #4a5568;
    color: var(--wonda-text);
}

.wonda-dark .wonda-message.bot-message {
    background: #2d3748;
    color: #e2e8f0;
}

.wonda-dark .wonda-message.user-message {
    background: #0073aa;
    color: white;
}

.wonda-dark .wonda-quick-prompts {
    background: #2d3748;
}

.wonda-dark .wonda-quick-prompt {
    background: #4a5568;
    border-color: #718096;
    color: #e2e8f0;
}

.wonda-dark .wonda-quick-prompt:hover {
    background: var(--wonda-primary);
}

.wonda-dark .wonda-input-area {
    background: #2d3748;
}

.wonda-dark .wonda-input-area textarea {
    background: #4a5568;
    border-color: #718096;
    color: white;
}

.wonda-dark .wonda-dropdown {
    background: #2d3748;
    border-color: #4a5568;
    color: white;
}

.wonda-dark .wonda-dropdown-item {
    color: #e2e8f0;
}

.wonda-dark .wonda-dropdown-item:hover {
    background: #4a5568;
}

/* Token usage indicator */
.wonda-token-badge {
    font-size: 10px;
    background: rgba(0,0,0,0.1);
    padding: 2px 6px;
    border-radius: 12px;
    margin-left: 8px;
    color: #666;
}

/* WhatsApp link styling */
.wonda-wa-link {
    display: inline-block;
    background: #25D366;
    color: white !important;
    padding: 8px 16px;
    border-radius: 30px;
    text-decoration: none;
    font-weight: 600;
    margin: 5px 0;
}

.wonda-wa-link:hover {
    background: #128C7E;
    text-decoration: none;
}

/* Responsive */
@media (max-width: 480px) {
    #wonda-chat-widget {
        bottom: 10px;
        right: 10px;
    }
    #wonda-chat-window {
        width: 90vw;
        height: 60vh;           /* Increased from 60vh to give more vertical space */
        bottom: 10px;
        right: 0;
        border-radius: var(--wonda-radius);
    }
    #wonda-chat-bubble {
        width: 50px;
        height: 50px;
        font-size: 24px;
    }
    /* Adjust input area on mobile */
    .wonda-input-area {
        padding: 6px 8px;
    }
    .wonda-input-area .wonda-send {
        padding: 0 12px;
        height: 40px;           /* Slightly larger touch target */
        line-height: 40px;
    }
}