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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #ffffff;
    height: 100vh;
    overflow: hidden;
    display: flex;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: linear-gradient(180deg, #0f0f0f 0%, #1a1a1a 50%, #0f0f0f 100%);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    padding: 24px 20px;
    flex-shrink: 0;
    border-right: 1px solid #2a2a2a;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
}

.sidebar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    height: 100%;
    background: linear-gradient(180deg, transparent 0%, #007bff 20%, #00ff88 50%, #007bff 80%, transparent 100%);
    opacity: 0.6;
}

.sidebar::after {
    content: '';
    position: absolute;
    top: -50%;
    right: -50%;
    width: 100%;
    height: 200%;
    background: radial-gradient(circle, rgba(0, 123, 255, 0.03) 0%, transparent 70%);
    pointer-events: none;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, rgba(0, 123, 255, 0.1) 0%, rgba(0, 123, 255, 0.05) 100%);
    border: 1px solid rgba(0, 123, 255, 0.3);
    color: white;
    padding: 16px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    width: 100%;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    margin-bottom: 24px;
}

.new-chat-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.6s ease;
}

.new-chat-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: radial-gradient(circle, rgba(0, 123, 255, 0.3) 0%, transparent 70%);
    transform: translate(-50%, -50%);
    transition: all 0.4s ease;
    border-radius: 50%;
}

.new-chat-btn:hover {
    background: linear-gradient(135deg, rgba(0, 123, 255, 0.2) 0%, rgba(0, 123, 255, 0.1) 100%);
    border-color: rgba(0, 123, 255, 0.5);
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 123, 255, 0.2), 0 0 0 1px rgba(0, 123, 255, 0.1);
}

.new-chat-btn:hover::before {
    left: 100%;
}

.new-chat-btn:hover::after {
    width: 100px;
    height: 100px;
}

.new-chat-btn:active {
    transform: translateY(0) scale(0.98);
}

.new-chat-btn svg {
    transition: transform 0.3s ease;
}

.new-chat-btn:hover svg {
    transform: rotate(90deg);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    margin-top: 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 123, 255, 0.3) transparent;
    padding-right: 4px;
}

.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(0, 123, 255, 0.3) 0%, rgba(0, 123, 255, 0.1) 100%);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(0, 123, 255, 0.5) 0%, rgba(0, 123, 255, 0.3) 100%);
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 10px;
    cursor: pointer;
    color: #b0b0b0;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.02) 0%, rgba(255, 255, 255, 0.01) 100%);
    margin-bottom: 6px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(5px);
}

.history-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 3px;
    height: 100%;
    background: linear-gradient(180deg, #007bff 0%, #00ff88 100%);
    transform: scaleY(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 0 2px 2px 0;
}

.history-item::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(0, 123, 255, 0.1) 0%, rgba(0, 255, 136, 0.05) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.history-item:hover {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.04) 100%);
    color: #ffffff;
    border-color: rgba(0, 123, 255, 0.3);
    transform: translateX(6px);
    box-shadow: 0 4px 20px rgba(0, 123, 255, 0.1);
}

.history-item:hover::before {
    transform: scaleY(1);
}

.history-item:hover::after {
    opacity: 1;
}

.history-item:hover svg {
    color: #007bff;
    transform: scale(1.1);
}

.history-item svg {
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.history-item.active {
    background: linear-gradient(135deg, rgba(0, 123, 255, 0.15) 0%, rgba(0, 255, 136, 0.08) 100%);
    color: #ffffff;
    border-color: rgba(0, 123, 255, 0.4);
    transform: translateX(6px);
}

.history-item.active::before {
    transform: scaleY(1);
}

.history-item.active::after {
    opacity: 1;
}

.sidebar-footer {
    padding-top: 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 12px;
    color: #888;
    text-align: center;
    margin-top: auto;
    position: relative;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.02) 0%, transparent 100%);
    border-radius: 8px;
    padding: 16px 12px 12px;
    backdrop-filter: blur(5px);
}

.sidebar-footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(0, 123, 255, 0.5), transparent);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    position: relative;
    height: 100vh;
}

.chat-header {
    height: 60px;
    border-bottom: 1px solid #333;
    background: linear-gradient(90deg, #000000 0%, #1a1a1a 100%);
    display: flex;
    align-items: center;
    padding: 0 24px;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-title {
    font-size: 16px;
    font-weight: 600;
    color: #ffffff;
    letter-spacing: 0.5px;
}

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

/* Chat Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scrollbar-width: thin;
    scrollbar-color: #ddd transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #bbb;
}

/* Welcome State */
.welcome-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #333;
    animation: fadeIn 0.6s ease-out;
    max-width: 800px;
    min-width: 800px;
    width: 800px;
    margin: 0 auto;
    padding: 0 24px;
    box-sizing: border-box;
}

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

.welcome-card {
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    padding: 48px;
    border-radius: 16px;
    text-align: left;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    border: 1px solid #e9ecef;
    position: relative;
    overflow: hidden;
}

.welcome-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #007bff, #0056b3);
}

.welcome-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    font-size: 20px;
    font-weight: 700;
    color: #1a1a1a;
}

.welcome-header span {
    font-size: 24px;
    animation: wave 2s ease-in-out infinite;
}

@keyframes wave {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(20deg); }
    75% { transform: rotate(-10deg); }
}

.welcome-text {
    color: #666;
    font-size: 15px;
    margin-bottom: 24px;
    line-height: 1.7;
    text-align: left;
}

.start-chat-btn {
    background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
    color: white;
    border: none;
    padding: 12px 28px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
}

.start-chat-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.start-chat-btn:hover {
    background: linear-gradient(135deg, #1a1a1a 0%, #333333 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.start-chat-btn:hover::before {
    left: 100%;
}

.start-chat-btn:active {
    transform: translateY(0);
}

/* Messages */
.message {
    display: flex;
    gap: 16px;
    max-width: 800px;
    min-width: 800px;
    margin: 0 auto;
    width: 800px;
    padding: 0 24px;
    animation: slideIn 0.4s ease-out;
    box-sizing: border-box;
}

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

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

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease;
}

.avatar:hover {
    transform: scale(1.05);
}

.bot-avatar {
    background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
    color: white;
    border: 2px solid #333;
}

.user-avatar {
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    color: #2563eb;
    border: 2px solid #dbeafe;
}

.message-bubble {
    padding: 16px 20px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.6;
    max-width: 100%;
    position: relative;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    transition: all 0.2s ease;
    word-wrap: break-word;
    word-break: break-word;
}

.message-bubble:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

.bot-message .message-bubble {
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    color: #1f2937;
    border-top-left-radius: 4px;
    border: 1px solid #e9ecef;
}

.user-message .message-bubble {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    color: #1e3a8a;
    border-top-right-radius: 4px;
    border: 1px solid #bfdbfe;
}

/* Input Area */
.input-area {
    padding: 24px;
    background: linear-gradient(180deg, #ffffff 0%, #f8f9fa 100%);
    max-width: 800px;
    min-width: 800px;
    width: 800px;
    margin: 0 auto;
    border-top: 1px solid #e9ecef;
    box-sizing: border-box;
}

/* 有侧栏时的输入区域样式 */
body:not(.no-sidebar) .input-area {
    padding: 24px;
}

.input-container {
    border: 2px solid #e5e7eb;
    border-radius: 16px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    background: #fff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.input-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(37, 99, 235, 0.05), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.input-container:focus-within {
    border-color: #2563eb;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1), 0 4px 20px rgba(0, 0, 0, 0.12);
    transform: translateY(-1px);
}

.input-container:focus-within::before {
    opacity: 1;
}

textarea {
    flex: 1;
    border: none;
    resize: none;
    padding: 8px;
    font-family: inherit;
    font-size: 15px;
    outline: none;
    max-height: 120px;
    background: transparent;
    line-height: 1.5;
    z-index: 1;
    position: relative;
}

textarea::placeholder {
    color: #9ca3af;
    transition: color 0.2s ease;
}

textarea:focus::placeholder {
    color: #6b7280;
}

.send-btn {
    background: #f3f4f6;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #9ca3af;
    transition: all 0.3s ease;
    z-index: 1;
    position: relative;
}

.send-btn:hover {
    background: #e5e7eb;
    transform: scale(1.05);
}

.send-btn.active {
    background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.send-btn.active:hover {
    background: linear-gradient(135deg, #1a1a1a 0%, #333333 100%);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.input-footer {
    text-align: center;
    font-size: 12px;
    color: #9ca3af;
    margin-top: 12px;
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

.input-footer:hover {
    opacity: 1;
}

/* Loading */
.typing-dots {
    display: inline-flex;
    gap: 6px;
    padding: 8px 0;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

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

/* Markdown Content Styling */
.message-content p {
    margin-bottom: 12px;
    line-height: 1.6;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content pre {
    background: #1e1e1e;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    color: #fff;
    margin: 12px 0;
    border: 1px solid #333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.message-content code {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    background: rgba(0, 0, 0, 0.08);
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.bot-message .message-content code {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.08);
}

.user-message .message-content code {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.2);
}

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

.message-content li {
    margin-bottom: 4px;
    line-height: 1.5;
}

.message-content blockquote {
    border-left: 4px solid #e5e7eb;
    padding-left: 16px;
    margin: 12px 0;
    color: #6b7280;
    font-style: italic;
}

.message-content h1, .message-content h2, .message-content h3 {
    margin: 16px 0 8px 0;
    font-weight: 600;
}

.message-content h1 {
    font-size: 1.5em;
}

.message-content h2 {
    font-size: 1.3em;
}

.message-content h3 {
    font-size: 1.1em;
}

/* Error Message Styling */
.error-message {
    border-left: 4px solid #e74c3c;
    padding-left: 12px;
}

.error-message .phone-support {
    transition: all 0.2s ease;
}

.error-message .phone-support:hover {
    background: #f1f3f4 !important;
    border-color: #c3c7ca !important;
}

.error-message .phone-support a {
    transition: color 0.2s ease;
}

.error-message .phone-support a:hover {
    color: #0056b3 !important;
    text-decoration: underline !important;
}

/* 响应式设计 - 手机端优化 */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        padding: 16px;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        border-right: none;
        border-bottom: 1px solid #333;
    }
    
    .new-chat-btn {
        width: auto;
        padding: 8px 16px;
        font-size: 13px;
    }
    
    .sidebar-footer {
        display: none;
    }
    
    .chat-header {
        padding: 0 16px;
        height: 50px;
    }
    
    .header-title {
        font-size: 14px;
    }
    
    .chat-messages {
        padding: 16px 0;
        gap: 16px;
    }
    
    .message {
        gap: 12px;
        padding: 0 16px;
        min-width: auto;
        width: 100%;
    }
    
    .avatar {
        width: 32px;
        height: 32px;
    }
    
    .message-bubble {
        padding: 12px 16px;
        font-size: 14px;
        border-radius: 12px;
    }
    
    .welcome-card {
        padding: 32px 24px;
    }
    
    .welcome-container {
        min-width: auto;
        width: 100%;
    }
    
    .welcome-header {
        font-size: 18px;
    }
    
    .input-area {
        padding: 16px;
        min-width: auto;
        width: 100%;
    }
    
    /* 有侧栏时的移动端输入区域样式 */
    body:not(.no-sidebar) .input-area {
        padding: 16px;
    }
    
    .input-container {
        padding: 10px 12px;
        border-radius: 12px;
    }
    
    .send-btn {
        width: 32px;
        height: 32px;
    }
    
    .error-message .phone-support {
        padding: 10px;
    }
    
    .error-message .phone-support div {
        font-size: 13px !important;
    }
}

@media (max-width: 480px) {
    .welcome-card {
        padding: 24px 16px;
    }
    
    .welcome-container {
        min-width: auto;
        width: 100%;
    }
    
    .welcome-header {
        font-size: 16px;
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }
    
    .start-chat-btn {
        width: 100%;
        justify-content: center;
        padding: 14px 20px;
    }
    
    .message-bubble {
        padding: 10px 14px;
        font-size: 13px;
    }
    
    .input-area {
        padding: 12px;
    }
}

/* 深色模式支持 */
@media (prefers-color-scheme: dark) {
    .welcome-card {
        background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
        color: #f9fafb;
        border-color: #374151;
    }
    
    .bot-message .message-bubble {
        background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
        color: #f9fafb;
        border-color: #374151;
    }
    
    .input-area {
        background: linear-gradient(180deg, #111827 0%, #1f2937 100%);
        border-color: #374151;
    }
    
    .input-container {
        background: #1f2937;
        border-color: #374151;
    }
    
    textarea {
        color: #f9fafb;
    }
    
    textarea::placeholder {
        color: #6b7280;
    }
}

/* 无侧栏布局样式 */
.no-sidebar {
    flex-direction: column;
}

.no-sidebar .sidebar {
    display: none;
}

.no-sidebar .main-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 0;
}

.no-sidebar .chat-header {
    justify-content: center;
    position: relative;
}

.no-sidebar .header-content {
    display: flex;
    align-items: center;
    gap: 16px;
}

.no-sidebar .new-chat-btn-header {
    position: absolute;
    right: 24px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0.1) 100%);
    border: 1px solid rgba(0, 0, 0, 0.3);
    color: white;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.no-sidebar .new-chat-btn-header:hover {
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.2) 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

@media (max-width: 768px) {
    .no-sidebar .main-content {
        padding: 0 16px;
    }
    
    .no-sidebar .new-chat-btn-header {
        right: 16px;
        padding: 8px 12px;
        font-size: 13px;
    }
}

/* 减少动画模式支持 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .welcome-header span {
        animation: none;
    }
    
    .typing-dot {
        animation: none;
    }
}

/* 焦点可见性增强 */
.new-chat-btn:focus-visible,
.start-chat-btn:focus-visible,
.send-btn:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

textarea:focus-visible {
    outline: none;
}

/* 选择文本样式 */
::selection {
    background: rgba(37, 99, 235, 0.2);
    color: inherit;
}

/* 滚动行为优化 */
.chat-messages {
    scroll-behavior: smooth;
}

/* 加载状态优化 */
.message-bubble:empty {
    min-height: 20px;
    display: flex;
    align-items: center;
}