/* ═══════════════════════════════════════════════════════════════════════
   Рабочая станция — каркас поверх существующего #app
   [рельс][список][чат][слот] + мобильная нижняя навигация
   ═══════════════════════════════════════════════════════════════════════ */

#app {
  display: flex;
  align-items: stretch;
}

/* ── Рельс ──────────────────────────────────────────────────────────────── */
.rail {
  width: var(--rail-w);
  min-width: var(--rail-w);
  height: var(--app-height, 100vh);
  background: var(--bg-rail, #0c0c0d);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0 12px;
  flex-shrink: 0;
}
.rail__mark {
  width: 40px; height: 40px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); margin-bottom: 16px;
}
.rail__mark svg { width: 26px; height: 26px; }
.rail__spaces { display: flex; flex-direction: column; gap: 4px; flex: 1; width: 100%; align-items: center; }
.rail__item {
  position: relative; width: 52px; height: 50px; border-radius: 13px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: transparent; border: none; cursor: pointer; color: var(--text-muted);
  transition: background var(--t-fast), color var(--t-fast);
}
.rail__item svg { width: 21px; height: 21px; }
.rail__item:hover { background: var(--bg-glass); color: var(--text-secondary); }
.rail__item--active { background: var(--accent-muted); color: var(--accent); }
.rail__item--active::before {
  content: ''; position: absolute; left: -14px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 22px; background: var(--accent); border-radius: 0 3px 3px 0;
}
.rail__label { font-size: 9px; font-weight: var(--fw-medium); letter-spacing: 0.01em; }
.rail__count {
  position: absolute; top: 5px; right: 8px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--accent); color: #fff;
  font-family: var(--font-mono); font-size: 9px; font-weight: var(--fw-medium);
  display: flex; align-items: center; justify-content: center;
}
.rail__bottom { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.rail__icon-btn {
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; cursor: pointer; color: var(--text-muted);
  transition: background var(--t-fast), color var(--t-fast);
}
.rail__icon-btn svg { width: 20px; height: 20px; }
.rail__icon-btn:hover { background: var(--bg-glass); color: var(--text-primary); }
.rail__avatar {
  width: 36px; height: 36px; border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-weight: var(--fw-semibold); font-size: 13px; color: var(--text-primary);
  overflow: hidden;
}

/* ── Список: новая шапка ────────────────────────────────────────────────── */
.sidebar__titlebar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 4px 12px;
}
.sidebar__space-title {
  font-size: var(--font-xl); font-weight: var(--fw-bold); letter-spacing: -0.02em;
  color: var(--text-primary);
}

/* ── Лента «Требует внимания» ───────────────────────────────────────────── */
.sidebar__activity { padding: 0 14px 10px; }
.activity {
  border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden;
  background: var(--bg-glass);
}
.activity__head { display: flex; align-items: center; gap: 7px; padding: 9px 12px 7px; }
.activity__head svg { width: 15px; height: 15px; color: var(--accent); }
.activity__head span {
  font-size: var(--font-xs); font-weight: var(--fw-semibold); letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-muted);
}
.activity__item {
  display: flex; gap: 9px; align-items: flex-start; width: 100%; text-align: left;
  padding: 8px 12px; border: none; border-top: 1px solid var(--border-subtle);
  background: transparent; cursor: pointer; transition: background var(--t-fast);
}
.activity__item:hover { background: var(--bg-glass-hover); }
.activity__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-top: 6px; flex-shrink: 0; }
.activity__text {
  flex: 1; min-width: 0; font-size: var(--font-sm); color: var(--text-secondary); line-height: 1.4;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.activity__text b { color: var(--text-primary); font-weight: var(--fw-semibold); }
.activity__time { font-family: var(--font-mono); font-size: var(--font-xs); color: var(--text-muted); flex-shrink: 0; }

/* ── Слот (правая панель) ───────────────────────────────────────────────── */
.slot {
  width: 0; min-width: 0; overflow: hidden;
  height: var(--app-height, 100vh);
  background: var(--bg-sidebar);
  border-left: 1px solid transparent;
  display: flex; flex-direction: column;
  flex-shrink: 0;
  transition: width var(--t-base), min-width var(--t-base);
}
.slot[data-open="true"] {
  width: var(--slot-w); min-width: var(--slot-w);
  border-left-color: var(--border);
}
.slot__head {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--header-h); padding: 0 8px 0 18px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.slot__title { font-size: var(--font-lg); font-weight: var(--fw-semibold); }
.slot__tabs { display: flex; gap: 2px; padding: 8px 12px; border-bottom: 1px solid var(--border-subtle); }
.slot__tab {
  flex: 1; padding: 7px 8px; border-radius: 8px; background: transparent; border: none; cursor: pointer;
  color: var(--text-muted); font-family: var(--font-family); font-size: var(--font-sm); font-weight: var(--fw-medium);
  transition: background var(--t-fast), color var(--t-fast);
}
.slot__tab:hover { background: var(--bg-glass); color: var(--text-secondary); }
.slot__tab--active { background: var(--bg-glass-hover); color: var(--text-primary); }
.slot__body { flex: 1; overflow-y: auto; }
.slot__loading, .slot__empty { padding: 40px 20px; text-align: center; color: var(--text-muted); font-size: var(--font-sm); }
.slot__empty svg { width: 30px; height: 30px; opacity: 0.5; margin-bottom: 10px; }
.slot__empty p { margin: 0; }
.slot__empty-hint { font-family: var(--font-mono); font-size: var(--font-xs); color: var(--text-muted); opacity: 0.7; }

.slot__prof { display: flex; flex-direction: column; align-items: center; padding: 26px 20px 18px; text-align: center; border-bottom: 1px solid var(--border-subtle); }
.slot__prof-avatar { width: 88px; height: 88px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 30px; font-weight: var(--fw-semibold); color: var(--text-primary); overflow: hidden; }
.slot__prof-name { font-size: var(--font-lg); font-weight: var(--fw-bold); letter-spacing: -0.01em; margin-top: 14px; }
.slot__prof-handle { font-family: var(--font-mono); font-size: var(--font-sm); color: var(--text-muted); margin-top: 3px; }
.slot__prof-bio { font-size: var(--font-sm); color: var(--text-secondary); margin-top: 12px; line-height: 1.5; }
.slot__prof-actions { display: flex; gap: 8px; margin-top: 18px; }
.slot__qbtn {
  display: flex; flex-direction: column; align-items: center; gap: 5px; width: 64px; padding: 10px 4px;
  border-radius: 11px; background: var(--bg-surface); border: 1px solid var(--border); color: var(--text-secondary);
  cursor: pointer; font-family: var(--font-family); font-size: var(--font-xs);
  transition: background var(--t-fast), color var(--t-fast);
}
.slot__qbtn svg { width: 18px; height: 18px; }
.slot__qbtn:hover { background: var(--bg-surface-hover); color: var(--text-primary); }
.slot__qbtn--danger:hover { color: var(--danger); }

.slot__group { padding: 14px 18px; border-bottom: 1px solid var(--border-subtle); }
.slot__group-label { font-size: var(--font-xs); font-weight: var(--fw-semibold); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; }
.slot__row { display: flex; align-items: center; gap: 12px; padding: 7px 0; }
.slot__row-ic { color: var(--text-muted); display: flex; }
.slot__row-ic svg { width: 17px; height: 17px; }
.slot__row-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: var(--fw-semibold); color: var(--text-primary); overflow: hidden; flex-shrink: 0; }
.slot__row-main { flex: 1; min-width: 0; }
.slot__row-k { font-size: var(--font-sm); color: var(--text-primary); }
.slot__row-v { font-size: var(--font-xs); color: var(--text-muted); margin-top: 1px; }

.slot__mgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 12px; }
.slot__mtile { aspect-ratio: 1; border-radius: 8px; overflow: hidden; background-color: var(--bg-surface); background-size: cover; background-position: center; border: 1px solid var(--border); cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.slot__mtile--video svg { width: 22px; height: 22px; }
.slot__mtile:hover { border-color: var(--border-accent); }
.slot__frow { display: flex; align-items: center; gap: 12px; padding: 9px 16px; cursor: pointer; }
.slot__frow:hover { background: var(--bg-glass); }
.slot__ficon { width: 38px; height: 38px; border-radius: 9px; background: var(--bg-surface); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; color: var(--accent); flex-shrink: 0; }
.slot__ficon svg { width: 18px; height: 18px; }

.slot__thread { display: block; width: 100%; text-align: left; padding: 12px 16px; background: transparent; border: none; border-bottom: 1px solid var(--border-subtle); cursor: pointer; transition: background var(--t-fast); }
.slot__thread:hover { background: var(--bg-glass); }
.slot__thread-title { font-size: var(--font-sm); font-weight: var(--fw-medium); color: var(--text-primary); }
.slot__thread-meta { font-family: var(--font-mono); font-size: var(--font-xs); color: var(--text-muted); margin-top: 3px; }

.icon-btn--active { color: var(--accent) !important; background: var(--accent-muted) !important; }
.icon-btn--sm { width: 32px; height: 32px; }

/* ═══ МОДАЛКА НАСТРОЕК (вкладки) ═══════════════════════════════════════════ */
.set-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 40px; opacity: 0; transition: opacity .2s ease;
}
.set-overlay--open { opacity: 1; }
.set-modal {
  position: relative; width: 100%; max-width: 720px; max-height: 84vh;
  background: var(--bg-sidebar); border: 1px solid var(--border);
  border-radius: 18px; display: flex; overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,0.5);
  transform: translateY(8px) scale(0.99); transition: transform .2s var(--ease-out);
}
.set-overlay--open .set-modal { transform: none; }
.set-modal__close { position: absolute; top: 14px; right: 14px; z-index: 2; }
.set-modal__nav { width: 200px; border-right: 1px solid var(--border); padding: 16px 10px; flex-shrink: 0; }
.set-modal__nav-title { font-size: var(--font-lg); font-weight: var(--fw-bold); padding: 4px 10px 14px; letter-spacing: -0.01em; }
.set-modal__nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 11px;
  border-radius: 9px; background: transparent; border: none; cursor: pointer;
  color: var(--text-secondary); font-family: var(--font-family); font-size: var(--font-base);
  text-align: left; transition: background var(--t-fast), color var(--t-fast);
}
.set-modal__nav-item svg { width: 18px; height: 18px; }
.set-modal__nav-item:hover { background: var(--bg-glass); color: var(--text-primary); }
.set-modal__nav-item--active { background: var(--accent-muted); color: var(--accent); }
.set-modal__body { flex: 1; overflow-y: auto; padding: 22px 26px; }

.set-h { font-size: var(--font-xs); font-weight: var(--fw-semibold); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); margin: 6px 0 6px; }
.set-h:not(:first-child) { margin-top: 22px; }
.set-h--danger { color: var(--danger); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border-subtle); }
.set-row--last { border-bottom: none; }
.set-row__main { min-width: 0; }
.set-row__k { font-size: var(--font-base); font-weight: var(--fw-medium); }
.set-row__v { font-size: var(--font-sm); color: var(--text-muted); margin-top: 2px; }

.set-switch { width: 42px; height: 24px; border-radius: 13px; background: var(--bg-surface-active); border: none; cursor: pointer; position: relative; transition: background .18s; flex-shrink: 0; }
.set-switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #d4d4d8; transition: transform .18s; }
.set-switch--on { background: var(--accent); }
.set-switch--on::after { transform: translateX(18px); background: #fff; }

.set-swatches { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.set-swatch { width: 34px; height: 34px; border-radius: 9px; cursor: pointer; border: 2px solid transparent; transition: transform .12s; }
.set-swatch:hover { transform: scale(1.08); }
.set-swatch--active { border-color: var(--text-primary); }

.set-acc { display: flex; align-items: center; gap: 16px; padding-bottom: 18px; border-bottom: 1px solid var(--border-subtle); margin-bottom: 6px; }
.set-acc__avatar { width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: var(--fw-semibold); color: var(--text-primary); overflow: hidden; flex-shrink: 0; }
.set-acc__name { font-size: var(--font-lg); font-weight: var(--fw-bold); }
.set-acc__handle { font-family: var(--font-mono); font-size: var(--font-sm); color: var(--text-muted); margin-top: 3px; }

.set-pill { padding: 3px 10px; border-radius: 10px; font-family: var(--font-mono); font-size: var(--font-xs); font-weight: var(--fw-medium); }
.set-pill--ok { background: var(--online); color: #06210f; }

@media (max-width: 768px) {
  .set-overlay { padding: 0; align-items: stretch; }
  .set-modal { max-width: none; max-height: none; height: 100%; border-radius: 0; border: none; flex-direction: column; }
  .set-modal__nav { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; border-right: none; border-bottom: 1px solid var(--border); padding: 14px 56px 12px 16px; }
  .set-modal__nav-title { width: 100%; padding: 4px 0 2px; }
  .set-modal__nav-item { width: auto; flex: 0 0 auto; padding: 8px 12px; font-size: var(--font-sm); white-space: nowrap; }
  .set-modal__body { padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); }
}

/* ═══ Плотность / движение ════════════════════════════════════════════════ */
#app[data-density="compact"] .chat__messages { gap: 1px; padding-top: 12px; padding-bottom: 12px; }
#app[data-density="compact"] .message__bubble { padding-top: 6px; padding-bottom: 6px; }
#app[data-density="compact"] .chat-item { padding-top: 7px; padding-bottom: 7px; }

[data-motion="reduce"] * { animation: none !important; transition: none !important; }

/* ── Split-view: второй чат рядом ───────────────────────────────────────── */
.chat-secondary {
  width: 0; min-width: 0; overflow: hidden;
  height: var(--app-height, 100vh);
  display: flex; flex-direction: column;
  flex-shrink: 0; flex-basis: 0;
  border-left: 1px solid transparent;
  background: var(--bg-chat);
  transition: flex-basis var(--t-base);
}
.chat-secondary[data-open="true"] {
  flex: 1 1 0; width: auto; min-width: 0;
  border-left-color: var(--border);
}
/* когда открыт второй чат — основной и второй делят пространство поровну */
#app[data-split="open"] .chat { flex: 1 1 0; }
.chat-secondary .chat__header--secondary { background: var(--bg-sidebar); }
.chat-secondary .chat__messages { flex: 1; overflow-y: auto; }

/* ── Мобильная нижняя навигация (скрыта на десктопе) ────────────────────── */
.mobnav { display: none; }

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

/* Слот уходит в оверлей на средних ширинах */
@media (max-width: 1180px) {
  .slot[data-open="true"] {
    position: fixed; right: 0; top: 0; bottom: 0;
    width: var(--slot-w); z-index: 60;
    box-shadow: -10px 0 40px rgba(0,0,0,0.4);
  }
  /* split не помещается на средних ширинах — прячем второй чат */
}
@media (max-width: 1024px) {
  .chat-secondary[data-open="true"] { display: none; }
}
@media (min-width: 1025px) and (max-width: 1180px) {
  .chat-secondary[data-open="true"] { display: flex; }
}

@media (max-width: 768px) {
  .rail { display: none; }
  .slot[data-open="true"] { width: 100%; min-width: 100%; }

  /* Нижняя навигация по пространствам */
  .mobnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    height: 58px; padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
    background: var(--bg-rail, #0c0c0d); border-top: 1px solid var(--border);
  }
  .mobnav__item {
    flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    background: none; border: none; cursor: pointer; color: var(--text-muted); border-radius: 10px;
    font-size: 10px; font-weight: var(--fw-medium); transition: color var(--t-fast);
  }
  .mobnav__item svg { width: 20px; height: 20px; }
  .mobnav__item--active { color: var(--accent); }
  .mobnav__badge {
    position: absolute; top: 3px; right: 50%; margin-right: -20px;
    min-width: 15px; height: 15px; padding: 0 4px; border-radius: 8px;
    background: var(--accent); color: #fff; font-family: var(--font-mono); font-size: 9px;
    display: flex; align-items: center; justify-content: center;
  }
  /* Когда открыт чат — прячем нижнюю навигацию, чат на весь экран */
  #app[data-mobile="conv"] .mobnav { display: none; }
  /* Запас снизу под навигацию в списке */
  #app:not([data-mobile="conv"]) .sidebar__chats { padding-bottom: 64px; }
}

/* ═══ ТРЕДЫ ══════════════════════════════════════════════════════════════ */
/* Бейдж «N ответов» под корневым сообщением */
.message__thread-badge {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 6px;
  padding: 4px 10px; border-radius: var(--radius-full, 999px);
  background: var(--accent-muted); border: 1px solid var(--border-accent);
  color: var(--text-accent); font-size: var(--font-xs); font-weight: var(--fw-medium);
  cursor: pointer; transition: background var(--t-fast), border-color var(--t-fast);
}
.message__thread-badge:hover { background: var(--bg-glass-hover); border-color: var(--accent); }
.message__thread-badge svg { width: 13px; height: 13px; }

/* Оверлей панели треда (выезжает справа) */
.thread-ov {
  position: fixed; inset: 0; z-index: 210;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(3px);
  opacity: 0; transition: opacity .2s ease;
  display: flex; justify-content: flex-end;
}
.thread-ov--open { opacity: 1; }
.thread-panel {
  display: flex; flex-direction: column;
  width: 460px; max-width: 100%; height: 100%;
  background: var(--bg-sidebar); border-left: 1px solid var(--border);
  box-shadow: -16px 0 50px rgba(0,0,0,0.5);
  transform: translateX(24px); transition: transform .22s var(--ease-out);
}
.thread-ov--open .thread-panel { transform: none; }
.thread-panel__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.thread-panel__title {
  display: flex; align-items: center; gap: 9px;
  font-size: var(--font-base); font-weight: var(--fw-semibold); color: var(--text-primary);
}
.thread-panel__title svg { width: 18px; height: 18px; color: var(--accent); }
.thread-panel__close {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: var(--radius-sm);
  color: var(--text-secondary); cursor: pointer; transition: background var(--t-fast);
}
.thread-panel__close:hover { background: var(--bg-glass); color: var(--text-primary); }
.thread-panel__close svg { width: 18px; height: 18px; }
.thread-panel__root {
  padding: 14px 18px; border-bottom: 1px solid var(--border-subtle); flex-shrink: 0;
}
.thread-panel__sep {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 18px; flex-shrink: 0;
  font-family: var(--font-mono); font-size: var(--font-xs); color: var(--text-muted);
}
.thread-panel__sep::after { content: ''; flex: 1; height: 1px; background: var(--border-subtle); }
.thread-panel__messages {
  flex: 1; overflow-y: auto; padding: 12px 18px;
  display: flex; flex-direction: column; gap: 2px;
}
.thread-panel__empty {
  margin: auto; text-align: center; color: var(--text-muted); font-size: var(--font-sm);
}
.thread-panel__composer {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-top: 1px solid var(--border); flex-shrink: 0;
}
.thread-panel__input {
  flex: 1; padding: 11px 14px; border-radius: var(--radius-md);
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-primary); font-family: var(--font-family); font-size: var(--font-base);
  outline: none; transition: background var(--t-fast), border-color var(--t-fast);
}
.thread-panel__input:focus { background: var(--bg-input-focus); border-color: var(--border-accent); }
.thread-panel__send {
  width: 40px; height: 40px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  background: var(--accent); border: none; border-radius: var(--radius-md);
  color: #fff; cursor: pointer; transition: background var(--t-fast);
}
.thread-panel__send:hover { background: var(--accent-hover); }
.thread-panel__send svg { width: 18px; height: 18px; }

@media (max-width: 768px) {
  .thread-panel { width: 100%; border-left: none; }
}
