/* ============================================================
   KakoChat · 主界面（会话列表 + 聊天窗口）
   ============================================================ */

.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-columns: 322px minmax(0, 1fr);
  overflow: hidden;
}

.only-mobile { display: none; }

/* ---------------- 左侧 ---------------- */
.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.sidebar-head { padding: 10px 10px 6px; flex: none; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 7px 9px;
  border-radius: var(--r-md);
  text-align: left;
  transition: background var(--dur);
}
.user-chip:hover { background: var(--panel-2); }
.user-chip-text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.user-chip-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.user-chip-line strong { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip-text small { color: var(--muted); }
.chev { width: 16px; height: 16px; flex: none; color: var(--muted); }

.search-wrap { position: relative; padding: 4px 12px 10px; flex: none; }
.search-icon {
  position: absolute;
  left: 22px;
  top: 50%;
  transform: translateY(-60%);
  width: 15px;
  height: 15px;
  color: var(--muted);
  pointer-events: none;
}
.search-input { padding-left: 33px; padding-right: 30px; height: 36px; }
.search-clear {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-60%);
  width: 22px;
  height: 22px;
  border-radius: var(--r-full);
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.search-clear:hover { background: var(--panel-3); color: var(--text); }

.side-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding-bottom: 14px; }

/* 会话行 */
.conv {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
  width: 100%;
  padding: 9px 14px;
  border-left: 2px solid transparent;
  text-align: left;
  transition: background var(--dur), border-color var(--dur);
}
.conv:hover { background: var(--panel-2); }
.conv.is-active { background: var(--panel-2); border-left-color: var(--accent); }
.conv-body { min-width: 0; display: grid; gap: 2px; }
.conv-name { display: flex; align-items: center; gap: 6px; min-width: 0; }
.conv-name strong { font-size: 14px; font-weight: 570; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-last {
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-meta { display: grid; gap: 5px; justify-items: end; flex: none; }
.conv-time { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); letter-spacing: .04em; }
.conv-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--r-full);
  background: var(--accent-fill);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.conv-badge.is-muted { background: var(--panel-3); color: var(--muted); }
.conv-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

/* 搜索结果行 */
.result-actions { display: flex; align-items: center; gap: 6px; flex: none; }

/* ---------------- 右侧聊天区 ---------------- */
.chat {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.chat-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 58px;
  padding: 0 12px 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.peer-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 5px 8px;
  border-radius: var(--r-sm);
  text-align: left;
}
.peer-chip:hover { background: var(--panel-2); }
.peer-chip-text { min-width: 0; display: grid; gap: 0; }
.peer-chip-text small { color: var(--muted); }
.chat-head-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }

/* 消息区 */
.msg-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 16px 0 10px; }
.msg-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
}

.day-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 12px;
}
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--line-soft); }
.day-sep span {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .12em;
  color: var(--muted);
  text-transform: uppercase;
}

.msg { display: flex; gap: 10px; align-items: flex-start; padding: 1.5px 0; }
.msg[data-mine="1"] { flex-direction: row-reverse; }
.msg-time {
  flex: none;
  width: 46px;
  padding-top: 8px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .04em;
  color: var(--muted);
  text-align: right;
}
.msg-body { display: flex; gap: 9px; align-items: flex-start; max-width: min(78%, 620px); }
.msg[data-mine="1"] .msg-body { flex-direction: row-reverse; }
.msg-main { min-width: 0; display: grid; gap: 3px; }
.msg[data-mine="1"] .msg-main { justify-items: end; }

.msg-bubble {
  padding: 8px 12px;
  border-radius: var(--r-xs) var(--r-md) var(--r-md) var(--r-md);
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 14.5px;
  line-height: 1.62;
  overflow-wrap: anywhere;
}
.msg[data-mine="1"] .msg-bubble {
  border-radius: var(--r-md) var(--r-xs) var(--r-md) var(--r-md);
  background: var(--accent-wash);
  border-color: var(--accent-line);
}
.msg.is-pending .msg-bubble { opacity: .55; }
.msg-flag {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--accent);
  padding-left: 2px;
}

/* 气泡内 Markdown */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 .55em; }.md h1, .md h2, .md h3 { font-size: 1.02em; font-weight: 650; margin: .5em 0 .35em; letter-spacing: -.01em; }
.md ul, .md ol { margin: .35em 0 .55em; padding-left: 1.25em; display: grid; gap: 2px; }
.md li::marker { color: var(--muted); }
.md code {
  font-family: var(--font-mono);
  font-size: .87em;
  padding: 1px 5px;
  border-radius: var(--r-xs);
  background: var(--panel-3);
  border: 1px solid var(--line-soft);
}
.md pre {
  margin: .45em 0;
  padding: 10px 12px;
  background: var(--panel-3);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  overflow-x: auto;
}
.md pre code { background: none; border: 0; padding: 0; font-size: 12.5px; letter-spacing: 0; line-height: 1.55; }
.md blockquote { margin: .45em 0; padding: 2px 0 2px 10px; border-left: 2px solid var(--accent-line); color: var(--text-dim); }
.md a { word-break: break-all; text-decoration: underline; text-underline-offset: 2px; }
.md hr { border: 0; height: 1px; background: var(--line); margin: .7em 0; }
.md strong { font-weight: 660; }
.md a.md-img { display: inline-block; max-width: 100%; margin: .3em 0; line-height: 0; }
.md img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  width: auto;
  height: auto;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  background: var(--panel-3);
}

/* 输入区 */
.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.composer-input {
  flex: 1;
  min-width: 0;
  max-height: 148px;
  padding: 10px 13px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  overflow-y: auto;
  transition: border-color var(--dur), box-shadow var(--dur);
}
.composer-input::placeholder { color: var(--muted); }
.composer-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.send-btn { height: 40px; padding: 0 16px; flex: none; }
.composer-tool { width: 40px; height: 40px; flex: none; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--panel-2); }
.composer-tool:hover { border-color: var(--accent-line); color: var(--accent); }

/* 顶部「加载更多」：有更早记录时显示按钮，翻到头后显示提示 */
.load-more {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 0 14px;
  margin-bottom: 6px;
  border-bottom: 1px dashed var(--line);
}
.load-more .btn {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-wash);
}
.load-more .btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.load-more-hint {
  font-size: 12px;
  color: var(--muted);
}

/* 空状态 */
.chat-empty {
  flex: 1;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 6px;
  text-align: center;
  padding: 30px;
}
.chat-empty h2 { font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.chat-empty p { font-size: 13px; color: var(--muted); max-width: 380px; }
.chat-empty .empty-mark {
  border-style: solid;
  border-color: var(--line);
  color: var(--muted);
  margin-bottom: 6px;
}

/* 好友主页 */
.profile-head { display: flex; align-items: center; gap: 14px; }
.profile-head .stack-tight { gap: 3px; }
.profile-name { font-size: 19px; font-weight: 650; letter-spacing: -.02em; display: flex; align-items: center; gap: 7px; }
.kv { display: grid; grid-template-columns: 92px 1fr; gap: 8px 12px; align-items: baseline; }
.kv dt {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.kv dd { font-size: 13.5px; overflow-wrap: anywhere; }

/* 设置面板 */
.settings-layout { display: grid; grid-template-columns: 168px minmax(0, 1fr); min-height: 380px; }
.settings-nav {
  border-right: 1px solid var(--line);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--panel-2);
}
.settings-nav button {
  text-align: left;
  padding: 8px 11px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  color: var(--text-dim);
}
.settings-nav button:hover { background: var(--panel-3); color: var(--text); }
.settings-nav button.is-active { background: var(--accent-wash); color: var(--accent); font-weight: 560; }
.settings-body { padding: 18px; overflow: auto; display: grid; gap: 18px; align-content: start; }
.settings-group { display: grid; gap: 12px; }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--panel-2);
}
.setting-row-main { min-width: 0; display: grid; gap: 2px; }
.setting-row-main strong { font-size: 13.5px; font-weight: 560; }
.setting-row-main span { font-size: 12px; color: var(--muted); }

/* 模型卡片 */
.model-card {
  display: grid;
  gap: 11px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel-2);
}
.model-card.is-active { border-color: var(--accent-line); background: var(--accent-wash); }
.model-card-head { display: flex; align-items: center; gap: 9px; }
.model-card-head strong { font-size: 13.5px; flex: 1; min-width: 0; }

/* 管理员：用户面板 */
.admin-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.invite-code {
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: .12em;
  color: var(--accent);
}

/* ---------------- 竖屏适配 ---------------- */
@media (max-width: 820px) {
  .only-mobile { display: grid; }

  .app { grid-template-columns: 1fr; }
  .sidebar, .chat {
    grid-area: 1 / 1;
    width: 100%;
    border-right: 0;
    transition: transform .24s cubic-bezier(.3, .8, .3, 1);
    will-change: transform;
  }
  .app[data-view="list"] .sidebar { transform: translateX(0); }
  .app[data-view="list"] .chat { transform: translateX(100%); }
  .app[data-view="chat"] .sidebar { transform: translateX(-100%); }
  .app[data-view="chat"] .chat { transform: translateX(0); }

  .msg-inner { padding: 0 14px; }
  .msg-time { display: none; }
  .msg-body { max-width: 88%; }
  .composer { padding: 10px 12px 14px; }
  .composer-input { font-size: 15px; }
  .send-btn span { display: none; }
  .send-btn { width: 40px; padding: 0; }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav {
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 8px;
  }
  .settings-nav button { white-space: nowrap; }
  .modal { width: 100%; max-height: 88vh; }
  .kv { grid-template-columns: 78px 1fr; }
}

@media (max-width: 420px) {
  .sidebar-head, .search-wrap { padding-left: 8px; padding-right: 8px; }
  .settings-body { padding: 14px; }
}

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

/* 左侧「发起群聊」入口 */
.side-tools { padding: 0 12px 8px; flex: none; }
.new-group-btn {
  width: 100%;
  height: 34px;
  justify-content: center;
  gap: 6px;
  border: 1px dashed var(--line);
  color: var(--text-dim);
}
.new-group-btn svg { width: 16px; height: 16px; }
.new-group-btn:hover { border-color: var(--accent-line); color: var(--accent); background: var(--accent-wash); }

/* 群聊标记：会话名后面的小胶囊 */
.conv-name .pill { flex: none; font-size: 9.5px; padding: 0 5px; }

/* 消息：气泡 + 操作按钮同一行 */
.msg-line { display: flex; align-items: center; gap: 4px; min-width: 0; max-width: 100%; }
.msg[data-mine="1"] .msg-line { flex-direction: row-reverse; }

.msg-tools {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: var(--r-full);
  color: var(--muted);
  opacity: 0;
  transition: opacity var(--dur), background var(--dur), color var(--dur);
}
.msg-tools svg { width: 16px; height: 16px; }
.msg:hover .msg-tools,
.msg-tools:focus-visible { opacity: 1; }
.msg-tools:hover { background: var(--panel-3); color: var(--text); }
/* 触屏没有 hover，按钮常驻但弱化显示 */
@media (hover: none) {
  .msg-tools { opacity: .45; }
  .msg:active .msg-tools { opacity: 1; }
}

/* 群聊里的发言人名字 */
.msg-author {
  font-size: 11.5px;
  font-weight: 560;
  color: var(--muted);
  padding: 0 2px 1px;
}

/* 已撤回的消息 */
.msg-bubble.is-recall {
  background: transparent;
  border-style: dashed;
  border-color: var(--line);
  color: var(--muted);
  font-size: 12.5px;
  font-style: italic;
  line-height: 1.5;
}
.msg[data-mine="1"] .msg-bubble.is-recall {
  background: transparent;
  border-color: var(--line);
}

/* 群资料面板 */
.group-head { display: flex; align-items: center; gap: 14px; }
.group-head .avatar { flex: none; }
.group-head-main { flex: 1; min-width: 0; display: grid; gap: 3px; }
.group-name-line { display: flex; align-items: center; gap: 7px; min-width: 0; }
.group-name { font-size: 17px; font-weight: 640; letter-spacing: -.01em; overflow-wrap: anywhere; }
.group-sub { font-size: 11px; color: var(--muted); letter-spacing: .05em; }
.group-head-tools { flex: none; display: flex; align-items: center; gap: 4px; }
.group-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* 成员 / 邀请选择器 */
.pick { display: grid; gap: 8px; min-width: 0; }
.pick-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pick-chips:empty { display: none; }
.pick-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 8px;
  border-radius: var(--r-full);
  background: var(--accent-wash);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  font-size: 12px;
  max-width: 180px;
}
.pick-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-chip-x { opacity: .7; font-size: 13px; line-height: 1; }
.pick-chip:hover .pick-chip-x { opacity: 1; }

.pick-list {
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--panel-2);
}
.pick-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  text-align: left;
  transition: background var(--dur);
}
.pick-row:hover { background: var(--panel-3); }
.pick-row.is-checked { background: var(--accent-wash); }
.pick-main { flex: 1; min-width: 0; display: grid; gap: 1px; }
.pick-name { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13.5px; }
.pick-sub { font-size: 10.5px; color: var(--muted); letter-spacing: .04em; }
.pick-check {
  flex: none;
  width: 19px;
  height: 19px;
  border-radius: var(--r-xs);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--accent-ink);
}
.pick-check.is-on { background: var(--accent-fill); border-color: var(--accent-fill); }
.pick-check svg { width: 13px; height: 13px; stroke-width: 2.4; }
.pick-list .list-head { padding: 8px 10px 4px; }

/* 聊天记录里的占位（撤回 / 已删除） */
.list-row-title.is-muted { color: var(--muted); font-style: italic; font-weight: 480; }

/* 群成员管理：让「移出成员」这类操作一眼可见 */
.member-hint { padding: 0 12px 8px; }
.list-row.is-manageable { cursor: pointer; }
.row-manage {
  flex: none;
  gap: 4px;
  padding: 0 9px;
  color: var(--text-dim);
}
.row-manage svg { width: 15px; height: 15px; }
.row-manage:hover {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-wash);
}
