/* Modern Chat Widget Styles */
#immichat_widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Chat Toggle Button */
#immichat_toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

#immichat_toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

#immichat_toggle::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

#immichat_toggle:hover::before {
    left: 100%;
}

/* Chat Window */
#immichat_window {
    display: none;
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    height: 600px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

#immichat_window.show {
    display: flex;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.chat-header {
    padding: 20px 25px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.chat-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
}

.chat-title {
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-title::before {
    content: '💬';
    font-size: 20px;
}

.chat-close,
.chat-reset {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.3s ease;
}

.chat-close:hover,
.chat-reset:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* Messages Area */
#immichat_messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
}

#immichat_messages::-webkit-scrollbar {
    width: 6px;
}

#immichat_messages::-webkit-scrollbar-track {
    background: transparent;
}

#immichat_messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

#immichat_messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Message Styles */
.chat-message {
    margin-bottom: 15px;
    animation: messageSlide 0.3s ease-out;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    text-align: right;
}

.chat-message.assistant {
    text-align: left;
}

.chat-bubble {
    display: inline-block;
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.chat-message.user .chat-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant .chat-bubble {
    background: white;
    color: #333;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Response type indicators */
.response-database .chat-bubble {
    border-left: 4px solid #28a745;
    background: linear-gradient(135deg, #f8fff9 0%, #f0fff4 100%);
}

.response-api .chat-bubble {
    border-left: 4px solid #0073aa;
    background: linear-gradient(135deg, #f8fbff 0%, #f0f8ff 100%);
}

.response-error .chat-bubble {
    border-left: 4px solid #dc3545;
    background: linear-gradient(135deg, #fff8f8 0%, #fff0f0 100%);
}

.response-indicator {
    font-size: 11px;
    color: #666;
    margin-top: 4px;
    text-align: left;
    font-style: italic;
}

.response-indicator i {
    margin-right: 4px;
    color: #28a745;
}

/* Enhanced message formatting */
.chat-bubble strong {
    font-weight: 600;
    color: inherit;
}

.chat-bubble em {
    font-style: italic;
    color: inherit;
}

.chat-bubble .emoji {
    font-size: 16px;
    margin-right: 4px;
    vertical-align: middle;
}

/* Advanced message formatting */
.chat-bubble .chat-header {
    font-size: 16px;
    font-weight: 600;
    margin: 8px 0 6px 0;
    color: #333;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 4px;
}

.chat-bubble .chat-subheader {
    font-size: 14px;
    font-weight: 600;
    margin: 6px 0 4px 0;
    color: #555;
}

.chat-bubble .chat-bullet {
    margin: 4px 0;
    padding-left: 16px;
    position: relative;
    line-height: 1.5;
}

.chat-bubble .chat-bullet::before {
    content: "•";
    position: absolute;
    left: 0;
    color: #667eea;
    font-weight: bold;
}

.chat-bubble .chat-numbered {
    margin: 4px 0;
    padding-left: 16px;
    position: relative;
    line-height: 1.5;
}

.chat-bubble .chat-important {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 6px;
    padding: 8px 12px;
    margin: 8px 0;
    font-weight: 500;
    color: #856404;
}

.chat-bubble .chat-code {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 8px 12px;
    margin: 8px 0;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #495057;
    white-space: pre-wrap;
    overflow-x: auto;
}

.chat-bubble .chat-inline-code {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 3px;
    padding: 2px 6px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #495057;
}

.chat-bubble .chat-link {
    color: #667eea;
    text-decoration: none;
    border-bottom: 1px dotted #667eea;
}

.chat-bubble .chat-link:hover {
    color: #5a6fd8;
    border-bottom: 1px solid #5a6fd8;
}

/* Quick Reply Buttons */
.quick-reply-container {
    margin-top: 15px;
}

.quick-reply-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
}

.quick-reply-btn {
    flex: 1;
    min-width: 120px;
    padding: 14px 20px;
    border: 2px solid transparent;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-transform: none;
    letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;
}

.quick-reply-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.quick-reply-btn:hover::before {
    left: 100%;
}

.quick-reply-btn i {
    font-size: 16px;
    z-index: 1;
}

.quick-reply-btn span {
    z-index: 1;
}

.yes-btn {
    background: linear-gradient(135deg, #0FA3A3 0%, #F36F4E 100%);
    color: white;
    border-color: #0FA3A3;
    box-shadow: 0 4px 15px rgba(15, 163, 163, 0.3);
}

.yes-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(15, 163, 163, 0.4);
    border-color: #F36F4E;
}

.no-btn {
    background: white;
    color: #6c757d;
    border-color: #dee2e6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.no-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-color: #adb5bd;
    color: #495057;
}

/* Mobile responsive for quick reply buttons */
@media (max-width: 480px) {
    .quick-reply-buttons {
        flex-direction: column;
        gap: 8px;
    }
    
    .quick-reply-btn {
        min-width: auto;
        width: 100%;
    }
}

/* Database response specific styling */
.response-database .chat-bubble strong {
    color: #28a745;
}

.response-database .chat-bubble .emoji {
    font-size: 18px;
}

/* API response specific styling */
.response-api .chat-bubble strong {
    color: #0073aa;
}

/* Error response specific styling */
.response-error .chat-bubble strong {
    color: #dc3545;
}

.chat-timestamp {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    text-align: center;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 18px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    width: fit-content;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #667eea;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0s; }

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Area */
#immichat_chat_input_area {
    padding: 20px;
    background: white;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#immichat_input {
    flex: 1;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 20px;
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    outline: none;
    transition: all 0.3s ease;
    font-family: inherit;
    max-height: 120px;
    min-height: 44px;
    background: white;
    color: #333;
}

#immichat_input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#immichat_send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

#immichat_send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

#immichat_send:active {
    transform: scale(0.95);
}

/* Lead Form Styles */
#immichat_lead_form {
    padding: 20px;
    background: white;
    overflow-y: auto;
    max-height: 100%;
}

.form-header {
    text-align: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.form-header h4 {
    margin: 0 0 8px 0;
    color: #333;
    font-size: 18px;
    font-weight: 600;
}

.form-header p {
    margin: 0;
    color: #666;
    font-size: 14px;
    line-height: 1.4;
}

.form-group {
    margin-bottom: 15px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.3s ease;
    font-family: inherit;
    box-sizing: border-box;
    background: white;
    color: #333;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-group input::placeholder {
    color: #999;
}

/* Specific input type styles */
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="tel"],
.form-group input[type="number"] {
    background: white;
    color: #333;
}

.form-group input[type="text"]:focus,
.form-group input[type="email"]:focus,
.form-group input[type="tel"]:focus,
.form-group input[type="number"]:focus {
    background: white;
    color: #333;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.form-actions button {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}

#immichat_back_to_chat {
    background: #f8f9fa;
    color: #666;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

#immichat_back_to_chat:hover {
    background: #e9ecef;
    color: #333;
}

#immichat_submit_lead {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

#immichat_submit_lead:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

#immichat_submit_lead:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Chat Actions Bottom */
.chat-actions-bottom {
    margin-top: 15px;
    text-align: center;
}

#immichat_show_form {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 8px;
    background: rgba(102, 126, 234, 0.05);
    color: #667eea;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}

#immichat_show_form:hover {
    background: rgba(102, 126, 234, 0.1);
    border-color: #667eea;
}

#immichat_show_form i {
    margin-right: 6px;
}

/* Responsive Design */
@media (max-width: 480px) {
    #immichat_window {
        width: calc(100vw - 40px);
        height: calc(100vh - 120px);
        bottom: 80px;
        right: 20px;
        left: 20px;
        border-radius: 15px;
    }

    .chat-header {
        padding: 15px 20px;
    }

    #immichat_messages {
        padding: 15px;
    }

    #immichat_chat_input_area {
        padding: 15px;
    }

    .chat-bubble {
        max-width: 85%;
        font-size: 15px;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    #immichat_window {
        background: #1a1a1a;
        border-color: rgba(255, 255, 255, 0.1);
    }

    #immichat_messages {
        background: #2a2a2a;
    }

    .chat-message.assistant .chat-bubble {
        background: #333;
        color: #fff;
        border-color: rgba(255, 255, 255, 0.1);
    }

    #immichat_input {
        background: #333;
        color: #fff;
        border-color: rgba(255, 255, 255, 0.1);
    }

    #immichat_input:focus {
        border-color: #667eea;
        background: #333;
        color: #fff;
    }

    .typing-indicator {
        background: #333;
        border-color: rgba(255, 255, 255, 0.1);
    }

    .chat-timestamp {
        color: #888;
    }

    /* Dark mode form styles */
    #immichat_lead_form {
        background: #1a1a1a;
    }

    .form-header h4 {
        color: #fff;
    }

    .form-header p {
        color: #ccc;
    }

    .form-group input {
        background: #333;
        color: #fff;
        border-color: rgba(255, 255, 255, 0.1);
    }

    .form-group input:focus {
        background: #333;
        color: #fff;
        border-color: #667eea;
    }

    .form-group input::placeholder {
        color: #888;
    }

    #immichat_back_to_chat {
        background: #333;
        color: #ccc;
        border-color: rgba(255, 255, 255, 0.1);
    }

    #immichat_back_to_chat:hover {
        background: #444;
        color: #fff;
    }
}

.chat-message.loading {
    opacity: 0.7;
}

.chat-bubble.success {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%) !important;
}

.chat-bubble.error {
    background: linear-gradient(135deg, #dc3545 0%, #fd7e14 100%) !important;
}