/* ============ Discord clone — styles ============ */
:root {
  --rail: #1e1f22;
  --sidebar: #2b2d31;
  --chat: #313338;
  --card: #313338;
  --input: #383a40;
  --hover: #35373c;
  --active: #404249;
  --brand: #5865f2;
  --brand-hover: #4752c4;
  --green: #23a559;
  --red: #f23f43;
  --yellow: #f0b232;
  --text: #dbdee1;
  --text-bright: #f2f3f5;
  --muted: #949ba4;
  --muted2: #80848e;
  --mention: rgba(240, 178, 50, 0.12);
  --mention-text: #f0b232;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: "gg sans", "Noto Sans", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--rail);
  color: var(--text);
  font-size: 15px;
  overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; }
a { color: #00a8fc; text-decoration: none; }
a:hover { text-decoration: underline; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #1a1b1e; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ============ Auth ============ */
#auth { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; overflow: auto; }
.auth-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(900px 500px at 15% 20%, #5865f2 0%, transparent 60%),
    radial-gradient(800px 500px at 85% 80%, #eb459e 0%, transparent 55%),
    linear-gradient(135deg, #404eed, #1e1f22);
}
.auth-card {
  position: relative; z-index: 1;
  background: var(--card); border-radius: 12px; padding: 32px;
  width: 480px; max-width: calc(100vw - 32px);
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
  text-align: center;
}
.auth-logo { display: flex; justify-content: center; margin-bottom: 8px; }
.auth-card h1 { color: var(--text-bright); font-size: 24px; font-weight: 700; }
.auth-sub { color: var(--muted); margin: 6px 0 20px; }
.field-label { display: block; text-align: left; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin: 16px 0 6px; }
.req { color: var(--red); }
.input {
  width: 100%; background: #1e1f22; border: 1px solid #1e1f22; border-radius: 4px;
  padding: 10px 12px; color: var(--text-bright); font-size: 15px; outline: none;
}
.input:focus { border-color: var(--brand); }
.auth-error { color: var(--red); font-size: 13px; min-height: 18px; margin: 8px 0 4px; text-align: left; }
.btn-primary {
  background: var(--brand); color: #fff; font-weight: 600; font-size: 15px;
  padding: 11px 16px; border-radius: 4px; transition: background .15s;
}
.btn-primary:hover { background: var(--brand-hover); }
.btn-block { width: 100%; margin-top: 8px; }
.btn-secondary {
  background: #4e5058; color: #fff; font-weight: 600; font-size: 14px;
  padding: 10px 14px; border-radius: 4px;
}
.btn-secondary:hover { background: #5d5f67; }
.btn-danger { background: var(--red); color: #fff; font-weight: 600; padding: 10px 14px; border-radius: 4px; }
.auth-switch { text-align: left; margin-top: 12px; font-size: 14px; }
.auth-switch a { color: #00a8fc; }
.auth-hint {
  margin-top: 18px; padding: 10px 12px; background: #1e1f22; border-radius: 6px;
  font-size: 12.5px; color: var(--muted); line-height: 1.7;
}

/* ============ App layout ============ */
.app { position: fixed; inset: 0; display: grid; grid-template-columns: 72px 240px 1fr 240px; }
.app.no-members { grid-template-columns: 72px 240px 1fr; }
.app > * { min-height: 0; min-width: 0; overflow: hidden; }

/* ============ Rail ============ */
.rail {
  background: var(--rail); padding: 12px 0; display: flex; flex-direction: column; align-items: center; gap: 8px;
  overflow-y: auto; overflow-x: hidden;
}
.rail::-webkit-scrollbar { width: 0; }
.rail-item {
  width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--hover); color: var(--text-bright); font-weight: 700; font-size: 17px;
  transition: border-radius .2s ease, background .2s ease, color .2s ease;
  position: relative; flex: 0 0 auto;
}
.rail-item:hover { border-radius: 35%; background: var(--brand); color: #fff; }
.rail-item.active { border-radius: 35%; background: var(--brand); color: #fff; }
.rail-item.home { background: var(--brand); color: #fff; }
.rail-item.home.active { border-radius: 35%; }
.rail-item.home svg { width: 28px; height: 28px; fill: #fff; }
.rail-item .pill {
  position: absolute; left: -16px; top: 50%; transform: translateY(-50%);
  width: 8px; border-radius: 0 4px 4px 0; background: #fff; transition: height .15s;
  height: 8px;
}
.rail-item .pill.unread { height: 8px; }
.rail-item .pill.active-pill { height: 36px; }
.rail-item .mention-count {
  position: absolute; bottom: -3px; right: -3px; background: var(--red); color: #fff;
  font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
  border: 3px solid var(--rail);
}
.rail-sep { width: 32px; height: 2px; background: #35363c; border-radius: 1px; flex: 0 0 auto; }
.rail-item.add:hover { background: var(--green); color: #fff; }
.rail-item .tooltip {
  position: absolute; left: 60px; top: 50%; transform: translateY(-50%) scale(.9);
  background: #000; color: #fff; font-size: 14px; font-weight: 600; padding: 8px 12px;
  border-radius: 6px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .1s, transform .1s;
  z-index: 100;
}
.rail-item:hover .tooltip { opacity: 1; transform: translateY(-50%) scale(1); }

/* ============ Sidebar ============ */
.sidebar { background: var(--sidebar); display: flex; flex-direction: column; min-height: 0; }
.sidebar-header {
  height: 48px; flex: 0 0 auto; display: flex; align-items: center; padding: 0 16px;
  font-weight: 600; color: var(--text-bright); box-shadow: 0 1px 0 rgba(0,0,0,.25);
  cursor: pointer; transition: background .1s; position: relative;
}
.sidebar-header:hover { background: var(--hover); }
.sidebar-header .chev { margin-left: auto; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 8px 8px 16px; }

.dm-search {
  margin: 8px; width: calc(100% - 16px); background: var(--input); border: none; border-radius: 4px;
  padding: 7px 10px; color: var(--text); font-size: 13px; outline: none; cursor: pointer;
}
.dm-search:hover { background: var(--active); }

.category {
  display: flex; align-items: center; gap: 4px; padding: 16px 8px 4px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
  cursor: pointer; user-select: none;
}
.category:hover { color: var(--text-bright); }
.category .arrow { transition: transform .15s; font-size: 10px; }
.category.collapsed .arrow { transform: rotate(-90deg); }
.category.collapsed ~ .cat-items { display: none; }
.cat-items { display: flex; flex-direction: column; gap: 2px; }

.channel {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 4px;
  color: var(--muted); font-size: 15px; font-weight: 500; cursor: pointer; position: relative;
}
.channel:hover { background: var(--hover); color: var(--text-bright); }
.channel.active { background: var(--active); color: #fff; }
.channel.unread { color: var(--text-bright); font-weight: 600; }
.channel.unread::before {
  content: ''; position: absolute; left: -8px; top: 50%; transform: translateY(-50%);
  width: 8px; height: 8px; border-radius: 0 4px 4px 0; background: #fff;
}
.channel .ch-icon { width: 20px; text-align: center; font-size: 18px; flex: 0 0 auto; opacity: .8; }
.channel .ch-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel .ch-badge {
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px; padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
}
.voice-members { padding: 2px 0 6px 30px; display: flex; flex-direction: column; gap: 2px; }
.voice-member { display: flex; align-items: center; gap: 8px; padding: 3px 8px; border-radius: 4px; font-size: 14px; color: var(--muted); cursor: pointer; }
.voice-member:hover { background: var(--hover); }
.voice-member .v-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-member .v-flags { font-size: 12px; display: flex; gap: 4px; }
.voice-member.self { color: var(--text-bright); }
.voice-member.speaking .v-name { color: var(--green); font-weight: 600; }
.avatar.ring { box-shadow: 0 0 0 2px var(--green); }
.channel.voice.ch-speaking { color: var(--green); }

.dm-item {
  display: flex; align-items: center; gap: 12px; padding: 7px 8px; border-radius: 4px;
  color: var(--muted); cursor: pointer; font-weight: 500; position: relative;
}
.dm-item:hover { background: var(--hover); color: var(--text-bright); }
.dm-item.active { background: var(--active); color: #fff; }
.dm-item.unread { color: var(--text-bright); }
.dm-item .dm-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-label { padding: 16px 8px 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: .5px; }

/* avatar */
.avatar {
  border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px; flex: 0 0 auto; position: relative;
  background: var(--brand); user-select: none; overflow: visible;
}
.avatar img.avatar-img, .avatar-img {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover; position: absolute; inset: 0;
}
.avatar .status-dot {
  position: absolute; bottom: -2px; right: -2px; width: 14px; height: 14px; border-radius: 50%;
  border: 3px solid var(--sidebar); display: flex; align-items: center; justify-content: center;
  font-size: 9px; color: #fff;
}
.status-online .status-dot, .status-dot.online { background: var(--green); }
.status-idle .status-dot, .status-dot.idle { background: var(--yellow); }
.status-dnd .status-dot, .status-dot.dnd { background: var(--red); }
.status-offline .status-dot, .status-dot.offline { background: #80848e; }
.status-dot.dnd::after { content: ''; position: absolute; width: 6px; height: 2px; background: var(--sidebar); border-radius: 1px; }
.status-dot.idle::after { content: ''; position: absolute; width: 5px; height: 5px; border-radius: 50%; background: var(--sidebar); top: 1px; left: 1px; }
.status-dot.offline::after { content: ''; position: absolute; width: 5px; height: 5px; border-radius: 50%; background: var(--sidebar); }

/* user panel */
.sidebar-bottom { flex: 0 0 auto; }
.voice-panel {
  background: #232428; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px;
}
.voice-panel .vp-title { color: var(--green); font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.voice-panel .vp-ch { color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; align-items: center; }
.voice-panel .vp-actions { display: flex; gap: 4px; }
.vp-btn {
  flex: 1; background: #383a40; border-radius: 4px; padding: 8px; font-size: 13px; font-weight: 600;
  color: var(--text); display: flex; align-items: center; justify-content: center; gap: 6px;
}
.vp-btn:hover { background: #42444a; }
.vp-btn.off { color: var(--red); }
.vp-btn.disconnect:hover { background: var(--red); color: #fff; }

.user-panel {
  background: #232428; padding: 8px; display: flex; align-items: center; gap: 4px;
}
.user-panel .me-btn {
  display: flex; align-items: center; gap: 8px; flex: 1; padding: 4px; border-radius: 4px; min-width: 0;
}
.user-panel .me-btn:hover { background: #35363c; }
.user-panel .me-name { font-size: 14px; font-weight: 700; color: var(--text-bright); line-height: 1.1; text-align: left; }
.user-panel .me-status { font-size: 12px; color: var(--muted); text-align: left; line-height: 1.2; }
.user-panel .up-btn {
  width: 32px; height: 32px; border-radius: 4px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 16px;
}
.user-panel .up-btn:hover { background: #35363c; color: var(--text-bright); }
.user-panel .up-btn.off { color: var(--red); }

/* ============ Friends page ============ */
.friends-tabs { display: flex; gap: 12px; padding: 10px 16px; box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.f-tab { color: var(--muted); font-weight: 600; font-size: 15px; padding: 4px 10px; border-radius: 4px; }
.f-tab:hover { background: var(--hover); color: var(--text-bright); }
.f-tab.sel { background: var(--active); color: #fff; }
.f-tab.add.sel { background: var(--green); color: #fff; }
.friend-row { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 8px; }
.friend-row:hover { background: var(--hover); }
.f-info { flex: 1; min-width: 0; }
.f-name { font-weight: 600; color: var(--text-bright); }
.f-status { font-size: 12px; color: var(--muted); }
.f-actions { display: flex; gap: 8px; }
.f-act { width: 38px; height: 38px; border-radius: 50%; background: var(--input); font-size: 17px; display: flex; align-items: center; justify-content: center; }
.f-act:hover { background: var(--active); }
.f-act.ok:hover { background: var(--green); }
.f-act.no:hover { background: var(--red); }
.add-friend-box { max-width: 600px; }
.add-friend-input { display: flex; gap: 10px; margin-top: 4px; }
.add-friend-input .input { flex: 1; }
.f-hint { color: var(--muted); font-size: 13px; margin-top: 10px; }
.f-empty { color: var(--muted); text-align: center; padding: 40px; }
.dm-act { opacity: 0; background: none; font-size: 16px; padding: 4px; border-radius: 4px; }
.dm-item:hover .dm-act { opacity: 1; }
.dm-act:hover { color: var(--green); }
/* ============ Call overlays (shared) ============ */
.call-overlay { position: fixed; inset: 0; z-index: 500; display: flex; flex-direction: column; }
.call-bg { position: absolute; inset: 0; background: #000; }
.call-avatar-block { text-align: center; color: #fff; }
.call-avatar { width: 120px; height: 120px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 44px; font-weight: 700; color: #fff; overflow: hidden; }
.ring-anim { animation: ringPulse 1.6s infinite; box-shadow: 0 0 0 0 rgba(255,255,255,.5); }
@keyframes ringPulse { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,.45);} 70% { box-shadow: 0 0 0 24px rgba(255,255,255,0);} 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0);} }
.call-name { font-size: 28px; font-weight: 700; margin-top: 16px; }
.call-sub { font-size: 16px; opacity: .8; margin-top: 4px; }
.call-btn { width: 62px; height: 62px; border-radius: 50%; background: rgba(255,255,255,.15); color: #fff; font-size: 24px; display: flex; align-items: center; justify-content: center; transition: transform .1s, background .15s; }
.call-btn:hover { transform: scale(1.06); background: rgba(255,255,255,.28); }
.call-btn.off { background: #fff; color: #111; }
.call-btn.hangup { background: var(--red); }
.call-btn.hangup:hover { background: #d2353a; }
.call-btn.ok { background: var(--green); }
.incoming-call {
  position: fixed; top: 20px; right: 20px; z-index: 600; background: #2b2d31; border-radius: 12px;
  padding: 14px 16px; display: flex; align-items: center; gap: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.5); border: 1px solid #3f4147;
  animation: slideIn .25s ease;
}
@keyframes slideIn { from { transform: translateX(120%); } to { transform: translateX(0); } }
.inc-info { display: flex; align-items: center; gap: 12px; }
.inc-avatar { width: 44px; height: 44px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; }
.inc-name { font-weight: 700; color: var(--text-bright); }
.inc-sub { font-size: 12px; color: var(--muted); }
.inc-actions { display: flex; gap: 8px; }
.inc-actions .call-btn { width: 46px; height: 46px; font-size: 20px; }

.msg.flash { background: rgba(88,101,242,.22); }
@keyframes flashFade { 0%{background:rgba(88,101,242,.35)} 100%{background:transparent} }
.msg.flash { animation: flashFade 1.2s ease; }

.reply-bar {
  background: #1e1f22; margin-bottom: 0; padding: 8px 12px; border-radius: 8px 8px 0 0;
  display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted);
}
.reply-bar .rb-text { flex: 1; min-width: 0; }
.reply-bar .rb-preview { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-bar button { color: var(--muted); font-size: 15px; padding: 2px 6px; border-radius: 4px; }
.reply-bar button:hover { color: #fff; background: var(--active); }

/* ============ Screen share stage ============ */
#screen-stage {
  display: none; flex: 0 0 auto; background: #1e1f22; border-bottom: 1px solid #000;
  padding: 10px; max-height: 42%; gap: 8px; align-items: stretch; justify-content: center;
}
#screen-stage.open { display: flex; }
.screen-tile {
  position: relative; background: #000; border-radius: 8px; overflow: hidden;
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center;
  max-height: 34vh;
}
.screen-tile video { width: 100%; height: 100%; object-fit: contain; }
.screen-tile .screen-label {
  position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.6); color: #fff;
  font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 4px;
}
.screen-tile.focus { border: 2px solid var(--green); }
#screen-stage .video-tile { max-height: 34vh; min-height: 0; flex: 1; }
#screen-stage .video-tile.focus { outline: 2px solid var(--green); outline-offset: -2px; }
.vp-btn.sharing { background: var(--green); color: #fff; }
.vp-btn.sharing:hover { background: #1d8a4c; }

/* volume controls */
.vol-row { display: flex; align-items: center; gap: 8px; padding: 2px 2px 4px; color: var(--muted); font-size: 13px; }
.vol-slider { flex: 1; -webkit-appearance: none; appearance: none; height: 4px; border-radius: 2px; background: #4e5058; outline: none; cursor: pointer; }
.vol-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #fff; cursor: pointer; border: none; }
.vol-slider::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; cursor: pointer; border: none; }
.vol-val { font-size: 12px; color: var(--muted); min-width: 38px; text-align: right; }
.v-vol-btn { font-size: 13px; opacity: 0; transition: opacity .12s; padding: 2px; border-radius: 4px; flex: 0 0 auto; }
.voice-member:hover .v-vol-btn { opacity: 1; }
.v-vol-btn:hover { background: var(--active); }

/* ============ Chat ============ */
.chat { background: var(--chat); display: flex; flex-direction: column; min-width: 0; }
.chat-header {
  height: 48px; flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 0 16px;
  box-shadow: 0 1px 0 rgba(0,0,0,.25); z-index: 2;
}
.chat-header .ch-title { font-weight: 700; color: var(--text-bright); font-size: 16px; display: flex; align-items: center; gap: 6px; }
.chat-header .ch-topic { color: var(--muted); font-size: 13px; border-left: 1px solid #3f4147; padding-left: 12px; margin-left: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-header .spacer { flex: 1; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 4px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 18px;
}
.icon-btn:hover { color: var(--text-bright); background: var(--hover); }
.header-status { font-size: 13px; color: var(--muted); }

.messages { flex: 1; overflow-y: auto; padding: 16px 0; min-height: 0; }
.msg-day {
  display: flex; align-items: center; gap: 12px; margin: 12px 16px; color: var(--muted); font-size: 12px; font-weight: 700;
}
.msg-day::before, .msg-day::after { content: ''; flex: 1; height: 1px; background: #3f4147; }
.msg {
  display: flex; gap: 16px; padding: 3px 16px 3px 16px; position: relative;
}
.msg:hover { background: #2e3035; }
.msg .msg-avatar { margin-top: 2px; cursor: pointer; width: 40px; flex: 0 0 auto; }
.msg-body { min-width: 0; flex: 1; }

/* group (compact) messages: same text column as full messages */
.msg.compact { display: flex; gap: 0; padding: 2px 16px 2px 16px; }
.msg.compact .compact-time {
  width: 56px; flex: 0 0 auto; text-align: right; padding-right: 8px;
  font-size: 10px; color: var(--muted); opacity: 0; padding-top: 6px; user-select: none;
  margin-right: 0;
}
.msg:hover .compact-time { opacity: 1; }
.msg.compact .msg-body { margin-left: 0; padding-left: 0; }

/* Discord-style reply reference */
.msg-reply { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 3px; min-width: 0; }
.msg-reply::before { content: ''; display: inline-block; width: 28px; border-top: 2px solid #4e5058; border-left: 2px solid #4e5058; border-radius: 8px 0 0 0; height: 12px; flex: 0 0 auto; margin-left: -2px; }
.msg-reply .r-avatar { width: 16px; height: 16px; font-size: 8px; flex: 0 0 auto; }
.msg-reply .r-name { color: var(--text-bright); font-weight: 600; flex: 0 0 auto; }
.msg-reply .r-text { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.compact .msg-reply::before { width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-author { font-weight: 600; color: var(--text-bright); cursor: pointer; font-size: 15px; }
.msg-author:hover { text-decoration: underline; }
.bot-tag {
  background: var(--brand); color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 5px; border-radius: 4px; text-transform: uppercase; vertical-align: middle;
}
.msg-time { color: var(--muted); font-size: 12px; }
.msg-content { color: var(--text); font-size: 15px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; }
.msg-content code {
  background: #1e1f22; border: 1px solid #3f4147; border-radius: 3px; padding: 1px 4px;
  font-family: "Consolas", monospace; font-size: 13px;
}
.msg-content .mention {
  background: var(--mention); color: var(--mention-text); border-radius: 4px; padding: 0 3px; font-weight: 500; cursor: pointer;
}
.msg-content .mention:hover { background: var(--mention-text); color: #1e1f22; }
.msg-content .mention-me { background: rgba(240, 178, 50, .25); color: #f0b232; font-weight: 600; }
.msg-edited { font-size: 10px; color: var(--muted2); margin-left: 4px; }
.msg-embeds { margin-top: 6px; display: flex; flex-direction: column; gap: 6px; }
.msg-embeds img { max-width: 360px; max-height: 300px; border-radius: 8px; display: block; }
.msg-actions {
  position: absolute; top: -14px; right: 16px; display: none; gap: 2px;
  background: var(--input); border: 1px solid #26272b; border-radius: 6px; padding: 3px;
  box-shadow: 0 2px 8px rgba(0,0,0,.3); z-index: 5;
}
.msg:hover .msg-actions { display: flex; }
.msg-act {
  width: 30px; height: 30px; border-radius: 4px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 15px;
}
.msg-act:hover { background: var(--active); color: var(--text-bright); }
.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-pill {
  display: flex; align-items: center; gap: 5px; background: var(--input); border: 1px solid transparent;
  border-radius: 8px; padding: 2px 8px; font-size: 13px; color: var(--muted); cursor: pointer;
}
.reaction-pill:hover { border-color: var(--brand); }
.reaction-pill.mine { background: rgba(88, 101, 242, .25); border-color: var(--brand); color: #c9cdfb; }
.reaction-pill .rc { font-weight: 700; }
.msg-edit-area { width: 100%; background: var(--input); border: none; border-radius: 8px; color: var(--text); padding: 10px 12px; font-size: 15px; resize: none; outline: none; }
.msg-edit-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

.typing-bar { height: 24px; flex: 0 0 auto; padding: 0 16px; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.typing-dots { display: inline-flex; gap: 2px; }
.typing-dots span { width: 5px; height: 5px; background: var(--muted); border-radius: 50%; animation: blink 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

.chat-input-wrap { flex: 0 0 auto; padding: 0 16px 24px; }
.chat-input {
  background: var(--input); border-radius: 8px; display: flex; align-items: flex-end; gap: 8px; padding: 4px 12px;
}
.chat-input textarea {
  flex: 1; background: none; border: none; outline: none; resize: none; color: var(--text-bright);
  font-size: 15px; padding: 11px 0; max-height: 200px; line-height: 1.3;
}
.chat-input .ci-btn { color: var(--muted); font-size: 20px; padding: 8px 2px; }
.chat-input .ci-btn:hover { color: var(--text-bright); }
.chat-input .send-btn { color: var(--brand); }

/* welcome / placeholder */
.placeholder {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 24px; gap: 12px; color: var(--muted);
}
.placeholder .big { font-size: 64px; }
.placeholder h2 { color: var(--text-bright); }

/* ============ Members panel ============ */
.members { background: var(--sidebar); overflow-y: auto; padding: 16px 8px; }
.members.hidden-panel { display: none; }
.member-group { margin-bottom: 16px; }
.member-group-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); padding: 0 8px 4px;
}
.member {
  display: flex; align-items: center; gap: 12px; padding: 5px 8px; border-radius: 4px; cursor: pointer;
}
.member:hover { background: var(--hover); }
.member .m-name { font-size: 15px; font-weight: 500; color: #c4c9ce; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.member.offline .m-name, .member.offline .avatar { opacity: .4; }
.member .m-status { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .m-info { min-width: 0; }

/* ============ Modals & popovers ============ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--card); border-radius: 12px; padding: 24px; width: 460px; max-width: 100%;
  box-shadow: 0 12px 40px rgba(0,0,0,.5); max-height: 90vh; overflow-y: auto;
}
.modal h2 { color: var(--text-bright); font-size: 22px; text-align: center; }
.modal .modal-sub { color: var(--muted); text-align: center; margin: 6px 0 18px; font-size: 14px; }
.modal h3 { color: var(--text-bright); font-size: 15px; margin: 20px 0 8px; text-align: center; }
.modal label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin: 14px 0 6px; }
.modal .input { background: #1e1f22; }
.modal .btn-primary, .modal .btn-secondary, .modal .btn-danger { width: 100%; margin-top: 14px; }
.modal .modal-row { display: flex; gap: 10px; }
.modal .modal-row > * { flex: 1; }
.type-switch { display: flex; gap: 8px; margin-top: 6px; }
.type-switch button {
  flex: 1; padding: 10px; border-radius: 6px; background: #1e1f22; color: var(--muted);
  font-weight: 600; font-size: 14px; border: 1px solid transparent;
}
.type-switch button.sel { border-color: var(--brand); color: var(--text-bright); background: rgba(88,101,242,.15); }

.invite-code {
  background: #1e1f22; border-radius: 6px; padding: 12px; display: flex; align-items: center; gap: 10px; margin-top: 8px;
}
.invite-code code { flex: 1; font-size: 18px; font-weight: 700; color: var(--text-bright); letter-spacing: 1px; }
.user-list { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; max-height: 320px; overflow-y: auto; }
.user-list .member { padding: 8px; }

.profile-head { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.profile-head .avatar { width: 80px; height: 80px; font-size: 28px; }
.profile-head .p-name { font-size: 20px; font-weight: 700; color: var(--text-bright); display: flex; align-items: center; gap: 8px; }
.profile-head .p-bio { color: var(--muted); font-size: 14px; }
.profile-card {
  background: var(--brand); height: 70px; border-radius: 8px 8px 0 0; margin: -24px -24px 0;
}
.profile-body { padding-top: 40px; margin-top: -40px; position: relative; }

.popover {
  position: fixed; z-index: 300; background: #111214; border-radius: 8px; padding: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); min-width: 180px;
}
.popover-item {
  width: 100%; text-align: left; padding: 8px 10px; border-radius: 4px; font-size: 14px; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.popover-item:hover { background: var(--brand); color: #fff; }
.popover-item.danger { color: var(--red); }
.popover-item.danger:hover { background: var(--red); color: #fff; }
.popover-sep { height: 1px; background: #2b2d31; margin: 4px 6px; }
.popover-item .dot { width: 10px; height: 10px; border-radius: 50%; }

/* toasts */
#toasts { position: fixed; bottom: 20px; left: 20px; z-index: 400; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #111214; color: var(--text-bright); padding: 12px 18px; border-radius: 8px;
  font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
  transform: translateX(-120%); transition: transform .25s ease; border-left: 4px solid var(--brand);
  max-width: 320px;
}
.toast.show { transform: translateX(0); }

/* emoji picker */
.emoji-picker {
  position: absolute; background: var(--input); border-radius: 8px; padding: 6px; display: flex; gap: 2px;
  box-shadow: 0 4px 16px rgba(0,0,0,.4); z-index: 50;
}
.emoji-picker button { font-size: 18px; padding: 4px 6px; border-radius: 4px; }
.emoji-picker button:hover { background: var(--active); }

/* ============ Rail DM unread badge ============ */
.rail-badge {
  position: absolute; bottom: -3px; right: -3px; background: var(--red); color: #fff;
  font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px; border: 3px solid var(--rail);
}

/* ============ Message attachments & link embeds ============ */
.msg-attachments { margin-top: 6px; display: flex; flex-direction: column; gap: 6px; }
.msg-attachments img { max-width: 400px; max-height: 320px; border-radius: 8px; display: block; cursor: pointer; }
.att-video { max-width: 420px; max-height: 340px; border-radius: 8px; background: #000; }
.att-file {
  display: flex; align-items: center; gap: 12px; background: var(--input); border-radius: 8px;
  padding: 12px 14px; max-width: 380px; color: var(--text); border: 1px solid #26272b;
}
.att-file:hover { background: var(--active); text-decoration: none; }
.att-file-ic { font-size: 26px; }
.att-file-info { display: flex; flex-direction: column; min-width: 0; }
.att-file-name { color: #00a8fc; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-file-meta { font-size: 12px; color: var(--muted); }
.att-file-dl { margin-left: auto; font-size: 18px; color: var(--muted); }
.msg-handle, .m-handle { font-size: 12px; color: var(--muted); font-weight: 400; }
.msg-handle { margin-left: -4px; }

.msg-embeds2 { margin-top: 6px; display: flex; flex-direction: column; gap: 6px; }
.link-embed {
  display: flex; gap: 0; background: var(--input); border-left: 4px solid var(--brand);
  border-radius: 4px; max-width: 520px; overflow: hidden;
}
.link-embed .le-main { padding: 10px 14px; min-width: 0; flex: 1; }
.link-embed .le-site { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.link-embed .le-title { color: #00a8fc; font-weight: 600; font-size: 14px; display: block; margin-bottom: 4px; }
.link-embed .le-desc { font-size: 13px; color: var(--text); line-height: 1.35; }
.link-embed .le-thumb { width: 140px; object-fit: cover; flex: 0 0 auto; }

/* ============ Attach bar (pending uploads) ============ */
.chat-input-wrap-inner { display: flex; flex-direction: column; }
.attach-bar { display: none; gap: 8px; flex-wrap: wrap; padding: 10px 12px 0; }
.attach-bar.open { display: flex; }
.attach-chip {
  display: flex; align-items: center; gap: 8px; background: var(--input); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; max-width: 260px;
}
.attach-chip .ac-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--text-bright); }
.attach-chip .ac-size { color: var(--muted); font-size: 11px; flex: 0 0 auto; }
.attach-chip .ac-x { color: var(--muted); padding: 2px 6px; border-radius: 4px; }
.attach-chip .ac-x:hover { background: var(--active); color: #fff; }
.chat-input #gif-btn { font-size: 12px; font-weight: 800; padding: 8px 4px; color: var(--muted); }
.chat-input #gif-btn:hover { color: var(--text-bright); }

/* GIF picker */
.gif-picker { width: 360px; padding: 0; overflow: hidden; }
.gif-head { padding: 10px; background: #111214; }
.gif-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 10px; max-height: 340px; overflow-y: auto; background: #1e1f22; }
.gif-item { padding: 0; border-radius: 6px; overflow: hidden; background: #2b2d31; aspect-ratio: 1; }
.gif-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gif-item:hover { outline: 2px solid var(--brand); }
.gif-loading { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 24px; font-size: 13px; }

/* ============ Discord-style call control bar ============ */
.dc-controls {
  position: relative; z-index: 5; display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 14px 20px 22px;
}
.dc-wrap { display: flex; align-items: stretch; height: 52px; border-radius: 26px; overflow: hidden; background: rgba(30,31,34,.85); }
.dc-wrap:hover { background: rgba(30,31,34,1); }
.dc-wrap.active { background: #fff; color: #111; }
.dc-wrap.active .dc-btn, .dc-wrap.active .dc-caret { color: #f23f43; }
.dc-wrap.danger .dc-btn { background: var(--red); color: #fff; border-radius: 26px; }
.dc-wrap.danger:hover .dc-btn { background: #d2353a; }
.dc-btn {
  width: 52px; height: 52px; border-radius: 26px; display: flex; align-items: center; justify-content: center;
  color: #fff; transition: background .15s;
}
.dc-btn svg { width: 24px; height: 24px; }
.dc-wrap.danger .dc-btn svg { width: 26px; height: 26px; transform: rotate(135deg); }
.dc-btn span { font-size: 12px; font-weight: 600; }
.dc-caret {
  width: 30px; display: flex; align-items: center; justify-content: center; color: #fff;
  border-left: 1px solid rgba(255,255,255,.15);
}
.dc-caret svg { width: 14px; height: 14px; }
.dc-wrap.active .dc-caret { border-left-color: rgba(0,0,0,.2); color: #f23f43; }
.dev-popover { min-width: 260px; max-height: 320px; overflow-y: auto; }
.dev-popover .dev-title { padding: 6px 10px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.popover-item.sel { color: #fff; background: rgba(88,101,242,.3); }
.popover-item.sel::after { content: '✓'; margin-left: auto; color: var(--green); }
/* ============ Call overlays (1:1 + group) ============ */
.call-bg.dark { opacity: 1; filter: brightness(.35) saturate(.7); }
.gcall-top { position: relative; z-index: 5; display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; color: #fff; }
.gcall-title { font-weight: 700; font-size: 16px; }
.gcall-count { font-weight: 500; color: rgba(255,255,255,.7); font-size: 14px; margin-left: 8px; }
.gcall-pop { background: rgba(255,255,255,.14); padding: 8px 14px; border-radius: 6px; font-size: 13px; font-weight: 600; color: #fff; }
.gcall-pop:hover { background: rgba(255,255,255,.25); }
.gcall-body { position: relative; z-index: 4; flex: 1; min-height: 0; padding: 0 22px; display: flex; }
/* Самоадаптивная сетка: число колонок и размер ячеек
   вычисляются в JS (layoutCallStage), чтобы все плитки
   влезали в доступное место и не перекрывались. */
.call-grid {
  display: grid;
  gap: 10px;
  align-content: start;
  justify-content: center;
  overflow-y: auto;
  min-height: 0;
  padding: 4px;
  width: 100%;
}

/* Плитки масштабируются по ширине колонки, сохраняя 16:9 */
.call-grid .video-tile,
.call-grid .avatar-tile {
  width: 100%;
  height: auto;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  box-sizing: border-box;
}
.call-grid .video-tile video,
.call-grid .avatar-tile { max-width: 100%; }

/* Демка — отдельная обычная плитка в общей сетке */
.call-grid .video-tile.is-screen {
  grid-column: auto;
  min-height: 0;
}
.video-tile .vt-label {
  position: absolute; left: 10px; bottom: 10px; background: rgba(0,0,0,.65); color: #fff;
  font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 6px;
}
.live-badge {
  position: absolute; left: 10px; top: 10px; background: var(--red); color: #fff;
  font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 6px; letter-spacing: .5px;
}
/* speaking indicator: green ring on tiles & avatars */
.video-tile.speaking { box-shadow: 0 0 0 3px var(--green), 0 0 18px rgba(35,165,89,.5); }
.avatar-tile.speaking { box-shadow: inset 0 0 0 3px var(--green), 0 0 18px rgba(35,165,89,.4); }
.call-avatar-block.speaking .call-avatar { box-shadow: 0 0 0 4px var(--green), 0 0 30px rgba(35,165,89,.6); }
.avatar-tile {
  position: relative; background: var(--brand); border-radius: 12px; overflow: hidden;
  min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
}
.avatar-tile .at-name { color: #fff; font-weight: 700; font-size: 17px; text-shadow: 0 1px 3px rgba(0,0,0,.5); }
.avatar-tile .at-muted {
  position: absolute; bottom: 10px; right: 10px; background: var(--red); color: #fff;
  width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.at-ava .avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

/* ============ Compact 1:1 call popup (does NOT block the app) ============ */
.call-popup {
  position: fixed; right: 22px; bottom: 22px; z-index: 550; width: 340px;
  background: #1e1f22; border-radius: 14px; overflow: hidden;
  box-shadow: 0 16px 50px rgba(0,0,0,.6); border: 1px solid #000;
  display: flex; flex-direction: column;
  animation: popIn .2s ease;
}
@keyframes popIn { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.pop-header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: #111214; }
.pop-who { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.pop-ava .avatar { width: 30px; height: 30px; font-size: 12px; }
.pop-name { font-weight: 700; color: var(--text-bright); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-timer { color: var(--muted); font-size: 12px; margin-left: auto; flex: 0 0 auto; }
.pop-x { color: var(--muted); width: 26px; height: 26px; border-radius: 6px; font-size: 14px; }
.pop-x:hover { background: var(--active); color: #fff; }
.pop-video { position: relative; height: 230px; background: #000; display: flex; align-items: center; justify-content: center; }
.pop-video .video-tile { position: static; min-height: 0; border-radius: 0; width: 100%; height: 100%; }
.pop-video .video-tile.pop-main { display: flex; }
.pop-video .video-tile.pop-pip {
  position: absolute; right: 10px; bottom: 10px; width: 96px; height: 70px; z-index: 6;
  border-radius: 8px; border: 2px solid rgba(255,255,255,.25); box-shadow: 0 6px 20px rgba(0,0,0,.6);
}
.pop-video.has-media .pop-avatar { display: none; }
.pop-avatar { width: 110px; height: 110px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: box-shadow .12s; }
.pop-avatar .avatar { width: 96px; height: 96px; font-size: 34px; }
.pop-avatar.speaking { box-shadow: 0 0 0 4px var(--green), 0 0 26px rgba(35,165,89,.6); }
.pop-video .video-tile.speaking { box-shadow: inset 0 0 0 3px var(--green); }
.pop-controls { background: #1e1f22; padding: 10px; display: flex; justify-content: center; }
.mini-controls { display: flex; gap: 10px; }
.mini-call-btn {
  width: 42px; height: 42px; border-radius: 50%; background: #2b2d31; color: #dbdee1;
  display: flex; align-items: center; justify-content: center; transition: background .15s, color .15s;
}
.mini-call-btn svg { width: 20px; height: 20px; }
.mini-call-btn:hover { background: #404249; color: #fff; }
.mini-call-btn.off, .mini-call-btn.on { background: #fff; color: #f23f43; }
.mini-call-btn.hangup { background: var(--red); color: #fff; transform: rotate(0deg); }
.mini-call-btn.hangup svg { transform: rotate(135deg); }
.mini-call-btn.hangup:hover { background: #d2353a; }
.call-popup.ringing { width: 300px; }
.call-popup.ringing .pop-video { height: 150px; }
.call-popup.ringing .pop-avatar { width: 84px; height: 84px; }
.call-popup.ringing .pop-avatar .avatar { width: 72px; height: 72px; }

/* ============ Inline (docked) 1:1 call — shown at the top of the DM you're viewing, like Discord ============ */
.dm-call-dock {
  position: relative; background: #000; flex: 0 0 auto; display: flex; flex-direction: column;
  min-height: 260px; max-height: 46vh; border-bottom: 1px solid #000;
}
.dm-call-dock .pop-video { flex: 1; min-height: 0; height: auto; }
.dm-call-dock .dock-top {
  position: absolute; top: 12px; left: 14px; z-index: 6; color: #fff; display: flex; align-items: baseline; gap: 8px;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
}
.dm-call-dock .dock-name { font-weight: 700; font-size: 15px; }
.dm-call-dock .dock-timer { font-size: 12px; opacity: .75; }
.dm-call-dock .dock-pop {
  position: absolute; top: 10px; right: 14px; z-index: 6; background: rgba(255,255,255,.14); color: #fff;
  border-radius: 6px; padding: 5px 9px; font-size: 12px; font-weight: 600;
}
.dm-call-dock .dock-pop:hover { background: rgba(255,255,255,.25); }

/* ============ Inline voice-channel view (clicking a voice channel opens its call, like real Discord) ============ */
.voice-view {
  flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative;
  background: radial-gradient(1200px 600px at 50% -10%, #3a3d6b 0%, transparent 55%), var(--chat);
}
.voice-view .call-grid { flex: 1; padding: 22px; }
.voice-view-cta { display: flex; gap: 12px; justify-content: center; padding: 0 22px 18px; }
.voice-cta {
  background: rgba(255,255,255,.08); color: #fff; font-weight: 600; font-size: 14px;
  padding: 10px 18px; border-radius: 8px; display: flex; align-items: center; gap: 8px;
}
.voice-cta:hover { background: rgba(255,255,255,.16); }
.voice-cta:disabled { opacity: .5; cursor: default; }
.voice-cta:disabled:hover { background: rgba(255,255,255,.08); }
.voice-view-extra { position: absolute; right: 18px; bottom: 88px; display: flex; gap: 8px; }
.ve-btn {
  width: 36px; height: 36px; border-radius: 8px; background: rgba(0,0,0,.4); color: #fff; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.ve-btn:hover { background: rgba(0,0,0,.6); }

/* ============ Lightbox ============ */
.lightbox {
  position: fixed; inset: 0; z-index: 900; background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center; padding: 40px;
}
.lightbox img { max-width: 95vw; max-height: 92vh; border-radius: 8px; box-shadow: 0 10px 60px rgba(0,0,0,.7); }
.lb-close, .lb-open {
  position: fixed; top: 20px; width: 44px; height: 44px; border-radius: 50%;
  background: #2b2d31; color: #fff; font-size: 18px; display: flex; align-items: center; justify-content: center;
}
.lb-close { right: 20px; } .lb-open { right: 74px; }
.lb-close:hover, .lb-open:hover { background: var(--red); }

/* ============ Drag & drop overlay ============ */
body.drag-over::after {
  content: '📎 Отпустите, чтобы отправить файлы';
  position: fixed; inset: 12px; z-index: 800; border: 3px dashed var(--brand); border-radius: 16px;
  background: rgba(88,101,242,.15); color: #fff; font-size: 22px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; pointer-events: none;
}

/* ============ Audio attachments ============ */
.att-audio { display: flex; align-items: center; gap: 10px; background: var(--input); border-radius: 8px; padding: 10px 14px; max-width: 420px; }
.att-audio audio { flex: 1; height: 36px; min-width: 200px; }
.att-img-link { padding: 0; border: none; background: none; cursor: zoom-in; display: block; }
.att-img-link img { transition: filter .12s; }
.att-img-link:hover img { filter: brightness(.92); }

/* avatar images inside various call UIs */
.call-avatar .avatar-img, .call-avatar img, .inc-avatar img, .at-ava img, .avatar img.avatar-img {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover;
}

/* ============ Settings overlay ============ */
.settings-overlay {
  position: fixed; inset: 0; z-index: 700; background: var(--chat);
  display: flex; align-items: stretch; justify-content: center; overflow: hidden;
}
.settings-wrap {
  display: flex; width: 100%; max-width: 1100px; position: relative; min-height: 0;
}
.settings-nav {
  flex: 0 0 220px; background: var(--sidebar); padding: 60px 12px 40px; overflow-y: auto;
}
.settings-nav-group { font-size: 11px; font-weight: 800; color: var(--muted); padding: 8px 10px; text-transform: uppercase; }
.settings-tab {
  width: 100%; text-align: left; padding: 8px 10px; border-radius: 4px; color: var(--muted);
  font-size: 15px; font-weight: 500; margin-bottom: 2px;
}
.settings-tab:hover { background: var(--hover); color: var(--text-bright); }
.settings-tab.sel { background: var(--brand); color: #fff; }
.settings-tab.danger { color: var(--red); }
.settings-tab.danger:hover { background: var(--red); color: #fff; }
.settings-nav-sep { height: 1px; background: #3f4147; margin: 10px 8px; }
.settings-content { flex: 1; padding: 60px 40px 40px; overflow-y: auto; max-width: 680px; }
.settings-h1 { color: var(--text-bright); font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.settings-sub { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.settings-close {
  position: fixed; top: 16px; right: 20px; width: 38px; height: 38px; border-radius: 50%;
  background: #2b2d31; color: #fff; font-size: 16px; border: 3px solid var(--chat);
}
.settings-close:hover { background: var(--red); }
.settings-content .input { background: #1e1f22; }
.settings-content textarea.input { resize: vertical; }

.acct-card { background: var(--sidebar); border-radius: 10px; padding: 0 0 18px; margin-top: 24px; }
.acct-banner { height: 90px; border-radius: 10px 10px 0 0; background: var(--brand); }
.acct-row { display: flex; align-items: flex-end; gap: 16px; padding: 0 16px; margin-top: -34px; }
.acct-ava .avatar { border: 6px solid var(--sidebar); }
.acct-info { padding-bottom: 6px; min-width: 0; }
.acct-name { font-weight: 800; color: var(--text-bright); font-size: 18px; }
.acct-handle { color: var(--muted); font-size: 14px; }
.acct-card .field-label, .acct-card .input, .acct-card button, .acct-card .f-hint { margin-left: 16px; margin-right: 16px; width: calc(100% - 32px); }

.set-banner-row { position: relative; margin-bottom: 50px; }
.set-banner { height: 120px; border-radius: 10px; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.set-banner img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: blur(6px) brightness(.7); transform: scale(1.1); }
.set-banner-btn { position: relative; z-index: 2; background: rgba(0,0,0,.55); color: #fff; padding: 8px 14px; border-radius: 6px; font-size: 13px; font-weight: 600; }
.set-banner-btn:hover { background: rgba(0,0,0,.8); }
.set-ava { position: absolute; left: 18px; bottom: -40px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.set-ava .avatar { border: 6px solid var(--chat); }
.set-ava-btn { background: rgba(0,0,0,.6); color: #fff; font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 4px; }
.set-ava-btn:hover { background: rgba(0,0,0,.85); }
.color-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.color-dot { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.color-dot.sel { border-color: #fff; box-shadow: 0 0 0 2px var(--brand); }

.token-box { background: var(--sidebar); border-radius: 10px; padding: 16px; margin-top: 16px; }
.token-row { display: flex; gap: 10px; align-items: center; }
.token-row code {
  flex: 1; background: #1e1f22; border-radius: 6px; padding: 10px 12px; font-size: 13px;
  color: var(--text-bright); word-break: break-all; font-family: "Consolas", monospace;
}
.token-row .btn-secondary { width: auto; margin: 0; flex: 0 0 auto; }
.token-box .btn-danger { width: 100%; }

/* ============ Profile popout ============ */
.modal.profile-modal { width: 420px; padding: 0; background: var(--sidebar); border-radius: 12px; overflow: hidden; }
.p-popout { }
.p-banner { height: 110px; background: var(--brand); position: relative; overflow: hidden; }
.p-banner-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: blur(8px) brightness(.7); transform: scale(1.15); }
.p-top { padding: 0 16px; margin-top: -40px; position: relative; }
.p-avatar .avatar { border: 8px solid var(--sidebar); }
.p-card-body { padding: 10px 16px 18px; }
.p-name-row { display: flex; align-items: center; gap: 8px; }
.p-display { font-size: 20px; font-weight: 800; color: var(--text-bright); }
.p-handle { color: var(--muted); font-size: 14px; font-weight: 500; }
.p-divider { height: 1px; background: #3f4147; margin: 14px 0; }
.p-section-title { font-size: 11px; font-weight: 800; color: var(--muted); letter-spacing: .5px; margin-bottom: 6px; }
.p-bio-text { color: var(--text); font-size: 14px; line-height: 1.4; margin-bottom: 14px; }
.p-empty { color: var(--muted2); font-style: italic; }
.p-actions { display: flex; gap: 8px; margin-top: 12px; }
.p-actions button { flex: 1; width: auto; margin-top: 0; }
.dot-inline { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--green); margin-right: 6px; }
.dot-inline.idle { background: var(--yellow); } .dot-inline.dnd { background: var(--red); } .dot-inline.offline { background: #80848e; }

/* dm top row */
.dm-top-row { display: flex; gap: 6px; align-items: center; padding: 8px 8px 0; }
.dm-top-row .dm-search { margin: 0; flex: 1; }
.dm-new-btn { background: var(--input); border-radius: 4px; width: 34px; height: 32px; color: var(--muted); font-size: 16px; flex: 0 0 auto; }
.dm-new-btn:hover { background: var(--active); color: var(--text-bright); }

@media (max-width: 900px) {
  .app { grid-template-columns: 72px 220px 1fr; }
  .members { display: none; }
  .call-grid { grid-template-columns: 1fr; }
}

/* ============ Video-tile fixes: Discord-like sizing ============
   Раньше у .video-tile не было базовых правил — <video> рисовался
   в натуральном размере и плитки «кривились». Теперь: видео всегда
   заполняет плитку; камера — object-fit: cover (как в Discord),
   экран/демка — contain (весь экран виден, с полосами) */
.video-tile {
  position: relative;
  background: #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.video-tile video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.video-tile.is-screen video { object-fit: contain; }

/* плитки-аватары в сетке канала: не форсим min-height 180px,
   иначе они «выпирают» из ячеек 16:9, посчитанных в JS */
.call-grid .video-tile,
.call-grid .avatar-tile { min-height: 0; }
.call-grid .avatar-tile {
  background: linear-gradient(180deg, rgba(0,0,0,.28), rgba(0,0,0,0) 55%), var(--brand);
  gap: clamp(4px, calc(var(--cell-w, 560px) * .02), 12px);
}
/* аватар и имя в плитке подстраиваются под ширину ячейки (--cell-w из layoutCallStage) */
.call-grid .avatar-tile .at-ava { line-height: 0; }
.call-grid .avatar-tile .at-ava .avatar {
  width: min(72px, calc(var(--cell-w, 560px) * .40)) !important;
  height: min(72px, calc(var(--cell-w, 560px) * .40)) !important;
  font-size: calc(min(72px, var(--cell-w, 560px) * .40) * .36) !important;
  background-clip: padding-box;
}
.call-grid .avatar-tile .at-name {
  font-size: clamp(10px, calc(var(--cell-w, 560px) * .045), 17px);
  max-width: 92%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 1:1-звонок: главная плитка занимает всю сцену, PiP — поверх */
.pop-video { overflow: hidden; }
.pop-video .video-tile { width: 100%; height: 100%; }
.pop-video .video-tile.pop-main { display: flex; }
/* своя демка-экран в PiP: широкий 16:9, как превью экрана в Discord */
.pop-video .video-tile.pop-pip { width: 96px; height: 70px; }
.pop-video .video-tile.pop-pip.is-screen { width: 152px; height: 86px; border-radius: 8px; }
.pop-video .video-tile.pop-pip video { object-fit: cover; }
.pop-video .video-tile.pop-pip.is-screen video { object-fit: contain; }
/* имя/бейдж внутри маленького PiP скрываем, чтобы не мешали */
.pop-video .video-tile.pop-pip .vt-label { display: none; }
.pop-video .video-tile.pop-pip .live-badge {
  left: 4px; top: 4px; font-size: 9px; padding: 2px 6px;
}

/* ============ Свой аватар-превью в углу 1:1-звонка ============
   Когда своя камера/экран выключены — в углу окна звонка показываем
   свой аватар (как в Discord: собеседник по центру, вы — в углу) */
.pop-self-ava {
  position: absolute; right: 10px; bottom: 10px; z-index: 7;
  width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: #1e1f22;
  box-shadow: 0 4px 14px rgba(0,0,0,.55);
}
.pop-self-ava .psa-ava { line-height: 0; display: flex; }
.pop-self-ava .avatar { box-shadow: 0 0 0 3px rgba(255,255,255,.18); }
.pop-self-ava .psa-mic {
  position: absolute; right: -4px; bottom: -2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--red); border: 2px solid #1e1f22;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; line-height: 1;
}
/* при выключенной камере свой аватар не должен перекрывать кнопки демки в 1:1-сцене */
.pop-video .video-tile.pop-main { padding-right: 0; }

/* ============ Дуо-аватары в 1:1-звонке без видео ============
   Как в Discord: у обоих камера выключена — два одинаковых круглых
   аватара стоят рядом по центру сцены звонка */
.pop-duo {
  position: absolute; inset: 0; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  gap: clamp(16px, 6vw, 40px);
}
.pop-circle {
  width: 108px; height: 108px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; position: relative;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  transition: box-shadow .12s;
}
.pop-circle .avatar {
  width: 94px; height: 94px; font-size: 32px;
  box-shadow: 0 0 0 3px rgba(0,0,0,.3);
}
.pop-circle.speaking {
  box-shadow: 0 0 0 4px var(--green), 0 0 26px rgba(35,165,89,.6);
}
.pop-circle .psa-mic {
  position: absolute; right: -2px; bottom: -2px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--red); border: 3px solid rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; line-height: 1;
}
.pop-video.has-media .pop-duo { display: none; }
/* компактное окно ринга: аватары чуть меньше */
.call-popup.ringing .pop-circle { width: 84px; height: 84px; }
.call-popup.ringing .pop-circle .avatar { width: 72px; height: 72px; font-size: 26px; }

/* ============ Зелёное кольцо говорящего — как в голосовом канале ============
   На сервере кольцо рисуется по самому аватару (.avatar.ring).
   Здесь делаем так же: снимаем внешнее свечение с круга/заглушки
   и рисуем обводку вокруг аватара собеседника */
.pop-video .pop-avatar.speaking,
.pop-video .pop-circle.speaking { box-shadow: none; }
.pop-video .pop-avatar.speaking .avatar,
.pop-video .pop-circle.speaking:not(.self) .avatar {
  box-shadow: 0 0 0 3px var(--green), 0 0 16px rgba(35,165,89,.55);
}

/* ============ RTC-статус звонка ============
   Панель «над профилем» в сайдбаре — как панель «Голос подключён» на сервере,
   но с состоянием соединения: RTC: соединяемся… / подключено / нет соединения */
.rtc-state {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--muted);
}
.rtc-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; flex: 0 0 auto; }
.rtc-state.ok { color: var(--green); }
.rtc-state.ok .rtc-dot { background: var(--green); }
.rtc-state.bad { color: var(--red); }
.rtc-state.bad .rtc-dot { background: var(--red); }
.rtc-state.wait { color: var(--yellow); }
.rtc-state.wait .rtc-dot { background: var(--yellow); animation: rtcBlink 1s infinite; }
@keyframes rtcBlink { 50% { opacity: .35; } }
.call-panel { border-top: 1px solid rgba(255,255,255,.06); }
.call-panel .vp-title { color: var(--text-bright); }
.call-panel .vp-btn.disconnect:hover { background: var(--red); color: #fff; }

/* чип статуса соединения в окне звонка (над аватарами, пока идёт подключение) */
.call-rtc-chip {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 9;
  background: rgba(0,0,0,.72); color: #fff; font-size: 12px; font-weight: 600;
  padding: 5px 12px; border-radius: 12px; pointer-events: none; white-space: nowrap;
}
.call-rtc-chip.failed { color: #ff8083; }
.call-rtc-chip.disconnected { color: var(--yellow); }
