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

html, body {
  height: 100%;
  background: #0d0f12;
  color: #e8eaed;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

/* ---- Логин ---- */

#login {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d0f12;
  z-index: 100;
}

#login[hidden] {
  display: none;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 300px;
  padding: 32px;
  background: #16191d;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
}

.login-card h2 {
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 8px;
}

.login-card input {
  background: #0d0f12;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 12px 14px;
  color: #e8eaed;
  font-size: 15px;
  outline: none;
}

.login-card input:focus {
  border-color: #2d7ff9;
}

.login-error {
  color: #f28b82;
  font-size: 13px;
  min-height: 16px;
  text-align: center;
}

/* ---- Сетка видео ---- */

#grid {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  gap: 8px;
  padding: 8px 8px 88px;
  align-items: stretch;
}

.tile {
  position: relative;
  background: #16191d;
  border-radius: 12px;
  overflow: hidden;
  min-height: 0;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #16191d;
}

.tile.novideo video {
  visibility: hidden; /* собеседник не шлёт видео — тёмная плитка вместо замороженного кадра */
}

/* Экранные плитки — по contain (весь экран виден), с тонкой рамкой-акцентом */
.tile[data-kind="screen"] {
  border: 1px solid rgba(138, 180, 248, 0.35);
}

.tile .name {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 4px 10px;
  background: rgba(13, 15, 18, 0.7);
  border-radius: 8px;
  font-size: 13px;
  backdrop-filter: blur(6px);
  pointer-events: none;
}

/* Кнопки плитки: закрепить + на весь экран (справа сверху, по наведению) */
.tile-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}

.tile:hover .tile-actions,
.tile.pinned .tile-actions {
  opacity: 1;
}

.tile-actions button {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 15, 18, 0.7);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  padding: 0;
}

.tile-actions button svg {
  width: 17px;
  height: 17px;
  fill: #e8eaed;
}

.tile-actions button:hover svg {
  fill: #8ab4f8;
}

.tile.pinned .tile-actions .pin svg {
  fill: #8ab4f8;
}

/* Закрепление (spotlight): закреплённая плитка большая сверху, остальные — лентой снизу */
#grid.spotlight {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  overflow-y: auto;
}

#grid.spotlight .tile.pinned {
  order: -1;
  flex: 1 1 100%;
  height: 70vh;
}

#grid.spotlight .tile:not(.pinned) {
  flex: 0 0 200px;
  height: 112px;
}

/* На весь экран: видео заполняет, contain для экрана сохраняется */
.tile:fullscreen {
  width: 100vw;
  height: 100vh;
  border: none;
  border-radius: 0;
}

.tile:fullscreen video {
  object-fit: contain;
}

/* Громкость участника: справа снизу, разворачивается по наведению */
.tile .vol {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: rgba(13, 15, 18, 0.7);
  border-radius: 8px;
  backdrop-filter: blur(6px);
  opacity: 0.55;
  transition: opacity 0.15s;
}

.tile .vol:hover {
  opacity: 1;
}

.tile .vol svg {
  width: 18px;
  height: 18px;
  fill: #e8eaed;
  cursor: pointer;
  flex: none;
}

.tile .vol.muted svg {
  fill: #f28b82;
}

.tile .vol input[type='range'] {
  width: 0;
  opacity: 0;
  transition: width 0.15s, opacity 0.15s;
  accent-color: #8ab4f8;
  cursor: pointer;
}

.tile .vol:hover input[type='range'] {
  width: 90px;
  opacity: 1;
}

/* ---- Список участников ---- */

#roster {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 6;
  background: rgba(22, 25, 29, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 14px;
  min-width: 160px;
  max-width: 240px;
}

#roster[hidden] {
  display: none;
}

.roster-title {
  font-size: 11px;
  color: #9aa0a6;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#rosterList {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

#rosterList li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9aa0a6;
  flex: none;
}

.dot.connected {
  background: #4caf7d;
}

.dot.connecting {
  background: #e0b34c;
}

.dot.failed {
  background: #f28b82;
}

#localVideo {
  position: fixed;
  right: 16px;
  bottom: 96px;
  width: 220px;
  max-width: 26vw;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  background: #16191d;
  transform: scaleX(-1);
  z-index: 5;
}

#localVideo.screen {
  transform: none;
  object-fit: contain;
}

/* ---- Статус ---- */

#status {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d0f12;
  z-index: 4;
}

#status.hidden {
  display: none;
}

.status-card {
  text-align: center;
  padding: 32px;
  max-width: 480px;
}

.status-card h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 12px;
}

.status-card p {
  color: #9aa0a6;
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 20px;
  word-break: break-all;
}

.btn-copy {
  background: #2d7ff9;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-copy:hover {
  background: #1a6ce8;
}

/* ---- Панель управления ---- */

#controls {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(22, 25, 29, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  z-index: 10;
}

.ctl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: #e8eaed;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 12px;
  transition: background 0.15s;
  min-width: 72px;
}

.ctl:hover {
  background: rgba(255, 255, 255, 0.08);
}

.ctl svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.ctl span {
  font-size: 11px;
  color: #9aa0a6;
}

.ctl.off {
  color: #f28b82;
}

.ctl .icon-off {
  display: none;
}

.ctl.off .icon-on {
  display: none;
}

.ctl.off .icon-off {
  display: inline;
}

.ctl.off span {
  color: #f28b82;
}

.ctl.active {
  color: #8ab4f8;
  background: rgba(138, 180, 248, 0.12);
}

.ctl.active span {
  color: #8ab4f8;
}

.ctl.danger {
  color: #f28b82;
}

.ctl.danger:hover {
  background: rgba(242, 139, 130, 0.15);
}

/* Значок непрочитанных в чате */
.ctl {
  position: relative;
}

.badge {
  position: absolute;
  top: 2px;
  right: 8px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  color: #fff;
  background: #2d7ff9;
  border-radius: 8px;
}

.badge[hidden] {
  display: none;
}

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

#chat {
  position: fixed;
  right: 16px;
  bottom: 96px;
  z-index: 11;
  width: 340px;
  max-width: calc(100vw - 32px);
  height: 460px;
  max-height: calc(100vh - 180px);
  display: flex;
  flex-direction: column;
  background: rgba(22, 25, 29, 0.96);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  overflow: hidden;
}

#chat[hidden] {
  display: none;
}

#chatHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-weight: 600;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#chatClose {
  background: none;
  border: none;
  color: #9aa0a6;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

#chatClose:hover {
  color: #e8eaed;
}

#chatMessages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
}

.msg .meta {
  font-size: 11px;
  color: #9aa0a6;
  margin-bottom: 2px;
}

.msg.me .meta {
  color: #8ab4f8;
}

.msg a.file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-top: 2px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: #8ab4f8;
  text-decoration: none;
}

.msg a.file:hover {
  background: rgba(255, 255, 255, 0.1);
}

.msg a.file .fsize {
  color: #9aa0a6;
  font-size: 12px;
}

#chatHint {
  font-size: 11px;
  color: #6b7075;
  padding: 0 16px 6px;
}

#chatForm {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

#chatAttach {
  display: flex;
  cursor: pointer;
  flex: none;
}

#chatAttach svg {
  width: 22px;
  height: 22px;
  fill: #9aa0a6;
}

#chatAttach:hover svg {
  fill: #e8eaed;
}

#chatInput {
  flex: 1;
  min-width: 0;
  background: #0d0f12;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px 12px;
  color: #e8eaed;
  font-size: 14px;
  outline: none;
}

#chatInput:focus {
  border-color: #2d7ff9;
}

#chatSend {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: #2d7ff9;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

#chatSend svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

#chatSend:hover {
  background: #1a6ce8;
}

.chat-uploading {
  font-size: 12px;
  color: #9aa0a6;
  padding: 0 16px 6px;
}

/* ---- Подсветка говорящего ---- */

.tile.speaking {
  outline: 3px solid #4caf7d;
  outline-offset: -3px;
}

#localVideo.speaking {
  border-color: #4caf7d;
  box-shadow: 0 0 0 2px #4caf7d, 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* ---- Push-to-talk индикатор ---- */

#pttHint {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  padding: 8px 18px;
  background: rgba(76, 175, 125, 0.9);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  border-radius: 20px;
  backdrop-filter: blur(8px);
}

#pttHint[hidden] {
  display: none;
}

/* ---- Панель устройств ---- */

#settings {
  position: fixed;
  right: 16px;
  bottom: 96px;
  z-index: 11;
  width: 320px;
  max-width: calc(100vw - 32px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: rgba(22, 25, 29, 0.96);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
}

#settings[hidden] {
  display: none;
}

#settingsHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}

#settingsClose {
  background: none;
  border: none;
  color: #9aa0a6;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

#settingsClose:hover {
  color: #e8eaed;
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: #9aa0a6;
}

.setting select {
  background: #0d0f12;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 9px 10px;
  color: #e8eaed;
  font-size: 14px;
  outline: none;
  max-width: 100%;
}

.setting select:focus {
  border-color: #2d7ff9;
}

.settings-hint {
  font-size: 12px;
  color: #9aa0a6;
  line-height: 1.7;
}

.settings-hint kbd {
  display: inline-block;
  padding: 1px 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 5px;
  font-family: inherit;
  font-size: 11px;
}

/* Кнопка «вернуть звонок в эту вкладку» в статус-оверлее */
#status .btn-copy.resume {
  background: #4caf7d;
}

#status .btn-copy.resume:hover {
  background: #3d9e6c;
}
