/* =========================================
   WP RAG Chatbot - Widget Styles
   ========================================= */

:root {
    --wpragchat-primary: #2563eb;
    --wpragchat-primary-dark: color-mix(in srgb, var(--wpragchat-primary) 80%, black);
    --wpragchat-radius: 16px;
    --wpragchat-shadow: 0 8px 32px rgba(0,0,0,0.18);
    --wpragchat-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --wpragchat-bg: #ffffff;
    --wpragchat-surface: #f8fafc;
    --wpragchat-border: #e2e8f0;
    --wpragchat-text: #1e293b;
    --wpragchat-muted: #64748b;
    --wpragchat-bot-bubble: #f1f5f9;
    --wpragchat-user-bubble: var(--wpragchat-primary);
}

/* Container principale */
.wpragchat-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: var(--wpragchat-font);
    font-size: 15px;
    line-height: 1.5;
}

/* Pulsante toggle */
.wpragchat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--wpragchat-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    z-index: 1;
}

.wpragchat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0,0,0,0.3);
}

.wpragchat-toggle:active {
    transform: scale(0.96);
}

/* Finestra chat */
.wpragchat-window {
    position: absolute;
    bottom: 74px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: var(--wpragchat-bg);
    border-radius: var(--wpragchat-radius);
    box-shadow: var(--wpragchat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--wpragchat-border);
    transform-origin: bottom right;
    transform: scale(0.85) translateY(12px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
}

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

/* Header */
.wpragchat-header {
    background: var(--wpragchat-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

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

.wpragchat-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.wpragchat-name {
    font-weight: 600;
    font-size: 15px;
}

.wpragchat-subtitle {
    font-size: 12px;
    opacity: 0.82;
}

.wpragchat-close {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    opacity: 0.8;
    font-size: 18px;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
    transition: opacity 0.15s;
}

.wpragchat-close:hover { opacity: 1; }

/* Area messaggi */
.wpragchat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--wpragchat-surface);
    scroll-behavior: smooth;
}

.wpragchat-messages::-webkit-scrollbar { width: 4px; }
.wpragchat-messages::-webkit-scrollbar-track { background: transparent; }
.wpragchat-messages::-webkit-scrollbar-thumb { background: var(--wpragchat-border); border-radius: 4px; }

/* Messaggi */
.wpragchat-message {
    display: flex;
    gap: 8px;
    animation: wpragchat-fadein 0.2s ease;
}

@keyframes wpragchat-fadein {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.wpragchat-message.user {
    flex-direction: row-reverse;
}

.wpragchat-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
}

.wpragchat-message.bot .wpragchat-bubble {
    background: var(--wpragchat-bot-bubble);
    color: var(--wpragchat-text);
    border-bottom-left-radius: 4px;
}

.wpragchat-message.user .wpragchat-bubble {
    background: var(--wpragchat-user-bubble);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Sorgenti */
.wpragchat-sources {
    margin-top: 8px;
    font-size: 12px;
    color: var(--wpragchat-muted);
}

.wpragchat-sources strong {
    display: block;
    margin-bottom: 3px;
}

.wpragchat-sources a {
    display: block;
    color: var(--wpragchat-primary);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wpragchat-sources a:hover { text-decoration: underline; }

/* Typing indicator */
.wpragchat-typing .wpragchat-bubble {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 12px 16px;
}

.wpragchat-dot {
    width: 7px;
    height: 7px;
    background: var(--wpragchat-muted);
    border-radius: 50%;
    animation: wpragchat-bounce 1.2s infinite;
}

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

@keyframes wpragchat-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40%           { transform: translateY(-6px); opacity: 1; }
}

/* Errore */
.wpragchat-message.error .wpragchat-bubble {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

/* Input area */
.wpragchat-input-area {
    padding: 12px 14px 10px;
    background: var(--wpragchat-bg);
    border-top: 1px solid var(--wpragchat-border);
    flex-shrink: 0;
}

.wpragchat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--wpragchat-surface);
    border: 1.5px solid var(--wpragchat-border);
    border-radius: 12px;
    padding: 6px 6px 6px 12px;
    transition: border-color 0.15s;
}

.wpragchat-input-wrapper:focus-within {
    border-color: var(--wpragchat-primary);
}

.wpragchat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-size: 14px;
    font-family: var(--wpragchat-font);
    color: var(--wpragchat-text);
    outline: none;
    max-height: 100px;
    min-height: 22px;
    line-height: 1.4;
}

.wpragchat-input::placeholder { color: var(--wpragchat-muted); }

.wpragchat-send {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--wpragchat-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, opacity 0.15s;
    flex-shrink: 0;
}

.wpragchat-send:disabled {
    background: var(--wpragchat-border);
    cursor: not-allowed;
    opacity: 0.6;
}

.wpragchat-send:not(:disabled):hover {
    background: var(--wpragchat-primary-dark);
}

.wpragchat-disclaimer {
    font-size: 11px;
    color: var(--wpragchat-muted);
    text-align: center;
    margin: 6px 0 0;
}

/* Mobile */
@media (max-width: 480px) {
    .wpragchat-container {
        bottom: 16px;
        right: 16px;
    }

    .wpragchat-window {
        right: -8px;
        width: calc(100vw - 16px);
        height: calc(100vh - 90px);
        max-height: none;
    }
}
