/* ============================================================
   Kable — 样式
   基于 mdui 2 的设计令牌。注意：mdui 的颜色令牌是 RGB 三元组
   （如 103,80,164），必须用 rgb() / rgba() 包裹，这里统一封装成
   --kc-* 语义变量使用。
   签名元素：等宽字体的时间戳与日期分隔标签。
   ============================================================ */

/* 说明：mdui 的颜色令牌是 RGB 三元组（如 103,80,164），需用 rgb() 包裹。
   这些 --kc-* 封装同时声明在 :root 和 body 上：
   自定义属性会在「声明处」完成变量替换，若只声明在 :root，
   一旦主题 class 落在别的元素上，这里的值就会被锁死在 :root 的主题上，
   而 mdui 组件读到的却是自己继承来的令牌，导致两套配色不一致。 */
:root, body {
  --kc-r-lg: 20px;
  --kc-r-md: 14px;
  --kc-r-sm: 10px;
  --kc-sidebar-w: 300px;
  --kc-maxw: 780px;
  --kc-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue",
    Arial, sans-serif;
  --kc-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", "Courier New", monospace;

  /* ---- mdui 令牌的可用色值封装 ---- */
  --kc-primary: rgb(var(--mdui-color-primary));
  --kc-on-primary: rgb(var(--mdui-color-on-primary));
  --kc-secondary-container: rgb(var(--mdui-color-secondary-container));
  --kc-tertiary: rgb(var(--mdui-color-tertiary));
  --kc-error: rgb(var(--mdui-color-error));
  --kc-error-container: rgb(var(--mdui-color-error-container));
  --kc-on-error-container: rgb(var(--mdui-color-on-error-container));

  --kc-surface: rgb(var(--mdui-color-surface));
  --kc-surface-low: rgb(var(--mdui-color-surface-container-low));
  --kc-surface-container: rgb(var(--mdui-color-surface-container));
  --kc-surface-high: rgb(var(--mdui-color-surface-container-high));
  --kc-surface-highest: rgb(var(--mdui-color-surface-container-highest));
  --kc-outline-variant: rgb(var(--mdui-color-outline-variant));

  /* 半透明强调色 */
  --kc-primary-55: rgba(var(--mdui-color-primary), 0.55);
  --kc-primary-20: rgba(var(--mdui-color-primary), 0.20);
  --kc-primary-18: rgba(var(--mdui-color-primary), 0.18);
  --kc-tertiary-65: rgba(var(--mdui-color-tertiary), 0.65);
  --kc-tertiary-20: rgba(var(--mdui-color-tertiary), 0.20);
  --kc-tertiary-18: rgba(var(--mdui-color-tertiary), 0.18);
  --kc-error-18: rgba(var(--mdui-color-error), 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--kc-font);
}

/* ============================================================
   启动遮罩
   首屏加载期间盖住界面，避免语言/主题/列表等内容分批刷新造成闪动。
   样式放在阻塞渲染的样式表里，保证第一帧就已是最终样子。
   ============================================================ */

.kc-splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: var(--kc-surface);
  transition: opacity 0.32s ease, visibility 0.32s ease;
}

.kc-splash--hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.kc-splash__mark {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: linear-gradient(140deg, var(--kc-primary), var(--kc-tertiary));
  color: #fff;
  font-size: 27px;
  font-weight: 800;
  line-height: 1;
  padding-bottom: 0.1em;
  user-select: none;
  animation: kc-splash-pop 0.5s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

@keyframes kc-splash-pop {
  from { opacity: 0; transform: scale(0.86); }
  to { opacity: 1; transform: none; }
}

.kc-splash__name {
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  opacity: 0.8;
}

/* 与前文消息区「信号线」同一视觉语言：流动的渐变细线 */
.kc-splash__bar {
  width: 132px;
  height: 3px;
  border-radius: 3px;
  overflow: hidden;
  background: var(--kc-outline-variant);
  opacity: 0.55;
}

.kc-splash__bar i {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg,
    transparent, var(--kc-primary), var(--kc-tertiary), transparent);
  animation: kc-splash-run 1.15s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes kc-splash-run {
  from { transform: translateX(-115%); }
  to { transform: translateX(265%); }
}

@media (prefers-reduced-motion: reduce) {
  .kc-splash__mark { animation: none; }
  .kc-splash__bar i { animation: none; width: 100%; opacity: 0.6; }
}

/* ---------------- 图标 ---------------- */

kc-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  flex: none;
}

kc-icon svg {
  width: 1em;
  height: 1em;
  display: block;
}

/* ---------------- 头像 ---------------- */

.kc-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  overflow: hidden;
  flex: none;
  position: relative;
  font-weight: 600;
  user-select: none;
  background: var(--kc-surface-highest);
}

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

/* 首字兜底层（图片加载失败时显示） */
.kc-avatar__fb { display: none; }

/* 无头像时直接显示的首字 */
.kc-avatar__initials {
  display: block;
  line-height: 1;
  font-weight: 700;
}

.kc-avatar.is-fallback { color: #fff !important; }
.kc-avatar.is-fallback .kc-avatar__fb { display: block; }
.kc-avatar.is-fallback img { display: none; }

/* 群头像用方角，和用户的圆形头像区分开 */
.kc-avatar--group { border-radius: 30%; }

/* ============================================================
   应用外壳
   ============================================================ */

.kc-app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--kc-surface);
}

.kc-appbar {
  flex: none;
  position: relative;
  z-index: 5;
}

.kc-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.kc-brand__mark {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--kc-primary), var(--kc-tertiary));
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  /* 关键：清掉继承的行高，否则居中的是行盒而非字形，字母会偏下 */
  line-height: 1;
  /* 大写字母没有降部，视觉重心偏低，向上微调补偿 */
  padding-bottom: 0.1em;
  user-select: none;
}

.kc-body {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.kc-sidebar {
  width: var(--kc-sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--kc-surface-low);
  border-right: 1px solid var(--kc-outline-variant);
}

.kc-sidebar__head {
  flex: none;
  padding: 12px 12px 8px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.kc-sidebar__head mdui-button { flex: 1; }

/* 侧栏搜索框：完全自控的圆润填充式 */
.kc-search {
  flex: none;
  padding: 0 12px 10px;
}

.kc-searchbox {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--kc-surface-high);
  border: 1px solid transparent;
  transition: background-color 0.16s ease, border-color 0.16s ease;
}

.kc-searchbox:focus-within {
  background: var(--kc-surface-container);
  border-color: var(--kc-primary-55);
}

.kc-searchbox > kc-icon {
  font-size: 19px;
  opacity: 0.5;
  flex: none;
}

/* 原生 input：去掉默认外观，完全贴合容器 */
.kc-searchbox input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 0.875rem;
  padding: 0;
}

.kc-searchbox input::placeholder {
  color: inherit;
  opacity: 0.5;
}

/* 去掉 Safari/Chrome 的 search 清除按钮，用自绘的 */
.kc-searchbox input::-webkit-search-decoration,
.kc-searchbox input::-webkit-search-cancel-button,
.kc-searchbox input::-webkit-search-results-button,
.kc-searchbox input::-webkit-search-results-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.kc-searchbox__clear {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  opacity: 0.5;
  cursor: pointer;
  transition: opacity 0.14s ease, background-color 0.14s ease;
}

.kc-searchbox__clear:hover {
  opacity: 0.9;
  background: var(--kc-surface-highest);
}

.kc-searchbox__clear kc-icon { font-size: 16px; }

/* 侧栏会话滚动区 */
.kc-sidebar__scroll {
  flex: 1;
  overflow-y: auto;
  padding: 2px 8px 20px;
  scrollbar-width: thin;
}

.kc-sidebar__scroll::-webkit-scrollbar { width: 8px; }
.kc-sidebar__scroll::-webkit-scrollbar-thumb {
  background: var(--kc-outline-variant);
  border-radius: 8px;
}

.kc-main {
  flex: 1;
  min-width: 0;
  /* 用 Grid 精确划分「信号线 / 消息区 / 输入框」三行。
     minmax(0, 1fr) 是关键：它显式把消息区的最小高度设为 0，
     否则消息很长时该行会被内容撑开，把输入框顶出视口。 */
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  position: relative;
  background: var(--kc-surface);
}

/* 顶部细线：加载时呼吸流动 */
.kc-signal {
  flex: none;
  height: 2px;
  background: transparent;
  overflow: hidden;
  position: relative;
}

.kc-main.is-busy .kc-signal::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent,
    var(--kc-primary), var(--kc-tertiary), transparent);
  animation: kc-flow 1.3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes kc-flow { to { transform: translateX(100%); } }

/* ============================================================
   会话列表
   ============================================================ */

.kc-conv {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 12px;
  border-radius: var(--kc-r-md);
  cursor: pointer;
  transition: background-color 0.16s ease;
  border: 1px solid transparent;
}

.kc-conv:hover { background: var(--kc-surface-high); }

.kc-conv.is-active {
  background: var(--kc-secondary-container);
  border-color: var(--kc-primary-20);
}

.kc-conv__main { flex: 1; min-width: 0; }

.kc-conv__top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.kc-conv__title {
  flex: 1;
  min-width: 0;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kc-conv__time {
  font-family: var(--kc-mono);
  font-size: 0.6875rem;
  opacity: 0.5;
  flex: none;
}

.kc-conv__sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.kc-conv__last {
  flex: 1;
  min-width: 0;
  font-size: 0.8125rem;
  opacity: 0.6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kc-conv__dot {
  flex: none;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--kc-primary);
  color: var(--kc-on-primary);
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
  font-family: var(--kc-mono);
}

.kc-conv__mute { flex: none; opacity: 0.4; font-size: 16px; }

/* ============================================================
   消息区
   ============================================================ */

.kc-scroll {
  flex: 1;
  /* 同 .kc-main：让消息区可在纵向收缩，输入框才不会被顶出视口 */
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.kc-scroll::-webkit-scrollbar { width: 10px; }
.kc-scroll::-webkit-scrollbar-thumb {
  background: var(--kc-outline-variant);
  border-radius: 10px;
}

.kc-thread {
  max-width: var(--kc-maxw);
  margin: 0 auto;
  padding: 20px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* 日期分隔：等宽小标签 + 细线 */
.kc-daysep {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 10px;
}

.kc-daysep::before,
.kc-daysep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--kc-outline-variant);
  opacity: 0.6;
}

.kc-daysep span {
  font-family: var(--kc-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.5;
  flex: none;
}

/* 单条消息：头像 + 气泡 */
.kc-msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 3px 0;
  max-width: 100%;
}

.kc-msg__col {
  min-width: 0;
  max-width: min(74%, 600px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

/* 自己的消息：整行靠右，头像在右侧 */
.kc-msg--me {
  flex-direction: row-reverse;
}

/* 让气泡紧贴头像，不被 flex 拉伸 */
.kc-msg--me .kc-msg__col {
  align-items: flex-end;
  margin-left: auto;
  flex: 0 1 auto;
}

.kc-msg--peer .kc-msg__col,
.kc-msg--ai .kc-msg__col {
  flex: 0 1 auto;
}

.kc-msg__meta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 4px;
  padding: 0 4px;
  width: 100%;
}

.kc-msg--me .kc-msg__meta {
  flex-direction: row-reverse;
  justify-content: flex-start;
}

.kc-msg__who {
  font-size: 0.75rem;
  font-weight: 700;
  opacity: 0.7;
}

.kc-msg__time {
  font-family: var(--kc-mono);
  font-size: 0.6875rem;
  opacity: 0.4;
}

.kc-msg__badge {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--kc-tertiary-20);
  color: var(--kc-tertiary);
}

/* 气泡本体 */
.kc-msg__text {
  position: relative;
  font-size: 0.9375rem;
  line-height: 1.68;
  word-break: break-word;
  overflow-wrap: anywhere;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--kc-surface-container);
  border: 1px solid var(--kc-outline-variant);
  /* 气泡尖角的圆角处理 */
  border-top-left-radius: 5px;
}

.kc-msg--me .kc-msg__text {
  background: var(--kc-primary);
  color: var(--kc-on-primary);
  border-color: transparent;
  border-top-left-radius: 16px;
  border-top-right-radius: 5px;
}

/* AI 代发：虚线描边 + 标记色 */
.kc-msg--ai .kc-msg__text {
  background: var(--kc-surface-high);
  border: 1px dashed var(--kc-tertiary-65);
  border-top-left-radius: 5px;
}

/* 气泡内元素的配色跟随气泡 */
.kc-msg--me .kc-msg__text a { color: var(--kc-on-primary); text-decoration: underline; }
.kc-msg--me .kc-msg__text code,
.kc-msg--me .kc-msg__text pre {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.22);
}
.kc-msg--me .kc-msg__text blockquote {
  border-left-color: rgba(255, 255, 255, 0.5);
}
.kc-msg--me .kc-msg__text th,
.kc-msg--me .kc-msg__text td {
  border-color: rgba(255, 255, 255, 0.3);
}

.kc-msg__text > *:first-child { margin-top: 0; }
.kc-msg__text > *:last-child { margin-bottom: 0; }

.kc-msg__text p { margin: 0 0 0.6em; }
.kc-msg__text ul, .kc-msg__text ol { margin: 0 0 0.6em; padding-left: 1.35em; }
.kc-msg__text li { margin: 0.16em 0; }
.kc-msg__text a { color: var(--kc-primary); overflow-wrap: anywhere; }
.kc-msg__text img {
  max-width: 100%;
  max-height: 340px;
  border-radius: 10px;
  display: block;
  margin: 6px 0;
}
.kc-msg__text blockquote {
  margin: 0 0 0.6em;
  padding: 1px 0 1px 12px;
  border-left: 3px solid var(--kc-outline-variant);
  opacity: 0.9;
}
.kc-msg__text h1, .kc-msg__text h2, .kc-msg__text h3,
.kc-msg__text h4, .kc-msg__text h5, .kc-msg__text h6 {
  font-size: 1.02em;
  margin: 0.8em 0 0.35em;
  line-height: 1.4;
}
.kc-msg__text hr {
  border: none;
  border-top: 1px solid var(--kc-outline-variant);
  margin: 0.8em 0;
}
.kc-msg__text table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.875em;
  margin-bottom: 0.6em;
  display: block;
  overflow-x: auto;
}
.kc-msg__text th, .kc-msg__text td {
  border: 1px solid var(--kc-outline-variant);
  padding: 5px 9px;
  text-align: left;
}
.kc-msg__text code {
  font-family: var(--kc-mono);
  font-size: 0.86em;
  background: var(--kc-surface-high);
  padding: 0.12em 0.4em;
  border-radius: 5px;
}
.kc-msg__text pre {
  margin: 0 0 0.65em;
  background: var(--kc-surface-high);
  border: 1px solid var(--kc-outline-variant);
  border-radius: var(--kc-r-sm);
  padding: 11px 13px;
  overflow-x: auto;
}
.kc-msg__text pre code {
  background: none;
  padding: 0;
  font-size: 0.8125rem;
  line-height: 1.6;
}

/* 消息操作按钮 */
.kc-msg__ops {
  display: flex;
  gap: 2px;
  margin-top: 3px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.kc-msg:hover .kc-msg__ops,
.kc-msg:focus-within .kc-msg__ops { opacity: 1; }

/* 光标 */
.kc-caret {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  vertical-align: -0.15em;
  margin-left: 2px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.7;
  animation: kc-blink 1.1s steps(2, start) infinite;
}
@keyframes kc-blink { to { opacity: 0; } }

/* 系统提示行 */
.kc-sysnote {
  align-self: center;
  max-width: 90%;
  margin: 6px 0;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--kc-surface-high);
  font-family: var(--kc-mono);
  font-size: 0.6875rem;
  opacity: 0.75;
  text-align: center;
}

.kc-more { align-self: center; margin: 4px 0 12px; }

/* ============================================================
   空态
   ============================================================ */

.kc-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 40px 24px;
  text-align: center;
  min-height: 0;
}

.kc-empty__icon { font-size: 40px; opacity: 0.25; margin-bottom: 6px; }
.kc-empty__title { font-size: 1rem; font-weight: 600; opacity: 0.75; }
.kc-empty__desc {
  font-size: 0.8125rem;
  opacity: 0.5;
  max-width: 34ch;
  line-height: 1.6;
}

.kc-sidebar .kc-empty { padding: 32px 16px; }

/* ============================================================
   输入区
   ============================================================ */

.kc-composer {
  flex: none;
  padding: 8px 20px 16px;
}

/* 胶囊输入区：全自控样式，不依赖 mdui 输入框组件 */
.kc-composer__inner {
  max-width: var(--kc-maxw);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 6px 6px 16px;
  border-radius: 24px;
  background: var(--kc-surface-high);
  border: 1px solid var(--kc-outline-variant);
  transition: border-color 0.16s ease;
}

.kc-composer__inner:focus-within {
  border-color: var(--kc-primary-55);
}

.kc-composer textarea {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 0.9375rem;
  line-height: 1.5;
  padding: 8px 0;
  margin: 0;
  resize: none;
  overflow-y: auto;
  scrollbar-width: thin;
}

.kc-composer textarea::placeholder {
  color: inherit;
  opacity: 0.5;
}

.kc-composer mdui-button-icon {
  flex: none;
  margin-bottom: 1px;
}

.kc-hint {
  max-width: var(--kc-maxw);
  margin: 7px auto 0;
  font-size: 0.6875rem;
  opacity: 0.42;
  text-align: center;
  font-family: var(--kc-mono);
}

/* ============================================================
   通用页面（通讯录 / 设置 / 主页 / 后台）
   ============================================================ */

.kc-page {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}

.kc-page::-webkit-scrollbar { width: 10px; }
.kc-page::-webkit-scrollbar-thumb {
  background: var(--kc-outline-variant);
  border-radius: 10px;
}

.kc-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 20px 80px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.kc-wrap--wide { max-width: 900px; }

.kc-card {
  border-radius: var(--kc-r-lg);
  background: var(--kc-surface-container);
  border: 1px solid var(--kc-outline-variant);
  padding: 18px 20px;
}

.kc-card__title { font-size: 0.9375rem; font-weight: 700; margin: 0 0 4px; }
.kc-card__desc {
  font-size: 0.8125rem;
  line-height: 1.6;
  opacity: 0.6;
  margin: 0 0 16px;
}

.kc-card > .kc-field:last-child,
.kc-card > *:last-child { margin-bottom: 0; }

.kc-field { margin-bottom: 16px; }
.kc-field mdui-text-field,
.kc-field mdui-select,
.kc-field mdui-slider { width: 100%; }

.kc-row { display: flex; gap: 12px; flex-wrap: wrap; }
.kc-row > * { flex: 1 1 180px; min-width: 0; }

.kc-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.kc-section-label {
  font-family: var(--kc-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.5;
  padding: 0 4px;
  margin-bottom: -8px;
}

.kc-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 0;
}

.kc-toggle + .kc-toggle { border-top: 1px solid var(--kc-outline-variant); }
.kc-toggle__text { min-width: 0; }
.kc-toggle__label { font-size: 0.875rem; font-weight: 600; }
.kc-toggle__desc {
  font-size: 0.75rem;
  opacity: 0.6;
  margin-top: 3px;
  line-height: 1.5;
}

.kc-swatches { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

.kc-swatch {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: transform 0.14s ease;
  padding: 0;
}

.kc-swatch:hover { transform: scale(1.08); }
.kc-swatch.is-active { outline-color: var(--kc-primary); }

.kc-user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-radius: var(--kc-r-md);
  transition: background-color 0.15s ease;
  cursor: pointer;
}

.kc-user-row:hover { background: var(--kc-surface-high); }

.kc-user-row__main { flex: 1; min-width: 0; }

.kc-user-row__name {
  font-size: 0.875rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.kc-user-row__sub {
  font-size: 0.75rem;
  opacity: 0.6;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kc-user-row__actions { display: flex; gap: 6px; flex: none; align-items: center; }

.kc-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--kc-surface-highest);
  opacity: 0.9;
}

.kc-tag--admin { background: var(--kc-primary-18); color: var(--kc-primary); }
.kc-tag--ai { background: var(--kc-tertiary-18); color: var(--kc-tertiary); }
.kc-tag--blocked { background: var(--kc-error-18); color: var(--kc-error); }

.kc-hr { height: 1px; background: var(--kc-outline-variant); margin: 14px 0; border: none; }

/* ============================================================
   登录页
   ============================================================ */

.kc-login {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  overflow-y: auto;
}

.kc-login__card {
  width: 100%;
  max-width: 400px;
  border-radius: 26px;
  padding: 30px 26px;
  background: var(--kc-surface-container);
  border: 1px solid var(--kc-outline-variant);
}

.kc-login__mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 16px;
  border-radius: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 25px;
  font-weight: 800;
  /* 同 .kc-brand__mark：清行高 + 视觉居中补偿 */
  line-height: 1;
  padding-bottom: 0.1em;
  color: #fff;
  background: linear-gradient(140deg, var(--kc-primary), var(--kc-tertiary));
  user-select: none;
}

.kc-login__title {
  font-size: 1.35rem;
  font-weight: 700;
  text-align: center;
  margin: 0 0 6px;
  letter-spacing: -0.02em;
}

.kc-login__sub {
  text-align: center;
  font-size: 0.8125rem;
  opacity: 0.6;
  margin: 0 0 24px;
  line-height: 1.6;
}

.kc-login__form { display: flex; flex-direction: column; gap: 4px; }

.kc-login__switch {
  text-align: center;
  margin-top: 18px;
  font-size: 0.8125rem;
  opacity: 0.75;
}

.kc-login__switch a {
  color: var(--kc-primary);
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
}

.kc-login__err {
  display: none;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--kc-r-md);
  background: var(--kc-error-container);
  color: var(--kc-on-error-container);
  font-size: 0.8125rem;
  line-height: 1.5;
  margin-bottom: 16px;
}

.kc-login__err.is-show { display: flex; }

/* ============================================================
   主页 / 资料页
   ============================================================ */

.kc-profile-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.kc-profile-head__main { flex: 1; min-width: 180px; }

.kc-profile-name {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.kc-profile-bio {
  font-size: 0.875rem;
  opacity: 0.75;
  margin-top: 8px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.kc-profile-meta {
  font-family: var(--kc-mono);
  font-size: 0.6875rem;
  opacity: 0.45;
  margin-top: 8px;
}

.kc-bio-text {
  font-size: 0.875rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ============================================================
   移动端抽屉 / 底部导航
   ============================================================ */

.kc-drawer-list { padding: 8px; }

.kc-mobile-nav {
  flex: none;
  display: none;
  border-top: 1px solid var(--kc-outline-variant);
  background: var(--kc-surface-low);
}

.kc-mobile-nav mdui-navigation-bar { width: 100%; }

/* ============================================================
   响应式
   ============================================================ */

@media (max-width: 860px) {
  /* 竖屏改成「列表 ⇄ 聊天」两屏切换（原生的主从导航）：
     默认展示会话列表，点进某个会话才切到聊天区，返回键回到列表。
     不能让侧栏一直 display:none —— 那样用户既看不到列表也没法发起聊天。 */
  .kc-sidebar {
    display: flex;
    width: 100%;
    border-right: none;
  }

  .kc-main { display: none; }

  .kc-app.showing-thread .kc-sidebar { display: none; }
  .kc-app.showing-thread .kc-main { display: grid; }

  /* 列表页用左上角汉堡菜单，聊天页用返回键，避免两个按钮并排出现 */
  .kc-app:not(.showing-thread) .kc-back-btn { display: none !important; }
  .kc-app.showing-thread #menuBtn { display: none !important; }

  /* 列表页没有「当前会话」，会话操作菜单与发起聊天按钮都收起来，
     因为侧栏里已经有一个更大更明确的「发起聊天」按钮了 */
  .kc-app:not(.showing-thread) #threadDropdown { display: none; }
  .kc-app:not(.showing-thread) #newChatBtn { display: none; }

  /* 聊天页顶部只留对方名字，不重复显示 App 的 K 标记 */
  .kc-app.showing-thread .kc-brand__mark { display: none; }

  /* 会话列表为空时占满可用高度，居中显示提示 */
  .kc-sidebar__scroll { display: flex; flex-direction: column; }

  /* 关键修复：mdui-navigation-bar 自身是 position: fixed，会脱离文档流，
     导致这个外层容器高度塌缩、flex 布局不为它留位置，
     固定定位的导航栏就会盖住底部输入框。这里用显式高度为它占位。 */
  .kc-mobile-nav {
    display: block;
    flex: none;
    height: 80px;
  }

  .kc-wrap { padding: 16px 14px 80px; }
  .kc-thread { padding: 14px 14px 20px; }
  .kc-composer { padding: 6px 12px 12px; }
  .kc-hint { display: none; }
}

@media (min-width: 861px) {
  .kc-back-btn { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ============================================================
   404 页面
   设计思路：聊天应用里的「信号断了」——
   沿用站内的品牌渐变与等宽字体（站内时间戳/标签就是等宽），
   把 404 做成一个可读性强的视觉主体，而不是放一个插画。
   ============================================================ */

.kc-404 {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
}

.kc-404__mark {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: linear-gradient(140deg, var(--kc-primary), var(--kc-tertiary));
  color: #fff;
  font-size: 21px;
  font-weight: 800;
  line-height: 1;
  padding-bottom: 0.1em;
  user-select: none;
  animation: kc-rise 0.34s cubic-bezier(0.2, 0.8, 0.3, 1) backwards;
}

/* 用品牌渐变填充大号等宽 404 */
.kc-404__code {
  margin: 20px 0 0;
  font-family: var(--kc-mono);
  font-size: clamp(60px, 16vw, 104px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.06em;
  /* 让渐变覆盖整个字面宽度 */
  background-image: linear-gradient(140deg, var(--kc-primary), var(--kc-tertiary));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: kc-rise 0.34s cubic-bezier(0.2, 0.8, 0.3, 1) 0.06s backwards;
}

.kc-404__title {
  margin: 18px 0 0;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  animation: kc-rise 0.34s cubic-bezier(0.2, 0.8, 0.3, 1) 0.12s backwards;
}

.kc-404__desc {
  margin: 8px 0 0;
  max-width: 34ch;
  font-size: 0.875rem;
  line-height: 1.7;
  opacity: 0.6;
  animation: kc-rise 0.34s cubic-bezier(0.2, 0.8, 0.3, 1) 0.16s backwards;
}

/* 把出错的地址原样显示出来，方便用户核对（等宽 + 不可选中溢出的部分省略） */
.kc-404__path {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(100%, 420px);
  margin-top: 24px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--kc-surface-high);
  border: 1px solid var(--kc-outline-variant);
  font-family: var(--kc-mono);
  font-size: 0.75rem;
  opacity: 0.8;
  animation: kc-rise 0.34s cubic-bezier(0.2, 0.8, 0.3, 1) 0.2s backwards;
}

.kc-404__path > kc-icon {
  flex: none;
  font-size: 15px;
  opacity: 0.6;
}

.kc-404__path code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kc-404__actions {
  margin-top: 28px;
  animation: kc-rise 0.34s cubic-bezier(0.2, 0.8, 0.3, 1) 0.24s backwards;
}

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

/* ============================================================
   群聊 / 消息操作（新增）
   ============================================================ */

/* 会话列表里的群成员数 */
.kc-conv__count {
  font-size: 0.6875rem;
  font-weight: 400;
  opacity: 0.5;
}

/* 每条消息的内联操作按钮（复制 / 撤回 / 删除） */
.kc-msg__ops {
  display: flex;
  gap: 2px;
  margin-top: 3px;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.kc-msg:hover .kc-msg__ops,
.kc-msg:focus-within .kc-msg__ops {
  opacity: 1;
  transform: none;
}

.kc-msg--me .kc-msg__ops { justify-content: flex-end; }

.kc-msg__op {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  opacity: 0.55;
  cursor: pointer;
  transition: opacity 0.15s ease, background-color 0.15s ease, transform 0.12s ease;
}

.kc-msg__op:hover {
  opacity: 1;
  background: var(--kc-surface-high);
}

.kc-msg__op:active { transform: scale(0.88); }

.kc-msg__op kc-icon { font-size: 16px; }

/* 触屏设备没有 hover，让操作按钮常驻可见 */
@media (hover: none) {
  .kc-msg__ops { opacity: 0.7; transform: none; }
}

/* 已撤回的提示行 */
.kc-sysnote--recall {
  background: transparent;
  opacity: 0.55;
  animation: kc-fade 0.32s ease both;
}

/* 会话选择器：整行负责点击，复选框不单独响应，避免重复切换 */
.kc-user-row mdui-checkbox { pointer-events: none; }

/* 已选人标签：左对齐，空时不占位 */
#selectedChips {
  justify-content: flex-start;
  gap: 8px;
}

#selectedChips:empty { display: none; }

/* 消息菜单里被隐藏的项（如已过期不能撤回） */
mdui-menu-item[hidden] { display: none !important; }

/* ============================================================
   动效
   原则：进场动画只在「首次渲染 / 打开会话」时播放一次。
   会话列表每几秒就会重绘一次，若动画挂在会被重绘的元素上，
   就会变成每隔几秒闪一下，所以统一用 kc-stagger 类显式控制。
   ============================================================ */

@keyframes kc-rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes kc-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes kc-pop {
  0% { opacity: 0; transform: scale(0.92); }
  60% { transform: scale(1.02); }
  100% { opacity: 1; transform: none; }
}

/* 错峰进场：--i 控制延迟；列表里由 JS 写入，静态卡片由 nth-child 兜底。
   ⚠️ 这里刻意用 backwards 而不是 both：
   fill-mode 为 forwards/both 时元素会一直处于「动画中」，
   在 Chrome 下会持续保留一个层叠上下文，卡片内展开的下拉菜单
   就再也盖不过后面的卡片了（菜单的 z-index 无法穿透父级层叠上下文）。 */
.kc-stagger > * {
  animation: kc-rise 0.34s cubic-bezier(0.2, 0.8, 0.3, 1) backwards;
  animation-delay: calc(var(--i, 0) * 26ms);
}

.kc-stagger > *:nth-child(1) { --i: 0; }
.kc-stagger > *:nth-child(2) { --i: 1; }
.kc-stagger > *:nth-child(3) { --i: 2; }
.kc-stagger > *:nth-child(4) { --i: 3; }
.kc-stagger > *:nth-child(5) { --i: 4; }
.kc-stagger > *:nth-child(6) { --i: 5; }
.kc-stagger > *:nth-child(7) { --i: 6; }
.kc-stagger > *:nth-child(8) { --i: 7; }
.kc-stagger > *:nth-child(9) { --i: 8; }
.kc-stagger > *:nth-child(10) { --i: 9; }
.kc-stagger > *:nth-child(11) { --i: 10; }
.kc-stagger > *:nth-child(n+12) { --i: 11; }

/* 会话行：切换/按下时的过渡 */
.kc-conv {
  transition: background-color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.kc-conv:active { transform: scale(0.985); }

/* 注意：不要给 .kc-msg 挂全局动画 —— 消息区在发送、加载更多、同步时都会重绘，
   那样每轮都会重播动画。进场动画统一由 .kc-stagger（仅打开会话时加）负责，
   新到达的单条消息由 JS 用 Web Animations API 播放。 */

/* 小按钮的按压反馈 */
.kc-searchbox__clear:active,
.kc-msg__op:active,
.kc-swatch:active { transform: scale(0.88); }

.kc-swatch { transition: transform 0.14s ease; }
.kc-searchbox__clear { transition: opacity 0.14s ease, background-color 0.14s ease, transform 0.12s ease; }

/* 输入框发送按钮按下时轻微回弹 */
.kc-composer__inner mdui-button-icon:active { transform: scale(0.92); }
.kc-composer__inner mdui-button-icon { transition: transform 0.12s ease; }

/* 注意：不要给 .kc-card 挂进场动画。
   带 fill-mode 的动画会让卡片形成持续的层叠上下文，
   卡片内展开的下拉菜单就会被后面的卡片盖住。 */

/* 抽屉与底部导航：mdui 自带动效，这里只补导航项按下反馈 */
mdui-navigation-bar-item { transition: opacity 0.15s ease; }
mdui-navigation-bar-item:active { opacity: 0.7; }

/* 群成员列表里的角色标签 */
.kc-role-tag {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--kc-primary-18);
  color: var(--kc-primary);
}

.kc-role-tag--owner {
  background: var(--kc-tertiary-18);
  color: var(--kc-tertiary);
}
