/* Custom styles for sidebar chat */

/* Message styles */
.message {
    max-width: 85%;
    margin-bottom: 16px;
    animation: fadeInUp 0.3s ease-out;
}

.message.user {
    margin-left: auto;
}

.message.assistant {
    margin-right: auto;
}

.message-content {
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.user .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: #f8f9fa;
    color: #2d3748;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
    text-align: center;
}

.message.user .message-time {
    text-align: right;
}

.message.assistant .message-time {
    text-align: left;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: #f8f9fa;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    max-width: 85%;
    margin-right: auto;
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
}

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

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

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

/* Status indicator */
.status-dot {
    transition: all 0.3s ease;
}

.status-dot.connected {
    background-color: #10b981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}

.status-dot.disconnected {
    background-color: #ef4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

.status-dot.loading {
    background-color: #f59e0b;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Input area */
#messageInput {
    transition: height 0.2s ease;
    min-height: 44px;
    max-height: 120px;
    overflow-y: auto;
    resize: none;
}

/* Hide scrollbar for messageInput */
#messageInput::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}

#messageInput::-webkit-scrollbar-thumb {
    background: transparent;
}

#messageInput:focus {
    outline: none;
}

/* Send button inside input */
#sendBtn, #stopBtnInside {
    z-index: 10;
    transition: all 0.2s ease;
}

#sendBtn:not(:disabled):hover {
    background-color: #2563eb;
    transform: scale(1.05);
}

#sendBtn:not(:disabled):active {
    transform: scale(0.95);
}

#sendBtn:disabled {
    background-color: #9ca3af;
    opacity: 0.6;
}

/* Stop button inside input */
#stopBtnInside:not(:disabled):hover {
    background-color: #dc2626;
    transform: scale(1.05);
}

#stopBtnInside:not(:disabled):active {
    transform: scale(0.95);
}

/* Character counter positioning */
#charCounter {
    z-index: 10;
    background: rgba(255, 255, 255, 0.8);
    padding: 1px 4px;
    border-radius: 4px;
    backdrop-filter: blur(4px);
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.message.user {
    animation: slideInRight 0.3s ease-out;
}

.message.assistant {
    animation: slideInLeft 0.3s ease-out;
}

/* Scrollbar styling */
#chatMessages::-webkit-scrollbar {
    width: 6px;
}

#chatMessages::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

#chatMessages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

#chatMessages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Button hover effects */
button {
    transition: all 0.2s ease;
}

button:hover {
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

/* Save button states */
#saveBtn:not(:disabled):hover {
    background-color: #e5e7eb;
}

#saveBtn.saving {
    color: #f59e0b;
    cursor: wait;
    animation: pulse 1s infinite;
}

#saveBtn.saved {
    color: #10b981;
}

#saveBtn.error {
    color: #ef4444;
}

/* Clear button styles */
#clearBtn:not(:disabled):hover {
    background-color: #fef2f2;
    color: #dc2626;
}

#clearBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Stop button styles */
#stopBtn {
    transition: all 0.2s ease;
}

#stopBtn:not(:disabled):hover {
    background-color: #dc2626;
    transform: translateY(-1px);
}

#stopBtn:active {
    transform: translateY(0);
}

#stopBtn.hidden {
    display: none !important;
}

/* Responsive design */
@media (max-width: 400px) {
    .message {
        max-width: 95%;
    }
    
    header {
        padding: 12px 16px;
    }
    
    footer {
        padding: 16px;
    }
    
    .message-content {
        padding: 10px 12px;
    }
}

/* Error message styling */
.error-message {
    background: #fee2e2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 12px 16px;
    border-radius: 12px;
    margin: 16px 0;
    font-size: 14px;
    animation: fadeInUp 0.3s ease-out;
}

/* Welcome message animation */
.welcome-message {
    animation: fadeInUp 0.5s ease-out;
}

/* Copy button */
.copy-btn {
    opacity: 0;
    transition: opacity 0.2s ease;
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.1);
    border: none;
    border-radius: 4px;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    background: rgba(0, 0, 0, 0.2);
}

.copy-btn svg {
    width: 14px;
    height: 14px;
    color: #6b7280;
}

/* Model selector styles */
#modelSelect {
    transition: all 0.2s ease;
    font-size: 13px;
}

#modelSelect:hover {
    border-color: #6b7280;
}

#modelSelect:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

#modelSelect:disabled {
    background-color: #f9fafb;
    color: #9ca3af;
    cursor: not-allowed;
}

/* Model selector info text */
#modelInfo {
    font-style: italic;
}

/* Footer model selector area */
footer .mb-3 {
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 8px;
}

footer #modelSelect {
    max-width: 300px;
}

.bottom-2-custom {
    bottom: 12px;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    footer .mb-3 {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    footer #modelSelect {
        min-width: 150px;
        max-width: 100%;
    }
    
    /* Adjust input layout for mobile */
    #messageInput {
        padding-right: 3rem; /* Reduce right padding on mobile */
    }
    
    #sendBtn, #stopBtnInside {
        right: 0.5rem; /* Mobile: slightly more padding from edge */
    }
    
    #charCounter {
        font-size: 10px; /* Smaller font */
        left: 0.5rem;
    }
}

@media (max-width: 400px) {
    .message {
        max-width: 95%;
    }
    
    header {
        padding: 12px 16px;
    }
    
    footer {
        padding: 16px;
    }
    
    .message-content {
        padding: 10px 12px;
    }
    
    /* Further mobile optimizations */
    #sendBtn, #stopBtnInside {
        width: 2rem; /* 32px */
        height: 2rem; /* 32px */
        right: 0.25rem;
    }
    
    #sendBtn svg, #stopBtnInside svg {
        width: 1rem;
        height: 1rem;
    }
    
    #stopBtn {
        width: 2.5rem; /* 40px */
        height: 2.5rem; /* 40px */
    }
}

/* Chat History Sidebar Styles */
#chatSidebar {
    transition: transform 0.3s ease;
}

.chat-history-item {
    transition: all 0.2s ease;
    position: relative;
}

.chat-history-item:hover {
    background-color: #f8f9fa;
    border-left: 3px solid #3b82f6;
}

.chat-history-item .delete-btn {
    transition: all 0.2s ease;
}

.chat-history-item:hover .delete-btn {
    opacity: 1;
}

.chat-history-item.active {
    background-color: #eff6ff;
    border-left: 3px solid #3b82f6;
}

.chat-history-item.active .title {
    color: #1e40af;
    font-weight: 600;
}

/* Sidebar Toggle Button */
#sidebarToggle {
    transition: all 0.2s ease;
}

#sidebarToggle:hover {
    background-color: #f3f4f6;
    transform: translateY(-1px);
}

/* New Chat Button */
#newChatBtn {
    transition: all 0.2s ease;
}

#newChatBtn:hover {
    background-color: #dbeafe;
    color: #1e40af;
    transform: translateY(-1px);
}

/* History List Scrollbar */
#chatHistoryList::-webkit-scrollbar {
    width: 4px;
}

#chatHistoryList::-webkit-scrollbar-track {
    background: #f8f9fa;
    border-radius: 2px;
}

#chatHistoryList::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 2px;
}

#chatHistoryList::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Mobile responsive for sidebar */
@media (max-width: 768px) {
    /* 移动端主布局调整 */
    main {
        flex-direction: column;
    }
    
    #chatSidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 50;
        width: 280px;
        max-width: 80vw;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }
    
    #chatSidebar:not(.hidden) {
        transform: translateX(0);
    }
    
    /* 移动端背景遮罩 */
    body.sidebar-open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 40;
        animation: fadeIn 0.3s ease;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    
    /* 确保聊天区域在移动端占满全部空间 */
    .flex-1.flex.flex-col {
        width: 100%;
        min-height: 100%;
    }
}

/* 桌面端确保侧边栏正常显示 */
@media (min-width: 769px) {
    #chatSidebar.hidden {
        display: none;
    }
    
    #chatSidebar:not(.hidden) {
        display: flex;
    }
}