:root {
  --bg-chat: #313338;
  --bg-side: #2b2d31;
  --bg-panel: #232428;
  --bg-input: #383a40;
  --bg-hover: #35373c;
  --text: #dbdee1;
  --text-muted: #949ba4;
  --text-strong: #f2f3f5;
  --accent: #5865f2;
  --green: #23a55a;
  --yellow: #f0b232;
  --red: #f23f43;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-chat);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.hidden { display: none !important; }

svg {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Вход ---------- */

.login {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 16px;
  background: var(--accent);
}
.login-card {
  width: 100%; max-width: 380px;
  padding: 28px;
  border-radius: 8px;
  background: var(--bg-chat);
  display: flex; flex-direction: column; gap: 16px;
}
.login-card h1 { margin: 0; text-align: center; color: var(--text-strong); font-size: 22px; }
.login-card label {
  display: flex; flex-direction: column; gap: 8px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-muted);
}
.login-card input {
  padding: 10px; border: 0; border-radius: 4px;
  background: #1e1f22; color: var(--text); font-size: 16px;
}
.login-card button[type=submit] {
  padding: 11px; border-radius: 4px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.login-card button[type=submit]:hover { filter: brightness(1.1); }
.error { color: var(--red); font-size: 14px; min-height: 1em; }

/* ---------- Каркас ---------- */

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

.sidebar {
  width: 260px; flex: none;
  display: flex; flex-direction: column;
  background: var(--bg-side);
}
.sidebar-header {
  height: 48px; padding: 0 16px;
  display: flex; align-items: center;
  font-weight: 600; color: var(--text-strong);
  box-shadow: 0 1px 0 rgba(0,0,0,.25);
}
.channels { flex: 1; overflow-y: auto; padding: 12px 8px; }

.channel {
  width: 100%; padding: 6px 8px; border-radius: 4px;
  display: flex; align-items: center; gap: 6px;
  color: var(--text-muted); text-align: left; font-weight: 500;
}
.channel:hover { background: var(--bg-hover); color: var(--text); }
.channel.active { color: var(--text-strong); }

.section-title {
  margin: 20px 8px 4px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-muted);
}

.members { list-style: none; margin: 0; padding: 0; }
#voice-members { padding-left: 28px; }
.member {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px; border-radius: 4px;
  color: var(--text-muted);
}
.member:hover { background: var(--bg-hover); }
.member .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member.me .name { color: var(--text); }
.member .badges { display: flex; gap: 2px; color: var(--text-muted); }
.member .badges svg { width: 16px; height: 16px; }
.member .ping { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.member .ping.bad { color: var(--yellow); }
.member .ping.down { color: var(--red); }

.avatar {
  width: 32px; height: 32px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 14px;
  box-shadow: 0 0 0 2px transparent;
  transition: box-shadow .1s;
}
.member .avatar { width: 24px; height: 24px; font-size: 11px; }
.avatar.speaking { box-shadow: 0 0 0 2px var(--bg-side), 0 0 0 4px var(--green); }

/* ---------- Нижние панели ---------- */

.voice-panel {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 8px 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid #1e1f22;
}
.voice-info { flex: 1; min-width: 0; }
.voice-status { font-size: 13px; font-weight: 600; color: var(--yellow); }
.voice-status.ok { color: var(--green); }
.voice-ping { font-size: 12px; color: var(--text-muted); }

.user-panel {
  display: flex; align-items: center; gap: 4px;
  padding: 8px;
  background: var(--bg-panel);
}
.me-name {
  flex: 1; min-width: 0; padding: 4px 6px; border-radius: 4px;
  text-align: left; font-weight: 600; color: var(--text-strong);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.me-name:hover { background: var(--bg-hover); }

.icon-btn {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 4px; color: var(--text-muted);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn .slash { display: none; }
.icon-btn.off { color: var(--red); }
.icon-btn.off .slash { display: inline; }
.icon-btn.danger:hover { color: var(--red); }

/* ---------- Трансляция экрана ---------- */

.voice-panel { flex-wrap: wrap; }
.share-row { flex-basis: 100%; display: flex; gap: 6px; }
.share-btn {
  flex: 1; min-width: 0; height: 32px; padding: 0 10px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--bg-input); color: var(--text); font-size: 13px; font-weight: 600;
}
.share-btn:hover:not(:disabled) { background: #404249; }
.share-btn:disabled { opacity: .5; cursor: default; }
.share-btn.on { background: var(--red); color: #fff; }
.share-btn svg { width: 18px; height: 18px; }
#share-quality {
  height: 32px; padding: 0 6px; border: 0; border-radius: 4px;
  background: var(--bg-input); color: var(--text); font: inherit; font-size: 13px;
}

.live {
  padding: 1px 5px; border-radius: 4px;
  background: var(--red); color: #fff; font-size: 10px; font-weight: 700; letter-spacing: .03em;
}
.live:hover { filter: brightness(1.15); }
.live.watching { background: var(--accent); }

.stage {
  flex: 1 1 62%; min-height: 0;
  display: flex; flex-direction: column;
  background: #000;
}
.stage-head {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px 6px 16px;
  background: var(--bg-panel); color: var(--text-strong); font-weight: 600;
}
.stage-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex: none; }
.stage-body { position: relative; flex: 1; min-height: 0; }
.stage-body video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.stage-wait {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--text-muted);
}
.stage:fullscreen .stage-head { position: absolute; top: 0; left: 0; right: 0; z-index: 1; opacity: 0; transition: opacity .2s; }
.stage:fullscreen:hover .stage-head { opacity: .9; }
.chat.with-stage .messages { flex: 1 1 38%; }

/* ---------- Чат ---------- */

.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-header {
  height: 48px; padding: 0 16px; flex: none;
  display: flex; align-items: center; gap: 6px;
  font-weight: 600; color: var(--text-strong);
  box-shadow: 0 1px 0 rgba(0,0,0,.25);
}
.chat-header .hash { color: var(--text-muted); font-size: 22px; font-weight: 400; }
.conn-status {
  margin-left: auto; padding: 2px 8px; border-radius: 4px;
  background: var(--red); color: #fff; font-size: 12px; font-weight: 600;
}

.messages { flex: 1; overflow-y: auto; padding: 16px 0 8px; }

.day {
  display: flex; align-items: center; gap: 8px;
  margin: 16px 16px 8px;
  font-size: 12px; font-weight: 600; color: var(--text-muted);
}
.day::before, .day::after { content: ""; flex: 1; height: 1px; background: #3f4147; }

.msg { position: relative; padding: 2px 16px 2px 72px; margin-top: 16px; }
.msg.grouped { margin-top: 0; }
.msg:hover { background: #2e3035; }
.msg > .avatar { position: absolute; left: 16px; top: 4px; width: 40px; height: 40px; font-size: 16px; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-name { font-weight: 600; }
.msg-time { font-size: 12px; color: var(--text-muted); }
.msg-hover-time {
  position: absolute; left: 16px; top: 5px; width: 44px;
  text-align: center; font-size: 11px; color: var(--text-muted);
  visibility: hidden;
}
.msg.grouped:hover .msg-hover-time { visibility: visible; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-text a { color: #00a8fc; }

.composer { margin: 0 16px 20px; flex: none; border-radius: 8px; background: var(--bg-input); }
.composer-row { display: flex; align-items: flex-start; padding-left: 6px; }
.composer-row .icon-btn { margin-top: 6px; }
.composer textarea {
  flex: 1; min-width: 0; max-height: 40vh; resize: none;
  padding: 11px 16px 11px 6px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text);
  font: inherit; font-size: 16px; line-height: 1.375;
}
.composer textarea:focus { outline: none; }

.attachments {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 10px 12px; border-bottom: 1px solid #2e3035;
}
.attachment { position: relative; flex: none; }
.attachment img {
  display: block; width: 96px; height: 96px; object-fit: cover;
  border-radius: 6px; background: #1e1f22;
}
.attachment.loading img { opacity: .5; }
.attachment.failed img { outline: 2px solid var(--red); opacity: .5; }
.attachment-del {
  position: absolute; top: -6px; right: -6px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--red); color: #fff; font-size: 16px; line-height: 20px;
}

.msg-images { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.msg-images img {
  display: block; max-width: 100%; object-fit: cover;
  border-radius: 6px; background: #2b2d31; cursor: zoom-in;
}
.img-removed {
  padding: 8px 12px; border-radius: 6px;
  background: #2b2d31; color: var(--text-muted); font-size: 13px; font-style: italic;
}

.chat.drop { outline: 3px dashed var(--accent); outline-offset: -8px; }

.lightbox {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, .85);
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: calc(100vh - 80px); object-fit: contain; }
.lightbox-open { position: absolute; bottom: 16px; color: var(--text-muted); font-size: 14px; }
.lightbox-open:hover { color: var(--text); }

/* ---------- Телефон ---------- */

@media (max-width: 700px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; max-height: 45vh; }
  .sidebar-header { display: none; }
  .channels { padding: 8px; }
  .msg { padding-left: 60px; }
  .msg > .avatar { left: 12px; width: 36px; height: 36px; }
  .composer { margin: 0 12px 12px; }
  .stage { flex-basis: 45%; }
}

/* ---------- Упоминания и эмодзи ---------- */

.mention {
  padding: 0 2px; border-radius: 3px;
  background: rgba(88, 101, 242, .3); color: #c9cdfb; font-weight: 500;
}
.mention.me { background: rgba(240, 178, 50, .25); color: #f7d58a; }
.msg.mentioned { background: rgba(240, 178, 50, .08); box-shadow: inset 2px 0 0 var(--yellow); }
.msg.mentioned:hover { background: rgba(240, 178, 50, .12); }
.msg-text.jumbo { font-size: 44px; line-height: 1.25; }

.composer { position: relative; }

.autocomplete {
  position: absolute; left: 0; right: 0; bottom: 100%; z-index: 5;
  margin-bottom: 8px; padding: 8px;
  border-radius: 8px; background: var(--bg-side);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
.ac-title {
  padding: 0 8px 6px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-muted);
}
.ac-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: 4px; cursor: pointer;
}
.ac-item.active { background: var(--bg-hover); color: var(--text-strong); }
.ac-item .avatar, .ac-icon { width: 24px; height: 24px; font-size: 11px; }
.ac-icon {
  flex: none; display: grid; place-items: center;
  border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700;
}
.ac-emoji { width: 24px; text-align: center; font-size: 20px; }
.ac-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-hint { font-size: 12px; color: var(--text-muted); }

.emoji-picker {
  position: absolute; right: 0; bottom: 100%; z-index: 5;
  width: min(360px, calc(100vw - 24px)); height: min(400px, 60vh);
  margin-bottom: 8px;
  display: flex; flex-direction: column;
  border-radius: 8px; background: var(--bg-side);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
.emoji-search {
  margin: 10px 10px 6px; padding: 8px 10px; border: 0; border-radius: 4px;
  background: #1e1f22; color: var(--text); font: inherit; font-size: 14px;
}
.emoji-search:focus { outline: none; }
.emoji-tabs { display: flex; gap: 2px; padding: 0 8px 6px; border-bottom: 1px solid #1e1f22; }
.emoji-tab { width: 34px; height: 30px; border-radius: 4px; font-size: 18px; }
.emoji-tab:hover { background: var(--bg-hover); }
.emoji-grid { position: relative; flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.emoji-cat {
  position: sticky; top: 0; z-index: 1;
  padding: 8px 4px 4px; background: var(--bg-side);
  font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-muted);
}
.emoji-section { display: grid; grid-template-columns: repeat(auto-fill, 38px); }
.emoji-btn { width: 38px; height: 38px; border-radius: 4px; font-size: 24px; line-height: 1; }
.emoji-btn:hover { background: var(--bg-hover); }
.emoji-empty { grid-column: 1 / -1; padding: 24px 0; text-align: center; color: var(--text-muted); }
