:root {
  --bg: #eef1f6;
  --panel: #ffffff;
  --border: #dde3ec;
  --text: #1d2530;
  --muted: #7c8798;
  --accent: #3b6ef5;
  --accent-dark: #2f59c9;
  --own: #3b6ef5;
  --own-text: #ffffff;
  --other: #eef1f6;
  --online: #34c77b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

/* ---------- Экран входа ---------- */
.join-screen {
  height: 100vh;
  display: grid;
  place-items: center;
}

.join-card {
  background: var(--panel);
  padding: 34px 30px;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(29, 37, 48, 0.12);
  width: min(360px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.join-card h1 {
  margin: 0;
  font-size: 32px;
  letter-spacing: 3px;
  color: var(--accent);
  text-align: center;
}

.join-card p {
  margin: 0;
  text-align: center;
  font-size: 14px;
}

input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

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

button {
  padding: 12px 18px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover {
  background: var(--accent-dark);
}

.error {
  color: #d94141;
  font-size: 13px;
  min-height: 18px;
  text-align: center;
}

/* ---------- Экран чата ---------- */
.chat-screen {
  height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.me-name {
  font-weight: 700;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 10px;
}

.icon-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.sidebar-title {
  margin: 14px 16px 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.users-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 12px;
  overflow-y: auto;
  flex: 1;
}

.user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
}

.user:hover {
  background: var(--bg);
}

.user.active {
  background: #e6edff;
}

.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  text-transform: uppercase;
}

.user-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #c6ced9;
}

.dot.online {
  background: var(--online);
}

.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  padding: 1px 7px;
}

.empty-note {
  padding: 0 16px;
  font-size: 13px;
}

/* ---------- Область переписки ---------- */
.chat {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  font-weight: 600;
  font-size: 16px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  max-width: 62%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg.own {
  align-self: flex-end;
  background: var(--own);
  color: var(--own-text);
  border-bottom-right-radius: 4px;
}

.msg.other {
  align-self: flex-start;
  background: var(--other);
  border-bottom-left-radius: 4px;
}

.msg .time {
  display: block;
  font-size: 11px;
  opacity: 0.7;
  margin-top: 4px;
  text-align: right;
}

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

.composer input {
  flex: 1;
}

/* ---------- Телефон ---------- */
@media (max-width: 640px) {
  .chat-screen {
    grid-template-columns: 110px 1fr;
  }
  .sidebar-title {
    display: none;
  }
  .user {
    padding: 8px;
  }
  .msg {
    max-width: 82%;
  }
}
