/* ===== 暖白主题 CSS 变量 ===== */
:root {
    --bg: #fdfbf7;
    --bg-secondary: #f9f5ee;
    --bg-tertiary: #f0ebe0;
    --text: #4a3f35;
    --text-secondary: #9b8e7c;
    --text-muted: #c4b9a8;
    --accent: #e8b88a;
    --accent-on: #d4a574;
    --bubble-user: #e8c8a0;
    --bubble-user-text: #fff;
    --bubble-ai: #fff;
    --border: #e8dfd2;
    --danger: #d4a0a0;
    --shadow: 0 1px 3px rgba(0,0,0,0.04);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --header-height: 48px;
    --input-height: 50px;
    --menu-width: 280px;
    --radius: 6px;
    --radius-sm: 4px;
    --font-size: 15px;
    --font-size-sm: 13px;
    --font-size-xs: 11px;
    --transition: 0.2s ease;
}

/* ===== 基础 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: var(--font-size);
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}
input, textarea { -webkit-user-select: text; user-select: text; outline: none; }

/* ===== App 容器 ===== */
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
    background: var(--bg);
}
@media (min-width: 481px) {
    #app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

/* ===== 顶部栏（微信风格） ===== */
#header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 8px;
}
#btn-menu {
    width: 32px; height: 32px;
    border: none; background: transparent;
    font-size: 20px; cursor: pointer;
    color: var(--text); line-height: 1;
    border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
}
#btn-menu:active { background: var(--bg-tertiary); }
#header-center {
    flex: 1; display: flex; align-items: center; justify-content: center;
}
#header-title { font-weight: 600; font-size: 17px; }
#header-time { color: var(--text-secondary); font-size: var(--font-size-xs); white-space: nowrap; }

/* ===== 主区域 ===== */
#main-area { flex: 1; overflow: hidden; position: relative; }
.page {
    position: absolute; inset: 0;
    overflow-y: auto; overflow-x: hidden;
    display: none; flex-direction: column;
    background: var(--bg);
}
.page.active { display: flex; }
.page-header {
    padding: 12px 16px; font-size: 13px; font-weight: 600;
    color: var(--text-secondary); border-bottom: 1px solid var(--border);
    background: var(--bg); flex-shrink: 0;
}

/* ===== 聊天区域 ===== */
#page-chat { background: transparent; }
#chat-bg {
    position: absolute; inset: 0;
    background-color: var(--bg);
    background-image: none;
    background-size: cover;
    background-position: center;
    opacity: 0.3;
    z-index: 0;
}
#chat-messages {
    position: relative; z-index: 1;
    flex: 1; overflow-y: auto;
    padding: 8px 12px;
    display: flex; flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}
#chat-messages.has-bg { background: transparent; }

/* 消息行 */
.msg-row {
    display: flex; gap: 8px; max-width: 100%;
    animation: msgIn 0.25s ease;
}
.msg-row.user { flex-direction: row-reverse; }
.msg-row.ai { flex-direction: row; }

/* 头像 */
.msg-avatar {
    width: 36px; height: 36px; border-radius: 4px;
    flex-shrink: 0; display: flex; align-items: center;
    justify-content: center; font-size: 16px; font-weight: 600;
    color: #fff; overflow: hidden;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg-avatar.user-av { background: #b8b8b8; }
.msg-avatar.ai-av { background: #a0b8d4; }

/* 消息气泡 */
.msg-bubble {
    max-width: 72%; padding: 9px 12px;
    font-size: var(--font-size); line-height: 1.5;
    word-break: break-word; position: relative;
}
.msg-row.user .msg-bubble {
    background: var(--bubble-user); color: var(--bubble-user-text);
    border-radius: var(--radius) 2px var(--radius) var(--radius);
}
.msg-row.ai .msg-bubble {
    background: var(--bubble-ai); color: var(--text);
    border-radius: 2px var(--radius) var(--radius) var(--radius);
    box-shadow: var(--shadow); border: 1px solid var(--border);
}
.msg-time {
    font-size: 10px; color: var(--text-muted); margin-top: 2px;
}
.msg-row.user .msg-time { text-align: right; }

/* 系统消息 */
.msg-system {
    text-align: center; padding: 4px 0;
    color: var(--text-muted); font-size: var(--font-size-xs);
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 打字指示器 */
#typing-indicator {
    display: flex; gap: 4px; padding: 4px 16px; align-items: center;
    position: relative; z-index: 1;
}
#typing-indicator.hidden { display: none; }
#typing-indicator span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--text-muted); animation: bounce 1.2s infinite;
}
#typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
#typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ===== 输入栏（微信风格） ===== */
#input-bar {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 10px; background: var(--bg-secondary);
    border-top: 1px solid var(--border); flex-shrink: 0;
    padding-bottom: calc(6px + var(--safe-area-bottom));
}
#msg-input {
    flex: 1; padding: 8px 12px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--bg); color: var(--text);
    font-size: var(--font-size);
}
#msg-input:focus { border-color: var(--accent); }
#btn-voice, #btn-send {
    height: 32px; border: none; border-radius: 6px;
    font-size: 13px; cursor: pointer; flex-shrink: 0;
    font-weight: 500; padding: 0 12px;
}
#btn-voice { background: var(--bg-tertiary); color: var(--text-secondary); }
#btn-send { background: var(--accent-on); color: #fff; }
#btn-voice:active, #btn-send:active { opacity: 0.8; }
#btn-send:disabled { opacity: 0.4; }

/* ===== 汉堡菜单 ===== */
#menu-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.3);
    z-index: 900; transition: opacity 0.25s;
}
#menu-overlay.hidden { opacity: 0; pointer-events: none; }

#side-menu {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--menu-width); max-width: 85vw;
    background: var(--bg); z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    display: flex; flex-direction: column;
    overflow-y: auto; box-shadow: 2px 0 12px rgba(0,0,0,0.1);
}
#side-menu.open { transform: translateX(0); }

#menu-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; border-bottom: 1px solid var(--border);
    font-weight: 600; font-size: 16px;
}
#btn-menu-close {
    width: 28px; height: 28px; border: none;
    background: transparent; font-size: 22px; cursor: pointer;
    color: var(--text-secondary);
}

/* 菜单中的用户/AI 资料 */
.menu-profile {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px; cursor: pointer;
    transition: background var(--transition);
}
.menu-profile:active { background: var(--bg-tertiary); }
.menu-avatar {
    width: 44px; height: 44px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: 600; color: #fff;
    flex-shrink: 0; overflow: hidden;
}
.menu-avatar img { width: 100%; height: 100%; object-fit: cover; }
#menu-user-avatar { background: #b8b8b8; }
#menu-ai-avatar { background: #a0b8d4; }
.menu-profile-info { flex: 1; min-width: 0; }
.menu-nickname { font-size: 15px; font-weight: 500; }
.menu-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.menu-divider { height: 1px; background: var(--border); margin: 6px 0; }

/* 菜单项 */
.menu-item {
    display: block; width: 100%; padding: 12px 20px;
    border: none; background: transparent; font-size: 15px;
    color: var(--text); text-align: left; cursor: pointer;
    transition: background var(--transition);
}
.menu-item:active { background: var(--bg-tertiary); }
.menu-item.active { color: var(--accent-on); font-weight: 600; background: var(--accent-dim); }

/* ===== 设置页 ===== */
.settings-tabs {
    display: flex; border-bottom: 1px solid var(--border);
    background: var(--bg); flex-shrink: 0; overflow-x: auto;
}
.stab {
    flex-shrink: 0; padding: 10px 14px; border: none;
    background: transparent; font-size: 13px; color: var(--text-secondary);
    cursor: pointer; border-bottom: 2px solid transparent;
    transition: all var(--transition);
}
.stab.active { color: var(--accent-on); border-bottom-color: var(--accent-on); font-weight: 600; }

#settings-content { flex: 1; overflow-y: auto; }

.settings-section { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.settings-section h3 {
    font-size: 12px; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px;
}

.setting-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 0; border-bottom: 1px solid rgba(0,0,0,0.03);
}
.setting-item:last-child { border-bottom: none; }
.setting-label { font-size: var(--font-size); }
.setting-desc { font-size: var(--font-size-xs); color: var(--text-muted); margin-top: 2px; }

.setting-item input[type="text"],
.setting-item input[type="password"],
.setting-item input[type="number"],
.setting-item select {
    padding: 6px 10px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--bg);
    color: var(--text); font-size: var(--font-size-sm);
    width: 160px;
}
.setting-item input:focus { border-color: var(--accent); }
.setting-item select { cursor: pointer; }

/* 背景选择器 */
.bg-options { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.bg-option {
    width: 56px; height: 56px; border-radius: 6px;
    border: 2px solid transparent; cursor: pointer;
    background-size: cover; background-position: center;
}
.bg-option.selected { border-color: var(--accent-on); }
.bg-option.none { background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--text-muted); }

/* 滑块 */
.slider-container { width: 160px; display: flex; align-items: center; gap: 6px; }
.slider-container input[type="range"] {
    flex: 1; -webkit-appearance: none; height: 4px;
    background: var(--border); border-radius: 2px; outline: none;
}
.slider-container input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 20px; height: 20px;
    border-radius: 50%; background: var(--accent-on); cursor: pointer;
}
.slider-value { font-size: var(--font-size-sm); color: var(--accent-on); width: 28px; text-align: right; }

/* 开关 */
.toggle {
    position: relative; width: 46px; height: 26px;
    background: var(--border); border-radius: 13px;
    cursor: pointer; transition: background var(--transition); flex-shrink: 0;
}
.toggle.on { background: var(--accent-on); }
.toggle::after {
    content: ''; position: absolute; top: 2px; left: 2px;
    width: 22px; height: 22px; border-radius: 50%;
    background: #fff; transition: transform var(--transition); box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.toggle.on::after { transform: translateX(20px); }

/* 按钮 */
.btn {
    padding: 8px 18px; border: none; border-radius: var(--radius-sm);
    font-size: var(--font-size-sm); cursor: pointer;
    transition: all var(--transition); font-weight: 500;
}
.btn-primary { background: var(--accent-on); color: #fff; }
.btn-secondary { background: var(--bg-tertiary); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn:active { opacity: 0.8; }

/* Modal */
.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center;
    z-index: 2000;
}
.modal.hidden { display: none; }
.modal-content {
    background: var(--bg); border-radius: 12px;
    padding: 20px; max-width: 340px; width: 90%;
    max-height: 80vh; overflow-y: auto; box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}

/* Toast */
#toast {
    position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
    background: rgba(60,50,40,0.9); color: #fff;
    padding: 8px 18px; border-radius: 20px;
    font-size: var(--font-size-sm); z-index: 3000;
    transition: opacity 0.3s; pointer-events: none;
}
#toast.hidden { opacity: 0; }

/* ===== AI内心活动页 ===== */
#thoughts-list { padding: 12px; }
.thought-item {
    padding: 12px; margin-bottom: 8px;
    background: var(--bg-secondary); border-radius: 8px;
    border: 1px solid var(--border);
}
.thought-time { font-size: var(--font-size-xs); color: var(--text-muted); margin-bottom: 4px; }
.thought-action { font-size: var(--font-size-sm); color: var(--accent-on); font-weight: 500; }
.thought-detail { font-size: var(--font-size-sm); color: var(--text-secondary); margin-top: 4px; }

/* ===== 好感度页 ===== */
#relationship-content { padding: 16px; }
.rel-stat { margin-bottom: 14px; }
.rel-label { font-size: var(--font-size-sm); color: var(--text-secondary); margin-bottom: 4px; }
.rel-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.rel-bar-fill { height: 100%; background: var(--accent-on); border-radius: 3px; transition: width 0.5s ease; }

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ===== 思考过程 ===== */
.msg-content-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.msg-row.user .msg-content-wrap { align-items: flex-end; }

.msg-thinking {
    margin-bottom: 4px; border-radius: 6px;
    background: rgba(0,0,0,0.03); border: 1px solid var(--border);
    overflow: hidden; font-size: 12px;
}
.thinking-header {
    padding: 4px 10px; cursor: pointer; color: var(--text-muted);
    user-select: none; font-size: 11px;
}
.thinking-body {
    padding: 6px 10px; color: var(--text-secondary);
    border-top: 1px solid var(--border); white-space: pre-wrap; line-height: 1.4;
}
.msg-thinking.collapsed .thinking-body { display: none; }
.msg-thinking.collapsed .thinking-header::after { content: ' >'; }

/* 消息操作按钮 */
.msg-actions { margin-top: 2px; }
.msg-action-btn {
    border: none; background: transparent;
    color: var(--text-muted); font-size: 11px;
    cursor: pointer; padding: 2px 6px; border-radius: 4px;
}
.msg-action-btn:hover { background: var(--bg-tertiary); color: var(--text-secondary); }

/* ===== 会话列表 ===== */
.session-item {
    display: flex; align-items: center; padding: 8px 16px;
    cursor: pointer; gap: 8px; transition: background var(--transition);
}
.session-item:hover { background: var(--bg-tertiary); }
.session-item.active { background: var(--accent-dim); }
.session-title {
    flex: 1; font-size: 13px; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
}
.session-del {
    width: 20px; height: 20px; border: none; background: transparent;
    color: var(--text-muted); cursor: pointer; font-size: 16px;
    border-radius: 10px; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; opacity: 0; transition: opacity var(--transition);
}
.session-item:hover .session-del { opacity: 1; }
.session-del:hover { background: var(--danger); color: #fff; }

/* ===== 脉冲动画（语音按钮用） ===== */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}
