/* =========================================================
   ChatBox — design tokens (palette unchanged)
   ========================================================= */
:root {
  --font: 'Inter', 'Vazirmatn', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --fs: 16px;

  --primary: #4F6BF5;
  --primary-2: #7B5CF6;
  --accent: #5B6CF5;            /* solid violet-blue used for filled controls */
  --primary-grad: var(--accent); /* kept as alias: no gradients on controls */
  --primary-soft: #E8EDFF;
  --online: #12B76A;
  --danger: #E5484D;

  --bg: #F4F6FB;
  --bg-elev: #FFFFFF;
  --surface: #EEF1F8;
  --surface-2: #E4E8F2;
  --text: #0F172A;
  --text-2: #586178;
  --text-3: #727B91;
  --border: #E6EAF2;
  --hover: rgba(79, 107, 245, .06);
  --press: rgba(79, 107, 245, .12);

  --nav-bg: #0F1320;
  --nav-fg: rgba(255, 255, 255, .62);
  --nav-active: rgba(140, 152, 255, .16);
  --nav-accent: #A3AEFF;

  --bubble-in: #FFFFFF;
  --bubble-in-text: #0F172A;
  --bubble-out: var(--accent);
  --bubble-out-text: #FFFFFF;
  --bubble-out-meta: rgba(255,255,255,.8);
  --chat-bg: #EDF0F8;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 1px rgba(15, 23, 42, .03);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, .08), 0 2px 6px rgba(15, 23, 42, .04);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, .16), 0 4px 12px rgba(15, 23, 42, .06);
  --scrim: rgba(10, 14, 26, .38);

  --r-xl: 28px;

  --ease-out: cubic-bezier(.22, .9, .24, 1);
  --ease-in: cubic-bezier(.4, 0, 1, 1);
  --t-fast: 160ms; --t-med: 340ms; --t-exit: 240ms;

  --av-1: #F2645E;
  --av-2: #3D8FF6;
  --av-3: #22B573;
  --av-4: #F79A3E;
  --av-5: #8B6EF7;
  --av-6: #2FA9D6;
  --av-7: #E86A9C;
  --av-8: #6C72E0;
  --av-9: #F4A65F;

  --fade: rgba(10, 14, 26, .30);
  --fade-mid: rgba(10, 14, 26, .14);
  --sab: env(safe-area-inset-bottom);   /* 0 while the on-screen keyboard is open */
  --app-h: 100dvh;                      /* set from visualViewport on phones */
  --app-top: 0px;
  --hdr-h: 64px;
  --cmp-h: 112px;
  color-scheme: light;
}
:root[data-text="sm"] { --fs: 15px; }
:root[data-text="lg"] { --fs: 17.5px; }

:root[data-theme="dark"] {
  --primary: #7C8CFF; --primary-soft: #232A4A;
  --bg: #0D111C; --bg-elev: #161B29; --surface: #1C2233; --surface-2: #262D41;
  --text: #E9EDF6; --text-2: #A3ACC0; --text-3: #8790A6; --border: #222A3C;
  --hover: rgba(124, 140, 255, .07); --press: rgba(124, 140, 255, .14);
  --nav-bg: #1B2132; --nav-fg: rgba(255, 255, 255, .6); --nav-active: rgba(140, 152, 255, .16); --nav-accent: #A9B3FF;
  --bubble-in: #1E2436; --bubble-in-text: #E9EDF6;
  --chat-bg: #0A0E18;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .35);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, .55);
  --scrim: rgba(0, 0, 0, .55);
  --fade: rgba(0, 0, 0, .78);
  --fade-mid: rgba(0, 0, 0, .4);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #7C8CFF; --primary-soft: #232A4A;
    --bg: #0D111C; --bg-elev: #161B29; --surface: #1C2233; --surface-2: #262D41;
    --text: #E9EDF6; --text-2: #A3ACC0; --text-3: #8790A6; --border: #222A3C;
    --hover: rgba(124, 140, 255, .07); --press: rgba(124, 140, 255, .14);
    --nav-bg: #1B2132; --nav-fg: rgba(255, 255, 255, .6); --nav-active: rgba(140, 152, 255, .16); --nav-accent: #A9B3FF;
    --bubble-in: #1E2436; --bubble-in-text: #E9EDF6;
    --chat-bg: #0A0E18;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, .55);
    --scrim: rgba(0, 0, 0, .55);
    --fade: rgba(0, 0, 0, .78);
    --fade-mid: rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

/* =========================================================
   Base
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: var(--fs);
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 10px; }
.ic { width: 22px; height: 22px; display: block; flex: none; }
[data-icon] { display: inline-grid; place-items: center; }

* { scrollbar-width: thin; scrollbar-color: var(--surface-2) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* Buttons */
.round-btn {
  width: 44px; height: 44px; flex: none; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--bg-elev); color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: transform var(--t-fast) var(--ease-out), background-color var(--t-fast), box-shadow var(--t-fast);
}
.round-btn .ic { width: 20px; height: 20px; }
.round-btn:hover { box-shadow: var(--shadow-md); }
.round-btn:active { transform: scale(.92); }
.round-btn--primary { background: var(--accent); color: #fff; box-shadow: none; }
.round-btn--primary:hover { box-shadow: none; filter: brightness(1.06); }
.round-btn--ghost { background: transparent; box-shadow: none; color: var(--text-2); }
.round-btn--ghost:hover { background: var(--hover); box-shadow: none; }
.round-btn--sm { width: 34px; height: 34px; }
.round-btn--sm .ic { width: 17px; height: 17px; }

.pill-btn {
  height: 36px; padding: 0 16px; border-radius: 999px;
  background: var(--primary-grad); color: #fff; font-weight: 600; font-size: 14px;
  transition: transform var(--t-fast);
}
.pill-btn:active { transform: scale(.95); }
.pill-btn--glass { background: rgba(255,255,255,.22); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.pill-btn--soft { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }

.segmented {
  display: inline-flex; padding: 4px; gap: 2px;
  background: var(--surface); border-radius: 999px;
}
.segmented button {
  height: 34px; padding: 0 16px; border-radius: 999px;
  font-size: 14px; font-weight: 600; color: var(--text-3);
  transition: background-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}
.segmented button.is-active { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented--sm button { height: 30px; padding: 0 14px; font-size: 13px; }

/* =========================================================
   App shell
   ========================================================= */
.app {
  position: fixed; left: 0; right: 0;
  top: var(--app-top); height: var(--app-h);
  overflow: hidden; background: var(--bg);
}
.main {
  position: absolute; inset: 0;
  background: var(--bg);
  transition: transform var(--t-med) var(--ease-out);
}
.main::after {
  content: ''; position: absolute; inset: 0; z-index: 5;
  background: rgba(0, 0, 0, .16);
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-med) var(--ease-out);
}
.app.chat-open .main { transform: translateX(-22%); }
.app.chat-open .main::after { opacity: 1; }
.app.chat-closing .main { transition-duration: var(--t-exit); }

.view {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  opacity: 0; visibility: hidden;
  transform: translateY(8px);
  transition: opacity .22s var(--ease-out), transform .28s var(--ease-out), visibility 0s linear .22s;
}
.view.is-active { opacity: 1; visibility: visible; transform: none; transition: opacity .26s var(--ease-out), transform .32s var(--ease-out), visibility 0s; }

.view-head {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 18px) 20px 10px;
  min-height: 76px; flex: none;
}
.view-title { margin: 0; font-size: 32px; font-weight: 700; letter-spacing: -.8px; line-height: 1.1; flex: 1; }
.view-head__actions { display: flex; gap: 10px; }

.view-search { padding: 0 20px 6px; animation: dropIn .24s var(--ease-out); flex: none; }
.search {
  display: flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 16px;
  background: var(--bg-elev); border-radius: 999px;
  box-shadow: var(--shadow-sm);
  border: 1.5px solid transparent;
  transition: border-color var(--t-fast);
}
.search:focus-within { border-color: var(--primary); }
.search__icon { color: var(--text-3); }
.search__icon .ic { width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; outline: none; font-size: 15px; }
.search input::placeholder { color: var(--text-3); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }

.chips { display: flex; gap: 8px; padding: 6px 20px 10px; overflow-x: auto; scrollbar-width: none; flex: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 34px; padding: 0 15px; border-radius: 999px;
  font-size: 14px; font-weight: 600; color: var(--text-2);
  background: var(--bg-elev); box-shadow: var(--shadow-sm);
  transition: background-color var(--t-fast), color var(--t-fast);
}
.chip.is-active { background: var(--primary-soft); color: var(--primary); box-shadow: none; }

.scroller {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding-bottom: calc(112px + var(--sab));
}

/* =========================================================
   Floating tab bar — fixed in place, never scrolls
   ========================================================= */
.tabbar {
  position: absolute; z-index: 4;
  left: 50%; bottom: calc(14px + var(--sab));
  transform: translateX(-50%);
  width: min(calc(100% - 32px), 380px); height: 62px;
  padding: 6px;
  display: flex; gap: 4px;
  background: var(--nav-bg);
  border-radius: 999px;
  box-shadow: 0 16px 40px rgba(10, 14, 26, .28), inset 0 0 0 1px rgba(255,255,255,.05);
}
.tabbar__item {
  position: relative;
  flex: 1 1 0; min-width: 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 999px;
  color: var(--nav-fg);
  transition: flex-grow var(--t-med) var(--ease-out), background-color var(--t-med) var(--ease-out), color var(--t-fast), transform var(--t-fast);
}
.tabbar__item .ic { width: 23px; height: 23px; stroke-width: 1.6; transition: transform var(--t-med) var(--ease-out); }
.tabbar__item.is-active .ic { fill: currentColor; fill-opacity: .18; }
.tabbar__item b { font-weight: 600; font-size: 14.5px; max-width: 0; overflow: hidden; opacity: 0; white-space: nowrap; transition: max-width var(--t-med) var(--ease-out), opacity .2s; }
.tabbar__item:hover { color: #fff; }
.tabbar__item.is-active { flex-grow: 2.1; background: var(--nav-active); color: var(--nav-accent); }
.tabbar__item.is-active b { max-width: 90px; opacity: 1; }
.tabbar__item:active { transform: scale(.96); }
.tabbar__dot { position: absolute; top: 13px; left: calc(50% + 6px); width: 8px; height: 8px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 2px var(--nav-bg); }
.tabbar__item.is-active .tabbar__dot { display: none; }

/* =========================================================
   Chats list
   ========================================================= */
.chat-list { list-style: none; margin: 0; padding-top: 2px; padding-left: 8px; padding-right: 8px; }
.chat-item {
  display: flex; align-items: flex-start; gap: 14px;
  width: 100%; padding: 12px; border-radius: 20px;
  text-align: start;
  transition: background-color var(--t-fast), transform var(--t-fast);
  animation: rise .42s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 28ms);
}
.chat-item:hover { background: var(--hover); }
.chat-item:active { background: var(--press); transform: scale(.985); }
.chat-item.is-active { background: var(--primary-soft); }
.chat-item__body { flex: 1; min-width: 0; position: relative; }
.chat-list li + li .chat-item__body::before {
  content: ''; position: absolute; left: 0; right: -12px; top: -13px;
  border-top: 1px solid var(--border);
}
.chat-item__row { display: flex; align-items: center; gap: 8px; }
.chat-item__name { flex: 1; min-width: 0; font-weight: 600; font-size: 1em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.chat-item__name .ic { width: 14px; height: 14px; color: var(--text-3); }
.chat-item__time { font-size: 12.5px; color: var(--text-3); flex: none; display: flex; align-items: center; gap: 3px; }
.chat-item__time .ic { width: 16px; height: 16px; color: var(--primary); }
.chat-item__row--sub { align-items: flex-start; margin-top: 3px; }
.chat-item__preview {
  flex: 1; min-width: 0; font-size: .875em; line-height: 1.45; color: var(--text-2);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.chat-item__preview b { color: var(--text); font-weight: 600; }
.chat-item__preview .typing-text, .chat-item__preview .kind { color: var(--primary); }
.badge {
  flex: none; min-width: 20px; height: 20px; padding: 0 6px; margin-top: 3px;
  border-radius: 999px; box-sizing: border-box; line-height: 1;
  display: inline-grid; place-items: center;
  background: var(--primary); color: #fff;
  font-size: 11.5px; font-weight: 700;
  animation: pop .3s var(--ease-out);
}
.badge.is-muted { background: var(--text-3); }
.pin-ic { color: var(--text-3); flex: none; margin-top: 3px; }
.pin-ic .ic { width: 15px; height: 15px; transform: rotate(45deg); }
.empty-list { text-align: center; color: var(--text-3); padding: 48px 16px; font-size: 15px; list-style: none; grid-column: 1 / -1; }

/* =========================================================
   Avatars
   ========================================================= */
.avatar {
  position: relative; flex: none;
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 20px;
  background: var(--av-2);
}
.avatar--md { width: 48px; height: 48px; font-size: 18px; }
.avatar--sm { width: 40px; height: 40px; font-size: 16px; }
.avatar--xs { width: 30px; height: 30px; font-size: 13px; }
.avatar--lg { width: 60px; height: 60px; font-size: 23px; }
.avatar--xl { width: 104px; height: 104px; font-size: 40px; box-shadow: var(--shadow-md); }
.avatar .ic { width: 46%; height: 46%; }
.avatar.is-online::after {
  content: ''; position: absolute; bottom: 1px; right: 1px;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--online); border: 2.5px solid var(--bg);
}
.avatar--sm.is-online::after { width: 11px; height: 11px; border-width: 2px; border-color: var(--bg-elev); }
.av-1 { background: var(--av-1); } .av-2 { background: var(--av-2); } .av-3 { background: var(--av-3); }
.av-4 { background: var(--av-4); } .av-5 { background: var(--av-5); } .av-6 { background: var(--av-6); }
.av-7 { background: var(--av-7); } .av-8 { background: var(--av-8); } .av-9 { background: var(--av-9); }

/* =========================================================
   Calls
   ========================================================= */
.call-list { list-style: none; margin: 0; padding-left: 8px; padding-right: 8px; }
.call-item {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 12px; border-radius: 20px;
  animation: rise .4s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 26ms);
}
.call-item__body { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; position: relative; align-self: stretch; }
.call-list li + li .call-item__body::before { content: ''; position: absolute; left: 0; right: -12px; top: -11px; border-top: 1px solid var(--border); }
.call-item__text { flex: 1; min-width: 0; }
.call-item__name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call-item__dir { display: flex; align-items: center; gap: 5px; font-size: .84em; color: var(--text-3); margin-top: 1px; }
.call-item__dir .ic { width: 15px; height: 15px; }
.call-item__dir.is-missed { color: var(--danger); }
.call-item__time { font-size: 12.5px; color: var(--text-3); white-space: nowrap; }
.call-item .round-btn { width: 40px; height: 40px; color: var(--text-2); }
.call-item .round-btn .ic { width: 18px; height: 18px; }

/* =========================================================
   Contacts grid
   ========================================================= */
.contact-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px; padding: 4px 20px calc(112px + var(--sab));
  align-content: start;
}
.contact-card {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 20px 10px 16px;
  background: var(--bg-elev); border-radius: 24px;
  box-shadow: var(--shadow-sm);
  text-align: center; min-width: 0;
  transition: transform var(--t-fast) var(--ease-out), box-shadow var(--t-fast);
  animation: rise .42s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 30ms);
}
.contact-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.contact-card:active { transform: scale(.97); }
.contact-card .avatar { margin-bottom: 10px; }
.contact-card__name { font-weight: 600; font-size: .95em; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-card__status { font-size: 12.5px; color: var(--text-3); display: inline-flex; align-items: center; gap: 5px; }
.contact-card__status.is-online::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--online); }
.contact-card__status.is-online { color: var(--text-2); }

/* =========================================================
   Settings
   ========================================================= */
.settings { padding: calc(env(safe-area-inset-top) + 14px) 16px calc(112px + var(--sab)); }
.settings__top { display: flex; justify-content: flex-end; }
.me-card { text-align: center; padding: 0 0 14px; animation: rise .4s var(--ease-out) both; }
.me-card .avatar { margin: 0 auto 14px; }
.me-card__name { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -.6px; }
.me-card__sub { margin-top: 4px; color: var(--text-3); font-size: 14px; }
.me-card__bio { margin-top: 6px; color: var(--text-2); font-size: 14.5px; }
.group-label { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .6px; padding: 16px 8px 8px; }
.card { background: var(--bg-elev); border-radius: 22px; padding: 6px; box-shadow: var(--shadow-sm); animation: rise .4s var(--ease-out) both; animation-delay: 60ms; }
.s-row {
  position: relative;
  width: 100%; display: flex; align-items: center; gap: 14px;
  min-height: 52px; padding: 8px 10px; border-radius: 16px;
  text-align: start;
  transition: background-color var(--t-fast);
}
button.s-row:hover { background: var(--hover); }
.s-row__ic { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; flex: none; }
.s-row__ic .ic { width: 18px; height: 18px; }
.s-row__label { flex: 1; min-width: 0; font-weight: 500; }
.s-row__value { color: var(--text-3); font-size: 14px; display: flex; align-items: center; gap: 4px; }
.s-row__value .ic { width: 18px; height: 18px; }
.s-row + .s-row::before { content: ''; position: absolute; top: 0; left: 58px; right: 10px; border-top: 1px solid var(--border); }
.switch { width: 46px; height: 28px; border-radius: 14px; background: var(--surface-2); position: relative; transition: background-color var(--t-fast); flex: none; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform var(--t-fast) var(--ease-out); }
.switch.is-on { background: var(--primary); }
.switch.is-on::after { transform: translateX(18px); }
.app-version { text-align: center; color: var(--text-3); font-size: 12.5px; padding: 20px 0 0; }

/* =========================================================
   Chat screen
   ========================================================= */
.chat-screen {
  position: absolute; inset: 0; z-index: 6;
  background: var(--chat-bg);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform var(--t-exit) var(--ease-in), visibility 0s linear var(--t-exit);
}
.app.chat-open .chat-screen { transform: none; visibility: visible; box-shadow: var(--shadow-lg); transition: transform var(--t-med) var(--ease-out); }
.app.chat-closing .chat-screen { box-shadow: var(--shadow-lg); }

/* Messages dissolve into the background under the floating header and composer.
   A mask fades the content itself, so there is no overlay box with visible edges. */
.messages {
  --fade-top: calc(var(--hdr-h) + 10px + env(safe-area-inset-top));
  --fade-bot: calc(var(--cmp-h) + 10px + var(--sab));
  -webkit-mask-image: linear-gradient(to bottom,
    transparent 0,
    transparent calc(var(--fade-top) * .8),
    #000 calc(var(--fade-top) + 30px),
    #000 calc(100% - var(--fade-bot) - 30px),
    transparent calc(100% - var(--fade-bot) * .8),
    transparent 100%);
          mask-image: linear-gradient(to bottom,
    transparent 0,
    transparent calc(var(--fade-top) * .8),
    #000 calc(var(--fade-top) + 30px),
    #000 calc(100% - var(--fade-bot) - 30px),
    transparent calc(100% - var(--fade-bot) * .8),
    transparent 100%);
}

.chat-header {
  position: absolute; z-index: 4;
  top: calc(10px + env(safe-area-inset-top)); left: 10px; right: 10px;
  max-width: 760px; margin: 0 auto;
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
  padding: 6px;
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-radius: 26px;
  box-shadow: var(--shadow-lg), 0 0 0 1px color-mix(in srgb, var(--border) 60%, transparent);
}
.chat-header .back-btn { width: 44px; height: 44px; }
.peer-av { margin-right: 2px; }
.peer { display: flex; flex-direction: column; align-items: center; min-width: 0; padding: 2px 8px; border-radius: 14px; line-height: 1.25; }
.peer:hover { background: var(--hover); }
.peer__name { font-weight: 700; font-size: 17px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.2px; }
.peer__status { font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.peer__status.is-online, .peer__status.is-typing { color: var(--primary); }
.peer-av { justify-self: end; border-radius: 50%; transition: transform var(--t-fast); }
.peer-av:active { transform: scale(.92); }

.typing-dots { display: inline-flex; gap: 3px; margin-inline-end: 5px; vertical-align: middle; }
.typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: dot 1.2s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }

.messages {
  position: absolute; inset: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: calc(var(--hdr-h) + 22px + env(safe-area-inset-top)) 12px calc(var(--cmp-h) + 30px + var(--sab));
  display: flex; flex-direction: column;
}
.messages > :first-child { margin-top: auto; }

.day-sep { align-self: center; margin: 14px 0 8px; position: sticky; top: 4px; z-index: 1; }
.day-sep span {
  display: inline-block; padding: 4px 12px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600;
  background: color-mix(in srgb, var(--bg-elev) 80%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  color: var(--text-2); box-shadow: var(--shadow-sm);
}

.msg-row { display: flex; align-items: flex-end; gap: 6px; margin-top: 8px; }
.msg-row.is-grouped { margin-top: 2px; }
.msg-row.out { justify-content: flex-end; }
.msg-row.in { justify-content: flex-start; }
.msg-row.in .row-av { visibility: hidden; }
.msg-row.in.is-last .row-av { visibility: visible; }
.msg-row.enter { animation: msgIn .32s var(--ease-out) both; }
.msg-row.out.enter { transform-origin: right bottom; }
.msg-row.in.enter { transform-origin: left bottom; }

.bubble {
  position: relative;
  max-width: min(78%, 520px);
  padding: 8px 13px 7px;
  border-radius: 20px;
  font-size: .97em; line-height: 1.5;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--t-fast), filter var(--t-fast);
}
.bubble:active { transform: scale(.985); }
.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); }
.in  .bubble { background: var(--bubble-in); color: var(--bubble-in-text); }
.out .bubble { border-bottom-right-radius: 6px; }
.in .bubble { border-bottom-left-radius: 6px; }
.out.is-grouped .bubble { border-top-right-radius: 6px; }
.in.is-grouped .bubble { border-top-left-radius: 6px; }
.bubble.is-highlight { animation: flash 1s var(--ease-out); }

.bubble__sender { display: block; font-size: 13.5px; font-weight: 700; margin-bottom: 1px; }
.bubble__text { white-space: pre-wrap; unicode-bidi: plaintext; }
.bubble__text.is-jumbo { font-size: 42px; line-height: 1.2; }
.bubble.is-bare { background: transparent !important; box-shadow: none; padding: 0; }
.out .bubble.is-bare { color: var(--text); }
.out .bubble.is-bare .meta:not(.meta--overlay) { color: var(--text-3); }
.bubble.is-bare .reaction:not(.is-mine) { background: var(--primary-soft); color: var(--primary); }

.meta {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11.5px; line-height: 1; white-space: nowrap;
  color: var(--text-3); user-select: none;
  padding-bottom: 1px;
}
.bubble__foot { display: flex; align-items: flex-end; gap: 10px; margin-top: 3px; min-height: 14px; }
.bubble__foot .reactions { margin-top: 2px; }
.has-media .bubble__foot { padding: 0 8px 4px; }
.has-media .media + .bubble__foot { padding-top: 6px; }
.out .meta { color: var(--bubble-out-meta); }
.meta .ic { width: 18px; height: 18px; stroke-width: 1.9; margin-right: -2px; }
.meta .is-sending { animation: spin 1s linear infinite; width: 12px; height: 12px; border: 1.6px solid currentColor; border-top-color: transparent; border-radius: 50%; }
.meta--overlay {
  position: absolute; top: auto; bottom: 8px; right: 8px; float: none; margin: 0;
  padding: 4px 7px; border-radius: 999px;
  background: rgba(0, 0, 0, .45); color: #fff !important;
  backdrop-filter: blur(6px);
}

.quote {
  display: block; margin: 2px 0 6px; padding: 4px 10px;
  border-left: 3px solid var(--primary); border-radius: 6px;
  background: var(--hover);
  font-size: 13.5px; line-height: 1.45; max-width: 100%; overflow: hidden;
}
.out .quote { border-color: rgba(255,255,255,.85); background: rgba(255,255,255,.16); }
.quote strong { display: block; font-size: 13px; color: var(--primary); }
.out .quote strong { color: #fff; }
.quote span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85; }

.bubble.has-media { padding: 4px; }
.bubble.has-media .bubble__text { display: block; padding: 6px 8px 0; }
.bubble.has-media .bubble__sender { padding: 2px 8px 4px; }
.media { position: relative; display: block; border-radius: 16px; overflow: hidden; background: var(--surface); max-width: 320px; min-width: 180px; }
.media img, .media video { display: block; width: 100%; height: auto; max-height: 360px; object-fit: cover; }
.media .play {
  position: absolute; inset: 0; margin: auto;
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(0,0,0,.45); color: #fff; backdrop-filter: blur(6px); pointer-events: none;
}
.media .play .ic { width: 22px; height: 22px; margin-left: 3px; fill: currentColor; }
.gif-msg { position: relative; }
.gif-msg img { width: 150px; height: 150px; display: block; object-fit: contain; }
.sticker-msg img { width: 140px; height: 140px; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; padding-top: 8px; }
.sticker-grid button { aspect-ratio: 1; border-radius: 16px; display: grid; place-items: center; transition: transform var(--t-fast), background-color var(--t-fast); }
.sticker-grid button:hover { background: var(--hover); transform: scale(1.06); }
.sticker-grid img { width: 80%; height: 80%; object-fit: contain; }
.gif-msg .meta--overlay { bottom: 0; }

.file-msg { display: flex; align-items: center; gap: 12px; min-width: 220px; padding: 4px 0 2px; }
.file-msg__ic { width: 46px; height: 46px; border-radius: 14px; flex: none; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.out .file-msg__ic { background: rgba(255,255,255,.2); color: #fff; }
.file-msg__name { font-weight: 600; font-size: 14.5px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.file-msg__size { font-size: 12.5px; opacity: .75; }

.loc { display: block; width: 260px; max-width: 100%; border-radius: 16px; overflow: hidden; background: var(--surface); text-decoration: none; color: inherit; isolation: isolate; }
.loc__map { position: relative; display: block; height: 150px; overflow: hidden; background: #dfe7ef; }
.loc__tiles { position: absolute; width: 768px; height: 768px; display: grid; grid-template-columns: repeat(3, 256px); }
.loc__tiles img { width: 256px; height: 256px; display: block; }
.loc__pin { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -100%); filter: drop-shadow(0 4px 6px rgba(0,0,0,.3)); }
.loc__pin svg { width: 36px; height: 36px; fill: #F5576C; stroke: #fff; display: block; }
.loc__info { display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-size: 13.5px; }
.loc__info strong { display: block; font-size: 14px; }
.loc__info span { opacity: .75; font-size: 12.5px; }
.loc__info .ic { width: 18px; height: 18px; flex: none; opacity: .8; }
.out .loc { background: rgba(255,255,255,.14); }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; }
.reaction { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 9px; border-radius: 999px; font-size: 14px; font-weight: 600; background: var(--primary-soft); color: var(--primary); animation: pop .3s var(--ease-out); }
.out .reaction { background: rgba(255,255,255,.2); color: #fff; }
.reaction.is-mine { background: var(--primary); color: #fff; }
.out .reaction.is-mine { background: #fff; color: var(--primary-2); }
.reaction small { font-size: 12px; }

.typing-bubble { padding: 12px 14px; }
.typing-bubble .typing-dots i { width: 7px; height: 7px; background: var(--text-3); }

.to-bottom {
  position: absolute; right: 16px; z-index: 3;
  bottom: calc(var(--cmp-h) + 24px + var(--sab));
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--bg-elev); color: var(--text-2); box-shadow: var(--shadow-md);
  opacity: 0; transform: translateY(10px) scale(.9); pointer-events: none;
  transition: opacity var(--t-fast), transform var(--t-fast);
}
.to-bottom.is-visible { opacity: 1; transform: none; pointer-events: auto; }

/* ---------- Composer: separate clip button + compact message pill ---------- */
.composer {
  position: absolute; z-index: 4;
  left: 10px; right: 10px; bottom: calc(10px + var(--sab));
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
}
.clip-btn, .composer__box {
  background: var(--bg-elev);
  box-shadow: var(--shadow-lg), 0 0 0 1px color-mix(in srgb, var(--border) 60%, transparent);
}
.clip-btn {
  width: 46px; height: 46px; flex: none; border-radius: 50%;
  display: grid; place-items: center; color: var(--text-2);
  transition: transform var(--t-fast) var(--ease-out), color var(--t-fast), background-color var(--t-fast);
}
.clip-btn .ic { width: 21px; height: 21px; transition: transform var(--t-med) var(--ease-out); }
.clip-btn:hover { color: var(--text); }
.clip-btn:active { transform: scale(.92); }
.clip-btn[aria-expanded="true"] { color: var(--primary); }
.clip-btn[aria-expanded="true"] .ic { transform: rotate(-45deg); }
.composer__box { flex: 1; min-width: 0; border-radius: 23px; padding: 3px; }
.composer__row { display: flex; align-items: flex-end; gap: 2px; }
.composer textarea {
  flex: 1; min-width: 0; display: block;
  resize: none; border: 0; outline: none; background: transparent;
  max-height: 132px; min-height: 40px;
  padding: 9px 4px;
  font-size: 16px; line-height: 1.375;
}
.composer textarea::placeholder { color: var(--text-3); }
.tool-btn {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: var(--text-3);
  transition: background-color var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.tool-btn .ic { width: 21px; height: 21px; }
.tool-btn:hover { color: var(--text); }
.tool-btn:active { transform: scale(.9); }
.tool-btn[aria-expanded="true"] { color: var(--primary); }

.send-btn {
  flex: none; height: 34px; margin: 3px; padding: 0 15px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary-grad); color: #fff;
  font-weight: 600; font-size: 14.5px; letter-spacing: .1px;
  transition: transform var(--t-fast) var(--ease-out), opacity var(--t-fast), box-shadow var(--t-fast);
}
.send-btn:active { transform: scale(.93); }
.send-btn:disabled { opacity: .35; box-shadow: none; cursor: default; }
.send-btn.pulse { animation: sendPulse .3s var(--ease-out); }
.send-btn--icon { width: 46px; height: 46px; padding: 0; margin: 0; }
.send-btn--icon .ic { width: 19px; height: 19px; }

.reply-bar { display: flex; align-items: center; gap: 10px; padding: 4px 2px 4px 10px; animation: dropIn .22s var(--ease-out); }
.reply-bar__icon { color: var(--primary); }
.reply-bar__icon .ic { width: 18px; height: 18px; }
.reply-bar__text { flex: 1; min-width: 0; border-left: 3px solid var(--primary); padding-left: 10px; line-height: 1.35; }
.reply-bar__text strong { display: block; font-size: 13px; color: var(--primary); }
.reply-bar__text span { display: block; font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Popovers floating above the composer ---------- */
.popover {
  position: absolute; z-index: 5;
  bottom: calc(var(--cmp-h) + 20px + var(--sab));
  background: var(--bg-elev);
  border-radius: 24px;
  box-shadow: var(--shadow-lg), 0 0 0 1px color-mix(in srgb, var(--border) 60%, transparent);
  animation: popUp .26s var(--ease-out);
}
.popover.is-leaving { animation: popDown .16s var(--ease-in) forwards; }
.attach-pop { left: 10px; width: 210px; padding: 6px; transform-origin: 23px 100%; }
.pop-item { width: 100%; display: flex; align-items: center; gap: 12px; height: 50px; padding: 0 8px; border-radius: 16px; font-weight: 500; text-align: start; transition: background-color var(--t-fast); }
.pop-item:hover { background: var(--hover); }
.pop-item__ic { width: 32px; height: 32px; display: grid; place-items: center; color: var(--text-2); flex: none; }
.pop-item__ic .ic { width: 21px; height: 21px; }
.pop-item { gap: 10px; height: 46px; font-size: 15px; }
.pop-item__gif { font-size: 11px; font-weight: 800; letter-spacing: .4px; }
.c-violet { background: var(--av-5); } .c-blue { background: var(--av-2); }
.c-green { background: var(--av-3); } .c-pink { background: var(--av-7); }
.c-orange { background: var(--av-4); } .c-teal { background: var(--av-6); }

.emoji-pop { left: 10px; right: 10px; max-width: 760px; margin: 0 auto; height: min(340px, 48dvh); display: flex; flex-direction: column; overflow: hidden; transform-origin: 50% 100%; }
.emoji-pop__tabs { margin: 10px auto 2px; flex: none; }
.emoji-pop__body { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 10px 12px; overscroll-behavior: contain; }
.emoji-cat { font-size: 12px; font-weight: 600; color: var(--text-3); padding: 10px 6px 4px; text-transform: uppercase; letter-spacing: .5px; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
.emoji-grid button {
  height: 44px; font-size: 26px; line-height: 1; border-radius: 12px;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  transition: transform var(--t-fast), background-color var(--t-fast);
}
.emoji-grid button:hover { background: var(--hover); transform: scale(1.15); }
.gif-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; padding-top: 8px; }
.gif-grid button { aspect-ratio: 1; border-radius: 16px; background: var(--surface); display: grid; place-items: center; overflow: hidden; transition: transform var(--t-fast); }
.gif-grid button:hover { transform: scale(1.04); }
.gif-grid img { width: 76%; height: 76%; object-fit: contain; }
.gif-grid .gif-upload { color: var(--primary); font-size: 12.5px; font-weight: 600; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }

/* =========================================================
   Sheets (floating cards), scrim, ctx menu, lightbox, toast
   ========================================================= */
.scrim { position: fixed; inset: 0; z-index: 20; background: var(--scrim); animation: fade .24s var(--ease-out); }
.scrim.is-leaving { animation: fadeOut .2s var(--ease-in) forwards; }

.sheet {
  position: fixed; z-index: 21;
  left: 10px; right: 10px; bottom: calc(10px + var(--sab));
  max-width: 520px; margin: 0 auto;
  background: var(--bg-elev);
  border-radius: var(--r-xl);
  padding: 10px 14px 16px;
  box-shadow: var(--shadow-lg);
  animation: sheetIn .36s var(--ease-out);
}
.sheet.is-leaving { animation: sheetOut .22s var(--ease-in) forwards; }
.sheet--tall { max-height: 84dvh; display: flex; flex-direction: column; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet__head strong { font-size: 17px; }
.sheet__spacer { width: 44px; }

.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; overflow-y: auto; padding-bottom: 12px; }
.preview-grid.is-single { grid-template-columns: 1fr; }
.preview-item { position: relative; border-radius: 18px; overflow: hidden; background: var(--surface); aspect-ratio: 1; }
.preview-grid.is-single .preview-item { aspect-ratio: auto; max-height: 52dvh; display: grid; place-items: center; }
.preview-item img, .preview-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview-grid.is-single .preview-item img, .preview-grid.is-single .preview-item video { object-fit: contain; max-height: 52dvh; }
.preview-item .file-msg { padding: 12px; }
.preview-foot { display: flex; gap: 8px; align-items: center; }
.preview-foot input { flex: 1; height: 46px; padding: 0 18px; border-radius: 23px; border: 0; outline: none; background: var(--surface); font-size: 16px; }
.preview-foot input:focus { box-shadow: inset 0 0 0 1.5px var(--primary); }

.pick-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.member { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 16px; width: 100%; text-align: start; transition: background-color var(--t-fast); }
.member:hover { background: var(--hover); }
.member__name { font-weight: 600; font-size: 15px; }
.member__sub { font-size: 13px; color: var(--text-3); }
.member__sub.is-online { color: var(--primary); }

.form { display: flex; flex-direction: column; gap: 10px; padding: 4px 2px 2px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field span { font-size: 13px; font-weight: 600; color: var(--text-2); padding-left: 4px; }
.field input { height: 48px; padding: 0 16px; border-radius: 16px; border: 1.5px solid transparent; background: var(--surface); outline: none; font-size: 16px; transition: border-color var(--t-fast); }
.field input:focus { border-color: var(--primary); background: var(--bg-elev); }

.ctx {
  position: fixed; z-index: 30;
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  transform-origin: var(--ox, 50%) var(--oy, 0%);
}
.ctx.is-leaving { animation: ctxOut .14s var(--ease-in) forwards; }
/* Two separate floating boxes: reactions pill + actions menu */
.ctx__reacts {
  display: flex; gap: 2px; padding: 5px;
  background: var(--bg-elev); border-radius: 999px;
  box-shadow: var(--shadow-lg), 0 0 0 1px color-mix(in srgb, var(--border) 60%, transparent);
  animation: ctxIn .22s var(--ease-out);
  transform-origin: var(--ox, 50%) 100%;
}
.ctx__reacts button { width: 42px; height: 42px; border-radius: 50%; font-size: 25px; transition: transform var(--t-fast) var(--ease-out), background-color var(--t-fast); animation: pop .32s var(--ease-out) both; }
.ctx__reacts button:nth-child(2) { animation-delay: 25ms; } .ctx__reacts button:nth-child(3) { animation-delay: 50ms; }
.ctx__reacts button:nth-child(4) { animation-delay: 75ms; } .ctx__reacts button:nth-child(5) { animation-delay: 100ms; }
.ctx__reacts button:nth-child(6) { animation-delay: 125ms; }
.ctx__reacts button:hover { transform: scale(1.22); background: var(--hover); }
.ctx__reacts button.is-mine { background: var(--primary-soft); }
.ctx__menu {
  min-width: 220px; padding: 6px;
  background: var(--bg-elev); border-radius: 22px;
  box-shadow: var(--shadow-lg), 0 0 0 1px color-mix(in srgb, var(--border) 60%, transparent);
  animation: ctxIn .22s var(--ease-out) both; animation-delay: 30ms;
  transform-origin: var(--ox, 50%) 0%;
}
.ctx__item { width: 100%; display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 12px; border-radius: 14px; font-size: 15px; text-align: start; transition: background-color var(--t-fast); }
.ctx__item:hover { background: var(--hover); }
.ctx__item .ic { width: 20px; height: 20px; color: var(--text-2); }
.ctx__item.is-danger, .ctx__item.is-danger .ic { color: var(--danger); }
.ctx__sep { height: 1px; background: var(--border); margin: 4px 8px; }

/* Delete confirmation */
.confirm { text-align: center; padding: 12px 8px 14px; }
.confirm__ic { width: 52px; height: 52px; border-radius: 50%; background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); margin-bottom: 10px; }
.confirm strong { display: block; font-size: 18px; }
.confirm p { margin: 4px 0 0; color: var(--text-2); font-size: 14.5px; }
.confirm__actions { display: flex; flex-direction: column; gap: 8px; }
.confirm-btn { height: 50px; border-radius: 16px; font-weight: 600; background: var(--surface); transition: transform var(--t-fast), filter var(--t-fast); }
.confirm-btn:active { transform: scale(.98); }
.confirm-btn.is-danger { background: var(--danger); color: #fff; }
.confirm-btn.is-danger-soft { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

/* Forwarded / edited markers in bubbles */
.fwd { display: flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 600; opacity: .85; margin-bottom: 2px; }
.fwd .ic { width: 14px; height: 14px; }
.in .fwd { color: var(--primary); }
.has-media .fwd { padding: 4px 8px 2px; }
.meta__edited { font-style: italic; margin-right: 2px; }

.lightbox { position: fixed; inset: 0; z-index: 40; background: rgba(5, 7, 12, .92); display: grid; place-items: center; animation: fade .2s var(--ease-out); }
.lightbox__body { max-width: 96vw; max-height: 88dvh; animation: zoomIn .3s var(--ease-out); }
.lightbox__body img, .lightbox__body video { max-width: 96vw; max-height: 88dvh; display: block; border-radius: 14px; }
.lightbox__close { position: absolute; top: calc(env(safe-area-inset-top) + 12px); right: 12px; color: #fff; background: rgba(255,255,255,.12); box-shadow: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--sab)); z-index: 50;
  transform: translateX(-50%); max-width: calc(100vw - 32px);
  padding: 11px 18px; border-radius: 999px;
  background: #1B2133; color: #fff; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn .28s var(--ease-out);
}

/* =========================================================
   Profile
   ========================================================= */
.profile { position: fixed; inset: 0; z-index: 25; background: var(--bg); animation: pushIn var(--t-med) var(--ease-out); }
.profile.is-leaving { animation: pushOut var(--t-exit) var(--ease-in) forwards; }
.profile__scroll { height: 100%; overflow-y: auto; overscroll-behavior: contain; }
.hero {
  position: relative; overflow: hidden;
  height: min(58dvh, 460px); min-height: 380px;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 0 20px 44px;
  color: #fff;
}
.hero::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.12) 0%, rgba(0,0,0,0) 30%, rgba(0,0,0,.06) 55%, rgba(0,0,0,.42) 100%);
}
.hero__mark {
  position: absolute; inset: 0 0 80px;
  display: grid; place-items: center;
  font-size: min(48vw, 220px); font-weight: 800; line-height: 1;
  color: rgba(255,255,255,.24);
  animation: zoomIn .5s var(--ease-out) both;
}
.hero__mark .ic { width: 36%; height: 36%; }
.hero__top { position: absolute; left: 14px; right: 14px; top: calc(env(safe-area-inset-top) + 12px); display: flex; justify-content: space-between; z-index: 1; }
.glass-btn { background: rgba(255,255,255,.2); color: #fff; box-shadow: none; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.glass-btn:hover { background: rgba(255,255,255,.3); box-shadow: none; }
.hero__body { position: relative; z-index: 1; animation: rise .45s var(--ease-out) both; animation-delay: 80ms; }
.hero__name { margin: 0; font-size: 32px; font-weight: 700; letter-spacing: -.8px; line-height: 1.15; text-align: center; text-shadow: 0 2px 12px rgba(0,0,0,.2); }
.hero__status { text-align: center; font-size: 14px; opacity: .92; margin-top: 4px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.hero__status.is-online::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #4ADE80; }
.hero__actions { display: flex; justify-content: center; gap: 22px; margin-top: 20px; }
.hero-action { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500; color: #fff; }
.hero-action > span:first-child { width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.22); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); transition: transform var(--t-fast), background-color var(--t-fast); }
.hero-action:hover > span:first-child { background: rgba(255,255,255,.32); }
.hero-action:active > span:first-child { transform: scale(.9); }
.hero-action .ic { width: 21px; height: 21px; }

.profile__sheet {
  position: relative; margin-top: -24px;
  background: var(--bg); border-radius: 28px 28px 0 0;
  padding: 16px 14px 32px;
  animation: rise .45s var(--ease-out) both; animation-delay: 100ms;
}
.info-row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 12px; width: 100%; text-align: start; }
.info-row + .info-row { border-top: 1px solid var(--border); }
.info-row > .ic { width: 19px; height: 19px; color: var(--text-3); }
.info-row__label { font-weight: 500; flex: none; }
.info-row__value { margin-left: auto; color: var(--text-2); text-align: right; font-size: 14.5px; overflow-wrap: anywhere; min-width: 0; }
.p-tabs { display: flex; justify-content: center; margin: 16px 0 12px; }
.p-tabs .segmented button { display: inline-flex; align-items: center; gap: 6px; }
.p-tabs .segmented .ic { width: 16px; height: 16px; }
.p-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.p-grid button { aspect-ratio: 1; background: var(--surface); position: relative; overflow: hidden; border-radius: 16px; transition: transform var(--t-fast); }
.p-grid button:active { transform: scale(.96); }
.p-grid img, .p-grid video { width: 100%; height: 100%; object-fit: cover; display: block; }
.p-empty { padding: 28px 10px; text-align: center; color: var(--text-3); font-size: 14px; }
.p-list .info-row__value { margin-left: 0; text-align: left; }
.p-link { color: var(--primary); text-decoration: none; overflow-wrap: anywhere; }

/* =========================================================
   Animations
   ========================================================= */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes dropIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes msgIn { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }
@keyframes dot { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-3px); opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; } }
@keyframes popUp { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes popDown { to { opacity: 0; transform: translateY(8px) scale(.97); } }
@keyframes sheetIn { from { transform: translateY(calc(100% + 20px)); } to { transform: none; } }
@keyframes sheetOut { to { transform: translateY(calc(100% + 20px)); } }
@keyframes ctxIn { from { opacity: 0; transform: scale(.88); } to { opacity: 1; transform: none; } }
@keyframes ctxOut { to { opacity: 0; transform: scale(.94); } }
@keyframes zoomIn { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: none; } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes pushIn { from { transform: translateX(100%); } to { transform: none; } }
@keyframes pushOut { to { transform: translateX(100%); } }
@keyframes sendPulse { 0% { transform: scale(1); } 40% { transform: scale(.88); } 100% { transform: scale(1); } }
@keyframes fly { 0% { transform: none; } 45% { transform: translate(8px, -8px) scale(.7); opacity: 0; } 46% { transform: translate(-8px, 8px) scale(.7); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes flash { 0%, 100% { filter: none; } 30% { filter: brightness(1.25) saturate(1.2); } }

/* =========================================================
   Desktop / tablet: two-pane layout
   ========================================================= */
@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 400px 1fr; grid-template-rows: minmax(0, 1fr); }
  .main { position: relative; inset: auto; transform: none !important; border-right: 1px solid var(--border); }
  .main::after { display: none; }
  .chat-screen { position: relative; inset: auto; transform: none !important; box-shadow: none !important; transition: none; visibility: visible; grid-column: 2; grid-row: 1; }
  .chat-screen.swap .messages { animation: rise .3s var(--ease-out); }
  .empty-pane { display: grid; place-items: center; grid-column: 2; grid-row: 1; background: var(--chat-bg); }
  .app.chat-open .empty-pane { display: none; }
  .empty-pane__card { text-align: center; color: var(--text-2); background: color-mix(in srgb, var(--bg-elev) 75%, transparent); padding: 22px 30px; border-radius: 24px; backdrop-filter: blur(10px); }
  .empty-pane__card p { margin: 10px 0 0; font-weight: 600; }
  .empty-pane__icon { display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 18px; background: var(--primary-grad); color: #fff; }
  .back-btn { visibility: hidden; }
  .profile { inset: 0 0 0 auto; width: 420px; border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); }
  .messages { padding-left: 6%; padding-right: 6%; }
  .composer { left: 24px; right: 24px; bottom: 18px; }
  .chat-header { left: 24px; right: 24px; top: 18px; }
  .emoji-pop { left: 24px; right: 24px; }
  .attach-pop { left: 26px; }
  .popover { bottom: calc(var(--cmp-h) + 28px); }
}
@media (max-width: 899px) { .empty-pane { display: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}
:root[data-motion="off"] *, :root[data-motion="off"] *::before, :root[data-motion="off"] *::after {
  animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important;
}

/* =========================================================
   Chat list: selection mode + context menu extras
   ========================================================= */
.select-head { animation: dropIn .22s var(--ease-out); }
.select-count { flex: 1; min-width: 0; font-size: 19px; font-weight: 700; letter-spacing: -.3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.select-head { gap: 8px; }
.select-head .round-btn { width: 40px; height: 40px; }
.select-head .round-btn .ic { width: 19px; height: 19px; }
.select-head .round-btn:disabled { opacity: .4; pointer-events: none; }
.round-btn--danger { color: var(--danger); }
.sel-check {
  position: absolute; right: -2px; bottom: -2px;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--bg-elev); color: transparent;
  border: 2px solid var(--text-3);
  transition: background-color var(--t-fast), border-color var(--t-fast), transform var(--t-fast) var(--ease-out);
}
.sel-check .ic { width: 13px; height: 13px; stroke-width: 3; }
.chat-item.is-selected .sel-check { background: var(--accent); border-color: var(--bg); color: #fff; animation: pop .26s var(--ease-out); }
.chat-item.is-selected { background: var(--primary-soft); }
.selecting .avatar.is-online::after { display: none; }
.ctx--plain .ctx__menu { animation-delay: 0ms; }

/* =========================================================
   Voice & video messages
   ========================================================= */
.composer__box { position: relative; }
.rec-btn {
  position: relative;
  width: 46px; height: 46px; flex: none; border-radius: 50%;
  display: grid; place-items: center; color: var(--text-2);
  background: var(--bg-elev);
  box-shadow: var(--shadow-lg), 0 0 0 1px color-mix(in srgb, var(--border) 60%, transparent);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform var(--t-fast) var(--ease-out), background-color var(--t-fast), color var(--t-fast);
}
.rec-btn:hover { color: var(--text); }
.rec-btn__ic { display: grid; place-items: center; }
.rec-btn__ic .ic { width: 21px; height: 21px; }
.rec-btn.swap .rec-btn__ic { animation: iconSwap .32s var(--ease-out); }
.rec-btn::before { /* level-reactive halo while recording */
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: var(--accent); opacity: 0; transform: scale(1);
  transition: transform .12s linear, opacity .2s;
  z-index: -1;
}
.rec-btn.is-recording { background: var(--accent); color: #fff; transform: scale(1.3); box-shadow: none; }
.rec-btn.is-recording::before { opacity: .22; transform: scale(calc(1 + var(--lvl, 0) * .9)); }
.rec-btn.is-cancel { background: var(--danger); }

.rec-bar {
  position: absolute; inset: 3px; z-index: 1;
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: var(--bg-elev); border-radius: 20px;
  font-size: 15px; animation: fade .18s var(--ease-out);
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: recBlink 1.1s ease-in-out infinite; flex: none; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.rec-hint { margin-left: auto; color: var(--text-3); font-size: 14px; white-space: nowrap; transform: translateX(var(--dx, 0px)); opacity: var(--hint-o, 1); }
.composer.is-recording .composer__row { visibility: hidden; }
.composer.is-recording .clip-btn { opacity: .4; pointer-events: none; }

.vnote-live {
  position: absolute; z-index: 6; left: 50%;
  bottom: calc(var(--cmp-h) + 46px + var(--sab));
  width: min(64vw, 240px); aspect-ratio: 1; margin-left: calc(min(64vw, 240px) / -2);
  border-radius: 50%; overflow: hidden; background: #000;
  box-shadow: var(--shadow-lg), 0 0 0 4px var(--bg-elev);
  animation: zoomIn .3s var(--ease-out);
}
.vnote-live video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.vnote-live__ring, .vnote__ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); pointer-events: none; }
.vnote-live__ring circle, .vnote__ring circle { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 304.7; stroke-dashoffset: calc(304.7 * (1 - var(--p, 0))); }

/* Voice message bubble */
.voice { display: flex; align-items: center; gap: 10px; min-width: 210px; padding: 2px 0 0; }
.voice__play {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  transition: transform var(--t-fast);
}
.voice__play:active { transform: scale(.9); }
.voice__play .ic { width: 18px; height: 18px; }
.out .voice__play { background: #fff; color: var(--accent); }
.voice__body { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.voice__wave { display: flex; align-items: center; gap: 2px; height: 26px; }
.voice__wave i { width: 3px; border-radius: 2px; background: currentColor; opacity: .32; flex: none; transition: opacity .12s; }
.in .voice__wave i { background: var(--accent); }
.voice__wave i.on { opacity: 1; }
.voice__time { font-size: 12px; opacity: .8; font-variant-numeric: tabular-nums; }

/* Round video message */
.vnote { position: relative; display: block; width: 210px; height: 210px; border-radius: 50%; overflow: hidden; background: #000; cursor: pointer; box-shadow: var(--shadow-md); }
.vnote video { width: 100%; height: 100%; object-fit: cover; display: block; }
.vnote__ring circle { stroke: #fff; opacity: 0; transition: opacity .2s; }
.vnote.is-playing .vnote__ring circle { opacity: .95; }
.vnote__dur { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); padding: 3px 8px; border-radius: 999px; background: rgba(0,0,0,.45); color: #fff; font-size: 12px; font-variant-numeric: tabular-nums; backdrop-filter: blur(6px); }
.vnote__mute { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: rgba(0,0,0,.45); color: #fff; backdrop-filter: blur(6px); }
.vnote__mute .ic { width: 15px; height: 15px; }
.vnote.is-playing .vnote__mute { display: none; }
.vnote .meta--overlay { right: 50%; transform: translateX(50%); bottom: 34px; display: none; }

@keyframes recBlink { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
@keyframes iconSwap { 0% { transform: scale(.4) rotate(-40deg); opacity: 0; } 100% { transform: none; opacity: 1; } }

/* =========================================================
   Installed web app (PWA) polish
   ========================================================= */
html, body { overscroll-behavior: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, a, .chat-item, .contact-card { touch-action: manipulation; }
.tabbar, .view-head, .chat-header, .composer, .chips, .ctx, .sheet__head { -webkit-user-select: none; user-select: none; }
img { -webkit-user-drag: none; }
@media (display-mode: standalone) {
  .settings .install-row { display: none; }
}

.install { text-align: center; padding: 4px 6px 4px; }
.install__icon { width: 72px; height: 72px; border-radius: 18px; box-shadow: var(--shadow-md); display: block; margin: 4px auto 12px; }
.install__lead { margin: 0 0 14px; color: var(--text-2); font-size: 14.5px; }
.install__steps { list-style: none; counter-reset: s; margin: 0 0 14px; padding: 0; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.install__steps li { counter-increment: s; display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--surface); border-radius: 16px; font-size: 14.5px; }
.install__steps li::before { content: counter(s); width: 26px; height: 26px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; }
.install__steps .ic { width: 18px; height: 18px; display: inline-block; vertical-align: -3px; color: var(--accent); }
.confirm-btn.is-primary { background: var(--accent); color: #fff; width: 100%; }

/* =========================================================
   Auth
   ========================================================= */
.auth {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(var(--sab) + 20px);
  background: var(--bg); overflow-y: auto;
}
.auth__card { width: 100%; max-width: 400px; text-align: center; animation: rise .45s var(--ease-out) both; }
.auth__logo { width: 68px; height: 68px; border-radius: 20px; display: block; margin: 0 auto 18px; box-shadow: var(--shadow-md); }
.auth__title { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -.6px; }
.auth__sub { margin: 6px 0 20px; color: var(--text-2); font-size: 15px; }
.auth__tabs { margin-bottom: 18px; }
.auth__form { text-align: left; gap: 12px; }
.auth__submit { margin-top: 6px; height: 52px; font-size: 16px; }
.auth__submit:disabled { opacity: .6; }
.auth__note { margin: 16px 0 0; color: var(--text-3); font-size: 13px; }
.field__err { color: var(--danger); font-size: 12.5px; min-height: 0; padding-left: 4px; }
.field__err:empty { display: none; }
.field.has-error input { border-color: var(--danger); }
.pw { position: relative; display: block; }
.pw input { width: 100%; padding-right: 48px; }
.pw__toggle { position: absolute; right: 4px; top: 4px; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--text-3); }
.pw__toggle .ic { width: 20px; height: 20px; }
.field input { width: 100%; }
body.is-auth .app { visibility: hidden; }

/* one wrapper per day: keeps sticky date labels from stacking */
.day { display: flex; flex-direction: column; }

/* =========================================================
   Accounts: photos, empty states, contacts sync, privacy
   ========================================================= */
.avatar.has-img { background: var(--surface) !important; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }

/* Unread badge: always a perfect circle, number optically centered */
.badge {
  width: 22px; height: 22px; min-width: 0; padding: 0; margin-top: 2px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11.5px; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -.2px;
  font-feature-settings: 'tnum';
}
.badge--2 { font-size: 10.5px; letter-spacing: -.4px; }
.badge--3 { width: 26px; height: 26px; font-size: 9.5px; letter-spacing: -.4px; }

.me-card__av { position: relative; display: block; width: 104px; margin: 0 auto 14px; border-radius: 50%; }
.me-card__av .avatar { margin: 0; }
.me-card__cam {
  position: absolute; right: 0; bottom: 2px; width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent); color: #fff;
  border: 3px solid var(--bg);
}
.me-card__cam .ic { width: 15px; height: 15px; }

.photo-edit { display: flex; align-items: center; gap: 16px; padding: 4px 4px 14px; }
.photo-edit__av { position: relative; flex: none; border-radius: 50%; }
.photo-edit__av .avatar { width: 72px; height: 72px; font-size: 26px; }
.photo-edit__cam { position: absolute; right: -2px; bottom: -2px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; border: 2px solid var(--bg-elev); }
.photo-edit__cam .ic { width: 13px; height: 13px; }
.photo-edit__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.photo-edit__remove { color: var(--danger); }
.sheet__text { margin: -2px 4px 12px; color: var(--text-2); font-size: 14.5px; }
#addSync { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
#addSync .ic { width: 18px; height: 18px; }

.empty-state {
  list-style: none; grid-column: 1 / -1;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 48px 24px 24px; animation: rise .4s var(--ease-out) both;
}
.empty-state__ic { width: 76px; height: 76px; border-radius: 26px; display: grid; place-items: center; background: var(--primary-soft); color: var(--accent); margin-bottom: 16px; }
.empty-state__ic .ic { width: 34px; height: 34px; stroke-width: 1.5; }
.empty-state h3 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.3px; }
.empty-state p { margin: 6px 0 18px; color: var(--text-2); font-size: 14.5px; max-width: 300px; }
.empty-state__actions { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 280px; }
.empty-state .confirm-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.empty-state .confirm-btn .ic { width: 18px; height: 18px; }

.chat-empty { margin: auto; text-align: center; padding: 18px 22px; border-radius: 22px; background: color-mix(in srgb, var(--bg-elev) 80%, transparent); box-shadow: var(--shadow-sm); color: var(--text-2); max-width: 260px; animation: rise .4s var(--ease-out) both; }
.chat-empty strong { display: block; color: var(--text); font-size: 15.5px; margin-bottom: 2px; }
.chat-empty span { font-size: 14px; }
.chat-empty button { margin-top: 12px; font-size: 34px; line-height: 1; border-radius: 16px; padding: 6px 10px; transition: transform var(--t-fast); }
.chat-empty button:hover { transform: scale(1.12); }

.s-row--stack { flex-wrap: wrap; row-gap: 10px; }
.s-row--stack .segmented { width: 100%; margin-left: 48px; width: calc(100% - 48px); }
.s-row--stack .segmented button { flex: 1; padding: 0 6px; white-space: nowrap; font-size: 12.5px; }
.s-row__hint { width: 100%; margin-left: 48px; font-size: 12.5px; color: var(--text-3); margin-top: -4px; }
.hero.has-photo .hero__mark { display: none; }
.hero.has-photo { background-size: cover !important; background-position: center !important; }
.badge { padding-top: 1px; }

/* =========================================================
   Mobile web (iOS Safari / Android Chrome) stability
   The page itself never scrolls; the app is pinned to the *visible* viewport,
   so the keyboard can't push the header off-screen or reveal gaps under the composer.
   ========================================================= */
html, body { position: fixed; inset: 0; overflow: hidden; touch-action: pan-x pan-y; }
html.kb-open { --sab: 0px; }
.profile, .auth, .lightbox, .scrim { top: var(--app-top); bottom: auto; height: var(--app-h); }
.sheet { bottom: calc(10px + var(--sab) + var(--kb-off, 0px)); }
html.kb-open .sheet { max-height: calc(var(--app-h) - 20px); overflow-y: auto; }
.chat-header, .composer { transform: translateZ(0); }       /* own layer: no repaint jitter */
.tabbar { transform: translate3d(-50%, 0, 0); }
.messages { will-change: scroll-position; -webkit-overflow-scrolling: touch; }
/* iOS zooms into inputs smaller than 16px — that zoom is what makes the page jump */
@media (pointer: coarse) {
  input, textarea, select { font-size: 16px !important; }
}
