/* Load after the shared page styles. */
html[data-theme] body.mobile-messages {
  background: #fff;
}

body.mobile-messages .cl-site-subnav {
  display: none;
}

body.mobile-messages .messages-page {
  min-height: 0;
  padding-block: 16px 12px;
}

body.mobile-messages .messages-app {
  min-height: 0;
  overflow: clip;
  background: #fff;
  box-shadow: none;
}

body.mobile-messages .messages-list:has(.empty-chat) {
  background: #fff;
}

body.mobile-messages .cl-safety-strip {
  display: none !important;
}

body.mobile-messages :is(.conversation-list, .messages-list) {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-gutter: auto;
  scroll-behavior: auto;
}

/* Let wheel and touch scrolling continue to the page at a pane's edge. */
body.mobile-messages :is(.messages-app, .chat-panel, .messages-list, .conversation-list) {
  overscroll-behavior-y: auto;
}

body.mobile-messages :is(.inbox-panel, .chat-panel, .product-panel) {
  min-height: 0;
}

body.mobile-messages :is(.inbox-header, .chat-header, .message-form) {
  flex: 0 0 auto;
}

@media (min-width: 881px) {
  body.mobile-messages .messages-app {
    --messages-panel-height: clamp(500px, calc(100dvh - 110px), 1100px);
    block-size: var(--messages-panel-height);
    grid-template-rows: minmax(0, 1fr);
  }

  /* With no chat open, the inbox grows with the page so wheel and touch
     gestures over the empty middle pane use the same document scroll. */
  body.mobile-messages .messages-app:has(.message-form[hidden]) {
    block-size: auto;
    min-block-size: var(--messages-panel-height);
    grid-template-rows: auto;
  }

  body.mobile-messages .messages-app:has(.message-form[hidden]) .conversation-list {
    flex: 1 0 auto;
    overflow: visible;
  }

  body.mobile-messages .messages-app:has(.message-form[hidden]) :is(.chat-panel, .product-panel) {
    align-self: start;
    block-size: var(--messages-panel-height);
  }

  body.mobile-messages .messages-app:has(.message-form[hidden]) .messages-list {
    overflow: visible;
  }

  body.mobile-messages .product-panel {
    overflow-y: auto;
  }

  body.mobile-messages .empty-chat {
    min-height: 100%;
    align-content: center;
    padding: 24px;
  }

  body.mobile-messages .product-empty {
    min-height: 100%;
    align-content: center;
    gap: 12px;
  }
}

@media (min-width: 881px) and (max-width: 1240px) {
  body.mobile-messages .messages-app {
    grid-template-columns: minmax(275px, 34%) minmax(0, 1fr);
  }
}

@media (min-width: 1241px) {
  body.mobile-messages .messages-app {
    grid-template-columns: minmax(285px, 29%) minmax(0, 1fr) minmax(245px, 25%);
  }
}

@media (max-width: 880px) {
  body.mobile-messages .messages-page {
    width: 100%; max-width: none; padding: 0;
  }
  body.mobile-messages .messages-app {
    display: block; height: auto; min-height: 0; border: 0; border-radius: 0;
  }
  body.mobile-messages .inbox-panel { border: 0; }
  body.mobile-messages .inbox-header { padding: 18px 16px 12px; gap: 12px; }
  body.mobile-messages .inbox-header .section-kicker { display: none; }
  body.mobile-messages .inbox-header h1 { font-size: 24px; line-height: 1.2; }
  body.mobile-messages .conversation-search input { font-size: 16px; }
  body.mobile-messages .conversation-list { overflow: visible; padding: 0 0 calc(88px + env(safe-area-inset-bottom)); }
  body.mobile-messages .conversation-item {
    grid-template-columns: 44px minmax(0,1fr); gap: 12px; align-items: center;
    padding: 14px 16px; margin: 0; border-radius: 0; border-bottom: 1px solid #e8edf3;
  }
  body.mobile-messages .conversation-avatar, body.mobile-messages .chat-avatar {
    width: 42px; height: 42px; border-radius: 50%; font-size: 15px; box-shadow: none;
  }
  body.mobile-messages .conversation-school { display: none; }
  body.mobile-messages :is(.conversation-title,.conversation-product,.conversation-last,.chat-header__copy h2,.chat-header__copy p) {
    overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  }
  html body.mobile-messages[data-view="chat"] {
    overflow: hidden;
    padding-bottom: 0 !important;
  }
  /* The chat composer owns the safe area while the bottom navigation is hidden. */
  html body.mobile-messages[data-view="chat"]::after { content: none; }
  html body.mobile-messages[data-view="chat"] :is(.cl-site-header,.cl-mobile-nav) { display: none !important; }
  body.mobile-messages[data-view="chat"] .messages-page {
    position: fixed; inset: var(--chat-top, 0px) 0 auto; height: var(--chat-height, 100dvh);
    min-height: 0; margin: 0; padding-top: env(safe-area-inset-top); background: white;
    box-sizing: border-box;
  }
  body.mobile-messages[data-view="chat"] .messages-app,
  body.mobile-messages[data-view="chat"] .chat-panel { height: 100%; min-height: 0; overflow: hidden; }
  body.mobile-messages .chat-panel { display: flex; flex-direction: column; }
  body.mobile-messages[data-view="list"] .chat-panel { display: none; }
  body.mobile-messages .chat-header { display: flex; align-items: center; gap: 5px; padding: 6px 8px; }
  body.mobile-messages .chat-header__copy { flex: 1; }
  body.mobile-messages .chat-header__copy h2 { font-size: 16px; }
  body.mobile-messages .chat-header__copy p { font-size: 12px; }
  body.mobile-messages .chat-header .mobile-back, body.mobile-messages .chat-safety-actions button {
    min-width: 44px; width: 44px; height: 44px; padding: 0; border: 0; background: transparent;
  }
  body.mobile-messages .chat-safety-actions { gap: 0; }
  body.mobile-messages .chat-safety-actions span {
    display: block; position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%);
  }
  .mobile-product-details { flex: none; border-bottom: 1px solid #e1e7ef; }
  .mobile-product-details summary { padding: 12px 16px; cursor: pointer; font-size: 13px; font-weight: 600; }
  body.mobile-messages[data-view="chat"] .mobile-product-details .product-panel {
    max-height: min(34dvh, 250px); overflow-y: auto; padding: 8px 16px;
  }
  body.mobile-messages .messages-list { flex: 1 1 0; min-height: 0; padding: 12px 14px; background: #f7f9fc; }
  body.mobile-messages .message { max-width: 86%; overflow-wrap: anywhere; }
  body.mobile-messages .message-form {
    min-height: 0; padding: 8px 12px calc(8px + max(env(safe-area-inset-bottom, 0px), var(--cl-native-bottom, 0px))); gap: 8px; background: white;
  }
  body.mobile-messages .message-composer { padding: 8px 12px; border-radius: 18px; box-shadow: none; }
  body.mobile-messages .message-form textarea { font-size: 16px; max-height: min(90px,18dvh); }
  body.mobile-messages .composer-meta { display: none; }
  body.mobile-messages .message-form button { flex: none; width: 44px; height: 44px; box-shadow: none; }
  body.mobile-messages .safety-modal__dialog { max-height: 86dvh; overflow-y: auto; }
}

/* Single consistent panel sizing; native scrolling within long lists. */
@media (min-width: 881px) {
  body.mobile-messages .messages-app {
    height: clamp(540px, calc(100dvh - 190px), 1000px) !important;
    min-height: 540px !important;
    block-size: auto !important;
  }
}
