:root {
  --bg: #f5f6f8; --panel: #fff; --text: #1d2129; --muted: #6b7280; --border: #e3e5ea;
  --accent: #3b6cf6; --accent-text: #fff; --mine: #e5edff; --err: #d33;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a; --panel: #1d2026; --text: #e8eaee; --muted: #8b93a1; --border: #2c3038;
    --accent: #5b83ff; --accent-text: #fff; --mine: #26334f; --err: #ff6b6b;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, "Malgun Gothic", sans-serif; }
h1, h2 { margin: 0; }
h2 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 12px 14px 6px; }
input, button { font: inherit; color: inherit; }
input { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; width: 100%; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button { white-space: nowrap; cursor: pointer; border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 8px 14px; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.link { border: 0; background: none; color: var(--muted); padding: 0; text-decoration: underline; }
.error { color: var(--err); min-height: 1.4em; margin: 6px 14px; font-size: 13px; }

/* auth */
.auth-body { display: grid; place-items: center; padding: 16px; }
.auth-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: 100%; max-width: 360px; }
.auth-card h1 { text-align: center; margin-bottom: 4px; font-size: 22px; }
.tagline { text-align: center; margin: 0 0 18px; font-size: 13px; color: var(--muted); }
.auth-card form { display: grid; gap: 12px; }
.auth-card label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.auth-card .error { margin: 0; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 16px; }
.tabs button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* app */
.app { display: grid; grid-template-columns: 220px 1fr 200px; height: 100%; }
.sidebar, .users { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.users { border-right: 0; border-left: 1px solid var(--border); }
.sidebar > header { display: flex; justify-content: space-between; align-items: center; padding: 14px; border-bottom: 1px solid var(--border); }
.list { list-style: none; margin: 0; padding: 0 6px; }
.list li { padding: 7px 10px; border-radius: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#rooms li { cursor: pointer; }
#rooms li:hover { background: var(--bg); }
#rooms li.active { background: var(--accent); color: var(--accent-text); }
#new-room { display: flex; gap: 6px; padding: 10px 14px 0; }
#new-room button { padding: 0 12px; }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-header { display: flex; justify-content: space-between; align-items: center; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--border); height: 52px; }
.chat-header h2 { padding: 0; font-size: 16px; color: var(--text); text-transform: none; letter-spacing: 0; }
.conn { font-size: 12px; color: var(--muted); }
.conn.ok { color: #22a55b; }
.conn.bad { color: var(--err); }
.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 75%; align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg.mine .meta { text-align: right; }
.msg .body { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine .body { background: var(--mine); border-color: transparent; }
.typing { min-height: 22px; padding: 0 16px; font-size: 13px; color: var(--muted); }
.composer { display: flex; gap: 8px; padding: 10px 14px 14px; background: var(--panel); border-top: 1px solid var(--border); }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 38vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .users { display: none; }
}
