/* Minimal always-on reset — keep tiny for first paint */
*, *::before, *::after { box-sizing: border-box; }
:root {
  --xam-font: Comfortaa, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
html, body, #app {
  margin: 0;
  height: 100%;
  font-family: var(--xam-font);
  font-size: 16px;
  line-height: 1.4;
  font-weight: 400;
  color: inherit;
  background: inherit;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
@media (hover: none) and (pointer: coarse) {
  html, body, #app {
    touch-action: manipulation;
    -ms-touch-action: manipulation;
  }
}
html[data-theme="dark"] {
  color: #fff;
  background: #0a0a0a;
}
html[data-theme="light"] {
  color: #1a1a1a;
  background: #c5d4a0;
}
button, input, textarea, a, summary, label {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
button {
  cursor: pointer;
  outline: none;
  transition: transform 0.12s ease, filter 0.12s ease, opacity 0.12s ease;
}
button:active:not(:disabled) {
  transform: scale(0.96);
  filter: brightness(0.94);
}
button:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
  outline: none;
}
@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
  button:active:not(:disabled) { transform: none; filter: none; }
}
#app { height: 100%; min-height: 100%; }

/* Bottom frosted toast */
#xam-notice-host {
  position: fixed;
  inset: 0;
  z-index: 100000;
  pointer-events: none;
}

.xam-toast {
  position: fixed;
  left: 50%;
  bottom: max(1.15rem, calc(env(safe-area-inset-bottom, 0px) + 0.75rem));
  transform: translate(-50%, calc(100% + 1.5rem));
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: min(22.5rem, calc(100vw - 1.75rem));
  padding: 0.7rem 1.15rem 0.7rem 0.7rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: #1a1a1a;
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.55);
  opacity: 0;
  pointer-events: auto;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease;
}

.xam-toast--show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.xam-toast--show:active {
  transform: translate(-50%, 0) scale(0.97);
}

html.xam-auth-on[data-auth-theme="dark"] .xam-toast,
html[data-theme="dark"] .xam-toast,
html.xam-auth-on[data-auth-theme="dark"] body .xam-toast {
  background: rgba(42, 42, 48, 0.86);
  color: #f3f3f5;
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.xam-toast-timer {
  --toast-progress: 1;
  position: relative;
  width: 2rem;
  height: 2rem;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
}

.xam-toast-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.xam-toast-ring-bg {
  stroke: rgba(126, 108, 210, 0.22);
  stroke-width: 2.5;
}

.xam-toast-ring-fg {
  stroke: #7E6CD2;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 94.2;
  stroke-dashoffset: calc(94.2 * (1 - var(--toast-progress)));
  transition: stroke-dashoffset 0.08s linear;
}

.xam-toast--error .xam-toast-ring-fg { stroke: #e57373; }
.xam-toast--error .xam-toast-ring-bg { stroke: rgba(229, 115, 115, 0.25); }
.xam-toast--error .xam-toast-count { color: #e57373; }

.xam-toast--info .xam-toast-ring-fg { stroke: #8774E1; }
.xam-toast--info .xam-toast-ring-bg { stroke: rgba(135, 116, 225, 0.22); }
.xam-toast--info .xam-toast-count { color: #8774E1; }

.xam-toast-count {
  position: relative;
  z-index: 1;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  color: #7E6CD2;
  font-variant-numeric: tabular-nums;
}

.xam-toast-text {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* One UI–like confirm sheet */
html.xam-confirm-open {
  overflow: hidden;
}

.xam-confirm {
  position: fixed;
  inset: 0;
  z-index: 100010;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.xam-confirm--show {
  pointer-events: auto;
}

.xam-confirm-backdrop {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.28s ease;
  -webkit-tap-highlight-color: transparent;
}

.xam-confirm--show .xam-confirm-backdrop {
  opacity: 1;
}

.xam-confirm-sheet {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-height: min(78vh, 36rem);
  margin: 0 auto;
  width: min(28rem, 100%);
  padding: 0.35rem 0 0;
  border-radius: 1.55rem 1.55rem 0 0;
  background: rgba(255, 255, 255, 0.94);
  color: #1a1a1a;
  backdrop-filter: blur(22px) saturate(1.25);
  -webkit-backdrop-filter: blur(22px) saturate(1.25);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.18);
  transform: translateY(108%);
  transition: transform 0.36s cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
}

.xam-confirm--show .xam-confirm-sheet {
  transform: translateY(0);
}

html[data-theme="dark"] .xam-confirm-sheet {
  background: rgba(36, 36, 40, 0.94);
  color: #f2f2f4;
  box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.5);
}

.xam-confirm-handle {
  width: 2.4rem;
  height: 0.28rem;
  margin: 0.45rem auto 0.55rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.16);
  flex: 0 0 auto;
}

html[data-theme="dark"] .xam-confirm-handle {
  background: rgba(255, 255, 255, 0.22);
}

.xam-confirm-head {
  flex: 0 0 auto;
  padding: 0.15rem 1.25rem 0.75rem;
}

.xam-confirm-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.xam-confirm-msg {
  margin: 0.4rem 0 0;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.35;
  color: rgba(0, 0, 0, 0.55);
}

html[data-theme="dark"] .xam-confirm-msg {
  color: rgba(255, 255, 255, 0.58);
}

.xam-confirm-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.15rem 0.75rem 0.85rem;
  overscroll-behavior: contain;
}

.xam-confirm-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.65rem;
  border-radius: 1rem;
}

.xam-confirm-item + .xam-confirm-item {
  margin-top: 0.15rem;
}

.xam-confirm-item-avatar {
  flex: 0 0 auto;
  width: 2.55rem;
  height: 2.55rem;
}

.xam-confirm-item-avatar .avatar,
.xam-confirm-item-avatar .avatar-wrap {
  width: 2.55rem !important;
  height: 2.55rem !important;
  font-size: 0.85rem !important;
}

.xam-confirm-item-meta {
  min-width: 0;
  flex: 1;
}

.xam-confirm-item-title {
  font-size: 0.95rem;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.xam-confirm-item-sub {
  margin-top: 0.15rem;
  font-size: 0.78rem;
  font-weight: 550;
  color: rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

html[data-theme="dark"] .xam-confirm-item-sub {
  color: rgba(255, 255, 255, 0.52);
}

.xam-confirm-item.is-danger .xam-confirm-item-sub {
  color: #e53935;
}

html[data-theme="dark"] .xam-confirm-item.is-danger .xam-confirm-item-sub {
  color: #ff6b6b;
}

.xam-confirm-actions {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  padding: 0.65rem 1rem max(0.85rem, env(safe-area-inset-bottom, 0px));
  background: inherit;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  position: sticky;
  bottom: 0;
  z-index: 2;
}

html[data-theme="dark"] .xam-confirm-actions {
  border-top-color: rgba(255, 255, 255, 0.08);
}

.xam-confirm-btn {
  min-height: 2.85rem;
  margin: 0;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 999px;
  font: inherit;
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.xam-confirm-btn:active {
  transform: scale(0.97);
}

.xam-confirm-btn--no {
  background: rgba(0, 0, 0, 0.06);
  color: inherit;
}

html[data-theme="dark"] .xam-confirm-btn--no {
  background: rgba(255, 255, 255, 0.1);
}

.xam-confirm-btn--yes {
  background: var(--ms-primary, #8774E1);
  color: #fff;
}

.xam-confirm-btn--yes.is-danger {
  background: #e53935;
}

html[data-theme="dark"] .xam-confirm-btn--yes.is-danger {
  background: #ff5252;
}

/* PWA install banner */
.xam-pwa {
  position: fixed;
  left: 50%;
  bottom: max(1rem, calc(env(safe-area-inset-bottom, 0px) + 0.65rem));
  z-index: 99990;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: 0.35rem 0.75rem;
  align-items: center;
  width: min(22.5rem, calc(100vw - 1.5rem));
  padding: 0.85rem 0.9rem;
  border-radius: 1.35rem;
  background: rgba(255, 255, 255, 0.9);
  color: #1a1a1a;
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  transform: translate(-50%, calc(100% + 1.75rem));
  opacity: 0;
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.24s ease;
  pointer-events: auto;
}
.xam-pwa--show {
  transform: translate(-50%, 0);
  opacity: 1;
}
html[data-theme="dark"] .xam-pwa,
html.xam-auth-on[data-auth-theme="dark"] .xam-pwa {
  background: rgba(42, 42, 48, 0.9);
  color: #f3f3f5;
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
}
.xam-pwa-icon {
  grid-row: 1 / span 2;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.85rem;
  object-fit: cover;
  align-self: start;
}
.xam-pwa-body { min-width: 0; }
.xam-pwa-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  line-height: 1.25;
}
.xam-pwa-sub,
.xam-pwa-tip {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  line-height: 1.35;
  opacity: 0.72;
}
.xam-pwa-tip b { font-weight: 650; opacity: 1; }
.xam-pwa-actions {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.15rem;
}
.xam-pwa-btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.42rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
}
.xam-pwa-btn--primary {
  background: #8774E1;
  color: #fff;
}
.xam-pwa-btn--ghost {
  background: transparent;
  color: inherit;
  opacity: 0.7;
}
.xam-pwa-btn--ghost:hover { opacity: 1; }

/* —— Zoom-through: messenger ↔ add-account —— */
.xam-zoom-portal {
  position: fixed;
  inset: 0;
  z-index: 80000;
  display: block;
  overflow: hidden;
  transform: scale(1);
  opacity: 1;
  transform-origin: 50% 42%;
  will-change: transform, opacity;
  /* Block clicks from falling through to auth (ghost tap → «Назад») */
  pointer-events: auto;
  touch-action: none;
  transition:
    transform 0.58s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.48s cubic-bezier(0.33, 0, 0.2, 1);
}

.xam-zoom-portal > .shell {
  height: 100%;
  min-height: 100%;
}

.xam-zoom-portal > .auth-host,
.xam-zoom-portal > .auth-wallpaper {
  min-height: 100%;
}

html.xam-zoom-busy #app,
html.xam-add-account-arming #app {
  pointer-events: none;
}

.xam-zoom-portal.is-leave-fwd {
  transform: scale(1.48);
  opacity: 0;
}

.xam-zoom-portal.is-leave-back {
  transform: scale(0.86);
  opacity: 0;
}

.xam-zoom-portal .shell,
.xam-zoom-portal .auth-host,
.xam-zoom-portal .auth-wallpaper {
  pointer-events: none;
}

/* Messenger arriving from behind the shrinking auth — no blur (blur ghosts as stacked panels) */
.shell.xam-zoom-enter {
  transform: scale(1.28);
  opacity: 0;
  transform-origin: 50% 42%;
  will-change: transform, opacity;
  pointer-events: none;
}

.shell.xam-zoom-enter.xam-zoom-enter-active {
  transform: scale(1);
  opacity: 1;
  transition:
    transform 0.58s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.5s cubic-bezier(0.33, 0, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
  .xam-zoom-portal,
  .shell.xam-zoom-enter,
  .shell.xam-zoom-enter.xam-zoom-enter-active {
    transition: none !important;
  }
}

/* ——— System UI font: Roboto (Telegram Android look), self-hosted ———
 * Roboto © The Roboto Project Authors, SIL Open Font License 1.1 (/assets/fonts/roboto/OFL.txt), via @fontsource/roboto 5.
 * Only 400 + 500, latin + cyrillic; 500 file also serves 600–900 so headings stay Medium (no faux bold). */
@font-face { font-family: "XamRoboto"; font-style: normal; font-display: swap; font-weight: 100 499; src: url(/assets/fonts/roboto/roboto-cyrillic-400-normal.woff2) format("woff2"); unicode-range: U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116; }
@font-face { font-family: "XamRoboto"; font-style: normal; font-display: swap; font-weight: 100 499; src: url(/assets/fonts/roboto/roboto-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "XamRoboto"; font-style: normal; font-display: swap; font-weight: 500 900; src: url(/assets/fonts/roboto/roboto-cyrillic-500-normal.woff2) format("woff2"); unicode-range: U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116; }
@font-face { font-family: "XamRoboto"; font-style: normal; font-display: swap; font-weight: 500 900; src: url(/assets/fonts/roboto/roboto-latin-500-normal.woff2) format("woff2"); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
:root {
  --xam-text-font: Comfortaa, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --xam-ui-font: "XamRoboto", Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  --xam-font: var(--xam-ui-font);
}
html, body, #app { font-family: var(--xam-ui-font); }
input, textarea, select, button { font-family: inherit; }
/* Content stays in the original font: message text, sender/chat names, nicks, composer */
.message-text, .message-sender-name, .message-reply, .message-reply__text, .message-mention,
.chat-name, .chat-preview, .chat-top-title, .search-hit-name, .search-hit-sub,
.side-drawer-name, .stories-name, .stories-caption, .chat-profile-nick, .xp-name, .xp-name-text, .xp-bar-name,
.xam-call-title, .xam-call-tile-name, .reply-preview-text, .pinned-messages-bar-text,
.st-preview-name, .st-preview-text, .st-hero-meta strong, .st-hero-meta > span:not(.st-hero-mail),
.st-account .st-row-title, .st-account .st-row-sub, .profile-thought-bubble,
#composer-input, .composer-field, .xam-rich-input {
  --xam-font: var(--xam-text-font);
  font-family: var(--xam-text-font) !important;
}

/* t103: свои скроллбары везде — тонкие (4px), без стрелок, прозрачная дорожка,
   ползунок появляется только при наведении на прокручиваемую область; на тач-экранах полос нет.
   Chromium 121+ игнорирует ::-webkit-scrollbar, если у элемента задан scrollbar-width/-color,
   поэтому стандартные свойства — только для Firefox (@supports ниже). */
:root { --xsb-thumb: rgba(255, 255, 255, .20); --xsb-thumb-hover: rgba(255, 255, 255, .34); }
html[data-theme="light"] { --xsb-thumb: rgba(0, 0, 0, .18); --xsb-thumb-hover: rgba(0, 0, 0, .32); }
::-webkit-scrollbar { width: 4px; height: 4px; background: transparent; }
::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-track-piece, ::-webkit-scrollbar-corner { background: transparent; border: 0; box-shadow: none; }
::-webkit-scrollbar-thumb { background: transparent; border: 0; border-radius: 4px; min-height: 24px; }
:hover::-webkit-scrollbar-thumb { background: var(--xsb-thumb); }
::-webkit-scrollbar-thumb:hover, ::-webkit-scrollbar-thumb:active { background: var(--xsb-thumb-hover); }
@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: transparent transparent; }
  *:hover { scrollbar-color: var(--xsb-thumb) transparent; }
}
@media (hover: none) and (pointer: coarse) {
  * { scrollbar-width: none !important; }
  ::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; }
}
/* t103: на десктопе (не тач) — тонкий ползунок у длинных списков, которые раньше были совсем без полосы */
@media not all and (hover: none) and (pointer: coarse) {
  html body .chat-list, html body .messages, html body .settings-pane { scrollbar-width: auto; }
  html body .chat-list::-webkit-scrollbar, html body .messages::-webkit-scrollbar, html body .settings-pane::-webkit-scrollbar { display: block; width: 4px; height: 0; }
}

/* t152b: during a call the bottom toast («Нет доступа к микрофону»…) sat on top of the call buttons,
   so a tap on «Завершить» only dismissed the toast — show it under the call header instead (iPhone) */
html.xam-ios:has(#xam-call-overlay:not(.hidden)) .xam-toast {
  top: max(4.5rem, calc(env(safe-area-inset-top, 0px) + 4rem));
  bottom: auto;
  transform: translate(-50%, calc(-100% - 5rem));
}
html.xam-ios:has(#xam-call-overlay:not(.hidden)) .xam-toast--show {
  transform: translate(-50%, 0);
}
