: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%; overflow: hidden; }
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: 100%;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 76px minmax(280px, 360px) minmax(0, 1fr);
  grid-template-rows: 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 {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  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; color: var(--muted); }
.overview-head .filters { margin: 14px 0 18px; }
.list-title { margin: 22px 0 10px; font-size: 18px; }
.list-title:first-child { margin-top: 0; }
.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 h2 { display: flex; align-items: center; gap: 6px; }
.account-card .star {
  background: none; border: none; cursor: pointer; padding: 0;
  font-size: 18px; line-height: 1; color: var(--muted);
  transition: color 0.15s, transform 0.1s;
}
.account-card .star:hover { transform: scale(1.2); }
.account-card .star.on { color: #f5a623; }
.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; flex-wrap: wrap; }
.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 {
  min-height: 0;
  background: #0b1219;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
  overflow: auto;
  overscroll-behavior: contain;
}
.avatar, .avatar-lg {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 650;
  position: relative;
  background: hsl(var(--avatar-h, 210) 42% 36%);
  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;
  background: hsl(var(--avatar-h, 210) 42% 36%);
}
.mention-link {
  background: none;
  border: 0;
  padding: 0;
  color: #6ab3f3;
  cursor: pointer;
  font: inherit;
  text-align: inherit;
}
.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 {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.dialogs-head { flex: none; 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; min-height: 0; overscroll-behavior: contain; }
.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; }
.archive-tag {
  margin-left: 6px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  vertical-align: 1px;
}
.dialog.on .archive-tag { color: rgba(255, 255, 255, .8); border-color: rgba(255, 255, 255, .35); }
.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;
  min-height: 0;
  overflow: hidden;
  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 {
  flex: none;
  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%; }
.chat-head .text-btn {
  height: 32px;
  border: 0;
  border-radius: 16px;
  padding: 0 10px;
  background: #243444;
  color: inherit;
  white-space: nowrap;
  flex: none;
}
.icon-btn:hover, .rail-btn:hover { background: var(--hover); }
.back { display: none; }

.messages { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; 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; }
.bubble .service-inline { color: var(--muted); font-size: 13px; }
.media-fallback {
  background: rgba(0, 0, 0, .18);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  max-width: 360px;
}
.dice { font-size: 42px; line-height: 1.1; }
.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 { flex: none; 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 { flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--panel); }
.search-bar input { flex: 1; }
.search-count { flex: none; color: var(--muted); font-size: 13px; min-width: 64px; text-align: right; }
.search-bar button { width: 32px; height: 32px; border: 0; border-radius: 50%; background: transparent; flex: none; }
.search-bar button:hover { background: var(--hover); }
.bubble.search-hit { box-shadow: inset 0 0 0 2px var(--accent); }

.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; }
.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: white;
  border: 0;
  font-size: 30px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 2;
}
.lb-nav:hover { background: rgba(0, 0, 0, .8); }
.lb-nav:disabled { opacity: .3; cursor: default; }
.lb-prev { left: 18px; }
.lb-next { right: 18px; }
.lb-counter {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  color: white;
  font-size: 14px;
  background: rgba(0, 0, 0, .55);
  padding: 5px 12px;
  border-radius: 14px;
  z-index: 2;
}
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: grid;
  place-items: center;
  z-index: 24;
  padding: 16px;
}
.modal.wide .modal-card {
  width: min(1100px, 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 12px;
  max-height: min(92vh, 900px);
}
.attach-tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 12px;
  border-bottom: 1px solid var(--line);
}
.attach-tabs button {
  flex: 1;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 6px 8px;
  color: var(--muted);
  font-size: 14px;
}
.attach-tabs button.on {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.attach-body {
  min-height: 220px;
  max-height: 80vh;
  overflow: auto;
}
.attach-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
}
.attach-list { display: grid; }
.attach-tile, .attach-file, .attach-audio {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  overflow: hidden;
  text-align: left;
  color: inherit;
  text-decoration: none;
}
.attach-tile { aspect-ratio: 1; position: relative; background: #0e1621; }
.attach-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #0e1621; }
.attach-tile .attach-time {
  position: absolute;
  right: 6px;
  bottom: 6px;
  color: white;
  font-size: 12px;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
  background: transparent;
}
.attach-tile .attach-play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, .45);
  color: white;
  font-size: 16px;
  padding: 0 0 0 2px;
}
.attach-file, .attach-audio {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
}
.attach-file b, .attach-audio b {
  display: block;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-file small, .attach-audio small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}
.file-badge, .voice-badge {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
}
.voice-badge { font-size: 18px; font-weight: 500; }
.attach-audio audio { width: 100%; height: 32px; margin-top: 6px; }
.attach-empty { color: var(--muted); padding: 28px 8px; text-align: center; }
.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: 76px minmax(0, 1fr); }
  .shell.pane-chat { grid-template-columns: minmax(0, 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; }
}
