/* Цвета и размеры — в одном месте, чтобы легко менять тему */
:root {
  --bg: #313338;          /* основной фон (чат) */
  --bg-side: #2b2d31;     /* боковая панель */
  --bg-deep: #1e1f22;     /* поля ввода, самый тёмный */
  --bg-panel: #232428;    /* панель «я» внизу */
  --bg-hover: #35373c;
  --text: #dbdee1;
  --text-strong: #f2f3f5;
  --muted: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --good: #23a559;
  --warn: #f0b232;
  --danger: #f23f43;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
}
.sprite { position: absolute; }
svg { fill: currentColor; }
.ico { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
button, input { font: inherit; color: inherit; }
h1, h2 { color: var(--text-strong); margin: 0; }

/* ---------- Экраны создания / входа ---------- */
.screen-center {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: radial-gradient(1200px 600px at 50% -10%, #3c3f8f55, transparent), var(--bg-deep);
}
.card {
  width: 100%;
  max-width: 420px;
  background: var(--bg);
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 8px 32px #0006;
  text-align: center;
}
.card h1 { font-size: 24px; margin-bottom: 8px; overflow-wrap: anywhere; }
.logo {
  width: 64px; height: 64px; margin: 0 auto 16px;
  border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff;
}
.logo svg { width: 32px; height: 32px; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); margin: 0 0 20px; }
.form { display: grid; gap: 16px; text-align: left; margin-top: 20px; }
.form label { display: grid; gap: 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.form input {
  padding: 10px 12px; border: 0; border-radius: 4px; outline: none;
  background: var(--bg-deep); color: var(--text-strong); font-size: 16px;
  text-transform: none; letter-spacing: 0; font-weight: 400;
}
.form input:focus { box-shadow: 0 0 0 2px var(--accent); }
.error { color: var(--danger); margin: 16px 0 0; font-size: 14px; }
.link { display: inline-block; margin-top: 20px; color: #00a8fc; font-size: 14px; text-decoration: none; }
.link:hover { text-decoration: underline; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 4px; padding: 10px 16px; cursor: pointer;
  font-weight: 600; transition: background .15s;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.ghost { background: transparent; color: var(--text); }
.btn.ghost:hover { background: var(--bg-hover); }
.btn.small { padding: 6px 10px; font-size: 13px; }

/* ---------- Канал ---------- */
.room {
  height: 100%;
  display: grid;
  grid-template-columns: 280px 1fr;
}
.sidebar {
  background: var(--bg-side);
  display: flex; flex-direction: column;
  min-height: 0;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 12px 12px 16px;
  border-bottom: 1px solid #1f2023;
  min-height: 52px;
}
.channel-title {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  font-weight: 700; color: var(--text-strong);
}
.channel-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-label {
  padding: 16px 16px 6px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
}

.members { list-style: none; margin: 0; padding: 0 8px 8px; overflow-y: auto; flex: 1; }
.member { border-radius: 4px; }
.member-row {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: 4px; outline: none;
}
.member-row[tabindex] { cursor: pointer; }
.member-row[tabindex]:hover, .member-row[tabindex]:focus-visible { background: var(--bg-hover); }
.member-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .you { color: var(--muted); }
.member-conn { font-size: 11px; color: var(--muted); white-space: nowrap; }
.member-conn.failed, .member-conn.disconnected { color: var(--warn); }
.muted-ico { color: var(--muted); width: 16px; height: 16px; }
.camera-ico { color: var(--muted); width: 16px; height: 16px; }

.avatar {
  width: 32px; height: 32px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 14px;
  transition: box-shadow .12s;
}
/* Зелёная обводка у того, кто сейчас говорит */
.member.speaking .avatar { box-shadow: 0 0 0 2px var(--bg-side), 0 0 0 4px var(--good); }

.volume { display: none; align-items: center; gap: 10px; padding: 2px 8px 10px 50px; font-size: 12px; color: var(--muted); }
.member.expanded .volume { display: flex; }
.volume input { flex: 1; accent-color: var(--accent); }

.me-panel {
  display: flex; align-items: center; gap: 4px;
  padding: 8px; background: var(--bg-panel);
}
.me-info {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0;
  padding: 4px; border: 0; border-radius: 4px; background: none; cursor: pointer; text-align: left;
}
.me-info:hover { background: var(--bg-hover); }
.me-text { display: grid; min-width: 0; }
.me-nick { font-weight: 600; color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn-status { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn-status[data-kind="good"] { color: var(--good); }
.conn-status[data-kind="bad"] { color: var(--warn); }
.me-actions { display: flex; gap: 2px; }
.icon-btn {
  width: 36px; height: 36px; border: 0; border-radius: 4px;
  display: grid; place-items: center; cursor: pointer;
  background: transparent; color: var(--text);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--bg-hover); }
.icon-btn.off { color: var(--danger); }
.icon-btn.on { color: var(--good); }
.icon-btn.danger { color: var(--danger); }
.icon-btn.danger:hover { background: var(--danger); color: #fff; }

/* Плашка «звук приостановлен» — поверх всего, сверху по центру */
.audio-banner {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20;
  display: inline-flex; align-items: center; gap: 8px;
  max-width: calc(100% - 32px);
  padding: 10px 16px; border: 0; border-radius: var(--radius); cursor: pointer;
  background: var(--warn); color: #1e1f22; font-weight: 600;
  box-shadow: 0 4px 16px #0008;
}
.audio-banner:hover { filter: brightness(1.08); }

/* ---------- Чат ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; min-height: 52px;
  border-bottom: 1px solid #26282c; box-shadow: 0 1px 0 #0002;
}
.chat-title { font-weight: 700; color: var(--text-strong); }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted);
  background: var(--bg-side); padding: 3px 8px; border-radius: 999px;
}
.badge .ico { width: 12px; height: 12px; color: var(--good); }

.messages { list-style: none; margin: 0; padding: 16px 0 8px; overflow-y: auto; flex: 1; min-height: 0; }
.msg {
  position: relative;
  display: grid; grid-template-columns: 40px minmax(0, 1fr); column-gap: 16px;
  padding: 2px 16px; margin-top: 14px;
}
.msg > :not(.avatar) { grid-column: 2; }
.msg:hover, .msg.active { background: #2e3035; }
.msg .avatar { grid-column: 1; width: 40px; height: 40px; grid-row: span 2; font-size: 16px; margin-top: 2px; }
.msg.has-reply .avatar { grid-row: 2 / span 2; }
.msg.grouped { margin-top: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-nick { font-weight: 600; color: var(--text-strong); }
.msg-time { font-size: 12px; color: var(--muted); }
.msg-body { display: grid; gap: 4px; justify-items: start; min-width: 0; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.system {
  display: block; margin-top: 10px; padding-left: 72px;
  color: var(--muted); font-size: 13px; font-style: italic;
}
.msg.system:hover { background: none; }
/* Подсветка сообщения, к которому перешли по цитате */
.msg.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: #5865f244; } to { background: transparent; } }

/* Цитата в ответе */
.msg-reply {
  display: flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%;
  margin: 0 0 2px; padding: 0; border: 0; background: none; cursor: pointer;
  font-size: 13px; color: var(--muted); text-align: left;
}
.msg-reply .ico { width: 14px; height: 14px; flex: none; }
.msg-reply-nick { font-weight: 600; color: var(--text); flex: none; }
.msg-reply-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-reply:hover .msg-reply-text { color: var(--text-strong); }

/* Картинки и GIF */
.msg-image {
  max-width: min(400px, 100%); height: auto; border-radius: var(--radius);
  background: var(--bg-side); cursor: zoom-in; display: block;
}

/* Реакции под сообщением */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent; background: var(--bg-side); color: var(--text);
  font-size: 14px; line-height: 1.4;
}
.reaction:hover { border-color: #4e5058; }
.reaction.mine { background: #5865f233; border-color: var(--accent); color: var(--text-strong); }

/* Кнопки действий над сообщением */
.msg-actions {
  position: absolute; top: -14px; right: 16px; z-index: 2;
  display: none; gap: 2px; padding: 2px;
  background: var(--bg); border: 1px solid #26282c; border-radius: 6px;
  box-shadow: 0 2px 8px #0005;
}
.msg:hover .msg-actions, .msg.active .msg-actions { display: flex; }
.msg-actions button {
  width: 32px; height: 28px; border: 0; border-radius: 4px; cursor: pointer;
  display: grid; place-items: center; background: none; color: var(--muted);
}
.msg-actions button:hover { background: var(--bg-hover); color: var(--text-strong); }
.msg-actions .ico { width: 18px; height: 18px; }

.reaction-picker {
  position: fixed; z-index: 30; display: flex; gap: 2px; padding: 4px;
  background: var(--bg-deep); border-radius: var(--radius); box-shadow: 0 4px 16px #0008;
}
.reaction-picker button {
  width: 36px; height: 36px; border: 0; border-radius: 6px; cursor: pointer;
  background: none; font-size: 20px; line-height: 1;
}
.reaction-picker button:hover { background: var(--bg-hover); transform: scale(1.15); }

/* ---------- Поле ввода ---------- */
.composer-wrap { position: relative; padding: 0 16px 20px; }
.reply-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: var(--radius) var(--radius) 0 0;
  background: var(--bg-side); font-size: 13px; color: var(--muted);
}
.reply-bar > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-bar b { color: var(--text-strong); }
.reply-cancel {
  width: 24px; height: 24px; border: 0; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; background: none; color: var(--muted);
}
.reply-cancel:hover { background: var(--bg-hover); color: var(--text-strong); }
.reply-bar:not([hidden]) + .chat-form { border-top-left-radius: 0; border-top-right-radius: 0; }

.chat-form {
  display: flex; align-items: center; gap: 4px;
  padding: 0 6px; border-radius: var(--radius); background: #383a40;
}
.chat-form #chat-input {
  flex: 1; min-width: 0; padding: 12px 6px; border: 0; outline: none;
  background: transparent; color: var(--text-strong); font-size: 15px;
}
.composer-btn {
  flex: none; height: 36px; min-width: 36px; padding: 0 6px; border: 0; border-radius: 6px; cursor: pointer;
  display: grid; place-items: center; background: none; color: var(--muted);
}
.composer-btn svg { width: 22px; height: 22px; }
.composer-btn:hover { color: var(--text-strong); }
.gif-btn { font-size: 12px; font-weight: 800; letter-spacing: .02em; }
.gif-btn span, .gif-btn { line-height: 1; }

.chat.dragging .messages { outline: 2px dashed var(--accent); outline-offset: -8px; }

/* Панель GIF */
.gif-panel {
  position: absolute; right: 16px; bottom: calc(100% - 12px); z-index: 25;
  width: min(420px, calc(100% - 32px)); height: min(440px, 60dvh);
  display: flex; flex-direction: column; gap: 8px; padding: 10px;
  background: var(--bg-side); border-radius: var(--radius); box-shadow: 0 8px 24px #0009;
}
.gif-panel > input {
  padding: 8px 10px; border: 0; border-radius: 4px; outline: none;
  background: var(--bg-deep); color: var(--text-strong); font-size: 15px;
}
.gif-panel > input:focus { box-shadow: 0 0 0 2px var(--accent); }
.gif-grid { flex: 1; overflow-y: auto; column-count: 2; column-gap: 6px; }
.gif-tile {
  display: block; width: 100%; margin: 0 0 6px; padding: 0; border: 0; border-radius: 6px;
  overflow: hidden; cursor: pointer; background: var(--bg-deep); break-inside: avoid;
}
.gif-tile img { display: block; width: 100%; height: auto; }
.gif-tile:hover { outline: 2px solid var(--accent); }
.gif-empty { column-span: all; text-align: center; color: var(--muted); margin: 24px 0; }
.gif-foot { font-size: 11px; color: var(--muted); text-align: right; letter-spacing: .03em; }

/* Просмотр картинки крупно */
.lightbox {
  border: 0; padding: 0; background: none; max-width: 96vw; max-height: 96dvh; cursor: zoom-out;
}
.lightbox::backdrop { background: #000d; }
.lightbox img { display: block; max-width: 96vw; max-height: 96dvh; object-fit: contain; border-radius: 6px; }

/* ---------- Видео ---------- */
.stage {
  display: grid; gap: 8px; padding: 12px 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  max-height: 55%; overflow-y: auto;
  border-bottom: 1px solid #26282c;
}
.tile {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden;
  background: #000; cursor: pointer;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.mirror video { transform: scaleX(-1); }   /* своё видео — как в зеркале */
.tile-name {
  position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px);
  padding: 2px 8px; border-radius: 4px; background: #000a; color: #fff; font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Зелёная рамка у говорящего — отдельным слоем поверх видео */
.tile::after { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; }
.tile.speaking::after { box-shadow: inset 0 0 0 3px var(--good); }
.tile:fullscreen video { object-fit: contain; }

/* ---------- Диалог и уведомления ---------- */
.dialog {
  border: 0; border-radius: 12px; padding: 24px; width: min(400px, calc(100% - 32px));
  background: var(--bg); color: var(--text); box-shadow: 0 8px 32px #0008;
}
.dialog::backdrop { background: #000a; }
.dialog .form { margin: 0; }
.dialog input {
  padding: 10px 12px; border: 0; border-radius: 4px; outline: none;
  background: var(--bg-deep); color: var(--text-strong); font-size: 16px;
}
.dialog input:focus { box-shadow: 0 0 0 2px var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--bg-deep); color: var(--text-strong);
  padding: 10px 16px; border-radius: var(--radius); box-shadow: 0 4px 16px #0008;
  font-size: 14px; z-index: 10;
}

/* ---------- Настройки голоса ---------- */
.fieldset { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: 16px; }
.fieldset:disabled { opacity: .45; }
.dialog .form { max-height: calc(100dvh - 96px); overflow-y: auto; }
.form select {
  padding: 10px 12px; border: 0; border-radius: 4px; outline: none;
  background: var(--bg-deep); color: var(--text-strong); font-size: 15px;
  text-transform: none; letter-spacing: 0; font-weight: 400;
}
.form select:focus { box-shadow: 0 0 0 2px var(--accent); }
.form label.check {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text);
  cursor: pointer;
}
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.field { display: grid; gap: 10px; }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.field-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.hint { margin: 0; font-size: 13px; color: var(--muted); }

.meter-wrap { position: relative; height: 24px; }
.meter {
  position: absolute; inset: 7px 0; border-radius: 5px; overflow: hidden;
  background: var(--bg-deep);
}
.meter-fill { height: 100%; width: 0; background: #4e5058; transition: width 60ms linear; }
.meter-fill.open { background: var(--good); }
.meter-wrap.disabled .meter-fill { background: var(--good); }
.meter-wrap.disabled input { opacity: .3; }

/* Ползунок прозрачный, виден только «бегунок» поверх полоски */
.meter-wrap input[type="range"] {
  position: absolute; inset: 0; width: 100%; margin: 0;
  appearance: none; -webkit-appearance: none; background: transparent; cursor: pointer;
}
.meter-wrap input[type="range"]::-webkit-slider-runnable-track { height: 24px; background: transparent; }
.meter-wrap input[type="range"]::-moz-range-track { height: 24px; background: transparent; }
.meter-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 8px; height: 24px; border-radius: 3px;
  background: #fff; box-shadow: 0 0 0 2px var(--bg-deep);
}
.meter-wrap input[type="range"]::-moz-range-thumb {
  width: 8px; height: 24px; border: 0; border-radius: 3px;
  background: #fff; box-shadow: 0 0 0 2px var(--bg-deep);
}
.meter-wrap input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--accent); }

.diag-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.diag-actions .btn { background: var(--bg-side); }
.diag-actions .btn:hover { background: var(--bg-hover); }
.diag-out {
  margin: 0; padding: 10px 12px; border-radius: 6px; background: var(--bg-deep);
  font: 12.5px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--text);
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 260px; overflow-y: auto;
}

/* ---------- Телефоны ---------- */
@media (max-width: 720px) {
  .room { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 45vh; border-bottom: 1px solid #1f2023; }
  .members { flex: 0 1 auto; }
  .me-panel { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .msg.system { padding-left: 16px; }
  .composer-wrap { padding: 0 8px max(12px, env(safe-area-inset-bottom)); }
  .stage { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); padding: 8px; max-height: 40%; }
  .msg { padding: 2px 8px; column-gap: 10px; }
  .msg-actions { right: 8px; }
  .gif-panel { right: 8px; width: calc(100% - 16px); }
  .card { padding: 24px 20px; }
}
