@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap');

/* 全局box-sizing设置，防止元素超出容器 */
*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    --bg-color: #f7f8fa;
    --chat-container-bg: #ffffff;
    --ai-message-bg: #f0f4f8;
    --user-message-bg: #e1eefe;
    --primary-text-color: #333;
    --secondary-text-color: #666;
    --accent-color: #4a80ff;
    --border-color: #e0e0e0;
    --shadow-color: rgba(0, 0, 0, 0.05);
    --font-family: 'Noto Sans SC', sans-serif;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --chat-container-bg: #2d2d2d;
    --ai-message-bg: #3a3a3a;
    --user-message-bg: #4a80ff;
    --primary-text-color: #ffffff;
    --secondary-text-color: #cccccc;
    --accent-color: #5a90ff;
    --border-color: #404040;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --success-color: #34d399;
    --error-color: #f87171;
    --warning-color: #fbbf24;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    color: var(--primary-text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    /* 移动端触摸优化 */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

/* 所有按钮和可点击元素的全局优化 */
button, a, [role="button"], input[type="submit"], input[type="button"] {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

.chat-container {
    width: 90%;
    max-width: 800px;
    height: 90vh;
    background-color: var(--chat-container-bg);
    border-radius: 16px;
    box-shadow: 0 8px 24px var(--shadow-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.chat-messages {
    flex-grow: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 95%; /* 最大化横向空间 */
    width: 100%;
}

.message-wrapper {
    display: flex;
    align-items: flex-start;
    width: 100%;
}

.message .bubble-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    opacity: 1; /* 常态显示，适配移动端 */
}

.user-message .bubble-actions {
    align-self: flex-end;
}

.bubble-action-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    color: var(--secondary-text-color);
    transition: all 0.2s;
    /* 移动端触摸优化 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 40px;
}

.bubble-action-btn:hover {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.bubble-action-btn:active {
    transform: scale(0.95);
    background-color: #2a5dc9;
}

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

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

.message .text {
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.6;
    width: 100%; /* 横向最大化 */
    box-sizing: border-box;
}

.ai-message .text {
    background-color: var(--ai-message-bg);
    border-top-left-radius: 0;
}

.user-message .text {
    background-color: var(--user-message-bg);
    color: #333;
    border-top-right-radius: 0;
}

[data-theme="dark"] .user-message .text {
    color: #ffffff;
}

/* Markdown 渲染样式优化 */
.message .text h1,
.message .text h2,
.message .text h3,
.message .text h4,
.message .text h5,
.message .text h6 {
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.4;
    color: var(--primary-text-color);
}

.message .text h1 { font-size: 1.8em; border-bottom: 2px solid var(--border-color); padding-bottom: 8px; }
.message .text h2 { font-size: 1.5em; border-bottom: 1px solid var(--border-color); padding-bottom: 6px; }
.message .text h3 { font-size: 1.3em; }
.message .text h4 { font-size: 1.1em; }
.message .text h5 { font-size: 1em; }
.message .text h6 { font-size: 0.9em; color: var(--secondary-text-color); }

.message .text p {
    margin: 8px 0;
    line-height: 1.6;
}

.message .text ul,
.message .text ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message .text li {
    margin: 4px 0;
    line-height: 1.6;
}

.message .text blockquote {
    margin: 12px 0;
    padding: 8px 16px;
    border-left: 4px solid var(--accent-color);
    background-color: rgba(74, 128, 255, 0.05);
    color: var(--secondary-text-color);
    font-style: italic;
}

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

[data-theme="dark"] .message .text code {
    background-color: rgba(255, 255, 255, 0.1);
    color: #ff79c6;
}

/* 代码块容器 */
.code-block-wrapper {
    margin: 12px 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background-color: #f6f8fa;
}

[data-theme="dark"] .code-block-wrapper {
    background-color: #2d2d2d;
    border-color: #444;
}

/* 代码块头部 */
.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background-color: #e8eaed;
    border-bottom: 1px solid var(--border-color);
}

[data-theme="dark"] .code-block-header {
    background-color: #1e1e1e;
    border-bottom-color: #444;
}

.code-lang {
    font-size: 12px;
    font-weight: 600;
    color: var(--secondary-text-color);
    text-transform: uppercase;
}

.code-copy-btn {
    padding: 4px 10px;
    font-size: 12px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.code-copy-btn:hover {
    background: #3a6dd9;
    transform: translateY(-1px);
}

.code-copy-btn:active {
    transform: translateY(0);
}

/* 代码块本体 */
.message .text pre {
    margin: 0;
    padding: 12px;
    background-color: transparent;
    border-radius: 0;
    overflow-x: auto;
    border: none;
}

.message .text pre code {
    background: none;
    padding: 0;
    color: var(--primary-text-color);
    font-size: 13px;
    line-height: 1.6;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

/* 对话中的图片网格 */
.chat-images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    margin: 10px 0;
}

.chat-image {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: transform 0.2s;
}

.chat-image:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.image-caption {
    font-size: 12px;
    color: var(--secondary-text-color);
    margin: 5px 0 0 0;
}

/* AI回复中的图片 */
.content-image {
    max-width: 100%;
    border-radius: 8px;
    margin: 10px 0;
    cursor: pointer;
    transition: transform 0.2s;
    border: 1px solid var(--border-color);
}

.content-image:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.message .text table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
    font-size: 0.9em;
}

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

.message .text table th {
    background-color: var(--ai-message-bg);
    font-weight: 600;
}

.message .text table tr:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] .message .text table tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.02);
}

.message .text hr {
    border: none;
    border-top: 2px solid var(--border-color);
    margin: 16px 0;
}

.message .text a {
    color: var(--accent-color);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

.message .text a:hover {
    border-bottom-color: var(--accent-color);
}

.message .text img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 12px 0;
}

.message .text strong {
    font-weight: 600;
    color: var(--primary-text-color);
}

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

.message .text del {
    text-decoration: line-through;
    opacity: 0.7;
}

/* 任务列表样式 */
.message .text input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
}

/* 快速帮助面板 */
.quick-help {
    margin: 16px 0;
    border: 2px solid var(--accent-color);
    border-radius: 8px;
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(74, 128, 255, 0.05), rgba(74, 128, 255, 0.1));
}

.quick-help summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.2s;
    user-select: none;
    color: var(--accent-color);
}

.quick-help summary:hover {
    background-color: rgba(74, 128, 255, 0.1);
}

.quick-help[open] summary {
    margin-bottom: 12px;
    border-bottom: 1px solid var(--accent-color);
}

.help-content {
    padding: 8px;
    font-size: 13px;
    line-height: 1.6;
}

.help-content h4 {
    margin: 12px 0 8px 0;
    font-size: 14px;
    color: var(--primary-text-color);
}

.help-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.help-content li {
    margin: 6px 0;
    color: var(--primary-text-color);
}

.help-content strong {
    color: var(--accent-color);
    font-weight: 600;
}

.help-link {
    display: inline-block;
    padding: 8px 16px;
    background-color: var(--accent-color);
    color: white !important;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 13px;
    transition: all 0.2s;
    text-align: center;
    flex: 1;
    min-width: 120px;
}

.help-link:hover {
    background-color: #3a6dd9;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(74, 128, 255, 0.3);
}

/* 高级设置折叠面板 */
.advanced-settings {
    margin: 16px 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    background-color: var(--ai-message-bg);
}

.advanced-settings summary {
    cursor: pointer;
    font-weight: 600;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.2s;
    user-select: none;
}

.advanced-settings summary:hover {
    background-color: rgba(74, 128, 255, 0.1);
}

.advanced-settings[open] summary {
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.advanced-settings input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    outline: none;
}

.advanced-settings input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
}

.advanced-settings input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    border: none;
}

.chat-input-container {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background-color: var(--chat-container-bg);
}

.input-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.api-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--secondary-text-color);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    /* 移动端触摸优化 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}

.api-status:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.api-status:active {
    transform: scale(0.98);
    background-color: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .api-status:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .api-status:active {
    background-color: rgba(255, 255, 255, 0.15);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--error-color);
    transition: background-color 0.3s ease;
}

.status-indicator.connected {
    background-color: var(--success-color);
}

.status-indicator.configuring {
    background-color: var(--warning-color);
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.action-btn {
    background: none;
    border: 1px solid var(--border-color);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    color: var(--secondary-text-color);
    transition: all 0.2s;
    /* 移动端触摸优化 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.action-btn:hover {
    background-color: #f0f0f0;
    color: var(--accent-color);
}

.action-btn:active {
    transform: scale(0.95);
    background-color: var(--accent-color);
    color: white;
}

.input-box {
    display: flex;
    align-items: center;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 4px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-box:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(74, 128, 255, 0.2);
}

#chat-input {
    flex-grow: 1;
    border: none;
    outline: none;
    padding: 12px;
    background-color: transparent;
    font-size: 16px;
    resize: none;
    height: 48px;
}

.upload-img-btn, #send-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 22px;
    padding: 8px;
    border-radius: 8px;
    color: var(--secondary-text-color);
    transition: background-color 0.2s, transform 0.1s;
    /* 移动端触摸优化 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-width: 44px;
    min-height: 44px;
}

/* 联网搜索开关样式 - iOS风格滑动开关 */
.web-search-toggle {
    position: relative;
    width: 48px;
    height: 28px;
    border-radius: 14px;
    background: var(--border-color);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    padding: 2px;
    border: none;
    /* 移动端触摸优化 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    margin: 0 4px;
}

.web-search-toggle .toggle-label {
    position: absolute;
    width: 24px;
    height: 24px;
    border-radius: 12px;
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    left: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--secondary-text-color);
}

/* 关闭状态 */
.web-search-toggle:not(.active) {
    background: #d1d5db;
}

.web-search-toggle:not(.active) .toggle-label {
    left: 2px;
    color: #9ca3af;
}

.web-search-toggle:not(.active):hover {
    background: #bbbfc7;
}

/* 开启状态 */
.web-search-toggle.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 2px 8px rgba(118, 75, 162, 0.3);
}

.web-search-toggle.active .toggle-label {
    left: 22px;
    color: #667eea;
    background: white;
}

/* 深色模式 */
[data-theme="dark"] .web-search-toggle:not(.active) {
    background: #4a4a4a;
}

[data-theme="dark"] .web-search-toggle:not(.active) .toggle-label {
    background: #6b7280;
    color: #d1d5db;
}

[data-theme="dark"] .web-search-toggle.active .toggle-label {
    background: white;
}

.upload-img-btn:hover, #send-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.upload-img-btn:active, #send-btn:active {
    transform: scale(0.9);
}

[data-theme="dark"] .upload-img-btn:hover, 
[data-theme="dark"] #send-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

#send-btn {
    background-color: var(--accent-color);
    color: white;
    margin-left: 8px;
}

#send-btn:hover {
    background-color: #3a6dd9;
}

#send-btn:active {
    background-color: #2a5dc9;
    transform: scale(0.95);
}

#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--secondary-text-color);
}

#chat-input:disabled {
    opacity: 0.7;
    background-color: var(--ai-message-bg);
    cursor: not-allowed;
}

#image-preview-container {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.image-preview {
    position: relative;
}

.image-preview img {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    object-fit: cover;
    border: 2px solid var(--border-color);
}

.remove-img-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 16px;
    line-height: 24px;
    text-align: center;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.remove-img-btn:hover {
    background: #dc2626;
}

/* 文件预览样式 */
.file-preview {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background-color: var(--ai-message-bg);
    border-radius: 8px;
    border: 2px solid var(--border-color);
    max-width: 250px;
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-size: 12px;
    color: var(--primary-text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.file-size {
    font-size: 10px;
    color: var(--secondary-text-color);
    margin-top: 2px;
}

.remove-file-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 16px;
    line-height: 24px;
    text-align: center;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.remove-file-btn:hover {
    background: #dc2626;
}

/* 设置面板样式 */
.settings-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 350px;
    height: 100%;
    background-color: var(--chat-container-bg);
    border-left: 1px solid var(--border-color);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 100;
    box-shadow: -4px 0 12px var(--shadow-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;  /* 父容器不滚动 */
}

.settings-panel.show {
    transform: translateX(0);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--chat-container-bg);
    position: sticky;
    top: 0;
    z-index: 10;
    flex-shrink: 0;  /* 头部不缩小 */
}

.settings-header h3 {
    margin: 0;
    color: var(--primary-text-color);
    font-size: 18px;
}

.close-settings-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--secondary-text-color);
    padding: 0;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s, transform 0.1s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.close-settings-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.close-settings-btn:active {
    background-color: rgba(0, 0, 0, 0.15);
    transform: scale(0.9);
}

[data-theme="dark"] .close-settings-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .close-settings-btn:active {
    background-color: rgba(255, 255, 255, 0.2);
}

.settings-content {
    padding: 24px;
    overflow-y: auto;  /* 只有内容区域滚动 */
    flex: 1;  /* 占据剩余空间 */
}

.settings-section {
    margin-bottom: 24px;
}

.settings-section h4 {
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-text-color);
}

.setting-item {
    margin-bottom: 16px;
}

.setting-item label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 14px;
    color: var(--primary-text-color);
}

.required {
    color: var(--error-color);
    font-weight: bold;
}

.setting-item small {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--secondary-text-color);
    line-height: 1.4;
}

.setting-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 24px 0;
}

/* 警告框样式 */
.warning-box {
    display: flex;
    gap: 12px;
    padding: 16px;
    background-color: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 8px;
    margin: 16px 0;
}

[data-theme="dark"] .warning-box {
    background-color: rgba(255, 193, 7, 0.15);
    border-color: rgba(255, 193, 7, 0.3);
}

.warning-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.warning-content {
    flex: 1;
}

.warning-content strong {
    display: block;
    margin-bottom: 8px;
    color: #856404;
    font-size: 14px;
}

[data-theme="dark"] .warning-content strong {
    color: #ffc107;
}

.warning-content p {
    margin: 6px 0;
    font-size: 13px;
    color: #856404;
    line-height: 1.5;
}

[data-theme="dark"] .warning-content p {
    color: #ffd54f;
}

.warning-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.warning-content li {
    font-size: 12px;
    color: #856404;
    line-height: 1.6;
}

[data-theme="dark"] .warning-content li {
    color: #ffd54f;
}

/* 按钮样式优化 */
.save-btn {
    background: linear-gradient(135deg, var(--accent-color), #3a6dd9);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
    box-shadow: 0 2px 8px rgba(74, 128, 255, 0.3);
    min-height: 40px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.save-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(74, 128, 255, 0.4);
}

.save-btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 6px rgba(74, 128, 255, 0.3);
}

.secondary-btn {
    background-color: var(--ai-message-bg);
    color: var(--primary-text-color);
    border: 1px solid var(--border-color);
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    min-height: 36px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.secondary-btn:hover {
    background-color: var(--user-message-bg);
    border-color: var(--accent-color);
}

.secondary-btn:active {
    transform: scale(0.97);
    background-color: var(--accent-color);
    color: white;
}

.notification-control {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    background-color: var(--warning-color);
    color: white;
}

.setting-item {
    margin-bottom: 16px;
}

.setting-item input,
.setting-item select,
.setting-item textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--chat-container-bg);
    color: var(--primary-text-color);
    font-size: 14px;
    transition: all 0.2s;
    box-sizing: border-box; /* 确保padding和border不会超出宽度 */
}

/* 复选框样式优化 */
.setting-item input[type="checkbox"] {
    width: auto;
    height: 16px;
    cursor: pointer;
    margin-right: 6px;
    vertical-align: middle;
}

.setting-item label:has(input[type="checkbox"]) {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-weight: normal;
}

.input-with-button {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.input-with-button input {
    flex: 1;
    padding-right: 45px; /* 为眼睛按钮留空间 */
}

.toggle-password-btn {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 8px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.toggle-password-btn:hover {
    opacity: 1;
}

.model-control {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.refresh-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s;
    flex-shrink: 0;
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.refresh-btn:hover {
    background-color: #3a6dd9;
    transform: rotate(180deg);
}

.refresh-btn:active {
    background-color: #2a5dc9;
    transform: rotate(180deg) scale(0.95);
}

.refresh-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.button-group {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.test-btn {
    flex: 1;
    background-color: var(--ai-message-bg);
    color: var(--primary-text-color);
    border: 2px solid var(--accent-color);
    padding: 10px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
    min-height: 40px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.test-btn:hover {
    background-color: var(--accent-color);
    color: white;
    transform: translateY(-2px);
}

.test-btn:active {
    background-color: var(--accent-color);
    color: white;
    transform: translateY(0) scale(0.98);
}

/* 小型测试按钮 */
.test-mini-btn {
    padding: 6px 10px;
    font-size: 12px;
    background: #10b981;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    min-height: 28px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.test-mini-btn:hover:not(:disabled) {
    background: #059669;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.3);
}

.test-mini-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: #9ca3af;
}

.test-result {
    margin-top: 12px;
    padding: 16px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.8;
    white-space: pre-wrap;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    max-height: 300px;
    overflow-y: auto;
}

.test-result.success {
    background-color: rgba(16, 185, 129, 0.1);
    border: 2px solid var(--success-color);
    color: var(--success-color);
    font-weight: 500;
}

.test-result.error {
    background-color: rgba(239, 68, 68, 0.05);
    border: 2px solid var(--error-color);
    color: var(--error-color);
    font-weight: 400;
}

.test-result.loading {
    background-color: rgba(74, 128, 255, 0.1);
    border: 2px solid var(--accent-color);
    color: var(--accent-color);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
}

.test-result.loading::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid var(--accent-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.02);
    }
}

.setting-item input:focus,
.setting-item select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(74, 128, 255, 0.1);
}


/* 加载动画 */
.loading-dots {
    display: flex;
    gap: 6px;
    padding: 10px 0;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--accent-color);
    animation: loading-bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

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

/* 对话框样式 */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

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

.dialog-content {
    background-color: var(--chat-container-bg);
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px var(--shadow-color);
    animation: slideUp 0.3s ease;
}

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

.dialog-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 12px 15px !important;
    border-bottom: 1px solid var(--border-color) !important;
    gap: 10px !important;
    flex-wrap: nowrap !important;
    min-height: 50px !important;
}

@media (max-width: 768px) {
    .dialog-header {
        padding: 10px 12px !important;
        min-height: 48px !important;
    }
    
    .dialog-header h3 {
        font-size: 16px !important;
    }
}

.dialog-header h3 {
    margin: 0 !important;
    color: var(--primary-text-color) !important;
    flex: 1 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

.close-dialog-btn {
    background: rgba(0, 0, 0, 0.05) !important;
    border: 2px solid var(--border-color) !important;
    font-size: 28px !important;
    font-weight: bold !important;
    cursor: pointer;
    color: var(--primary-text-color) !important;
    padding: 0 !important;
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    min-height: 48px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    transition: all 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0 !important;
}

.close-dialog-btn:hover {
    background-color: rgba(255, 0, 0, 0.1) !important;
    border-color: #f00 !important;
}

.close-dialog-btn:active {
    background-color: rgba(255, 0, 0, 0.2) !important;
    transform: scale(0.95) !important;
}

.dialog-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;  /* 占据剩余空间 */
}

@media (max-width: 768px) {
    .dialog-body {
        padding: 15px;
        -webkit-overflow-scrolling: touch;  /* iOS滚动优化 */
    }
}

/* 历史对话列表 */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background-color: var(--ai-message-bg);
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.history-item:hover {
    background-color: var(--user-message-bg);
}

.history-item-content {
    flex: 1;
}

.history-title {
    font-weight: 500;
    color: var(--primary-text-color);
    margin-bottom: 4px;
}

.history-time {
    font-size: 12px;
    color: var(--secondary-text-color);
}

.delete-history-btn {
    background-color: var(--error-color);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    min-height: 40px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.delete-history-btn:hover {
    opacity: 0.8;
}

.delete-history-btn:active {
    transform: scale(0.95);
    opacity: 0.9;
}

/* 定时任务表单 */
.task-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 14px;
    font-weight: 500;
    color: var(--primary-text-color);
}

.weekday-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
    background-color: var(--ai-message-bg);
    border-radius: 8px;
}

.weekday-selector label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 14px;
    font-weight: normal;
    cursor: pointer;
}

.weekday-check {
    cursor: pointer;
}

.settings-section {
    padding: 10px;
    background-color: var(--ai-message-bg);
    border-radius: 8px;
}

.task-input {
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--chat-container-bg);
    color: var(--primary-text-color);
    font-size: 14px;
    box-sizing: border-box;
}

.task-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.task-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    min-height: 36px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.task-btn:hover {
    background-color: #3a6dd9;
}

.task-btn:active {
    transform: scale(0.98);
    background-color: #2a5dc9;
}

/* 任务列表 */
.task-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.task-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background-color: var(--ai-message-bg);
    border-radius: 8px;
}

.task-content {
    flex: 1;
}

.task-message {
    font-weight: 500;
    color: var(--primary-text-color);
    margin-bottom: 4px;
}

.task-time {
    font-size: 12px;
    color: var(--secondary-text-color);
    margin-bottom: 4px;
}

.task-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
}

.task-status.pending {
    background-color: var(--warning-color);
    color: white;
}

.task-status.completed {
    background-color: var(--success-color);
    color: white;
}

.task-tag {
    display: inline-block;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
    background-color: var(--accent-color);
    color: white;
    margin-top: 4px;
}

.delete-task-btn {
    background-color: var(--error-color);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    min-height: 40px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.delete-task-btn:hover {
    opacity: 0.8;
}

.delete-task-btn:active {
    transform: scale(0.95);
    opacity: 0.9;
}

.empty-message {
    text-align: center;
    color: var(--secondary-text-color);
    padding: 20px;
}

/* 股票分析样式 */
.stock-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
}

.stock-tab-btn {
    background: none;
    border: none;
    padding: 12px 20px;
    cursor: pointer;
    color: var(--secondary-text-color);
    font-size: 14px;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.stock-tab-btn:hover {
    color: var(--accent-color);
    background-color: rgba(74, 128, 255, 0.05);
}

.stock-tab-btn.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
    font-weight: 600;
}

.stock-tab-content {
    display: none;
}

.stock-tab-content.active {
    display: block;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stock-result {
    margin-top: 20px;
    padding: 16px;
    border-radius: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.stock-result.loading {
    background-color: rgba(74, 128, 255, 0.1);
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
    text-align: center;
    padding: 30px;
}

.stock-result.success {
    background-color: rgba(16, 185, 129, 0.05);
    border: 1px solid var(--success-color);
}

.stock-result.error {
    background-color: rgba(239, 68, 68, 0.05);
    border: 1px solid var(--error-color);
    color: var(--error-color);
}

.stock-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.stock-result-header h4 {
    margin: 0;
    color: var(--primary-text-color);
}

.copy-result-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    min-height: 36px;
    touch-action: manipulation;
}

.copy-result-btn:hover {
    background-color: #3a6dd9;
}

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

.stock-result-content {
    background-color: var(--chat-container-bg);
    padding: 12px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--primary-text-color);
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
}

.stock-result.error h4 {
    color: var(--error-color);
}

.stock-result.error ul {
    margin: 10px 0;
    padding-left: 20px;
}

.stock-result.error li {
    margin: 4px 0;
    font-size: 12px;
}

/* 响应式设计 - 移动端优化 */
@media (max-width: 768px) {
    body {
        padding: 0;
        margin: 0;
    }
    
    .chat-container {
        width: 100%;
        height: 100vh;
        height: 100dvh; /* 动态视口高度，适配移动端地址栏 */
        border-radius: 0;
        max-width: none;
    }
    
    .settings-panel {
        width: 100%;
        height: 100%;
    }
    
    .action-buttons {
        gap: 4px;
        flex-wrap: nowrap;
    }
    
    /* 移动端按钮保持足够大的点击区域 */
    .action-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
        /* 确保触摸友好 */
        min-width: 40px;
        min-height: 40px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* 输入区域优化 */
    .input-toolbar {
        margin-bottom: 8px;
        flex-wrap: nowrap;
        gap: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .api-status {
        font-size: 12px;
        padding: 8px 10px;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .api-status span {
        display: inline-block;
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* 输入框优化 */
    .chat-input-container {
        padding: 12px 16px;
    }
    
    .input-box {
        padding: 2px;
    }
    
    #chat-input {
        padding: 10px;
        min-height: 44px;
        max-height: 120px;
    }
    
    .upload-img-btn, #send-btn {
        min-width: 40px;
        min-height: 40px;
        font-size: 20px;
    }
    
    /* 对话气泡按钮在移动端更明显 */
    .bubble-action-btn {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 44px;
    }
    
    .file-preview {
        max-width: 150px;
    }
    
    .dialog-content {
        width: 95%;
        max-height: 90vh;
    }
    
    /* 移动端文本输入优化 */
    #chat-input {
        font-size: 16px; /* 防止iOS自动缩放 */
    }
    
    /* 移动端滚动优化 */
    .chat-messages {
        -webkit-overflow-scrolling: touch;
    }
    
    /* 股票分析移动端优化 */
    .stock-tabs {
        gap: 5px;
    }
    
    .stock-tab-btn {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .form-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .stock-result {
        max-height: 300px;
    }
    
    /* 对话框移动端优化 */
    .dialog-content {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        display: flex !important;
        flex-direction: column !important;
    }
    
    .dialog-header {
        flex-shrink: 0 !important;
        position: relative !important;
    }
    
    .dialog-body {
        flex: 1 !important;
        overflow-y: auto !important;
        padding: 15px !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* 设置面板移动端 */
    .settings-content {
        padding: 15px;
    }
    
    .quick-help {
        margin: 12px 0;
    }
    
    /* 消息优化 */
    .chat-messages {
        padding: 16px;
    }
    
    .message {
        max-width: 100%;
    }
    
    /* 表单优化 */
    .form-group {
        margin-bottom: 15px;
    }
    
    .form-group label {
        font-size: 14px;
        margin-bottom: 6px;
    }
    
    .task-input,
    .setting-item input,
    .setting-item select,
    .setting-item textarea {
        font-size: 16px; /* 防止iOS自动缩放 */
        padding: 12px;
        min-height: 44px;
    }
    
    /* 按钮组优化 - 移动端保持横向，减小间距 */
    .button-group {
        gap: 6px;
    }
    
    .button-group button {
        font-size: 13px;
        padding: 8px 12px;
    }
}


/* 思考过程样式 */
.thinking-message {
    opacity: 0.8;
}

.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    font-style: italic;
}

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

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

.thinking-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.thinking-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

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

.thinking-text {
    font-size: 14px;
    color: var(--text-secondary);
}

/* 通知动画 */
@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

/* ===== 设置面板折叠样式 ===== */
.settings-section-collapsible summary {
    transition: background 0.2s ease;
}

.settings-section-collapsible summary:hover {
    background: var(--ai-message-bg) !important;
}

.settings-section-collapsible[open] summary {
    border-radius: 8px 8px 0 0 !important;
}
