/* Фаридграм — тёмная тема в духе мессенджеров */

:root {
  --bg-app: #0e1621;
  --bg-side: #17212b;
  --bg-card: #1c2733;
  --bg-hover: #202b36;
  --bg-active: #2b5278;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --accent: #2ea6ff;
  --accent-hi: #4fb6ff;
  --text: #e9edf1;
  --muted: #7f91a4;
  --line: #23303d;
  --danger: #e05a5a;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg-app);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2a3947; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- вход --- */

.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1b3a56 0%, var(--bg-app) 60%);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  padding: 32px 28px;
  background: var(--bg-side);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-logo, .brand-mark, .empty-mark {
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--accent), #1b7fd1);
  color: #fff;
  font-weight: 700;
  border-radius: 50%;
}

.auth-logo { width: 64px; height: 64px; margin: 0 auto 14px; font-size: 30px; }
.auth-card h1 { margin: 0 0 6px; font-size: 24px; }
.auth-sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  padding: 4px;
  background: var(--bg-app);
  border-radius: 10px;
}

.auth-tabs button {
  flex: 1;
  padding: 9px;
  border-radius: 8px;
  color: var(--muted);
}

.auth-tabs button.active { background: var(--bg-card); color: var(--text); }

#auth-form { display: flex; flex-direction: column; gap: 10px; }

input, textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-app);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  resize: vertical;
}

input:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--muted); }

.btn-primary {
  padding: 12px 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-radius: 10px;
  transition: background .15s ease;
}

.btn-primary:hover { background: var(--accent-hi); }
.btn-primary:disabled { opacity: .55; cursor: default; }

.ghost-btn {
  padding: 10px 14px;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.ghost-btn:hover { background: var(--bg-hover); }

.auth-error {
  padding: 9px 12px;
  background: rgba(224, 90, 90, .12);
  border: 1px solid rgba(224, 90, 90, .4);
  border-radius: 10px;
  color: #ff9c9c;
  font-size: 13px;
  text-align: left;
}

/* --- каркас --- */

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

.sidebar {
  display: flex;
  flex-direction: column;
  width: 330px;
  flex: 0 0 330px;
  background: var(--bg-side);
  border-right: 1px solid var(--line);
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand-mark { width: 30px; height: 30px; font-size: 15px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: var(--muted);
  font-size: 18px;
}

.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

/* Кнопка «назад» в чате нужна только на узком экране */
.mobile-only { display: none; }

.sidebar-search { padding: 10px 12px; }
.sidebar-search input { padding: 9px 12px; border-radius: 18px; }

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

.chat-row {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 9px 10px;
  border-radius: 12px;
  text-align: left;
}

.chat-row:hover { background: var(--bg-hover); }
.chat-row.active { background: var(--bg-active); }
.chat-row.active .chat-row-sub, .chat-row.active .chat-row-time { color: #cfe3f5; }

.chat-row-body { flex: 1; min-width: 0; }
.chat-row-head { display: flex; justify-content: space-between; gap: 8px; }
.chat-row-name { font-weight: 600; }
.chat-row-name, .chat-row-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row-sub { color: var(--muted); font-size: 13px; }
.chat-row-time { color: var(--muted); font-size: 12px; flex: none; }

.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  display: grid;
  place-items: center;
}

.avatar {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 50%;
  object-fit: cover;
  background: #2a3947;
}

.avatar-sm { width: 34px; height: 34px; }
.avatar-lg { width: 96px; height: 96px; }

.online-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #4bcf6b;
  border: 2px solid var(--bg-side);
  position: absolute;
  right: -1px;
  bottom: -1px;
}

.avatar-wrap { position: relative; flex: none; }

.me-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

/* --- основная область --- */

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.main-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: var(--bg-side);
  border-bottom: 1px solid var(--line);
}

.main-tabs button, .feed-tabs button {
  padding: 8px 16px;
  border-radius: 18px;
  color: var(--muted);
}

.main-tabs button:hover, .feed-tabs button:hover { background: var(--bg-hover); }
.main-tabs button.active, .feed-tabs button.active { background: var(--bg-active); color: #fff; }

.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.scroll-area { flex: 1; overflow-y: auto; padding: 20px; max-width: 720px; width: 100%; margin: 0 auto; }

.empty {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.empty-mark { width: 72px; height: 72px; font-size: 32px; opacity: .85; }

/* --- переписка --- */

.chat-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--bg-side);
  border-bottom: 1px solid var(--line);
}

.chat-title { font-weight: 600; }
.chat-status { color: var(--muted); font-size: 13px; }
.chat-status.typing { color: var(--accent); }

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 18px 8px;
}

.msg { max-width: min(70%, 560px); display: flex; flex-direction: column; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.in { align-self: flex-start; }

.msg-bubble {
  padding: 8px 12px;
  background: var(--bubble-in);
  border-radius: 16px 16px 16px 4px;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg.out .msg-bubble { background: var(--bubble-out); border-radius: 16px 16px 4px 16px; }
.msg-author { color: var(--accent); font-size: 12px; font-weight: 600; margin: 0 0 2px 6px; }
.msg-meta { display: flex; gap: 5px; align-items: center; margin: 2px 6px 0; color: var(--muted); font-size: 11px; }
.msg-media { margin: -2px 0 4px; border-radius: 12px; overflow: hidden; }
.msg-media img { max-height: 320px; object-fit: cover; }
.msg-check { color: var(--accent-hi); }

/* цитата внутри пузыря */
.msg-quote {
  display: block;
  margin: 0 0 6px;
  padding: 4px 8px;
  border-left: 3px solid var(--accent);
  background: rgba(0, 0, 0, .18);
  border-radius: 6px;
  font-size: 13px;
  color: #cfe3f5;
  white-space: normal;
  cursor: pointer;
}

.msg-quote-name { display: block; font-weight: 600; color: var(--accent-hi); font-size: 12px; }
.msg-quote-text { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* «Ответить» и «Удалить» живут в строке со временем: на мыши — по наведению, на телефоне — по тапу */
.msg-tools { display: flex; gap: 4px; opacity: 0; transition: opacity .12s ease; }
.msg:hover .msg-tools, .msg-tools:focus-within, .msg.tools-on .msg-tools { opacity: 1; }

.msg-tools button {
  padding: 2px 8px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 11px;
  background: var(--bg-card);
}

.msg-tools button:hover { color: var(--text); background: var(--bg-hover); }
.msg-tools .msg-del:hover { color: var(--danger); }

.reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 18px 8px;
  padding: 8px 12px;
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  font-size: 13px;
}

.reply-bar-body { flex: 1; min-width: 0; }
.reply-bar-name { color: var(--accent-hi); font-weight: 600; font-size: 12px; }
.reply-bar-text { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.history-top { padding: 6px 0 10px; text-align: center; color: var(--muted); font-size: 12px; }

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px 18px;
  background: var(--bg-app);
}

.composer input { border-radius: 22px; }

.send-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  font-size: 17px;
}

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

.attach-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 18px 14px;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 13px;
}

.attach-preview img { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; }

/* --- лента, люди, профиль --- */

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.composer-card textarea { margin-bottom: 10px; }
.composer-card-row { display: flex; align-items: center; gap: 10px; }
.composer-card-row .btn-primary { margin-left: auto; }
.hint { color: var(--muted); font-size: 13px; }
.hint.saved { color: #4bcf6b; margin-top: 8px; }
.feed-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.section-title { margin: 22px 0 12px; font-size: 15px; color: var(--muted); font-weight: 600; }

.post-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.post-author { font-weight: 600; }
.post-text { white-space: pre-wrap; word-wrap: break-word; }
.post-media { margin-top: 10px; border-radius: 12px; overflow: hidden; }
.post-actions { display: flex; gap: 8px; margin-top: 12px; align-items: center; }

.act-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 16px;
  color: var(--muted);
  font-size: 13px;
}

.act-btn:hover { background: var(--bg-hover); color: var(--text); }
.act-btn.liked { color: #ff6b8a; }
.act-btn.danger:hover { color: var(--danger); }

.comments { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.comment { display: flex; gap: 8px; margin-bottom: 10px; }
.comment-body { background: var(--bubble-in); border-radius: 12px; padding: 7px 11px; }
.comment-author { font-size: 12px; font-weight: 600; color: var(--accent); }
.comment-form { display: flex; gap: 8px; }
.comment-form input { border-radius: 18px; }

.people-search { margin-bottom: 16px; }
.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }

.person {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.person .avatar { margin: 0 auto 10px; width: 64px; height: 64px; }
.person-name { font-weight: 600; }
.person-login { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.person-bio { color: var(--muted); font-size: 13px; margin-bottom: 12px; min-height: 18px; }
.person-actions { display: flex; gap: 8px; justify-content: center; }
.person-actions button { flex: 1; padding: 8px; font-size: 13px; border-radius: 10px; }

.profile-card { display: flex; gap: 20px; align-items: flex-start; }
.profile-main { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.profile-actions { display: flex; gap: 10px; }
.avatar-upload { position: relative; cursor: pointer; display: block; }

/* чужой профиль */
.user-name { font-size: 20px; font-weight: 600; }
.user-bio { color: var(--muted); white-space: pre-wrap; }
.user-stats { display: flex; gap: 18px; color: var(--muted); font-size: 13px; }
.user-stats b { color: var(--text); }
.link-user { cursor: pointer; }
.link-user:hover .post-author, .link-user:hover .person-name { color: var(--accent-hi); }
.chat-title.link-user:hover { color: var(--accent-hi); }

/* заголовок группы в сайдбаре: «Чаты» / «Люди» */
.list-label {
  padding: 10px 12px 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* всплывающие подсказки об ошибках и событиях */
.toasts {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 30;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 14px;
  animation: toast-in .16s ease;
}

.toast.error { border-color: rgba(224, 90, 90, .5); color: #ff9c9c; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.avatar-upload-hint {
  position: absolute;
  inset: auto 0 0 0;
  padding: 4px;
  background: rgba(0, 0, 0, .6);
  border-radius: 0 0 48px 48px;
  font-size: 11px;
  text-align: center;
}

/* --- модальное окно --- */

.modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .6); z-index: 20; }
.modal-card { width: min(420px, 92vw); background: var(--bg-side); border: 1px solid var(--line); border-radius: 18px; padding: 22px; box-shadow: var(--shadow); }
.modal-card h3 { margin: 0 0 14px; }
.modal-card input { margin-bottom: 12px; }
.group-members { max-height: 240px; overflow-y: auto; margin-bottom: 14px; }
.group-member { display: flex; align-items: center; gap: 10px; padding: 7px 4px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* --- мобильные --- */

@media (max-width: 780px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    border-right: none;
  }
  .main { min-height: 0; }
  /* На телефоне показываем что-то одно: либо список чатов, либо открытый экран */
  body.m-list .sidebar { display: flex; }
  body.m-list .main { flex: 0 0 auto; }
  body.m-list .main .view { display: none; }
  body:not(.m-list) .sidebar { display: none; }
  /* Вкладки уходят вниз — привычная мобильная панель навигации */
  .main-tabs {
    order: 2;
    justify-content: space-between;
    overflow-x: auto;
    border-top: 1px solid var(--line);
    border-bottom: none;
  }
  .mobile-only { display: grid; }
  .msg { max-width: 85%; }
  .profile-card { flex-direction: column; align-items: center; }
}
