/*
 * BIOS Personal mobile polish R27.
 *
 * Loaded after R25/R26. It keeps the established mobile section window while
 * tightening the phone type scale and restoring Conversation's bounded,
 * independently scrolling viewport.
 */

@media (max-width: 760px),
  (max-width: 1024px) and (max-height: 500px) and (pointer: coarse) {
  body.bios-live.mobile-section-window {
    --mobile-title-size: clamp(28px, 8vw, 34px);
    --mobile-section-title-size: clamp(24px, 7vw, 29px);
  }

  /* A compact, shared hierarchy for the non-chat Personal sections. */
  body.bios-live.mobile-section-window .main > .view.active:not(.view-ai-chat)
    :is(.greeting h1, .page-title h1, .privacy-head h1, .family-head h1,
      .create-protocol-head h1, .protocol-detail-head h1, .case-detail-head h1) {
    font-size: var(--mobile-title-size);
    line-height: 1.08;
    letter-spacing: -.035em;
  }

  body.bios-live.mobile-section-window .view-today .greeting h1 {
    max-width: 100%;
    font-size: clamp(32px, 8.7vw, 38px);
    line-height: 1.04;
  }

  body.bios-live.mobile-section-window .ai-hero {
    padding-top: 16px;
  }

  body.bios-live.mobile-section-window .ai-title h2 {
    font-size: clamp(23px, 6.3vw, 27px);
    line-height: 1.18;
  }

  body.bios-live.mobile-section-window .home-editorial {
    padding: 24px 20px 0;
  }

  body.bios-live.mobile-section-window .home-editorial-copy h2 {
    max-width: 100%;
    font-size: clamp(30px, 8.2vw, 35px);
    line-height: 1.06;
  }

  body.bios-live.mobile-section-window .home-editorial-copy p {
    font-size: 15px;
  }

  body.bios-live.mobile-section-window .home-editorial-primary {
    width: auto;
    min-width: min(100%, 220px);
    min-height: 48px;
  }

  body.bios-live.mobile-section-window .home-editorial-visual {
    width: calc(100% + 40px);
    height: 210px;
    margin-right: -20px;
    margin-left: -20px;
  }

  body.bios-live.mobile-section-window .home-benefit-card {
    padding: 21px 19px !important;
  }

  body.bios-live.mobile-section-window .home-referral-card h3 {
    max-width: 15ch;
    font-size: clamp(26px, 7.2vw, 30px);
    line-height: 1.1;
  }

  body.bios-live.mobile-section-window .home-referral-card p {
    margin-top: 12px;
    font-size: 14px;
  }

  body.bios-live.mobile-section-window .home-referral-link {
    margin-top: 16px;
  }

  body.bios-live.mobile-section-window .home-referral-link input,
  body.bios-live.mobile-section-window .home-referral-link button {
    min-height: 44px;
  }

  body.bios-live.mobile-section-window .home-bonus-card > strong {
    margin-top: 18px;
    font-size: clamp(42px, 12vw, 50px);
  }

  body.bios-live.mobile-section-window .home-articles-head h2 {
    font-size: var(--mobile-section-title-size);
    line-height: 1.08;
  }

  /* The R25 card intent is vertical; explicitly clear the older phone columns. */
  body.bios-live.mobile-section-window .home-article-card {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: auto auto !important;
  }

  body.bios-live.mobile-section-window .home-article-media {
    grid-column: 1;
    grid-row: 1;
    aspect-ratio: 16 / 9;
  }

  body.bios-live.mobile-section-window .home-article-copy {
    grid-column: 1;
    grid-row: 2;
    gap: 10px;
    padding: 15px 16px 17px !important;
  }

  body.bios-live.mobile-section-window .home-article-copy :is(b, strong) {
    font-size: clamp(17px, 4.8vw, 19px);
    line-height: 1.28;
  }

  /* Conversation owns one viewport: header, scroll thread and anchored composer. */
  body.bios-live.mobile-section-window:has(.view-ai-chat.active) {
    overflow: hidden;
  }

  body.bios-live.mobile-section-window .main:has(> .view-ai-chat.active) {
    height: calc(100dvh - 12px);
    min-height: 0;
    overflow: hidden;
  }

  body.bios-live.mobile-section-window .view-ai-chat.active {
    position: absolute;
    inset: 0;
    display: flex;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: 100%;
    padding: calc(76px + env(safe-area-inset-top)) 0 0;
    flex-direction: column;
    overflow: hidden;
  }

  body.bios-live.mobile-section-window .view-ai-chat > .page-head {
    display: flex;
    width: 100%;
    min-height: 48px;
    box-sizing: border-box;
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    margin: 0 !important;
    padding: 0 16px 10px 70px;
  }

  body.bios-live.mobile-section-window .view-ai-chat .chat-title-cluster {
    display: block;
    min-width: 0;
    margin: 0;
  }

  body.bios-live.mobile-section-window .view-ai-chat :is(.chat-identity-mark,
    .chat-title-meta, .personal-chat-sidebar-toggle) {
    display: none !important;
  }

  body.bios-live.mobile-section-window .view-ai-chat .page-title h1 {
    margin: 0;
    font-size: clamp(22px, 6.2vw, 25px);
    line-height: 1.1;
    letter-spacing: -.025em !important;
  }

  body.bios-live.mobile-section-window .view-ai-chat .chat-workspace,
  body.bios-live.mobile-section-window .view-ai-chat .chat-workspace.insights-collapsed {
    position: relative;
    display: block;
    width: 100%;
    height: auto;
    min-height: 0;
    flex: 1 1 auto;
    margin: 0;
    overflow: hidden;
  }

  body.bios-live.mobile-section-window .view-ai-chat .chat-experience,
  body.bios-live.mobile-section-window .view-ai-chat .chat-workspace.insights-collapsed .chat-experience {
    position: absolute;
    inset: 0;
    min-height: 0;
    border-radius: 0;
  }

  body.bios-live.mobile-section-window .view-ai-chat .chat-thread {
    min-height: 0;
    padding: 16px 13px calc(112px + env(safe-area-inset-bottom));
    direction: ltr;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-gutter: auto;
  }

  body.bios-live.mobile-section-window .view-ai-chat .chat-thread > .message.user {
    width: fit-content;
    max-width: 86%;
    align-self: flex-end;
    margin-right: 0;
    margin-left: auto;
  }

  body.bios-live.mobile-section-window .view-ai-chat .message:not(.user) {
    width: 100%;
    max-width: 100%;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  body.bios-live.mobile-section-window .view-ai-chat .message:not(.user) > .message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 10px;
    background-size: 18px 18px;
  }

  body.bios-live.mobile-section-window .view-ai-chat .message:not(.user) .bubble {
    padding: 13px 13px 10px;
  }

  body.bios-live.mobile-section-window .view-ai-chat .message:not(.user) .bios-message-text {
    font-size: 14px;
    line-height: 1.55;
  }

  body.bios-live.mobile-section-window .view-ai-chat .chat-bottom {
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 10px 8px calc(8px + env(safe-area-inset-bottom));
  }

  body.bios-live.mobile-section-window .view-ai-chat .chat-composer,
  body.bios-live.mobile-section-window .view-ai-chat .chat-experience.is-scrolling .chat-composer {
    min-height: 58px;
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    gap: 8px;
    padding: 7px 8px;
  }

  body.bios-live.mobile-section-window .view-ai-chat :is(.composer-plus, .composer-send) {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }
}

@media (max-width: 360px) {
  body.bios-live.mobile-section-window .view-today .greeting h1 {
    font-size: 31px;
  }

  body.bios-live.mobile-section-window .home-editorial-copy h2 {
    font-size: 29px;
  }
}
