/**
 * Stili widget chatbot frontend
 */

/* Container principale */
.gend-ai-chatbot {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

/* Toggle button */
.gend-ai-chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    color: #fff;
}

.gend-ai-chatbot-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 25px rgba(102, 126, 234, 0.5);
}

.gend-ai-chatbot-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3), 0 4px 20px rgba(102, 126, 234, 0.4);
}

.gend-ai-icon-close {
    display: none;
}

.gend-ai-chatbot.is-open .gend-ai-icon-chat {
    display: none;
}

.gend-ai-chatbot.is-open .gend-ai-icon-close {
    display: flex;
}

/* Chat window */
.gend-ai-chatbot-window {
    position: absolute;
    bottom: 75px;
    right: 0;
    width: 600px;
    max-width: calc(100vw - 40px);
    height: 550px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
}

.gend-ai-chatbot.is-open .gend-ai-chatbot-window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.gend-ai-chatbot-header {
    display: flex;
    align-items: center;
    padding: 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

.gend-ai-chatbot-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
}

.gend-ai-chatbot-title {
    flex: 1;
}

.gend-ai-chatbot-title strong {
    display: block;
    font-size: 15px;
}

.gend-ai-chatbot-status {
    font-size: 12px;
    opacity: 0.8;
}

.gend-ai-chatbot-minimize {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.gend-ai-chatbot-minimize:hover {
    opacity: 1;
}

/* Messages area */
.gend-ai-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8f9fa;
}

/* Message bubbles */
.gend-ai-message {
    margin-bottom: 16px;
    display: flex;
}

.gend-ai-message-content {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    word-wrap: break-word;
}

.gend-ai-message-bot .gend-ai-message-content {
    background: #fff;
    border: 1px solid #e9ecef;
    border-bottom-left-radius: 4px;
}

.gend-ai-message-user {
    justify-content: flex-end;
}

.gend-ai-message-user .gend-ai-message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Typing indicator */
.gend-ai-message-typing .gend-ai-message-content {
    display: flex;
    align-items: center;
    padding: 16px 20px;
}

.gend-ai-typing-dots {
    display: flex;
    gap: 4px;
}

.gend-ai-typing-dots span {
    width: 8px;
    height: 8px;
    background: #667eea;
    border-radius: 50%;
    animation: gend-ai-typing 1.4s infinite ease-in-out;
}

.gend-ai-typing-dots span:nth-child(1) {
    animation-delay: 0s;
}

.gend-ai-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.gend-ai-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes gend-ai-typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Sources */
.gend-ai-sources {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e9ecef;
    font-size: 12px;
}

.gend-ai-sources-title {
    font-weight: 600;
    color: #495057;
    margin-bottom: 8px;
}

.gend-ai-source-link {
    display: block;
    color: #667eea;
    text-decoration: none;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gend-ai-source-link:hover {
    text-decoration: underline;
}

/* Input area */
.gend-ai-chatbot-input {
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid #e9ecef;
}

.gend-ai-chatbot-form {
    display: flex;
    gap: 8px;
}

.gend-ai-input {
    flex: 1;
    border: 1px solid #e9ecef;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.gend-ai-input:focus {
    border-color: #667eea;
}

.gend-ai-input:disabled {
    background: #f8f9fa;
    cursor: not-allowed;
}

.gend-ai-submit {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, opacity 0.2s;
}

.gend-ai-submit:hover {
    transform: scale(1.05);
}

.gend-ai-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.gend-ai-chatbot-footer {
    text-align: center;
    margin-top: 8px;
    color: #adb5bd;
    font-size: 11px;
}

/* Error message */
.gend-ai-message-error .gend-ai-message-content {
    background: #fee2e2;
    border-color: #fecaca;
    color: #991b1b;
}

/* Stato attesa */
.gend-ai-status-text {
    color: #666;
    font-style: italic;
    animation: gend-ai-pulse 1.5s ease-in-out infinite;
}

@keyframes gend-ai-pulse {
    0%, 100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

/* Streaming cursor */
.gend-ai-streaming-cursor {
    display: inline-block;
    width: 8px;
    height: 16px;
    background: #667eea;
    margin-left: 4px;
    vertical-align: text-bottom;
    animation: gend-ai-cursor-blink 1s infinite;
}

@keyframes gend-ai-cursor-blink {
    0%, 50% {
        opacity: 1;
    }
    51%, 100% {
        opacity: 0;
    }
}

.gend-ai-message-streaming .gend-ai-message-content {
    min-height: 24px;
}

/* Mobile responsive */
@media (max-width: 480px) {
    .gend-ai-chatbot {
        bottom: 10px;
        right: 10px;
    }
    
    .gend-ai-chatbot-toggle {
        width: 50px;
        height: 50px;
    }
    
    .gend-ai-chatbot-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 80px);
        bottom: 65px;
        right: 0;
        border-radius: 12px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .gend-ai-chatbot-toggle,
    .gend-ai-chatbot-window,
    .gend-ai-typing-dots span {
        transition: none;
        animation: none;
    }
}

/* Print */
@media print {
    .gend-ai-chatbot {
        display: none;
    }
}
