:root {
  --bg-sidebar: #17212b;
  --bg-chat: #0e1621;
  --bg-header: #17212b;
  --bg-composer: #17212b;
  --bg-active-chat: #2b5278;
  --bg-msg-in: #182533;
  --bg-msg-out: #2b5278;
  --text-primary: #f5f5f5;
  --text-secondary: #7f91a4;
  --accent-color: #5288c1;
  --accent-hover: #6499d3;
  --border-color: #101921;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-chat);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

.mono-text {
  font-family: 'JetBrains Mono', monospace;
}

.hidden {
  display: none !important;
}

/* Сетка приложения */
.app-layout {
  display: flex;
  width: 100vw;
  height: 100vh;
}

/* Сайдбар */
.sidebar {
  width: 360px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  height: 56px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.search-box {
  flex: 1;
  background: #242f3d;
  border-radius: 20px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  color: var(--text-secondary);
}

.search-box input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  height: 36px;
}

.chats-list {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.chat-item:hover {
  background: #202b36;
}

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

.avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4086f4, #31c976);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
}

.chat-meta {
  flex: 1;
  min-width: 0;
}

.chat-meta-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.chat-item-title {
  font-weight: 500;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time {
  font-size: 12px;
  color: var(--text-secondary);
}

.chat-item-preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Профиль внизу сайдбара */
.my-profile-bar {
  height: 64px;
  background: #1e2a36;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 10px;
}

.profile-meta {
  flex: 1;
  min-width: 0;
}

.my-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.my-addr {
  font-size: 11px;
  color: var(--text-secondary);
}

/* Область переписки */
.chat-viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #0e1621;
  position: relative;
}

.empty-chat-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bubble-tip {
  background: rgba(0, 0, 0, 0.35);
  padding: 8px 16px;
  border-radius: 16px;
  font-size: 14px;
  color: var(--text-secondary);
}

.active-chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  height: 56px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
}

.chat-header .avatar {
  width: 40px;
  height: 40px;
  font-size: 16px;
}

.chat-title {
  font-size: 15px;
  font-weight: 700;
}

.chat-status {
  font-size: 12px;
  color: #4fae4e;
}

/* Поток сообщений */
.messages-flow {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  max-width: 460px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.4;
  position: relative;
  word-break: break-word;
}

.msg.in {
  align-self: flex-start;
  background: var(--bg-msg-in);
  border-bottom-left-radius: 0;
}

.msg.out {
  align-self: flex-end;
  background: var(--bg-msg-out);
  border-bottom-right-radius: 0;
}

.msg-time {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  float: right;
  margin-left: 10px;
  margin-top: 4px;
}

/* Поле ввода */
.chat-composer {
  background: var(--bg-composer);
  border-top: 1px solid var(--border-color);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-composer input {
  flex: 1;
  height: 40px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 15px;
}

.send-btn {
  background: transparent;
  border: none;
  color: var(--accent-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
}

.send-btn:hover {
  color: var(--accent-hover);
  transform: scale(1.08);
}

/* Модальное окно входа */
.auth-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.auth-card {
  width: 380px;
  background: #17212b;
  border-radius: 12px;
  padding: 32px 28px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
  text-align: center;
}

.auth-logo {
  margin-bottom: 16px;
}

.auth-card h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.auth-card p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.auth-step {
  display: none;
}

.auth-step.active {
  display: block;
}

.input-group {
  text-align: left;
  margin-bottom: 16px;
}

.input-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.input-group input {
  width: 100%;
  height: 44px;
  background: #242f3d;
  border: 1px solid #1c2733;
  border-radius: 8px;
  color: #fff;
  padding: 0 12px;
  font-size: 14px;
  outline: none;
}

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

.mono-input {
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px !important;
  letter-spacing: 4px;
  text-align: center;
}

.username-prefix-input {
  display: flex;
  align-items: center;
  background: #242f3d;
  border: 1px solid #1c2733;
  border-radius: 8px;
  padding-left: 12px;
}

.username-prefix-input span {
  color: var(--accent-color);
  font-weight: 700;
  font-size: 16px;
}

.username-prefix-input input {
  border: none;
  background: transparent;
}

.tg-btn {
  width: 100%;
  height: 44px;
  background: var(--accent-color);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
}

.tg-btn:hover {
  background: var(--accent-hover);
}

.tg-btn-link {
  background: transparent;
  border: none;
  color: var(--accent-color);
  font-size: 13px;
  cursor: pointer;
  margin-top: 12px;
}

.auth-hint {
  font-size: 12px !important;
  line-height: 1.4;
  margin-top: 8px;
}

.auth-error-msg {
  color: #ff5959;
  font-size: 13px;
  margin-top: 14px;
  min-height: 18px;
}
