/* ==========================================================================
   ISTIC 主题 (ASK-002): 在 style.css 之后加载, 只覆盖变量和少量变量够不到的选择器。
   参照客户的 KaiWu (开物 / 兰台) 模板: 冷色、通透 —— slate 灰底、白色卡片、细边框、
   极淡阴影, 单一 indigo → violet 强调色; 全部无衬线。深色由同一 slate / indigo 色系推出。
   布局、文字与行为不变; 无外部字体 / 图片 / CDN。
   ========================================================================== */

:root {
  --font-sans: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-serif: var(--font-sans); /* 模板的标题也是无衬线 (加粗) */

  /* 浅色: slate-50 底, 白色侧栏与卡片 */
  --bg: #F8FAFC;
  --side: #FFFFFF;
  --surface: #FFFFFF;
  --bubble: #EEF2FF;
  --text: #0F172A;
  --text-2: #334155;
  --text-3: #64748B;
  --text-4: #94A3B8;
  --line: rgba(15, 23, 42, .09);
  --line-2: rgba(15, 23, 42, .13);
  --line-3: rgba(15, 23, 42, .24);
  --hover: rgba(15, 23, 42, .04);
  --hover-2: rgba(15, 23, 42, .07);
  --side-hover: rgba(15, 23, 42, .04);
  --side-active: rgba(79, 70, 229, .08);
  --nav-hover: rgba(15, 23, 42, .05);
  --code-bg: rgba(15, 23, 42, .06);
  --code-block: #F1F5F9;
  --scroll: #CBD5E1;
  --backdrop: rgba(15, 23, 42, .36);

  --brand: #4F46E5;
  --brand-hover: #4338CA;
  --brand-text: #4338CA;
  --brand-soft: rgba(79, 70, 229, .08);
  --brand-line: rgba(79, 70, 229, .30);
  --on-brand: #FFFFFF;
  --focus: rgba(79, 70, 229, .50);

  /* ISTIC 专用 (导航选中态; 图标栏 ASK-003 复用): 淡色选中行 / 实心选中块 / 图标栏底色 / 品牌渐变 */
  --istic-active-bg: var(--brand-soft);
  --istic-active-text: var(--brand-text);
  --istic-active-fill: var(--brand);
  --istic-on-active-fill: var(--on-brand);
  --istic-rail: #F8FAFC;
  --istic-grad: linear-gradient(135deg, #4F46E5, #9333EA);

  --amber: #B45309;
  --amber-bg: #FFFBEB;
  --amber-line: #FDE68A;
  --danger: #DC2626;
  --run-err: var(--danger);
  --note-text: var(--text-3);
  --note-line: var(--line-2);
  --danger-bg: #FEF2F2;
  --danger-line: #FECACA;
  --on-danger: #FFFFFF;
  --ok: #047857;
  --ok-bg: #ECFDF5;

  /* 模型配色: 模板用的 blue / emerald / amber / violet / rose / cyan / lime / slate */
  --m0: #2563EB; --m1: #059669; --m2: #D97706; --m3: #7C3AED;
  --m4: #E11D48; --m5: #0891B2; --m6: #65A30D; --m7: #64748B;
  --on-accent: #FFFFFF;

  --shadow-1: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-composer: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(79, 70, 229, .06);
  --shadow-composer-focus: 0 0 0 3px rgba(79, 70, 229, .10), 0 10px 28px rgba(79, 70, 229, .10);
  --shadow-pop: 0 10px 32px rgba(15, 23, 42, .10), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow-modal: 0 24px 72px rgba(15, 23, 42, .18), 0 2px 6px rgba(15, 23, 42, .06);
}

/* 深色: 跟随系统 (未手动指定浅色时) 与手动指定, 两处取值相同 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F172A; --side: #0B1222; --surface: #1E293B; --bubble: #272E52;
    --text: #F1F5F9; --text-2: #CBD5E1; --text-3: #94A3B8; --text-4: #64748B;
    --line: rgba(226, 232, 240, .10); --line-2: rgba(226, 232, 240, .15); --line-3: rgba(226, 232, 240, .26);
    --hover: rgba(226, 232, 240, .06); --hover-2: rgba(226, 232, 240, .09);
    --side-hover: rgba(226, 232, 240, .05); --side-active: rgba(129, 140, 248, .16); --nav-hover: rgba(226, 232, 240, .07);
    --code-bg: rgba(226, 232, 240, .09); --code-block: #0B1222; --scroll: rgba(226, 232, 240, .18); --backdrop: rgba(2, 6, 23, .6);
    --brand: #4F46E5; --brand-hover: #6366F1; --brand-text: #A5B4FC;
    --brand-soft: rgba(129, 140, 248, .16); --brand-line: rgba(129, 140, 248, .42); --focus: rgba(165, 180, 252, .6);
    --on-brand: #FFFFFF; --istic-rail: #0B1222;
    --run-err: var(--danger); --seg-on: #334155;
    --m0: #60A5FA; --m1: #34D399; --m2: #FBBF24; --m3: #A78BFA; --m4: #FB7185; --m5: #22D3EE; --m6: #A3E635; --m7: #94A3B8;
    --on-accent: #0F172A;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .25);
    --shadow-composer: 0 1px 2px rgba(0, 0, 0, .25), 0 8px 24px rgba(0, 0, 0, .22);
    --shadow-composer-focus: 0 0 0 3px rgba(129, 140, 248, .18), 0 10px 28px rgba(0, 0, 0, .3);
    --shadow-pop: 0 10px 32px rgba(0, 0, 0, .45), 0 1px 3px rgba(0, 0, 0, .3);
    --shadow-modal: 0 24px 72px rgba(0, 0, 0, .55);
  }
}
:root[data-theme="dark"] {
  --bg: #0F172A; --side: #0B1222; --surface: #1E293B; --bubble: #272E52;
  --text: #F1F5F9; --text-2: #CBD5E1; --text-3: #94A3B8; --text-4: #64748B;
  --line: rgba(226, 232, 240, .10); --line-2: rgba(226, 232, 240, .15); --line-3: rgba(226, 232, 240, .26);
  --hover: rgba(226, 232, 240, .06); --hover-2: rgba(226, 232, 240, .09);
  --side-hover: rgba(226, 232, 240, .05); --side-active: rgba(129, 140, 248, .16); --nav-hover: rgba(226, 232, 240, .07);
  --code-bg: rgba(226, 232, 240, .09); --code-block: #0B1222; --scroll: rgba(226, 232, 240, .18); --backdrop: rgba(2, 6, 23, .6);
  --brand: #4F46E5; --brand-hover: #6366F1; --brand-text: #A5B4FC;
  --brand-soft: rgba(129, 140, 248, .16); --brand-line: rgba(129, 140, 248, .42); --focus: rgba(165, 180, 252, .6);
  --on-brand: #FFFFFF; --istic-rail: #0B1222;
  --run-err: var(--danger); --seg-on: #334155;
  --m0: #60A5FA; --m1: #34D399; --m2: #FBBF24; --m3: #A78BFA; --m4: #FB7185; --m5: #22D3EE; --m6: #A3E635; --m7: #94A3B8;
  --on-accent: #0F172A;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .25);
  --shadow-composer: 0 1px 2px rgba(0, 0, 0, .25), 0 8px 24px rgba(0, 0, 0, .22);
  --shadow-composer-focus: 0 0 0 3px rgba(129, 140, 248, .18), 0 10px 28px rgba(0, 0, 0, .3);
  --shadow-pop: 0 10px 32px rgba(0, 0, 0, .45), 0 1px 3px rgba(0, 0, 0, .3);
  --shadow-modal: 0 24px 72px rgba(0, 0, 0, .55);
}

/* ---------------- 变量够不到的地方 ---------------- */

/* 标题: 模板是加粗的无衬线 */
.greeting, .auth-title, .admin-title, .pj-h1 { font-weight: 700; letter-spacing: 0; }
.brand-name, .auth-brand-name, .modal-head h2, .form-head h3, .rtp-title, .admin-sec-head h2,
.admin-card h3, .sup-card-head h2, .grp-page-head h2, .md h3 { font-weight: 600; letter-spacing: 0; }

/* 侧栏当前页与当前聊天: 淡 indigo 底 + 强调色文字 (模板的选中项) */
.nav-item[aria-current="page"] { background: var(--istic-active-bg); color: var(--istic-active-text); font-weight: 500; }
.hist-item.active .hist-open { color: var(--istic-active-text); font-weight: 500; }
.sys-nav-item[aria-current="page"] { background: var(--istic-active-bg); color: var(--istic-active-text); }

/* 发送按钮: 模板是圆角方块 + 实心强调色 */
.send-btn { border-radius: 10px; }

/* style.css 里写死的颜色: 其余已是变量 (--note-text / --note-line / --run-err / --seg-on, 在上面的根变量里); 录音计时没有变量 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .rec-time { color: #A5B4FC; }
}
:root[data-theme="dark"] .rec-time { color: #A5B4FC; }

/* ==========================================================================
   ASK-003 图标栏: 侧栏改成模板 (KaiWu) 的外壳 —— 左边 64px 图标栏 + 右边 216px 二级面板 (共 280px)。
   只用 CSS 作用在现有结构上: .sidebar 变成网格, .side-top / .brand 用 display: contents 拆开放格子。
     第 1 列 (图标栏): 品牌方块 / 主要操作 (图标在上、文字在下) / 收起按钮 (收起时) / 外观 语言 用量 + 头像
     第 2 列 (面板):   标题行 (品牌名 + 收起按钮) / 项目 已置顶 最近 列表
   选择器都以 #sidebar 开头, 好压过 style.css 里 :root[data-side="collapsed"] 的窄栏规则。
   宽屏收起 = 只剩图标栏 (64px); 窄屏 (≤860px) 仍是抽屉, 抽屉里同样是图标栏 + 面板。
   ========================================================================== */
:root { --side-w: 280px; --rail-w: 64px; }

#sidebar {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  grid-template-rows: 64px minmax(0, 1fr) auto auto;
  /* 图标栏底色 + 1px 分隔线, 面板白底 */
  background:
    linear-gradient(to right, transparent 63px, var(--line) 63px 64px, transparent 64px),
    linear-gradient(to right, var(--istic-rail) 64px, var(--side) 64px);
}
#sidebar .side-top, #sidebar .brand { display: contents; }

/* 品牌方块: 40px 圆角渐变块, 里面的标志画成白色 */
#sidebar .brand-mark {
  grid-column: 1; grid-row: 1; place-self: center;
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: var(--istic-grad); box-shadow: 0 4px 10px -2px rgba(79, 70, 229, .35);
}
#sidebar .brand-mark img, #sidebar .brand-mark svg { width: 26px; height: 16px; object-fit: contain; filter: brightness(0) invert(1); }

/* 面板标题行: 气泡图标 + 加粗标题, 下边一条线; 收起按钮靠右 */
#sidebar .brand-name {
  grid-column: 2; grid-row: 1; align-self: stretch;
  display: flex; align-items: center; gap: 10px; min-width: 0; padding: 0 52px 0 20px;
  border-bottom: 1px solid var(--line); font: 700 15px/1.2 var(--font-sans); color: var(--text);
  overflow: hidden; text-overflow: ellipsis;
}
#sidebar .brand-name::before {
  content: ""; flex: none; width: 18px; height: 18px; background: var(--brand-text);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 12a8 8 0 0 1-11.8 7L4 20.5l1.5-4.9A8 8 0 1 1 21 12z'/%3E%3Cpath d='M8.5 12h.01M12 12h.01M15.5 12h.01'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 12a8 8 0 0 1-11.8 7L4 20.5l1.5-4.9A8 8 0 1 1 21 12z'/%3E%3Cpath d='M8.5 12h.01M12 12h.01M15.5 12h.01'/%3E%3C/svg%3E") center / contain no-repeat;
}
#sidebar #btn-collapse { grid-column: 2; grid-row: 1; justify-self: end; align-self: center; margin-right: 12px; color: var(--text-3); }
#sidebar #btn-collapse:hover { color: var(--text); }

/* 主要操作: 图标栏里一列方块, 上面一条 32px 短线 */
#sidebar .side-nav {
  grid-column: 1; grid-row: 2; min-height: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 4px 0 12px; overflow-x: hidden; overflow-y: auto; scrollbar-width: none;
}
#sidebar .side-nav::-webkit-scrollbar { display: none; }
#sidebar .side-nav::before { content: ""; flex: none; width: 32px; height: 1px; margin-bottom: 8px; background: var(--line-2); }
#sidebar .nav-item {
  flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  width: 52px; height: auto; min-height: 52px; padding: 6px 2px; border-radius: 12px;
  color: var(--text-3); font-size: 11px; font-weight: 600; line-height: 1.2; text-align: center; white-space: normal;
  transition: background-color .15s var(--ease), color .15s var(--ease), box-shadow .15s var(--ease);
}
#sidebar .nav-label { flex: none; max-width: 100%; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; }
:root[lang="en"] #sidebar .nav-label { font-size: 9.5px; letter-spacing: -.01em; overflow-wrap: normal; } /* 英文 "Scheduled tasks" 折两行也不出栏 */
#sidebar .kbd-hint { display: none; }
#sidebar .nav-item:hover { background: var(--hover-2); color: var(--text); }
/* 当前页 (以及聊天页时的「新建聊天」): 实心强调色方块 + 右外侧一道 4×16 小竖条 */
#sidebar .nav-item[aria-current="page"],
body[data-view="app"] #sidebar .side-nav:not(:has([aria-current="page"])) #btn-new-chat {
  background: var(--istic-active-fill); color: var(--istic-on-active-fill);
  box-shadow: 0 6px 14px -4px rgba(79, 70, 229, .45);
}
#sidebar .nav-item[aria-current="page"]::before,
body[data-view="app"] #sidebar .side-nav:not(:has([aria-current="page"])) #btn-new-chat::before {
  content: ""; position: absolute; top: 50%; left: calc(100% + 1px); width: 4px; height: 16px; margin-top: -8px;
  border-radius: 0 4px 4px 0; background: var(--istic-active-fill); /* 竖条贴在方块右外侧 (方块里放不下四字标签) */
}
#sidebar .nav-item:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 12px; }

/* 底部: 外观 / 语言 / 用量 竖排, 再下面是头像 (名字、角色、⌄ 只在菜单里看) */
#sidebar .side-foot {
  grid-column: 1; grid-row: 4; margin: 0;
  flex-direction: column; align-items: center; justify-content: flex-start; gap: 6px;
  padding: 8px 0 16px; border-top: 0;
}
#sidebar .acct-tools { order: -1; flex-direction: column; gap: 2px; }
#sidebar .acct-tool { width: 36px; height: 34px; border-radius: 10px; }
#sidebar .acct-tool:hover { background: var(--hover-2); color: var(--text); }
/* ASK-017 语言按钮 = 模板的紧凑切换器: 「文A」图标 (Lucide languages, ISC) + 下面一行 9px 粗体的当前语言 (中文 / EN)。
   只用 CSS: 地球图标的 svg 隐藏路径, 改用遮罩画「文A」; 文字用按钮的 ::before (::after 是悬停提示, 不动)。 */
#sidebar #btn-lang:not([hidden]) { /* [hidden] (未登录) 仍要藏住 */
  width: 40px; height: 40px; border-radius: 12px;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
#sidebar #btn-lang .ic {
  width: 20px; height: 20px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 8 6 6'/%3E%3Cpath d='m4 14 6-6 2-3'/%3E%3Cpath d='M2 5h12'/%3E%3Cpath d='M7 2h1'/%3E%3Cpath d='m22 22-5-10-5 10'/%3E%3Cpath d='M14 18h6'/%3E%3C/svg%3E") center / 20px 20px no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 8 6 6'/%3E%3Cpath d='m4 14 6-6 2-3'/%3E%3Cpath d='M2 5h12'/%3E%3Cpath d='M7 2h1'/%3E%3Cpath d='m22 22-5-10-5 10'/%3E%3Cpath d='M14 18h6'/%3E%3C/svg%3E") center / 20px 20px no-repeat;
}
#sidebar #btn-lang .ic > * { display: none; }
#sidebar #btn-lang::before { content: "中文"; order: 1; font: 700 9px/1 var(--font-sans); letter-spacing: 0; white-space: nowrap; }
:root[lang="en"] #sidebar #btn-lang::before { content: "EN"; }
#sidebar .side-account { flex: none; width: 44px; height: 44px; justify-content: center; padding: 0; margin: 0; border-radius: 12px; }
#sidebar .acct-main, #sidebar .acct-chev, #sidebar .side-account .role-badge { display: none; }
#sidebar .side-account .acct-av { width: 32px; height: 32px; font-size: 14px; }
@media (hover: hover) { /* 图标栏里的提示一律出在右侧 (上方会被侧栏裁掉) */
  #sidebar .acct-tool[data-tip]:hover::after { top: 50%; bottom: auto; left: calc(100% + 8px); right: auto; transform: translateY(-50%); }
}

/* 面板列表: 小灰字分组标题, 38px 圆角行; 当前聊天 = 淡强调色底 + 强调色加粗字 */
#sidebar .side-section { grid-column: 2; grid-row: 2 / -1; min-height: 0; margin: 0; padding: 8px 12px 16px; overflow-y: auto; }
#sidebar .side-label { padding: 12px 12px 6px; font-size: 12px; font-weight: 500; color: var(--text-4); }
#sidebar .history, #sidebar #pinned { padding: 0 0 4px; }
#sidebar .hist-item { height: 38px; margin: 2px 0; border-radius: 8px; }
#sidebar .hist-item.has-sub { height: auto; min-height: 46px; }
#sidebar .hist-item:hover { background: var(--side-hover); }
#sidebar .hist-open { padding: 0 12px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--text-2); }
#sidebar .hist-item.active { background: var(--istic-active-bg); }
#sidebar .hist-item.active .hist-open { color: var(--istic-active-text); font-weight: 600; }
#sidebar .hist-empty { padding: 8px 12px; }

/* 跳到输入框的链接藏在屏幕上方时, 它的大阴影会漏进面板标题行 */
.skip-link:not(:focus) { box-shadow: none; }

/* 宽屏收起: 只留图标栏, 收起按钮挪到图标栏 (头像上方) */
@media (min-width: 861px) {
  :root[data-side="collapsed"] #sidebar { grid-template-columns: 64px 0; }
  :root[data-side="collapsed"] #sidebar .brand { display: contents; }
  :root[data-side="collapsed"] #sidebar .brand-name,
  :root[data-side="collapsed"] #sidebar .side-section { display: none; }
  :root[data-side="collapsed"] #sidebar .nav-label { display: block; }
  :root[data-side="collapsed"] #sidebar #btn-collapse { grid-column: 1; grid-row: 3; justify-self: center; margin: 4px 0 0; }
}
@media (min-width: 861px) and (hover: hover) { /* 收起时图标右侧的提示 (style.css 的 data-rail-tip) 不能被滚动区裁掉 */
  :root[data-side="collapsed"] #sidebar .side-nav { overflow: visible; }
}
