* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --tg-blue: #2AABEE;
  --tg-blue-dark: #229ED9;
  --bg-chat: #8db09f;
  --bubble-out: #effdde;
  --bubble-in: #ffffff;
  --text: #000000;
  --text-muted: #707579;
  --sidebar-bg: #ffffff;
  --hover: #f4f4f5;
  --active: #2AABEE;
  --divider: #e7e7e7;
  --online: #4fae4e;
  --check: #4fae4e;
  --search-bg: #f1f1f2;
  --meta-out: #5fa055;
  --quote-bg: rgba(42, 171, 238, .08);
  /* Telegram avatar palette */
  --av-0: linear-gradient(#ff885e, #ff516a);
  --av-1: linear-gradient(#ffcd6a, #ffa85c);
  --av-2: linear-gradient(#82b1ff, #665fff);
  --av-3: linear-gradient(#a0de7e, #54cb68);
  --av-4: linear-gradient(#53edd6, #28c9b7);
  --av-5: linear-gradient(#72d5fd, #2a9ef1);
  --av-6: linear-gradient(#e0a2f3, #d669ed);
  /* Sender name colors in group bubbles */
  --ct-0: #e8506d;
  --ct-1: #e8a13e;
  --ct-2: #6271e3;
  --ct-3: #52b35c;
  --ct-4: #26b3a1;
  --ct-5: #2a9ef1;
  --ct-6: #c75fe0;
}

body.dark {
  color-scheme: dark;
  --bg-chat: #0e1621;
  --bubble-out: #2b5278;
  --bubble-in: #182533;
  --text: #f5f5f5;
  --text-muted: #708499;
  --sidebar-bg: #17212b;
  --hover: #202b36;
  --divider: #101921;
  --check: #71bbe7;
  --search-bg: #242f3d;
  --meta-out: #7da8d3;
  --quote-bg: rgba(113, 187, 231, .12);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", sans-serif;
  font-size: 15px;
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

/* ---------- Login ---------- */

.login-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sidebar-bg);
}

.login-card { text-align: center; width: 320px; }
.login-card h1 { font-size: 28px; margin: 16px 0 8px; }
.login-hint { color: var(--text-muted); margin-bottom: 24px; line-height: 1.4; }

.login-card input {
  width: 100%;
  padding: 12px 16px;
  background: var(--search-bg);
  color: var(--text);
  border: 2px solid var(--divider);
  border-radius: 10px;
  font-size: 16px;
  outline: none;
  margin-bottom: 12px;
  transition: border-color .15s;
}
.login-card input:focus { border-color: var(--tg-blue); }

.login-card button {
  width: 100%;
  padding: 12px;
  background: var(--tg-blue);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
}
.login-card button:hover { background: var(--tg-blue-dark); }
.login-error { color: #e53935; font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- Layout ---------- */

.app { display: flex; height: 100vh; }

.sidebar {
  width: 320px;
  min-width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--divider);
  display: flex;
  flex-direction: column;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='%23ffffff' fill-opacity='0.06'%3E%3Ccircle cx='20' cy='20' r='6'/%3E%3Ccircle cx='60' cy='60' r='6'/%3E%3Crect x='52' y='12' width='14' height='14' rx='4'/%3E%3Crect x='12' y='52' width='14' height='14' rx='4'/%3E%3C/g%3E%3C/svg%3E");
}

/* ---------- Sidebar ---------- */

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 8px 10px 12px;
  border-bottom: 1px solid var(--divider);
}

.me-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 0 4px 0 6px; cursor: pointer; }

button { touch-action: manipulation; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
}
.icon-btn { transition: background .12s, color .12s; }
.icon-btn:hover { background: var(--hover); }

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--tg-blue);
  outline-offset: 2px;
}
.composer-row:focus-within { box-shadow: 0 1px 2px rgba(0,0,0,.1), 0 0 0 1.5px var(--tg-blue); }

.search-wrap { padding: 8px 12px; }
.search-wrap input {
  width: 100%;
  padding: 8px 14px;
  background: var(--search-bg);
  border: none;
  border-radius: 18px;
  font-size: 14px;
  outline: none;
  color: var(--text);
}
.search-wrap input:focus { filter: brightness(.97); }

.chat-list { flex: 1; overflow-y: auto; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  user-select: none;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); color: white; }
.chat-item.active .chat-item-last,
.chat-item.active .chat-item-time { color: rgba(255,255,255,.85); }

.chat-item-body { flex: 1; min-width: 0; }
.chat-item-top { display: flex; align-items: baseline; }
.chat-item-name {
  flex: 1;
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-time { font-size: 12px; color: var(--text-muted); margin-left: 6px; }
.chat-item-bottom { display: flex; align-items: center; margin-top: 2px; }
.chat-item-last {
  flex: 1;
  font-size: 13.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-name.secret { color: var(--online); }
.chat-item-last .typing { color: var(--tg-blue); }
.chat-item-last .draft { color: #e53935; }
.chat-item.active .chat-item-last .draft { color: #ffd4d4; }
.chat-item.active .chat-item-last .typing { color: #d4f1ff; }

.badge {
  background: #c4c9cc;
  color: white;
  font-size: 12px;
  font-weight: 600;
  border-radius: 10px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
}
.badge.unread { background: var(--tg-blue); }
.badge.unread.muted { background: #9aa3aa; }
.chat-item.active .badge { background: white; color: var(--tg-blue); }

/* ---------- Avatars ---------- */

.avatar {
  border-radius: 50%;
  color: white;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  user-select: none;
}
.avatar-sm { width: 42px; height: 42px; font-size: 17px; }
.avatar-xs { width: 34px; height: 34px; font-size: 14px; }
.avatar.c0 { background: var(--av-0); }
.avatar.c1 { background: var(--av-1); }
.avatar.c2 { background: var(--av-2); }
.avatar.c3 { background: var(--av-3); }
.avatar.c4 { background: var(--av-4); }
.avatar.c5 { background: var(--av-5); }
.avatar.c6 { background: var(--av-6); }
.avatar.saved { background: var(--av-5); }

.avatar .online-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--online);
  border: 2px solid var(--sidebar-bg);
}

/* ---------- Chat view ---------- */

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.empty-pill {
  background: rgba(0,0,0,.3);
  color: white;
  padding: 6px 14px;
  border-radius: 14px;
  font-size: 14px;
}

.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.scroll-bottom {
  position: absolute;
  right: 20px;
  bottom: 78px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--sidebar-bg);
  color: var(--text-muted);
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
.scroll-bottom:hover { color: var(--tg-blue); }
.scroll-bottom .badge {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
}

.unread-divider {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--tg-blue);
  background: var(--sidebar-bg);
  opacity: .92;
  padding: 4px 0;
  margin: 6px -16px;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--divider);
}
.chat-header-text { min-width: 0; flex: 1; }
.btn-mute { margin-left: auto; }
.chat-title { font-weight: 600; font-size: 15px; }
.chat-status { font-size: 13px; color: var(--text-muted); }
.chat-status.online, .chat-status.typing { color: var(--tg-blue); }
.chat-status.typing::after, .chat-item-last .typing::after {
  content: '';
  display: inline-block;
  width: 1.1em;
  text-align: left;
  animation: typing-dots 1.2s steps(4) infinite;
}
@keyframes typing-dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 6px;
  display: flex;
  flex-direction: column;
}

.day-sep {
  align-self: center;
  background: rgba(0,0,0,.25);
  color: white;
  font-size: 13px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 12px;
  margin: 8px 0;
}

.msg-row { display: flex; margin-bottom: 10px; }
.msg-row.grouped { margin-top: -8px; }
.msg-row.out { justify-content: flex-end; }

.bubble {
  max-width: min(480px, 78%);
  padding: 6px 10px 7px;
  border-radius: 12px;
  background: var(--bubble-in);
  box-shadow: 0 1px 1px rgba(0,0,0,.05);
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
  cursor: default;
}
.msg-row.out .bubble { background: var(--bubble-out); }
.msg-row.first-in-group .bubble { border-top-left-radius: 12px; }

.bubble .sender {
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 1px;
}

.bubble .reply-quote {
  border-left: 3px solid var(--tg-blue);
  padding: 2px 8px;
  margin: 2px 0 4px;
  border-radius: 4px;
  background: var(--quote-bg);
  font-size: 13px;
  cursor: pointer;
}
.reply-quote .reply-name { color: var(--tg-blue); font-weight: 600; }
.reply-quote .reply-content {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.bubble .meta {
  float: right;
  margin: 8px -4px -4px 8px;
  font-size: 11.5px;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  user-select: none;
}
.msg-row.out .meta { color: var(--meta-out); }
.meta .ticks { font-size: 13px; letter-spacing: -3px; }
.meta .ticks.read { color: var(--check); }

.msg-deleted { font-style: italic; color: var(--text-muted); }

/* ---------- Delivery states & link previews ---------- */

.send-failed {
  color: #e53935;
  font-weight: 600;
  font-size: 11.5px;
  cursor: pointer;
}

.link-preview {
  display: block;
  border-left: 3px solid var(--tg-blue);
  background: var(--quote-bg);
  border-radius: 6px;
  padding: 6px 10px;
  margin-top: 6px;
  text-decoration: none;
  color: inherit;
  max-width: 380px;
}
.lp-site {
  display: block;
  color: var(--tg-blue);
  font-size: 12.5px;
  font-weight: 600;
}
.lp-title { display: block; font-weight: 600; font-size: 14px; }
.lp-desc {
  display: block;
  color: var(--text-muted);
  font-size: 13px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.lp-img {
  display: block;
  max-width: 100%;
  max-height: 160px;
  border-radius: 6px;
  margin-top: 6px;
  object-fit: cover;
}

/* ---------- Reactions ---------- */

.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.rx {
  border: none;
  background: var(--quote-bg);
  color: var(--tg-blue-dark);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.rx.mine {
  background: var(--tg-blue);
  color: white;
}

.ctx-emoji-row {
  display: flex;
  gap: 2px;
  padding: 4px 8px 8px;
  border-bottom: 1px solid var(--divider);
  margin-bottom: 4px;
}
.ctx-emoji {
  border: none;
  background: none;
  font-size: 20px;
  padding: 4px;
  border-radius: 50%;
  cursor: pointer;
}
.ctx-emoji:hover { background: var(--hover); transform: scale(1.15); }

/* ---------- Staged attachments & drop overlay ---------- */

.staged-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--sidebar-bg);
  border-radius: 10px 10px 0 0;
  border-bottom: 1px solid var(--divider);
  padding: 8px 10px;
}
.staged-bar + .composer-row {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.staged-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--search-bg);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 13px;
  max-width: 220px;
}
.staged-chip img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
}
.staged-chip .staged-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.staged-chip .staged-x {
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
}
.staged-chip .staged-x:hover { color: #e53935; }
.staged-chip.uploading { opacity: .6; }

.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(42, 171, 238, .18);
  border: 3px dashed var(--tg-blue);
  border-radius: 12px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.drop-pill {
  background: var(--sidebar-bg);
  color: var(--text);
  font-weight: 600;
  padding: 12px 22px;
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.25);
}

/* ---------- Voice messages ---------- */

.voice-msg {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  padding: 4px 0;
}
.voice-play {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--tg-blue);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.voice-track {
  flex: 1;
  height: 5px;
  border-radius: 3px;
  background: var(--quote-bg);
  overflow: hidden;
}
.voice-progress {
  display: block;
  height: 100%;
  width: 0;
  background: var(--tg-blue);
  transition: width .2s linear;
}
.voice-time {
  font-size: 12.5px;
  color: var(--text-muted);
  min-width: 34px;
  text-align: right;
}

.rec-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--sidebar-bg);
  border-radius: 10px;
  padding: 8px 8px 8px 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
.rec-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e53935;
  animation: rec-pulse 1s infinite;
}
@keyframes rec-pulse {
  50% { opacity: .25; }
}
.rec-timer {
  flex: 1;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* ---------- Forwarding & pins ---------- */

.fwd-from {
  color: var(--tg-blue);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 1px;
}

.pinned-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--divider);
  padding: 5px 16px;
  cursor: pointer;
}
.pinned-bar-text {
  flex: 1;
  min-width: 0;
  border-left: 3px solid var(--tg-blue);
  padding-left: 10px;
}
.pinned-label { color: var(--tg-blue); font-size: 12.5px; font-weight: 600; }
.pinned-content {
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- System messages ---------- */

.sys-msg {
  align-self: center;
  background: rgba(0,0,0,.2);
  color: white;
  font-size: 13px;
  padding: 3px 12px;
  border-radius: 12px;
  margin: 4px 0;
  text-align: center;
}

/* ---------- Info & profile modals ---------- */

.modal-subtitle { font-size: 13.5px; color: var(--text-muted); margin-top: -6px; }
.modal-subtitle:not(:first-of-type) {
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--divider);
}

.info-title-row { display: flex; align-items: center; gap: 8px; }
.info-title-row h2 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.info-title-row input {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  padding: 6px 10px;
}

.member-remove.make-owner { color: var(--tg-blue); }
.member-remove.make-owner:hover { background: var(--quote-bg); }

.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
}
.member-row .member-name { flex: 1; min-width: 0; }
.member-row .member-status { font-size: 12.5px; color: var(--text-muted); }
.member-row .member-status.online { color: var(--tg-blue); }
.member-remove {
  border: none;
  background: none;
  color: #e53935;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.member-remove:hover { background: rgba(229,57,53,.1); }

.btn-flat.danger { color: #e53935; }
.btn-flat.danger:hover { background: rgba(229,57,53,.08); }

.color-row { display: flex; gap: 10px; justify-content: center; padding: 4px 0; }
.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  padding: 0;
}
.color-swatch.selected { border-color: var(--tg-blue); }

.chat-header-text { cursor: pointer; }

.search-section {
  padding: 10px 14px 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}

/* ---------- Attachments ---------- */

.attach-img {
  display: block;
  max-width: 300px;
  max-height: 320px;
  border-radius: 8px;
  margin: 2px 0 4px;
}

.attach-file {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  margin: 2px 0 4px;
  min-width: 180px;
}
.attach-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tg-blue);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.attach-text { display: flex; flex-direction: column; min-width: 0; }
.attach-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}
.attach-size { font-size: 12.5px; color: var(--text-muted); }

/* ---------- Composer ---------- */

.composer { padding: 8px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }

.reply-bar {
  display: flex;
  align-items: center;
  background: var(--sidebar-bg);
  border-radius: 10px 10px 0 0;
  padding: 6px 10px;
  border-bottom: 1px solid var(--divider);
}
.reply-bar + .reply-bar { border-radius: 0; }
.reply-bar-text { flex: 1; min-width: 0; border-left: 3px solid var(--tg-blue); padding-left: 8px; }
.reply-bar .reply-name { color: var(--tg-blue); font-size: 13px; font-weight: 600; }
.reply-bar .reply-content {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  background: var(--sidebar-bg);
  border-radius: 10px;
  padding: 6px 8px;
  gap: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
.composer:has(.reply-bar:not(.hidden)) .composer-row {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

#input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font: inherit;
  color: var(--text);
  caret-color: var(--tg-blue);
  max-height: 140px;
  line-height: 1.4;
  padding: 6px 0;
  background: transparent;
}

.composer-row .icon-btn,
#btn-mic { color: var(--text-muted); }
#btn-send { color: var(--tg-blue); }

.send-btn {
  background: none;
  border: none;
  color: var(--tg-blue);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
}
.send-btn:hover { background: rgba(42,171,238,.1); }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--sidebar-bg);
  border-radius: 14px;
  padding: 20px;
  width: 380px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal h2 { font-size: 18px; }
.modal input {
  padding: 10px 12px;
  border: 1.5px solid var(--divider);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: var(--search-bg);
  color: var(--text);
}
.modal input:focus { border-color: var(--tg-blue); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: #eef7fd;
  color: var(--tg-blue-dark);
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
}
.chip:hover { background: #fdeeee; color: #e53935; }

.modal-results { overflow-y: auto; max-height: 240px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.btn-flat {
  background: none;
  border: none;
  color: var(--tg-blue);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-flat:hover { background: var(--quote-bg); }
.btn-primary {
  background: var(--tg-blue);
  border: none;
  color: white;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-primary:disabled { opacity: .5; cursor: default; }

/* ---------- Operator UI ---------- */

.invite-row { display: flex; align-items: center; gap: 8px; }
.invite-row input {
  flex: 1;
  font-size: 12.5px;
  padding: 6px 10px !important;
}

.modal select {
  padding: 10px 12px;
  border: 1.5px solid var(--divider);
  border-radius: 8px;
  font-size: 14px;
  background: var(--search-bg);
  color: var(--text);
  outline: none;
}

.sessions { max-height: 180px; }
.session-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  font-size: 13px;
}
.session-row .session-info { flex: 1; min-width: 0; }
.session-row .session-ua {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.session-row .session-meta { color: var(--text-muted); font-size: 12px; }
.session-current {
  color: var(--online);
  font-size: 12px;
  font-weight: 600;
}

.admin-user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
}
.admin-user-row .member-name { flex: 1; min-width: 0; }
.admin-user-row.disabled .member-name { opacity: .5; text-decoration: line-through; }

/* ---------- Voice calls ---------- */

.avatar-lg { width: 84px; height: 84px; font-size: 32px; }

.call-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 18, 26, .92);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.call-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: white;
}
.call-name { font-size: 24px; font-weight: 600; }
.call-status { color: #9fb3c8; font-size: 15px; min-height: 22px; }
.call-actions { display: flex; gap: 26px; margin-top: 26px; }
.call-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 24px;
  transition: transform .12s;
}
.call-btn:hover { transform: scale(1.07); }
.call-btn.accept { background: #4fae4e; }
.call-btn.hangup { background: #e53935; }
.call-btn.mute { background: rgba(255,255,255,.18); }
.call-btn.mute.muted { background: #e8a13e; }

/* ---------- User profile card ---------- */

.modal.user-card { width: 340px; align-items: center; text-align: center; }
.user-card .avatar-lg { margin: 6px auto 2px; }
.uc-name { font-size: 20px; font-weight: 700; }
.uc-username { color: var(--text-muted); font-size: 14px; margin-top: -8px; }
.uc-status { font-size: 13.5px; color: var(--text-muted); min-height: 18px; }
.uc-status.online { color: var(--tg-blue); }
.uc-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 4px;
}
.user-card .modal-actions { justify-content: center; width: 100%; }
.uc-badge {
  display: inline-block;
  background: var(--quote-bg);
  color: var(--tg-blue-dark);
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 1px 7px;
  margin-left: 6px;
  vertical-align: 2px;
}

/* ---------- Video calls ---------- */

.call-remote {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  z-index: 1;
}
.call-local {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 200px;
  max-width: 28vw;
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
  z-index: 2;
  transform: scaleX(-1); /* mirror your own preview */
}
.call-card { position: relative; z-index: 3; }
.call-overlay.video-live .avatar-lg { display: none; }
.call-overlay.video-live .call-card {
  position: absolute;
  bottom: 28px;
  left: 0;
  right: 0;
}
.call-overlay.video-live .call-name,
.call-overlay.video-live .call-status { text-shadow: 0 1px 4px rgba(0,0,0,.7); }
.call-btn.mute.cam-off { background: #e8a13e; }

/* ---------- Onboarding ---------- */

.modal.onboard { width: 420px; }
.ob-tips { display: flex; flex-direction: column; gap: 16px; padding: 6px 0; }
.ob-tip { display: flex; gap: 14px; align-items: flex-start; }
.ob-tip > span { font-size: 24px; line-height: 1.2; }
.ob-tip div { font-size: 14px; color: var(--text-muted); }
.ob-tip b { color: var(--text); }

/* ---------- Context menu ---------- */

.ctx-menu {
  position: fixed;
  background: var(--sidebar-bg);
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,.18);
  padding: 6px 0;
  z-index: 200;
  min-width: 160px;
}
.ctx-item {
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}
.ctx-item:hover { background: var(--hover); }
.ctx-item.danger { color: #e53935; }

/* ---------- Inline formatting ---------- */

.md-code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13.5px;
  background: rgba(127, 127, 127, .15);
  border-radius: 4px;
  padding: 1px 5px;
}
.md-pre {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  background: rgba(127, 127, 127, .12);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 4px 0;
  overflow-x: auto;
  white-space: pre;
}

/* ---------- Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .88);
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  cursor: zoom-out;
}
.lightbox img {
  max-width: 92vw;
  max-height: 84vh;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, .6);
}
.lightbox-caption {
  color: #eee;
  font-size: 14px;
  max-width: 80vw;
  text-align: center;
}

/* ---------- Seen-by (context menu) ---------- */

.ctx-seen {
  padding: 6px 16px 8px;
  font-size: 12.5px;
  color: var(--text-muted);
  max-width: 240px;
  border-bottom: 1px solid var(--divider);
  margin-bottom: 4px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.75);
  color: white;
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 300;
}

/* ---------- Scrollbars ---------- */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.18); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

.btn-back { display: none; }

@media (max-width: 640px) {
  .sidebar { width: 100%; min-width: 0; }
  .app.chat-open .sidebar { display: none; }
  .app:not(.chat-open) .main { display: none; }
  .btn-back { display: flex; }
}
