* { box-sizing: border-box; }

:root {
  --bg: #0f1117;
  --bg2: #151923;
  --card: #1b2030;
  --card2: #222a3f;
  --line: #2c3550;
  --text: #e9ecf5;
  --muted: #8d95ad;
  --accent: #7c5cff;
  --accent2: #3ddc84;
  --danger: #ff5470;
  --radius: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(124, 92, 255, .25), transparent 60%),
    radial-gradient(700px 420px at 100% 0%, rgba(61, 220, 132, .14), transparent 55%),
    var(--bg);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

.btn {
  border: 0; cursor: pointer; border-radius: 12px;
  padding: .65rem 1.1rem; font-size: .95rem; font-weight: 600;
  color: #fff; transition: transform .12s, filter .12s, opacity .12s;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.1); }
.btn:active { transform: translateY(0); }
.btn-primary { background: linear-gradient(135deg, var(--accent), #5b8cff); }
.btn-alt { background: linear-gradient(135deg, #2bb673, var(--accent2)); color: #08240f; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; border-radius: 9px; }

input, textarea {
  width: 100%; background: var(--bg2); color: var(--text);
  border: 1px solid var(--line); border-radius: 11px;
  padding: .65rem .8rem; font-size: .95rem; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, .22);
}
input:disabled { opacity: .55; }
textarea { resize: vertical; }

/* ---------- AUTH ---------- */
.auth {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1.2rem;
}
.auth-card {
  width: 100%; max-width: 420px; text-align: center;
  background: linear-gradient(180deg, var(--card), var(--card2));
  border: 1px solid var(--line); border-radius: 22px;
  padding: 2rem 1.6rem 1.5rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}
.auth-logo { font-size: 3rem; animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-7px) rotate(-4deg); } }
.auth-title { margin: .4rem 0 .2rem; font-size: 1.55rem; }
.auth-sub { margin: 0 0 1.1rem; color: var(--muted); font-size: .9rem; }
.auth-tabs {
  display: flex; gap: .4rem; background: var(--bg2);
  border-radius: 12px; padding: .3rem; margin-bottom: 1.1rem;
}
.auth-tab {
  flex: 1; border: 0; cursor: pointer; padding: .55rem;
  border-radius: 9px; font-weight: 600; font-size: .9rem;
  background: transparent; color: var(--muted); transition: all .18s;
}
.auth-tab.active { background: var(--accent); color: #fff; }
.auth-form { display: flex; flex-direction: column; gap: .75rem; text-align: left; }
.auth-form label { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; color: var(--muted); }
.auth-form .btn { margin-top: .3rem; }
.auth-hint { margin: 1rem 0 0; font-size: .82rem; color: var(--muted); }
.form-error {
  margin-top: .8rem; padding: .55rem .8rem; font-size: .85rem;
  background: rgba(255, 84, 112, .14); color: var(--danger);
  border: 1px solid rgba(255, 84, 112, .4); border-radius: 10px;
}
.form-ok {
  margin-top: .8rem; padding: .55rem .8rem; font-size: .85rem;
  background: rgba(61, 220, 132, .13); color: var(--accent2);
  border: 1px solid rgba(61, 220, 132, .4); border-radius: 10px;
}
.field-label { display: block; font-size: .85rem; color: var(--muted); margin: .2rem 0 .45rem; }

/* пикеры */
.avatar-picker, .color-picker { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: .8rem; }
.avatar-opt {
  width: 44px; height: 44px; font-size: 1.4rem; cursor: pointer;
  border: 2px solid transparent; border-radius: 12px;
  background: var(--bg2); display: flex; align-items: center; justify-content: center;
  transition: transform .12s, border-color .12s;
}
.avatar-opt:hover { transform: scale(1.08); }
.avatar-opt.active { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(61, 220, 132, .25); }
.color-opt {
  width: 32px; height: 32px; cursor: pointer; border-radius: 50%;
  border: 2px solid transparent; transition: transform .12s;
}
.color-opt:hover { transform: scale(1.12); }
.color-opt.active { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, .2); }

.avatar {
  width: 44px; height: 44px; border-radius: 13px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.35rem; overflow: hidden; font-weight: 700; color: #fff;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 34px; height: 34px; font-size: 1rem; border-radius: 10px; }
.avatar.lg { width: 92px; height: 92px; font-size: 3rem; border-radius: 26px; }

/* ---------- APP ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .7rem 1.2rem;
  background: rgba(15, 17, 23, .88); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 1.05rem; }
.nav { display: flex; gap: .4rem; flex: 1; flex-wrap: wrap; }
.nav-btn {
  position: relative; border: 1px solid transparent; cursor: pointer;
  background: transparent; color: var(--muted);
  padding: .5rem .95rem; border-radius: 11px; font-weight: 600; font-size: .92rem;
  transition: all .15s;
}
.nav-btn:hover { color: var(--text); background: var(--card); }
.nav-btn.active { color: #fff; background: var(--accent); }
.badge {
  margin-left: .4rem; min-width: 20px; height: 20px; padding: 0 5px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--danger); color: #fff; font-size: .7rem; font-weight: 800;
  border-radius: 10px;
}
.topbar-me { display: flex; align-items: center; gap: .55rem; font-weight: 600; font-size: .9rem; }

.main { flex: 1; width: 100%; max-width: 1060px; margin: 0 auto; padding: 1.4rem 1.1rem 3rem; }
.view { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

.card {
  background: linear-gradient(180deg, var(--card), var(--card2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.empty { text-align: center; color: var(--muted); padding: 2.2rem 1rem; font-size: .95rem; }

/* ---------- ЛЕНТА ---------- */
.composer { padding: 1rem; margin-bottom: 1.3rem; }
.composer-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .6rem; font-weight: 600; }
.composer-foot { display: flex; align-items: center; justify-content: space-between; margin-top: .7rem; }

.posts { display: flex; flex-direction: column; gap: 1rem; }
.post { padding: 1rem; }
.post-head { display: flex; align-items: center; gap: .7rem; margin-bottom: .55rem; }
.who { display: flex; flex-direction: column; min-width: 0; }
.post-author { font-weight: 700; }
.post-time { color: var(--muted); font-size: .78rem; }
.post-text { white-space: pre-wrap; font-size: 1rem; line-height: 1.55; margin: 0 0 .7rem; word-break: break-word; }
.post-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.react-btn {
  border: 1px solid var(--line); background: var(--bg2); cursor: pointer;
  border-radius: 20px; padding: .3rem .6rem; font-size: .9rem;
  color: var(--muted); transition: all .13s;
}
.react-btn:hover { transform: scale(1.05); border-color: var(--accent); }
.react-btn.mine { background: rgba(124, 92, 255, .25); border-color: var(--accent); color: #fff; }
.react-btn b { font-size: .78rem; margin-left: .2rem; }
.add-react {
  border: 1px dashed var(--line); background: transparent; cursor: pointer;
  border-radius: 20px; padding: .3rem .6rem; font-size: .9rem; color: var(--muted);
}
.add-react:hover { border-color: var(--accent2); color: var(--accent2); }
.react-picker {
  display: flex; gap: .3rem; padding: .35rem; width: 100%;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 22px;
}
.react-picker .react-btn { border: 0; background: transparent; font-size: 1.15rem; }

.comments { margin-top: .8rem; border-top: 1px solid var(--line); padding-top: .7rem; display: flex; flex-direction: column; gap: .55rem; }
.comments-list { display: flex; flex-direction: column; gap: .55rem; }
.comment { display: flex; gap: .55rem; align-items: flex-start; animation: fade .18s ease; }
.comment-body { flex: 1; min-width: 0; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: .45rem .7rem; }
.comment-author { font-weight: 700; font-size: .86rem; }
.comment-text { font-size: .9rem; margin: .12rem 0; word-break: break-word; }
.comment-form { display: flex; gap: .5rem; margin-top: .3rem; }
.comment-form input { flex: 1; }

/* ---------- ЧАТЫ ---------- */
.chats-layout { display: grid; grid-template-columns: 300px 1fr; gap: 1rem; min-height: 66vh; }
.chat-side { padding: .9rem; display: flex; flex-direction: column; gap: .8rem; }
.chat-actions { display: flex; flex-direction: column; gap: .5rem; }
.chat-list { display: flex; flex-direction: column; gap: .45rem; overflow-y: auto; max-height: 58vh; scrollbar-width: thin; }
.chat-item {
  display: flex; gap: .6rem; align-items: center; cursor: pointer;
  padding: .55rem .6rem; border-radius: 12px; border: 1px solid transparent;
  background: transparent; color: inherit; font: inherit; text-align: left;
  transition: background .14s;
}
.chat-item:hover { background: var(--bg2); }
.chat-item.active { background: rgba(124, 92, 255, .2); border-color: var(--accent); }
.chat-item-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-item-title { font-weight: 700; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-last { color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item.unread .chat-item-title::after {
  content: ''; display: inline-block; width: 8px; height: 8px;
  background: var(--danger); border-radius: 50%; margin-left: .4rem; vertical-align: middle;
}

.chat-window { display: flex; flex-direction: column; padding: .9rem; min-height: 66vh; }
.chat-open { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: .7rem;
  padding-bottom: .7rem; border-bottom: 1px solid var(--line); margin-bottom: .7rem;
}
.chat-head-info { flex: 1; min-width: 0; }
.chat-head-title { font-weight: 800; }
#chatHeadAvatar .avatar { width: 46px; height: 46px; }
.messages {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .5rem;
  padding: .2rem .1rem; max-height: 52vh; scrollbar-width: thin;
}
.msg { display: flex; gap: .5rem; max-width: 78%; animation: fade .16s ease; align-items: flex-end; }
.msg .bubble {
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 14px 14px 14px 4px; padding: .5rem .75rem; min-width: 0;
}
.msg .msg-name { font-size: .75rem; font-weight: 700; color: var(--accent2); margin-bottom: .1rem; }
.msg .msg-text { font-size: .92rem; margin: 0; word-break: break-word; white-space: pre-wrap; }
.msg .msg-time { font-size: .68rem; color: var(--muted); text-align: right; margin-top: .15rem; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg.mine .bubble {
  background: linear-gradient(135deg, rgba(124, 92, 255, .35), rgba(91, 140, 255, .28));
  border-color: rgba(124, 92, 255, .55);
  border-radius: 14px 14px 4px 14px;
}
.message-form { display: flex; gap: .55rem; margin-top: .7rem; }
.message-form input { flex: 1; }

/* ---------- НАСТРОЙКИ ---------- */
.settings-card { max-width: 560px; margin: 0 auto; padding: 1.5rem 1.4rem; display: flex; flex-direction: column; gap: .6rem; }
.settings-card h2 { margin: 0 0 .5rem; }
.settings-avatar {
  width: 96px; height: 96px; margin: 0 auto .6rem; border-radius: 28px;
  display: flex; align-items: center; justify-content: center;
  font-size: 3rem; color: #fff; font-weight: 800; overflow: hidden;
  border: 1px solid var(--line);
}
.settings-avatar img { width: 100%; height: 100%; object-fit: cover; }
.settings-actions { margin-top: .8rem; display: flex; gap: .6rem; }
.upload-row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.upload-row input[type='file'] { flex: 1; min-width: 180px; padding: .5rem; }

/* ---------- МОДАЛКИ ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(5, 7, 12, .7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(5, 7, 12, .7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal {
  width: 100%; max-width: 440px; max-height: 86vh; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 1.2rem;
  animation: pop .2s ease; scrollbar-width: thin;
}
@keyframes pop { from { opacity: 0; transform: scale(.94); } }
.modal h3 { margin: 0; font-size: 1.1rem; }
.modal header { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .9rem; }
.modal footer { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }
.modal footer .primary, .modal .primary {
  border: 0; cursor: pointer; border-radius: 12px; padding: .6rem 1.1rem;
  font-size: .92rem; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), #5b8cff);
}
.icon-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  width: 32px; height: 32px; border-radius: 10px; cursor: pointer; font-size: .95rem;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.pick-list { display: flex; flex-direction: column; gap: .4rem; max-height: 300px; overflow-y: auto; margin-top: .5rem; }
.pick-item {
  display: flex; gap: .6rem; align-items: center; cursor: pointer;
  padding: .5rem .6rem; border-radius: 11px; border: 1px solid var(--line);
  background: var(--bg2); color: inherit; font: inherit; text-align: left;
  transition: all .13s;
}
.pick-item:hover { border-color: var(--accent); }
.pick-item.sel { background: rgba(124, 92, 255, .22); border-color: var(--accent); }
.pick-item .pick-who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pick-item .pick-who b { font-size: .92rem; }
.pick-item .pick-who span { font-size: .78rem; color: var(--muted); }
.pick-check { font-size: 1.05rem; color: transparent; font-weight: 800; }
.pick-item.sel .pick-check { color: var(--accent2); }

/* ---------- ЗВОНОК ---------- */
.call-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: radial-gradient(700px 500px at 50% 30%, rgba(124, 92, 255, .35), rgba(8, 10, 16, .96));
  display: flex; align-items: center; justify-content: center;
}
.call-box { text-align: center; animation: fade .25s ease; }
.call-avatar {
  width: 130px; height: 130px; margin: 0 auto 1rem; border-radius: 40px;
  display: flex; align-items: center; justify-content: center;
  font-size: 4rem; overflow: hidden; color: #fff; font-weight: 800;
  box-shadow: 0 0 0 6px rgba(255, 255, 255, .08);
  animation: pulse 1.4s ease-in-out infinite;
}
.call-avatar img { width: 100%; height: 100%; object-fit: cover; }
@keyframes pulse { 50% { box-shadow: 0 0 0 18px rgba(124, 92, 255, .12); } }
.call-title { font-size: 1.5rem; font-weight: 800; }
.call-status { color: var(--muted); margin-top: .4rem; }
.call-timer { color: var(--accent2); font-size: 1.15rem; font-weight: 700; margin-top: .3rem; font-variant-numeric: tabular-nums; }
.call-actions { display: flex; gap: 1.2rem; justify-content: center; margin-top: 1.8rem; }
.call-btn {
  width: 66px; height: 66px; border-radius: 50%; border: 0; cursor: pointer;
  font-size: 1.6rem; background: var(--card2); border: 1px solid var(--line);
  transition: transform .13s, filter .13s;
}
.call-btn:hover { transform: scale(1.08); }
.call-end { background: var(--danger); animation: ring 1s ease-in-out infinite; }
@keyframes ring { 50% { filter: brightness(1.25); } }

/* ---------- TOAST ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 120; padding: .7rem 1.2rem; font-size: .92rem; font-weight: 600;
  background: var(--card2); border: 1px solid var(--accent);
  border-radius: 12px; box-shadow: 0 12px 34px rgba(0, 0, 0, .5);
  animation: pop .2s ease;
}

@media (max-width: 820px) {
  .chats-layout { grid-template-columns: 1fr; }
  .brand span { display: none; }
  .topbar-me { display: none; }
  .msg { max-width: 92%; }
}
