/* css/ai-features.css */

/* AI Explanation Button - REMOVED from QuizEngine, its styles are now on sidebar buttons */
/*
.ai-explanation-btn{
    margin-top:12px;
    padding:10px 18px;
    background:linear-gradient(135deg,var(--primary-color),var(--secondary-color));
    color:#fff;
    border:none;
    border-radius:8px;
    cursor:pointer;
    font-size:.9rem;
    font-weight:600;
    transition:var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    min-height: 42px;
    position: relative;
    overflow: hidden;
    font-family: inherit;
}

.ai-explanation-btn:before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.ai-explanation-btn:hover:before {
    left: 100%;
}

.ai-explanation-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0,0,0,.15);
}

.ai-explanation-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}
.ai-explanation-btn:disabled:before {
    display: none;
}
*/

/* NEW: AI action button container for quiz/review interface */
.ai-action-btn-container {
    margin-top: 15px;
    display: flex;
    justify-content: flex-end; /* 按钮组靠右对齐 */
    align-items: center;      /* 垂直居中对齐按钮（如果高度不同） */
    gap: 10px;                /* 按钮之间的间距 */
    /* flex-direction: row; is the default for display: flex.
       Removed flex-direction: column; to ensure buttons are side-by-side. */
}

/* AI Explanation Box (content area) - RETAINED for AI content display */
.ai-explanation-box{
    margin-top:14px; /* Adjust if context changes */
    background:rgba(247,250,252,.7);
    backdrop-filter: blur(5px);
    padding:16px 18px;
    border:1px solid rgba(102, 126, 234, 0.15);
    border-left:4px solid var(--primary-color);
    border-radius:8px;
    font-size:.95em;
    line-height:1.6;
    color:var(--text-secondary);
    box-shadow:0 2px 10px rgba(0,0,0,0.05);
    box-sizing: border-box;
}

/* AI Streaming Related Styles - RETAINED */
.ai-streaming-container {
    min-height: 60px;
    margin-top: 10px;
}

.ai-thinking {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    justify-content: center;
}

.thinking-dots {
    display: flex;
    gap: 4px;
}

.thinking-dots .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: thinkingPulse 1.4s ease-in-out infinite both;
}

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

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

/* AI Content Area Styles (for streamed/rendered content) - RETAINED */
.ai-content {
    animation: fadeInContent 0.5s ease-out;
    line-height: 1.6;
    max-height: 400px;
    overflow-y: auto;
    padding: 8px 0;
    overflow-anchor: none;
    color: var(--text-primary);
}

/* Scrollbar styling for AI content (and other scrollable areas) - RETAINED */
.ai-content::-webkit-scrollbar {
    width: 6px;
}

.ai-content::-webkit-scrollbar-track {
    background: #f7fafc;
    border-radius: 3px;
}

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

/* Markdown Elements Styling - RETAINED, these will now apply to markdown rendered in AI chat messages */
/* These are common Markdown elements that AI responses will use */
.ai-content h1, .ai-content h2, .ai-content h3 {
    color: var(--text-primary);
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.4;
}

.ai-content h1 {
    font-size: 1.3rem;
    border-bottom: 3px solid var(--primary-color);
    padding-bottom: 6px;
}

.ai-content h2 {
    font-size: 1.1rem;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-content h3 {
    font-size: 1rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Add icons to headings based on text content (pseudo-elements) */
.ai-content h2:before {
    font-size: 1rem;
    margin-right: 0.2em;
}

.ai-content h2:has-text("正确答案"):before,
.ai-content h2:has-text("🎯"):before {
    content: "🎯";
}

.ai-content h2:has-text("错误选项"):before,
.ai-content h2:has-text("❌"):before {
    content: "❌";
}

.ai-content h2:has-text("知识拓展"):before,
.ai-content h2:has-text("💡"):before {
    content: "💡";
}

.ai-content h2:has-text("学习建议"):before,
.ai-content h2:has-text("📚"):before {
    content: "📚";
}

.ai-content p {
    margin: 8px 0;
    color: var(--text-secondary);
    text-align: justify;
}

.ai-content ul, .ai-content ol {
    margin: 8px 0 8px 20px;
    color: var(--text-secondary);
}

.ai-content li {
    margin: 4px 0;
    position: relative;
}

.ai-content ul li:before {
    content: "•";
    color: var(--primary-color);
    font-weight: bold;
    position: absolute;
    left: -15px;
}

.ai-content ol li {
    counter-increment: item;
    padding-left: 10px;
}

.ai-content ol li:before {
    content: counter(item) ".";
    color: var(--primary-color);
    font-weight: bold;
    position: absolute;
    left: -20px;
}

/* Code Styling */
.ai-content code {
    background: rgba(102, 126, 234, 0.1);
    color: var(--primary-color);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
    border: 1px solid rgba(102, 126, 234, 0.2);
}

.ai-content pre {
    background: #f8fafc;
    padding: 12px;
    border-radius: 6px;
    border-left: 4px solid var(--primary-color);
    overflow-x: auto;
    margin: 12px 0;
    position: relative;
    box-sizing: border-box;
}

.ai-content pre code {
    background: none;
    border: none;
    padding: 0;
    color: inherit;
    font-size: 1em;
}

/* Emphasis Styling */
.ai-content strong {
    color: var(--text-primary);
    font-weight: 600;
}

.ai-content em {
    color: var(--primary-color);
    font-style: italic;
}

.ai-content strong em,
.ai-content em strong {
    color: var(--secondary-color);
    font-weight: 600;
    font-style: italic;
}

/* Link Styling */
.ai-content a {
    color: var(--primary-color);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: var(--transition);
}

.ai-content a:hover {
    border-bottom-color: var(--primary-color);
    color: var(--primary-hover);
}

/* Blockquote Styling */
.ai-content blockquote {
    border-left: 4px solid var(--accent-color);
    margin: 12px 0;
    padding: 8px 16px;
    background: rgba(240, 147, 251, 0.05);
    border-radius: 0 6px 6px 0;
    font-style: italic;
    color: var(--text-secondary);
    box-sizing: border-box;
}

/* Table Styling (if needed) */
.ai-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.9rem;
}

.ai-content th,
.ai-content td {
    border: 1px solid var(--border-color-light);
    padding: 8px 12px;
    text-align: left;
}

.ai-content th {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
}

.ai-content tr:nth-child(even) {
    background: #f8fafc;
}

/* Error State Styling - RETAINED */
.ai-error {
    color: var(--error-color);
    background: rgba(229, 62, 62, 0.1);
    padding: 12px;
    border-radius: 6px;
    border-left: 4px solid var(--error-color);
    margin: 10px 0;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    box-sizing: border-box;
}

.ai-error:before {
    content: "⚠️";
    flex-shrink: 0;
}

/* Loading state for AI explanation button - REMOVED (button moved) */
/*
.ai-explanation-btn.loading {
    background: linear-gradient(135deg, #6c7293, #8e92b8);
    cursor: wait;
}

.ai-explanation-btn.loading:after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 8px;
}
*/

/* AI Hint feature - REMOVED (button moved) */
/*
.ai-hint-wrapper { margin: 18px 0; }
.ai-hint-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    color: #fff; border: none; padding: 8px 14px;
    border-radius: 6px; font-size: .9rem; cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}
.ai-hint-btn:hover { transform: translateY(-1px); }
.ai-hint-content {
    margin-top: 10px;
    color: var(--text-secondary);
    line-height: 1.6;
    background: #f8fafc;
    padding: 12px 15px;
    border-radius: 6px;
    border-left: 4px solid var(--accent-color);
    box-shadow: 0 1px 5px rgba(0,0,0,0.05);
    box-sizing: border-box;
}
.ai-hint-content.loading { opacity: .6; font-style: italic; }

.ai-hint-content{
  white-space:pre-wrap;
  word-break:break-all;
  overflow-wrap:anywhere;
  max-height:400px;
  overflow-y:auto;
}
*/

/* Responsive adjustments for AI content display */
@media (max-width: 768px) {
    .ai-content {
        max-height: 300px;
        font-size: 0.9rem;
    }
    .ai-content h1 { font-size: 1.2rem; }
    .ai-content h2 { font-size: 1rem; }
    .ai-content h3 { font-size: 0.95rem; }
    .ai-thinking { padding: 15px 0; }
    .ai-content ul, .ai-content ol {
        margin-left: 16px;
    }
}

@media (max-width: 480px) {
    .ai-content {
        max-height: 250px;
        padding: 6px 0;
    }
    .ai-content h1, .ai-content h2, .ai-content h3 { margin: 12px 0 6px 0; }
    .ai-content p { margin: 6px 0; }
    .ai-content ul, .ai-content ol { margin-left: 15px; }
    .ai-content code { font-size: 0.8em; }
    .ai-content pre { padding: 0.7em; }
    .ai-content table { font-size: 0.75em; }
}