/* RAG Inline Chat - Clean Black & White Design */
.rag-inline-chat {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    max-width: 1200px; /* Match section width */
    margin: 40px auto;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

.rag-inline-chat-container {
    padding: 0;
}

.rag-chat-header {
    background: #333333;
    color: white;
    padding: 24px 32px;
    border-bottom: 1px solid #e0e0e0;
    font-family: 'Yu Gothic', 'Meiryo', 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', sans-serif;
}

/* Only override theme CSS that conflicts, preserve inline styles */
.rag-chat-header h3:not([style]) {
    margin: 0 0 8px 0;
    font-size: 18px;
    font-weight: 600;
}

.rag-chat-header p:not([style]) {
    margin: 0;
    opacity: 0.9;
    font-size: 14px;
}

/* Ensure font family is applied to all elements */
.rag-chat-header,
.rag-chat-header * {
    font-family: 'Yu Gothic', 'Meiryo', 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', sans-serif !important;
}

/* Override only theme CSS that might interfere, but preserve inline styles */
.rag-chat-header p:not([style]),
.rag-chat-header h3:not([style]),
.rag-chat-header div:not([style]) {
    margin: 0;
    font-size: 14px;
    line-height: 1.6;
    color: white;
}

/* Force theme CSS to not override our styles */
html body .rag-inline-chat .rag-chat-header {
    font-family: 'Yu Gothic', 'Meiryo', 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', sans-serif !important;
}

/* Ensure inline styles take absolute precedence */
.rag-chat-header *[style] {
    font-family: 'Yu Gothic', 'Meiryo', 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', sans-serif !important;
}

/* Remove any default text-align to let inline styles work */
.rag-chat-header,
.rag-chat-header * {
    text-align: initial;
}

/* PRIORITY: Settings margin > Default margin */
/* Only apply default margin if no margin is specified in inline styles */
.rag-chat-header p:not([style*="margin"]) {
    margin: 1em 0 !important;
    line-height: 1.5 !important;
}

html body .rag-inline-chat .rag-chat-header p:not([style*="margin"]) {
    margin: 1em 0 !important;
    line-height: 1.5 !important;
    font-size: 13px !important;
}

/* WordPress admin-like heading styles for chatbot header */
/* Only apply if no inline styles are specified */
.rag-chat-header h1:not([style*="font-size"]):not([style*="margin"]) {
    color: #1d2327 !important;
    font-size: 2em !important;
    margin: 0.67em 0 !important;
}

.rag-chat-header h2:not([style*="font-size"]):not([style*="margin"]),
.rag-chat-header h3:not([style*="font-size"]):not([style*="margin"]) {
    color: #1d2327 !important;
    font-size: 1.3em !important;
    margin: 1em 0 !important;
}

.rag-chat-header h4:not([style*="font-size"]):not([style*="margin"]) {
    font-size: 1em !important;
    margin: 1.33em 0 !important;
}

.rag-chat-header h5:not([style*="font-size"]):not([style*="margin"]) {
    font-size: 0.83em !important;
    margin: 1.67em 0 !important;
}

.rag-chat-header h6:not([style*="font-size"]):not([style*="margin"]) {
    font-size: 0.67em !important;
    margin: 2.33em 0 !important;
}

/* But if there are inline styles, respect them */
html body .rag-inline-chat .rag-chat-header h1:not([style*="font-size"]):not([style*="margin"]) {
    color: white !important;
    font-size: 2em !important;
    margin: 0.67em 0 !important;
}

html body .rag-inline-chat .rag-chat-header h2:not([style*="font-size"]):not([style*="margin"]),
html body .rag-inline-chat .rag-chat-header h3:not([style*="font-size"]):not([style*="margin"]) {
    color: white !important;
    font-size: 1.3em !important;
    margin: 1em 0 !important;
}

html body .rag-inline-chat .rag-chat-header h4:not([style*="font-size"]):not([style*="margin"]) {
    color: white !important;
    font-size: 1em !important;
    margin: 1.33em 0 !important;
}

html body .rag-inline-chat .rag-chat-header h5:not([style*="font-size"]):not([style*="margin"]) {
    color: white !important;
    font-size: 0.83em !important;
    margin: 1.67em 0 !important;
}

html body .rag-inline-chat .rag-chat-header h6:not([style*="font-size"]):not([style*="margin"]) {
    color: white !important;
    font-size: 0.67em !important;
    margin: 2.33em 0 !important;
}

/* Ensure proper spacing for all text elements */
.rag-chat-header h3,
.rag-chat-header p,
.rag-chat-header div {
    line-height: 1.5 !important;
}

.rag-chat-messages {
    height: 300px;
    overflow-y: auto;
    padding: 20px;
    background: #fafafa;
}

.rag-message {
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
}

.rag-message-user {
    justify-content: flex-end;
}

.rag-message-bot {
    justify-content: flex-start;
}

.rag-message-error {
    justify-content: flex-start;
}

.message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px; /* Match section font size */
    line-height: 1.6;
}

.rag-message-user .message-content {
    background: #333333;
    color: white;
    border-bottom-right-radius: 4px;
}

.rag-message-bot .message-content {
    background: white;
    color: #333333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}

.rag-message-welcome {
    justify-content: flex-start;
}

.rag-message-welcome .message-content {
    background: white;
    color: #333333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
    /* No white-space: pre-wrap for welcome message */
}

.rag-message-error .message-content {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    border-bottom-left-radius: 4px;
}

/* API Error Info Styling */
.rag-api-error-info {
    background: #fef3cd;
    border: 1px solid #ffeaa7;
    border-radius: 6px;
    padding: 16px;
    margin-top: 20px;
    color: #856404;
}

.rag-api-error-info p {
    margin: 8px 0;
}

.rag-api-error-info strong {
    color: #856404;
    font-weight: 600;
}

.rag-quick-questions {
    padding: 20px;
    background: white;
    border-bottom: 1px solid #e5e7eb;
}

.rag-quick-questions p {
    margin: 0 0 12px 0;
    font-size: 14px; /* Match section font size */
    color: #333333;
    font-weight: 500;
}

.quick-questions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 8px;
}

.quick-question-btn {
    background: #f8f8f8;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 14px; /* Match section font size */
    color: #333333;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.quick-question-btn:hover {
    background: #f0f0f0;
    border-color: #cccccc;
}

.rag-chat-input {
    padding: 20px;
    background: white;
}

.input-container {
    display: flex;
    gap: 12px;
    align-items: center;
}

#rag-chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px; /* Match section font size */
    outline: none;
    transition: border-color 0.2s ease;
}

#rag-chat-input:focus {
    border-color: #333333;
}

#rag-chat-input:disabled {
    background: #f9fafb;
    color: #9ca3af;
    cursor: not-allowed;
}

#rag-send-btn {
    background: #333333;
    color: white;
    border: none;
    border-radius: 6px;
    width: 44px;
    height: 44px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

#rag-send-btn:hover:not(:disabled) {
    background: #555555;
    transform: scale(1.05);
}

#rag-send-btn:disabled {
    background: #cccccc;
    cursor: not-allowed;
    transform: none;
}

.send-icon {
    font-size: 16px;
    font-weight: bold;
}

.rag-typing-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e5e7eb;
    color: #6b7280;
    font-size: 14px;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

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

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

/* Responsive design */
@media (max-width: 768px) {
    .rag-inline-chat {
        margin: 20px;
        border-radius: 8px;
    }
    
    .rag-chat-header {
        padding: 20px;
    }
    
    .rag-chat-header h3 {
        font-size: 20px;
    }
    
    .rag-chat-messages {
        height: 250px;
        padding: 16px;
    }
    
    .message-content {
        max-width: 85%;
        font-size: 13px;
    }
    
    .quick-questions-grid {
        grid-template-columns: 1fr;
    }
    
    .rag-chat-input {
        padding: 16px;
    }
    
    .input-container {
        gap: 8px;
    }
    
    #rag-chat-input {
        padding: 10px 14px;
        font-size: 13px;
    }
    
    #rag-send-btn {
        width: 40px;
        height: 40px;
    }
}

/* Scrollbar styling */
.rag-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.rag-chat-messages::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.rag-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.rag-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}