/*
  NiMilex — фирменные компоненты поверх базовой системы.
  48-угольные аватары, штриховые статусы сообщений, фильтр-чипы, экран «Звонки»,
  карточка профиля «Вы», рабочая отметка. Всё оформлено под тёмную и светлую тему.
*/

/* ---------- Фирменный 48-угольник для аватаров и монограмм (§4, §16) ---------- */

.avatar {
  clip-path: var(--polygon48);
  border-radius: 0;
  /* Монограмма из ограниченной палитры — приглушённая, с золотым контуром внутри.
     Фото/градиент подставляются из JS через --avatar-bg. */
  background: var(--avatar-bg, var(--gray));
  color: #F7F4EC;
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* Присутствие: точка внутри огранки, чтобы 48-угольник её не срезал. */
.avatar-online::after {
  right: 6%;
  bottom: 6%;
  width: 26%;
  height: 26%;
  min-width: 10px;
  min-height: 10px;
  border: 2px solid var(--bg);
  background: var(--green);
}

/* Фотография в аватаре — заполняет форму целиком, без постоянной рамки. */
.avatar.has-photo {
  background-size: cover;
  background-position: center;
  color: transparent;
}

/* Крупный аватар профиля: заметная огранка. */
.avatar-xl {
  width: 96px;
  height: 96px;
  font-size: 34px;
}

/* ---------- Штриховые статусы сообщений (§15) ---------- */
/* Собственная пиктограмма: короткие диагональные штрихи под единым углом.
   Число штрихов = стадия: 1 — отправляется, 2 — на сервере, 3 — доставлено,
   3 золотых — прочитано, «/!» — ошибка. Отличие не только цветом (кол-во штрихов). */

.strokes {
  display: inline-flex;
  align-items: center;
  gap: 1.5px;
  height: 12px;
  vertical-align: middle;
}

.strokes .s {
  display: block;
  width: 2px;
  height: 11px;
  border-radius: 2px;
  transform: skewX(-24deg);
  background: var(--stroke-server);
  transition: background var(--dur) var(--ease), opacity var(--dur) var(--ease);
}

.strokes[data-state="sending"] .s { background: var(--stroke-sent); }
.strokes[data-state="sending"] .s:first-child { animation: stroke-pulse 1.3s var(--ease) infinite; }
.strokes[data-state="server"] .s { background: var(--stroke-server); }
.strokes[data-state="delivered"] .s { background: var(--stroke-delivered); }
.strokes[data-state="read"] .s {
  background: var(--stroke-read);
  /* Прочитано — насыщеннее и чуть шире: отличие сверх цвета (§15). */
  width: 2.4px;
  box-shadow: 0 0 6px rgba(201, 162, 78, 0.5);
}
.strokes[data-state="error"] { color: var(--stroke-error); }
.strokes[data-state="error"] .s { background: var(--stroke-error); height: 11px; }
.strokes[data-state="error"] .bang {
  transform: none;
  width: 2px;
  height: 11px;
  border-radius: 2px;
  background: var(--stroke-error);
  position: relative;
}

@keyframes stroke-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* Крупные штрихи в шапке диалога / карточке доставки. */
.strokes-lg { height: 18px; gap: 2.5px; }
.strokes-lg .s { width: 3px; height: 17px; }

/* ---------- Фирменная рабочая отметка (Signet, §7/§9) ---------- */
/* Маленький золотой ромбовидный знак рядом с названием рабочего чата.
   Без отдельного фона и тяжёлой рамки. */

.signet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  color: var(--accent-strong);
  vertical-align: middle;
}

.signet svg { width: 16px; height: 16px; display: block; }

.row-title-line {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.row-title-line .row-title { min-width: 0; }

/* Строка превью со статусом-штрихами в конце (§7). */
.row-preview-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin-top: 1px;
}
.row-preview-line .chat-row-preview { flex: 1; min-width: 0; }
.row-preview-line .strokes { flex: 0 0 auto; }

/* ---------- Заголовок раздела в стиле макета ---------- */

.nmx-head {
  flex: 0 0 auto;
  min-height: var(--header-h);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--separator);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  position: sticky;
  top: 0;
  z-index: 6;
}

.nmx-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.4px;
  flex: 1;
  min-width: 0;
}

.nmx-title-center {
  flex: 1;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.2px;
  user-select: none;
}

/* Аватар-кнопка слева в шапке «Чаты» → открывает «Вы». */
.nmx-head-avatar { flex: 0 0 auto; }

/* Секция-заголовок внутри списка: «Недавние», «Все контакты». */
.list-section {
  padding: 16px 16px 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--label-secondary);
}

/* ---------- Фильтр-чипы (§7: Все / Непрочитанные / Избранные / Группы) ---------- */

.chips {
  display: flex;
  gap: 8px;
  padding: 10px 14px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 15px;
  border-radius: var(--r-full);
  background: var(--bg-input);
  color: var(--label-secondary);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.chip.is-active {
  background: var(--accent-dim);
  color: var(--accent-strong);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

/* ---------- Экран «Звонки» (§6) ---------- */

.call-row-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  color: var(--label-secondary);
}

.call-dir {
  display: inline-flex;
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
}
.call-dir.in  { color: var(--green); }
.call-dir.out { color: var(--accent-strong); }
.call-dir.missed { color: var(--red); }
.call-row.missed .call-name { color: var(--red); }

.call-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: var(--r-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-strong);
  background: var(--accent-dim);
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.call-btn:hover { background: color-mix(in srgb, var(--accent) 26%, transparent); }
.call-btn:active { transform: scale(0.92); }
.call-btn svg { width: 20px; height: 20px; }

.presence-line {
  font-size: 13px;
  color: var(--label-secondary);
}
.presence-line.online { color: var(--green); }

/* ---------- Экран «Вы» (§10) ---------- */

.you-scroll {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 40px;
}

/* На широком экране раздел «Вы» — читаемая колонка по центру, не на всю ширину. */
@media (min-width: 900px) {
  .you-scroll > * {
    max-width: 640px;
    margin-left: auto;
    margin-right: auto;
  }
}

/* Шевроны и указатели в разделе «Вы» — фиксированного размера (иначе SVG
   растягивается на всю строку). */
.you-item .rot180,
.you-profile .rot180,
.you-item-label + .rot180 {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
}

.you-profile {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 12px 14px 8px;
  padding: 16px;
  border-radius: var(--r-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  width: calc(100% - 28px);
  text-align: left;
  transition: background var(--dur-fast) var(--ease);
}
.you-profile:hover { background: var(--bg-hover); }

.you-profile-body { flex: 1; min-width: 0; }
.you-profile-name { font-size: 20px; font-weight: 700; letter-spacing: -0.2px; }
.you-profile-id { font-size: 13.5px; color: var(--label-secondary); margin-top: 2px; }
.you-profile-id b { color: var(--accent-strong); font-weight: 600; }
.you-profile-phone { font-size: 13.5px; color: var(--label-secondary); }
.you-profile .rot180 { color: var(--label-tertiary); }

/* Группа пунктов настроек — карточкой со скруглением. */
.you-group {
  margin: 10px 14px;
  border-radius: var(--r-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  overflow: hidden;
}

.you-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  text-align: left;
  background: none;
  transition: background var(--dur-fast) var(--ease);
  position: relative;
}
.you-item:hover { background: var(--bg-hover); }
.you-item + .you-item::before {
  content: "";
  position: absolute;
  top: 0; left: 58px; right: 0; height: 1px;
  background: var(--separator);
  transform: scaleY(0.5);
}

/* Иконка в скруглённом акцентном квадрате (как в макете «Вы»). */
.you-item-ic {
  width: 30px; height: 30px; flex: 0 0 30px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: var(--label-on-accent);
  background: var(--accent);
}
.you-item-ic.tone-blue   { background: #4E6BE0; }
.you-item-ic.tone-green  { background: var(--green); }
.you-item-ic.tone-violet { background: #7C5CE0; }
.you-item-ic.tone-gray   { background: var(--gray); }
.you-item-ic svg { width: 18px; height: 18px; }

.you-item-label { flex: 1; font-size: 16px; font-weight: 500; }
.you-item .rot180 { color: var(--label-tertiary); }
.you-item-value { font-size: 15px; color: var(--label-secondary); }

/* ---------- Переключатель (тумблер) ---------- */

.switch {
  position: relative;
  width: 50px; height: 30px;
  flex: 0 0 50px;
  border-radius: var(--r-full);
  background: var(--bg-active);
  transition: background var(--dur) var(--ease);
}
.switch.is-on { background: var(--accent); }
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: var(--r-full);
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
  transition: transform var(--dur) var(--ease);
}
.switch.is-on::after { transform: translateX(20px); }

/* ---------- QR профиля ---------- */

.qr-box {
  display: grid;
  place-items: center;
  padding: 24px;
}
.qr-canvas {
  width: min(260px, 70vw);
  height: min(260px, 70vw);
  image-rendering: pixelated;
  border-radius: var(--r-md);
  background: #fff;
  padding: 14px;
}

/* Рамка-заглушка кода профиля с фирменными угловыми маркерами. */
.qr-frame {
  width: min(240px, 66vw);
  height: min(240px, 66vw);
  display: grid;
  place-items: center;
  border-radius: var(--r-lg);
  background: var(--bg-grouped);
  position: relative;
  border: 2px solid var(--separator);
}
.qr-frame::before, .qr-frame::after {
  content: "";
  position: absolute;
  width: 46px; height: 46px;
  border: 4px solid var(--accent);
  border-radius: 10px;
}
.qr-frame::before { top: 14px; left: 14px; border-right: none; border-bottom: none; }
.qr-frame::after { bottom: 14px; right: 14px; border-left: none; border-top: none; }
.qr-frame-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-strong);
  letter-spacing: 0.5px;
}

/* ---------- Кадрирование аватара по 48-угольнику ---------- */

.cropper {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}
.cropper-stage {
  position: relative;
  width: min(300px, 78vw);
  height: min(300px, 78vw);
  overflow: hidden;
  background: var(--bg-grouped);
  touch-action: none;
  clip-path: var(--polygon48);
  cursor: grab;
}
.cropper-stage:active { cursor: grabbing; }
.cropper-stage canvas, .cropper-stage img { position: absolute; top: 0; left: 0; }
.cropper-range { width: 100%; }

/* ---------- Пасхалка: длинное нажатие на «NiMilex» ---------- */
.nmx-egg { color: var(--accent-strong); font-weight: 700; }

/* На телефоне заголовок раздела крупнее прижимаем к краям */
@media (max-width: 899px) {
  .nmx-title { font-size: 30px; }
}
