* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f1220;
  --bg-2: #161a2e;
  --panel: #1c2138;
  --border: #2a3050;
  --text: #e8eaf6;
  --muted: #9aa1c0;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --green: #22c55e;
  --danger: #ef4444;
}

html, body {
  height: 100%;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--text);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* ---------- Auth ---------- */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.brand {
  text-align: center;
  margin-bottom: 24px;
}

.brand-logo {
  font-size: 40px;
  line-height: 1;
}

.brand h1 {
  font-size: 26px;
  margin-top: 8px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand p {
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}

.auth-form h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

.auth-form label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}

.auth-form input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border 0.2s;
}

.auth-form input:focus {
  border-color: var(--accent);
}

.error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-bottom: 8px;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.switch {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: 16px;
}

.switch a {
  color: var(--accent);
  text-decoration: none;
}

.switch a:hover {
  text-decoration: underline;
}

/* ---------- App layout ---------- */

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand-sm {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-sm .brand-logo {
  font-size: 22px;
}

.brand-name {
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.badge {
  font-size: 12px;
  color: var(--green);
}

.user-chip {
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--muted);
}

.layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: 220px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
}

.sidebar h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 10px;
}

#room-list {
  list-style: none;
}

#room-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.2s;
  color: var(--text);
  font-size: 14px;
}

#room-list li:hover {
  background: var(--bg-2);
}

#room-list li.active {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.room-emoji {
  font-size: 18px;
}

/* ---------- Chat pane ---------- */

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

.room-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

.room-header h2 {
  font-size: 18px;
}

.room-header p {
  color: var(--muted);
  font-size: 13px;
}

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

.msg {
  max-width: 70%;
  animation: pop 0.15s ease;
}

@keyframes pop {
  from { transform: translateY(6px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.msg.mine {
  align-self: flex-end;
}

.msg .bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.msg.mine .bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
}

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

.msg .meta b {
  color: var(--text);
}

.msg.mine .meta {
  text-align: right;
}

.time {
  color: var(--muted);
  font-weight: 400;
}

.sys {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Chat input ---------- */

.chat-input {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.chat-input input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.chat-input input:focus {
  border-color: var(--accent);
}

.chat-input .btn-primary {
  width: auto;
  padding: 0 24px;
}

/* ---------- Loading ---------- */

.loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--muted);
  background: var(--bg);
  z-index: 99;
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .sidebar {
    width: 64px;
    padding: 12px 6px;
  }
  .sidebar h3 { display: none; }
  #room-list li { justify-content: center; padding: 10px 0; }
  #room-list li span.room-label { display: none; }
  .msg { max-width: 90%; }
}
