/* AI画图页面样式 - Enhanced */

:root {
    --primary-color: #4285f4;
    --primary-hover: #3367d6;
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --text-primary: #202124;
    --text-secondary: #5f6368;
    --border-color: #dadce0;
    --user-msg-bg: #e8f0fe;
    --user-msg-text: #174ea6;
    --ai-msg-bg: #f1f3f4;
    --ai-msg-text: #202124;
    --shadow-sm: 0 1px 2px 0 rgba(60,64,67,0.3), 0 1px 3px 1px rgba(60,64,67,0.15);
    --shadow-md: 0 4px 6px rgba(50,50,93,0.11), 0 1px 3px rgba(0,0,0,0.08);
}

.ai-plotter-wrapper {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px); /* Adjust based on actual header height */
    padding: 16px;
    gap: 16px;
    background: var(--bg-color);
    font-family: 'Google Sans', Roboto, Arial, sans-serif;
    box-sizing: border-box;
}

/* Tab 导航 */
.ai-tab-navigation {
    display: flex;
    gap: 12px;
    padding: 4px;
    background: rgba(255,255,255,0.5);
    border-radius: 24px;
    align-items: center;
    backdrop-filter: blur(5px);
}

.ai-tab-btn {
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 500;
    background: white;
    border: 1px solid transparent;
    border-radius: 20px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.ai-tab-btn:hover {
    background: #fff;
    color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.ai-tab-btn.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 6px rgba(66, 133, 244, 0.3);
}

.ai-tab-navigation a {
    margin-left: auto;
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-secondary);
    text-decoration: none;
    background: white;
    border-radius: 20px;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.ai-tab-navigation a:hover {
    background: white;
    color: var(--primary-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Tab 内容区域 */
.ai-tab-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent outer scroll */
    position: relative;
    border-radius: 12px;
}

.ai-tab-section {
    display: none;
    flex: 1;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.ai-tab-section.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

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

/* 主布局 */
.ai-main-layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 16px;
    height: 100%;
    overflow: hidden; /* Important */
}

.ai-left-panel, .ai-right-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    height: 100%;
    overflow: hidden; /* Important */
    min-height: 0;
}

.ai-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(0,0,0,0.02);
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.3s ease;
}

.ai-card:hover {
    box-shadow: var(--shadow-md);
}

.ai-card h3 {
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

/* 聊天区域 */
#chatMessages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #ffffff;
    border-radius: 12px;
    min-height: 0; /* Crucial for scrolling */
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 16px;
    border: 1px solid #f1f3f4;
    scroll-behavior: smooth;
}

/* 滚动条样式 */
#chatMessages::-webkit-scrollbar {
    width: 6px;
}
#chatMessages::-webkit-scrollbar-track {
    background: transparent;
}
#chatMessages::-webkit-scrollbar-thumb {
    background-color: #dadce0;
    border-radius: 3px;
}
#chatMessages::-webkit-scrollbar-thumb:hover {
    background-color: #bdc1c6;
}

.chat-message {
    margin-bottom: 16px;
    padding: 0;
    font-size: 14px;
    max-width: 90%;
    position: relative;
    word-wrap: break-word;
    display: flex;
    flex-direction: column;
    animation: messageIn 0.3s ease;
}

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

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    line-height: 1.5;
}

.user-message {
    align-self: flex-end;
    margin-left: auto;
}

.user-message .message-content {
    background: var(--user-msg-bg);
    color: var(--user-msg-text);
    border-bottom-right-radius: 4px;
}

.ai-message {
    align-self: flex-start;
    margin-right: auto;
}

.ai-message .message-content {
    background: var(--ai-msg-bg);
    color: var(--ai-msg-text);
    border-bottom-left-radius: 4px;
}

.ai-chat-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: #f8f9fa;
    padding: 10px;
    border-radius: 24px;
    border: 1px solid var(--border-color);
    flex-shrink: 0; /* Prevent shrinking */
    transition: all 0.2s;
}

.ai-chat-input-wrapper:focus-within {
    background: white;
    border-color: var(--primary-color);
    box-shadow: 0 1px 4px rgba(66, 133, 244, 0.2);
}

#chatInput {
    flex: 1;
    padding: 8px 0;
    border: none;
    background: transparent;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    outline: none;
    color: var(--text-primary);
}

.ai-attachment-btn, .ai-btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.ai-attachment-btn:hover {
    background: rgba(0,0,0,0.05);
    color: var(--text-primary);
}

.ai-btn-primary {
    background: var(--primary-color);
    color: white;
    padding: 8px;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.ai-btn-primary:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.ai-btn-primary svg {
    width: 18px;
    height: 18px;
    margin-left: -2px; /* Visual adjustment for send icon */
}

/* 绘图区域优化 */
.ai-plot-container {
    flex: 1;
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
    border: 1px solid #eee;
    position: relative;
    min-height: 0;
}

.ai-plot-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #9aa0a6;
}

.ai-plot-placeholder p {
    margin: 8px 0;
}

/* 输入表单样式优化 */
.ai-form-group {
    margin-bottom: 16px;
}

.ai-form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.ai-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.2s;
    box-sizing: border-box;
}

.ai-input:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.1);
}

.ai-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-btn-group {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.ai-btn-full {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.ai-btn-secondary {
    background: #f1f3f4;
    color: var(--text-primary);
}

.ai-btn-secondary:hover {
    background: #e8eaed;
}

/* 示例 Grid 优化 */
.ai-example-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    overflow-y: auto;
    padding: 4px;
}

.ai-example-item {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-example-item:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(66, 133, 244, 0.15);
    transform: translateY(-2px);
}

.ai-example-expr {
    font-family: 'Roboto Mono', monospace;
    font-size: 15px;
    font-weight: 500;
    color: var(--primary-color);
}

.ai-example-desc {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Enhanced Example Library Styles */
.ai-example-category-section {
    margin-bottom: 24px;
    background: #fff;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.ai-category-title {
    font-size: 18px;
    color: var(--primary-color);
    margin: 0 0 16px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid #e8f0fe;
    font-weight: 600;
}

.ai-subcategory-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.ai-subcategory-group {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 12px;
}

.ai-subcategory-title {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0 0 12px 0;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
}

.ai-subcategory-title::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 14px;
    background: var(--primary-color);
    margin-right: 8px;
    border-radius: 2px;
    opacity: 0.6;
}

/* Override existing grid for better density in library view */
.ai-example-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}

.ai-example-item {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 40px;
}

.ai-example-item:hover {
    border-color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(66, 133, 244, 0.15);
    transform: translateY(-1px);
    background: #f8fbff;
}

.ai-example-expr {
    font-family: 'Roboto Mono', monospace;
    font-size: 13px;
    font-weight: 500;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .ai-main-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }
    
    .ai-left-panel {
        order: 2; /* Put chat below plot on mobile? Or maybe Tabs handle this */
    }
}

/* Loading 动画样式 */
.loading-message .message-content {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    min-width: 60px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: #5f6368;
    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;
}

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

.loading-text {
    font-size: 13px;
    color: #5f6368;
    margin-left: 8px;
    font-style: italic;
    animation: fadeIn 0.5s ease;
}
