:root {
  --sea-900: #0b2b40;
  --sea-800: #0f3d5c;
  --sea-700: #14567d;
  --sea-500: #2f8fbf;
  --sea-300: #8fd3ef;
  --bubble-mine: #bfe3f7;
  --bubble-her: #ffffff;
  --page: #eaf2f7;
  --line: #d7e5ee;
  --text: #17303f;
  --muted: #6b8494;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, #e6f2f8 0%, var(--page) 60%, #dfeef7 100%);
  overflow: hidden;
}
.hidden { display: none !important; }

/* ---------- 登录 ---------- */
.login-wrap { height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  border: 1px solid #ffffffaa;
  border-radius: 22px;
  box-shadow: 0 18px 50px rgba(15, 61, 92, 0.18);
  padding: 30px 26px 26px;
  text-align: center;
}
.login-avatar {
  width: 84px; height: 84px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 8px 20px rgba(15, 61, 92, .18);
  object-fit: cover;
}
.login-card h1 { font-size: 22px; margin: 12px 0 4px; letter-spacing: 2px; color: var(--sea-800); }
.login-sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.login-card input {
  width: 100%; margin-bottom: 10px; padding: 12px 14px;
  border-radius: 12px; border: 1px solid var(--line); background: #fff;
  font-size: 15px; outline: none;
}
.login-card input:focus { border-color: var(--sea-500); box-shadow: 0 0 0 3px #2f8fbf22; }
.login-card button {
  width: 100%; padding: 12px; border: 0; border-radius: 12px;
  background: linear-gradient(135deg, var(--sea-700), var(--sea-500));
  color: #fff; font-size: 15px; letter-spacing: 3px; cursor: pointer;
}
.login-card button:disabled { opacity: .6; }
.tip { min-height: 18px; color: #c0392b; font-size: 12px; margin: 10px 0 0; }

/* ---------- 布局 ---------- */
.app { height: 100%; display: grid; grid-template-columns: 280px 1fr; }
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: rgba(255, 255, 255, .78);
  border-right: 1px solid var(--line);
}
.side-head { display: flex; align-items: center; gap: 10px; padding: 16px 14px; }
.side-me .nick { font-weight: 600; font-size: 14px; }
.side-me .status { font-size: 11px; color: var(--muted); }
.avatar { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; background: #dbeaf3; }
.conv-list { padding: 6px; overflow: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 10px; border-radius: 14px; cursor: pointer; }
.conv.active { background: linear-gradient(135deg, #cfe8f7, #e6f4fb); }
.conv-main { min-width: 0; flex: 1; }
.conv-title { font-size: 14px; font-weight: 600; }
.conv-last { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-foot { padding: 12px 14px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px;
  background: rgba(255, 255, 255, .82); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.chat-title { font-size: 15px; font-weight: 600; }
.chat-sub { font-size: 11px; color: var(--muted); }

.messages { flex: 1; overflow-y: auto; padding: 18px 18px 8px; scroll-behavior: smooth; }
.msg { display: flex; gap: 10px; margin-bottom: 14px; align-items: flex-end; }
.msg.mine { flex-direction: row-reverse; }
.msg .avatar { width: 34px; height: 34px; flex: none; }
.bubble {
  max-width: min(66%, 560px); padding: 10px 13px; border-radius: 16px;
  line-height: 1.55; font-size: 15px; word-break: break-word; white-space: pre-wrap;
  box-shadow: 0 2px 6px rgba(15, 61, 92, .05);
}
.msg.her .bubble { background: var(--bubble-her); border-bottom-left-radius: 6px; }
.msg.mine .bubble { background: var(--bubble-mine); border-bottom-right-radius: 6px; }
/* 正文：换行原样保留（pre-wrap），长串不撑破气泡（break-word）。两条缺一条就会要么段落糊成一坨、要么界面被撑爆 */
.bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.bubble img { max-width: 220px; max-height: 260px; border-radius: 10px; display: block; cursor: zoom-in; }
.bubble .file-link { color: var(--sea-700); text-decoration: none; }
.msg-time { text-align: center; font-size: 11px; color: var(--muted); margin: 14px 0 10px; }
.typing { color: var(--muted); font-size: 13px; padding: 0 0 8px 44px; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .9); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none; max-height: 132px; padding: 11px 14px;
  border-radius: 14px; border: 1px solid var(--line); outline: none;
  font-size: 15px; line-height: 1.45; font-family: inherit; background: #fff;
}
.composer textarea:focus { border-color: var(--sea-500); }
.send {
  border: 0; border-radius: 14px; padding: 11px 18px; cursor: pointer;
  background: linear-gradient(135deg, var(--sea-700), var(--sea-500)); color: #fff; font-size: 14px;
}
.send:disabled { opacity: .5; }
.ghost {
  border: 0; background: transparent; color: var(--sea-700);
  font-size: 20px; cursor: pointer; padding: 6px 8px; border-radius: 10px;
}
.ghost:hover { background: #2f8fbf1a; }

.lightbox {
  position: fixed; inset: 0; background: rgba(8, 32, 46, .92);
  display: grid; place-items: center; z-index: 50; padding: 20px; cursor: zoom-out;
}
.lightbox img { max-width: 96vw; max-height: 92vh; border-radius: 8px; }
.only-mobile { display: none; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .app.show-chat .sidebar { display: none; }
  .only-mobile { display: inline-block; }
  .bubble { max-width: 76%; }
  .messages { padding: 14px 12px 6px; }
}

.bubble .hint { color: var(--muted); font-size: 13px; font-style: italic; }


/* 可点击换头像 */
.avatar.pickable {
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.avatar.pickable:hover { transform: scale(1.06); box-shadow: 0 0 0 2px rgba(58,124,165,.45); }
.avatar.pickable:active { transform: scale(.94); }
