:root {
  --bg-1: #1e1f22;
  --bg-2: #2b2d31;
  --bg-3: #313338;
  --bg-4: #383a40;
  --bg-hover: #35373c;
  --brand: #5865f2;
  --brand-h: #4752c4;
  --green: #23a559;
  --green-h: #1e8e4d;
  --red: #f23f43;
  --red-h: #da373c;
  --text: #f2f3f5;
  --muted: #949ba4;
  --link: #00a8fc;
  --online: #23a559;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", "Noto Sans", sans-serif;
  color: var(--text);
  background: transparent;
  user-select: none;
}
input, textarea, .messages { user-select: text; }

.titlebar {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  background: rgba(15, 16, 18, 0.55);
  border-bottom: 1px solid rgba(255,255,255,.08);
  -webkit-app-region: drag;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  background: linear-gradient(
    to bottom,
    #ffffff 0 33.333%,
    #0039a6 33.333% 66.666%,
    #d52b1e 66.666% 100%
  );
  pointer-events: none;
}
#auth, #app, #incoming { position: relative; z-index: 1; }

.hidden { display: none !important; }

.auth {
  min-height: calc(100% - 28px);
  display: grid;
  place-items: center;
  background: transparent;
}
.auth-box {
  width: min(720px, 94vw);
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  background: rgba(17, 18, 20, 0.88);
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0,0,0,.4);
  overflow: hidden;
}
.auth-left {
  padding: 36px 28px;
  background: #0039a6;
}
.logo-mark {
  width: 56px; height: 56px; border-radius: 16px;
  background: #fff; color: #d52b1e;
  display: grid; place-items: center;
  font-weight: 800; font-size: 16px; margin-bottom: 18px;
}
.auth-left h1 { margin: 0 0 10px; font-size: 28px; }
.auth-left p { margin: 0; color: #d6daff; line-height: 1.5; }
.auth-form { padding: 36px 32px; }
.auth-form h2 { margin: 0 0 6px; }
.auth-form label {
  display: block; margin: 14px 0 6px;
  color: #b5bac1; font-size: 12px; font-weight: 700; letter-spacing: .02em;
  text-transform: uppercase;
}
.auth-form input {
  width: 100%; height: 40px; border: 0; border-radius: 4px;
  background: #1e1f22; color: #fff; padding: 0 10px; font-size: 16px;
}
.auth-form button, .ok, .danger, .tab.add {
  width: 100%; height: 42px; margin-top: 18px; border: 0; border-radius: 4px;
  background: var(--brand); color: #fff; font-weight: 600; cursor: pointer;
}
.auth-form button:hover { background: var(--brand-h); }
.switch { color: var(--muted); font-size: 14px; }
.switch a { color: var(--link); text-decoration: none; }
.error { color: #f23f43; min-height: 18px; font-size: 13px; margin-top: 8px; }
.muted { color: var(--muted); margin: 0 0 18px; }

.app {
  height: calc(100% - 28px);
  display: grid;
  grid-template-columns: 72px 240px 1fr 240px;
  background: transparent;
}

.servers {
  background: rgba(20, 21, 24, 0.72);
  display: flex; flex-direction: column; align-items: center;
  padding: 12px 0; gap: 8px;
}
.server-icon {
  width: 48px; height: 48px; border: 0; border-radius: 24px;
  background: var(--bg-3); color: var(--text);
  display: grid; place-items: center; cursor: pointer;
  font-weight: 700; transition: border-radius .15s, background .15s;
}
.server-icon:hover, .server-icon.active {
  border-radius: 16px; background: var(--brand);
}
.server-icon.home { color: #dbdee1; }
.server-icon.home.active, .server-icon.home:hover {
  background: var(--green); color: #fff;
}
.server-sep { width: 32px; height: 2px; background: #3f4147; border-radius: 1px; }

.sidebar { background: rgba(35, 36, 40, 0.78); display: flex; flex-direction: column; }
.sidebar-head {
  height: 48px; padding: 0 16px; display: flex; align-items: center;
  font-weight: 700; box-shadow: 0 1px 0 rgba(0,0,0,.2);
}
.nav-list { flex: 1; overflow: auto; padding: 8px; }
.nav-item, .friend-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 4px; cursor: pointer; color: #949ba4;
}
.nav-item:hover, .friend-row:hover, .nav-item.active { background: var(--bg-hover); color: #fff; }
.nav-label {
  margin: 12px 8px 6px; font-size: 11px; font-weight: 700;
  letter-spacing: .04em; color: #949ba4; text-transform: uppercase;
  display: flex; align-items: center; justify-content: space-between;
}
.nav-label .mini {
  border: 0; background: transparent; color: #b5bac1; cursor: pointer;
  font-size: 16px; line-height: 1; padding: 0 4px;
}
.nav-item.nested { margin-left: 18px; padding: 4px 8px; font-size: 13px; }

.user-panel {
  height: 52px; background: rgba(17, 18, 20, 0.55); display: flex; align-items: center;
  gap: 8px; padding: 0 8px;
}
.user-meta { flex: 1; min-width: 0; }
.user-meta b, .user-meta span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta span { color: var(--green); font-size: 12px; }
#btn-logout {
  border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px;
}

.avatar, .avatar.big {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; position: relative;
  flex: 0 0 auto; color: #fff;
}
.avatar.big { width: 72px; height: 72px; font-size: 28px; margin: 0 auto 10px; }
.avatar::after {
  content: ""; position: absolute; right: -2px; bottom: -2px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #80848e; border: 2px solid var(--bg-2);
}
.avatar.online::after { background: var(--online); }

.main { display: flex; flex-direction: column; min-width: 0; background: rgba(49, 51, 56, 0.82); }
.topbar {
  height: 48px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; box-shadow: 0 1px 0 rgba(0,0,0,.2); font-weight: 700;
}
.top-actions { display: flex; gap: 8px; }
.top-actions button {
  border: 0; background: var(--bg-4); color: #fff; border-radius: 4px;
  padding: 6px 10px; cursor: pointer;
}

.friends-view, .chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.friend-tabs { display: flex; gap: 8px; padding: 16px; border-bottom: 1px solid #3f4147; }
.tab {
  border: 0; background: transparent; color: #b5bac1; border-radius: 4px;
  padding: 6px 10px; cursor: pointer; font-weight: 600;
}
.tab.active { background: #43444b; color: #fff; }
.tab.add { width: auto; height: auto; margin: 0; background: var(--green); }
.tab.add:hover { background: var(--green-h); }
.friends-body { padding: 8px 16px; overflow: auto; }
.friend-row .grow { flex: 1; }
.friend-row .actions { display: flex; gap: 6px; }
.friend-row button, .ok, .danger {
  width: auto; height: 32px; margin: 0; padding: 0 10px; border-radius: 16px;
}
.ok { background: var(--green); }
.ok:hover { background: var(--green-h); }
.danger { background: var(--red); }
.danger:hover { background: var(--red-h); }
.add-box { max-width: 640px; padding: 20px 8px; }
.add-box h3 { margin: 0 0 8px; }
.add-row { display: flex; gap: 8px; }
.add-row input {
  flex: 1; height: 44px; border: 0; border-radius: 8px;
  background: #1e1f22; color: #fff; padding: 0 12px;
}
.add-row button { width: 180px; height: 44px; margin: 0; }

.messages { flex: 1; overflow: auto; padding: 16px; }
.msg { display: flex; gap: 12px; padding: 6px 8px; border-radius: 4px; }
.msg:hover { background: rgba(0,0,0,.08); }
.msg .body b { margin-right: 8px; }
.msg .when { color: var(--muted); font-size: 12px; font-weight: 400; }
.msg p { margin: 4px 0 0; line-height: 1.375; white-space: pre-wrap; word-break: break-word; }
.composer { padding: 0 16px 20px; }
.composer input {
  width: 100%; height: 44px; border: 0; border-radius: 8px;
  background: var(--bg-4); color: #fff; padding: 0 14px; font-size: 15px;
}

.call-view { flex: 1; display: flex; flex-direction: column; background: rgba(17, 18, 20, 0.35); }
.call-stage {
  flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px; padding: 16px;
}
.call-tile {
  background: #1e1f22; border-radius: 12px; overflow: hidden;
  display: grid; place-items: center; min-height: 200px; position: relative;
}
.call-tile video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.call-tile span {
  position: absolute; left: 10px; bottom: 10px;
  background: rgba(0,0,0,.55); padding: 4px 8px; border-radius: 6px; font-size: 12px;
}
.call-bar {
  height: 72px; display: flex; justify-content: center; align-items: center; gap: 12px;
}
.round {
  width: 48px; height: 48px; border: 0; border-radius: 50%;
  background: #3f4147; color: #fff; cursor: pointer; font-size: 12px;
}
.round.accent { background: var(--brand); }
.round.danger { background: var(--red); }
.round.on { background: #e3b341; color: #111; }

.members { background: rgba(35, 36, 40, 0.78); padding: 16px 8px; overflow: auto; }
.members h3 { margin: 0 8px 10px; color: var(--muted); font-size: 12px; letter-spacing: .04em; }

.incoming {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: grid; place-items: center; z-index: 20;
}
.incoming-card {
  width: 320px; background: #313338; border-radius: 12px; padding: 24px; text-align: center;
}
.incoming-actions { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }

.empty { color: var(--muted); padding: 24px 8px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 64px 1fr; }
  .sidebar, .members { display: none; }
  .auth-box { grid-template-columns: 1fr; }
  .auth-left { display: none; }
}
