:root {
  --pink: #ffb7d5;
  --pink-dark: #ff9ec7;
  --pink-deep: #e0729f;
  --bg: #fff5fa;
  --line: #ffe0ee;
  --ink: #4a3b43;
  --ink-soft: #90788a;
  --bubble: #ffffff;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, "PingFang SC",
        "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

/* ---------- 顶栏 ---------- */
.topbar {
  flex: none;
  position: relative;          /* 手机上那个「更多」下拉要挂在它下面 */
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  background: linear-gradient(135deg, #ffd9ec, #ffeaf5);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(255, 158, 199, .18);
  z-index: 5;
}

.topbar .avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(224, 114, 159, .25);
}

.who { flex: 1; min-width: 0; }

.who .name { font-weight: 700; font-size: 15px; }

.who .status {
  font-size: 12px;
  color: var(--pink-deep);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.new-chat {
  flex: none;
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(135deg, var(--pink-dark), var(--pink-deep));
  box-shadow: 0 3px 10px rgba(224, 114, 159, .3);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.new-chat:active { transform: scale(.96); }

/* 顶栏第二个按钮：保存上下文（白底，别跟「新会话」抢眼） */
.new-chat.ghost {
  color: var(--pink-deep);
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: none;
}

/* 顶栏右边那组按钮：桌面端直接并排显示，手机上收进「⋯」下拉（见下面的小屏规则） */
.tb-actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.tb-more { display: none; }        /* 平时藏着，只有窄屏才露出来 */

/* ---------- 保存上下文的小弹窗 ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(74, 59, 67, .35);
}

.modal[hidden] { display: none; }

.modal-box {
  width: 100%;
  max-width: 400px;
  padding: 16px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 12px 40px rgba(224, 114, 159, .35);
}

.modal-box h3 { margin: 0 0 8px; font-size: 15px; }

.modal-hint {
  margin: 0 0 10px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--ink-soft);
}

.modal-hint code {
  padding: 1px 5px;
  border-radius: 6px;
  background: #fff0f7;
  color: var(--pink-deep);
  font-size: 12px;
}

.modal-box input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff8fc;
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 别改小，iOS 上小于 16px 会自动放大页面 */
  outline: none;
}

.modal-box input:focus { border-color: var(--pink-dark); background: #fff; }

.modal-msg {
  margin: 8px 0 0;
  min-height: 18px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.modal-msg.ok { color: #3d9970; }
.modal-msg.bad { color: #c0392b; }

.modal-btns {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.modal-btns button {
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  color: #fff;
  background: linear-gradient(135deg, var(--pink-dark), var(--pink-deep));
  box-shadow: 0 3px 10px rgba(224, 114, 159, .3);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.modal-btns button:disabled { opacity: .5; box-shadow: none; }

.modal-btns .modal-cancel {
  color: var(--ink-soft);
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: none;
}

/* ---------- 消息区 ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px 18px;
}

.messages > *:first-child { margin-top: 0; }

/* ---------- 回到最底部 ---------- */
.to-bottom {
  position: fixed;
  right: max(16px, calc(50vw - 404px));
  bottom: calc(70px + env(safe-area-inset-bottom));
  z-index: 6;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  color: #fff;
  background: linear-gradient(135deg, var(--pink-dark), var(--pink-deep));
  box-shadow: 0 3px 12px rgba(224, 114, 159, .4);
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px) scale(.85);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  -webkit-tap-highlight-color: transparent;
}

.to-bottom.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.to-bottom:active { transform: scale(.9); }

.msg {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 14px 0;
}

.msg.user { flex-direction: row-reverse; }

.msg .avatar {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid #fff;
  box-shadow: 0 1px 4px rgba(224, 114, 159, .22);
}

.bubble {
  max-width: 84%;
  padding: 10px 13px;
  border-radius: var(--radius);
  background: var(--bubble);
  border: 1px solid var(--line);
  box-shadow: 0 1px 4px rgba(224, 114, 159, .1);
  overflow-wrap: anywhere;
}

.msg.agent .bubble { border-top-left-radius: 5px; }

.msg.user .bubble {
  border-top-right-radius: 5px;
  background: linear-gradient(135deg, var(--pink-dark), #ff86b6);
  border-color: transparent;
  color: #fff;
  white-space: pre-wrap;
}

/* 雏草姬发来的图片：贴着气泡宽度，别撑破 */
.msg.user .bubble img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 12px;
}

.msg.user .bubble .text { margin-top: 6px; }

/* Markdown 正文 */
.content > *:first-child { margin-top: 0; }
.content > *:last-child { margin-bottom: 0; }
.content p { margin: .55em 0; }
.content ul, .content ol { margin: .55em 0; padding-left: 1.3em; }
.content li { margin: .2em 0; }
.content h1, .content h2, .content h3, .content h4 { margin: .8em 0 .4em; line-height: 1.35; }
.content h1 { font-size: 1.25em; }
.content h2 { font-size: 1.15em; }
.content h3 { font-size: 1.05em; }
.content blockquote {
  margin: .6em 0;
  padding: .2em .8em;
  border-left: 3px solid var(--pink);
  background: #fff6fb;
  color: var(--ink-soft);
  border-radius: 0 8px 8px 0;
}
.content a { color: var(--pink-deep); }
.content table {
  border-collapse: collapse;
  width: 100%;
  margin: .6em 0;
  font-size: .92em;
  display: block;
  overflow-x: auto;
}
.content th, .content td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; }
.content th { background: #fff2f8; }

/* 行内代码 */
.content :not(pre) > code {
  background: #ffeaf4;
  color: #c2417a;
  padding: 1px 5px;
  border-radius: 5px;
  font-family: ui-monospace, "SFMono-Regular", Consolas, "Courier New", monospace;
  font-size: .89em;
}

/* 代码块 */
.content pre {
  position: relative;
  margin: .7em 0;
  padding: 28px 0 10px;
  border-radius: 10px;
  background: #0d1117;
  overflow: hidden;
}

.content pre > code,
.content pre > code.hljs {
  display: block;
  padding: 0 12px;
  background: transparent;
  overflow-x: auto;
  font-family: ui-monospace, "SFMono-Regular", Consolas, "Courier New", monospace;
  font-size: 12.5px;
  line-height: 1.6;
}

.code-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background: rgba(255, 255, 255, .07);
  font-size: 11px;
  color: #8b949e;
}

.code-copy {
  border: none;
  background: transparent;
  color: #8b949e;
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 5px;
  -webkit-tap-highlight-color: transparent;
}

.code-copy:active { background: rgba(255, 255, 255, .12); }

/* ---------- 思考过程 ---------- */
.thinking {
  margin: 6px 0;
  border-left: 3px solid var(--pink);
  border-radius: 8px;
  background: #fff6fb;
  font-size: 13px;
}

.thinking > summary {
  list-style: none;
  cursor: pointer;
  padding: 6px 10px;
  color: var(--pink-deep);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.thinking > summary::-webkit-details-marker { display: none; }

.thinking > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 5px;
  transition: transform .15s;
}

.thinking[open] > summary::before { transform: rotate(90deg); }

.thinking[open] > summary .spin { display: none; }

.spin {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--pink-dark);
  animation: pulse 1s ease-in-out infinite;
  vertical-align: middle;
}

@keyframes pulse {
  0%, 100% { opacity: .3; transform: scale(.75); }
  50% { opacity: 1; transform: scale(1); }
}

.thinking-body {
  padding: 0 11px 8px;
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  color: var(--ink-soft);
  line-height: 1.6;
}

/* ---------- 工具调用 ---------- */
.tool {
  margin: 6px 0;
  border: 1px dashed #cfe0ff;
  border-radius: 8px;
  background: #f5f9ff;
  font-size: 13px;
}

.tool > summary {
  list-style: none;
  cursor: pointer;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #3b6bb5;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tool > summary::-webkit-details-marker { display: none; }

.tool > summary::before {
  content: "▸";
  transition: transform .15s;
}

.tool[open] > summary::before { transform: rotate(90deg); }

.tool .tname { font-weight: 600; overflow-wrap: anywhere; }

.tool .tstate {
  margin-left: auto;
  flex: none;
  font-size: 11px;
  color: #8aa4c8;
}

.tool .tstate.ok { color: #3d9970; }

.tool-body { padding: 0 10px 9px; }

.tool-label {
  margin: 6px 0 3px;
  font-size: 11px;
  color: #8aa4c8;
}

.tool-body pre {
  margin: 0;
  padding: 6px 8px;
  max-height: 220px;
  overflow: auto;
  border-radius: 6px;
  background: #fff;
  border: 1px solid #e2ecfa;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #46607d;
}

/* ---------- 表情包 ---------- */
/* 表情包：只限最大尺寸，不写死成正方形。
   表情包长得横七竖八（有宽有竖的），原来钉死 116×116 会把它们压扁拉变形——
   这里 width/height 都 auto，浏览器按原图宽高比缩到框里，不变形。 */
.sticker {
  display: block;
  width: auto;
  height: auto;
  max-width: 116px;
  max-height: 116px;
  margin: 8px 0 2px;
  border-radius: 14px;
  box-shadow: 0 3px 12px rgba(224, 114, 159, .22);
}

/* ---------- 错误 ---------- */
.error {
  margin: 6px 0;
  padding: 8px 11px;
  border-radius: 8px;
  background: #fff0f2;
  border: 1px solid #ffd3da;
  color: #c0392b;
  font-size: 13px;
}

/* ---------- 上下文占用（输入框上面那条） ---------- */
.ctx-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px 0;
  background: #fff;
  font-size: 11.5px;
  color: var(--ink-soft);
}

.ctx-bar[hidden] { display: none; }

.ctx-label { flex: none; }

.ctx-track {
  flex: 1;
  height: 5px;
  border-radius: 999px;
  background: #ffe3f0;
  overflow: hidden;
}

.ctx-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--pink-dark), var(--pink-deep));
  transition: width .3s ease;
}

/* 快到自动压缩那条线了就变橙，提醒一下 */
.ctx-fill.warn { background: linear-gradient(90deg, #ffb347, #ff8c42); }

.ctx-text {
  flex: none;
  font-variant-numeric: tabular-nums;
}

/* 系统提示条（比如「历史太长，已经压成摘要了」），跟塔菲说的话区分开 */
.notice {
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  background: #fff0f7;
  color: var(--ink-soft);
  font-size: 12px;
}

/* ---------- 输入区 ---------- */
.composer {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--line);
}

.composer-row {
  /* 输入框和两个按钮共用这一个高度，单行时三者顶底完全对齐：
     1px 边框 + 9px 内距 + 24px 行高 + 9px 内距 + 1px 边框 = 44px，
     正好也是手机上够大的点击区域。 */
  --ctl-h: 44px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.composer textarea {
  flex: 1;
  min-height: var(--ctl-h);
  max-height: 140px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #fff8fc;
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 别改小，iOS 上小于 16px 会自动放大页面 */
  line-height: 24px; /* 用固定行高，别用倍数，否则单行高度凑不齐 --ctl-h */
  resize: none;
  outline: none;
}

.composer textarea:focus { border-color: var(--pink-dark); background: #fff; }

/* 选图按钮：圆形，跟「发送」区分开 */
.icon-btn {
  flex: none;
  width: var(--ctl-h);
  height: var(--ctl-h);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff8fc;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:disabled { opacity: .45; cursor: default; }
.icon-btn:not(:disabled):active { transform: scale(.94); }

#send {
  flex: none;
  height: var(--ctl-h);
  padding: 0 18px;
  border: none;
  border-radius: 22px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--pink-dark), var(--pink-deep));
  box-shadow: 0 3px 10px rgba(224, 114, 159, .3);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#send:disabled { opacity: .5; box-shadow: none; cursor: default; }
#send:not(:disabled):active { transform: scale(.96); }

/* 待发送图片的缩略图 + 右上角小叉 */
.attach-bar { display: flex; }
.attach-bar[hidden] { display: none; }

.attach-item {
  position: relative;
  width: 72px;
  height: 72px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff8fc;
}

.attach-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attach-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

/* ---------- 窄屏（手机）：顶栏收成一个「⋯」 ----------
   手机上「导入上下文 / 保存上下文 / 新会话」三个按钮并排会把标题挤没，
   所以只留「新会话」，另外两个收进「⋯」下拉，点一下才展开。 */
@media (max-width: 719px) {
  .tb-more { display: inline-block; }

  .tb-actions {
    position: absolute;
    z-index: 6;
    top: calc(100% + 6px);
    right: 12px;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 8px;
    min-width: 150px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 10px 26px rgba(224, 114, 159, .28);
  }

  .tb-actions.open { display: flex; }

  .tb-actions .new-chat { width: 100%; text-align: center; }

  /* 上下文那条在最上面，手机上稍微做大一点、加粗，别让人看不见 */
  .ctx-bar { padding: 6px 12px 0; font-size: 12px; gap: 7px; }
  .ctx-track { height: 6px; }
  .ctx-text { font-weight: 600; color: var(--pink-deep); }
}

/* ---------- 桌面端 ---------- */
@media (min-width: 720px) {
  .topbar, .messages, .composer, .ctx-bar {
    padding-left: max(16px, calc(50vw - 420px));
    padding-right: max(16px, calc(50vw - 420px));
  }
  .topbar { padding-top: 12px; padding-bottom: 12px; }
  .bubble { max-width: 76%; }
  .sticker { max-width: 140px; max-height: 140px; }
}

/* 小屏手机上顶栏挤了三个按钮（导入 / 保存 / 新会话），把按钮压窄一点，
   免得把「永雏塔菲 · 在线喵」那一块挤没了 */
@media (max-width: 480px) {
  .topbar { gap: 6px; padding-left: 10px; padding-right: 10px; }
  .new-chat { padding: 7px 9px; font-size: 12px; }
}

/* ---------- 后台管理（/admin） ----------
   聊天页是 flex 满屏不滚动的，后台要能上下滚，所以整套样式都挂在 body.admin 下面。 */
body.admin {
  display: block;
  overflow-y: auto;
}

body.admin .status.bad { color: #d2496f; }

/* 顶栏里那个汉堡按钮，只有手机上露出来（JS 用 hidden 控制它出不出现） */
.nav-toggle {
  display: none;
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, .75);
  color: var(--pink-deep);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.nav-toggle[hidden] { display: none; }

/* 左边导航 + 右面板 */
.admin-shell {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  max-width: 1060px;
  margin: 0 auto;
  padding: 0 14px 26px;
}

.admin-main {
  flex: 1;
  min-width: 0;
  padding-top: 14px;
}

.view {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.view[hidden] { display: none; }

body.admin .card {
  padding: 14px 15px;
  background: var(--bubble);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(255, 158, 199, .14);
}

body.admin .card h2 {
  margin: 0 0 10px;
  font-size: 15px;
}

body.admin .card h3.sub {
  margin: 16px 0 10px;
  font-size: 13px;
  color: var(--pink-deep);
}

body.admin .card h3.sub:first-of-type { margin-top: 4px; }

body.admin .card label {
  display: block;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--ink-soft);
}

body.admin .card input {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff8fc;
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 别改小，iOS 上小于 16px 会自动放大页面 */
  outline: none;
}

body.admin .card input:focus { border-color: var(--pink-dark); background: #fff; }

body.admin .card button {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--pink-dark), var(--pink-deep));
  box-shadow: 0 3px 10px rgba(224, 114, 159, .3);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

body.admin .card button:disabled { opacity: .5; box-shadow: none; cursor: default; }
body.admin .card button:not(:disabled):active { transform: scale(.96); }

/* 卡片里的次要按钮（比如「恢复内置的」）：白底描边，不跟主按钮抢眼 */
body.admin .card button.ghost {
  color: var(--pink-deep);
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: none;
}

/* 并排两个按钮用（主 + 次） */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* 提示词那种多行输入。跟上面的 input 一样是 16px：iOS 上小于 16px 会自动放大页面 */
body.admin .card textarea {
  width: 100%;
  min-height: 300px;
  max-height: 70vh;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff8fc;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  line-height: 1.65;
  outline: none;
  resize: vertical;
}

body.admin .card textarea:focus { border-color: var(--pink-dark); background: #fff; }

body.admin .hint {
  margin: 10px 0 0;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--ink-soft);
}

body.admin .hint code {
  padding: 1px 5px;
  border-radius: 6px;
  background: #fff0f7;
  color: var(--pink-deep);
  font-size: 12px;
}

body.admin .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

body.admin .chips button {
  padding: 5px 12px;
  font-weight: 400;
  font-size: 12.5px;
  color: var(--pink-deep);
  background: #fff0f7;
  border: 1px solid var(--line);
  box-shadow: none;
}

/* ---------- 侧边导航（分组可折叠） ---------- */

.sidebar {
  flex: none;
  width: 186px;
  padding-top: 14px;
  position: sticky;
  top: 14px;
}

.sidebar[hidden] { display: none; }

.nav-group { margin-bottom: 2px; }

.nav-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font: inherit;
  font-size: 12.5px;
  letter-spacing: .6px;
  color: var(--ink-soft);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.nav-head:hover { background: #fff0f7; }

.nav-head .caret {
  margin-left: auto;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  transition: transform .15s;
}

.nav-group.closed .caret { transform: rotate(-90deg); }
.nav-group.closed .nav-items { display: none; }

.nav-items { padding: 2px 0 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 8px 10px 8px 16px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.nav-item:hover { background: #fff0f7; }

.nav-item.on {
  color: #fff;
  background: linear-gradient(135deg, var(--pink-dark), var(--pink-deep));
  box-shadow: 0 2px 8px rgba(224, 114, 159, .28);
}

.sidebar-tip {
  margin: 14px 4px 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--ink-soft);
}

/* 整条侧边栏收起 / 展开（桌面端）。收起来侧边栏整个收走，页面立刻宽敞；
   按钮在顶栏上，状态记在浏览器里（localStorage），换设备要重收一次。
   手机上导航本来就是抽屉，用不上这个按钮。 */
.nav-collapse[hidden] { display: none; }

@media (min-width: 761px) {
  .sidebar.collapsed { display: none; }
}

@media (max-width: 760px) {
  .nav-collapse { display: none !important; }
}

/* 勾选类开关（比如向量检索的总闸） */
body.admin .card label.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 0;
  font-size: 13.5px;
  line-height: 1.5;
  cursor: pointer;
}

body.admin .card label.switch input[type="checkbox"] {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--pink-dark);
  cursor: pointer;
}

/* ---------- 仪表盘 ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff8fc;
}

.stat-label { font-size: 12px; color: var(--ink-soft); }

.stat-value {
  margin-top: 2px;
  font-size: 20px;
  font-weight: 700;
  color: var(--pink-deep);
  line-height: 1.3;
}

.stat-note {
  margin-top: 2px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.bar {
  height: 8px;
  margin-top: 12px;
  border-radius: 999px;
  background: #ffe9f3;
  overflow: hidden;
}

.bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--pink-dark), var(--pink-deep));
  transition: width .3s ease;
}

.bar span.warn { background: linear-gradient(90deg, #ff9d6c, #e0603a); }

/* ---------- 表情包库 ---------- */

.mood-block { margin-top: 14px; }

.mood-head {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
}

.sticker-card {
  position: relative;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff8fc;
  text-align: center;
}

.sticker-thumb {
  display: block;
  width: 100%;
  height: 64px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}

.sticker-name,
.sticker-size {
  margin-top: 4px;
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.sticker-size { color: #b9a3ae; }

.sticker-del {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .5);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  box-shadow: none;
}

/* 后台卡片里的按钮默认又大又圆（见 body.admin .card button），会把右上角这个
   小圆钮撑爆——「删」字挤出圈外。这里按更高的优先级把它打回原样：固定 22×22、
   不留内边距、字号 11px，再居中。 */
body.admin .card .sticker-del {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  min-width: 0;
  padding: 0;
  font-size: 11px;
  font-weight: 400;
  line-height: 1;
  border-radius: 50%;
  color: #fff;
  background: rgba(0, 0, 0, .5);
  box-shadow: none;
}

.mood-empty {
  grid-column: 1 / -1;
  font-size: 12px;
  color: #c9b3bf;
}

/* ---------- 文件 / 存档列表 ---------- */

.rows {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  font-size: 13px;
  background: #fff;
}

.row + .row { border-top: 1px solid var(--line); }
.row.clickable { cursor: pointer; }
.row.clickable:hover { background: #fff6fb; }
.row.empty { color: var(--ink-soft); justify-content: center; }

.row-icon { flex: none; }

.row-name {
  flex: none;
  max-width: 42%;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.row-meta {
  flex: 1;
  min-width: 0;
  font-size: 11.5px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-btn {
  flex: none;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 400;
  color: var(--pink-deep);
  background: #fff0f7;
  border: 1px solid var(--line);
  box-shadow: none;
}

.row-btn.danger { color: #c0392b; }

.session-body {
  margin: 12px 0 0;
  padding: 10px 12px;
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffafd;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--ink);
}

/* ---------- 检查更新 ---------- */

.row-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

body.admin .card button.danger {
  background: linear-gradient(135deg, #ff9d8a, #e0603a);
  box-shadow: 0 3px 10px rgba(224, 96, 58, .3);
}

.update-result {
  margin-top: 12px;
  font-size: 12.5px;
  line-height: 1.8;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.update-log {
  margin: 6px 0 0;
  padding: 8px 10px;
  max-height: 200px;
  overflow: auto;
  border-radius: 10px;
  background: #fff8fc;
  border: 1px solid var(--line);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.55;
}

.ok-line { color: #3d9970; }
.bad-line { color: #c0392b; }
.dim { color: var(--ink-soft); }

/* ---------- 下拉框 / 文件选择框 ---------- */

body.admin .card select,
body.admin .card input[type="file"] {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff8fc;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  outline: none;
}

body.admin .card select:focus { border-color: var(--pink-dark); background: #fff; }

body.admin .card input[type="file"] { padding: 8px 10px; font-size: 13px; }

/* ---------- 手机上：导航变成抽屉 ---------- */
@media (max-width: 760px) {
  .nav-toggle:not([hidden]) { display: flex; align-items: center; justify-content: center; }

  .admin-shell {
    display: block;
    padding: 12px;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    top: 0;
    left: 0;
    bottom: 0;
    width: 232px;
    padding: 16px 12px;
    overflow-y: auto;
    background: #fff;
    box-shadow: 0 8px 30px rgba(224, 114, 159, .3);
    transform: translateX(-105%);
    transition: transform .2s ease;
  }

  .sidebar.open { transform: none; }

  .admin-main { padding-top: 0; }
}

