:root {
  color-scheme: dark;
  --bg-0: #1e1f22;
  --bg-1: #2b2d31;
  --bg-2: #313338;
  --bg-3: #383a40;
  --rail: #1e1f22;
  --chat: #313338;
  --text: #f2f3f5;
  --muted: #949ba4;
  --muted-2: #b5bac1;
  --line: #3f4147;
  --brand: #5865f2;
  --brand-hover: #4752c4;
  --green: #23a559;
  --red: #da373c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  color: var(--text);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input,
select {
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: 4px;
  outline: none;
  background: #1e1f22;
  color: var(--text);
  padding: 0 10px;
}

input::placeholder {
  color: #80848e;
}

.hidden {
  display: none !important;
}

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #313338;
}

.auth-panel {
  width: min(420px, 100%);
  padding: 28px;
  border-radius: 5px;
  background: #2b2d31;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  margin: 0 auto 18px;
}

.auth-panel h1 {
  margin: 0;
  text-align: center;
  font-size: 26px;
}

.auth-copy {
  margin: 8px 0 20px;
  text-align: center;
  color: var(--muted-2);
  line-height: 1.35;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.tabs button,
.stack button {
  min-height: 38px;
  border-radius: 4px;
  background: var(--bg-3);
  font-weight: 700;
}

.tabs button.active,
.stack button {
  background: var(--brand);
}

.tabs button:hover,
.stack button:hover {
  background: var(--brand-hover);
}

.stack {
  display: grid;
  gap: 10px;
}

.error {
  min-height: 18px;
  margin: 12px 0 0;
  color: #fa777c;
}

.shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 72px 240px minmax(0, 1fr);
  background: var(--chat);
  min-height: 0;
}

.server-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  background: var(--rail);
}

.server-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #313338;
  color: #dbdee1;
  font-weight: 800;
  transition: border-radius 140ms ease, background 140ms ease;
}

.server-icon:hover,
.server-icon.active {
  border-radius: 16px;
  background: var(--brand);
  color: #fff;
}

.server-icon.add {
  color: var(--green);
}

.server-icon.add:hover {
  background: var(--green);
  color: #fff;
}

.rail-divider {
  width: 32px;
  height: 2px;
  border-radius: 999px;
  background: #35363c;
  margin: 4px 0;
}

.sidebar {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto auto auto 1fr auto;
  background: var(--bg-1);
  overflow: hidden;
}

.search {
  display: grid;
  grid-template-columns: 1fr 34px;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.28);
}

.search button {
  border-radius: 4px;
  background: #1e1f22;
  color: var(--muted-2);
}

.nav-list {
  padding: 8px;
}

.nav-item,
.user-row {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border-radius: 4px;
  background: transparent;
  color: var(--muted-2);
  text-align: left;
  box-shadow: none;
}

.nav-item:hover,
.user-row:hover,
.user-row.active {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

.results {
  padding: 0 8px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 4px;
  color: var(--muted);
}

.section-title h2 {
  margin: 0;
  font-size: 12px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.contacts {
  overflow: auto;
  padding: 0 8px 8px;
}

.user-row {
  min-height: 38px;
  justify-content: space-between;
}

.user-row::before {
  content: "";
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: linear-gradient(135deg, #5865f2, #3ba55d);
}

.user-row button {
  min-height: 28px;
  padding: 0 9px;
  border-radius: 3px;
  background: var(--brand);
  color: #fff;
}

.profile button,
.top-actions button {
  min-height: 32px;
  border-radius: 4px;
  background: #2b2d31;
  color: var(--muted-2);
}

.profile button:hover,
.top-actions button:hover:not(:disabled) {
  background: #3f4249;
  color: #fff;
}

#hangupBtn {
  background: var(--red);
  color: #fff;
}

.profile {
  min-height: 56px;
  display: grid;
  grid-template-columns: 34px 1fr 34px 34px;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: #232428;
}

.profile strong,
.profile span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile span {
  color: var(--muted);
  font-size: 12px;
}

.avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #5865f2;
  color: white;
  font-size: 12px;
  font-weight: 800;
}

.avatar.has-image,
.call-avatar.has-image,
.message-avatar.has-image,
.peer-avatar.has-image {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: #111214;
  color: transparent;
}

.avatar.large {
  width: 86px;
  height: 86px;
  font-size: 22px;
}

.chat {
  min-width: 0;
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--chat);
}

.chat-head {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.28);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03);
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.peer-avatar {
  background: #3f4147;
}

.peer {
  display: block;
  color: #fff;
  font-weight: 700;
}

.chat-head small {
  display: block;
  margin-top: 2px;
  color: var(--green);
  font-size: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-actions button {
  width: 32px;
  display: grid;
  place-items: center;
}

#callBtn:not(:disabled) {
  color: #dbdee1;
}

#callBtn:not(:disabled):hover {
  color: #fff;
}

.media {
  flex: 0 0 auto;
  position: relative;
  min-height: 238px;
  max-height: 42vh;
  height: 238px;
  background: #050505;
  border-bottom: 1px solid rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.call-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  z-index: 1;
}

.call-member {
  display: grid;
  justify-items: center;
  gap: 7px;
  min-width: 118px;
}

.call-member span {
  color: #f2f3f5;
  font-weight: 700;
}

.call-member small {
  color: var(--muted);
  font-size: 12px;
}

.call-avatar {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #5865f2, #3ba55d);
  color: white;
  font-weight: 900;
  box-shadow: 0 0 0 4px #050505, 0 0 0 7px rgba(255, 255, 255, 0.08);
}

.call-avatar.has-image {
  box-shadow: 0 0 0 3px #050505, 0 0 0 5px rgba(35, 165, 89, 0.65);
}

.call-avatar.self {
  background: linear-gradient(135deg, #3f4147, #5865f2);
}

#remoteVideo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  position: relative;
  z-index: 2;
  background: #050505;
}

.media.has-video #remoteVideo {
  display: block;
}

.media.has-video .call-stage {
  display: none;
}

#localPreview {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 190px;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: #000;
  border: 1px solid #111;
  border-radius: 6px;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 18px 16px 0;
}

.message {
  position: relative;
  max-width: 860px;
  margin: 0 0 14px;
  padding: 2px 8px 2px 58px;
  border-radius: 4px;
  color: #dbdee1;
}

.message:hover {
  background: rgba(0, 0, 0, 0.08);
}

.message-avatar {
  position: absolute;
  left: 10px;
  top: 4px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #5865f2, #1abc9c);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.message.mine .message-avatar {
  background: linear-gradient(135deg, #23a559, #5865f2);
}

.message-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}

.message-author {
  color: #f2f3f5;
  font-weight: 700;
}

.message-time {
  color: var(--muted);
  font-size: 12px;
}

.message-text {
  color: #dbdee1;
  line-height: 1.35;
  white-space: pre-wrap;
}

.message .meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.message .meta::first-line {
  color: #fff;
}

.message img {
  max-width: min(440px, 100%);
  display: block;
  margin-top: 8px;
  border-radius: 6px;
}

.message a {
  color: #00a8fc;
}

.composer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 16px;
  background: var(--chat);
  border-top: 1px solid rgba(0, 0, 0, 0.12);
}

.composer input {
  min-height: 44px;
  border-radius: 8px;
  background: #383a40;
}

.file-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #383a40;
  color: var(--muted-2);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.file-btn:hover {
  color: #fff;
}

#sendBtn {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 4px;
  background: var(--brand);
  font-weight: 700;
}

#sendBtn:hover:not(:disabled) {
  background: var(--brand-hover);
}

.media:fullscreen,
.media:-webkit-full-screen,
#remoteVideo:fullscreen,
#remoteVideo:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-height: none;
  background: #000;
}

.media:fullscreen #remoteVideo,
.media:-webkit-full-screen #remoteVideo {
  display: block;
  width: 100vw;
  height: 100vh;
  max-height: none;
  object-fit: contain;
}

.media:fullscreen #localPreview,
.media:-webkit-full-screen #localPreview {
  width: min(22vw, 320px);
  right: 24px;
  bottom: 24px;
}

.incoming {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-radius: 6px;
  background: #2b2d31;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  z-index: 10;
}

.incoming button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 4px;
  background: var(--green);
  font-weight: 700;
}

#rejectCall {
  background: var(--red);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.62);
  z-index: 20;
}

.settings-panel {
  width: min(560px, 100%);
  border-radius: 6px;
  background: #2b2d31;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.settings-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.28);
}

.settings-panel h2 {
  margin: 0;
  font-size: 18px;
}

.settings-panel header button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #1e1f22;
  color: var(--muted-2);
}

.settings-grid {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.settings-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted-2);
  font-weight: 700;
}

.settings-grid select {
  background: #1e1f22;
}

.avatar-settings {
  display: flex;
  align-items: center;
  gap: 14px;
}

.upload-avatar,
#testMicBtn {
  width: max-content;
  min-height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0 12px;
  border-radius: 4px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.meter {
  height: 10px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #1e1f22;
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 80ms linear;
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .shell {
    min-height: 100vh;
    height: auto;
    grid-template-columns: 64px 1fr;
  }

  .sidebar {
    display: none;
  }

  .chat {
    height: 100vh;
    min-height: 0;
  }
}

/* Speaking voice indicator (Discord style) */
.avatar.speaking,
.call-avatar.speaking {
  box-shadow: 0 0 0 3px var(--green) !important;
  animation: pulse-speaking 1.5s infinite;
}

.user-row.speaking::before {
  box-shadow: 0 0 0 2px var(--green) !important;
  animation: pulse-speaking 1.5s infinite;
}

@keyframes pulse-speaking {
  0% {
    box-shadow: 0 0 0 3px rgba(35, 165, 89, 0.6);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(35, 165, 89, 0);
  }
  100% {
    box-shadow: 0 0 0 3px rgba(35, 165, 89, 0.6);
  }
}

