/* AI Chatbot Frontend Styles */

:root {
    --primary-color: #0073aa;
}

.ai-chatbot-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.ai-chatbot-widget.bottom-right {
    bottom: 20px;
    right: 20px;
}

.ai-chatbot-widget.bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Chatbot Toggle Button */
.chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary-color);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    padding: 0;
    overflow: hidden;
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

.chatbot-toggle img {
    width: 48px; /* Ingrandito da 32px */
    height: 48px; /* Ingrandito da 32px */
    object-fit: cover; /* Cambiato da contain a cover */
    border-radius: 50%;
}

.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 20px;
    height: 20px;
    background: #dc3545;
    color: #fff;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* Chatbot Window */
.chatbot-window {
    position: absolute;
    bottom: 80px;
    width: 380px;
    height: 600px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

.ai-chatbot-widget.bottom-left .chatbot-window {
    left: 0;
}

.ai-chatbot-widget.bottom-right .chatbot-window {
    right: 0;
}

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

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

.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    padding: 6px;
    object-fit: contain;
}

.chatbot-title strong {
    display: block;
    font-size: 15px;
    margin-bottom: 2px;
}

.chatbot-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chatbot-status::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #46b450;
    border-radius: 50%;
    display: inline-block;
}

.chatbot-close {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.chatbot-close:hover {
    background: rgba(255,255,255,0.15);
}

/* Messages Container */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}

/* Messages */
.message {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    animation: messageSlideIn 0.3s ease;
}

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

.bot-message {
    flex-direction: row;
}

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

.message-avatar {
    flex-shrink: 0;
}

.bot-message .message-avatar img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #fff;
    padding: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.message-content {
    flex: 1;
    max-width: 75%;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.bot-message .message-bubble {
    background: #fff;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

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

.message-time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    padding: 0 4px;
}

.user-message .message-time {
    text-align: right;
}

/* Typing Indicator */
.typing-indicator {
    padding: 0 20px 10px;
    background: #f8f9fa;
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: #fff;
    border-radius: 12px;
    width: fit-content;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typingDot 1.4s infinite;
}

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

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

@keyframes typingDot {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Input Area */
.chatbot-input-area {
    background: #fff;
    border-top: 1px solid #e5e5e5;
    padding: 16px 20px;
}

.voice-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f0f0;
}

.continuous-voice-button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #f8f9fa;
    border: 2px solid #e0e0e0;
    border-radius: 20px;
    color: #666;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 13px;
    font-weight: 500;
}

.continuous-voice-button:hover {
    background: #e8e9ea;
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.continuous-voice-button.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
    animation: continuousPulse 2s infinite;
}

.continuous-voice-button svg {
    flex-shrink: 0;
}

.continuous-voice-button.active svg circle {
    animation: pulse 1.5s infinite;
}

@keyframes continuousPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(0, 115, 170, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(0, 115, 170, 0);
    }
}

.voice-status {
    font-size: 12px;
    color: #666;
    font-style: italic;
}

#chatbot-form {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    padding: 0 4px;
}

#chatbot-input {
    flex: 1;
    border: 2px solid #e0e0e0;
    border-radius: 24px;
    padding: 12px 18px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
    background: #fafafa;
}

#chatbot-input:focus {
    border-color: var(--primary-color);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.1);
}

.send-button {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px;
    min-height: 44px;
    border-radius: 50%;
    background: var(--primary-color) !important;
    border: none !important;
    color: #fff !important;
    cursor: pointer;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0 !important;
    margin-left: 8px;
}

.send-button svg {
    width: 24px !important;
    height: 24px !important;
    display: block !important;
    stroke: #fff !important;
    stroke-width: 2.5 !important;
    fill: none !important;
    pointer-events: none;
}

.send-button:hover {
    filter: brightness(1.15);
    transform: scale(1.05);
}

.send-button:active {
    transform: scale(0.95);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: none !important;
}

/* Tooltip per i pulsanti */
.voice-button[title]:hover::after,
.send-button[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    margin-bottom: 8px;
    pointer-events: none;
    z-index: 1000;
    animation: tooltipFadeIn 0.2s ease;
}

.voice-button[title]:hover::before,
.send-button[title]:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.85);
    margin-bottom: 3px;
    pointer-events: none;
    z-index: 1000;
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.powered-by {
    text-align: center;
    font-size: 11px;
    color: #999;
}

/* Responsive */
@media (max-width: 480px) {
    .chatbot-window {
        position: fixed;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 100% !important;
        border-radius: 0;
        max-height: 100vh;
    }
    
    .ai-chatbot-widget.bottom-right .chatbot-window,
    .ai-chatbot-widget.bottom-left .chatbot-window {
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
    }
}

/* Error Message */
.error-message {
    background: #fef1f1;
    color: #dc3232;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    margin: 10px 20px;
    border: 1px solid #fecdcd;
}

/* Product Cards */
.product-cards-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 10px 20px;
    background: #f8f9fa;
}

.product-card {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #e5e5e5;
    display: flex;
    gap: 12px;
    padding: 12px;
    transition: all 0.2s;
    animation: slideIn 0.3s ease;
}

.product-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

.product-card.out-of-stock {
    opacity: 0.7;
}

.product-image {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
    border-radius: 8px;
    overflow: hidden;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-image .no-image {
    font-size: 32px;
}

.product-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.product-name {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #1d2327;
    line-height: 1.3;
}

.product-price {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary-color);
}

.product-stock {
    font-size: 12px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
    width: fit-content;
}

.product-stock.in-stock {
    background: #e7f7ed;
    color: #1e8449;
}

.product-stock.out-of-stock {
    background: #fef1f1;
    color: #dc3232;
}

.product-link {
    display: inline-block;
    color: var(--primary-color);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    margin-top: auto;
    transition: all 0.2s;
}

.product-link:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Responsive Product Cards */
@media (max-width: 480px) {
    .product-card {
        flex-direction: column;
    }
    
    .product-image {
        width: 100%;
        height: 120px;
    }
}

/* Voice Compatibility Warning */
.voice-compatibility-warning {
    background: #fff8e1;
    border: 1px solid #ffc107;
    border-radius: 8px;
    margin-bottom: 12px;
    overflow: hidden;
}

.warning-content {
    padding: 12px 16px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    position: relative;
}

.warning-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.warning-text {
    flex: 1;
    font-size: 13px;
    line-height: 1.5;
    color: #856404;
}

.warning-text strong {
    color: #000;
}

.warning-text small {
    display: block;
    margin-top: 6px;
    opacity: 0.8;
}

.close-warning {
    position: absolute;
    top: 8px;
    right: 8px;
    background: transparent;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: #856404;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    transition: background 0.2s;
}

.close-warning:hover {
    background: rgba(0,0,0,0.1);
}


/* Voice Button Styles */
.voice-button {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px;
    min-height: 44px;
    border-radius: 50%;
    background: #f5f5f5 !important;
    border: 2px solid #e0e0e0 !important;
    color: #666 !important;
    cursor: pointer;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s ease;
    flex-shrink: 0;
    position: relative;
    padding: 0 !important;
    margin-right: 8px;
}

.voice-button svg {
    width: 22px !important;
    height: 22px !important;
    display: block !important;
    pointer-events: none;
}

.voice-button .mic-icon {
    stroke: #666 !important;
    stroke-width: 2.5 !important;
    fill: none !important;
}

.voice-button:hover {
    background: #e8e8e8 !important;
    border-color: #ccc !important;
    transform: scale(1.05);
}

.voice-button:hover .mic-icon {
    stroke: #333 !important;
}

.voice-button:active {
    transform: scale(0.95);
}

.voice-button.recording {
    background: #dc3545 !important;
    border-color: #dc3545 !important;
    color: #fff !important;
    animation: voicePulse 1.5s infinite ease-in-out;
}

.voice-button.recording .mic-icon {
    display: none !important;
}

.voice-button.recording .recording-icon {
    display: block !important;
    animation: recordingSpin 2s linear infinite;
    fill: #fff !important;
}

@keyframes voicePulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
    }
    50% {
        transform: scale(1.08);
        box-shadow: 0 0 0 12px rgba(220, 53, 69, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
    }
}

@keyframes recordingSpin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Voice Active Input */
#chatbot-input.voice-active {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1) !important;
    animation: inputPulse 1.5s infinite ease-in-out;
}

@keyframes inputPulse {
    0%, 100% {
        box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
    }
    50% {
        box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.25);
    }
}

/* Speaker Button in Messages */
.bot-message {
    flex-direction: row;
    position: relative;
}

.speaker-button {
    background: transparent;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
    flex-shrink: 0;
    margin-left: 8px;
    opacity: 0;
}

.message:hover .speaker-button {
    opacity: 1;
}

.speaker-button:hover {
    background: #f0f0f0;
    color: var(--primary-color);
}

.speaker-button.playing {
    color: var(--primary-color);
    animation: speakerPulse 1s infinite;
}

@keyframes speakerPulse {
    0%, 100% { 
        opacity: 1;
        transform: scale(1);
    }
    50% { 
        opacity: 0.6;
        transform: scale(1.1);
    }
}

/* Loading state per pulsanti vocali */
.voice-button.loading,
.speaker-button.loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.voice-button.loading::after,
.speaker-button.loading::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.6s linear infinite;
    top: 50%;
    left: 50%;
    margin-left: -7px;
    margin-top: -7px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Pulsante cancella conversazione */
.chatbot-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chatbot-action-button {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
    opacity: 0.8;
}

.chatbot-action-button:hover {
    background: rgba(255,255,255,0.15);
    opacity: 1;
}

.chatbot-action-button svg {
    width: 20px;
    height: 20px;
}
