/* ==================== 全局样式 ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: #f5f5f5;
    color: #333;
    height: 100vh;
    overflow: hidden;
}

/* ==================== 应用容器 ==================== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ==================== 侧边栏 ==================== */
.sidebar {
    width: 300px;
    background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.sidebar-header h2 {
    font-size: 1.3em;
    font-weight: 600;
}

.toggle-sidebar {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 1.2em;
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle-sidebar:hover {
    background: rgba(255, 255, 255, 0.3);
}

.new-chat-btn {
    margin: 15px;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 500;
    transition: all 0.3s;
}

.new-chat-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

/* ==================== 设置区域 ==================== */
.settings-section {
    padding: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    max-height: 50%;
    overflow-y: auto;
}

.settings-section h3 {
    font-size: 1em;
    margin-bottom: 15px;
    opacity: 0.9;
}

.setting-group {
    margin-bottom: 15px;
}

.setting-group label {
    display: block;
    font-size: 0.85em;
    margin-bottom: 5px;
    opacity: 0.9;
}

.setting-group input[type="text"],
.setting-group input[type="password"],
.setting-group input[type="number"],
.setting-group select,
.setting-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 0.9em;
    transition: all 0.3s;
}

/* 下拉框选项样式 */
.setting-group select option {
    background: #2d2d2d;
    color: white;
    padding: 8px;
}

.setting-group input::placeholder,
.setting-group textarea::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.setting-group input:focus,
.setting-group select:focus,
.setting-group textarea:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

.setting-group textarea {
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
}

.setting-hint {
    font-size: 0.75em;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 4px;
    font-style: italic;
}

.model-group {
    display: flex;
    gap: 8px;
}

.model-group select {
    flex: 1;
}

/* API 配置选择器 */
.api-config-selector {
    display: flex;
    gap: 8px;
    align-items: center;
}

.api-config-selector select {
    flex: 1;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.status-text {
    font-size: 0.8em;
    margin-top: 5px;
    min-height: 18px;
}

.advanced-settings {
    margin-top: 10px;
}

.advanced-settings summary {
    cursor: pointer;
    font-size: 0.9em;
    opacity: 0.9;
    padding: 8px 0;
    user-select: none;
}

.advanced-settings summary:hover {
    opacity: 1;
}

/* Checkbox 样式 */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: white;
}

.checkbox-label span {
    font-size: 0.9em;
}

/* ==================== 历史对话列表 ==================== */
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.chat-history h3 {
    font-size: 1em;
    margin-bottom: 10px;
    opacity: 0.9;
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-item {
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    border: 1px solid transparent;
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-item.active {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
}

.chat-item-title {
    font-size: 0.95em;
    font-weight: 500;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-time {
    font-size: 0.75em;
    opacity: 0.7;
}

.empty-list {
    text-align: center;
    padding: 20px;
    opacity: 0.6;
    font-size: 0.9em;
}

/* ==================== 侧边栏底部 ==================== */
.sidebar-footer {
    padding: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    gap: 8px;
}

.footer-btn {
    flex: 1;
    padding: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    transition: all 0.3s;
}

.footer-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ==================== 作者信息 ==================== */
.author-credit {
    padding: 12px 15px;
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.author-credit a {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 0.85em;
    transition: all 0.3s;
    display: inline-block;
}

.author-credit a:hover {
    color: white;
    transform: translateY(-2px);
}

/* ==================== 主聊天区域 ==================== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
}

/* ==================== 聊天头部 ==================== */
.chat-header {
    padding: 20px;
    background: white;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 15px;
}

.mobile-menu-btn {
    display: none;
    background: #f0f0f0;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2em;
}

.chat-header h1 {
    flex: 1;
    font-size: 1.3em;
    font-weight: 600;
    color: #333;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.header-actions .icon-btn {
    background: #f0f0f0;
    color: #333;
    border: 1px solid #e0e0e0;
}

.header-actions .icon-btn:hover {
    background: #e0e0e0;
}

/* ==================== 消息容器 ==================== */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #fafafa;
}

.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.welcome-icon {
    font-size: 4em;
    margin-bottom: 20px;
}

.welcome-message h2 {
    font-size: 1.5em;
    color: #667eea;
    margin-bottom: 10px;
}

.welcome-message p {
    font-size: 1em;
    color: #999;
}

/* ==================== 消息样式 ==================== */
.message {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    animation: fadeIn 0.3s ease;
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

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

.message-user .message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.message-assistant .message-avatar {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.message-system .message-avatar {
    background: #ffc107;
}

.message-content {
    flex: 1;
    max-width: 80%;
}

.message-text {
    background: white;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.message-user .message-text {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.message-assistant .message-text {
    background: white;
    border: 1px solid #e0e0e0;
}

.message-system .message-text {
    background: #fff3cd;
    border: 1px solid #ffc107;
    color: #856404;
}

.message-time {
    font-size: 0.75em;
    color: #999;
    margin-top: 5px;
    padding: 0 4px;
}

/* ==================== 输入区域 ==================== */
.input-area {
    padding: 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    position: relative; /* 为附件菜单提供定位参考 */
}

.input-container {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#user-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    font-size: 1em;
    font-family: inherit;
    resize: none;
    max-height: 200px;
    overflow-y: auto;
    transition: border-color 0.3s;
}

#user-input:focus {
    outline: none;
    border-color: #667eea;
}

.send-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 100px;
    justify-content: center;
}

.send-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

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

.input-tips {
    margin-top: 10px;
    font-size: 0.85em;
    color: #999;
    text-align: center;
}

/* ==================== 滚动条美化 ==================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* 侧边栏滚动条 */
.sidebar ::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
}

.sidebar ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* ==================== 响应式设计 ==================== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
    }

    .sidebar.collapsed {
        transform: translateX(0);
    }

    .mobile-menu-btn {
        display: block;
    }

    .chat-header h1 {
        font-size: 1.1em;
    }

    .message-content {
        max-width: 90%;
    }

    .input-container {
        flex-direction: column;
        align-items: stretch;
    }

    .send-btn {
        width: 100%;
    }

    .sidebar-footer {
        flex-wrap: wrap;
    }

    .footer-btn {
        flex: 1 1 calc(50% - 4px);
        min-width: 80px;
    }
}

/* ==================== 暗色模式支持 ==================== */
@media (prefers-color-scheme: dark) {
    body {
        background: #1a1a1a;
        color: #e0e0e0;
    }

    .chat-main {
        background: #2d2d2d;
    }

    .chat-header {
        background: #2d2d2d;
        border-bottom-color: #444;
    }

    .chat-header h1 {
        color: #e0e0e0;
    }

    .header-actions .icon-btn {
        background: #444;
        color: #e0e0e0;
        border-color: #555;
    }

    .header-actions .icon-btn:hover {
        background: #555;
    }

    .messages-container {
        background: #1a1a1a;
    }

    .message-assistant .message-text {
        background: #2d2d2d;
        border-color: #444;
        color: #e0e0e0;
    }

    #user-input {
        background: #2d2d2d;
        color: #e0e0e0;
        border-color: #444;
    }

    #user-input:focus {
        border-color: #667eea;
    }

    .input-area {
        background: #2d2d2d;
        border-top-color: #444;
    }
}

/* ==================== 打印样式 ==================== */
@media print {
    .sidebar,
    .chat-header,
    .input-area {
        display: none;
    }

    .messages-container {
        padding: 0;
        overflow: visible;
    }

    .message {
        page-break-inside: avoid;
    }
}

/* ==================== 快速模型选择器 ==================== */
.quick-model-select {
    padding: 12px 16px;
    background: #f0f0f0;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s;
    max-width: 200px;
    color: #333;
}

.quick-model-select:hover {
    border-color: #667eea;
}

.quick-model-select:focus {
    outline: none;
    border-color: #667eea;
    background: white;
}

.quick-model-select option {
    padding: 8px;
}

/* ==================== 附件按钮 ==================== */
.attach-btn {
    padding: 12px 16px;
    background: #f0f0f0;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    font-size: 1.3em;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attach-btn:hover {
    background: #e0e0e0;
    transform: translateY(-2px);
}

/* ==================== 附件菜单 ==================== */
.attach-menu {
    position: absolute;
    bottom: 100%;
    left: 20px;
    margin-bottom: 10px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 100;
    animation: slideUp 0.2s ease;
}

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

.attach-menu button {
    padding: 10px 16px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95em;
    text-align: left;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.attach-menu button:hover {
    background: #f0f0f0;
    transform: translateX(4px);
}

/* ==================== 附件预览区 ==================== */
.attachments-preview {
    margin-top: 12px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.attachment-item {
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #e0e0e0;
    background: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.attachment-item:hover {
    border-color: #667eea;
    transform: scale(1.05);
}

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

.attachment-item .document-icon {
    font-size: 2.5em;
    margin-bottom: 5px;
}

.attachment-item .attachment-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 0.7em;
    padding: 4px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attachment-item .remove-attachment {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255, 0, 0, 0.8);
    color: white;
    border: none;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
}

.attachment-item .remove-attachment:hover {
    background: rgba(255, 0, 0, 1);
    transform: scale(1.1);
}

/* ==================== 消息附件显示 ==================== */
.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.message-image {
    max-width: 300px;
    max-height: 300px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    border: 2px solid #e0e0e0;
}

.message-image:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
}

.message-document {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f0f0f0;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    font-size: 0.9em;
}

.message-document .document-icon {
    font-size: 1.5em;
}

.message-document .document-name {
    color: #333;
    font-weight: 500;
}

/* 暗色模式下的附件样式 */
@media (prefers-color-scheme: dark) {
    .quick-model-select {
        background: #444;
        border-color: #555;
        color: #e0e0e0;
    }

    .quick-model-select:hover,
    .quick-model-select:focus {
        border-color: #667eea;
        background: #555;
    }

    .attach-btn {
        background: #444;
        border-color: #555;
    }

    .attach-btn:hover {
        background: #555;
    }

    .attach-menu {
        background: #2d2d2d;
        border-color: #444;
    }

    .attach-menu button {
        background: #2d2d2d;
        border-color: #444;
        color: #e0e0e0;
    }

    .attach-menu button:hover {
        background: #444;
    }

    .attachments-preview {
        background: #2d2d2d;
        border-color: #444;
    }

    .attachment-item {
        background: #2d2d2d;
        border-color: #444;
    }

    .attachment-item:hover {
        border-color: #667eea;
    }

    .message-document {
        background: #444;
        border-color: #555;
    }

    .message-document .document-name {
        color: #e0e0e0;
    }

    .message-image {
        border-color: #444;
    }
}

/* 响应式设计 - 移动端附件样式 */
@media (max-width: 768px) {
    .quick-model-select {
        max-width: 100%;
        margin-bottom: 10px;
    }

    .attach-menu {
        left: 20px;
        right: 20px;
    }

    .attachment-item {
        width: 80px;
        height: 80px;
    }

    .message-image {
        max-width: 100%;
    }
}

