/* =========================================
   Chat Components - 紫白极简风格
   沉浸式手机聊天App设计
   ========================================= */

/* =========================================
   聊天室容器 - 全屏沉浸式
   ========================================= */

.chat-room {
    position: fixed;
    inset: 0;
    background: var(--bg-color);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

@supports (height: 100dvh) {
    .chat-room {
        height: 100dvh;
    }
}

/* =========================================
   顶部栏 - 角色存在感提示区
   ========================================= */

.chat-header {
    position: sticky;
    top: 0;
    height: calc(var(--header-height) + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    display: flex;
    align-items: center;
    padding-left: var(--space-3);
    padding-right: var(--space-4);
    background: transparent;
    border-bottom: none;
    flex-shrink: 0;
    z-index: 10;
    border-radius: 0 0 24px 24px; 
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    margin-bottom: 0;
}

/* 左侧包裹区（返回 + 头像 + 名称状态） */
.chat-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 1;
    min-width: 0;
}

/* 返回按钮 */
.chat-header .back-btn {
    min-width: var(--touch-target);
    height: var(--touch-target);
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--primary-dark);
    margin-right: 0;
    background: transparent;
    box-shadow: none;
}

.chat-header .back-btn:active {
    background: rgba(167, 139, 250, 0.15);
    transform: scale(0.95);
}

.chat-header .back-btn i {
    font-size: 24px;
}

/* 角色信息区域 */
.chat-header-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}

/* 角色头像 */
.chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.15);
    border: 2px solid var(--white);
}

.chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 角色名称与状态 */
.chat-header-details {
    flex: 1;
    min-width: 0;
}

.chat-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: #1a1a2e;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.chat-status {
    font-size: var(--font-size-xs);
    color: #666;
    display: flex;
    align-items: center;
    gap: var(--space-1);
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.chat-status .online-dot {
    width: 6px;
    height: 6px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: pulse-dot 2s ease-in-out infinite;
}

.chat-status-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    flex: 1;
}

.chat-status.is-typing .chat-status-text {
    color: var(--primary-dark);
    font-weight: 600;
    letter-spacing: 0.3px;
}

.chat-status.is-typing .online-dot {
    background: #10b981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* 右侧操作按钮区 */
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: transparent;
    border-radius: 999px;
    padding: 0;
    box-shadow: none;
}

/* 圆形触控按钮 */
.header-action-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--primary-color);
    background: transparent;
}

.header-action-btn:active {
    background: rgba(167, 139, 250, 0.15);
    transform: scale(0.95);
}

.header-action-btn i {
    font-size: 20px;
    stroke-width: 1.5;
}

/* 选择模式下的头部 */
.chat-header.select-mode {
    background: transparent;
}

.chat-header.select-mode .chat-title {
    color: #8B5CF6;
}

.btn-delete-selected {
    padding: var(--space-2) var(--space-4);
    background: #ef4444;
    color: white;
    border: none;
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-delete-selected:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-delete-selected:not(:disabled):active {
    transform: scale(0.95);
}

/* =========================================
   聊天内容区 - 可滚动消息区域
   ========================================= */

.chat-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: calc(var(--radius-lg) + var(--space-4)) var(--space-4) calc(var(--space-4) + 72px + env(safe-area-inset-bottom));
    background: transparent;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    position: relative;
}

/* 支持背景壁纸 - 使用伪元素避免透明问题 */
.chat-body[style*="background-image"]::before {
    content: '';
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-image: inherit;
    opacity: 0.5;
    z-index: -1;
}

.chat-body[style*="background-image"] {
    background: rgba(255, 255, 255, 0.7);
}

/* =========================================
   时间戳样式
   ========================================= */

.timestamp-container {
    display: flex;
    justify-content: center;
    padding: var(--space-3) 0;
}

.timestamp-text {
    background: rgba(var(--primary-color-rgb), 0.12);
    color: var(--primary-dark);
    font-size: var(--font-size-xs);
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-weight: 500;
}

/* =========================================
   消息行布局
   ========================================= */

.message-row {
    display: flex;
    width: 100%;
    align-items: flex-start;
    gap: var(--space-2);
    animation: messageIn 0.3s ease-out;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 左侧消息 (AI) */
.message-row.left {
    flex-direction: row;
    padding-right: var(--space-10);
}

/* 右侧消息 (用户) */
.message-row.right {
    flex-direction: row-reverse;
    padding-left: var(--space-10);
}


/* =========================================
   头像样式
   ========================================= */

.avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.12);
    align-self: flex-start;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar.avatar-circle,
.avatar.avatar-circle img {
    border-radius: 50%;
}

/* 隐藏连续消息的头像 */
.message-row.consecutive .avatar {
    visibility: hidden;
}

/* =========================================
   气泡样式 - 紫白配色
   ========================================= */

.bubble {
    position: relative;
    padding: var(--space-3) var(--space-4);
    max-width: 100%;
    border-radius: var(--radius-xl);
    font-size: var(--font-size-base);
    line-height: 1.6;
    word-wrap: break-word;
    word-break: break-word;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

.bubble.image-bubble {
    padding: 6px;
    background: transparent;
    border: none;
    box-shadow: none;
}

.bubble.image-bubble img {
    max-width: 220px;
    max-height: 220px;
    width: auto;
    height: auto;
    border-radius: var(--radius-md);
    display: flex-end;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.2);
}

.message-row.right .bubble.image-bubble {
    background: transparent;
}

/* 连续消息的气泡间距 */
.bubble + .bubble {
    margin-top: var(--space-1);
}

/* 左侧气泡 (AI) - 白色底 */
.message-row.left .bubble {
    background: var(--white);
    color: #1a1a2e;
    border-top-left-radius: var(--radius-sm);
    box-shadow: 0 2px 12px rgba(139, 92, 246, 0.08);
    border: 1px solid rgba(167, 139, 250, 0.1);
}

/* 右侧气泡 (用户) - 柔和紫色 */
.message-row.right .bubble {
    background: var(--user-bubble-bg);
    color: var(--user-bubble-text);
    border-top-right-radius: var(--radius-sm);
    box-shadow: 0 2px 12px rgba(var(--primary-color-rgb), 0.2);
}

/* 气泡按压效果 */
.bubble:active {
    transform: scale(0.98);
}

/* 禁止小三角箭头 */
.bubble::before,
.bubble::after {
    display: none;
}

/* =========================================
   多种气泡风格
   ========================================= */

/* 圆润风格 */
.bubble.bubble-style-rounded {
    border-radius: var(--radius-2xl);
    padding: var(--space-3) var(--space-5);
}

.message-row.left .bubble.bubble-style-rounded {
    border-top-left-radius: var(--radius-md);
}

.message-row.right .bubble.bubble-style-rounded {
    border-top-right-radius: var(--radius-md);
}

/* 简约风格 */
.bubble.bubble-style-minimal {
    border-radius: var(--radius-lg);
    box-shadow: none;
    border: none;
}

.message-row.left .bubble.bubble-style-minimal {
    background: rgba(255, 255, 255, 0.9);
}

.message-row.right .bubble.bubble-style-minimal {
    background: rgba(var(--primary-color-rgb), 0.8);
}

/* 渐变风格 */
.bubble.bubble-style-gradient {
    border-radius: var(--radius-xl);
}

.message-row.left .bubble.bubble-style-gradient {
    background: linear-gradient(135deg, #FFFFFF 0%, rgba(var(--primary-color-rgb), 0.05) 100%);
}

.message-row.right .bubble.bubble-style-gradient {
    background: var(--user-bubble-bg);
}

/* =========================================
   Markdown 内容样式
   ========================================= */

.bubble p {
    margin: 0 0 var(--space-2) 0;
}

.bubble p:last-child {
    margin: 0;
}

.bubble ul,
.bubble ol {
    margin: var(--space-2) 0;
    padding-left: var(--space-5);
}

.bubble li {
    margin-bottom: var(--space-1);
}

.bubble pre {
    background: rgba(139, 92, 246, 0.08);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: var(--space-2) 0;
    font-size: var(--font-size-sm);
}

.bubble code {
    background: rgba(139, 92, 246, 0.1);
    padding: 2px 6px;
    border-radius: var(--radius-xs);
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 0.9em;
}

.bubble pre code {
    background: none;
    padding: 0;
}

/* 用户气泡内代码块 */
.message-row.right .bubble code {
    background: rgba(255, 255, 255, 0.3);
}

.message-row.right .bubble pre {
    background: rgba(255, 255, 255, 0.2);
}

/* =========================================
   思考过程气泡
   ========================================= */

.bubble.thinking {
    background: linear-gradient(135deg, rgba(167, 139, 250, 0.08) 0%, rgba(139, 92, 246, 0.05) 100%);
    border: 1px solid rgba(167, 139, 250, 0.2);
    color: #666;
}

.thinking-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--primary-dark);
    margin-bottom: var(--space-2);
    font-weight: 500;
}

.thinking-indicator i {
    color: var(--primary-color);
    animation: thinking-pulse 2s ease-in-out infinite;
}

@keyframes thinking-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.95); }
}

.thinking-content {
    font-style: italic;
    font-size: var(--font-size-sm);
    line-height: 1.5;
    color: #666;
}

/* =========================================
   语音消息样式
   ========================================= */

.bubble.audio {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 100px;
    max-width: 200px;
    cursor: pointer;
    padding: var(--space-3) var(--space-4);
}

.bubble.audio:hover {
    opacity: 0.9;
}

.audio-icon {
    width: 24px;
    height: 24px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%238B5CF6'%3E%3Cpath d='M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02z'/%3E%3C/svg%3E") no-repeat center;
    background-size: contain;
    flex-shrink: 0;
    animation: audio-wave 1.5s ease-in-out infinite;
}

@keyframes audio-wave {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.audio-duration {
    font-size: var(--font-size-xs);
    color: #666;
    margin-left: auto;
}

/* =========================================
   选择模式
   ========================================= */

.chat-body.select-mode .message-row {
    padding-left: var(--space-10);
    position: relative;
}

.msg-checkbox {
    position: absolute;
    left: var(--space-2);
    top: 50%;
    transform: translateY(-50%);
    width: var(--touch-target);
    height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.msg-checkbox i {
    font-size: 22px;
    transition: all 0.2s ease;
    color: var(--primary-color);
}

.message-row.selected {
    background: rgba(var(--primary-color-rgb), 0.1);
    border-radius: var(--radius-lg);
    margin: var(--space-1) 0;
    padding: var(--space-2);
}

/* =========================================
   底部输入区域 - 整体胶囊组件
   ========================================= */

.footer-layout {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    padding: var(--space-3) var(--space-4);
    padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
    flex-shrink: 0;
    border-top: none;
    border-radius: 0;
    box-shadow: none;
    margin-top: 0;
    z-index: 10;
}

/* 引用消息预览 */
.reply-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-2);
    background: rgba(var(--primary-color-rgb), 0.1);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--primary-dark);
}

/* 图片预览 */
.image-preview {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    margin-bottom: var(--space-2);
    background: rgba(var(--primary-color-rgb), 0.08);
    border-radius: var(--radius-md);
    border: 1px solid rgba(167, 139, 250, 0.2);
    max-width: 80%;
}

.image-preview img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.15);
}

.image-preview-remove {
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--primary-dark);
}

.image-preview-remove:active {
    transform: scale(0.95);
}

.reply-content {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: #666;
    flex: 1;
    overflow: hidden;
}

.reply-content i {
    color: var(--primary-dark);
    font-size: 16px;
    flex-shrink: 0;
}

.reply-content span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 输入栏 - 整体胶囊 */
.footer-input-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.input-bar {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--white);
    border-radius: 30px;
    padding: 6px 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    border: none;
    transition: all 0.2s ease;
}

.input-bar:focus-within {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

/* 键盘弹出时让输入区整体上移并预留底部安全区 */
@supports (height: 100dvh) {
    .footer-layout {
        padding-bottom: calc(max(var(--space-3), env(safe-area-inset-bottom)) + env(keyboard-inset-height, 0px));
    }

    .chat-body {
        padding-bottom: calc(var(--space-4) + 72px + env(safe-area-inset-bottom) + env(keyboard-inset-height, 0px));
    }
}

.chat-room:has(.chat-input:focus) .footer-layout {
    padding-bottom: calc(max(var(--space-3), env(safe-area-inset-bottom)) + env(keyboard-inset-height, 0px));
}

/* 图标按钮 - 圆形触控区 */
.icon-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.mic-btn {
    background: transparent;
}

.mic-btn:active {
    background: transparent;
    transform: scale(0.95);
}

.mic-btn svg path {
    fill: var(--primary-color);
}

.input-bar .icon-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    background: transparent;
}

.icon-btn:active {
    background: rgba(167, 139, 250, 0.15);
    transform: scale(0.95);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

.icon-btn svg path {
    fill: var(--primary-color);
    transition: fill 0.2s ease;
}

.icon-btn:hover svg path {
    fill: var(--primary-dark);
}

/* 点击的是圆形触控区而非图标本体 */
.icon-btn svg,
.icon-btn svg path,
.icon-btn i {
    pointer-events: none;
}

/* 文本输入框（仅承载文字，背景与圆角归属容器） */
.chat-input {
    flex: 1;
    min-width: 0;
    min-height: 40px;
    max-height: 140px;
    border: none;
    outline: none;
    background: transparent;
    font-family: inherit;
    font-size: var(--font-size-base);
    line-height: 1.5;
    padding: var(--space-2) 0;
    resize: none;
    color: #1a1a2e;
    border-radius: 0;
    overflow-y: auto;
    width: 100%;
    white-space: pre-wrap;
    word-break: break-word;
    caret-color: var(--primary-dark);
}

.chat-input::placeholder {
    color: #999;
}

.chat-input::-webkit-scrollbar {
    width: 0;
    height: 0;
}

/* 加号按钮 */
.plus-btn i {
    font-size: 22px;
    color: var(--primary-color);
    transition: color 0.2s ease;
}

.plus-btn:active i {
    color: var(--primary-dark);
}

/* =========================================
   更多功能面板
   ========================================= */

.more-panel {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
    padding: var(--space-5) var(--space-2);
    animation: panelIn 0.25s ease-out;
    background: var(--white);
    border-radius: var(--radius-xl);
    box-shadow: 0 -4px 16px rgba(139, 92, 246, 0.08);
}

@keyframes panelIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.panel-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    transition: all 0.2s ease;
}

.panel-item:active {
    transform: scale(0.95);
}

.panel-icon {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--primary-color-rgb), 0.08);
    border-radius: var(--radius-lg);
    transition: all 0.2s ease;
    color: var(--primary-dark);
}

.panel-item:active .panel-icon {
    background: rgba(167, 139, 250, 0.2);
}

.panel-text {
    font-size: var(--font-size-xs);
    color: #666;
    text-align: center;
}

/* =========================================
   消息列表项（会话列表）
   ========================================= */

.msg-list-item {
    display: flex;
    padding: var(--space-4);
    background: var(--white);
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: var(--radius-lg);
    margin: 0 var(--space-4) var(--space-2);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.05);
    border: 1px solid rgba(167, 139, 250, 0.08);
}

.msg-list-item:active {
    background: rgba(167, 139, 250, 0.08);
    transform: scale(0.99);
}

.msg-content-preview {
    flex: 1;
    margin-left: var(--space-3);
    overflow: hidden;
}

.msg-top-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: var(--space-1);
    align-items: center;
}

.msg-name {
    font-weight: 600;
    font-size: var(--font-size-base);
    color: #1a1a2e;
}

.msg-time {
    font-size: var(--font-size-xs);
    color: #999;
}

.msg-preview {
    color: #666;
    font-size: var(--font-size-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

/* =========================================
   模态框与抽屉 - 紫白毛玻璃风格
   ========================================= */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(139, 92, 246, 0.15);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 2000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: overlayIn 0.2s ease-out;
}

@keyframes overlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    padding: var(--space-6);
    padding-bottom: max(var(--space-6), env(safe-area-inset-bottom));
    overflow-y: auto;
    animation: modalIn 0.3s ease-out;
    box-shadow: 0 -8px 40px rgba(139, 92, 246, 0.15);
    border-top: 1px solid rgba(167, 139, 250, 0.2);
}

@keyframes modalIn {
    from {
        transform: translateY(100%);
        opacity: 0.8;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* 世界书启用弹窗 */
.worldbook-picker {
    padding: 0;
    border-radius: var(--radius-xxl);
    overflow: hidden;
    max-height: 85vh;
}

.worldbook-picker .modal-header,
.worldbook-picker .modal-footer {
    padding: var(--space-4) var(--space-5);
}

.worldbook-picker .modal-body {
    padding: var(--space-4) var(--space-5);
}

.worldbook-picker .modal-header {
    background: linear-gradient(135deg, rgba(167, 139, 250, 0.12) 0%, rgba(139, 92, 246, 0.06) 100%);
}

.worldbook-picker-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.worldbook-picker-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: rgba(167, 139, 250, 0.08);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(167, 139, 250, 0.15);
    cursor: pointer;
    transition: all 0.2s ease;
}

.worldbook-picker-item:active {
    transform: scale(0.98);
    background: rgba(167, 139, 250, 0.15);
}

.worldbook-picker-info {
    flex: 1;
    min-width: 0;
}

.worldbook-picker-name {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: #1a1a2e;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.worldbook-picker-desc {
    font-size: var(--font-size-xs);
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =========================================
   聊天设置抽屉 - 角色聊天设置UI
   ========================================= */

.chat-settings-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 2100;
    transform: translateX(100%);
    transition: transform 0.3s ease-out;
    display: flex;
    flex-direction: column;
    box-shadow: -8px 0 40px rgba(139, 92, 246, 0.15);
}

.chat-settings-drawer.active {
    transform: translateX(0);
}

.chat-settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    padding-top: calc(var(--space-4) + env(safe-area-inset-top));
    background: linear-gradient(135deg, rgba(167, 139, 250, 0.1) 0%, rgba(139, 92, 246, 0.05) 100%);
    border-bottom: 1px solid rgba(167, 139, 250, 0.15);
}

.chat-settings-header h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: #1a1a2e;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.chat-settings-header h3 i {
    color: #8B5CF6;
}

.chat-settings-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #A78BFA;
}

.chat-settings-close:active {
    background: rgba(167, 139, 250, 0.15);
    transform: scale(0.95);
}

.chat-settings-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
}

/* 设置分组 */
.chat-settings-section {
    margin-bottom: var(--space-5);
}

.chat-settings-section-title {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--primary-dark);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-3);
    padding-left: var(--space-2);
}

.chat-settings-group {
    background: var(--white);
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(139, 92, 246, 0.08);
    border: 1px solid rgba(167, 139, 250, 0.12);
}

/* 设置项 */
.chat-settings-item {
    display: flex;
    align-items: center;
    padding: var(--space-4);
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid rgba(167, 139, 250, 0.1);
    gap: var(--space-4);
}

.chat-settings-item:last-child {
    border-bottom: none;
}

.chat-settings-item:active {
    background: rgba(167, 139, 250, 0.08);
}

.chat-settings-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-lg);
    flex-shrink: 0;
    background: rgba(var(--primary-color-rgb), 0.16);
    color: var(--primary-dark);
}

.chat-settings-icon i {
    font-size: 18px;
}

.chat-settings-text {
    flex: 1;
    min-width: 0;
}

.chat-settings-label {
    font-size: var(--font-size-base);
    font-weight: 500;
    color: #1a1a2e;
    margin-bottom: 2px;
}

.chat-settings-desc {
    font-size: var(--font-size-xs);
    color: #666;
}

.chat-settings-value {
    font-size: var(--font-size-sm);
    color: var(--primary-dark);
    font-weight: 500;
}

.chat-settings-arrow {
    color: var(--primary-color);
    font-size: 18px;
}

/* 角色卡片 */
.chat-character-card {
    display: flex;
    align-items: center;
    padding: var(--space-4);
    background: linear-gradient(135deg, rgba(167, 139, 250, 0.08) 0%, rgba(139, 92, 246, 0.04) 100%);
    border-radius: var(--radius-xl);
    margin-bottom: var(--space-4);
    gap: var(--space-4);
    border: 1px solid rgba(167, 139, 250, 0.15);
}

.chat-character-avatar {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.2);
}

.chat-character-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-character-info {
    flex: 1;
    min-width: 0;
}

.chat-character-name {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: #1a1a2e;
    margin-bottom: var(--space-1);
}

.chat-character-desc {
    font-size: var(--font-size-sm);
    color: #666;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.chat-character-edit {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--primary-dark);
    background: rgba(var(--primary-color-rgb), 0.1);
}

.chat-character-edit:active {
    background: rgba(167, 139, 250, 0.25);
    transform: scale(0.95);
}

/* 开关样式 */
.chat-settings-switch {
    width: 50px;
    height: 28px;
    background: rgba(var(--primary-color-rgb), 0.2);
    border-radius: var(--radius-full);
    position: relative;
    cursor: pointer;
    transition: background 0.2s ease;
}

.chat-settings-switch.active {
    background: var(--primary-gradient);
}

.chat-settings-switch-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 24px;
    height: 24px;
    background: var(--white);
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease;
}

.chat-settings-switch.active .chat-settings-switch-thumb {
    transform: translateX(22px);
}

/* 设置项旧样式兼容 */
.settings-item {
    display: flex;
    align-items: center;
    padding: var(--space-4) 0;
    border-bottom: 1px solid rgba(167, 139, 250, 0.1);
    cursor: pointer;
    transition: all 0.2s ease;
    gap: var(--space-4);
}

.settings-item:last-child {
    border-bottom: none;
}

.settings-item:active {
    opacity: 0.7;
}

.settings-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    flex-shrink: 0;
    background: linear-gradient(135deg, rgba(167, 139, 250, 0.15) 0%, rgba(139, 92, 246, 0.25) 100%);
    color: #8B5CF6;
}

.settings-icon i {
    font-size: 20px;
}

.settings-text {
    flex: 1;
    font-size: var(--font-size-base);
    color: #1a1a2e;
}

/* 消息操作菜单 */
.message-actions-menu {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    padding: var(--space-2);
    display: flex;
    gap: var(--space-1);
    box-shadow: 0 8px 40px rgba(139, 92, 246, 0.2);
    border: 1px solid rgba(167, 139, 250, 0.2);
    animation: menuIn 0.2s ease-out;
}

@keyframes menuIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.action-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 60px;
}

.action-item:active {
    background: rgba(167, 139, 250, 0.15);
}

.action-item i {
    font-size: 20px;
    color: #8B5CF6;
}

.action-item span {
    font-size: var(--font-size-xs);
    color: #666;
}

/* 面具选择器 */
.persona-selector-item {
    display: flex;
    align-items: center;
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s ease;
    gap: var(--space-4);
    margin-bottom: var(--space-2);
    border: 1px solid rgba(167, 139, 250, 0.1);
}

.persona-selector-item:active {
    background: rgba(167, 139, 250, 0.08);
}

.persona-selector-item.active {
    background: rgba(167, 139, 250, 0.15);
    border-color: rgba(139, 92, 246, 0.3);
}

.persona-selector-avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.15);
}

.persona-selector-avatar.avatar-circle {
    border-radius: 50%;
}

.persona-selector-info {
    flex: 1;
    min-width: 0;
}

.persona-selector-name {
    font-weight: 600;
    font-size: var(--font-size-base);
    color: #1a1a2e;
    margin-bottom: var(--space-1);
}

.persona-selector-desc {
    font-size: var(--font-size-sm);
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =========================================
   响应式适配
   ========================================= */

@media (max-width: 375px) {
    .bubble {
        font-size: var(--font-size-sm);
        padding: var(--space-2) var(--space-3);
    }
    
    .avatar {
        width: 34px;
        height: 34px;
    }
    
    .message-row.left {
        padding-right: var(--space-6);
    }
    
    .message-row.right {
        padding-left: var(--space-6);
    }
}

