/* Phone layout (max-width: 800px). */
@media (max-width: 800px) {
  /* Denser SVG doodle tile on phones (same asset as desktop; JS tints via data-URL). */
  html {
    --wallpaper-tile: 200px;
  }
  /* Resolve Android's translucent menu layers to opaque iOS paints, so the
     system's bottom extension can use exactly the same colour as the footer. */
  html.ios-device {
    --ios-menu-bg: color-mix(in srgb, var(--sidebar) var(--glass-menu-mix, 86%), var(--wallpaper-color, #d0e7f5));
    --ios-menu-footer-bg: color-mix(in srgb, var(--sidebar) var(--glass-menu-mix, 86%), var(--ios-menu-bg));
  }
  /* Extensions live under DMs in the main channel list on mobile. */

  

  
  .app.mail-mode:not(.settings-open) #chat-nav {
    display: block;
  }
  .app.mail-mode:not(.settings-open) #mail-nav {
    display: block;
  }
  .app.mail-mode:not(.settings-open) #filter,
.app.mail-mode:not(.settings-open) #channels-section-head,
.app.mail-mode:not(.settings-open) #channel-actions,
.app.mail-mode:not(.settings-open) #channel-list,
.app.mail-mode:not(.settings-open) #dm-section-head,
.app.mail-mode:not(.settings-open) #dm-list,
.app.mail-mode:not(.settings-open) #chat-tools {
    display: none !important;
  }
  /* Do NOT paint html/body with --sidebar here: that dark blue flashes
     under the soft keyboard. Keep the shared wallpaper paint from above. */
  .app {
    background: transparent;
    min-height: 100%;
    min-height: 100dvh;
  }
  @supports (min-height: -webkit-fill-available) {
    .app { min-height: -webkit-fill-available; }
  }
  .team-rail { display: none; }
  /* Swipe right on the main panel: the rail slides out over the chat list. */
  .app.rail-drawer-open .team-rail {
    display: flex; position: fixed; left: 0; top: 0; bottom: 0; z-index: 60;
    width: calc(76px + env(safe-area-inset-left, 0px));
    padding: calc(14px + var(--sat)) 0 calc(14px + var(--sab)) env(safe-area-inset-left, 0px);
    overflow-y: auto; overscroll-behavior: contain;
    box-shadow: 8px 0 28px rgba(0, 0, 0, .28);
    animation: rail-drawer-in .22s cubic-bezier(.22, .61, .36, 1);
  }
  /* The profile button lives in the chat list's own footer on a phone. */
  .app.rail-drawer-open .team-rail .rail-me-bar { display: none; }
  .rail-drawer-backdrop { display: none; }
  .app.rail-drawer-open .rail-drawer-backdrop {
    display: block; position: fixed; inset: 0; z-index: 59; background: rgba(8, 12, 24, .36);
    animation: rail-drawer-fade .22s ease;
  }
  /* The iOS PWA viewport can stop above the screen's bottom edge. Both layers
     must cover that extension, so neither the rail nor its dimming ends early.
     device-boot.js provides the full screen height in the page's zoomed pixels. */
  html.ios-standalone .app.rail-drawer-open .team-rail,
  html.ios-standalone .app.rail-drawer-open .rail-drawer-backdrop {
    bottom: auto;
    height: max(100lvh, var(--ios-screen-h, 100lvh));
    min-height: 100%;
  }
  /* Pult and Space Board are for a big screen: every button of theirs
     (.desktop-only — the rail, the profile card, «Подключиться») goes on a phone. */
  .desktop-only { display: none !important; }
  /* Personal/tool pages: one edge-to-edge glass card over wallpaper. */
  .feature-screen {
    position: fixed;
    inset: 0;
    z-index: 20;
    width: 100%;
    height: 100%;
    min-height: 100%;
    min-height: 100dvh;
    background: transparent;
    padding: env(safe-area-inset-top, 0px) 0 var(--sab);
    justify-content: flex-start;
    align-items: stretch;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  .app.rail-feature-open.feature-chrome-open .channel-header {
    position: fixed;
    top: env(safe-area-inset-top, 0px);
    left: 12px;
    right: 12px;
    z-index: 25;
    margin: 8px 0 0;
    padding-left: 12px;
  }
  .app.rail-feature-open.mail-mode.feature-chrome-open .channel-header {
    left: 18px;
    right: 18px;
    margin: 0;
    padding: 6px 8px 6px 6px;
    gap: 0 8px;
    min-height: 60px;
    align-items: center;
    align-content: center;
  }
  .app.rail-feature-open.feature-chrome-open #feature-screen {
    padding-top: calc(env(safe-area-inset-top, 0px) + var(--chat-scroll-top, 76px) + 10px);
    padding-left: 0;
    padding-right: 0;
  }
  .app.rail-feature-open.mail-mode:not(.mail-dialog-open) .composer-wrap {
    display: none !important;
  }
  .app.rail-feature-open.mail-mode.feature-chrome-open #feature-screen {
    top: 0;
    left: 18px !important;
    right: 18px !important;
    width: auto !important;
    bottom: calc(8px + var(--sab));
    height: auto;
    min-height: 0;
    padding-top: calc(env(safe-area-inset-top, 0px) + var(--chat-scroll-top, 76px) + 10px);
    padding-bottom: 4px;
    padding-left: 0 !important;
    padding-right: 0 !important;
    overflow: hidden;
  }
  .app.mail-mode .feature-card {
    min-height: 0;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
    padding: 0;
    background: transparent;
    box-shadow: none;
  }
  @supports (min-height: -webkit-fill-available) {
    .feature-screen { min-height: -webkit-fill-available; }
  }
  .feature-card {
    width: 100%;
    max-width: 100%;
    min-height: 100%;
    border-radius: 0;
    border: 0;
    box-shadow: none;
    padding: 8px 16px 28px;
    /* At least the screen tall, and taller with its content (stretch pinned it to
       the screen, and sticky notes below it hung over the wallpaper). */
    align-self: flex-start;
    height: auto;
    box-sizing: border-box;
    background: var(--glass-tools-bg);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
  }
  #dialogue-overlay.dialogue-overlay,
  #notif-center.notif-center {
    padding:
      calc(var(--chat-scroll-top, 76px) + 10px)
      12px
      calc(var(--chat-overlay-bottom, 48px) + 6px);
  }
  .dialogue-card {
    width: min(720px, 100%);
  }
  .feature-back {
    width: 44px; height: 44px; margin: 0 0 2px -8px;
  }
  .sidebar-footer { display: flex; }
  .sidebar-me-btn { display: inline-flex; }
  .sidebar-team-mark {
    display: grid;
    place-items: center;
  }
  .sidebar-logout {
    display: grid;
  }
  .me-bar:hover .user-menu { display: none; }
  .me-bar.menu-open .user-menu {
    display: block;
    position: fixed;
    left: 8px;
    right: auto;
    bottom: calc(78px + var(--sab));
    top: auto;
    width: min(86vw, 304px);
    max-height: calc(100% - 96px);
    z-index: 30;
  }
  .sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    height: auto;
    max-height: 100%;
    min-height: 0;
    z-index: 8;
    transform: none;
    transition: transform .32s cubic-bezier(.22,.61,.36,1);
    box-shadow: none;
    background: color-mix(in srgb, var(--sidebar) var(--glass-menu-mix, 86%), transparent);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
    /* inset:0 already fills the visible viewport. Extra min-height (100lvh /
       fill-available) grows past the screen and clips the profile row on
       tall iPhones (16 / 18 Pro Max). */
    padding-bottom: 0;
    box-sizing: border-box;
  }
  /* Match the Android list while keeping the colour independent of whichever
     chat happens to be prepared behind the menu. */
  html.ios-device .sidebar {
    background: var(--ios-menu-bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  html.ios-device .sidebar-header {
    background: color-mix(in srgb, var(--sidebar-head) var(--glass-menu-mix, 86%), var(--ios-menu-bg));
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  /* Home-screen PWA: -webkit-fill-available stops above the home indicator,
     so html/body wallpaper (#d0e7f5) peeks as a light strip. Paint the list
     navy through that band, and stretch chat wallpaper over it. */
  html.ios-standalone:not(.app-chat-open),
  html.ios-standalone:not(.app-chat-open) body,
  /* Safari tab: the same light wallpaper shows between the list and the toolbar. */
  html.ios-browser:not(.app-chat-open),
  html.ios-browser:not(.app-chat-open) body {
    background-color: var(--ios-menu-footer-bg) !important;
    background-image: none !important;
  }
  /* Do not depend exclusively on the mirrored class on <html>: during a PWA
     resume iOS can paint its bottom extension before that class is reconciled.
     The visible app state is authoritative. The list can also be a drawer over
     a prepared chat, where <html> intentionally keeps app-chat-open. */
  @supports selector(html:has(.app)) {
    html.ios-device:has(.app:not(.chat-open)),
    html.ios-device:has(.app:not(.chat-open)) body,
    html.ios-device:has(.app.menu-drawer-open),
    html.ios-device:has(.app.menu-drawer-open) body {
      background-color: var(--ios-menu-footer-bg) !important;
      background-image: none !important;
    }
  }
  html.ios-standalone .sidebar {
    bottom: 0;
  }
  html.ios-standalone.app-chat-open,
  html.ios-standalone.app-chat-open body {
    background-size: cover !important;
  }
  /* …down to the screen's bottom edge (--ios-screen-h, device-boot.js): the
     window is shorter than the screen there, and the page under it showed. */
  html.ios-standalone.app-chat-open:not([data-wallpaper="custom"]),
  html.ios-standalone.app-chat-open:not([data-wallpaper="custom"]) body {
    background-size: var(--wallpaper-lock-w, 100vw) max(100lvh, var(--ios-screen-h, 100lvh)) !important;
    background-position: left top !important;
  }
  html.ios-standalone .chat-wallpaper,
  html.ios-standalone .app.chat-open .chat-wallpaper {
    min-height: max(100lvh, var(--ios-screen-h, 100lvh)) !important;
    height: max(100lvh, var(--wallpaper-lock-h, 100lvh), var(--ios-screen-h, 100lvh)) !important;
  }
  .sidebar-footer {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding-top: 8px;
    padding-bottom: max(4px, var(--sab));
    width: 100%;
    box-sizing: border-box;
  }
  html.ios-device .sidebar-footer {
    padding-bottom: max(8px, var(--sab));
    background: var(--ios-menu-footer-bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .sidebar-footer .sidebar-me-row {
    display: flex;
    flex: 0 0 auto;
    width: 100%;
    align-items: center;
    gap: 2px;
  }
  .sidebar-footer .sidebar-me-btn {
    display: inline-flex;
    flex: 1 1 auto;
    width: auto;
    max-width: none;
    min-width: 0;
    padding: 2px 8px 0 4px;
  }
  .sidebar-footer .sidebar-me-name {
    max-width: none;
    flex: 1 1 auto;
  }
  /* Tools live in the profile card on mobile. */
  .sidebar-footer .sidebar-rail-tools { display: none !important; }
  /* The main menu (channels, direct messages) as large as the settings menu. */
  #chat-nav .section-head > span:first-child {
    font-size: calc(14px * 1.1 * var(--text-scale, 1));
  }
  #chat-nav .section-head { padding-top: 16px; padding-bottom: 6px; }
  #chat-nav .nav-item {
    font-size: calc(17px * 1.1 * var(--text-scale, 1));
    padding: 9px 12px;
    gap: 12px;
    min-height: 44px;
  }
  #chat-nav .nav-item .avatar {
    width: 32px; height: 32px; min-width: 32px; min-height: 32px; max-width: 32px; max-height: 32px;
    flex: 0 0 32px; font-size: 13px;
  }
  #chat-nav .nav-item .avatar .presence { width: 12px; height: 12px; }
  #chat-nav .hash { width: 22px; }
  #channel-actions button {
    font-size: calc(17px * 1.1 * var(--text-scale, 1));
    padding: 10px 12px;
    min-height: 44px;
  }
  /* 16 px at least: iPhone zooms the page into a smaller field on focus. */
  .sidebar .filter { font-size: max(16px, calc(16px * var(--text-scale, 1))); min-height: 44px; }
  /* Settings menu opened from profile → larger type on phone. */
  #settings-nav .section-head > span:first-child {
    font-size: calc(14px * 1.1 * var(--text-scale, 1));
  }
  #settings-nav .nav-item {
    font-size: calc(17px * 1.1 * var(--text-scale, 1));
    padding: 10px 12px;
    gap: 12px;
    min-height: 44px;
  }
  #settings-nav .nav-item svg {
    width: 24px;
    height: 24px;
  }
  #accounts-nav .nav-item {
    font-size: calc(17px * 1.1 * var(--text-scale, 1));
    padding: 10px 12px;
    gap: 12px;
    min-height: 44px;
  }
  #accounts-nav .nav-item svg {
    width: 24px;
    height: 24px;
  }
  .app.chat-open .sidebar {
    transform: translateX(-100%);
    pointer-events: none;
    z-index: 20;
    transition: transform .32s cubic-bezier(.22,.61,.36,1);
    will-change: transform;
    box-shadow: none;
  }
  .app.chat-open.menu-drawer-open .sidebar,
  .app.chat-open.menu-dragging .sidebar {
    pointer-events: auto;
    box-shadow: 12px 0 32px rgba(0,0,0,.22);
  }
  .app.chat-open.menu-drawer-open .sidebar {
    transform: translate3d(0, 0, 0);
  }
  .app.chat-open .sidebar.is-dragging {
    transition: none;
  }
  .app.chat-open .sidebar.is-settling {
    transition: transform .32s cubic-bezier(.22,.61,.36,1);
  }
  /* iOS: pin shell; never allow horizontal document pan (white gutter). */
  html.ios-device,
  html.ios-device body {
    overflow-x: hidden !important;
    overscroll-behavior-x: none !important;
    touch-action: pan-y;
    width: 100% !important;
    max-width: 100% !important;
  }
  html.ios-device .app {
    overflow-x: hidden !important;
    overscroll-behavior-x: none !important;
    touch-action: pan-y;
    width: 100% !important;
    max-width: 100% !important;
  }
  html.ios-device .app.chat-open.menu-drawer-open .main {
    background: var(--wallpaper-color, #d0e7f5) !important;
  }
  html.ios-device .app.chat-open .sidebar {
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: none !important;
    will-change: auto;
    /* Class toggle only — CSS transition, no mid-gesture inline transforms. */
    transition: transform .32s cubic-bezier(.22,.61,.36,1);
  }
  html.ios-device .app.chat-open.menu-drawer-open .sidebar {
    transform: translate3d(0, 0, 0) !important;
  }
  html.ios-device .app.chat-open:not(.menu-drawer-open) .sidebar {
    transform: translate3d(-100%, 0, 0) !important;
  }
  .menu-drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 19;
    background: rgba(15, 23, 42, .36);
    opacity: 0;
    transition: opacity .32s ease;
    pointer-events: none;
  }
  .app.menu-drawer-open .menu-drawer-backdrop:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
  }
  .app.menu-dragging .menu-drawer-backdrop:not(.hidden) {
    transition: none;
    pointer-events: none;
  }
  /* Channels ↔ settings list: slide only while swapping (no permanent absolute layers). */
  #sidebar-scroll {
    position: relative;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .app.settings-nav-animating #sidebar-scroll {
    overflow: hidden;
  }
  .app.settings-nav-animating #chat-nav,
  .app.settings-nav-animating #settings-nav {
    will-change: transform;
  }
  .app.settings-open.settings-nav-prep #chat-nav,
  .app.settings-open.settings-nav-exit #chat-nav {
    display: block !important;
  }
  .app.settings-open.settings-nav-prep #settings-nav,
  .app.settings-open.settings-nav-exit #settings-nav {
    display: block !important;
  }
  .app.settings-open.settings-nav-prep #chat-nav {
    transform: none;
  }
  .app.settings-open.settings-nav-prep #settings-nav {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    width: 100%;
    transform: translate3d(100%, 0, 0);
    z-index: 2;
  }
  .app.settings-open.settings-nav-animating:not(.settings-nav-prep) #chat-nav {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    width: 100%;
    transform: translate3d(-28%, 0, 0);
    opacity: 0;
    pointer-events: none;
    transition: transform .32s cubic-bezier(.22,.61,.36,1), opacity .28s ease;
  }
  .app.settings-open.settings-nav-animating:not(.settings-nav-prep) #settings-nav {
    position: relative;
    transform: none;
    transition: transform .32s cubic-bezier(.22,.61,.36,1);
  }
  .app.settings-open.settings-nav-exit #chat-nav {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    width: 100%;
    transform: none;
    opacity: 1;
    transition: transform .32s cubic-bezier(.22,.61,.36,1), opacity .28s ease;
  }
  .app.settings-open.settings-nav-exit #settings-nav {
    position: relative;
    transform: translate3d(100%, 0, 0);
    transition: transform .32s cubic-bezier(.22,.61,.36,1);
  }
  .nav-backdrop { display: none !important; }
  .menu-toggle { display: grid; }
  .settings-menu {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    margin: 0 0 2px -8px;
    padding: 0;
    color: var(--text-strong);
    justify-self: start;
    border-radius: 10px;
  }
  .settings-menu svg {
    width: 22px;
    height: 22px;
    display: block;
    margin: 0;
  }
  /* Settings list must not be covered by the detail panel. */
  .app.settings-open:not(.chat-open):not(.settings-detail-exit) #admin-screen,
  .app.settings-open:not(.settings-detail-open):not(.settings-detail-exit) #admin-screen {
    display: none !important;
  }
  /* Full-screen settings detail — cover wallpaper and chat chrome. */
  .app.settings-detail-open #admin-screen:not(.hidden),
  .app.settings-open.chat-open #admin-screen:not(.hidden),
  .app.settings-detail-exit #admin-screen:not(.hidden) {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    inset: 0 !important;
    z-index: 40 !important;
    width: 100% !important;
    height: 100% !important;
    height: 100dvh !important;
    min-height: 100% !important;
    min-height: 100dvh !important;
    max-height: none !important;
    background: #fff !important;
    display: flex !important;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 16px calc(32px + var(--sab));
    box-sizing: border-box;
    transform: translate3d(0, 0, 0);
    transition: transform .32s cubic-bezier(.22,.61,.36,1);
  }
  .app.settings-detail-exit #admin-screen:not(.hidden) {
    transform: translate3d(100%, 0, 0);
    pointer-events: none;
  }
  .app.settings-detail-enter #admin-screen:not(.hidden) {
    transform: translate3d(100%, 0, 0);
    transition: none;
  }
  .app.settings-detail-enter.settings-detail-enter-active #admin-screen:not(.hidden) {
    transform: translate3d(0, 0, 0);
    transition: transform .32s cubic-bezier(.22,.61,.36,1);
  }
  /* Do not set height: -webkit-fill-available on this overlay: iOS can
     compute it as 0 and you get a blank white screen over the app. */
  .app.settings-open.chat-open #admin-screen:not(.hidden):not(:has([data-panel]:not(.hidden))) {
    display: none !important;
  }
  .app.settings-detail-open .chat-wallpaper,
  .app.settings-open.chat-open .chat-wallpaper {
    display: none !important;
    visibility: hidden !important;
  }
  .app.settings-detail-open .settings-card,
  .app.settings-open.chat-open .settings-card {
    width: 100%;
    max-width: 100%;
    min-height: 100%;
    flex: 1 0 auto;
    overflow-x: hidden;
    box-sizing: border-box;
    border-radius: 0;
    box-shadow: none;
    align-self: stretch;
    background: #fff;
    display: flex;
    flex-direction: column;
  }
  .app.settings-detail-open #admin-actions,
  .app.settings-open.chat-open #admin-actions,
  html.capacitor-android .app.settings-open #admin-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin-top: auto;
    padding-top: 12px;
    padding-bottom: calc(8px + var(--sab));
    background: #fff;
  }
  .settings-card h1 { font-size: calc(26px * var(--text-scale, 1)); line-height: 1.2; }
  /* Settings list (screen 5): hide profile row. */
  .app.settings-open .sidebar-footer,
  .app.settings-open #sidebar-footer {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
    padding: 0 !important;
    margin: 0 !important;
    pointer-events: none !important;
  }
  /* To-chat chevron removed from mobile. */
  .sidebar-to-chat {
    display: none !important;
  }
  .settings-panel-sub {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .for-all-head {
    display: none; /* label lives on each mobile for-all toggle */
  }
  /* Appearance (mobile only): in-card toggles with «Для всех» above each switch. */
  [data-panel="appearance"] .settings-panel-sub {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  [data-panel="appearance"] .for-all-head {
    display: none !important;
  }
  [data-panel="appearance"] .appearance-row {
    position: relative;
    grid-template-columns: minmax(0, 1fr);
    column-gap: 0;
  }
  [data-panel="appearance"] .appearance-row:has(> .for-all-toggle:not(.hidden)) .appearance-row-body {
    padding-right: 70px; /* room for in-card toggle + label */
  }
  [data-panel="appearance"] .appearance-row > .for-all-toggle {
    --for-all-lift: calc(1.25em + 10px + (48px - 32px) / 2);
    position: absolute;
    top: calc(12px + var(--for-all-lift));
    right: 14px;
    width: 52px;
    min-height: 32px;
    margin: 0 !important;
    align-self: auto;
    justify-self: auto;
    z-index: 2;
    border: 0;
    background: transparent;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
  }
  [data-panel="appearance"] .appearance-forall-head { display: none !important; }
  [data-panel="appearance"] .appearance-row > .for-all-toggle .for-all-toggle-label {
    display: block;
    position: absolute;
    left: 50%;
    top: calc(-1 * var(--for-all-lift));
    transform: translateX(-50%);
    width: max-content;
    text-align: center;
    font-size: calc(11px * var(--text-scale, 1));
    font-weight: 500;
    color: #6b7080;
    line-height: 1.15;
    white-space: nowrap;
  }
  [data-panel="appearance"] .appearance-row > .for-all-toggle { display: flex; align-self: auto; }
  [data-panel="appearance"] .appearance-row-tall > .for-all-toggle {
    margin-top: 0 !important;
  }
  .notify-row {
    grid-template-columns: minmax(0, 1fr);
    column-gap: 0;
    row-gap: 8px;
  }
  .cal-pref-line {
    grid-template-columns: minmax(0, 1fr);
    column-gap: 0;
    row-gap: 8px;
  }
  .notify-row > .for-all-toggle,
.cal-pref-line > .for-all-toggle {
    width: 100%;
    min-height: 48px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid #ebebeb;
    border-radius: 10px;
    background: #fafbfc;
    justify-self: stretch;
  }

  
  .settings-card .plugin-card label.settings-toggle {
    padding: 6px 0 !important;
    min-height: 0 !important;
  }
  .notify-row > .for-all-toggle .for-all-toggle-label,
.cal-pref-line > .for-all-toggle .for-all-toggle-label {
    display: block;
    flex: 1;
    min-width: 0;
    font-size: calc(14px * var(--text-scale, 1));
    font-weight: 700;
    color: var(--text-strong);
  }
  .notify-row > .for-all-toggle .settings-toggle-ui,
.cal-pref-line > .for-all-toggle .settings-toggle-ui,
.settings-card .notify-row > .for-all-toggle .settings-toggle-ui,
.settings-card .cal-pref-line > .for-all-toggle .settings-toggle-ui,
[data-panel="appearance"] .appearance-row > .for-all-toggle .settings-toggle-ui,
.settings-card [data-panel="appearance"] .appearance-row > .for-all-toggle .settings-toggle-ui {
    width: 52px;
    height: 32px;
    flex: none;
  }
  .notify-row > .for-all-toggle .settings-toggle-ui::after,
.cal-pref-line > .for-all-toggle .settings-toggle-ui::after,
.settings-card .notify-row > .for-all-toggle .settings-toggle-ui::after,
.settings-card .cal-pref-line > .for-all-toggle .settings-toggle-ui::after,
[data-panel="appearance"] .appearance-row > .for-all-toggle .settings-toggle-ui::after,
.settings-card [data-panel="appearance"] .appearance-row > .for-all-toggle .settings-toggle-ui::after {
    top: 3px;
    left: 3px;
    width: 26px;
    height: 26px;
  }
  .notify-row > .for-all-toggle input:checked + .settings-toggle-ui::after,
.cal-pref-line > .for-all-toggle input:checked + .settings-toggle-ui::after,
.settings-card .notify-row > .for-all-toggle input:checked + .settings-toggle-ui::after,
.settings-card .cal-pref-line > .for-all-toggle input:checked + .settings-toggle-ui::after,
[data-panel="appearance"] .appearance-row > .for-all-toggle input:checked + .settings-toggle-ui::after,
.settings-card [data-panel="appearance"] .appearance-row > .for-all-toggle input:checked + .settings-toggle-ui::after {
    transform: translateX(20px);
  }
  .settings-card label.settings-toggle {
    min-height: 52px;
    padding: 16px;
    gap: 16px;
  }
  .settings-card .settings-toggle-ui {
    flex: 0 0 52px;
    width: 52px;
    height: 32px;
  }
  .settings-card .settings-toggle-ui::after {
    top: 3px;
    left: 3px;
    width: 26px;
    height: 26px;
  }
  .settings-card label.settings-toggle input:checked + .settings-toggle-ui::after {
    transform: translateX(20px);
  }
  .settings-avatar-block { display: flex; }
  .menu-toggle .menu-ico-list { display: none; }
  .menu-toggle .menu-ico-back { display: block; }
  .main { width: 100%; min-width: 0; min-height: 0; overflow: hidden; }
  /* Startup splash only — sidebar/rail stay at the default .team-mark size. */
  .boot .team-mark,
  #boot-team-mark {
    width: 112px;
    height: 112px;
    border-radius: 50%;
    font-size: 36px;
  }
  .boot .team-mark.has-logo,
  #boot-team-mark.has-logo {
    background: transparent;
    box-shadow: none;
  }
  /* Fixed wallpaper layer: size is frozen in px by JS so keyboard resize
     cannot reflow background-size:cover (no squash). Stays behind chrome;
     soft keyboard overlays this paint — never expose sidebar blue. */
  .chat-wallpaper {
    position: fixed;
    inset: auto;
    top: 0;
    left: 0;
    right: auto;
    bottom: auto;
    width: var(--wallpaper-lock-w, 100vw);
    height: var(--wallpaper-lock-h, 100lvh);
    min-height: 100lvh;
    min-height: 100dvh;
    z-index: 0;
    background-size: cover !important;
    background-position: center top !important;
  }
  html[data-wallpaper="custom"] .chat-wallpaper {
    background-size: var(--wallpaper-size-mobile, cover) !important;
    background-position: var(--wallpaper-pos-mobile, center center) !important;
  }
  html[data-wallpaper="space"] .chat-wallpaper {
    background-size: var(--wallpaper-size-mobile, cover), cover !important;
    background-position: var(--wallpaper-pos-mobile, center center), center !important;
  }
  /* Keep html/body wallpaper crop identical to the locked layer so the
     status-bar strip never falls back to a flat/gray fill (Android). */
  html, body {
    background-size: var(--wallpaper-lock-w, 100vw) var(--wallpaper-lock-h, 100dvh) !important;
    background-position: left top !important;
  }
  html[data-wallpaper="custom"],
  html[data-wallpaper="custom"] body {
    background-size: var(--wallpaper-size-mobile, cover) !important;
    background-position: var(--wallpaper-pos-mobile, center center) !important;
  }
  html[data-wallpaper="space"],
  html[data-wallpaper="space"] body {
    background-size: var(--wallpaper-size-mobile, cover), cover !important;
    background-position: var(--wallpaper-pos-mobile, center center), center !important;
  }
  .app.chat-open .chat-wallpaper {
    top: 0 !important;
    left: 0 !important;
    width: var(--wallpaper-lock-w, 100vw) !important;
    min-width: 100vw;
    min-height: 100dvh !important;
    background-position: left top !important;
  }
  html[data-wallpaper="custom"] .app.chat-open .chat-wallpaper,
  html[data-wallpaper="space"] .app.chat-open .chat-wallpaper {
    background-position: var(--wallpaper-pos-mobile, center center) !important;
  }
  .app.chat-open .main {
    background: transparent !important;
  }
  html, body, .app {
    height: 100%;
    min-height: 100%;
    min-height: 100dvh;
  }
  .main {
    flex: 1;
    min-height: 0;
  }
  .composer-wrap {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding-top: 8px;
    padding-left: calc(12px + env(safe-area-inset-left, 0px));
    padding-right: calc(12px + env(safe-area-inset-right, 0px));
    padding-bottom: calc(8px + var(--sab) + var(--kb-inset, 0px));
    background: transparent;
    z-index: 4;
    margin-top: auto;
    flex: none;
  }
  /* iOS Safari tab: bottom chrome already clears the home indicator. Extra
     safe-area padding left a tall empty strip under the composer (unlike Android).
     Keep a modest pad so mic/cam stay above the gesture edge. */
  html.ios-device.ios-browser .composer-wrap {
    padding-bottom: 12px;
  }

  /* iOS: enlarge composer icon hit targets (HIG ~44pt). */
  html.ios-device .attach-btn,
  html.ios-device .emoji-btn,
  html.ios-device .media-btn,
  html.ios-device .send {
    width: max(44px, var(--chrome-icon-btn));
    height: max(44px, var(--chrome-icon-btn));
  }
  html.ios-device .media-btn::before {
    top: -12px;
    right: -10px;
    bottom: -14px;
    left: -10px;
  }

  /* ---- iOS keyboard layout (IOS_KB_LAYOUT=true in app.js) ---- */
  html.ios-device.ios-kb-layout.composer-focused,
  html.ios-device.ios-kb-layout.composer-focused body {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
    overscroll-behavior: none;
  }
  html.ios-device.ios-kb-layout.composer-focused .channel-header {
    flex-shrink: 0 !important;
    position: relative;
    z-index: 12;
    transform: none !important;
  }
  html.ios-device.ios-kb-layout.composer-focused.chat-chrome-overlay .channel-header {
    position: absolute;
  }
  html.ios-device.ios-kb-layout.composer-focused .composer-wrap {
    flex-shrink: 0 !important;
  }
  html.ios-device.ios-kb-layout.ios-focus-lift #composer-input {
    transform: translateY(var(--ios-focus-lift, 0px));
    opacity: 0;
  }
  html.ios-device.ios-kb-layout.kb-vv-pin .app {
    position: fixed !important;
    top: var(--vv-top, 0px) !important;
    left: 0 !important;
    right: 0 !important;
    bottom: auto !important;
    width: 100% !important;
    height: var(--vv-height, 100%) !important;
    max-height: var(--vv-height, 100%) !important;
    min-height: 0 !important;
    overflow: hidden !important;
    transform: none !important;
  }
  html.ios-device.ios-kb-layout.kb-vv-pin .main {
    min-height: 0;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  html.ios-device.ios-kb-layout.kb-vv-pin .thread {
    flex: 1 1 auto;
    min-height: 0;
  }
  html.ios-device.ios-kb-layout.kb-vv-pin .chat-wallpaper {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: var(--wallpaper-lock-w, 100vw) !important;
    height: var(--wallpaper-lock-h, 100dvh) !important;
    min-height: var(--wallpaper-lock-h, 100dvh) !important;
    z-index: 0 !important;
  }
  html.ios-device.ios-kb-layout.kb-vv-pin.kb-open .composer-wrap {
    padding-bottom: 6px;
  }
  /* Mobile: safe-area insets on the shared glass header. */
  .channel-header {
    margin: calc(6px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-left, 0px)) 0 calc(12px + env(safe-area-inset-right, 0px));
  }
  /* iOS: keep header snug under the status bar / Dynamic Island (Android-like). */
  html.ios-device .channel-header {
    margin-top: calc(2px + env(safe-area-inset-top, 0px));
  }
  html.chat-chrome-overlay .main > .channel-header {
    top: calc(6px + env(safe-area-inset-top, 0px) + var(--chat-banner-h, 0px));
    left: calc(12px + env(safe-area-inset-left, 0px));
    right: calc(12px + env(safe-area-inset-right, 0px));
  }
  html.ios-device.chat-chrome-overlay .main > .channel-header {
    top: calc(2px + env(safe-area-inset-top, 0px) + var(--chat-banner-h, 0px));
  }
  html.chat-chrome-overlay .main > .pinned-banner:not(.hidden) {
    left: calc(12px + env(safe-area-inset-left, 0px));
    right: calc(12px + env(safe-area-inset-right, 0px));
  }
  /* Elevate chat header above messages only while chat is open.
     If always elevated, it paints over the sidebar after going back. */
  .main > .channel-header {
    z-index: 1;
  }
  .app.chat-open .main > .channel-header {
    z-index: 12;
  }
  /* Menu → chat: header drops from top, composer rises from bottom. */
  .app.chat-chrome-enter:not(.chat-chrome-enter-active) .channel-header {
    transform: translate3d(0, -110%, 0) !important;
    opacity: 0 !important;
    pointer-events: none !important;
    transition: none !important;
  }
  .app.chat-chrome-enter:not(.chat-chrome-enter-active) .composer-wrap {
    transform: translate3d(0, 110%, 0) !important;
    opacity: 0 !important;
    pointer-events: none !important;
    transition: none !important;
  }
  .app.chat-chrome-enter.chat-chrome-enter-active .channel-header,
  .app.chat-chrome-enter.chat-chrome-enter-active .composer-wrap {
    transform: translate3d(0, 0, 0);
    opacity: 1;
    pointer-events: auto;
    transition:
      transform var(--chat-enter-ms, 560ms) cubic-bezier(.22,.61,.36,1),
      opacity var(--chat-enter-ms, 560ms) cubic-bezier(.22,.61,.36,1);
    will-change: transform, opacity;
  }
  @media (prefers-reduced-motion: reduce) {
    .app.chat-chrome-enter:not(.chat-chrome-enter-active) .channel-header,
    .app.chat-chrome-enter:not(.chat-chrome-enter-active) .composer-wrap,
    .app.chat-chrome-enter.chat-chrome-enter-active .channel-header,
    .app.chat-chrome-enter.chat-chrome-enter-active .composer-wrap {
      transform: none !important;
      opacity: 1 !important;
      transition: none !important;
    }
  }
  .app.chat-open .channel-header .member-menu-wrap {
    z-index: 13;
  }
  .app.chat-open .channel-header .member-search-menu {
    position: absolute;
    left: auto;
    right: 0;
    top: calc(100% + 8px);
    width: min(92vw, 320px);
    max-width: min(92vw, 320px);
    z-index: 40;
    background: var(--glass-chip-bg);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
    border: var(--glass-border);
  }
  .pinned-banner {
    margin: 6px calc(12px + env(safe-area-inset-left, 0px)) 0 calc(12px + env(safe-area-inset-right, 0px));
  }
  /* Keyboard open: only pad when --kb-inset > 0 (overlays-content).
     If the layout already resized above the keyboard, --kb-inset stays 0. */
  html.kb-open .composer-wrap {
    padding-bottom: calc(6px + var(--sab) + var(--kb-inset, 0px));
  }
  /* Keep layout height stable while the soft keyboard overlays content. */
  html.kb-open,
  html.kb-open body {
    overflow: hidden;
    overscroll-behavior: none;
  }
  html.kb-open .app {
    height: 100%;
    max-height: 100%;
  }
  .composer-shell { padding: 6px 6px 6px 8px; }
  .composer textarea,
  .composer .composer-rich { font-size: 16px; }
  .composer-tools { gap: 2px; }
  .attach-btn, .emoji-btn, .media-btn, .send {
    width: var(--chrome-icon-btn);
    height: var(--chrome-icon-btn);
  }
  .icq-smiley { width: 30px; height: 30px; }
  .emoji-picker-item { font-size: 30px; }
  .emoji-picker-item.is-icq img.icq-smiley { width: 34px; height: 34px; }
  .msg.emoji-only .msg-body { font-size: 48px; }
  .msg.emoji-only.emoji-2 .msg-body { font-size: 40px; }
  .msg.emoji-only.emoji-3 .msg-body { font-size: 32px; }
  .typing { min-height: 0; padding: 0 16px; }
  .rhs { position: fixed; right: 0; top: 0; bottom: 0; z-index: 9; box-shadow: -8px 0 24px rgba(0,0,0,.15); }
  /* Full height on a phone: keep the head below the status bar, the foot above the home bar. */
  .rhs, .rhs.sheet { padding-top: var(--sat); padding-bottom: var(--sab); box-sizing: border-box; }
  .rhs.sheet {
    position: fixed; top: 0; right: 0; bottom: 0; left: auto;
    width: min(78vw, 300px); max-width: 78vw; flex: none;
    z-index: 25; box-shadow: -12px 0 32px rgba(0,0,0,.18);
    transform: translate3d(0,0,0);
    transition: transform .32s cubic-bezier(.22,.61,.36,1);
    will-change: transform;
  }
  /* iOS: left edge shadow/border reads as a hard black strip on DM/channel cards. */
  html.ios-device .rhs,
  html.ios-device .rhs.sheet,
  html.ios-device .app.profile-open .rhs.sheet {
    border-left: none !important;
    box-shadow: none !important;
  }
  .rhs.sheet.is-dragging { transition: none; }
  .rhs.sheet.is-settling { transition: transform .32s cubic-bezier(.22,.61,.36,1); }
  .app.profile-open .rhs.sheet {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(78vw, 300px);
    max-width: 78vw;
    flex: none;
  }
  .app.sheet-dragging .main,
  .app.sheet-dragging .thread {
    touch-action: pan-y;
  }
  .rhs.sheet .profile-visit {
    padding: 12px 14px 20px;
  }
  .rhs.sheet .card-avatar-wrap {
    width: 112px; height: 112px;
    min-width: 112px; min-height: 112px;
    max-width: 112px; max-height: 112px;
    flex: 0 0 112px;
  }
  .rhs.sheet .profile-visit .avatar {
    width: 100% !important; height: 100% !important;
    min-width: 0 !important; min-height: 0 !important;
    max-width: none !important; max-height: none !important;
    flex: none !important;
  }
  .rhs.sheet .card-availability {
    flex: 0 0 auto;
  }
  /* Storage is in the profile-card tools row on mobile. */
  #card-media {
    display: none !important;
  }
  .rhs-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 8;
    background: var(--glass-dim);
    opacity: 0;
    transition: opacity .28s ease;
    pointer-events: none;
  }
  .app.profile-open .rhs-backdrop:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
  }
  .app.sheet-dragging .rhs-backdrop:not(.hidden) {
    transition: none;
    pointer-events: none;
  }
}

/* «Выбрать» on a phone: the count on its own line, the three buttons share the
   width — in one row at 108px each «Удалить» went off the screen. */
@media (max-width: 800px) {
  .select-bar { flex-wrap: wrap; gap: 8px; padding: 6px 0 2px; }
  .select-count { flex: 1 0 100%; margin: 0 0 0 6px; }
  .select-bar .btn { flex: 1 1 0; min-width: 0; padding: 10px 8px; font-size: 14px; white-space: nowrap; }
}

/* Phones: the chat in its glass window over the wallpaper, as on a computer —
   from under the status bar to just above the bottom, the messages clipped to it
   (clip-path keeps the layout, so the header/composer offsets stay as computed). */
@media (max-width: 800px) {
  html.chat-chrome-overlay .main {
    --chat-win-top: calc(var(--sat) + 2px);
    --chat-win-side: 6px;
    --chat-win-bottom: max(6px, var(--sab));
  }
  html.chat-chrome-overlay .app.chat-open .main::after,
  html.chat-chrome-overlay .main::after {
    content: "";
    position: absolute;
    top: var(--chat-win-top);
    left: var(--chat-win-side);
    right: var(--chat-win-side);
    bottom: var(--chat-win-bottom);
    z-index: 0;
    border-radius: 20px;
    background: var(--glass-window-bg, rgba(255, 255, 255, .55));
    border: 1px solid rgba(255, 255, 255, .75);
    box-shadow: 0 12px 40px rgba(40, 50, 110, .10);
    pointer-events: none;
  }
  html.chat-chrome-overlay .main > .thread {
    clip-path: inset(var(--chat-win-top) calc(var(--chat-win-side) + 1px) var(--chat-win-bottom) calc(var(--chat-win-side) + 1px) round 19px);
  }
}

/* iPhone home-screen app: the window reaches above the header (it sits inside,
   as on a computer) and down closer to the edge — the composer with it, still
   clear of the home indicator. The keyboard keeps its own padding. */
@media (max-width: 800px) {
  html.ios-standalone.chat-chrome-overlay .main {
    --chat-win-top: max(0px, calc(env(safe-area-inset-top, 0px) - 8px));
    --chat-win-bottom: 16px;
  }
  html.ios-standalone.chat-chrome-overlay:not(.kb-open) .main > .composer-wrap {
    padding-bottom: 22px;
  }
}

/* iPhone: the profile / channel card takes the whole screen, under the notch. */
@media (max-width: 800px) {
  html.ios-device .rhs.sheet,
  html.ios-device .app.profile-open .rhs.sheet {
    width: 100vw !important;
    max-width: 100vw !important;
    left: 0 !important;
  }
}

/* Phones: with the menu fully open over a chat, the chat isn't drawn under the
   (86% opaque, blurred) menu — its bubbles showed through and moved behind it.
   While the menu is dragged or settles the chat stays, so the menu slides over it. */
@media (max-width: 800px) {
  .app.chat-open.menu-drawer-open:not(.menu-dragging) > .main { visibility: hidden; }
}

/* Android app: the profile / channel card scrolls clear of the navigation bar. */

@keyframes rail-drawer-in { from { transform: translate3d(-100%, 0, 0); } to { transform: none; } }
@keyframes rail-drawer-fade { from { opacity: 0; } to { opacity: 1; } }
