:root {
  --bg: #111827;
  --bg-2: #1f2937;
  --bg-3: #374151;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #2563eb;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
}

.hidden { display: none !important; }

.center {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card {
  background: var(--bg-2);
  padding: 24px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(340px, 90vw);
}

.card h1 { margin: 0 0 8px; font-size: 24px; text-align: center; }

input, button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--bg-3);
  padding: 10px 12px;
}

input { background: var(--bg); color: var(--text); width: 100%; }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}

button.ghost {
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
}

.error { color: var(--danger); font-size: 14px; min-height: 18px; }

#app-view {
  display: flex;
  height: 100dvh;
}

#sidebar {
  width: 280px;
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--bg-3);
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-bottom: 1px solid var(--bg-3);
  font-weight: 600;
}

#chat-list { flex: 1; overflow-y: auto; }

.chat-item {
  padding: 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--bg-3);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.chat-item:hover, .chat-item.active { background: var(--bg-3); }

.chat-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-item .preview {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  margin-top: 6px;
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

#chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--bg-3);
  background: var(--bg-2);
  font-weight: 600;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg { max-width: 75%; }

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

.msg .bubble {
  background: var(--bg-2);
  padding: 8px 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  width: fit-content;
}

.msg.own { align-self: flex-end; text-align: right; }
.msg.own .bubble { background: var(--accent); margin-left: auto; }

#composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--bg-3);
}

#placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

#admin-panel {
  position: absolute;
  inset: 0;
  background: var(--bg);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 10;
}

#admin-panel h2 { margin: 12px 0 4px; font-size: 18px; }

.row { display: flex; gap: 8px; }

.checkboxes {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--bg-3);
  border-radius: 8px;
  padding: 8px;
}

.checkboxes label { display: flex; align-items: center; gap: 8px; }
.checkboxes input { width: auto; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px;
  border-bottom: 1px solid var(--bg-3);
  gap: 8px;
}
.list li .members { color: var(--muted); font-size: 13px; }

.list button.danger { background: transparent; color: var(--danger); padding: 4px 8px; }

@media (max-width: 640px) {
  #sidebar {
    width: 100%;
    position: absolute;
    inset: 0;
    z-index: 5;
  }
  #sidebar.collapsed { display: none; }
  #main { width: 100%; }
  .msg { max-width: 85%; }
}
