/* ============================================================
   CHAT ARCHIVE 24/7 | MASTER-SAVE — «Досье»

   Язык: архивное дело. Чёрный картон обложки, машинопись, штамп,
   полоса редактуры на том, что собеседник удалил или переписал.
   Цвет несёт смысл, а не украшает: бычья кровь — изъятое и опасное,
   охра — исправленное. Коробок почти нет, структуру держат линейки.
   ============================================================ */

:root {
  /* Картон и бумага */
  --board-deep: #0B0A09;
  --board:      #121110;
  --leaf:       #1A1816;
  --leaf-2:     #232019;

  /* Машинопись */
  --bone:       #E9E4D8;
  --bone-dim:   #A7A194;
  --graphite:   #6E6960;

  /* Пометки дела */
  --oxblood:      #9A2A38;
  --oxblood-ink:  #CF5460;
  --ochre:        #C08F44;

  --rule:       rgba(233, 228, 216, 0.14);
  --rule-soft:  rgba(233, 228, 216, 0.07);

  --sans: 'Golos Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --gut: 18px;
  --rail-h: 68px;
}

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

html { background: var(--board-deep); }

body {
  background: var(--board-deep);
  color: var(--bone);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  font-weight: 400;
  min-height: 100vh;
  padding-bottom: calc(var(--rail-h) + env(safe-area-inset-bottom, 0px) + 24px);
  -webkit-font-smoothing: antialiased;
}

#app { width: 100%; max-width: 720px; margin: 0 auto; }

::selection { background: var(--oxblood); color: var(--bone); }

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

/* ============================================================
   Обложка дела
   ============================================================ */

.cover {
  position: relative;
  overflow: hidden;
  background: var(--board);
  border-bottom: 1px solid var(--rule);
  border-left: 3px solid var(--oxblood);
  padding: 22px var(--gut) 20px;
}

/* Зернистость картона: одна текстура на всё приложение, только здесь. */
.cover-grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.28'/%3E%3C/svg%3E");
}

.cover > *:not(.cover-grain) { position: relative; }

.cover-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.cover-mark {
  display: block;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.22em;
  color: var(--bone);
}

.cover-sub {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  color: var(--graphite);
}

/* Штамп — единственное место, где уместен верхний регистр:
   резиновый штамп так и выглядит. */
.stamp {
  flex: none;
  transform: rotate(-5deg);
  padding: 5px 10px 4px;
  border: 1.5px solid var(--oxblood-ink);
  box-shadow: inset 0 0 0 1px rgba(207, 84, 96, 0.35);
  color: var(--oxblood-ink);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  line-height: 1.3;
  text-align: center;
  max-width: 128px;
  opacity: 0.92;
}

.stamp.granted { border-color: var(--ochre); color: var(--ochre); box-shadow: inset 0 0 0 1px rgba(192, 143, 68, 0.3); }

.cover-case {
  margin: 18px 0 16px;
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--bone);
}

/* Строки дела с отточием — как в бланке описи. */
.form-lines { display: flex; flex-direction: column; gap: 7px; }

.form-line { display: flex; align-items: baseline; gap: 8px; }

.form-line dt {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  color: var(--bone-dim);
}

.form-line dt::after {
  content: "";
  flex: 1;
  position: relative;
  top: -4px;
  border-bottom: 1px dotted var(--rule);
}

.form-line dd {
  flex: none;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--bone);
}

/* ============================================================
   Разделы
   ============================================================ */

.tab-content { display: none; padding: 0 var(--gut); }
.tab-content.active { display: block; }

.section {
  margin: 26px 0 12px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--bone);
}

.section-note {
  margin: -6px 0 16px;
  font-size: 13.5px;
  color: var(--bone-dim);
  max-width: 62ch;
}

/* ============================================================
   Пилюли периодов и фильтров (Адаптивные с переносом)
   ============================================================ */

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.filter-pills::-webkit-scrollbar { display: none; }

.pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 11px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: #d1d5db;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .14s ease;
  user-select: none;
}

.pill:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.22);
}

.pill:active {
  transform: scale(0.96);
}

.pill.active {
  background: var(--oxblood-ink);
  border-color: var(--oxblood-ink);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 0 10px rgba(184, 51, 42, 0.35);
}

.pill.locked { opacity: 0.45; }

.pill.select-btn {
  padding: 5px 12px;
  font-size: 12px;
  color: var(--ochre);
  border-color: rgba(217, 119, 6, 0.35);
  background: rgba(217, 119, 6, 0.08);
}

.pill.select-btn:hover {
  background: rgba(217, 119, 6, 0.16);
  border-color: var(--ochre);
  color: #ffffff;
}

/* ============================================================
   Сводка и фигуранты (кто удаляет и правит)
   ============================================================ */

.tally {
  display: flex;
  border: 1px solid var(--rule);
  border-radius: 2px;
  margin-bottom: 16px;
}

.tally-cell {
  flex: 1;
  padding: 12px 10px;
  text-align: center;
}

.tally-cell + .tally-cell { border-left: 1px solid var(--rule); }

.tally-num {
  display: block;
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.tally-cell.deleted .tally-num { color: var(--oxblood-ink); }
.tally-cell.edited  .tally-num { color: var(--ochre); }
.tally-cell.saved   .tally-num { color: var(--bone); }

.tally-name {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--graphite);
}

.peer-list { display: flex; flex-direction: column; }

.peer-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule-soft);
}

.peer-place {
  flex: none;
  width: 18px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--graphite);
  font-variant-numeric: tabular-nums;
}

.peer-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14.5px;
}

/* Шапка с названиями колонок: два голых числа рядом иначе не прочитать,
   а разводить их одним цветом нельзя — цвет не для всех различим. */
.peer-head {
  display: flex;
  justify-content: flex-end;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule);
}

.peer-head .peer-counts span {
  font-size: 10.5px;
  color: var(--graphite);
}

.peer-counts {
  flex: none;
  display: flex;
  gap: 8px;
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.peer-counts > span {
  display: inline-block;
  width: 46px;
  text-align: right;
}

.peer-counts .c-del { color: var(--oxblood-ink); }
.peer-counts .c-ed  { color: var(--ochre); }
.peer-counts .c-off { color: var(--graphite); }

.insights-locked {
  padding: 16px;
  border: 1px dashed var(--rule);
  border-radius: 2px;
  font-size: 13.5px;
  color: var(--bone-dim);
}

/* ============================================================
   Поиск
   ============================================================ */

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  margin-top: 22px;
  padding-left: 10px;
  background: var(--leaf);
  border-bottom: 1px solid var(--rule);
}

.search-box input {
  flex: 1;
  padding: 10px 30px 10px 0;
  border: 0;
  background: transparent;
  color: var(--bone);
  font-family: var(--sans);
  font-size: 15px;
}

.search-box input::placeholder { color: var(--graphite); }
.search-box input:focus { outline: none; }
.search-box:focus-within { border-bottom-color: var(--bone-dim); }

.search-clear {
  position: absolute;
  right: 6px;
  border: 0;
  background: transparent;
  color: var(--graphite);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}

/* ============================================================
   Лента записей
   ============================================================ */

.feed-list { display: flex; flex-direction: column; }

.day-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 6px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--graphite);
}

.day-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--rule-soft);
}

.item-card {
  display: flex;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--rule-soft);
}

.item-avatar,
.chat-avatar {
  position: relative;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 2px;
  border: 1px solid var(--rule);
  background: var(--leaf-2);
  color: var(--bone-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  user-select: none;
}

.avatar-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: grayscale(0.35) contrast(1.05);
}

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

.item-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }

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

.item-chat {
  font-size: 12px;
  color: var(--graphite);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-entry { padding: 2px 0; cursor: pointer; }

.entry-line { display: flex; align-items: baseline; gap: 8px; }

.entry-kind {
  flex: none;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--graphite);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 1px 4px;
}

.entry-kind.eph { color: var(--oxblood-ink); border-color: rgba(207, 84, 96, 0.45); }

.entry-text {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  color: var(--bone-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-time {
  flex: none;
  font-family: var(--mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--graphite);
}

.feed-photo-preview { margin-top: 7px; }

.feed-photo-preview img {
  max-width: 108px;
  max-height: 84px;
  border-radius: 2px;
  border: 1px solid var(--rule);
  display: block;
}

/* ============================================================
   Приложения к делу — контактный лист
   ============================================================ */

.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
}

.grid-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--leaf);
  cursor: pointer;
}

.grid-item img.photo-item {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: grayscale(0.2);
  transition: filter .15s;
}

.grid-item:hover img.photo-item { filter: grayscale(0); }

.grid-overlay {
  position: absolute;
  inset: auto 0 0 0;
  padding: 16px 6px 5px;
  background: linear-gradient(to top, rgba(11, 10, 9, 0.92), transparent);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.grid-author {
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--bone);
}

.grid-date, .grid-size {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--bone-dim);
  flex: none;
}

/* Текстовая и файловая плитка: бумажный листок вместо картинки. */
.grid-item.grid-text,
.grid-item.ghost {
  background: var(--leaf);
  border: 1px solid var(--rule-soft);
  padding: 9px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.grid-kind {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--graphite);
  flex: none;
}

.grid-caption {
  flex: 1;
  min-height: 0;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--bone-dim);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.grid-foot {
  margin-top: auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

/* Красная метка осталась одна на всё приложение — у перехваченного
   одноразового. Поэтому она маленькая и ей верят. */
.grid-badge {
  position: absolute;
  top: 0;
  right: 0;
  padding: 1px 4px;
  background: var(--oxblood);
  color: var(--bone);
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.06em;
  z-index: 1;
}

.grid-item.selected { outline: 2px solid var(--ochre); outline-offset: -2px; }

/* ============================================================
   Фигуранты
   ============================================================ */

.chats-list { display: flex; flex-direction: column; }

.chats-search { margin: 0 0 4px; }

/* Строки списков в админке. */
.chat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--rule-soft);
}

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

/* Строка фигуранта: карточка-фото, имя, время, а под ним — что пойманно. */
.chat-row {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 12px 0;
  border-bottom: 1px solid var(--rule-soft);
  cursor: pointer;
}

.chat-row[hidden] { display: none; }
.chat-row:active { background: var(--leaf); }

.chat-row .chat-avatar { width: 44px; height: 44px; font-size: 16px; }

.chat-row-main { flex: 1; min-width: 0; }

.chat-row-top { display: flex; align-items: baseline; gap: 10px; }

.chat-name {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-when {
  flex: none;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--graphite);
  font-variant-numeric: tabular-nums;
}

.chat-row-meta,
.tx-who-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 12px;
  margin-top: 2px;
  font-size: 12.5px;
}

.chat-count { color: var(--graphite); font-variant-numeric: tabular-nums; }

/* Пойманное — полоса редактуры цвета пометки: кровь — удалено, охра — правка. */
.caught { display: inline-flex; align-items: center; gap: 6px; }
.caught::before { content: ''; width: 10px; height: 3px; background: currentColor; }
.caught-deleted { color: var(--oxblood-ink); }
.caught-edited { color: var(--ochre); }

/* ============================================================
   Стенограмма переписки
   ============================================================ */

#tab-chats.in-chat > .section { display: none; }

.tx-head {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 calc(-1 * var(--gut));
  padding: 14px var(--gut) 12px;
  background: var(--board-deep);
  border-bottom: 1px solid var(--rule);
}

.tx-head .back-link-btn { margin-bottom: 10px; }

.tx-who { display: flex; align-items: center; gap: 12px; }
.tx-who .chat-avatar { width: 40px; height: 40px; font-size: 15px; }
.tx-who-text { min-width: 0; }

.tx-who h3 {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tx-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tx-filters[hidden] { display: none; }

.back-link-btn {
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: transparent;
  color: var(--bone-dim);
  padding: 4px 10px;
  font-family: var(--sans);
  font-size: 13px;
  cursor: pointer;
}

.tx { display: flex; flex-direction: column; padding: 4px 0 16px; }

.tx-day {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 6px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--graphite);
}

.tx-day::before,
.tx-day::after { content: ''; flex: 1; height: 1px; background: var(--rule-soft); }
.tx-day[hidden] { display: none; }

/* Листок: чужое слева, своё справа и на бумаге посветлее. */
.tx-msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 86%;
  margin-top: 3px;
}

.tx-msg.first { margin-top: 12px; }
.tx-msg.own { align-self: flex-end; align-items: flex-end; }
.tx-msg[hidden] { display: none; }

.tx-sender {
  margin: 0 0 3px 1px;
  font-size: 12px;
  font-weight: 600;
  color: var(--bone-dim);
}

.tx-slip {
  min-width: 64px;
  max-width: 100%;
  padding: 8px 11px 6px;
  background: var(--leaf);
  border: 1px solid var(--rule-soft);
  border-radius: 2px;
}

.tx-msg.own .tx-slip { background: var(--leaf-2); }
.tx-msg.edited .tx-slip { cursor: pointer; }

.tx-text {
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.tx-meta {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 8px;
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--graphite);
  font-variant-numeric: tabular-nums;
}

.tx-flag-edited { color: var(--ochre); }
.tx-flag-eph { color: var(--oxblood-ink); }

/* Удалённое собеседником: листок под кровью и оттиск штампа, как на обложке. */
.tx-msg.deleted .tx-slip {
  background: linear-gradient(rgba(154, 42, 56, 0.12), rgba(154, 42, 56, 0.12)), var(--leaf);
  border-color: rgba(207, 84, 96, 0.4);
}

.tx-stamp {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  margin: 3px 0 8px 2px;
  padding: 3px 8px 2px;
  transform: rotate(-4deg);
  transform-origin: left center;
  border: 1.5px solid var(--oxblood-ink);
  box-shadow: inset 0 0 0 1px rgba(207, 84, 96, 0.35);
  color: var(--oxblood-ink);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.14em;
  opacity: 0.92;
}

.tx-stamp time { letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }

/* Место под фото занято до загрузки: иначе лента прыгает и открытие
   «на последних сообщениях» промахивается. */
.tx-photo {
  display: block;
  width: 240px;
  max-width: 100%;
  aspect-ratio: 4 / 3;
  margin: 2px 0 6px;
  object-fit: cover;
  border-radius: 2px;
  background: var(--board);
  cursor: zoom-in;
}

.tx-sticker { display: block; width: 128px; height: 128px; object-fit: contain; margin: 2px 0 4px; }

.tx-media {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 168px;
  margin: 2px 0 6px;
  padding: 7px 12px 7px 7px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--board);
  color: var(--bone);
  font-family: var(--sans);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}

.tx-media-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 2px; }
.tx-media[data-kind="video_note"] .tx-media-thumb { border-radius: 50%; }

.tx-play {
  flex: none;
  width: 0;
  height: 0;
  margin-left: 6px;
  border-left: 10px solid var(--bone);
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}

/* Файла нет — это просто строка в листке, а не кнопка. */
.tx-media.missing {
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  min-width: 0;
  margin: 0 0 2px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--bone-dim);
  cursor: default;
}

.tx-media-note { font-size: 12px; color: var(--graphite); }

/* Полоса редактуры: прежняя версия под вычеркнутой строкой. */
.edit-history {
  margin-top: 8px;
  padding: 9px 11px;
  border-left: 2px solid var(--oxblood);
  background: rgba(154, 42, 56, 0.08);
}

.edit-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--oxblood-ink);
  margin-bottom: 5px;
}

.edit-step + .edit-step { margin-top: 7px; }

.edit-old {
  position: relative;
  font-size: 13.5px;
  color: var(--bone-dim);
  text-decoration: line-through;
  text-decoration-color: var(--oxblood-ink);
  text-decoration-thickness: 1.5px;
  word-break: break-word;
}

.edit-when {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--graphite);
  margin-top: 2px;
}

/* ============================================================
   Доступ
   ============================================================ */

/* Вкладка начинается не с заголовка, а с карточек (тест-драйв, скидка,
   статус) — без отступа они прилипали к обложке. */
#tab-billing { padding-top: 20px; }

.billing-status {
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 16px;
}

.billing-tier {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.12em;
  color: var(--ochre);
  margin-bottom: 6px;
}

.billing-expires { font-size: 14px; color: var(--bone); }

.billing-line { font-size: 13.5px; color: var(--bone-dim); margin-top: 4px; }

.billing-discount {
  margin-top: 10px;
  padding: 9px 11px;
  border-left: 2px solid var(--ochre);
  background: rgba(192, 143, 68, 0.09);
  font-size: 13px;
  color: var(--bone);
}

.billing-ref { font-size: 13px; color: var(--graphite); margin-top: 8px; }

.billing-plans { display: flex; flex-direction: column; }

.plan-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--rule-soft);
}

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

.plan-title { font-size: 14.5px; font-weight: 500; }

.plan-note { font-size: 12.5px; color: var(--graphite); margin-top: 2px; }

.plan-saving { color: var(--ochre); }

.plan-old {
  text-decoration: line-through;
  text-decoration-color: var(--oxblood-ink);
  color: var(--graphite);
  margin-right: 6px;
}

.plan-actions { flex: none; }

.plan-btn {
  border: 1px solid var(--bone-dim);
  border-radius: 2px;
  background: transparent;
  color: var(--bone);
  padding: 7px 14px;
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background .12s, color .12s;
}

.plan-btn:hover { background: var(--bone); color: var(--board); }

.billing-methods { display: flex; flex-direction: column; }

.method-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 13px 0;
  border: 0;
  border-bottom: 1px solid var(--rule-soft);
  background: transparent;
  color: var(--bone);
  font-family: var(--sans);
  font-size: 14.5px;
  cursor: pointer;
}

.billing-history { display: flex; flex-direction: column; }

.history-when, .history-days {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--graphite);
  font-variant-numeric: tabular-nums;
}

.history-what { font-size: 14px; }

.billing-history > div {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule-soft);
}

.billing-history .history-what { flex: 1; min-width: 0; }

/* ============================================================
   Выдача дела
   ============================================================ */

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  user-select: none;
}

.check input { position: absolute; opacity: 0; width: 0; height: 0; }

.check-box {
  flex: none;
  width: 16px;
  height: 16px;
  border: 1px solid var(--bone-dim);
  border-radius: 1px;
  position: relative;
}

.check input:checked + .check-box {
  background: var(--ochre);
  border-color: var(--ochre);
}

.check input:checked + .check-box::after {
  content: "";
  position: absolute;
  left: 4.5px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid var(--board);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.check input:focus-visible + .check-box { outline: 2px solid var(--ochre); outline-offset: 2px; }

.check-row { padding: 12px 0; border-bottom: 1px solid var(--rule-soft); }

.export-chats { display: flex; flex-direction: column; }

.export-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--rule-soft);
  cursor: pointer;
  font-size: 14px;
}

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

.export-count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--graphite);
  font-variant-numeric: tabular-nums;
}

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

.link-btn {
  border: 0;
  background: transparent;
  color: var(--ochre);
  font-family: var(--sans);
  font-size: 13.5px;
  cursor: pointer;
  padding: 2px 0;
}

/* ============================================================
   Навигация (Чёткие кнопки с рамками и иконками)
   ============================================================ */

.rail {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: rgba(14, 13, 12, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 6px calc(env(safe-area-inset-bottom, 0px) + 6px);
  gap: 5px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
}

.tab-btn {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 3px 2px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: #9ca3af;
  font-family: var(--sans);
  cursor: pointer;
  transition: all .16s ease;
  user-select: none;
  box-sizing: border-box;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
  color: #e5e7eb;
}

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

.tab-btn .tab-icon {
  font-size: 18px;
  line-height: 1;
  display: block;
  transition: transform .16s ease;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

.tab-btn .tab-label {
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  display: block;
}

.tab-btn.active {
  background: linear-gradient(180deg, rgba(225, 29, 72, 0.24) 0%, rgba(184, 51, 42, 0.14) 100%);
  border: 1.5px solid #e11d48;
  color: #ffffff;
  box-shadow: 0 0 12px rgba(225, 29, 72, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.tab-btn.active .tab-icon {
  transform: translateY(-1px) scale(1.15);
}

.tab-btn.active .tab-label {
  color: #ffffff;
  font-weight: 600;
}

.tab-btn::before {
  display: none;
}

/* ============================================================
   Просмотр вложения
   ============================================================ */

.modal, .sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal.open, .sheet.open { display: flex; }

.modal-overlay, .sheet-overlay {
  position: absolute;
  inset: 0;
  background: rgba(5, 5, 4, 0.9);
}

.modal-card {
  position: relative;
  max-width: 94vw;
  max-height: 88vh;
  padding: 0;
}

.modal-card img, .modal-card video {
  max-width: 94vw;
  max-height: 80vh;
  display: block;
  border: 1px solid var(--rule);
}

.modal-title {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--bone-dim);
  margin-bottom: 8px;
}

.modal-close-btn {
  position: absolute;
  top: -40px;
  right: 0;
  width: 32px;
  height: 32px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: transparent;
  color: var(--bone);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

/* Лист действий */
.sheet { align-items: flex-end; }

.sheet-card {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  background: var(--board);
  border-top: 3px solid var(--oxblood);
  border-radius: 16px 16px 0 0;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px var(--gut) calc(16px + env(safe-area-inset-bottom, 0px));
  animation: rise .18s ease-out;
}

@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

.sheet-title {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--graphite);
  margin-bottom: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 13px 0;
  border: 0;
  border-top: 1px solid var(--rule-soft);
  background: transparent;
  color: var(--bone);
  font-family: var(--sans);
  font-size: 15px;
  cursor: pointer;
}

.sheet-btn.danger { color: var(--oxblood-ink); }
.sheet-btn.quiet { color: var(--graphite); }

/* ============================================================
   Служебные состояния
   ============================================================ */

.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 0;
  color: var(--graphite);
  font-size: 13.5px;
}

.spinner {
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--rule);
  border-top-color: var(--oxblood-ink);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  padding: 24px 0;
  color: var(--graphite);
  font-size: 13.5px;
}

.notice {
  position: fixed;
  left: 50%;
  bottom: calc(var(--rail-h) + 16px);
  transform: translateX(-50%);
  z-index: 70;
  background: var(--leaf-2);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--ochre);
  border-radius: 2px;
  padding: 9px 14px;
  font-size: 13.5px;
  max-width: 88vw;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media (min-width: 560px) {
  .media-grid { grid-template-columns: repeat(4, 1fr); }
}


/* ============================================================
   НОВЫЕ СТИЛИ: PIN, STT, Floating Player, Quota, Favorites, Charts
   ============================================================ */

/* Кнопка избранного на медиа-плитке */
.grid-item {
  position: relative;
}

.btn-fav {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(233, 228, 216, 0.2);
  background: rgba(11, 10, 9, 0.65);
  backdrop-filter: blur(4px);
  color: var(--bone-dim);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
  transition: all 0.2s ease;
}

.btn-fav.active {
  background: #f59e0b;
  border-color: #f59e0b;
  color: #000;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
}

/* Расшифровка аудио/видео (Speech-to-Text) */
.item-transcription {
  margin-top: 6px;
  padding: 6px 10px;
  background: rgba(192, 143, 68, 0.08);
  border-left: 2px solid var(--ochre);
  border-radius: 3px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--bone);
  font-style: italic;
  word-break: break-word;
}

/* Ghost Mode Diff */
.ghost-diff-box {
  margin-top: 8px;
  padding: 8px 12px;
  background: rgba(154, 42, 56, 0.1);
  border-left: 3px solid var(--oxblood-ink);
  border-radius: 3px;
  font-size: 13px;
  line-height: 1.5;
}

.ghost-diff-box s {
  color: var(--oxblood-ink);
  background: rgba(207, 84, 96, 0.2);
  padding: 1px 3px;
  border-radius: 2px;
}

.ghost-diff-box u {
  color: #10b981;
  background: rgba(16, 185, 129, 0.2);
  padding: 1px 3px;
  border-radius: 2px;
  text-decoration: none;
  font-weight: 600;
}

/* Floating Continuous Audio/Video Player */
.floating-player {
  position: fixed;
  left: 50%;
  bottom: calc(var(--rail-h) + 10px);
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 680px;
  background: #1c1a17;
  border: 1px solid var(--ochre);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  z-index: 60;
  padding: 10px 14px;
}

.player-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.player-kind {
  font-size: 10px;
  font-family: var(--mono);
  background: var(--ochre);
  color: #000;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 2px;
}

.player-title {
  font-size: 13px;
  color: var(--bone);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-close {
  background: transparent;
  border: none;
  color: var(--bone-dim);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.player-btn-play {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--ochre);
  color: #000;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.player-seek-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.player-range {
  width: 100%;
  accent-color: var(--ochre);
  cursor: pointer;
  height: 4px;
}

.player-time {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--bone-dim);
}

.player-speed-btn {
  background: rgba(233, 228, 216, 0.1);
  border: 1px solid var(--rule);
  color: var(--bone);
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
}

/* Пока не ясно, нужен ли ПИН, архив не показываем — только кольцо загрузки.
   Иначе до ответа сервера (через ngrok — секунды) было видно всё приложение. */
html.pin-checking #app { visibility: hidden; }
html.pin-checking #pin-lock-modal { visibility: visible; }
html.pin-checking body::after {
  content: '';
  position: fixed;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border: 2px solid var(--rule);
  border-top-color: var(--bone);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

/* PIN Lock Screen Modal */
.pin-modal {
  position: fixed;
  inset: 0;
  background: var(--board-deep);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.pin-card {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.pin-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.pin-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}

.pin-sub {
  font-size: 13px;
  color: var(--bone-dim);
  margin-bottom: 24px;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 30px;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--bone-dim);
  transition: all 0.2s ease;
}

.pin-dot.filled {
  background: var(--ochre);
  border-color: var(--ochre);
  box-shadow: 0 0 10px rgba(192, 143, 68, 0.5);
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.pin-key {
  height: 56px;
  background: var(--leaf);
  border: 1px solid var(--rule);
  border-radius: 50%;
  color: var(--bone);
  font-size: 22px;
  font-family: var(--sans);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease;
}

.pin-key:active {
  background: var(--leaf-2);
  border-color: var(--ochre);
}

.pin-key.special {
  font-size: 18px;
  background: transparent;
  border: none;
}

.pin-error {
  color: var(--oxblood-ink);
  font-size: 13px;
  margin-top: 16px;
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* SVG Charts */
.admin-chart-svg path.line-users {
  stroke: #3b82f6;
  stroke-width: 2.5;
  fill: none;
}

.admin-chart-svg path.line-msgs {
  stroke: #10b981;
  stroke-width: 2.5;
  fill: none;
}

.admin-chart-svg path.line-stars {
  stroke: #f59e0b;
  stroke-width: 2.5;
  fill: none;
}


/* Admin Subtabs & Management (3x2 адаптивная сетка без переполнения) */
.admin-subtabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 16px;
  width: 100%;
  box-sizing: border-box;
}
.subtab-btn {
  width: 100%;
  box-sizing: border-box;
  min-width: 0;
  padding: 8px 3px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--leaf);
  color: var(--bone-dim);
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.25;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}
.subtab-btn:hover {
  color: var(--bone);
  border-color: var(--bone-dim);
}
.subtab-btn.active {
  background: var(--ochre);
  color: var(--board-deep);
  border-color: var(--ochre);
  font-weight: 600;
}
.admin-user-card {
  background: var(--leaf);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.admin-user-top {
  display: flex;
  align-items: center;
  gap: 12px;
}
.admin-user-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px dashed var(--rule-soft);
}
.admin-action-btn {
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 3px;
  border: 1px solid var(--rule);
  background: var(--leaf-2);
  color: var(--bone);
  cursor: pointer;
  transition: all 0.12s ease;
}
.admin-action-btn:hover {
  border-color: var(--ochre);
  color: var(--ochre);
}
.admin-action-btn.danger {
  border-color: var(--oxblood);
  color: var(--oxblood-ink);
}
.admin-action-btn.danger:hover {
  background: var(--oxblood);
  color: #fff;
}
.admin-action-btn.primary {
  background: var(--ochre);
  color: var(--board-deep);
  border-color: var(--ochre);
}
.admin-action-btn.primary:hover {
  opacity: 0.9;
}

/* ============================================================
   Stats Grid & Cards
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}
.stat-card {
  background: var(--leaf);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 10px 12px;
  box-sizing: border-box;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.stat-label {
  font-size: 11px;
  color: var(--bone-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--bone);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   Promo Generator & Promo List
   ============================================================ */
.promo-gen-card {
  background: var(--leaf);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 18px;
  box-sizing: border-box;
  width: 100%;
}
.promo-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}
.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}
.form-label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--bone-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.form-input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 9px 10px;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--board);
  color: var(--bone);
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease;
}
.form-input:focus {
  border-color: var(--ochre);
}
.code-input {
  text-transform: uppercase;
  font-family: var(--mono);
  font-weight: 600;
}
.form-input[type="number"]::-webkit-inner-spin-button,
.form-input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.form-input[type="number"] {
  -moz-appearance: textfield;
}
.promo-create-btn {
  width: 100%;
  margin-top: 12px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 6px;
}
.promo-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.promo-list-title {
  font-size: 12px;
  color: var(--bone-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0;
}
.promo-count-badge {
  font-size: 11px;
  color: var(--ochre);
  background: rgba(192, 143, 68, 0.12);
  border: 1px solid rgba(192, 143, 68, 0.25);
  padding: 2px 7px;
  border-radius: 10px;
}
.promo-items-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
  width: 100%;
  box-sizing: border-box;
}
.promo-card {
  background: var(--leaf);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 12px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  min-width: 0;
}
.promo-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  width: 100%;
}
.promo-card-code-area {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}
.promo-card-code {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13.5px;
  color: var(--ochre);
  background: rgba(192, 143, 68, 0.12);
  border: 1px solid rgba(192, 143, 68, 0.3);
  padding: 3px 8px;
  border-radius: 5px;
  letter-spacing: 0.5px;
}
.promo-card-uses {
  font-size: 11px;
  color: var(--bone-dim);
  background: var(--board);
  padding: 3px 7px;
  border-radius: 4px;
}
.promo-card-delete-btn {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #ef4444;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}
.promo-card-delete-btn:hover {
  background: rgba(239, 68, 68, 0.2);
}
.promo-card-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  width: 100%;
}
.promo-chip {
  font-size: 11.5px;
  color: var(--bone);
  background: var(--board);
  border: 1px solid var(--rule-soft);
  padding: 3px 8px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

/* ============================================================
   In-App Toasts & Custom Modals
   ============================================================ */
.toast-container {
  position: fixed;
  top: 12px;
  left: 14px;
  right: 14px;
  z-index: 10000;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.app-toast {
  pointer-events: auto;
  max-width: 480px;
  width: 100%;
  background: #181715;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translateY(-16px);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.app-toast.visible {
  opacity: 1;
  transform: translateY(0);
}
.toast-success {
  border-color: rgba(16, 185, 129, 0.5);
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.15);
}
.toast-error {
  border-color: rgba(239, 68, 68, 0.5);
  box-shadow: 0 8px 24px rgba(239, 68, 68, 0.15);
}
.toast-warning {
  border-color: rgba(234, 179, 8, 0.5);
  box-shadow: 0 8px 24px rgba(234, 179, 8, 0.15);
}
.toast-icon {
  font-size: 16px;
  flex-shrink: 0;
}
.toast-msg {
  font-size: 13px;
  line-height: 1.35;
  color: var(--bone);
  word-break: break-word;
}

/* Custom Modals (Alert & Confirm) */
.custom-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}
.custom-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(5, 5, 4, 0.85);
  backdrop-filter: blur(6px);
}
.custom-modal-card {
  position: relative;
  background: #181615;
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 22px 18px 18px;
  max-width: 380px;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.custom-modal-icon {
  font-size: 32px;
  margin-bottom: 8px;
}
.custom-modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--bone);
  margin-bottom: 8px;
}
.custom-modal-text {
  font-size: 13.5px;
  color: var(--bone-dim);
  line-height: 1.45;
  margin-bottom: 16px;
  word-break: break-word;
}
.alert-modal-support {
  background: rgba(192, 143, 68, 0.08);
  border: 1px solid rgba(192, 143, 68, 0.25);
  border-radius: 8px;
  padding: 10px;
  font-size: 12px;
  color: var(--bone-dim);
  margin-bottom: 16px;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}
.support-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--ochre);
  color: var(--board-deep);
  font-weight: 600;
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 20px;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.support-pill:hover {
  opacity: 0.9;
}
.custom-modal-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}
.custom-modal-btn {
  flex: 1;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--rule);
  transition: all 0.15s ease;
}
.custom-modal-btn.confirm {
  background: var(--ochre);
  color: var(--board-deep);
  border-color: var(--ochre);
}
.custom-modal-btn.cancel {
  background: transparent;
  color: var(--bone-dim);
}
.custom-modal-btn:hover {
  opacity: 0.9;
}

/* Mobile responsive safeguards.
   clip режет вбок так же, как hidden, но не делает элемент контейнером
   прокрутки — иначе ломается sticky (шапка переписки). hidden — для старых движков. */
body {
  overflow-x: hidden;
  overflow-x: clip;
  width: 100%;
  max-width: 100vw;
}
#app {
  overflow-x: hidden;
  overflow-x: clip;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}
@media (max-width: 360px) {
  :root {
    --gut: 12px;
  }
  .subtab-btn {
    font-size: 10.5px;
    padding: 7px 2px;
  }
  .rail {
    padding: 4px 4px calc(env(safe-area-inset-bottom, 0px) + 4px);
    gap: 3px;
  }
  .tab-btn {
    height: 46px;
    border-radius: 7px;
    padding: 2px 1px;
    gap: 1px;
  }
  .tab-btn .tab-icon {
    font-size: 15px;
  }
  .tab-btn .tab-label {
    font-size: 9px;
  }
  .pill {
    padding: 5px 8px;
    font-size: 11px;
  }
}

/* Раздел «Команды» */
.cmd-search { margin: 4px 0 6px; }
.cmd-chat { padding: 12px 0; border-bottom: 1px solid var(--rule-soft); }
.cmd-chat-name { font-weight: 600; margin-bottom: 6px; }
.cmd-toggle, .cmd-field { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13.5px; }
.cmd-field select { background: var(--board); color: var(--bone); border: 1px solid var(--rule); border-radius: 4px; padding: 4px 6px; }
.cmd-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cmd-num { width: 64px; background: var(--board); color: var(--bone); border: 1px solid var(--rule); border-radius: 4px; padding: 4px 6px; }
.cmd-text { width: 100%; min-height: 64px; margin: 6px 0 8px; background: var(--board); color: var(--bone); border: 1px solid var(--rule); border-radius: 4px; padding: 8px; font: inherit; box-sizing: border-box; }
.cmd-rights { list-style: none; padding: 0; margin: 0 0 6px; font-size: 13.5px; line-height: 1.8; }
.cmd-pro-note { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; margin-bottom: 8px; border: 1px solid var(--ochre); border-radius: 4px; font-size: 13px; }
.cmd-pro-contents { margin-bottom: 8px; }

/* Справочник всех команд: группа сворачивается, в строке — команда, что
   делает и пример. Копируется пример, а не голое имя: его сразу можно править. */
.cmd-group { border-top: 1px solid var(--rule); }
.cmd-group:last-of-type { border-bottom: 1px solid var(--rule); }

.cmd-group > summary {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 0;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.cmd-group > summary::-webkit-details-marker { display: none; }
.cmd-group > summary::after { content: '+'; margin-left: auto; color: var(--graphite); font-family: var(--mono); }
.cmd-group[open] > summary::after { content: '−'; }
.cmd-group-count { font-family: var(--mono); font-size: 12px; font-weight: 400; color: var(--graphite); }
.cmd-group > .cmd-pro-note { margin: 0 0 4px; }

.cmd-ref { padding: 11px 0; border-top: 1px solid var(--rule-soft); }

.cmd-ref-head { display: flex; align-items: baseline; gap: 8px; }

.cmd-ref-name { flex: none; font-family: var(--mono); font-size: 13.5px; color: var(--ochre); }

.cmd-ref-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cmd-ref-copy {
  flex: none;
  padding: 3px 9px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: transparent;
  color: var(--bone-dim);
  font-family: var(--sans);
  font-size: 12px;
  cursor: pointer;
}

.cmd-ref-copy:active { background: var(--leaf-2); color: var(--bone); }

.cmd-ref-lock { flex: none; font-size: 12px; color: var(--graphite); }

.cmd-ref-desc { margin-top: 3px; font-size: 13.5px; color: var(--bone-dim); }

.cmd-ref-usage { margin-top: 3px; font-size: 12.5px; color: var(--graphite); overflow-wrap: anywhere; }

.cmd-ref-usage code {
  padding: 0 4px;
  border-radius: 2px;
  background: var(--leaf-2);
  color: var(--bone);
  font-family: var(--mono);
  font-size: 12px;
}

/* Без PRO команда видна, но приглушена: понятно, что есть, и где взять. */
.cmd-ref.locked .cmd-ref-name,
.cmd-ref.locked .cmd-ref-title,
.cmd-ref.locked .cmd-ref-desc,
.cmd-ref.locked .cmd-ref-usage { opacity: 0.55; }
