/* AI Sidebar Styles - Themed for StudyAll */

:root {
    --ai-sidebar-width: 380px;
}

/* Sidebar Container */
.ai-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: var(--ai-sidebar-width);
    background-color: var(--sidebar-bg);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    z-index: 999;
    border-left: 1px solid var(--border-color);
}

.ai-sidebar.collapsed {
    transform: translateX(100%);
}

/* Header */
.ai-sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--sidebar-bg);
}

.ai-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-status-dot {
    width: 8px;
    height: 8px;
    background-color: var(--muted-text);
    border-radius: 50%;
    transition: background-color 0.3s;
}

.ai-status-dot.active {
    background-color: var(--accent-primary);
    box-shadow: 0 0 5px var(--accent-primary);
}

.ai-sidebar-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--sidebar-text);
}

.ai-sidebar-subtitle {
    margin: 0;
    font-size: 0.75rem;
    color: var(--muted-text);
}

.ai-clear-btn {
    background: transparent;
    border: none;
    color: var(--muted-text);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 6px 10px;
    border-radius: 6px;
    transition: all 0.2s;
    font-family: inherit;
}

.ai-clear-btn:hover {
    background: var(--card-bg);
    color: var(--text-primary);
}

/* Chatbox */
.ai-chatbox {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.ai-chatbox::-webkit-scrollbar {
    width: 6px;
}

.ai-chatbox::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chatbox::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.ai-chatbox::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* Messages */
.ai-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    animation: ai-fadeIn 0.3s ease;
}

@keyframes ai-fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-message.user {
    background-color: var(--accent-primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.ai-message.bot {
    background-color: #2A2A2A;
    color: #E8E8E8;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
    padding-right: 28px;
    /* Space for action buttons */
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Message content */
.ai-message-img {
    max-width: 100%;
    border-radius: 8px;
    margin-bottom: 8px;
    display: block;
}

.ai-file-attachment {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.1);
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.ai-file-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Bot message markdown */
.ai-message.bot pre {
    background: #1E1E1E;
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 10px 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-message.bot code {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
    background: #1E1E1E;
    padding: 2px 4px;
    border-radius: 3px;
}

.ai-message.bot p {
    margin: 0 0 8px 0;
}

.ai-message.bot p:last-child {
    margin: 0;
}

.ai-message.bot ul,
.ai-message.bot ol {
    margin: 8px 0;
    padding-left: 20px;
}

.ai-message.bot h1,
.ai-message.bot h2,
.ai-message.bot h3 {
    font-weight: 600;
    margin: 12px 0 6px 0;
    line-height: 1.3;
}

.ai-message.bot h1 {
    font-size: 1.25em;
}

.ai-message.bot h2 {
    font-size: 1.15em;
}

.ai-message.bot h3 {
    font-size: 1.05em;
}

.ai-message.bot strong {
    font-weight: 600;
}

/* Sources */
.ai-sources {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
    font-size: 0.8rem;
}

.ai-sources-title {
    color: var(--muted-text);
    font-size: 0.75rem;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-source-chip {
    display: inline-flex;
    align-items: center;
    background: var(--main-bg);
    color: var(--accent-primary);
    padding: 4px 8px;
    border-radius: 4px;
    margin-right: 6px;
    margin-bottom: 6px;
    text-decoration: none;
    transition: background 0.2s;
    font-size: 0.75rem;
}

.ai-source-chip:hover {
    background: var(--border-hover);
}

/* Message Tools */
.ai-message-tools {
    position: absolute;
    top: 6px;
    right: 6px;
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    gap: 4px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(4px);
    border-radius: 6px;
    padding: 3px;
    border: 1px solid var(--border-color);
}

.ai-message:hover .ai-message-tools {
    opacity: 1;
}

.ai-action-btn {
    background: transparent;
    border: none;
    color: var(--muted-text);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.ai-action-btn:hover {
    background: var(--card-bg);
    color: var(--text-primary);
}

/* Input Area */
.ai-input-area {
    padding: 16px;
    background-color: var(--sidebar-bg);
    border-top: 1px solid var(--border-color);
}

.ai-file-preview {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    overflow-x: auto;
    padding: 2px;
}

.ai-preview-item {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 10px;
    border: 2px solid var(--border-color);
    background-size: cover;
    background-position: center;
    background-color: var(--card-bg);
    flex-shrink: 0;
    transition: all 0.2s;
}

.ai-preview-item:hover {
    border-color: var(--accent-primary);
    transform: scale(1.05);
}

.ai-preview-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: var(--accent-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    border: 2px solid var(--sidebar-bg);
    transition: all 0.2s;
}

.ai-preview-remove:hover {
    background: var(--accent-hover);
    transform: scale(1.1);
}

.ai-input-container {
    display: flex;
    align-items: center;
    background: #2A2A2A;
    border-radius: 14px;
    padding: 8px 12px;
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
    gap: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.ai-input-container:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(88, 101, 242, 0.2), 0 4px 12px rgba(0, 0, 0, 0.3);
}

.ai-input-container textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: #E8E8E8;
    padding: 6px 8px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.9rem;
    font-weight: 400;
    resize: none;
    height: 38px;
    min-height: 38px;
    max-height: 120px;
    outline: none;
    line-height: 1.5;
}

.ai-input-container textarea::placeholder {
    color: rgba(255, 255, 255, 0.4);
    opacity: 1;
}

.ai-icon-btn {
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.6);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    position: relative;
}

.ai-icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    transform: translateY(-1px);
}

.ai-icon-btn:active {
    transform: translateY(0);
}

.ai-icon-btn.active {
    background: var(--accent-light);
    color: var(--accent-primary);
}

.ai-icon-btn.active::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 6px;
    height: 6px;
    background: var(--accent-primary);
    border-radius: 50%;
    box-shadow: 0 0 4px var(--accent-primary);
}

.ai-send-btn {
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-hover) 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(88, 101, 242, 0.3);
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

.ai-send-btn:hover {
    box-shadow: 0 4px 12px rgba(88, 101, 242, 0.4);
    transform: translateY(-2px);
}

.ai-send-btn:disabled {
    background: var(--border-color);
    color: var(--muted-text);
    cursor: not-allowed;
    opacity: 0.5;
    box-shadow: none;
    transform: none;
}

/* Typing Cursor */
.ai-cursor {
    display: inline-block;
    width: 6px;
    height: 16px;
    background-color: var(--accent-primary);
    animation: ai-blink 1s step-end infinite;
    vertical-align: middle;
    margin-left: 4px;
}

@keyframes ai-blink {
    50% {
        opacity: 0;
    }
}

/* Toggle Button */
.ai-toggle-btn {
    position: fixed;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    border: 1px solid var(--border-color);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-md);
    z-index: 998;
}

.ai-sidebar:not(.collapsed)+.ai-toggle-btn {
    right: calc(var(--ai-sidebar-width) + 20px);
}

.ai-toggle-btn:hover {
    background-color: var(--card-bg);
    box-shadow: var(--shadow-lg);
}

/* Typing Indicator */
.ai-typing-indicator {
    padding: 12px 16px !important;
}

.ai-typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.ai-typing-dots span {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    animation: ai-typing-pulse 1.4s infinite;
}

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

.ai-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes ai-typing-pulse {

    0%,
    60%,
    100% {
        opacity: 0.4;
        transform: scale(1);
    }

    30% {
        opacity: 1;
        transform: scale(1.2);
    }
}

/* Search Indicator */
.ai-search-indicator {
    padding: 12px 16px;
}

.ai-search-status {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
    font-size: 14px;
}

.ai-search-spinner {
    animation: ai-search-spin 1.5s linear infinite;
    color: var(--accent-primary);
}

@keyframes ai-search-spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Stop Button */
.ai-typing-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-stop-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    transition: all 0.2s ease;
}

.ai-stop-btn:hover {
    background: var(--error);
    color: white;
    border-color: var(--error);
}

/* User Message Tools (Edit Button) */
.ai-message-tools.user-tools {
    opacity: 0;
    transition: opacity 0.2s ease;
}

.ai-message.user:hover .ai-message-tools.user-tools {
    opacity: 1;
}

/* Send Button Modes */
.ai-send-btn.cancel-mode {
    pointer-events: auto !important;
    cursor: pointer !important;
    opacity: 1 !important;
}

.ai-send-btn.cancel-mode svg {
    fill: var(--error);
    stroke: none;
}

.ai-send-btn.cancel-mode:hover {
    background: var(--bg-tertiary);
}

.ai-send-btn.editing {
    background: var(--success-light) !important;
    border-color: var(--success) !important;
}

/* Responsive */
@media (max-width: 768px) {
    :root {
        --ai-sidebar-width: 100%;
    }

    .ai-toggle-btn {
        bottom: 20px;
        top: auto;
    }
}