/* ============================================================
   Docs AI Chat Widget — Right Sidebar Style (Mem0-like)
   ============================================================ */

/* "Ask AI" button in docs header (next to search, no hard border) */
.docs-ai-header-btn {
    position: absolute; right: 0.3rem; top: 50%; transform: translateY(-50%);
    z-index: 2;
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.25rem 0.55rem; font-size: 0.72rem; font-weight: 500;
    color: var(--t-text-muted); background: transparent;
    margin-left: 0.4rem;
    border: none; border-radius: 8px;
    cursor: pointer; transition: all 0.15s; white-space: nowrap;
    flex-shrink: 0;
}
.docs-ai-header-btn i { font-size: 13px; }
.docs-ai-header-btn:hover { color: var(--t-text); background: var(--t-bg-hover); }

/* Hidden overlay (no backdrop for sidebar style) */
.docs-ai-overlay { display: none; }

/* Right sidebar panel */
.docs-ai-panel {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: 340px;
    background: var(--t-bg-card, #fff);
    border-left: none;
    box-shadow: -2px 0 24px rgba(0,0,0,0.06);
    display: none;
    flex-direction: column;
    z-index: 1101;
    transition: width 0.25s ease;
}
.docs-ai-panel.open {
    display: flex;
}
.docs-ai-panel.expanded {
    width: 560px;
}

/* Push content when AI panel is open (non-docs/home pages)
   .content is position:fixed + right:0, so we change 'right' and 'width' */
body:not(:has(.docs-page)):not(:has(.home-page)):has(.docs-ai-panel.open) .content {
    right: 340px !important;
    width: calc(100% - 160px - 340px) !important;
    transition: margin-left 0.2s ease, width 0.25s ease, right 0.25s ease !important;
}
body:not(:has(.docs-page)):not(:has(.home-page)):has(.docs-ai-panel.expanded) .content {
    right: 560px !important;
    width: calc(100% - 160px - 560px) !important;
}
/* Collapsed sidebar + AI panel */
body.sidebar-collapsed:not(:has(.docs-page)):not(:has(.home-page)):has(.docs-ai-panel.open) .content {
    right: 340px !important;
    width: calc(100% - 52px - 340px) !important;
}
body.sidebar-collapsed:not(:has(.docs-page)):not(:has(.home-page)):has(.docs-ai-panel.expanded) .content {
    right: 560px !important;
    width: calc(100% - 52px - 560px) !important;
}
/* Homepage: .content is position:relative + flex:1, use max-width to cap flex growth */
body:has(.home-page):has(.docs-ai-panel.open) .content {
    max-width: calc(100% - 340px) !important;
    overflow: hidden !important;
    transition: max-width 0.25s ease !important;
}
body:has(.home-page):has(.docs-ai-panel.expanded) .content {
    max-width: calc(100% - 560px) !important;
    overflow: hidden !important;
}
body:has(.docs-ai-panel.open) .vk-topnav {
    right: 340px;
    transition: right 0.25s ease;
}
body:has(.docs-ai-panel.expanded) .vk-topnav {
    right: 560px;
}

/* Push docs page header + content when AI panel is open */
body:has(.docs-ai-panel.open) .docs-header {
    right: 340px;
    transition: right 0.25s ease;
}
body:has(.docs-ai-panel.expanded) .docs-header {
    right: 560px;
}
body:has(.docs-ai-panel.open) .docs-main {
    margin-right: 340px;
    transition: margin-right 0.25s ease;
}
body:has(.docs-ai-panel.expanded) .docs-main {
    margin-right: 560px;
}

/* Panel header */
.docs-ai-header {
    padding: 0.7rem 0.9rem;
    border-bottom: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.docs-ai-header-left {
    display: flex;
    align-items: center;
    gap: 6px;
}
.docs-ai-header-logo {
    width: 18px; height: 18px;
    border-radius: 3px; object-fit: contain;
}
.docs-ai-header-title {
    font-size: 0.8rem; font-weight: 600; color: var(--t-text);
}
.docs-ai-header-actions {
    display: flex; align-items: center; gap: 2px;
}
.docs-ai-header-actions button {
    background: none; border: none;
    color: var(--t-text-muted); cursor: pointer;
    font-size: 14px; padding: 4px; line-height: 1;
    border-radius: 4px; transition: all 0.15s;
}
.docs-ai-header-actions button:hover {
    color: var(--t-text); background: var(--t-bg-hover);
}
.docs-ai-header-close {
    background: none; border: none;
    color: var(--t-text-muted); cursor: pointer;
    font-size: 16px; padding: 4px; line-height: 1;
    border-radius: 4px; transition: all 0.15s;
}
.docs-ai-header-close:hover {
    color: var(--t-text); background: var(--t-bg-hover);
}

/* Disclaimer */
.docs-ai-disclaimer {
    padding: 0.5rem 0.9rem 0; font-size: 0.65rem; color: var(--t-text-dimmer, var(--t-text-muted));
    text-align: center; opacity: 0.7; flex-shrink: 0; margin-top: 0;
    transition: opacity 0.2s;
}
.docs-ai-disclaimer.hidden { display: none; }

/* Messages area */
.docs-ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Welcome message */
.docs-ai-welcome {
    padding: 1rem;
    background: var(--t-bg-card);
    border: 1px solid var(--t-border);
    border-radius: 8px;
    color: var(--t-text-secondary, var(--t-text-muted));
    font-size: 0.78rem;
    line-height: 1.5;
}

/* Message bubbles */
.docs-ai-msg {
    max-width: 90%;
    padding: 0.6rem 0.8rem;
    border-radius: 10px;
    font-size: 0.78rem;
    line-height: 1.5;
    word-wrap: break-word;
}
.docs-ai-msg-user {
    align-self: flex-end;
    background: var(--t-text);
    color: var(--t-bg);
    border-bottom-right-radius: 4px;
}
.docs-ai-msg-ai {
    align-self: flex-start;
    background: var(--t-bg-card);
    color: var(--t-text);
    border: 1px solid var(--t-border);
    border-bottom-left-radius: 4px;
}

/* AI message markdown */
.docs-ai-msg-ai p {
    margin: 0 0 0.5rem 0;
}
.docs-ai-msg-ai p:last-child {
    margin-bottom: 0;
}
.docs-ai-msg-ai strong {
    font-weight: 600;
}
.docs-ai-msg-ai ul, .docs-ai-msg-ai ol {
    margin: 0.4rem 0;
    padding-left: 1.3rem;
}
.docs-ai-msg-ai li {
    margin-bottom: 0.25rem;
}
.docs-ai-msg-ai code {
    background: var(--t-bg-hover);
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-size: 0.8rem;
}
.docs-ai-msg-ai h3, .docs-ai-msg-ai h4 {
    margin: 0.6rem 0 0.3rem 0;
    font-size: 0.9rem;
    font-weight: 600;
}
.docs-ai-msg-ai blockquote {
    margin: 0.4rem 0;
    padding: 0.3rem 0.8rem;
    border-left: 3px solid var(--t-border);
    color: var(--t-text-muted);
    font-size: 0.82rem;
}
.docs-ai-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0;
    font-size: 0.8rem;
}
.docs-ai-table th, .docs-ai-table td {
    border: 1px solid var(--t-border);
    padding: 0.4rem 0.6rem;
    text-align: left;
}
.docs-ai-table th {
    background: var(--t-bg-hover);
    font-weight: 600;
}
.docs-ai-table tr:nth-child(even) td {
    background: var(--t-bg-hover);
    opacity: 0.7;
}

/* References */
.docs-ai-refs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.6rem;
    padding-top: 0.6rem;
    border-top: none;
}
.docs-ai-ref-tag {
    font-size: 0.72rem;
    padding: 0.2rem 0.6rem;
    background: var(--t-bg-hover);
    border: none;
    border-radius: 4px;
    color: var(--t-text-muted) !important;
    cursor: pointer;
    text-decoration: none !important;
    transition: all 0.15s;
}
.docs-ai-ref-tag:hover {
    color: var(--t-text) !important;
    background: var(--t-bg-active);
    text-decoration: none !important;
}

/* Loading indicator */
.docs-ai-loading {
    align-self: flex-start;
    display: flex;
    gap: 5px;
    padding: 0.75rem 1rem;
}
.docs-ai-loading-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--t-text-dimmer);
    animation: docsAiPulse 1.2s infinite;
}
.docs-ai-loading-dot:nth-child(2) { animation-delay: 0.2s; }
.docs-ai-loading-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes docsAiPulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* Input area */
.docs-ai-input-area {
    padding: 0.6rem 0.9rem;
    border-top: none;
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    flex-shrink: 0;
}
.docs-ai-input {
    flex: 1;
    padding: 0.5rem 0.7rem;
    border: none;
    border-radius: 8px;
    background: var(--t-bg-hover);
    color: var(--t-text);
    font-size: 0.78rem;
    outline: none;
    transition: background 0.15s;
    resize: none;
}
.docs-ai-input:focus {
    background: var(--t-bg-active);
}
.docs-ai-input::placeholder {
    color: var(--t-text-dimmer);
}
.docs-ai-send {
    width: 32px; height: 32px;
    border-radius: 50%; border: none;
    background: var(--t-text); color: var(--t-bg);
    cursor: pointer; display: flex;
    align-items: center; justify-content: center;
    font-size: 13px; transition: opacity 0.15s;
    flex-shrink: 0;
}
.docs-ai-send:hover { opacity: 0.85; }
.docs-ai-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* Community links (inside welcome area) */
.docs-ai-community {
    margin-top: 0.75rem; padding-top: 0.65rem;
    border-top: 1px solid var(--t-border);
    display: flex; flex-direction: column; gap: 0.4rem;
}
.docs-ai-community > span {
    font-size: 0.68rem; color: var(--t-text-dimmer);
}
.docs-ai-community-links {
    display: flex; gap: 0.35rem;
}
.docs-ai-community-btn {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.3rem 0.6rem; font-size: 0.7rem; font-weight: 500;
    border-radius: 6px; text-decoration: none; transition: all 0.15s;
    white-space: nowrap;
}
.docs-ai-community-btn:hover { text-decoration: none; }
.docs-ai-discord {
    color: #5865F2 !important; background: rgba(88,101,242,0.1);
}
.docs-ai-discord i { color: #5865F2 !important; }
.docs-ai-discord:hover { background: rgba(88,101,242,0.2); color: #5865F2 !important; }
.docs-ai-discord:hover i { color: #5865F2 !important; }
.docs-ai-wechat {
    color: var(--t-text-muted) !important; background: var(--t-bg-hover);
}
.docs-ai-wechat i { color: var(--t-text-muted) !important; }
.docs-ai-wechat:hover { background: var(--t-bg-active); color: var(--t-text) !important; }
.docs-ai-wechat:hover i { color: var(--t-text) !important; }
.docs-ai-community-btn i { font-size: 12px; }

/* Inline WeChat card (inside chat panel) */
.docs-ai-wechat-card {
    background: var(--t-bg-card);
    border: 1px solid var(--t-border);
    border-radius: 10px;
    overflow: hidden;
    animation: docsAiSlideIn 0.2s ease;
}
@keyframes docsAiSlideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.docs-ai-wechat-card-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--t-border);
    font-size: 0.75rem; font-weight: 600; color: var(--t-text);
}
.docs-ai-wechat-card-header i.bi-wechat { color: #07C160; margin-right: 0.3rem; }
.docs-ai-wechat-card-close {
    background: none; border: none; color: var(--t-text-muted);
    cursor: pointer; font-size: 16px; padding: 2px; line-height: 1;
    border-radius: 4px; transition: all 0.15s;
}
.docs-ai-wechat-card-close:hover { color: var(--t-text); background: var(--t-bg-hover); }
.docs-ai-wechat-card-body {
    padding: 1rem;
    display: flex; flex-direction: column; align-items: center; gap: 0.6rem;
    text-align: center;
}
.docs-ai-wechat-card-body img {
    border-radius: 8px;
    border: 1px solid var(--t-border);
}
.docs-ai-wechat-card-body p {
    font-size: 0.7rem; color: var(--t-text-muted);
    line-height: 1.5; margin: 0;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .docs-ai-panel { width: 100vw; }
    .docs-ai-panel.expanded { width: 100vw; }
    .docs-ai-header-btn { padding: 0.2rem 0.4rem; font-size: 0.65rem; }
}
