/* 主样式文件 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
}

:root {
    /* 主题颜色 */
    --primary-color: #4A8BDF;
    --secondary-color: #3A7BC8;
    --text-color: #333333;
    --light-bg: #f5f5f5;
    --border-color: #e0e0e0;
    --sent-bubble: #4A8BDF;
    --received-bubble: #FFFFFF;
    --online-color: #4CAF50;
    --offline-color: #F44336;
    
    /* 安全区域变量 */
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
}

html {
    height: 100%;
}

body {
    background-color: var(--light-bg);
    height: 100%;
    overflow: hidden;
    color: var(--text-color);
    box-sizing: border-box;
}
/* 主容器 */
.main-container {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* 欢迎界面 */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 20px;
    text-align: center;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
}

.welcome-title {
    font-size: 28px;
    color: white;
    margin-bottom: 20px;
}

.welcome-btn {
    padding: 12px 32px;
    background: white;
    color: var(--primary-color);
    border: none;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

/* 聊天界面 */
#chatScreen {
    display: none;
    height: 100%;
    flex-direction: column;
}

/* 头部 */
.chat-header {
    background-color: var(--primary-color);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    z-index: 1000;
}

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

.back-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
}

.header-title {
    font-size: 18px;
    font-weight: 500;
}

/* 用户状态 */
.user-status {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.network-status {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.network-status.online {
    background-color: var(--online-color);
}

.network-status.offline {
    background-color: var(--offline-color);
}

.user-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.user-dropdown {
    position: absolute;
    top: 45px;
    right: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    min-width: 180px;
    overflow: hidden;
    display: none;
    z-index: 2000;
}

/* 聊天列表页 */
.chat-list-page {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-list-container {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 20px;
    min-height: 0;
}

.chat-item {
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

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

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

.chat-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-members {
    font-size: 12px;
    color: #666;
}

.chat-code {
    background: rgba(74, 139, 223, 0.1);
    color: var(--primary-color);
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 500;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #666;
}

/* 底部操作 */
.bottom-actions {
    padding: 12px 16px;
    padding-bottom: calc(12px + var(--safe-area-inset-bottom, 0px));
    background: var(--light-bg);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.action-btn {
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* 聊天详情页 */
.chat-detail-page {
    display: none;
    flex-direction: column;
    height: 100%;
}

.messages-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    min-height: 0;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 20px 16px 80px;
    display: flex;
    flex-direction: column;
}

/* 消息样式 */
.message {
    max-width: 70%;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
}

.message.received {
    align-self: flex-start;
}

.message.sent {
    align-self: flex-end;
}

.message-sender {
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

.message.sent .message-sender {
    text-align: right;
}

.message-content {
    padding: 10px 14px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.4;
    font-size: 15px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.message.received .message-content {
    background-color: var(--received-bubble);
    border-top-left-radius: 4px;
}

.message.sent .message-content {
    background-color: var(--sent-bubble);
    border-top-right-radius: 4px;
    color: white;
}

.message-time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
}

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

.message.sent .message-time {
    text-align: right;
}

/* 输入区域 */
.input-area {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid var(--border-color);
    padding: 12px 16px;
    padding-bottom: calc(12px + var(--safe-area-inset-bottom, 0px));
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1000;
    flex-shrink: 0;
}
.input-wrapper {
    flex: 1;
    display: flex;
    background: white;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.message-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 12px 16px;
    font-size: 16px;
    background: transparent;
}

.send-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.send-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.attach-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attach-btn:hover {
    color: var(--secondary-color);
}

.hidden-file-input {
    display: none;
}

.message-media {
    margin-top: 6px;
    max-width: 100%;
}

.message-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 12px;
    object-fit: cover;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.message-image:hover {
    opacity: 0.9;
}

.message-file-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(74, 139, 223, 0.1);
    color: var(--primary-color);
    text-decoration: none;
    border-radius: 12px;
    font-size: 14px;
}

.message-file-link:hover {
    background: rgba(74, 139, 223, 0.2);
}

.message.sent .message-image {
    border-top-right-radius: 4px;
}

.message.received .message-image {
    border-top-left-radius: 4px;
}

.message.sent .message-file-link {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.message.sent .message-file-link:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 菜单 */
.menu-container {
    position: relative;
}

.menu-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    padding: 8px 0;
    min-width: 60px;
}

.menu-dropdown {
    position: absolute;
    bottom: 45px;
    left: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    min-width: 120px;
    overflow: hidden;
    display: none;
    z-index: 2000;
}

/* 下拉菜单项 */
.dropdown-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-color);
}

.dropdown-item:hover {
    background: var(--light-bg);
}

/* 滚动条样式 */
.chat-list-container::-webkit-scrollbar,
.messages-container::-webkit-scrollbar {
    width: 4px;
}

.chat-list-container::-webkit-scrollbar-track,
.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.chat-list-container::-webkit-scrollbar-thumb,
.messages-container::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 2px;
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 3000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

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

.modal-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    text-align: center;
}

.modal-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 20px;
}

.modal-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.modal-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 6px;
}

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

.modal-btn.secondary {
    background: #f0f0f0;
    color: #666;
}

/* ========== 左侧导航栏样式 ========== */
.desktop-sidebar {
    display: none;
    width: 60px;
    min-width: 60px;
    background: #f8f9fa;
    border-right: 1px solid var(--border-color);
    flex-direction: column;
    align-items: center;
    padding-top: 20px;
    gap: 8px;
    z-index: 100;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.sidebar-item {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    cursor: pointer;
    color: #888;
    font-size: 20px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.sidebar-item:hover {
    background: rgba(74, 139, 223, 0.1);
    color: var(--primary-color);
}

.sidebar-item:active {
    transform: scale(0.9);
    transition: transform 0.1s ease;
}

.sidebar-item.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 8px rgba(74, 139, 223, 0.3);
}

.sidebar-item.active::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 0 3px 3px 0;
}

/* 页面切换动画 */
.chat-list-page,
.chat-detail-page {
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.page-slide-out {
    opacity: 0;
    transform: translateX(-20px);
}

.page-slide-in {
    opacity: 1;
    transform: translateX(0);
}

/* ========== 二维码相关样式 ========== */
.qr-code-container {
    text-align: center;
    margin: 20px 0;
}

.qr-code-container canvas,
.qr-code-container img {
    margin: 0 auto;
    border-radius: 8px;
}

.qr-code-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    justify-content: center;
}

.qr-code-actions .modal-btn {
    display: flex;
    align-items: center;
    gap: 6px;
}

.invite-code-display {
    font-size: 20px;
    color: var(--primary-color);
    letter-spacing: 2px;
    margin-bottom: 10px;
    font-weight: 600;
}

.qr-hint {
    font-size: 12px;
    color: #666;
    margin-top: 8px;
}

/* ========== 扫码加入按钮样式 ========== */
.join-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.join-options .modal-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.scan-area {
    text-align: center;
    padding: 20px 0;
}

.scan-area video {
    border-radius: 12px;
    max-width: 100%;
}

.scan-area .scan-hint {
    margin-top: 12px;
    color: #666;
    font-size: 13px;
}
