:root {
  --bg: #15171c;
  --bg2: #1c1f26;
  --bg3: #242832;
  --line: #2f3440;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #5b8def;
  --danger: #e5534b;
  --radius: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; background: var(--accent); border: 0; border-radius: 6px;
  padding: 6px 12px; cursor: pointer; }
button:hover { filter: brightness(1.1); }
button.icon { background: transparent; padding: 4px 8px; font-size: 16px; }
button.link { background: transparent; color: var(--muted); padding: 0; }
button.danger { background: var(--danger); }
button.ghost { background: var(--bg3); }
input, textarea, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; width: 100%; }
label { display: block; margin: 10px 0; color: var(--muted); font-size: 13px; }
label input { margin-top: 4px; }
input[type=color] { flex: 0 0 56px; height: 40px; padding: 2px; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1em; font-size: 13px; }
.spacer { flex: 1; }

.auth { display: grid; place-items: center; height: 100%; padding: 16px; }
.card { background: var(--bg2); padding: 28px; border-radius: 12px; width: 100%; max-width: 360px; }
.card h1 { margin: 0; }
.card button[type=submit] { width: 100%; margin-top: 8px; padding: 10px; }

.app { display: grid; grid-template-columns: 72px 240px 1fr 220px; height: 100%; }
.app.no-members { grid-template-columns: 72px 240px 1fr; }
.app.no-members .members { display: none; }

.guilds { background: var(--bg); padding: 12px 0; display: flex; flex-direction: column; align-items: center; gap: 8px; overflow-y: auto; }
.guild-btn { width: 48px; height: 48px; border-radius: 50%; background: var(--bg3); display: grid; place-items: center;
  font-weight: 600; font-size: 14px; padding: 0; transition: border-radius .15s; }
.guild-btn.active, .guild-btn:hover { border-radius: 16px; background: var(--accent); }
.guild-btn.add { color: #3ba55d; font-size: 22px; }

.sidebar { background: var(--bg2); display: flex; flex-direction: column; min-width: 0; }
.sidebar-head, .chat-head { height: 48px; display: flex; align-items: center; gap: 8px; padding: 0 12px;
  border-bottom: 1px solid var(--line); font-weight: 600; flex-shrink: 0; }
.sidebar-head span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channels { flex: 1; overflow-y: auto; padding: 8px; }
.cat { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin: 14px 6px 4px;
  display: flex; justify-content: space-between; }
.cat button { padding: 0 4px; font-size: 14px; }
.ch { display: flex; gap: 6px; align-items: center; padding: 5px 8px; border-radius: 6px; color: var(--muted);
  cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ch:hover { background: var(--bg3); color: var(--text); }
.ch.active { background: var(--bg3); color: var(--text); }
.ch.thread { margin-left: 18px; font-size: 13px; }
.ch.voice { cursor: default; }
.ch .unread { width: 6px; height: 6px; border-radius: 50%; background: var(--text); margin-left: auto; }
.me { padding: 10px 12px; background: var(--bg); display: flex; justify-content: space-between; align-items: center; }

.chat { display: flex; flex-direction: column; min-width: 0; background: var(--bg3); }
.messages { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; }
.msg { padding: 3px 8px; border-radius: 6px; position: relative; }
.msg:hover { background: rgba(0,0,0,.12); }
.msg .who { font-weight: 600; margin-right: 6px; }
.msg .when { color: var(--muted); font-size: 11px; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; }
.msg.cont .head { display: none; }
.msg .actions { position: absolute; right: 8px; top: -10px; display: none; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 6px; }
.msg:hover .actions { display: flex; }
.msg .actions button { background: transparent; padding: 2px 8px; font-size: 12px; }
.load-more { align-self: center; margin: 8px; }
.typing { height: 18px; padding: 0 18px; }
.composer { padding: 0 16px 16px; }
.composer textarea { resize: none; max-height: 200px; background: var(--bg2); border: 0; padding: 12px; }
.empty { margin: auto; text-align: center; color: var(--muted); }

.members { background: var(--bg2); overflow-y: auto; padding: 8px; }
.member { padding: 5px 8px; border-radius: 6px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member:hover { background: var(--bg3); }
.member .tag { font-size: 11px; color: var(--muted); margin-left: 4px; }

dialog { background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  width: min(560px, calc(100% - 32px)); max-height: 85vh; padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin-top: 0; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { background: var(--bg3); }
.tabs button.active { background: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.row > * { flex: 1; }
.row > button { flex: 0 0 auto; }
.perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
.perm-grid label { display: flex; gap: 8px; align-items: center; margin: 2px 0; color: var(--text); }
.perm-grid input { width: auto; margin: 0; }
.list-item { padding: 6px 8px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.list-item > span { flex: 1; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--bg2);
  border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; z-index: 10; }
.mobile-only { display: none; }

@media (max-width: 800px) {
  .app, .app.no-members { grid-template-columns: 60px 1fr; }
  .sidebar { position: fixed; left: 60px; top: 0; bottom: 0; width: 240px; z-index: 5; display: none; }
  .app.show-sidebar .sidebar { display: flex; }
  .members, .app.no-members .members { position: fixed; right: 0; top: 48px; bottom: 0; width: 220px; z-index: 5; display: none; }
  .app.show-members-mobile .members { display: block; }
  .guild-btn { width: 42px; height: 42px; }
  .mobile-only { display: inline-block; }
}
