/* ==========================================================
   base.css — 设计变量、主题（浅 / 深 / 跟随系统）、重置
   主题由 <html data-theme="light|dark|system"> 控制
   其余可调项由 js/settings.js 写入 :root 行内变量
   ========================================================== */

/* ---------- 自托管字体（东南亚文字，仅含对应文字子集；可变字重 100–900，覆盖 Regular 与 Medium） ---------- */
@font-face { font-family: "IM Noto Sans Khmer";   src: url("../assets/fonts/noto-sans-khmer-vf.woff2") format("woff2");   font-weight: 100 900; font-display: swap; unicode-range: U+1780-17FF, U+19E0-19FF, U+200C-200D, U+25CC; }
@font-face { font-family: "IM Noto Sans Thai";    src: url("../assets/fonts/noto-sans-thai-vf.woff2") format("woff2");    font-weight: 100 900; font-display: swap; unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "IM Noto Sans Myanmar"; src: url("../assets/fonts/noto-sans-myanmar-vf.woff2") format("woff2"); font-weight: 100 900; font-display: swap; unicode-range: U+1000-109F, U+200C-200D, U+25CC, U+A92E, U+A9E0-A9FE, U+AA60-AA7F; }
@font-face { font-family: "IM Noto Sans Lao";     src: url("../assets/fonts/noto-sans-lao-vf.woff2") format("woff2");     font-weight: 100 900; font-display: swap; unicode-range: U+0E81-0EDF, U+200C-200D, U+25CC; }

:root {
  /* —— 可由设置覆盖的变量（默认值） —— */
  --accent: #3390ec;
  --fs: 15px;
  /* 按 <html lang> 切换的首选文字字体；不存在的族名会被浏览器跳过 */
  --font-lang: im-none;
  --lh: 1.4;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --bubble-radius: 12px;
  --avatar-radius: 50%;
  --side-w: 360px;
  --item-h: 72px;
  --item-avatar: 54px;

  /* —— 由主色派生 —— */
  --accent-hover: color-mix(in srgb, var(--accent) 86%, #000);
  --accent-soft: color-mix(in srgb, var(--accent) 12%, var(--bg));
  --on-accent: #ffffff;

  /* —— 浅色主题 —— */
  --bg: #ffffff;
  --bg-soft: #f4f4f5;
  --bg-hover: #f2f3f5;
  --chat-bg: #dde6ee;
  --text: #0f1419;
  --text-2: #707579;
  --text-3: #a2acb4;
  --border: #e6e8ea;
  --border-strong: #c3cad1;
  --bubble-in: #ffffff;
  --bubble-out: var(--accent);
  --bubble-out-text: #ffffff;
  --bubble-out-meta: rgba(255, 255, 255, .78);
  --bubble-out-quote: rgba(255, 255, 255, .18);
  --bg-active: var(--accent);
  --badge-muted: #a7afb6;
  --online: #2fb35a;
  --danger: #e04b4b;
  --sys-bg: rgba(40, 60, 80, .32);
  --overlay: rgba(0, 0, 0, .32);
  --shadow: 0 2px 10px rgba(0, 0, 0, .10);
  --radius: 12px;
  --radius-sm: 8px;
  --head-h: 56px;
  --chat-pattern: none;

  /* —— 界面风格（css/themes/*.css 覆盖；默认值 = telegram，与改造前一致） —— */
  --head-bg: var(--bg);              /* 对话顶栏 */
  --head-fg: var(--text);
  --head-fg-2: var(--text-2);
  --head-accent: var(--accent);      /* 顶栏里的「在线 / 正在输入」 */
  --head-border: var(--border);
  --side-head-bg: var(--bg);         /* 左栏顶部（搜索栏所在） */
  --list-sep: transparent;           /* 会话列表分隔线（从文字起点画到右边） */
  --item-active-bg: var(--bg-active);/* 列表选中行 */
  --item-active-fg: #fff;
  --item-active-fg-2: #fff;
  --badge-bg: var(--accent);         /* 未读角标 */
  --badge-fg: var(--on-accent);
  --bubble-out-line: #fff;           /* 自己气泡里的引用竖线 / 引用名 / 链接卡竖线 / 我点的表情底 */
  --receipt-read: currentColor;      /* 已读双勾 */
  --composer-bg: transparent;        /* 输入栏整条 */
  --composer-input-bg: var(--bg);    /* 输入框 */
  --composer-input-radius: var(--radius);
  --composer-btn-bg: var(--bg);      /* 输入栏两侧圆按钮底 */
  --send-bg: var(--accent);
  --send-fg: var(--on-accent);

  --c1: #3390ec; --c2: #e3735a; --c3: #2fae8f; --c4: #e0a030;
  --c5: #4aa7c9; --c6: #d4566e; --c7: #5b8a3c;
  color-scheme: light;
}

/* 深色变量：手动深色 */
:root[data-theme="dark"] {
  --bg: #17212b;
  --bg-soft: #0f1923;
  --bg-hover: #202b36;
  --chat-bg: #0e1621;
  --text: #e8edf1;
  --text-2: #8b98a5;
  --text-3: #627080;
  --border: #253240;
  --border-strong: #3a4a5b;
  --bubble-in: #1c2a38;
  --bubble-out: color-mix(in srgb, var(--accent) 52%, #17212b);
  --bubble-out-text: #eef4fa;
  --bubble-out-meta: rgba(220, 235, 250, .65);
  --bubble-out-quote: rgba(255, 255, 255, .10);
  --bg-active: color-mix(in srgb, var(--accent) 52%, #17212b);
  --badge-muted: #4c5966;
  --sys-bg: rgba(60, 80, 100, .55);
  --overlay: rgba(0, 0, 0, .5);
  --shadow: 0 2px 12px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

/* 深色变量：跟随系统（与上方保持一致） */
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #17212b;
    --bg-soft: #0f1923;
    --bg-hover: #202b36;
    --chat-bg: #0e1621;
    --text: #e8edf1;
    --text-2: #8b98a5;
    --text-3: #627080;
    --border: #253240;
    --border-strong: #3a4a5b;
    --bubble-in: #1c2a38;
    --bubble-out: color-mix(in srgb, var(--accent) 52%, #17212b);
    --bubble-out-text: #eef4fa;
    --bubble-out-meta: rgba(220, 235, 250, .65);
    --bubble-out-quote: rgba(255, 255, 255, .10);
    --bg-active: color-mix(in srgb, var(--accent) 52%, #17212b);
    --badge-muted: #4c5966;
    --sys-bg: rgba(60, 80, 100, .55);
    --overlay: rgba(0, 0, 0, .5);
    --shadow: 0 2px 12px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

/* 按语言切字体栈 / 行高 */
:root:lang(km) { --font-lang: "IM Noto Sans Khmer"; }
:root:lang(th) { --font-lang: "IM Noto Sans Thai"; }
:root:lang(my) { --font-lang: "IM Noto Sans Myanmar"; --lh: 1.61; } /* 1.4 × 1.15 */
:root:lang(lo) { --font-lang: "IM Noto Sans Lao"; }
:root:lang(zh-TW) { --font-lang: "PingFang TC", "Microsoft JhengHei", "Noto Sans CJK TC"; }

/* 头像形状 */
:root[data-avatar="rounded"] { --avatar-radius: min(24%, 14px); }

/* 列表密度 */
:root[data-density="compact"] { --item-h: 56px; --item-avatar: 42px; }

/* 聊天背景图案 */
:root[data-chat-bg="dots"]   { --chat-pattern: url("../assets/bg/dots.svg"); }
:root[data-chat-bg="grid"]   { --chat-pattern: url("../assets/bg/grid.svg"); }
:root[data-chat-bg="waves"]  { --chat-pattern: url("../assets/bg/waves.svg"); }
:root[data-chat-bg="custom"] { --chat-pattern: var(--chat-custom, none); }

/* —— 重置 —— */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  /* 语言首选字体 → 用户所选字体栈 → 四种自托管文字兜底（任何语言下都能显示语言名） */
  font-family: var(--font-lang), var(--font), "IM Noto Sans Khmer", "IM Noto Sans Thai", "IM Noto Sans Myanmar", "IM Noto Sans Lao", sans-serif;
  font-size: var(--fs);
  line-height: var(--lh);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, h3, h4, p { margin: 0; }
img { max-width: 100%; }
.ti { font-size: 22px; line-height: 1; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="checkbox"], input[type="range"] { accent-color: var(--accent); }
[hidden] { display: none !important; }

/* —— 细滚动条（6px，轨道透明） —— */
.scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.scroll::-webkit-scrollbar-track { background: transparent; }
.scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.scroll::-webkit-scrollbar-thumb:hover { background: var(--text-3); }
@supports not selector(::-webkit-scrollbar) {
  .scroll { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
