/* ==========================================================================
   Kosmo — регистрация (код-пароль, профиль) и само приложение:
   чаты, лента, поиск, профиль, нижняя панель.
   Переменные --c-* и пружины берутся из styles.css.
   ========================================================================== */

/* ---------- Аватары ---------- */
.avatar {
  --a1: #82b1ff;
  --a2: #665fff;
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: linear-gradient(160deg, var(--a1), var(--a2));
  color: #fff;
  font-weight: 600;
  font-size: 20px;
  user-select: none;
}
.avatar > span { line-height: 1; }
.avatar-xl { width: 104px; height: 104px; font-size: 40px; }
.avatar-sm { width: 40px; height: 40px; font-size: 15px; }
.avatar-tab { width: 26px; height: 26px; font-size: 11px; }
.avatar.is-online::after {
  content: "";
  position: absolute;
  right: 1px; bottom: 1px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #30d158;
  border: 2.5px solid var(--bg);
}
.avatar-icon svg { width: 46%; height: 46%; }
.avatar .pop { animation: initials-pop 380ms var(--spring-bouncy); }
@keyframes initials-pop { from { transform: scale(0.5); opacity: 0; } }
/* Пустой аватар: силуэт вместо инициалов */
.avatar.is-empty { background: var(--c-field-bg); color: var(--c-text-3); }
html[data-theme="material"] .avatar.is-empty { background: var(--md-sys-color-surface-container-high); }

/* ---------- Кнопка «назад» в регистрации ---------- */
.auth .back-btn { animation: back-in 420ms var(--spring) both; }
@keyframes back-in { from { opacity: 0; transform: translateX(-12px) scale(0.8); } }

/* ---------- Код-пароль: 4 ячейки ---------- */
.pass-cells { display: flex; gap: 14px; justify-content: center; }
.pass-cell {
  position: relative;
  width: 60px; height: 70px;
  display: grid; place-items: center;
  border-radius: 20px;
  background: var(--c-cell-bg);
  border: 1px solid var(--c-cell-border);
  transition: border-color 250ms ease, box-shadow 250ms ease, background 400ms ease, scale var(--spring-bouncy-dur) var(--spring-bouncy);
}
html[data-theme="material"] .pass-cell { border-radius: 18px; }
.pass-cell.is-active { border-color: var(--c-cell-border-active); scale: 1.06; }
html[data-theme="glass"] .pass-cell.is-active { box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.07); }
html[data-theme="material"] .pass-cell.is-active { box-shadow: inset 0 0 0 1px var(--c-cell-border-active); }
/* Точка вместо цифры: «вспыхивает» при вводе */
.pass-cell::after {
  content: "";
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--c-text);
  scale: 0;
  opacity: 0;
  transition: scale 380ms var(--spring-bouncy), opacity 160ms ease;
}
html[data-theme="material"] .pass-cell::after { background: var(--md-sys-color-primary); }
.pass-cell.is-filled::after { scale: 1; opacity: 1; }
.pass-cells.is-error { animation: shake 420ms cubic-bezier(0.36, 0.07, 0.19, 0.97); }
.pass-cells.is-error .pass-cell { border-color: var(--c-error); }
.pass-cells.is-error .pass-cell::after { background: var(--c-error); }
.pass-cells.is-done .pass-cell {
  border-color: var(--c-success);
  animation: wave 600ms var(--spring-bouncy) both;
  animation-delay: calc(var(--i) * 60ms);
}
.pass-cells.is-done .pass-cell::after { background: var(--c-success); }

/* ---------- Цифровая клавиатура как на iPhone ---------- */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 80px);
  gap: 16px 26px;
  justify-content: center;
  margin-top: 44px;
}
.key {
  position: relative;
  width: 80px; height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  overflow: hidden;
  isolation: isolate;
  color: var(--c-text);
  user-select: none;
  touch-action: manipulation;
  /* отпускание: подсветка гаснет медленно, как на iOS */
  transition: background 450ms ease, border-radius 350ms var(--md-emphasized), scale var(--spring-bouncy-dur) var(--spring-bouncy);
}
.key-num { font-size: 34px; line-height: 1; font-weight: 400; font-variant-numeric: tabular-nums; }
.key-sub { font-size: 10px; line-height: 12px; font-weight: 600; letter-spacing: 0.14em; color: var(--c-text-2); }
.key-spacer { width: 80px; height: 80px; }
.key-del { background: transparent !important; color: var(--c-text-2); }
.key-del svg { width: 30px; height: 30px; stroke-width: 1.8; }
.key-del.is-hidden { opacity: 0; pointer-events: none; }
.key-del { transition: opacity 200ms ease, scale var(--spring-bouncy-dur) var(--spring-bouncy); }

html[data-theme="glass"] .key {
  background: rgba(255, 255, 255, 0.11);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
}
/* нажатие: мгновенно светлеет */
html[data-theme="glass"] .key.is-down { background: rgba(255, 255, 255, 0.36); transition: background 0ms, scale 120ms ease-out; }
html[data-theme="glass"] .key-del.is-down { scale: 0.88; }

html[data-theme="material"] .key { background: var(--md-sys-color-surface-container-high); }
html[data-theme="material"] .key-num { font-size: 32px; font-weight: 500; }
html[data-theme="material"] .key-sub { color: var(--md-sys-color-on-surface-variant); }
/* Material Expressive: круг морфится в скруглённый квадрат */
html[data-theme="material"] .key.is-down {
  border-radius: 26px;
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  transition-duration: 120ms;
}

@media (max-height: 720px) {
  .keypad { grid-template-columns: repeat(3, 70px); gap: 12px 24px; margin-top: 28px; }
  .key, .key-spacer { width: 70px; height: 70px; }
  .key-num { font-size: 30px; }
}

/* ---------- Имя, @username, описание ---------- */
.setup-form { margin-top: 28px; }
.setup-form .field { padding: 0 18px 0 22px; gap: 4px; }
.setup-form input,
.setup-form textarea {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 18px;
  caret-color: var(--c-accent);
}
.setup-form input::placeholder,
.setup-form textarea::placeholder { color: var(--c-text-3); }
.at { color: var(--c-text-2); font-size: 18px; font-weight: 500; }
.field-status { width: 24px; height: 24px; display: grid; place-items: center; }
.field-status svg { grid-area: 1 / 1; width: 20px; height: 20px; opacity: 0; scale: 0.4; transition: opacity 180ms ease, scale var(--spring-bouncy-dur) var(--spring-bouncy); }
.field-status .ok { color: var(--c-success); stroke-width: 2.4; }
.field-status .bad { color: var(--c-error); stroke-width: 2.4; }
.field.is-valid .field-status .ok,
.field.is-invalid .field-status .bad { opacity: 1; scale: 1; }

.field-area { height: auto; align-items: stretch; padding: 16px 22px 30px !important; }
html[data-theme="glass"] .field-area { border-radius: 28px; }
.field-area textarea { resize: none; height: auto; font-family: inherit; line-height: 1.4; }
.counter {
  position: absolute;
  right: 20px; bottom: 10px;
  font-size: 13px;
  color: var(--c-text-3);
  font-variant-numeric: tabular-nums;
  transition: color 200ms ease;
}
.counter.is-low { color: var(--c-error); }

.bio-name { margin: 14px 0 2px; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
html[data-theme="material"] .bio-name { font-weight: 500; letter-spacing: 0; }
.bio-username { margin: 0; color: var(--c-text-2); font-size: 16px; }

/* Уход из регистрации в приложение */
.auth.is-leaving { animation: auth-out 420ms var(--md-emphasized-accel) both; }
@keyframes auth-out { to { opacity: 0; transform: scale(1.06); filter: blur(10px); } }

/* ==========================================================================
   Приложение
   ========================================================================== */
.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overflow: clip;   /* clip не даёт браузеру «прокрутить» контейнер к полю в фокусе */
  --tabbar-space: calc(96px + env(safe-area-inset-bottom));
}
.app.is-entering .views { animation: app-in 700ms var(--spring) both; }
.app.is-entering .tabbar { animation: tabbar-in 800ms 150ms var(--spring) both; }
@keyframes app-in { from { opacity: 0; transform: scale(0.94); } }
@keyframes tabbar-in { from { opacity: 0; transform: translate(-50%, 140%) scale(0.9); } }

.views {
  position: absolute;
  inset: 0;
  transform-origin: 50% 40%;
  transition: transform var(--spring-dur) var(--spring), opacity 300ms ease;
}
.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  padding-inline: max(0px, calc((100% - 680px) / 2));
  padding-bottom: var(--tabbar-space);
}
.view::-webkit-scrollbar { display: none; }
.view.is-entering { animation: view-in 520ms var(--spring) both; }
.view.is-leaving { animation: view-out 160ms ease-in both; }
@keyframes view-in { from { opacity: 0; transform: translateY(14px) scale(0.985); } }
@keyframes view-out { to { opacity: 0; transform: scale(0.985); } }
html[data-theme="material"] .view.is-entering { animation: view-in 400ms var(--md-emphasized-decel) both; }

/* Шапка: круг «+», пилюля с названием, круг поиска.
   Под ней — затемнение, чтобы список растворялся при прокрутке */
.app-header,
.panel-header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) 16px 14px;
}
.app-header::before,
.panel-header::before {
  content: "";
  position: absolute;
  inset: 0 0 -28px;
  z-index: -1;
  background: linear-gradient(var(--page-bg) 45%, transparent);
  pointer-events: none;
}
.circle-btn {
  position: relative;
  flex: none;
  width: 48px; height: 48px;
  display: grid; place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--c-text);
  transition: scale var(--spring-bouncy-dur) var(--spring-bouncy), background 200ms ease, border-radius 350ms var(--md-emphasized);
}
.circle-btn svg { width: 22px; height: 22px; }
.circle-btn:active { scale: 0.9; }
.circle-spacer { flex: none; width: 48px; height: 48px; }
html[data-theme="material"] .circle-btn {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
html[data-theme="material"] .circle-btn:active { border-radius: 16px; scale: 1; }

.title-pill {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 600;
}
html[data-theme="material"] .title-pill {
  background: var(--md-sys-color-surface-container-high);
  font-size: 18px;
  font-weight: 500;
}

/* ---------- Список чатов ---------- */
.chat-list { list-style: none; margin: 0; padding: 0 8px 8px; }
.chat {
  position: relative;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  gap: 2px 12px;
  align-items: center;
  padding: 9px 10px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 200ms ease, scale 300ms var(--spring-bouncy);
  animation: chat-in 520ms var(--spring) both;
  animation-delay: calc(var(--i, 0) * 28ms);
}
@keyframes chat-in { from { opacity: 0; transform: translateY(16px); } }
.chat:hover { background: rgba(255, 255, 255, 0.05); }
.chat:active { background: rgba(255, 255, 255, 0.09); scale: 0.985; }
html[data-theme="glass"] .chat + .chat::before {
  content: "";
  position: absolute;
  top: 0; left: 78px; right: 10px;
  height: 0.5px;
  background: var(--c-hairline);
}
html[data-theme="material"] .chat { border-radius: 28px; }
.chat .avatar { grid-row: span 2; }
.chat-top, .chat-bottom { display: flex; align-items: center; gap: 6px; min-width: 0; }
.chat-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 600; }
.chat-name-icon { flex: none; width: 16px; height: 16px; }
.verified { color: var(--c-accent); }
.muted-icon { color: var(--c-text-3); }
.chat-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  color: var(--c-text-2);
}
.chat-text b { font-weight: 500; color: var(--c-text); }
.chat-meta { grid-row: span 2; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; align-self: stretch; justify-content: center; }
.chat-time { display: flex; align-items: center; gap: 3px; font-size: 13px; color: var(--c-text-3); font-variant-numeric: tabular-nums; }
.chat-time svg { width: 16px; height: 16px; color: var(--c-accent); stroke-width: 2.2; }
.badge {
  min-width: 22px; height: 22px;
  padding: 0 7px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: var(--c-accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.badge.is-muted { background: rgba(235, 235, 245, 0.3); }
html[data-theme="material"] .badge { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
html[data-theme="material"] .badge.is-muted { background: var(--md-sys-color-surface-container-highest); color: var(--md-sys-color-on-surface-variant); }
.pin { width: 16px; height: 16px; color: var(--c-text-3); }

/* ---------- Лента ---------- */
.feed { display: flex; flex-direction: column; gap: 14px; padding: 2px 16px 8px; }
.post {
  padding: 14px;
  border-radius: 26px;
  background: #121214;
  animation: chat-in 560ms var(--spring) both;
  animation-delay: calc(var(--i, 0) * 60ms);
}
html[data-theme="material"] .post { background: var(--md-sys-color-surface-container-low); border-radius: 28px; }
.post-head { display: flex; align-items: center; gap: 10px; }
.post-author { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 4px; }
.post-time { font-size: 13px; color: var(--c-text-3); }
.post-text { margin: 10px 2px 12px; font-size: 16px; line-height: 1.42; }
.post-art {
  aspect-ratio: 16 / 10;
  border-radius: 18px;
  background: var(--art);
  margin-bottom: 10px;
}
html[data-theme="material"] .post-art { border-radius: 20px; }
.post-actions { display: flex; align-items: center; gap: 4px; }
.post-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--c-text-2);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  transition: background 200ms ease, color 200ms ease, scale 300ms var(--spring-bouncy);
}
.post-action:active { scale: 0.92; }
.post-action svg { width: 19px; height: 19px; }
.post-action.is-liked { color: #ff375f; background: rgba(255, 55, 95, 0.14); }
.post-action.is-liked svg { fill: currentColor; animation: heart 450ms var(--spring-bouncy); }
@keyframes heart { 30% { transform: scale(1.35); } }
html[data-theme="material"] .post-action { background: var(--md-sys-color-surface-container-high); }
html[data-theme="material"] .post-action.is-liked { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
.post-views { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--c-text-3); }
.post-views svg { width: 17px; height: 17px; }

/* ---------- Профиль: аватар и имя сверху, остальное — плашками ---------- */
.profile { display: flex; flex-direction: column; gap: 14px; padding: 0 16px 8px; }
.profile-hero { display: flex; flex-direction: column; align-items: center; padding: 6px 0 10px; text-align: center; }
.hero-avatar { position: relative; width: 132px; height: 132px; display: grid; place-items: center; }
/* вращающаяся «орбита» вокруг аватара */
.hero-orbit {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #64d2ff, #7d5cff, #bf5af2, #ff375f, #64d2ff);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
  animation: orbit 8s linear infinite;
}
.hero-orbit::after {
  content: "";
  position: absolute;
  top: 6px; left: 50%;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 12px 3px rgba(191, 90, 242, 0.8);
}
html[data-theme="material"] .hero-orbit {
  background: conic-gradient(from 0deg, var(--md-sys-color-primary), var(--md-sys-color-tertiary), var(--md-sys-color-primary));
}
@keyframes orbit { to { rotate: 360deg; } }
.avatar-hero { width: 116px; height: 116px; font-size: 44px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); }
.profile-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 0;
  font-size: 30px;
  line-height: 36px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.profile-name .cosmic-badge { width: 26px; height: 26px; }
html[data-theme="material"] .profile-name { font-weight: 500; letter-spacing: 0; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
  padding: 14px 16px 16px;
  border: 0;
  border-radius: 24px;
  background: #121214;
  text-align: left;
  font: inherit;
  color: inherit;
  animation: chat-in 520ms var(--spring) both;
  transition: scale 300ms var(--spring-bouncy), background 200ms ease;
}
.tile:nth-child(2) { animation-delay: 40ms; }
.tile:nth-child(3) { animation-delay: 80ms; }
.tile:nth-child(4) { animation-delay: 120ms; }
.tile:nth-child(5) { animation-delay: 160ms; }
button.tile:active { scale: 0.97; }
button.tile:hover { background: #18181b; }
.tile-wide { grid-column: 1 / -1; }
.tile-icon {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  margin-bottom: 10px;
  border-radius: 12px;
  background: rgba(10, 132, 255, 0.16);
  color: #64b5ff;
}
.tile:nth-child(2) .tile-icon { background: rgba(48, 209, 88, 0.15); color: #4cd964; }
.tile:nth-child(3) .tile-icon { background: rgba(191, 90, 242, 0.16); color: #d68cff; }
.tile:nth-child(4) .tile-icon { background: rgba(255, 159, 10, 0.15); color: #ffb340; }
.tile:nth-child(5) .tile-icon { background: rgba(255, 55, 95, 0.15); color: #ff6b8a; }
.tile-icon svg { width: 20px; height: 20px; }
.tile-label { font-size: 13px; color: var(--c-text-2); }
.tile-value { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 600; }
.tile-wide .tile-value { white-space: normal; font-weight: 500; line-height: 1.4; }
html[data-theme="material"] .tile { background: var(--md-sys-color-surface-container); border-radius: 28px; }
html[data-theme="material"] .tile-icon,
html[data-theme="material"] .tile:nth-child(n) .tile-icon {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-radius: 14px;
}
html[data-theme="material"] .tile-value { font-weight: 500; }

.group {
  width: 100%;
  border-radius: 26px;
  background: #121214;
  overflow: hidden;
  text-align: left;
}
html[data-theme="material"] .group { background: var(--md-sys-color-surface-container); border-radius: 28px; }
.group-row { display: flex; align-items: center; gap: 14px; min-height: 56px; padding: 0 16px; }
.group-row-col { flex-direction: column; align-items: stretch; gap: 12px; padding: 16px; }
.group-label { font-size: 13px; font-weight: 600; color: var(--c-text-2); padding-left: 4px; }
.group-row .seg { min-width: 0; }
.group-row-btn { width: 100%; border: 0; background: none; font-size: 17px; text-align: left; transition: background 200ms ease; }
.group-row-btn:active { background: rgba(255, 255, 255, 0.06); }
html[data-theme="glass"] .group-row-btn + .group-row-btn { box-shadow: inset 0 0.5px 0 var(--c-hairline); }
.row-icon {
  width: 32px; height: 32px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
}
.row-icon svg { width: 19px; height: 19px; }
html[data-theme="material"] .row-icon { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); border-radius: 50%; }
.row-text { flex: 1; }
.row-value { color: var(--c-text-2); font-variant-numeric: tabular-nums; }
.chev-right { width: 18px; height: 18px; color: var(--c-text-3); }
.danger { color: var(--c-error); }
.danger .row-icon { background: rgba(255, 69, 58, 0.14); }
html[data-theme="material"] .danger .row-icon { background: rgba(242, 184, 181, 0.14); color: var(--c-error); }
.palette-inline { margin-top: 0; }

/* ---------- Нижняя панель ---------- */
.tabbar {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  width: min(440px, calc(100% - 28px));
  height: 66px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 4px;
  border-radius: 999px;
  transform: translateX(-50%);
  transition: transform var(--spring-dur) var(--spring), opacity 250ms ease;
}
/* панель над списком: тинт плотнее, чтобы текст под ней не читался */
html[data-theme="glass"] .tabbar { background: rgba(28, 28, 30, 0.64); }
html[data-theme="glass"] .tabbar { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 10px 40px rgba(0, 0, 0, 0.5); }
html[data-theme="material"] .tabbar { background: var(--md-sys-color-surface-container); height: 72px; padding: 6px; }

.tab {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--c-text-2);
  transition: color 250ms ease, scale 300ms var(--spring-bouncy);
}
.tab:active { scale: 0.92; }
.tab-icon { position: relative; display: grid; place-items: center; width: 26px; height: 26px; }
.tab-icon svg { width: 25px; height: 25px; }
.tab-label { font-size: 11px; font-weight: 600; letter-spacing: 0.01em; }
.tab.is-active { color: var(--c-accent); }
.tab.is-active .tab-icon svg { fill: currentColor; fill-opacity: 0.18; }
.tab-badge {
  position: absolute;
  top: 4px; left: calc(50% + 6px);
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ff3b30;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
html[data-theme="material"] .tab-badge { background: var(--md-sys-color-error); color: #601410; top: 6px; }

/* Glass: светлый «бегунок» перетекает к выбранной вкладке и чуть растягивается в пути */
.tab-thumb {
  position: absolute;
  top: 4px; bottom: 4px; left: 4px;
  width: calc((100% - 8px) / 4);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
  transform: translateX(calc(var(--tab-i, 0) * 100%));
  transition: transform var(--spring-bouncy-dur) var(--spring-bouncy), scale 220ms ease;
}
.tabbar.is-moving .tab-thumb { scale: 1.12 0.9; }

/* Material: индикатор-пилюля за иконкой выбранной вкладки (M3 navigation bar) */
html[data-theme="material"] .tab-thumb {
  top: 6px; bottom: 6px; left: 6px;
  width: calc((100% - 12px) / 4);
  background: var(--md-sys-color-secondary-container);
  box-shadow: none;
  transition: transform 450ms var(--md-emphasized), scale 220ms ease;
}
html[data-theme="material"] .tab { color: var(--md-sys-color-on-surface-variant); gap: 4px; }
html[data-theme="material"] .tab.is-active { color: var(--md-sys-color-on-secondary-container); }
html[data-theme="material"] .tab-label { font-size: 12px; font-weight: 500; }
html[data-theme="material"] .tab.is-active .tab-label { font-weight: 700; }
.tab.is-active .avatar-tab { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px currentColor; }

/* ---------- Боковые панели (поиск, чат, сессии, смена номера) ---------- */
.panel {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  scrollbar-width: none;
  padding-inline: max(0px, calc((100% - 680px) / 2));
  background: var(--page-bg);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform var(--spring-dur) var(--spring), visibility 0s linear var(--spring-dur);
  box-shadow: -30px 0 60px rgba(0, 0, 0, 0.6);
}
html[data-theme="material"] .panel { transition: transform 450ms var(--md-emphasized), visibility 0s linear 450ms; }
.panel::-webkit-scrollbar { display: none; }
html[data-theme] .panel.is-open { transform: none; visibility: visible; transition-delay: 0s; }
/* основной экран уезжает влево и гаснет, нижняя панель опускается */
.app.has-panel .views { transform: translateX(-22%) scale(0.94); opacity: 0; }
.app.has-panel .tabbar { transform: translate(-50%, 150%) scale(0.9); opacity: 0; pointer-events: none; }
html[data-theme="material"] .app.has-panel .views { transition: transform 450ms var(--md-emphasized), opacity 250ms ease; }
.panel-body { flex: 1; padding: 4px 16px 40px; }

.search-pill {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  border-radius: 999px;
  color: var(--c-text-2);
  cursor: text;
}
.search-pill svg { width: 20px; height: 20px; flex: none; }
.search-pill input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; font-size: 17px; color: var(--c-text); caret-color: var(--c-accent); }
.search-pill input::placeholder { color: var(--c-text-3); }
.search-pill input::-webkit-search-cancel-button { display: none; }
html[data-theme="material"] .search-pill { background: var(--md-sys-color-surface-container-high); height: 56px; color: var(--md-sys-color-on-surface-variant); }

.section-label { margin: 14px 6px 8px; font-size: 13px; font-weight: 600; color: var(--c-text-2); text-align: left; }
.panel-body .chat-list { padding: 0; }
.panel mark { background: none; color: var(--c-accent); font-weight: 600; }
.search-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 64px 16px; color: var(--c-text-3); animation: chat-in 400ms var(--spring) both; }
.search-empty svg { width: 44px; height: 44px; stroke-width: 1.6; }

/* ---------- Меню «+» ---------- */
.menu {
  position: absolute;
  z-index: 6;
  top: calc(max(14px, env(safe-area-inset-top)) + 56px);
  left: max(16px, calc((100% - 680px) / 2 + 16px));
  min-width: 230px;
  padding: 6px;
  border-radius: 26px;
  transform-origin: 24px 0;
  animation: menu-in 420ms var(--spring-bouncy) both;
}
.menu.is-closing { animation: menu-out 160ms ease-in both; }
@keyframes menu-in { from { opacity: 0; transform: scale(0.4); } }
@keyframes menu-out { to { opacity: 0; transform: scale(0.7); } }
html[data-theme="glass"] .menu { background: var(--c-sheet-bg); }
html[data-theme="glass"] .menu { box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55); }
html[data-theme="material"] .menu { background: var(--md-sys-color-surface-container); border-radius: 18px; padding: 8px 0; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 18px;
  background: none;
  font-size: 16px;
  text-align: left;
  transition: background 150ms ease;
}
.menu-item:hover { background: rgba(255, 255, 255, 0.08); }
.menu-item svg { width: 21px; height: 21px; }
html[data-theme="material"] .menu-item { border-radius: 0; padding: 0 16px; }

/* ---------- Ripple-хосты (Material) ---------- */
.ripple-host { position: relative; overflow: hidden; isolation: isolate; }

/* ---------- Градиенты-спрайт и «космические» галочки ---------- */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.cosmic-badge { flex: none; width: 19px; height: 19px; overflow: visible; filter: drop-shadow(0 0 6px rgba(125, 92, 255, 0.55)); }
.cosmic-owner { filter: drop-shadow(0 0 6px rgba(255, 159, 10, 0.55)); }
.name-with-badge { display: inline-flex; align-items: center; gap: 5px; min-width: 0; }

/* Аватар Kosmo: планета на звёздном небе */
.avatar-kosmo {
  background: radial-gradient(circle at 30% 20%, #2b1d5c, #0b0a1a 72%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.avatar-kosmo svg { width: 100%; height: 100%; }
.avatar-head { width: 48px; height: 48px; }
.chat-head-avatar { flex: none; width: 48px; height: 48px; }

/* Пилюля с двумя строками: имя и подпись */
.title-pill-2 { display: flex; flex-direction: column; justify-content: center; gap: 0; line-height: 1.15; }
.pill-title { display: inline-flex; font-size: 16px; font-weight: 600; }
.pill-title .cosmic-badge { width: 17px; height: 17px; }
.pill-sub { font-size: 12px; font-weight: 500; color: var(--c-text-2); }

/* ---------- Чат Kosmo ---------- */
.messages { flex: 1; display: flex; flex-direction: column; gap: 6px; padding: 4px 12px 110px; }
.day-chip {
  align-self: center;
  margin: 6px 0 2px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-2);
}
html[data-theme="material"] .day-chip { background: var(--md-sys-color-surface-container-high); }
.msg {
  position: relative;
  align-self: flex-start;
  max-width: min(420px, 92%);
  padding: 14px 16px 26px;
  border-radius: 22px 22px 22px 8px;
  background: #1c1c1e;
  text-align: left;
}
.msg.is-new { animation: msg-in 560ms var(--spring-bouncy) both; transform-origin: 0 100%; }
@keyframes msg-in { from { opacity: 0; transform: translateY(20px) scale(0.92); } }
html[data-theme="material"] .msg { background: var(--md-sys-color-surface-container-high); border-radius: 24px 24px 24px 8px; }
.msg-title { margin: 0 0 4px; font-size: 16px; font-weight: 700; }
html[data-theme="material"] .msg-title { font-weight: 600; }
.msg-text { margin: 0 0 12px; font-size: 15px; line-height: 1.4; color: var(--c-text-2); }
.msg-text b { color: var(--c-text); font-weight: 600; }
.msg-rows { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 14px; background: rgba(255, 255, 255, 0.05); }
html[data-theme="material"] .msg-rows { background: var(--md-sys-color-surface-container-highest); }
.msg-row { display: grid; grid-template-columns: 20px auto 1fr; align-items: center; gap: 8px; min-height: 30px; font-size: 14px; }
.msg-row svg { width: 18px; height: 18px; color: var(--c-accent); }
.msg-label { color: var(--c-text-2); }
.msg-value { text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.msg-time { position: absolute; right: 14px; bottom: 7px; font-size: 11px; color: var(--c-text-3); }
.msg-btn { width: 100%; height: 46px; margin-top: 12px; font-size: 16px; }
.msg-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(48, 209, 88, 0.14);
  color: #4cd964;
  font-size: 13px;
  font-weight: 600;
}
.msg-chip svg { width: 16px; height: 16px; }
.msg-chip.is-muted { background: rgba(255, 255, 255, 0.07); color: var(--c-text-2); }
html[data-theme="material"] .msg-chip { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
html[data-theme="material"] .msg-chip.is-muted { background: var(--md-sys-color-surface-container-highest); color: var(--md-sys-color-on-surface-variant); }

.btn-danger { background: rgba(255, 69, 58, 0.16); color: #ff6961; }
html[data-theme="material"] .btn-danger { background: var(--md-sys-color-error); color: #601410; }

/* Поле ввода в чате Kosmo — только для чтения */
.composer-ro {
  position: fixed;
  z-index: 2;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  width: min(440px, calc(100% - 28px));
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  transform: translateX(-50%);
  color: var(--c-text-2);
  font-size: 14px;
}
html[data-theme="glass"] .composer-ro { background: rgba(28, 28, 30, 0.64); }
html[data-theme="material"] .composer-ro { background: var(--md-sys-color-surface-container-high); }
.composer-ro svg { width: 18px; height: 18px; }

/* ---------- Сессии ---------- */
.sess-card {
  display: flex;
  gap: 14px;
  padding: 16px;
  margin-bottom: 10px;
  border-radius: 24px;
  background: #121214;
  text-align: left;
  animation: chat-in 480ms var(--spring) both;
  transition: opacity 240ms ease, transform 240ms ease;
}
.sess-card.is-removing { opacity: 0; transform: translateX(40px) scale(0.96); }
html[data-theme="material"] .sess-card { background: var(--md-sys-color-surface-container); border-radius: 28px; }
.sess-icon {
  flex: none;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 14px;
  background: rgba(10, 132, 255, 0.16);
  color: #64b5ff;
}
.sess-icon svg { width: 24px; height: 24px; }
html[data-theme="material"] .sess-icon { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); border-radius: 50%; }
.sess-info { flex: 1; min-width: 0; }
.sess-name { margin: 2px 0 4px; font-size: 16px; font-weight: 600; }
.sess-meta { display: flex; align-items: center; gap: 6px; margin: 0 0 2px; font-size: 14px; color: var(--c-text-2); overflow-wrap: anywhere; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: #30d158; box-shadow: 0 0 0 3px rgba(48, 209, 88, 0.2); }
.chips, .sess-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-2);
}
.chip svg { width: 14px; height: 14px; }
.chip-trusted { background: rgba(48, 209, 88, 0.14); color: #4cd964; }
html[data-theme="material"] .chip { background: var(--md-sys-color-surface-container-highest); color: var(--md-sys-color-on-surface-variant); }
html[data-theme="material"] .chip-trusted { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  font-size: 14px;
  font-weight: 600;
  transition: scale 300ms var(--spring-bouncy), background 200ms ease;
}
.chip-btn:active { scale: 0.94; }
.chip-btn svg { width: 16px; height: 16px; }
.chip-btn.danger { background: rgba(255, 69, 58, 0.14); }
html[data-theme="material"] .chip-btn { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
html[data-theme="material"] .chip-btn.danger { background: rgba(242, 184, 181, 0.16); color: var(--c-error); }
.note {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--c-text-2);
  font-size: 14px;
  line-height: 1.4;
  text-align: left;
}
.note svg { flex: none; width: 20px; height: 20px; }
html[data-theme="material"] .note { background: var(--md-sys-color-surface-container); }
#sessions .btn { width: 100%; margin-top: 6px; }

/* ---------- Смена номера ---------- */
.steps { display: flex; flex-direction: column; }
.step { display: flex; flex-direction: column; align-items: center; gap: 14px; padding-top: 24px; text-align: center; }
.step.step-in { animation: step-in 480ms var(--spring) both; }
@keyframes step-in { from { opacity: 0; transform: translateX(36px); } }
html[data-theme="material"] .step.step-in { animation: step-in 420ms var(--md-emphasized-decel) both; }
.step .btn, .step .field { width: 100%; }
.step-icon {
  width: 84px; height: 84px;
  display: grid; place-items: center;
  border-radius: 28px;
  background: rgba(10, 132, 255, 0.16);
  color: #64b5ff;
}
.step-icon svg { width: 40px; height: 40px; stroke-width: 1.8; }
.step-icon-ok { background: rgba(48, 209, 88, 0.16); color: #4cd964; border-radius: 50%; }
.step-icon-ok .draw { stroke-dasharray: 1; stroke-dashoffset: 1; stroke-width: 2.6; }
.step-in .step-icon-ok { animation: pop-in 520ms var(--spring-bouncy) both; }
.step-in .draw { animation: draw 500ms 220ms ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes pop-in { from { transform: scale(0.4); opacity: 0; } }
html[data-theme="material"] .step-icon { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
.step-title { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
html[data-theme="material"] .step-title { font-weight: 500; letter-spacing: 0; }
.step-value { margin: -6px 0 6px; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--c-accent); }
.step-text { margin: 0 0 8px; max-width: 340px; font-size: 15px; line-height: 1.45; color: var(--c-text-2); }
.step .otp { margin-top: 8px; }
