:root {
  --bg: #313338;
  --bg-side: #2b2d31;
  --bg-dark: #1e1f22;
  --bg-input: #383a40;
  --text: #dbdee1;
  --muted: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --danger: #f23f42;
  --ok: #23a55a;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1 { margin: 0 0 16px; font-size: 24px; text-align: center; }
h2 {
  margin: 16px 8px 4px;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--bg-dark);
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 8px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); }
button { cursor: pointer; border: 0; border-radius: 4px; }
button.primary { background: var(--accent); color: #fff; padding: 9px 16px; font-weight: 600; }
button.primary:hover { background: var(--accent-hover); }
button.small { background: var(--bg-input); padding: 6px 10px; }
button.small:hover { background: #4a4d55; }
button.wide { width: 100%; margin-top: 6px; }
button.link { background: none; color: var(--muted); padding: 4px 6px; }
button.link:hover { color: var(--text); text-decoration: underline; }
button.center { display: block; margin: 8px auto; }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }

/* auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 16px; background: var(--bg-dark); }
.card { background: var(--bg); width: 100%; max-width: 380px; padding: 28px; border-radius: 8px; box-shadow: 0 8px 24px #0006; }
.card form { display: grid; gap: 12px; }
.card label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; text-transform: uppercase; color: var(--muted); }
.card input { text-transform: none; font-weight: 400; color: var(--text); }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tab { flex: 1; background: var(--bg-input); padding: 8px; color: var(--muted); }
.tab.active { background: var(--accent); color: #fff; }

/* app layout */
.app { display: grid; grid-template-columns: 250px 1fr; height: 100%; }
.sidebar { background: var(--bg-side); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 12px 12px 16px; font-weight: 700; border-bottom: 1px solid var(--bg-dark); }
.side-scroll { flex: 1; overflow-y: auto; padding-bottom: 12px; }
.me { padding: 10px 14px; background: #232428; font-weight: 600; }
.channels, .online { list-style: none; margin: 0; padding: 0 8px; }
.channels button {
  display: block; width: 100%; text-align: left; padding: 6px 8px; margin: 1px 0;
  background: none; color: var(--muted); border-radius: 4px;
}
.channels button:hover:not(:disabled) { background: #35373c; color: var(--text); }
.channels button.active { background: #404249; color: #fff; }
.channels button.unread { color: #fff; font-weight: 700; }
.channels button:disabled { cursor: not-allowed; opacity: .6; }
.online li { padding: 3px 8px; color: var(--muted); }
.online li::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: var(--ok); }
.owner-tools { padding: 0 8px; }
.owner-tools h2 { margin-left: 0; }
.inline-form { display: grid; grid-template-columns: 1fr auto auto; gap: 4px; }
.inline-form select { width: auto; }
#invite-box { margin-top: 6px; display: grid; grid-template-columns: 1fr auto; gap: 4px; }
#invite-box .hint { grid-column: 1 / -1; }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head { display: flex; justify-content: space-between; padding: 12px 16px; font-weight: 700; border-bottom: 1px solid var(--bg-dark); }
.conn { color: var(--danger); font-weight: 400; font-size: 13px; }
.messages { flex: 1; overflow-y: auto; padding: 8px 0; }
.msg { padding: 3px 16px; }
.msg:hover { background: #2e3035; }
.msg .head { display: flex; gap: 8px; align-items: baseline; }
.msg .author { font-weight: 600; color: #fff; }
.msg .time { color: var(--muted); font-size: 12px; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.composer { display: flex; gap: 8px; padding: 0 16px 16px; }
.composer textarea { resize: none; max-height: 160px; background: var(--bg-input); }

@media (max-width: 700px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 38vh; }
}

/* Phase 2: admin screens */
button.danger { color: #fff; background: #8e2a2c; }
button.danger:hover { background: var(--danger); }
.chan-row { display: flex; align-items: center; }
.chan-row > button:first-child { flex: 1; min-width: 0; }
.channels button.gear { width: auto; padding: 4px 6px; opacity: 0; }
.chan-row:hover .gear, .channels button.gear:focus-visible { opacity: 1; }
.msg .head .del { margin-left: auto; opacity: 0; font-size: 12px; padding: 0 4px; }
.msg:hover .head .del { opacity: 1; }
.composer textarea:disabled { opacity: .6; cursor: not-allowed; }

.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-card { background: var(--bg); width: 100%; max-width: 860px; max-height: 90vh; display: flex; flex-direction: column; border-radius: 8px; box-shadow: 0 8px 24px #0008; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; font-weight: 700; border-bottom: 1px solid var(--bg-dark); }
.modal-body { padding: 12px 16px 16px; overflow-y: auto; }
.modal-body .tabs { max-width: 300px; }
.modal-body label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; text-transform: uppercase; color: var(--muted); }
.modal-body input[type=color] { padding: 2px; height: 34px; width: 80px; }
.modal-body h3 { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; color: var(--muted); }

.roles-layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; }
.role-list { list-style: none; margin: 0; padding: 0; }
.role-row { display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 4px; }
.role-row.active { background: #404249; }
.role-row .role-name { flex: 1; text-align: left; background: none; padding: 6px 4px; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.new-role { margin-top: 8px; grid-template-columns: 1fr auto; }
.role-edit { display: grid; gap: 10px; align-content: start; }
.perm-list { display: grid; gap: 6px; }
.perm { display: flex !important; flex-direction: row; align-items: flex-start; gap: 8px; text-transform: none !important; font-weight: 400 !important; color: var(--text) !important; font-size: 14px !important; }
.perm input { width: auto; margin-top: 3px; }
.perm b { display: block; }
.perm small { color: var(--muted); }
.btn-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }

.member-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--bg-dark); flex-wrap: wrap; }
.member-name { font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: flex !important; flex-direction: row; align-items: center; background: var(--bg-input); padding: 4px 8px; border-radius: 12px; text-transform: none !important; font-weight: 400 !important; color: var(--text) !important; font-size: 13px !important; }
.chip input { width: auto; margin-right: 4px; }

.ov-row { border: 1px solid var(--bg-dark); border-radius: 6px; padding: 10px; margin: 10px 0; }
.ov-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ov-head b { flex: 1; }
.badge { background: var(--accent); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 8px; }
.ov-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.ov-add { display: flex; gap: 8px; margin-top: 12px; }
.ov-add select { flex: 1; }

@media (max-width: 700px) { .roles-layout { grid-template-columns: 1fr; } }
