/* AI Tutor Enhanced Styles - Phase 5 */
/* Modern, professional styling with animations */

/* CSS Variables for Theming */
:root {
    --ai-primary: #667eea;
    --ai-primary-dark: #5a67d8;
    --ai-secondary: #764ba2;
    --ai-success: #48bb78;
    --ai-warning: #f6ad55;
    --ai-error: #fc8181;
    --ai-bg: #ffffff;
    --ai-surface: #f7fafc;
    --ai-text: #2d3748;
    --ai-text-light: #718096;
    --ai-border: #e2e8f0;
    --ai-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    --ai-shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.15);
    --ai-radius: 12px;
    --ai-radius-sm: 8px;
    --ai-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Widget Container - High z-index to stay above sidebar */
.ai-tutor-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Chat bubble (always visible) */
.ai-tutor-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-primary), var(--ai-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--ai-shadow-lg);
    transition: var(--ai-transition);
    position: relative;
}

.ai-tutor-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 15px 50px rgba(102, 126, 234, 0.4);
}

/* Chat container - True Glass Transparency */
.ai-tutor-chat-container {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 500px;
    max-width: calc(100vw - 40px);
    height: 700px;
    max-height: 85vh;

    /* True Glassmorphism - Highly Transparent */
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.18);

    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.15),
                0 0 0 1px rgba(255, 255, 255, 0.1) inset;
    display: none; /* Hidden by default */
    flex-direction: column;
    transition: var(--ai-transition);
    animation: slideUp 0.3s ease-out;
    overflow: hidden;
    min-width: 350px;
    min-height: 500px;
}

/* Resize handle - Upper Left */
.ai-tutor-chat-container .resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    z-index: 10;
}

.ai-tutor-chat-container .resize-handle::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 12px;
    height: 12px;
    background: linear-gradient(225deg, transparent 50%, rgba(102, 126, 234, 0.4) 50%);
    border-radius: 20px 0 0 0;
}

/* Enhanced Header - Glass Transparent */
.ai-tutor-header {
    background: linear-gradient(135deg,
        rgba(102, 126, 234, 0.3),
        rgba(118, 75, 162, 0.3));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    padding: 16px;
    border-radius: 20px 20px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: move;
    user-select: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
}

.header-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-tutor-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-status-dot {
    width: 8px;
    height: 8px;
    background: var(--ai-success);
    border-radius: 50%;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Context Badge */
.context-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    backdrop-filter: blur(10px);
}

.context-badge-icon {
    font-size: 14px;
}

/* Header Actions */
.header-actions {
    display: flex;
    gap: 8px;
}

.header-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--ai-transition);
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* Quick Actions Bar */
.quick-actions {
    display: flex;
    gap: 8px;
    padding: 12px;
    background: var(--ai-surface);
    border-bottom: 1px solid var(--ai-border);
    overflow-x: auto;
}

.quick-actions::-webkit-scrollbar {
    height: 4px;
}

.quick-actions::-webkit-scrollbar-thumb {
    background: var(--ai-border);
    border-radius: 2px;
}

.action-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: white;
    border: 1px solid var(--ai-border);
    border-radius: 20px;
    font-size: 13px;
    color: var(--ai-text);
    cursor: pointer;
    transition: var(--ai-transition);
    white-space: nowrap;
    flex-shrink: 0;
}

.action-chip:hover {
    background: var(--ai-primary);
    color: white;
    border-color: var(--ai-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.chip-icon {
    font-size: 16px;
}

/* Messages Area - Takes full available space */
.ai-chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: transparent;
    min-height: 0; /* Important for flex-grow to work */
}

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

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

.ai-chat-container::-webkit-scrollbar-thumb:hover {
    background: var(--ai-text-light);
}

/* Message Bubbles */
.ai-message {
    display: flex;
    gap: 12px;
    animation: messageSlideIn 0.3s ease-out;
}

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

.ai-message-user {
    flex-direction: row-reverse;
}

.ai-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-primary), var(--ai-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.ai-message-user .ai-message-avatar {
    background: var(--ai-surface);
    color: var(--ai-text);
    border: 2px solid var(--ai-border);
}

.ai-message-content {
    max-width: 75%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-message-bubble {
    padding: 12px 16px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #1a202c;
    line-height: 1.6;
    word-wrap: break-word;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.ai-message-user .ai-message-bubble {
    background: linear-gradient(135deg,
        rgba(102, 126, 234, 0.8),
        rgba(118, 75, 162, 0.8));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.ai-message-time {
    font-size: 11px;
    color: var(--ai-text-light);
    padding: 0 16px;
}

/* Code Blocks */
.ai-message-bubble pre {
    margin: 12px 0;
    padding: 0;
    background: #2d3748;
    border-radius: var(--ai-radius-sm);
    overflow: hidden;
}

.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #1a202c;
    border-bottom: 1px solid #4a5568;
}

.code-language {
    font-size: 12px;
    color: #a0aec0;
    font-weight: 500;
    text-transform: uppercase;
}

.code-copy-btn {
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 12px;
    cursor: pointer;
    transition: var(--ai-transition);
}

.code-copy-btn:hover {
    background: var(--ai-primary);
}

.ai-message-bubble code {
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #e2e8f0;
    background: transparent;
    padding: 12px;
    display: block;
    overflow-x: auto;
}

/* Inline code */
.ai-message-bubble code:not(pre code) {
    display: inline;
    padding: 2px 6px;
    background: rgba(102, 126, 234, 0.1);
    color: var(--ai-primary);
    border-radius: 4px;
    font-size: 13px;
}

/* Typing Indicator */
.ai-typing-indicator {
    display: flex;
    gap: 12px;
    padding: 12px;
    align-items: center;
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--ai-surface);
    border-radius: var(--ai-radius-sm);
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ai-text-light);
    animation: typingBounce 1.4s infinite;
}

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

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

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Input Area - Glass */
.ai-input-container {
    padding: 16px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 0 0 20px 20px;
    flex-shrink: 0;
}

.ai-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.ai-input {
    flex: 1;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 24px;
    font-size: 14px;
    color: #1a202c;
    resize: none;
    transition: var(--ai-transition);
    font-family: inherit;
    line-height: 1.5;
}

.ai-input::placeholder {
    color: rgba(45, 55, 72, 0.6);
}

.ai-input:focus {
    outline: none;
    border-color: rgba(102, 126, 234, 0.6);
    background: rgba(255, 255, 255, 0.7);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15),
                0 0 0 1px rgba(255, 255, 255, 0.3) inset;
}

.ai-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-primary), var(--ai-secondary));
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--ai-transition);
    flex-shrink: 0;
}

.ai-send-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.ai-send-btn:active {
    transform: scale(0.95);
}

.ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Responsive */
@media (max-width: 480px) {
    .ai-tutor-widget {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
        max-width: none;
        max-height: none;
    }

    .quick-actions {
        padding: 8px;
    }

    .action-chip {
        padding: 6px 10px;
        font-size: 12px;
    }
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

.ai-tutor-widget {
    animation: slideUp 0.4s ease-out;
}

/* Markdown Styling */
.ai-message-bubble strong {
    font-weight: 600;
    color: var(--ai-text);
}

.ai-message-bubble em {
    font-style: italic;
}

.ai-message-bubble a {
    color: var(--ai-primary);
    text-decoration: underline;
}

.ai-message-bubble a:hover {
    color: var(--ai-primary-dark);
}

/* Lists */
.ai-message-bubble ul,
.ai-message-bubble ol {
    margin: 8px 0;
    padding-left: 24px;
}

.ai-message-bubble li {
    margin: 4px 0;
}

/* Welcome Message */
.ai-welcome-message {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
    border: 1px solid rgba(102, 126, 234, 0.2);
}
