/* Mobile layout layer: keeps desktop navigation untouched and gives small screens
   a compact header, fixed bottom navigation, and contained page scrolling. */
@media (max-width: 700px) {
  html,
  body,
  #app {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .shell {
    display: block;
    width: 100%;
    min-height: 100dvh;
    height: 100dvh;
    overflow: hidden;
  }

  .shell > .sidebar {
    position: fixed;
    inset: 0 0 auto;
    z-index: 20;
    display: block;
    width: 100%;
    height: 64px;
    min-height: 64px;
    padding: 12px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: hidden;
  }

  .sidebar .brand {
    width: max-content;
    font-size: 20px;
  }

  .sidebar .nav,
  .sidebar .account {
    display: none;
  }

  .shell > .main {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    padding: 86px 14px 92px;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .topline {
    margin-bottom: 20px;
    gap: 12px;
  }

  .h1 {
    font-size: clamp(27px, 8vw, 34px);
  }

  .card {
    width: 100%;
    padding: 16px;
    border-radius: 16px;
  }

  .page-sections {
    gap: 22px;
    margin-top: 16px;
  }

  .grid,
  .grid2,
  .grid3 {
    grid-template-columns: minmax(0, 1fr);
  }

  .row {
    min-width: 0;
  }

  .person {
    min-width: 0;
    padding: 11px;
  }

  .person .grow {
    min-width: 0;
  }

  .person > .btn,
  .person > span:has(.btn) {
    flex: 0 0 auto;
  }

  .friends-sections .person .grow {
    display: grid;
    gap: 2px;
    align-content: center;
  }

  .friends-sections .person .grow > b {
    line-height: 1.2;
  }

  .friends-sections .person .grow > .muted {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 3px;
    line-height: 1.25;
  }

  .search-card > .row {
    align-items: stretch;
    flex-direction: column;
  }

  .search-card > .row > .btn {
    width: 100%;
  }

  .search-card .result-list .btn {
    width: auto;
    max-width: max-content;
    white-space: nowrap;
  }

  .friends-sections {
    gap: 22px;
  }

  .setting-row {
    min-height: 88px;
    padding: 19px 14px;
    gap: 12px;
  }

  .setting-row > div {
    min-width: 0;
  }

  .setting-row p {
    max-width: 44ch;
  }

  .theme-options {
    width: 100%;
  }

  .theme-choice {
    flex: 1;
    padding: 8px 7px;
  }

  .settings-link {
    padding: 16px 14px;
  }

  .profile-card {
    margin-inline: auto;
  }

  .bottomnav {
    position: fixed;
    inset: auto 0 0;
    z-index: 25;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    width: 100%;
    min-height: 70px;
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(14px);
  }

  .bottomnav button {
    min-width: 0;
    justify-content: center;
    padding: 8px 3px;
    border-radius: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    text-align: center;
  }

  .messages-page-body {
    height: calc(100dvh - 210px) !important;
    min-height: 420px !important;
    overflow: hidden !important;
  }

  .messages-page-body .messages-layout,
  .messages-page-body .conversation-panel,
  .messages-page-body .chat-panel {
    min-width: 0;
    width: 100%;
  }

  .messages-page-body .messages-layout {
    height: 100% !important;
    min-height: 0 !important;
  }

  .messages-page-body .conversation-panel,
  .messages-page-body .chat-panel {
    height: 100% !important;
    min-height: 0 !important;
  }

  .message-redesign .chat-panel .message-header {
    padding-inline: 10px;
  }

  .message-redesign .chat-panel .message-header .message-peer-info b {
    max-width: 46vw;
    font-size: 16px !important;
  }

  .message-redesign .chat-panel .messages {
    padding-inline: 8px;
  }

  .message-redesign .chat-panel #composer {
    right: 4px !important;
    left: 4px !important;
    gap: 5px;
  }

  .message-redesign .chat-panel #composer > .input {
    min-width: 0;
    padding-inline: 10px;
    font-size: 14px;
  }

  .message-redesign .chat-panel #composer > .message-tools {
    gap: 3px;
  }

  .message-redesign .chat-panel #composer > .message-tools .message-tool {
    width: 30px;
    height: 30px;
  }

  .message-redesign .chat-panel #composer > button:not(.message-tool) {
    width: 38px;
    height: 36px;
    padding: 0;
    font-size: 0;
  }

  .message-redesign .chat-panel #composer > button:not(.message-tool)::after {
    content: '↑';
    font-size: 17px;
  }

  .call-page {
    min-height: calc(100dvh - 190px);
    border-radius: 18px;
  }

  .call-controls {
    bottom: 16px;
    flex-wrap: wrap;
  }

  .call-control {
    min-width: 64px;
    height: 56px;
    padding-inline: 5px;
  }

  .active-call-pill,
  .call-message-pill {
    max-width: calc(100% - 20px);
  }

  .active-call-pill {
    top: 10px;
  }

  .toast {
    right: 12px;
    bottom: 82px;
    left: 12px;
    text-align: center;
  }
}

@media (max-width: 380px) {
  .bottomnav button {
    font-size: 10px;
  }

  .setting-row {
    padding-inline: 11px;
  }

  .toggle {
    width: 44px;
  }

  .toggle.on span {
    transform: translateX(16px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .bottomnav,
  .shell > .sidebar {
    backdrop-filter: none;
  }
}
