/* ==========================================================================
   Мессенджер — тёмная тема в духе Telegram
   ========================================================================== */

:root {
  --bg: #070c12;
  --panel: #17212b;
  --panel-2: #1d2836;
  --hover: #202c39;
  --active: #2b5278;
  --text: #e9edf1;
  --muted: #8696a7;
  --accent: #5aa2e8;
  --accent-strong: #3390ec;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --border: #0f1820;
  --danger: #f16b6b;
  --ok: #4fae6b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: #2b3a49 transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: #2b3a49;
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: radial-gradient(1200px 600px at 50% -10%, #12202c 0, transparent 60%), var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

/* ----------------------------------- аватары ------------------------------ */

.avatar {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.4px;
  user-select: none;
  overflow: hidden;
}

.av-0 { background: linear-gradient(135deg, #5b8def, #3d5afe); }
.av-1 { background: linear-gradient(135deg, #f0883e, #d9622b); }
.av-2 { background: linear-gradient(135deg, #45b884, #2f8f68); }
.av-3 { background: linear-gradient(135deg, #b06ad6, #7d3fb3); }
.av-4 { background: linear-gradient(135deg, #e05a7a, #b83b5e); }
.av-5 { background: linear-gradient(135deg, #35b3c4, #1f8a99); }
.av-6 { background: linear-gradient(135deg, #c9a227, #a17f10); }
.av-7 { background: linear-gradient(135deg, #6d7f95, #4c5b6d); }

/* -------------------------------- экран входа ---------------------------- */

.auth-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow-y: auto;
  background: radial-gradient(900px 500px at 50% 0, #142430 0, transparent 65%), var(--bg);
  z-index: 10;
}

.auth-card {
  width: min(400px, 100%);
  padding: 32px 28px 24px;
  border: 1px solid #22303d;
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-logo {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, #63b0f2, #2b6cb0);
  color: #fff;
  font-size: 30px;
  line-height: 1;
}

.auth-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.auth-subtitle {
  margin: 8px 0 20px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.45;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 18px;
  border-radius: 12px;
  background: #0f1a24;
}

.auth-tab {
  padding: 9px 8px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.auth-tab.active {
  background: var(--active);
  color: #fff;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.field-label {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
}

.field {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid #263544;
  border-radius: 10px;
  background: #0f1a24;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field::placeholder {
  color: #5d6f80;
}

.field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(90, 162, 232, 0.14);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, background 0.15s;
}

.btn.primary {
  background: var(--accent-strong);
  color: #fff;
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.btn.ghost {
  background: var(--panel-2);
  color: var(--text);
}

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

.btn.danger {
  background: rgba(241, 107, 107, 0.14);
  color: var(--danger);
}

.btn.danger:hover {
  background: rgba(241, 107, 107, 0.24);
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.auth-submit {
  width: 100%;
  margin-top: 18px;
}

.form-error {
  min-height: 18px;
  margin-top: 10px;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.35;
}

.auth-footnote {
  margin-top: 18px;
  color: #5d6f80;
  font-size: 11.5px;
  line-height: 1.4;
}

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

.app {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: var(--panel);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--panel);
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 8px;
}

.avatar-btn {
  padding: 0;
  border: none;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  line-height: 0;
}

.avatar-btn .avatar {
  width: 40px;
  height: 40px;
  font-size: 14px;
}

.search-box {
  flex: 1;
  min-width: 0;
}

.search-box input {
  width: 100%;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 20px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.search-box input::placeholder {
  color: #63758a;
}

.search-box input:focus {
  border-color: #33485c;
}

.search-box input::-webkit-search-cancel-button {
  filter: grayscale(1) brightness(1.6);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

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

.icon-btn.accent {
  background: var(--accent-strong);
  color: #fff;
  font-size: 22px;
}

.icon-btn.accent:hover {
  filter: brightness(1.08);
}

.back {
  display: none;
}

/* -------------------------------- заявки --------------------------------- */

.requests {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 10px 10px;
  border-bottom: 1px solid var(--border);
}

.request-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--panel-2);
}

.request-card .avatar {
  width: 36px;
  height: 36px;
  font-size: 13px;
}

.request-info {
  flex: 1;
  min-width: 0;
}

.request-name {
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.request-sub {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  padding: 0;
  border: none;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
}

.mini-btn.ok {
  background: rgba(79, 174, 107, 0.18);
  color: var(--ok);
}

.mini-btn.ok:hover {
  background: rgba(79, 174, 107, 0.3);
}

.mini-btn.no {
  background: rgba(241, 107, 107, 0.14);
  color: var(--danger);
}

.mini-btn.no:hover {
  background: rgba(241, 107, 107, 0.26);
}

/* ------------------------------- список чатов ---------------------------- */

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

.chat-list:empty {
  flex: 0;
}

.chat-item {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  margin-bottom: 2px;
  padding: 9px 10px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
}

.chat-item:hover {
  background: var(--hover);
}

.chat-item.active {
  background: var(--active);
}

.chat-item-main {
  min-width: 0;
}

.chat-item-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.chat-item-name {
  flex: 1;
  overflow: hidden;
  font-size: 14.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11.5px;
}

.chat-item-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.chat-item-preview {
  flex: 1;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item.active .chat-item-preview,
.chat-item.active .chat-item-time {
  color: rgba(255, 255, 255, 0.72);
}

.badge {
  display: grid;
  place-items: center;
  min-width: 21px;
  height: 21px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--accent-strong);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
}

.chat-item.active .badge {
  background: #fff;
  color: var(--active);
}

.list-empty {
  padding: 22px 12px;
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
}

.sidebar-empty {
  margin: auto 24px;
  padding-bottom: 24px;
  color: var(--muted);
  text-align: center;
}

.sidebar-empty-icon {
  font-size: 34px;
  line-height: 1;
  opacity: 0.85;
}

.sidebar-empty-title {
  margin-top: 10px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.sidebar-empty-text {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.45;
}

/* ---------------------------------- чат ---------------------------------- */

.chat-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #0b141c;
}

.chat-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: auto;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.placeholder-logo {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  margin-bottom: 16px;
  border-radius: 50%;
  background: #14212d;
  color: #3c5670;
  font-size: 38px;
}

.chat-placeholder p {
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
}

.chat-placeholder span {
  font-size: 13.5px;
}

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

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.chat-head .avatar {
  width: 40px;
  height: 40px;
  font-size: 14px;
}

.chat-head-info {
  flex: 1;
  min-width: 0;
}

.chat-head-name {
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-head-status {
  overflow: hidden;
  margin-top: 1px;
  color: var(--muted);
  font-size: 12.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-head-status.online {
  color: var(--accent);
}

/* ------------------------------- сообщения ------------------------------- */

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px 10px;
  background-color: #0b141c;
  background-image: radial-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1.2px);
  background-size: 26px 26px;
  overflow-wrap: anywhere;
}

.msg-row {
  display: flex;
  animation: pop 0.16s ease-out;
}

/* анимация только у последнего сообщения, чтобы при перерисовке не мигало всё */
.msg-row:not(:last-child) {
  animation: none;
}

.msgs-spacer {
  flex: 1 0 auto;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
}

.msg-row.mine {
  justify-content: flex-end;
}

.bubble {
  display: flex;
  flex-direction: column;
  max-width: min(74%, 620px);
  padding: 7px 11px 5px;
  border-radius: 14px;
  background: var(--bubble-in);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.18);
}

.msg-row:not(.mine) .bubble {
  border-bottom-left-radius: 5px;
}

.msg-row.mine .bubble {
  border-bottom-right-radius: 5px;
  background: var(--bubble-out);
}

.msg-row.failed .bubble {
  outline: 1px solid rgba(241, 107, 107, 0.6);
}

.msg-text {
  font-size: 14.5px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.msg-meta {
  display: flex;
  align-items: center;
  align-self: flex-end;
  gap: 4px;
  margin-top: 2px;
  color: rgba(233, 237, 241, 0.45);
  font-size: 11px;
  line-height: 1;
}

.msg-check {
  font-size: 11px;
  letter-spacing: -1.5px;
}

.msg-check.read {
  color: #7fd3ff;
}

.msg-check.pending {
  opacity: 0.55;
}

.msg-error {
  margin-left: 4px;
  color: #ff9b9b;
  font-size: 11px;
}

.day-sep {
  align-self: center;
  margin: 12px 0 6px;
  padding: 4px 11px;
  border-radius: 10px;
  background: rgba(23, 33, 43, 0.9);
  color: var(--muted);
  font-size: 12px;
}

.msgs-loading,
.msgs-empty {
  align-self: center;
  margin: auto;
  padding: 20px;
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
}

.load-more {
  align-self: center;
  margin-bottom: 10px;
  padding: 6px 14px;
  border: none;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--accent);
  font-size: 12.5px;
  cursor: pointer;
}

.load-more:hover {
  background: var(--hover);
}

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

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.composer textarea {
  flex: 1;
  min-height: 42px;
  max-height: 140px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 18px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  line-height: 1.35;
  outline: none;
  resize: none;
  transition: border-color 0.15s;
}

.composer textarea::placeholder {
  color: #63758a;
}

.composer textarea:focus {
  border-color: #33485c;
}

.send-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--accent-strong);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}

.send-btn:hover {
  filter: brightness(1.1);
}

.send-btn:active {
  transform: scale(0.95);
}

/* -------------------------------- модалки -------------------------------- */

.modal-root {
  position: relative;
  z-index: 60;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 8, 12, 0.62);
  backdrop-filter: blur(4px);
  animation: fade 0.15s ease-out;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.modal {
  display: flex;
  flex-direction: column;
  width: min(430px, 100%);
  max-height: min(86dvh, 640px);
  padding: 18px 20px 20px;
  border: 1px solid #24323f;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  animation: rise 0.18s ease-out;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.985);
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.modal-head h2 {
  font-size: 17px;
  font-weight: 600;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.modal-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions .btn {
  min-width: 96px;
}

.profile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid #1f2c38;
  font-size: 14px;
}

.profile-row:first-child {
  border-top: none;
}

.profile-label {
  color: var(--muted);
  font-size: 12.5px;
}

.profile-value {
  overflow: hidden;
  font-size: 14px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 14px;
}

/* --------------------------------- тост ---------------------------------- */

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  z-index: 100;
  max-width: min(90vw, 460px);
  padding: 10px 18px;
  border-radius: 12px;
  background: #2b5278;
  color: #fff;
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  background: #7a2f2f;
}

/* ------------------------------- адаптив --------------------------------- */

@media (max-width: 900px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .chat-pane {
    display: none;
  }

  body.chat-open .chat-pane {
    display: flex;
  }

  body.chat-open .sidebar {
    display: none;
  }

  .back {
    display: grid;
  }

  .messages {
    padding: 12px 12px 8px;
  }

  .bubble {
    max-width: 84%;
  }

  .auth-card {
    padding: 26px 20px 20px;
  }
}

@media (min-width: 901px) {
  .sidebar {
    width: 360px;
  }
}

/* ------------------------------- юзернейм ------------------------------- */

.username-input {
  position: relative;
  display: flex;
  align-items: center;
}

.username-input .field {
  padding-left: 30px;
}

.username-prefix {
  position: absolute;
  left: 13px;
  color: var(--muted);
  font-size: 15px;
  pointer-events: none;
}

.field-hint {
  color: #5d6f80;
  font-size: 11.5px;
  line-height: 1.35;
}

.field-code {
  padding: 12px;
  font-size: 22px;
  letter-spacing: 7px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.auth-step-text {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.auth-step-text strong {
  color: var(--text);
  font-weight: 600;
}

.auth-secondary {
  width: 100%;
  margin-top: 8px;
}

/* -------------------------------- звонок -------------------------------- */

.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(900px 500px at 50% 0, #16232f 0, transparent 60%), #080d13;
}

.call-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(460px, 100%);
  text-align: center;
}

.call-media {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 52vh;
  margin-bottom: 6px;
  border-radius: 18px;
  overflow: hidden;
  background: #0f1922;
}

.call-media.audio {
  aspect-ratio: auto;
  max-height: none;
  margin-bottom: 0;
  overflow: visible;
  background: transparent;
}

.call-video-remote {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.call-video-local {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 28%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  background: #000;
  object-fit: cover;
}

.call-person {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.call-avatar {
  width: 96px;
  height: 96px;
  font-size: 32px;
}

.call-name {
  font-size: 20px;
  font-weight: 600;
}

.call-sub {
  color: var(--muted);
  font-size: 13px;
}

.call-status {
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
}

.call-timer {
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}

.call-actions {
  display: flex;
  gap: 14px;
  margin-top: 8px;
}

.call-btn {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #24313d;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.call-btn:hover {
  background: #2d3d4c;
}

.call-btn:active {
  transform: scale(0.95);
}

.call-btn.end {
  background: #d84a4a;
}

.call-btn.end:hover {
  background: #e55c5c;
}

.call-btn.accept {
  background: #3fa562;
}

.call-btn.accept:hover {
  background: #4cb972;
}

.call-btn.off {
  background: #4a5560;
  opacity: 0.75;
}

@media (max-width: 480px) {
  .chat-head {
    gap: 6px;
    padding: 8px 10px;
  }

  .chat-head .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .call-avatar {
    width: 76px;
    height: 76px;
  }

  .call-media {
    aspect-ratio: 3 / 4;
    max-height: 46vh;
  }
}

/* ----------------------------- аватарки и профиль ----------------------------- */

.avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-clickable {
  cursor: pointer;
  transition: opacity 0.15s;
}

.avatar-clickable:hover {
  opacity: 0.85;
}

/* ------------------------------ поиск людей ------------------------------ */

.search-result {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0;
  padding: 9px 10px;
  border-radius: 12px;
  background: var(--panel-2);
  cursor: pointer;
}

.search-result:hover {
  background: var(--hover);
}

.search-result .avatar {
  width: 44px;
  height: 44px;
  font-size: 15px;
}

.search-result-info {
  flex: 1;
  min-width: 0;
}

.search-result-name {
  overflow: hidden;
  font-size: 14.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-username {
  overflow: hidden;
  color: var(--muted);
  font-size: 12.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-hint {
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.mini-btn.add {
  background: var(--accent-strong);
  color: #fff;
}

.mini-btn.add:hover {
  filter: brightness(1.1);
}

/* ------------------------------ чужой профиль ----------------------------- */

.profile-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 6px 0 14px;
}

.profile-avatar {
  width: 96px;
  height: 96px;
  margin-bottom: 4px;
  font-size: 30px;
}

.profile-name {
  font-size: 17px;
  font-weight: 600;
}

.profile-username {
  color: var(--muted);
  font-size: 13px;
}

.profile-avatar-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.profile-avatar-actions .btn {
  padding: 8px 12px;
  font-size: 13px;
}

/* --------------------------- полноэкранный просмотр -------------------------- */

.call-fullscreen-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(8, 13, 19, 0.62);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
}

.call-fullscreen-btn:hover {
  background: rgba(8, 13, 19, 0.85);
}

.call-video-remote {
  cursor: zoom-in;
}

.call-video-remote.screen-share {
  object-fit: contain;
}

.call-video-remote:fullscreen {
  width: 100vw;
  height: 100vh;
  object-fit: contain;
  background: #000;
  cursor: zoom-out;
}

/* ==========================================================================
   Новые возможности: группы, файлы, голосовые, реакции, поиск и история
   ========================================================================== */

.chat-head .icon-btn svg,
.composer .icon-btn svg,
.attach-btn svg,
.mic-btn svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#new-group-btn svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.attach-btn,
.mic-btn {
  width: 42px;
  height: 42px;
  color: var(--muted);
}

.attach-btn:hover,
.mic-btn:hover {
  color: var(--text);
}

.mic-btn.recording {
  color: var(--danger);
  background: rgba(241, 107, 107, 0.14);
}

.recording-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
}

.rec-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--danger);
  animation: recPulse 1s ease-in-out infinite;
}

.rec-time {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.rec-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rec-btn {
  padding: 7px 11px;
  font-size: 12.5px;
}

@keyframes recPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}

/* ------------------------------- сообщения ------------------------------- */

.msg-row {
  align-items: flex-end;
  gap: 6px;
}

.msg-avatar {
  width: 30px;
  height: 30px;
  font-size: 11px;
}

.msg-sender {
  margin-bottom: 2px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.msg-system {
  align-self: center;
  max-width: 82%;
  margin: 6px 0;
  padding: 5px 12px;
  border-radius: 12px;
  background: rgba(23, 33, 43, 0.75);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
}

.msg-text.deleted {
  color: var(--muted);
  font-style: italic;
}

.msg-edited {
  margin-left: 3px;
  color: rgba(233, 237, 241, 0.42);
  font-size: 10.5px;
}

.msg-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-bottom: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}

.msg-row:hover .msg-actions,
.msg-row:focus-within .msg-actions {
  opacity: 1;
}

.msg-row.mine .msg-actions {
  order: -1;
}

.msg-action {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.msg-action:hover {
  background: var(--hover);
  color: var(--text);
}

.msg-action svg {
  display: block;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.msg-image-btn {
  display: block;
  max-width: 100%;
  padding: 0;
  border: none;
  background: none;
  cursor: zoom-in;
}

.msg-image {
  display: block;
  max-width: min(320px, 100%);
  max-height: 320px;
  border-radius: 10px;
  object-fit: cover;
}

.msg-file {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 180px;
  max-width: 320px;
  padding: 4px 2px;
  color: inherit;
  text-decoration: none;
}

.msg-file-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent);
}

.msg-file-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.msg-file-info {
  min-width: 0;
}

.msg-file-name {
  overflow: hidden;
  font-size: 13.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-file-size {
  margin-top: 2px;
  color: rgba(233, 237, 241, 0.55);
  font-size: 11.5px;
}

.msg-voice {
  min-width: 220px;
  max-width: 300px;
}

.msg-voice audio {
  display: block;
  width: 100%;
  height: 38px;
}

.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.reaction {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.16);
  color: inherit;
  font-size: 12px;
  cursor: pointer;
}

.reaction:hover {
  background: rgba(255, 255, 255, 0.12);
}

.reaction.mine {
  border-color: var(--accent);
  background: rgba(90, 162, 232, 0.2);
}

.reaction-picker {
  position: fixed;
  z-index: 220;
  display: flex;
  gap: 3px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.reaction-picker button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 19px;
  cursor: pointer;
}

.reaction-picker button:hover {
  background: var(--hover);
  transform: scale(1.12);
}

.msg-row.highlight .bubble {
  animation: highlightBubble 1.8s ease;
}

@keyframes highlightBubble {
  0%, 100% { box-shadow: 0 1px 1px rgba(0, 0, 0, 0.18); }
  20%, 60% { box-shadow: 0 0 0 3px var(--accent), 0 0 24px rgba(90, 162, 232, 0.4); }
}

/* ------------------------------- группы --------------------------------- */

.member-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 230px;
  overflow-y: auto;
}

.member-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 4px;
  border-radius: 10px;
}

.member-row:hover {
  background: var(--hover);
}

.member-row .avatar {
  width: 36px;
  height: 36px;
  font-size: 13px;
}

.member-info {
  flex: 1;
  min-width: 0;
}

.member-name {
  overflow: hidden;
  font-size: 13.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-sub {
  overflow: hidden;
  color: var(--muted);
  font-size: 11.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-owner {
  padding: 2px 7px;
  border-radius: 8px;
  background: rgba(90, 162, 232, 0.16);
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 600;
}

.group-search-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 190px;
  overflow-y: auto;
}

.group-search-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 6px;
  border-radius: 10px;
  background: var(--panel-2);
}

.group-search-row .avatar {
  width: 32px;
  height: 32px;
  font-size: 12px;
}

.group-search-info {
  flex: 1;
  min-width: 0;
}

.group-search-name {
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-search-sub {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-search-row .mini-btn {
  width: 30px;
  height: 30px;
}

.group-section-title {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ------------------------------- поиск ---------------------------------- */

.search-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 320px;
  overflow-y: auto;
}

.search-result-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 10px;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  text-align: left;
  border: none;
  cursor: pointer;
}

.search-result-row:hover {
  background: var(--hover);
}

.search-result-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.search-result-text {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ----------------------------- история звонков --------------------------- */

.call-history-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 360px;
  overflow-y: auto;
}

.call-history-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.call-history-row:last-child {
  border-bottom: none;
}

.call-history-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: rgba(90, 162, 232, 0.14);
  color: var(--accent);
  font-size: 15px;
}

.call-history-icon.missed {
  background: rgba(241, 107, 107, 0.14);
  color: var(--danger);
}

.call-history-info {
  flex: 1;
  min-width: 0;
}

.call-history-title {
  overflow: hidden;
  font-size: 13.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call-history-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
}

.call-history-action {
  flex: 0 0 auto;
}

.empty-note {
  padding: 16px 6px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* ------------------------------- адаптив --------------------------------- */

@media (hover: none) {
  .msg-actions {
    opacity: 1;
  }
}

.recording-bar[hidden] {
  display: none;
}

.image-preview {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  margin: 0 auto;
  border-radius: 12px;
  object-fit: contain;
}

.msg-edit-field {
  width: 100%;
  min-height: 110px;
  resize: vertical;
}

.member-row {
  width: 100%;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.member-row.selected {
  background: rgba(90, 162, 232, 0.14);
}

.member-row .msg-action {
  flex: 0 0 auto;
  margin-left: auto;
}

.inline-actions .field {
  flex: 1;
  min-width: 150px;
}

.inline-actions .btn {
  flex: 0 0 auto;
}

.call-history-row {
  cursor: pointer;
}

.call-history-row:hover {
  background: var(--hover);
}

@media (max-width: 480px) {
  .msg-image {
    max-width: min(250px, 100%);
    max-height: 250px;
  }

  .recording-bar {
    flex-wrap: wrap;
    gap: 6px;
  }

  .rec-label {
    flex-basis: 100%;
    order: 3;
  }
}
