/* Каркас приложения: две панели на компьютере, отдельные экраны на телефоне. */

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ==================================================================
   Экран входа
   ================================================================== */
.auth {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
  padding-bottom: calc(24px + var(--safe-bottom));
  overflow-y: auto;
  background:
    radial-gradient(900px 520px at 50% -12%, rgba(108, 92, 231, 0.16), transparent 70%),
    var(--bg);
}

.auth__card {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 22px;
  animation: slide-up var(--slow) var(--ease);
}

.auth__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-bottom: 6px;
}

.auth__mark {
  width: 76px;
  height: 76px;
}

.auth__wordmark {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 10px;
  text-indent: 10px;
  line-height: 1;
}

.auth__tagline {
  font-size: 11px;
  letter-spacing: 4.5px;
  text-indent: 4.5px;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 500;
}

.auth__lead {
  text-align: center;
  color: var(--text-dim);
  font-size: 14.5px;
  line-height: 1.55;
  margin-top: 6px;
}

.auth__form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px;
  border-radius: var(--r-xl);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.auth__switch {
  text-align: center;
  font-size: 14px;
  color: var(--text-dim);
}

.auth__error {
  padding: 11px 14px;
  border-radius: var(--r-md);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px;
  line-height: 1.45;
}

.auth__inviter {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  border-radius: var(--r-md);
  background: var(--accent-tint);
  font-size: 14px;
}

/* ==================================================================
   Каркас мессенджера
   ================================================================== */
.shell {
  display: flex;
  flex: 1;
  min-height: 0;
  background: var(--bg);
}

/* --- Боковая панель --- */
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
}

.sidebar__top {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--header-h);
  padding: 0 10px 0 16px;
  flex: none;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 3.4px;
  text-indent: 3.4px;
  /* Это кнопка возврата к списку чатов, а сам знак занимает всего 25 px по
     высоте. Отступы поднимают область нажатия до пальцевой, не сдвигая
     при этом сам логотип. */
  min-height: 44px;
  padding: 0 8px;
  margin-left: -8px;
  border-radius: var(--r-md);
  transition: background var(--fast) var(--ease);
}

.sidebar__brand:hover {
  background: var(--surface-2);
}

.sidebar__brand svg {
  width: 24px;
  height: 24px;
}

.sidebar__search {
  padding: 2px 12px 10px;
  flex: none;
}

.sidebar__list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 12px;
}

.sidebar__footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--border-soft);
  flex: none;
  padding-bottom: calc(10px + var(--safe-bottom));
}

.sidebar__me {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 5px 7px;
  border-radius: var(--r-md);
  text-align: left;
  transition: background var(--fast) var(--ease);
}

.sidebar__me:hover {
  background: var(--surface-2);
}

/* --- Главная область --- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background:
    radial-gradient(760px 420px at 78% -8%, rgba(108, 92, 231, 0.07), transparent 68%),
    var(--bg);
  padding-right: var(--safe-right);
}

/* ==================================================================
   Мобильная раскладка
   ================================================================== */
.tabbar {
  display: none;
  flex: none;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.tabbar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-faint);
  transition: color var(--fast) var(--ease);
  position: relative;
}

.tabbar__item[aria-selected="true"] {
  color: var(--accent-soft);
}

.tabbar__item .icon {
  width: 22px;
  height: 22px;
}

.tabbar__badge {
  position: absolute;
  top: 6px;
  left: 50%;
  margin-left: 4px;
  min-width: 17px;
  height: 17px;
  font-size: 10.5px;
  padding: 0 4px;
}

@media (max-width: 900px) {
  /* На телефоне список и диалог — разные экраны. Класс на .shell
     переключает, какой из них виден: так работает кнопка «Назад». */
  .shell {
    position: relative;
  }

  .sidebar {
    width: 100%;
    border-right: none;
  }

  .main {
    position: absolute;
    inset: 0;
    z-index: 5;
    transform: translateX(100%);
    transition: transform var(--slow) var(--ease);
    background: var(--bg);
    padding-top: var(--safe-top);
  }

  .shell--conversation .main {
    transform: translateX(0);
  }

  #app.app--chat-open > .tabbar {
    display: none;
  }

  .tabbar {
    display: flex;
  }

  .sidebar__footer {
    display: none;
  }

  /* Цели для пальца заметно крупнее, чем под мышью. */
  .icon-btn {
    width: 44px;
    height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .main {
    transition: none;
  }
}

/* Планшет: панель уже, но раскладка остаётся двухпанельной. */
@media (min-width: 901px) and (max-width: 1180px) {
  :root {
    --sidebar-w: 310px;
  }
}

/* ==================================================================
   Экраны настроек, приглашений и панели владельца
   ================================================================== */
.page {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 0 40px;
}

.page__header {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-soft);
}

.page__title {
  font-size: 17px;
  font-weight: 650;
}

.page__body {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.page__section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

/* На широком экране узкая колонка посередине смотрится потерянно: справа и
   слева остаются огромные пустые поля. Раскладываем разделы в две колонки —
   страница перестаёт быть бесконечной простынёй, и почти всё видно сразу.
   Первый раздел (профиль) занимает всю ширину: он главный на странице. */
@media (min-width: 1240px) {
  .page__body {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 22px 24px;
  }

  .page__body > .page__section:first-child,
  .page__body > .page__section--full {
    grid-column: 1 / -1;
  }
}

/* Карточка статистики в панели владельца */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.stat {
  padding: 14px 16px;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat__value {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.4px;
}

.stat__label {
  font-size: 12.5px;
  color: var(--text-dim);
}

.meter {
  height: 7px;
  border-radius: var(--r-full);
  background: var(--surface-4);
  overflow: hidden;
  margin-top: 8px;
}

.meter__fill {
  height: 100%;
  border-radius: var(--r-full);
  background: var(--gradient);
  transition: width var(--slow) var(--ease);
}

.meter__fill--warn {
  background: var(--warning);
}

.meter__fill--danger {
  background: var(--danger);
}

/* Согласованные палитры в настройках */
.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(156px, 1fr));
  gap: 9px;
}

.swatch {
  min-width: 0;
  min-height: 58px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  transition: border-color var(--fast) var(--ease), background-color var(--fast) var(--ease), transform var(--fast) var(--ease);
}

.swatch:hover {
  transform: translateY(-1px);
  background: var(--surface-3);
}

.swatch[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-tint);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
}

.swatch__preview {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--swatch-a), var(--swatch-b));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.14), 0 4px 12px rgba(0,0,0,.18);
}

.swatch__copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.swatch__title {
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.swatch__subtitle {
  color: var(--text-faint);
  font-size: 11px;
}

.profile-save-state {
  display: block;
  min-height: 20px;
  margin-top: 9px;
  padding-inline: 2px;
  color: var(--text-faint);
  font-size: 12px;
  transition: color var(--fast) var(--ease), opacity var(--fast) var(--ease);
}
.profile-save-state[data-state="saving"],
.profile-save-state[data-state="pending"] { color: var(--text-dim); }
.profile-save-state[data-state="saved"] { color: var(--success); }
.profile-save-state[data-state="error"] { color: var(--danger); }



@media (max-width: 900px) {
  /* Контакты, приглашения и профиль уже представлены вкладками снизу.
     Дублирующая стрелка в шапке только съедает место и путает навигацию. */
  .page__header > .icon-btn:first-child {
    display: none;
  }
}
