:root {
  --primary: #B388FF;
  --primary-dark: #7C4DFF;
  --on-primary: #1A1A1A;
  --bg: #121212;
  --surface: #1E1E1E;
  --surface-variant: #2A2A2A;
  --text: #FFFFFF;
  --text-dim: #B0B0B0;
  --bubble-in: #2A2A2A;
  --bubble-out: #B388FF;
  --bubble-out-text: #1A1A1A;
  --danger: #EF5350;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; }

/* LOGO / LOADING */
#screen-loading { align-items: center; justify-content: center; gap: 24px; }
.logo {
  font-size: 64px;
  font-weight: bold;
  color: var(--primary);
  text-align: center;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--surface-variant);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* AUTH */
.auth-box {
  margin: auto;
  padding: 32px 24px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.auth-box h1 { font-size: 28px; margin-bottom: 4px; }
.auth-box .subtitle { color: var(--text-dim); margin-bottom: 24px; }
.auth-box input {
  width: 100%;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--surface-variant);
  border: 2px solid transparent;
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  outline: none;
}
.auth-box input:focus { border-color: var(--primary); }
.btn {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  border-radius: 24px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  margin-top: 8px;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-outline {
  width: 100%;
  padding: 14px;
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: 24px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  margin-top: 8px;
}
.link {
  display: block;
  margin-top: 16px;
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
  font-weight: bold;
}
.error {
  margin-top: 12px;
  color: var(--danger);
  min-height: 20px;
  font-size: 14px;
}

/* TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--primary);
  color: var(--on-primary);
  min-height: 56px;
  box-shadow: 0 2px 4px rgba(0,0,0,.2);
  z-index: 10;
}
.topbar-title {
  font-size: 18px;
  font-weight: bold;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Имя + статус собеседника в шапке чата */
.topbar-title-group {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.topbar-title-group .topbar-title {
  flex: none;
  font-size: 17px;
  line-height: 1.2;
}
.topbar-status {
  font-size: 12px;
  line-height: 1.2;
  opacity: .85;
  min-height: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* SVG-иконки в поле ввода (прикрепить, отправить) */
.input-icon {
  width: 22px;
  height: 22px;
  display: block;
  pointer-events: none;
}
.topbar-actions { display: flex; gap: 8px; }
.topbar button {
  background: transparent;
  border: none;
  color: var(--on-primary);       
  cursor: pointer;
  padding: 0;
  width: 40px;
  height: 40px;
  display: inline-flex;            
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.15s ease;
  font-size: 22px;                 
  line-height: 1;
}

.topbar button:hover { background: rgba(0, 0, 0, 0.08); }
.topbar button:active { background: rgba(0, 0, 0, 0.16); }

.topbar .icon {
  width: 22px;
  height: 22px;
  display: block;
  stroke: currentColor;
  pointer-events: none;
}
.topbar .back { font-size: 24px; padding: 4px 10px; }
.topbar .avatar.sm {
  width: 36px; height: 36px;
  border-radius: 50%;
  object-fit: cover;
}
.search-input {
  flex: 1;
  padding: 8px 12px;
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: 8px;
  color: var(--on-primary);
  outline: none;
  font-size: 15px;
}
.search-input::placeholder { color: rgba(0,0,0,.5); }

/* LISTS */
.dialogs-list {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 24px;
}
.dialog-item {
  display: flex;
  gap: 14px;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
.dialog-item:hover { background: var(--surface-variant); }
.avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-variant);
  flex-shrink: 0;
}
.avatar.lg { width: 120px; height: 120px; }
.dialog-info { flex: 1; min-width: 0; }
.dialog-name {
  font-weight: bold;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dialog-msg {
  color: var(--text-dim);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}
.empty {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-dim);
  text-align: center;
  display: none;
}
.empty.visible { display: block; }

/* MESSAGES */
.messages-area {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}
.messages-area .messages-list {
  flex: 1;
}
.messages-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Кнопка «вниз»: появляется, когда список прокручен вверх. */
#scroll-bottom {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 6;
  width: 42px;
  height: 42px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}
#scroll-bottom.visible { display: flex; }
#scroll-bottom:hover { background: var(--surface-variant); }
#scroll-bottom:active { transform: translateY(1px); }
#scroll-bottom svg {
  width: 22px;
  height: 22px;
  display: block;
  pointer-events: none;
}

.msg-row {
  display: flex;
  gap: 8px;
  max-width: 100%;
  align-items: flex-end;
}
.msg-row.mine { justify-content: flex-end; }
.msg-row .avatar.xs {
  width: 32px; height: 32px;
  border-radius: 50%;
}
.msg-bubble {
  max-width: 70%;
  padding: 8px 12px 6px;
  border-radius: 16px;
  position: relative;
  word-wrap: break-word;
  font-size: 15px;
  line-height: 1.35;
}
.msg-row:not(.mine) .msg-bubble {
  background: var(--bubble-in);
  border-bottom-left-radius: 4px;
}
.msg-row.mine .msg-bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-bottom-right-radius: 4px;
}
.msg-sender {
  font-size: 12px;
  font-weight: bold;
  color: var(--primary);
  margin-bottom: 2px;
}
.msg-time {
  font-size: 11px;
  opacity: .65;
  margin-left: 8px;
  float: right;
  margin-top: 4px;
}
.msg-image {
  max-width: 100%;
  max-height: 260px;
  border-radius: 12px;
  margin-bottom: 4px;
  display: block;
}
.date-sep {
  text-align: center;
  margin: 12px 0;
}
.date-sep span {
  background: var(--surface-variant);
  color: var(--text-dim);
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: bold;
}

/* ═══════════════════════════════════════════════ */
/* ОКНО ПОДТВЕРЖДЕНИЯ УДАЛЕНИЯ                      */
/* ═══════════════════════════════════════════════ */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 3500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, .6);
}

.confirm-box {
  width: 100%;
  max-width: 400px;
  padding: 20px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}

.confirm-title {
  font-size: 18px;
  font-weight: bold;
  color: var(--text);
  margin-bottom: 10px;
}

.confirm-text {
  font-size: 15px;
  color: var(--text-dim);
  line-height: 1.4;
  margin-bottom: 14px;
}

.confirm-check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  background: var(--surface-variant);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.confirm-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}
.confirm-actions button { flex: 1; margin-top: 0; }

/* ═══════════════════════════════════════════════ */
/* ПАНЕЛЬ ЭМОДЗИ                                    */
/* ═══════════════════════════════════════════════ */
.emoji-panel {
  display: none;
  flex-wrap: wrap;
  gap: 2px;
  max-height: 200px;
  overflow-y: auto;
  padding: 8px;
  background: var(--surface);
  border-top: 1px solid rgba(255,255,255,.06);
  -webkit-overflow-scrolling: touch;
}
.emoji-panel.visible { display: flex; }

.emoji-item {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  border-radius: 8px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s ease;
}
.emoji-item:hover { background: var(--surface-variant); }
.emoji-item:active { background: var(--primary); }

/* ═══════════════════════════════════════════════ */
/* ПОЛНОЭКРАННЫЙ ПРОСМОТР ФОТО                      */
/* ═══════════════════════════════════════════════ */
.image-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, .92);
  opacity: 0;
  visibility: hidden;
  transition: opacity .18s ease, visibility .18s ease;
  cursor: zoom-out;
}
.image-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.image-overlay img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  cursor: default;
}

.image-overlay button {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .15);
  color: #FFFFFF;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.image-overlay button:hover { background: rgba(255, 255, 255, .28); }

/* ═══════════════════════════════════════════════ */
/* ОТВЕТЫ НА СООБЩЕНИЯ                              */
/* ═══════════════════════════════════════════════ */

/* Панель «отвечаем на…» над полем ввода, скрыта по умолчанию */
.reply-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--surface);
  border-top: 1px solid rgba(255,255,255,.06);
}
.reply-preview.visible { display: flex; }

.reply-preview-bar {
  width: 3px;
  align-self: stretch;
  min-height: 28px;
  background: var(--primary);
  border-radius: 2px;
  flex-shrink: 0;
}

.reply-preview-body { flex: 1; min-width: 0; }
.reply-preview-name {
  font-size: 13px;
  font-weight: bold;
  color: var(--primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-preview-text {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-preview button {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  border-radius: 50%;
  flex-shrink: 0;
}
.reply-preview button:hover { background: var(--surface-variant); }

/* Цитата внутри пузыря сообщения */
.msg-reply {
  border-left: 3px solid var(--primary);
  padding: 4px 6px;
  margin-bottom: 4px;
  background: rgba(0,0,0,.12);
  border-radius: 4px;
  max-width: 100%;
}
.msg-row.mine .msg-reply { background: rgba(0,0,0,.10); }
.msg-reply-name {
  font-size: 12px;
  font-weight: bold;
  color: var(--primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-reply-text {
  font-size: 12px;
  opacity: .8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* INPUT BAR */
.input-bar {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: var(--surface-variant);
  align-items: center;
}
.input-bar input[type="text"] {
  flex: 1;
  padding: 12px 16px;
  background: var(--surface);
  border: none;
  border-radius: 20px;
  color: var(--text);
  outline: none;
  font-size: 15px;
}
.input-bar button {
  width: 44px; height: 44px;
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 20px;
  cursor: pointer;
  border-radius: 50%;
}

/* PROFILE */
.profile-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.profile-content .avatar.lg { align-self: center; margin-bottom: 8px; }
.profile-content label {
  font-size: 14px;
  color: var(--text-dim);
  margin-top: 8px;
}
.profile-content input,
.profile-content textarea {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface-variant);
  border: 2px solid transparent;
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  font-family: inherit;
}
.profile-content input:focus,
.profile-content textarea:focus { border-color: var(--primary); }
.colors-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;   /* ← центрируем кружки */
  gap: 8px;
  margin-top: 8px;
}
.color-cell {
  aspect-ratio: 1;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
}
.color-cell.selected { border-color: var(--text); }

/* CHIPS (create group) */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface-variant);
  border-radius: 12px;
  font-size: 14px;
}
.chip button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(200%);
  background: var(--surface);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  transition: transform .25s;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  max-width: 80vw;
}
.toast.visible { transform: translateX(-50%) translateY(0); }

/* MOBILE */
@media (max-width: 600px) {
  .auth-box { padding: 24px 16px; }
  .logo { font-size: 48px; }
  .msg-bubble { max-width: 80%; }
}

/* =============================================== */
/* ����: �������                                                        */
/* =============================================== */
body.light-theme {
  --bg: #FFFFFF;
  --surface: #F5F5F5;
  --surface-variant: #EEEEEE;
  --text: #121212;
  --text-dim: #666666;
  --bubble-in: #EEEEEE;
  --bubble-out: #B388FF;
  --bubble-out-text: #1A1A1A;
  --on-primary: #1A1A1A;
}

body.light-theme .msg-bubble {
  color: #121212;
}
body.light-theme .msg-row.mine .msg-bubble {
  color: #1A1A1A;
}

/* =============================================== */
/* ���������� ����                                                     */
/* =============================================== */
.popup-menu {
  position: fixed;
  min-width: 200px;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  padding: 6px;
  z-index: 2000;
  display: none;
  animation: popupFadeIn 0.15s ease-out;
}
.popup-menu.visible { display: block; }

@keyframes popupFadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.popup-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  color: var(--text);
  user-select: none;
}
.popup-menu-item:hover { background: var(--surface-variant); }
.popup-menu-item:active { background: var(--surface-variant); }
.popup-menu-item svg {
  width: 20px; height: 20px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
}

/* =============================================== */
/* ������ (������� ����������� � ��.)                                 */
/* =============================================== */
.badge-container {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 4px;
  vertical-align: middle;
}
.badge-icon {
  width: 16px;
  height: 16px;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}
.badge-icon.lg { width: 20px; height: 20px; }

/* Коллекция бейджей в профиле (все, а не только выбранный) */
.badge-collection {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: var(--surface-variant);
  border-radius: 10px;
}
.badge-collection .badge-container { margin-left: 0; gap: 6px; }
.badge-collection .badge-icon { width: 20px; height: 20px; }
.badges-empty {
  color: var(--text-dim);
  font-size: 14px;
}

/* ─── Выбор бейджа в своём профиле ─── */
.badge-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.badge-cell {
  width: 44px;
  height: 44px;
  padding: 7px;
  box-sizing: border-box;
  border: 2px solid transparent;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .12s ease;
}
.badge-cell:hover { background: rgba(255,255,255,.08); transform: scale(1.06); }
.badge-cell.selected {
  border-color: var(--primary);
  background: rgba(179, 136, 255, .18);
}
.badge-cell .badge-icon { width: 100%; height: 100%; }

.badge-cell-busy { opacity: .5; pointer-events: none; }

/* ═══════════════════════════════════════════════ */
/* ИНФОРМАЦИЯ О ГРУППЕ                              */
/* ═══════════════════════════════════════════════ */

/* ─── Шапка группы: буква + название + счётчик ───
   Без цветной плашки: фон блока не рисуем, только содержимое.
   Фон остаётся лишь у самого кружка с буквой (.gi-avatar). */
.gi-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px 12px;
  flex-shrink: 0;
}

.gi-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .28);
  color: #FFFFFF;
  font-size: 26px;
  font-weight: bold;
  user-select: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.gi-header-text { flex: 1; min-width: 0; }

.gi-header-name {
  font-size: 20px;
  font-weight: bold;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gi-header-meta {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Список участников внутри прокручиваемого экрана */
.gi-members {
  flex: none;
  overflow: visible;
  padding-bottom: 0;
  margin-bottom: 8px;
}

/* Опасное действие (выход из группы) */
.btn-danger {
  background: var(--danger);
  color: #FFFFFF;
}

/* Экран группы: цветной плашки с вылезающей аватаркой нет,
   поэтому большой отступ .profile-content здесь не нужен */
.profile-content.group-info-content {
  padding-top: 0;
}

/* --- ������� ����� (�������� ������ �������) --- */
.profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px 16px 4px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}
.profile-header .avatar.lg {
  margin-bottom: 12px;
}
.profile-header .display-name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 22px;
  font-weight: bold;
  text-align: center;
  width: 100%;
}
.profile-header .username-line {
  color: var(--text-dim);
  font-size: 15px;
  margin-top: 4px;
  text-align: center;
  width: 100%;
}
.profile-header .bio-line {
  margin-top: 12px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.4;
  word-break: break-word;
}

/* Цветной блок ПОД шапкой */
.profile-color-header {
  position: relative;
  width: 100%;
  height: 140px;
  background: linear-gradient(135deg, #B388FF 0%, #7C4DFF 100%);
  transition: background 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Аватарка внутри цветного блока */
.profile-color-header .avatar.lg {
  width: 120px;
  height: 120px;
  border: 4px solid var(--bg);
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
  margin-bottom: -60px;
  position: relative;
  z-index: 2;
}

/* Отступ для контента, чтобы аватарка не перекрывала кнопки */
.profile-content {
  padding-top: 40px;             /* место под вылезающую аватарку */
}

/* Сетка цветов */
.colors-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.color-cell {
  aspect-ratio: 1;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.color-cell:hover { transform: scale(1.08); }
.color-cell.selected {
  border-color: var(--text);
  transform: scale(1.1);
}

.profile-header .bio-line {
  margin-top: 12px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  max-width: 400px;
  line-height: 1.4;
}

.profile-content textarea {
  width: 100% !important;
  min-height: 100px;
  box-sizing: border-box;
  align-self: stretch;
  resize: vertical;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.5;
}

.registered-at-value {
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 4px;
  margin-bottom: 8px;
}

/* ═══════════════════════════════════════════════ */
/* НАСТРОЙКИ                                        */
/* ═══════════════════════════════════════════════ */
.settings-profile-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  margin-bottom: 16px;
  background: var(--surface-variant);
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.settings-profile-card:hover { background: rgba(255,255,255,.08); }
.settings-profile-info { flex: 1; min-width: 0; }
.settings-profile-name {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 17px;
  font-weight: bold;
  color: var(--text);
}
.settings-profile-username {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
}
.settings-profile-registered-at {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.settings-section-header {
  font-size: 13px;
  font-weight: bold;
  color: var(--primary);
  margin: 16px 8px 6px;
  text-transform: none;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 12px;
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.15s ease;
  user-select: none;
}
.settings-row:hover { background: var(--surface-variant); }

.settings-row-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: var(--text-dim);
}
.settings-row-label {
  flex: 1;
  font-size: 16px;
  color: var(--text);
}
.settings-row-label.danger { color: var(--danger); }
.settings-row-label-col { flex: 1; min-width: 0; }
.settings-row-sub {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
}

.chevron {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-dim);
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--surface);
  border-radius: 24px;
  transition: background 0.2s;
}
.switch .slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}
.switch input:checked + .slider {
  background: var(--primary);
}
.switch input:checked + .slider::before {
  transform: translateX(20px);
}

/* ═══════════════════════════════════════════════ */
/* MESSAPP+                                         */
/* ═══════════════════════════════════════════════ */
.plus-header-title {
  font-size: 22px;
  font-weight: bold;
  color: var(--text);
  margin-bottom: 4px;
}
.plus-header-sub {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 20px;
}
.plus-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  margin-bottom: 12px;
  background: var(--surface-variant);
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.plus-card:hover { background: rgba(255,255,255,.08); }
.plus-card-icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}
.plus-card-info { flex: 1; min-width: 0; }
.plus-card-title {
  font-size: 17px;
  font-weight: bold;
  color: var(--text);
}
.plus-card-sub {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Светлая тема — переопределения */
body.light-theme .settings-profile-card { background: #EEEEEE; }
body.light-theme .settings-profile-card:hover { background: #E0E0E0; }
body.light-theme .settings-row:hover { background: #EEEEEE; }
body.light-theme .plus-card { background: #EEEEEE; }
body.light-theme .plus-card:hover { background: #E0E0E0; }
body.light-theme .switch .slider { background: #CFCFCF; }

/* ═══════════════════════════════════════════════ */
/* ПРОФИЛЬ ПОЛЬЗОВАТЕЛЯ — МОДАЛЬНОЕ ОКНО (2b)      */
/* ═══════════════════════════════════════════════ */

.profile-overlay {
  position: fixed;
  inset: 0;
  z-index: 1900;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(3px);
}
.profile-overlay.visible { display: flex; }

/* Уведомления должны быть видны поверх модального профиля. */
.toast { z-index: 4000; }

.profile-modal {
  --pm-border: rgba(255, 255, 255, .10);
  --pm-border-strong: rgba(255, 255, 255, .18);
  --pm-faint: rgba(255, 255, 255, .05);
  --pm-faint-text: rgba(255, 255, 255, .46);
  position: relative;
  width: min(1120px, 100%);
  height: min(860px, calc(100vh - 48px));
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 26px;
  background: var(--surface);
  border: 1px solid var(--pm-border);
  box-shadow: 0 40px 120px rgba(0, 0, 0, .65);
  animation: profileModalIn .18s ease-out;
}
.profile-modal:focus { outline: none; }

body.light-theme .profile-modal {
  --pm-border: rgba(0, 0, 0, .10);
  --pm-border-strong: rgba(0, 0, 0, .18);
  --pm-faint: rgba(0, 0, 0, .045);
  --pm-faint-text: rgba(0, 0, 0, .46);
}

@keyframes profileModalIn {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─── Обложка и шапка ─────────────────────────── */

.pm-cover {
  position: relative;
  height: 140px;
  flex-shrink: 0;
  overflow: hidden;
  background: linear-gradient(135deg, #6A3DE8 0%, #8B5CF6 48%, #B388FF 100%);
}

.pm-cover::before,
.pm-cover::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .16);
  pointer-events: none;
}
.pm-cover::before {
  width: 280px;
  height: 280px;
  right: -80px;
  top: -150px;
}
.pm-cover::after {
  width: 170px;
  height: 170px;
  left: -55px;
  bottom: -105px;
  border-color: rgba(255, 255, 255, .10);
}

.pm-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 3;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .18);
  background: rgba(0, 0, 0, .28);
  color: #FFFFFF;
  display: grid;
  place-items: center;
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s ease;
}
.pm-close:hover { background: rgba(0, 0, 0, .44); }

.profile-head {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  gap: 20px;
  margin-top: -48px;
  padding: 0 36px;
  flex-shrink: 0;
}

.pm-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.pm-avatar {
  display: block;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 5px solid var(--surface);
  background: #4A4A4A;
  object-fit: cover;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .35);
}

.pm-online {
  position: absolute;
  right: 5px;
  bottom: 7px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #4CAF50;
  border: 3px solid var(--surface);
}

.pm-identity {
  flex: 1;
  min-width: 0;
  padding-bottom: 4px;
}

.pm-name {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 28px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -.4px;
}
.pm-name .badge-container { margin-left: 0; gap: 4px; }
.pm-name .badge-icon { width: 22px; height: 22px; }

.pm-username {
  margin-top: 3px;
  font-size: 14px;
  color: var(--text-dim);
}
.profile-head .pm-username { color: rgba(255, 255, 255, .78); }

.pm-copy {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 5px;
  padding: 2px 7px 2px 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  line-height: 1.3;
  cursor: pointer;
  transition: color .14s ease, background .14s ease;
}
.pm-copy:hover {
  color: var(--text);
  background: var(--pm-faint);
}
.pm-copy svg { width: 12px; height: 12px; flex-shrink: 0; }

.pm-status {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.pm-status[hidden] { display: none; }
.pm-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4CAF50;
  flex-shrink: 0;
}
.pm-status.is-offline .pm-status-dot { background: #8A8A8A; }

.pm-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 4px;
  flex-shrink: 0;
}
.pm-head-actions .btn,
.pm-head-actions .btn-outline {
  width: auto;
  margin-top: 0;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

/* На десктопе username не должен пересекать границу обложки. */
@media (min-width: 901px) {
  .pm-avatar-wrap {
    align-self: flex-start;
  }
  .profile-head .pm-username {
    margin-top: 20px;
    color: var(--text-dim);
  }
  .pm-name {
    flex-wrap: nowrap;
    white-space: nowrap;
    overflow: hidden;
  }
  .pm-name > span:first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .pm-name .badge-container {
    flex-shrink: 0;
  }
}

.pm-action-primary svg,
.pm-action-secondary svg { width: 16px; height: 16px; }
.pm-action-secondary {
  border-width: 1px;
  border-color: var(--pm-border-strong);
  color: var(--text);
}
.pm-action-secondary:hover { background: var(--pm-faint); }

/* ─── Тело: левая колонка + контент ───────────── */

.profile-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 28px;
  padding: 22px 36px 32px;
  overflow-y: auto;
  scrollbar-width: none;
}
.profile-body::-webkit-scrollbar { display: none; }

.profile-side {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.pm-section-title {
  margin: 8px 0 8px 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .9px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.pm-bio {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-dim);
  word-break: break-word;
}
.pm-bio.is-empty { color: var(--pm-faint-text); font-style: italic; }

/* ─── Бейджи-иконки ───────────────────────────── */

.badge-icons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.badge-chip {
  position: relative;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--pm-border-strong);
  background: var(--pm-faint);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  font: inherit;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.badge-chip:hover {
  transform: translateY(-2px);
  border-color: rgba(179, 136, 255, .55);
}
.badge-chip .badge-icon { width: 22px; height: 22px; }
.badge-chip.verified {
  background: rgba(64, 196, 255, .10);
  border-color: rgba(64, 196, 255, .30);
}
.badge-chip.tester {
  background: rgba(255, 152, 0, .10);
  border-color: rgba(255, 152, 0, .32);
}
.badge-chip.admin {
  background: rgba(255, 193, 7, .10);
  border-color: rgba(255, 193, 7, .32);
}

.badge-tip {
  position: absolute;
  top: calc(100% + 9px);
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  z-index: 30;
  padding: 6px 9px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .14);
  background: #0C0C0E;
  color: #FFFFFF;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .14s ease, transform .14s ease;
}
.badge-tip::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-bottom-color: #0C0C0E;
}
.badge-chip.open .badge-tip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.badge-chip:first-child .badge-tip {
  left: 0;
  transform: translateY(-4px);
}
.badge-chip:first-child.open .badge-tip { transform: translateY(0); }
.badge-chip:first-child .badge-tip::before { left: 21px; }
.badge-chip:last-child .badge-tip {
  left: auto;
  right: 0;
  transform: translateY(-4px);
}
.badge-chip:last-child.open .badge-tip { transform: translateY(0); }
.badge-chip:last-child .badge-tip::before { left: auto; right: 21px; }
.badge-chip.open {
  box-shadow: 0 0 0 2px rgba(179, 136, 255, .35);
}
.badge-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--pm-faint-text);
  transition: opacity .14s ease;
}
.badge-open .badge-hint { opacity: 0; }

/* ─── Общие группы ────────────────────────────── */

.pm-groups-title { margin-top: 22px; }
.pm-groups { display: flex; flex-direction: column; }
.pm-group {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 0;
  border: 0;
  border-top: 1px solid var(--pm-border);
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.pm-group:first-child { border-top: 0; }
.pm-group:hover .pm-group-name { color: var(--primary); }
.pm-group-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}
.pm-group-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pm-group-name {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .14s ease;
}
.pm-group-meta {
  margin-top: 1px;
  font-size: 10.5px;
  color: var(--text-dim);
}
.pm-group-chevron {
  width: 14px;
  height: 14px;
  color: var(--pm-faint-text);
  flex-shrink: 0;
}

/* ─── Низ левой колонки ───────────────────────── */

.pm-side-bottom {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--pm-border);
}
.pm-registration {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-dim);
}
.pm-registration svg {
  width: 15px;
  height: 15px;
  color: var(--primary);
  flex-shrink: 0;
}
.pm-report {
  margin-top: 10px;
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  font-size: 12px;
  color: var(--danger);
  cursor: pointer;
}
.pm-report:hover { text-decoration: underline; }

/* ─── Правая колонка ──────────────────────────── */

.profile-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.pm-section { min-width: 0; }
.pm-section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.pm-section-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}
.pm-count {
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--pm-faint);
  border: 1px solid var(--pm-border);
  color: var(--pm-faint-text);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.4;
}
.pm-all {
  margin-left: auto;
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--primary);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.pm-all:hover { color: #C7A4FF; }

/* ─── Медиа ───────────────────────────────────── */

.media-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}
.media-thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  padding: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--pm-border);
  background: var(--surface-variant);
  cursor: pointer;
  transition: transform .16s ease, border-color .16s ease;
}
.media-thumb:hover {
  transform: scale(1.02);
  border-color: rgba(179, 136, 255, .45);
}
.media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.media-thumb.broken {
  background:
    radial-gradient(circle at 80% 10%, rgba(255, 255, 255, .14), transparent 32%),
    linear-gradient(135deg, #7C4DFF, #B388FF);
}
.media-thumb.broken img { display: none; }
.media-thumb.more {
  display: grid;
  place-items: center;
  background: var(--surface-variant);
  border-color: var(--pm-border-strong);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
}
.media-thumb.more:hover { border-color: var(--primary); }

/* ─── Файлы и ссылки ──────────────────────────── */

.section-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}
.mini-section { min-width: 0; }
.mini-list { display: flex; flex-direction: column; }
.mini-row {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 44px;
  padding: 7px 0;
  border: 0;
  border-top: 1px solid var(--pm-border);
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.mini-row:first-child { border-top: 0; }
.mini-row:hover .mini-title { color: var(--primary); }
.mini-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mini-title {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .14s ease;
}
.mini-meta {
  margin-top: 1px;
  font-size: 10.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mini-action {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  color: var(--pm-faint-text);
  flex-shrink: 0;
}
.mini-action svg { width: 14px; height: 14px; }
.mini-row:hover .mini-action { color: var(--text); }

.file-icon,
.link-icon,
.album {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: .2px;
}
.file-icon { border: 1px solid transparent; }
.file-icon.pdf { background: rgba(239, 83, 80, .14); border-color: rgba(239, 83, 80, .28); color: #EF5350; }
.file-icon.zip { background: rgba(179, 136, 255, .14); border-color: rgba(179, 136, 255, .30); color: #B388FF; }
.file-icon.doc { background: rgba(64, 196, 255, .12); border-color: rgba(64, 196, 255, .28); color: #40C4FF; }
.file-icon.sheet { background: rgba(76, 175, 80, .12); border-color: rgba(76, 175, 80, .28); color: #81C784; }
.file-icon.other { background: var(--pm-faint); border-color: var(--pm-border); color: var(--text-dim); }

.link-icon {
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 800;
  background: linear-gradient(135deg, #7C4DFF, #B388FF);
}

/* ─── Музыка ──────────────────────────────────── */

.music-list { display: flex; flex-direction: column; }
.track {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 7px 0;
  border: 0;
  border-top: 1px solid var(--pm-border);
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.track:first-child { border-top: 0; }
.track:hover .track-title { color: var(--primary); }
.track-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.track-title {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .14s ease;
}
.track-artist {
  margin-top: 1px;
  font-size: 10.5px;
  color: var(--text-dim);
}
.track-duration {
  font-size: 10.5px;
  color: var(--pm-faint-text);
  margin-right: 4px;
  flex-shrink: 0;
}
.track-play {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--pm-border-strong);
  background: var(--pm-faint);
  color: var(--text);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  cursor: pointer;
}
.track-play svg { width: 13px; height: 13px; }
.track:hover .track-play {
  background: var(--primary);
  border-color: transparent;
  color: var(--on-primary);
}

/* ─── Пустые состояния ────────────────────────── */

.pm-empty {
  margin-top: 4px;
  padding: 16px 14px;
  border: 1px dashed var(--pm-border-strong);
  border-radius: 12px;
  color: var(--pm-faint-text);
  font-size: 12.5px;
  text-align: center;
}
.pm-empty-side {
  border: 0;
  padding: 6px 0;
  text-align: left;
  font-size: 12px;
}

/* ─── Адаптив ─────────────────────────────────── */

@media (max-width: 900px) {
  .profile-overlay { padding: 0; }
  .profile-modal {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: 0;
  }
  .pm-cover { height: 120px; }
  .profile-head {
    flex-wrap: wrap;
    gap: 14px;
    margin-top: -40px;
    padding: 0 20px 16px;
  }
  .pm-avatar { width: 80px; height: 80px; border-width: 4px; }
  .pm-name { font-size: 23px; }
  .pm-head-actions {
    width: 100%;
    padding-bottom: 0;
    gap: 8px;
  }
  .pm-head-actions .btn,
  .pm-head-actions .btn-outline { flex: 1; justify-content: center; }
  .profile-body {
    grid-template-columns: 1fr;
    gap: 22px;
    padding: 20px;
  }
  .pm-side-bottom { margin-top: 0; }
  .media-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .section-row { grid-template-columns: 1fr; }
  .badge-chip:first-child .badge-tip,
  .badge-chip:last-child .badge-tip {
    left: 50%;
    right: auto;
    transform: translateX(-50%) translateY(-4px);
  }
  .badge-chip:first-child.open .badge-tip,
  .badge-chip:last-child.open .badge-tip { transform: translateX(-50%) translateY(0); }
  .badge-chip:first-child .badge-tip::before,
  .badge-chip:last-child .badge-tip::before { left: 50%; right: auto; }
}

@media (max-width: 520px) {
  .pm-head-actions { flex-wrap: wrap; }
}

/* ═══════════════════════════════════════════════ */
/* МОБИЛЬНЫЙ ПРОФИЛЬ (≤600px) — СВАЙП-РАЗДЕЛЫ     */
/* ═══════════════════════════════════════════════ */

.pm-mobile {
  --pmm-appbar-h: 52px;
  --pmm-cover-h: 64px;
  --pmm-border: rgba(255, 255, 255, .09);
  --pmm-border-strong: rgba(255, 255, 255, .15);
  --pmm-faint: rgba(255, 255, 255, .045);
  --pmm-faint-text: rgba(255, 255, 255, .46);
  --pmm-underline: rgba(255, 255, 255, .22);
  position: relative;
  isolation: isolate;
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
}

body.light-theme .pm-mobile {
  --pmm-border: rgba(0, 0, 0, .09);
  --pmm-border-strong: rgba(0, 0, 0, .15);
  --pmm-faint: rgba(0, 0, 0, .045);
  --pmm-faint-text: rgba(0, 0, 0, .46);
  --pmm-underline: rgba(0, 0, 0, .22);
}

.pm-mobile [hidden] { display: none !important; }

/* Общая подложка шапки и обложки: градиент и круги не обрезаются на стыке. */
.pmm-header-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--pmm-appbar-h) + var(--pmm-cover-h));
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(180deg, #B388FF 0%, #8F6ACC 100%);
}
.pmm-header-bg::before,
.pmm-header-bg::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}
.pmm-header-bg::before {
  width: 190px;
  height: 190px;
  right: -58px;
  top: calc(var(--pmm-appbar-h) - 104px);
  border: 1px solid rgba(255, 255, 255, .16);
}
.pmm-header-bg::after {
  width: 120px;
  height: 120px;
  left: -40px;
  bottom: -72px;
  border: 1px solid rgba(255, 255, 255, .10);
}

.pmm-appbar {
  height: var(--pmm-appbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 10px 0 6px;
  background: transparent;
  color: var(--pmm-appbar-fg, var(--text));
  border-bottom: 0;
  position: relative;
  z-index: 5;
}
.pmm-back {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  padding: 0;
  cursor: pointer;
}
.pmm-back svg { width: 21px; height: 21px; }
.pmm-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.1px;
}

.pmm-scroll {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Обложка и личность ─────────────────────── */

.pmm-cover {
  height: var(--pmm-cover-h);
  flex-shrink: 0;
  background: transparent;
}

.pmm-identity-row {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: -24px;
  padding: 0 14px;
  flex-shrink: 0;
}
.pmm-avatar-wrap {
  position: relative;
  width: 80px;
  height: 80px;
  flex-shrink: 0;
}
.pmm-avatar {
  display: block;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid var(--bg);
  background: var(--surface-variant);
  object-fit: cover;
  box-shadow: 0 7px 18px rgba(0, 0, 0, .24);
}
.pmm-online {
  position: absolute;
  right: 0;
  bottom: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #4CAF50;
  border: 2px solid var(--bg);
}
.pmm-identity {
  flex: 1;
  min-width: 0;
  padding-top: 24px;
}
.pmm-name {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  font-size: 19px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pmm-name > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pmm-name .badge-container {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.pmm-name .badge-icon { width: 17px; height: 17px; }

.pmm-username {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  margin-top: 1px;
  padding: 1px 5px 1px 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.3;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  text-decoration: underline dotted var(--pmm-underline);
  text-underline-offset: 3px;
  transition: background .14s ease, color .14s ease;
}
.pmm-username.pressing,
.pmm-username:active {
  background: rgba(179, 136, 255, .16);
  color: var(--text);
  text-decoration-color: transparent;
}
.pmm-username.copied { color: var(--primary); }
.pmm-copy-ico {
  width: 11px;
  height: 11px;
  color: var(--pmm-faint-text);
  flex-shrink: 0;
}

.pmm-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pmm-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4CAF50;
  flex-shrink: 0;
}
.pmm-status.is-offline .pmm-status-dot { background: #8A8A8A; }

.pmm-username-hint {
  margin-top: 2px;
  font-size: 10px;
  line-height: 1.2;
  color: var(--pmm-faint-text);
  letter-spacing: .1px;
}

.pmm-bio {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.pmm-bio[hidden] { display: none !important; }

/* ─── Действия ───────────────────────────────── */

.pmm-actions {
  display: flex;
  gap: 6px;
  margin: 8px 14px 0;
  flex-shrink: 0;
}
.pmm-btn {
  flex: 1;
  height: 34px;
  border: 0;
  border-radius: 9px;
  padding: 0 10px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
  cursor: pointer;
}
.pmm-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.pmm-btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 5px 16px rgba(124, 77, 255, .18);
}
.pmm-btn-secondary {
  background: var(--pmm-faint);
  color: var(--text);
  border: 1px solid var(--pmm-border-strong);
}

/* ─── Бейджи ─────────────────────────────────── */

.pmm-badges-block {
  margin: 7px 14px 0;
  flex-shrink: 0;
}
.pmm-badge-row {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: nowrap;
  overflow: hidden;
}
.pmm-badge-row .badge-chip {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--pmm-border-strong);
  background: var(--pmm-faint);
  color: var(--text);
  flex-shrink: 0;
}
.pmm-badge-row .badge-chip svg { width: 16px; height: 16px; }
.pmm-badge-row .badge-tip { display: none; }
.pmm-badge-row .badge-chip.open {
  transform: translateY(-1px);
  box-shadow: 0 0 0 2px rgba(179, 136, 255, .35);
}
.pmm-badge-row .badges-empty {
  font-size: 10px;
  color: var(--pmm-faint-text);
}
.pmm-badge-caption {
  height: 12px;
  margin-top: 4px;
  font-size: 9px;
  line-height: 12px;
  color: var(--pmm-faint-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .14s ease;
}
.pmm-badge-caption.active { color: var(--text); }

/* ─── Регистрация ────────────────────────────── */

.pmm-registration {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 7px 14px 0;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}
.pmm-registration svg {
  width: 14px;
  height: 14px;
  color: var(--primary);
  flex-shrink: 0;
}

/* ─── Вкладки ────────────────────────────────── */

.pmm-tabs {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 14px;
  margin-top: 8px;
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.pmm-tabs::-webkit-scrollbar { display: none; }
.pmm-tab {
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--pmm-border);
  border-radius: 8px;
  background: var(--pmm-faint);
  color: var(--text-dim);
  font: inherit;
  font-size: 10.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.pmm-tab-count {
  font-size: 8.5px;
  color: var(--pmm-faint-text);
  transition: color .14s ease;
}
.pmm-tab.active {
  background: var(--primary);
  border-color: transparent;
  color: var(--on-primary);
}
.pmm-tab.active .pmm-tab-count { color: rgba(26, 26, 26, .64); }

/* ─── Пейджер ────────────────────────────────── */

.pmm-pager {
  flex: 1;
  min-height: 0;
  display: flex;
  margin-top: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}
.pmm-pager::-webkit-scrollbar { display: none; }

.pmm-page {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  scrollbar-width: none;
  padding-bottom: 6px;
}
.pmm-page::-webkit-scrollbar { display: none; }

.pmm-page-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px 4px;
}
.pmm-page-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -.1px;
}
.pmm-count {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--pmm-faint);
  color: var(--pmm-faint-text);
  font-size: 9px;
  font-weight: 600;
  line-height: 1.25;
}
.pmm-all {
  margin-left: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.pmm-empty {
  margin: 4px 14px 0;
  padding: 16px 14px;
  border: 1px dashed var(--pmm-border-strong);
  border-radius: 12px;
  color: var(--pmm-faint-text);
  font-size: 12.5px;
  text-align: center;
}
.pmm-page-footer { padding: 10px 14px 4px; }
.pmm-footer-btn {
  width: 100%;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--pmm-border-strong);
  background: var(--pmm-faint);
  color: var(--text);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

/* Списки внутри пейджера */

.pmm-group-list,
.pmm-file-list,
.pmm-link-list {
  display: flex;
  flex-direction: column;
  padding: 0 14px;
}
.pm-mobile .pm-group {
  gap: 9px;
  min-height: 54px;
  padding: 8px 0;
}
.pm-mobile .pm-group-avatar { width: 36px; height: 36px; }
.pm-mobile .pm-group-name { font-size: 12.5px; }
.pm-mobile .pm-group-meta { margin-top: 2px; font-size: 10px; }
.pm-mobile .pm-group-chevron { width: 14px; height: 14px; }

.pm-mobile .mini-row {
  gap: 9px;
  min-height: 54px;
  padding: 8px 0;
}
.pm-mobile .mini-title { font-size: 12.5px; }
.pm-mobile .mini-meta { margin-top: 2px; font-size: 10px; }
.pm-mobile .file-icon,
.pm-mobile .link-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
}
.pm-mobile .file-icon { font-size: 8.5px; }
.pm-mobile .link-icon { font-size: 11px; }
.pm-mobile .mini-action { width: 16px; height: 16px; }
.pm-mobile .mini-action svg { width: 14px; height: 14px; }

.pm-mobile .pmm-media-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  padding: 0 14px;
}
.pm-mobile .pmm-media-grid .media-thumb {
  width: auto;
  height: auto;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
}
.pm-mobile .pmm-media-grid .media-thumb.more { font-size: 11px; }

/* ─── Точки ──────────────────────────────────── */

.pmm-dots {
  height: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.pmm-swipe-hint {
  margin-right: 3px;
  font-size: 8.5px;
  color: var(--pmm-faint-text);
  white-space: nowrap;
}
.pmm-dot {
  width: 5px;
  height: 5px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: var(--pmm-border-strong);
  cursor: pointer;
  transition: width .18s ease, background .18s ease;
}
.pmm-dot.active {
  width: 16px;
  background: var(--primary);
}

/* ─── Нижняя панель ──────────────────────────── */

.pmm-bottom-bar {
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  background: var(--surface);
  border-top: 1px solid var(--pmm-border);
  position: relative;
  z-index: 5;
}
.pmm-report {
  border: 0;
  background: transparent;
  padding: 8px 12px;
  color: var(--danger);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  cursor: pointer;
}
.pmm-report svg { width: 13px; height: 13px; flex-shrink: 0; }

/* ─── Включение мобильной версии ─────────────── */

@media (max-width: 600px) {
  .profile-overlay { padding: 0; }
  .profile-modal {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    border: 0;
    box-shadow: none;
    animation: none;
    background: var(--bg);
  }
  .profile-modal > .pm-cover,
  .profile-modal > .profile-head,
  .profile-modal > .profile-body { display: none; }
  .pm-mobile { display: flex; }
}

/* Плавающая кнопка «Скачать APK» */
.btn-download {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 1500;

  width: 56px;
  height: 56px;
  max-width: 56px;
  max-height: 56px;
  border-radius: 50%;

  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;

  background: #B388FF;

  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;

  -webkit-tap-highlight-color: transparent;
}

.btn-download:hover {
  box-shadow: 0 8px 24px rgba(179, 136, 255, 0.55);
}

.btn-download:active {
  transform: scale(0.94);
}

.btn-download img {
  width: 28px;
  height: 28px;
  display: block;
  
  /* ↑ Если SVG уже фиолетовый — эту строку УБЕРИ */
}

@media (max-width: 480px) {
  .btn-download {
    width: 46px;
    height: 46px;
    left: 16px;
    bottom: 16px;
  }
  .btn-download img {
    width: 23px;
    height: 23px;
  }
}

/* ═══════════════════════════════════════════════ */
/* РЕДАКТИРОВАНИЕ ПРОФИЛЯ — МАКЕТ 01               */
/* Шапка как в публичном профиле + карточки.        */
/* ═══════════════════════════════════════════════ */

.profile-edit-screen {
  --pme-appbar-h: 52px;
  --pme-cover-h: 64px;
  --pme-color: #B388FF;
  --pme-color-light: #C9A6FF;
  --pme-color-dark: #8666BF;
  --pme-appbar-fg: #FFFFFF;
  --pme-border: rgba(255, 255, 255, .09);
  --pme-border-strong: rgba(255, 255, 255, .15);
  --pme-faint: rgba(255, 255, 255, .045);
  --pme-faint-text: rgba(255, 255, 255, .46);
  background: var(--bg);
  color: var(--text);
}

body.light-theme .profile-edit-screen {
  --pme-border: rgba(0, 0, 0, .09);
  --pme-border-strong: rgba(0, 0, 0, .15);
  --pme-faint: rgba(0, 0, 0, .045);
  --pme-faint-text: rgba(0, 0, 0, .46);
}

.pme-modal {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* ─── Шапка: один градиент под appbar и обложкой ─── */

.pme-header {
  position: relative;
  flex-shrink: 0;
}

/* Крестик есть только в десктопном модальном окне. */
.pme-close { display: none; }

.pme-header-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--pme-appbar-h) + var(--pme-cover-h));
  overflow: hidden;
  pointer-events: none;
  background:
    linear-gradient(
      180deg,
      var(--pme-color) 0,
      var(--pme-color) var(--pme-appbar-h),
      var(--pme-color-dark) 100%
    );
}

.pme-header-bg::before,
.pme-header-bg::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .16);
  pointer-events: none;
}

.pme-header-bg::before {
  width: 190px;
  height: 190px;
  right: -58px;
  top: calc(var(--pme-appbar-h) - 104px);
}

.pme-header-bg::after {
  width: 120px;
  height: 120px;
  left: -40px;
  bottom: -72px;
  border-color: rgba(255, 255, 255, .10);
}

.pme-appbar {
  position: relative;
  z-index: 3;
  height: var(--pme-appbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 10px 0 6px;
  color: var(--pme-appbar-fg);
}

.pme-back {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  padding: 0;
  cursor: pointer;
}

.pme-back svg {
  width: 21px;
  height: 21px;
}

.pme-appbar-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.1px;
}

.pme-cover {
  position: relative;
  z-index: 1;
  height: var(--pme-cover-h);
  flex-shrink: 0;
}

/* ─── Аватар, имя, username ─────────────────────── */

.pme-identity {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: -24px;
  padding: 0 14px;
  flex-shrink: 0;
}

.pme-avatar-wrap {
  position: relative;
  width: 80px;
  height: 80px;
  flex-shrink: 0;
}

.pme-avatar {
  display: block;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid var(--bg);
  background: var(--surface-variant);
  object-fit: cover;
  box-shadow: 0 7px 18px rgba(0, 0, 0, .24);
}

.pme-avatar-edit {
  position: absolute;
  right: -2px;
  bottom: 0;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  background: var(--primary);
  color: var(--on-primary);
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .35);
}

.pme-avatar-edit svg {
  width: 12px;
  height: 12px;
  stroke-width: 2.2;
}

.pme-identity-main {
  flex: 1;
  min-width: 0;
  padding-top: 24px;
}

.pme-name {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  font-size: 19px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -.3px;
  white-space: nowrap;
  overflow: hidden;
}

.pme-name > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pme-header-badge {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.pme-header-badge .badge-container {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.pme-header-badge .badge-icon {
  width: 17px;
  height: 17px;
}

.pme-username {
  margin-top: 1px;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pme-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pme-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4CAF50;
  flex-shrink: 0;
}

.pme-head-actions {
  display: none;
}

/* ─── Тело: карточки ────────────────────────────── */

.pme-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 8px 14px 12px;
  overflow-y: auto;
  overflow-x: hidden;
}

.pme-info-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 11px;
  border-radius: 12px;
  border: 1px solid rgba(179, 136, 255, .17);
  background: rgba(179, 136, 255, .07);
  color: #C9B6F4;
  font-size: 10.5px;
  line-height: 1.4;
}

.pme-info-banner svg {
  width: 14px;
  height: 14px;
  color: var(--primary);
  margin-top: 1px;
  flex-shrink: 0;
}

.pme-info-banner-desktop {
  display: none;
}

body.light-theme .pme-info-banner {
  color: #5B3E8F;
  background: rgba(124, 77, 255, .06);
  border-color: rgba(124, 77, 255, .16);
}

.pme-error {
  display: none;
  margin: 0;
  padding: 8px 11px;
  border-radius: 10px;
  background: rgba(239, 83, 80, .10);
  border: 1px solid rgba(239, 83, 80, .25);
  color: var(--danger);
  font-size: 11.5px;
  line-height: 1.4;
}

.pme-error:not(:empty) {
  display: block;
}

.pme-layout {
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-height: 0;
}

.pme-side {
  display: none;
}

.pme-form-panel {
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-width: 0;
}

.pme-card {
  background: var(--surface);
  border: 1px solid var(--pme-border);
  border-radius: 16px;
  padding: 12px;
}

.pme-card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 8px;
  color: var(--text-dim);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.pme-card-title span {
  color: var(--pme-faint-text);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .2px;
  text-transform: none;
}

.pme-grid-2 {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.pme-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.pme-grid-2 .pme-field + .pme-field {
  margin-top: 0;
}

.pme-grid-2 + .pme-field {
  margin-top: 7px;
}

.pme-label {
  color: var(--text-dim);
  font-size: 10.5px;
  line-height: 1.2;
  font-weight: 600;
}

.pme-field input,
.pme-field textarea {
  width: 100%;
  border: 1px solid var(--pme-border);
  border-radius: 11px;
  background: var(--surface-variant);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  outline: none;
}

.pme-field input {
  height: 38px;
  padding: 0 11px;
}

.pme-field textarea {
  height: 68px;
  padding: 9px 11px;
  line-height: 1.45;
  resize: none;
}

.pme-field input:focus,
.pme-field textarea:focus {
  border-color: rgba(179, 136, 255, .72);
  box-shadow: 0 0 0 3px rgba(179, 136, 255, .11);
}

.pme-field input::placeholder,
.pme-field textarea::placeholder {
  color: var(--pme-faint-text);
}

.pme-sub-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 6px;
  color: var(--text-dim);
  font-size: 10.5px;
  font-weight: 600;
}

.pme-sub-label span {
  color: var(--pme-faint-text);
  font-size: 9.5px;
  font-weight: 500;
}

.pme-swatches {
  display: grid;
  grid-template-columns: repeat(6, 30px);
  justify-content: space-between;
  gap: 7px;
}

.pme-swatches .color-cell {
  width: 30px;
  height: 30px;
  aspect-ratio: auto;
  border-width: 2px;
  position: relative;
}

.pme-swatches .color-cell.selected {
  border-color: transparent;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text);
}

.pme-swatches .color-cell.selected::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m20 6-11 11-5-5'/%3E%3C/svg%3E") center / 13px 13px no-repeat;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .35));
  pointer-events: none;
}

.pme-sub-label + .pme-swatches {
  margin-bottom: 10px;
}

.pme-badge-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  border-radius: 0;
}

.pme-badge-picker .badge-cell {
  width: 32px;
  height: 32px;
  padding: 5px;
  border-width: 1px;
  border-color: var(--pme-border-strong);
  border-radius: 9px;
  background: rgba(255, 255, 255, .045);
}

body.light-theme .pme-badge-picker .badge-cell {
  background: rgba(0, 0, 0, .035);
}

.pme-badge-picker .badge-cell.selected {
  border-color: var(--primary);
  background: rgba(179, 136, 255, .18);
}

.pme-hint {
  margin-top: 6px;
  color: var(--pme-faint-text);
  font-size: 9.5px;
  line-height: 1.35;
}

.pme-registration {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.35;
}

.pme-registration svg {
  width: 14px;
  height: 14px;
  color: var(--primary);
  flex-shrink: 0;
}

.pme-registration-mobile {
  margin: 1px 1px 0;
  padding: 1px;
}

.pme-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── Нижняя панель сохранения ─────────────────── */

.pme-savebar {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(18, 18, 20, 0), var(--bg) 30%);
  border-top: 1px solid rgba(255, 255, 255, .055);
}

body.light-theme .pme-savebar {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), var(--bg) 30%);
  border-top-color: rgba(0, 0, 0, .06);
}

.pme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}

.pme-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.pme-savebar .pme-btn {
  flex: 1;
}

.pme-savebar .pme-btn-ghost {
  flex: 0 0 108px;
}

.pme-btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 6px 18px rgba(179, 136, 255, .24);
}

.pme-btn-primary:hover {
  background: #C7A4FF;
}

body.light-theme .pme-btn-primary:hover {
  background: var(--primary-dark);
  color: #FFFFFF;
}

.pme-btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--pme-border-strong);
}

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

/* Планшет: та же мобильная компоновка, но уже по центру. */
@media (min-width: 601px) and (max-width: 900px) {
  .pme-modal {
    width: 100%;
    max-width: 620px;
    margin: 0 auto;
    border-left: 1px solid var(--pme-border);
    border-right: 1px solid var(--pme-border);
    box-shadow: 0 0 60px rgba(0, 0, 0, .18);
  }
}

/* ─── Десктоп: модальное окно 940 × 680 ─────────── */

@media (min-width: 901px) {
  .profile-edit-screen {
    --pme-appbar-h: 0px;
    --pme-cover-h: 120px;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background:
      radial-gradient(600px 340px at 72% 16%, rgba(77, 150, 255, .16), transparent 70%),
      rgba(5, 5, 8, .78);
  }

  body.light-theme .profile-edit-screen {
    background:
      radial-gradient(600px 340px at 72% 16%, rgba(77, 150, 255, .12), transparent 70%),
      rgba(0, 0, 0, .34);
  }

  .pme-modal {
    width: min(940px, 100%);
    height: min(680px, calc(100vh - 40px));
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, .11);
    background: var(--surface);
    box-shadow: 0 38px 100px rgba(0, 0, 0, .62);
  }

  body.light-theme .pme-modal {
    border-color: rgba(0, 0, 0, .10);
    box-shadow: 0 38px 100px rgba(0, 0, 0, .28);
  }

  .pme-header {
    flex-shrink: 0;
  }

  .pme-close {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 5;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, .20);
    background: rgba(0, 0, 0, .24);
    color: #FFFFFF;
    cursor: pointer;
  }

  .pme-close:hover {
    background: rgba(0, 0, 0, .38);
  }

  .pme-close svg {
    width: 17px;
    height: 17px;
  }

  .pme-header-bg {
    height: var(--pme-cover-h);
    background:
      linear-gradient(
        135deg,
        var(--pme-color-light) 0%,
        var(--pme-color) 46%,
        var(--pme-color-dark) 100%
      );
  }

  .pme-header-bg::before {
    width: 280px;
    height: 280px;
    right: -78px;
    top: -155px;
    border-color: rgba(255, 255, 255, .18);
  }

  .pme-header-bg::after {
    width: 170px;
    height: 170px;
    left: -48px;
    bottom: -108px;
    border-color: rgba(255, 255, 255, .11);
  }

  .pme-appbar {
    display: none;
  }

  .pme-cover {
    height: var(--pme-cover-h);
  }

  .pme-identity {
    align-items: flex-end;
    gap: 18px;
    margin-top: -40px;
    padding: 0 28px;
  }

  .pme-avatar-wrap {
    width: 84px;
    height: 84px;
    align-self: flex-end;
  }

  .pme-avatar {
    width: 84px;
    height: 84px;
    border-width: 4px;
    border-color: var(--surface);
  }

  .pme-avatar-edit {
    right: -2px;
    bottom: 0;
    width: 26px;
    height: 26px;
    border-color: var(--surface);
  }

  .pme-identity-main {
    padding-top: 0;
    padding-bottom: 4px;
  }

  .pme-name {
    gap: 7px;
    font-size: 26px;
    letter-spacing: -.5px;
  }

  .pme-header-badge .badge-icon {
    width: 20px;
    height: 20px;
  }

  .pme-username {
    margin-top: 2px;
    font-size: 13.5px;
  }

  .pme-status {
    margin-top: 5px;
    font-size: 12.5px;
  }

  .pme-head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 4px;
    flex-shrink: 0;
  }

  .pme-head-actions .pme-btn {
    height: 36px;
    padding: 0 13px;
    border-radius: 10px;
    font-size: 12px;
  }

  .pme-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 20px 28px 24px;
    overflow: hidden;
  }

  .pme-layout {
    order: 1;
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 258px minmax(0, 1fr);
    gap: 26px;
  }

  .pme-body > .pme-info-banner {
    display: none;
  }

  .pme-info-banner-desktop {
    display: flex;
    margin-top: 12px;
    flex-shrink: 0;
  }

  .pme-error {
    order: 3;
    margin-top: 10px;
    flex-shrink: 0;
  }

  .pme-side {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding-top: 2px;
  }

  .pme-section-title {
    margin: 0 0 7px;
    color: var(--text-dim);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
  }

  .pme-bio-preview {
    margin: 0 0 18px;
    color: var(--text-dim);
    font-size: 12.5px;
    line-height: 1.55;
    word-break: break-word;
  }

  .pme-bio-preview.is-empty {
    color: var(--pme-faint-text);
    font-style: italic;
  }

  .pme-badges-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .pme-badges-preview .badge-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .pme-badges-preview .badge-icon {
    width: 42px;
    height: 42px;
    padding: 9px;
    box-sizing: border-box;
    border: 1px solid var(--pme-border-strong);
    border-radius: 12px;
    background: var(--pme-faint);
  }

  .pme-side-bottom {
    margin-top: auto;
    padding-top: 16px;
  }

  .pme-form-panel {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow: hidden;
    padding: 17px 19px;
    border: 1px solid rgba(255, 255, 255, .075);
    border-radius: 16px;
    background: #202025;
  }

  body.light-theme .pme-form-panel {
    border-color: rgba(0, 0, 0, .08);
    background: #FFFFFF;
  }

  .pme-card {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .pme-card + .pme-card {
    margin-top: 12px;
    padding-top: 14px;
    border-top: 1px solid var(--pme-border);
  }

  .pme-card-title {
    margin-bottom: 10px;
  }

  .pme-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .pme-grid-2 + .pme-field {
    margin-top: 9px;
  }

  .pme-field textarea {
    height: 72px;
  }

  .pme-sub-label {
    margin-bottom: 5px;
  }

  .pme-swatches {
    grid-template-columns: repeat(12, 30px);
    gap: 6px;
  }

  .pme-sub-label + .pme-swatches {
    margin-bottom: 10px;
  }

  .pme-badge-picker .badge-cell {
    width: 34px;
    height: 34px;
  }

  .pme-registration-mobile {
    display: none;
  }

  .pme-savebar {
    display: none;
  }
}