/**
 * QQChat 主樣式文件
 */

/* 全局樣式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #007bff;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --border-color: #dee2e6;
    --bg-color: #ffffff;
    --sidebar-bg: #f8f9fa;
    --chat-bg: #ffffff;
    --message-own-bg: #dcf8c6;
    --message-other-bg: #ffffff;
    --text-color: #212529;
    --text-muted: #6c757d;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 6px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-color);
    background-color: var(--light-color);
    padding-bottom: env(safe-area-inset-bottom);
}

/* 認證頁面 */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.auth-box {
    background: var(--bg-color);
    border-radius: 10px;
    padding: 30px;
    box-shadow: var(--shadow-lg);
}

.auth-box h1 {
    text-align: center;
    margin-bottom: 10px;
    color: var(--primary-color);
}

.auth-box .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 30px;
}

.auth-tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
}

.tab-btn {
    flex: 1;
    padding: 10px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.3s;
    position: relative;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

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

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--text-color);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-size: 14px;
    transition: border-color 0.3s;
}

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

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

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

.btn-primary:hover {
    background-color: #0056b3;
}

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

.btn-secondary:hover {
    background-color: #5a6268;
}

.error-message {
    color: var(--danger-color);
    font-size: 12px;
    margin-top: 10px;
    display: none;
}

.success-message {
    color: var(--success-color);
    font-size: 12px;
    margin-top: 10px;
    display: none;
}

/* 使用條款鏈接 */
.auth-footer {
    text-align: center;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.auth-box .auth-footer {
    margin-top: 20px;
    padding-top: 20px;
}

.auth-footer p {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0;
}

.auth-footer a {
    color: var(--primary-color);
    text-decoration: none;
}

.auth-footer a:hover {
    text-decoration: underline;
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary-color);
    text-decoration: none;
    cursor: pointer;
    font-size: 14px;
    padding: 5px 10px;
    transition: color 0.3s;
}

.btn-link:hover {
    color: #0056b3;
    text-decoration: underline;
}

/* VIP升级按钮 */
.vip-upgrade-link {
    color: #ffc107;
    font-weight: 600;
    background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
    color: #343a40;
    padding: 6px 12px;
    border-radius: 4px;
    text-decoration: none;
    display: inline-block;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(255, 193, 7, 0.3);
}

.vip-upgrade-link:hover {
    background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
    color: #343a40;
    text-decoration: none;
    box-shadow: 0 4px 8px rgba(255, 193, 7, 0.4);
    transform: translateY(-1px);
}

/* 聊天頁面 */
.chat-page {
    height: 100dvh; /* 使用动态视口高度，自动适配 Safari 工具栏 */
    overflow: hidden;
    /* 支持安全区域 */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

.chat-container {
    display: flex;
    height: 100dvh; /* 使用动态视口高度，自动适配 Safari 工具栏 */
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
}

/* 側邊欄 */
.sidebar-left,
.sidebar-right {
    width: 300px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-right {
    border-right: none;
    border-left: 1px solid var(--border-color);
}

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

.sidebar-header h2,
.sidebar-header h3 {
    font-size: 18px;
    color: var(--primary-color);
}

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

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.search-box {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
}

.search-box input {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-size: 14px;
}

.tabs {
    display: flex;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.list-header h3 {
    font-size: 14px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px 10px;
    color: var(--text-muted);
    font-size: 16px;
    transition: color 0.3s;
}

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

/* 聊天室列表 */
.rooms-list,
.friends-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.room-item,
.friend-item {
    padding: 12px;
    background-color: var(--bg-color);
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.room-item:hover,
.friend-item:hover {
    background-color: #e9ecef;
}

.room-item.active {
    background-color: #e7f3ff;
    border-left: 3px solid var(--primary-color);
}

.room-item-content {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.room-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.room-item-name {
    font-weight: 500;
    color: var(--text-color);
}

.room-item-name.restricted {
    opacity: 0.6;
    color: var(--text-muted);
}

.restriction-indicator {
    display: inline-block;
    margin-left: 4px;
    font-size: 12px;
    cursor: help;
}

.unread-badge {
    background-color: var(--danger-color);
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: bold;
}

.room-item-message {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-item-time {
    font-size: 11px;
    color: var(--text-muted);
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

/* 主聊天區域 */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--chat-bg);
    overflow: hidden;
}

.no-room-selected {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 18px;
}

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.chat-header h3 {
    font-size: 16px;
    font-weight: 500;
}

.chat-header-actions {
    display: flex;
    gap: 10px;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-color: #f0f0f0;
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    display: flex;
    gap: 10px;
    max-width: 70%;
}

.message.own {
    align-self: flex-end;
    flex-direction: row-reverse;
}

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

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

.avatar-placeholder {
    width: 100%;
    height: 100%;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.message-header {
    display: flex;
    gap: 10px;
    align-items: center;
}

.message-username {
    font-weight: 500;
    font-size: 12px;
    color: var(--text-muted);
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
}

.message-text {
    padding: 10px 15px;
    background-color: var(--message-other-bg);
    border-radius: 10px;
    word-wrap: break-word;
}

.message.own .message-text {
    background-color: var(--message-own-bg);
}

.message-image {
    max-width: 300px;
    max-height: 300px;
    border-radius: 10px;
    cursor: pointer;
}

.message-file {
    padding: 10px 15px;
    background-color: var(--message-other-bg);
    border-radius: 10px;
}

.message-file a {
    color: var(--primary-color);
    text-decoration: none;
}

.message.own .message-file {
    background-color: var(--message-own-bg);
}

/* 輸入區域 */
.chat-input-area {
    padding: 15px 20px;
    background-color: var(--bg-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    align-items: center;
}

.input-actions {
    display: flex;
    gap: 5px;
}

#messageInput {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 14px;
    outline: none;
}

#messageInput:focus {
    border-color: var(--primary-color);
}

.btn-send {
    padding: 10px 20px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
    flex-shrink: 0;
    white-space: nowrap;
    min-width: 60px;
}

.btn-send:hover {
    background-color: #0056b3;
}

/* 用戶列表 */
.users-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background-color: var(--bg-color);
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.user-item:hover {
    background-color: #e9ecef;
}

.user-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

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

.online-indicator {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background-color: var(--success-color);
    border: 2px solid white;
    border-radius: 50%;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* 在弹窗中的online indicator */
.modal .online-indicator {
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-width: 2px;
}

/* 用户选择列表中的头像包装器 */
.user-select-avatar-wrapper {
    position: relative;
    width: 36px;
    height: 36px;
    margin-right: 12px;
    flex-shrink: 0;
}

.user-select-avatar-wrapper .user-select-avatar,
.user-select-avatar-wrapper img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.user-select-avatar-wrapper .online-indicator {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background-color: var(--success-color);
    border: 2px solid white;
    border-radius: 50%;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.user-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 500;
    color: var(--text-color);
}

/* VIP徽章 */
.vip-badge {
    display: inline-block;
    padding: 2px 6px;
    margin-left: 4px;
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    color: #8b6914;
    font-size: 10px;
    font-weight: bold;
    border-radius: 3px;
    text-transform: uppercase;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    vertical-align: middle;
}

/* VIP 提醒样式 */
.vip-reminder {
    display: none;
    background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
    color: #343a40;
    padding: 12px 20px;
    margin: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    position: relative;
}

.vip-reminder.expired {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    color: #ffffff;
}

.vip-reminder-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1200px;
    margin: 0 auto;
    gap: 12px;
}

.vip-reminder-icon {
    font-size: 1.2em;
    flex-shrink: 0;
}

.vip-reminder-message {
    flex: 1;
    font-weight: 500;
    font-size: 0.95em;
}

.vip-reminder-link {
    color: inherit;
    text-decoration: underline;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
    transition: background 0.2s;
    flex-shrink: 0;
}

.vip-reminder-link:hover {
    background: rgba(255, 255, 255, 0.3);
}

.vip-reminder.expired .vip-reminder-link {
    background: rgba(255, 255, 255, 0.15);
}

.vip-reminder.expired .vip-reminder-link:hover {
    background: rgba(255, 255, 255, 0.25);
}

.vip-reminder-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 1.5em;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
    flex-shrink: 0;
}

.vip-reminder-close:hover {
    background: rgba(0, 0, 0, 0.1);
}

.vip-reminder.expired .vip-reminder-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* 移动端适配 */
@media (max-width: 768px) {
    .vip-reminder-content {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .vip-reminder-message {
        flex-basis: 100%;
        order: 1;
    }
    
    .vip-reminder-link {
        order: 2;
    }
    
    .vip-reminder-close {
        order: 3;
    }
}

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

.modal.active,
.modal[style*="display: block"],
.modal[style*="display: flex"] {
    display: flex !important;
}

.modal-content {
    background-color: var(--bg-color);
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
    max-height: calc(100dvh - 40px);
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    margin: auto;
    position: relative;
}

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

.modal-header h3 {
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
    line-height: 1;
}

.modal-close:hover {
    background-color: var(--light-color);
    color: var(--text-color);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    align-items: center;
}

.modal-footer .btn {
    min-width: 80px;
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-footer .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.users-select-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 10px;
}

.user-select-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    cursor: pointer;
}

.user-select-item:hover {
    background-color: var(--light-color);
}

/* 好友請求列表 */
.friend-requests-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.friend-request-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background-color: var(--bg-color);
    border-radius: 5px;
    border: 1px solid var(--border-color);
}

.request-actions {
    margin-left: auto;
    display: flex;
    gap: 10px;
}

.btn-sm {
    padding: 5px 15px;
    font-size: 12px;
}

.btn-success {
    background-color: var(--success-color);
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.btn-success:hover {
    background-color: #218838;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.btn-danger:hover {
    background-color: #c82333;
}

/* 搜索結果列表 */
.search-results-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 400px;
    overflow-y: auto;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background-color: var(--bg-color);
    border-radius: 5px;
    border: 1px solid var(--border-color);
}

.search-result-item .user-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.search-result-item .user-email {
    font-size: 12px;
    color: var(--text-muted);
}

.search-result-item .user-actions {
    margin-left: auto;
}

.badge {
    padding: 5px 10px;
    border-radius: 3px;
    font-size: 12px;
    display: inline-block;
}

.badge-success {
    background-color: var(--success-color);
    color: white;
}

.badge-warning {
    background-color: var(--warning-color);
    color: #212529;
}

.friend-item {
    position: relative;
}

.friend-actions {
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.3s;
}

.friend-item:hover .friend-actions {
    opacity: 1;
}

.btn-delete-friend {
    color: var(--danger-color);
    font-size: 14px;
}

.btn-delete-friend:hover {
    color: #c82333;
}

/* 好友請求徽章 */
.request-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: var(--danger-color);
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: bold;
    min-width: 18px;
    text-align: center;
    white-space: nowrap;
    max-width: calc(100vw - 20px);
    overflow: hidden;
    text-overflow: ellipsis;
}

#friendRequestsBtn {
    position: relative;
    overflow: visible;
}

/* 好友标签按钮中的请求数量徽章 */
.tab-btn .request-count-badge {
    display: inline-block;
    background-color: var(--danger-color);
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: bold;
    min-width: 18px;
    text-align: center;
    margin-left: 6px;
    vertical-align: middle;
}

/* 用戶選擇列表（創建群組） */
.users-select-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 10px;
}

.user-select-item {
    margin-bottom: 8px;
}

.user-select-item input[type="checkbox"] {
    margin-right: 12px;
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 0;
    margin-bottom: 0;
}

.user-select-item label {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 10px;
    border-radius: 5px;
    transition: background-color 0.3s;
    width: 100%;
}

.user-select-item label:hover {
    background-color: var(--hover-color);
}

/* user-select-avatar 现在在 user-select-avatar-wrapper 内定义 */

.user-select-item label span {
    flex: 1;
}

/* 移動端導航按鈕 */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1001;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 20px;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    transition: background-color 0.3s;
    touch-action: manipulation;
}

.mobile-menu-btn:hover,
.mobile-menu-btn:active {
    background-color: #0056b3;
}

.mobile-chat-back-btn {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-color);
    cursor: pointer;
    padding: 5px 10px;
    margin-right: 10px;
}

/* 響應式設計 */
@media (max-width: 768px) {
    .sidebar-left,
    .sidebar-right {
        width: 280px;
    }
    
    .message {
        max-width: 85%;
    }
    
    .chat-input-area {
        padding: 12px 15px;
    }
    
    #messageInput {
        font-size: 16px; /* 防止iOS自動縮放 */
    }
    
    .btn-send {
        padding: 12px 20px;
        font-size: 16px;
    }
    
    .modal-content {
        width: 95%;
        max-height: 90vh;
    }
}

@media (max-width: 640px) {
    /* 顯示移動端按鈕 */
    .mobile-menu-btn {
        display: block;
    }
    
    .mobile-chat-back-btn {
        display: block;
    }
    
    /* 聊天容器布局 */
    .chat-container {
        position: relative;
        height: 100dvh;
        height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        overflow: hidden;
    }
    
    /* 側邊欄默認隱藏，點擊後顯示 */
    .sidebar-left {
        position: fixed;
        top: 0;
        left: -100%;
        width: 85%;
        max-width: 320px;
        height: 100dvh;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    }
    
    .sidebar-left.mobile-open {
        left: 0;
    }
    
    /* 遮罩層 */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 999;
        touch-action: none;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    /* 右側邊欄在移動端隱藏或調整 */
    .sidebar-right {
        position: fixed;
        top: 0;
        right: -100%;
        width: 85%;
        max-width: 320px;
        height: 100dvh; /* 使用动态视口高度，自动适配 Safari 工具栏 */
        z-index: 1000;
        transition: right 0.3s ease;
        box-shadow: -2px 0 10px rgba(0,0,0,0.1);
        /* 支持安全区域 */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .sidebar-right.mobile-open {
        right: 0;
    }
    
    /* 主聊天區域全屏 */
    .chat-main {
        width: 100%;
        height: 100dvh; /* 使用动态视口高度，自动适配 Safari 工具栏 */
        height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        display: flex;
        flex-direction: column;
        overflow: hidden;
        max-width: 100vw;
    }
    
    /* 聊天頭部優化 */
    .chat-header {
        padding: 12px 15px;
        position: sticky;
        top: 0;
        z-index: 100;
        background-color: var(--bg-color);
    }
    
    .chat-header h3 {
        font-size: 16px;
        flex: 1;
        margin: 0;
    }
    
    .chat-header-actions {
        gap: 8px;
    }
    
    .btn-icon {
        padding: 8px;
        font-size: 18px;
        min-width: 40px;
        min-height: 40px;
    }
    
    /* 消息容器優化 */
    .messages-container {
        padding: 15px;
        /* 为输入框预留空间，加上安全区域底部间距 */
        padding-bottom: calc(80px + env(safe-area-inset-bottom));
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .message {
        max-width: 85%;
    }
    
    .message-avatar {
        width: 36px;
        height: 36px;
    }
    
    .message-text {
        padding: 10px 12px;
        font-size: 15px;
    }
    
    /* 輸入區域優化 */
    .chat-input-area {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        background-color: var(--bg-color);
        border-top: 1px solid var(--border-color);
        /* 确保输入框不被手机toolbar遮挡 */
        z-index: 10;
        box-sizing: border-box;
        /* 使用 transform 来动态调整位置，避免被工具栏遮挡（JavaScript 辅助） */
        transform: translateY(0);
        transition: transform 0.2s ease-out;
        will-change: transform;
    }
    
    .input-actions {
        gap: 8px;
    }
    
    .input-actions .btn-icon {
        min-width: 44px;
        min-height: 44px;
        font-size: 20px;
    }
    
    #messageInput {
        padding: 12px 15px;
        font-size: 16px; /* 防止iOS自動縮放 */
        border-radius: 25px;
        flex: 1;
        min-width: 0; /* 允许flex item缩小 */
        max-width: 100%;
        box-sizing: border-box;
        width: 100%;
    }
    
    .btn-send {
        padding: 12px 20px;
        font-size: 15px;
        border-radius: 25px;
        min-width: 60px;
        flex-shrink: 0;
        white-space: nowrap;
    }
    
    /* 列表項優化 */
    .room-item,
    .friend-item {
        padding: 15px 12px;
        min-height: 60px;
    }
    
    .user-item {
        padding: 12px;
        min-height: 56px;
    }
    
    .user-avatar {
        width: 44px;
        height: 44px;
    }
    
    /* 側邊欄頭部優化 */
    .sidebar-header {
        padding: 15px 12px;
    }
    
    .sidebar-header h2,
    .sidebar-header h3 {
        font-size: 18px;
    }
    
    /* 搜索框優化 */
    .search-box {
        margin-bottom: 12px;
    }
    
    .search-box input {
        padding: 12px;
        font-size: 16px; /* 防止iOS自動縮放 */
    }
    
    /* Tab按鈕優化 */
    .tabs {
        margin-bottom: 12px;
    }
    
    .tab-btn {
        padding: 12px;
        font-size: 15px;
        min-height: 44px;
    }
    
    /* 模態框優化 */
    .modal {
        padding: 10px;
        align-items: flex-start;
        padding-top: 5vh;
    }
    
    .modal-content {
        width: 95%;
        max-width: 95%;
        max-height: 85vh;
        border-radius: 15px;
        margin: 0 auto;
    }
    
    .modal-header {
        padding: 15px;
    }
    
    .modal-header h3 {
        font-size: 18px;
    }
    
    .modal-body {
        padding: 15px;
    }
    
    .modal-footer {
        padding: 15px;
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
        padding: 14px;
        font-size: 16px;
        margin-bottom: 10px;
    }
    
    /* 表單優化 */
    .form-group {
        margin-bottom: 20px;
    }
    
    .form-group label {
        font-size: 14px;
        margin-bottom: 8px;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 12px;
        font-size: 16px; /* 防止iOS自動縮放 */
        border-radius: 8px;
    }
    
    /* 按鈕優化 */
    .btn {
        padding: 12px 20px;
        font-size: 16px;
        min-height: 44px;
        border-radius: 8px;
    }
    
    .btn-sm {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 40px;
    }
    
    /* 認證頁面優化 */
    .auth-container {
        padding: 15px;
    }
    
    .auth-box {
        padding: 25px 20px;
    }
    
    .auth-box h1 {
        font-size: 24px;
    }
    
    /* 空狀態優化 */
    .empty-state {
        padding: 30px 15px;
        font-size: 15px;
    }
    
    /* 未讀徽章優化 */
    .unread-badge {
        padding: 4px 8px;
        font-size: 12px;
        min-width: 20px;
    }
    
    /* 用戶選擇列表優化 */
    .users-select-list {
        max-height: 250px;
    }
    
    .user-select-item label {
        padding: 12px;
        min-height: 56px;
    }
    
    .user-select-avatar-wrapper {
        width: 40px;
        height: 40px;
    }
    
    /* 额外的小屏幕优化 */
    @media (max-width: 375px) {
        .chat-header {
            padding: 10px 12px;
        }
        
        .chat-header h3 {
            font-size: 14px;
        }
        
        .btn-icon {
            min-width: 36px;
            min-height: 36px;
            font-size: 16px;
        }
        
        .message {
            max-width: 90%;
        }
        
        .message-text {
            padding: 8px 10px;
            font-size: 14px;
        }
        
        .chat-input-area {
            padding: 8px 10px;
        }
        
        #messageInput {
            padding: 10px 12px;
            font-size: 16px;
        }
        
        .btn-send {
            padding: 10px 16px;
            font-size: 14px;
            min-width: 50px;
        }
    }
    
    /* 横屏优化 */
    @media (max-height: 500px) and (orientation: landscape) {
        .chat-header {
            padding: 8px 12px;
        }
        
        .chat-header h3 {
            font-size: 14px;
        }
        
        .messages-container {
            padding: 10px 15px;
            padding-bottom: calc(70px + env(safe-area-inset-bottom));
        }
        
        .chat-input-area {
            padding: 8px 12px;
            padding-bottom: calc(8px + env(safe-area-inset-bottom));
        }
        
        #messageInput {
            padding: 8px 12px;
            font-size: 14px;
        }
        
        .btn-send {
            padding: 8px 16px;
            font-size: 14px;
        }
    }
}

/* 滾動條樣式 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--light-color);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

