:root {
  --bg: #0e1419;
  --bg-elev: #15202b;
  --bg-chat: #0b1116;
  --sidebar: #121a22;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e7ecf1;
  --muted: #8b9aab;
  --accent: #3d9cf0;
  --accent-soft: rgba(61, 156, 240, 0.16);
  --green: #3ecf8e;
  --danger: #e35d6a;
  --bubble-in: #1c2733;
  --bubble-out: #1a3a55;
  --wash: radial-gradient(1200px 600px at 10% -10%, #1a3050 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #163528 0%, transparent 45%),
    linear-gradient(160deg, #0e1419, #101820 40%, #0c1218);
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--wash);
  background-color: var(--bg);
}

button, input { font: inherit; }
button {
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  padding: 0.65rem 1rem;
  background: var(--accent);
  color: #041018;
  font-weight: 600;
}
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
button:disabled { opacity: 0.5; cursor: default; }

#app { min-height: 100%; }

/* ——— Login ——— */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
}
.login-card {
  width: min(440px, 100%);
  text-align: center;
}
.brand {
  font-family: var(--display);
  font-size: clamp(2.4rem, 6vw, 3.2rem);
  letter-spacing: -0.03em;
  margin: 0 0 0.35rem;
}
.login-card p {
  color: var(--muted);
  margin: 0 0 1.75rem;
  line-height: 1.45;
}
.qr-wrap {
  margin: 0 auto 1.25rem;
  padding: 1rem;
  width: fit-content;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.qr-wrap canvas { display: block; }
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 500;
}
.status-pill::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1); }
}
.hint {
  margin-top: 1.5rem;
  color: var(--muted);
  font-size: 0.92rem;
}
.hint strong { color: var(--text); font-weight: 600; }

/* ——— Shell ——— */
.shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: rgba(10, 14, 18, 0.55);
  backdrop-filter: blur(10px);
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .shell.chat-open .sidebar { display: none; }
  .shell:not(.chat-open) .main { display: none; }
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-top {
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.side-top h1 {
  font-family: var(--display);
  font-size: 1.35rem;
  margin: 0;
}
.me {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.15rem;
}
.peer-list {
  overflow: auto;
  flex: 1;
  padding: 0.4rem;
}
.peer {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 0.7rem;
  padding: 0.7rem 0.75rem;
  border-radius: 12px;
  cursor: pointer;
  align-items: center;
}
.peer:hover, .peer.active { background: var(--accent-soft); }
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: linear-gradient(145deg, #2b5f8f, #1d3d58);
  color: #d9ecff;
}
.peer-name { font-weight: 600; font-size: 0.95rem; }
.peer-prev {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background:
    radial-gradient(800px 400px at 70% -20%, rgba(45, 110, 160, 0.18), transparent 60%),
    var(--bg-chat);
}
.chat-top {
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(18, 26, 34, 0.72);
}
.chat-top .title { font-weight: 600; }
.chat-top .sub { color: var(--muted); font-size: 0.8rem; }
.messages {
  flex: 1;
  overflow: auto;
  padding: 1rem 1.1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.msg {
  max-width: min(72%, 520px);
  padding: 0.55rem 0.75rem 0.35rem;
  border-radius: 14px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.in {
  align-self: flex-start;
  background: var(--bubble-in);
  border-bottom-left-radius: 5px;
}
.msg.out {
  align-self: flex-end;
  background: var(--bubble-out);
  border-bottom-right-radius: 5px;
}
.msg .meta {
  display: block;
  text-align: right;
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 0.2rem;
}
.composer {
  display: flex;
  gap: 0.6rem;
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid var(--line);
  background: rgba(18, 26, 34, 0.85);
}
.composer input {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  outline: none;
}
.composer input:focus { border-color: rgba(61, 156, 240, 0.55); }
.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 2rem;
}
.error {
  color: var(--danger);
  margin-top: 0.75rem;
  font-size: 0.9rem;
}
