/**
 * AIDB RAG Chatbot - Styles
 */

.aidb-rag-chatbot {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 560px;
    max-width: 640px;
    margin: 0 auto 24px;
    background: #fff;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
}

/* Header */
.aidb-rag-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    color: #fff;
    flex-shrink: 0;
}

.aidb-rag-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
}

.aidb-rag-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: #8b9cf7;
}

.aidb-rag-badge {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(139, 156, 247, 0.25);
    color: #a5b4fc;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.aidb-rag-header-actions {
    display: flex;
    gap: 4px;
}

.aidb-rag-header-actions button {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

.aidb-rag-header-actions button:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

/* Messages area */
.aidb-rag-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 32px;
    background: #f7f8fc;
    position: relative;
}

.aidb-rag-messages-inner {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.aidb-rag-messages-inner.has-messages {
    min-height: 100%;
    justify-content: flex-end;
}

.aidb-rag-message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 90%;
}

.aidb-rag-message-wrapper:has(.aidb-rag-message-user) {
    align-self: flex-end;
}

.aidb-rag-message-wrapper:has(.aidb-rag-message-assistant) {
    align-self: flex-start;
}

.aidb-rag-message {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.65;
    word-wrap: break-word;
    animation: aidb-rag-fade-in 0.3s ease;
}

@keyframes aidb-rag-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.aidb-rag-message-assistant {
    background: #fff;
    color: #333;
    border: 1px solid #e4e7f0;
    border-bottom-left-radius: 4px;
}

.aidb-rag-message-user {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Markdown in assistant messages */
.aidb-rag-message-assistant strong { font-weight: 700; }
.aidb-rag-message-assistant code {
    background: rgba(0, 0, 0, 0.05);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.9em;
}
.aidb-rag-message-assistant ul {
    margin: 8px 0;
    padding-left: 18px;
}
.aidb-rag-message-assistant li {
    margin-bottom: 4px;
}

/* Paper reference highlight in text */
.aidb-rag-paper-ref {
    background: linear-gradient(135deg, rgba(139, 156, 247, 0.12), rgba(139, 156, 247, 0.06));
    color: #4f46e5;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 500;
    font-size: 0.92em;
}

a.aidb-rag-paper-ref {
    text-decoration: none;
    border-bottom: 1px dashed rgba(79, 70, 229, 0.4);
    transition: all 0.2s;
    cursor: pointer;
}

a.aidb-rag-paper-ref:hover {
    background: linear-gradient(135deg, rgba(139, 156, 247, 0.22), rgba(139, 156, 247, 0.12));
    border-bottom-color: #4f46e5;
    color: #3730a3;
}

/* References panel */
.aidb-rag-references {
    margin-top: 8px;
    animation: aidb-rag-fade-in 0.3s ease;
}

.aidb-rag-refs-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid #dde1ec;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    color: #5b6078;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    width: 100%;
    justify-content: center;
}

.aidb-rag-refs-toggle:hover {
    background: #f0f2f8;
    border-color: #c5c9d9;
}

.aidb-rag-refs-toggle.open {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    background: #f0f2f8;
}

.aidb-rag-refs-list {
    display: none;
    border: 1px solid #dde1ec;
    border-top: none;
    border-radius: 0 0 8px 8px;
    background: #fff;
    overflow: hidden;
}

.aidb-rag-ref-item {
    padding: 10px 14px;
    border-bottom: 1px solid #f0f2f8;
}

.aidb-rag-ref-item:last-child {
    border-bottom: none;
}

.aidb-rag-ref-title {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #2d3748;
    text-decoration: none;
    line-height: 1.4;
    margin-bottom: 4px;
}

.aidb-rag-ref-title:hover {
    color: #4f46e5;
    text-decoration: underline;
}

.aidb-rag-ref-meta {
    display: flex;
    gap: 12px;
    font-size: 11px;
    color: #8890a4;
    margin-bottom: 4px;
}

.aidb-rag-ref-score {
    color: #6366f1;
    font-weight: 500;
}

.aidb-rag-ref-keywords {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.aidb-rag-ref-kw {
    display: inline-block;
    padding: 1px 7px;
    background: #f0f2f8;
    color: #5b6078;
    border-radius: 8px;
    font-size: 10px;
    line-height: 1.6;
}

/* Typing indicator */
.aidb-rag-typing { padding-top: 8px; }

.aidb-rag-thinking-text {
    font-size: 12px;
    color: #8890a4;
    margin-right: 8px;
}

.aidb-rag-dots {
    display: inline-flex;
    gap: 3px;
    vertical-align: middle;
}

.aidb-rag-dots span {
    width: 5px;
    height: 5px;
    background: #8b9cf7;
    border-radius: 50%;
    animation: aidb-rag-bounce 1.4s infinite ease-in-out both;
}

.aidb-rag-dots span:nth-child(1) { animation-delay: -0.32s; }
.aidb-rag-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes aidb-rag-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Suggestion buttons */
.aidb-rag-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 24px;
    animation: aidb-rag-fade-in 0.4s ease;
}

.aidb-rag-suggestion {
    display: inline-block;
    padding: 8px 14px;
    background: #fff;
    border: 1.5px solid #c5c9e0;
    border-radius: 20px;
    font-size: 13px;
    color: #3d4263;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    line-height: 1.3;
}

.aidb-rag-suggestion:hover {
    background: #4f46e5;
    color: #fff;
    border-color: #4f46e5;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
}

.aidb-rag-suggestion-secondary {
    background: transparent;
    border-style: dashed;
    color: #6b7280;
}

.aidb-rag-suggestion-secondary:hover {
    background: #f3f4f6;
    color: #3d4263;
    border-color: #c5c9e0;
    border-style: dashed;
    transform: translateY(-1px);
    box-shadow: none;
}

/* Input area */
.aidb-rag-input-form {
    padding: 14px 16px;
    border-top: 1px solid #e4e7f0;
    background: #fff;
    flex-shrink: 0;
}

.aidb-rag-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: #f5f6fa;
    border-radius: 24px;
    padding: 6px 6px 6px 18px;
    border: 1px solid #dde1ec;
    transition: border-color 0.2s;
    min-height: 48px;
    box-sizing: border-box;
}

.aidb-rag-input-wrapper:focus-within {
    border-color: #8b9cf7;
    box-shadow: 0 0 0 3px rgba(139, 156, 247, 0.1);
}

.aidb-rag-input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    max-height: 100px;
    padding: 8px 0;
    font-family: inherit;
}

.aidb-rag-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
}

.aidb-rag-send-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #4338ca, #4f46e5);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.aidb-rag-send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Remaining counter in header */
.aidb-rag-remaining {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.55);
    padding: 3px 8px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    font-variant-numeric: tabular-nums;
}

/* Tier note (free members) */
.aidb-rag-guest-note {
    text-align: center;
    font-size: 11px;
    color: #999;
    margin-top: 6px;
}

.aidb-rag-guest-note a {
    color: #6366f1;
    font-weight: 500;
    text-decoration: none;
}

.aidb-rag-guest-note a:hover {
    text-decoration: underline;
}

/* Visitor preview: disabled suggestions */
.aidb-rag-suggestions-disabled .aidb-rag-suggestion {
    opacity: 0.5;
    cursor: default;
    pointer-events: none;
}

/* Visitor preview: login CTA */
.aidb-rag-login-cta {
    padding: 20px 16px;
    border-top: 1px solid #e4e7f0;
    background: #fff;
    flex-shrink: 0;
    text-align: center;
}

.aidb-rag-login-btn {
    display: block;
    padding: 12px 24px;
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #fff;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
}

.aidb-rag-login-btn:hover {
    background: linear-gradient(135deg, #4338ca, #4f46e5);
    color: #fff;
    text-decoration: none;
    box-shadow: 0 2px 12px rgba(79, 70, 229, 0.3);
}

.aidb-rag-login-sub {
    font-size: 11px;
    color: #999;
    margin: 8px 0 0;
}

/* Source note at bottom */
.aidb-rag-source-note {
    padding: 4px 0 0;
    text-align: right;
    font-size: 10px;
    color: #aab0c0;
}

.aidb-rag-source-note a {
    color: #8890a4;
    text-decoration: none;
    border-bottom: 1px dotted #b0b6c8;
    transition: color 0.2s;
}

.aidb-rag-source-note a:hover {
    color: #4f46e5;
    border-bottom-color: #4f46e5;
}

/* History panel */
.aidb-rag-history-panel {
    background: #fff;
    border-bottom: 1px solid #e4e7f0;
    max-height: 280px;
    overflow-y: auto;
    flex-shrink: 0;
}

.aidb-rag-history-list {
    padding: 4px 0;
}

.aidb-rag-history-header {
    padding: 8px 16px;
    border-bottom: 1px solid #eef0f6;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.aidb-rag-history-count {
    font-size: 11px;
    color: #8890a4;
    font-weight: 500;
}

.aidb-rag-history-warning {
    font-size: 11px;
    color: #d97706;
    line-height: 1.4;
}

.aidb-rag-history-empty {
    padding: 20px 16px;
    text-align: center;
    font-size: 13px;
    color: #8890a4;
}

.aidb-rag-history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px 10px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-left: 3px solid transparent;
}

.aidb-rag-history-item:hover {
    background: #f5f6fa;
}

.aidb-rag-history-item.active {
    background: #eef0fb;
    border-left-color: #4f46e5;
}

.aidb-rag-history-item-content {
    flex: 1;
    min-width: 0;
}

.aidb-rag-history-item-title {
    font-size: 13px;
    font-weight: 500;
    color: #2d3748;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.aidb-rag-history-item-meta {
    font-size: 11px;
    color: #8890a4;
    margin-top: 2px;
}

.aidb-rag-history-delete {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    border-radius: 6px;
    color: #aab0c0;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s;
    opacity: 0;
}

.aidb-rag-history-item:hover .aidb-rag-history-delete {
    opacity: 1;
}

.aidb-rag-history-delete:hover {
    background: #fee2e2;
    color: #dc2626;
}

/* Paper page embedded layout */
.aidb-paper-rag-section {
    margin-top: 40px;
    padding-top: 32px;
    border-top: 2px solid #eef0f6;
}

.aidb-paper-rag-section .aidb-paper-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.aidb-paper-rag-icon {
    color: #6366f1;
    flex-shrink: 0;
}

.aidb-paper-rag-desc {
    font-size: 13px;
    color: #6b7280;
    margin: 4px 0 16px;
    line-height: 1.6;
}

.aidb-paper-rag-section .aidb-rag-chatbot {
    max-width: 100%;
}

/* Search + Chat grid layout (homepage) */
.aidb-search-chat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}

.aidb-search-chat-bot .aidb-rag-chatbot {
    max-width: 100%;
}

@media (max-width: 900px) {
    .aidb-search-chat-grid {
        grid-template-columns: 1fr;
    }
}

/* Compact: height <= 400px */
.aidb-rag-compact .aidb-rag-input::placeholder {
    color: transparent;
}

/* Responsive */
@media (max-width: 600px) {
    .aidb-rag-chatbot {
        max-width: 100%;
        border-radius: 8px;
    }

    .aidb-rag-message-wrapper {
        max-width: 95%;
    }

    .aidb-rag-suggestion {
        font-size: 12px;
        padding: 6px 12px;
    }
}
