/* IOSFIX 26.11.2026 — читаемый классический шрифт везде + вёрстка под iPhone 12 mini … 16/17 Pro Max (375–440 pt).
   Подключается ПОСЛЕДНИМ (index.html, в конце body) и аккуратно перекрывает старые слои оформления. */

/* ---------- 1. Шрифт: системный, как в iOS/macOS (San Francisco), Windows (Segoe UI), Android (Roboto) ---------- */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: var(--font) !important;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility; font-synthesis: none; font-kerning: normal;
}
/* один шрифт для всего интерфейса (кроме кода и игральных карт) — раньше часть блоков сама задавала system-ui/Inter */
body *:not(code):not(pre):not(kbd):not(samp):not(.cg-card):not(.cg-card *):not(svg):not(svg *) { font-family: inherit !important; }
button, input, textarea, select { font-family: var(--font) !important; }
code, pre, kbd, samp { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace !important; }

/* без «сжатых» и сверхжирных заголовков, без прозрачной градиентной заливки текста */
h1, h2, h3, .m-title, .mc-title, .menu-title, .rd-f-head h1, .rdx-hi { letter-spacing: normal !important; }
h1, .m-title, .rd-f-head h1, .menu-title { font-weight: 700 !important; }
.rdx-hi, .menu-hero strong, #profile-name { font-weight: 700 !important; }
#rd-feed .rd-f-head h1 { background: none !important; -webkit-background-clip: border-box !important; background-clip: border-box !important;
  -webkit-text-fill-color: currentColor !important; color: var(--f-tx, #f3ebe4) !important; }
#rd-feed .rd-f-body h3, .ct-sec, .rd-f-body h3 { letter-spacing: .04em !important; }

/* ---------- 2. Список чатов: читаемые размеры, имя не налезает на время ---------- */
.row .top { min-width: 0; }
.row .top strong {
  display: block !important; /* у flex-контейнера многоточие не работает — значки внутри остаются в строке (inline) */
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 16px; font-weight: 600 !important; line-height: 1.25;
}
.row .top time { flex: none; font-size: 13px; font-variant-numeric: tabular-nums; }
.row .preview { font-size: 15px; line-height: 1.3; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .top strong .vchk, .row .top strong svg { flex: none; }

/* ---------- 3. Телефоны (все iPhone 12 mini … Pro Max — ширина до 440 pt) ---------- */
@media (max-width: 860px) {
  /* сообщения — как в iOS (17pt ≈ 16–17px), спокойная высота строки */
  .msg .bubble .text, .msg .bubble { font-size: 16px; line-height: 1.38; }
  .msg .foot { font-size: 12px; }

  /* шапка открытого чата: место под имя. Поиск по чату — в профиле (⋮ → «Поиск»), закрепить чат — долгим нажатием в списке */
  #thread .chat-head #chat-search-btn, #thread .chat-head #pin-btn { display: none !important; }
  #thread .chat-head .icon-btn { width: 40px; height: 40px; min-width: 40px; }
  #thread .chat-head #peer-open { min-width: 0; flex: 1 1 auto; }
  #peer-name { font-size: 17px; font-weight: 600 !important; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
  #peer-status { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
  #conn-ind { display: none !important; } /* третья строка «🌐 интернет / 🚫 нет сети» под именем — на телефоне лишняя */

  /* плашка сквозного шифрования — компактно, в одну-две строки, не съедает экран */
  #e2e { margin: 6px 10px !important; padding: 8px 12px !important; border-radius: 12px !important; font-size: 13px !important; }
  #e2e .e2e-text strong { font-size: 13px !important; }
  #e2e .e2e-ctl { margin-top: 6px !important; gap: 6px !important; }
  #e2e .e2e-ctl button, #e2e .e2e-ctl button[data-e2e] { min-height: 34px !important; padding: 0 12px !important; font-size: 13px !important; border-radius: 99px !important; }

  /* поле ввода: 16px — iOS не увеличивает страницу при фокусе; подсказка в одну строку */
  #input, .composer textarea { font-size: 16px !important; line-height: 1.35; }
  #input::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* нижняя панель: подписи не мельче 11px */
  .shell .rail .rail-item .rail-label { font-size: 11px !important; }

  /* «Лента»: до самой нижней панели (без просвета списка чатов), заголовок не перекрыт кнопкой «назад» */
  html.phone #rd-feed.rd-feed { bottom: var(--pn-bar-h, calc(66px + env(safe-area-inset-bottom))) !important; }
  html.phone #rd-feed .rd-f-head { padding-left: 12px !important; gap: 8px !important; }
  .rd-f-back { display: none; }
  html.phone .rd-f-back { display: grid; place-items: center; flex: none; width: 40px; height: 40px; margin-right: 2px; border: 0; border-radius: 50%;
    background: rgba(255,255,255,.08); color: inherit; cursor: pointer; }
  html.phone #rd-feed .rd-f-head h1 { font-size: 28px !important; }
}

/* узкие iPhone (12/13 mini — 375 pt): чуть плотнее */
@media (max-width: 380px) {
  .row { padding-left: 12px !important; padding-right: 12px !important; }
  .row .top strong { font-size: 15.5px; }
  .row .preview { font-size: 14.5px; }
  #thread .chat-head .icon-btn { width: 38px; height: 38px; min-width: 38px; }
}

/* ---------- 4. Безопасные зоны iPhone (вырез / Dynamic Island / полоска «домой») ---------- */
@supports (padding: env(safe-area-inset-top)) {
  @media (max-width: 860px) {
    #thread .chat-head { padding-top: max(env(safe-area-inset-top), 6px) !important; }
    .composer, #composer { padding-bottom: max(env(safe-area-inset-bottom), 8px) !important; }
    html.phone.pn-chat .composer, html.phone.pn-chat #composer { padding-bottom: max(env(safe-area-inset-bottom), 8px) !important; }
  }
}
.row .top strong > * { vertical-align: -3px; }
.row .top { gap: 10px !important; }

/* IOSGAP 26.11.2026: фон страницы на iPhone — в цвет нижней панели (никакой серой полосы под ней даже при погрешности в 1–2px) */
html.phone.ios, html.phone.ios body { background: var(--sidebar, #141010) !important; }
html.phone.ios.mux-light, html.phone.ios.mux-light body, html.phone.ios.light, html.phone.ios.light body { background: #faf8f6 !important; }

/* ---------- 5. LANDFIX 26.11.2026: iPhone в альбомной ориентации ----------
   Шире 860px (Plus / 16 Pro / Pro Max лёжа) работает десктопная сетка: панель · чаты · диалог.
   Высота экрана там ~400–440px — строка сетки не должна расти по содержимому, колонки прокручиваются сами. */
@media (min-width: 861px) and (max-height: 520px) {
  .shell { height: var(--app-height, 100dvh) !important; grid-template-rows: minmax(0, 1fr) !important; overflow: hidden; }
  .shell > * { min-height: 0 !important; max-height: 100%; }
  .shell > .rail { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; padding-bottom: env(safe-area-inset-bottom); padding-left: env(safe-area-inset-left); }
  .shell > .rail::-webkit-scrollbar { display: none; }
  .shell > .stage { padding-right: env(safe-area-inset-right); }
  .composer, #composer { padding-bottom: max(env(safe-area-inset-bottom), 8px) !important; }
}
/* невысокий экран (любой телефон лёжа): плашка шифрования в одну строку, ленте — место */
@media (max-height: 520px) {
  html.phone #e2e { margin: 4px 8px !important; padding: 4px 10px !important; }
  html.phone #e2e .e2e-text span { display: none !important; }
  html.phone #e2e .e2e-ctl { margin-top: 4px !important; }
  html.phone #e2e .e2e-ctl button, html.phone #e2e .e2e-ctl button[data-e2e] { min-height: 28px !important; }
}
