/* Mobile-only polish layer: keeps desktop layout untouched while improving touch ergonomics. */
:root {
  --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
  --mobile-safe-top: env(safe-area-inset-top, 0px);
  --mobile-app-height: 100vh;
  --mobile-control-size: 44px;
  --mobile-shell-gap: 14px;
  --mobile-composer-height: 118px;
  --mobile-topbar-height: 72px;
  --kb-offset: 0px;
  --mobile-edge-pad: max(14px, env(safe-area-inset-left, 0px));
  --mobile-edge-pad-right: max(14px, env(safe-area-inset-right, 0px));
}

@supports (height: 100dvh) {
  :root {
    --mobile-app-height: 100dvh;
  }
}

.mobile-settings-save-rail {
  display: none;
}

@media (max-width: 768px), (hover: none) and (pointer: coarse) {
  html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    background:
      radial-gradient(circle at top, rgba(0, 149, 246, 0.18), transparent 32%),
      linear-gradient(180deg, #f5f8fc 0%, #edf3fb 48%, #e7eef8 100%);
  }

  body {
    min-height: var(--mobile-app-height);
    line-height: 1.55;
    overscroll-behavior-y: contain;
    overscroll-behavior-x: none;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    font-family: "SF Pro Text", "Segoe UI", "PingFang TC", "Noto Sans TC", sans-serif;
    background: transparent;
    color: #122033;
    letter-spacing: 0.002em;
  }

  body,
  button,
  input,
  select,
  textarea {
    font-size: 16px;
  }

  :is(
    h1,
    h2,
    h3,
    .app-brand-title,
    #screenTitle,
    .dm-empty-title,
    .ios-settings-title
  ) {
    text-wrap: balance;
  }

  :is(
    p,
    .muted,
    #headerDesc,
    #homeSubHint,
    .dm-empty-sub,
    .ig-dm-thread-intro p
  ) {
    text-wrap: pretty;
  }

  button,
  input[type="button"],
  input[type="submit"],
  input[type="reset"],
  select,
  textarea,
  [role="button"] {
    min-height: 44px;
  }

  button,
  input,
  select,
  textarea,
  [role="button"] {
    touch-action: manipulation;
  }

  a,
  button,
  [role="button"] {
    -webkit-tap-highlight-color: rgba(17, 24, 39, 0.08);
  }

  main,
  .page,
  .screen,
  .content,
  .container {
    scroll-margin-top: calc(12px + var(--mobile-safe-top));
  }

  .page,
  .screen,
  .content,
  .container {
    padding-left: var(--mobile-edge-pad);
    padding-right: var(--mobile-edge-pad-right);
  }

  input,
  select,
  textarea {
    border-radius: 16px;
    scroll-margin-bottom: calc(24px + var(--kb-offset, 0px));
  }

  :is(button, a, input, select, textarea, [role="button"]):focus-visible {
    outline: 3px solid rgba(0, 149, 246, 0.28);
    outline-offset: 2px;
  }

  :is(button, a, [role="button"]) {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(37, 99, 235, 0.12);
  }

  .layout {
    display: block;
    min-height: var(--mobile-app-height);
  }

  .sidebar.iphone-nav-shell {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    padding: 0 12px calc(10px + var(--mobile-safe-bottom));
    background:
      linear-gradient(180deg, rgba(237, 243, 251, 0) 0%, rgba(237, 243, 251, 0.92) 26%, rgba(237, 243, 251, 0.98) 100%);
    pointer-events: none;
  }

  .nav.nav-dock {
    pointer-events: auto;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
    padding: 8px 6px 6px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 26px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.14);
    backdrop-filter: blur(18px);
  }

  .nav.nav-dock .tab-btn {
    min-height: 58px;
    padding: 8px 4px;
    border-radius: 18px;
    transition: transform 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
  }

  .nav.nav-dock .tab-btn.active {
    background: linear-gradient(180deg, rgba(219, 234, 254, 0.96) 0%, rgba(255, 255, 255, 0.98) 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.84), 0 10px 18px rgba(59, 130, 246, 0.16);
  }

  .nav.nav-dock .tab-btn:active {
    transform: scale(0.97);
  }

  .nav.nav-dock .tab-label {
    margin-top: 4px;
    font-size: 11px;
    letter-spacing: 0.01em;
  }

  .nav.nav-dock .tab-btn.active .tab-label {
    color: #1d4ed8;
    font-weight: 700;
  }

  .nav.nav-dock .tab-btn.active .tab-icon svg {
    stroke: #1d4ed8;
  }

  .mobile-friends-view .sidebar.iphone-nav-shell {
    visibility: hidden;
    opacity: 0;
    transform: translateY(calc(100% + 20px));
    pointer-events: none;
  }

  .main.app-shell-main {
    min-height: var(--mobile-app-height);
    padding-bottom: calc(96px + var(--mobile-safe-bottom));
  }

  .mobile-friends-view .main.app-shell-main {
    padding-bottom: calc(18px + var(--mobile-safe-bottom));
  }

  .app-topbar {
    position: sticky;
    top: 0;
    z-index: 18;
    padding:
      calc(10px + var(--mobile-safe-top))
      var(--mobile-edge-pad-right)
      10px
      var(--mobile-edge-pad);
    background: rgba(245, 248, 252, 0.84);
    backdrop-filter: blur(18px);
    border-bottom: 1px solid rgba(148, 163, 184, 0.16);
    transition:
      padding 160ms ease,
      background-color 160ms ease,
      box-shadow 160ms ease,
      border-color 160ms ease;
  }

  .mobile-friends-view .app-topbar {
    background: rgba(243, 247, 252, 0.9);
  }

  .app-brand-row {
    align-items: center;
    gap: 10px;
  }

  #mainApp .app-brand-title {
    font-size: 22px !important;
    letter-spacing: -0.03em;
    font-weight: 800;
    transition: font-size 160ms ease, letter-spacing 160ms ease;
  }

  .app-topbar-actions {
    gap: 8px;
    margin-left: auto;
  }

  #mainApp .top-icon-btn {
    width: var(--mobile-control-size) !important;
    min-width: var(--mobile-control-size);
    height: var(--mobile-control-size) !important;
    min-height: var(--mobile-control-size);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
    transition:
      width 160ms ease,
      min-width 160ms ease,
      height 160ms ease,
      min-height 160ms ease,
      transform 140ms ease,
      box-shadow 140ms ease,
      background-color 140ms ease;
  }

  .top-icon-btn:active {
    transform: scale(0.96);
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
  }

  #appShellContent {
    padding: 10px 0 0;
    scroll-padding-top: calc(var(--mobile-topbar-height) + 14px);
    scroll-padding-bottom: calc(112px + var(--mobile-safe-bottom));
  }

  html.is-content-scrolled #mainApp .app-topbar,
  #mainApp .app-topbar.is-scrolled {
    padding-top: calc(6px + var(--mobile-safe-top)) !important;
    padding-bottom: 6px !important;
    background: rgba(245, 248, 252, 0.94) !important;
    border-bottom-color: rgba(148, 163, 184, 0.2) !important;
    box-shadow: 0 12px 26px rgba(15, 23, 42, 0.08) !important;
  }

  html.is-content-scrolled #mainApp .app-brand-title,
  #mainApp .app-topbar.is-scrolled .app-brand-title {
    font-size: 20px !important;
    letter-spacing: -0.025em;
  }

  html.is-content-scrolled #mainApp .top-icon-btn,
  #mainApp .app-topbar.is-scrolled .top-icon-btn {
    width: 40px !important;
    min-width: 40px;
    height: 40px !important;
    min-height: 40px;
  }

  .card,
  .panel,
  .list-item,
  .row {
    border-radius: 20px;
  }

  .card.section,
  .card.header {
    margin-bottom: 14px;
    border: 1px solid rgba(148, 163, 184, 0.14);
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.08);
  }

  .card.section {
    padding: 16px;
  }

  .card.header {
    padding: 18px 16px;
  }

  .header-row {
    display: grid;
    gap: 12px;
  }

  .header-row > div:first-child {
    display: grid;
    gap: 6px;
    min-width: 0;
  }

  #flowLabel {
    font-size: 12px !important;
    letter-spacing: 0.03em;
  }

  #screenTitle {
    font-size: 26px !important;
    line-height: 1.06;
    letter-spacing: -0.04em;
  }

  #headerDesc,
  #homeSubHint {
    font-size: 13px !important;
    line-height: 1.65 !important;
    color: #667085 !important;
  }

  .badges {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .badges::-webkit-scrollbar {
    display: none;
  }

  .badge {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 10px 12px;
    border-radius: 999px;
    font-size: 12px;
    white-space: nowrap;
    background: rgba(248, 250, 252, 0.96);
    scroll-snap-align: start;
  }

  .badges::after {
    content: "";
    min-width: 4px;
  }

  .tab-panel {
    scroll-margin-top: calc(74px + var(--mobile-safe-top));
  }

  .two-col-half,
  .dashboard-main {
    gap: 14px;
  }

  .field label,
  .small.muted,
  .muted.small {
    letter-spacing: 0.01em;
  }

  :is(
    .metric .value,
    .salary-donut-value,
    .iphone-punch-money,
    .cal-head-title,
    .calendar-month-chip,
    #salary .record,
    #recordList
  ) {
    font-variant-numeric: tabular-nums;
  }

  #attendance .two-col,
  #salary .two-col-half,
  #settings .two-col-half {
    gap: 14px;
  }

  #attendance .attendance-punch-panel {
    padding: 18px;
    border-radius: 24px;
  }

  #attendance .attendance-punch-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  #attendance .attendance-punch-actions .action-btn {
    min-height: 52px;
  }

  #attendance .record-list,
  #salary .record-list {
    gap: 10px;
  }

  #attendance .record,
  #salary .record {
    padding: 14px 15px;
    border-radius: 18px;
    line-height: 1.6;
    background: rgba(255, 255, 255, 0.94);
    border-color: rgba(148, 163, 184, 0.14);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
  }

  #salary .two-col-half {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  #salary .metric {
    min-height: 118px;
    padding: 16px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.94);
    border-color: rgba(148, 163, 184, 0.14);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
  }

  #salary .metric .label {
    font-size: 13px;
    color: #7a8699;
  }

  #salary .metric .value {
    font-size: clamp(24px, 6vw, 28px);
    line-height: 1.08;
  }

  #calendar .calendar-toolbar,
  #calendar .calendar-toolbar-actions {
    width: 100%;
  }

  #calendar .calendar-toolbar-actions {
    justify-content: space-between;
  }

  #calendar .calendar-icon-btn,
  #calendar .calendar-mobile-fab {
    min-width: 48px;
    min-height: 48px;
  }

  .calendar-drawer-backdrop,
  .calendar-modal-backdrop {
    align-items: flex-end;
    padding: 10px;
  }

  .calendar-drawer,
  .calendar-modal {
    width: 100%;
    max-height: min(86dvh, 760px);
    border-radius: 28px 28px 18px 18px;
    padding-bottom: calc(18px + var(--mobile-safe-bottom));
  }

  .calendar-drawer-header,
  .calendar-modal-top {
    position: sticky;
    top: 0;
    z-index: 1;
    background: inherit;
  }

  #settings .card.section {
    padding: 18px 16px;
  }

  #settings .field {
    display: grid;
    gap: 8px;
    margin-top: 14px;
  }

  #settings .field label {
    font-size: 13px;
    font-weight: 700;
  }

  #attendance .muted,
  #salary .muted,
  #settings .mini-note,
  #settings .storage-status {
    color: #667085 !important;
  }

  #settings input,
  #settings select {
    min-height: 52px;
    color: #122033 !important;
    background: #f8fbff !important;
    border-color: rgba(148, 163, 184, 0.18) !important;
  }

  #settings .field label {
    color: #5b6472;
  }

  #settings input::placeholder {
    color: #94a3b8 !important;
  }

  #settings .mini-note,
  #settings .storage-status {
    border-radius: 16px;
    line-height: 1.65;
  }

  .ios-settings-main {
    scroll-padding-bottom: calc(24px + 72px + var(--mobile-safe-bottom));
  }

  .ios-settings-profile,
  .ios-settings-row {
    min-height: 52px;
  }

  .auth-overlay.auth-iphone-login {
    overscroll-behavior-y: contain;
  }

  .auth-phone-body,
  .auth-redesign-card.auth-phone-body {
    scroll-padding-bottom: calc(28px + var(--mobile-safe-bottom));
  }

  .auth-privacy-ig .auth-privacy-trigger,
  .auth-show-password,
  .auth-bottom-switch button {
    min-width: 44px;
    min-height: 44px;
  }

  .auth-language-row {
    min-height: 44px;
  }

  .auth-ig-field input,
  .auth-ig-primary {
    min-height: 54px;
  }

  :is(.messages, .message-list, .chat-messages, .dm-messages, [data-chat-messages]) {
    scroll-padding-top: 16px;
    scroll-padding-bottom: calc(var(--mobile-composer-height) + 20px + var(--mobile-safe-bottom));
    overscroll-behavior: contain;
  }

  :is(.message, .chat-message, .dm-message, .bubble) {
    max-width: min(82%, 34rem);
    line-height: 1.46;
    overflow-wrap: anywhere;
  }

  :is(.composer, .chat-composer, .dm-composer, .message-composer, [data-chat-composer]) {
    position: sticky;
    bottom: 0;
    z-index: 5;
    padding-bottom: max(10px, var(--mobile-safe-bottom));
    backdrop-filter: blur(12px);
  }

  :is(.tabs, .bottom-nav, .mobile-nav, nav[aria-label*="bottom" i]) {
    padding-bottom: max(8px, var(--mobile-safe-bottom));
  }

  :is(.list-item, .row, .menu-item) {
    min-height: 48px;
  }

  #friends.tab-panel > .card.section {
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
  }

  #friends.tab-panel {
    padding-bottom: 4px;
  }

  .mobile-friends-view #friends .ig-dm-discover-body,
  .mobile-friends-view #friends .ig-dm-list {
    padding-bottom: calc(18px + var(--mobile-safe-bottom));
  }

  .dm-shell {
    display: flex;
    flex-direction: column;
    gap: var(--mobile-shell-gap);
    min-height: calc(var(--mobile-app-height) - var(--mobile-topbar-height) - 104px - var(--mobile-safe-bottom));
  }

  .mobile-friends-view .dm-shell {
    gap: 10px;
    min-height: calc(var(--mobile-app-height) - var(--mobile-topbar-height) - 28px - var(--mobile-safe-bottom));
  }

  .dm-sidebar-card,
  .dm-thread-card {
    overflow: hidden;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(148, 163, 184, 0.14);
    box-shadow: 0 18px 36px rgba(15, 23, 42, 0.08);
  }

  .dm-sidebar-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    max-height: min(54vh, 39rem);
    overflow: hidden;
  }

  .mobile-friends-view .dm-sidebar-card {
    gap: 14px;
    max-height: none;
    min-height: calc(var(--mobile-app-height) - var(--mobile-topbar-height) - 34px - var(--mobile-safe-bottom));
    padding: 14px 14px 12px;
    border-radius: 28px;
  }

  .dm-sidebar-summary {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }

  .dm-sidebar-summary::-webkit-scrollbar {
    display: none;
  }

  .dm-sidebar-chip {
    min-height: 34px;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 12px;
    background: #eef4ff;
    color: #2563eb;
    flex: 0 0 auto;
    scroll-snap-align: start;
  }

  .dm-sidebar-chip.soft {
    background: #f2f5f9;
    color: #5b6472;
  }

  .dm-search-mini {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 2px 0 6px;
    background: rgba(255, 255, 255, 0.94);
  }

  .dm-search-mini input,
  #friendChatInput {
    width: 100%;
    min-height: 46px;
    padding: 0 16px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: #f8fbff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  }

  .dm-search-actions {
    display: grid;
    gap: 10px;
  }

  .dm-request-list,
  .dm-search-result-list,
  .dm-list {
    display: grid;
    gap: 10px;
    overflow: auto;
    scroll-snap-type: y proximity;
  }

  .dm-list {
    min-height: 120px;
    padding-bottom: 6px;
    padding-right: 2px;
  }

  .mobile-friends-view .dm-list {
    padding-bottom: calc(18px + var(--mobile-safe-bottom));
    scroll-padding-bottom: calc(18px + var(--mobile-safe-bottom));
  }

  .dm-item {
    position: relative;
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    min-height: 78px;
    padding: 15px 16px;
    border-radius: 24px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    border: 1px solid rgba(191, 219, 254, 0.46);
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.06);
    transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease, background-color 150ms ease;
  }

  .dm-item.active {
    background: linear-gradient(180deg, #eff6ff 0%, #ffffff 100%);
    border-color: rgba(96, 165, 250, 0.5);
    box-shadow: 0 16px 30px rgba(37, 99, 235, 0.12);
  }

  .dm-item.has-unread {
    border-color: rgba(96, 165, 250, 0.42);
    background: linear-gradient(180deg, #f9fbff 0%, #f3f8ff 100%);
  }

  .dm-item.has-unread::before {
    content: "";
    position: absolute;
    inset: 10px auto 10px 8px;
    width: 3px;
    border-radius: 999px;
    background: linear-gradient(180deg, #60a5fa 0%, #2563eb 100%);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
  }

  .dm-item:active {
    transform: scale(0.985);
  }

  .dm-item.active .dm-name,
  .dm-item.has-unread .dm-name {
    color: #0f2f52;
  }

  .dm-avatar {
    width: 52px;
    height: 52px;
    font-size: 16px;
    color: #17324d;
  }

  .dm-meta {
    min-width: 0;
  }

  .dm-name-row {
    align-items: baseline;
    gap: 10px;
  }

  .dm-name {
    font-size: 15px;
    line-height: 1.15;
    letter-spacing: -0.01em;
    color: #13263b;
  }

  .dm-time {
    font-size: 11px;
    color: #7b8797;
  }

  .dm-time.unread {
    color: #2563eb;
    font-weight: 700;
  }

  .dm-snippet {
    margin-top: 5px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    white-space: normal;
    font-size: 13px;
    line-height: 1.45;
    color: #667085;
  }

  .dm-snippet.unread {
    color: #334155;
    font-weight: 600;
  }

  .dm-unread-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: #2563eb;
    box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.14);
  }

  .dm-camera-mini {
    color: #9aa7b8;
  }

  .dm-list-filler {
    padding: 14px 14px 18px;
    border-radius: 18px;
    color: #7b8797;
    line-height: 1.7;
    background: rgba(248, 250, 252, 0.82);
    border: 1px dashed rgba(148, 163, 184, 0.24);
  }

  .dm-list > *,
  .dm-request-list > *,
  .dm-search-result-list > * {
    min-height: 58px;
    padding: 12px 14px;
    border-radius: 18px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    border: 1px solid rgba(191, 219, 254, 0.42);
    box-shadow: 0 10px 20px rgba(15, 23, 42, 0.05);
    scroll-snap-align: start;
  }

  .dm-list > * + *,
  .dm-request-list > * + *,
  .dm-search-result-list > * + * {
    margin-top: 0;
  }

  .dm-list strong,
  .dm-request-list strong,
  .dm-search-result-list strong {
    font-size: 15px;
    letter-spacing: -0.01em;
  }

  .dm-list em,
  .dm-request-list em,
  .dm-search-result-list em {
    display: block;
    margin-top: 4px;
    font-size: 13px;
    line-height: 1.55;
    color: #526072;
  }

  .dm-thread-card {
    position: relative;
    min-height: calc(var(--mobile-app-height) - var(--mobile-topbar-height) - 126px - var(--mobile-safe-bottom));
    isolation: isolate;
  }

  .dm-thread-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 88px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0));
    pointer-events: none;
    z-index: 0;
  }

  .dm-thread-card,
  .dm-thread-panel {
    display: flex;
    flex-direction: column;
  }

  .dm-thread-panel {
    position: relative;
  }

  .dm-thread-top {
    position: sticky;
    top: 0;
    z-index: 3;
    gap: 10px;
    padding: 14px 16px 10px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(18px);
    border-bottom: 1px solid rgba(148, 163, 184, 0.14);
  }

  .dm-thread-user .dm-avatar {
    width: 44px;
    height: 44px;
  }

  .dm-thread-top::after {
    content: "";
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 0;
    height: 1px;
    background: linear-gradient(90deg, rgba(148, 163, 184, 0), rgba(148, 163, 184, 0.3), rgba(148, 163, 184, 0));
  }

  .dm-back-btn,
  .dm-icon-btn,
  .dm-compose-icon,
  .dm-reply-close {
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
    border-radius: 14px;
  }

  .dm-thread-user {
    min-width: 0;
    flex: 1;
  }

  .dm-thread-user > div:last-child {
    min-width: 0;
  }

  #friendThreadName {
    font-size: 18px !important;
    line-height: 1.15;
    letter-spacing: -0.02em;
  }

  #friendThreadStatus {
    font-size: 12px !important;
  }

  .dm-thread-actions {
    gap: 8px;
  }

  .dm-badge {
    margin: 10px 16px 0;
    align-self: flex-start;
    border-radius: 999px;
    background: #e8f3ff;
    color: #2563eb;
    font-weight: 700;
  }

  .dm-empty {
    min-height: 360px;
    padding: 22px 18px 28px;
    display: grid;
    align-items: center;
  }

  .dm-empty-shell {
    padding: 22px 18px;
    border-radius: 24px;
    background: linear-gradient(180deg, #f8fbff 0%, #eef5ff 100%);
  }

  .dm-empty-title {
    font-size: 22px;
    line-height: 1.15;
    letter-spacing: -0.03em;
  }

  .dm-empty-sub {
    margin-top: 8px;
    font-size: 13px;
    line-height: 1.7;
  }

  .dm-thread-panel.hidden,
  .dm-empty.hidden {
    display: none;
  }

  .dm-thread-messages {
    flex: 1;
    min-height: 180px;
    padding: 16px 16px calc(var(--mobile-composer-height) + 18px);
    background:
      radial-gradient(circle at top right, rgba(191, 219, 254, 0.34), transparent 34%),
      radial-gradient(circle at bottom left, rgba(219, 234, 254, 0.28), transparent 28%),
      linear-gradient(180deg, #f8fbff 0%, #eef4fb 100%);
    scrollbar-width: none;
    scroll-behavior: smooth;
  }

  .dm-thread-messages > * + * {
    margin-top: 12px;
  }

  .dm-thread-messages::-webkit-scrollbar {
    display: none;
  }

  :is(.dm-jump-latest, .ig-dm-jump-latest) {
    position: absolute;
    right: 16px;
    bottom: calc(var(--mobile-composer-height) + 16px);
    z-index: 5;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.96);
    color: #2563eb;
    box-shadow:
      0 14px 30px rgba(15, 23, 42, 0.18),
      inset 0 1px 0 rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(18px);
    opacity: 0;
    transform: translateY(8px) scale(0.96);
    pointer-events: none;
    transition:
      opacity 160ms ease,
      transform 160ms ease,
      box-shadow 160ms ease;
  }

  :is(.dm-jump-latest, .ig-dm-jump-latest) svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.3;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  :is(.dm-jump-latest, .ig-dm-jump-latest).is-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }

  :is(.dm-jump-latest, .ig-dm-jump-latest).has-unseen::after {
    content: "";
    position: absolute;
    top: 7px;
    right: 7px;
    width: 9px;
    height: 9px;
    border: 2px solid #ffffff;
    border-radius: 999px;
    background: #ef4444;
  }

  :is(.dm-jump-latest, .ig-dm-jump-latest):active {
    transform: translateY(1px) scale(0.96);
    box-shadow:
      0 10px 22px rgba(15, 23, 42, 0.14),
      inset 0 1px 0 rgba(255, 255, 255, 0.88);
  }

  .dm-message-stack {
    display: grid;
    gap: 6px;
    max-width: min(84vw, 25rem);
  }

  .dm-bubble {
    padding: 12px 15px;
    font-size: 15px;
    line-height: 1.5;
    border-radius: 24px;
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
  }

  .dm-bubble.them {
    color: #14304a;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(244, 248, 252, 0.96));
    border-color: rgba(191, 219, 254, 0.34);
    border-top-left-radius: 12px;
  }

  .dm-bubble.me {
    color: #0f172a;
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 35%, #c7d2fe 100%);
    border-color: rgba(96, 165, 250, 0.26);
    border-top-right-radius: 12px;
  }

  .dm-reply-preview {
    margin-bottom: 8px;
    padding: 8px 10px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.48);
    border: 1px solid rgba(148, 163, 184, 0.16);
  }

  .dm-reply-line {
    color: #2563eb;
  }

  .dm-message-meta {
    padding: 0 6px;
    font-size: 11px;
    color: #7b8797;
  }

  .dm-message-meta .status-pill {
    min-height: 20px;
    padding: 0 9px;
    color: #2563eb;
    border-color: rgba(96, 165, 250, 0.22);
    background: rgba(219, 234, 254, 0.72);
  }

  .dm-thread-messages > * {
    max-width: min(84%, 34rem);
  }

  .dm-thread-messages > *:not([class*="self"]):not([class*="mine"]) {
    margin-right: auto;
  }

  .dm-thread-messages > [class*="self"],
  .dm-thread-messages > [class*="mine"] {
    margin-left: auto;
  }

  :is(
    .record-list,
    .dm-list,
    .dm-thread-messages,
    .ig-dm-thread,
    .ig-dm-list,
    .calendar-modal-body,
    .avatar-picker-sheet
  ) {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }

  .dm-compose {
    position: sticky;
    bottom: 0;
    z-index: 4;
    display: grid;
    gap: 8px;
    padding: 8px 12px calc(12px + var(--mobile-safe-bottom));
    background: rgba(245, 248, 252, 0.9);
    backdrop-filter: blur(18px);
    border-top: 1px solid rgba(148, 163, 184, 0.14);
    box-shadow: 0 -8px 22px rgba(15, 23, 42, 0.06);
  }

  .dm-reply-bar {
    border-radius: 16px;
    padding: 10px 12px;
    background: #eef4ff;
    border: 1px solid rgba(96, 165, 250, 0.18);
  }

  .dm-compose-row {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 40px 40px auto;
    gap: 8px;
    align-items: center;
    min-height: 56px;
    padding: 7px;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(191, 219, 254, 0.44);
    box-shadow: 0 10px 24px rgba(148, 163, 184, 0.16);
    transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease, grid-template-columns 140ms ease;
  }

  .dm-compose-row.is-focused {
    border-color: rgba(96, 165, 250, 0.54);
    box-shadow: 0 14px 28px rgba(37, 99, 235, 0.16);
    transform: translateY(-1px);
  }

  .dm-compose-row.is-has-text {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .dm-compose-row.is-has-text #dmImageBtn,
  .dm-compose-row.is-has-text #dmMicBtn,
  .dm-compose-row.is-has-text #dmHeartBtn {
    display: none;
  }

  #friendChatInput {
    min-width: 0;
    font-size: 16px;
    box-shadow: none;
    border-width: 0;
    background: transparent;
    padding: 0 10px;
  }

  #friendChatInput::placeholder {
    color: #94a3b8;
  }

  #sendFriendChatBtn {
    min-width: 58px;
    min-height: 42px;
    padding: 0 16px;
    border-radius: 999px;
    white-space: nowrap;
    box-shadow: 0 10px 20px rgba(59, 130, 246, 0.2);
    transition: min-width 140ms ease, transform 140ms ease, box-shadow 140ms ease;
  }

  #sendFriendChatBtn.is-ready {
    min-width: 72px;
    box-shadow: 0 14px 26px rgba(37, 99, 235, 0.26);
  }

  .dm-quick-actions {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    padding-right: 4px;
    scrollbar-width: none;
  }

  .dm-quick-actions::-webkit-scrollbar {
    display: none;
  }

  .dm-quick-btn {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 0 14px;
    border-radius: 999px;
    background: #ffffff;
    border: 1px solid rgba(191, 219, 254, 0.6);
    color: #2563eb;
    font-size: 13px;
    font-weight: 700;
    transition: transform 140ms ease, background-color 140ms ease, border-color 140ms ease;
  }

  .dm-quick-btn:active,
  .dm-compose-icon:active,
  .dm-back-btn:active,
  #sendFriendChatBtn:active {
    transform: scale(0.98);
  }

  .dm-compose-icon,
  .dm-back-btn,
  .dm-reply-close {
    background: linear-gradient(180deg, #ffffff 0%, #f5f9ff 100%);
    border: 1px solid rgba(191, 219, 254, 0.4);
    box-shadow: 0 8px 18px rgba(148, 163, 184, 0.14);
  }

  .mobile-thread-open .dm-sidebar-card {
    display: none;
  }

  .mobile-thread-open .dm-shell {
    min-height: calc(var(--mobile-app-height) - var(--mobile-topbar-height) - 52px - var(--mobile-safe-bottom));
  }

  .mobile-thread-open .dm-thread-card {
    min-height: calc(var(--mobile-app-height) - var(--mobile-topbar-height) - 52px - var(--mobile-safe-bottom));
    border-radius: 0;
    margin-inline: calc(-1 * var(--mobile-edge-pad));
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    box-shadow: none;
    background: linear-gradient(180deg, #f8fbff 0%, #eef4fb 100%);
  }

  .mobile-thread-open .app-topbar {
    padding-bottom: 6px;
    border-bottom-color: rgba(148, 163, 184, 0.12);
  }

  .mobile-thread-open .app-brand-title {
    font-size: 17px;
    letter-spacing: -0.02em;
  }

  html.is-content-scrolled body.mobile-thread-open .app-brand-title {
    font-size: 17px !important;
    letter-spacing: -0.02em;
  }

  .mobile-thread-open .app-topbar-actions {
    display: none;
  }

  .mobile-thread-open #friends.tab-panel > .card.section {
    margin-bottom: 0;
    padding-inline: 0;
  }

  .mobile-thread-open .dm-thread-top,
  .mobile-thread-open .dm-thread-messages,
  .mobile-thread-open .dm-compose {
    padding-left: max(16px, var(--mobile-edge-pad));
    padding-right: max(16px, var(--mobile-edge-pad-right));
  }

  .mobile-thread-open .dm-thread-top {
    padding-top: calc(10px + var(--mobile-safe-top));
    background: rgba(248, 251, 255, 0.94);
  }

  .mobile-thread-open .dm-thread-messages {
    border-radius: 0;
    padding-top: 12px;
    padding-bottom: calc(var(--mobile-composer-height) + 20px + var(--kb-offset, 0px));
  }

  .is-keyboard-open .dm-compose {
    padding-bottom: 10px;
  }

  .is-keyboard-open .sidebar.iphone-nav-shell {
    transform: translateY(calc(100% + 20px));
    transition: transform 180ms ease;
  }

  .is-keyboard-open .main.app-shell-main {
    padding-bottom: 24px;
  }

  #friends .ig-dm-header,
  #friends .ig-dm-chat-header {
    min-height: 56px;
    padding-inline: 10px;
  }

  #friends .ig-dm-header-actions button,
  #friends .ig-dm-chat-actions button,
  #friends .ig-icon-btn {
    min-width: var(--mobile-control-size);
    min-height: var(--mobile-control-size);
  }

  #friends .ig-dm-row {
    min-height: 72px;
    padding-top: 12px;
    padding-bottom: 12px;
    padding-left: 10px;
    padding-right: 10px;
    border-radius: 20px;
  }

  #friends .ig-dm-row:active {
    transform: scale(0.985);
  }

  #friends .ig-dm-meta strong {
    font-size: 15px;
  }

  #friends .ig-dm-meta em {
    font-size: 14px;
  }

  #friends .ig-dm-thread {
    gap: 12px;
    padding-top: 14px;
    padding-bottom: calc(var(--mobile-composer-height) + 12px + var(--kb-offset, 0px));
    scroll-padding-bottom: calc(var(--mobile-composer-height) + 12px + var(--kb-offset, 0px));
  }

  #friends .ig-dm-thread-intro {
    padding-bottom: 14px;
  }

  #friends .ig-dm-bubble-stack {
    max-width: min(78vw, 22rem);
  }

  #friends .ig-dm-bubble {
    padding: 11px 15px;
    font-size: 16px;
    line-height: 1.48;
    border-radius: 20px;
  }

  #friends .ig-dm-bubble-stack em {
    font-size: 11px;
  }

  #friends .ig-dm-compose {
    gap: 10px;
    padding: 10px 12px calc(10px + var(--mobile-safe-bottom) + var(--kb-offset, 0px));
    background: rgba(245, 248, 252, 0.94);
    backdrop-filter: blur(18px);
  }

  #friends .ig-dm-compose-media {
    width: var(--mobile-control-size);
    height: var(--mobile-control-size);
  }

  #friends .ig-dm-compose-field {
    min-height: 46px;
    height: 46px;
    border-radius: 18px;
  }

  #friends .ig-dm-compose-field > span,
  #friends .ig-dm-send {
    width: 36px;
    height: 36px;
  }

  #friends .ig-dm-send.is-active {
    width: 38px;
    height: 38px;
  }

  /* Settings gets a one-handed save affordance only after mobile edits are made. */
  #settings.tab-panel {
    padding-bottom: calc(156px + var(--mobile-safe-bottom));
  }

  .mobile-settings-save-rail {
    position: fixed;
    left: var(--mobile-edge-pad);
    right: var(--mobile-edge-pad-right);
    bottom: calc(92px + var(--mobile-safe-bottom));
    z-index: 34;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 62px;
    padding: 10px 10px 10px 14px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 18px 34px rgba(15, 23, 42, 0.14);
    backdrop-filter: blur(18px);
    opacity: 0;
    transform: translateY(14px);
    pointer-events: none;
    transition: opacity 160ms ease, transform 160ms ease;
  }

  .mobile-settings-save-rail.is-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }

  .mobile-settings-save-copy {
    display: grid;
    gap: 2px;
    min-width: 0;
  }

  .mobile-settings-save-copy strong {
    font-size: 14px;
    line-height: 1.2;
    color: #122033;
  }

  .mobile-settings-save-copy span {
    font-size: 12px;
    color: #667085;
  }

  .mobile-settings-save-rail button {
    min-width: 96px;
    min-height: 44px;
    padding-inline: 16px;
    border-radius: 999px;
    white-space: nowrap;
  }

  .is-keyboard-open .mobile-settings-save-rail {
    opacity: 0;
    transform: translateY(14px);
    pointer-events: none;
  }

  #friends .ig-dm-compose-field {
    transition: border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
  }

  #friends .ig-dm-compose-field:focus-within {
    border-color: rgba(96, 165, 250, 0.54);
    box-shadow: 0 12px 24px rgba(37, 99, 235, 0.14);
    background: rgba(255, 255, 255, 0.98);
  }

  #friends .ig-dm-compose-field input::placeholder {
    color: #94a3b8;
    opacity: 1;
  }

}

@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .is-keyboard-open .sidebar.iphone-nav-shell {
    transition: none;
  }
}
