:root {
  --bg: #f4f6f9;
  --sidebar-bg: #ffffff;
  --text: #333;
  --text-sec: #888;
  --accent: #3b7cf0;
  --msg-in: #eef2f7;
  --msg-out: #dcf8c6;
  --border: #ddd;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  justify-content: center;
}

.app {
  display: flex;
  width: 100%;
  max-width: 1200px;
  height: 100%;
  box-shadow: 0 0 20px rgba(0,0,0,0.1);
}

/* --- SIDEBAR --- */
.sidebar {
  width: 320px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.me-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  color: #fff;
  font-weight: bold;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: #ccc;
}

.me-info b { font-size: 16px; display: block; }

.search-wrap {
  padding: 12px;
  position: relative; /* без этого кнопка «＋» уезжает */
}

.search-wrap input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  outline: none;
  font-size: 14px;
}

#newChatBtn {
  position: absolute;
  right: 22px;
  top: 14px;
  width: 38px;
  height: 38px;
  font-size: 16px;
  border-radius: 50%;
}

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

.chat-item {
  display: flex;
  align-items: center;
  padding: 12px;
  cursor: pointer;
  transition: background 0.2s;
  border-bottom: 1px solid #f0f0f0;
  animation: slideIn 0.3s ease forwards;
}

.chat-item:hover { background: #f9f9f9; }
.chat-item.active { background: #eef6ff; }

.chat-item .avatar { margin-right: 12px; width: 44px; height: 44px; font-size: 16px; }

.chat-mid { flex: 1; overflow: hidden; }

.chat-name {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font-weight: 600;
  font-size: 15px;
}

.chat-time { font-size: 12px; color: var(--text-sec); margin-left: 8px; }

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

.badge {
  background: var(--accent);
  color: #fff;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 8px;
}

.read-check {
  float: right;
  color: #88aaff;
  font-weight: bold;
  margin-left: 6px;
  opacity: 0.9;
  font-size: 13px;
}

/* --- CHAT AREA --- */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header .back-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-sec);
  padding: 4px;
}

.chat-header .who { display: flex; flex-direction: column; line-height: 1.2; }
.chat-header .who b { font-size: 16px; }
.chat-header .online-status { font-size: 12px; color: #2ecc71; }
.chat-header .online-status.offline { color: #999; }

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

.msg {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
}

.msg.in  { align-self: flex-start; background: var(--msg-in); border-bottom-left-radius: 2px; }
.msg.out { align-self: flex-end;   background: var(--msg-out); border-bottom-right-radius: 2px; }

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

/* --- INPUT BAR --- */
.input-bar {
  padding: 12px;
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.input-bar input {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 24px;
  outline: none;
  font-size: 14px;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: #888;
  padding: 8px;
  border-radius: 50%;
}

.icon-btn.ghost { background: #f0f0f0; color: #333; }

/* --- EMPTY STATE --- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: #999;
}
.empty-ico { font-size: 48px; margin-bottom: 16px; opacity: 0.6; }

/* --- AUTH --- */
.auth {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.auth-card {
  background: #fff;
  padding: 32px;
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.auth-card h2 { text-align: center; margin-bottom: 8px; }
.auth-sub { color: #888; margin-bottom: 20px; text-align: center; }

.auth-tabs {
  display: flex;
  margin-bottom: 20px;
  border-bottom: 1px solid #eee;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  cursor: pointer;
  color: #888;
  font-weight: 500;
}

.auth-tab.active { color: var(--accent); border-bottom: 2px solid var(--accent); }

#authForm input {
  width: 100%;
  padding: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  font-size: 14px;
}

#authForm input:focus {
  border-color: #bcd6f7;
  box-shadow: 0 0 0 3px #e3edf9;
}

.auth-submit {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.auth-err { margin-top: 12px; color: #d9534f; text-align: center; font-size: 13px; }

/* --- MODAL «новый чат» --- */
#ncOverlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(20, 40, 70, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

.nc-box {
  width: 90%;
  max-width: 340px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(20, 40, 70, 0.2);
  padding: 24px;
}

.nc-box h3 { margin-bottom: 14px; text-align: center; }

.nc-box input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  outline: none;
  font-size: 14px;
  background: #f4f7fb;
}

.nc-btns { display: flex; gap: 10px; }

.nc-btn {
  flex: 1;
  padding: 11px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  background: #f4f7fb;
  color: #5b6b84;
  transition: background 0.25s;
}

.nc-btn.primary {
  background: linear-gradient(135deg, #4f8ef7, #2f6fe4);
  color: #fff;
  box-shadow: 0 4px 14px rgba(47,111,228,0.35);
}

/* --- ANIMATIONS --- */
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

/* --- MOBILE --- */
@media (max-width: 768px) {
  .chat-area.open { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; }
  .sidebar { display: none; }
  .sidebar.visible { display: flex; }
}
