:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --muted: #8b92a3;
  --accent: #5b8cff;
  --accent-2: #3f6fe0;
  --danger: #e5484d;
  --ok: #3ccf91;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }
h1 { font-size: 22px; margin: 8px 0 20px; }
h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.hidden { display: none !important; }
.error { color: var(--danger); min-height: 1em; margin: 6px 0 0; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.empty { color: var(--muted); font-size: 13px; margin: 0; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: #3a4150; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.icon { padding: 8px 10px; }
.btn.off { background: #3a2226; border-color: #5a2a30; }

/* ---------- avatars ---------- */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  color: #fff;
  font-weight: 600;
  background: var(--panel-2);
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.md { width: 40px; height: 40px; font-size: 14px; }
.avatar.xl { width: 96px; height: 96px; font-size: 32px; }

/* ---------- top bar ---------- */

.brand { font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.brand span { color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.me { display: flex; align-items: center; gap: 10px; }
.status { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.status.online { background: var(--ok); }

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

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 240px 1fr 360px;
  gap: 1px;
  background: var(--border);
}
.layout > * { background: var(--bg); min-height: 0; }

.sidebar { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 24px; }
.count {
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 0 7px;
  font-size: 11px;
  letter-spacing: 0;
}

.userlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.userlist li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
}
.userlist li:hover { background: var(--panel); }
.userlist .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 11px; color: var(--muted); }
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(229, 72, 77, .25);
}

/* ---------- video ---------- */

.video-panel { display: flex; flex-direction: column; }
.video-idle {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}
.video-idle h2 { justify-content: center; font-size: 14px; }
.video-idle p { color: var(--muted); max-width: 360px; margin: 0 auto 18px; }
.video-idle .btn { padding: 12px 22px; font-size: 15px; }

.video-live { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 12px; gap: 12px; }
.video-grid {
  --cols: 1;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-auto-rows: 1fr;
  gap: 8px;
}
.tile {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.local video { transform: scaleX(-1); }
.tile-placeholder {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--panel);
}
.tile.no-video .tile-placeholder { display: flex; }
.tile-name {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .6);
  font-size: 12px;
}
.tile.connecting .tile-name::after { content: " · connecting…"; color: var(--muted); }
.tile.failed .tile-name::after { content: " · connection failed"; color: var(--danger); }
.video-controls { display: flex; justify-content: center; gap: 8px; }

/* ---------- chat ---------- */

.chat-panel { display: flex; flex-direction: column; padding: 16px 0 12px; }
.chat-panel h2 { padding: 0 16px; }
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg { display: flex; gap: 10px; }
.msg-main { min-width: 0; flex: 1; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; }
.msg-name { font-weight: 600; }
.msg.mine .msg-name { color: var(--accent); }
.msg-meta time { color: var(--muted); font-size: 11px; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-photo { margin: 4px 0; }
.msg-photo img {
  display: block;
  max-width: 100%;
  max-height: 260px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.msg-photo .download { display: inline-block; margin-top: 4px; font-size: 12px; }

.composer { display: flex; gap: 6px; padding: 12px 16px 0; }
.composer input[type="text"] {
  flex: 1;
  min-width: 0;
}
.chat-panel .error { padding: 0 16px; }

input[type="text"], input[type="password"] {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  outline: none;
}
input[type="text"]:focus, input[type="password"]:focus { border-color: var(--accent); }

/* ---------- standalone pages ---------- */

body.centered { align-items: center; justify-content: center; padding: 20px; }
.card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
}
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.field input { color: var(--text); font-size: 14px; }
.avatar-picker { display: flex; align-items: center; gap: 18px; margin-bottom: 20px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- responsive ---------- */

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; grid-auto-rows: auto; overflow-y: auto; }
  .sidebar { flex-direction: row; flex-wrap: wrap; }
  .sidebar section { flex: 1; min-width: 200px; }
  .video-panel { min-height: 50vh; }
  .chat-panel { height: 70vh; }
}
