/* WP AI Chatbot - Frontend Widget Styles */

:root {
    --iamkd-primary: #4f46e5;       /* Dynamically overridden by PHP style injection */
    --iamkd-primary-hover: #4338ca; /* Dynamically overridden by PHP style injection */
    --iamkd-bg-bot: #f3f4f6;
    --iamkd-text-bot: #1f2937;
    --iamkd-text-user: #ffffff;
    --iamkd-radius: 16px;
    --iamkd-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --iamkd-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Floating Chat Button */
.iamkd-chat-trigger {
    position: fixed;
    bottom: 24px;
    width: 60px !important;
    height: 60px !important;
    border-radius: 50% !important;
    background-color: var(--iamkd-primary);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    border: none !important;
    outline: none;
    padding: 0 !important;
    transition: var(--iamkd-transition);
}

.iamkd-chat-trigger:hover {
    background-color: var(--iamkd-primary-hover);
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.iamkd-chat-trigger:active {
    transform: scale(0.95);
}

.iamkd-chat-trigger svg {
    width: 28px;
    height: 28px;
    fill: #ffffff;
    display: block;
    flex-shrink: 0;
    transition: var(--iamkd-transition);
}

.iamkd-chat-trigger svg path {
    fill: #ffffff;
}

/* Position Options */
.iamkd-pos-right {
    right: 24px;
}
.iamkd-pos-left {
    left: 24px;
}

/* Chat Window Container */
.iamkd-chat-container {
    position: fixed;
    bottom: 96px;
    width: 380px;
    height: 580px;
    max-height: calc(100vh - 120px);
    background-color: #ffffff;
    border-radius: var(--iamkd-radius);
    box-shadow: var(--iamkd-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999998;
    opacity: 0;
    transform: scale(0.9) translateY(20px);
    pointer-events: none;
    transition: var(--iamkd-transition);
}

.iamkd-chat-container.iamkd-active {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

/* Chat Header */
.iamkd-chat-header {
    background-color: var(--iamkd-primary);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #ffffff;
    position: relative;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.iamkd-chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 100%);
    pointer-events: none;
}

.iamkd-bot-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.iamkd-avatar {
    width: 40px;
    height: 40px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 18px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    box-sizing: border-box;
}

.iamkd-avatar-text {
    color: #ffffff;
}

.iamkd-bot-meta {
    display: flex;
    flex-direction: column;
}

.iamkd-bot-name {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
}

.iamkd-bot-status {
    font-size: 11px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.iamkd-status-dot {
    width: 6px;
    height: 6px;
    background-color: #10b981;
    border-radius: 50%;
    display: inline-block;
    animation: iamkd-pulse 2s infinite;
}

@keyframes iamkd-pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 5px rgba(16, 185, 129, 0);
    }
    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

.iamkd-close-btn {
    background: none;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--iamkd-transition);
    opacity: 0.8;
}

.iamkd-close-btn:hover {
    opacity: 1;
    background-color: rgba(255, 255, 255, 0.1);
}

.iamkd-close-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.iamkd-close-btn svg path,
.iamkd-close-btn svg polygon {
    fill: currentColor !important;
}

/* Chat Messages Content Area */
.iamkd-chat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #f9fafb;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Custom Scrollbar for Chat Body */
.iamkd-chat-body::-webkit-scrollbar {
    width: 6px;
}
.iamkd-chat-body::-webkit-scrollbar-track {
    background: transparent;
}
.iamkd-chat-body::-webkit-scrollbar-thumb {
    background-color: #d1d5db;
    border-radius: 10px;
}
.iamkd-chat-body::-webkit-scrollbar-thumb:hover {
    background-color: #9ca3af;
}

/* Message Bubbles */
.iamkd-message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: iamkd-message-slide 0.3s ease forwards;
    opacity: 0;
    transform: translateY(10px);
}

@keyframes iamkd-message-slide {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.iamkd-msg-bot {
    align-self: flex-start;
}

.iamkd-msg-user {
    align-self: flex-end;
}

.iamkd-msg-bubble {
    padding: 12px 16px;
    border-radius: var(--iamkd-radius);
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.iamkd-msg-bot .iamkd-msg-bubble {
    background-color: var(--iamkd-bg-bot);
    color: var(--iamkd-text-bot);
    border-top-left-radius: 4px;
}

.iamkd-msg-user .iamkd-msg-bubble {
    background-color: var(--iamkd-primary);
    color: var(--iamkd-text-user);
    border-top-right-radius: 4px;
}

/* Formatting for Bot Responses (Markdown style) */
.iamkd-msg-bubble p {
    margin: 0 0 8px 0;
}
.iamkd-msg-bubble p:last-child {
    margin-bottom: 0;
}
.iamkd-msg-bubble code {
    background-color: rgba(0, 0, 0, 0.05);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: Consolas, Monaco, "Andale Mono", monospace;
    font-size: 0.9em;
}
.iamkd-msg-bubble pre {
    background-color: rgba(0, 0, 0, 0.07);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}
.iamkd-msg-bubble pre code {
    background: none;
    padding: 0;
}
.iamkd-msg-bubble ul, .iamkd-msg-bubble ol {
    margin: 4px 0 8px 18px;
    padding: 0;
}
.iamkd-msg-bubble li {
    margin-bottom: 4px;
}

.iamkd-msg-timestamp {
    font-size: 10px;
    color: #9ca3af;
    margin-top: 4px;
    align-self: flex-start;
}

.iamkd-msg-user .iamkd-msg-timestamp {
    align-self: flex-end;
}

/* Typing Indicator */
.iamkd-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background-color: var(--iamkd-bg-bot);
    border-radius: 12px;
    border-top-left-radius: 4px;
    width: fit-content;
}

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

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

@keyframes iamkd-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* Chat Footer & Inputs */
.iamkd-chat-footer {
    padding: 16px 20px;
    background-color: #ffffff;
    border-top: 1px solid #f3f4f6;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.iamkd-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background-color: #f3f4f6;
    border-radius: 24px;
    padding: 6px 12px 6px 18px;
    border: 1px solid transparent;
    transition: var(--iamkd-transition);
}

.iamkd-input-wrapper:focus-within {
    border-color: var(--iamkd-primary);
    background-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.iamkd-chat-input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    padding: 6px 0;
    resize: none;
    overflow: hidden; /* hide scrollbar — JS auto-grows height */
    max-height: 120px;
    font-size: 14px;
    line-height: 1.4;
    font-family: inherit;
    color: #1f2937;
    scrollbar-width: none;      /* Firefox */
    -ms-overflow-style: none;   /* IE/Edge */
}
.iamkd-chat-input::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.iamkd-chat-input::placeholder {
    color: #9ca3af;
}

.iamkd-send-btn {
    background-color: var(--iamkd-primary);
    border: none;
    outline: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--iamkd-transition);
    opacity: 0.6;
    pointer-events: none;
    flex-shrink: 0;
}

.iamkd-send-btn.iamkd-active {
    opacity: 1;
    pointer-events: auto;
}

.iamkd-send-btn:hover {
    transform: scale(1.05);
}

.iamkd-send-btn svg {
    width: 16px;
    height: 16px;
    fill: #ffffff;
    display: block;
    flex-shrink: 0;
    transform: rotate(45deg);
    margin-right: 2px;
    margin-top: -1px;
}

.iamkd-send-btn svg path {
    fill: #ffffff;
}

.iamkd-footer-brand {
    font-size: 10px;
    text-align: center;
    color: #9ca3af;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.iamkd-footer-brand a {
    color: inherit;
    text-decoration: none;
    font-weight: 500;
}

.iamkd-footer-brand a:hover {
    color: var(--iamkd-primary);
}

/* Responsive Rules for Mobile */
@media (max-width: 480px) {
    .iamkd-chat-container {
        width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
    }
    
    .iamkd-chat-trigger {
        bottom: 16px !important;
    }
    
    .iamkd-pos-right .iamkd-chat-trigger { right: 16px !important; }
    .iamkd-pos-left .iamkd-chat-trigger { left: 16px !important; }
}
