/* style.css —— 页面样式（纯 CSS，没有框架依赖） */

/* CSS 变量：颜色集中定义，改主题只改这里 */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #8b95a7;
  --line: #e8ecf3;
  --primary: #3b6df6;
  --primary-dark: #2d57d1;
  --bubble: #f1f4f9;
  --shadow: 0 18px 50px rgba(31, 41, 55, .08);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

/* 整个聊天窗口 */
.app {
  width: min(860px, 100%);
  height: min(760px, calc(100vh - 40px));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 顶部栏 */
.topbar {
  flex: none;
  height: 78px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: 12px; }

.logo {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #5b8cff, #3b6df6);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 19px;
  font-weight: 700;
}

.brand h1 { margin: 0; font-size: 17px; }
.brand p  { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

.status {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--muted);
  background: #f6f8fc;
  padding: 7px 12px;
  border-radius: 999px;
}

.pulse {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, .15);
}

.status.error .pulse { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, .15); }

/* 消息区域：唯一可以滚动的部分 */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 24px;
  scroll-behavior: smooth;
}

.empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
}

/* 单条消息 */
.msg {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  animation: fade .18s ease-out;
}

@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 自己发的消息：整体反向排列，气泡靠右 */
.msg.mine { flex-direction: row-reverse; }
.msg.mine .body { align-items: flex-end; }

.avatar {
  flex: none;
  width: 36px; height: 36px;
  border-radius: 11px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  display: grid;
  place-items: center;
  user-select: none;
}

.body {
  max-width: min(72%, 560px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}

.head { display: flex; align-items: center; gap: 8px; padding: 0 3px; }
.name { font-size: 12px; font-weight: 600; color: #4b5563; }
.head time { font-size: 11px; color: var(--muted); }

.bubble {
  background: var(--bubble);
  padding: 10px 14px;
  border-radius: 4px 14px 14px 14px;
  font-size: 14px;
  line-height: 1.65;
  /* 关键：允许长英文/链接换行，否则会把布局撑破 */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.mine .bubble {
  background: var(--primary);
  color: #fff;
  border-radius: 14px 4px 14px 14px;
}

/* 底部输入区 */
.composer {
  flex: none;
  border-top: 1px solid var(--line);
  padding: 16px 24px 18px;
}

.nick-field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--muted);
}

.nick-field input {
  width: 190px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 13px;
  color: var(--text);
  outline: none;
}

.nick-field input:focus,
.input-row textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 109, 246, .1);
}

.input-row { display: flex; gap: 10px; align-items: flex-end; }

.input-row textarea {
  flex: 1;
  min-height: 46px;
  max-height: 130px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 13px 14px;
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  outline: none;
}

.input-row button {
  flex: none;
  height: 46px;
  padding: 0 26px;
  border: 0;
  border-radius: 11px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

.input-row button:hover:not(:disabled) { background: var(--primary-dark); }
.input-row button:disabled { opacity: .55; cursor: not-allowed; }

.meta {
  display: flex;
  justify-content: space-between;
  margin-top: 9px;
  font-size: 11px;
  color: var(--muted);
}

/* 手机上铺满屏幕 */
@media (max-width: 640px) {
  body { padding: 0; }
  .app { height: 100dvh; border-radius: 0; border: 0; }
  .topbar { height: 66px; padding: 0 16px; }
  .messages { padding: 16px; }
  .composer { padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); }
  .body { max-width: 80%; }
}
