/* A mobile chat owns one visible viewport. History scrolls; the composer and
   navigation occupy their real heights, including the iPhone safe area. */
@media (max-width: 650px) {
  body.customer-chat-mobile {
    position: fixed;
    top: var(--customer-chat-top, 0px);
    left: 0;
    right: 0;
    width: 100%;
    height: var(--customer-chat-height, 100dvh);
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    overscroll-behavior: none;
    background: #f4f7fa;
  }

  .customer-chat-mobile > .header {
    position: relative;
    flex: 0 0 56px;
    height: 56px;
    min-height: 0;
    padding: 0 15px;
  }

  .customer-chat-mobile .header .brand {
    min-width: 0;
    gap: 9px;
    font-size: 17px;
    letter-spacing: 2px;
  }

  .customer-chat-mobile .header .brand-mark {
    width: 29px;
    height: 32px;
    padding: 7px;
    gap: 5px;
  }

  .customer-chat-mobile .header .brand-mark::after { left: 13px; }
  .customer-chat-mobile .header .brand small { font-size: 6px; letter-spacing: 1.1px; }
  .customer-chat-mobile .header .staff-link { font-size: 10px; }

  .customer-chat-mobile > #app {
    display: flex;
    flex: 1 1 0;
    width: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
  }

  .customer-chat-mobile .chat-page.container.page-shell {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
  }

  .customer-chat-mobile .chat-page > .page-heading,
  .customer-chat-mobile .chat-bottom-links { display: none; }

  .customer-chat-mobile .chat-page .chat-shell {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    height: auto;
    width: 100%;
    max-width: none;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
  }

  .customer-chat-mobile .chat-toolbar {
    flex: 0 0 auto;
    min-width: 0;
    gap: 8px;
    padding: 12px 14px;
    background: #fff;
  }

  .customer-chat-mobile .chat-profile { flex: 1 1 auto; min-width: 0; }
  .customer-chat-mobile .chat-profile > div:last-child { min-width: 0; }
  .customer-chat-mobile .chat-profile strong { display: block; font-size: 13px; font-weight: 600; }
  .customer-chat-mobile .chat-profile strong,
  .customer-chat-mobile .chat-status { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .customer-chat-mobile .chat-status { max-width: none; font-size: 10px; color: #6b7d8d; }
  .customer-chat-mobile .chat-toolbar .chat-tools { display: flex; flex: 0 0 auto; gap: 4px; }
  .customer-chat-mobile .chat-toolbar .chat-tools button { min-height: 36px; padding: 6px 7px; font-size: 10px; }
  .customer-chat-mobile .chat-safety { flex: 0 0 auto; font-size: 10px; line-height: 1.6; color: #677b8c; padding: 7px 14px; }
  .customer-chat-mobile .chat-reconnect { flex: 0 0 auto; font-size: 11px; line-height: 1.5; padding: 6px 12px; }

  .customer-chat-mobile .chat-messages {
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 16px 14px;
    scroll-behavior: auto;
    background: #f4f7fa;
  }

  .customer-chat-mobile .message { gap: 8px; margin-bottom: 18px; }
  .customer-chat-mobile .message-body { min-width: 0; max-width: calc(100% - 44px); }
  .customer-chat-mobile .bubble { font-size: 14px; line-height: 1.65; padding: 10px 13px; }
  .customer-chat-mobile .message-meta { font-size: 10px; color: #748697; }
  .customer-chat-mobile .message-state { font-size: 10px; color: #718596; }
  .customer-chat-mobile .chat-history-note,
  .customer-chat-mobile .message-date { font-size: 10px; color: #7e90a0; }

  /* Compact, stable thumbnails cannot stretch the message column or move the
     send row below the screen. The original remains available in the lightbox. */
  .customer-chat-mobile .message .message-image {
    display: block;
    width: min(184px, 54vw);
    max-width: 100%;
    max-height: none;
    padding: 4px;
  }

  .customer-chat-mobile .message .message-image img {
    display: block;
    width: 100%;
    height: 132px;
    max-width: 100%;
    max-height: 132px;
    object-fit: contain;
    border-radius: 7px;
    background: #eaf0f5;
  }

  .customer-chat-mobile .composer {
    flex: 0 0 auto;
    min-width: 0;
    width: 100%;
    padding: 7px 12px 10px;
    border-top: 1px solid #dce5ed;
    background: #fff;
    box-shadow: 0 -5px 18px #16344d06;
    z-index: 2;
  }

  .customer-chat-mobile .chat-compose-tools { min-width: 0; gap: 12px; margin: 0 0 4px; }
  .customer-chat-mobile .chat-compose-tools button { flex: 0 0 auto; min-height: 36px; font-size: 12px; color: #4b657b; }
  .customer-chat-mobile .chat-compose-tools button svg { width: 19px; height: 19px; }
  .customer-chat-mobile .chat-compose-tools > span { min-width: 0; max-width: none; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 9px; color: #7c8d9c; }
  .customer-chat-mobile .composer-row { min-width: 0; display: flex; align-items: stretch; gap: 8px; }
  .customer-chat-mobile .composer textarea {
    display: block;
    flex: 1 1 0;
    min-width: 0;
    width: 0;
    height: 56px;
    min-height: 48px;
    max-height: 88px;
    margin: 0;
    padding: 11px 12px;
    font-size: 16px;
    line-height: 1.45;
    color: #18334b;
    border-color: #dce5ed;
    background: #f6f8fa;
    border-radius: 12px;
    resize: none;
  }

  .customer-chat-mobile .composer .primary-button.chat-send {
    display: flex;
    flex: 0 0 68px;
    width: 68px;
    height: auto;
    min-height: 48px;
    margin: 0;
    padding: 10px 8px;
    gap: 5px;
    border-radius: 12px;
    background: #123751;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    box-shadow: none;
  }

  .customer-chat-mobile .chat-send svg { width: 16px; height: 16px; }
  .customer-chat-mobile .chat-compose-hint { margin-top: 6px; font-size: 9px; line-height: 1.4; color: #7e90a0; }
  .customer-chat-mobile #chat-preview .image-preview { margin: 0 0 7px; padding: 6px 8px; gap: 8px; }
  .customer-chat-mobile #chat-preview .preview-thumb img { width: 48px; height: 42px; }
  .customer-chat-mobile #chat-preview .preview-name { flex: 1 1 0; min-width: 0; }
  .customer-chat-mobile #chat-preview .preview-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
  .customer-chat-mobile #chat-preview .preview-name > span { font-size: 9px; line-height: 1.5; }
  .customer-chat-mobile #chat-preview .preview-actions { display: flex; flex: 0 0 auto; gap: 2px; }
  .customer-chat-mobile #chat-preview .preview-actions .text-button { min-width: 32px; min-height: 36px; padding: 5px; }
  .customer-chat-mobile .chat-end { flex: 0 0 auto; padding: 6px 14px; font-size: 11px; line-height: 1.5; }

  .customer-chat-mobile > .bottom-nav {
    position: relative;
    top: auto;
    bottom: auto;
    left: auto;
    right: auto;
    flex: 0 0 var(--customer-nav-height, calc(64px + env(safe-area-inset-bottom, 0px)));
    height: var(--customer-nav-height, calc(64px + env(safe-area-inset-bottom, 0px)));
    min-height: 0;
    margin: 0;
    z-index: 3;
  }

  .customer-chat-mobile #toast { bottom: calc(var(--customer-nav-height, 64px) + 12px); }

  .customer-chat-mobile.customer-chat-keyboard > .bottom-nav,
  .customer-chat-keyboard .chat-safety,
  .customer-chat-keyboard .chat-compose-hint,
  .customer-chat-keyboard .chat-compose-tools > span { display: none; }
  .customer-chat-mobile.customer-chat-keyboard > .header { flex-basis: 48px; height: 48px; }
  .customer-chat-keyboard .header .brand small { display: none; }
  .customer-chat-keyboard .chat-toolbar { padding-top: 8px; padding-bottom: 8px; }
  .customer-chat-keyboard .composer { padding-top: 5px; padding-bottom: 8px; }
  .customer-chat-keyboard .composer textarea { height: 48px; }
  .customer-chat-keyboard #toast { bottom: 112px; }

  /* Small iPhones can leave less than 380 CSS pixels above the keyboard. The
     conversation and send controls take priority over the decorative header. */
  .customer-chat-mobile.customer-chat-compact > .header,
  .customer-chat-compact .chat-safety,
  .customer-chat-compact .chat-compose-hint,
  .customer-chat-compact .chat-compose-tools > span { display: none; }
  .customer-chat-compact .chat-toolbar { padding-top: 5px; padding-bottom: 5px; }
  .customer-chat-compact .chat-toolbar .chat-tools button { min-height: 32px; }
  .customer-chat-compact .composer { padding-top: 4px; padding-bottom: 6px; }
  .customer-chat-compact .chat-compose-tools button { min-height: 28px; }
  .customer-chat-compact .composer textarea { height: 48px; }
  .customer-chat-compact #chat-preview .image-preview { margin-bottom: 4px; padding-top: 4px; padding-bottom: 4px; }
  .customer-chat-compact #chat-preview .preview-thumb img { height: 30px; width: 40px; }
}

@media (max-width: 350px) {
  .customer-chat-mobile .chat-toolbar { padding-left: 10px; padding-right: 10px; }
  .customer-chat-mobile .chat-profile > .avatar { display: none; }
  .customer-chat-mobile .composer { padding-left: 10px; padding-right: 10px; }
  .customer-chat-mobile .chat-toolbar .chat-tools button { font-size: 10px; padding-left: 5px; padding-right: 5px; }
  .customer-chat-mobile .chat-compose-tools > span { font-size: 8px; }
}
