/* Reset specific to chatbot to avoid theme conflicts */
#kology-chatbot-container {
    position: fixed;
    bottom: 100px; /* Moved up to avoid WhatsApp widget overlap */
    right: 24px;
    z-index: 999999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: #1f2937;
}

#kology-chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: white;
    border: none;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
}

#kology-chatbot-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

#kology-chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 550px;
    max-height: calc(100vh - 200px); /* Prevent cutting off the top on smaller screens */
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid rgba(0,0,0,0.05);
}

#kology-chatbot-container.kology-chatbot-open #kology-chatbot-window {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0) scale(1);
}

#kology-chatbot-header {
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.kology-chatbot-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.kology-chatbot-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: white url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%236366f1"><path d="M12 2a2 2 0 0 1 2 2c0 .74-.4 1.39-1 1.73V7h1a7 7 0 0 1 7 7h1a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1h-1v1a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-1H3a1 1 0 0 1-1-1v-3a1 1 0 0 1 1-1h1a7 7 0 0 1 7-7h1V5.73A2 2 0 1 1 12 2zm-2 11a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm4 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4z"/></svg>') center/20px no-repeat;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.kology-chatbot-title strong {
    display: block;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
}

.kology-chatbot-title span {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 4px;
}

.kology-chatbot-title span::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background-color: #10b981;
    border-radius: 50%;
}

#kology-chatbot-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
    padding: 4px;
}

#kology-chatbot-close:hover {
    opacity: 1;
}

/* --- LEAD GENERATION FORM --- */
#kology-chatbot-lead-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    background: #f9fafb;
    overflow-y: auto;
}

.lead-form-header {
    text-align: center;
    margin-bottom: 20px;
}

.lead-form-header h3 {
    margin: 0 0 8px 0;
    font-size: 18px;
    color: #1f2937;
}

.lead-form-header p {
    margin: 0;
    font-size: 14px;
    color: #6b7280;
    line-height: 1.4;
}

.lead-form-group {
    margin-bottom: 16px;
}

.lead-form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
    font-family: inherit;
}

.lead-form-group input:focus {
    border-color: #6366f1;
}

#kology-lead-submit {
    width: 100%;
    padding: 14px;
    background: #6366f1;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 8px;
}

#kology-lead-submit:hover {
    background: #4f46e5;
}

#kology-lead-error {
    color: #ef4444;
    font-size: 13px;
    text-align: center;
    margin-top: 12px;
    min-height: 20px;
}

/* --- CHAT MESSAGES --- */
#kology-chatbot-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    gap: 16px; /* slightly more gap for rich messages */
}

.kology-chatbot-message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    animation: fadeIn 0.3s ease;
    word-wrap: break-word;
}

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

.bot-message {
    background: white;
    color: #374151;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    border: 1px solid #f3f4f6;
}

.user-message {
    background: #6366f1;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

/* --- MARKDOWN PREMIUM STYLING FOR BOT MESSAGES --- */
.bot-message strong {
    color: #1f2937;
    font-weight: 600;
}

.bot-message p {
    margin: 0 0 12px 0;
}
.bot-message p:last-child {
    margin-bottom: 0;
}

.bot-message ul, .bot-message ol {
    margin: 8px 0 12px 0;
    padding-left: 20px;
}

.bot-message li {
    margin-bottom: 6px;
}

.bot-message h1, .bot-message h2, .bot-message h3 {
    margin: 16px 0 8px 0;
    font-size: 16px;
    color: #111827;
}

.bot-message h1:first-child, .bot-message h2:first-child, .bot-message h3:first-child {
    margin-top: 0;
}

.bot-message a {
    color: #6366f1;
    text-decoration: underline;
}

/* --- INPUT AREA --- */
#kology-chatbot-input-area {
    padding: 16px;
    background: white;
    border-top: 1px solid #f3f4f6;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-shrink: 0;
}

#kology-chatbot-input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 20px;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    background: #f9fafb;
}

#kology-chatbot-input:focus {
    border-color: #6366f1;
    background: white;
}

#kology-chatbot-send {
    background: #6366f1;
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
}

#kology-chatbot-send:hover {
    background: #4f46e5;
}

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

.kology-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

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

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

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Scrollbar styling */
#kology-chatbot-messages::-webkit-scrollbar,
#kology-chatbot-lead-form::-webkit-scrollbar {
    width: 6px;
}
#kology-chatbot-messages::-webkit-scrollbar-track,
#kology-chatbot-lead-form::-webkit-scrollbar-track {
    background: transparent;
}
#kology-chatbot-messages::-webkit-scrollbar-thumb,
#kology-chatbot-lead-form::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 10px;
}

/* Responsive */
@media (max-width: 480px) {
    #kology-chatbot-window {
        width: calc(100vw - 40px);
        height: 70vh;
        bottom: 90px;
        right: -4px;
    }
}
