/* 基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6C63FF;
    --primary-dark: #5A52D5;
    --bg: #F5F5F5;
    --white: #FFFFFF;
    --text: #333333;
    --text-light: #666666;
    --border: #E0E0E0;
    --success: #4CAF50;
    --error: #F44336;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* 页面切换 */
.page {
    width: 100%;
    height: 100vh;
}

.hidden {
    display: none !important;
}

/* 登录页面 */
.login-container {
    max-width: 400px;
    margin: 0 auto;
    padding: 60px 20px;
    text-align: center;
}

.logo {
    margin-bottom: 20px;
}

.logo svg {
    filter: drop-shadow(0 4px 6px rgba(108, 99, 255, 0.3));
}

h1 {
    font-size: 28px;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-light);
    margin-bottom: 40px;
}

/* 表单 */
.input-group {
    margin-bottom: 16px;
}

.input-group label {
    display: block;
    text-align: left;
    margin-bottom: 6px;
    font-size: 14px;
    color: var(--text-light);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="url"] {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s;
}

input:focus {
    outline: none;
    border-color: var(--primary);
}

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
}

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

.chat-input-area .btn-primary {
    width: auto;
    padding: 12px 16px;
    min-width: 44px;
    min-height: 44px;
}

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

.btn-secondary {
    background: var(--border);
    color: var(--text);
}

.btn-danger {
    background: var(--danger, #dc3545);
    color: white;
}

.btn-small {
    width: auto;
    padding: 8px 16px;
    font-size: 14px;
}

.btn-icon {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-light);
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--bg);
    color: var(--primary);
}

/* 切换表单 */
.switch-form {
    margin-top: 24px;
    color: var(--text-light);
}

.switch-form a {
    color: var(--primary);
    text-decoration: none;
}

/* 主页面布局 */
#main-page {
    display: flex;
}

/* 侧边栏 */
.sidebar {
    width: 260px;
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h2 {
    font-size: 20px;
}

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

.status.connected {
    background: var(--success);
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.3);
}

.status.disconnected {
    background: var(--error);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--text-light);
    text-decoration: none;
    transition: all 0.2s;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(108, 99, 255, 0.1);
    color: var(--primary);
}

.nav-item svg {
    opacity: 0.7;
}

.nav-item.active svg {
    opacity: 1;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* 主内容区 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.page-header {
    padding: 20px 24px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.page-header h2 {
    font-size: 20px;
}

.content-page {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* 联系人列表 */
.contacts-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--white);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.contact-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* 未读消息标记 */
.unread-badge {
    background: var(--error);
    color: white;
    font-size: 12px;
    font-weight: bold;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

.contact-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
}

.contact-info {
    flex: 1;
}

.contact-name {
    font-weight: 500;
    margin-bottom: 4px;
}

.contact-url {
    font-size: 12px;
    color: var(--text-light);
}

/* 聊天面板 */
.chat-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 800px;
    height: 100vh;
    background: var(--white);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0,0,0,0.1);
}

.chat-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-title h3 {
    font-size: 16px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* 空状态和加载 */
.empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary, #999);
    font-size: 14px;
}

.empty::before {
    content: '💬';
    display: block;
    font-size: 32px;
    margin-bottom: 10px;
}

/* 加载动画 */
.loading {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary, #999);
}

.loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border, #ddd);
    border-top-color: var(--primary, #6c51ff);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
    vertical-align: middle;
}

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

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 16px;
    word-break: break-word;
}

.message.sent {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received {
    align-self: flex-start;
    background: var(--bg);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
}

.chat-input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
}

.chat-input-area input {
    flex: 1;
    padding: 12px 16px;
    font-size: 16px;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--white);
}

/* 群成员面板 */
.group-members-panel {
    position: absolute;
    right: 0;
    top: 60px;
    bottom: 70px;
    width: 280px;
    background: var(--white);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 12px rgba(0,0,0,0.1);
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.group-members-panel.hidden {
    display: none;
}

.group-members-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.group-members-header h4 {
    margin: 0;
    font-size: 16px;
}

.group-members-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.group-member-item {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.group-member-item:hover {
    background: var(--bg);
}

.group-member-item .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.group-member-item .member-info {
    flex: 1;
}

.group-member-item .member-name {
    font-size: 14px;
    font-weight: 500;
}

.group-member-item .member-portal {
    font-size: 11px;
    color: var(--text-light);
    overflow: hidden;
    text-overflow: ellipsis;
}

.group-member-item .member-badge {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--primary);
    color: white;
}

.group-member-item .btn-remove-member {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--danger, #dc3545);
    color: white;
    border: none;
    cursor: pointer;
    margin-left: auto;
}

.group-member-item .btn-remove-member:hover {
    opacity: 0.8;
}

/* 设置页 */
.settings-list {
    background: var(--white);
    border-radius: 8px;
    overflow: hidden;
}

.setting-item {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

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

.setting-item.danger {
    color: var(--error);
    cursor: pointer;
}

/* 开关 */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary);
}

input:checked + .slider:before {
    transform: translateX(24px);
}

/* 弹窗 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--white);
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    overflow: hidden;
}

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

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-light);
}

.modal form {
    padding: 20px;
}

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

.modal-actions .btn {
    flex: 1;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    z-index: 2000;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* 徽章 */
.badge {
    background: var(--error);
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: auto;
}

.badge.hidden {
    display: none;
}

/* 请求列表 */
.requests-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.request-item {
    background: var(--white);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.request-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
}

.request-info {
    flex: 1;
}

.request-name {
    font-weight: 500;
    margin-bottom: 4px;
}

.request-portal {
    font-size: 12px;
    color: var(--text-light);
}

.request-message {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 8px;
    padding: 8px;
    background: var(--bg);
    border-radius: 8px;
}

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

.request-actions .btn {
    padding: 8px 16px;
    font-size: 14px;
}

/* 匿名申请页面 */
#apply-page textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    resize: vertical;
}

#apply-page textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* Portal URL 显示 */
.portal-url {
    background: var(--bg);
    padding: 12px 16px;
    border-radius: 8px;
    font-family: monospace;
    font-size: 14px;
    color: var(--primary);
    margin-bottom: 20px;
    word-break: break-all;
}

/* 登录提示 */
.login-tips {
    margin-top: 24px;
    padding: 16px;
    background: rgba(108, 99, 255, 0.1);
    border-radius: 8px;
    text-align: left;
}

.login-tips p {
    margin: 4px 0;
    font-size: 13px;
    color: var(--text-light);
}

/* 用户信息 */
.user-details {
    display: flex;
    flex-direction: column;
}

.user-portal {
    font-size: 11px;
    color: var(--text-light);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 分享框 */
.share-box {
    background: rgba(108, 99, 255, 0.05);
    border: 1px dashed var(--primary);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

.share-box p {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 12px;
}

.share-url {
    display: flex;
    gap: 8px;
}

.share-url input {
    flex: 1;
    background: white;
}

/* 添加联系人框 */
.add-contact-box {
    background: rgba(108, 99, 255, 0.08);
    border: 1px solid var(--primary);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

.add-contact-box h3 {
    font-size: 14px;
    margin: 0 0 8px 0;
    color: var(--primary);
}

.add-contact-box p {
    font-size: 13px;
    color: var(--text-light);
    margin: 0 0 12px 0;
}

.add-contact-form {
    display: flex;
    gap: 8px;
}

.add-contact-form input {
    flex: 1;
    background: white;
}

.add-contact-message {
    font-size: 12px;
    margin-top: 8px;
    min-height: 16px;
}

.add-contact-message.success {
    color: #10b981;
}

.add-contact-message.error {
    color: #ef4444;
}

/* 设置描述 */
.setting-desc {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
}

/* 响应式 */
@media (max-width: 768px) {
    .sidebar {
        width: 200px;
    }
    
    .chat-panel {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .sidebar {
        display: none;
    }
}

/* 成员选择 */
.members-select {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
}

.member-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    cursor: pointer;
    border-radius: 4px;
}

.member-checkbox:hover {
    background: var(--bg);
}

.member-checkbox input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* 文件消息样式 */
.file-message {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 10px;
    margin: 4px 0;
}

.file-message .file-link {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.file-message .file-icon {
    font-size: 24px;
}

.file-message .file-info {
    flex: 1;
}

.file-message .file-name {
    font-weight: 500;
    word-break: break-all;
}

.file-message .file-size {
    font-size: 12px;
    opacity: 0.7;
    margin-top: 2px;
}

.image-message {
    margin: 4px 0;
}

.image-message img {
    display: block;
    max-width: 100%;
    border-radius: 8px;
}

.uploading {
    opacity: 0.7;
    font-style: italic;
}

/* 文件上传按钮 */
#file-btn {
    padding: 8px;
    margin-right: 8px;
}

#file-btn:hover {
    background: var(--bg);
}

/* 隐藏文件输入 */
#file-input {
    display: none;
}

/* ============== 通话 UI ============== */
.call-overlay {
    position: fixed;
    inset: 0;
    background: #1c1c1e;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
}
.call-overlay.hidden { display: none; }

.call-incoming-box {
    text-align: center;
    padding: 40px;
}
.call-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    margin: 0 auto 20px;
    color: white;
}
.call-peer-name {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 8px;
}
.call-status { font-size: 16px; color: rgba(255,255,255,0.7); margin-bottom: 32px; }
.call-duration { font-size: 18px; color: rgba(255,255,255,0.85); margin-top: 8px; font-variant-numeric: tabular-nums; }

.call-actions {
    display: flex;
    gap: 60px;
    justify-content: center;
    margin-top: 40px;
}
.call-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s;
}
.call-btn:hover { transform: scale(1.08); }
.call-btn-accept { background: #34c759; }
.call-btn-reject { background: #ff3b30; transform: rotate(135deg); }
.call-btn-reject:hover { transform: rotate(135deg) scale(1.08); }
.call-btn-secondary { background: rgba(255,255,255,0.18); }
.call-btn-secondary.active { background: rgba(255,255,255,0.4); }

/* 通话中视频 */
.call-remote-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}
.call-local-video {
    position: absolute;
    top: 24px;
    right: 16px;
    width: 110px;
    height: 150px;
    border-radius: 10px;
    object-fit: cover;
    background: #2a2a2a;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    z-index: 2;
}
.call-info {
    position: absolute;
    top: 32px;
    left: 24px;
    z-index: 2;
    background: rgba(0,0,0,0.45);
    padding: 12px 18px;
    border-radius: 12px;
}
.call-controls {
    position: absolute;
    bottom: 60px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 32px;
    z-index: 2;
}

/* 仅语音通话隐藏视频流(纯黑背景 + 头像中央) */
.call-overlay.audio-only .call-remote-video,
.call-overlay.audio-only .call-local-video { display: none; }
.call-overlay.audio-only .call-info { position: static; background: transparent; text-align: center; padding-top: 80px; }
.call-overlay.audio-only .call-info::before {
    content: '';
    display: block;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    margin: 0 auto 20px;
}

