/* AI Knowledge Base Pro - Chat Widget */
.aikb-chat-widget {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    background: #fff;
}

/* Header */
.aikb-chat-header {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.aikb-chat-header h3 { margin: 0; font-size: 16px; font-weight: 600; }
.aikb-chat-header-actions { display: flex; gap: 8px; align-items: center; }
.aikb-chat-header-actions select {
    background: rgba(255,255,255,0.2);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
}
.aikb-chat-header-actions option { color: #333; }
.aikb-chat-btn-new {
    background: rgba(255,255,255,0.2);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}
.aikb-chat-btn-new:hover { background: rgba(255,255,255,0.3); }

/* Sidebar */
.aikb-chat-body { display: flex; flex: 1; min-height: 0; }
.aikb-chat-sidebar {
    width: 220px;
    border-right: 1px solid #e5e7eb;
    overflow-y: auto;
    background: #f9fafb;
    flex-shrink: 0;
}
.aikb-chat-sidebar-header {
    padding: 12px;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
}
.aikb-chat-history-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.15s;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.aikb-chat-history-item:hover { background: #eff6ff; }
.aikb-chat-history-item.active { background: #e0e7ff; }
.aikb-chat-history-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aikb-chat-history-item .delete-chat {
    opacity: 0;
    cursor: pointer;
    color: #ef4444;
    font-size: 16px;
    padding: 0 4px;
}
.aikb-chat-history-item:hover .delete-chat { opacity: 1; }

/* Main Chat Area */
.aikb-chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.aikb-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #fafbfc;
    scroll-behavior: smooth;
}

.aikb-msg {
    margin-bottom: 16px;
    display: flex;
    gap: 10px;
    animation: aikb-fadeIn 0.3s;
}
@keyframes aikb-fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.aikb-msg-user { flex-direction: row-reverse; }
.aikb-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}
.aikb-msg-user .aikb-msg-avatar { background: #4f46e5; color: #fff; }
.aikb-msg-assistant .aikb-msg-avatar { background: #10b981; color: #fff; }

.aikb-msg-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.6;
    font-size: 14px;
    word-break: break-word;
}
.aikb-msg-user .aikb-msg-bubble {
    background: #4f46e5;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.aikb-msg-assistant .aikb-msg-bubble {
    background: #fff;
    border: 1px solid #e5e7eb;
    color: #374151;
    border-bottom-left-radius: 4px;
}
.aikb-msg-bubble img { max-width: 200px; border-radius: 8px; margin-top: 8px; }
.aikb-msg-bubble pre {
    background: #1f2937;
    color: #e5e7eb;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 13px;
    margin: 8px 0;
}
.aikb-msg-bubble code { background: #f3f4f6; padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.aikb-msg-bubble pre code { background: none; padding: 0; }

/* Welcome Message */
.aikb-welcome {
    text-align: center;
    padding: 40px;
    color: #9ca3af;
}
.aikb-welcome-icon { font-size: 48px; margin-bottom: 12px; }
.aikb-welcome h4 { margin: 0 0 8px; color: #6b7280; font-size: 16px; }
.aikb-welcome p { font-size: 14px; }

/* Input Area */
.aikb-chat-input-area {
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}
.aikb-chat-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.aikb-chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 10px 16px;
    font-size: 14px;
    resize: none;
    min-height: 42px;
    max-height: 120px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}
.aikb-chat-input:focus { border-color: #4f46e5; }
.aikb-chat-send-btn {
    background: #4f46e5;
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 10px 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s;
    white-space: nowrap;
}
.aikb-chat-send-btn:hover { background: #4338ca; }
.aikb-chat-send-btn:disabled { background: #9ca3af; cursor: not-allowed; }

/* Image Upload Button */
.aikb-chat-img-btn {
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 10px 12px;
    cursor: pointer;
    font-size: 18px;
    color: #6b7280;
    transition: all 0.15s;
}
.aikb-chat-img-btn:hover { color: #4f46e5; border-color: #4f46e5; }

/* Image Preview */
.aikb-image-preview {
    margin-bottom: 8px;
    position: relative;
    display: none;
}
.aikb-image-preview img {
    max-height: 80px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}
.aikb-image-preview .remove {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #ef4444;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Typing Indicator */
.aikb-typing {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}
.aikb-typing span {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: aikb-bounce 1.4s ease-in-out infinite;
}
.aikb-typing span:nth-child(2) { animation-delay: 0.2s; }
.aikb-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes aikb-bounce {
    0%, 80%, 100% { transform: scale(0.6); }
    40% { transform: scale(1); }
}

/* Dark Theme */
.aikb-chat-widget.aikb-theme-dark { background: #1a1a2e; border-color: #2d2d44; }
.aikb-theme-dark .aikb-chat-messages { background: #16162a; }
.aikb-theme-dark .aikb-msg-assistant .aikb-msg-bubble { background: #2d2d44; color: #e5e7eb; border-color: #3d3d5c; }
.aikb-theme-dark .aikb-chat-input-area { background: #1a1a2e; border-color: #2d2d44; }
.aikb-theme-dark .aikb-chat-input { background: #2d2d44; color: #e5e7eb; border-color: #3d3d5c; }
.aikb-theme-dark .aikb-chat-sidebar { background: #12122a; border-color: #2d2d44; }
.aikb-theme-dark .aikb-chat-history-item { border-color: #2d2d44; color: #e5e7eb; }
.aikb-theme-dark .aikb-chat-history-item:hover { background: #2d2d44; }
.aikb-theme-dark .aikb-welcome { color: #6b7280; }

/* Search Widget */
.aikb-search-widget { max-width: 600px; margin: 0 auto; }
.aikb-search-input-wrap { display: flex; gap: 8px; margin-bottom: 16px; }
.aikb-search-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    font-size: 15px;
}
.aikb-search-input:focus { border-color: #4f46e5; outline: none; }
.aikb-search-btn {
    background: #4f46e5;
    color: #fff;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 500;
}
.aikb-search-results { font-size: 14px; }
.aikb-search-result { padding: 12px; border: 1px solid #e5e7eb; border-radius: 8px; margin-bottom: 8px; }
.aikb-search-result-source { font-size: 11px; color: #6b7280; margin-top: 6px; }

@media (max-width: 768px) {
    .aikb-chat-sidebar { display: none; }
    .aikb-msg-bubble { max-width: 90%; }
}

/* ── Image Question Pipeline Styles ─────────────────────────── */

/* Input hint bar */
.aikb-input-hint {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 6px;
    text-align: center;
    letter-spacing: 0.01em;
}

/* Image in user message bubble */
.aikb-msg-image-wrap {
    margin-bottom: 8px;
    position: relative;
    display: inline-block;
}
.aikb-msg-image {
    max-width: 220px;
    max-height: 180px;
    border-radius: 10px;
    border: 2px solid rgba(255,255,255,0.3);
    display: block;
    cursor: zoom-in;
}
.aikb-img-label {
    display: block;
    font-size: 11px;
    margin-top: 4px;
    opacity: 0.75;
    font-style: italic;
}
.aikb-img-type-label {
    font-size: 11px;
    color: #6b7280;
    margin-top: 4px;
    display: block;
}

/* Extracted question chip */
.aikb-question-chip {
    background: #f0fdf4;
    border: 1px solid #86efac;
    border-left: 4px solid #22c55e;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: 13px;
}
.aikb-question-chip-label {
    display: block;
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #15803d;
    margin-bottom: 6px;
}
.aikb-question-chip-text {
    color: #166534;
    line-height: 1.5;
    white-space: pre-wrap;
    font-family: inherit;
    max-height: 120px;
    overflow-y: auto;
}

/* Answer content with step formatting */
.aikb-answer-content { line-height: 1.7; }
.aikb-section-header {
    font-weight: 700;
    color: #4f46e5;
    font-size: 13px;
    margin: 14px 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid #e0e7ff;
    padding-bottom: 4px;
}
.aikb-step {
    display: flex;
    gap: 10px;
    margin: 8px 0;
    padding: 8px 12px;
    background: #f8fafc;
    border-radius: 8px;
    border-left: 3px solid #4f46e5;
    align-items: flex-start;
}
.aikb-step-num {
    font-weight: 700;
    color: #4f46e5;
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 13px;
}

/* Multi-stage progress indicator */
.aikb-stage-progress {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 0;
    min-width: 220px;
}
.aikb-stage {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 13px;
    color: #9ca3af;
    opacity: 0.5;
    transition: all 0.3s ease;
}
.aikb-stage.aikb-stage-active {
    background: #eff6ff;
    color: #1d4ed8;
    opacity: 1;
    font-weight: 600;
}
.aikb-stage.aikb-stage-active .aikb-stage-icon {
    animation: aikb-pulse 1.2s ease-in-out infinite;
}
.aikb-stage.aikb-stage-done {
    color: #15803d;
    opacity: 0.8;
}
.aikb-stage-icon { font-size: 18px; }
@keyframes aikb-pulse {
    0%, 100% { transform: scale(1); }
    50%       { transform: scale(1.25); }
}

/* Drag & Drop overlay */
.aikb-drag-overlay {
    position: absolute;
    inset: 0;
    background: rgba(79,70,229,0.15);
    backdrop-filter: blur(3px);
    z-index: 100;
    border-radius: 16px;
    border: 3px dashed #4f46e5;
    display: flex;
    align-items: center;
    justify-content: center;
}
.aikb-drag-overlay-inner {
    text-align: center;
    color: #4f46e5;
    font-weight: 600;
    font-size: 16px;
}

/* Welcome tips row */
.aikb-welcome-tips {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 16px;
}
.aikb-tip {
    background: #eff6ff;
    color: #3730a3;
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid #c7d2fe;
    font-weight: 500;
}

/* Image preview label */
.aikb-image-preview {
    margin-bottom: 8px;
    position: relative;
    display: none;
    padding: 8px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px dashed #d1d5db;
}

/* Fullscreen image click */
.aikb-msg-image:active { opacity: 0.85; }
