/* =========================================================
 * Lucky WeChat-style Theme（微信深色 / 浅色版式覆盖）
 * 说明：本文件在 style.css 之后加载，仅做视觉覆盖，
 *       不改变任何 DOM 结构、id 与事件绑定。
 * 主题通过 body.theme-dark / body.theme-light 切换。
 * ========================================================= */

/* ---------- 主题变量 ---------- */
body.theme-dark{
    --wx-bg:#191919;            /* 聊天页背景 */
    --wx-list-bg:#1e1e1e;       /* 会话列表背景 */
    --wx-bar-bg:#202020;        /* 顶栏 / 输入栏背景 */
    --wx-panel-bg:#2c2c2c;      /* 面板 / 弹层 */
    --wx-bubble-in:#2c2c2c;     /* 接收气泡 */
    --wx-bubble-out:#95ec69;    /* 发送气泡（微信绿） */
    --wx-bubble-out-text:#0b1a0f;
    --wx-text:#e6e6e6;
    --wx-text-2:#8a8a8a;
    --wx-border:#2a2a2a;
    --wx-icon:#9b9b9b;
    --wx-green:#07c160;
    --wx-green-d:#06ad56;
    --wx-input:#2c2c2c;

    /* 覆盖全局旧变量，让未单独覆盖的组件跟随深色 */
    --primary:var(--wx-green);
    --primary-dark:var(--wx-green-d);
    --primary-light:#1a3a28;
    --primary-bg:#1a2b22;
    --text-primary:var(--wx-text);
    --text-secondary:var(--wx-text-2);
    --text-tertiary:#9a9a9a;            /* v4.5.9 第15项：深色下辅助文字提亮，避免看不清 */
    --bg-app:var(--wx-bg);
    --bg-panel:var(--wx-list-bg);
    --bg-chat:var(--wx-bg);
    --bg-hover:#2a2a2a;
    --border-color:var(--wx-border);
    /* v4.5.9 第15项：补齐推送面板等组件使用的别名，避免回退成白色背景导致白底浅字 */
    --bg-primary:var(--wx-panel-bg);
    --bg-secondary:#242424;
    --primary-color:var(--wx-green);
    --text-color:var(--wx-text);
    --shadow-sm:none;
    --shadow-md:0 4px 16px rgba(0,0,0,.4);
}
body.theme-light{
    --wx-bg:#ededed;
    --wx-list-bg:#ededed;
    --wx-bar-bg:#f7f7f7;
    --wx-panel-bg:#ffffff;
    --wx-bubble-in:#ffffff;
    --wx-bubble-out:#95ec69;
    --wx-bubble-out-text:#0b1a0f;
    --wx-text:#191919;
    --wx-text-2:#888888;
    --wx-border:#d8d8d8;
    --wx-icon:#666666;
    --wx-green:#07c160;
    --wx-green-d:#06ad56;
    --wx-input:#ffffff;

    --primary:var(--wx-green);
    --primary-dark:var(--wx-green-d);
    --primary-light:#e7f7ee;
    --primary-bg:#eef8f2;
    --text-primary:var(--wx-text);
    --text-secondary:var(--wx-text-2);
    --text-tertiary:#a0a0a0;
    --bg-app:var(--wx-bg);
    --bg-panel:var(--wx-list-bg);
    --bg-chat:var(--wx-bg);
    --bg-hover:#e6e6e6;
    --border-color:var(--wx-border);
    --bg-primary:#ffffff;
    --bg-secondary:#f5f7fb;
    --primary-color:var(--wx-green);
    --text-color:var(--wx-text);
    --shadow-md:0 4px 16px rgba(0,0,0,.1);
}

body{ background:var(--wx-bg); color:var(--wx-text); }
.screen, #mainScreen, .content-area{ background:var(--wx-bg); }

/* ---------- 线性图标通用样式 ---------- */
.wx-ico{ width:24px; height:24px; display:block; fill:none; stroke:currentColor;
    stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
.wx-ico.sm{ width:21px; height:21px; }
.wx-ico.lg{ width:28px; height:28px; }

/* ---------- 侧栏 / 底部 Tab ---------- */
.sidebar{ background:#1f1f1f; }
body.theme-light .sidebar{ background:#f7f7f7; border-right:1px solid var(--wx-border); }
.nav-item{ color:var(--wx-icon); }
.nav-item.active{ color:var(--wx-green); }
.nav-item .wx-ico{ margin:0 auto 2px; }
body.theme-light .nav-item:hover{ color:var(--wx-green); }

/* ---------- 列表面板 ---------- */
.list-panel{ background:var(--wx-list-bg); border-right-color:var(--wx-border); }
.list-header{ border-bottom-color:var(--wx-border); }
.list-header h2{ color:var(--wx-text); font-size:17px; font-weight:600; }
.list-header .icon-btn{ color:var(--wx-text); }
/* 搜索框：保留原 no-repeat 定位，避免放大镜背景平铺（图8修复） */
.search-box input{
    background-color:var(--wx-input);
    background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='M21 21l-4.35-4.35'/%3E%3C/svg%3E");
    background-repeat:no-repeat;
    background-position:12px center;
    color:var(--wx-text);
}
.search-box input:focus{ background-color:var(--wx-input); box-shadow:0 0 0 1px var(--wx-green); }

/* 会话项 */
.chat-item{ border-bottom:1px solid var(--wx-border); padding:12px 14px; gap:12px; }
.chat-item:hover{ background:rgba(127,127,127,.08); }
.chat-item.active{ background:rgba(7,193,96,.12); }
.chat-item-avatar{ border-radius:6px; }
.chat-item-name{ color:var(--wx-text); font-size:15px; }
.chat-item-msg{ color:var(--wx-text-2); }
.chat-item-time{ color:var(--wx-text-2); }
.chat-item-badge,.nav-badge,.quick-badge{ background:#fa5151; }
/* 未读角标移到消息摘要行右侧，避免压住右上角时间（微信版式） */
.chat-item-badge{ top:auto; bottom:12px; right:14px; }
.chat-item.unread .chat-item-msg{ padding-right:34px; }

/* 通讯录 */
.contact-quick-icon{ background:var(--wx-green); }
.contact-item:hover,.contact-quick-item:hover{ background:rgba(127,127,127,.08); }
.contact-letter{ color:var(--wx-text-2); background:var(--wx-list-bg); }

/* ---------- 设置页 ---------- */
.settings-item{ background:var(--wx-panel-bg); border-bottom-color:var(--wx-bg); }
.settings-item > span:first-child{ color:var(--wx-text); }
.settings-value,.chevron,.settings-section-title{ color:var(--wx-text-2); }
.settings-profile{ border-bottom:1px solid var(--wx-bg); }
.settings-profile-name{ color:var(--wx-text); }
.settings-logout-btn{ background:var(--wx-panel-bg); color:#fa5151; border-top:1px solid var(--wx-bg); }
body.theme-dark .settings-logout-btn{ color:#ff6b6b; }

/* ---------- 聊天头部：标题居中 + 返回未读 ---------- */
.chat-header{
    position:relative; height:56px; padding:0 8px;
    background:var(--wx-bar-bg); border-bottom-color:var(--wx-border);
    justify-content:space-between;
}
.chat-header .mobile-back-btn{
    width:44px; height:44px; margin-right:0; color:var(--wx-text);
    position:relative; z-index:2; gap:2px;
}
.back-badge{
    font-size:13px; color:var(--wx-green); font-weight:500; margin-left:2px; min-width:8px;
}
.chat-header-info{
    position:absolute; left:50%; top:0; height:100%;
    transform:translateX(-50%); text-align:center;
    display:flex; flex-direction:column; align-items:center; justify-content:center;
    max-width:56%; pointer-events:none; z-index:1;
}
.chat-header-name{ font-size:17px; font-weight:600; color:var(--wx-text);
    max-width:100%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chat-header-sub{ font-size:11px; color:var(--wx-text-2); margin-top:1px; }
.chat-header-actions{ gap:4px; z-index:2; }
.chat-header-actions .icon-btn{ color:var(--wx-text); }

/* ---------- 消息列表与气泡 ---------- */
.message-list{ background:var(--wx-bg); }
.msg-time-sep span,.msg-day-sep span{ color:#a0a0a0; background:rgba(127,127,127,.12); }
.msg-system span{ color:#c8c8c8; background:rgba(127,127,127,.16); }

.msg-avatar{ border-radius:5px; }
.msg-row.received .msg-bubble{
    background:var(--wx-bubble-in); color:var(--wx-text);
    border-radius:5px; box-shadow:none;
}
.msg-row.sent .msg-bubble{
    background:var(--wx-bubble-out); color:var(--wx-bubble-out-text);
    border-radius:5px; box-shadow:none;
}
/* 气泡小尖角 */
.msg-row .msg-bubble{ position:relative; }
.msg-row.received .msg-bubble::before,
.msg-row.sent .msg-bubble::after{
    content:""; position:absolute; top:12px; width:0; height:0;
    border:6px solid transparent;
}
.msg-row.received .msg-bubble::before{ left:-11px; border-right-color:var(--wx-bubble-in); }
.msg-row.sent .msg-bubble::after{ right:-11px; border-left-color:var(--wx-bubble-out); }
.msg-bubble.image-msg{padding:0;background:transparent!important;box-shadow:none!important;}
.msg-bubble.image-msg::before,.msg-bubble.image-msg::after{display:none;}
.msg-meta-time,.msg-read-status,.msg-unread-dot,.msg-sender-name{ color:var(--wx-text-2); }
.msg-read-status.read{ color:var(--wx-green); }
.msg-quote{ background:rgba(127,127,127,.12); color:var(--wx-text-2); }
.msg-bubble.quote-msg{ border-left-color:var(--wx-green); }

/* ---------- 输入区（微信式） ---------- */
.input-area{
    background:var(--wx-bar-bg); border-top-color:var(--wx-border);
    padding:8px 10px calc(8px + env(safe-area-inset-bottom,0px));
}
.input-toolbar{ display:none; } /* 旧工具栏隐藏，功能移入 + 号面板（保留 DOM 与绑定） */

.wx-input-row{ display:flex; align-items:flex-end; gap:6px; min-width:0; width:100%; box-sizing:border-box; }
.wx-input-box{
    flex:1 1 0; min-width:0; position:relative; display:flex; align-items:flex-end;
    background:var(--wx-input); border-radius:6px; min-height:40px;
}
#messageInput{
    flex:1 1 0; min-width:0; width:100%; border:none; background:transparent; color:var(--wx-text);
    border-radius:6px; padding:9px 12px; font-size:16px;
    min-height:40px; max-height:120px; line-height:1.4; resize:none; outline:none;
}
#messageInput::placeholder{ color:var(--wx-text-2); }

.wx-icon-btn{
    width:38px; height:40px; flex:0 0 38px; border:none; background:transparent;
    color:var(--wx-icon); cursor:pointer; display:flex; align-items:center;
    justify-content:center; padding:0; -webkit-tap-highlight-color:transparent;
}
.wx-icon-btn:active{ opacity:.6; }
.wx-icon-btn.active{ color:var(--wx-green); }
/* 防止输入栏任何子元素撑破容器导致 + 号溢出屏幕 */
.input-area, .wx-input-row{ max-width:100%; box-sizing:border-box; }
#messageInput{ box-sizing:border-box; max-width:100%; }
/* 所有按钮固定宽度、绝不收缩；输入框优先收缩，保证 +/发送 永远在屏内 */
.wx-input-row > .wx-icon-btn, .wx-input-row > #sendBtn{ flex:0 0 auto; }

#sendBtn{
    width:auto; min-width:56px; height:38px; padding:0 12px;
    background:var(--wx-green); color:#fff; border:none; border-radius:5px;
    font-size:15px; font-weight:500; cursor:pointer; flex-shrink:0;
    display:flex; align-items:center; justify-content:center;
}
#sendBtn:hover{ background:var(--wx-green-d); }
#sendBtn:disabled{ background:#b9b9b9; cursor:not-allowed; }
.voice-mode-btn.active{ background:transparent; color:var(--wx-green); }
.voice-record-bar{ background:var(--wx-input); border-color:var(--wx-border); }
.voice-record-prompt{ color:var(--wx-text-2); }

/* ---------- + 号功能面板 ---------- */
.more-panel{
    display:none; background:var(--wx-bar-bg); border-top:1px solid var(--wx-border);
    padding:16px 8px calc(20px + env(safe-area-inset-bottom,0px));
    animation:wxFade .16s ease;
}
@keyframes wxFade{ from{opacity:0;transform:translateY(6px);} to{opacity:1;transform:none;} }
.more-grid{
    display:grid; grid-template-columns:repeat(4,1fr); row-gap:20px; column-gap:4px;
}
.more-item{
    display:flex; flex-direction:column; align-items:center; gap:8px;
    border:none; background:transparent; color:var(--wx-text); cursor:pointer;
    font-size:12px; padding:6px 2px; -webkit-tap-highlight-color:transparent;
}
.more-item:active{ opacity:.6; }
.more-item .more-ico{
    width:52px; height:52px; border-radius:12px; background:var(--wx-panel-bg);
    display:flex; align-items:center; justify-content:center; color:var(--wx-text);
}
.more-item .wx-ico{ width:27px; height:27px; }
.more-item.muted .more-ico{ color:var(--wx-text-2); }

/* ---------- 通话方式选择弹窗（参照视频：视频通话/语音通话/取消） ---------- */
.wx-sheet{
    position:fixed; left:0; right:0; bottom:0; z-index:1200;
    background:var(--wx-panel-bg); border-radius:14px 14px 0 0;
    padding-bottom:env(safe-area-inset-bottom,0px);
    animation:wxUp .2s ease;
}
@keyframes wxUp{ from{transform:translateY(100%);} to{transform:none;} }
.wx-sheet-mask{ position:fixed; inset:0; background:rgba(0,0,0,.45); z-index:1199; }
.wx-sheet-item{
    height:56px; display:flex; align-items:center; justify-content:center; gap:10px;
    font-size:17px; color:var(--wx-text); cursor:pointer;
    border-bottom:1px solid var(--wx-border);
}
.wx-sheet-item:active{ background:rgba(127,127,127,.12); }
.wx-sheet-item .wx-ico{ width:22px; height:22px; }
.wx-sheet-cancel{
    height:56px; display:flex; align-items:center; justify-content:center;
    font-size:17px; color:var(--wx-text-2); cursor:pointer; margin-top:8px;
    background:var(--wx-panel-bg);
}

/* ---------- 表情面板 ---------- */
.emoji-panel{
    background:var(--wx-panel-bg); border-color:var(--wx-border);
    bottom:calc(56px + env(safe-area-inset-bottom,0px));
}
.emoji-tabs{ border-bottom-color:var(--wx-border); }
.emoji-tab{ color:var(--wx-text-2); }
.emoji-tab.active{ color:var(--wx-green); border-bottom-color:var(--wx-green); }
.emoji-item:hover{ background:rgba(127,127,127,.12); }

/* ---------- 模态框 ---------- */
.modal{ background:var(--wx-panel-bg); color:var(--wx-text); }
.modal-header{ border-bottom-color:var(--wx-border); }
.modal-header h3{ color:var(--wx-text); }
.modal-close,.modal-edit{ color:var(--wx-text); }
.form-input{ background:var(--wx-input); color:var(--wx-text); border-color:var(--wx-border); }
.form-input:focus{ background:var(--wx-input); border-color:var(--wx-green); }

/* ---------- 移动端微调 ---------- */
@media (max-width:768px), (max-width:1024px) and (pointer:coarse){
    .sidebar{ background:#1f1f1f; }
    body.theme-light .sidebar{ background:#f7f7f7; }
    .sidebar .nav-item.active{ color:var(--wx-green); }
    .chat-header{ height:52px; padding:0 4px; }
    #sendBtn{ height:40px; }
    .chat-header-actions .icon-btn{ width:40px; height:40px; }
}

/* ==================== 好友资料工具（备注 / 清除聊天记录） ==================== */
.profile-friend-tools{
    margin:8px 0 4px; padding:0 16px;
}
.profile-tool-btn{
    width:100%; display:flex; align-items:center; gap:10px;
    padding:13px 14px; margin-bottom:8px; border:none; border-radius:8px;
    background:var(--wx-panel-bg); color:var(--wx-text); font-size:15px;
    cursor:pointer; text-align:left; box-shadow:var(--shadow-sm);
}
.profile-tool-btn:active{ opacity:.7; }
.profile-tool-btn .wx-ico{ color:var(--wx-green); flex-shrink:0; }
.profile-tool-btn .tool-value{
    margin-left:auto; color:var(--wx-text-2); font-size:13px;
    max-width:45%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.profile-tool-btn.danger .wx-ico{ color:#fa5151; }
.profile-tool-btn.danger{ color:#fa5151; }

/* ==================== 字体大小调节 ==================== */
/* 以 --wx-font-scale 为倍数，覆盖核心文字；默认 1（标准） */
body.font-small  { --wx-font-scale:0.88; }
body.font-normal { --wx-font-scale:1; }
body.font-large  { --wx-font-scale:1.15; }
body.font-xlarge { --wx-font-scale:1.32; }

body.font-small .msg-bubble,
body.font-normal .msg-bubble,
body.font-large .msg-bubble,
body.font-xlarge .msg-bubble{
    font-size:calc(15px * var(--wx-font-scale));
}
body.font-small .chat-item-name,
body.font-normal .chat-item-name,
body.font-large .chat-item-name,
body.font-xlarge .chat-item-name{
    font-size:calc(15px * var(--wx-font-scale));
}
body.font-small .chat-item-msg,
body.font-normal .chat-item-msg,
body.font-large .chat-item-msg,
body.font-xlarge .chat-item-msg{
    font-size:calc(13px * var(--wx-font-scale));
}
body.font-small .chat-item-time,
body.font-normal .chat-item-time,
body.font-large .chat-item-time,
body.font-xlarge .chat-item-time{
    font-size:calc(12px * var(--wx-font-scale));
}
body.font-small .contact-item-name,
body.font-normal .contact-item-name,
body.font-large .contact-item-name,
body.font-xlarge .contact-item-name{
    font-size:calc(15px * var(--wx-font-scale));
}
body.font-small .contact-item-sub,
body.font-normal .contact-item-sub,
body.font-large .contact-item-sub,
body.font-xlarge .contact-item-sub{
    font-size:calc(12px * var(--wx-font-scale));
}
body.font-small .msg-meta-time,
body.font-small .msg-read-status,
body.font-normal .msg-meta-time,
body.font-normal .msg-read-status,
body.font-large .msg-meta-time,
body.font-large .msg-read-status,
body.font-xlarge .msg-meta-time,
body.font-xlarge .msg-read-status{
    font-size:calc(11px * var(--wx-font-scale));
}
body.font-small .settings-item > span:first-child,
body.font-large .settings-item > span:first-child,
body.font-xlarge .settings-item > span:first-child{
    font-size:calc(15px * var(--wx-font-scale));
}

/* ==================== 备忘录 ==================== */
.memo-modal{ width:min(94vw,520px); }
.memo-add-row{ display:flex; flex-direction:column; gap:8px; margin-bottom:14px; }
.memo-add-row textarea{ resize:vertical; }
.memo-list{ display:flex; flex-direction:column; gap:10px; }
.memo-empty{ padding:32px 16px; text-align:center; color:var(--wx-text-2); font-size:14px; }
.memo-item{
    background:var(--wx-panel-bg); border-radius:8px; padding:12px 14px;
    border:1px solid var(--wx-border);
}
.memo-item-text{ color:var(--wx-text); font-size:15px; line-height:1.5; word-break:break-word; white-space:pre-wrap; }
.memo-item-meta{ color:var(--wx-text-2); font-size:12px; margin-top:6px; }
.memo-item-actions{ display:flex; gap:16px; margin-top:8px; justify-content:flex-end; }
.memo-item-actions button{
    border:none; background:transparent; color:var(--wx-green); font-size:13px;
    cursor:pointer; padding:4px 6px;
}
.memo-item-actions button:last-child{ color:#fa5151; }
.memo-item-actions button:active{ opacity:.6; }

/* ==================== 深色模式文字对比度修复 ==================== */
/* 输入框聚焦时原样式 background:#fff 导致深色下白底白字 */
#messageInput:focus{ background:transparent; color:var(--wx-text); }

/* 长按消息菜单：原样式硬编码白底且无文字色，深色下白底白字看不见 */
.context-menu{
    background:var(--wx-panel-bg);
    border:1px solid var(--wx-border);
}
.ctx-item{ color:var(--wx-text); }
.ctx-item:hover{ background:var(--bg-hover); color:var(--wx-green); }
.ctx-item.danger:hover{ background:rgba(250,81,81,.12); color:#fa5151; }
.ctx-sep{ background:var(--wx-border); }

/* ==================== 备忘录：标题 / 分类 / 修改 ==================== */
.memo-add-row input#memoTitleInput{ font-weight:600; }
.memo-cat-picker, .memo-filter-bar{ display:flex; flex-wrap:wrap; gap:6px; }
.memo-cat-picker .memo-cat{
    border:1px solid var(--wx-border); background:var(--wx-input); color:var(--wx-text-2);
    border-radius:16px; padding:5px 12px; font-size:13px; cursor:pointer;
}
.memo-cat-picker .memo-cat.active{
    background:var(--wx-green); color:#fff; border-color:var(--wx-green);
}
.memo-add-actions{ display:flex; gap:10px; justify-content:flex-end; }
.memo-add-actions .btn-primary{ background:var(--wx-green); color:#fff; border:none; border-radius:6px; padding:8px 20px; font-size:14px; cursor:pointer; }
.memo-add-actions .btn-secondary{ background:var(--wx-input); color:var(--wx-text); border:1px solid var(--wx-border); border-radius:6px; padding:8px 16px; font-size:14px; cursor:pointer; }
.memo-filter-bar{ border-bottom:1px solid var(--wx-border); padding-bottom:10px; margin-bottom:4px; }
.memo-filter-bar .memo-filter{
    border:none; background:transparent; color:var(--wx-text-2);
    padding:5px 10px; font-size:13px; border-radius:6px; cursor:pointer;
}
.memo-filter-bar .memo-filter.active{ background:var(--wx-panel-bg); color:var(--wx-green); font-weight:600; box-shadow:var(--shadow-sm); }
.memo-item-head{ display:flex; align-items:center; gap:8px; justify-content:space-between; }
.memo-item-title{ font-size:15px; font-weight:600; color:var(--wx-text); flex:1; word-break:break-word; }
.memo-cat-tag{
    background:var(--primary-bg,var(--wx-input)); color:var(--wx-green);
    font-size:11px; padding:2px 9px; border-radius:10px; flex-shrink:0;
}
.memo-item-actions button:nth-child(2){ color:var(--wx-green) !important; }
