/* ============================================================
   箱缘印包智能体 · 同事端样式
   移动优先；主色 #c8102e；深色模式跟随系统；无任何外部资源
   ============================================================ */

/* ---------- 设计变量 ---------- */
:root {
  color-scheme: light dark;
  --brand: #c8102e;
  --brand-deep: #9a0b21;
  --brand-soft: rgba(200, 16, 46, .08);
  --brand-line: rgba(200, 16, 46, .28);

  --bg: #f3efe6;
  --bg-deep: #e9e2d4;
  --surface: #fffdf8;
  --surface-2: #f8f3ea;
  --surface-3: #efe8db;
  --ink: #1b1815;
  --ink-2: #4c463d;
  --muted: #7d7466;
  --line: #e1d8c8;
  --line-strong: #cdc1ad;
  --kraft: #b98a4f;
  --ok: #1c7a4d;
  --warn: #8a5200;
  --warn-bg: #fff4d9;
  --warn-line: #e8bf6a;
  --danger: #b3261e;

  --shadow-sm: 0 1px 2px rgba(48, 38, 22, .06);
  --shadow-md: 0 2px 4px rgba(48, 38, 22, .05), 0 10px 28px -14px rgba(48, 38, 22, .35);
  --shadow-lg: 0 24px 60px -24px rgba(38, 28, 14, .45);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;

  --font-sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
               "Noto Sans CJK SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-serif: "Songti SC", "STSong", "Source Han Serif SC", "Noto Serif CJK SC",
                "SimSun", Georgia, serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, "Courier New", monospace;

  --app-h: 100dvh;
  --sidebar-w: 300px;
  --topbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #e8384f;
    --brand-deep: #ff6b7d;
    --brand-soft: rgba(232, 56, 79, .14);
    --brand-line: rgba(232, 56, 79, .38);

    --bg: #12100e;
    --bg-deep: #0c0a09;
    --surface: #1d1917;
    --surface-2: #241f1b;
    --surface-3: #2c2621;
    --ink: #f2ece2;
    --ink-2: #d3c9ba;
    --muted: #a2988a;
    --line: #352e27;
    --line-strong: #4a4036;
    --kraft: #c99a5e;
    --ok: #5cc28c;
    --warn: #f0c274;
    --warn-bg: #3a2a10;
    --warn-line: #6b4f1e;
    --danger: #ff8b7e;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow-md: 0 2px 6px rgba(0, 0, 0, .45), 0 14px 30px -18px rgba(0, 0, 0, .8);
    --shadow-lg: 0 24px 70px -24px rgba(0, 0, 0, .9);
  }
}

/* ---------- 基础 ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}

/* 纸箱瓦楞纹理：极轻的竖纹 + 暖色渐层 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    repeating-linear-gradient(90deg, rgba(120, 96, 60, .035) 0 1px, transparent 1px 7px),
    radial-gradient(120% 80% at 12% 0%, rgba(185, 138, 79, .10), transparent 60%);
}
@media (prefers-color-scheme: dark) {
  body::before {
    background-image:
      repeating-linear-gradient(90deg, rgba(255, 255, 255, .018) 0 1px, transparent 1px 7px),
      radial-gradient(120% 80% at 12% 0%, rgba(232, 56, 79, .10), transparent 60%);
  }
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.35; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.hidden, [hidden] { display: none !important; }
.only-mobile { display: none; }
.noscript { padding: 24px; text-align: center; }

::selection { background: var(--brand); color: #fff; }

/* 细滚动条 */
.chat-scroll, .conv-list, .page-scroll, .msg-list { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.chat-scroll::-webkit-scrollbar, .conv-list::-webkit-scrollbar,
.page-scroll::-webkit-scrollbar { width: 8px; }
.chat-scroll::-webkit-scrollbar-thumb, .conv-list::-webkit-scrollbar-thumb,
.page-scroll::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 18px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .02em;
  transition: background-color .15s ease, border-color .15s ease, transform .1s ease, opacity .15s ease;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 2px 0 rgba(0, 0, 0, .12); }
.btn-primary:hover:not(:disabled) { background: var(--brand-deep); }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.btn-block { width: 100%; }
.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 2px 0 rgba(0, 0, 0, .12); }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }
.btn.is-loading { color: transparent; pointer-events: none; position: relative; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border-radius: 10px;
  color: var(--ink-2);
  font-size: 17px;
  line-height: 1;
  transition: background-color .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input::placeholder { color: var(--muted); opacity: .85; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.textarea { min-height: 76px; resize: vertical; line-height: 1.55; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--ink-2); letter-spacing: .02em; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.7;
}
.pill-muted { background: var(--surface-3); color: var(--muted); }
.pill-brand { background: var(--brand-soft); color: var(--brand); }

.form-error {
  margin: 10px 0 0;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  background: rgba(179, 38, 30, .08);
  border: 1px solid rgba(179, 38, 30, .25);
  color: var(--danger);
  font-size: 13.5px;
  line-height: 1.5;
}

/* ============================================================
   登录页
   ============================================================ */
.login-view {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  height: 100dvh;
  height: var(--app-h);
}

.login-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  padding: 56px clamp(36px, 6vw, 88px);
  color: #f7f1e6;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .03) 0 1px, transparent 1px 9px),
    radial-gradient(90% 70% at 100% 0%, rgba(200, 16, 46, .38), transparent 62%),
    linear-gradient(155deg, #221a14 0%, #171310 58%, #100d0b 100%);
  overflow: hidden;
}
.login-brand::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 10px;
  background: repeating-linear-gradient(90deg, var(--brand) 0 18px, transparent 18px 26px);
  opacity: .85;
}

.brand-head { display: flex; align-items: flex-start; gap: 18px; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 54px; height: 54px;
  flex: 0 0 auto;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22), 0 8px 22px -10px rgba(200, 16, 46, .9);
}
.brand-mark.sm { width: 36px; height: 36px; border-radius: 9px; font-size: 20px; }

.brand-kicker {
  font-size: 12px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: rgba(247, 241, 230, .62);
  margin-bottom: 10px;
}
.brand-title {
  font-family: var(--font-serif);
  font-size: clamp(38px, 4.6vw, 62px);
  line-height: 1.06;
  letter-spacing: .04em;
  font-weight: 700;
}
.brand-desc {
  max-width: 34em;
  font-size: 15.5px;
  line-height: 1.8;
  color: rgba(247, 241, 230, .8);
}
.brand-points {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 14px;
  color: rgba(247, 241, 230, .74);
}
.brand-points li { display: flex; gap: 10px; align-items: baseline; }
.brand-points li::before {
  content: "";
  width: 6px; height: 6px;
  flex: 0 0 auto;
  transform: translateY(-2px) rotate(45deg);
  background: var(--brand);
}
.brand-points b { color: #fff; font-size: 16px; }

.flute-band {
  height: 26px;
  border-top: 1px solid rgba(247, 241, 230, .16);
  border-bottom: 1px solid rgba(247, 241, 230, .16);
  background: repeating-linear-gradient(90deg,
    rgba(247, 241, 230, .16) 0 2px,
    transparent 2px 5px,
    rgba(247, 241, 230, .16) 5px 7px,
    transparent 7px 14px);
  opacity: .6;
}
.brand-foot {
  font-size: 12px;
  letter-spacing: .16em;
  color: rgba(247, 241, 230, .45);
}

.login-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  background:
    radial-gradient(80% 60% at 50% 0%, var(--surface), transparent 70%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 30px 28px 26px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
}
.login-title { font-family: var(--font-serif); font-size: 27px; letter-spacing: .06em; }
.login-hint { margin-top: 8px; font-size: 13.5px; color: var(--muted); line-height: 1.65; }
.login-card .field { margin-top: 18px; }
.login-card .btn-block { margin-top: 22px; }
.login-foot { margin-top: 16px; text-align: center; font-size: 12.5px; color: var(--muted); }

/* ============================================================
   主界面骨架
   ============================================================ */
.app-view {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100dvh;
  height: var(--app-h);
  transition: grid-template-columns .22s ease;
}
.app-view.side-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
.app-view.side-collapsed .sidebar { transform: translateX(-100%); opacity: 0; pointer-events: none; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 14px;
  padding: 14px 12px 12px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  transition: transform .22s ease, opacity .22s ease;
  overflow: hidden;
}

.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px 0; }
.side-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.side-brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.side-brand-text strong { font-size: 14.5px; letter-spacing: .02em; white-space: nowrap; }
.side-brand-text span { font-size: 11.5px; color: var(--muted); letter-spacing: .08em; }

.btn-new {
  width: 100%;
  min-height: 44px;
  justify-content: flex-start;
  gap: 8px;
  padding: 0 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: 14.5px;
  font-weight: 600;
  transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}
.btn-new span { color: var(--brand); font-size: 18px; font-weight: 700; }
.btn-new:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

.conv-section { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; gap: 6px; }
.section-label {
  padding: 0 6px;
  font-size: 11.5px;
  letter-spacing: .14em;
  color: var(--muted);
  text-transform: uppercase;
}
.conv-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 0 8px;
  margin: 0 -4px;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  color: var(--ink-2);
  text-align: left;
  transition: background-color .12s ease, color .12s ease, border-color .12s ease;
}
.conv-item:hover { background: var(--surface-3); color: var(--ink); }
.conv-item.is-active {
  background: var(--surface);
  border-color: var(--brand-line);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.conv-item.is-active::before {
  content: "";
  width: 3px;
  align-self: stretch;
  border-radius: 3px;
  background: var(--brand);
  margin: -2px 0;
}
.conv-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.conv-title {
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-time { font-size: 11px; color: var(--muted); }
.conv-del {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 14px;
  opacity: 0;
  transition: opacity .12s ease, color .12s ease, background-color .12s ease;
}
.conv-item:hover .conv-del, .conv-item:focus-within .conv-del { opacity: 1; }
.conv-del:hover { background: rgba(179, 38, 30, .12); color: var(--danger); }
@media (hover: none) { .conv-del { opacity: .8; } }

.conv-empty { padding: 10px 8px; font-size: 12.5px; color: var(--muted); line-height: 1.6; }

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--ink-2);
  text-align: left;
  transition: background-color .12s ease, color .12s ease;
}
.nav-item:hover { background: var(--surface-3); color: var(--ink); }
.nav-item.is-active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-ico { width: 18px; text-align: center; font-size: 14px; }
.nav-danger { color: var(--muted); }
.nav-danger:hover { color: var(--danger); background: rgba(179, 38, 30, .08); }

.side-mask {
  position: fixed;
  inset: 0;
  z-index: 2;
  background: rgba(18, 14, 10, .48);
  backdrop-filter: blur(2px);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }

/* ---------- 工作区 / 顶栏 ---------- */
.workspace { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 12px 0 8px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
}
.topbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: repeating-linear-gradient(90deg, var(--brand) 0 22px, transparent 22px 30px);
  opacity: .5;
}
.topbar-title {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .08em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-chip {
  display: flex;
  align-items: baseline;
  gap: 7px;
  max-width: 46vw;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.user-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-dept { font-size: 11.5px; color: var(--muted); white-space: nowrap; }

/* ---------- 页面栈 ---------- */
.view-stack { position: relative; flex: 1 1 auto; min-height: 0; }
.page { position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0; visibility: hidden; opacity: 0; }
.page.is-active { visibility: visible; opacity: 1; }
.page-scroll { overflow-y: auto; padding: 24px 20px 60px; }
.page-inner { width: 100%; max-width: 820px; margin: 0 auto; }

.page-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.back-btn {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  margin-top: 4px;
  border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 16px;
  line-height: 1;
  transition: background-color .15s ease, color .15s ease;
}
.back-btn:hover { background: var(--surface-3); color: var(--ink); }
.page-title { font-family: var(--font-serif); font-size: 25px; letter-spacing: .04em; }
.page-sub { margin-top: 5px; font-size: 13px; color: var(--muted); line-height: 1.6; }

.card {
  padding: 20px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   对话区
   ============================================================ */
.page-chat { padding: 0; }

.chat-scroll {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  padding: 20px 16px 8px;
}

.msg-list {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* 空状态 */
.empty-state {
  width: 100%;
  max-width: 660px;
  margin: clamp(16px, 7vh, 72px) auto 24px;
  text-align: center;
  animation: rise .35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.empty-kicker {
  font-size: 11px;
  letter-spacing: .26em;
  color: var(--muted);
  text-transform: uppercase;
}
.empty-title {
  margin: 10px 0 8px;
  font-family: var(--font-serif);
  font-size: clamp(30px, 6vw, 44px);
  letter-spacing: .1em;
  font-weight: 700;
}
.empty-title::after {
  content: "";
  display: block;
  width: 54px; height: 3px;
  margin: 14px auto 0;
  background: var(--brand);
}
.empty-desc { max-width: 30em; margin: 14px auto 0; font-size: 14px; color: var(--ink-2); line-height: 1.8; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
  transition: border-color .15s ease, color .15s ease, background-color .15s ease, transform .1s ease;
}
.chip:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.chip:active { transform: translateY(1px); }
.empty-note { margin-top: 22px; font-size: 11.5px; color: var(--muted); letter-spacing: .04em; }

/* 消息 */
.msg { display: flex; flex-direction: column; max-width: 100%; animation: rise .22s ease both; }
.msg-user { align-items: flex-end; }
.msg-assistant { align-items: flex-start; }

.bubble {
  position: relative;
  max-width: min(100%, 720px);
  padding: 12px 15px;
  border-radius: var(--r-xl);
  font-size: 15px;
  line-height: 1.75;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.msg-user .bubble {
  background: var(--brand);
  color: #fff;
  border-bottom-right-radius: 7px;
  box-shadow: 0 6px 18px -12px rgba(200, 16, 46, .9);
  white-space: pre-wrap;
}
.msg-assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 7px;
  box-shadow: var(--shadow-sm);
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 6px 6px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .06em;
}
.msg-assistant .msg-meta::before {
  content: "箱";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font-family: var(--font-serif);
  font-size: 12px;
  letter-spacing: 0;
}

/* 思考中 */
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 2px 0;
  color: var(--muted);
  font-size: 13.5px;
}
.dots { display: inline-flex; gap: 4px; }
.dots i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--brand);
  opacity: .35;
  animation: blink 1.15s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: .16s; }
.dots i:nth-child(3) { animation-delay: .32s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

/* 光标 */
.caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--brand);
  animation: caret 1s step-end infinite;
}
@keyframes caret { 50% { opacity: 0; } }

/* 出处 */
.sources {
  margin-top: 12px;
  border-top: 1px dashed var(--line-strong);
  padding-top: 10px;
}
.sources > summary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  list-style: none;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--brand);
  padding: 3px 8px 3px 4px;
  border-radius: 7px;
  user-select: none;
}
.sources > summary::-webkit-details-marker { display: none; }
.sources > summary:hover { background: var(--brand-soft); }
.sources > summary::before {
  content: "▸";
  font-size: 11px;
  transition: transform .15s ease;
  display: inline-block;
}
.sources[open] > summary::before { transform: rotate(90deg); }
.src-count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 11px;
  text-align: center;
}
.src-list { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-top: 9px; }
.src-item {
  padding: 9px 11px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 12.5px;
  line-height: 1.6;
}
.src-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.src-path { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.src-title { font-weight: 600; color: var(--ink); }
.src-head { color: var(--ink-2); }
.src-head::before { content: "· "; color: var(--muted); }
.src-snip {
  margin-top: 5px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}
.src-item.is-open .src-snip { display: block; -webkit-line-clamp: unset; }
.src-badge { font-size: 11px; color: var(--muted); }

/* 待复核提示 */
.warn {
  display: flex;
  gap: 9px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--warn);
  font-size: 13px;
  line-height: 1.6;
  font-weight: 500;
}
.warn-ico { flex: 0 0 auto; font-size: 14px; line-height: 1.5; }

/* 消息操作条 */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 8px 4px 0;
  opacity: .55;
  transition: opacity .15s ease;
}
.msg:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
.act-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid transparent;
  transition: background-color .12s ease, color .12s ease, border-color .12s ease;
}
.act-btn:hover { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
.act-btn.is-on {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: var(--brand-line);
  opacity: 1;
}
.act-btn:disabled { opacity: .5; cursor: default; }
.act-sep { width: 1px; height: 12px; background: var(--line-strong); margin: 0 3px; }
.act-hint { font-size: 11px; color: var(--ok); }

/* 流式错误 */
.msg-error {
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: var(--r-sm);
  background: rgba(179, 38, 30, .08);
  border: 1px solid rgba(179, 38, 30, .25);
  color: var(--danger);
  font-size: 13px;
}

/* 流式提示（已停止 / 补充说明） */
.stream-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  padding-left: 2px;
}

/* 骨架屏 */
.skeleton { animation: shimmer 1.4s ease-in-out infinite; background: var(--surface-3); border-radius: 8px; }
@keyframes shimmer { 0%, 100% { opacity: .55; } 50% { opacity: .95; } }
.sk-msg { display: flex; flex-direction: column; gap: 8px; padding: 12px 15px; border: 1px solid var(--line); border-radius: var(--r-xl); background: var(--surface); max-width: 72%; }
.sk-line { height: 12px; }
.sk-line.w80 { width: 80%; }
.sk-line.w60 { width: 60%; }
.sk-line.w40 { width: 40%; }
.sk-user { align-self: flex-end; min-width: 120px; }
.sk-conv { height: 38px; border-radius: 10px; }

/* ---------- 输入区 ---------- */
.composer-wrap {
  flex: 0 0 auto;
  padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, var(--bg) 26%);
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 7px 7px 7px 14px;
  border-radius: var(--r-xl);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.composer:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft), var(--shadow-md);
}
.composer-input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 38px;
  max-height: 168px;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  resize: none;
  overflow-y: auto;
}
.composer-input:focus { outline: none; }
.composer-input::placeholder { color: var(--muted); }
.composer-input:disabled { opacity: .6; }

.send-btn {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 19px;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color .15s ease, opacity .15s ease, transform .1s ease;
  box-shadow: 0 6px 16px -10px rgba(200, 16, 46, 1);
}
.send-btn:hover:not(:disabled) { background: var(--brand-deep); }
.send-btn:active:not(:disabled) { transform: scale(.96); }
.send-btn:disabled { background: var(--surface-3); color: var(--muted); box-shadow: none; cursor: not-allowed; }
.send-btn.is-stop { background: var(--ink-2); font-size: 14px; }

.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  max-width: 860px;
  margin: 6px auto 0;
  padding: 0 6px;
  font-size: 11px;
  color: var(--muted);
}
.stream-hint { color: var(--brand); font-weight: 600; }

/* ============================================================
   Markdown 渲染
   ============================================================ */
.md { font-size: 15px; line-height: 1.78; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md.is-streaming::after { content: '▍'; color: var(--brand); margin-left: 2px; animation: caret 1s steps(1) infinite; }
.md p { margin: 0 0 10px; }
.md h1, .md h2, .md h3, .md h4 {
  margin: 18px 0 8px;
  font-family: var(--font-serif);
  letter-spacing: .02em;
  line-height: 1.4;
}
.md h1 { font-size: 21px; }
.md h2 { font-size: 19px; }
.md h3 { font-size: 17px; }
.md h4 { font-size: 15.5px; }
.md h1::after, .md h2::after {
  content: "";
  display: block;
  width: 100%;
  height: 1px;
  margin-top: 7px;
  background: linear-gradient(90deg, var(--brand-line), transparent);
}
.md strong { font-weight: 700; color: var(--ink); }
.md em { font-style: normal; color: var(--ink-2); text-decoration: underline dotted var(--line-strong); text-underline-offset: 3px; }
.md del { color: var(--muted); }
.md ul, .md ol { margin: 0 0 10px; padding-left: 1.35em; }
.md li { margin: 3px 0; }
.md li::marker { color: var(--brand); font-weight: 600; }
.md code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: .88em;
}
.md pre {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: #1f1b17;
  border: 1px solid #332c25;
  color: #f1e9dc;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.65;
}
.md pre code {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-size: inherit;
}
.md blockquote {
  margin: 0 0 12px;
  padding: 8px 14px;
  border-left: 3px solid var(--brand);
  background: var(--surface-2);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  color: var(--ink-2);
}
.md blockquote p:last-child { margin-bottom: 0; }
.md hr { border: 0; border-top: 1px solid var(--line-strong); margin: 16px 0; }
.md a {
  color: var(--brand);
  text-decoration: underline;
  text-decoration-color: var(--brand-line);
  text-underline-offset: 2px;
  word-break: break-all;
}
.md a:hover { text-decoration-color: var(--brand); }
.md table {
  width: 100%;
  margin: 0 0 12px;
  border-collapse: collapse;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
  white-space: nowrap;
}
.md th, .md td {
  padding: 7px 11px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.md th { background: var(--surface-2); font-weight: 600; color: var(--ink); }
.md tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.md img { max-width: 100%; height: auto; border-radius: 8px; }

/* ============================================================
   记忆页 / 搜索页
   ============================================================ */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-wide { grid-column: 1 / -1; }
.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.form-status { font-size: 12.5px; color: var(--ok); }
.form-status.is-error { color: var(--danger); }

.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 30px 0 12px;
}
.section-title { font-family: var(--font-serif); font-size: 19px; letter-spacing: .04em; }

.org-list { display: flex; flex-direction: column; gap: 10px; }
.org-card {
  padding: 14px 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.org-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.org-label { font-size: 14px; font-weight: 600; }
.org-key { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.org-ver { margin-left: auto; font-size: 11px; color: var(--muted); }
.org-body { margin-top: 6px; font-size: 13.5px; color: var(--ink-2); line-height: 1.7; white-space: pre-wrap; }
.org-empty { padding: 16px; border: 1px dashed var(--line-strong); border-radius: var(--r-md); color: var(--muted); font-size: 13px; text-align: center; }

.search-bar { display: flex; gap: 10px; margin-bottom: 16px; }
.search-input { flex: 1 1 auto; min-width: 0; }
.search-meta { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; min-height: 18px; }
.search-results { display: flex; flex-direction: column; gap: 10px; }
.result-card {
  display: block;
  padding: 14px 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  transition: border-color .15s ease, box-shadow .15s ease, transform .1s ease;
}
.result-card:hover { border-color: var(--brand-line); box-shadow: var(--shadow-sm); }
.result-path { font-family: var(--font-mono); font-size: 11px; color: var(--muted); word-break: break-all; }
.result-title { margin-top: 3px; font-size: 15px; font-weight: 600; }
.result-heading { margin-top: 2px; font-size: 12.5px; color: var(--brand); }
.result-snippet { margin-top: 7px; font-size: 13px; color: var(--ink-2); line-height: 1.7; }

.blank-state { padding: 40px 20px; text-align: center; }
.blank-title { font-family: var(--font-serif); font-size: 18px; }
.blank-desc { margin-top: 6px; font-size: 13px; color: var(--muted); }

/* ============================================================
   弹层 / Toast
   ============================================================ */
.mask {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(18, 14, 10, .5);
  backdrop-filter: blur(3px);
  animation: fade .15s ease;
}
.dialog {
  width: 100%;
  max-width: 420px;
  padding: 22px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: pop .18s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.dialog-title { font-family: var(--font-serif); font-size: 19px; letter-spacing: .03em; }
.dialog-desc { margin-top: 8px; font-size: 13.5px; color: var(--ink-2); line-height: 1.7; white-space: pre-wrap; }
.dialog-input { margin-top: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
  width: max-content;
  max-width: min(92vw, 460px);
}
.toast {
  padding: 10px 16px;
  border-radius: 999px;
  background: #211c17;
  color: #f7f1e6;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: var(--shadow-lg);
  animation: toastIn .2s ease both;
  text-align: center;
}
.toast.is-error { background: #7c1a15; color: #ffeceb; }
.toast.is-ok { background: #145235; color: #e7fff2; }
.toast.out { animation: toastOut .2s ease both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }

/* ============================================================
   响应式：手机 / 平板
   ============================================================ */
@media (max-width: 880px) {
  :root { --topbar-h: 54px; }

  .login-view { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: var(--app-h); }
  .login-brand { justify-content: flex-start; gap: 12px; padding: 26px 22px 22px; }
  .login-brand::after { height: 6px; }
  .brand-mark { width: 44px; height: 44px; font-size: 24px; }
  .brand-title { font-size: 30px; display: inline-block; }
  .brand-title br { display: none; }
  .brand-head { align-items: center; gap: 14px; }
  .brand-kicker { margin-bottom: 4px; letter-spacing: .16em; }
  .brand-desc { font-size: 13.5px; line-height: 1.7; }
  .brand-points, .brand-foot, .flute-band { display: none; }
  .login-panel { align-items: flex-start; padding: 22px 18px 40px; }
  .login-card { max-width: 440px; padding: 22px 20px; box-shadow: none; }

  .app-view { grid-template-columns: minmax(0, 1fr); }
  .app-view.side-collapsed { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 40;
    width: min(86vw, 330px);
    padding-top: calc(14px + env(safe-area-inset-top));
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    transform: translateX(-102%);
    opacity: 1;
    pointer-events: auto;
    background: var(--surface-2);
    box-shadow: 24px 0 60px -30px rgba(0, 0, 0, .6);
    border-right: 1px solid var(--line);
  }
  .app-view.side-open .sidebar { transform: translateX(0); }
  .only-mobile { display: inline-flex; }

  .topbar { padding-left: 4px; }

  .chat-scroll { padding: 16px 12px 4px; }
  .msg-list { gap: 16px; }
  .bubble { max-width: 100%; font-size: 14.5px; padding: 11px 13px; }
  .msg-user .bubble { max-width: 86%; }

  .composer-wrap { padding-left: 10px; padding-right: 10px; }
  .composer { padding-left: 12px; }
  .composer-foot { font-size: 10.5px; }
  .composer-foot > span:first-child { display: none; }

  .page-scroll { padding: 16px 14px 48px; }
  .page-title { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; gap: 14px; }
  .card { padding: 16px; }
  .md { font-size: 14.5px; }
  .md table { font-size: 12.5px; }
  .md pre { font-size: 12px; }
  .empty-state { margin-top: 4vh; }
  .empty-title { font-size: 32px; }
  .empty-desc { font-size: 13.5px; }
  .chips { gap: 7px; margin-top: 16px; }
  .chip { font-size: 12.5px; padding: 7px 12px; }

  .toast-host { bottom: calc(16px + env(safe-area-inset-bottom)); }
}

@media (max-width: 420px) {
  .topbar-title { font-size: 15.5px; letter-spacing: .04em; }
  .user-chip { padding: 4px 8px; gap: 5px; max-width: 40vw; }
  .user-name { font-size: 12.5px; }
  .user-dept { display: none; }
}

/* 横屏矮屏：压缩空状态 */
@media (max-height: 560px) and (max-width: 880px) {
  .empty-state { margin-top: 8px; }
  .empty-title { font-size: 26px; }
  .empty-desc, .empty-note { display: none; }
  .chips { margin-top: 10px; }
}

/* 无障碍：尊重减少动效 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
