:root {
  --bg: #151c27;
  --panel: #1d2838;
  --panel-soft: #213043;
  --line: #2f425d;
  --text: #dfe8f5;
  --muted: #8ea1bd;
  --accent: #6cb7e9;
  --accent-soft: #75cba3;
  --system: #d7c58a;
  --danger: #ff8d8d;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at top, #1e2a3d 0%, var(--bg) 44%);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(205, 228, 255, 0.03) 0,
    rgba(205, 228, 255, 0.03) 1px,
    transparent 1px,
    transparent 3px
  );
  opacity: 0.22;
  z-index: 0;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 250px 1fr;
  position: relative;
  z-index: 1;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #1d2838 0%, #1a2535 100%);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.sidebar-header h2 {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

#onlineCount {
  min-width: 24px;
  text-align: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(106, 166, 255, 0.12);
  color: var(--text);
  font-size: 12px;
  padding: 2px 7px;
}

.users-list {
  list-style: none;
  margin: 0;
  padding: 10px 10px 12px;
  overflow-y: auto;
  min-height: 0;
}

.users-list li {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  padding: 7px 9px;
  border-radius: 8px;
  color: #c9d6ea;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
}

.users-list li::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px rgba(117, 203, 163, 0.2);
}

.users-list li:last-child {
  margin-bottom: 0;
}

.chat {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  background: linear-gradient(180deg, #223146 0%, #1f2b3d 100%);
}

.chat-header {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(23, 33, 48, 0.92);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-shadow: 0 0 8px rgba(108, 183, 233, 0.15);
}

.status {
  min-width: 96px;
  text-align: center;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 12px;
  line-height: 1.2;
  padding: 7px 10px;
}

.status.offline {
  background: rgba(255, 141, 141, 0.12);
  border-color: rgba(255, 141, 141, 0.35);
  color: #ffb5b5;
}

.status.online {
  background: rgba(117, 203, 163, 0.16);
  border-color: rgba(117, 203, 163, 0.38);
  color: #c8efdd;
}

.status.reconnecting {
  background: rgba(108, 183, 233, 0.15);
  border-color: rgba(108, 183, 233, 0.4);
  color: #c6e8fb;
}

.messages {
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.messages:empty::before {
  content: "ожидание входящих сигналов";
  margin: auto;
  padding: 8px 12px;
  border-radius: 7px;
  border: 1px dashed rgba(147, 164, 191, 0.4);
  color: var(--muted);
  font-size: 13px;
}

.msg {
  width: fit-content;
  max-width: min(72ch, 82%);
  border-radius: 12px;
  padding: 8px 11px;
  border: 1px solid transparent;
}

.msg-meta {
  color: #8fa2be;
  font-size: 11px;
  margin-bottom: 4px;
}

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
}

.msg-text a {
  color: #8ed0ff;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg-chat {
  background: rgba(255, 255, 255, 0.045);
  border-color: rgba(255, 255, 255, 0.06);
  align-self: flex-start;
}

.msg-chat.self {
  background: rgba(108, 183, 233, 0.15);
  border-color: rgba(108, 183, 233, 0.3);
  align-self: flex-end;
}

.msg-system {
  align-self: center;
  max-width: 90%;
  text-align: center;
  color: var(--system);
  border-color: rgba(215, 197, 138, 0.35);
  background: rgba(215, 197, 138, 0.1);
  padding: 6px 11px;
  font-size: 12px;
  text-shadow: 0 0 8px rgba(215, 197, 138, 0.22);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: rgba(26, 34, 48, 0.9);
}

.composer input,
.composer button,
.login-card input,
.login-card button {
  border-radius: 10px;
  font: inherit;
}

.composer input,
.login-card input {
  border: 1px solid #415677;
  background: #1b2434;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.composer input:focus,
.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 183, 233, 0.2);
}

.composer button,
.login-card button {
  border: 1px solid var(--accent);
  background: #4f9dcf;
  color: #eff5ff;
  padding: 10px 14px;
  cursor: pointer;
  transition: filter 120ms ease, transform 120ms ease;
}

.composer button:hover:not(:disabled),
.login-card button:hover:not(:disabled) {
  filter: brightness(1.07);
}

.composer button:active:not(:disabled),
.login-card button:active:not(:disabled) {
  transform: translateY(1px);
}

.composer button:disabled,
.login-card button:disabled,
.composer input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 18, 0.74);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 30;
}

.overlay.hidden {
  display: none;
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #202b3c;
}

.login-card h2 {
  margin: 0 0 12px;
  font-size: 18px;
  text-shadow: 0 0 8px rgba(108, 183, 233, 0.14);
}

.login-card form {
  display: grid;
  gap: 8px;
}

.login-card label {
  font-size: 13px;
  color: var(--muted);
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.error {
  min-height: 18px;
  margin: 6px 0 0;
  color: var(--danger);
  font-size: 12px;
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(140px, 26vh) 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
