/* 孙哥的服务器 · 网页聊天室 */
:root {
  --bg: #0b0f14;
  --bg-soft: #0f151d;
  --panel: #151c25;
  --panel-2: #1b2430;
  --line: #25303d;
  --line-soft: rgba(255, 255, 255, .06);
  --text: #e6edf6;
  --muted: #8695a9;
  --accent: #4ade80;
  --accent-deep: #22c55e;
  --accent-soft: rgba(74, 222, 128, .12);
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
p { margin: 0; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 登录 ---------- */
.login-view {
  position: relative;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 32px 20px;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(74, 222, 128, .16), transparent 46%),
    radial-gradient(circle at 84% 84%, rgba(56, 189, 248, .12), transparent 42%),
    linear-gradient(180deg, #090d12, #0d1117 55%, #0a0e13);
}

.login-view::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .035) 1px, transparent 1px);
  background-size: 46px 46px;
  -webkit-mask-image: radial-gradient(circle at 50% 44%, #000 28%, transparent 74%);
  mask-image: radial-gradient(circle at 50% 44%, #000 28%, transparent 74%);
  pointer-events: none;
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(400px, 100%);
  padding: 30px 28px 26px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(20, 27, 36, .86);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

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

.brand-badge {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 13px;
  background: linear-gradient(150deg, #6ee7a0, #22c55e 60%, #15803d);
  color: #06240f;
  font: 800 17px/1 ui-monospace, "SFMono-Regular", Consolas, monospace;
  letter-spacing: .04em;
  box-shadow: 0 10px 24px rgba(34, 197, 94, .32), inset 0 1px 0 rgba(255, 255, 255, .4);
  flex: none;
}
.brand-badge.small { width: 42px; height: 42px; border-radius: 11px; font-size: 13px; }

.brand-text h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .01em;
}
.brand-text p {
  margin-top: 2px;
  font-size: 13px;
  color: var(--muted);
}

.login-form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field span { font-size: 13px; color: var(--muted); }
.field input {
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #0d131a;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.field input::placeholder { color: #5c6a7d; }
.field input:hover { border-color: #344252; }
.field input:focus {
  border-color: var(--accent-deep);
  background: #0b1117;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, .16);
}

.btn-primary {
  height: 47px;
  margin-top: 6px;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(180deg, #5ce68d, #22c55e);
  color: #06240f;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .02em;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(34, 197, 94, .24);
  transition: transform .12s, filter .15s;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .7; cursor: default; transform: none; }

.login-error {
  min-height: 20px;
  font-size: 13px;
  color: var(--danger);
  text-align: center;
}

.login-hint {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
}
.login-hint strong { color: #a9e8c0; font-weight: 600; }

.login-foot {
  position: relative;
  z-index: 1;
  font-size: 12px;
  color: #566273;
}

/* ---------- 布局 ---------- */
.chat-view {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px 14px 14px;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
}

.server-card {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 10px 14px;
}
.server-text h2 { font-size: 15.5px; font-weight: 700; }
.conn-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--muted);
}
.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: 0 0 8px currentColor;
  flex: none;
}
.conn-dot.online { background: var(--accent); }
.conn-dot.offline { background: var(--danger); }
.conn-dot.connecting { animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: .3; } }

.online-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 6px 8px;
  font-size: 11.5px;
  letter-spacing: .06em;
  color: var(--muted);
  text-transform: uppercase;
}
.online-head b {
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  color: #b7e9c9;
  background: var(--accent-soft);
}

.online-list {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0 2px;
  list-style: none;
  overflow-y: auto;
}
.online-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 10px;
  font-size: 14px;
  color: #d3deea;
  transition: background .12s;
}
.online-item:hover { background: rgba(255, 255, 255, .04); }
.online-item .online-dot {
  width: 7px;
  height: 7px;
  margin-left: auto;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px rgba(74, 222, 128, .7);
}
.online-empty {
  padding: 14px 10px;
  font-size: 13px;
  color: #5f6c7e;
}

.avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: #2c3a4a;
  text-transform: uppercase;
  flex: none;
  user-select: none;
}
.avatar.small { width: 32px; height: 32px; border-radius: 9px; font-size: 13px; }
.avatar.tiny { width: 28px; height: 28px; border-radius: 8px; font-size: 12px; }

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 10px 8px 2px;
  border-top: 1px solid var(--line);
}
.self { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1; }
.self-text { display: flex; flex-direction: column; min-width: 0; }
.self-text b { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.self-text span { font-size: 11px; color: var(--muted); }

.btn-ghost {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex: none;
  transition: color .15s, border-color .15s, background .15s;
}
.btn-ghost svg { width: 17px; height: 17px; }
.btn-ghost:hover { color: var(--danger); border-color: rgba(248, 113, 113, .4); background: rgba(248, 113, 113, .08); }

/* ---------- 聊天主体 ---------- */
.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
  background:
    radial-gradient(circle at 78% -10%, rgba(74, 222, 128, .07), transparent 42%),
    var(--bg);
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 66px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 15, 20, .8);
  backdrop-filter: blur(10px);
  flex: none;
}
.head-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-head h3 { font-size: 15.5px; font-weight: 700; }
.chat-head p { margin-top: 1px; font-size: 11.5px; color: var(--muted); }

.only-mobile { display: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
  color: #aab6c6;
  cursor: pointer;
  flex: none;
  transition: color .15s, border-color .15s, background .15s;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { color: var(--accent); border-color: rgba(74, 222, 128, .35); background: #18212b; }

.online-chip {
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
}
.online-chip b { color: #b7e9c9; }
.online-chip i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 24px 10px;
}

.msg {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 11px;
  max-width: 960px;
  margin: 0 auto 16px;
  animation: msgIn .2s ease both;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

.msg-main { min-width: 0; }
.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}
.msg-name { font-size: 13.5px; font-weight: 650; color: #cfe0f2; }
.msg.own .msg-name { color: var(--accent); }
.msg-time { font-size: 11px; color: #64748b; }

.msg-bubble {
  display: inline-block;
  max-width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--line-soft);
  border-radius: 4px 13px 13px 13px;
  background: var(--panel);
  font-size: 14.5px;
  line-height: 1.62;
  overflow-wrap: anywhere;
}
.msg.own .msg-bubble {
  border-color: rgba(74, 222, 128, .22);
  background: rgba(74, 222, 128, .09);
}
.msg-text { white-space: pre-wrap; }
.msg-text a {
  color: #7dd3fc;
  text-decoration: none;
  border-bottom: 1px solid rgba(125, 211, 252, .35);
}
.msg-text a:hover { border-bottom-color: currentColor; }

.msg-bubble.media-only { padding: 5px; background: #101720; border-color: var(--line); }
.msg.own .msg-bubble.media-only { background: rgba(74, 222, 128, .07); }

.msg-image {
  display: block;
  max-width: min(420px, 100%);
  max-height: 420px;
  border-radius: 9px;
  object-fit: contain;
  background: #0a0f14;
  cursor: zoom-in;
}
.msg-video {
  display: block;
  width: min(420px, 100%);
  max-height: 420px;
  border-radius: 9px;
  background: #000;
}
.msg-media + .msg-text { margin-top: 7px; }

.msg-text + .msg-media { margin-top: 8px; }

/* 空状态 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 100%;
  min-height: 220px;
  text-align: center;
  color: var(--muted);
}
.empty-block {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin-bottom: 8px;
  border: 1px dashed #33414f;
  border-radius: 15px;
  color: #4b5a6b;
  font: 700 16px/1 ui-monospace, Consolas, monospace;
}
.empty-state strong { font-size: 15px; font-weight: 600; color: #b3c1d1; }
.empty-state span { font-size: 13px; }

.load-older {
  display: block;
  margin: 0 auto 16px;
  padding: 7px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.load-older:hover { color: var(--text); border-color: #3a4a5c; }
.load-older:disabled { opacity: .55; cursor: default; }

.jump-latest {
  position: absolute;
  left: 50%;
  bottom: 128px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid rgba(74, 222, 128, .3);
  border-radius: 999px;
  background: #16241c;
  color: #a9e8c0;
  font-size: 12.5px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .4);
  z-index: 5;
}
.jump-latest svg { width: 14px; height: 14px; }

/* ---------- 输入区 ---------- */
.composer {
  flex: none;
  padding: 10px 24px 16px;
  background: linear-gradient(180deg, rgba(11, 15, 20, 0), rgba(11, 15, 20, .92) 34%);
}
.composer-inner { max-width: 960px; margin: 0 auto; }

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--panel);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .25);
  transition: border-color .15s, box-shadow .15s;
}
.composer-row:focus-within {
  border-color: rgba(74, 222, 128, .4);
  box-shadow: 0 0 0 3px rgba(74, 222, 128, .1);
}

.attach-btn { border: 0; background: transparent; }
.attach-btn:hover { background: #1b2531; }

.composer textarea {
  flex: 1;
  min-height: 40px;
  max-height: 132px;
  padding: 9px 4px;
  border: 0;
  outline: none;
  background: transparent;
  resize: none;
  line-height: 1.55;
  font-size: 14.5px;
  overflow-y: auto;
}
.composer textarea::placeholder { color: #5c6a7d; }

.btn-send {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, #5ce68d, #22c55e);
  color: #06240f;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  flex: none;
  transition: filter .15s, opacity .15s, transform .1s;
}
.btn-send svg { width: 16px; height: 16px; }
.btn-send:hover:not(:disabled) { filter: brightness(1.06); }
.btn-send:active:not(:disabled) { transform: translateY(1px); }
.btn-send:disabled {
  background: #23303d;
  color: #6a7a8c;
  cursor: default;
}

.attach-tip {
  max-width: 960px;
  margin: 7px auto 0;
  font-size: 11.5px;
  color: #566273;
  text-align: right;
}

.attachment {
  display: flex;
  align-items: center;
  gap: 11px;
  max-width: 960px;
  margin: 0 auto;
  padding: 9px 11px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #101720;
}
.attach-thumb {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 9px;
  background: #0a0f14;
  color: #7f8ea1;
  font-size: 11px;
  overflow: hidden;
  flex: none;
}
.attach-thumb img,
.attach-thumb video { width: 100%; height: 100%; object-fit: cover; }
.attach-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.attach-name {
  font-size: 13px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.attach-meta { font-size: 11.5px; color: var(--muted); }
.attach-bar {
  height: 3px;
  margin-top: 2px;
  border-radius: 999px;
  background: #223040;
  overflow: hidden;
}
.attach-bar i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #6ee7a0);
  border-radius: inherit;
  transition: width .2s;
}
.attach-bar.indeterminate i {
  width: 36% !important;
  animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide {
  from { transform: translateX(-110%); }
  to { transform: translateX(320%); }
}
.attach-remove {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.attach-remove:hover { color: var(--danger); border-color: rgba(248, 113, 113, .4); }

.composer-status {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--muted);
}
.composer-status.error { color: var(--danger); }
.status-bar {
  width: 120px;
  height: 3px;
  border-radius: 999px;
  background: #223040;
  overflow: hidden;
  flex: none;
}
.status-bar i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #6ee7a0);
  transition: width .2s;
}

/* ---------- 其他 ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 6, 9, .92);
  cursor: zoom-out;
  backdrop-filter: blur(6px);
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 108px;
  transform: translateX(-50%);
  z-index: 60;
  padding: 9px 16px;
  border: 1px solid rgba(248, 113, 113, .35);
  border-radius: 10px;
  background: #26161a;
  color: #fecaca;
  font-size: 13px;
  box-shadow: var(--shadow);
  max-width: min(420px, 86vw);
  text-align: center;
}

.sidebar-backdrop { display: none; }

/* 滚动条 */
.messages::-webkit-scrollbar,
.online-list::-webkit-scrollbar,
textarea::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb,
.online-list::-webkit-scrollbar-thumb,
textarea::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #2a3542;
}
.messages::-webkit-scrollbar-thumb:hover { background: #384656; }
.messages::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 820px) {
  .chat-view { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(288px, 82vw);
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 18px 0 40px rgba(0, 0, 0, .45);
  }
  .sidebar.open { transform: none; }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(4, 8, 12, .6);
    backdrop-filter: blur(2px);
  }

  .chat-head { height: 58px; padding: 0 14px; }
  .chat-head p { display: none; }
  .messages { padding: 14px 14px 8px; }
  .msg { grid-template-columns: 32px minmax(0, 1fr); gap: 9px; margin-bottom: 13px; }
  .msg .avatar { width: 32px; height: 32px; border-radius: 9px; font-size: 13px; }
  .msg-image, .msg-video { max-width: min(300px, 100%); max-height: 320px; }
  .composer { padding: 8px 12px 12px; }
  .composer-row { padding: 6px; gap: 6px; }
  .attach-btn { width: 36px; height: 36px; }
  .btn-send { height: 36px; padding: 0 12px; }
  .btn-send span { display: none; }
  .attach-tip { display: none; }
  .jump-latest { bottom: 116px; }

  .only-mobile { display: flex; align-items: center; justify-content: center; }
}

@media (max-width: 420px) {
  .login-card { padding: 24px 20px 20px; }
  .brand-badge { width: 46px; height: 46px; }
}
