/* RAG Chat - Frontend Styles */

.rag-chat-wrapper {
    max-width: 650px;
    margin: 0 auto;
    margin-top: 50px;
    position: relative;
}

/* Input Area */
.rag-chat-input-area {
    position: relative;
    display: flex;
    align-items: center;
}

.rag-chat-input-area .form-control {
    border: none;
    background-color: #fff;
    font-size: 16px;
    border-radius: 10px;
    height: 60px;
    padding: 0 20px;
    font-weight: 400;
    opacity: .8;
    padding-right: 60px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: 300ms all;
}

.rag-chat-input-area .form-control:focus {
    outline: none;
    border: none;
    opacity: 1;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

#rag-send-btn {
    position: absolute;
    right: 5px;
    top: 5px;
    border: none;
    width: 50px;
    height: 50px;
    background-color: var(--main-color-one);
    border-radius: 6px;
    color: #fff;
    transition: 300ms all;
    cursor: pointer;
    font-size: 16px;
}

#rag-send-btn:hover {
    background-color: var(--secondary-color);
}

#rag-send-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Response Area */
.rag-chat-response {
    margin-top: 15px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.4s ease, opacity 0.3s ease, padding 0.3s ease;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.rag-chat-response.active {
    max-height: 500px;
    overflow-y: auto;
    opacity: 1;
    padding: 20px 25px;
}

/* Close Button */
.rag-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    color: #999;
    font-size: 14px;
    cursor: pointer;
    padding: 5px;
    line-height: 1;
    transition: color 0.2s;
    z-index: 2;
}

.rag-close-btn:hover {
    color: #333;
}

/* Loading Animation */
.rag-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
}

.rag-typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
}

.rag-typing-indicator span {
    width: 8px;
    height: 8px;
    background-color: var(--main-color-one, #4a9eff);
    border-radius: 50%;
    animation: ragTyping 1.4s infinite ease-in-out;
}

.rag-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.rag-typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes ragTyping {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.rag-loading-text {
    color: #888;
    font-size: 14px;
}

/* Answer - direction set by JS based on content */
.rag-answer {
    font-size: 15px;
    line-height: 1.8;
    color: #333;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    word-break: normal;
}

.rag-answer.dir-rtl {
    direction: rtl;
    text-align: right;
}

.rag-answer.dir-ltr {
    direction: ltr;
    text-align: left;
}

.rag-answer a {
    color: var(--main-color-one, #4a9eff);
    text-decoration: underline;
    text-decoration-color: rgba(74, 158, 255, 0.3);
    text-underline-offset: 2px;
    transition: text-decoration-color 0.2s;
    word-break: break-all;
}

.rag-answer a:hover {
    text-decoration-color: var(--main-color-one, #4a9eff);
}

.rag-answer ul,
.rag-answer ol {
    margin: 8px 0;
    padding-left: 20px;
}

.dir-rtl .rag-answer ul,
.dir-rtl .rag-answer ol {
    padding-left: 0;
    padding-right: 20px;
}

.rag-answer li {
    margin-bottom: 4px;
}

.rag-answer code {
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 13px;
}

/* Typewriter cursor */
.rag-cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background-color: var(--main-color-one, #4a9eff);
    margin-left: 1px;
    vertical-align: text-bottom;
    animation: ragCursorBlink 0.7s infinite;
}

@keyframes ragCursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.dir-rtl .rag-cursor,
[dir="rtl"] .rag-cursor {
    margin-left: 0;
    margin-right: 1px;
}

/* Error */
.rag-error {
    color: #dc3545;
    font-size: 14px;
}

.rag-error i {
    margin-right: 5px;
}

/* Sources - improved layout */
.rag-sources {
    margin-top: 15px;
    padding-top: 14px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.rag-sources.dir-rtl {
    direction: rtl;
    text-align: right;
}

.rag-sources.dir-ltr {
    direction: ltr;
    text-align: left;
}

.rag-sources-title {
    font-size: 12px;
    font-weight: 700;
    color: #999;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.rag-sources-title i {
    margin-right: 5px;
    color: var(--main-color-one, #4a9eff);
}

.rag-sources-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    list-style: none;
    padding: 0;
    margin: 0;
}

.rag-source-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f5f7fa;
    border: 1px solid #e8ecf1;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 13px;
    transition: all 0.2s ease;
    max-width: 100%;
}

.rag-source-item:hover {
    background: #edf0f5;
    border-color: var(--main-color-one, #4a9eff);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.rag-source-item .source-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: #fff;
}

.rag-source-item .source-icon.type-knowledgebase {
    background: #3b82f6;
}

.rag-source-item .source-icon.type-faq {
    background: #8b5cf6;
}

.rag-source-item .source-icon.type-blog {
    background: #10b981;
}

.rag-source-item .source-icon.type-page {
    background: #f59e0b;
}

.rag-source-item a {
    color: #374151;
    text-decoration: none;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    transition: color 0.2s;
}

.rag-source-item:hover a {
    color: var(--main-color-one, #4a9eff);
}

.rag-source-item .source-label {
    color: #374151;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.rag-source-badge {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Suggested Questions */
.rag-suggested-questions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 14px;
}

.rag-suggestion-chip {
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 13px;
    color: #555;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rag-suggestion-chip:hover {
    background: var(--main-color-one, #4a9eff);
    color: #fff;
    border-color: var(--main-color-one, #4a9eff);
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
}

.rag-suggestion-chip:active {
    transform: translateY(0);
}

/* Hide suggestions when response is active */
.rag-chat-wrapper.suggestions-hidden .rag-suggested-questions {
    display: none;
}

/* RTL Support */
[dir="rtl"] .rag-chat-input-area .form-control {
    padding-right: 20px;
    padding-left: 60px;
}

[dir="rtl"] #rag-send-btn {
    right: auto;
    left: 5px;
}

[dir="rtl"] .rag-close-btn {
    right: auto;
    left: 10px;
}

/* Scrollbar */
.rag-chat-response::-webkit-scrollbar {
    width: 6px;
}

.rag-chat-response::-webkit-scrollbar-track {
    background: transparent;
}

.rag-chat-response::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.rag-chat-response::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    .rag-chat-wrapper {
        margin-top: 30px;
        max-width: 100%;
    }

    .rag-chat-input-area .form-control {
        font-size: 14px;
        height: 50px;
        padding: 0 15px;
        padding-right: 50px;
    }

    [dir="rtl"] .rag-chat-input-area .form-control {
        padding-right: 15px;
        padding-left: 50px;
    }

    #rag-send-btn {
        width: 42px;
        height: 42px;
        top: 4px;
        right: 4px;
        font-size: 14px;
    }

    [dir="rtl"] #rag-send-btn {
        right: auto;
        left: 4px;
    }

    .rag-chat-response.active {
        max-height: 60vh;
        padding: 15px;
    }

    .rag-answer {
        font-size: 14px;
        line-height: 1.9;
    }

    .rag-sources-list {
        gap: 6px;
    }

    .rag-source-item {
        padding: 5px 10px;
        font-size: 12px;
        max-width: calc(100vw - 60px);
    }

    .rag-source-item a,
    .rag-source-item .source-label {
        max-width: calc(100vw - 150px);
    }

    .rag-source-item .source-icon {
        width: 20px;
        height: 20px;
        font-size: 10px;
    }

    .rag-source-badge {
        font-size: 9px;
    }

    .rag-suggested-questions {
        gap: 6px;
        margin-bottom: 10px;
    }

    .rag-suggestion-chip {
        font-size: 12px;
        padding: 5px 12px;
        white-space: normal;
        max-width: 100%;
        text-align: center;
    }

    .rag-close-btn {
        top: 5px;
        right: 5px;
    }

    [dir="rtl"] .rag-close-btn {
        right: auto;
        left: 5px;
    }
}

@media (max-width: 480px) {
    .rag-chat-response.active {
        padding: 12px;
    }

    .rag-answer {
        font-size: 13px;
    }

    .rag-suggestion-chip {
        font-size: 11px;
        padding: 4px 10px;
    }

    .rag-sources-list {
        flex-direction: column;
    }

    .rag-source-item {
        width: 100%;
    }

    .rag-source-item a,
    .rag-source-item .source-label {
        max-width: calc(100vw - 120px);
    }
}

/* Dark Mode Support */
body.dark-mode-enabled .rag-chat-input-area .form-control {
    background-color: #2a2d35;
    color: rgba(255, 255, 255, 0.85);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

body.dark-mode-enabled .rag-chat-input-area .form-control:focus {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

body.dark-mode-enabled .rag-chat-input-area .form-control::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

body.dark-mode-enabled .rag-chat-response {
    background: rgba(42, 45, 53, 0.95);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

body.dark-mode-enabled .rag-close-btn {
    color: rgba(255, 255, 255, 0.4);
}

body.dark-mode-enabled .rag-close-btn:hover {
    color: rgba(255, 255, 255, 0.8);
}

body.dark-mode-enabled .rag-typing-indicator span {
    background-color: #79c0ff;
}

body.dark-mode-enabled .rag-loading-text {
    color: rgba(255, 255, 255, 0.5);
}

body.dark-mode-enabled .rag-answer {
    color: rgba(255, 255, 255, 0.85);
}

body.dark-mode-enabled .rag-answer a {
    color: #79c0ff;
    text-decoration-color: rgba(121, 192, 255, 0.3);
}

body.dark-mode-enabled .rag-answer a:hover {
    text-decoration-color: #79c0ff;
}

body.dark-mode-enabled .rag-answer code {
    background: rgba(255, 255, 255, 0.1);
    color: #79c0ff;
}

body.dark-mode-enabled .rag-error {
    color: #f87171;
}

body.dark-mode-enabled .rag-sources {
    border-top-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode-enabled .rag-sources-title {
    color: rgba(255, 255, 255, 0.5);
}

body.dark-mode-enabled .rag-source-item {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.12);
}

body.dark-mode-enabled .rag-source-item:hover {
    background: rgba(255, 255, 255, 0.12);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

body.dark-mode-enabled .rag-source-item a,
body.dark-mode-enabled .rag-source-item .source-label {
    color: rgba(255, 255, 255, 0.8);
}

body.dark-mode-enabled .rag-source-item:hover a {
    color: var(--main-color-one, #4a9eff);
}

body.dark-mode-enabled .rag-source-badge {
    color: rgba(255, 255, 255, 0.4);
}

body.dark-mode-enabled .rag-suggestion-chip {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.7);
}

body.dark-mode-enabled .rag-suggestion-chip:hover {
    background: var(--main-color-one, #4a9eff);
    color: #fff;
    border-color: var(--main-color-one, #4a9eff);
}

body.dark-mode-enabled .rag-chat-response::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

body.dark-mode-enabled .rag-chat-response::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}
