/* Assistant specific styles */
.study-assistant-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 160px); /* Account for topbar, margins */
    background: var(--bg-surface);
    border-radius: 20px;
    border: 1px solid var(--border-glass);
    overflow: hidden;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

.chat-header {
    padding: 16px 24px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-glass);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
}

.chat-header__info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header__icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
}

.chat-header__title {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.chat-header__status {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-header__status::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--accent-purple);
    border-radius: 50%;
    display: inline-block;
}

.chat-actions {
    display: flex;
    gap: 8px;
}

.chat-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--border-glass);
    background: transparent;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

/* Chat History Area */
.chat-window {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

.chat-message {
    display: flex;
    gap: 16px;
    max-width: 85%;
    animation: slideUp 0.3s ease-out forwards;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message--user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message--ai {
    align-self: flex-start;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-message--user .chat-avatar {
    background: rgba(16, 185, 129, 0.1);
    color: var(--text-primary);
    border: 1px solid var(--border-glass);
}

.chat-message--ai .chat-avatar {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.chat-bubble {
    padding: 14px 18px;
    border-radius: 18px;
    position: relative;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-primary);
}

.chat-message--user .chat-bubble {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid var(--border-glass);
    border-bottom-right-radius: 4px;
}

.chat-message--ai .chat-bubble {
    background: rgba(16, 185, 129, 0.05);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-bottom-left-radius: 4px;
}

.chat-bubble--error {
    background: rgba(239, 68, 68, 0.08) !important;
    border: 1px solid rgba(239, 68, 68, 0.25) !important;
    color: #ef4444 !important;
}

.chat-bubble--error strong {
    color: #dc2626 !important;
}

/* Markdown Rendering inside Bubble */
.chat-bubble p { margin-bottom: 0.8rem; color: inherit; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble strong { font-weight: 600; color: inherit; }
.chat-message--ai .chat-bubble strong { 
    color: var(--text-primary);
    background: rgba(16, 185, 129, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}
.chat-bubble em { font-style: italic; }
.chat-bubble ul, .chat-bubble ol { margin-left: 20px; margin-bottom: 0.8rem; }
.chat-bubble li { margin-bottom: 4px; }
.chat-bubble .markdown-body {
    overflow-x: auto;
}
.chat-bubble .markdown-body table {
    width: 100%;
    margin: 0.8rem 0;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid rgba(15, 23, 42, 0.14);
    border-radius: 12px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.55);
}
.chat-bubble .markdown-body th,
.chat-bubble .markdown-body td {
    padding: 10px 12px;
    text-align: left;
    vertical-align: top;
    border-right: 1px solid rgba(15, 23, 42, 0.12);
    border-bottom: 1px solid rgba(15, 23, 42, 0.12);
}
.chat-bubble .markdown-body th:last-child,
.chat-bubble .markdown-body td:last-child {
    border-right: none;
}
.chat-bubble .markdown-body tr:last-child td {
    border-bottom: none;
}
.chat-bubble .markdown-body thead th {
    background: rgba(16, 185, 129, 0.12);
    font-weight: 700;
}
.chat-bubble .markdown-body table:first-child,
.chat-bubble .markdown-body table:last-child {
    margin-top: 0;
    margin-bottom: 0;
}
[data-theme="dark"] .chat-bubble .markdown-body table {
    border-color: rgba(148, 163, 184, 0.24);
    background: rgba(15, 23, 42, 0.92);
}
[data-theme="dark"] .chat-bubble .markdown-body th,
[data-theme="dark"] .chat-bubble .markdown-body td {
    border-right-color: rgba(148, 163, 184, 0.18);
    border-bottom-color: rgba(148, 163, 184, 0.18);
    color: var(--text-primary);
}
[data-theme="dark"] .chat-bubble .markdown-body thead th {
    background: rgba(16, 185, 129, 0.18);
}
.chat-bubble code {
    background: rgba(0,0,0,0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}
.chat-bubble pre {
    background: #1e1e1e;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 0.8rem;
    overflow-x: auto;
}
.chat-bubble pre code {
    background: transparent;
    padding: 0;
    color: #d4d4d4;
}

/* Typing Indicator */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 12px 18px;
    background: rgba(16, 185, 129, 0.05);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--accent-mint);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0s; }

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

/* Input Area */
.chat-input-area {
    padding: 20px 24px;
    background: var(--bg-dark);
    border-top: 1px solid var(--border-glass);
}

.chat-input-wrapper {
    position: relative;
    display: flex;
    align-items: flex-end;
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    transition: all 0.2s ease;
}

.chat-input-wrapper:focus-within {
    border-color: var(--accent-mint);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 14px 16px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    resize: none;
    min-height: 50px;
    max-height: 150px;
    outline: none;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    margin: 5px;
    border-radius: 12px;
    border: none;
    background: var(--accent-mint);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: var(--accent-purple);
    transform: translateY(-1px);
}

.chat-send-btn:disabled {
    background: var(--border-glass);
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
}

.chat-disclaimer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 12px;
}

/* Mobile */
@media (max-width: 768px) {
    .study-assistant-container {
        height: calc(100vh - 120px);
        border-radius: 12px;
    }
    .chat-message { max-width: 95%; }
}
