:root {
  --bg: #0a0e15;
  --bg-2: #0f1520;
  --panel: #121a27;
  --panel-2: #16202f;
  --line: #1e2a3c;
  --line-2: #27374d;
  --text: #e6edf7;
  --muted: #7f90a8;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, .14);
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 14px;
  --mono: ui-monospace, "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1000px 600px at 15% -10%, rgba(91, 140, 255, .12), transparent 60%),
    radial-gradient(800px 500px at 110% 110%, rgba(34, 197, 94, .08), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 14px/1.55 "Microsoft YaHei UI", "PingFang SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.err { color: var(--red); font-size: 13px; min-height: 18px; }
.ok { color: var(--green); }

/* ---------- controls ---------- */
button, input, textarea, select {
  font: inherit;
  color: inherit;
}
input, textarea {
  width: 100%;
  background: #0c131e;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: none; }
label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.field { margin-bottom: 14px; }
.btn {
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: .15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); background: #1a2740; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(180deg, #6a97ff, #4a7bf0); border-color: #6a97ff; color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: rgba(239, 68, 68, .5); color: #ffb4b4; }
.btn.danger:hover { background: rgba(239, 68, 68, .14); border-color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 断线横幅：链接失效 / 服务重启时告诉用户，而不是甩一句 Failed to fetch */
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  display: flex; gap: 12px; align-items: center; justify-content: center;
  padding: 10px 14px; background: #7f1d1d; color: #fff; font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
}
.offline-banner .btn { background: rgba(255, 255, 255, .16); border-color: rgba(255, 255, 255, .4); color: #fff; }
body.offline .chat-shell { padding-top: 44px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; padding: 8px 14px 0; background: #121a27; border-bottom: 1px solid var(--line); }
.tab {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 7px 14px; border-radius: 10px 10px 0 0; cursor: pointer; font-size: 13px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: #0c131e; border-color: var(--line); border-bottom-color: #0c131e; }

.login-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.card {
  background: linear-gradient(180deg, rgba(22, 32, 47, .95), rgba(15, 21, 32, .95));
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 30px 28px 24px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .3px;
}
.brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 12px var(--green);
}
.login-card .brand { margin-bottom: 6px; }
.login-card .muted { font-size: 12.5px; margin: 0 0 22px; }
.login-card .btn.primary { width: 100%; padding: 11px; margin-top: 4px; }
.hint { margin-top: 16px; font-size: 11.5px; color: var(--muted); line-height: 1.6; border-top: 1px dashed var(--line); padding-top: 12px; }
.switch-line { margin-top: 12px; text-align: center; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 12.5px; cursor: pointer; padding: 4px; }
.link-btn:hover { text-decoration: underline; }
.shake { animation: shake .35s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ---------- user chat ---------- */
.chat-shell {
  height: 100%;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: rgba(10, 14, 21, .6);
  backdrop-filter: blur(6px);
  position: relative;
}

/* 防截屏：失焦/切后台时整块糊掉 */
body.privacy-on .chat-shell { filter: blur(18px); transition: filter .12s ease; }
body.privacy-on::after {
  content: "内容已隐藏";
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: rgba(8, 12, 19, .72);
  color: #93a4bd; font-size: 15px; letter-spacing: 2px;
}

/* 水印：截图里带上账号，便于追责 */
.watermark {
  position: absolute; inset: 0; overflow: hidden;
  pointer-events: none; z-index: 1; opacity: .03;
}
.watermark span {
  position: absolute; font-size: 11px; white-space: nowrap;
  color: #fff; transform: rotate(-22deg); font-family: var(--mono);
}

/* 禁止选中 / 长按菜单 / 拖拽保存 */
.msg, .bubble, .bubble img, .meta {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}
.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #121a27;
  position: sticky;
  top: 0;
  z-index: 5;
}
.avatar {
  width: 38px; height: 38px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-weight: 700;
  background: linear-gradient(140deg, #35507e, #23334c);
  color: #cfe0ff;
  flex: 0 0 auto;
}
.chat-head .who { flex: 1; min-width: 0; }
.chat-head .who b { display: block; font-size: 15px; }
.chat-head .who span { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); display: inline-block; }
.status-dot.on { background: var(--green); box-shadow: 0 0 8px var(--green); }

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.day-sep { text-align: center; font-size: 11px; color: var(--muted); margin: 8px 0; }
.msg { display: flex; flex-direction: column; max-width: 78%; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.in { align-self: flex-start; align-items: flex-start; }
.bubble {
  padding: 10px 13px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}
.msg.in .bubble { border-bottom-left-radius: 5px; }
.msg.out .bubble {
  background: linear-gradient(180deg, #3f6bd8, #3559b8);
  border-color: #4a76e0;
  border-bottom-right-radius: 5px;
  color: #fff;
}
.bubble img { max-width: 260px; max-height: 320px; border-radius: 10px; display: block; cursor: zoom-in; }
.meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.tag {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--muted);
}
.tag.fire { border-color: rgba(245, 158, 11, .45); color: #ffce7a; background: rgba(245, 158, 11, .1); }
.tag.done { border-color: rgba(34, 197, 94, .4); color: #7ee2a1; background: rgba(34, 197, 94, .08); }
.burnbar { height: 2px; width: 100%; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.burnbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--amber), var(--red)); width: 100%; }
.burnbar.self i { background: linear-gradient(90deg, var(--accent), #7dd3fc); }
.msg.burned .bubble { opacity: .45; filter: grayscale(1); }
.msg.burned .bubble img { filter: blur(3px); }
.burn-note { font-size: 11px; color: #ffce7a; margin-top: 4px; }

.composer {
  border-top: 1px solid var(--line);
  padding: 12px 14px 14px;
  background: #121a27;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  position: relative;
  z-index: 2;
}
.composer .box {
  flex: 1;
  background: #0c131e;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 10px 8px 12px;
  transition: border-color .15s;
}
.composer .box:focus-within { border-color: var(--accent); }
.composer textarea {
  border: none; background: transparent; padding: 0; max-height: 120px; min-height: 24px; display: block;
  box-shadow: none;
}
.composer textarea:focus { box-shadow: none; }
.composer .tools { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.icon-btn {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  padding: 4px 8px; border-radius: 8px; font-size: 15px; line-height: 1;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.send-btn {
  width: 42px; height: 42px; border-radius: 12px; border: none; cursor: pointer;
  background: linear-gradient(180deg, #6a97ff, #4a7bf0); color: #fff; font-size: 16px;
  display: grid; place-items: center; flex: 0 0 auto;
}
.send-btn:hover { filter: brightness(1.08); }
.send-btn:disabled { opacity: .45; }

.typing { font-size: 11px; color: var(--muted); padding: 2px 18px 10px; height: 22px; }

/* ---------- viewer ---------- */
.viewer {
  position: fixed; inset: 0; background: rgba(3, 6, 12, .88);
  display: grid; place-items: center; z-index: 50; padding: 30px; cursor: zoom-out;
}
.viewer img { max-width: 92vw; max-height: 88vh; border-radius: 12px; box-shadow: 0 20px 60px #000; }

/* ---------- admin console ---------- */
.admin-shell { height: 100%; display: grid; grid-template-columns: 320px 1fr; }
.side {
  border-right: 1px solid var(--line);
  background: rgba(15, 21, 32, .92);
  display: flex; flex-direction: column; min-height: 0;
}
.side-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--line); }
.side-head .brand { font-size: 15px; }
.side-head .brand .dot { background: var(--amber); box-shadow: 0 0 12px var(--amber); }
.side-ops { display: flex; gap: 8px; margin-top: 12px; }
.side-ops .btn { flex: 1; }
.side-list { flex: 1; overflow-y: auto; padding: 8px; min-height: 0; }
.side-foot {
  border-top: 1px solid var(--line);
  padding: 10px 14px;
  font-size: 11px;
  color: var(--muted);
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.user-item {
  display: flex; gap: 10px; align-items: center;
  padding: 10px; border-radius: 12px; cursor: pointer;
  border: 1px solid transparent;
}
.user-item:hover { background: var(--panel); }
.user-item.active { background: var(--accent-soft); border-color: rgba(91, 140, 255, .45); }
.user-item .avatar { width: 34px; height: 34px; border-radius: 10px; font-size: 13px; }
.user-item .info { min-width: 0; flex: 1; }
.user-item .info b { display: block; font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-item .info span { font-size: 11px; color: var(--muted); font-family: var(--mono); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  background: var(--red); color: #fff; font-size: 10.5px; font-weight: 700;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  display: grid; place-items: center;
}
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: rgba(10, 14, 21, .55); }
.main-head {
  padding: 12px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; background: rgba(18, 26, 39, .8);
}
.main-head .who { flex: 1; min-width: 0; }
.main-head .who b { font-size: 15px; }
.pw-chip {
  font-family: var(--mono); font-size: 12px;
  background: #0c131e; border: 1px dashed var(--line-2); border-radius: 8px;
  padding: 4px 8px; color: #ffce7a; cursor: pointer; user-select: all;
}
.pw-chip:hover { border-color: var(--amber); }
.thread-wrap { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.empty {
  flex: 1; display: grid; place-items: center; color: var(--muted); font-size: 13px;
  text-align: center; padding: 40px;
}
.empty .big { font-size: 40px; margin-bottom: 10px; opacity: .5; }

/* modal */
.modal-mask {
  position: fixed; inset: 0; background: rgba(3, 6, 12, .7);
  display: grid; place-items: center; z-index: 40; padding: 24px;
  backdrop-filter: blur(3px);
}
.modal { width: 100%; max-width: 420px; padding: 22px; }
.modal h3 { margin: 0 0 4px; font-size: 16px; }
.modal p { margin: 0 0 18px; font-size: 12.5px; color: var(--muted); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.pw-row { display: flex; gap: 8px; }
.pw-row input { font-family: var(--mono); }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px);
  background: #1b2740; border: 1px solid var(--line-2); color: var(--text);
  padding: 10px 16px; border-radius: 999px; font-size: 12.5px;
  opacity: 0; transition: .25s; z-index: 80; pointer-events: none;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .4);
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- share / tunnel ---------- */
.tunnel-pill {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; cursor: pointer;
  background: rgba(34, 197, 94, .12); border: 1px solid rgba(34, 197, 94, .45); color: #7ee2a1;
  white-space: nowrap;
}
.tunnel-pill:hover { background: rgba(34, 197, 94, .2); }
.share-status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin: 14px 0 10px; color: var(--muted); }
.share-url { display: flex; gap: 8px; align-items: center; }
.share-url input { font-family: var(--mono); font-size: 12px; padding: 9px 10px; }
.share-url .btn { flex: 0 0 auto; }
.share-url a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.share-url a.btn.disabled { opacity: .45; pointer-events: none; }
.share-log {
  margin-top: 12px; max-height: 90px; overflow: auto; font-family: var(--mono); font-size: 10.5px;
  color: #6c7d95; background: #080d15; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px; white-space: pre-wrap;
}
.modal .hint { margin-top: 14px; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #233146; border-radius: 9px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #2f4160; background-clip: padding-box; }

@media (max-width: 820px) {
  .admin-shell { grid-template-columns: 1fr; }
  .side { position: absolute; inset: 0 auto 0 0; width: 300px; z-index: 30; transform: translateX(-100%); transition: .2s; }
  .side.open { transform: none; }
  .side-toggle { display: inline-flex !important; }
  .chat-shell { border: none; }
  .msg { max-width: 88%; }

  /* 头部在窄屏改成两行：第一行 ☰ + 名字/状态，第二行密码 + 操作按钮 */
  .main-head { flex-wrap: wrap; row-gap: 8px; padding: 10px 12px; }
  .main-head .avatar { display: none; }
  .main-head .who { flex: 1 1 calc(100% - 52px); min-width: 0; }
  .main-head .who b,
  .main-head .who div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .main-head .who span { white-space: nowrap; }
  #pwChip { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #delBtn { margin-left: auto; }
}
.side-toggle { display: none; }
