:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-2: #0e1621;
  --line: rgba(255, 255, 255, 0.06);
  --text: #f5f5f5;
  --muted: #7d8b99;
  --accent: #2ea6ff;
  --accent-2: #5288c1;
  --out: #2b5278;
  --in: #182533;
  --danger: #e05d5d;
  --ok: #5dca8a;
  --hover: rgba(255, 255, 255, 0.04);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate form {
  width: min(380px, 100%);
  background: var(--panel);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.gate h1 { margin: 0 0 8px; }
.gate p { color: var(--muted); margin: 0 0 16px; }
.gate .primary { width: 100%; }

.shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 76px minmax(280px, 360px) minmax(0, 1fr);
  position: relative;
}
.shell.home {
  grid-template-columns: 76px minmax(0, 1fr);
}
.shell.home .dialogs,
.shell.home .chat,
.shell.home .info { display: none; }
.overview {
  overflow: auto;
  background: var(--bg);
}
.overview-inner { max-width: 760px; margin: 0 auto; padding: 28px 20px 48px; }
.overview-head h1 { margin: 0 0 6px; font-size: 28px; }
.overview-head p { margin: 0 0 18px; color: var(--muted); }
.account-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  background: var(--panel);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.account-card:hover { background: #1c2a38; }
.account-card h2 { margin: 0 0 4px; font-size: 16px; font-weight: 650; }
.account-card .sub { color: var(--muted); font-size: 13px; }
.account-card .counts { margin-top: 6px; color: var(--muted); font-size: 13px; }
.account-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.pill { font-size: 12px; border-radius: 999px; padding: 3px 8px; }
.pill.alive { background: rgba(93, 202, 138, 0.16); color: var(--ok); }
.pill.dead { background: rgba(224, 93, 93, 0.14); color: #ffb4b4; }

.rail {
  background: #0b1219;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
  overflow: auto;
}
.avatar, .avatar-lg {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 650;
  position: relative;
  background: #243444;
  overflow: hidden;
  flex: none;
}
.avatar img, .avatar-lg img, .profile-photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo, .avatar-sm { cursor: pointer; }
.avatar-sm { width: 34px; height: 34px; font-size: 13px; }
.msg-row { display: flex; gap: 8px; align-items: flex-end; align-self: flex-start; max-width: min(720px, 92%); }
.msg-row .bubble { max-width: 100%; }
.profile { text-align: center; }
.profile h2 { margin: 0; font-size: 22px; }
.profile .presence, .profile .marks { color: var(--muted); margin-top: 4px; font-size: 14px; }
.profile-photo {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  margin: 4px auto 14px;
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  font-size: 42px;
  font-weight: 650;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.profile-rows { margin-top: 16px; text-align: left; }
.profile-row {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line);
  padding: 10px 2px;
}
.profile-row span { display: block; color: var(--accent); font-size: 13px; }
.profile-row b { display: block; font-weight: 550; word-break: break-all; }
.profile-row a { color: inherit; text-decoration: none; }
.avatar-btn {
  position: relative;
  width: 48px;
  height: 48px;
  border: 0;
  padding: 0;
  background: transparent;
}
.avatar-btn.active .avatar { outline: 2px solid var(--accent); outline-offset: 2px; }
.avatar .dot, .avatar-btn .dot, .status-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #0b1219;
  background: var(--muted);
}
.dot.online, .status-dot.online { background: var(--ok); }
.dot.error, .status-dot.error { background: var(--danger); }
.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: white;
  font-size: 11px;
  display: grid;
  place-items: center;
}
.rail-btn, .icon-btn, .send, .filters button, .primary, .ghost, .danger {
  border: 0;
  background: transparent;
}
.rail-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #1c2834;
  color: var(--accent);
  font-size: 26px;
}
.rail-spacer { flex: 1; }

.dialogs { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.dialogs-head { padding: 12px 12px 8px; }
.dialogs-head input, .search-bar input, .field input, .field textarea, #composerText, #chatSearch {
  width: 100%;
  background: #242f3d;
  border: 0;
  border-radius: 20px;
  padding: 10px 14px;
  outline: none;
}
.filters { display: flex; gap: 6px; margin-top: 8px; overflow: auto; }
.filters button {
  border-radius: 14px;
  padding: 5px 10px;
  color: var(--muted);
  background: transparent;
  white-space: nowrap;
}
.filters button.on { background: #2b5278; color: white; }
.dialog-list { overflow: auto; flex: 1; }
.dialog {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  align-items: center;
}
.dialog:hover, .dialog.on { background: var(--hover); }
.dialog.on { background: #2b5278; }
.dialog .title-row, .dialog .sub-row { display: flex; justify-content: space-between; gap: 8px; }
.dialog .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog .time, .dialog .preview, .muted { color: var(--muted); font-size: 13px; }
.dialog.on .time, .dialog.on .preview { color: rgba(255,255,255,.75); }
.preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread {
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: var(--accent-2);
  color: white;
  font-size: 12px;
  display: grid;
  place-items: center;
  padding: 0 6px;
}
.pin { font-size: 12px; }

.chat { display: flex; flex-direction: column; min-width: 0; background: #0e1621 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Ccircle cx='2' cy='2' r='1' fill='%2317222d'/%3E%3C/svg%3E"); }
.empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 24px; }
.empty h1 { color: var(--text); font-weight: 600; margin-bottom: 8px; }
.chat-head {
  height: 60px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.chat-head .who { flex: 1; min-width: 0; }
.chat-head .who b, .chat-head .who span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .who span { color: var(--muted); font-size: 13px; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; }
.icon-btn:hover, .rail-btn:hover { background: var(--hover); }
.back { display: none; }

.messages { flex: 1; overflow: auto; padding: 16px 8% 8px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; background: rgba(23, 33, 43, .9); color: var(--muted); border-radius: 12px; padding: 4px 10px; font-size: 13px; margin: 8px 0; }
.bubble {
  max-width: min(680px, 86%);
  padding: 7px 10px 5px;
  border-radius: 12px;
  background: var(--in);
  position: relative;
  word-wrap: break-word;
}
.bubble.out { align-self: flex-end; background: var(--out); border-bottom-right-radius: 4px; }
.bubble.in { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.service { align-self: center; background: rgba(23, 33, 43, .92); color: var(--muted); font-size: 13px; }
.sender, button.sender {
  color: #6ab3f3;
  font-size: 13px;
  font-weight: 650;
  margin-bottom: 2px;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.reply {
  border-left: 2px solid var(--accent);
  padding-left: 8px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.forward { color: var(--accent-2); font-size: 13px; margin-bottom: 4px; }
.text a { color: #6ab3f3; }
.meta { float: right; margin: 6px 0 0 10px; color: rgba(255,255,255,.6); font-size: 12px; }
.media-img, .media-video { max-width: 360px; max-height: 360px; border-radius: 8px; display: block; }
.video-note { width: 220px; height: 220px; object-fit: cover; border-radius: 50%; }
.file-card, .card, .poll, .markup { margin-top: 6px; }
.file-card, .card {
  background: rgba(0,0,0,.15);
  border-radius: 8px;
  padding: 8px;
}
.poll button, .markup button, .kb button {
  display: block;
  width: 100%;
  text-align: left;
  margin-top: 4px;
  background: rgba(255,255,255,.06);
  border: 0;
  border-radius: 8px;
  padding: 7px 8px;
}
.poll .bar { height: 4px; background: rgba(255,255,255,.15); border-radius: 2px; margin-top: 4px; }
.poll .bar span { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.sticker { font-size: 42px; background: transparent !important; }
.album { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
.album img, .album video { width: 100%; height: 160px; object-fit: cover; border-radius: 6px; }
.jump {
  position: absolute;
  right: 24px;
  bottom: 84px;
  background: var(--panel);
  border-radius: 16px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.chat { position: relative; }
.composer { background: var(--panel); padding: 8px 12px 12px; }
.banner {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  margin-bottom: 6px;
  border-left: 2px solid var(--accent);
  color: var(--muted);
  font-size: 13px;
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
#composerText { resize: none; max-height: 160px; border-radius: 18px; }
#sendBtn, #attachBtn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--muted);
}
#sendBtn { background: var(--accent); color: white; }
.search-bar { padding: 8px 12px; background: var(--panel); }

.info {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow: auto;
  padding: 18px;
  z-index: 6;
}
.info .avatar-lg { width: 96px; height: 96px; margin: 8px auto 12px; font-size: 32px; }
.info h2 { text-align: center; margin: 0 0 4px; font-size: 20px; }
.info .center { text-align: center; color: var(--muted); }
.member { padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; }

.menu {
  position: fixed;
  z-index: 20;
  background: #1e2c3a;
  border-radius: 10px;
  min-width: 180px;
  box-shadow: var(--shadow);
  padding: 6px;
}
.menu button, .modal button.row {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 8px 10px;
  border-radius: 8px;
}
.menu button:hover, .modal button.row:hover { background: var(--hover); }
.reactions { display: flex; gap: 4px; padding: 4px; }
.reactions button { width: 32px; background: transparent; border: 0; font-size: 18px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #243444;
  padding: 10px 14px;
  border-radius: 10px;
  z-index: 30;
  box-shadow: var(--shadow);
}
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.86);
  display: grid;
  place-items: center;
  z-index: 25;
}
.lightbox img, .lightbox video { max-width: 92vw; max-height: 92vh; }
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: grid;
  place-items: center;
  z-index: 24;
  padding: 16px;
}
.modal-card {
  width: min(460px, 100%);
  background: var(--panel);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
  max-height: min(80vh, 720px);
  overflow: auto;
}
.modal-card h3 { margin: 0 0 12px; }
.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tabs button.on { color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.field span { color: var(--muted); font-size: 13px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.primary { background: var(--accent); color: white; border-radius: 8px; padding: 8px 12px; }
.ghost, .danger { border-radius: 8px; padding: 8px 12px; background: #243444; }
.danger { color: #ffb4b4; }
.session-box { width: 100%; min-height: 90px; background: #0e1621; border: 0; border-radius: 8px; padding: 8px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .shell.home { grid-template-columns: 76px minmax(0, 1fr); }
  .shell.home .rail { display: flex; }
  .account-card { grid-template-columns: auto minmax(0, 1fr); }
  .account-side { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; }
  .shell.pane-chat .rail, .shell.pane-chat .dialogs { display: none; }
  .shell.pane-list .chat { display: none; }
  .back { display: grid; place-items: center; }
  .info { position: fixed; inset: 0; width: auto; z-index: 15; }
  .messages { padding: 12px; }
}
