/* ============================================================================
   Основной экран мессенджера
   ========================================================================== */
.app-screen {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 12px;
  padding: 12px;
}

/* ── Боковая панель ───────────────────────────────────────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 0;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
}
.sidebar-brand { display: flex; align-items: center; gap: 9px; }
.sidebar-mark { width: 30px; height: 30px; object-fit: contain; filter: drop-shadow(0 2px 8px var(--thread-glow)); }
.sidebar-title { font-family: var(--font-display); font-weight: 700; font-size: 20px; letter-spacing: 0.04em; }

.sidebar-search {
  position: relative;
  padding: 0 16px 12px;
}
.sidebar-search i {
  position: absolute;
  left: 28px; top: 50%;
  transform: translateY(-60%);
  width: 16px; height: 16px;
  color: var(--text-faint);
  pointer-events: none;
}
.sidebar-search .input { padding-left: 38px; }

.sidebar-nav {
  display: flex;
  gap: 7px;
  padding: 0 16px 12px;
  flex-wrap: wrap;
}
.nav-pill {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 99px;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.nav-pill.active {
  background: var(--secure-dim);
  border-color: rgba(52, 211, 153, 0.3);
  color: var(--secure);
}
.nav-pill[data-soon="true"] { opacity: 0.6; }
.soon {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 5px;
  border-radius: 5px;
  color: var(--text-faint);
}

.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px; min-height: 0; }

.list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 100%;
  color: var(--text-faint);
  text-align: center;
  padding: 20px;
}
.list-empty i { width: 34px; height: 34px; opacity: 0.5; }
.list-empty p { font-size: 13px; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.18s;
  position: relative;
}
.chat-item:hover { background: rgba(255, 255, 255, 0.04); }
.chat-item.active { background: rgba(99, 102, 241, 0.13); }
.chat-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 18%;
  height: 64%;
  width: 3px;
  border-radius: 99px;
  background: linear-gradient(var(--thread-1), var(--thread-2));
}
.chat-item-meta { flex: 1; min-width: 0; }
.chat-item-name { font-weight: 600; font-size: 14.5px; color: var(--text); display: block; }
.chat-item-preview {
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}
.chat-item-preview i { width: 12px; height: 12px; }
.chat-item-badge {
  background: #3b9eff;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 99px;
  display: grid;
  place-items: center;
  padding: 0 6px;
  box-shadow: 0 2px 8px rgba(59, 158, 255, 0.4);
  flex-shrink: 0;
}

/* Плашка-сводка непрочитанных при входе */
.unread-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 14px 0;
  padding: 12px 14px;
  background: linear-gradient(120deg, rgba(59, 158, 255, 0.16), rgba(99, 102, 241, 0.16));
  border: 1px solid rgba(59, 158, 255, 0.3);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--text);
  animation: rise 0.4s var(--ease) both;
}
.unread-banner i[data-lucide="bell"] {
  width: 18px; height: 18px;
  color: #3b9eff;
  flex-shrink: 0;
}
.unread-banner span { flex: 1; line-height: 1.4; }
.unread-banner-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.unread-banner-close:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.unread-banner-close i { width: 15px; height: 15px; }

/* Профиль внизу */
.sidebar-profile {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.profile-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.profile-name { font-weight: 600; font-size: 14px; }
.profile-status { font-size: 11.5px; color: var(--secure); display: flex; align-items: center; gap: 5px; }
.dot-online, .dot-secure { width: 7px; height: 7px; border-radius: 50%; background: var(--secure); box-shadow: 0 0 6px var(--secure); }
.dot-thread { width: 7px; height: 7px; border-radius: 50%; background: var(--thread-1); box-shadow: 0 0 6px var(--thread-glow); display:inline-block; }
.dot-secure { display:inline-block; }

/* ── Окно чата ────────────────────────────────────────────────────────────── */
.chat-pane {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--border);
  min-height: 0;
}

.chat-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 20px;
}
.chat-empty-mark { width: 76px; height: 76px; object-fit: contain; opacity: 0.85; filter: drop-shadow(0 6px 24px var(--thread-glow)); margin-bottom: 4px; }
.chat-empty h2 { font-family: var(--font-display); font-weight: 600; font-size: 22px; }
.chat-empty p { color: var(--text-dim); font-size: 14px; line-height: 1.6; }

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

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
}
.chat-back { display: none; }
.chat-header-meta { flex: 1; min-width: 0; }
.chat-peer-name { font-weight: 600; font-size: 16px; display: block; }
.chat-peer-status { font-size: 12px; color: var(--secure); display: flex; align-items: center; gap: 5px; }
.lock-ico { width: 12px; height: 12px; }
.chat-header-actions { display: flex; gap: 7px; }
.chat-header-actions [data-soon="true"] { opacity: 0.5; }

/* Лента сообщений */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}
.msg-row { display: flex; margin-top: 8px; animation: rise 0.3s var(--ease) both; }
.msg-row.out { justify-content: flex-end; }
.bubble {
  max-width: min(560px, 74%);
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
}
.msg-row.in .bubble {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.msg-row.out .bubble {
  background: linear-gradient(135deg, var(--thread-1), var(--thread-2));
  color: #fff;
  border-bottom-right-radius: 6px;
}
.bubble-time {
  font-size: 10.5px;
  opacity: 0.6;
  margin-top: 4px;
  display: block;
  text-align: right;
}
.msg-row.out .bubble-time { color: rgba(255,255,255,0.85); }

.msg-day {
  align-self: center;
  font-size: 11px;
  color: var(--text-faint);
  background: rgba(0,0,0,0.25);
  padding: 4px 12px;
  border-radius: 99px;
  margin: 14px 0 6px;
}

/* Композер */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
}
.composer-input-wrap { flex: 1; }
.composer-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 11px 16px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14.5px;
  resize: none;
  outline: none;
  max-height: 140px;
  line-height: 1.4;
  transition: border-color 0.2s;
}
.composer-input:focus { border-color: var(--thread-1); }
.composer-send { width: 44px; height: 44px; padding: 0; border-radius: 50%; flex-shrink: 0; }

/* ── Модалка безопасности ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(5, 6, 9, 0.7);
  backdrop-filter: blur(6px);
  animation: fade 0.2s var(--ease) both;
  padding: 20px;
}
.modal {
  width: min(440px, 100%);
  border-radius: var(--radius-lg);
  padding: 28px;
  position: relative;
  box-shadow: var(--shadow-deep);
  animation: scaleIn 0.3s var(--ease) both;
}
.modal-close { position: absolute; top: 16px; right: 16px; }
.modal-head { text-align: center; margin-bottom: 22px; }
.security-shield {
  width: 60px; height: 60px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--secure-dim);
  border: 1px solid rgba(52, 211, 153, 0.3);
}
.security-shield i { width: 28px; height: 28px; color: var(--secure); }
.modal-head h2 { font-family: var(--font-display); font-size: 21px; font-weight: 600; margin-bottom: 8px; }
.modal-head p { font-size: 13px; color: var(--text-dim); line-height: 1.5; }

.fingerprint-block { margin-bottom: 14px; }
.fp-label { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; display: flex; align-items: center; gap: 7px; font-weight: 600; }
.fp-value {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 12.5px;
  letter-spacing: 0.06em;
  line-height: 1.7;
  color: var(--text);
  word-break: break-all;
}

/* Визуальный отпечаток — сетка "нитей" из хэша */
.fp-visual {
  height: 48px;
  border-radius: var(--radius-sm);
  margin: 16px 0;
  display: flex;
  gap: 3px;
  overflow: hidden;
}
.fp-bar { flex: 1; border-radius: 2px; }

.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-faint);
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.modal-foot i { width: 15px; height: 15px; flex-shrink: 0; }

/* ── Эмодзи-панель ────────────────────────────────────────────────────────── */
.emoji-panel {
  position: fixed;
  z-index: 90;
  width: min(340px, 92vw);
  height: 360px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-deep);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: scaleIn 0.18s var(--ease) both;
}
.emoji-search { padding: 10px; border-bottom: 1px solid var(--border); }
.emoji-cats { display: flex; gap: 2px; padding: 8px 8px 0; flex-wrap: wrap; }
.emoji-cat {
  background: none; border: none; cursor: pointer;
  font-size: 18px; padding: 6px; border-radius: 8px;
  opacity: 0.6; transition: all 0.15s;
}
.emoji-cat:hover, .emoji-cat.active { opacity: 1; background: rgba(255,255,255,0.07); }
.emoji-grid {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  align-content: start;
}
.emoji-btn {
  background: none; border: none; cursor: pointer;
  font-size: 22px; padding: 5px; border-radius: 8px;
  transition: background 0.12s, transform 0.12s;
  line-height: 1;
}
.emoji-btn:hover { background: rgba(255,255,255,0.09); transform: scale(1.18); }
.emoji-cat-label {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 4px 2px;
}

/* ── Адаптив ──────────────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  .app-screen { grid-template-columns: 1fr; padding: 0; gap: 0; }
  .sidebar { border-radius: 0; }
  .chat-pane { border-radius: 0; }
  /* На мобиле показываем что-то одно */
  .app-screen[data-view="chat"] .sidebar { display: none; }
  .app-screen[data-view="list"] .chat-pane { display: none; }
  .chat-back { display: inline-flex !important; }
  /* На мобиле статус в одну строку, без переноса */
  .chat-peer-status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
  .chat-peer-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
  .composer-input { min-height: 44px; }
}

/* UltraWide — ограничиваем ширину ленты для читаемости */
@media (min-width: 1700px) {
  .app-screen { grid-template-columns: 380px 1fr; max-width: 2200px; margin: 0 auto; }
}
