/* Base chat panel: shared by inline (shortcode) and floating modes.
   Positioning lives in the mode classes below, not here. */
.world-ai-chat-widget {
    width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    background: #fff;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Inline mode: rendered by [world_ai_chat] inside page content. */
.world-ai-chat-widget.wai-chat-inline {
    max-width: 480px;
    margin: 1rem 0;
}

/* Floating container: bubble + welcome + window, injected via wp_footer. */
.wai-chat-floating {
    position: fixed;
    bottom: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: calc(100vw - 2rem);
}

.wai-chat-floating.wai-chat-pos-bottom-right {
    right: 1rem;
    align-items: flex-end;
}

.wai-chat-floating.wai-chat-pos-bottom-left {
    left: 1rem;
    align-items: flex-start;
}

/* Welcome bubble shown next to the toggle while the chat is closed. */
.wai-chat-welcome {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    max-width: 260px;
    padding: 0.6rem 0.8rem;
    background: #fff;
    color: #111827;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    font-size: 0.85rem;
    line-height: 1.35;
}

.wai-chat-welcome-close {
    background: none;
    border: none;
    padding: 0;
    color: #6b7280;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}

.wai-chat-welcome-close:hover {
    color: #111827;
}

/* Floating toggle bubble. */
.wai-chat-bubble {
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: #2563eb;
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.wai-chat-bubble:hover {
    background: #1d4ed8;
}

/* Floating window: the shared chat panel inside the floating container. */
.wai-chat-floating .world-ai-chat-widget {
    width: 320px;
    max-width: calc(100vw - 2rem);
}

/* Open/closed states: closed shows bubble (+welcome), open shows the window. */
.wai-chat-floating.is-closed .world-ai-chat-widget {
    display: none;
}

.wai-chat-floating.is-open .wai-chat-welcome {
    display: none;
}

.world-ai-chat-widget.minimized .wai-chat-body,
.world-ai-chat-widget.minimized .wai-chat-form {
    display: none;
}

.wai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: #111827;
    color: #fff;
    cursor: pointer;
}

.wai-chat-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.wai-chat-toggle {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
}

.wai-chat-body {
    flex: 1;
    min-height: 280px;
    max-height: 400px;
    overflow-y: auto;
    padding: 0.75rem;
    background: #f9fafb;
}

.wai-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.wai-chat-message {
    padding: 0.6rem 0.8rem;
    border-radius: 0.75rem;
    font-size: 0.9rem;
    line-height: 1.35;
    max-width: 85%;
    word-wrap: break-word;
}

.wai-chat-message.user {
    align-self: flex-end;
    background: #2563eb;
    color: #fff;
}

.wai-chat-message.assistant,
.wai-chat-message.agent {
    align-self: flex-start;
    background: #fff;
    color: #111827;
    border: 1px solid #e5e7eb;
}

.wai-chat-message.agent {
    border-left: 4px solid #10b981;
}

.wai-chat-typing {
    font-size: 0.8rem;
    color: #6b7280;
    padding: 0.25rem 0.5rem;
}

.wai-chat-typing.hidden {
    display: none;
}

.wai-chat-form {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}

.wai-chat-input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    font-size: 0.9rem;
}

.wai-chat-send {
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 0.5rem;
    padding: 0 1rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.wai-chat-send:disabled,
.wai-chat-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.wai-chat-error {
    color: #dc2626;
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    text-align: center;
}

/* Mobile: keep the bubble reachable and the window inside the viewport. */
@media (max-width: 480px) {
    .wai-chat-floating .world-ai-chat-widget {
        width: calc(100vw - 2rem);
    }

    .wai-chat-floating .wai-chat-body {
        min-height: 200px;
        max-height: 50vh;
    }

    .wai-chat-welcome {
        max-width: calc(100vw - 6rem);
    }

    .wai-chat-bubble {
        width: 52px;
        height: 52px;
    }
}
