/* ================= 基础重置与变量 ================= */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --bg-color: #1a1a1a;
    --chat-bg: #2b2b2b;
    --header-bg: #333;
    --text-color: #e0e0e0;
    --doctor-bubble: #3d5a80;
    --operator-bubble: #444;
    --input-bg: #2b2b2b;
    --border-color: #444;
    --active-color: #5b8def;
    --tab-bar-bg: #2a2a2a;
}
:root.light-mode {
    --bg-color: #f0f2f5;
    --chat-bg: #e5e5e5;
    --header-bg: #ffffff;
    --text-color: #1a1a1a;
    --doctor-bubble: #95ec69;
    --operator-bubble: #ffffff;
    --input-bg: #ffffff;
    --border-color: #d9d9d9;
    --active-color: #3d5a80;
    --tab-bar-bg: #f8f8f8;
}
html, body {
    height: 100%; width: 100%; max-width: 100vw;
    overflow-x: hidden;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    transition: background-color 0.3s, color 0.3s;
}
#app {
    display: flex; flex-direction: column;
    height: 100vh; height: 100dvh;
    max-width: 800px; margin: 0 auto;
    background-color: var(--bg-color);
    overflow: hidden;
    position: relative;
}

.hidden { display: none !important; }

/* ================= 视图容器系统 ================= */
.view {
    position: absolute; inset: 0;
    bottom: 0; /* will be overridden by tab bar */
    display: flex; flex-direction: column;
    background-color: var(--bg-color);
    transition: opacity 0.2s, transform 0.2s;
    z-index: 1;
}
.view.active { z-index: 10; }
.view:not(.active) { display: none; }
/* 有底部 Tab Bar 的视图（列表页、设置页） */
#view-messages, #view-contacts, #view-moments, #view-settings {
    bottom: 64px;
    bottom: calc(64px + env(safe-area-inset-bottom));
}
/* 全屏视图（聊天详情、群聊聊天、新建群聊）——也需为 tab bar 让位 */
#view-chat-detail, #view-group-chat, #view-group-create {
    bottom: 64px;
    bottom: calc(64px + env(safe-area-inset-bottom));
}

/* ================= 视图头部 ================= */
.view-header {
    display: flex; align-items: center;
    height: 52px; padding: 0 16px;
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    transition: background-color 0.3s;
}
.view-header-title {
    font-size: 18px; font-weight: 700;
    color: var(--text-color);
}
.back-btn {
    background: none; border: none;
    color: var(--active-color); font-size: 20px;
    cursor: pointer; padding: 0 8px 0 0;
    transition: opacity 0.2s;
}
.back-btn:active { opacity: 0.6; }

/* ================= 消息页头部 ================= */
.messages-header {
    display: flex; align-items: center;
    height: 52px; padding: 0 16px;
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    transition: background-color 0.3s;
}
.messages-header-title {
    flex: 1; text-align: center;
    font-size: 18px; font-weight: 700;
    color: var(--text-color);
}
.header-avatar {
    width: 36px; height: 36px;
    border-radius: 50%; object-fit: cover;
    cursor: pointer; flex-shrink: 0;
    transition: opacity 0.2s;
}
.header-avatar:active { opacity: 0.7; }
.header-add-btn {
    width: 36px; height: 36px;
    background: none; border: none;
    color: var(--text-color);
    font-size: 28px; line-height: 1;
    cursor: pointer; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    transition: background 0.2s, opacity 0.2s;
}
.header-add-btn:active {
    background: var(--chat-bg);
    opacity: 0.7;
}

/* ================= 消息页 Tab 切换 ================= */
.messages-tabs {
    display: flex;
    padding: 0 16px;
    gap: 0;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.messages-tab {
    flex: 1;
    padding: 10px 0;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: #888;
    font-size: 14px;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}
.messages-tab.active {
    color: var(--active-color);
    border-bottom-color: var(--active-color);
}

/* ================= 聊天详情头部 ================= */
.chat-header {
    display: flex; align-items: center; gap: 10px;
    height: 52px; padding: 0 12px;
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    transition: background-color 0.3s;
}
#chat-detail-title, #group-chat-title {
    font-size: 16px; font-weight: 600;
    color: var(--text-color);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#chat-detail-title { flex: 0 1 auto; }
#group-chat-title { flex: 1; }
.chat-emotion-tag {
    flex: 0 0 auto;
    font-size: 11px; font-weight: 400;
    padding: 2px 8px; border-radius: 10px;
    background: rgba(91,141,239,0.15);
    color: var(--active-color);
    white-space: nowrap;
    max-width: 80px;
    overflow: hidden; text-overflow: ellipsis;
    margin-right: auto;
}
#chat-detail-settings-btn, #group-chat-info-btn {
    background: none; border: 1px solid var(--border-color);
    border-radius: 50%; width: 34px; height: 34px;
    font-size: 16px; cursor: pointer;
    color: var(--text-color);
    display: flex; align-items: center; justify-content: center;
    transition: border-color 0.2s;
}

/* ================= 底部 Tab Bar ================= */
#tab-bar {
    position: absolute; bottom: 0; left: 0; right: 0;
    display: flex;
    height: 64px;
    padding-bottom: env(safe-area-inset-bottom);
    background-color: var(--tab-bar-bg);
    border-top: 1px solid var(--border-color);
    z-index: 100;
    transition: background-color 0.3s;
}
.tab-btn {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 2px;
    background: none; border: none;
    color: #888; cursor: pointer;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.tab-btn.active { color: var(--active-color); }
.tab-icon { font-size: 22px; line-height: 1; }
.tab-label { font-size: 11px; }

/* ================= 聊天列表搜索框 ================= */
.chat-list-search-wrap {
    padding: 10px 16px;
    background: var(--bg-color);
    flex-shrink: 0;
}
.chat-list-search-wrap input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.chat-list-search-wrap input:focus { border-color: var(--active-color); }

/* ================= 滚动列表通用 ================= */
.scroll-list {
    flex: 1; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

/* ================= 干员/群聊列表项 ================= */
.list-item {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.list-item:active { background: var(--chat-bg); }
.list-item-avatar {
    width: 48px; height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background-color: #555;
}
.list-item-info {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column; gap: 4px;
}
.list-item-name {
    font-size: 15px; font-weight: 600;
    color: var(--text-color);
}
.list-item-preview {
    font-size: 12px; color: #888;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-item-bio {
    font-size: 12px; color: #888;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-item-badge {
    background: var(--active-color);
    color: #fff; font-size: 10px;
    padding: 2px 8px; border-radius: 10px;
    flex-shrink: 0;
}
/* 群聊列表项中的多头像拼图 */
.list-item-avatars {
    display: grid; gap: 2px;
    width: 48px; height: 48px;
    flex-shrink: 0;
}
.list-item-avatars.two { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.list-item-avatars.three { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.list-item-avatars.three img:first-child { grid-column: 1 / -1; }
.list-item-avatars.four { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.list-item-avatars img {
    width: 100%; height: 100%;
    object-fit: cover; border-radius: 4px;
}

/* ================= 消息列表群聊分隔线 ================= */
.messages-section-divider {
    padding: 10px 16px 6px;
    font-size: 12px; color: #888;
    letter-spacing: 1px;
    font-weight: 600;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
}

/* ================= 消息列表空状态 ================= */
.messages-empty {
    flex: 1; display: flex;
    align-items: center; justify-content: center;
    color: #888; font-size: 15px;
}
.messages-empty.hidden { display: none; }

/* ================= 列表通用空状态 ================= */
.list-empty {
    text-align: center; color: #888;
    padding: 40px 20px; font-size: 14px;
}

/* ================= 新建群聊 ================= */
#group-create-ops { padding: 8px 0; }
.group-create-op {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.group-create-op:active { background: var(--chat-bg); }
.group-create-op img {
    width: 42px; height: 42px;
    border-radius: 50%; object-fit: cover;
    background-color: #555;
    border: 2px solid transparent;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.group-create-op.selected img {
    border-color: var(--active-color);
    box-shadow: 0 0 10px rgba(91, 141, 239, 0.5);
}
.group-create-op-name {
    flex: 1; font-size: 15px; color: var(--text-color);
}
.group-create-op-check {
    width: 22px; height: 22px;
    border-radius: 50%; border: 2px solid var(--border-color);
    transition: all 0.2s;
    flex-shrink: 0;
}
.group-create-op.selected .group-create-op-check {
    background: var(--active-color); border-color: var(--active-color);
}
#group-create-confirm {
    background: var(--active-color); color: #fff;
    border: none; border-radius: 6px;
    padding: 6px 14px; font-size: 14px;
    cursor: pointer; font-weight: 600;
}
#group-create-confirm:disabled { opacity: 0.4; cursor: default; }

/* ================= 视图底部按钮 ================= */
.view-footer {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    background: var(--header-bg);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}
#new-group-btn {
    width: 100%; padding: 12px;
    background: transparent;
    border: 1px dashed var(--border-color);
    border-radius: 10px;
    color: var(--text-color); font-size: 15px;
    cursor: pointer; transition: all 0.2s;
}
#new-group-btn:active { border-color: var(--active-color); color: var(--active-color); }

/* ================= 设置页 ================= */
.settings-section {
    margin-bottom: 4px;
}
.settings-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    font-size: 15px; color: var(--text-color);
    transition: background 0.15s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.settings-row:active { background: var(--chat-bg); }
.settings-row .settings-val { color: #888; font-size: 13px; }
.settings-row.danger { color: #e05555; }
.settings-row.danger .settings-val { color: #e05555; }

/* ================= 设置页 section 标题 ================= */
.settings-section-label {
    font-size: 12px; color: #888;
    padding: 20px 16px 6px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}
.settings-section-label:first-of-type { padding-top: 12px; }

/* ================= 设置页底部信息 ================= */
.settings-footer-info {
    padding: 40px 16px 32px;
    text-align: center;
}
.settings-footer-version {
    font-size: 12px; color: #555;
    margin-bottom: 6px;
}
.settings-footer-identity {
    font-size: 12px; color: #666;
}

/* ================= API Key 弹窗 ================= */
#apikey-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,0.5);
}
#apikey-modal {
    position: fixed; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 201;
    background: var(--header-bg);
    border-radius: 12px;
    width: calc(100vw - 64px); max-width: 400px;
    overflow: hidden;
}
.apikey-modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}
.apikey-modal-header h3 { font-size: 16px; margin: 0; }
#apikey-close-btn {
    background: none; border: none;
    color: var(--text-color); font-size: 18px; cursor: pointer;
    padding: 4px 8px;
}
.apikey-modal-body {
    padding: 20px;
    display: flex; flex-direction: column; gap: 8px;
}
.apikey-modal-body label {
    font-size: 13px; color: #888;
    margin-top: 4px;
}
.apikey-modal-body input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 14px;
    outline: none;
}
.apikey-modal-body input:focus {
    border-color: var(--active-color);
}
.apikey-hint {
    font-size: 12px; color: #666;
    margin-top: 8px;
    line-height: 1.5;
}
.apikey-modal-footer {
    display: flex; gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    justify-content: flex-end;
}
.apikey-modal-footer button {
    padding: 8px 20px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--header-bg);
    color: var(--text-color);
    font-size: 14px; cursor: pointer;
    transition: background 0.15s;
}
.apikey-modal-footer button:active { background: var(--chat-bg); }
#apikey-save-btn {
    background: var(--active-color);
    color: #fff;
    border-color: var(--active-color);
}
#apikey-save-btn:disabled {
    opacity: 0.5; cursor: default;
}
#apikey-test-btn:disabled {
    opacity: 0.5; cursor: default;
}
/* ================= 隐藏 NSFW 暗号配置 ================= */
.nsfw-settings-label { color: #c8a050 !important; }
.nsfw-collapse-header {
    cursor: pointer; user-select: none;
    display: flex; align-items: center; gap: 6px;
}
.nsfw-collapse-header:hover { opacity: 0.8; }
.nsfw-collapse-arrow { font-size: 10px; transition: transform 0.2s; }
/* ================= 设置页下拉选择框 ================= */
.settings-row-select select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 13px;
    outline: none;
    cursor: pointer;
    min-width: 80px;
    text-align: right;
    -webkit-appearance: none;
    appearance: none;
}
.settings-row-select select:focus {
    border-color: var(--accent-color);
}
.settings-row-static {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 16px 4px;
    font-size: 14px; color: var(--text-color);
}
.nsfw-hint { font-size: 11px; color: #666; }
.settings-row-input {
    padding: 4px 16px 14px;
}
.settings-row-input input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 13px;
    outline: none;
}
.settings-row-input input:focus {
    border-color: #c8a050;
}
.nsfw-settings-note {
    padding: 12px 16px 32px;
    font-size: 12px; color: #666;
    line-height: 1.6;
}

/* ================= PIN 验证弹窗 ================= */
#pin-overlay {
    position: fixed; inset: 0; z-index: 300;
    background: rgba(0,0,0,0.7);
}
#pin-modal {
    position: fixed; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 301;
    background: var(--header-bg);
    border: 1px solid #c8a050;
    border-radius: 12px;
    width: calc(100vw - 64px); max-width: 360px;
    overflow: hidden;
    box-shadow: 0 0 40px rgba(200,160,80,0.15);
}
.pin-modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}
.pin-modal-header h3 { font-size: 16px; color: #c8a050; margin: 0; }
#pin-close-btn {
    background: none; border: none;
    color: var(--text-color); font-size: 18px; cursor: pointer;
}
.pin-modal-body {
    padding: 20px;
    display: flex; flex-direction: column; gap: 12px;
}
.pin-warning {
    font-size: 13px; color: #c8a050;
    text-align: center; margin: 0;
}
#pin-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 18px; text-align: center; letter-spacing: 8px;
    outline: none;
}
#pin-input:focus { border-color: #c8a050; }
.pin-error {
    font-size: 12px; color: #e05555;
    text-align: center; margin: 0;
}
.pin-modal-footer {
    display: flex;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    justify-content: center;
}
#pin-confirm-btn {
    width: 100%;
    padding: 10px 20px;
    border: 1px solid #c8a050;
    border-radius: 8px;
    background: rgba(200,160,80,0.1);
    color: #c8a050;
    font-size: 14px; cursor: pointer;
    transition: background 0.15s;
}
#pin-confirm-btn:active { background: rgba(200,160,80,0.25); }

/* NSFW 视觉做减法：降低遮罩强度 */
#nsfw-veil {
    opacity: 0.4 !important;
    transition: opacity 1s ease;
}
#nsfw-veil.active { opacity: 0.6 !important; }

/* ================= NSFW Toggle Switch ================= */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px; height: 26px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #555;
    border-radius: 26px;
    transition: background 0.3s;
}
.toggle-slider::before {
    content: "";
    position: absolute;
    height: 20px; width: 20px;
    left: 3px; bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s;
}
.toggle-switch input:checked + .toggle-slider {
    background: #c8a050;
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
}
.memory-nsfw-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    margin-bottom: 16px;
    background: var(--chat-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}
.memory-nsfw-row span {
    font-size: 14px; color: var(--text-color);
}

/* ================= 群聊设置面板 ================= */
#group-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 1000;
    transition: opacity 0.3s;
}
#group-overlay.hidden { opacity: 0; pointer-events: none; }
#group-panel {
    position: fixed; top: 0; right: 0;
    width: 400px; max-width: 90vw;
    height: 100vh; height: 100dvh;
    background: var(--bg-color);
    border-left: 1px solid var(--border-color);
    z-index: 1001; display: flex; flex-direction: column;
    transform: translateX(0);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: -4px 0 24px rgba(0,0,0,0.3);
}
#group-panel.hidden { transform: translateX(100%); box-shadow: none; }
.group-panel-header {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 20px; border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.group-panel-header h2 { font-size: 18px; margin: 0; color: var(--text-color); }
#group-panel-close-btn {
    margin-left: auto; background: none;
    border: 1px solid var(--border-color); border-radius: 50%;
    width: 32px; height: 32px; cursor: pointer;
    color: var(--text-color); font-size: 16px;
    display: flex; align-items: center; justify-content: center;
}
.group-panel-body {
    flex: 1; overflow-y: auto; padding: 20px;
    -webkit-overflow-scrolling: touch;
}
.group-settings-section {
    margin-bottom: 22px;
}
.group-settings-section label {
    display: block; font-size: 13px; color: #888;
    margin-bottom: 8px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.group-settings-section input,
.group-settings-section textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    font-size: 14px; font-family: inherit;
    transition: border-color 0.2s;
}
.group-settings-section input:focus,
.group-settings-section textarea:focus {
    border-color: var(--active-color); outline: none;
}
.group-settings-section textarea {
    resize: vertical; min-height: 60px;
}
.group-panel-footer {
    padding: 16px 20px; border-top: 1px solid var(--border-color);
    display: flex; gap: 10px; flex-shrink: 0;
}
.group-panel-footer button {
    flex: 1; padding: 12px;
    border: 1px solid var(--border-color); border-radius: 8px;
    background: transparent; color: var(--text-color);
    font-size: 14px; cursor: pointer; transition: all 0.2s;
}
.group-panel-footer button:active { opacity: 0.7; }
.group-panel-footer .danger-btn {
    color: #e05555; border-color: #e05555;
}

/* ================= 群聊成员列表 ================= */
.group-member-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.04);
}
.group-member-item img {
    width: 36px; height: 36px;
    border-radius: 50%; object-fit: cover;
    background: #555; flex-shrink: 0;
}
.group-member-item .member-name {
    flex: 1; font-size: 14px; color: var(--text-color);
}
.group-member-item .member-remove-btn {
    background: none; border: none;
    color: #888; font-size: 16px; cursor: pointer;
    padding: 4px 8px; transition: color 0.2s;
}
.group-member-item .member-remove-btn:hover { color: #e05555; }

/* ================= 添加成员弹窗 ================= */
#add-member-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6); z-index: 1010;
    transition: opacity 0.3s;
}
#add-member-overlay.hidden { opacity: 0; pointer-events: none; }
#add-member-modal {
    position: fixed; top: 10%; left: 50%;
    transform: translate(-50%, 0);
    width: 380px; max-width: 90vw; max-height: 70vh;
    background: var(--bg-color);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    z-index: 1011; display: flex; flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#add-member-modal.hidden { display: none; }
.add-member-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 16px; border-bottom: 1px solid var(--border-color);
}
.add-member-header h3 { margin: 0; font-size: 16px; color: var(--text-color); }
#add-member-close-btn {
    background: none; border: none; color: #888;
    font-size: 18px; cursor: pointer;
}
#add-member-list {
    flex: 1; overflow-y: auto; padding: 8px 0;
    -webkit-overflow-scrolling: touch;
}
.add-member-op {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px; cursor: pointer; transition: background 0.15s;
}
.add-member-op:active { background: var(--chat-bg); }
.add-member-op img {
    width: 38px; height: 38px;
    border-radius: 50%; object-fit: cover; background: #555;
    border: 2px solid transparent; transition: border-color 0.2s;
}
.add-member-op.selected img {
    border-color: var(--active-color);
    box-shadow: 0 0 8px rgba(91,141,239,0.4);
}
.add-member-op .add-member-op-name { flex: 1; font-size: 14px; color: var(--text-color); }
.add-member-op .add-member-op-check {
    width: 20px; height: 20px; border-radius: 50%;
    border: 2px solid var(--border-color); transition: all 0.2s;
}
.add-member-op.selected .add-member-op-check {
    background: var(--active-color); border-color: var(--active-color);
}
.add-member-footer {
    padding: 12px 16px; border-top: 1px solid var(--border-color);
}
#add-member-confirm-btn {
    width: 100%; padding: 12px;
    background: var(--active-color); color: #fff;
    border: none; border-radius: 8px;
    font-size: 14px; font-weight: bold; cursor: pointer;
}
#add-member-confirm-btn:disabled { opacity: 0.4; cursor: default; }

/* ================= 聊天区域（共享） ================= */
#chat-area, #group-chat-area {
    flex: 1; min-height: 0;
    overflow-y: auto; padding: 15px;
    -webkit-overflow-scrolling: touch;
    display: flex; flex-direction: column;
}
.message {
    display: flex; align-items: flex-start;
    margin-bottom: 15px; width: 100%; flex-shrink: 0;
}
.avatar {
    width: 40px; height: 40px;
    border-radius: 6px; object-fit: cover;
    flex-shrink: 0; background-color: #555;
}
.bubble {
    max-width: 75%; padding: 10px 14px;
    border-radius: 12px; line-height: 1.5;
    font-size: 16px; word-wrap: break-word; overflow-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    transition: background-color 0.3s, color 0.3s;
}
.message.doctor { flex-direction: row-reverse; }
.message.doctor .avatar { margin-left: 10px; }
.message.doctor .bubble {
    background-color: var(--doctor-bubble); color: #fff;
    border-top-right-radius: 2px;
}
.message.operator { flex-direction: row; }
.message.operator .avatar { margin-right: 10px; }
.message.operator .bubble {
    background-color: var(--operator-bubble); color: var(--text-color);
    border-top-left-radius: 2px;
}
.message.action { justify-content: center; }
.message.action .bubble {
    background-color: transparent; color: #888;
    font-style: italic; text-align: center;
    box-shadow: none; padding: 0; max-width: 90%;
}
/* 群聊干员名称标签 */
.msg-sender-name {
    font-size: 11px; color: var(--active-color);
    margin-bottom: 2px; margin-left: 4px; font-weight: 600;
}
/* 群聊发言闪烁 */
.message.speaking .bubble {
    animation: speak-pulse 1.5s ease-in-out infinite;
}
@keyframes speak-pulse {
    0%, 100% { box-shadow: 0 0 4px rgba(91,141,239,0.2); }
    50% { box-shadow: 0 0 12px rgba(91,141,239,0.5); }
}

/* ================= 底部输入区（共享） ================= */
#input-area, #group-input-area {
    display: flex; padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    background-color: var(--header-bg);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    transition: background-color 0.3s;
}
#msg-input, #group-msg-input {
    flex: 1; padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 20px; background-color: var(--input-bg);
    color: var(--text-color); font-size: 16px; line-height: 1.4;
    outline: none; transition: all 0.3s;
    resize: none; overflow-y: auto;
    min-height: 42px; max-height: 150px;
    font-family: inherit;
}
#msg-input:focus, #group-msg-input:focus { border-color: #5b8def; }
#send-btn, #group-send-btn {
    margin-left: 10px; padding: 0 20px;
    background-color: #5b8def; color: white;
    border: none; border-radius: 20px;
    font-size: 16px; font-weight: bold; cursor: pointer;
}
#send-btn:active, #group-send-btn:active { background-color: #4a7bd4; }
.continue-btn {
    margin-left: auto; padding: 0 14px;
    background: transparent; color: #5b8def;
    border: 1px solid #5b8def;
    border-radius: 20px; font-size: 13px;
    cursor: pointer; transition: all 0.3s; flex-shrink: 0;
}
.continue-btn:hover { background: rgba(91,141,239,0.1); border-color: #7aafff; color: #7aafff; }
.continue-btn:active { background: rgba(91,141,239,0.2); }
#scene-toggle, #group-scene-toggle {
    margin-left: 8px; padding: 0 14px;
    background: transparent; color: #888;
    border: 1px solid var(--border-color);
    border-radius: 20px; font-size: 13px;
    cursor: pointer; transition: all 0.3s; flex-shrink: 0;
}
#scene-toggle:hover, #group-scene-toggle:hover { border-color: #a0a0a0; color: #ccc; }
#scene-toggle.active, #group-scene-toggle.active {
    background: #8b7355; color: #fff;
    border-color: #8b7355; font-weight: bold;
}
/* 场景模式消息 */
.message.doctor.scene .bubble {
    font-style: italic; color: #b0a090;
    background-color: rgba(61, 90, 128, 0.35);
    border: 1px dashed rgba(160, 140, 120, 0.3);
}

/* ================= 登录页 ================= */
.login-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; min-height: 100dvh;
    background: #1a1a1a; padding: 20px;
}
.login-container {
    text-align: center; background: #2b2b2b;
    padding: 40px 30px; border-radius: 16px;
    width: 100%; max-width: 420px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}
.login-avatar {
    width: 80px; height: 80px;
    border-radius: 50%; margin-bottom: 16px; object-fit: cover;
}
.login-container h2 {
    color: #e0e0e0; font-size: 18px;
    margin-bottom: 24px; font-weight: normal;
}
.input-group { text-align: left; margin-bottom: 16px; }
.input-group label { display: block; color: #888; font-size: 14px; margin-bottom: 6px; }
.input-group input {
    width: 100%; padding: 12px 14px;
    border: 1px solid #444; border-radius: 8px;
    background: #1a1a1a; color: #e0e0e0;
    font-size: 16px; outline: none;
    transition: border-color 0.3s; -webkit-appearance: none;
}
.input-group input:focus { border-color: #5b8def; }
.login-btn {
    width: 100%; padding: 14px; margin-top: 8px;
    background: #5b8def; color: #fff;
    border: none; border-radius: 8px;
    font-size: 16px; font-weight: bold; cursor: pointer;
    transition: background 0.2s; -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
}
.login-btn:active { background: #4a7bd4; }
.error-msg { color: #e05555; font-size: 13px; margin-top: 12px; min-height: 18px; }
.login-tabs {
    display: flex; gap: 0;
    margin-bottom: 20px;
    border: 1px solid #444; border-radius: 8px;
    overflow: hidden;
}
.login-tab {
    flex: 1; padding: 10px 0;
    background: #1a1a1a; color: #888;
    border: none; font-size: 14px; cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.login-tab.active { background: #5b8def; color: #fff; }
.login-tab:first-child { border-right: 1px solid #444; }
.login-hint {
    color: #666; font-size: 12px;
    margin-bottom: 8px; text-align: left;
    line-height: 1.5;
}

/* ================= NSFW 里模式视觉 ================= */
#nsfw-veil {
    position: fixed; inset: 0; z-index: 100;
    pointer-events: none;
    background: radial-gradient(ellipse at center, rgba(200,160,80,0.0) 0%, rgba(180,120,60,0.0) 100%);
    transition: background 2.5s ease-out;
}
body.nsfw-entering #nsfw-veil,
body.nsfw-mode:not(.nsfw-entering):not(.nsfw-exiting) #nsfw-veil {
    background: radial-gradient(ellipse at center, rgba(200,160,80,0.08) 0%, rgba(180,120,60,0.03) 100%);
}
body.nsfw-exiting #nsfw-veil {
    background: radial-gradient(ellipse at center, rgba(200,160,80,0.0) 0%, rgba(180,120,60,0.0) 100%);
    transition: background 2s ease-out;
}
body.nsfw-entering #chat-area,
body.nsfw-entering #group-chat-area {
    background-color: #2a2520;
    transition: background-color 2.5s ease-out;
}
body.nsfw-mode:not(.nsfw-entering):not(.nsfw-exiting) #chat-area,
body.nsfw-mode:not(.nsfw-entering):not(.nsfw-exiting) #group-chat-area {
    background-color: #2a2520;
    transition: background-color 0.6s ease;
}
body.nsfw-exiting #chat-area,
body.nsfw-exiting #group-chat-area {
    background-color: var(--chat-bg);
    transition: background-color 2s ease-out;
}
body.nsfw-entering .chat-header,
body.nsfw-mode:not(.nsfw-entering):not(.nsfw-exiting) .chat-header {
    border-bottom-color: #5a4a3a;
    transition: border-color 2.5s ease-out;
}
body.nsfw-exiting .chat-header {
    border-bottom-color: var(--border-color);
    transition: border-color 2s ease-out;
}

/* ================= 深聊模式 ================= */
.deep-chat-btn {
    background: transparent; color: #888;
    border: none; font-size: 20px; cursor: pointer;
    padding: 0 6px; transition: all 0.3s;
}
.deep-chat-btn:hover { color: #ccc; }
.deep-chat-btn.active { color: #c9a96e; text-shadow: 0 0 8px rgba(201,169,110,0.4); }

#deep-chat-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 16px; background: rgba(91,141,239,0.08);
    border-bottom: 1px solid rgba(91,141,239,0.2);
    flex-shrink: 0; font-size: 13px;
    transition: all 0.4s;
}
#deep-chat-bar.hidden { display: none; }
#deep-chat-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #5b8def; flex-shrink: 0;
    transition: background 0.6s;
}
#deep-chat-topic-label { color: var(--text-color); font-weight: bold; flex: 1; }
.deep-chat-round { color: #888; font-size: 12px; flex-shrink: 0; }
.deep-chat-end-btn {
    background: transparent; color: #888;
    border: 1px solid #555; border-radius: 12px;
    padding: 2px 12px; font-size: 12px; cursor: pointer;
    transition: all 0.3s; flex-shrink: 0;
}
.deep-chat-end-btn:hover { border-color: #e05555; color: #e05555; }

#deep-chat-cards {
    padding: 6px 12px; background: rgba(0,0,0,0.15);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0; overflow: hidden;
    transition: all 0.4s;
}
#deep-chat-cards.hidden { display: none; }
#deep-chat-cards-scroll {
    display: flex; gap: 8px; overflow-x: auto;
    scrollbar-width: none; padding: 2px 0;
}
#deep-chat-cards-scroll::-webkit-scrollbar { display: none; }
.deep-card {
    flex-shrink: 0; padding: 4px 10px;
    background: rgba(91,141,239,0.12); border: 1px solid rgba(91,141,239,0.25);
    border-radius: 12px; font-size: 12px; color: var(--text-color);
    white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis;
    animation: cardIn 0.3s ease-out;
}
@keyframes cardIn {
    from { opacity: 0; transform: translateX(10px); }
    to { opacity: 1; transform: translateX(0); }
}

/* 沉浸模式：深聊时隐藏 tab bar */
#tab-bar.deep-chat-immersive {
    transform: translateY(100%);
    transition: transform 0.4s ease;
}
#view-chat-detail.deep-chat-active {
    bottom: 0;
    bottom: env(safe-area-inset-bottom, 0);
    transition: bottom 0.4s ease;
}

/* ================= 记忆管理面板 ================= */
#memory-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 1000;
    transition: opacity 0.3s;
}
#memory-overlay.hidden { opacity: 0; pointer-events: none; }
#memory-panel {
    position: fixed; top: 0; right: 0;
    width: 400px; max-width: 90vw;
    height: 100vh; height: 100dvh;
    background: var(--bg-color);
    border-left: 1px solid var(--border-color);
    z-index: 1001; display: flex; flex-direction: column;
    transform: translateX(0);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: -4px 0 24px rgba(0,0,0,0.3);
}
#memory-panel.hidden { transform: translateX(100%); box-shadow: none; }
.memory-panel-header {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 20px; border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.memory-panel-header h2 { font-size: 18px; margin: 0; color: var(--text-color); }
#memory-operator-name { color: var(--active-color); font-weight: bold; font-size: 14px; }
#memory-close-btn {
    margin-left: auto; background: none;
    border: 1px solid var(--border-color); border-radius: 50%;
    width: 32px; height: 32px; cursor: pointer;
    color: var(--text-color); font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
#memory-close-btn:hover { color: #e05555; border-color: #e05555; }
.memory-panel-body {
    flex: 1; overflow-y: auto; padding: 20px;
    -webkit-overflow-scrolling: touch;
}
.memory-section { margin-bottom: 28px; }
.memory-section h3 {
    font-size: 14px; color: #888; margin-bottom: 12px;
    padding-bottom: 6px; border-bottom: 1px solid var(--border-color);
    text-transform: uppercase; letter-spacing: 1px;
}
.memory-item {
    background: var(--chat-bg); border: 1px solid var(--border-color);
    border-radius: 8px; padding: 12px; margin-bottom: 10px;
    transition: border-color 0.2s;
}
.memory-item:hover { border-color: #5b8def; }
.memory-item-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 6px;
}
.memory-item-time { font-size: 11px; color: #666; }
.memory-item-topic { font-size: 11px; color: var(--active-color); font-weight: bold; }
.memory-item-summary {
    width: 100%; background: var(--input-bg);
    border: 1px solid var(--border-color); border-radius: 6px;
    padding: 8px 10px; color: var(--text-color);
    font-size: 13px; font-family: inherit; line-height: 1.5;
    resize: vertical; min-height: 60px; transition: border-color 0.2s;
}
.memory-item-summary:focus { border-color: #5b8def; outline: none; }
.memory-item-fact { display: flex; align-items: center; gap: 10px; }
.memory-item-fact-text { flex: 1; font-size: 13px; color: var(--text-color); line-height: 1.5; }
.memory-delete-btn {
    background: none; border: 1px solid transparent; border-radius: 4px;
    color: #888; cursor: pointer; font-size: 12px;
    padding: 4px 8px; transition: all 0.2s; flex-shrink: 0;
}
.memory-delete-btn:hover { color: #e05555; border-color: #e05555; }
.memory-panel-footer {
    padding: 16px 20px; border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}
#memory-clear-all-btn {
    width: 100%; padding: 12px; background: transparent;
    border: 1px solid #e05555; border-radius: 8px;
    color: #e05555; font-size: 14px; font-weight: bold;
    cursor: pointer; transition: all 0.2s;
}
#memory-clear-all-btn:hover { background: #e05555; color: #fff; }
#memory-clear-all-btn.confirm {
    background: #e05555; color: #fff;
    animation: pulse-red 0.6s ease-in-out infinite alternate;
}
@keyframes pulse-red {
    from { box-shadow: 0 0 4px rgba(224,85,85,0.4); }
    to   { box-shadow: 0 0 16px rgba(224,85,85,0.8); }
}
.memory-empty { text-align: center; color: #555; font-size: 13px; padding: 20px 0; font-style: italic; }
.memory-saved {
    color: #4caf50; font-size: 11px; margin-left: 8px;
    opacity: 0; transition: opacity 0.3s;
}
.memory-saved.show { opacity: 1; }

/* ================= 信赖值详情（记忆面板内） ================= */
#trust-section h3 { color: #c8a050; }
.trust-bar-wrap { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.trust-bar { flex: 1; height: 8px; background: var(--border-color); border-radius: 4px; overflow: hidden; }
.trust-bar-fill { height: 100%; border-radius: 4px; transition: width 0.6s ease, background 0.6s ease; }
.trust-value-text { font-size: 14px; font-weight: bold; color: var(--text-color); min-width: 50px; text-align: right; }
.trust-attitude {
    font-size: 12px; color: #888; line-height: 1.6;
    margin-bottom: 16px; padding: 8px 10px;
    background: var(--chat-bg); border-radius: 6px; border-left: 3px solid #c8a050;
}
.trust-history-title { font-size: 11px; color: #666; margin-bottom: 8px; letter-spacing: 0.5px; }
.trust-history-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.04); font-size: 12px;
}
.trust-history-item .change { font-weight: bold; min-width: 36px; text-align: right; }
.trust-history-item .change.positive { color: #4caf50; }
.trust-history-item .change.negative { color: #e05555; }
.trust-history-item .date { color: #555; margin-left: 8px; }
.trust-history-item .reason { flex: 1; color: #999; margin-left: 8px; }

/* ================= 动态页占位 ================= */
#view-moments {
    display: flex; flex-direction: column;
}
.moments-section {
    flex: 1; display: flex; flex-direction: column;
    overflow: hidden;
}
.moments-section + .moments-section {
    border-top: 1px solid var(--border-color, #e5e5e5);
}
.moments-section-header {
    padding: 12px 16px 8px;
    font-size: 13px; font-weight: 600;
    color: #999; letter-spacing: 0.5px;
}
.moments-placeholder {
    flex: 1; display: flex;
    align-items: center; justify-content: center;
    color: #888; font-size: 15px;
}
