/*
 * JuggleChat mobile-web layout overrides.
 *
 * The bundled client is desktop-first: its navigation is a 66px left rail,
 * the conversation list is fixed at 344px, and settings drawers are 375px.
 * Keep the desktop layout untouched and turn those regions into a single-pane
 * mobile flow below the Bootstrap md breakpoint.
 */

:root {
  --jg-viewport-height: 100dvh;
  --jg-mobile-nav-height: 0px;
}

@media (max-width: 767.98px) {
  :root {
    --jg-mobile-nav-height: calc(58px + env(safe-area-inset-bottom, 0px));
  }

  html,
  body,
  #app {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body {
    min-width: 0;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  /* Login and registration */
  .jg-login-newui {
    min-height: var(--jg-viewport-height, 100dvh) !important;
    height: var(--jg-viewport-height, 100dvh);
    align-items: flex-start;
    padding:
      max(8px, env(safe-area-inset-top, 0px))
      max(8px, env(safe-area-inset-right, 0px))
      max(8px, env(safe-area-inset-bottom, 0px))
      max(8px, env(safe-area-inset-left, 0px)) !important;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .jg-login-card {
    width: min(100%, 440px) !important;
    height: min(545px, calc(var(--jg-viewport-height, 100dvh) - 16px)) !important;
    min-height: 0 !important;
    margin: auto;
    padding: 0 !important;
    border-radius: 14px;
    overflow: hidden auto !important;
  }

  .jg-login-content {
    padding: 68px clamp(20px, 8vw, 40px) 24px !important;
    overflow: hidden auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .jg-register-card .jg-login-content,
  .jg-login-org-card .jg-login-content {
    padding-top: 28px !important;
  }

  .jg-login-logo {
    top: 24px !important;
    width: min(164px, 50vw) !important;
    height: auto !important;
  }

  .jg-login-tabs {
    gap: 20px;
    margin-top: 38px !important;
    margin-bottom: 24px;
  }

  .jg-login-tab {
    font-size: 18px;
  }

  .jg-login-form-group {
    margin-bottom: 16px;
  }

  .jg-login-input,
  .jg-login-btn,
  .jg-login-org-input-card,
  .jg-login-org-submit {
    min-height: 48px;
    height: 48px;
  }

  .jg-login-input input,
  .jg-login-org-input-new,
  .tyn-settings-input,
  .tyn-settings-textarea,
  .tyn-chat-form-input,
  input,
  textarea,
  select {
    font-size: 16px !important;
  }

  .jg-login-btn {
    margin-top: 16px;
  }

  .jg-login-links {
    gap: clamp(18px, 8vw, 32px) !important;
    margin-top: 18px;
    flex-wrap: wrap;
  }

  .jg-login-qr-toggle {
    top: 14px;
    right: 14px;
    width: 48px;
    height: 48px;
  }

  .jg-login-setting-btn {
    top: 26px;
    right: 72px;
  }

  .jg-login-qr-hint {
    display: none !important;
  }

  .jg-login-qrcode-box {
    width: min(180px, 56vw);
    height: min(180px, 56vw);
  }

  .jg-register-back {
    margin: 0 0 24px !important;
  }

  .jg-register-title {
    margin-bottom: 24px;
    font-size: 22px;
  }

  .jg-login-org-panel,
  .jg-login-org-submit {
    width: 100% !important;
  }

  .jg-login-org-panel {
    margin-top: 42px;
  }

  .jg-login-org-title-new {
    margin-bottom: 32px;
    font-size: 22px;
  }

  /* Root layout and bottom navigation */
  .tyn-web-root {
    --appbar-height: var(--jg-mobile-nav-height);
    --content-full-height: calc(var(--jg-viewport-height, 100dvh) - var(--jg-mobile-nav-height));
    width: 100%;
    height: var(--jg-viewport-height, 100dvh) !important;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
  }

  .tyn-web-root > .tyn-aside-footer {
    order: 2;
    width: 100% !important;
    min-width: 0 !important;
    height: var(--jg-mobile-nav-height);
    min-height: var(--jg-mobile-nav-height);
    flex: 0 0 var(--jg-mobile-nav-height);
    flex-direction: row !important;
    align-items: flex-start;
    padding: 0 6px env(safe-area-inset-bottom, 0px) !important;
    border-top: 1px solid #e9edf2;
    background: rgba(255, 255, 255, .98);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, .05);
    z-index: 1300;
  }

  .tyn-web-root > .show-content {
    order: 1;
    width: 100%;
    min-width: 0;
    height: var(--content-full-height) !important;
    min-height: 0;
    flex: 1 1 auto;
  }

  .tyn-aside-footer .jg-footer-tools {
    width: 100%;
    height: 58px;
    margin: 0 !important;
    padding: 0;
    flex-direction: row !important;
    align-items: stretch;
    justify-content: space-around;
  }

  .tyn-aside-footer .jg-footer-tool,
  .tyn-aside-footer .jg-footer-top-box .jg-footer-tool,
  .tyn-aside-footer .jg-footer-top-box .jg-footer-tool:first-child {
    min-width: 0;
    height: 58px;
    margin: 0 !important;
    flex: 1 1 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .tyn-aside-footer .jg-asider-footer-item {
    width: 100%;
    min-height: 48px;
    gap: 2px;
    padding-top: 4px;
  }

  .tyn-aside-footer .jg-asider-footer-item .icon {
    width: 23px !important;
    height: 23px !important;
  }

  .tyn-aside-footer .jg-header-user-avatar {
    width: 30px;
    height: 30px;
  }

  html.jg-keyboard-open {
    --jg-mobile-nav-height: 0px;
  }

  html.jg-keyboard-open .tyn-web-root > .tyn-aside-footer {
    display: none !important;
  }

  /* Conversation list -> chat detail is a true single-pane flow. */
  .tyn-web-root .tyn-content {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: var(--content-full-height) !important;
    overflow: hidden;
  }

  .tyn-web-root .tyn-content > .tyn-aside {
    width: 100% !important;
    max-width: none;
    min-width: 0;
    flex: 1 1 auto;
  }

  .tyn-web-root .jg-conver-list,
  .tyn-web-root .jg-conversation-body,
  .tyn-web-root .tyn-aside-body,
  .tyn-web-root .tyn-contact-wrapper {
    width: 100% !important;
    max-width: 100%;
    min-width: 0;
  }

  .tyn-content:not(.tyn-contact):not(.tyn-content-active) > .tyn-main {
    display: none !important;
  }

  .tyn-content:not(.tyn-contact).tyn-content-active > .tyn-aside {
    display: none !important;
  }

  .tyn-content:not(.tyn-contact).tyn-content-active > .tyn-main.show {
    position: absolute;
    inset: 0;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: 100%;
    display: flex !important;
    z-index: 1100;
  }

  /* Contacts keep the category strip and the actual contact list visible. */
  .tyn-contact.tyn-content {
    flex-direction: column;
  }

  .tyn-contact.tyn-content > .tyn-contact-aside {
    width: 100% !important;
    height: auto !important;
    min-height: 0;
    flex: 0 0 auto;
    overflow: visible;
  }

  .tyn-contact-aside > .tyn-aside-body {
    height: auto !important;
    min-height: 0;
    overflow: hidden;
  }

  .tyn-contact-aside .tyn-aside-list {
    display: flex;
    width: 100%;
    gap: 8px;
    padding: 8px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .tyn-contact-aside .tyn-aside-list::-webkit-scrollbar {
    display: none;
  }

  .tyn-contact-aside .tyn-aside-item {
    width: auto;
    min-width: max-content;
    min-height: 42px;
    flex: 0 0 auto;
    padding: 8px 12px;
    border-radius: 10px;
  }

  .tyn-contact-aside .jg-arrow {
    display: none !important;
  }

  .tyn-contact.tyn-content > .tyn-main {
    position: relative;
    width: 100% !important;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    height: auto !important;
    flex: 1 1 auto;
    display: flex !important;
  }

  .tyn-contact.tyn-content > .tyn-main > .jg-conversations-header {
    display: none !important;
  }

  .jg-conversations-header,
  .tyn-chat-head,
  .tyn-settings-header {
    height: calc(60px + env(safe-area-inset-top, 0px)) !important;
    min-height: calc(60px + env(safe-area-inset-top, 0px)) !important;
    padding-top: env(safe-area-inset-top, 0px) !important;
    box-sizing: border-box;
  }

  .jg-conversations-header {
    padding-right: 10px;
    padding-left: 16px;
  }

  .jg-conversations-header .title,
  .jg-conversations-header h5,
  .jg-conversations-header h6 {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .jg-contact-actions {
    flex: 0 0 auto;
    gap: 2px;
  }

  .jg-contact-action,
  .jg-conversation-tool,
  .tyn-chat-head .tool,
  .tyn-chat-head .js-toggle-main {
    width: 44px;
    height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
  }

  .tyn-aside-toplist {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .tyn-aside-toplist::-webkit-scrollbar {
    display: none;
  }

  .newui-conversation-card {
    gap: 10px;
  }

  .newui-conversation-main {
    min-width: 0;
    gap: 10px;
  }

  .newui-conversation-side.newui-conversation-side-short {
    width: 48px;
    min-width: 48px;
  }

  .newui-conversation-side.newui-conversation-side-medium {
    width: 68px;
    min-width: 68px;
  }

  .newui-conversation-side.newui-conversation-side-long {
    width: min(96px, 27vw);
    min-width: min(96px, 27vw);
  }

  /* The base bundle hides this after Bootstrap's d-md-none rule. */
  .tyn-chat-head > .h5-list {
    display: flex !important;
    flex: 0 0 auto;
    margin: 0 2px 0 -4px !important;
  }

  .tyn-chat-head {
    gap: 0;
    padding-right: 4px !important;
    padding-left: 4px !important;
  }

  .tyn-chat-head > * {
    padding: 0 !important;
  }

  .tyn-chat-head > .tyn-media-group {
    min-width: 0;
    flex: 1 1 auto;
    gap: 8px;
  }

  .tyn-chat-head .tyn-conver-header-title,
  .tyn-chat-head .tyn-media-row,
  .tyn-chat-head .name {
    min-width: 0;
  }

  .tyn-chat-head .name,
  .tyn-chat-head .meta {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tyn-chat-head .jg-conversation-header-tools {
    flex: 0 0 auto;
    gap: 0 !important;
  }

  .tyn-chat-content-aside,
  .tyn-chat-content-aside.show-aside {
    width: 100% !important;
    max-width: 100%;
    right: 0;
  }

  .jg-pinned-box {
    max-width: calc(100vw - 16px);
  }

  /* Composer: keep all actions reachable without consuming half the screen. */
  .tyn-composer-shell {
    --composer-height: 116px !important;
    min-height: 116px !important;
    max-height: 42vh;
  }

  .tyn-composer-resize-handle {
    display: none;
  }

  .tyn-composer-toolbar {
    height: 44px;
    min-height: 44px;
    padding: 6px 10px 0;
    gap: 4px;
    overflow: hidden;
  }

  .tyn-composer-left,
  .tyn-composer-right,
  .tyn-composer-toolbar-left {
    gap: 8px;
  }

  .tyn-composer-toolbar-left {
    min-width: 0;
    max-width: calc(100vw - 48px);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .tyn-composer-toolbar-left::-webkit-scrollbar {
    display: none;
  }

  .tyn-composer-toolbar .btn,
  .tyn-chat-form-inner .btn,
  .tyn-toolbar-icon-wrap {
    min-width: 38px;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .tyn-chat-form-inner {
    min-height: 72px;
    padding: 6px 12px 10px;
  }

  .tyn-composer-editor {
    min-height: 54px;
  }

  .tyn-chat-form-input {
    min-height: 54px !important;
    max-height: 112px;
    line-height: 22px;
    padding: 4px 0 8px !important;
  }

  /* Settings, profile and right-side drawers */
  .tyn-common-aside,
  .tyn-common-aside.tyn-common-aside-right {
    width: 100% !important;
    max-width: 100%;
    height: var(--jg-viewport-height, 100dvh);
    border-radius: 0 !important;
  }

  .tyn-common-aside.show-caside,
  .tyn-common-aside.tyn-common-aside-right.show-caside {
    inset: 0 !important;
    z-index: 1500 !important;
  }

  .tyn-settings-page,
  .tyn-settings-page--list,
  .tyn-settings-page--compact,
  .tyn-settings-page--qrcode {
    width: 100%;
    min-width: 0;
    padding: 12px 12px 18px !important;
  }

  .jg-setting-aside,
  .jg-setting-panel,
  .jg-setting-row,
  .jg-setting-aside .jg-li {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box;
  }

  .jg-setting-row-main,
  .jg-setting-row-value,
  .jg-setting-aside .jg-li > * {
    min-width: 0;
    max-width: 100%;
  }

  .tyn-settings-section {
    width: 100%;
    min-width: 0;
    padding-right: 14px;
    padding-left: 14px;
  }

  .tyn-settings-row,
  .tyn-settings-row--compact {
    min-width: 0;
    gap: 8px;
  }

  .tyn-settings-main,
  .tyn-settings-extra,
  .tyn-settings-selector,
  .tyn-settings-selector__value {
    min-width: 0;
  }

  .tyn-settings-selector {
    max-width: 52vw;
  }

  .tyn-settings-selector__value,
  .tyn-settings-row-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tyn-settings-selector__dropdown {
    max-width: calc(100vw - 24px);
    max-height: min(60vh, 420px);
    overflow-y: auto;
  }

  .tyn-settings-qrcode-box {
    width: min(258px, calc(100vw - 64px));
    height: min(258px, calc(100vw - 64px));
  }

  .tyn-settings-members,
  .tyn-settings-section--group-members .tyn-settings-members {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  /* Right-top add menu and other floating panels */
  .jg-addmenu {
    position: fixed !important;
    top: calc(56px + env(safe-area-inset-top, 0px)) !important;
    right: max(10px, env(safe-area-inset-right, 0px)) !important;
    left: auto !important;
    width: min(200px, calc(100vw - 20px));
    min-width: 156px;
    max-height: calc(var(--jg-viewport-height, 100dvh) - 76px);
    overflow-y: auto;
    transform-origin: top right;
  }

  .jg-addmenu-item {
    min-height: 46px;
    padding: 11px 16px;
  }

  .jg-addmenu-backdrop,
  .dropmenu-backdrop,
  .fade-bg {
    touch-action: manipulation;
  }

  .modal-dialog {
    width: auto;
    max-width: calc(100vw - 24px) !important;
    margin: 12px auto !important;
  }

  .modal-content {
    max-height: calc(var(--jg-viewport-height, 100dvh) - 24px);
    overflow: hidden;
  }

  .modal-body {
    max-height: calc(var(--jg-viewport-height, 100dvh) - 64px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .jg-agent-modal-content,
  .modal-addfriend,
  .modal-transfer-owner,
  .modal-merge-content,
  .tyn-group-add-member-content {
    width: 100% !important;
    max-width: calc(100vw - 24px) !important;
  }
}

@media (max-width: 359.98px) {
  .jg-login-content {
    padding-right: 16px !important;
    padding-left: 16px !important;
  }

  .jg-login-tabs {
    gap: 14px;
  }

  .jg-login-tab {
    font-size: 17px;
  }

  .newui-conversation-card {
    padding-right: 10px;
    padding-left: 10px;
  }

  .newui-conversation-avatar-wrap,
  .newui-conversation-avatar-wrap .tyn-avatar,
  .newui-conversation-avatar {
    width: 40px;
    min-width: 40px;
    height: 40px;
  }

  .newui-conversation-side.newui-conversation-side-medium {
    width: 60px;
    min-width: 60px;
  }

  .newui-conversation-side.newui-conversation-side-long {
    width: 74px;
    min-width: 74px;
  }

  .tyn-chat-head .tyn-conver-avatar {
    width: 34px;
    min-width: 34px;
    height: 34px;
  }

  .tyn-chat-head .jg-conversation-header-tools .tool,
  .tyn-chat-head .js-toggle-main {
    width: 40px;
    min-width: 40px;
    height: 40px;
  }

  .tyn-chat-head .name {
    font-size: 13px;
  }

  .tyn-composer-toolbar {
    padding-right: 6px;
    padding-left: 6px;
  }

  .tyn-composer-left,
  .tyn-composer-right,
  .tyn-composer-toolbar-left {
    gap: 4px;
  }

  .tyn-settings-page,
  .tyn-settings-page--list,
  .tyn-settings-page--compact,
  .tyn-settings-page--qrcode {
    padding-right: 8px !important;
    padding-left: 8px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .jg-addmenu,
  .tyn-common-aside,
  .tyn-chat-content-aside {
    transition: none !important;
  }
}
