/* Keep the public support chat inside the visual viewport when a mobile keyboard opens. */
:root {
  --web-visual-viewport-height: 100dvh;
  --web-visual-viewport-width: 100vw;
  --web-visual-viewport-offset-top: 0px;
  --web-visual-viewport-offset-left: 0px;
}

@media (max-width: 760px) {
  html.support-keyboard-active,
  html.support-keyboard-active body {
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    overflow: hidden !important;
    overscroll-behavior: none !important;
    background: #f4f5f7 !important;
  }

  #webApp .support-chat__composer textarea {
    font-size: 16px !important;
  }

  #webApp .panel--support {
    display: grid !important;
    grid-template-rows: minmax(0, 1fr) !important;
    width: 100% !important;
    height: calc(var(--web-visual-viewport-height, 100dvh) - 86px - env(safe-area-inset-bottom, 0px)) !important;
    min-height: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: #f4f5f7 !important;
  }

  #webApp .panel--support > .app-topbar {
    display: none !important;
  }

  #webApp .panel--support .support-chat {
    grid-template-rows: minmax(0, 1fr) auto auto auto !important;
    height: auto !important;
    min-height: 0 !important;
    width: 100% !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: #ffffff !important;
    box-shadow: none !important;
    overflow: hidden !important;
  }

  #webApp .panel--support .support-chat__messages {
    box-sizing: border-box !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    padding: 10px !important;
    gap: 8px !important;
    overflow-y: auto !important;
    background: #f6f7f9 !important;
  }

  #webApp .panel--support .support-message,
  #webApp .panel--support .support-message--agent,
  #webApp .panel--support .support-message--user,
  #webApp .panel--support .support-message--virtual {
    max-width: 86% !important;
  }

  #webApp .panel--support .support-message__image-button {
    max-width: 100% !important;
  }

  #webApp .panel--support .support-message__image {
    max-height: 180px !important;
  }

  #webApp .panel--support .support-message--virtual > span {
    display: none !important;
  }

  #webApp .panel--support .support-chat__composer {
    grid-template-columns: 44px minmax(0, 1fr) 60px !important;
    align-items: end !important;
    gap: 6px !important;
    padding: 6px !important;
    border-top: 1px solid #e5e7eb !important;
    background: #ffffff !important;
  }

  #webApp .panel--support .support-chat__attach,
  #webApp .panel--support .support-chat__composer > button {
    min-width: 0 !important;
    min-height: 48px !important;
    height: 48px !important;
    padding: 0 6px !important;
    border-radius: 8px !important;
  }

  #webApp .panel--support .support-chat__attach {
    border-color: #e1d5ad !important;
    color: #74530b !important;
    background: #fff8df !important;
  }

  #webApp .panel--support .support-chat__composer textarea {
    box-sizing: border-box !important;
    min-width: 0 !important;
    min-height: 48px !important;
    height: 48px !important;
    max-height: 84px !important;
    padding: 11px 12px !important;
    border-color: #dfe3e8 !important;
    border-radius: 8px !important;
    color: #172033 !important;
    background: #ffffff !important;
    line-height: 24px !important;
    resize: none !important;
  }

  #webApp .panel--support .support-chat__image-preview {
    grid-template-columns: 42px minmax(0, 1fr) auto !important;
    gap: 8px !important;
    min-height: 50px !important;
    margin: 0 8px 6px !important;
    padding: 6px 8px !important;
  }

  #webApp .panel--support .support-chat__image-preview img {
    width: 42px !important;
    height: 42px !important;
  }

  #webApp .mobile-shell.support-keyboard-open {
    position: fixed !important;
    top: var(--web-visual-viewport-offset-top, 0px) !important;
    right: auto !important;
    bottom: auto !important;
    left: var(--web-visual-viewport-offset-left, 0px) !important;
    width: var(--web-visual-viewport-width, 100vw) !important;
    height: var(--web-visual-viewport-height, 100dvh) !important;
    min-height: 0 !important;
    padding-bottom: 0 !important;
    overflow: hidden !important;
    overscroll-behavior: none !important;
    background: #f4f5f7 !important;
  }

  #webApp .mobile-shell.support-keyboard-open .panel--support {
    display: grid !important;
    grid-template-rows: minmax(0, 1fr) !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  #webApp .mobile-shell.support-keyboard-open .support-chat {
    grid-template-rows: minmax(0, 1fr) auto auto auto !important;
    height: auto !important;
    min-height: 0 !important;
    width: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
    overflow: hidden !important;
  }

  #webApp .mobile-shell.support-keyboard-open .support-chat__messages {
    height: auto !important;
    min-height: 0 !important;
    padding: 8px 10px !important;
    gap: 7px !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
    touch-action: pan-y !important;
  }

  #webApp .mobile-shell.support-keyboard-open .support-message--virtual {
    width: 100% !important;
    max-width: 100% !important;
  }

  #webApp .mobile-shell.support-keyboard-open .support-message--virtual .support-message__image-button {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 42px !important;
    height: 42px !important;
    display: grid !important;
    place-items: center !important;
    border-color: rgba(203, 151, 19, 0.28) !important;
    border-radius: 8px !important;
    color: #79550d !important;
    background: #fff8d9 !important;
    box-shadow: none !important;
    font-size: 13px !important;
    line-height: 1 !important;
    font-weight: 700 !important;
    letter-spacing: 0 !important;
  }

  #webApp .mobile-shell.support-keyboard-open .support-message--virtual .support-message__image-button::after {
    content: "客服公告图片，点击查看";
  }

  #webApp .mobile-shell.support-keyboard-open .support-message--virtual .support-message__image {
    display: none !important;
  }

  #webApp .mobile-shell.support-keyboard-open .support-message--virtual p {
    padding: 8px 10px !important;
    font-size: 14px !important;
    line-height: 1.4 !important;
  }

  #webApp .mobile-shell.support-keyboard-open .support-message--virtual time {
    display: none !important;
  }

  #webApp .mobile-shell.support-keyboard-open .support-chat__composer {
    grid-template-columns: 44px minmax(0, 1fr) 60px !important;
    gap: 6px !important;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)) !important;
  }

  #webApp .mobile-shell.support-keyboard-open .support-chat__composer textarea {
    min-height: 48px !important;
    height: 48px !important;
    max-height: 72px !important;
  }

  #webApp .mobile-shell.support-keyboard-open .bottom-nav {
    display: none !important;
  }
}
