/* ========== 基础重置与变量 ========== */
:root {
    /* 微信风格配色 */
    --wechat-green: #07C160;
    --wechat-dark: #1A1A1A;
    --wechat-gray: #888888;
    --wechat-light: #EDEDED;
    --wechat-white: #FFFFFF;
    --wechat-blue: #3A7BFF;
    --wechat-red: #FF3B30;
    
    /* 渐变 */
    --gradient-primary: linear-gradient(135deg, #07C160 0%, #06AD56 100%);
    --gradient-dark: linear-gradient(135deg, #2C2C2C 0%, #1A1A1A 100%);
    
    /* 阴影 */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);
    
    /* 圆角 */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    
    /* 字体 */
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    --font-size-xs: 11px;
    --font-size-sm: 13px;
    --font-size-md: 15px;
    --font-size-lg: 17px;
    --font-size-xl: 20px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background: var(--wechat-dark);
    color: var(--wechat-white);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    position: fixed;
    top: 0;
    left: 0;
}

/* ========== 应用容器 ========== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 480px;
    margin: 0 auto;
    background: var(--wechat-dark);
    position: relative;
}

/* ========== 顶部导航栏 ========== */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--wechat-dark);
    border-bottom: 0.5px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
    height: 56px;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.menu-btn, .icon-btn {
    background: none;
    border: none;
    color: var(--wechat-white);
    font-size: 20px;
    padding: 8px;
    cursor: pointer;
}

.chat-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--wechat-white);
}

/* ========== 聊天区域 ========== */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--wechat-dark);
}

.messages-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    scroll-behavior: smooth;
}

.messages-wrapper::-webkit-scrollbar {
    width: 4px;
}

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

.messages-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

/* ========== 消息样式 ========== */
.message {
    display: flex;
    margin-bottom: 16px;
    animation: messageSlide 0.3s ease-out;
}

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

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

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

.message.system-message {
    justify-content: center;
}

.message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: var(--font-size-md);
    line-height: 1.5;
    word-wrap: break-word;
}

.user-message .message-content {
    background: var(--wechat-green);
    color: var(--wechat-white);
    border-bottom-right-radius: 4px;
}

.ai-message .message-content {
    background: #2C2C2C;
    color: var(--wechat-white);
    border-bottom-left-radius: 4px;
}

.system-message .message-content {
    background: transparent;
    color: var(--wechat-gray);
    font-size: var(--font-size-sm);
    text-align: center;
    padding: 8px 16px;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin: 0 8px;
    flex-shrink: 0;
    overflow: hidden;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-message .message-avatar {
    order: 2;
}

.ai-message .message-avatar {
    order: 0;
}

.message-time {
    font-size: var(--font-size-xs);
    color: var(--wechat-gray);
    margin-top: 4px;
    text-align: right;
}

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

/* ========== 快速回复按钮 ========== */
.quick-replies {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    overflow-x: auto;
    background: var(--wechat-dark);
    border-top: 0.5px solid rgba(255, 255, 255, 0.1);
}

.quick-btn {
    flex-shrink: 0;
    background: #2C2C2C;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--wechat-white);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.quick-btn:active {
    background: var(--wechat-green);
    transform: scale(0.95);
}

/* ========== 输入区域 ========== */
.chat-input {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: #2C2C2C;
    border-top: 0.5px solid rgba(255, 255, 255, 0.1);
    gap: 8px;
}

.input-icon {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
}

#messageInput {
    flex: 1;
    background: #3A3A3A;
    border: none;
    border-radius: var(--radius-md);
    padding: 12px 16px;
    color: var(--wechat-white);
    font-size: var(--font-size-md);
    outline: none;
}

#messageInput::placeholder {
    color: var(--wechat-gray);
}

.send-btn {
    background: var(--wechat-green);
    border: none;
    color: var(--wechat-white);
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: var(--font-size-md);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.send-btn:active {
    background: #06AD56;
    transform: scale(0.95);
}

.send-btn:disabled {
    background: #3A3A3A;
    color: var(--wechat-gray);
}

/* ========== 表情面板 ========== */
.emoji-panel {
    position: absolute;
    bottom: 70px;
    left: 0;
    right: 0;
    background: #2C2C2C;
    border-top: 0.5px solid rgba(255, 255, 255, 0.1);
    padding: 16px;
    z-index: 50;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 12px;
}

.emoji-grid button {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.emoji-grid button:active {
    background: rgba(255, 255, 255, 0.1);
}

/* ========== 侧边菜单 ========== */
.side-menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
}

.menu-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.menu-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    background: var(--wechat-dark);
    padding: 24px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

.side-menu:not(.hidden) .menu-content {
    transform: translateX(0);
}

.menu-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.menu-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    overflow: hidden;
}

.menu-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.menu-info h2 {
    font-size: var(--font-size-xl);
    font-weight: 600;
}

.menu-info p {
    font-size: var(--font-size-sm);
    color: var(--wechat-gray);
    margin-top: 4px;
}

.menu-nav {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.menu-nav a {
    color: var(--wechat-white);
    text-decoration: none;
    font-size: var(--font-size-lg);
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: color 0.2s;
}

.menu-nav a:hover {
    color: var(--wechat-green);
}

/* ========== 状态面板 ========== */
.status-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
}

.panel-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.panel-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    background: var(--wechat-dark);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.panel-header span {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    color: var(--wechat-gray);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
}

.panel-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.status-section {
    margin-bottom: 24px;
}

.status-section h3 {
    font-size: var(--font-size-md);
    color: var(--wechat-gray);
    margin-bottom: 12px;
}

/* 情绪条 */
.emotion-bars, .personality-bars {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.emotion-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.emotion-label {
    font-size: var(--font-size-sm);
    width: 60px;
    color: var(--wechat-gray);
}

.emotion-bar-bg {
    flex: 1;
    height: 8px;
    background: #3A3A3A;
    border-radius: 4px;
    overflow: hidden;
}

.emotion-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.emotion-value {
    font-size: var(--font-size-xs);
    width: 30px;
    text-align: right;
    color: var(--wechat-gray);
}

/* 日常状态 */
.daily-status {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.daily-item {
    background: #2C2C2C;
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
}

.daily-item .label {
    color: var(--wechat-gray);
    margin-bottom: 4px;
}

.daily-item .value {
    color: var(--wechat-white);
    font-weight: 500;
}

/* ========== 设置弹窗 ========== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    width: 90%;
    max-width: 400px;
    max-height: 85vh;
    background: var(--wechat-dark);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.settings-section {
    margin-bottom: 24px;
}

.settings-section h3 {
    font-size: var(--font-size-md);
    color: var(--wechat-green);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(7, 193, 96, 0.3);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: var(--font-size-sm);
    color: var(--wechat-gray);
    margin-bottom: 8px;
}

.input-field {
    width: 100%;
    background: #2C2C2C;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    color: var(--wechat-white);
    font-size: var(--font-size-md);
    outline: none;
    transition: border-color 0.2s;
}

.input-field:focus {
    border-color: var(--wechat-green);
}

.select-field {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.toggle-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toggle-switch {
    position: relative;
    width: 48px;
    height: 28px;
    background: #3A3A3A;
    border-radius: 14px;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
}

.toggle-group input:checked + .toggle-switch {
    background: var(--wechat-green);
}

.toggle-group input:checked + .toggle-switch::after {
    transform: translateX(20px);
}

.avatar-upload {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.current-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid var(--wechat-green);
}

.current-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.hint {
    font-size: var(--font-size-xs);
    color: var(--wechat-gray);
}

.connection-status {
    margin-top: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    text-align: center;
}

.connection-status.success {
    background: rgba(7, 193, 96, 0.2);
    color: var(--wechat-green);
}

.connection-status.error {
    background: rgba(255, 59, 48, 0.2);
    color: var(--wechat-red);
}

.connection-status.loading {
    background: rgba(58, 123, 255, 0.2);
    color: var(--wechat-blue);
}

/* ========== 按钮样式 ========== */
.btn {
    width: 100%;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-md);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--wechat-green);
    color: white;
}

.btn-primary:hover {
    background: #06AD56;
}

.btn-secondary {
    background: #2C2C2C;
    color: var(--wechat-white);
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 8px;
}

.btn-danger {
    background: rgba(255, 59, 48, 0.2);
    color: var(--wechat-red);
    border: 1px solid rgba(255, 59, 48, 0.3);
}

.btn-danger:hover {
    background: rgba(255, 59, 48, 0.3);
}

/* ========== 加载动画 ========== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 400;
    gap: 20px;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--wechat-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    color: var(--wechat-gray);
    font-size: var(--font-size-md);
}

/* ========== 工具类 ========== */
.hidden {
    display: none !important;
}

/* ========== 打字动画 ========== */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--wechat-gray);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ========== 滚动条美化 ========== */
::-webkit-scrollbar {
   width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ========== 响应式优化 ========== */
@media (max-height: 700px) {
    .chat-header {
        height: 48px;
        padding: 10px 16px;
    }
    
    .chat-input {
        padding: 8px 16px;
    }
    
    .quick-replies {
        padding: 8px 16px;
    }
}

/* ========== 深色模式优化 ========== */
@media (prefers-color-scheme: light) {
    :root {
        --wechat-dark: #F5F5F5;
        --wechat-white: #FFFFFF;
        --wechat-gray: #888888;
    }
    
    .message-content.ai-message {
        background: white;
        color: #333;
        box-shadow: var(--shadow-sm);
    }
}