:root {
  --bg-app: #313338;
  --bg-sidebar: #2b2d31;
  --bg-deep: #1e1f22;
  --bg-input: #383a40;
  --bg-bubble: #383a40;
  --bg-bubble-mine: #3f4b8c;
  --border: #1e1f22;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --online: #23a55a;
  --offline: #80848e;
  --danger: #da373c;
  --text: #dbdee1;
  --text-muted: #949ba4;
}

* { box-sizing: border-box; }
body {
  font-family: system-ui, sans-serif;
  background: var(--bg-app);
  color: var(--text);
  margin: 0;
  min-height: 100vh;
}
.center {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 16px;
}
.card {
  background: var(--bg-sidebar);
  border-radius: 14px;
  padding: 28px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
h1 { margin-top: 0; font-size: 1.6rem; }
h3 { color: var(--text); }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
input, button, textarea {
  font: inherit;
}
input {
  width: 100%;
  padding: 10px 12px;
  margin: 6px 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
}
button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }
button.secondary {
  background: var(--bg-input);
  color: var(--text);
}
button.secondary:hover { background: #4a4d55; }
button.small { width: auto; padding: 4px 10px; font-size: 0.8rem; }
button:disabled { opacity: 0.5; cursor: default; }
.error { color: #ff8080; min-height: 1.2em; font-size: 0.9rem; }
.hint { color: var(--text-muted); font-size: 0.85rem; margin-top: 10px; }
a { color: #8ea1ff; }

/* avatar / color picker */
.type-toggle { display: flex; gap: 8px; margin-bottom: 12px; }
.type-toggle button {
  width: auto;
  flex: 1;
  background: var(--bg-input);
  color: var(--text);
}
.type-toggle button.selected { background: var(--accent); color: #fff; }
.picker-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.pick-emoji {
  width: 40px;
  height: 40px;
  font-size: 1.3rem;
  border-radius: 10px;
  background: var(--bg-input);
  border: 2px solid var(--border);
  cursor: pointer;
}
.pick-emoji.selected { border-color: var(--accent); }
.pick-color {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}
.pick-color.selected { border-color: #fff; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-card { max-width: 420px; max-height: 90vh; overflow-y: auto; }

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

.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  gap: 10px;
}
.me {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  font-weight: 700;
}
.sidebar-section { overflow-y: auto; }
.sidebar-section h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin: 6px 6px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.badge {
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  padding: 0 6px;
  font-size: 0.7rem;
}
.sidebar-section ul { list-style: none; margin: 0; padding: 0; }
#channelList li, #dmList li {
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
#channelList li:hover, #dmList li:hover { background: #35373c; color: var(--text); }
#channelList li.active, #dmList li.active { background: #404249; color: #fff; font-weight: 700; }
#dmList li span:first-of-type, #peopleList li span:first-of-type, #requestList li span { flex: 1; }
#peopleList li, #requestList li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  font-size: 0.9rem;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.online { background: var(--online); }
.status-dot.offline { background: var(--offline); }
.sidebar-bottom { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.sidebar-bottom a, .sidebar-bottom button { width: auto; text-align: center; padding: 8px; }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.avatar.avatar-sm { width: 28px; height: 28px; font-size: 0.95rem; }

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-app);
  border-bottom: 1px solid var(--border);
}
.chat-header #channelTitle { font-weight: 700; }
.chat-header button { width: auto; padding: 6px 12px; }

.incoming-call-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: #3a3f2e;
  border-bottom: 1px solid var(--border);
}
.incoming-call-banner span { flex: 1; font-weight: 600; }
.incoming-call-banner button { width: auto; padding: 6px 14px; }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg {
  display: flex;
  gap: 8px;
  max-width: 75%;
  align-self: flex-start;
}
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg .bubble {
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--bg-bubble);
  word-wrap: break-word;
}
.msg.mine .bubble { background: var(--bg-bubble-mine); }
.msg .nick { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 2px; display: block; }
.msg .report {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  width: auto;
  padding: 0;
  margin-top: 4px;
  text-decoration: underline;
  cursor: pointer;
}

.chat-input {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--bg-app);
  border-top: 1px solid var(--border);
}
.chat-input input { margin: 0; flex: 1; }
.chat-input button { width: auto; padding: 10px 20px; }

/* video call */
.call-overlay {
  flex-direction: column;
  background: var(--bg-deep);
  padding: 14px;
  border-bottom: 1px solid var(--border);
}
.call-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}
.call-tile {
  position: relative;
  width: 220px;
  background: var(--bg-sidebar);
  border-radius: 10px;
  overflow: hidden;
}
.call-tile video { width: 100%; height: 160px; object-fit: cover; display: block; background: #000; }
.call-tile .call-name {
  position: absolute;
  bottom: 6px;
  left: 8px;
  background: rgba(0,0,0,0.5);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
}
.call-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 12px;
}
.call-controls button { width: auto; padding: 8px 16px; }
#leaveCall { background: var(--danger); color: #fff; }

table { width: 100%; border-collapse: collapse; margin-top: 14px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; }
.pill.banned { background: #4c1a20; color: #ff9db2; }
.pill.ok { background: #1c3f28; color: #8fffb0; }
.codebox {
  background: var(--bg-input);
  border: 1px dashed var(--border);
  padding: 10px;
  border-radius: 8px;
  word-break: break-all;
  margin: 10px 0;
}
