/* ========== CSS变量定义 ========== */
:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #3a3a3a;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --accent-primary: #4a9eff;
    --accent-secondary: #6c5ce7;
    --border-color: #404040;
    --success-color: #00b894;
    --error-color: #ff7675;
    --warning-color: #fdcb6e;
}

/* ========== 全局样式重置 ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--accent-secondary);
}

/* ========== 页面过渡动画 ========== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page-enter {
    animation: fadeInUp 0.5s ease-out;
}

/* ========== 登录页面背景 ========== */
@keyframes gradientFlow {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.login-background {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(
        -45deg,
        #1a1a1a,
        #2d2d2d,
        #4a9eff,
        #6c5ce7
    );
    background-size: 400% 400%;
    animation: gradientFlow 15s ease infinite;
}

/* ========== 登录容器 ========== */
.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 40px 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.app-title {
    text-align: center;
    font-size: 2rem;
    margin-bottom: 30px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ========== 表单样式 ========== */
.auth-form h2 {
    text-align: center;
    margin-bottom: 25px;
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 20px;
}

.input-field {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 15px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}

.input-field::placeholder {
    color: var(--text-secondary);
}

.input-field:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.1);
    transform: translateY(-2px);
}

/* ========== 按钮样式 ========== */
.button {
    position: relative;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    overflow: hidden;
}

.button-primary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
}

.button-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(74, 158, 255, 0.4);
}

.button-primary:active:not(:disabled) {
    transform: translateY(0);
}

.button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 按钮波纹效果 */
@keyframes ripple {
    from {
        transform: scale(0);
        opacity: 0.6;
    }
    to {
        transform: scale(4);
        opacity: 0;
    }
}

.button::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    pointer-events: none;
}

.button:active::after {
    animation: ripple 0.6s ease-out;
}

.switch-mode {
    text-align: center;
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* ========== Toast通知 ========== */
@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateY(-100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastSlideOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-100%);
    }
}

.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 14px 24px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    z-index: 10000;
    animation: toastSlideIn 0.3s ease-out;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    max-width: 90%;
}

.toast.hide {
    animation: toastSlideOut 0.3s ease-in;
}

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--error-color);
}

.toast.info {
    background: var(--accent-primary);
}

.toast.warning {
    background: var(--warning-color);
}

/* ========== 聊天容器 ========== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ========== 好友列表 ========== */
.friend-list-container {
    width: 100%;
    height: 100%;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
}

.friend-list-header {
    padding: 20px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.friend-list-header h2 {
    font-size: 1.5rem;
    margin: 0;
}

.logout-btn {
    padding: 8px 16px;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.logout-btn:hover {
    opacity: 0.8;
    transform: scale(0.95);
}

.search-container {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
}

.search-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.3s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.1);
}

.search-results {
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-primary);
    border-radius: 8px;
    margin-top: 10px;
}

.friend-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
}

/* 好友列表项动画 */
@keyframes friendSlideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.friend-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid var(--border-color);
    animation: friendSlideIn 0.3s ease-out;
}

.friend-item:hover {
    background: var(--bg-tertiary);
    transform: translateX(5px);
}

.friend-item:active {
    transform: translateX(5px) scale(0.98);
}

.friend-item.active {
    background: var(--bg-tertiary);
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    margin-right: 15px;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
}

.avatar:hover {
    transform: scale(1.1);
}

.online-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: var(--success-color);
    border: 2px solid var(--bg-secondary);
    border-radius: 50%;
}

@keyframes onlinePulse {
    0%, 100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(0, 184, 148, 0.7);
    }
    50% {
        opacity: 0.8;
        box-shadow: 0 0 0 4px rgba(0, 184, 148, 0);
    }
}

.online-indicator {
    animation: onlinePulse 2s ease-in-out infinite;
}

.friend-info {
    flex: 1;
    min-width: 0;
}

.friend-name {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.last-message {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-badge {
    background: var(--error-color);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
    min-width: 20px;
    text-align: center;
}

@keyframes badgeBounce {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
}

.message-badge.new {
    animation: badgeBounce 0.5s ease-out;
}

/* ========== 聊天窗口 ========== */
.chat-window {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    z-index: 100;
    display: flex;
    flex-direction: column;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(100%);
    }
}

.chat-window.open {
    animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-window.close {
    animation: slideOutRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-header {
    padding: 15px 20px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 15px;
}

.back-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 8px 12px;
    transition: transform 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
}

.back-btn:hover {
    transform: scale(1.1);
}

.back-btn:active {
    transform: scale(0.95);
    background: var(--bg-secondary);
    border-radius: 8px;
}

.chat-friend-info {
    flex: 1;
}

.chat-friend-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* 消息气泡 */
@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 16px;
    word-wrap: break-word;
    animation: messageSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.message-bubble.sent {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border-bottom-right-radius: 4px;
}

.message-bubble.received {
    align-self: flex-start;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-bubble.ai {
    align-self: flex-start;
    background: var(--bg-tertiary);
    border: 2px solid var(--accent-secondary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-bubble.new {
    animation: messageSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes messageSending {
    0% {
        opacity: 0.5;
        transform: scale(0.98);
    }
    50% {
        opacity: 0.7;
        transform: scale(1);
    }
    100% {
        opacity: 0.5;
        transform: scale(0.98);
    }
}

.message-bubble.sending {
    animation: messageSending 1.5s ease-in-out infinite;
}

.message-content {
    margin-bottom: 5px;
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    text-align: right;
}

.message-image {
    max-width: 100%;
    border-radius: 8px;
    cursor: pointer;
}

@keyframes imageLoad {
    from {
        opacity: 0;
        filter: blur(10px);
    }
    to {
        opacity: 1;
        filter: blur(0);
    }
}

.message-image {
    animation: imageLoad 0.5s ease-out;
}

/* AI思考动画 */
@keyframes dotPulse {
    0%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    50% {
        opacity: 1;
        transform: scale(1.2);
    }
}

.ai-thinking {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
}

.ai-thinking span {
    width: 8px;
    height: 8px;
    background: var(--accent-secondary);
    border-radius: 50%;
    animation: dotPulse 1.4s ease-in-out infinite;
}

.ai-thinking span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-thinking span:nth-child(3) {
    animation-delay: 0.4s;
}

/* 输入栏 */
.input-container {
    padding: 15px 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.message-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 24px;
    color: var(--text-primary);
    font-size: 15px;
    resize: none;
    max-height: 120px;
    transition: all 0.3s ease;
}

.message-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.1);
}

.input-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: var(--accent-primary);
    transform: scale(1.1);
}

.send-btn {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
}

@keyframes sendButtonActive {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.9) rotate(-5deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
    }
}

.send-btn:active {
    animation: sendButtonActive 0.3s ease;
}

/* 表情包选择器 */
@keyframes emojiPickerSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.emoji-picker {
    position: absolute;
    bottom: 70px;
    right: 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 15px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
    max-width: 300px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: emojiPickerSlideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 1000;
}

.emoji {
    font-size: 28px;
    cursor: pointer;
    transition: transform 0.2s ease;
    text-align: center;
}

@keyframes emojiPop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.3);
    }
    100% {
        transform: scale(1);
    }
}

.emoji:active {
    animation: emojiPop 0.3s ease;
}

/* 图片模态框 */
@keyframes imageZoomIn {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: imageZoomIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    padding: 20px;
}

.image-modal img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
}

.close-modal {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--bg-secondary);
    border: none;
    color: white;
    font-size: 32px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.close-modal:hover {
    background: var(--error-color);
    transform: rotate(90deg);
}

/* 骨架屏加载 */
@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-secondary) 0%,
        var(--bg-tertiary) 50%,
        var(--bg-secondary) 100%
    );
    background-size: 1000px 100%;
    animation: shimmer 2s infinite linear;
    border-radius: 8px;
}

/* 上传进度 */
@keyframes uploadProgress {
    from {
        width: 0%;
    }
    to {
        width: 100%;
    }
}

.upload-progress-bar {
    height: 4px;
    background: var(--accent-primary);
    animation: uploadProgress 2s ease-out;
    border-radius: 2px;
}

@keyframes uploadPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(74, 158, 255, 0.7);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(74, 158, 255, 0);
    }
}

.uploading-indicator {
    animation: uploadPulse 1.5s ease-out infinite;
}

/* ========== 响应式设计 ========== */
@media (min-width: 768px) {
    .chat-container {
        flex-direction: row;
    }
    
    .friend-list-container {
        width: 360px;
        border-right: 1px solid var(--border-color);
    }
    
    .chat-window {
        position: relative;
        flex: 1;
        display: flex !important;
    }
    
    .back-btn {
        display: none !important;
    }
}

/* 移动端确保聊天窗口正确显示 */
@media (max-width: 767px) {
    .chat-window {
        display: flex;
    }
    
    .back-btn {
        display: inline-flex !important;
    }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

/* 性能优化 */
.animated-element {
    will-change: transform, opacity;
    transform: translateZ(0);
}

/* 隐藏元素 */
.hidden {
    display: none !important;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 16px;
}
