/* ══════════════════════════════════════════════════════
   星讯 · 聊天客户端样式
   ══════════════════════════════════════════════════════ */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --line: #e4e7f0;
  --text: #1a1d29;
  --text-2: #6b7280;
  --text-3: #9aa1ae;
  --brand: #5b5bd6;
  --brand-2: #7c3aed;
  --brand-soft: #eeeeff;
  --mine-1: #5b5bd6;
  --mine-2: #7c3aed;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 45, .06), 0 1px 3px rgba(20, 24, 45, .04);
  --shadow-md: 0 4px 16px rgba(20, 24, 45, .08);
  --shadow-lg: 0 18px 48px rgba(20, 24, 45, .16);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1017;
    --surface: #171a24;
    --surface-2: #1f2331;
    --line: #272c3b;
    --text: #e8ebf4;
    --text-2: #98a0b3;
    --text-3: #6c7488;
    --brand: #7b7bf0;
    --brand-2: #a78bfa;
    --brand-soft: #21213a;
    --danger: #f87171;
    --ok: #4ade80;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .35);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
[hidden] { display: none !important; }

/* ────────────────── 登录页 ────────────────── */

.auth {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 20%, rgba(124, 58, 237, .10), transparent 45%),
    radial-gradient(circle at 85% 78%, rgba(91, 91, 214, .10), transparent 45%),
    var(--bg);
}

.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px 28px 26px;
  box-shadow: var(--shadow-lg);
}

.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }

.brand-mark {
  width: 46px; height: 46px; flex: none;
  border-radius: 13px;
  display: grid; place-items: center;
  font-size: 21px; font-weight: 600; color: #fff;
  background: linear-gradient(140deg, var(--brand), var(--brand-2));
  box-shadow: 0 6px 18px rgba(91, 91, 214, .34);
}

.brand h1 { font-size: 20px; font-weight: 650; letter-spacing: .3px; }
.brand-sub { font-size: 12.5px; color: var(--text-3); margin-top: 1px; }

.seg {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface-2);
  border-radius: 11px;
  margin-bottom: 20px;
}

.seg-btn {
  flex: 1; padding: 8px; border-radius: 8px;
  font-size: 13.5px; font-weight: 550; color: var(--text-2);
  transition: .18s;
}
.seg-btn.is-on {
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-sm);
}

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; font-size: 12px; font-weight: 550;
  color: var(--text-2); margin-bottom: 6px;
}
.field input {
  width: 100%; padding: 11px 13px;
  background: var(--surface-2);
  border: 1.5px solid transparent;
  border-radius: 10px;
  outline: none;
  transition: .18s;
}
.field input:focus {
  background: var(--surface);
  border-color: var(--brand);
  box-shadow: 0 0 0 3.5px rgba(91, 91, 214, .12);
}
.field input::placeholder { color: var(--text-3); }

.form-error {
  min-height: 16px; font-size: 12.5px; line-height: 16px;
  color: var(--danger);
  margin-bottom: 6px;
}

.btn-primary {
  width: 100%; padding: 12px;
  border-radius: 10px;
  font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 6px 18px rgba(91, 91, 214, .3);
  transition: .18s;
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }

.auth-note {
  margin-top: 18px; text-align: center;
  font-size: 12px; color: var(--text-3);
}

/* ────────────────── 主布局 ────────────────── */

.app {
  height: 100%;
  display: flex;
  background: var(--bg);
}

.sidebar {
  width: 312px; flex: none;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.side-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px 10px;
}

.avatar {
  width: 36px; height: 36px; flex: none;
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 600; color: #fff;
  background: linear-gradient(140deg, var(--brand), var(--brand-2));
  letter-spacing: .5px;
}

.side-me { flex: 1; min-width: 0; }
.side-me strong {
  display: block; font-size: 13.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.conn {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--text-3);
}
.conn i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-3); transition: .2s;
}
.conn em { font-style: normal; }
.conn.is-on i { background: var(--ok); box-shadow: 0 0 0 3px rgba(22, 163, 74, .15); }
.conn.is-off i { background: var(--danger); }

.icon-btn {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px; color: var(--text-2);
  transition: .16s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.search-wrap { padding: 4px 14px 10px; }
#conv-search {
  width: 100%; padding: 8px 12px;
  background: var(--surface-2);
  border: none; border-radius: 9px; outline: none;
  font-size: 13px;
}
#conv-search::placeholder { color: var(--text-3); }

.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }

.conv-item {
  display: flex; gap: 10px; align-items: center;
  padding: 10px; border-radius: 11px;
  cursor: pointer; transition: .14s;
  margin-bottom: 2px;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.is-active { background: var(--brand-soft); }

.conv-ava {
  width: 40px; height: 40px; flex: none;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 600; color: #fff;
  position: relative;
}
.conv-ava .dot {
  position: absolute; right: -2px; bottom: -2px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--ok);
  border: 2.5px solid var(--surface);
}

.conv-body { flex: 1; min-width: 0; }
.conv-top {
  display: flex; align-items: baseline; gap: 8px;
}
.conv-title {
  font-size: 13.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-time { margin-left: auto; font-size: 10.5px; color: var(--text-3); flex: none; }
.conv-preview {
  font-size: 12.5px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 1px;
}

.badge {
  flex: none; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px;
  background: var(--brand); color: #fff;
  font-size: 10.5px; font-weight: 600;
  display: grid; place-items: center;
}

.list-empty {
  padding: 40px 20px; text-align: center;
  font-size: 12.5px; color: var(--text-3); line-height: 1.9;
}

/* ────────────────── 聊天区 ────────────────── */

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.chat-empty {
  flex: 1; display: grid; place-content: center; justify-items: center;
  gap: 6px; text-align: center; padding: 24px;
}
.empty-art {
  color: var(--text-3);
  opacity: .5;
  margin-bottom: 8px;
}
.chat-empty h2 { font-size: 15px; font-weight: 600; color: var(--text-2); }
.chat-empty p { font-size: 12.5px; color: var(--text-3); }
.chat-empty b { color: var(--brand); }

.chat-main { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-head {
  display: flex; align-items: center; gap: 6px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  min-height: 58px;
}

.back-btn { display: none; }

.chat-peer { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.chat-peer strong { display: block; font-size: 14px; font-weight: 620; }
.peer-status { font-size: 11.5px; color: var(--text-3); line-height: 1.4; }
.peer-status.is-on { color: var(--ok); }

.msg-scroll {
  flex: 1; overflow-y: auto;
  padding: 18px;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
}

/* 消息不足一屏时贴底显示，符合聊天软件习惯；
   超过一屏时 margin 自动归零，滚动正常 */
.msg-inner {
  margin-top: auto;
  display: flex;
  flex-direction: column;
}

.load-more { text-align: center; margin-bottom: 14px; }
.load-more button {
  font-size: 12px; color: var(--brand);
  padding: 5px 14px; border-radius: 20px;
  background: var(--brand-soft);
  transition: .16s;
}
.load-more button:hover { filter: brightness(.96); }

#msg-list { display: flex; flex-direction: column; gap: 3px; }

.day-sep {
  align-self: center;
  font-size: 11px; color: var(--text-3);
  padding: 10px 0 8px;
}

.msg { display: flex; gap: 8px; max-width: min(74%, 560px); }
.msg.is-mine { align-self: flex-end; flex-direction: row-reverse; }

.msg-ava {
  width: 30px; height: 30px; flex: none;
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600; color: #fff;
  align-self: flex-end;
}

.bubble {
  padding: 8px 12px;
  border-radius: 13px;
  font-size: 13.5px;
  word-break: break-word;
  white-space: pre-wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  border-bottom-left-radius: 5px;
}
.msg.is-mine .bubble {
  background: linear-gradient(135deg, var(--mine-1), var(--mine-2));
  color: #fff; border-color: transparent;
  border-bottom-left-radius: 13px;
  border-bottom-right-radius: 5px;
  box-shadow: 0 3px 12px rgba(91, 91, 214, .26);
}

.msg.is-failed .bubble { opacity: .6; box-shadow: 0 0 0 1.5px var(--danger); }
.msg-meta {
  font-size: 10px; color: var(--danger);
  margin-top: 3px; text-align: right;
}

/* 文件卡片 */
.file-card {
  display: flex; align-items: center; gap: 10px;
  min-width: 200px;
  text-decoration: none; color: inherit;
}
.file-icon {
  width: 34px; height: 34px; flex: none;
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 15px;
  background: rgba(255, 255, 255, .2);
}
.msg:not(.is-mine) .file-icon { background: var(--brand-soft); }
.file-info { min-width: 0; }
.file-name {
  font-size: 13px; font-weight: 550;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 190px;
}
.file-size { font-size: 10.5px; opacity: .7; }

.bubble.is-image { padding: 4px; background: var(--surface-2); }
.msg.is-mine .bubble.is-image {
  background: linear-gradient(135deg, var(--mine-1), var(--mine-2));
}
.bubble.is-image img {
  display: block; max-width: 240px; max-height: 260px;
  border-radius: 10px; object-fit: cover;
}

/* 输入区 */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 132px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1.5px solid transparent;
  border-radius: 12px;
  outline: none;
  line-height: 1.5;
  transition: .16s;
}
.composer textarea:focus {
  background: var(--surface);
  border-color: var(--brand);
}
.composer textarea::placeholder { color: var(--text-3); font-size: 13px; }

.attach { margin-bottom: 4px; }

.btn-send {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border-radius: 11px; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 4px 12px rgba(91, 91, 214, .3);
  transition: .16s;
  margin-bottom: 2px;
}
.btn-send:hover { filter: brightness(1.08); }
.btn-send:active { transform: scale(.94); }
.btn-send:disabled { opacity: .4; box-shadow: none; cursor: not-allowed; }

/* ────────────────── 弹窗 ────────────────── */

.modal {
  position: fixed; inset: 0;
  background: rgba(12, 15, 28, .42);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: 20px; z-index: 40;
}

.modal-card {
  width: min(400px, 100%);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 16px;
  max-height: min(560px, 82vh);
  display: flex; flex-direction: column;
}
.modal-card > header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.modal-card h3 { font-size: 15px; font-weight: 620; }
.modal-card > input {
  padding: 10px 13px;
  background: var(--surface-2);
  border: 1.5px solid transparent;
  border-radius: 10px; outline: none;
}
.modal-card > input:focus { border-color: var(--brand); background: var(--surface); }

.search-result { margin-top: 10px; overflow-y: auto; }
.search-result .hint {
  padding: 20px 0; text-align: center;
  font-size: 12.5px; color: var(--text-3);
}

.user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 8px; border-radius: 10px;
  cursor: pointer; transition: .14s;
}
.user-row:hover { background: var(--surface-2); }
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13.5px; font-weight: 550; }
.user-id { font-size: 11.5px; color: var(--text-3); }
.user-go { font-size: 12px; color: var(--brand); font-weight: 550; }

/* ────────────────── 上传条 / Toast ────────────────── */

.upload-bar {
  position: fixed; left: 50%; bottom: 18px;
  transform: translateX(-50%);
  width: min(320px, 82vw);
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  z-index: 50;
}
#upload-text { font-size: 12px; color: var(--text-2); }
.upload-bar .bar {
  height: 4px; margin-top: 7px;
  background: var(--surface-2);
  border-radius: 2px; overflow: hidden;
}
.upload-bar .bar i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  border-radius: 2px;
  transition: width .2s;
}

.toast {
  position: fixed; top: 18px; left: 50%;
  transform: translateX(-50%);
  padding: 9px 18px;
  background: var(--text);
  color: var(--bg);
  border-radius: 10px;
  font-size: 12.5px;
  box-shadow: var(--shadow-md);
  z-index: 60;
  animation: slide-down .22s ease;
}
@keyframes slide-down {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ────────────────── 滚动条 ────────────────── */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 4px;
  border: 2px solid transparent; background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--text-3); }

/* ────────────────── 移动端 ────────────────── */

@media (max-width: 760px) {
  .sidebar { width: 100%; border-right: none; }

  .app.is-chatting .sidebar { display: none; }
  .app.is-chatting .chat { display: flex; }

  .chat { display: none; }
  .app:not(.is-chatting) .chat { display: none; }

  .back-btn { display: grid; place-items: center; }

  .chat-head { padding: 10px 12px; }
  .msg-scroll { padding: 14px 12px; }
  .msg { max-width: 84%; }
  .composer { padding: 10px 12px; }

  .auth { padding: 16px; }
  .auth-card { padding: 26px 22px 22px; }
}
