/* Dify Chat V2 Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --border-radius: 8px;
    --transition: all 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--background-color);
    overflow-x: hidden;
}

/* 登录页面样式 */
#login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-box {
    background: var(--surface-color);
    padding: 40px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-box h1 {
    margin-bottom: 30px;
    color: var(--text-primary);
    font-size: 2rem;
    font-weight: 600;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 14px;
    transition: var(--transition);
    background-color: var(--surface-color);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-primary:disabled {
    background-color: var(--secondary-color);
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    padding: 8px 16px;
    background-color: var(--border-color);
    color: var(--text-primary);
    border: none;
    border-radius: var(--border-radius);
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background-color: var(--secondary-color);
    color: white;
}

.error-message {
    color: var(--error-color);
    font-size: 14px;
    margin-top: 10px;
    text-align: center;
}

/* 主应用样式 */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* 侧边栏样式 */
.sidebar {
    width: 300px;
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.btn-new-chat {
    width: 100%;
    padding: 12px 16px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-new-chat:hover {
    background-color: var(--primary-hover);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.history-section h3 {
    margin-bottom: 15px;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
}

.history-list {
    list-style: none;
}

.conversation-item {
    padding: 12px;
    margin-bottom: 8px;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

.conversation-item:hover {
    background-color: var(--background-color);
}

.conversation-item.active {
    background-color: var(--primary-color);
    color: white;
}

.conversation-content {
    flex: 1;
    overflow: hidden;
}

.conversation-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.conversation-date {
    font-size: 12px;
    color: var(--text-muted);
}

.conversation-item.active .conversation-date {
    color: rgba(255, 255, 255, 0.8);
}

.conversation-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition);
    opacity: 0;
}

.conversation-item:hover .conversation-delete {
    opacity: 1;
}

.conversation-delete:hover {
    background-color: var(--error-color);
    color: white;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.user-info {
    margin-bottom: 15px;
    text-align: center;
}

.username {
    display: block;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.user-role {
    font-size: 12px;
    color: var(--text-muted);
    background-color: var(--background-color);
    padding: 2px 8px;
    border-radius: 12px;
    display: inline-block;
}

.user-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.action-link, .action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--border-radius);
    text-decoration: none;
    color: var(--text-primary);
    background: none;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
    width: 100%;
    text-align: left;
}

.action-link:hover, .action-btn:hover {
    background-color: var(--background-color);
}

/* 主内容区域样式 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    padding: 20px;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

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

.btn-icon {
    background: none;
    border: none;
    padding: 8px;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}

.btn-icon:hover {
    background-color: var(--background-color);
    color: var(--text-primary);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-color: var(--background-color);
}

.message {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
}

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

.assistant-message {
    align-items: flex-start;
}

.system-message {
    align-items: center;
    text-align: center;
}

.message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: var(--border-radius);
    background-color: var(--surface-color);
    box-shadow: var(--shadow-sm);
    line-height: 1.6;
}

.user-message .message-content {
    background-color: var(--primary-color);
    color: white;
}

.assistant-message .message-content {
    background-color: var(--surface-color);
    color: var(--text-primary);
}

.system-message .message-content {
    background-color: var(--background-color);
    color: var(--text-secondary);
    font-style: italic;
}

.system-message.error .message-content {
    background-color: var(--error-color);
    color: white;
}

.system-message.warning .message-content {
    background-color: var(--warning-color);
    color: white;
}

.message-files {
    margin-bottom: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.file-attachment {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background-color: var(--background-color);
    border-radius: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.welcome-message, .loading-message, .error-message, .empty-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.welcome-message h3 {
    margin-bottom: 10px;
    color: var(--text-primary);
}

.error-message {
    color: var(--error-color);
}

/* 聊天输入区域样式 */
.chat-input-container {
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
    padding: 20px;
}

.file-preview-area {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.file-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background-color: var(--background-color);
    border-radius: var(--border-radius);
    font-size: 14px;
    color: var(--text-primary);
}

.file-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.file-remove:hover {
    background-color: var(--error-color);
    color: white;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.textarea-wrapper {
    flex: 1;
    position: relative;
}

.textarea-wrapper textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    transition: var(--transition);
    background-color: var(--surface-color);
    max-height: 120px;
    overflow-y: auto;
}

.textarea-wrapper textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

.btn-send {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 12px;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    font-size: 16px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-send:hover {
    background-color: var(--primary-hover);
}

.btn-send:disabled {
    background-color: var(--secondary-color);
    cursor: not-allowed;
}

/* 弹窗样式 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: var(--surface-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-header h3 {
    margin: 0;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.modal-close:hover {
    background-color: var(--background-color);
    color: var(--text-primary);
}

.modal form {
    padding: 20px;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* 加载动画 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-overlay p {
    color: var(--text-primary);
    font-size: 16px;
    margin: 0;
}

/* 通知样式 */
.notification-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.notification {
    padding: 12px 20px;
    border-radius: var(--border-radius);
    color: white;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease-out;
    max-width: 400px;
}

.notification.info {
    background-color: var(--primary-color);
}

.notification.success {
    background-color: var(--success-color);
}

.notification.warning {
    background-color: var(--warning-color);
}

.notification.error {
    background-color: var(--error-color);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* 响应式设计 */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: fixed;
        top: 0;
        left: -100%;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .main-content {
        width: 100%;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .modal-content {
        width: 95%;
        margin: 20px;
    }
    
    .login-box {
        padding: 30px 20px;
    }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background-color);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* 代码块样式 */
pre {
    background-color: var(--background-color);
    padding: 12px;
    border-radius: var(--border-radius);
    overflow-x: auto;
    margin: 8px 0;
}

code {
    background-color: var(--background-color);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

/* 链接样式 */
a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* 表格样式 */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

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

th {
    background-color: var(--background-color);
    font-weight: 600;
}

/* 引用样式 */
blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--text-secondary);
    font-style: italic;
}

/* 列表样式 */
ul, ol {
    padding-left: 20px;
    margin: 8px 0;
}

li {
    margin: 4px 0;
}

/* 图片样式 */
img {
    max-width: 100%;
    height: auto;
    border-radius: var(--border-radius);
    margin: 8px 0;
}

/* 分隔线样式 */
hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 16px 0;
}

/* 选择文本样式 */
::selection {
    background-color: var(--primary-color);
    color: white;
}

/* 焦点样式 */
*:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

button:focus,
input:focus,
textarea:focus {
    outline: none;
}

/* 打印样式 */
@media print {
    .sidebar,
    .chat-header,
    .chat-input-container,
    .modal,
    .loading-overlay,
    .notification-container {
        display: none !important;
    }
    
    .main-content {
        width: 100%;
    }
    
    .message-content {
        max-width: 100%;
        box-shadow: none;
        border: 1px solid var(--border-color);
    }
}