:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #151a23;
  --muted: #7b8492;
  --line: #e3e7ee;
  --blue: #3f7edb;
  --blue-2: #e7f0ff;
  --green: #23b26b;
  --red: #e54b61;
  --shadow: 0 18px 48px rgba(18, 32, 56, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hidden { display: none !important; }

.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 16% 22%, rgba(63, 126, 219, 0.14), transparent 28%),
    radial-gradient(circle at 82% 80%, rgba(35, 178, 107, 0.1), transparent 24%),
    var(--bg);
}

.auth-card {
  width: min(100%, 440px);
  padding: 28px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}

.brand-mark,
.logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, #3f7edb, #67b7ff);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
}

.brand h1,
.panel-header h2,
.dialog-header h2 {
  margin: 0;
}

.brand p,
.panel-header p,
.dialog-header p,
.auth-note,
.status {
  margin: 4px 0 0;
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 14px;
}

label span {
  display: block;
  margin-bottom: 7px;
  color: #475162;
  font-size: 14px;
  font-weight: 700;
}

input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--text);
  outline: 0;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(63, 126, 219, 0.13);
}

.auth-form button,
.send-button {
  height: 46px;
  border: 0;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  font-weight: 750;
}

.auth-form button:disabled,
.send-button:disabled {
  opacity: 0.5;
  cursor: default;
}

.code-row {
  display: none;
}

.code-row.visible {
  display: block;
}

.auth-note {
  margin-top: 18px;
  font-size: 14px;
  line-height: 1.45;
}

.status {
  min-height: 20px;
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.4;
}

.status.error { color: var(--red); }
.status.ok { color: var(--green); }

.messenger {
  height: 100vh;
  display: grid;
  grid-template-columns: 76px 360px minmax(0, 1fr);
  background: var(--surface);
}

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 18px 12px;
  border-right: 1px solid var(--line);
  background: #fbfcfe;
}

.rail .logo {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  margin-bottom: 8px;
}

.rail-button,
.icon-button,
.back-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
}

.rail-button.active,
.icon-button:hover,
.back-button:hover {
  background: var(--blue-2);
  color: var(--blue);
}

.rail-button.bottom {
  margin-top: auto;
}

.chat-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
}

.panel-header,
.dialog-header {
  min-height: 74px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-header {
  justify-content: space-between;
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 16px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}

.search input {
  border: 0;
  box-shadow: none;
  padding: 0;
}

.chat-list {
  min-height: 0;
  overflow: auto;
  padding: 4px 10px 14px;
}

.chat-item {
  width: 100%;
  min-height: 74px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  border: 0;
  border-radius: 14px;
  padding: 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.chat-item:hover {
  background: #eef3fa;
}

.chat-item.active {
  background: var(--blue-2);
}

.avatar,
.chat-avatar {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, #3f7edb, #67b7ff);
  color: #fff;
  font-weight: 800;
}

.chat-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  font-weight: 750;
}

.chat-title span:first-child,
.chat-preview {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-time,
.chat-preview {
  color: var(--muted);
  font-size: 13px;
}

.dialog {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.back-button {
  display: none;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 24px;
}

.message {
  max-width: 680px;
  margin-bottom: 16px;
}

.message.own {
  margin-left: auto;
}

.message-meta {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.bubble {
  display: inline-block;
  padding: 11px 13px;
  border-radius: 14px;
  background: #f0f3f7;
  line-height: 1.45;
}

.message.own .bubble {
  background: var(--blue);
  color: #fff;
}

.empty-state {
  height: 100%;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
}

.empty-state h3 {
  margin: 0 0 8px;
  color: var(--text);
}

.composer {
  min-height: 76px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 112px;
  gap: 12px;
  align-items: center;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

@media (max-width: 900px) {
  .messenger {
    grid-template-columns: 1fr;
  }

  .rail {
    display: none;
  }

  .chat-panel,
  .dialog {
    height: 100vh;
  }

  .messenger.chat-open .chat-panel {
    display: none;
  }

  .messenger:not(.chat-open) .dialog {
    display: none;
  }

  .back-button {
    display: grid;
  }

  .composer {
    grid-template-columns: 42px minmax(0, 1fr) 84px;
  }
}
