:root {
  --bg: #12151c;
  --bg-panel: #181c26;
  --bg-elevated: #20242f;
  --border: #2a2f3d;
  --text: #e8e9ee;
  --text-dim: #9199ad;
  --accent: #5b8cff;
  --accent-hover: #7aa0ff;
  --danger: #ff6b6b;
  --success: #51cf66;
  --radius: 10px;
  --font-ui: 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  height: 100vh;
  overflow: hidden;
}

/* ---------- Auth pages ---------- */
body.auth-page {
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 360px;
}

.auth-card h1 {
  margin: 0 0 1.5rem;
  font-size: 1.4rem;
  letter-spacing: -0.01em;
}

.auth-card label {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.auth-card input {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.6rem 0.7rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.95rem;
}

.auth-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-card button {
  width: 100%;
  padding: 0.65rem;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: white;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  margin-top: 0.5rem;
}

.auth-card button:hover { background: var(--accent-hover); }

.auth-switch {
  margin-top: 1.25rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  text-align: center;
}

.auth-switch a, .auth-card a { color: var(--accent); text-decoration: none; }
.auth-switch a:hover, .auth-card a:hover { text-decoration: underline; }

.alert {
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.alert-error { background: rgba(255,107,107,0.12); color: var(--danger); border: 1px solid rgba(255,107,107,0.3); }
.alert-success { background: rgba(81,207,102,0.12); color: var(--success); border: 1px solid rgba(81,207,102,0.3); }

/* ---------- Chat app layout ---------- */
.chat-app {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #12151c;
  flex-shrink: 0;
}

.username { font-weight: 600; font-size: 0.9rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.logout-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 1.1rem;
}
.logout-link:hover { color: var(--danger); }

.admin-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 1.1rem;
}
.admin-link:hover { color: var(--accent); }

.my-role-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.5rem 1rem 0;
}

.role-badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-left: 0.35rem;
}

.rooms-section, .online-section {
  padding: 1rem;
  overflow-y: auto;
}
.rooms-section { flex: 1; border-bottom: 1px solid var(--border); }
.online-section { max-height: 200px; }

.rooms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 0.6rem;
  font-weight: 700;
}

#new-room-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  width: 22px;
  height: 22px;
  cursor: pointer;
  line-height: 1;
}
#new-room-btn:hover { border-color: var(--accent); color: var(--accent); }

.room-list, .online-list { list-style: none; margin: 0; padding: 0; }

.room-list li {
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.room-list li:hover { background: var(--bg-elevated); color: var(--text); }
.room-list li.active { background: var(--accent); color: white; }

.room-online-badge {
  font-size: 0.7rem;
  background: rgba(255,255,255,0.15);
  padding: 0.05rem 0.4rem;
  border-radius: 10px;
}

.online-list li {
  padding: 0.3rem 0;
  font-size: 0.85rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.chat-header h1 { margin: 0; font-size: 1.1rem; }
.chat-header p { margin: 0.2rem 0 0; font-size: 0.85rem; color: var(--text-dim); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.message {
  display: flex;
  gap: 0.6rem;
  max-width: 70%;
}

.message .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #12151c;
}

.message-body { display: flex; flex-direction: column; }

.message-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 0.15rem;
}
.message-meta .name { font-weight: 600; color: var(--text); }

.message-text {
  background: var(--bg-elevated);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.92rem;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message.own { align-self: flex-end; flex-direction: row-reverse; }
.message.own .message-body { align-items: flex-end; }
.message.own .message-text { background: var(--accent); color: white; }

.delete-msg-btn {
  align-self: center;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.85rem;
  opacity: 0.5;
  padding: 0 0.3rem;
}
.delete-msg-btn:hover { opacity: 1; color: var(--danger); }

.mute-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  margin-left: auto;
  opacity: 0.5;
}
.mute-icon-btn:hover { opacity: 1; }

.message-form {
  display: flex;
  gap: 0.6rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  position: relative;
}

.message-form input {
  flex: 1;
  padding: 0.65rem 0.9rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.92rem;
}
.message-form input:focus { outline: none; border-color: var(--accent); }

.message-form button {
  padding: 0.65rem 1.2rem;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: white;
  font-weight: 600;
  cursor: pointer;
}
.message-form button:hover { background: var(--accent-hover); }

/* ---------- Dialog ---------- */
dialog {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 320px;
}
dialog::backdrop { background: rgba(0,0,0,0.5); }
dialog h2 { font-size: 1.05rem; margin: 0 0 1rem; text-transform: none; letter-spacing: normal; color: var(--text); }
dialog label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.9rem; }
dialog input {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.7rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 0.5rem; }
.dialog-actions button {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
}
.dialog-actions button[type="submit"] { background: var(--accent); border-color: var(--accent); color: white; }

@media (max-width: 700px) {
  .sidebar { width: 200px; }
  .message { max-width: 88%; }
}

/* ---------- Admin page ---------- */
body.admin-page {
  overflow-y: auto;
  padding: 0 0 3rem;
}

.admin-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border);
}
.admin-header h1 { margin: 0; font-size: 1.3rem; flex: 1; }
.my-role { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.back-link { color: var(--accent); text-decoration: none; font-size: 0.9rem; }
.back-link:hover { text-decoration: underline; }

.admin-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 2rem;
}

.admin-section {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}
.admin-section h2 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 0 0 1rem;
}

.admin-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.admin-table th, .admin-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
.admin-table th { color: var(--text-dim); font-weight: 600; }

.admin-table select {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.4rem;
}

.admin-table button {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  font-size: 0.8rem;
  margin-right: 0.3rem;
}
.admin-table button:hover { border-color: var(--accent); }
.admin-table button.danger:hover { border-color: var(--danger); color: var(--danger); }

.new-room-inline {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.new-room-inline input {
  flex: 1;
  padding: 0.5rem 0.7rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}
.new-room-inline button {
  padding: 0.5rem 1rem;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.hint { color: var(--text-dim); font-size: 0.85rem; }

.upload-folder-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.upload-folder-label:hover { border-color: var(--accent); }
