/* ==========================================================================
   LSchat iOS UI Kit — компоненты по Apple Human Interface Guidelines
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* Системные цвета iOS (light) */
  --sys-blue: #007AFF;
  --sys-green: #34C759;
  --sys-red: #FF3B30;
  --sys-orange: #FF9500;
  --sys-yellow: #FFCC00;
  --sys-purple: #AF52DE;
  --sys-teal: #5AC8FA;
  --sys-indigo: #5856D6;
  --sys-pink: #FF2D55;
  --sys-gray: #8E8E93;
  --sys-gray2: #AEAEB2;
  --sys-gray3: #C7C7CC;
  --sys-gray4: #D1D1D6;
  --sys-gray5: #E5E5EA;
  --sys-gray6: #F2F2F7;

  --tint: var(--sys-blue);

  --bg: #FFFFFF;                       /* systemBackground */
  --bg-secondary: #F2F2F7;             /* secondarySystemBackground */
  --bg-grouped: #F2F2F7;               /* systemGroupedBackground */
  --bg-grouped-cell: #FFFFFF;          /* secondarySystemGroupedBackground */
  --bg-tertiary: #FFFFFF;

  --label: #000000;
  --label-secondary: rgba(60, 60, 67, 0.60);
  --label-tertiary: rgba(60, 60, 67, 0.30);
  --label-quaternary: rgba(60, 60, 67, 0.18);
  --placeholder: rgba(60, 60, 67, 0.30);

  --separator: rgba(60, 60, 67, 0.29);
  --fill: rgba(120, 120, 128, 0.20);
  --fill-secondary: rgba(120, 120, 128, 0.16);
  --fill-tertiary: rgba(118, 118, 128, 0.12);
  --fill-quaternary: rgba(116, 116, 128, 0.08);

  --bar-bg: rgba(249, 249, 249, 0.94);
  --bar-border: rgba(0, 0, 0, 0.3);
  --tab-bar-bg: #F9F9F9;

  --bubble-out: var(--sys-blue);
  --bubble-out-text: #FFFFFF;
  --bubble-in: #E9E9EB;
  --bubble-in-text: #000000;

  --cell-highlight: #D1D1D6;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-rounded: -apple-system-rounded, var(--font);

  /* Типографика HIG (Default size) */
  --fs-large-title: 34px;
  --fs-title1: 28px;
  --fs-title2: 22px;
  --fs-title3: 20px;
  --fs-headline: 17px;
  --fs-body: 17px;
  --fs-callout: 16px;
  --fs-subhead: 15px;
  --fs-footnote: 13px;
  --fs-caption1: 12px;
  --fs-caption2: 11px;

  --nav-h: 44px;
  --tab-h: 49px;
  --sai-top: env(safe-area-inset-top, 0px);
  --sai-bottom: env(safe-area-inset-bottom, 0px);
  --sai-left: env(safe-area-inset-left, 0px);
  --sai-right: env(safe-area-inset-right, 0px);

  --radius-cell: 10px;
  --radius-bubble: 18px;
  --ease-ios: cubic-bezier(0.32, 0.72, 0, 1);
  --dur-push: 0.42s;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --sys-blue: #0A84FF;
    --sys-green: #30D158;
    --sys-red: #FF453A;
    --sys-orange: #FF9F0A;
    --sys-yellow: #FFD60A;
    --sys-purple: #BF5AF2;
    --sys-teal: #64D2FF;
    --sys-indigo: #5E5CE6;
    --sys-pink: #FF375F;
    --sys-gray: #8E8E93;
    --sys-gray2: #636366;
    --sys-gray3: #48484A;
    --sys-gray4: #3A3A3C;
    --sys-gray5: #2C2C2E;
    --sys-gray6: #1C1C1E;

    --bg: #000000;
    --bg-secondary: #1C1C1E;
    --bg-grouped: #000000;
    --bg-grouped-cell: #1C1C1E;
    --bg-tertiary: #2C2C2E;

    --label: #FFFFFF;
    --label-secondary: rgba(235, 235, 245, 0.60);
    --label-tertiary: rgba(235, 235, 245, 0.30);
    --label-quaternary: rgba(235, 235, 245, 0.18);
    --placeholder: rgba(235, 235, 245, 0.30);

    --separator: rgba(84, 84, 88, 0.60);
    --fill: rgba(120, 120, 128, 0.36);
    --fill-secondary: rgba(120, 120, 128, 0.32);
    --fill-tertiary: rgba(118, 118, 128, 0.24);
    --fill-quaternary: rgba(116, 116, 128, 0.18);

    --bar-bg: rgba(29, 29, 29, 0.94);
    --bar-border: rgba(255, 255, 255, 0.15);
    --tab-bar-bg: #1D1D1D;

    --bubble-in: #262629;
    --bubble-in-text: #FFFFFF;
    --cell-highlight: #3A3A3C;
  }
}
:root[data-theme="dark"] {
  --sys-blue: #0A84FF; --sys-green: #30D158; --sys-red: #FF453A; --sys-orange: #FF9F0A;
  --sys-yellow: #FFD60A; --sys-purple: #BF5AF2; --sys-teal: #64D2FF; --sys-indigo: #5E5CE6;
  --sys-pink: #FF375F; --sys-gray: #8E8E93; --sys-gray2: #636366; --sys-gray3: #48484A;
  --sys-gray4: #3A3A3C; --sys-gray5: #2C2C2E; --sys-gray6: #1C1C1E;
  --bg: #000000; --bg-secondary: #1C1C1E; --bg-grouped: #000000; --bg-grouped-cell: #1C1C1E; --bg-tertiary: #2C2C2E;
  --label: #FFFFFF; --label-secondary: rgba(235,235,245,.6); --label-tertiary: rgba(235,235,245,.3);
  --label-quaternary: rgba(235,235,245,.18); --placeholder: rgba(235,235,245,.3);
  --separator: rgba(84,84,88,.6); --fill: rgba(120,120,128,.36); --fill-secondary: rgba(120,120,128,.32);
  --fill-tertiary: rgba(118,118,128,.24); --fill-quaternary: rgba(116,116,128,.18);
  --bar-bg: rgba(29,29,29,.94); --bar-border: rgba(255,255,255,.15); --tab-bar-bg: #1D1D1D;
  --bubble-in: #262629; --bubble-in-text: #FFFFFF; --cell-highlight: #3A3A3C;
}

/* --------------------------------------------------------------------------
   База: ощущение нативного приложения
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;                 /* никакого «резинового» скролла всей страницы */
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--label);
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

body {
  position: fixed;
  inset: 0;
  user-select: none;
  -webkit-user-select: none;
}

.ios-app {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
}

/* iOS standalone (PWA): «малый» вьюпорт (height:100%, 100svh, innerHeight) укорочен
   на высоту статус-бара, хотя веб-вью занимает весь экран (viewport-fit=cover).
   Из-за этого под таб-баром оставалась пустая полоса. Берём «большой» вьюпорт. */
@media (display-mode: standalone), (display-mode: fullscreen) {
  html, body { height: 100vh; height: 100lvh; }
}

button, input, textarea {
  font: inherit;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  background: none;
  margin: 0;
  padding: 0;
}
button { cursor: pointer; }
button:focus, input:focus, textarea:focus, button:focus-visible { outline: none; }
input, textarea, [contenteditable] { user-select: text; -webkit-user-select: text; }
[contenteditable]:focus { outline: none; }
a { color: var(--tint); text-decoration: none; }
svg { display: block; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

.selectable { user-select: text; -webkit-user-select: text; }

/* --------------------------------------------------------------------------
   Навигационный стек / экраны
   -------------------------------------------------------------------------- */
.nav-stack {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transform: translate3d(0, 0, 0);
  will-change: transform;
  overflow: hidden;
}
.screen.grouped { background: var(--bg-grouped); }

/* Push-анимация как в UIKit: новый экран едет справа, старый уезжает на -30% и темнеет */
.screen.push-enter { transform: translate3d(100%, 0, 0); }
.screen.push-enter-active { transform: translate3d(0, 0, 0); transition: transform var(--dur-push) var(--ease-ios); }
.screen.push-under { transform: translate3d(-30%, 0, 0); transition: transform var(--dur-push) var(--ease-ios); }
.screen.push-under::after {
  content: ""; position: absolute; inset: 0; background: rgba(0,0,0,.12); pointer-events: none;
  transition: opacity var(--dur-push) var(--ease-ios);
}
.screen.push-under-reset { transform: translate3d(0,0,0); transition: transform var(--dur-push) var(--ease-ios); }
.screen.pop-exit { transform: translate3d(100%, 0, 0); transition: transform var(--dur-push) var(--ease-ios); }
.screen.dragging, .screen.dragging-under { transition: none !important; }
.screen.with-shadow { box-shadow: -4px 0 16px rgba(0,0,0,.18); }
.screen.with-tab-bar .content { padding-bottom: calc(var(--tab-h) + var(--sai-bottom)); }
.screen:not(.with-tab-bar) ~ .tab-bar { display: none; }

/* Прокручиваемое содержимое экрана */
.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding-top: calc(var(--nav-h) + var(--sai-top));
  scrollbar-width: none;
}
.content::-webkit-scrollbar { display: none; }

/* --------------------------------------------------------------------------
   Navigation Bar
   -------------------------------------------------------------------------- */
.nav-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 20;
  padding-top: var(--sai-top);
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  transition: box-shadow .2s;
}
.nav-bar.scrolled { box-shadow: 0 0.33px 0 var(--bar-border); }
.nav-bar.transparent:not(.scrolled) { background: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; }

.nav-row {
  height: var(--nav-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 8px;
}
.nav-left { justify-self: start; display: flex; align-items: center; min-width: 0; }
.nav-right { justify-self: end; display: flex; align-items: center; gap: 4px; }
.nav-title {
  font-size: var(--fs-headline);
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 48vw;
  opacity: 1;
  transition: opacity .15s;
}
.nav-title .subtitle { display: block; font-size: var(--fs-caption1); font-weight: 400; color: var(--label-secondary); }
.nav-bar.large:not(.scrolled) .nav-title { opacity: 0; }

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: var(--nav-h);
  padding: 0 8px;
  color: var(--tint);
  font-size: var(--fs-body);
  white-space: nowrap;
  transition: opacity .1s;
}
.nav-btn:active { opacity: .35; }
.nav-btn.bold { font-weight: 600; }
.nav-btn svg { width: 24px; height: 24px; fill: currentColor; }
.nav-btn.back { padding-left: 0; }
.nav-btn.back .chevron { width: 12px; height: 20px; margin-right: 4px; }
.nav-btn.back .chevron path { fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }

.large-title {
  padding: 4px 16px 8px;
  font-size: var(--fs-large-title);
  font-weight: 700;
  letter-spacing: 0.37px;
  line-height: 41px;
}

/* --------------------------------------------------------------------------
   Search Bar
   -------------------------------------------------------------------------- */
.search-bar {
  padding: 0 16px 10px;
}
.search-field {
  position: relative;
  display: flex;
  align-items: center;
  height: 36px;
  border-radius: 10px;
  background: var(--fill-tertiary);
  padding: 0 8px;
  gap: 6px;
}
.search-field svg { width: 16px; height: 16px; fill: var(--label-secondary); flex: none; }
.search-field input {
  flex: 1;
  min-width: 0;
  height: 100%;
  font-size: var(--fs-body);
  background: transparent;
}
.search-field input::placeholder { color: var(--placeholder); }
.search-field .clear {
  width: 18px; height: 18px; border-radius: 50%; background: var(--sys-gray); color: var(--bg);
  display: none; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex: none;
}
.search-field.has-text .clear { display: inline-flex; }

/* --------------------------------------------------------------------------
   Списки (Plain / Inset Grouped)
   -------------------------------------------------------------------------- */
.list { margin: 0; padding: 0; list-style: none; }

.cell {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 6px 16px 6px 16px;
  background: var(--bg-grouped-cell);
  color: var(--label);
  width: 100%;
  text-align: left;
}
.cell:active, .cell.is-pressed { background: var(--cell-highlight); }
.cell.no-press:active { background: var(--bg-grouped-cell); }
.cell-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.cell-title { font-size: var(--fs-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-subtitle { font-size: var(--fs-subhead); color: var(--label-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-value { color: var(--label-secondary); font-size: var(--fs-body); flex: none; }
.cell-chevron { width: 8px; height: 14px; flex: none; }
.cell-chevron path { fill: none; stroke: var(--sys-gray3); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.cell .icon-box {
  width: 29px; height: 29px; border-radius: 7px; display: flex; align-items: center; justify-content: center; flex: none;
}
.cell .icon-box svg { width: 18px; height: 18px; fill: #fff; }

/* Разделители в стиле iOS: с отступом, ниже контента */
.cell::after {
  content: "";
  position: absolute;
  left: 16px; right: 0; bottom: 0;
  height: 0.5px;
  background: var(--separator);
}
.cell.inset-avatar::after { left: 76px; }
.cell.inset-icon::after { left: 57px; }
.list > :last-child.cell::after, .cell:last-child::after { display: none; }

.group {
  margin: 0 16px 24px;
  border-radius: var(--radius-cell);
  overflow: hidden;
  background: var(--bg-grouped-cell);
}
.group-header {
  padding: 24px 32px 7px;
  font-size: var(--fs-footnote);
  color: var(--label-secondary);
  text-transform: uppercase;
  letter-spacing: -0.08px;
}
.group-header + .group { margin-top: 0; }
.group-footer {
  margin: -16px 32px 24px;
  font-size: var(--fs-footnote);
  color: var(--label-secondary);
}

.list .plain-cell { background: var(--bg); }
.list .plain-cell:active { background: var(--cell-highlight); }

/* --------------------------------------------------------------------------
   Аватар, бейдж
   -------------------------------------------------------------------------- */
.avatar {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 19px;
  background: linear-gradient(180deg, var(--a1, #8E8E93), var(--a2, #636366));
  flex: none;
  position: relative;
}
.avatar.sm { width: 36px; height: 36px; font-size: 15px; }
.avatar.lg { width: 100px; height: 100px; font-size: 40px; }
.avatar.xl { width: 60px; height: 60px; font-size: 24px; }
.avatar .online {
  position: absolute; right: 0; bottom: 0; width: 14px; height: 14px; border-radius: 50%;
  background: var(--sys-green); border: 2.5px solid var(--bg);
}
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--sys-red); color: #fff; font-size: var(--fs-footnote); font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}
.badge.muted { background: var(--sys-gray); }

/* --------------------------------------------------------------------------
   Tab Bar
   -------------------------------------------------------------------------- */
.tab-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  height: calc(var(--tab-h) + var(--sai-bottom));
  padding: 0 0 var(--sai-bottom);
  display: flex;
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 -0.33px 0 var(--bar-border);
  transition: transform .25s var(--ease-ios);
}
.tab-bar.hidden-bar { transform: translateY(100%); }
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding-top: 5px;
  color: var(--sys-gray);
  position: relative;
}
.tab-item.is-active { color: var(--tint); }
.tab-icon svg { width: 28px; height: 28px; fill: currentColor; }
.tab-label { font-size: 10px; font-weight: 500; letter-spacing: -0.24px; }
.tab-badge { position: absolute; top: 2px; left: calc(50% + 6px); height: 18px; min-width: 18px; font-size: 11px; }

/* --------------------------------------------------------------------------
   Кнопки
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 50px; padding: 0 20px; border-radius: 12px;
  font-size: var(--fs-body); font-weight: 600;
  background: var(--tint); color: #fff;
  transition: opacity .1s, transform .1s;
}
.btn:active { opacity: .8; transform: scale(.98); }
.btn.block { width: 100%; }
.btn.tinted { background: rgba(0, 122, 255, .15); color: var(--tint); }
.btn.gray { background: var(--fill-tertiary); color: var(--tint); }
.btn.plain { background: transparent; color: var(--tint); height: auto; padding: 8px; }
.btn.destructive { color: var(--sys-red); }
.btn:disabled { opacity: .4; pointer-events: none; }

/* --------------------------------------------------------------------------
   Toggle (UISwitch)
   -------------------------------------------------------------------------- */
.toggle {
  position: relative; width: 51px; height: 31px; border-radius: 16px;
  background: var(--fill); flex: none; transition: background .2s;
}
.toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0,0,0,.15), 0 3px 1px rgba(0,0,0,.06);
  transition: transform .2s var(--ease-ios);
}
.toggle.on { background: var(--sys-green); }
.toggle.on::after { transform: translateX(20px); }

/* Segmented control */
.segmented {
  display: flex; padding: 2px; border-radius: 9px; background: var(--fill-tertiary); margin: 0 16px 16px;
}
.segmented button {
  flex: 1; height: 28px; border-radius: 7px; font-size: var(--fs-footnote); font-weight: 500; color: var(--label);
}
.segmented button.is-active { background: var(--bg-grouped-cell); box-shadow: 0 3px 8px rgba(0,0,0,.12), 0 3px 1px rgba(0,0,0,.04); font-weight: 600; }

/* Текстовое поле в группе */
.field { display: flex; align-items: center; min-height: 44px; padding: 0 16px; background: var(--bg-grouped-cell); position: relative; }
.field input { flex: 1; height: 44px; font-size: var(--fs-body); }
.field input::placeholder { color: var(--placeholder); }
.field label { width: 100px; flex: none; }
.field::after { content: ""; position: absolute; left: 16px; right: 0; bottom: 0; height: .5px; background: var(--separator); }
.field:last-child::after { display: none; }

/* --------------------------------------------------------------------------
   Пузыри сообщений (iMessage-style)
   -------------------------------------------------------------------------- */
.messages { display: flex; flex-direction: column; padding: 8px 16px 8px; gap: 2px; }
.msg-date {
  align-self: center; margin: 14px 0 8px; font-size: var(--fs-caption1); font-weight: 600; color: var(--label-secondary);
}
.msg {
  max-width: 75%;
  padding: 7px 12px 8px;
  border-radius: var(--radius-bubble);
  font-size: var(--fs-body);
  line-height: 1.3;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  animation: msg-in .22s var(--ease-ios);
}
@keyframes msg-in { from { opacity: 0; transform: translateY(8px) scale(.96); } to { opacity: 1; transform: none; } }
.msg.out { align-self: flex-end; background: var(--bubble-out); color: var(--bubble-out-text); }
.msg.in  { align-self: flex-start; background: var(--bubble-in); color: var(--bubble-in-text); }
.msg.out.tail { border-bottom-right-radius: 4px; }
.msg.in.tail  { border-bottom-left-radius: 4px; }
.msg.out.tail::after, .msg.in.tail::after {
  content: ""; position: absolute; bottom: 0; width: 10px; height: 14px;
}
.msg.out.tail::after {
  right: -6px;
  background: radial-gradient(12px 14px at 0 0, var(--bubble-out) 98%, transparent 100%);
  clip-path: polygon(0 0, 100% 100%, 0 100%);
}
.msg.in.tail::after {
  left: -6px;
  background: radial-gradient(12px 14px at 100% 0, var(--bubble-in) 98%, transparent 100%);
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
}
.msg + .msg.tail, .msg.tail + .msg { margin-top: 6px; }
.msg-meta {
  align-self: flex-end; font-size: var(--fs-caption2); color: var(--label-secondary); margin: 2px 4px 6px;
}
.msg-meta.in { align-self: flex-start; }
.msg .time {
  display: inline-block; font-size: 11px; opacity: .7; margin-left: 8px; float: right; margin-top: 6px; line-height: 1;
}
.typing {
  align-self: flex-start; background: var(--bubble-in); border-radius: var(--radius-bubble); padding: 12px 14px; display: flex; gap: 4px;
}
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--label-tertiary); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5 } 30% { transform: translateY(-4px); opacity: 1 } }

/* Поле ввода сообщения */
.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 12px calc(6px + var(--sai-bottom));
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 -0.33px 0 var(--bar-border);
}
.composer.keyboard-open { padding-bottom: 6px; }
.composer .round-btn {
  width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: var(--tint); flex: none; margin-bottom: 1px;
}
.composer .round-btn svg { width: 22px; height: 22px; fill: currentColor; }
.composer .round-btn.send { background: var(--tint); color: #fff; transition: transform .15s var(--ease-ios), opacity .15s; }
.composer .round-btn.send:disabled { opacity: 0; transform: scale(.5); position: absolute; pointer-events: none; }
.composer-field {
  flex: 1; min-height: 36px; max-height: 120px; border-radius: 18px; border: .5px solid var(--sys-gray3);
  background: var(--bg); display: flex; align-items: flex-end; padding: 0 12px;
  position: relative;
}
.composer-field textarea, .composer-field .ta {
  flex: 1; resize: none; min-height: 34px; max-height: 118px; padding: 7px 0; line-height: 20px; font-size: 17px;
  background: transparent; overflow-y: auto; white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-modify: read-write-plaintext-only;
}
.composer-field .ta:empty::before { content: attr(data-placeholder); color: var(--placeholder); pointer-events: none; }
.composer-field textarea::placeholder { color: var(--placeholder); }
.composer-field textarea::-webkit-scrollbar, .composer-field .ta::-webkit-scrollbar { display: none; }

/* --------------------------------------------------------------------------
   Action Sheet / Alert / Toast
   -------------------------------------------------------------------------- */
.overlay {
  position: absolute; inset: 0; z-index: 100;
  background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity .25s;
}
.overlay.center { align-items: center; }
.overlay.open { opacity: 1; }

.sheet {
  width: calc(100% - 16px); margin-bottom: calc(8px + var(--sai-bottom));
  transform: translateY(100%); transition: transform .35s var(--ease-ios);
}
.overlay.open .sheet { transform: none; }
.sheet-group { border-radius: 13px; overflow: hidden; background: var(--bar-bg); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); margin-bottom: 8px; }
.sheet-title { padding: 14px 16px; text-align: center; font-size: var(--fs-footnote); color: var(--label-secondary); border-bottom: .5px solid var(--separator); }
.sheet-btn {
  display: block; width: 100%; height: 57px; font-size: 20px; color: var(--tint); text-align: center;
  border-bottom: .5px solid var(--separator);
}
.sheet-btn:last-child { border-bottom: 0; }
.sheet-btn:active { background: var(--fill-tertiary); }
.sheet-btn.destructive { color: var(--sys-red); }
.sheet-btn.cancel { font-weight: 600; background: var(--bg-grouped-cell); }

.alert {
  width: 270px; border-radius: 14px; overflow: hidden; background: var(--bar-bg);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  transform: scale(1.1); opacity: 0; transition: transform .25s var(--ease-ios), opacity .2s;
}
.overlay.open .alert { transform: none; opacity: 1; }
.alert-body { padding: 19px 16px 17px; text-align: center; }
.alert-title { font-size: var(--fs-headline); font-weight: 600; margin-bottom: 4px; }
.alert-msg { font-size: var(--fs-footnote); color: var(--label); }
.alert-body input {
  width: 100%; height: 30px; margin-top: 12px; padding: 0 8px; border-radius: 6px;
  background: var(--bg); border: .5px solid var(--separator); font-size: 13px;
}
.alert-actions { display: flex; border-top: .5px solid var(--separator); }
.alert-actions button {
  flex: 1; height: 44px; font-size: var(--fs-body); color: var(--tint); border-right: .5px solid var(--separator);
}
.alert-actions button:last-child { border-right: 0; }
.alert-actions button.bold { font-weight: 600; }
.alert-actions button.destructive { color: var(--sys-red); }
.alert-actions button:active { background: var(--fill-tertiary); }
.alert-actions.vertical { flex-direction: column; }
.alert-actions.vertical button { border-right: 0; border-bottom: .5px solid var(--separator); }

.toast {
  position: absolute; left: 50%; top: calc(var(--sai-top) + 8px); transform: translate(-50%, -150%);
  z-index: 200; padding: 10px 18px; border-radius: 22px; background: var(--bg-grouped-cell);
  box-shadow: 0 4px 20px rgba(0,0,0,.18); font-size: var(--fs-subhead); font-weight: 500;
  transition: transform .4s var(--ease-ios), opacity .25s, visibility 0s .4s; white-space: nowrap;
  opacity: 0; visibility: hidden; pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; transition-delay: 0s; }

/* Context menu (long press) */
.ctx-menu {
  position: absolute; z-index: 110; min-width: 250px; border-radius: 13px; overflow: hidden;
  background: var(--bar-bg); -webkit-backdrop-filter: blur(30px); backdrop-filter: blur(30px);
  box-shadow: 0 10px 40px rgba(0,0,0,.25); transform-origin: top center;
  animation: ctx-in .2s var(--ease-ios);
}
@keyframes ctx-in { from { transform: scale(.6); opacity: 0 } }
.ctx-menu button {
  display: flex; align-items: center; justify-content: space-between; width: 100%; height: 44px; padding: 0 16px;
  font-size: var(--fs-body); border-bottom: .5px solid var(--separator); color: var(--label);
}
.ctx-menu button:last-child { border-bottom: 0; }
.ctx-menu button:active { background: var(--fill-tertiary); }
.ctx-menu button.destructive { color: var(--sys-red); }
.ctx-menu button svg { width: 20px; height: 20px; fill: currentColor; }

/* --------------------------------------------------------------------------
   Пустое состояние, вспомогательное
   -------------------------------------------------------------------------- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 60px 32px; color: var(--label-secondary); gap: 8px;
}
.empty svg { width: 56px; height: 56px; fill: var(--label-tertiary); margin-bottom: 8px; }
.empty b { color: var(--label); font-size: var(--fs-title3); }
.text-secondary { color: var(--label-secondary); }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.px-16 { padding-left: 16px; padding-right: 16px; }

/* Уменьшенная анимация */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* Скрытый переключатель для системного тактильного отклика на iOS.
   display:none его отключает — прячем прозрачностью. */
.haptic-tick { position: absolute; left: -9999px; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* Отладочный оверлей метрик вьюпорта (?debug=1) */
.vp-debug { position: fixed; left: 0; right: 0; top: 0; z-index: 9999; padding: 6px 8px; background: rgba(0,0,0,.82); color: #0f0; font: 11px/1.35 ui-monospace, Menlo, monospace; pointer-events: none; white-space: pre-wrap; }

/* --------------------------------------------------------------------------
   Десктоп (мышь + широкий экран): приложение — это телефон. Раньше .ios-app
   растягивался на всю ширину окна и выглядел как расплющенный планшет. Теперь
   на большом экране показываем аккуратную «рамку телефона» по центру на
   нейтральном фоне. Всё внутри позиционируется относительно .ios-app
   (position:absolute), поэтому бары и экраны подстраиваются автоматически.
   На айфоне/андроиде/планшете (coarse pointer) — как было, во весь экран.
   -------------------------------------------------------------------------- */
@media (min-width: 760px) and (pointer: fine) {
  body {
    background:
      radial-gradient(1200px 800px at 50% -10%, #2a2c31 0%, #17181b 55%, #0e0f11 100%);
    display: flex; align-items: center; justify-content: center;
  }
  @media (prefers-color-scheme: light) {
    body { background: radial-gradient(1200px 800px at 50% -10%, #e9edf3 0%, #d7dce4 60%, #c9ced7 100%); }
  }
  .ios-app {
    position: relative;
    inset: auto;
    width: 402px;
    height: min(872px, 94vh);
    border-radius: 46px;
    overflow: hidden;
    box-shadow: 0 40px 90px -20px rgba(0,0,0,.55), 0 0 0 11px #0b0b0d, 0 0 0 12px rgba(255,255,255,.06);
  }
}
@media (min-width: 760px) and (pointer: fine) and (min-height: 920px) {
  .ios-app { height: 872px; }
}
