:root {
  color-scheme: light dark;
  /* Telegram Web / Desktop light tokens */
  --bg: #C8D9E8;
  --surface: #FFFFFF;
  --surface-2: #F1F3F5;
  --surface-3: #E6EBEF;
  --text: #000000;
  --text-soft: #222222;
  --muted: #707579;
  --line: rgba(0, 0, 0, 0.08);
  --border: rgba(0, 0, 0, 0.08);
  --separator: rgba(0, 0, 0, 0.1);
  --accent: #3390EC;
  --accent-2: #2A7ACB;
  --bubble-in: #FFFFFF;
  --bubble-out: #EEFFDE;
  --bubble-out-text: #000000;
  --bubble-in-text: #000000;
  --bubble-out-meta: #4FAE4E;
  --green: #4FAE4E;
  --red: #E53935;
  --orange: #F5A623;
  --indigo: #7B6FF0;
  --fill: rgba(112, 117, 121, 0.12);
  --fill-2: rgba(112, 117, 121, 0.1);
  --fill-3: rgba(112, 117, 121, 0.07);
  --hairline: rgba(0, 0, 0, 0.06);
  --shadow: 0 8px 28px rgba(15, 35, 55, 0.14);
  --shadow-sm: 0 1px 3px rgba(15, 35, 55, 0.08);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --tabbar-h: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --font: "Roboto", "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --chat-pattern: radial-gradient(circle at 12% 18%, rgba(51, 144, 236, 0.08), transparent 34%),
    radial-gradient(circle at 88% 72%, rgba(79, 174, 78, 0.07), transparent 36%),
    linear-gradient(180deg, #C8D9E8 0%, #B9CEDF 100%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1621;
    --surface: #17212B;
    --surface-2: #232E3C;
    --surface-3: #2B3848;
    --text: #F5F5F5;
    --text-soft: #E4ECF2;
    --muted: #708499;
    --line: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.08);
    --separator: rgba(255, 255, 255, 0.1);
    --accent: #6AB3F3;
    --accent-2: #5288C1;
    --bubble-in: #182533;
    --bubble-out: #2B5278;
    --bubble-out-text: #FFFFFF;
    --bubble-in-text: #F5F5F5;
    --bubble-out-meta: #7AC3F0;
    --green: #5DBB63;
    --red: #E53935;
    --orange: #F5A623;
    --indigo: #8B7CF6;
    --fill: rgba(112, 132, 153, 0.28);
    --fill-2: rgba(112, 132, 153, 0.22);
    --fill-3: rgba(112, 132, 153, 0.16);
    --hairline: rgba(255, 255, 255, 0.08);
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.35);
    --chat-pattern: radial-gradient(circle at 14% 16%, rgba(106, 179, 243, 0.08), transparent 32%),
      linear-gradient(180deg, #0E1621 0%, #0B121A 100%);
  }
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #C8D9E8; --surface: #FFFFFF; --surface-2: #F1F3F5; --surface-3: #E6EBEF;
  --text: #000000; --text-soft: #222222; --muted: #707579;
  --line: rgba(0, 0, 0, 0.08); --border: rgba(0, 0, 0, 0.08); --separator: rgba(0, 0, 0, 0.1);
  --accent: #3390EC; --accent-2: #2A7ACB;
  --bubble-in: #FFFFFF; --bubble-out: #EEFFDE; --bubble-out-text: #000000; --bubble-in-text: #000000;
  --bubble-out-meta: #4FAE4E;
  --green: #4FAE4E; --red: #E53935; --fill: rgba(112, 117, 121, 0.12); --fill-2: rgba(112, 117, 121, 0.1);
  --hairline: rgba(0, 0, 0, 0.06); --shadow: 0 8px 28px rgba(15, 35, 55, 0.14);
  --chat-pattern: radial-gradient(circle at 12% 18%, rgba(51, 144, 236, 0.08), transparent 34%),
    linear-gradient(180deg, #C8D9E8 0%, #B9CEDF 100%);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0E1621; --surface: #17212B; --surface-2: #232E3C; --surface-3: #2B3848;
  --text: #F5F5F5; --text-soft: #E4ECF2; --muted: #708499;
  --line: rgba(255, 255, 255, 0.08); --border: rgba(255, 255, 255, 0.08); --separator: rgba(255, 255, 255, 0.1);
  --accent: #6AB3F3; --accent-2: #5288C1;
  --bubble-in: #182533; --bubble-out: #2B5278; --bubble-out-text: #FFFFFF; --bubble-in-text: #F5F5F5;
  --bubble-out-meta: #7AC3F0;
  --green: #5DBB63; --red: #E53935; --fill: rgba(112, 132, 153, 0.28); --fill-2: rgba(112, 132, 153, 0.22);
  --hairline: rgba(255, 255, 255, 0.08); --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --chat-pattern: radial-gradient(circle at 14% 16%, rgba(106, 179, 243, 0.08), transparent 32%),
    linear-gradient(180deg, #0E1621 0%, #0B121A 100%);
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 20px;
  height: 20px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hidden {
  display: none !important;
}

.auth-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 15% 50%, color-mix(in srgb, var(--accent) 15%, transparent), transparent 50%),
    radial-gradient(circle at 85% 30%, color-mix(in srgb, var(--accent-2) 15%, transparent), transparent 50%),
    var(--bg);
  animation: bgPulse 10s ease-in-out infinite alternate;
}

@keyframes bgPulse {
  0% { background-position: 0% 0%; }
  100% { background-position: 100% 100%; }
}

.auth-card {
  width: min(380px, 100%);
  padding: 32px;
  border: 1px solid color-mix(in srgb, var(--line) 40%, transparent);
  border-radius: 24px;
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  backdrop-filter: blur(32px);
  -webkit-backdrop-filter: blur(32px);
  box-shadow: var(--shadow), 0 0 0 1px color-mix(in srgb, var(--surface) 20%, transparent) inset;
  text-align: center;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.auth-card:hover {
  transform: translateY(-4px);
}

.brand-mark img {
  width: 80px;
  height: 80px;
  filter: drop-shadow(0 8px 16px color-mix(in srgb, var(--accent) 40%, transparent));
}

.auth-card h1 {
  margin-top: 12px;
  font-size: 29px;
}

.auth-card p {
  margin: 6px 0 22px;
  color: var(--muted);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 16px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-2);
}

.segment {
  min-height: 40px;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.segment.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .08);
}

.form-stack {
  display: grid;
  gap: 12px;
}

.field,
.search,
.composer-input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.field {
  min-height: 48px;
  border-radius: 14px;
  padding: 0 14px;
}

.textarea {
  min-height: 92px;
  padding: 12px 14px;
  resize: vertical;
}

.field:focus,
.search:focus,
.composer-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.primary-btn,
.secondary-btn,
.danger-text {
  min-height: 48px;
  border-radius: 16px;
  padding: 0 16px;
  font-weight: 600;
  transition: all .2s cubic-bezier(0.4, 0, 0.2, 1);
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: white;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 30%, transparent);
}
.primary-btn:hover {
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 40%, transparent);
  transform: translateY(-2px);
}

.secondary-btn {
  background: var(--surface-2);
  color: var(--text);
}

.danger-text {
  background: transparent;
  color: var(--red);
}

.primary-btn:active,
.secondary-btn:active,
.danger-text:active,
.icon-btn:active,
.tab:active,
.send-btn:active,
.voice-btn:active {
  transform: scale(.96);
}

.full {
  width: 100%;
}

.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) calc(64px + var(--safe-bottom));
  background: var(--bg);
}

.incoming-call-banner {
  position: fixed;
  top: max(10px, env(safe-area-inset-top, 0px));
  left: 50%;
  z-index: 45;
  width: min(560px, calc(100vw - 20px));
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  transform: translateX(-50%);
  padding: 8px 9px 8px 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: 0 16px 44px rgba(0, 0, 0, .2);
  backdrop-filter: blur(18px);
  animation: callBannerIn .18s ease both;
}

@keyframes callBannerIn {
  from { opacity: 0; transform: translate(-50%, -12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.incoming-call-main {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-weight: 800;
}

.incoming-call-main span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.incoming-call-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 50%;
  background: var(--green);
  animation: pulseDot 1s infinite;
}

@keyframes pulseDot {
  50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--green) 0%, transparent); }
}

.incoming-call-actions {
  display: flex;
  gap: 6px;
}

.incoming-call-accept,
.incoming-call-decline {
  min-width: 78px;
  height: 40px;
  border-radius: 999px;
  color: white;
  font-size: 13px;
  font-weight: 850;
}

.incoming-call-accept {
  background: var(--green);
}

.incoming-call-decline {
  background: var(--red);
}

.sidebar {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 68px 58px minmax(0, 1fr);
  background: var(--surface);
  overflow: hidden;
}

.app-head,
.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}

.profile-chip {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.profile-text,
.chat-title {
  min-width: 0;
  display: grid;
}

.profile-text strong,
.chat-title strong,
.chat-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-text span,
.chat-title span {
  color: var(--muted);
  font-size: 12px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  border-radius: 12px;
  background: transparent;
  color: var(--text-soft);
  transition: transform .14s ease, background .14s ease;
}

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

.icon-btn .icon,
.send-btn .icon,
.voice-btn .icon {
  pointer-events: none;
}

.search-bar {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.chat-create-wrap { position: absolute; right: 18px; bottom: 76px; z-index: 8; display: grid; justify-items: end; gap: 9px; }
.chat-create-btn { width: 48px; height: 48px; border: 0; border-radius: 16px; background: var(--accent); color: #fff; font-size: 29px; line-height: 1; box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 32%, transparent); cursor: pointer; transition: transform .16s ease, box-shadow .16s ease; }
.chat-create-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 30px color-mix(in srgb, var(--accent) 48%, transparent); }
.chat-create-menu { display: grid; gap: 3px; min-width: 168px; padding: 6px; border: 1px solid var(--line); border-radius: 14px; background: color-mix(in srgb, var(--surface) 92%, transparent); box-shadow: 0 12px 30px rgba(0,0,0,.2); backdrop-filter: blur(18px); }
.chat-create-menu button { border: 0; border-radius: 10px; padding: 10px 12px; color: var(--text); background: transparent; text-align: left; font: inherit; cursor: pointer; }
.chat-create-menu button:hover { background: var(--surface-2); }
.chat-profile-trigger { border: 0; padding: 0; color: inherit; background: transparent; cursor: pointer; text-align: left; }
.chat-title.chat-profile-trigger { flex: 1; }
.avatar-wrap.chat-profile-trigger { flex: 0 0 auto; }
.group-modal-card { width: min(460px, calc(100vw - 28px)); max-height: min(680px, calc(100vh - 28px)); overflow: auto; }
.group-members-list { display: grid; gap: 8px; max-height: 270px; overflow: auto; padding: 4px 0; }
.member-picker-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; padding: 9px; border-radius: 10px; background: var(--surface-2); font-size: 13px; }
.member-picker-row .secondary-btn, .member-picker-row .danger-text { padding: 6px 8px; font-size: 12px; }
.copy-row { display: flex; gap: 8px; margin: 6px 0 14px; }
.copy-row .field { min-width: 0; }
.unread-badge { min-width: 20px; height: 20px; display: inline-grid; place-items: center; padding: 0 6px; border-radius: 10px; color: #fff; background: var(--accent); font-size: 11px; }
.settings-check { display: flex; align-items: center; gap: 8px; color: var(--text-soft); font-size: 13px; }
.chat-info-actions { display: grid; gap: 8px; margin: 12px 0; }

.search {
  height: 42px;
  border-radius: 14px;
  padding: 0 14px;
}

.pane {
  min-height: 0;
  display: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.pane.active {
  display: block;
  animation: paneIn .18s ease both;
}

@keyframes paneIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}



.pane-title {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 16px 16px 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.pull-hint {
  height: 0;
  overflow: hidden;
  color: var(--accent);
  font-size: 12px;
  text-align: center;
  transition: height .16s ease;
}

.pull-hint.active {
  height: 28px;
  padding-top: 8px;
}

.list {
  display: grid;
  gap: 2px;
  padding: 6px;
}

.chat-item {
  width: 100%;
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 14px;
  background: transparent;
  text-align: left;
  transition: transform .14s ease, background .14s ease;
}

.chat-item:hover,
.chat-item.active {
  background: var(--surface-2);
}

.chat-item.active {
  box-shadow: inset 3px 0 0 var(--accent), 0 2px 12px rgba(31, 29, 24, .04);
}

.chat-item:active {
  transform: scale(.985);
}

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

.chat-item-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.chat-name {
  font-size: 15px;
  font-weight: 760;
}

.chat-time,
.chat-sub {
  color: var(--muted);
  font-size: 12px;
}

.chat-sub {
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  width: 48px;
  height: 48px;
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 48px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--accent);
  color: white;
  font-weight: 850;
}

.avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.avatar.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .26), transparent);
  animation: skeleton 1.1s infinite;
}

/* Wrapper for avatar + online dot */
.avatar-wrap {
  position: relative;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
}

.avatar-wrap .avatar {
  flex: none;
  width: 100%;
  height: 100%;
}

.online-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--green);
  border: 2.5px solid var(--surface);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 50%, transparent);
  animation: onlinePulse 2.4s ease-in-out infinite;
  z-index: 2;
  pointer-events: none;
}

@keyframes onlinePulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 50%, transparent); }
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--green) 0%, transparent); }
}

.online-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--green) 18%, transparent);
  color: var(--green);
  font-size: 11px;
  font-weight: 750;
}

@keyframes skeleton {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

.avatar-xl {
  width: 120px;
  height: 120px;
  flex-basis: 120px;
  font-size: 42px;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--text) 12%, transparent);
  border: 4px solid var(--surface);
  position: relative;
  z-index: 2;
}

.settings-card { margin: 10px; padding: 18px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: 0 8px 24px rgba(33, 29, 24, .04); }
.avatar-block { display: flex; align-items: center; gap: 16px; padding-bottom: 18px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.avatar-xl { width: 80px; height: 80px; flex-basis: 80px; font-size: 28px; border-width: 3px; box-shadow: none; }
.avatar-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.avatar-actions .secondary-btn, .avatar-actions .danger-text { min-height: 34px; padding: 0 10px; border-radius: 10px; font-size: 12px; }

.chat-shell {
  min-width: 0;
  min-height: 0;
  display: none;
  position: relative;
  background: var(--chat-wallpaper, radial-gradient(circle at 15% 15%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 28%), var(--bg));
  background-size: auto;
}

.empty-state {
  height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state img {
  width: 84px;
  height: 84px;
}

.empty-state strong {
  color: var(--text);
  font-size: 20px;
}

.chat-view {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.back-btn {
  font-size: 0;
}

.chat-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.call-btn,
.video-btn {
  color: var(--accent);
}

.video-btn {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.messages {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow-y: auto;
  padding: 14px 10px 8px;
}

.msg-row {
  display: flex;
  touch-action: pan-y;
}

.msg-row.out {
  justify-content: flex-end;
}

.bubble {
  max-width: min(82%, 560px);
  padding: 8px 11px 7px;
  border-radius: 18px;
  background: var(--bubble-in);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .04);
  overflow-wrap: anywhere;
  animation: msgIn .16s ease both;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-row.out .bubble {
  background: var(--bubble-out);
}

.msg-row.replying .bubble {
  transform: translateX(28px);
}

.bubble .body {
  font-size: 15px;
  line-height: 1.36;
}

.reply-quote {
  margin-bottom: 6px;
  padding-left: 8px;
  border-left: 3px solid var(--accent);
  color: var(--text-soft);
  font-size: 12px;
}

.meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.msg-tick {
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  color: var(--muted);
  letter-spacing: -2px;
  transition: color .25s ease;
}

.msg-tick--read {
  color: var(--accent);
}

.date-sep {
  align-self: center;
  margin: 10px 0;
  padding: 5px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--muted);
  font-size: 12px;
}

.voice-message {
  width: min(300px, calc(100vw - 100px));
  min-width: min(240px, calc(100vw - 100px));
  max-width: 100%;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  overflow: hidden;
  padding: 6px 4px;
}

.voice-play {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 70%, #000) 100%);
  color: white;
  border: none;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 30%, transparent);
}

.voice-play:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 40%, transparent);
}

.voice-play:active {
  transform: scale(0.95);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 30%, transparent);
}

.voice-message.playing .voice-play {
  animation: pulse-ring 2s infinite cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 50%, transparent); }
  70% { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.voice-play .icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.voice-right {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.voice-wave {
  width: 100%;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  contain: layout paint;
}

.voice-wave span {
  flex: 1;
  border-radius: 4px;
  background-color: color-mix(in srgb, var(--text) 20%, transparent);
  transition: background-color 0.15s ease, transform 0.1s ease;
  transform-origin: center;
}

.voice-wave span.played {
  background-color: var(--accent);
}

.voice-wave:hover span {
  opacity: 0.8;
}

.voice-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.3px;
}

.voice-time {
  font-variant-numeric: tabular-nums;
}

.voice-message > div {
  min-width: 0;
  overflow: hidden;
}

.typing-line {
  min-height: 20px;
  padding: 0 14px 2px;
  color: var(--accent);
  font-size: 13px;
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: opacity .2s ease;
}

.typing-line:empty {
  opacity: 0;
}

.typing-line:not(:empty)::before {
  content: '';
  flex: 0 0 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: typingPulse .8s ease-in-out infinite;
}

@keyframes typingPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .4; transform: scale(.7); }
}

.composer-wrap {
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  padding-bottom: max(8px, var(--safe-bottom));
}

.composer {
  min-height: 52px;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 4px;
  align-items: center;
  padding: 6px 8px;
  position: relative;
  z-index: 5;
}

.composer-input {
  flex: 1 1 auto;
  height: 40px;
  border-radius: 20px;
  padding: 0 14px;
  min-width: 0;
}

.send-btn,
.voice-btn {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 18px;
  transition: transform .14s ease, background .14s ease, opacity 0.14s ease;
  touch-action: manipulation;
  pointer-events: auto;
  position: relative;
  z-index: 6;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.voice-btn {
  background: var(--surface-3);
  color: var(--accent);
}

.composer .icon-btn {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  pointer-events: auto;
  z-index: 6;
}

.timer-btn {
  position: relative;
}

.timer-btn.active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.timer-val {
  position: absolute;
  right: 1px;
  bottom: 1px;
  min-width: 18px;
  height: 14px;
  padding: 0 3px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
}

.timer-val:empty {
  display: none;
}

.voice-btn.recording {
  background: var(--red);
  color: white;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--red) 38%, transparent); }
  50% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--red) 0%, transparent); }
}

.composer.hidden {
  display: none !important;
}

.composer .send-btn.hidden,
.composer .voice-btn.hidden {
  display: none !important;
}

.recording-strip {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border-top: 1px solid var(--line);
  box-sizing: border-box;
  animation: slideUp 0.18s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.recording-strip.hidden {
  display: none !important;
}

.recording-strip .icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  color: var(--text-color);
  border: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, color 0.2s;
}

.recording-strip .icon-btn:active {
  transform: scale(0.95);
}

.recording-strip .record-cancel-btn {
  background: var(--surface-3);
  color: var(--red);
}

.recording-strip .record-cancel-btn:hover {
  background: color-mix(in srgb, var(--red) 15%, var(--surface-3));
}

.recording-strip .record-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-color);
  white-space: nowrap;
}

.recording-strip .record-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1s infinite alternate;
}

.recording-strip .record-dot.paused {
  background: var(--muted);
  animation: none;
}

@keyframes blink {
  from { opacity: 1; }
  to { opacity: 0.3; }
}

.recording-strip #record-meter {
  flex: 1;
  height: 32px;
  background: var(--surface-2);
  border-radius: 16px;
  padding: 2px 8px;
  min-width: 80px;
}

.recording-strip .slide-to-cancel-text {
  font-size: 13px;
  color: var(--muted);
  animation: slideTextPulse 1.5s infinite;
}

@keyframes slideTextPulse {
  0%, 100% { opacity: 0.6; transform: translateX(0); }
  50% { opacity: 1; transform: translateX(-4px); }
}

.recording-strip .record-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.recording-strip .record-pause-btn {
  color: var(--accent);
}

.recording-strip .record-send-btn {
  background: var(--accent);
  color: white;
}

.recording-strip .record-send-btn:hover {
  filter: brightness(1.1);
}

.recording-strip .hidden {
  display: none !important;
}

.reply-preview {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 0;
  color: var(--muted);
  font-size: 13px;
  justify-content: space-between;
  color: var(--accent);
}

.reply-preview button {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
}

.record-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
}

.tabbar {
  height: calc(64px + var(--safe-bottom));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: start;
  padding-bottom: var(--safe-bottom);
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
}

.tab {
  height: 64px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.tab.active {
  color: var(--accent);
}

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

.tab.active .icon {
  filter: drop-shadow(0 7px 14px color-mix(in srgb, var(--accent) 34%, transparent));
}

.settings-card {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 0 16px 90px;
  max-width: 500px;
  margin: 0 auto;
  position: relative;
}

.settings-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 140px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 40%, transparent), color-mix(in srgb, var(--accent) 10%, transparent));
  border-radius: 0 0 32px 32px;
  z-index: 0;
}

.avatar-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-top: 50px;
  position: relative;
  z-index: 1;
}

.avatar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  background: var(--surface-2);
  padding: 6px;
  border-radius: 20px;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--text) 5%, transparent);
}

.avatar-actions button {
  min-height: 32px;
  padding: 0 14px;
  font-size: 13px;
  border-radius: 14px;
  background: transparent;
}

.avatar-actions button:hover {
  background: var(--surface-3);
}

.avatar-actions #avatar-delete-btn:hover {
  background: color-mix(in srgb, var(--red) 15%, transparent);
}

.profile-form {
  background: var(--surface-2);
  padding: 24px 20px;
  border-radius: 28px;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--text) 4%, transparent);
  position: relative;
  z-index: 1;
  margin-bottom: 8px;
}

.profile-form label {
  display: grid;
  gap: 8px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.profile-form .field {
  background: var(--surface);
  border: 1px solid transparent;
  box-shadow: inset 0 2px 6px color-mix(in srgb, var(--text) 2%, transparent);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.profile-form .field:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 15%, transparent);
  transform: translateY(-1px);
}

.profile-form .primary-btn {
  margin-top: 12px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 80%, #000));
  box-shadow: 0 4px 16px color-mix(in srgb, var(--accent) 30%, transparent);
}

#logout-btn {
  background: color-mix(in srgb, var(--red) 8%, transparent);
  color: var(--red);
  border: 1px solid color-mix(in srgb, var(--red) 15%, transparent);
  height: 52px;
  border-radius: 16px;
  font-weight: 700;
}

.muted-list {
  color: var(--muted);
}

.muted-list::before {
  content: "История звонков появится после первого вызова";
  display: block;
  padding: 12px;
}

.call-item {
  width: 100%;
  min-height: 70px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 18px;
  background: transparent;
  text-align: left;
  transition: transform .14s ease, background .14s ease;
}

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

.call-item:active {
  transform: scale(.985);
}

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

.call-sub {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.call-sub.bad {
  color: var(--red);
}

.call-sub .icon {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
}

.call-sub span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call-overlay,
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(26, 24, 21, 0.48);
  backdrop-filter: blur(12px);
}

.call-card,
.modal-card {
  width: min(440px, 100%);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(30, 25, 18, .22);
  backdrop-filter: blur(24px);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
  color: var(--text);
}

.call-card {
  min-height: min(680px, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px 22px 30px;
  text-align: center;
}

.call-card::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--accent) 25%, transparent), transparent 60%);
  animation: callGlowRotate 15s linear infinite;
  z-index: 0;
  pointer-events: none;
}
@keyframes callGlowRotate {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.call-card > * {
  z-index: 1;
}

.call-card.video-mode {
  width: min(820px, 100%);
  min-height: min(760px, calc(100vh - 32px));
}

.call-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 18px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
}

.call-timer {
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.85);
}
.call-timer::before {
  content: '·';
  margin-right: 10px;
  color: rgba(255, 255, 255, 0.3);
}

.call-mid {
  flex: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  min-height: 0;
}

.call-bottom {
  display: grid;
  gap: 24px;
}

.call-media {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 16;
  max-height: 52vh;
  overflow: hidden;
  border-radius: 28px;
  background: #000;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.call-media video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

/* Suppress the native "play" overlay some WebViews draw on a paused/frameless
   <video>, so no stray play-button icon shows over the remote camera. */
.call-media video::-webkit-media-controls,
.call-media video::-webkit-media-controls-overlay-play-button,
.call-media video::-webkit-media-controls-start-playback-button {
  display: none !important;
  -webkit-appearance: none;
}

#local-video {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 30%;
  max-width: 160px;
  aspect-ratio: 3 / 4;
  height: auto;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  transition: transform 0.3s ease;
}
#local-video.mirrored {
  transform: scaleX(-1);
}
#local-video:hover {
  transform: scale(1.05);
}

.avatar-call {
  width: 130px;
  height: 130px;
  flex-basis: 130px;
  font-size: 48px;
  border: 4px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.1);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 50%, transparent);
  animation: callPulseWow 2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes callPulseWow {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); }
  70% { box-shadow: 0 0 0 50px color-mix(in srgb, var(--accent) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent); }
}

.call-wave {
  width: 140px;
  height: 24px;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 5px;
}

.call-wave span {
  align-self: center;
  height: 30%;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  animation: level 900ms infinite ease-in-out;
}

.call-wave span:nth-child(2n) { animation-delay: 120ms; }
.call-wave span:nth-child(3n) { animation-delay: 260ms; }

@keyframes level {
  50% { height: 100%; }
}

.call-tools {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.call-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 26px;
}

.call-action {
  width: 68px;
  height: 68px;
  min-width: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  border: none;
  transition: transform 0.2s, box-shadow 0.2s, filter 0.2s;
}
.call-action .icon {
  width: 26px;
  height: 26px;
}
.call-action .icon.icon-end {
  transform: rotate(135deg);
}
.call-action:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
}
.call-action:active {
  transform: translateY(1px);
}

.green { background: linear-gradient(135deg, #11998e, #38ef7d); box-shadow: 0 8px 24px rgba(56, 239, 125, 0.4); }
.red { background: linear-gradient(135deg, #FF416C, #FF4B2B); box-shadow: 0 8px 24px rgba(255, 75, 43, 0.4); }

.tool-btn {
  width: 52px;
  height: 52px;
  min-width: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,0.1);
  color: white;
  border: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(10px);
  transition: all 0.2s;
}
.tool-btn .icon {
  width: 21px;
  height: 21px;
}

.tool-btn:hover {
  background: rgba(255,255,255,0.2);
}

.tool-btn.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 50%, transparent);
}

.tool-btn.danger-active {
  background: var(--red);
  color: white;
}

.message-menu {
  position: fixed;
  z-index: 60;
  min-width: 160px;
  display: grid;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.bubble { border-radius: 18px !important; box-shadow: none; }
.msg-row.out .bubble { border-bottom-right-radius: 5px !important; }
.msg-row.in .bubble { border-bottom-left-radius: 5px !important; }

.message-menu button {
  min-height: 40px;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  padding: 0 10px;
}

.message-menu button:hover {
  background: var(--surface-2);
}

.modal-card {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.modal-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.group-modal-card { padding: 0; gap: 0; overflow: hidden; }
.group-modal-card > header { min-height: 64px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.group-modal-card > .form-stack,
.group-modal-card > #chat-invite-wrap,
.group-modal-card > #chat-member-actions,
.group-modal-card > #chat-edit-wrap,
.group-modal-card > .group-members-list,
.group-modal-card > .chat-info-actions,
.group-modal-card > #block-user-btn { margin-left: 18px; margin-right: 18px; }
.group-modal-card > .form-stack { margin-top: 18px; margin-bottom: 18px; }
.chat-info-hero { position: relative; display: block; min-height: 224px; overflow: hidden; padding: 0 20px 20px; background: var(--surface); }
.profile-cover { height: 106px; margin: 0 -20px; background: linear-gradient(120deg, #16213a, #244d69 54%, #68c9c0); }
.profile-cover::after { content: ''; display: block; width: 100%; height: 100%; background: radial-gradient(circle at 18% 25%, rgba(255,255,255,.22) 0 2px, transparent 3px), radial-gradient(circle at 80% 70%, rgba(255,255,255,.17) 0 1px, transparent 2px); background-size: 24px 24px, 18px 18px; opacity: .7; }
.profile-cover--channel { background: linear-gradient(120deg, #251949, #6b2a77 52%, #ee7455); }
.info-avatar { position: relative; z-index: 1; width: 76px; height: 76px; display: grid; place-items: center; margin: -38px 0 10px; border: 4px solid var(--surface); border-radius: 26px; color: #fff; background: linear-gradient(135deg, #202d4a, #4d7996); font-size: 25px; font-weight: 850; box-shadow: 0 8px 18px rgba(25, 30, 40, .22); }
.info-avatar--group { border-radius: 24px; background: linear-gradient(135deg, #492452, #d65e4b); }
.profile-identity strong { display: block; max-width: 100%; overflow: hidden; font-size: 21px; font-weight: 780; letter-spacing: -.035em; text-overflow: ellipsis; white-space: nowrap; }
.profile-identity > span { display: block; margin-top: 4px; color: var(--text-soft); font-size: 13px; }
.profile-identity .profile-kind { margin-bottom: 5px; color: var(--accent); font-size: 10px; font-weight: 850; letter-spacing: .12em; }
.profile-identity p { margin-top: 10px; color: var(--text-soft); font-size: 13px; line-height: 1.45; }
.group-members-list { max-height: 240px; padding: 4px 0 16px; }
.member-picker-row { border: 1px solid var(--line); background: var(--surface-2); }

.cropper {
  width: min(500px, 100%);
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 24px;
  background: var(--surface-2);
}

#avatar-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#avatar-zoom {
  width: 100%;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + var(--safe-bottom));
  z-index: 80;
  max-width: min(420px, calc(100vw - 28px));
  transform: translateX(-50%);
  padding: 12px 14px;
  border-radius: 999px;
  background: #111820;
  color: white;
  box-shadow: var(--shadow);
  font-size: 14px;
  animation: toastIn .18s ease both;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (min-width: 820px) {
  .app {
    grid-template-columns: 372px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .sidebar {
    border-right: 1px solid var(--line);
  }

  .chat-shell {
    display: block;
  }

  .tabbar {
    display: none;
  }

  .back-btn {
    display: none;
  }

  .bubble {
    max-width: min(68%, 560px);
  }

  .voice-message {
    width: 300px;
    min-width: 260px;
  }

  .call-media {
    aspect-ratio: 16 / 9;
  }
}

@media (max-width: 819px) {
  .incoming-call-banner {
    grid-template-columns: minmax(0, 1fr);
  }

  .incoming-call-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .incoming-call-accept,
  .incoming-call-decline {
    width: 100%;
  }

  .app.chat-open {
    grid-template-rows: minmax(0, 1fr);
  }

  .app.chat-open .sidebar,
  .app.chat-open .tabbar {
    display: none;
  }

  .app.chat-open .chat-shell {
    display: block;
  }
}


.file-message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 180px;
  padding: 10px 12px;
  color: inherit;
  text-decoration: none;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 13%, transparent);
}
.file-message span { color: var(--muted); font-size: 12px; }
.msg-row.selected .bubble { outline: 2px solid var(--accent); outline-offset: 2px; }
.selection-bar {
  position: fixed; z-index: 20; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 14px;
  color: var(--text); background: var(--surface); box-shadow: 0 8px 28px rgba(0, 0, 0, .24);
}
.selection-bar button { border: 0; border-radius: 8px; padding: 7px 9px; color: inherit; background: var(--surface-2); cursor: pointer; }

.msg-media {
  max-width: 100%;
  border-radius: 12px;
  display: block;
  margin-bottom: 6px;
  cursor: pointer;
}
.msg-video {
  cursor: default;
}
.media-viewer { position: fixed; inset: 0; z-index: 120; display: grid; grid-template-columns: 64px minmax(0, 1fr) 64px; align-items: center; padding: 20px; background: #121211; }
.media-viewer-content { min-width: 0; height: 100%; display: grid; place-items: center; }
.media-viewer-content img, .media-viewer-content video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 10px; }
.media-viewer-nav, .media-viewer-close { width: 42px; height: 42px; border-radius: 50%; color: #fff; background: rgba(255,255,255,.13); font-size: 30px; }
.media-viewer-close { position: absolute; top: 18px; right: 18px; z-index: 1; font-size: 22px; }
.search-section { padding: 14px 12px 6px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.settings-tools { display: grid; gap: 8px; margin-top: 14px; }
.settings-modal-content { display: grid; gap: 14px; padding: 18px; }
.settings-modal-content label { display: grid; gap: 6px; color: var(--text-soft); font-size: 13px; }
.settings-modal-content select.field { padding-right: 10px; }
.device-list { display: grid; gap: 8px; }
.device-list small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.devices-intro { margin: 0; color: var(--text-soft); font-size: 13px; line-height: 1.45; }
.device-card { display: flex; align-items: center; gap: 12px; padding: 13px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-2); }
.device-card.current { border-color: color-mix(in srgb, var(--accent) 38%, var(--line)); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.device-glyph { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 42px; border-radius: 13px; background: linear-gradient(135deg, #73bf65, #369449); }
.device-glyph img { width: 22px; height: 22px; display: block; }
.device-glyph-windows { background: linear-gradient(135deg, #2888df, #1456a0); }
.device-glyph-browser { background: linear-gradient(135deg, #6d60ca, #3f357f); }
.device-copy { min-width: 0; flex: 1; display: grid; gap: 2px; }
.device-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.device-copy span { color: var(--text-soft); font-size: 12px; }
.current-device { padding: 4px 6px; border-radius: 6px; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); font-size: 9px; letter-spacing: .08em; }
.device-empty { padding: 22px; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); text-align: center; font-size: 13px; }
.attach-btn {
  color: var(--text-soft);
}

.location-widget {
  width: min(300px, calc(100vw - 96px));
  max-width: 100%;
  display: block;
  overflow: hidden;
  border-radius: 14px;
  background: var(--surface-2);
  text-align: left;
  cursor: pointer;
}

.location-map {
  height: 132px;
  position: relative;
  overflow: hidden;
  background: var(--surface-3);
}

.location-preview {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.location-pin {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .22);
  transform: translate(-50%, -50%);
  z-index: 2;
}

.location-pin::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .28);
}

.location-pin-large {
  width: 56px;
  height: 56px;
}

.location-viewer-map {
  width: 100%;
  height: 100%;
  border: 0;
}

.location-stop {
  margin-left: auto;
  min-height: 32px;
  border-radius: 999px;
  padding: 0 12px;
  background: color-mix(in srgb, var(--red) 18%, var(--surface-2));
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
}

.location-footer {
  display: flex;
  gap: 9px;
  align-items: center;
  padding: 9px;
}

.location-avatar {
  width: 38px;
  height: 38px;
}

.location-text {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.location-text strong,
.location-text span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.location-text span {
  color: var(--muted);
  font-size: 12px;
}

.location-viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--surface);
}

.location-viewer-head {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: max(12px, env(safe-area-inset-top, 0px)) 14px 10px;
  border-bottom: 1px solid var(--line);
}

.location-viewer-head div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.location-viewer-head span {
  color: var(--muted);
  font-size: 12px;
}
.media-hidden { opacity: 0 !important; position: absolute !important; pointer-events: none !important; z-index: -10 !important; width: 1px !important; height: 1px !important; }

/* Reactions */
.reactions-picker {
  display: flex;
  justify-content: space-around;
  padding: 6px 4px 10px 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
  gap: 4px;
}

.reactions-picker span {
  font-size: 20px;
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 8px;
  transition: transform 0.12s cubic-bezier(0.175, 0.885, 0.32, 1.275), background 0.15s ease;
  user-select: none;
}

.reactions-picker span:hover {
  background: var(--surface-2);
  transform: scale(1.28);
}

.reactions-picker span:active {
  transform: scale(0.9);
}

.message-reactions-container {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
  margin-bottom: -2px;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}

.reaction-pill:hover {
  transform: scale(1.05);
  background: var(--line);
}

.reaction-pill:active {
  transform: scale(0.95);
}

.reaction-pill.active {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border-color: var(--accent);
  color: var(--accent);
}

/* Sticker / GIF Picker */
.sticker-picker {
  position: absolute;
  bottom: 70px;
  left: 14px;
  right: 14px;
  max-height: 280px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUpSticker 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUpSticker {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.sticker-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.sticker-tab {
  flex: 1;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  background: transparent;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  border: none;
  transition: color 0.15s ease, background 0.15s ease;
}

.sticker-tab.active {
  color: var(--accent);
  background: var(--surface);
}

.sticker-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.sticker-content.active {
  display: block;
}

.stickers-grid, .gifs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 8px;
}

.stickers-grid img, .gifs-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  cursor: pointer;
  border-radius: 10px;
  transition: transform 0.12s ease;
  user-select: none;
}

.stickers-grid img:hover, .gifs-grid img:hover {
  transform: scale(1.15);
}

.stickers-grid img:active, .gifs-grid img:active {
  transform: scale(0.95);
}

/* GIF Search */
.gif-search-box {
  padding-bottom: 10px;
}

.gif-search-box input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  font-size: 13px;
}

.gif-search-box input:focus {
  border-color: var(--accent);
}

/* Sticker Bubble Render in Chat */
.msg-row.sticker-row .bubble {
  background: transparent !important;
  box-shadow: none !important;
  padding: 0 !important;
  border: none !important;
}

.msg-row.sticker-row .bubble::before,
.msg-row.sticker-row .bubble::after {
  display: none !important;
}

.sticker-media {
  max-width: 160px;
  max-height: 160px;
  border-radius: 12px;
  display: block;
  user-select: none;
  pointer-events: auto;
}

.msg-row.sticker-row .meta {
  color: var(--muted);
  font-size: 10px;
  margin-top: 4px;
  background: rgba(0, 0, 0, 0.4);
  padding: 1px 6px;
  border-radius: 8px;
  color: white;
  width: fit-content;
}

.msg-row.sticker-row.out .meta {
  margin-left: auto;
}

.wallpaper-presets {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.wallpaper-preset {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}
.wallpaper-preset:hover {
  transform: scale(1.1);
}
.wallpaper-preset.active {
  border-color: var(--accent);
  transform: scale(1.05);
  box-shadow: 0 0 0 2px var(--surface), 0 4px 12px rgba(0, 0, 0, 0.25);
}

.chat-search-bar {
  display: flex;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  gap: 12px;
  z-index: 10;
}
.chat-search-bar.hidden {
  display: none !important;
}

.pinned-banner {
  display: flex;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  z-index: 4;
  flex-shrink: 0;
}
.pinned-banner.hidden {
  display: none !important;
}
#pinned-banner-click {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: pointer;
}
#pinned-banner-click span:first-child {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}
#pinned-banner-text {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#unpin-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
}
.chat-search-bar input {
  flex: 1;
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
.chat-search-bar input:focus {
  border-color: var(--accent);
}
.chat-search-bar button {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, color 0.2s;
}
.chat-search-bar button:hover {
  background: rgba(127, 127, 127, 0.1);
  color: var(--text);
}

/* Stories CSS */
.stories-bar {
  display: flex;
  overflow-x: auto;
  padding: 10px 14px;
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.stories-bar::-webkit-scrollbar { display: none; }
.story-circle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  width: 60px;
  flex-shrink: 0;
  background: transparent;
  border: 0;
  color: inherit;
}
.story-circle-img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  padding: 2px;
  background: linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
  position: relative;
}
.story-circle-img.mine { background: var(--line); }
.story-circle-img.mine.has-story { background: var(--accent); }
.story-circle-img img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--surface);
  background: var(--bg);
}
.story-fallback {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px solid var(--surface);
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}
.story-circle-img .add-badge {
  position: absolute;
  bottom: 0;
  right: 0;
  background: var(--accent);
  color: white;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  border: 2px solid var(--surface);
}
.story-circle-name {
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  text-align: center;
}

.story-viewer {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #000;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  color: #fff;
}
.story-viewer.hidden { display: none !important; }
.story-progress {
  display: flex;
  gap: 4px;
  padding: 10px;
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 2;
}
.story-progress-bar {
  flex: 1;
  height: 2px;
  background: rgba(255,255,255,0.3);
  border-radius: 2px;
  overflow: hidden;
}
.story-progress-fill { height: 100%; background: #fff; width: 0%; }
.story-header {
  position: absolute;
  top: 20px; left: 10px; right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 2;
}
.story-user { display: flex; align-items: center; gap: 8px; }
.story-user .avatar { width: 32px; height: 32px; border: 1px solid rgba(255,255,255,0.3); }
.story-head-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.story-name { font-size: 14px; font-weight: 500; text-shadow: 0 1px 2px rgba(0,0,0,0.5); }
.story-views {
  font-size: 12px;
  color: rgba(255,255,255,0.78);
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.story-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.story-close { color: #fff; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5)); }
.story-delete {
  color: #fff;
  background: rgba(239,68,68,0.24);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}
.story-delete:hover {
  background: rgba(239,68,68,0.38);
}
.story-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.story-content img, .story-content video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.story-caption {
  position: absolute;
  bottom: 40px; left: 20px; right: 20px;
  text-align: center; font-size: 16px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}
.story-nav {
  position: absolute;
  top: 0; bottom: 0; width: 30%; z-index: 1;
}
.story-nav.left { left: 0; }
.story-nav.right { right: 0; }

/* ===== Feature pack: polls, video notes, streaks, screen share ===== */
.streak-chip {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: color-mix(in srgb, #ff8a3d 18%, transparent);
  color: #ff8a3d;
  vertical-align: middle;
}
.streak-badge {
  display: inline-flex;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: color-mix(in srgb, #ff8a3d 20%, transparent);
  color: #ff8a3d;
  white-space: nowrap;
}
.chat-title {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}
.chat-title .streak-badge {
  margin-left: 0;
  margin-top: 2px;
}

.poll-card {
  min-width: 220px;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.poll-question {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.3;
}
.poll-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.poll-option {
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-2) 80%, transparent);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
}
.poll-option .poll-bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  z-index: 0;
  border-radius: 12px;
  pointer-events: none;
}
.poll-option .poll-opt-text,
.poll-option .poll-opt-meta {
  position: relative;
  z-index: 1;
}
.poll-option.voted {
  border-color: var(--accent);
}
.poll-option:hover {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
}
.poll-footer {
  font-size: 11px;
  color: var(--muted);
}
.poll-options-edit {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.poll-option-edit-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.poll-option-edit-row .field {
  flex: 1;
}
.poll-modal-card {
  max-width: 420px;
  width: min(94vw, 420px);
}

.video-note-row .bubble {
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
  padding: 0 !important;
}
.video-note {
  position: relative;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--accent);
  cursor: pointer;
  background: #000;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.video-note-player {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.video-note-play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 28px;
  background: rgba(0,0,0,.28);
  pointer-events: none;
  transition: opacity .15s ease;
}
.video-note.playing .video-note-play {
  opacity: 0;
}

.emoji-sticker {
  font-size: 72px;
  line-height: 1;
  padding: 4px;
  user-select: none;
}
.emoji-sticker-btn {
  font-size: 32px;
  line-height: 1;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 12px;
  padding: 6px;
  transition: transform .12s ease, background .12s ease;
}
.emoji-sticker-btn:hover {
  transform: scale(1.12);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.gif-media {
  max-width: 220px;
  max-height: 220px;
  border-radius: 14px;
}

.circle-recorder {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(0,0,0,.72);
  display: grid;
  place-items: center;
  padding: 20px;
}
.circle-recorder.hidden { display: none; }
.circle-recorder-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(92vw, 360px);
}
#circle-preview {
  width: min(72vw, 280px);
  height: min(72vw, 280px);
  border-radius: 50%;
  object-fit: cover;
  background: #111;
  border: 4px solid #fff;
  box-shadow: 0 0 0 4px var(--accent), 0 20px 40px rgba(0,0,0,.35);
  transform: scaleX(-1);
}
.circle-timer {
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: .04em;
}
.circle-actions {
  display: flex;
  gap: 10px;
}
.circle-hint {
  color: rgba(255,255,255,.7);
  font-size: 13px;
  margin: 0;
}

#call-screen.active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent);
}


/* ==========================================================================
   BRGRAM — Telegram messenger design layer
   ========================================================================== */

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.35;
  letter-spacing: 0;
}

button, input, textarea, select {
  font-family: inherit;
  letter-spacing: inherit;
}

/* —— Auth —— */
.auth-screen {
  background:
    radial-gradient(120% 80% at 10% 0%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 55%),
    radial-gradient(100% 70% at 100% 100%, color-mix(in srgb, var(--green) 12%, transparent), transparent 50%),
    var(--surface-2);
  animation: none;
}
.auth-card {
  width: min(400px, 100%);
  padding: 32px 24px 24px;
  border: 0;
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow), 0 0 0 1px var(--hairline);
  text-align: center;
}
.auth-card:hover { transform: none; }
.auth-card h1 {
  margin-top: 12px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0;
}
.auth-card p {
  margin: 6px 0 22px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}
.brand-mark img {
  width: 84px;
  height: 84px;
  border-radius: 22px;
  filter: drop-shadow(0 10px 24px color-mix(in srgb, var(--accent) 30%, transparent));
}
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  margin-bottom: 16px;
  padding: 3px;
  border-radius: 12px;
  background: var(--fill);
}
.segment {
  min-height: 36px;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.segment.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

/* —— Controls —— */
.field, .search, .composer-input {
  border: 0;
  background: var(--fill-2);
  color: var(--text);
  border-radius: 12px;
}
.field {
  min-height: 48px;
  border-radius: 12px;
  padding: 0 14px;
  font-size: 15px;
}
.textarea { min-height: 92px; padding: 12px 14px; border-radius: 12px; }
.field:focus, .search:focus, .composer-input:focus {
  outline: none;
  border-color: transparent;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent);
  background: var(--surface);
}
.primary-btn {
  min-height: 48px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  box-shadow: none;
  letter-spacing: 0;
}
.primary-btn:hover {
  filter: brightness(1.04);
  transform: none;
  box-shadow: none;
}
.secondary-btn {
  min-height: 44px;
  border-radius: 12px;
  background: var(--fill-2);
  color: var(--accent);
  font-weight: 600;
}
.danger-text {
  min-height: 44px;
  border-radius: 12px;
  color: var(--red);
  font-weight: 600;
}
.primary-btn:active, .secondary-btn:active, .danger-text:active,
.icon-btn:active, .tab:active, .send-btn:active, .voice-btn:active, .chat-item:active {
  transform: scale(0.98);
  opacity: 0.94;
}

/* —— App shell —— */
.app {
  background: var(--surface);
  grid-template-rows: minmax(0, 1fr) calc(var(--tabbar-h) + var(--safe-bottom));
}
.sidebar {
  position: relative;
  background: var(--surface);
  grid-template-rows: auto auto minmax(0, 1fr);
}
.app-head, .chat-head {
  gap: 8px;
  min-height: 56px;
  padding: max(10px, var(--safe-top)) 12px 10px;
  border-bottom: 1px solid var(--separator);
  background: var(--surface);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.profile-text strong, .chat-title strong {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0;
}
.profile-text span, .chat-title span {
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
}
.icon-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 50%;
  color: var(--accent);
  background: transparent;
}
.icon-btn:hover { background: var(--fill-3); }
.icon-btn .icon { width: 22px; height: 22px; stroke-width: 1.9; }

.search-bar {
  padding: 0 12px 10px;
  border-bottom: 0;
  background: transparent;
}
.search {
  height: 38px;
  border-radius: 20px;
  padding: 0 14px 0 36px;
  font-size: 15px;
  background: var(--fill) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%23707579' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='6' cy='6' r='4.5'/%3E%3Cpath d='M10 10l3 3'/%3E%3C/svg%3E") 12px center no-repeat;
  background-size: 14px 14px, auto;
}
.search::placeholder { color: var(--muted); }

.pane-title {
  padding: 14px 16px 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.list { gap: 0; padding: 0; }
.chat-item {
  min-height: 70px;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 0;
  border-bottom: 1px solid var(--separator);
  background: transparent;
}
.chat-item:hover, .chat-item.active {
  background: var(--fill-3);
  box-shadow: none;
  transform: none;
}
.chat-item.active {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.chat-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0;
}
.chat-time, .chat-sub {
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
}
.chat-sub { margin-top: 2px; font-size: 14px; }
.unread-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.avatar {
  width: 50px;
  height: 50px;
  flex: 0 0 50px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0;
}
.avatar-wrap { width: 50px; height: 50px; flex: 0 0 50px; }
.online-dot {
  width: 13px;
  height: 13px;
  border: 2px solid var(--surface);
  background: var(--green);
  animation: none;
}
.online-badge {
  background: color-mix(in srgb, var(--green) 16%, transparent);
  color: var(--green);
  font-weight: 600;
}

/* FAB */
.chat-create-wrap { right: 16px; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); z-index: 12; }
.chat-create-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--accent);
  font-size: 30px;
  font-weight: 300;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 38%, transparent);
}
.chat-create-menu {
  border: 0;
  border-radius: 14px;
  padding: 6px;
  background: var(--surface);
  box-shadow: var(--shadow), 0 0 0 1px var(--hairline);
}
.chat-create-menu button {
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

/* —— Chat —— */
.chat-shell {
  background: var(--chat-wallpaper, var(--chat-pattern));
}
.empty-state {
  gap: 10px;
  color: var(--muted);
}
.empty-state img {
  width: 88px;
  height: 88px;
  border-radius: 22px;
  box-shadow: var(--shadow-sm);
}
.empty-state strong {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--text);
}
.empty-state span { font-size: 14px; }

.call-btn, .video-btn { color: var(--accent); }
.video-btn { background: transparent; }

.messages {
  gap: 3px;
  padding: 10px 8px 12px;
}
.msg-row { margin: 1px 0; }
.bubble {
  max-width: min(78%, 480px);
  padding: 7px 10px 5px;
  border-radius: 14px;
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
  animation: msgIn .16s ease both;
}
.msg-row.out .bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-bottom-right-radius: 4px;
}
.msg-row.in .bubble {
  border-bottom-left-radius: 4px;
}
.bubble .body {
  font-size: 15px;
  line-height: 1.35;
  letter-spacing: 0;
}
.reply-quote {
  margin-bottom: 5px;
  padding: 3px 0 3px 8px;
  border-left: 2px solid var(--accent);
  color: inherit;
  opacity: 0.9;
  font-size: 13px;
}
.msg-row.out .reply-quote { border-left-color: var(--bubble-out-meta, var(--accent)); }
.meta {
  margin-top: 2px;
  color: var(--muted);
  opacity: 1;
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.msg-row.out .meta { color: var(--bubble-out-meta, var(--muted)); }
.msg-tick { color: var(--muted); opacity: 1; }
.msg-tick--read { color: var(--accent); opacity: 1; }
.msg-row.out .msg-tick { color: var(--bubble-out-meta, var(--muted)); }
.msg-row.out .msg-tick--read { color: var(--accent); }
.msg-row.in .msg-tick--read { color: var(--accent); opacity: 1; }
.date-sep {
  margin: 12px 0 8px;
  padding: 4px 10px;
  border-radius: 11px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  box-shadow: none;
}

.voice-play {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  box-shadow: none;
}
.msg-row.out .voice-play {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent);
}
.voice-wave span { background-color: color-mix(in srgb, currentColor 28%, transparent); }
.voice-wave span.played { background-color: currentColor; }
.msg-row.out .voice-wave span.played { background-color: var(--accent); }
.msg-row.out .voice-meta { color: var(--bubble-out-meta, var(--muted)); }

.typing-line {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
  font-weight: 500;
}
.typing-line:not(:empty)::before { background: var(--accent); }

/* —— Composer (Telegram bar) —— */
.composer-wrap {
  position: relative;
  z-index: 30;
  border-top: 1px solid var(--separator);
  background: var(--surface);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  padding-bottom: max(6px, var(--safe-bottom));
  isolation: isolate;
}
.composer {
  min-height: 50px;
  margin: 6px 8px 8px;
  padding: 4px 4px 4px 2px;
  gap: 2px;
  border: 0;
  border-radius: 24px;
  background: var(--surface-2);
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center;
  position: relative;
  z-index: 31;
  overflow: visible;
}
.composer-input {
  flex: 1 1 auto !important;
  grid-column: auto !important;
  height: 40px;
  border-radius: 20px;
  padding: 0 12px;
  background: transparent;
  font-size: 15px;
  box-shadow: none !important;
  min-width: 0;
}
.composer-input:focus { background: transparent; box-shadow: none !important; }
.composer .icon-btn {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  color: var(--accent);
  pointer-events: auto;
  position: relative;
  z-index: 32;
}
.send-btn, .voice-btn {
  flex: 0 0 42px !important;
  grid-column: auto !important;
  grid-row: auto !important;
  width: 42px !important;
  height: 42px !important;
  min-width: 42px !important;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  pointer-events: auto !important;
  touch-action: manipulation !important;
  z-index: 40;
  cursor: pointer;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.voice-btn {
  background: transparent;
  color: var(--accent);
  touch-action: none !important;
}
.voice-btn.recording {
  background: var(--red);
  color: #fff;
}
.composer .send-btn.hidden,
.composer .voice-btn.hidden {
  display: none !important;
}
.composer .send-btn:not(.hidden) {
  display: grid !important;
  place-items: center;
}
.reply-preview, .edit-preview {
  margin: 0 12px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--fill-3);
  border-left: 3px solid var(--accent);
  color: var(--text-soft);
  font-size: 13px;
}
#edit-preview {
  display: flex !important;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: var(--fill-3) !important;
  border-left: 3px solid var(--accent) !important;
}
#edit-preview.hidden { display: none !important; }
#edit-text {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#edit-cancel {
  flex: 0 0 auto;
  background: none;
  border: 0;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 6px;
}

/* —— Tab bar —— */
.tabbar {
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  border-top: 1px solid var(--separator);
  background: var(--surface);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  align-items: stretch;
  z-index: 15;
}
.tab {
  height: var(--tabbar-h);
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
}
.tab.active {
  color: var(--accent);
}
.tab .icon { width: 24px; height: 24px; stroke-width: 1.8; }
.tab.active .icon { filter: none; }

/* —— Settings —— */
.settings-card {
  margin: 0;
  padding: 0 12px 100px;
  max-width: 640px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  gap: 12px;
}
.settings-card::before { display: none; }
.avatar-block {
  margin-top: 12px;
  padding: 22px 16px;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.avatar-xl {
  width: 92px;
  height: 92px;
  flex-basis: 92px;
  font-size: 32px;
  border: 0;
  box-shadow: var(--shadow-sm);
}
.avatar-actions {
  background: transparent;
  padding: 0;
  gap: 8px;
}
.profile-form label,
.settings-modal-content label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}
.profile-form,
.settings-tools,
.wallpaper-section,
.apk-publish-section {
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  border: 0;
  overflow: hidden;
}
.profile-form { padding: 8px 14px 14px; gap: 12px; }
.settings-tools { display: grid; gap: 0; margin-top: 0; padding: 0; }
.settings-tools .secondary-btn,
.settings-tools .full {
  border-radius: 0;
  min-height: 48px;
  justify-content: flex-start;
  padding: 0 16px;
  background: transparent;
  border-bottom: 1px solid var(--separator);
  color: var(--text);
  font-weight: 400;
  font-size: 15px;
}
.settings-tools .secondary-btn:last-child { border-bottom: 0; }
#logout-btn {
  background: var(--surface-2);
  color: var(--red);
  border-radius: var(--radius-lg);
  font-weight: 500;
  font-size: 15px;
}
.wallpaper-section {
  padding: 14px 16px 16px !important;
  border-top: 0 !important;
  margin-top: 0 !important;
}

/* —— Modals —— */
.modal, .call-overlay {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.modal-card, .group-modal-card {
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.group-modal-card > header {
  min-height: 56px;
  border-bottom: 0.5px solid var(--separator);
  font-weight: 600;
}
.member-picker-row {
  border: 0;
  border-radius: 12px;
  background: var(--fill-3);
}
.info-avatar {
  border-radius: 50%;
  border-width: 3px;
  background: linear-gradient(145deg, var(--accent), var(--indigo));
  box-shadow: var(--shadow-sm);
}
.profile-cover {
  background: linear-gradient(135deg, #5AC8FA, #007AFF 50%, #5856D6);
}
.profile-cover--channel {
  background: linear-gradient(135deg, #AF52DE, #FF2D55 55%, #FF9500);
}

/* —— Calls —— */
.incoming-call-banner {
  border: 0;
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  box-shadow: var(--shadow);
}
.incoming-call-accept, .incoming-call-decline {
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
}
.tool-btn {
  background: rgba(255,255,255,0.14);
  border: 0;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.tool-btn.active { background: var(--accent); box-shadow: none; }
.green { background: var(--green); box-shadow: 0 8px 24px color-mix(in srgb, var(--green) 40%, transparent); }
.red { background: var(--red); box-shadow: 0 8px 24px color-mix(in srgb, var(--red) 40%, transparent); }

/* —— Menus / toast / media —— */
.message-menu {
  border: 0;
  border-radius: 14px;
  padding: 6px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  box-shadow: var(--shadow);
}
.message-menu button {
  min-height: 44px;
  border-radius: 10px;
  font-size: 17px;
  padding: 0 14px;
}
.toast {
  border-radius: 14px;
  padding: 12px 18px;
  background: color-mix(in srgb, #1C1C1E 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-size: 15px;
  font-weight: 500;
  bottom: calc(72px + var(--safe-bottom));
}
.selection-bar {
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  border: 0.5px solid var(--separator);
}
.file-message {
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.msg-row.out .file-message { background: rgba(255,255,255,.16); }

/* Stories */
.stories-bar {
  background: transparent;
  border-bottom: 0.5px solid var(--separator);
  padding: 12px 14px;
}
.story-circle-img {
  background: linear-gradient(45deg, #FF9500, #FF2D55 40%, #AF52DE 70%, #5856D6);
  padding: 2.5px;
}
.story-circle-img.mine { background: var(--fill); }
.story-circle-img.mine.has-story { background: var(--accent); }
.story-circle-name { font-size: 11px; color: var(--text-soft); font-weight: 500; }

/* Stickers / pinned / search */
.sticker-picker {
  border: 0;
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  box-shadow: var(--shadow);
}
.sticker-tabs { background: var(--fill-3); border-bottom: 0.5px solid var(--separator); }
.sticker-tab.active { color: var(--accent); font-weight: 600; }
.pinned-banner, .chat-search-bar {
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border-bottom: 0.5px solid var(--separator);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.chat-search-bar input {
  border: 0;
  background: var(--fill);
  border-radius: 10px;
  font-size: 16px;
}
#pinned-banner-click span:first-child { color: var(--accent); font-weight: 600; }

/* Polls */
.poll-option {
  border: 0;
  border-radius: 12px;
  background: var(--fill-3);
}
.poll-option.voted { box-shadow: inset 0 0 0 1.5px var(--accent); }
.poll-option .poll-bar { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* Reactions */
.reaction-pill {
  border-radius: 12px;
  background: var(--fill-2);
  border: 0;
}
.reaction-pill.active {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
}

/* Recording */
.recording-strip {
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-top: 0.5px solid var(--separator);
}
.recording-strip .record-send-btn { background: var(--accent); }

/* Desktop split */
@media (min-width: 820px) {
  .app {
    grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
    background: var(--surface);
  }
  .sidebar {
    background: var(--surface);
    border-right: 1px solid var(--separator);
  }
  .chat-shell {
    background: var(--chat-wallpaper, var(--chat-pattern));
  }
  .tabbar { display: none; }
  .chat-item { border-bottom-color: transparent; border-radius: 10px; margin: 0 6px; }
  .chat-item:hover, .chat-item.active { border-radius: 10px; }
  .list { padding: 4px 0 16px; gap: 1px; }
  .bubble { max-width: min(58%, 480px); }
}

/* Mobile chat open */
@media (max-width: 819px) {
  .app.chat-open {
    grid-template-rows: minmax(0, 1fr);
  }
}

/* Soft scrollbars */
.pane, .messages, .group-members-list {
  scrollbar-width: thin;
  scrollbar-color: var(--fill) transparent;
}
.pane::-webkit-scrollbar, .messages::-webkit-scrollbar { width: 6px; }
.pane::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb {
  background: var(--fill);
  border-radius: 999px;
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
