:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1d212a;
  --line: #262b36;
  --text: #e6e8ee;
  --muted: #8b93a5;
  --brand: #4f8cff;
  --mine: #2a4a7f;
  --theirs: #1f2430;
  --warn: #ffb020;
  --danger: #ff5d5d;
  --ok: #35c46b;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --panel-2: #f0f2f5;
    --line: #e2e5ea;
    --text: #14181f;
    --muted: #6b7382;
    --mine: #d8e6ff;
    --theirs: #eef0f4;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }

.chat {
  max-width: 720px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}
@media (min-width: 760px) {
  .chat { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
.head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 2;
}
.head h1 { font-size: 16px; margin: 0; font-weight: 600; }
.head .sub { color: var(--muted); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.dot.off { background: var(--muted); }

.log {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.row { display: flex; }
.row.out { justify-content: flex-end; }
.bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 14px;
  background: var(--theirs);
  white-space: pre-wrap;
  word-break: break-word;
}
.row.out .bubble { background: var(--mine); }
.bubble .meta { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }
.sys { text-align: center; color: var(--muted); font-size: 12px; }

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 24px;
  max-width: 420px;
}
.empty strong { color: var(--text); display: block; margin-bottom: 8px; font-size: 17px; }

.composer {
  border-top: 1px solid var(--line);
  padding: 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--panel);
}
.composer textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  outline: none;
}
.composer textarea:focus { border-color: var(--brand); }
.send {
  border: 0;
  background: var(--brand);
  color: #fff;
  padding: 0 18px;
  height: 44px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
}
.send:disabled { opacity: .5; cursor: default; }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ---------- inbox ---------- */
.inbox { display: flex; height: 100dvh; }
.side {
  width: 300px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  flex-shrink: 0;
}
.side .head { padding: 12px 14px; }
.side .list { overflow-y: auto; flex: 1; }
.item {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.item:hover { background: var(--panel-2); }
.item.active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--brand); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--panel-2); display: grid; place-items: center;
  font-size: 13px; color: var(--muted); flex-shrink: 0; border: 1px solid var(--line);
}
.item .body { min-width: 0; flex: 1; }
.item .top { display: flex; justify-content: space-between; gap: 6px; }
.item .name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .preview { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  font-size: 10.5px; padding: 1px 6px; border-radius: 6px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.badge.tg { color: #6ab0ff; }
.badge.web { color: #b48cff; }
.badge.blocked { color: var(--danger); }
.unread {
  background: var(--brand); color: #fff; font-size: 11px;
  min-width: 18px; height: 18px; border-radius: 9px;
  display: grid; place-items: center; padding: 0 5px;
}
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.main .head { justify-content: space-between; }
.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 9px; padding: 5px 10px; cursor: pointer; font-size: 12.5px;
}
.ghost:hover { color: var(--text); border-color: var(--muted); }
.ghost.danger:hover { color: var(--danger); border-color: var(--danger); }
.login {
  margin: auto; width: min(360px, 90vw); display: flex; flex-direction: column; gap: 10px;
}
.login input {
  padding: 11px 14px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--panel-2); outline: none;
}
@media (max-width: 720px) {
  .side { width: 100%; }
  .inbox.thread-open .side { display: none; }
  .inbox:not(.thread-open) .main { display: none; }
  .back { display: inline-flex !important; }
}
.back { display: none; }
