:root {
  --bg: #f5f3ff;
  --panel: #ffffff;
  --text: #171323;
  --muted: #7a718f;
  --primary: #6d4aff;
  --primary-dark: #5636db;
  --line: #ece8ff;
  --bubble-me: #6d4aff;
  --bubble-them: #ffffff;
  --shadow: 0 18px 45px rgba(69, 45, 145, .13);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, textarea {
  font: inherit;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(109,74,255,.20), transparent 35%),
    linear-gradient(135deg, #f8f6ff, #efeaff);
}

.login-card {
  width: min(420px, 100%);
  background: rgba(255,255,255,.94);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--primary);
  font-size: 28px;
  margin-bottom: 18px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 30px;
}

.muted, .small-note {
  color: var(--muted);
}

.small-note {
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 0;
}

.alert {
  background: #fff1f1;
  color: #9f1239;
  border: 1px solid #fecdd3;
  border-radius: 14px;
  padding: 12px 14px;
  margin: 18px 0;
}

.login-form {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

.login-form label {
  display: grid;
  gap: 7px;
  font-weight: 700;
  font-size: 14px;
}

.login-form input {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  outline: none;
}

.login-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(109,74,255,.12);
}

.login-form button,
.composer button {
  border: 0;
  border-radius: 16px;
  padding: 14px 18px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.login-form button:hover,
.composer button:hover {
  background: var(--primary-dark);
}

#app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 340px 1fr;
}

.sidebar {
  background: rgba(255,255,255,.92);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  padding: 18px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.topbar strong {
  display: block;
  font-size: 18px;
}

.topbar span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 9px 12px;
  cursor: pointer;
}

.contacts {
  padding: 12px;
  display: grid;
  gap: 8px;
  overflow: auto;
}

.contact {
  border: 0;
  width: 100%;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 18px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}

.contact:hover, .contact.active {
  background: #f0ecff;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 900;
  text-transform: uppercase;
}

.contact-text {
  flex: 1;
  min-width: 0;
}

.contact-text strong,
.contact-text small {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-text small {
  color: var(--muted);
  margin-top: 3px;
}

.badge {
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 900;
}

.chat {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
}

.chat-header {
  background: rgba(255,255,255,.88);
  border-bottom: 1px solid var(--line);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header strong,
.chat-header span {
  display: block;
}

.chat-header span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.back {
  display: none;
  border: 0;
  background: #f0ecff;
  color: var(--primary);
  border-radius: 13px;
  width: 42px;
  height: 42px;
  font-size: 22px;
}

.messages {
  padding: 22px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.messages.empty {
  justify-content: center;
  align-items: center;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  display: grid;
  gap: 8px;
}

.empty-state div {
  font-size: 42px;
}

.empty-state strong {
  color: var(--text);
}

.msg {
  max-width: min(72%, 680px);
  padding: 11px 13px;
  border-radius: 18px;
  line-height: 1.35;
  box-shadow: 0 8px 20px rgba(69,45,145,.08);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg.me {
  align-self: flex-end;
  background: var(--bubble-me);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msg.them {
  align-self: flex-start;
  background: var(--bubble-them);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.msg-time {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  opacity: .72;
}

.composer {
  padding: 14px;
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.90);
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 13px 14px;
  min-height: 48px;
  max-height: 140px;
  outline: none;
}

.composer textarea:focus {
  border-color: var(--primary);
}

.composer button:disabled,
.composer textarea:disabled {
  opacity: .55;
  cursor: not-allowed;
}

@media (max-width: 780px) {
  #app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: 100vh;
  }

  .chat {
    display: none;
  }

  body.chat-open .sidebar {
    display: none;
  }

  body.chat-open .chat {
    display: grid;
  }

  .back {
    display: inline-grid;
    place-items: center;
  }

  .msg {
    max-width: 86%;
  }
}

.install-box {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 9999;
  max-width: 520px;
  margin: 0 auto;
  background: rgba(255,255,255,.97);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  align-items: center;
}

.install-box.hidden {
  display: none;
}

.install-box p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.install-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.install-actions button {
  border: 0;
  border-radius: 14px;
  padding: 10px 13px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.install-actions .ghost {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}

@media (max-width: 560px) {
  .install-box {
    align-items: flex-start;
    flex-direction: column;
  }
}

.group-item {
  border: 1px solid var(--line);
  background: #fff;
}
