:root {
  --bg: #f2f6fc;
  --bg-soft: #e8eff8;
  --card: #ffffff;
  --accent: #3b82f6;
  --accent-deep: #1e5fd6;
  --accent-soft: #dcebff;
  --text: #1c2740;
  --text-soft: #7b8aa5;
  --divider: #e3ebf5;
  --radius: 16px;
  --shadow: 0 8px 28px rgba(30, 95, 214, 0.10);
  --ease: cubic-bezier(0.33, 1, 0.68, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'Segoe UI', Roboto, -apple-system, sans-serif;
  background: linear-gradient(160deg, #f4f8fe 0%, #eaf1fa 40%, #e3edf9 100%);
  color: var(--text);
  overflow: hidden;
}

.app { height: 100vh; height: 100dvh; display: flex; }

/* ---------- Левая панель ---------- */
.sidebar {
  width: 340px; min-width: 300px;
  display: flex; flex-direction: column;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(14px);
  border-right: 1px solid var(--divider);
  transition: margin-left 0.4s var(--ease);
}
.profile {
  padding: 16px 18px;
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(135deg, #4f8ef7 0%, #2f6fe4 55%, #5aa0ff 100%);
  color: #fff;
  border-bottom-left-radius: 18px;
  border-bottom-right-radius: 18px;
  box-shadow: var(--shadow);
}
.avatar {
  width: 46px; height: 46px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.7);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: #fff;
}
.avatar.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.35), rgba(255,255,255,0.7), rgba(255,255,255,0.35));
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
.profile b { display: block; font-size: 15px; }
.profile .status { font-size: 12px; opacity: 0.85; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #6ef7a5; box-shadow: 0 0 0 0 rgba(110,247,165,0.6); animation: pulse 2s infinite; }

.search-wrap { padding: 14px 16px 8px; }
.search {
  width: 100%; padding: 11px 16px;
  border: none; border-radius: 12px;
  background: var(--bg-soft);
  outline: none; font-size: 14px; color: var(--text);
  transition: box-shadow 0.3s var(--ease), background 0.3s var(--ease);
}
.search:focus { background: #fff; box-shadow: 0 0 0 2px var(--accent-soft), 0 4px 14px rgba(59,130,246,0.12); }

.chat-list { flex: 1; overflow-y: auto; padding: 8px 10px 16px; }
.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb { background: #c9d8ee; border-radius: 6px; }

.chat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 14px;
  cursor: pointer;
  transition: background 0.25s var(--ease), transform 0.25s var(--ease);
  opacity: 0; transform: translateY(8px);
  animation: fadeUp 0.4s var(--ease) forwards;
}
.chat-item:hover { background: #edf3fb; transform: translateX(2px); }
.chat-item.active { background: linear-gradient(135deg, #e3eeff, #dbe9ff); box-shadow: inset 0 0 0 1px #c9defc; }
.chat-item .avatar { width: 48px; height: 48px; border: none; }
.chat-mid { flex: 1; min-width: 0; }
.chat-name { font-weight: 600; font-size: 14.5px; display: flex; justify-content: space-between; }
.chat-time { font-size: 11px; color: var(--text-soft); font-weight: 400; }
.chat-last { font-size: 13px; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: linear-gradient(135deg, #4f8ef7, #2f6fe4);
  color: #fff; font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  animation: pop 0.35s var(--ease);
}

/* Скелетоны */
.skeleton-item { display: flex; gap: 12px; padding: 10px 12px; align-items: center; }
.sk {
  border-radius: 10px;
  background: linear-gradient(90deg, #e6edf6 25%, #f3f7fd 50%, #e6edf6 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
.sk.avatar { width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0; }
.sk.line { height: 12px; }
.sk.w60 { width: 60%; }
.sk.w40 { width: 40%; }

/* ---------- Правая панель ---------- */
.chat-area {
  flex: 1; display: flex; flex-direction: column;
  position: relative; min-width: 0;
  background: linear-gradient(165deg, #f2f7fe 0%, #e9f1fb 45%, #e2ecf9 100%);
}
/* Лёгкий фон чата в духе VK: переливы + паттерн */
.chat-area::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background-image:
    radial-gradient(600px 400px at 15% 10%, rgba(120, 170, 255, 0.14), transparent 60%),
    radial-gradient(700px 500px at 85% 80%, rgba(90, 140, 235, 0.12), transparent 60%),
    radial-gradient(500px 350px at 60% 30%, rgba(160, 200, 255, 0.10), transparent 65%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='none' stroke='%23a8c4ec' stroke-width='1.5'%3E%3Ccircle cx='30' cy='30' r='7'/%3E%3Cpath d='M78 22l14 8-14 8z'/%3E%3Crect x='22' y='80' width='14' height='14' rx='4' transform='rotate(15 29 87)'/%3E%3Cpath d='M70 92c6-8 14-8 20 0'/%3E%3Ccircle cx='104' cy='58' r='4'/%3E%3C/g%3E%3C/svg%3E");
  background-size: auto, auto, auto, 120px 120px;
}
/* Контент — выше фона */
.chat-header, .messages, .input-bar, .empty-state { position: relative; z-index: 1; }

.chat-header {
  padding: 12px 22px; display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,0.75); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--divider);
}
.back-btn {
  display: none;
  width: 38px; height: 38px; border: none; border-radius: 50%;
  background: var(--bg-soft); color: var(--accent-deep);
  font-size: 18px; cursor: pointer;
  transition: background 0.25s var(--ease), transform 0.15s var(--ease);
}
.back-btn:active { transform: scale(0.92); }
.chat-header .avatar { width: 42px; height: 42px; }
.chat-header .who b { display: block; font-size: 15px; }
.chat-header .who .online-status { font-size: 12px; color: #2fb56b; }

.messages {
  flex: 1; overflow-y: auto; padding: 24px 8%;
  display: flex; flex-direction: column; gap: 6px;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: #c9d8ee; border-radius: 6px; }

.msg {
  max-width: 62%;
  padding: 10px 14px 8px;
  border-radius: 18px;
  font-size: 14.5px; line-height: 1.45;
  opacity: 0; transform: translateY(12px) scale(0.97);
  animation: msgIn 0.35s var(--ease) forwards;
  position: relative;
  box-shadow: 0 2px 10px rgba(30, 95, 214, 0.06);
  word-break: break-word;
}
.msg.out {
  align-self: flex-end;
  color: #fff;
  background: linear-gradient(135deg, #4f8ef7 0%, #2f6fe4 70%, #3f7ff0 100%);
  border-bottom-right-radius: 6px;
}
.msg.in {
  align-self: flex-start;
  background: #ffffff;
  border-bottom-left-radius: 6px;
  border: 1px solid #edf2fa;
}
.msg .time { display: block; font-size: 10.5px; opacity: 0.65; text-align: right; margin-top: 5px; }
.msg .media {
  width: 260px; max-width: 100%;
  border-radius: 12px; overflow: hidden; margin-bottom: 6px;
  background: linear-gradient(120deg, #d6e6fb, #eef4fc);
}
.msg .media img { display: block; width: 100%; }
.msg .voice { display: flex; align-items: center; gap: 10px; padding: 4px 2px; }
.play-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(255,255,255,0.25); color: #fff; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s var(--ease);
}
.msg.in .play-btn { background: var(--accent-soft); color: var(--accent-deep); }
.play-btn:hover { transform: scale(1.08); }
.wave { display: flex; align-items: center; gap: 3px; height: 26px; }
.wave i {
  width: 3px; border-radius: 3px; background: rgba(255,255,255,0.6);
  animation: wave 1.2s ease-in-out infinite;
}
.msg.in .wave i { background: #bcd6f7; }

.msg.sending { opacity: 0.6; filter: saturate(0.7); }

.typing {
  align-self: flex-start; display: flex; gap: 4px; padding: 12px 16px;
  background: #fff; border-radius: 18px; border-bottom-left-radius: 6px;
  border: 1px solid #edf2fa; width: fit-content;
}
.typing i {
  width: 7px; height: 7px; border-radius: 50%; background: #9db9e6;
  animation: bounce 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }

.input-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,0.8); backdrop-filter: blur(12px);
  border-top: 1px solid var(--divider);
}
.input-bar input {
  flex: 1; min-width: 0; padding: 13px 18px;
  border-radius: 22px; border: 1px solid #e3ebf5;
  outline: none; font-size: 14.5px; background: var(--bg-soft);
  transition: box-shadow 0.3s var(--ease), background 0.3s var(--ease), border-color 0.3s var(--ease);
}
.input-bar input:focus {
  background: #fff; border-color: #bcd6f7;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.icon-btn {
  width: 46px; height: 46px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(135deg, #4f8ef7, #2f6fe4);
  color: #fff; font-size: 18px; flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(47,111,228,0.35);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), opacity 0.3s;
}
.icon-btn:hover { transform: translateY(-2px); box-shadow: 0 7px 18px rgba(47,111,228,0.45); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.ghost { background: var(--bg-soft); color: var(--accent-deep); box-shadow: none; }

/* Пустое состояние */
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  opacity: 0; animation: fadeUp 0.6s var(--ease) 0.2s forwards;
  text-align: center; padding: 20px;
}
.empty-ico {
  width: 92px; height: 92px; border-radius: 30px;
  background: linear-gradient(135deg, #dcebff, #c3dcfb);
  display: flex; align-items: center; justify-content: center; font-size: 40px;
  box-shadow: var(--shadow);
  animation: float 4s ease-in-out infinite;
}
.empty-state h2 { color: var(--text); font-weight: 600; }
.empty-state p { color: var(--text-soft); font-size: 14px; max-width: 300px; }

/* ---------- Мобильная адаптация ---------- */
@media (max-width: 768px) {
  .sidebar { width: 100%; min-width: 0; }
  .chat-area {
    position: fixed; inset: 0; z-index: 10;
    transform: translateX(100%);
    transition: transform 0.4s var(--ease);
  }
  .chat-area.open { transform: translateX(0); }
  .back-btn { display: flex; align-items: center; justify-content: center; }
  .messages { padding: 18px 5%; }
  .msg { max-width: 82%; }
  .msg .media { width: 220px; }
}

/* ---------- Анимации ---------- */
@keyframes fadeUp { to { opacity: 1; transform: translateY(0); } }
@keyframes msgIn { to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(110,247,165,0.6); }
  70% { box-shadow: 0 0 0 7px rgba(110,247,165,0); }
  100% { box-shadow: 0 0 0 0 rgba(110,247,165,0); }
}
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}
@keyframes wave { 0%, 100% { transform: scaleY(0.5); } 50% { transform: scaleY(1.4); } }
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* ---------- Экран входа ---------- */
.auth {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #f4f8fe, #e3edf9);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 360px;
  background: #fff; border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px;
  animation: fadeUp 0.5s var(--ease);
}
.auth-card h2 { text-align: center; margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--text-soft); font-size: 13px; margin-bottom: 20px; }
.auth-tabs { display: flex; gap: 6px; background: var(--bg-soft); padding: 4px; border-radius: 12px; margin-bottom: 16px; }
.auth-tab {
  flex: 1; padding: 9px; border: none; background: transparent;
  border-radius: 9px; cursor: pointer; font-size: 14px;
  color: var(--text-soft); transition: all 0.25s var(--ease);
}
.auth-tab.active { background: #fff; color: var(--accent-deep); font-weight: 600; box-shadow: 0 2px 8px rgba(30,95,214,0.12); }
.auth-card input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px;
  border: 1px solid var(--divider); border-radius: 12px;
  outline: none; font-size: 14px; background: var(--bg-soft);
  transition: box-shadow 0.3s var(--ease), background 0.3s;
}
.auth-card input:focus { background: #fff; border-color: #bcd6f7; box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-submit {
  width: 100%; padding: 13px; border: none; border-radius: 12px;
  background: linear-gradient(135deg, #4f8ef7, #2f6fe4);
  color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 14px rgba(47,111,228,0.35);
  transition: transform 0.2s var(--ease);
}
.auth-submit:hover { transform: translateY(-1px); }
.auth-err { color: #d33; font-size: 13px; text-align: center; min-height: 18px; margin-top: 6px; }

/* ---------- Окно нового чата ---------- */
#ncOverlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(20, 40, 70, 0.35);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.25s var(--ease);
}
.nc-box {
  width: 90%; max-width: 340px;
  background: #fff; border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px;
  animation: fadeUp 0.35s var(--ease);
}
.nc-box h3 { margin-bottom: 14px; text-align: center; }
.nc-box input {
  width: 100%; padding: 12px 14px; margin-bottom: 16px;
  border: 1px solid var(--divider); border-radius: 12px;
  outline: none; font-size: 14px; background: var(--bg-soft);
}
.nc-box input:focus { background: #fff; border-color: #bcd6f7; box-shadow: 0 0 0 3px var(--accent-soft); }
.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: var(--bg-soft); color: var(--text-soft);
  transition: background 0.25s var(--ease);
}
.nc-btn.primary {
  background: linear-gradient(135deg, #4f8ef7, #2f6fe4);
  color: #fff;
  box-shadow: 0 4px 14px rgba(47,111,228,0.35);
}

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