.ai-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.ai-chat-message {
    margin-bottom: 15px;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
}

.ai-chat-message.user {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.ai-chat-message.ai {
    align-items: flex-start;
}

.ai-chat-message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    overflow: hidden;
    margin: 0 8px;
    flex-shrink: 0;
    background-color: #007bff;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 12px;
}

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

.ai-chat-message-content-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}

.ai-chat-message.user .ai-chat-message-content-wrapper {
    margin-right: 12px;
}

.ai-chat-message-content {
    padding: 10px 15px;
    border-radius: 15px;
    font-size: 14px;
    line-height: 1.4;
}

.ai-chat-message.user .ai-chat-message-content {
    background: #007bff;
    color: #fff;
    border-top-right-radius: 4px;
}

.ai-chat-message.ai .ai-chat-message-content {
    background: #f1f1f1;
    color: #333;
    border-top-left-radius: 4px;
}

.ai-chat-input {
    padding: 15px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
}

.ai-chat-input textarea {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: none;
    height: 40px;
    font-family: inherit;
    outline: none;
    overflow: hidden;
}

.ai-chat-input textarea:focus {
    border-color: #007bff;
}

.ai-chat-input button {
    padding: 0 20px;
    background: #007bff;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.ai-chat-input button:hover {
    background: #0056b3;
}

.ai-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    width: 400px;
    height: 600px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    /*transition: all 0.3s ease;*/
    overflow: hidden;
    max-height: calc(100vh - 40px);
    isolation: isolate;
}

.ai-chat-widget.minimized {
    width: 60px;
    height: 60px !important;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #007bff;
    color: #fff;
}

.ai-chat-widget.minimized .ai-chat-widget-header,
.ai-chat-widget.minimized .ai-chat-widget-content {
    display: none;
}

.ai-chat-widget.minimized::after {
    content: '';
    width: 24px;
    height: 24px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'%3E%3C/path%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
}

.ai-chat-widget-header {
    padding: 15px;
    background: #007bff;
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-chat-widget-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
    color: #fff;
}

.ai-chat-widget-toggle {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 5px;
}

.ai-chat-widget-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: calc(100% - 60px);
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 15px;
    background: #f1f1f1;
    border-radius: 15px;
    width: fit-content;
    margin-bottom: 15px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #666;
    border-radius: 50%;
    animation: typing 1s infinite ease-in-out;
}

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

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

@keyframes typing {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

@media (max-width: 768px) {
    .ai-chat-widget {
        width: 100%;
        height: 100%;
        max-height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
        display: flex;
        flex-direction: column;
        transition: height 0.3s ease;
    }

    .ai-chat-widget-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        position: relative;
    }

    .ai-chat {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }

    .ai-chat-messages {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .ai-chat-input {
        flex-shrink: 0;
        position: relative;
        z-index: 10;
        background: #fff;
        border-top: 1px solid #eee;
        position: sticky;
        bottom: 0;
    }

    .ai-chat-input textarea {
        max-height: 80px;
    }

    .ai-chat-widget.minimized {
        width: 60px;
        height: 60px !important;
        max-height: 60px !important;
        border-radius: 50%;
        bottom: 20px;
        right: 20px;
        top: auto;
        left: auto;
    }
}

/* Add viewport height meta tag support for mobile browsers */
@supports (height: 100dvh) {
    @media (max-width: 768px) {
        .ai-chat-widget {
            height: 100dvh; /* Use dynamic viewport height for better mobile support */
            max-height: 100dvh;
        }
    }
}

/* Fix for iOS Safari */
@supports (-webkit-touch-callout: none) {
    .ai-chat-input {
        padding-bottom: 10px;
    }

    /* Prevent unwanted zoom on input focus */
    .ai-chat-input textarea {
        font-size: 16px;
    }
}

/* Lead created notification */
.ai-chat-notification {
    text-align: center;
    padding: 10px 15px;
    margin: 10px auto;
    background: rgba(0, 123, 255, 0.1);
    border-radius: 8px;
    font-size: 14px;
    color: #007bff;
    max-width: 90%;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.ai-chat-notification.fade-out {
    opacity: 0;
}
