/**
 * KEChatBot Frontend Styles
 *
 * @package KEChatBot
 * @version 1.0.4
 */

 /* Toggle button */
#chatbot-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background: var(--kechatbot-primary);
    color:var(--kechatbot-primary-text);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.3);
    z-index: 9998;
    transition: all 0.3s ease;
}

#chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 32px rgba(102, 126, 234, 0.4);
}

#chatbot-toggle.show {
    display: flex;
}


/* Reset and base styles */
#chatbot {
    p, ul {
        margin: 1px;
    }
    * {
        box-sizing: border-box;
    }
}



/* Main chatbot container */
#chatbot {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1), 0 8px 16px rgba(0, 0, 0, 0.06);
    z-index: 9999;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;


    &.hidden {
        transform: translateY(100%);
        opacity: 0;
        pointer-events: none;
    }

    /* Header styles */
    #chatbot-header {
        background: var(--kechatbot-primary);
        color: var(--kechatbot-primary-text);
        padding: 20px;
        font-weight: 600;
        font-size: 16px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
    }

    .header-left, .header-right {
        display: flex;
        align-items: center;
        gap: 12px;
    }

    /* .header-left::before {
        content: url('../images/chat.svg');
    } */

    #close-button, #reset-button {
        width: 28px;
        height: 28px;
        border: none;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.2);
        color: white;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 16px;
        font-weight: bold;
        transition: all 0.2s ease;
        line-height: 1;
    }

    #close-button:hover, #reset-button:hover {
        background: rgba(255, 255, 255, 0.3);
        transform: scale(1.1);
    }

    #close-button:active, #reset-button:active {
        transform: scale(0.95);
    }

    #reset-button {
        background: none;
    }

    /* Preview animation section */
    #preview {
        display: none;
        min-height: 50px;
        overflow: hidden;
        position: relative;
        font-family: monospace;
        font-size: 80%;
        width:100%
    }

    #preview::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        /* background: linear-gradient(
            90deg,
            transparent 0%,
            rgba(0, 255, 0, 0.1) 50%,
            transparent 100%
        ); */
        animation: scan 2s linear infinite;
        pointer-events: none;
    }

    @keyframes scan {
        0% { transform: translateX(-100%); }
        100% { transform: translateX(100%); }
    }





    /* Messages area */
    #chatbot-messages {
        max-height: 60vh;
        min-height: 30vh;
        overflow-y: auto;
        padding: 20px;
        background: #fafbfc;
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

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

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

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

    #chatbot-messages::-webkit-scrollbar-thumb:hover {
        background: #9ca3af;
    }

    /* Message styles */
    .message {
        display: flex;
        margin-bottom: 12px;
        animation: slideIn 0.3s ease-out;
    }

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

    .message-bot {
        justify-content: flex-start;
    }

    .message-content {
        max-width: 75%;
        padding: 12px 16px;
        border-radius: 18px;
        font-size: 14px;
        line-height: 1.4;
        word-wrap: break-word;
        /* white-space: pre-wrap; */
    }

    .message-user .message-content {
        /* background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); */
        background: var(--kechatbot-primary);
        color: white;
        border-bottom-right-radius: 6px;
    }

    .message-bot .message-content {
        background: white;
        color: #374151;
        border: 1px solid #e5e7eb;
        border-bottom-left-radius: 6px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }

    /* Avatar styles */
    .message-avatar {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        margin: 0 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        flex-shrink: 0;
        align-self: flex-end;
    }

    .message-user .message-avatar {
        background: var(--kechatbot-primary);
        color:var(--kechatbot-primary-text);
        order: 2;
    }

    .message-bot .message-avatar {
        background: #f3f4f6;
        color: #6b7280;
    }

    /* Input area */
    #chatbot-input-container {
        padding: 20px;
        background: white;
        border-top: 1px solid #e5e7eb;
        position: relative;
    }

    #chatbot-input {
        width: 100%;
        min-height: 44px;
        max-height: 120px;
        padding: 12px;
        border: 1px solid #e5e7eb;
        border-radius: 24px;
        font-size: 14px;
        font-family: inherit;
        outline: none;
        transition: all 0.2s ease;
        background: #f9fafb;
        resize: none;
        overflow-y: hidden;
        line-height: 1.4;
        box-sizing: border-box;
    }

    #chatbot-input:focus {
        border-color: #667eea;
        background: white;
        box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    }

    #chatbot-input::placeholder {
        color: #9ca3af;
    }

    #send-button {
        position: absolute;
        right: 28px; /* 20px container padding + 8px internal spacing */
        bottom: 28px; /* 20px container padding + 8px internal spacing */
        width: 32px;
        height: 32px;
        border: none;
        border-radius: 16px; /* Metà dell'altezza per il round */
        background: var(--kechatbot-primary);
        color:var(--kechatbot-primary-text);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
        font-size: 14px;
        z-index: 10;
    }

    #send-button:hover {
        transform: scale(1.08);
        box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    }

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

    #send-button:disabled {
        opacity: 0.5;
        cursor: not-allowed;
        transform: none;
    }

    /* Typing indicator */
    .typing-indicator {
        display: none;
        align-items: flex-end;
        .typing-wrapper {
            padding: 5px;
            background: white;
            border-radius: 18px;
            border-bottom-left-radius: 6px;
            border: 1px solid #e5e7eb;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
            width: fit-content;
        }
    }

    /* .typing-dots {
        display: flex;
        gap: 4px;
    }

    .typing-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #9ca3af;
        animation: typing 1.4s infinite ease-in-out;
    }

    .typing-dot:nth-child(1) {
        animation-delay: -0.32s;
    }

    .typing-dot:nth-child(2) {
        animation-delay: -0.16s;
    }*/

    /* Error message styling */
    .message div.error-message {
        color: #b30000;
        font-style: italic;
    }

    /* Animations */
    @keyframes typing {
        0%, 80%, 100% {
            transform: scale(0.8);
            opacity: 0.5;
        }
        40% {
            transform: scale(1);
            opacity: 1;
        }
    }

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

    /* Word counter */
    .word-counter {
        font-size: 11px;
        color: #6b7280;
        text-align: left;
        margin-top: 4px;
        margin-left: 12px! important;
        transition: color 0.2s ease;
    }

    .word-counter.warning {
        color: #f59e0b;
    }

    .word-counter.error {
        color: #ef4444;
    }

    .word-counter.pulse-error {
        color: #ef4444;
        animation: pulseError 0.5s ease-in-out;
    }

    @keyframes pulseError {
        0%, 100% {
            transform: scale(1);
            color: #ef4444;
        }
        50% {
            transform: scale(1.1);
            color: #dc2626;
            font-weight: 600;
        }
    }

    /* Responsive design */
    @media (max-width: 480px) {
        #chatbot {
            bottom: 10px;
            right: 10px;
            left: 10px;
            width: auto;
            max-width: none;
        }

        #chatbot-toggle {
            bottom: 10px;
            right: 10px;
        }

        #chatbot-messages {
            height: 240px;
            padding: 16px;
        }

        #chatbot-header {
            padding: 16px;
        }

        #chatbot-input-container {
            padding: 16px;
        }

        #send-button {
            right: 6x;
            bottom: 30px;
        }
    }
}