/* Mobile CSS - 手机版样式 */

body {
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* CSS变量定义 - 用于动态视口适配 */
:root {
    /* 动态视口高度 - 由JavaScript设置 */
    --viewport-height: 100vh;
    --viewport-width: 100vw;
    --safe-height: 100vh;
    --usable-height: 100vh;
    
    /* safe area inset - 处理notch和折叠区 */
    --safe-area-inset-top: 0px;
    --safe-area-inset-bottom: 0px;
    --safe-area-inset-left: 0px;
    --safe-area-inset-right: 0px;
    
    /* 手机特定变量 */
    --mobile-sidebar-width: 80%;
    --mobile-sidebar-max-width: 320px;
    --mobile-panel-max-width: 420px;
    --mobile-base-font-size: 15px;
    --mobile-input-font-size: 16px;
    --mobile-button-min-height: 44px;
    --mobile-chat-input-height: 44px;
    --mobile-page-gutter: 16px;
}

/* 确保html和body占满整个视口 */
html {
    /* 使用dvh(动态视口高度) - 会自动根据浏览器UI调整 */
    /* 回退到vh，由JavaScript动态调整 */
    height: 100dvh;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}

body {
    height: var(--viewport-height);
    width: var(--viewport-width);
    margin: 0;
    padding: 0;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    
    /* 防止安卓键盘弹出时页面缩放 */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.no-scrollbar::-webkit-scrollbar { 
    display: none; 
}
.no-scrollbar { 
    -ms-overflow-style: none; 
    scrollbar-width: none; 
}

.transition-fast { 
    transition: all 0.15s ease; 
}

.chat-bubble-img {
    transition: transform 0.08s ease;
    /* 禁用 hover 效果，手机不支持 */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
}

.chat-bubble-img:active {
    transform: scale(0.98);
}

.fade-in-up {
    opacity: 0;
    transform: translateY(12px);
    animation: fadeInUp 0.4s ease forwards;
}

.panel-fade {
    opacity: 0;
    transform: translateY(8px);
    animation: fadeInUp 0.35s ease 0.1s forwards;
}

.chat-bubble {
    opacity: 0;
    transform: translateY(8px);
    animation: bubbleIn 0.25s ease forwards;
}

.sidebar-item {
    transition: background-color 0.12s ease;
    /* 移除 hover 效果 */
}

.sidebar-item:active {
    background-color: rgba(59, 130, 246, 0.1);
    transform: none;
}

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bubbleIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 手机特定优化 */
:root {
    --mobile-sidebar-width: 80%;
    --mobile-sidebar-max-width: 320px;
    --mobile-panel-max-width: 420px;
    --mobile-base-font-size: 15px;
    --mobile-input-font-size: 16px;
    --mobile-button-min-height: 44px;
    --mobile-chat-input-height: 44px;
    --mobile-page-gutter: 16px;
    --mobile-screen-width: 100vw;
    --mobile-screen-height: 100vh;
}

* {
    -webkit-tap-highlight-color: transparent; /* 禁用点击高亮 */
}

/* 登录面板 - 确保完整显示 */
#loginPanel {
    max-width: var(--mobile-panel-max-width);
    max-height: 90%;
    overflow-y: auto;
    padding-top: max(var(--mobile-page-gutter), env(safe-area-inset-top));
    padding-bottom: max(var(--mobile-page-gutter), env(safe-area-inset-bottom));
    padding-left: max(var(--mobile-page-gutter), env(safe-area-inset-left));
    padding-right: max(var(--mobile-page-gutter), env(safe-area-inset-right));
}

/* 主应用容器 */
#mainApp {
    height: var(--viewport-height) !important;
    max-height: var(--usable-height) !important;
    width: 100% !important;
    padding-top: max(0px, env(safe-area-inset-top));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
}

/* 侧边栏菜单 - 毛玻璃效果 */
#sidebarList {
    width: var(--mobile-sidebar-width) !important;
    max-width: var(--mobile-sidebar-max-width) !important;
    height: 100% !important;
    background: rgba(248, 250, 252, 0.7) !important;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    background-blend-mode: overlay;
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.1);
    padding-top: max(0px, env(safe-area-inset-top));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
}

/* 聊天输入框 - 确保不被键盘遮挡 */
#messageInput {
    font-size: var(--mobile-input-font-size) !important;
    min-height: var(--mobile-chat-input-height);
    /* 防止iOS双击缩放 */
    user-select: text;
    -webkit-user-select: text;
}

/* 聊天框 - 完整高度占用 */
#chatBox {
    height: auto;
    flex: 1 1 auto;
}

/* 侧边栏内容优化 */
#listContent {
    padding: 0.5rem !important;
}

#listContent > div {
    padding: 0.5rem !important;
    font-size: 14px !important;
}

/* 侧边栏遮罩 */
#sidebarOverlay {
    background-color: rgba(15, 23, 42, 0.15) !important;
}

button, [role="button"] {
    -webkit-appearance: none;
    appearance: none;
    min-height: var(--mobile-button-min-height); /* iOS 推荐的触摸区域大小 */
    min-width: 44px;
}

input {
    -webkit-appearance: none;
    appearance: none;
    font-size: var(--mobile-input-font-size); /* 防止 iOS 自动放大 */
}

/* 禁用长按菜单 */
img {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* 未读消息徽章 - 移动端样式 */
.unread-badge {
    position: absolute;
    top: 0;
    right: 0;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
    animation: badgePulse 0.6s ease-out;
    border: 2px solid white;
}

/* 相对定位用于徽章 */
.sidebar-item {
    position: relative;
}

/* 新消息分隔线 - 移动端 */
.new-message-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 10px 0;
    opacity: 0.6;
    animation: fadeInDivider 0.3s ease-out;
}

.new-message-divider::before,
.new-message-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(to right, transparent, #ef4444 50%, transparent);
}

.new-message-divider span {
    font-size: 11px;
    font-weight: 600;
    color: #ef4444;
    white-space: nowrap;
}
