/* ============================================
   SoulChat 移动端改造专用样式表
   版本：v1.0
   说明：此文件为移动端 UI 改造新增样式，
   不修改原有 styles.css 的任何内容。
   ============================================ */

/* ============================================
   1. 移动端两栏分离式布局
   ============================================ */

/* 通讯录页面 - 默认全屏显示 */
.contact-list-page {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-white);
    display: flex;
    flex-direction: column;
    z-index: 10;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* 聊天页面 - 初始隐藏，全屏覆盖 */
.chat-page {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    z-index: 20;
    transition: transform 0.3s ease, opacity 0.3s ease;
    /* 键盘弹出时由 JS 动态设置 height 和 position */
    will-change: height, position;
}

/* 键盘弹出时，聊天页面由 JS 控制高度 */
body.keyboard-active .chat-page {
    /* 高度由 JS 动态设为 visualViewport.height，页面自然缩短 */
    transition: none;
}


/* 键盘弹出时，消息区域需要减少底部 padding */
body.keyboard-active .chat-page-messages {
    padding-bottom: 8px; /* 键盘弹出时减少底部 padding */
}

/* 键盘弹出时，输入栏固定在底部 */
body.keyboard-active .mobile-input-bar {
    position: relative; /* 保持 flex 布局中的自然位置 */
    bottom: 0;
}

/* 键盘弹出时，确保输入框不被键盘遮挡 */
body.keyboard-active .mobile-input {
    max-height: 80px; /* 键盘弹出时限制输入框最大高度，避免撑开布局 */
}


/* ============================================
   2. 通讯录页面 - 品牌标题
   ============================================ */
.mobile-brand-title {
    text-align: center;
    font-size: 30px;
    font-weight: 600;
    color: #F9A26C;
    letter-spacing: 0.5px;
    padding: 12px 0 4px 0;
    padding-top: calc(12px + var(--safe-top));
    line-height: 1.2;
    flex-shrink: 0;
    background: var(--bg-white);
}

/* ============================================
   3. 通讯录页面 - 顶部搜索栏
   ============================================ */
.mobile-search-top {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    gap: 8px;
    flex-shrink: 0;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
}

.mobile-search-bar {
    flex: 1;
    position: relative;
}

.mobile-search-input {
    width: 100%;
    height: 48px;
    padding: 0 16px;
    border: none;
    border-radius: 24px;
    background: #F0F0F0;
    font-size: 15px;
    color: var(--text);
    outline: none;
    transition: background 0.2s;
}

.mobile-search-input:focus {
    background: #E8E8E8;
}

.mobile-search-input::placeholder {
    color: #BBB;
    font-size: 15px;
}

/* 橙色加号按钮 - 直径36px */
.mobile-btn-add {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    color: #FFF;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.2s;
}

.mobile-btn-add:hover {
    background: var(--primary-hover);
}

.mobile-btn-add:active {
    transform: scale(0.92);
}

/* ============================================
   3. 通讯录页面 - 角色列表
   ============================================ */
.mobile-role-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.mobile-role-items {
    padding: 4px 0;
}

/* 角色项 - 高度72px */
.mobile-role-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    height: 72px;
    cursor: pointer;
    transition: background 0.15s;
    gap: 12px;
    border-bottom: 1px solid #F5F5F5;
}

.mobile-role-item:hover {
    background: #F9F9F9;
}

.mobile-role-item:active {
    background: var(--primary-light);
}

.mobile-role-item.active {
    background: var(--primary-light);
}

/* 角色头像 - 48px */
.mobile-role-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-role-avatar-img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.mobile-role-avatar-text {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 500;
}

/* 角色信息 */
.mobile-role-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mobile-role-name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mobile-role-preview {
    font-size: 13px;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mobile-role-time {
    font-size: 11px;
    color: #BBB;
    flex-shrink: 0;
    align-self: flex-start;
    margin-top: 2px;
}

/* ============================================
   4. 通讯录页面 - 底部设置按钮
   ============================================ */
.mobile-bottom-settings {
    flex-shrink: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    padding-bottom: var(--safe-bottom);
}

.mobile-btn-settings {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.mobile-btn-settings:hover {
    background: #F0F0F0;
}

.mobile-btn-settings:active {
    background: #E8E8E8;
}

.mobile-hamburger {
    font-size: 24px;
    line-height: 1;
    font-weight: 700;
}

/* ============================================
   5. 聊天页面 - 顶部栏（高度56px）
   ============================================ */
.chat-page-topbar {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 56px;
    padding: 0 12px;
    padding-top: var(--safe-top);
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: relative;
    z-index: 25;
}

.chat-page-back {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(calc(-50% + var(--safe-top) / 2));
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chat-page-back:hover {
    background: #F0F0F0;
}

.chat-page-back:active {
    background: #E8E8E8;
}

.chat-page-role-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-page-menu-wrapper {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(calc(-50% + var(--safe-top) / 2));
}

.chat-page-menu-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chat-page-menu-btn:hover {
    background: #F0F0F0;
}

.chat-page-menu-btn:active {
    background: #E8E8E8;
}

/* 三点菜单浮层 */
.chat-page-dropdown {
    position: absolute;
    top: 40px;
    right: 0;
    background: var(--bg-white);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    min-width: 160px;
    z-index: 100;
    overflow: hidden;
}

.chat-page-dropdown-item {
    display: block;
    width: 100%;
    padding: 14px 16px;
    border: none;
    background: transparent;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

.chat-page-dropdown-item:hover {
    background: #F5F5F5;
}

.chat-page-dropdown-item:first-child {
    border-bottom: 1px solid var(--border);
}

/* ============================================
   6. 聊天页面 - 消息区域
   ============================================ */
.chat-page-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
    display: flex;
    flex-direction: column;
    gap: 2px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* ============================================
   7. 移动端底部输入栏（新布局）
   布局：输入框 | [+] | 发送
   ============================================ */
.mobile-input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    padding-bottom: calc(8px + var(--safe-bottom));
    background: var(--bg-white);
    border-top: 1px solid #F0F0F0;
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 25;
}

.mobile-input {
    flex: 1;
    min-width: 0;
    min-height: 40px;
    max-height: 100px;
    padding: 8px 14px;
    border: none;
    border-radius: 20px;
    background: #F5F5F5;
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    outline: none;
    resize: none;
    line-height: 1.4;
    transition: background 0.2s;
}

.mobile-input:focus {
    background: #EFEFEF;
}

.mobile-input::placeholder {
    color: #BBB;
}

/* 加号按钮容器 */
.mobile-plus-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.mobile-plus-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.mobile-plus-btn:hover {
    background: #F0F0F0;
}

.mobile-plus-btn:active {
    background: #E8E8E8;
}

/* 加号浮层 */
.mobile-plus-menu {
    position: absolute;
    bottom: 48px;
    right: 0;
    background: #FFF;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    padding: 6px 0;
    min-width: 140px;
    z-index: 30;
}

.mobile-plus-menu-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: transparent;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

.mobile-plus-menu-item:hover {
    background: #F5F5F5;
}

.mobile-plus-menu-item:active {
    background: #EEEEEE;
}

/* 发送按钮 */
.mobile-send-btn {
    width: 60px;
    height: 40px;
    border: none;
    border-radius: 20px;
    background: #F9A26C;
    color: #FFF;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, opacity 0.2s;
}

.mobile-send-btn:hover {
    background: #E8915C;
}

.mobile-send-btn:active {
    background: #D4814D;
}

.mobile-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 深色模式适配 */
body.dark-mode .mobile-input-bar {
    background: #1E1E1E;
    border-top-color: #333;
}

body.dark-mode .mobile-input {
    background: #2A2A2A;
    color: #E0E0E0;
}

body.dark-mode .mobile-input:focus {
    background: #333;
}

body.dark-mode .mobile-plus-btn {
    color: #AAA;
}

body.dark-mode .mobile-plus-menu {
    background: #2A2A2A;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

body.dark-mode .mobile-plus-menu-item {
    color: #E0E0E0;
}

body.dark-mode .mobile-plus-menu-item:hover {
    background: #333;
}

/* 加号按钮容器（旧版，保留兼容） */
.chat-page-plus-wrapper {
    position: relative;
}

.chat-page-plus-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.chat-page-plus-btn:hover {
    background: #F0F0F0;
}

.chat-page-plus-btn:active {
    background: #E8E8E8;
}

/* 加号浮层 */
.chat-page-plus-menu {
    position: absolute;
    bottom: 48px;
    right: 0;
    background: var(--bg-white);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    min-width: 140px;
    z-index: 100;
    overflow: hidden;
}

.chat-page-plus-menu-item {
    display: block;
    width: 100%;
    padding: 14px 16px;
    border: none;
    background: transparent;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

.chat-page-plus-menu-item:hover {
    background: #F5F5F5;
}

/* 发送按钮 */
.chat-page-send {
    width: 60px;
    height: 40px;
    border: none;
    border-radius: 20px;
    background: var(--primary);
    color: #FFF;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s;
}

.chat-page-send:hover {
    background: var(--primary-hover);
}

.chat-page-send:active {
    transform: scale(0.95);
}

.chat-page-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ============================================
   8. 页面切换动画
   ============================================ */

/* 从右侧滑入 */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* 向左侧滑出 */
@keyframes slideOutLeft {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(-100%);
        opacity: 0;
    }
}

/* 从下方滑入 */
@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* 向下滑出 */
@keyframes slideDown {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(100%);
        opacity: 0;
    }
}

/* 动画 CSS 类 */
.animate-slide-in-right {
    animation: slideInRight 0.3s ease forwards;
}

.animate-slide-out-left {
    animation: slideOutLeft 0.3s ease forwards;
}

.animate-slide-up {
    animation: slideUp 0.3s ease forwards;
}

.animate-slide-down {
    animation: slideDown 0.3s ease forwards;
}

/* ============================================
   9. 移动端响应式适配（max-width: 767px）
   ============================================ */
@media (max-width: 767px) {
    /* 通讯录页面全屏 */
    .contact-list-page {
        width: 100%;
        height: 100%;
    }

    /* 聊天页面固定全屏 */
    .chat-page {
        width: 100%;
        height: 100vh;
        height: 100dvh;
    }

    /* 底部输入栏 sticky 定位 */
    .chat-page-inputbar {
        position: sticky;
        bottom: 0;
    }

    /* 消息气泡最大宽度90% */
    .chat-page-messages .message-bubble {
        max-width: 90%;
    }

    /* 安全区适配 */
    .mobile-search-top {
        padding-top: calc(8px + env(safe-area-inset-top, 0px));
    }

    .chat-page-topbar {
        padding-top: env(safe-area-inset-top, 0px);
        height: calc(56px + env(safe-area-inset-top, 0px));
    }

    .chat-page-inputbar {
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }

    .mobile-bottom-settings {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .chat-page-messages {
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
}

/* ============================================
   10. PC端样式（min-width: 768px）
   ============================================ */
@media (min-width: 768px) {
    /* 通讯录页面宽度260px */
    .contact-list-page {
        position: relative;
        width: 260px;
        min-width: 260px;
        height: 100%;
        border-right: 1px solid var(--border);
    }

    /* 聊天页面flex自适应 */
    .chat-page {
        position: relative;
        flex: 1;
        height: 100%;
    }

    /* 三栏并排显示 */
    #app {
        display: flex;
        flex-direction: row;
        width: 100%;
        height: 100%;
    }

    /* PC端隐藏移动端返回按钮 */
    .chat-page-back {
        display: none !important;
    }

    /* PC端隐藏语音图标（使用PC端专用按钮） */
    .chat-page-tool-btn {
        display: none !important;
    }

    /* PC端隐藏加号按钮 */
    .chat-page-plus-wrapper {
        display: none !important;
    }

    /* PC端发送按钮宽度80px */
    .chat-page-send {
        width: 80px;
    }

    /* PC端安全区适配 */
    .chat-page-topbar {
        padding-top: 0;
        height: 56px;
    }

    .chat-page-inputbar {
        padding-bottom: 8px;
    }

    .mobile-bottom-settings {
        padding-bottom: 0;
    }
}

/* ============================================
   11. iOS 安全区适配（通用）
   ============================================ */
@supports (padding-top: env(safe-area-inset-top)) {
    .mobile-search-top {
        padding-top: calc(8px + env(safe-area-inset-top, 0px));
    }

    .chat-page-topbar {
        padding-top: env(safe-area-inset-top, 0px);
        height: calc(56px + env(safe-area-inset-top, 0px));
    }

    .chat-page-inputbar {
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }

    .mobile-bottom-settings {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .chat-page-messages {
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
}

/* ============================================
   12. 消息气泡样式增强
   ============================================ */
.chat-page-messages .message {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    width: 100%;
    margin-bottom: 2px;
    position: relative;
    margin-top: 28px;
}

.chat-page-messages .message:first-child {
    margin-top: 0;
}

.chat-page-messages .message.user {
    flex-direction: row-reverse;
    align-self: flex-end;
}

.chat-page-messages .message.ai {
    flex-direction: row;
    align-self: flex-start;
}

/* 消息头像 */
.chat-page-messages .message-avatar-wrapper {
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 50%;
    line-height: 0;
}

.chat-page-messages .message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* 消息气泡 - 自适应宽度，达到容器85%才换行 */
.chat-page-messages .message-bubble {
    padding: 10px 14px;
    font-size: 15px;
    line-height: 1.5;
    overflow-wrap: break-word;
    word-wrap: break-word;
    max-width: 90%;
    white-space: pre-wrap;
    display: inline-block;
    box-sizing: border-box;
}

.chat-page-messages .message.user .message-bubble {
    background: #F0F0F0;
    color: var(--text);
    border-radius: 16px 16px 4px 16px;
}

.chat-page-messages .message.ai .message-bubble {
    background: var(--primary);
    color: #FFF;
    border-radius: 16px 16px 16px 4px;
}

/* AI回复耗时标签：显示在气泡右下角 */
.chat-page-messages .response-time-badge {
    display: inline-block;
    font-size: 11px;
    color: rgba(255,255,255,0.7);
    margin-left: 6px;
    vertical-align: middle;
    white-space: nowrap;
}

/* 时间戳 */
.chat-page-messages .message-timestamp {
    text-align: center;
    font-size: 12px;
    color: var(--text-light);
    padding: 8px 0;
    width: 100%;
    position: absolute;
    top: -28px;
    left: 0;
}

/* 正在输入指示器 */
.chat-page-messages .typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
    margin-left: 40px;
}

.chat-page-messages .typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.chat-page-messages .typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.chat-page-messages .typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

.chat-page-messages .typing-indicator span:nth-child(3) {
    animation-delay: 0s;
}

/* ============================================
   13. 深色模式适配
   ============================================ */
body.dark-mode .mobile-search-input {
    background: #2A2A4A;
    color: #E0E0E0;
}

body.dark-mode .mobile-role-item:hover {
    background: #1E2A4A;
}

body.dark-mode .mobile-role-item.active {
    background: #2A1A0E;
}

body.dark-mode .chat-page-messages .message.user .message-bubble {
    background: #2A2A4A;
    color: #E0E0E0;
}

body.dark-mode .chat-page-input {
    background: #2A2A4A;
    border-color: #3A3A5A;
    color: #E0E0E0;
}

body.dark-mode .chat-page-input:focus {
    border-color: var(--primary);
    background: #1E2A4A;
}

body.dark-mode .mobile-bottom-settings {
    background: rgba(22, 33, 62, 0.9);
}

body.dark-mode .chat-page-dropdown {
    background: #16213E;
}

body.dark-mode .chat-page-dropdown-item:hover {
    background: #1E2A4A;
}

body.dark-mode .chat-page-plus-menu {
    background: #16213E;
}

body.dark-mode .chat-page-plus-menu-item:hover {
    background: #1E2A4A;
}

/* ============================================
   14. 滚动条美化
   ============================================ */
.mobile-role-list::-webkit-scrollbar,
.chat-page-messages::-webkit-scrollbar {
    width: 3px;
}

.mobile-role-list::-webkit-scrollbar-track,
.chat-page-messages::-webkit-scrollbar-track {
    background: transparent;
}

.mobile-role-list::-webkit-scrollbar-thumb,
.chat-page-messages::-webkit-scrollbar-thumb {
    background: #DDD;
    border-radius: 2px;
}

/* ============================================
   15. 工具类
   ============================================ */
.mobile-hidden {
    display: none !important;
}

.mobile-visible {
    display: flex !important;
}

/* 防止页面滚动 */
body.mobile-chat-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* ============================================
   16. 移动端键盘适配增强
   ============================================ */

/* 当键盘弹出时，聊天页面高度由 JS 动态控制 */
.keyboard-active .chat-page {
    /* 高度由 JS 通过 style.height 动态设置 */
    /* 保留原有的 transform/opacity transition，追加 height transition */
    transition: transform 0.3s ease, opacity 0.3s ease, height 0.1s ease, bottom 0.1s ease;
}

/* 输入框聚焦时的安全区域 */
.mobile-input:focus {
    /* 确保输入框在键盘弹出时可见 */
    scroll-margin-bottom: 120px;
}

/* 聊天消息区域底部留出足够空间，防止被输入栏遮挡 */
.chat-page-messages {
    padding-bottom: calc(16px + var(--safe-bottom));
}

/* 确保消息区域在键盘弹出时仍可滚动查看历史消息 */
.keyboard-active .chat-page-messages {
    padding-bottom: calc(80px + var(--safe-bottom));
}

/* 防止 iOS 上输入框被放大镜/预测文字遮挡 */
.mobile-input {
    -webkit-user-modify: read-write-plaintext-only;
}

/* ============================================
   iOS 输入法悬浮气泡遮挡修复
   ============================================ */

/**
 * 修复 iOS 输入法「来自剪贴板」悬浮气泡遮挡输入框的问题
 * 
 * 问题现象：
 * - iOS 设备上，当剪贴板存有网址（如 soulchat.hk）时
 * - 点击输入框唤起输入法，系统自动弹出悬浮预览气泡
 * - 气泡层级高于页面输入框，遮挡输入文字与光标
 * 
 * 修复策略（三层防御）：
 * 1. CSS 层：提升输入框 z-index，确保不被气泡遮挡
 * 2. JS 层：聚焦时清空剪贴板（从源头消除触发条件）
 * 3. 兜底层：引导提示文案
 */

/* 方案1-CSS: 提升输入框层级 */
.mobile-input {
    position: relative;
    z-index: 100;
}

/* 输入框聚焦时，输入栏背景更亮，视觉上更突出 */
.mobile-input:focus {
    box-shadow: 0 0 0 2px rgba(249, 162, 108, 0.3);
}

/* 深色模式适配 */
body.dark-mode .mobile-input:focus {
    box-shadow: 0 0 0 2px rgba(249, 162, 108, 0.4);
}

/**
 * 方案3-兜底: 引导提示浮层
 * 当用户被气泡遮挡时，提示点击空白处可消除
 */
.ios-clipboard-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: #FFF;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    z-index: 9999;
    white-space: nowrap;
    animation: iosToastFadeIn 0.3s ease, iosToastFadeOut 0.3s ease 2.7s forwards;
    pointer-events: none;
    max-width: 90%;
    text-align: center;
}

@keyframes iosToastFadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes iosToastFadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* 防止 Android 上输入框被键盘预测栏遮挡 */
@media (max-width: 767px) {
    .mobile-input-bar {
        /* 使用 safe-area-inset-bottom 确保在 iPhone X+ 上不被 Home Indicator 遮挡 */
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        /* 使用 constant 作为 fallback */
        padding-bottom: calc(8px + constant(safe-area-inset-bottom, 0px));
    }

    /* 当键盘弹出时，聊天页面高度自适应（动态视口） */
    .chat-page {
        height: 100vh;
        height: 100dvh;
    }
}

/* 深色模式适配 */
body.dark-mode .mobile-input-bar {
    background: var(--bg-white);
    border-top-color: #333;
}

/* ============================================
   17. 防止页面被键盘顶起时内容错位
   ============================================ */
/* 注意：body 保持 position: fixed 不变，由 JS 动态调整 chat-page 的高度 */
body.keyboard-active {
    /* 仅标记状态，不改变布局 */
}



