/* ChatGPT风格的聊天界面样式 */
/* 基础样式已在 common.css 中定义 */
body {
    background-color: #f7f7f8;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 0; /* 聊天页面不需要 padding */
    overflow: hidden; /* 防止 body 滚动，只让消息区域滚动 */
}

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: linear-gradient(135deg, #0066ff 0%, #0080ff 50%, #00bfff 100%);
    color: white;
    padding: 0.75rem 2rem; /* 减少上下 padding，降低高度 */
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header h1 {
    font-size: 1.25rem; /* 稍微减小字体，降低高度 */
    font-weight: 600;
    margin: 0; /* 确保没有额外 margin */
}

.status {
    font-size: 0.85rem; /* 稍微减小字体 */
    opacity: 0.9;
    margin-top: 0.25rem; /* 减少间距 */
}

.status.connected {
    color: #4ade80;
}

.status.disconnected {
    color: #f87171;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    margin-top: 0; /* 移除顶部 margin，因为 header 是 fixed */
    height: 100vh; /* 确保占满视口高度 */
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #f7f7f8;
    /* 添加 padding 避免被固定的 header 和 input-container 遮挡 */
    padding-top: calc(2rem + 65px); /* header 高度约 65px，增加顶部间距让消息不贴顶 */
    padding-bottom: calc(1rem + 100px); /* input-container 高度约 100px */
}

.message {
    display: flex;
    margin-bottom: 1.5rem;
    animation: fadeIn 0.3s ease-in;
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message-content {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    position: relative;
    word-wrap: break-word;
}

.message.user .message-content {
    background: linear-gradient(135deg, #0066ff 0%, #0080ff 50%, #00bfff 100%);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message.assistant .message-content {
    background: white;
    color: #333;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 0.25rem;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin: 0 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.875rem;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #0066ff 0%, #0080ff 50%, #00bfff 100%);
    color: white;
    order: 2;
}

.message.assistant .message-avatar {
    background: #f3f4f6;
    color: #6b7280;
}

.message-time {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 0.25rem;
    text-align: right;
}

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

.typing-indicator {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 1rem;
    border-bottom-left-radius: 0.25rem;
    max-width: 70%;
}

.typing-dots {
    display: flex;
    gap: 0.25rem;
}

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

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

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

.input-container {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    padding: 1rem;
    background: white;
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    /* 如果 chat-container 有最大宽度，需要居中并限制宽度 */
    width: 100%;
    max-width: 1200px;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: #f9fafb;
    border: 1px solid #d1d5db;
    border-radius: 1rem;
    padding: 0.5rem;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: #0066ff;
    box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.1);
}

.message-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    padding: 0.5rem;
    font-size: 1rem;
    resize: none;
    max-height: 120px;
    min-height: 20px;
}

.message-input::placeholder {
    color: #9ca3af;
}

.image-preview {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background: #f3f4f6;
    border-radius: 0.5rem;
}

.image-preview img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 0.25rem;
}

/* 消息中的图片样式 */
.message-image-wrapper {
    margin-top: 0.5rem;
    border-radius: 0.5rem;
    overflow: hidden;
    max-width: 100%;
}

.message-image {
    max-width: min(100%, 400px); /* 限制最大宽度为400px，但不超过容器宽度 */
    max-height: 80px; /* 减小最大高度，让图片更紧凑 */
    width: auto;
    height: auto;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
    display: block;
    object-fit: contain;
}

.message-image:hover {
    opacity: 0.9;
    transform: scale(1.01);
}

/* 图片放大模态框 */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    cursor: pointer;
    animation: fadeIn 0.2s ease;
}

.image-modal img {
    max-width: 90vw;
    max-height: 90vh;
    width: auto;
    height: auto;
    border-radius: 0.5rem;
    object-fit: contain;
    cursor: default;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

/* 音频消息样式 */
.message-audio-wrapper {
    margin-top: 0.5rem;
    width: 100%;
}

.message-audio {
    width: 100%;
    max-width: 300px;
    height: 40px;
    border-radius: 0.5rem;
}

/* 视频消息样式 */
.message-video-wrapper {
    margin-top: 0.5rem;
    width: 100%;
    border-radius: 0.5rem;
    overflow: hidden;
}

.message-video {
    width: 100%;
    max-width: 400px;
    max-height: 300px;
    border-radius: 0.5rem;
}

.image-preview button {
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    cursor: pointer;
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
}

.btn {
    padding: 0.5rem;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.btn-image {
    background: #f3f4f6;
    color: #6b7280;
}

.btn-send {
    background: linear-gradient(135deg, #0066ff 0%, #0080ff 50%, #00bfff 100%);
    color: white;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #9ca3af;
    text-align: center;
}

.empty-state h3 {
    margin-bottom: 0.5rem;
    color: #6b7280;
}

.empty-state p {
    font-size: 0.875rem;
}

.scroll-to-bottom {
    position: fixed;
    bottom: 120px; /* 调整位置，避免被固定的输入框遮挡 */
    right: 20px;
    background: #0066ff;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: all 0.2s;
    z-index: 99; /* 确保在输入框之上 */
}

.scroll-to-bottom:hover {
    background: #0052cc;
    transform: translateY(-2px);
}

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

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

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

@media (max-width: 768px) {
    .chat-container {
        height: 100vh;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .header {
        padding: 1rem;
    }
    
    .header-link {
        left: 1rem !important;
        font-size: 0.8rem !important;
        padding: 0.4rem 0.8rem !important;
    }
    
    #logoutBtn {
        right: 1rem !important;
        font-size: 0.8rem !important;
        padding: 0.4rem 0.8rem !important;
    }
    
    /* 移动端调整消息区域的 padding */
    .messages-container {
        padding-top: calc(1.5rem + 60px); /* 移动端 header 稍矮，增加顶部间距 */
        padding-bottom: calc(1rem + 90px); /* 移动端 input 稍矮 */
    }
    
    /* 移动端输入框全宽 */
    .input-container {
        max-width: 100%;
    }
}
