:root {
    /* Google AI Studio Dark Theme Tokens (Approximate) */
    --md-sys-color-background: #131314;
    --md-sys-color-on-background: #E3E3E3;
    --md-sys-color-surface: #1E1F20;
    --md-sys-color-surface-container: #28292a;
    --md-sys-color-on-surface: #E3E3E3;
    --md-sys-color-on-surface-variant: #C4C7C5;
    --md-sys-color-primary: #A8C7FA;
    --md-sys-color-on-primary: #062E6F;
    --md-sys-color-primary-container: #0842A0;
    --md-sys-color-on-primary-container: #D3E3FD;
    --md-sys-color-outline: #8E918F;
    --md-sys-color-outline-variant: #444746;
    --md-sys-color-error-container: #93000A;
    --md-sys-color-on-error-container: #FFDAD6;

    --user-msg-bg: #28292a;
    --agent-msg-bg: transparent;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Google Sans', 'Roboto', sans-serif;
    background-color: #000000; /* 浏览器背景设为纯黑，突出中间的“窗口” */
    color: var(--md-sys-color-on-background);
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px; /* 给窗口四周留出边距 */
}

.container {
    width: 100%;
    max-width: 1200px; /* 限制最大宽度 */
    height: 100%;
    max-height: 900px; /* 限制最大高度，避免在超大屏幕上太高 */
    display: flex;
    flex-direction: column;
    background: var(--md-sys-color-background);
    border-radius: 24px; /* 窗口圆角 */
    border: 1px solid var(--md-sys-color-outline-variant);
    box-shadow: 0 0 40px rgba(0,0,0,0.5); /* 窗口阴影 */
    overflow: hidden; /* 保证子元素不溢出圆角 */
}

header {
    padding: 20px 32px;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--md-sys-color-background);
}

header h1 {
    font-family: 'Google Sans', sans-serif;
    font-size: 1.25rem;
    font-weight: 400;
    color: var(--md-sys-color-on-background);
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 模拟 Gemini 的星光图标 */
header h1::before {
    content: '✦';
    font-size: 1.5rem;
    background: linear-gradient(135deg, #4285f4, #d96570, #fbbc05);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 0.875rem;
    color: var(--md-sys-color-on-surface-variant);
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    padding: 8px 20px;
    background-color: transparent;
    color: var(--md-sys-color-primary);
    text-decoration: none;
    border-radius: 100px;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.2s;
    border: 1px solid var(--md-sys-color-outline-variant);
}

.nav-btn:hover {
    background-color: rgba(168, 199, 250, 0.08);
    border-color: var(--md-sys-color-primary);
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 32px 0;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.message {
    display: flex;
    gap: 20px;
    width: 100%;
    padding: 0 40px; /* 增加内部边距 */
    animation: fadeIn 0.2s ease-out;
}

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

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

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

.user-message .message-avatar {
    background-color: var(--md-sys-color-surface-container);
    color: var(--md-sys-color-on-surface-variant);
}

.agent-message .message-avatar {
    background: linear-gradient(135deg, #4285f4, #d96570, #fbbc05);
    background-size: 200% 200%;
    color: #fff;
    transition: all 0.3s ease;
}

.agent-message .message-avatar::before {
    content: '✦';
}

/* Gemini 生成状态动画 */
@keyframes gradient-spin {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes pulse-soft {
    0% { box-shadow: 0 0 0 0 rgba(66, 133, 244, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(66, 133, 244, 0); }
    100% { box-shadow: 0 0 0 0 rgba(66, 133, 244, 0); }
}

.agent-message.typing .message-avatar {
    animation: gradient-spin 3s ease infinite, pulse-soft 2s infinite;
}

.message-content {
    line-height: 1.6;
    font-size: 1rem;
    color: var(--md-sys-color-on-surface);
    max-width: 70%; /* 稍微收窄一点单条消息的宽度 */
    display: flex;
    flex-direction: column;
    gap: 16px; /* 块之间的间距 */
}

.user-message .message-content {
    background-color: var(--md-sys-color-surface-container);
    padding: 12px 24px;
    border-radius: 24px;
    border-top-right-radius: 4px;
    display: block; /* 用户消息通常只是简单文本块 */
}

.agent-message .message-content {
    padding-top: 6px;
}

.message-image {
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--md-sys-color-outline-variant);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    max-width: 100%;
    align-self: flex-start; /* 确保图片靠左对齐 */
}

.message-image img {
    width: 100%;
    height: auto;
    display: block;
}

.chat-input-container {
    padding: 24px 40px;
    background: var(--md-sys-color-background);
    display: flex;
    justify-content: center;
    border-top: 1px solid var(--md-sys-color-outline-variant);
}

.input-wrapper {
    width: 100%;
    position: relative;
    display: flex;
    align-items: flex-end;
    background-color: var(--md-sys-color-surface-container);
    border-radius: 32px;
    border: 1px solid var(--md-sys-color-outline-variant);
    transition: all 0.2s;
    padding: 8px 12px; /* 调整内边距 */
    gap: 8px;
}

.input-wrapper:focus-within {
    border-color: var(--md-sys-color-primary);
    background-color: var(--md-sys-color-surface-container);
    box-shadow: 0 0 0 2px rgba(168, 199, 250, 0.1);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.icon-btn:hover {
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface);
}

.input-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.image-preview-area {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    /* padding-bottom: 8px;  只有有图片时才需要 padding，JS 控制 */
}

.image-preview-item {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--md-sys-color-outline-variant);
}

.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-image-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
}

textarea {
    flex: 1;
    padding: 8px 0;
    border: none;
    background: transparent;
    font-size: 1rem;
    font-family: 'Roboto', sans-serif;
    resize: none;
    max-height: 150px;
    min-height: 24px;
    color: var(--md-sys-color-on-surface);
    line-height: 1.5;
}

textarea:focus {
    outline: none;
}

.send-btn {
    width: 48px;
    height: 48px;
    /* margin: 4px; */
    border-radius: 50%;
    background-color: var(--md-sys-color-on-surface);
    color: var(--md-sys-color-background);
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.send-btn:hover {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    transform: scale(1.05);
}

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

.send-btn:disabled {
    background-color: transparent;
    color: var(--md-sys-color-outline);
    cursor: not-allowed;
    transform: none;
}

.send-btn .btn-text { display: none; }
.send-btn::after {
    content: '➤';
    font-size: 1.1rem;
    margin-left: -2px;
}

@media (max-width: 768px) {
    body {
        padding: 0; /* 移动端占满全屏 */
    }
    .container {
        border-radius: 0;
        border: none;
        max-height: none;
    }
    .message {
        padding: 0 20px;
    }
    .message-content {
        max-width: 85%;
    }
    .chat-input-container {
        padding: 16px 20px;
    }
}

.error-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
    padding: 12px 24px;
    border-radius: 100px;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.error-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* --- Markdown 和容器样式 --- */

/* 文本块样式 */
.text-block {
    color: inherit;
    width: 100%;
}

.markdown-body p {
    margin-bottom: 16px;
}

.markdown-body p:last-child {
    margin-bottom: 0;
}

.markdown-body ul, .markdown-body ol {
    margin-bottom: 16px;
    padding-left: 24px;
}

.markdown-body li {
    margin-bottom: 8px;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}

.markdown-body h1:first-child, .markdown-body h2:first-child, .markdown-body h3:first-child {
    margin-top: 0;
}

.markdown-body pre {
    background-color: #1e1e1e;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 16px;
    border: 1px solid var(--md-sys-color-outline-variant);
}

.markdown-body code {
    font-family: 'Roboto Mono', monospace;
    background-color: rgba(255, 255, 255, 0.1);
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 0.9em;
}

.markdown-body pre code {
    background-color: transparent;
    padding: 0;
    font-size: 0.9em;
}

.markdown-body strong {
    font-weight: 700;
    color: var(--md-sys-color-primary-container);
    filter: brightness(1.5);
}

/* 内联省略号动画 */
.typing-indicator-inline {
    display: inline-flex;
    align-items: baseline;
    gap: 3px;
    margin-left: 4px;
    vertical-align: baseline;
}

.typing-indicator-inline span {
    width: 4px;
    height: 4px;
    background-color: var(--md-sys-color-on-surface);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
    opacity: 0.7;
}

.typing-indicator-inline span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator-inline span:nth-child(2) { animation-delay: -0.16s; }

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