:root {
  --bg-darkest: #1e1f22;
  --bg-dark: #2b2d31;
  --bg-primary: #313338;
  --bg-secondary: #383a40;
  --bg-secondary-alt: #2b2d31;
  --bg-modifier-hover: rgba(78, 80, 88, 0.4);
  --brand: #5865f2;
  --brand-hover: #4752c4;
  --text-normal: #dbdee1;
  --text-muted: #949ba4;
  --text-bright: #f2f3f5;
  --green: #23a559;
  --red: #f23f42;
  --red-hover: #da373c;
  --header-h: 48px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "gg sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-normal);
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

input, textarea {
  font-family: inherit;
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-secondary);
  color: var(--text-bright);
  padding: 10px 16px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  opacity: 0;
  transform: translateY(-8px);
  transition: all .25s ease;
  border-left: 4px solid var(--brand);
  max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { border-left-color: var(--red); }
.toast-success { border-left-color: var(--green); }

/* Auth */
.auth-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #3b3f8f 0%, #1e1f22 60%);
}
.auth-card {
  background: var(--bg-dark);
  padding: 32px;
  border-radius: 8px;
  width: 340px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
.logo {
  text-align: center;
  color: var(--text-bright);
  margin: 0 0 20px;
  font-size: 26px;
}
.logo span { color: var(--brand); }
.auth-tabs {
  display: flex;
  margin-bottom: 20px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-secondary);
}
.auth-tab {
  flex: 1;
  padding: 10px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
}
.auth-tab.active {
  background: var(--brand);
  color: white;
}
.auth-form { display: flex; flex-direction: column; gap: 6px; }
.auth-form label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 8px;
}
.auth-form input {
  background: var(--bg-primary);
  border: 1px solid #1e1f22;
  color: var(--text-normal);
  padding: 10px;
  border-radius: 4px;
  outline: none;
}
.auth-form input:focus { border-color: var(--brand); }
.btn-primary {
  margin-top: 18px;
  background: var(--brand);
  color: white;
  padding: 11px;
  border-radius: 4px;
  font-weight: 600;
}
.btn-primary:hover { background: var(--brand-hover); }
.btn-danger {
  background: var(--red);
  color: white;
  padding: 10px 18px;
  border-radius: 4px;
  font-weight: 600;
}
.btn-danger:hover { background: var(--red-hover); }
.btn-success {
  background: var(--green);
  color: white;
  padding: 10px 18px;
  border-radius: 4px;
  font-weight: 600;
}

/* App shell */
.app-shell {
  height: 100vh;
  display: flex;
}

.server-rail {
  width: 72px;
  background: var(--bg-darkest);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
  overflow-y: auto;
}
.server-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--text-bright);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  background-size: cover;
  background-position: center;
  transition: border-radius .15s ease, background-color .15s ease;
  flex-shrink: 0;
}
.server-icon:hover, .server-icon.active { border-radius: 16px; background-color: var(--brand); }
.server-icon.home.active { background-color: var(--brand); }
.server-icon.add-server { background: var(--bg-secondary); color: var(--green); font-size: 22px; }
.server-icon.add-server:hover { background-color: var(--green); color: white; }
.rail-separator {
  width: 32px;
  height: 2px;
  background: var(--bg-secondary);
  border-radius: 1px;
}
.server-list { display: flex; flex-direction: column; gap: 8px; width: 100%; align-items: center; }

.sidebar {
  width: 240px;
  background: var(--bg-dark);
  display: flex;
  flex-direction: column;
}
.sidebar-view { flex: 1; overflow-y: auto; padding: 12px 8px; }
.sidebar-header {
  padding: 8px;
  font-weight: 700;
  color: var(--text-bright);
}
.server-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--bg-darkest);
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
}
.server-header button { background: transparent; color: var(--text-muted); font-size: 15px; }
.add-friend-btn {
  width: 100%;
  background: var(--bg-secondary);
  color: var(--text-bright);
  padding: 8px;
  border-radius: 4px;
  font-weight: 600;
  margin-bottom: 8px;
}
.add-friend-btn:hover { background: var(--brand); }
.section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin: 12px 4px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.section-title button {
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
}
.list-item:hover { background: var(--bg-modifier-hover); color: var(--text-bright); }
.list-item.active { background: var(--bg-secondary); color: var(--text-bright); }
.list-item-info { flex: 1; min-width: 0; }
.list-item-name { font-size: 14px; font-weight: 600; color: inherit; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.channel-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
}
.channel-item::before { content: "#"; color: var(--text-muted); font-weight: 700; }
.channel-item:hover { background: var(--bg-modifier-hover); color: var(--text-bright); }
.channel-item.active { background: var(--bg-secondary); color: var(--text-bright); }

.friend-request-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 4px;
}
.friend-request-item:hover { background: var(--bg-modifier-hover); }
.friend-request-actions { display: flex; gap: 6px; margin-left: auto; }
.friend-request-actions button {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--text-bright);
  display: flex;
  align-items: center;
  justify-content: center;
}
.friend-request-actions .accept:hover { background: var(--green); }
.friend-request-actions .decline:hover { background: var(--red); }

.leave-server-btn {
  margin-top: auto;
  width: calc(100% - 16px);
  background: transparent;
  color: var(--red);
  padding: 8px;
  font-size: 13px;
  text-align: left;
}
.leave-server-btn:hover { text-decoration: underline; }

.user-bar {
  height: 52px;
  background: var(--bg-secondary-alt);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  border-top: 1px solid var(--bg-darkest);
}
.user-bar-info { flex: 1; min-width: 0; }
.user-bar-name { font-size: 13px; font-weight: 600; color: var(--text-bright); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-bar-status { font-size: 11px; color: var(--text-muted); }
.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.icon-btn:hover { background: var(--bg-modifier-hover); color: var(--text-bright); }

.avatar {
  border-radius: 50%;
  background-color: var(--brand);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  flex-shrink: 0;
}
.avatar.small { width: 32px; height: 32px; font-size: 13px; position: relative; }
.avatar.large { width: 80px; height: 80px; font-size: 28px; margin: 0 auto 12px; }
.avatar.tiny { width: 24px; height: 24px; font-size: 10px; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  border: 2px solid var(--bg-dark);
  position: absolute;
  bottom: -2px;
  right: -2px;
}
.status-dot.online { background: var(--green); }
.list-item .avatar.small { margin-right: 0; }

/* Main content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
}
.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--bg-darkest);
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
  font-weight: 700;
  color: var(--text-bright);
  flex-shrink: 0;
}
.chat-header-actions { display: flex; gap: 8px; }
.chat-header-actions button {
  background: var(--bg-secondary);
  color: var(--text-bright);
  width: 32px;
  height: 32px;
  border-radius: 50%;
}
.chat-header-actions button:hover { background: var(--brand); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.message { display: flex; gap: 14px; }
.message-content { min-width: 0; }
.message-header { display: flex; align-items: baseline; gap: 8px; }
.message-author { font-weight: 600; color: var(--text-bright); font-size: 15px; cursor: pointer; }
.message-author:hover { text-decoration: underline; }
.message-time { font-size: 11px; color: var(--text-muted); }
.message-text { color: var(--text-normal); font-size: 15px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }

.message-form { padding: 0 16px 20px; flex-shrink: 0; }
.message-form { display: flex; gap: 8px; }
.message-form input {
  flex: 1;
  background: var(--bg-secondary);
  border: none;
  color: var(--text-normal);
  padding: 12px;
  border-radius: 8px;
  outline: none;
}
.message-form button {
  background: var(--brand);
  color: white;
  padding: 0 18px;
  border-radius: 8px;
  font-weight: 600;
}

.member-list {
  width: 240px;
  background: var(--bg-dark);
  padding: 16px 8px;
  overflow-y: auto;
}
.member-list-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin: 4px 8px 8px;
}
.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
}
.member-item:hover { background: var(--bg-modifier-hover); }
.member-item-name { font-size: 14px; color: var(--text-normal); font-weight: 500; }
.member-item-role { font-size: 10px; color: var(--brand); font-weight: 700; text-transform: uppercase; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 90;
}
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-dark);
  border-radius: 8px;
  padding: 24px;
  width: 420px;
  max-width: calc(100vw - 32px);
  z-index: 100;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
.modal h2 { margin: 0 0 8px; color: var(--text-bright); text-align: center; }
.modal-sub { color: var(--text-muted); font-size: 14px; text-align: center; margin-bottom: 16px; }
.modal-form { display: flex; flex-direction: column; gap: 10px; }
.modal-form label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 6px;
}
.modal-form input, .modal-form textarea {
  background: var(--bg-primary);
  border: 1px solid var(--bg-darkest);
  color: var(--text-normal);
  padding: 10px;
  border-radius: 4px;
  outline: none;
  resize: vertical;
}
.modal-form input:focus, .modal-form textarea:focus { border-color: var(--brand); }
.modal-close {
  margin-top: 16px;
  width: 100%;
  background: transparent;
  color: var(--text-muted);
  padding: 8px;
  text-align: center;
}
.modal-close:hover { color: var(--text-bright); }
.modal-tabs { display: flex; margin-bottom: 16px; border-radius: 6px; overflow: hidden; background: var(--bg-secondary); }
.modal-tab { flex: 1; padding: 8px; background: transparent; color: var(--text-muted); font-weight: 600; }
.modal-tab.active { background: var(--brand); color: white; }

.settings-avatar-row { display: flex; flex-direction: column; align-items: center; margin-bottom: 16px; }
.settings-avatar-row input { color: var(--text-muted); font-size: 12px; }

.invite-code-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-primary);
  padding: 10px 14px;
  border-radius: 4px;
  gap: 12px;
}
#invite-code-text { font-family: monospace; font-size: 16px; color: var(--text-bright); word-break: break-all; }
.invite-code-box button {
  background: var(--brand);
  color: white;
  padding: 8px 14px;
  border-radius: 4px;
  font-weight: 600;
  flex-shrink: 0;
}

.profile-popout-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.profile-popout-actions button {
  background: var(--bg-secondary);
  color: var(--text-bright);
  padding: 8px 14px;
  border-radius: 4px;
  font-weight: 600;
}
.profile-popout-actions button:hover { background: var(--brand); }
#modal-user-profile h2, #modal-user-profile p { text-align: center; }
#profile-popout-about { color: var(--text-normal); font-size: 14px; }

/* Calls */
.call-modal { text-align: center; }
.call-modal-actions { display: flex; gap: 16px; justify-content: center; margin-top: 20px; }

.call-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
#remote-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #111;
}
#local-video {
  position: absolute;
  bottom: 100px;
  right: 24px;
  width: 200px;
  height: 150px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid var(--bg-secondary);
  background: #222;
}
.call-controls {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
}
.call-controls button {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: white;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.call-controls button:hover { background: var(--bg-modifier-hover); }
.call-controls button.active-off { background: var(--red); }

/* Scrollbars */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-darkest); border-radius: 4px; }

@media (max-width: 900px) {
  .member-list { display: none !important; }
}
