/* WhatsApp Style Chat Widget */
#konnection-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: "Roboto", sans-serif;
    pointer-events: none;
    width: 350px;
    height: 500px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-end;
}

#konnection-chat-widget * {
    pointer-events: auto;
}

/* Chat Button */
.konnection-chat-button {
    height: 50px;
    padding: 0 20px;
    border-radius: 25px;
    background: #0014cc;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease-in-out;
    position: absolute;
    bottom: 0;
    right: 0;
    pointer-events: auto;
}

.konnection-chat-button-text {
    display: block;
}

.konnection-chat-icon-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.konnection-chat-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ff3b30;
    color: white;
    font-size: 10px;
    font-weight: bold;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

.konnection-chat-online-dot {
    position: absolute;
    bottom: -2px;
    left: -2px;
    background: #34c759;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid white;
}

/* Icona chat e chiusura */
.chat-icon {
    display: block;
    font-size: 20px;
    transition: opacity 0.3s ease-in-out;
}
.close-icon {
    display: none;
    font-size: 20px;
    transition: opacity 0.3s ease-in-out;
}

/* Effetto di cambio icona quando la chat è aperta */
.konnection-chat-open .chat-icon {
    display: none;
}
.konnection-chat-open .close-icon {
    display: block;
}
.konnection-chat-open .konnection-chat-badge,
.konnection-chat-open .konnection-chat-online-dot,
.konnection-chat-open .konnection-chat-button-text {
    display: none;
}
.konnection-chat-open .konnection-chat-button {
    width: 50px;
    height: 50px;
    padding: 0;
    border-radius: 50%;
}

/* Popup Styles */
#konnection-chat-popup {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 300px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border: 1px solid #eaeaea;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease-in-out;
    opacity: 1;
    transform: translateY(0);
    z-index: 10000;
    pointer-events: auto;
}

#konnection-chat-popup.konnection-chat-popup-hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
    display: none;
}

.konnection-popup-header {
    display: flex;
    align-items: center;
    padding: 15px;
    border-bottom: none;
}

.konnection-popup-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    color: #666;
    font-size: 20px;
    overflow: hidden;
}

.konnection-popup-title {
    flex-grow: 1;
    font-weight: bold;
    font-size: 16px;
    color: #333;
}

.konnection-popup-close {
    background: none;
    border: none;
    color: #999;
    font-size: 16px;
    cursor: pointer;
    padding: 5px;
}

.konnection-popup-close:hover {
    color: #333;
}

.konnection-popup-body {
    padding: 0 15px 15px 15px;
    font-size: 14px;
    color: #555;
    line-height: 1.5;
}

.konnection-popup-footer {
    padding: 0 15px 15px 15px;
    display: flex;
    justify-content: center;
}

.konnection-popup-btn {
    background: #0014cc;
    color: white;
    border: none;
    border-radius: 20px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    justify-content: center;
    transition: background 0.3s;
}

.konnection-popup-btn:hover {
    opacity: 0.9;
}

/* Quando la chat è chiusa */
.konnection-chat-closed {
    width: auto !important;
    height: auto !important;
}

.konnection-chat-closed #konnection-chat-container {
    display: none !important;
}

/* Chat Container */
#konnection-chat-container {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 100%;
    height: calc(100% - 70px);
    background: #efe7dd;
    border-radius: 15px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease-in-out;
    pointer-events: auto;
}

/* Quando la chat è aperta */
.konnection-chat-open #konnection-chat-container {
    display: flex;
    transform: translateY(0);
    opacity: 1;
}

/* Chat Header */
.chat-header {
    padding: 15px;
    background: #1c54e5;
    color: white;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-header-top {
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.chat-header-actions {
    display: flex;
    gap: 10px;
}

.chat-header-icon {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.9;
    transition: opacity 0.2s;
}

.chat-header-icon:hover {
    opacity: 1;
}

.chat-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    background: #fff;
    flex-shrink: 0;
}

.chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-header-info h3 {
    color: white;
    margin: 0;
    padding: 0;
    font-size: 16px;
    font-weight: bold;
}

.chat-header-status {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background-color: #34c759;
    border-radius: 50%;
    display: inline-block;
}

.status-text {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.9);
}

/* Chat Messages */
#konnection-chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
}

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

#konnection-chat-messages::-webkit-scrollbar-thumb {
    background: #bbb;
    border-radius: 3px;
}

/* Input Area */
.chat-input-wrapper {
    background: #ffffff;
    padding: 12px 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-input-container {
    display: flex;
    align-items: center;
    border: 1.5px solid #1c54e5;
    border-radius: 24px;
    padding: 8px 12px;
    background: #f9f9f9;
}

#konnection-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    outline: none;
    resize: none;
    min-height: 20px;
    max-height: 80px;
    padding: 0;
    color: #333;
}

#konnection-chat-input::placeholder {
    color: #999;
}

.chat-emoji-btn {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-emoji-btn:hover {
    color: #333;
}

/* Pulsante di invio */
#konnection-chat-send {
    background: none;
    color: #1c54e5;
    border: none;
    cursor: pointer;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#konnection-chat-send:hover {
    color: #0033aa;
}

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

/* Message Bubbles */
.message {
    padding: 10px 14px;
    border-radius: 15px;
    max-width: 75%;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    display: inline-block;
    position: relative;
    margin-bottom: 6px;
}

/* User Messages */
.user-message {
    background: #f0f0f0;
    color: black;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
    margin-left: auto;
}

/* Bot Messages */
.bot-message {
    background: #1c54e5;
    color: white;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
    margin-right: auto;
}

.bot-message.loading {
    background: #f0f0f0;
    color: #666;
}

/* Media Queries migliorati per tutti i dispositivi mobili */
@media (max-width: 767px) {
    #konnection-chat-widget {
        width: 300px;
        height: 450px;
    }
}

@media (max-width: 480px) {
    #konnection-chat-widget {
        bottom: 10px;
        right: 10px;
        width: calc(100vw - 20px);
        max-width: 350px;
        height: 400px;
    }
    
    #konnection-chat-container {
        width: 100%;
        height: calc(100% - 60px);
        right: 0;
    }
    
    .konnection-chat-button {
        height: 50px;
        padding: 0 15px;
    }
    
    .konnection-chat-open .konnection-chat-button {
        width: 50px;
        padding: 0;
    }
}

/* Per schermi molto piccoli */
@media (max-width: 360px) {
    #konnection-chat-widget {
        height: 80vh;
        max-height: 500px;
    }
    
    #konnection-chat-container {
        width: 100%;
        height: calc(100% - 60px);
        bottom: 60px;
    }
    
    .chat-input-container {
        padding: 8px;
    }
    
    #konnection-chat-input {
        padding: 8px;
    }
    
    #konnection-chat-send {
        min-width: 40px;
        min-height: 40px;
    }
}

/* Fix per dispositivi iOS */
@supports (-webkit-touch-callout: none) {
    #konnection-chat-widget {
        /* Previene problemi con il viewheight su iOS */
        height: 450px;
    }
}