/* =========================================================
   灵聊 LingChat — 样式
   移动优先，同时适配桌面；浅色主题
   ========================================================= */

:root {
  --brand: #6366f1;
  --brand-2: #a855f7;
  --brand-dark: #4f46e5;
  --grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 55%, #a855f7 100%);

  --bg: #f5f6fb;
  --bg-chat: #eef0f8;
  --panel: #ffffff;
  --panel-2: #f7f8fc;
  --line: #e6e8f0;
  --line-soft: #eff1f7;

  --text: #1c1f2b;
  --text-2: #5a6076;
  --text-3: #9aa0b5;

  --bubble-me: var(--grad);
  --bubble-other: #ffffff;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(28, 31, 43, .06);
  --shadow: 0 6px 20px rgba(28, 31, 43, .08);
  --shadow-lg: 0 16px 48px rgba(28, 31, 43, .16);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* ⚠️ 关键规则，别删：
   作者样式里的 display（.drawer{display:flex}、.modal-mask{display:grid}、
   .jump-btn{display:inline-flex}）优先级高于浏览器默认的 [hidden]{display:none}，
   所以带 hidden 属性的抽屉 / 弹窗会一直显示、全屏盖住页面，导致输入框点不动、发不出消息。
   必须在这里显式兜住。 */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior: none;
}

body { overflow: hidden; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }

/* ================= 整体布局 ================= */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  max-width: 820px;
  margin: 0 auto;
  background: var(--bg-chat);
  position: relative;
  box-shadow: 0 0 0 1px rgba(28,31,43,.05);
}

@media (min-width: 900px) {
  body { background: #e9ebf5; }
  .app { height: 100vh; border-radius: 0; }
}

/* ================= 顶栏 ================= */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-t)) 12px 10px;
  background: var(--grad);
  color: #fff;
  box-shadow: 0 2px 12px rgba(99, 102, 241, .28);
  z-index: 20;
}

.topbar-title { flex: 1 1 auto; min-width: 0; text-align: center; }

.room-name {
  font-size: 16.5px;
  font-weight: 650;
  letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.room-sub {
  display: flex; align-items: center; justify-content: center;
  gap: 5px;
  font-size: 11.5px;
  opacity: .92;
  margin-top: 1px;
}

.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #fbbf24;
  box-shadow: 0 0 0 2px rgba(255,255,255,.35);
  transition: background .25s;
}
.dot.online { background: #4ade80; }
.dot.offline { background: #f87171; }

.icon-btn {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 0; border-radius: 12px;
  background: rgba(255,255,255,.16);
  color: #fff;
  cursor: pointer;
  transition: background .18s, transform .12s;
}
.icon-btn:hover { background: rgba(255,255,255,.28); }
.icon-btn:active { transform: scale(.93); }

/* ================= 消息区 ================= */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.empty-hint {
  margin: auto;
  text-align: center;
  color: var(--text-3);
  padding: 40px 20px;
}
.empty-emoji { font-size: 44px; line-height: 1; margin-bottom: 10px; }
.empty-hint p { margin: 4px 0; }

/* 系统消息 */
.sys {
  align-self: center;
  max-width: 88%;
  font-size: 12px;
  color: var(--text-3);
  background: rgba(255,255,255,.72);
  border: 1px solid var(--line-soft);
  padding: 3px 12px;
  border-radius: 999px;
  text-align: center;
}

/* 日期分隔 */
.day-sep {
  align-self: center;
  font-size: 11.5px;
  color: var(--text-3);
  background: rgba(255,255,255,.7);
  padding: 2px 10px;
  border-radius: 999px;
  margin: 6px 0 2px;
}

/* 消息行 */
.row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  animation: pop .22s cubic-bezier(.2,.9,.3,1.2);
}
.row.me { flex-direction: row-reverse; }

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.avatar {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 13px;
  font-weight: 650;
  color: #fff;
  background: var(--grad);
  user-select: none;
  box-shadow: var(--shadow-sm);
}
.row.me .avatar { display: none; }

.bubble-wrap { display: flex; flex-direction: column; max-width: min(78%, 520px); }
.row.me .bubble-wrap { align-items: flex-end; }

.who {
  font-size: 11.5px;
  color: var(--text-3);
  margin: 0 0 3px 4px;
}
.row.me .who { display: none; }

.bubble {
  padding: 9px 13px;
  border-radius: var(--radius);
  background: var(--bubble-other);
  box-shadow: var(--shadow-sm);
  word-break: break-word;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.row:not(.me) .bubble { border-bottom-left-radius: 5px; }

.row.me .bubble {
  background: var(--bubble-me);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 3px 12px rgba(99,102,241,.28);
}

.bubble a { color: var(--brand-dark); text-decoration: underline; word-break: break-all; }
.row.me .bubble a { color: #fff; }

.bubble.pending { opacity: .62; }

.meta {
  font-size: 10.5px;
  color: var(--text-3);
  margin: 3px 4px 0;
  display: flex; gap: 5px; align-items: center;
}
.row.me .meta { justify-content: flex-end; }
.tick { color: var(--brand); font-size: 10px; }

/* 正在输入 */
.typing-bubble { display: inline-flex; gap: 4px; align-items: center; padding: 11px 14px; }
.typing-bubble i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-3);
  animation: blink 1.3s infinite;
}
.typing-bubble i:nth-child(2) { animation-delay: .18s; }
.typing-bubble i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,60%,100% { opacity:.3; transform: translateY(0); } 30% { opacity:1; transform: translateY(-3px); } }

/* 回到底部 */
.jump-btn {
  position: absolute;
  right: 16px;
  bottom: calc(96px + var(--safe-b));
  z-index: 15;
  display: inline-flex; align-items: center; gap: 5px;
  border: 0; cursor: pointer;
  background: var(--panel);
  color: var(--brand);
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: pop .2s;
}

/* ================= 输入区 ================= */
.composer {
  flex: 0 0 auto;
  padding: 8px 10px calc(8px + var(--safe-b));
  background: var(--panel);
  border-top: 1px solid var(--line);
  z-index: 20;
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--panel-2);
  border: 1.5px solid var(--line);
  border-radius: 20px;
  padding: 5px 5px 5px 14px;
  transition: border-color .18s, box-shadow .18s;
}
.composer-inner:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(99,102,241,.13);
}

#input {
  flex: 1 1 auto;
  border: 0; outline: 0;
  background: transparent;
  resize: none;
  font: inherit;
  color: var(--text);
  padding: 8px 0;
  max-height: 132px;
  line-height: 1.45;
}
#input::placeholder { color: var(--text-3); }

.send-btn {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border: 0; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--grad);
  color: #fff;
  cursor: pointer;
  transition: transform .12s, opacity .18s, filter .18s;
  box-shadow: 0 3px 10px rgba(99,102,241,.35);
}
.send-btn:active { transform: scale(.9); }
.send-btn:disabled { opacity: .4; filter: grayscale(.5); box-shadow: none; cursor: default; }

.composer-meta {
  display: flex; justify-content: space-between; align-items: center;
  min-height: 15px;
  padding: 3px 6px 0;
  font-size: 11px;
  color: var(--text-3);
}
.typing-hint { color: var(--brand); }
.me-hint { color: var(--text-3); white-space: nowrap; }

/* ================= 抽屉 ================= */
.drawer-mask {
  position: fixed; inset: 0;
  background: rgba(20, 22, 34, .42);
  backdrop-filter: blur(2px);
  z-index: 40;
  animation: fade .18s;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(84vw, 330px);
  background: var(--panel);
  z-index: 50;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideIn .24s cubic-bezier(.2,.9,.3,1);
  padding-top: var(--safe-t);
  overflow: hidden;
}
@keyframes slideIn { from { transform: translateX(-100%); } to { transform: none; } }

.drawer-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--grad);
  color: #fff;
}
.drawer-me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; cursor: pointer; }
.drawer-me .avatar { background: rgba(255,255,255,.24); }
.drawer-me-name { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-head .muted { color: rgba(255,255,255,.8); }

.drawer-section { padding: 14px 14px 4px; }
.drawer-label {
  font-size: 11.5px; font-weight: 700; letter-spacing: .6px;
  color: var(--text-3); text-transform: uppercase;
  margin-bottom: 8px;
}

.room-list { display: flex; flex-direction: column; gap: 4px; max-height: 190px; overflow-y: auto; }

.room-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s;
}
.room-item:hover { background: var(--panel-2); }
.room-item.active { background: rgba(99,102,241,.09); border-color: rgba(99,102,241,.28); }
.room-item .rname { flex: 1; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-item .rcount { font-size: 11.5px; color: var(--text-3); }
.room-item .rdot { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; flex: 0 0 auto; }
.room-item .rdot.zero { background: #d5d8e4; }

.join-row { display: flex; gap: 6px; margin-top: 9px; }
.join-row input {
  flex: 1; min-width: 0;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 11px; font: inherit; font-size: 13.5px;
  outline: 0; background: var(--panel-2); color: var(--text);
}
.join-row input:focus { border-color: var(--brand); background: #fff; }

.mini-btn {
  border: 0; border-radius: var(--radius-sm);
  background: var(--grad); color: #fff;
  padding: 0 14px; font: inherit; font-size: 13.5px; font-weight: 600;
  cursor: pointer;
}
.mini-btn:active { transform: scale(.96); }

.member-list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 160px; overflow-y: auto; }
.member-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 4px 11px 4px 5px;
  font-size: 12.5px;
  max-width: 100%;
}
.member-chip .avatar { width: 22px; height: 22px; border-radius: 7px; font-size: 10px; }
.member-chip.off { opacity: .5; }
.member-chip .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.drawer-foot {
  margin-top: auto;
  padding: 12px 14px calc(14px + var(--safe-b));
  border-top: 1px solid var(--line-soft);
  display: flex; flex-direction: column; gap: 8px;
}

/* ================= 按钮 ================= */
.ghost-btn, .primary-btn {
  border: 0; border-radius: var(--radius-sm);
  padding: 10px 16px;
  font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: transform .12s, background .15s;
}
.ghost-btn { background: var(--panel-2); color: var(--text-2); border: 1px solid var(--line); }
.ghost-btn:hover { background: #eef0f8; }
.primary-btn { background: var(--grad); color: #fff; }
.primary-btn:active, .ghost-btn:active { transform: scale(.97); }

/* ================= 弹窗 ================= */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(20,22,34,.45);
  backdrop-filter: blur(3px);
  z-index: 60;
  display: grid; place-items: center;
  padding: 20px;
  animation: fade .16s;
}
.modal {
  width: min(94vw, 380px);
  background: var(--panel);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  animation: popIn .2s cubic-bezier(.2,.9,.3,1.15);
}
@keyframes popIn { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }

.modal h3 { margin: 0 0 4px; font-size: 17px; }
.modal p { margin: 0 0 14px; }

.modal input[type=text] {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font: inherit;
  outline: 0;
  background: var(--panel-2);
  color: var(--text);
}
.modal input[type=text]:focus { border-color: var(--brand); background: #fff; }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  font-size: 14.5px;
}
.switch-row input { width: 42px; height: 24px; accent-color: var(--brand); cursor: pointer; }
.divider { height: 1px; background: var(--line-soft); margin: 12px 0; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-size: 13.5px; }
.kv b { max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ================= Toast ================= */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(120px + var(--safe-b));
  transform: translateX(-50%);
  background: rgba(28,31,43,.92);
  color: #fff;
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  z-index: 90;
  animation: pop .2s;
  max-width: 86vw;
  text-align: center;
}

/* 滚动条 */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-thumb { background: #cfd3e2; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #b6bbd0; }
::-webkit-scrollbar-track { background: transparent; }
