/* AI Chat Container Styles */
.ai-chat-container {
    background-color: #f5f7fa;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    margin: 20px 0;
    overflow: hidden;
    position: relative;
    display: none; /* Hidden by default, shown when AI evaluation is available */
    transition: all 0.3s ease;
    /* Ensure chat container has its own stacking context */
    z-index: 100;
    /* Maximum width to prevent stretching on large screens */
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}

.ai-chat-header {
    background: linear-gradient(135deg, #2c3e50, #34495e);
    color: white;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
    display: flex;
    align-items: center;
}

.ai-chat-header h3 i {
    margin-right: 8px;
    font-size: 18px;
}

.ai-chat-toggle {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 20px;
    transition: transform 0.3s ease;
}

.ai-chat-toggle:focus {
    outline: none;
}

.ai-chat-toggle.collapsed {
    transform: rotate(180deg);
}

/* Chat Messages Area */
.ai-chat-messages {
    max-height: 700px;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scrollbar-width: thin;
    scrollbar-color: #c1c9d2 transparent;
    /* Ensure scrolling only affects this container */
    overflow-anchor: none;
    /* Subtle background pattern */
    background-image: linear-gradient(rgba(255, 255, 255, 0.8) 1px, transparent 1px),
                      linear-gradient(90deg, rgba(255, 255, 255, 0.8) 1px, transparent 1px);
    background-size: 20px 20px;
    background-color: #f5f7fa;
}

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

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

.ai-chat-messages::-webkit-scrollbar-thumb {
    background-color: #c1c9d2;
    border-radius: 6px;
}

/* Message Bubbles */
.message {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 18px;
    line-height: 1.2;
    position: relative;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin-bottom: 2px;
}

.message.user {
    background-color: #e3f2fd;
    border: 1px solid #bbdefb;
    color: #1565c0;
    align-self: flex-end;
    border-bottom-right-radius: 5px;
}

.message.ai {
    background-color: white;
    border: 1px solid #e0e0e0;
    color: #424242;
    align-self: flex-start;
    border-bottom-left-radius: 5px;
}

/* Markdown formatting styles for AI messages */
.message.ai ul {
    margin: 3px 0 3px 15px;
    padding-left: 0;
}

.message.ai li {
    margin-bottom: 2px;
    line-height: 1.2;
}

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

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

.message .timestamp {
    font-size: 10px;
    color: #9e9e9e;
    margin-top: 3px;
    text-align: right;
    display: block;
}

/* Input Area */
.ai-chat-input {
    display: flex;
    align-items: flex-end;
    padding: 15px;
    border-top: 1px solid #e0e0e0;
    background-color: white;
    /* Fix: Remove fixed padding-right that was causing overflow issues */
    position: relative;
    width: 100%;
    box-sizing: border-box;
}

.ai-chat-input .textarea-container {
    position: relative;
    flex: 1;
    /* Fix: Remove fixed padding that was constraining the input */
    box-sizing: border-box;
    /* Fix: Add margin to provide space for the send button */
    margin-right: 50px;
    width: calc(100% - 50px);
}

.ai-chat-input textarea {
    width: 100%;
    min-height: 20px;
    max-height: 150px;
    padding: 10px 15px;
    /* Fix: Adjust padding to ensure text doesn't overflow */
    padding-right: 30px;
    border: 1px solid #cfd8dc;
    border-radius: 24px;
    resize: none;
    font-size: 14px;
    line-height: 1.3;
    outline: none;
    transition: border 0.3s ease;
    overflow-y: auto;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: #c1c9d2 transparent;
}

.ai-chat-input textarea:focus {
    border-color: #90a4ae;
}

.ai-chat-input textarea::-webkit-scrollbar {
    width: 4px;
}

.ai-chat-input textarea::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-input textarea::-webkit-scrollbar-thumb {
    background-color: #c1c9d2;
    border-radius: 4px;
}

.chat-char-counter {
    position: absolute;
    right: 10px;
    bottom: 10px;
    font-size: 11px;
    color: #9e9e9e;
    z-index: 5;
}

.ai-chat-send {
    background-color: #2c3e50;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.3s ease;
    /* Fix: Use absolute positioning to ensure it doesn't affect layout flow */
    position: absolute;
    right: 15px;
    bottom: 15px;
    z-index: 10;
}

.ai-chat-send:hover {
    background-color: #1a2533;
}

.ai-chat-send:disabled {
    background-color: #b0bec5;
    cursor: not-allowed;
}

.ai-chat-send i {
    font-size: 18px;
}

/* Loading animation */
.ai-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background-color: #f5f5f5;
    border-radius: 18px;
    align-self: flex-start;
    margin-top: 3px;
    width: fit-content;
}

.ai-typing-dot {
    width: 6px;
    height: 6px;
    background-color: #9e9e9e;
    border-radius: 50%;
    animation: typing-animation 1.4s infinite ease-in-out both;
}

.ai-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

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

@keyframes typing-animation {
    0%, 80%, 100% { 
        transform: scale(0);
    }
    40% { 
        transform: scale(1.0);
    }
}

/* Premium notice */
.ai-chat-premium-notice {
    background-color: #fff3cd;
    border: 1px solid #ffeeba;
    padding: 10px;
    margin: 10px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #856404;
    font-size: 13px;
}

.ai-chat-premium-notice i {
    font-size: 18px;
}

/* Chat message status */
.message-status {
    font-size: 11px;
    color: #9e9e9e;
    margin-top: 5px;
    text-align: right;
    height: 11px;
}

.message-error {
    color: #d32f2f;
}

/* Retry button */
.retry-button {
    background-color: #e3f2fd;
    border: 1px solid #bbdefb;
    color: #1565c0;
    padding: 6px 12px;
    border-radius: 18px;
    cursor: pointer;
    font-size: 13px;
    margin-top: 6px;
    align-self: center;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.retry-button:hover {
    background-color: #bbdefb;
    transform: translateY(-1px);
}

.retry-button:active {
    transform: translateY(1px);
}

.message-error {
    color: #d32f2f;
    font-size: 13px;
    padding: 6px 12px;
    background-color: #ffebee;
    border-radius: 18px;
    align-self: center;
    margin-top: 6px;
    border: 1px solid #ffcdd2;
}

/* Responsive design */
@media (max-width: 768px) {
    .message {
        max-width: 90%;
    }
    
    .ai-chat-input {
        flex-direction: column;
        gap: 10px;
    }
    
    .ai-chat-send {
        align-self: flex-end;
    }
}

/* Empty state */
.ai-chat-empty {
    text-align: center;
    padding: 30px 20px;
    color: #78909c;
}

.ai-chat-empty i {
    font-size: 40px;
    margin-bottom: 15px;
    opacity: 0.7;
}

.ai-chat-empty p {
    margin: 10px 0 0;
}

/* Initial welcome message */
.welcome-message {
    padding: 10px;
    text-align: center;
    background-color: #e8f5e9;
    margin: 10px;
    border-radius: 8px;
    border-left: 4px solid #4caf50;
    font-size: 13px;
    line-height: 1.3;
}

.welcome-message p {
    margin: 0;
    line-height: 1.3;
    margin-bottom: 5px;
}

.welcome-message p:last-child {
    margin-bottom: 0;
}

.welcome-message strong {
    color: #2e7d32;
}

/* AI Intelligence Center - Main Container */
.ai-intelligence-center {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 15px;
    overflow: hidden;
    position: relative;
    transition: all 0.3s ease;
    z-index: 100;
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #e0e0e0;
}

/* Header Styling */
.intelligence-center-header {
    background: linear-gradient(135deg, var(--gradient-start) 0%, var(--gradient-end) 100%);
    color: white;
    padding: 12px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.intelligence-center-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    display: flex;
    align-items: center;
}

.intelligence-center-header h3 i {
    margin-right: 10px;
    font-size: 18px;
    color: #fff;
}

/* Tab buttons */
.intelligence-center-tabs {
    display: flex;
    gap: 10px;
}

.intelligence-center-tabs .tab-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

.intelligence-center-tabs .tab-btn i {
    margin-right: 6px;
    font-size: 14px;
}

.intelligence-center-tabs .tab-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.intelligence-center-tabs .tab-btn.active {
    background: rgba(255, 255, 255, 0.3);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Tab Content */
.intelligence-center-content {
    min-height: 300px;
    position: relative;
    padding: 12px;
    background-color: white;
}

/* Tab Panels */
.ai-tab-panel {
    display: none;
    padding: 0;
    background-color: white;
    border-radius: 4px;
}

.ai-tab-panel.active {
    display: block;
}

/* AI Disabled Message */
.ai-feature-disabled-message {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: #6c757d;
    background-color: rgba(240, 242, 245, 0.8);
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    backdrop-filter: blur(2px);
}

.ai-feature-disabled-message i {
    font-size: 36px;
    margin-bottom: 15px;
    color: #adb5bd;
}

.ai-feature-disabled-message p {
    font-size: 16px;
    max-width: 280px;
    line-height: 1.5;
}

/* AI Chat Container Styles - Updated */
.ai-chat-container {
    background-color: white;
    overflow: hidden;
    position: relative;
    transition: all 0.3s ease;
    height: 100%;
    display: flex;
    flex-direction: column;
    border-radius: 4px;
}

/* Chat Messages Area - Updated */
.ai-chat-messages {
    max-height: 500px;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scrollbar-width: thin;
    scrollbar-color: #c1c9d2 transparent;
    overflow-anchor: none;
    background-image: linear-gradient(rgba(255, 255, 255, 0.8) 1px, transparent 1px),
                      linear-gradient(90deg, rgba(255, 255, 255, 0.8) 1px, transparent 1px);
    background-size: 20px 20px;
    background-color: #f8fafc;
    flex: 1;
}

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

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

.ai-chat-messages::-webkit-scrollbar-thumb {
    background-color: #c1c9d2;
    border-radius: 3px;
}

/* Chat Input Area - Updated styling */
.ai-chat-input {
    display: flex;
    padding: 15px;
    background-color: #fff;
    border-top: 1px solid #eaedf0;
    gap: 10px;
    align-items: flex-end;
}

.ai-chat-input .textarea-container {
    flex: 1;
    position: relative;
}

.ai-chat-input textarea {
    width: 100%;
    resize: none;
    border: 1px solid #dce3ed;
    border-radius: 8px;
    padding: 12px 15px;
    padding-right: 40px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    overflow-y: auto;
    min-height: 40px;
    max-height: 120px;
    transition: border-color 0.2s;
}

.ai-chat-input textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.chat-char-counter {
    position: absolute;
    right: 10px;
    bottom: 10px;
    font-size: 11px;
    color: #9e9e9e;
}

.ai-chat-send {
    background-color: #1e3c72;
    color: white;
    border: none;
    height: 40px;
    width: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ai-chat-send:hover {
    background-color: #2a5298;
    transform: translateY(-2px);
}

.ai-chat-send:disabled {
    background-color: #ccd4e0;
    cursor: not-allowed;
    transform: none;
}

.ai-chat-send i {
    font-size: 16px;
}

/* Message Styles - Keep existing but update styling */
.message {
    padding: 12px 15px;
    border-radius: 10px;
    max-width: 85%;
    position: relative;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    margin-bottom: 5px;
}

.message.user {
    background-color: #e3eefa;
    color: #2c3e50;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.message.ai {
    background-color: white;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.timestamp {
    font-size: 10px;
    color: #94a3b8;
    position: absolute;
    right: 8px;
    bottom: 4px;
}

.message-error {
    background-color: #fee2e2;
    color: #b91c1c;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin: 10px 0;
    text-align: center;
}

.retry-button {
    background-color: #e5e7eb;
    border: none;
    color: #4b5563;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    margin: 5px auto;
    display: block;
    transition: background-color 0.2s;
}

.retry-button:hover {
    background-color: #d1d5db;
}

/* AI Typing Indicator */
.ai-typing {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px;
    background-color: white;
    border-radius: 10px;
    align-self: flex-start;
    margin: 5px 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.ai-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #3498db;
    opacity: 0.7;
    animation: typing-animation 1.4s infinite ease-in-out both;
}

.ai-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

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

@keyframes typing-animation {
    0%, 80%, 100% { 
        transform: scale(0.6);
    }
    40% { 
        transform: scale(1);
    }
}

/* Welcome message styling */
.welcome-message {
    background-color: #f8f9fa;
    border-left: 3px solid #3498db;
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 15px;
}

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

.welcome-message p:first-child {
    margin-top: 0;
}

.welcome-message p:last-child {
    margin-bottom: 0;
}

/* AI Chat Premium Notice */
.ai-chat-premium-notice {
    display: flex;
    align-items: center;
    gap: 12px;
    background-color: #f8f9fa;
    border-left: 3px solid #f59e0b;
    padding: 15px;
    border-radius: 5px;
    margin: 10px 0;
}

.ai-chat-premium-notice i {
    font-size: 18px;
    color: #f59e0b;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .intelligence-center-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .intelligence-center-tabs {
        width: 100%;
    }
    
    .intelligence-center-tabs .tab-btn {
        flex: 1;
        justify-content: center;
    }
    
    .intelligence-center-content {
        padding: 10px;
    }
}

@media (max-width: 480px) {
    .intelligence-center-header {
        padding: 10px;
    }
    
    .intelligence-center-content {
        padding: 8px;
    }
}

/* Experience Level Selector */
.ai-experience-selector {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background-color: #edf2f7;
    border-bottom: 1px solid #e2e8f0;
}

.ai-experience-selector label {
    font-weight: 500;
    margin-right: 10px;
    font-size: 14px;
    color: #4a5568;
    white-space: nowrap;
}

.ai-experience-selector select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    background-color: white;
    font-size: 14px;
    color: #2d3748;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    max-width: 400px;
}

.ai-experience-selector select:hover {
    border-color: #a0aec0;
}

.ai-experience-selector select:focus {
    border-color: #4299e1;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.3);
}

/* System messages for level changes */
.system-message {
    background-color: #e6f7ff;
    border-left: 3px solid #1890ff;
    color: #0050b3;
    padding: 8px 12px;
    border-radius: 6px;
    margin: 8px 0;
    font-size: 13px;
    text-align: center;
    align-self: center;
}

/* Responsive adjustments for experience selector */
@media (max-width: 640px) {
    .ai-experience-selector {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .ai-experience-selector select {
        width: 100%;
        max-width: none;
    }
}

/* 數學公式樣式 */
.math-block {
    display: block;
    margin: 10px 0;
    padding: 8px;
    background-color: rgba(240, 240, 240, 0.5);
    border-radius: 4px;
    font-family: 'Cambria Math', 'Times New Roman', serif;
    overflow-x: auto;
    text-align: center;
}

.math-inline {
    font-family: 'Cambria Math', 'Times New Roman', serif;
    padding: 0 2px;
}

/* 代碼塊樣式 */
.message pre {
    background-color: #f8f9fa;
    border-radius: 4px;
    padding: 10px;
    margin: 10px 0;
    overflow-x: auto;
}

.message code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
    background-color: rgba(0, 0, 0, 0.05);
    padding: 2px 4px;
    border-radius: 3px;
}

.message pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    display: block;
}

/* 優化 AI 訊息格式 */
.message.ai {
    padding: 12px 15px;
    line-height: 1.5;
}

.message.ai p {
    margin: 0 0 10px 0;
}

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

.message.ai h1, .message.ai h2, .message.ai h3 {
    margin: 15px 0 10px 0;
    color: #2c3e50;
    font-weight: 600;
}

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

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

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

.message.ai ul, .message.ai ol {
    margin: 10px 0 10px 20px;
    padding: 0;
}

.message.ai li {
    margin-bottom: 5px;
    line-height: 1.4;
}

.message.ai ul li {
    list-style-type: disc;
}

.message.ai ol li {
    list-style-type: decimal;
} 