/* ============================================================
   夜聊 · 聊天室样式
   ============================================================ */

:root {
  --bg: #f2f1ee;
  --panel: #ffffff;
  --panel-2: #faf9f7;
  --line: rgba(20, 20, 26, 0.08);
  --line-2: rgba(20, 20, 26, 0.14);
  --text: #191a1e;
  --text-2: #6b6c77;
  --text-3: #9b9ca7;
  --accent: #5b5bd6;
  --accent-hover: #4f4fc8;
  --accent-soft: #ecebfb;
  --mine-from: #6a6ae4;
  --mine-to: #5757d2;
  --other-bubble: #ffffff;
  --shadow-sm: 0 1px 2px rgba(20, 20, 26, 0.05);
  --shadow-md: 0 2px 6px rgba(20, 20, 26, 0.06), 0 16px 40px rgba(20, 20, 26, 0.08);
  --radius: 18px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

[data-theme="dark"] {
  --bg: #0e0f12;
  --panel: #16171b;
  --panel-2: #1b1c21;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.15);
  --text: #f1f1f4;
  --text-2: #9b9ca7;
  --text-3: #6d6e79;
  --accent: #7b7bf2;
  --accent-hover: #8b8bf5;
  --accent-soft: #232338;
  --mine-from: #6f6fe8;
  --mine-to: #5a5ad0;
  --other-bubble: #1f2027;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.35), 0 20px 50px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

#app {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* ---------------- Sidebar ---------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 22px 18px 16px;
  background: var(--panel-2);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 4px 20px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(150deg, var(--mine-from), var(--mine-to));
  box-shadow: 0 6px 16px rgba(91, 91, 214, 0.28);
  flex: 0 0 auto;
}

.brand-mark svg { width: 22px; height: 22px; }

.brand-name {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.2px;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 3px;
}

.room-card {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.room-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3ecf8e;
  box-shadow: 0 0 0 3px rgba(62, 207, 142, 0.16);
  flex: 0 0 auto;
}

.room-title { font-size: 14px; font-weight: 620; }

.room-desc {
  margin: 6px 0 12px;
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.5;
}

.room-actions { display: flex; gap: 8px; }

.ghost-btn {
  flex: 1;
  height: 32px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 550;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.ghost-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--line-2); }
.ghost-btn.icon-only { flex: 0 0 32px; display: grid; place-items: center; padding: 0; }

.ghost-btn svg { width: 16px; height: 16px; }

.i-sun { display: block; }
.i-moon { display: none; }
[data-theme="dark"] .i-sun { display: none; }
[data-theme="dark"] .i-moon { display: block; }

.members-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 22px 6px 10px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.9px;
  text-transform: uppercase;
  color: var(--text-3);
}

.members-head .count {
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 999px;
  letter-spacing: 0;
}

.members {
  list-style: none;
  margin: 0;
  padding: 0 2px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  scrollbar-width: thin;
}

.member {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--text-2);
  transition: background 0.15s;
}

.member:hover { background: var(--panel); }
.member.self { color: var(--text); font-weight: 550; }

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 650;
  color: #fff;
  flex: 0 0 auto;
  letter-spacing: 0;
}

.member .tag {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-3);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 1px 5px;
}

.sidebar-foot { padding-top: 12px; border-top: 1px solid var(--line); }

.me-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  transition: background 0.15s;
}

.me-card:hover { background: var(--panel); }

.me-card .avatar { width: 30px; height: 30px; font-size: 12px; }

.me-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.me-name { font-size: 13px; font-weight: 600; color: var(--text); }
.me-hint { font-size: 11px; color: var(--text-3); }

.i-edit { width: 15px; height: 15px; margin-left: auto; color: var(--text-3); flex: 0 0 auto; }

.mode-line {
  margin-top: 6px;
  padding: 7px 9px;
  border-radius: 9px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-3);
  background: transparent;
}

.mode-line.warn { color: #b4741a; background: rgba(240, 173, 78, 0.12); }
[data-theme="dark"] .mode-line.warn { color: #e0a955; }

/* ---------------- Chat ---------------- */

.chat {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 26px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 5;
}

.chat-title h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.1px;
}

.chat-title p {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-title .dot { width: 6px; height: 6px; box-shadow: none; }

.header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.pill {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.pill.demo { background: rgba(240, 173, 78, 0.16); color: #b4741a; }
[data-theme="dark"] .pill.demo { color: #e0a955; }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  display: grid;
  place-items: center;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: var(--panel); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }
.only-mobile { display: none; }

/* -------- messages -------- */

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 22px 26px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar,
.members::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb,
.members::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: 99px;
}

.empty {
  margin: auto;
  text-align: center;
  max-width: 320px;
  padding-bottom: 40px;
  animation: fade-in 0.4s ease both;
}

.empty-icon {
  width: 66px;
  height: 66px;
  margin: 0 auto 16px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
}

.empty-icon svg { width: 34px; height: 34px; }
.empty h2 { margin: 0 0 6px; font-size: 15px; font-weight: 620; }
.empty p { margin: 0; font-size: 13px; color: var(--text-3); line-height: 1.6; }

.time-sep {
  align-self: center;
  margin: 18px 0 12px;
  font-size: 11px;
  color: var(--text-3);
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  border: 1px solid var(--line);
  padding: 3px 10px;
  border-radius: 999px;
}

.msg {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 2px 0;
  max-width: min(680px, 78%);
  animation: rise 0.24s cubic-bezier(0.22, 0.9, 0.3, 1) both;
}

.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg.same { margin-top: 0; }

.msg .avatar {
  width: 30px;
  height: 30px;
  font-size: 12px;
  box-shadow: var(--shadow-sm);
}

.msg.same .avatar { visibility: hidden; height: 0; width: 30px; }

.msg-body { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.msg.mine .msg-body { align-items: flex-end; }

.msg-name {
  font-size: 11.5px;
  color: var(--text-3);
  padding: 0 6px;
  line-height: 1.4;
}

.msg.mine .msg-name { display: none; }
.msg.same .msg-name { display: none; }

.bubble {
  position: relative;
  padding: 9px 13px;
  border-radius: 16px;
  border-bottom-left-radius: 6px;
  background: var(--other-bubble);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg.mine .bubble {
  background: linear-gradient(160deg, var(--mine-from), var(--mine-to));
  border-color: transparent;
  border-radius: 16px;
  border-bottom-right-radius: 6px;
  color: #fff;
  box-shadow: 0 2px 10px rgba(91, 91, 214, 0.24);
}

.msg.same .bubble { border-bottom-left-radius: 16px; border-top-left-radius: 6px; }
.msg.mine.same .bubble { border-bottom-right-radius: 16px; border-top-right-radius: 6px; }

.bubble time {
  display: inline-block;
  margin-left: 8px;
  font-size: 10px;
  opacity: 0.55;
  vertical-align: bottom;
  white-space: nowrap;
}

.msg.mine .bubble time { opacity: 0.72; }

.sys {
  align-self: center;
  margin: 8px 0;
  font-size: 11.5px;
  color: var(--text-3);
  text-align: center;
  max-width: 80%;
}

.jump-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 118px;
  z-index: 6;
  border: 1px solid var(--line-2);
  background: var(--panel);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  animation: rise 0.2s ease both;
}

.typing {
  height: 18px;
  padding: 0 28px;
  font-size: 11.5px;
  color: var(--text-3);
  opacity: 0;
  transition: opacity 0.2s;
}

.typing.on { opacity: 1; }

/* -------- composer -------- */

.composer {
  position: relative;
  padding: 4px 20px 14px;
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 10px 10px 16px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow-md);
  transition: border-color 0.18s, box-shadow 0.18s;
}

.composer-box:focus-within {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 10%, transparent), var(--shadow-md);
}

#input {
  flex: 1;
  min-height: 24px;
  max-height: 132px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  padding: 4px 0;
}

#input::placeholder { color: var(--text-3); }

.composer-tools { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }

.send-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(160deg, var(--mine-from), var(--mine-to));
  transition: transform 0.14s, opacity 0.18s, box-shadow 0.18s;
  box-shadow: 0 4px 12px rgba(91, 91, 214, 0.3);
}

.send-btn svg { width: 18px; height: 18px; }
.send-btn:disabled { opacity: 0.36; cursor: default; box-shadow: none; }
.send-btn:not(:disabled):hover { transform: translateY(-1px); }
.send-btn:not(:disabled):active { transform: scale(0.95); }

.composer-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 8px 6px 0;
  font-size: 11px;
  color: var(--text-3);
}

.retain-note {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.hint-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  white-space: nowrap;
}

.counter {
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
  transition: color 0.15s;
}

.counter.near { color: #b4741a; }
.counter.full { color: #d0453a; font-weight: 650; }
[data-theme="dark"] .counter.near { color: #e0a955; }
[data-theme="dark"] .counter.full { color: #f07a6d; }

kbd {
  font-family: inherit;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid var(--line-2);
  background: var(--panel);
}

.emoji-panel {
  position: absolute;
  right: 20px;
  bottom: 104px;
  width: 264px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
  z-index: 10;
  animation: rise 0.16s ease both;
}

.emoji-panel button {
  border: 0;
  background: transparent;
  font-size: 19px;
  line-height: 1;
  padding: 6px 0;
  border-radius: 8px;
  transition: background 0.12s, transform 0.12s;
}

.emoji-panel button:hover { background: var(--accent-soft); transform: scale(1.12); }

/* ---------------- Modal ---------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 12, 16, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in 0.2s ease both;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  padding: 28px 24px 22px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(12, 12, 16, 0.3);
  text-align: center;
  animation: pop 0.26s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}

.modal-emoji { font-size: 34px; margin-bottom: 6px; }
.modal-card h2 { margin: 0 0 6px; font-size: 18px; font-weight: 650; }
.modal-sub { margin: 0 0 18px; font-size: 12.5px; color: var(--text-3); line-height: 1.6; }

#nameInput {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  text-align: center;
  outline: 0;
  transition: border-color 0.16s, box-shadow 0.16s;
}

#nameInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 12%, transparent);
}

.name-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  padding: 8px 4px;
  border-radius: 8px;
}

.link-btn:hover { color: var(--accent); }

.primary-btn {
  flex: 1;
  height: 44px;
  border: 0;
  border-radius: 14px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  background: linear-gradient(160deg, var(--mine-from), var(--mine-to));
  box-shadow: 0 8px 20px rgba(91, 91, 214, 0.28);
  transition: transform 0.14s, opacity 0.16s;
}

.primary-btn:hover { transform: translateY(-1px); }
.primary-btn:active { transform: scale(0.98); }

/* ---------------- Toasts ---------------- */

.toast-wrap {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border-radius: 12px;
  background: #22232a;
  color: #fff;
  font-size: 12.5px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
  animation: rise 0.22s ease both;
  max-width: 78vw;
  text-align: center;
}

[data-theme="dark"] .toast { background: #2c2d36; }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(12, 12, 16, 0.34);
  animation: fade-in 0.18s ease both;
}

/* ---------------- Animations ---------------- */

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

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pop {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ---------------- Responsive ---------------- */

@media (max-width: 860px) {
  #app { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 286px;
    z-index: 30;
    transform: translateX(-102%);
    transition: transform 0.26s cubic-bezier(0.22, 0.9, 0.3, 1);
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.18);
  }

  .sidebar.open { transform: translateX(0); }
  .only-mobile { display: grid; }
  .chat-header { padding: 12px 16px; gap: 6px; }
  .messages { padding: 16px 14px 8px; }
  .msg { max-width: 88%; }
  .composer { padding: 2px 12px 10px; }
  .composer-hint { margin: 6px 4px 0; }
  .composer-hint kbd, .retain-note { display: none; }
  .hint-right { margin-left: auto; }
  .emoji-panel { right: 12px; bottom: 92px; width: calc(100vw - 24px); max-width: 300px; }
  .jump-btn { bottom: 96px; }
  .header-right { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .messages { scroll-behavior: auto; }
}
