/* 页面容器样式 */
.main-container {
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* 树谱页面（在 main-container 内部） */
#treePage {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    overflow: hidden;
}

#treePage.active {
    display: flex;
    flex-direction: column;
}

/* 聊天室和个人中心页面（在 main-container 外部） */
#chatConversationPage,
#settingsPage {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0; /* 覆盖全屏，包括底部导航栏 */
    display: none;
    z-index: 2000; /* 确保在底部导航栏 (通常 z-index 较低) 和统计浮层之上 */
    height: 100vh; 
    height: 100dvh; 
    background: #fff; /* 确保背景不透明 */
    /* 优化动画曲线：使滑动感更顺滑，类似 iOS/WeChat */
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    transform: translateX(100%);
    /* 添加投影，增强层级感 */
    box-shadow: -5px 0 15px rgba(0,0,0,0.1);
}

#chatConversationPage.active,
#settingsPage.active {
    display: flex;
    flex-direction: column;
    transform: translateX(0);
}

/* 页面切换动画辅助类 */
.page-sliding {
    display: flex !important; /* 强制显示以进行动画 */
}

#chatPage,
#profilePage,
#baseInfoPage,
#membershipPage,
#messagesPage,
#aboutPage,
#treeManagementPage,
#chatListPage {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 56px; /* 减去底部导航栏高度 */
    display: none;
    z-index: 10;
    height: calc(100vh - 56px); /*  fallback */
    height: calc(100dvh - 56px); /* 使用动态视口高度 */
}

#chatPage.active,
#profilePage.active,
#baseInfoPage.active,
#membershipPage.active,
#messagesPage.active,
#aboutPage.active,
#treeManagementPage.active {
    display: flex;
    flex-direction: column;
}

/* ==================== 我的页面样式 ==================== */
.profile-container {
    height: 100%;
    overflow-y: auto;
    background: #f5f5f5;
    padding-bottom: 70px; /* 留出底部导航栏空间 */
}

/* 用户信息头部 */
.profile-header {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    padding: 30px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-avatar {
    width: 70px;
    height: 70px;
    border-radius: 8px;
    overflow: hidden;
    border: 3px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

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

.user-info {
    flex: 1;
}

.user-nickname {
    font-size: 22px;
    font-weight: 600;
    color: white;
    margin: 0 0 6px 0;
}

.user-bio {
    font-size: 14px;
    opacity: 0.9;
    color: rgba(255, 255, 255, 0.9);
    margin: 0;
}

/* 功能菜单 - 仿照设置页面的卡片样式 */
.profile-section {
    padding: 20px;
}

.menu-group-title {
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.menu-list {
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    padding: 0;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 18px 20px;
    border-bottom: 1px solid #f8fafc;
    cursor: pointer;
    transition: all 0.3s;
}

.menu-item:last-child {
    border-bottom: none;
}

.menu-item:hover {
    background: #f8fafc;
}

.menu-item:active {
    background: #f1f5f9;
}

.menu-item.danger:hover {
    background: #fef2f2;
}

.menu-icon {
    font-size: 28px;
    margin-right: 16px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    border-radius: 12px;
}

.menu-item.danger .menu-icon {
    background: #fef2f2;
}

.menu-info {
    flex: 1;
}

.menu-title {
    font-size: 16px;
    color: #1e293b;
    font-weight: 600;
    margin-bottom: 4px;
}

.menu-desc {
    font-size: 13px;
    color: #64748b;
    line-height: 1.4;
}

.profile-msg-dot {
    display: none;
    width: 8px;
    height: 8px;
    background: #ff3b30;
    border-radius: 50%;
    margin-left: 6px;
    vertical-align: middle;
}

.menu-badge {
    background: #ff4444;
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 600;
    margin-right: 8px;
}

.menu-arrow {
    color: #cbd5e1;
    font-size: 24px;
    line-height: 1;
    font-weight: 300;
}

/* 二级页面容器 */
.subpage-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #f5f5f5;
}

.subpage-header {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: none;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.subpage-header h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    color: white;
}

.btn-back,
.btn-add,
.btn-edit {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-back {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(10px);
}

.btn-back:hover {
    background: rgba(255, 255, 255, 0.3);
}

.btn-add,
.btn-edit {
    background: var(--primary-color);
    color: white;
}

.btn-add:hover,
.btn-edit:hover {
    background: var(--primary-hover);
}

.edit-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.edit-actions .btn-save {
    flex: 1;
    margin-top: 0;
}

.edit-actions .btn-save:first-child {
    background: #f5f5f5;
    color: #666;
}

.edit-actions .btn-save:first-child:hover {
    background: #e0e0e0;
}

.subpage-content {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    background: #f5f5f5;
}

/* 基础信息详情 */
.info-detail-list {
    padding: 0;
    background: white;
    border-radius: 8px;
    margin: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.info-detail-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    background: white;
    transition: background 0.2s;
}

.info-detail-item:last-child {
    border-bottom: none;
}

.info-detail-item.editable:hover {
    background: #f9f9f9;
}

.info-detail-label {
    color: #666;
    font-size: 14px;
    min-width: 80px;
}

.info-detail-value {
    color: #333;
    font-weight: 500;
    flex: 1;
    text-align: right;
}

.info-detail-avatar {
    display: flex;
    align-items: center;
    gap: 12px;
}

.info-detail-avatar img {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    object-fit: cover;
    border: 2px solid #e0e0e0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* 可编辑头像 */
.editable-avatar {
    position: relative;
    cursor: pointer;
    display: inline-block;
}

.editable-avatar img {
    width: 80px;
    height: 80px;
    border-radius: 12px;
    border: 3px solid #e0e0e0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: border-color 0.3s, box-shadow 0.3s;
}

.editable-avatar:hover img {
    border-color: var(--primary-color);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.3);
}

.avatar-overlay {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(102, 126, 234, 0.9);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    transition: opacity 0.2s;
    opacity: 1;
    z-index: 1;
}

.editable-avatar:hover .avatar-overlay {
    opacity: 1;
}

/* 可编辑字段 */
.editable-value {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.editable-value:hover {
    background: rgba(102, 126, 234, 0.1);
}

.edit-icon {
    display: inline-block;
    width: 14px;
    height: 14px;
    position: relative;
    opacity: 0.5;
    vertical-align: middle;
    margin-left: 4px;
    transition: opacity 0.2s;
}
.edit-icon::before {
    content: '';
    position: absolute;
    bottom: 1px;
    left: 2px;
    width: 8px;
    height: 2px;
    background: currentColor;
    transform: rotate(-45deg);
    border-radius: 1px;
}
.edit-icon::after {
    content: '';
    position: absolute;
    top: 0;
    right: 1px;
    width: 0;
    height: 0;
    border-left: 4px solid currentColor;
    border-top: 3px solid transparent;
    border-bottom: 3px solid transparent;
    transform: rotate(-45deg);
}

.editable-value:hover .edit-icon {
    opacity: 1;
}

/* 编辑弹窗 */
.inline-edit-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.inline-edit-content {
    background: white;
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
}

.inline-edit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.inline-edit-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.btn-close-modal {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.inline-edit-body {
    margin-bottom: 20px;
}

.inline-edit-body input,
.inline-edit-body select,
.inline-edit-body textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.inline-edit-body input:focus,
.inline-edit-body select:focus,
.inline-edit-body textarea:focus {
    border-color: var(--primary-color);
}

.inline-edit-body textarea {
    resize: vertical;
    min-height: 100px;
}

.inline-edit-footer {
    display: flex;
    gap: 12px;
}

.inline-edit-footer button {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-cancel {
    background: #f5f5f5;
    color: #666;
}

.btn-cancel:hover {
    background: #e0e0e0;
}

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

.btn-confirm:hover {
    background: var(--primary-hover);
}

/* 编辑资料表单 */
.edit-form {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 14px;
    font-weight: 500;
    color: #333;
}

.form-group input,
.form-group textarea {
    padding: 12px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--primary-color);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group select {
    padding: 12px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    background: white;
}

.form-group select:focus {
    border-color: var(--primary-color);
}

.avatar-editor {
    display: flex;
    align-items: center;
    gap: 16px;
}

.avatar-editor img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e0e0e0;
}

.info-detail-avatar img {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e0e0e0;
}

.btn-upload-avatar {
    padding: 10px 20px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-upload-avatar:hover {
    background: var(--primary-hover);
}

.btn-save {
    padding: 14px 20px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 20px;
}

.btn-save:hover {
    background: var(--primary-hover);
}

/* 关于我们 */
.about-content {
    padding: 20px;
    text-align: center;
}

.about-content h3 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 10px;
}

.about-content .version {
    color: #999;
    font-size: 14px;
    margin-bottom: 20px;
}

.about-content .description {
    font-size: 16px;
    color: #666;
    margin-bottom: 30px;
}

.about-content .features {
    text-align: left;
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
}

.about-content .features h4 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
}

.about-content .features ul {
    list-style: none;
    padding: 0;
}

.about-content .features li {
    padding: 8px 0;
    color: #666;
    font-size: 14px;
}

.about-content .features li:before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 10px;
    border-right: 2px solid var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
    transform: rotate(45deg);
    margin-right: 8px;
    vertical-align: middle;
    position: relative;
    top: -1px;
}

/* 基础信息列表 */
.info-list {
    padding: 0;
}

.info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
}

.info-item:last-child {
    border-bottom: none;
}

.info-label {
    color: #666;
    font-size: 14px;
}

.info-value {
    color: #333;
    font-weight: 500;
}

/* 族谱列表 */
.tree-list {
    padding: 0;
}

.tree-item {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.2s;
}

.tree-item:last-child {
    border-bottom: none;
}

.tree-item:hover {
    background: #f9f9f9;
}

.tree-icon {
    font-size: 24px;
    margin-right: 12px;
}

.tree-info {
    flex: 1;
}

.tree-name {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 4px;
}

.tree-desc {
    font-size: 13px;
    color: #999;
}

.tree-role {
    font-size: 12px;
    padding: 4px 8px;
    background: #f0f0f0;
    border-radius: 4px;
    color: #666;
}

.tree-role.founder {
    background: #e3f2fd;
    color: #1976d2;
}

.tree-actions {
    display: flex;
    gap: 8px;
}

.btn-add-tree {
    padding: 6px 12px;
    font-size: 13px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-add-tree:hover {
    background: var(--primary-hover);
}

/* 会话列表 */
.conversation-list {
    padding: 0;
}

.conversation-item {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.2s;
}

.conversation-item:last-child {
    border-bottom: none;
}

.conversation-item:hover {
    background: #f9f9f9;
}

.conversation-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #e0e0e0;
    margin-right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.conversation-info {
    flex: 1;
    overflow: hidden;
}

.conversation-name {
    font-size: 15px;
    font-weight: 500;
    margin-bottom: 4px;
}

.conversation-last-message {
    font-size: 13px;
    color: #999;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    font-size: 12px;
    color: #999;
    margin-left: 8px;
}

.unread-badge {
    background: #ff4444;
    color: white;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

/* 设置列表 */
.settings-list {
    padding: 0;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.2s;
}

.settings-item:last-child {
    border-bottom: none;
}

.settings-item:hover {
    background: #f9f9f9;
}

.settings-item.danger {
    color: var(--danger-color);
}

.settings-label {
    font-size: 15px;
}

.settings-arrow {
    font-size: 20px;
    color: #ccc;
}

/* 空状态 */
.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: #999;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state-text {
    font-size: 14px;
}

/* ==================== 族谱管理页面样式 ==================== */
.tree-management-header {
    padding: 16px 20px;
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
}

.tree-management-header .btn-primary {
    width: 100%;
    padding: 12px 20px;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-icon {
    font-size: 18px;
}

.tree-list {
    background: #fff;
}

.tree-item {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.2s;
}

.tree-item:last-child {
    border-bottom: none;
}

.tree-item:hover {
    background: #f9f9f9;
}

.tree-item.current {
    background: #f0f4ff;
    border-left: 3px solid var(--primary-color);
}

.tree-icon {
    font-size: 24px;
    margin-right: 12px;
    flex-shrink: 0;
}

.tree-info {
    flex: 1;
    overflow: hidden;
    min-width: 0;
}

.tree-name {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-description {
    font-size: 13px;
    color: #999;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
    margin-left: 12px;
}

.tree-member-count {
    font-size: 12px;
    color: #999;
    background: #f5f5f5;
    padding: 2px 8px;
    border-radius: 10px;
}

.tree-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-left: 12px;
    flex-shrink: 0;
}

.tree-actions-row {
    display: flex;
    gap: 6px;
}

.tree-actions button {
    padding: 6px 10px;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.tree-actions .btn-switch {
    width: 100%;
    background: var(--primary-color);
    color: #fff;
}

.tree-actions .btn-switch:hover {
    background: var(--primary-hover);
}

.tree-actions .btn-edit,
.tree-actions .btn-delete {
    flex: 1;
    text-align: center;
}

.tree-actions .btn-edit {
    background: #f0f0f0;
    color: #666;
}

.tree-actions .btn-edit:hover {
    background: #e0e0e0;
}

.tree-actions .btn-delete {
    background: #fff0f0;
    color: var(--danger-color);
}

.tree-actions .btn-delete:hover {
    background: #ffe0e0;
}

/* ==================== 聊天室页面样式 ==================== */
.chat-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #f5f5f5;
    position: relative;
    -webkit-overflow-scrolling: touch; /* iOS 平滑滚动 */
}

.chat-header {
    background: white;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0; /* 防止被压缩 */
}

.chat-header h2 {
    font-size: 18px;
    font-weight: 600;
}

/* 聊天室消息样式已移至 style.css */

/* ==================== 新建族谱弹窗 ==================== */
.tree-modal .modal-content {
    width: 90%;
    max-width: 500px;
}

.tree-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 14px;
    font-weight: 500;
    color: #333;
}

.form-group input,
.form-group textarea,
.form-group select {
    padding: 12px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--primary-color);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-hint {
    font-size: 12px;
    color: #999;
}

/* 响应式适配 */
@media (max-width: 768px) {
    .user-nickname {
        font-size: 20px;
    }
    
    .user-avatar {
        width: 70px;
        height: 70px;
    }
    
    .profile-header {
        padding: 30px 16px 20px;
    }
    
    .profile-section {
        margin: 12px;
    }
    
    .section-title {
        padding: 14px 16px;
    }
    
    .info-item,
    .tree-item,
    .conversation-item,
    .settings-item {
        padding: 14px 16px;
    }
}
