/* AI聊天 · 网页聊天，QQ 式布局 */

/* hidden 属性必须真的隐藏：下面很多块写了 display:flex/grid，
   作者样式优先级高于浏览器默认的 [hidden]{display:none}，不加这条就会一直显示着。 */
[hidden] { display: none !important; }

:root {
  --bg: #f2f4f7;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --line: #e7e9ee;
  --text: #14171c;
  --sub: #8b9099;
  --me: #12b7f5;
  --me-text: #ffffff;
  --peer: #ffffff;
  --peer-text: #14171c;
  --danger: #e5484d;
  --hover: #eef0f4;
  --active: #e4f4fd;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1014;
    --panel: #15191f;
    --panel-2: #12161b;
    --line: #232830;
    --text: #e9ebef;
    --sub: #858c96;
    --me: #0a84ff;
    --me-text: #ffffff;
    --peer: #1e242c;
    --peer-text: #e9ebef;
    --hover: #1b2027;
    --active: #16324a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", "Segoe UI", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor;
      stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.app { display: flex; height: 100%; }

/* ---------------- 左栏：好友列表 ---------------- */

.sidebar {
  width: 288px;
  flex: 0 0 288px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 10px;
  padding-top: max(16px, env(safe-area-inset-top));
}

.brand { font-size: 17px; font-weight: 700; letter-spacing: .04em; }

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 9px;
  color: var(--sub);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { transform: scale(.94); }

.search {
  margin: 0 12px 10px;
  display: flex; align-items: center; gap: 7px;
  padding: 0 10px;
  height: 34px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--sub);
}
.search svg { width: 16px; height: 16px; flex: 0 0 16px; }
.search input {
  flex: 1; min-width: 0;
  background: none; border: 0; outline: 0;
  color: var(--text); font: inherit; font-size: 14px;
}
.search input::placeholder { color: var(--sub); }

.friends {
  flex: 1;
  margin: 0; padding: 4px 8px 12px;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.friend {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 9px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .13s;
}
.friend:hover { background: var(--hover); }
.friend.on { background: var(--active); }

.friend .ava {
  width: 44px; height: 44px; flex: 0 0 44px;
  border-radius: 12px;
  object-fit: cover;
  object-position: center 18%;
  background: var(--panel-2);
}

.friend .meta { flex: 1; min-width: 0; }
.friend .row1 { display: flex; align-items: baseline; gap: 6px; }
.friend .name {
  font-size: 14.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.friend .time { margin-left: auto; font-size: 11px; color: var(--sub); flex: 0 0 auto; }
.friend .snippet {
  margin-top: 2px;
  font-size: 12.5px; color: var(--sub);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.dot {
  min-width: 17px; height: 17px;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px; line-height: 17px; text-align: center;
  font-variant-numeric: tabular-nums;
}

.side-foot {
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--sub);
}

/* ---------------- 右栏：聊天 ---------------- */

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  position: relative;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--sub);
}
.empty-mark {
  font-size: 26px; font-weight: 700; letter-spacing: .18em;
  color: var(--text); opacity: .12;
  margin-bottom: 10px;
}
.empty p { margin: 0; font-size: 13.5px; }

.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.chat-head .back { display: none; margin-left: -6px; }
.chat-head .peer-ava {
  width: 34px; height: 34px;
  border-radius: 10px;
  object-fit: cover;
  object-position: center 18%;
  background: var(--panel-2);
}
.peer { line-height: 1.25; min-width: 0; }
.peer-name { font-size: 15px; font-weight: 650; }
.peer-status { font-size: 11.5px; color: var(--sub); }
.chat-head .icon-btn { margin-left: auto; }

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
}

.divider {
  align-self: center;
  margin: 14px 0 10px;
  padding: 2px 9px;
  border-radius: 7px;
  background: rgba(125, 135, 150, .12);
  color: var(--sub);
  font-size: 11.5px;
}

.row { display: flex; align-items: flex-start; gap: 8px; margin-top: 8px; }
.row.me { flex-direction: row-reverse; justify-content: flex-start; }

.row .ava {
  width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: 10px;
  object-fit: cover; object-position: center 18%;
  background: var(--panel-2);
}
.row.cont .ava { visibility: hidden; }

.bubbles { display: flex; flex-direction: column; gap: 5px; max-width: min(72%, 560px); }
.row.me .bubbles { align-items: flex-end; }

.bubble {
  padding: 9px 12px;
  border-radius: 4px 13px 13px 13px;
  background: var(--peer);
  color: var(--peer-text);
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  animation: pop .18s ease-out both;
}
.row.me .bubble {
  border-radius: 13px 4px 13px 13px;
  background: var(--me);
  color: var(--me-text);
  box-shadow: none;
}

.cont .bubble { animation: none; }

@keyframes pop {
  from { opacity: 0; transform: translateY(4px) scale(.985); }
  to { opacity: 1; transform: none; }
}

.bubble.pic {
  padding: 0;
  overflow: hidden;
  background: var(--panel-2);
  line-height: 0;
}
.bubble.pic img {
  display: block;
  width: 100%;
  max-width: 340px;
  height: auto;
  border-radius: inherit;
}
.bubble.pic .cap { padding: 6px 10px 8px; font-size: 11.5px; color: var(--sub); line-height: 1.4; }

.note {
  align-self: center;
  margin: 10px 0;
  padding: 6px 12px;
  border-radius: 9px;
  background: rgba(229, 72, 77, .1);
  color: var(--danger);
  font-size: 12.5px;
  max-width: 88%;
  text-align: center;
}

.typing {
  display: inline-flex; gap: 4px; align-items: center;
  padding: 12px 14px;
}
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--sub);
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink {
  0%, 60%, 100% { opacity: .28; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

/* ---------------- 输入区 ---------------- */

.composer {
  display: flex; align-items: flex-end; gap: 9px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.composer textarea {
  flex: 1 1 auto;
  width: 0;
  min-width: 0;
  min-height: 40px;
  max-height: 132px;
  padding: 9px 12px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  line-height: 1.4;
  resize: none;
  outline: 0;
  transition: border-color .15s;
}
.composer textarea:focus { border-color: var(--me); }
.composer textarea::placeholder { color: var(--sub); }

.send {
  flex: 0 0 auto;
  height: 40px;
  padding: 0 18px;
  border-radius: 11px;
  background: var(--me);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  transition: opacity .15s, transform .1s;
}
.send:active { transform: scale(.97); }
.send:disabled { opacity: .45; cursor: default; }

/* ---------------- 底部弹层 ---------------- */

.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 14, 20, .38);
  opacity: 0;
  transition: opacity .2s;
  z-index: 20;
}
.sheet-backdrop.in { opacity: 1; }

.sheet {
  position: fixed;
  left: 50%; bottom: 0;
  width: min(460px, 100%);
  transform: translate(-50%, 100%);
  background: var(--panel);
  border-radius: 16px 16px 0 0;
  z-index: 21;
  transition: transform .24s cubic-bezier(.32, .72, 0, 1);
  padding-bottom: env(safe-area-inset-bottom);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
}
.sheet.in { transform: translate(-50%, 0); }

.sheet-handle {
  width: 36px; height: 4px;
  margin: 9px auto 0;
  border-radius: 2px;
  background: var(--line);
}
.sheet-title {
  padding: 12px 20px 8px;
  font-size: 13px; color: var(--sub);
}
.sheet-body { overflow-y: auto; padding-bottom: 10px; }

.item {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 20px;
  font-size: 15px;
  cursor: pointer;
}
.item:hover { background: var(--hover); }
.item .hint { margin-left: auto; font-size: 12.5px; color: var(--sub); }
.item.danger { color: var(--danger); }
.item .check { margin-left: auto; color: var(--me); font-weight: 700; }

.facts { padding: 4px 20px 12px; }
.facts li {
  margin: 0 0 7px;
  padding-left: 14px;
  position: relative;
  font-size: 13.5px;
  color: var(--text);
  list-style: none;
}
.facts li::before {
  content: '';
  position: absolute; left: 2px; top: 8px;
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--sub);
}
.facts .none { color: var(--sub); font-size: 13px; }

/* ---------------- 移动端 ---------------- */

@media (max-width: 760px) {
  .sidebar {
    width: 100%;
    flex: 1 1 100%;
    border-right: 0;
  }
  .chat { display: none; }

  body.in-chat .sidebar { display: none; }
  body.in-chat .chat { display: flex; }

  .chat-head .back { display: grid; }
  .bubbles { max-width: 78%; }
  .messages { padding: 10px 12px 6px; }
}

/* ---------------- 登录 ---------------- */

.gate {
  position: fixed; inset: 0;
  z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.gate-box {
  width: min(320px, 100%);
  text-align: center;
}

.gate-mark {
  font-size: 30px; font-weight: 700; letter-spacing: .2em;
  margin-bottom: 6px;
}
.gate-sub {
  margin: 0 0 22px;
  font-size: 13.5px;
  color: var(--sub);
}

.gate-box input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  outline: 0;
  text-align: center;
  letter-spacing: .08em;
}
.gate-box input:focus { border-color: var(--me); }

.gate-box button {
  width: 100%;
  height: 44px;
  margin-top: 12px;
  border-radius: 11px;
  background: var(--me);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}
.gate-box button:disabled { opacity: .5; }

.gate-err {
  min-height: 18px;
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--danger);
}
