* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* 防止移动端橡皮筋效果导致的页面滚动 */
    overscroll-behavior: none;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    height: 100vh;
    height: 100dvh; /* 移动端动态视口高度 */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#loginScreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.login-card {
    background: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    text-align: center;
    width: 90%;
    max-width: 400px;
}

.login-card h1 {
    font-size: 1.8rem;
    margin-bottom: 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-card p {
    color: #64748b;
    margin-bottom: 30px;
}

.login-card input {
    width: 100%;
    padding: 15px 20px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 1rem;
    margin-bottom: 20px;
    outline: none;
}

.login-card input:focus {
    border-color: #667eea;
}

.login-card button {
    width: 100%;
    padding: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

#chatScreen {
    display: none;
    flex: 1;
    flex-direction: row;
    overflow: hidden;
}

.sidebar {
    width: 240px;
    background: #f8fafc;
    border-right: 1px solid #e2e8f0;
    padding: 15px;
    overflow-y: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-title {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 8px;
    margin-bottom: 5px;
    cursor: pointer;
}

.user-item:hover {
    background: #e2e8f0;
}

.user-item.active {
    background: #667eea;
    color: white;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: bold;
}

.user-name {
    font-size: 14px;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0;
    overflow: hidden;
}

/* Resizers */
.resizer-v {
    width: 5px;
    cursor: col-resize;
    background: transparent;
    transition: background 0.2s;
}

.resizer-v:hover,
.resizer-v.dragging {
    background: #94a3b8;
}

.resizer-h {
    height: 5px;
    cursor: row-resize;
    background: #cbd5e1;
    margin: 5px 0;
    transition: background 0.2s;
    border-radius: 3px;
}

.resizer-h:hover,
.resizer-h.dragging {
    background: #94a3b8;
}

.header {
    background: white;
    padding: 15px 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-height: 0;
}

.message {
    display: flex;
    gap: 10px;
    max-width: 85%;
}

.message.self {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #667eea;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: bold;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    background: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

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

.input-area {
    background: white;
    padding: 15px 20px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    position: relative;
}

.input-area input {
    flex: 1;
    padding: 12px 18px;
    border: 2px solid #e2e8f0;
    border-radius: 25px;
    font-size: 1rem;
    outline: none;
}

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

/* @ 弹窗样式 */
#atPopup {
    z-index: 1000;
}

#atPopup .at-user-item:hover {
    background: #f1f5f9;
    cursor: pointer;
}

/* 被提及消息样式 */
.message.mentioned {
    border: 2px solid #fbbf24;
    border-radius: 12px;
    padding: 8px;
    animation: pulse 0.5s ease;
}

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

.input-area button {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
}

/* 拖拽覆盖层 */
.drop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(102, 126, 234, 0.2);
    border: 3px dashed #667eea;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #667eea;
    z-index: 100;
    border-radius: 8px;
}

.drop-overlay.active {
    display: flex;
}

/* 图片预览 */
.preview-image {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    margin: 5px 0;
    object-fit: contain;
}

/* 上传进度 */
.upload-progress {
    font-size: 12px;
    color: #666;
    margin-top: 4px;
}

/* 文件链接 */
.file-link {
    cursor: pointer;
    color: #667eea;
    text-decoration: underline;
}

.file-link:hover {
    color: #764ba2;
}

/* typing 消息样式 */
.typing-message {
    justify-content: flex-start;
    animation: fadeIn 0.3s ease;
}

.typing-content {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f1f5f9;
    border-radius: 18px;
    font-size: 0.85rem;
    color: #64748b;
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

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

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

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

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

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

/* 侧边栏切换按钮 */
#toggleSidebar {
    display: none;
    padding: 8px 12px;
    background: #f1f5f9;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
}

#toggleSidebar:hover {
    background: #e2e8f0;
}

/* 移动端适配 */
@media (max-width: 768px) {
    html, body {
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }

    #chatScreen {
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }

    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 100;
        width: 80%;
        max-width: 280px;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        transition: transform 0.3s ease;
        height: 100%;
    }

    .sidebar.collapsed {
        display: none !important;
    }

    .sidebar.collapsed + .resizer-v {
        display: none;
    }

    #toggleSidebar {
        display: block;
    }

    .resizer-v {
        display: none;
    }

    .chat-main {
        height: 100%;
        overflow: hidden;
    }

    .header {
        flex-shrink: 0;
        padding: 10px 15px;
    }

    .chat-area {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 10px;
        min-height: 0; /* 关键：允许 flex 收缩 */
    }

    .input-area {
        flex-shrink: 0;
        padding: 10px 15px;
    }

    .message {
        max-width: 95%;
    }

    .message-bubble {
        max-width: 100%;
        overflow: hidden;
        word-wrap: break-word;
        word-break: break-word;
    }

    /* Markdown 代码块横向滚动 */
    .message-bubble pre {
        overflow-x: auto;
        max-width: 100%;
        -webkit-overflow-scrolling: touch;
    }

    .message-bubble code {
        white-space: pre;
        word-break: normal;
    }
}

/* MIC 按钮 */
.mic-btn {
    background: #667eea;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.mic-btn:hover {
    background: #5a6fd6;
}

.mic-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

.mic-btn.recording {
    background: #ef4444;
    animation: pulse 1s infinite;
}

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

/* 录音指示器 */
.recording-indicator {
    position: absolute;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 100;
}

.recording-wave {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 20px;
}

.recording-wave span {
    width: 3px;
    background: #ef4444;
    border-radius: 2px;
    animation: wave 0.5s ease-in-out infinite;
}

.recording-wave span:nth-child(1) { height: 30%; animation-delay: 0s; }
.recording-wave span:nth-child(2) { height: 60%; animation-delay: 0.1s; }
.recording-wave span:nth-child(3) { height: 100%; animation-delay: 0.2s; }
.recording-wave span:nth-child(4) { height: 70%; animation-delay: 0.3s; }
.recording-wave span:nth-child(5) { height: 40%; animation-delay: 0.4s; }
.recording-wave span:nth-child(6) { height: 80%; animation-delay: 0.5s; }
.recording-wave span:nth-child(7) { height: 50%; animation-delay: 0.6s; }
.recording-wave span:nth-child(8) { height: 90%; animation-delay: 0.7s; }
.recording-wave span:nth-child(9) { height: 60%; animation-delay: 0.8s; }
.recording-wave span:nth-child(10) { height: 40%; animation-delay: 0.9s; }

@keyframes wave {
    0%, 100% { transform: scaleY(0.5); }
    50% { transform: scaleY(1); }
}

/* 语音消息波形 */
.voice-message {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 18px;
    min-width: 80px;
    max-width: 300px;
    cursor: pointer;
    box-sizing: border-box;
}

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

.voice-message.other {
    background: #e2e8f0;
    color: #1a202c;
}

/* 播放按钮 */
.voice-play-btn {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 8px;
    line-height: 1;
    color: white;
    cursor: pointer;
}

.voice-message.self .voice-play-btn {
    background: rgba(255,255,255,0.3);
    color: white;
}

.voice-message.other .voice-play-btn {
    background: rgba(0,0,0,0.2);
    color: #333;
}

.voice-play-btn.playing {
    background: transparent;
    font-size: 10px;
    color: white;
}

.voice-message.other .voice-play-btn.playing {
    color: #333;
}

/* 波形 */
.voice-wave {
    display: flex;
    align-items: center;
    gap: 1px;
    height: 16px;
    flex: 1;
    min-width: 40px;
}

.voice-wave span {
    width: 2px;
    background: #666;
    border-radius: 1px;
    opacity: 0.8;
    flex-shrink: 0;
}

.voice-message.self .voice-wave span {
    background: white;
}

/* 时长 */
.voice-duration {
    font-size: 11px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* 音频播放按钮 */
.audio-play-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: currentColor;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.audio-play-btn::after {
    content: '';
    border-style: solid;
    border-width: 5px 0 5px 8px;
    border-color: transparent transparent transparent white;
    margin-left: 2px;
}

/* 语音播放按钮 */
.voice-play-btn {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: currentColor;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 10px;
    color: white;
}

.voice-play-btn.playing {
    background: transparent;
    color: white;
    font-size: 12px;
}

/* 录音中波形动画 */
.voice-wave.recording span {
    animation: wave 0.5s ease-in-out infinite;
    background: #ef4444;
}

.voice-message.self .voice-wave.recording span {
    background: white;
}

/* 图片预览 Modal */
.image-modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.9);
    cursor: pointer;
}

.modal-content {
    margin: auto;
    display: block;
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10000;
}

.modal-close:hover,
.modal-close:focus {
    color: #bbb;
    text-decoration: none;
}
