/* Training System 1.9.7.6 — native WebView chat integration */
.tm-bottom-nav a[href*="section=chat"],
.mini-top-menu a[href*="section=chat"] { position: relative; }

.xtr-mchat-nav-badge {
  position: absolute;
  top: 7px;
  right: calc(50% - 24px);
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  background: #ff171d;
  border: 2px solid #0b0d0f;
  color: #fff;
  font: 800 10px/1 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  box-shadow: 0 3px 9px rgba(255,23,29,.3);
  z-index: 4;
}
.xtr-mchat-nav-badge[hidden] { display: none !important; }

/* Host chat section remains the only chat surface in WebView. */
.tm-app--chat .tm-chat-view {
  min-height: calc(100dvh - var(--tm-bottom-nav-height, 76px));
  display: flex;
  flex-direction: column;
  background: #f3f4f6;
}

.tm-app--chat .chat-header {
  flex: 0 0 auto;
}

.tm-app--chat .chat-messages-area {
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px 14px 10px;
  overflow: hidden;
  box-sizing: border-box;
}

.xtr-mchat {
  width: 100%;
  height: 100%;
  min-height: 360px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  color: #17191c;
  font-family: inherit;
}

.xtr-mchat-loading,
.xtr-mchat-error,
.xtr-mchat-empty {
  margin: auto;
  width: min(100%, 560px);
  border: 1px solid rgba(19,24,29,.08);
  border-radius: 22px;
  background: rgba(255,255,255,.92);
  box-shadow: 0 10px 30px rgba(18,22,26,.055);
  padding: 28px 22px;
  text-align: center;
  box-sizing: border-box;
}
.xtr-mchat-loading span {
  display: block;
  width: 28px;
  height: 28px;
  margin: 0 auto 12px;
  border: 3px solid #e7e9ec;
  border-top-color: #c51f2a;
  border-radius: 50%;
  animation: xtrMchatSpin .8s linear infinite;
}
@keyframes xtrMchatSpin { to { transform: rotate(360deg); } }
.xtr-mchat-loading strong,
.xtr-mchat-error strong,
.xtr-mchat-empty strong { display:block; font-size:16px; line-height:1.3; }
.xtr-mchat-error p,
.xtr-mchat-empty p { margin:8px 0 0; color:#737981; font-size:14px; line-height:1.45; }
.xtr-mchat-empty > span { display:block; margin-bottom:10px; font-size:28px; }
.xtr-mchat-error button {
  margin-top: 16px;
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: #c51f2a;
  color: #fff;
  font-weight: 800;
}

.xtr-mchat-contacts {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 2px 0 8px;
}
.xtr-mchat-contacts[hidden],
.xtr-mchat-thread[hidden],
.xtr-mchat-error[hidden],
.xtr-mchat-loading[hidden] { display: none !important; }

.xtr-mchat-contact {
  appearance: none;
  width: 100%;
  display: grid;
  grid-template-columns: 48px minmax(0,1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 78px;
  padding: 13px 14px;
  border: 1px solid rgba(19,24,29,.08);
  border-radius: 18px;
  background: #fff;
  color: inherit;
  text-align: left;
  box-shadow: 0 6px 20px rgba(18,22,26,.045);
}
.xtr-mchat-contact:active { transform: scale(.995); }
.xtr-mchat-contact.has-unread { border-color: rgba(197,31,42,.25); background:#fffafb; }
.xtr-mchat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: #f7e8ea;
  color: #a91e28;
  font-size: 20px;
  font-weight: 900;
}
.xtr-mchat-contact-copy { min-width:0; display:flex; flex-direction:column; gap:2px; }
.xtr-mchat-contact-copy strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:16px; line-height:1.25; }
.xtr-mchat-contact-copy small { color:#8b4a50; font-weight:700; font-size:12px; }
.xtr-mchat-contact-copy em { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:#7a8087; font-style:normal; font-size:13px; }
.xtr-mchat-contact-badge {
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 999px;
  display:grid;
  place-items:center;
  background:#c51f2a;
  color:#fff;
  font-size:11px;
  line-height:1;
}
.xtr-mchat-contact-arrow { color:#9ba0a6; font-size:28px; font-weight:300; }

.xtr-mchat-thread {
  flex: 1 1 auto;
  min-height: 0;
  display:flex;
  flex-direction:column;
  background:#fff;
  border:1px solid rgba(19,24,29,.08);
  border-radius:20px;
  overflow:hidden;
  box-shadow:0 7px 24px rgba(18,22,26,.05);
}
.xtr-mchat-thread-head {
  flex:0 0 auto;
  min-height:58px;
  display:flex;
  align-items:center;
  gap:10px;
  padding:8px 12px;
  border-bottom:1px solid #eceef0;
  background:#fff;
}
.xtr-mchat-back {
  width:42px;
  height:42px;
  border:0;
  border-radius:13px;
  background:#f3f4f5;
  color:#202429;
  font-size:30px;
  line-height:1;
}
.xtr-mchat-peer { min-width:0; display:flex; flex-direction:column; }
.xtr-mchat-peer strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:15px; }
.xtr-mchat-peer small { color:#8c9298; font-size:11px; margin-top:1px; }
.xtr-mchat-messages {
  flex:1 1 auto;
  min-height:0;
  overflow:auto;
  overscroll-behavior:contain;
  padding:14px 12px 18px;
  display:flex;
  flex-direction:column;
  gap:10px;
  background:linear-gradient(180deg,#f7f7f8 0%,#f2f3f4 100%);
}
.xtr-mchat-thread-empty { margin:auto; color:#8a9097; font-size:14px; }
.xtr-mchat-message { max-width:82%; display:flex; flex-direction:column; align-items:flex-start; }
.xtr-mchat-message.is-mine { align-self:flex-end; align-items:flex-end; }
.xtr-mchat-message.is-theirs { align-self:flex-start; }
.xtr-mchat-sender { margin:0 0 3px 5px; color:#8d4b50; font-size:10px; font-weight:800; }
.xtr-mchat-bubble {
  padding:10px 12px;
  border-radius:16px 16px 16px 5px;
  background:#fff;
  border:1px solid rgba(19,24,29,.07);
  box-shadow:0 2px 8px rgba(0,0,0,.025);
  color:#23262a;
  font-size:14px;
  line-height:1.42;
  word-break:break-word;
}
.is-mine .xtr-mchat-bubble { border-radius:16px 16px 5px 16px; background:#c51f2a; border-color:#c51f2a; color:#fff; }
.xtr-mchat-time { margin-top:3px; padding:0 4px; color:#9a9fa5; font-size:9px; }
.xtr-mchat-image { display:block; max-width:240px; padding:0; border:0; background:transparent; border-radius:14px; overflow:hidden; }
.xtr-mchat-image img { display:block; width:100%; max-height:260px; object-fit:cover; }
.xtr-mchat-file {
  min-width:210px;
  max-width:280px;
  display:grid;
  grid-template-columns:auto minmax(0,1fr) auto;
  align-items:center;
  gap:8px;
  padding:10px 12px;
  border-radius:14px;
  background:#fff;
  border:1px solid #e3e5e7;
  color:#24282c;
  text-decoration:none;
}
.is-mine .xtr-mchat-file { background:#fff7f7; border-color:#f0cdd0; }
.xtr-mchat-file span:nth-child(2) { min-width:0; display:flex; flex-direction:column; }
.xtr-mchat-file strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:12px; }
.xtr-mchat-file small { color:#8a9095; font-size:10px; }

/* Reuse the host composer; do not create a floating dock. */
.tm-app--chat .chat-input-bar {
  flex:0 0 auto;
  display:none;
  align-items:flex-end;
  gap:8px;
  margin:0;
  padding:10px 14px calc(10px + env(safe-area-inset-bottom,0px));
  border-top:1px solid rgba(19,24,29,.09);
  background:#fff;
  box-sizing:border-box;
  z-index:3;
}
.tm-app--chat .chat-input-bar.xtr-mchat-composer-active { display:flex; }
.tm-app--chat .chat-input {
  min-width:0;
  flex:1 1 auto;
  height:44px;
  min-height:44px;
  margin:0;
  padding:0 14px;
  border:1px solid #dfe2e5;
  border-radius:14px;
  background:#f7f8f9;
  color:#202428;
  font-size:16px;
  box-sizing:border-box;
}
.tm-app--chat .chat-input:focus { border-color:#c51f2a; outline:0; box-shadow:0 0 0 3px rgba(197,31,42,.08); }
.tm-app--chat .chat-send-btn {
  flex:0 0 44px;
  width:44px;
  height:44px;
  border-radius:14px;
  background:#c51f2a;
  color:#fff;
}
.tm-app--chat .chat-send-btn:disabled { opacity:.45; }
.xtr-mchat-attach {
  flex:0 0 44px;
  width:44px;
  height:44px;
  display:grid;
  place-items:center;
  border:1px solid #dfe2e5;
  border-radius:14px;
  background:#f7f8f9;
  color:#6f747a;
  font-size:27px;
  font-weight:300;
  cursor:pointer;
  box-sizing:border-box;
}
.xtr-mchat-attach.has-file { border-color:#c51f2a; background:#fff0f1; color:#c51f2a; }

.xtr-mchat-inline-notice {
  position:fixed;
  left:16px;
  right:16px;
  bottom:calc(88px + env(safe-area-inset-bottom,0px));
  z-index:9999;
  padding:11px 14px;
  border-radius:13px;
  background:#202328;
  color:#fff;
  font-size:12px;
  text-align:center;
  box-shadow:0 10px 30px rgba(0,0,0,.22);
}
.xtr-mchat-inline-notice.is-danger { background:#a71924; }
.xtr-mchat-inline-notice[hidden] { display:none !important; }

.xtr-mchat-lightbox {
  position:fixed;
  inset:0;
  z-index:100000;
  display:grid;
  place-items:center;
  padding:max(16px,env(safe-area-inset-top,0px)) 12px max(16px,env(safe-area-inset-bottom,0px));
  background:rgba(4,5,6,.94);
  box-sizing:border-box;
}
.xtr-mchat-lightbox[hidden] { display:none !important; }
.xtr-mchat-lightbox img { max-width:100%; max-height:100%; object-fit:contain; border-radius:12px; }
.xtr-mchat-lightbox-close {
  position:absolute;
  top:max(14px,env(safe-area-inset-top,0px));
  right:14px;
  width:44px;
  height:44px;
  border:0;
  border-radius:50%;
  background:rgba(255,255,255,.13);
  color:#fff;
  font-size:28px;
}
body.xtr-mchat-lightbox-open { overflow:hidden; }

/* Hard guarantee: no legacy floating Training-System launcher/dock in the native app shell. */
.tm-app .xtr-chat-launcher,
.tm-app .xtr-chat-dock { display:none !important; }

@media (max-width: 430px) {
  .tm-app--chat .chat-messages-area { padding:10px 10px 8px; }
  .xtr-mchat { min-height:300px; }
  .xtr-mchat-contact { min-height:72px; grid-template-columns:44px minmax(0,1fr) auto; gap:10px; padding:11px 12px; border-radius:16px; }
  .xtr-mchat-avatar { width:44px; height:44px; border-radius:14px; font-size:18px; }
  .xtr-mchat-message { max-width:88%; }
  .xtr-mchat-thread { border-radius:17px; }
  .tm-app--chat .chat-input-bar { padding-left:10px; padding-right:10px; }
  .xtr-mchat-nav-badge { top:5px; right:calc(50% - 22px); }
}

/* ========================================================================== 
   1.9.7.7 — WebView Chat viewport/composer hardening
   The native Chat section is a single flex column between the app topbar and
   bottom navigation. The host composer participates in layout instead of
   sitting behind the bottom navigation.
   ========================================================================== */
.tm-app--chat .tm-chat-view {
  --xtr-mchat-view-height: calc(100dvh - 150px);
  height: var(--xtr-mchat-view-height) !important;
  min-height: 0 !important;
  max-height: var(--xtr-mchat-view-height) !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  position: relative;
}

.tm-app--chat .chat-header {
  position: relative !important;
  top: auto !important;
  flex: 0 0 auto !important;
  min-height: 68px;
}

.tm-app--chat .chat-messages-area {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  height: auto !important;
  max-height: none !important;
  padding: 10px 12px !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 0 !important;
}

.tm-app--chat .xtr-mchat {
  flex: 1 1 auto;
  min-height: 0 !important;
  height: 100% !important;
  max-height: 100% !important;
}

.tm-app--chat .xtr-mchat-thread {
  min-height: 0 !important;
  height: 100%;
  max-height: 100%;
  border-radius: 18px;
}

.tm-app--chat .xtr-mchat-thread-head {
  min-height: 58px;
  padding: 8px 10px;
}

.tm-app--chat .xtr-mchat-messages {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  height: auto !important;
  padding: 12px 10px 14px;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* Override the host fixed composer: it must sit above the bottom navigation
   as the final flex row of the native chat section. */
.tm-app--chat .chat-input-bar {
  position: relative !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  width: 100% !important;
  flex: 0 0 auto !important;
  margin: 0 !important;
  padding: 8px 10px max(8px, env(safe-area-inset-bottom, 0px)) !important;
  background: rgba(255,255,255,.98) !important;
  box-shadow: 0 -6px 18px rgba(8,10,12,.055) !important;
  border-top: 1px solid rgba(8,10,12,.08) !important;
}

.tm-app--chat .chat-input-bar.xtr-mchat-composer-active {
  display: flex !important;
}

.tm-app--chat .chat-input,
.tm-app--chat .chat-send-btn,
.tm-app--chat .xtr-mchat-attach {
  min-height: 44px;
  height: 44px;
}

.tm-app--chat .chat-input {
  font-size: 16px !important;
  padding: 0 12px !important;
}

.tm-app--chat .xtr-mchat-message {
  max-width: min(86%, 390px);
}

.tm-app--chat .xtr-mchat-image {
  width: auto;
  max-width: min(72vw, 280px);
  border-radius: 15px;
  background: #eceef0;
}

.tm-app--chat .xtr-mchat-image img {
  width: auto;
  max-width: 100%;
  max-height: min(34dvh, 300px);
  object-fit: contain;
  background: #eceef0;
}

.tm-app--chat .xtr-mchat-sender {
  margin-left: 4px;
  font-size: 10px;
}

.tm-app--chat .xtr-mchat-time {
  font-size: 9px;
  line-height: 1.2;
}

body.xtr-mchat-thread-open {
  overflow: hidden;
}

@media (max-width: 430px) {
  .tm-app--chat .chat-messages-area {
    padding: 8px !important;
  }
  .tm-app--chat .xtr-mchat-thread {
    border-radius: 16px;
  }
  .tm-app--chat .xtr-mchat-thread-head {
    min-height: 54px;
    padding: 6px 8px;
  }
  .tm-app--chat .xtr-mchat-messages {
    padding: 10px 8px 12px;
    gap: 8px;
  }
  .tm-app--chat .xtr-mchat-message {
    max-width: 90%;
  }
  .tm-app--chat .xtr-mchat-image {
    max-width: min(76vw, 260px);
  }
  .tm-app--chat .xtr-mchat-image img {
    max-height: min(31dvh, 270px);
  }
  .tm-app--chat .chat-input-bar {
    gap: 7px;
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
}

/* ========================================================================== 
   1.9.7.8 — WebView Chat contact identity + scroll responsiveness hardening
   ========================================================================== */
.tm-app--chat .xtr-mchat-messages {
  scroll-behavior: auto !important;
  touch-action: pan-y;
  overscroll-behavior-x: none;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
}

.tm-app--chat .xtr-mchat-thread,
.tm-app--chat .xtr-mchat-messages,
.tm-app--chat .xtr-mchat-contacts {
  min-width: 0;
}

.tm-app--chat .xtr-mchat-messages > * {
  flex-shrink: 0;
}

@media (max-width: 430px) {
  .tm-app--chat .xtr-mchat-messages {
    padding: 10px 9px 12px !important;
    gap: 8px;
  }
  .tm-app--chat .xtr-mchat-message {
    max-width: 90%;
  }
}

/* ========================================================================== 
   1.9.7.9 — WebView Chat attachment feedback + keyboard viewport polish
   ========================================================================== */
.tm-app--chat .chat-input-bar {
  flex-wrap: wrap;
  align-content: flex-end;
}

.tm-app--chat .xtr-mchat-pending-attachment {
  order: -1;
  flex: 0 0 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 48px minmax(0,1fr) auto 36px;
  align-items: center;
  gap: 10px;
  margin: 0 0 7px;
  padding: 8px 9px;
  border: 1px solid rgba(197,31,42,.18);
  border-radius: 14px;
  background: #fff7f8;
  box-sizing: border-box;
}
.tm-app--chat .xtr-mchat-pending-attachment[hidden] { display: none !important; }
.tm-app--chat .xtr-mchat-pending-thumb {
  width: 48px;
  height: 48px;
  overflow: hidden;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: #eceef0;
  color: #8d3038;
}
.tm-app--chat .xtr-mchat-pending-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}
.tm-app--chat .xtr-mchat-filetype {
  max-width: 44px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #a51e28;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .35px;
}
.tm-app--chat .xtr-mchat-pending-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tm-app--chat .xtr-mchat-pending-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #202327;
  font-size: 12px;
  line-height: 1.25;
}
.tm-app--chat .xtr-mchat-pending-copy small,
.tm-app--chat .xtr-mchat-pending-status {
  color: #7e848a;
  font-size: 10px;
  line-height: 1.25;
}
.tm-app--chat .xtr-mchat-pending-status {
  min-width: 0;
  color: #9c3a42;
  font-weight: 800;
  white-space: nowrap;
}
.tm-app--chat .xtr-mchat-pending-remove {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: rgba(197,31,42,.08);
  color: #a51e28;
  font-size: 22px;
  line-height: 1;
}
.tm-app--chat .xtr-mchat-pending-attachment.is-sending .xtr-mchat-pending-status::before {
  content: "";
  width: 13px;
  height: 13px;
  margin-right: 6px;
  display: inline-block;
  vertical-align: -2px;
  border: 2px solid rgba(197,31,42,.22);
  border-top-color: #c51f2a;
  border-radius: 50%;
  animation: xtrMchatSpin .75s linear infinite;
}
.tm-app--chat .xtr-mchat-pending-attachment.is-sending .xtr-mchat-pending-remove {
  opacity: .35;
  pointer-events: none;
}
.tm-app--chat .xtr-mchat-attach.is-disabled {
  opacity: .45;
  pointer-events: none;
}
.tm-app--chat .chat-send-btn[aria-busy="true"] {
  position: relative;
  color: transparent !important;
}
.tm-app--chat .chat-send-btn[aria-busy="true"] svg { opacity: 0; }
.tm-app--chat .chat-send-btn[aria-busy="true"]::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,.42);
  border-top-color: #fff;
  border-radius: 50%;
  animation: xtrMchatSpin .72s linear infinite;
}

/* visualViewport already excludes the Android keyboard. When the keyboard is
   open the bottom navigation is outside the visible viewport, therefore it
   must not reserve an additional strip below the composer. */
body.xtr-mchat-keyboard-open .tm-app--chat .chat-input-bar {
  padding-bottom: 8px !important;
}
body.xtr-mchat-keyboard-open .tm-app--chat .tm-chat-view {
  min-height: 0 !important;
}
body.xtr-mchat-keyboard-open .tm-app--chat .chat-messages-area {
  padding-bottom: 6px !important;
}

@media (max-width: 430px) {
  .tm-app--chat .xtr-mchat-pending-attachment {
    grid-template-columns: 42px minmax(0,1fr) 34px;
    gap: 8px;
    padding: 7px 8px;
  }
  .tm-app--chat .xtr-mchat-pending-thumb {
    width: 42px;
    height: 42px;
    border-radius: 10px;
  }
  .tm-app--chat .xtr-mchat-pending-status {
    grid-column: 2;
    white-space: normal;
  }
  .tm-app--chat .xtr-mchat-pending-remove {
    grid-column: 3;
    grid-row: 1 / span 2;
    align-self: center;
  }
}

/* ========================================================================== 
   1.9.7.10 — WebView Chat composer single-row regression fix
   The attachment preview owns a full grid row while attach/input/send are
   forced into one deterministic row at every mobile width.
   ========================================================================== */
.tm-app--chat .chat-input-bar.xtr-mchat-composer-active {
  display: grid !important;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  grid-auto-flow: row;
  align-items: end;
  column-gap: 8px;
  row-gap: 7px;
  flex-wrap: initial !important;
  align-content: initial !important;
}

.tm-app--chat .chat-input-bar .xtr-mchat-pending-attachment {
  grid-column: 1 / -1;
  grid-row: 1;
  width: 100%;
  min-width: 0;
  margin: 0 !important;
}

.tm-app--chat .chat-input-bar .xtr-mchat-attach {
  grid-column: 1;
  grid-row: 2;
  width: 44px !important;
  min-width: 44px !important;
  max-width: 44px !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box;
}

.tm-app--chat .chat-input-bar .chat-input {
  grid-column: 2;
  grid-row: 2;
  width: 100% !important;
  min-width: 0 !important;
  max-width: none !important;
  margin: 0 !important;
  box-sizing: border-box;
}

.tm-app--chat .chat-input-bar .chat-send-btn {
  grid-column: 3;
  grid-row: 2;
  width: 44px !important;
  min-width: 44px !important;
  max-width: 44px !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box;
}

@media (max-width: 430px) {
  .tm-app--chat .chat-input-bar.xtr-mchat-composer-active {
    grid-template-columns: 42px minmax(0, 1fr) 42px;
    column-gap: 7px;
    row-gap: 6px;
  }
  .tm-app--chat .chat-input-bar .xtr-mchat-attach,
  .tm-app--chat .chat-input-bar .chat-send-btn {
    width: 42px !important;
    min-width: 42px !important;
    max-width: 42px !important;
  }
}

/* ========================================================================== 
   1.9.7.12 — Thread settle, message dates and attachment preview hardening
   ========================================================================== */
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-image {
  width: min(68vw, 260px) !important;
  max-width: min(68vw, 260px) !important;
  height: auto !important;
  max-height: 280px !important;
  overflow: hidden !important;
  display: block !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 15px !important;
  background: #eceef0 !important;
  box-sizing: border-box !important;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-image img {
  display: block !important;
  width: 100% !important;
  height: auto !important;
  max-width: 100% !important;
  max-height: 280px !important;
  object-fit: contain !important;
  object-position: center !important;
  border-radius: inherit !important;
  background: #eceef0 !important;
}

.tm-app--chat .xtr-mchat-lightbox {
  position: fixed !important;
  inset: 0 !important;
  z-index: 2147483000 !important;
  width: 100vw !important;
  height: 100dvh !important;
  padding: max(18px, env(safe-area-inset-top,0px)) 14px max(18px, env(safe-area-inset-bottom,0px)) !important;
  display: grid !important;
  place-items: center !important;
  overflow: hidden !important;
  background: rgba(3,4,5,.96) !important;
  box-sizing: border-box !important;
}
.tm-app--chat .xtr-mchat-lightbox[hidden] { display: none !important; }
.tm-app--chat .xtr-mchat-lightbox img {
  display: block !important;
  width: auto !important;
  height: auto !important;
  max-width: calc(100vw - 28px) !important;
  max-height: calc(100dvh - 42px - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px)) !important;
  object-fit: contain !important;
  object-position: center !important;
  border-radius: 14px !important;
}
.tm-app--chat .xtr-mchat-lightbox-close {
  z-index: 2 !important;
}

.tm-app--chat .xtr-mchat-time {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 430px) {
  .tm-app--chat #xtrMobileChatRoot .xtr-mchat-image {
    width: min(72vw, 250px) !important;
    max-width: min(72vw, 250px) !important;
    max-height: 250px !important;
  }
  .tm-app--chat #xtrMobileChatRoot .xtr-mchat-image img {
    max-height: 250px !important;
  }
}

/* ========================================================================== 
   1.9.7.13 — Attachment tray + deterministic thread bottom hardening
   Pending attachments live in their own flex row above the composer so they
   cannot be clipped or lost when the Android keyboard changes the viewport.
   ========================================================================== */
.tm-app--chat .xtr-mchat-attachment-tray {
  flex: 0 0 auto !important;
  width: 100% !important;
  min-width: 0 !important;
  margin: 0 !important;
  padding: 8px 10px 0 !important;
  background: rgba(255,255,255,.98) !important;
  box-sizing: border-box !important;
  border-top: 1px solid rgba(19,24,29,.06);
}
.tm-app--chat .xtr-mchat-attachment-tray[hidden] { display: none !important; }
.tm-app--chat .xtr-mchat-attachment-tray .xtr-mchat-pending-attachment {
  width: 100% !important;
  margin: 0 !important;
  display: grid !important;
  grid-template-columns: 48px minmax(0,1fr) 36px !important;
  grid-template-areas:
    "thumb copy remove"
    "thumb status remove" !important;
  align-items: center !important;
  gap: 3px 10px !important;
  padding: 8px 9px !important;
}
.tm-app--chat .xtr-mchat-attachment-tray .xtr-mchat-pending-thumb { grid-area: thumb; }
.tm-app--chat .xtr-mchat-attachment-tray .xtr-mchat-pending-copy { grid-area: copy; }
.tm-app--chat .xtr-mchat-attachment-tray .xtr-mchat-pending-status {
  grid-area: status;
  white-space: normal !important;
}
.tm-app--chat .xtr-mchat-attachment-tray .xtr-mchat-pending-remove {
  grid-area: remove;
  align-self: center;
}

/* The composer has exactly one row. The pending attachment is no longer a
   child of this grid, so it can never force the send button onto another row. */
.tm-app--chat .chat-input-bar.xtr-mchat-composer-active {
  display: grid !important;
  grid-template-columns: 44px minmax(0,1fr) 44px !important;
  grid-template-rows: 44px !important;
  grid-auto-rows: 44px !important;
  align-items: center !important;
  column-gap: 8px !important;
  row-gap: 0 !important;
}
.tm-app--chat .chat-input-bar .xtr-mchat-attach { grid-column:1 !important; grid-row:1 !important; }
.tm-app--chat .chat-input-bar .chat-input { grid-column:2 !important; grid-row:1 !important; }
.tm-app--chat .chat-input-bar .chat-send-btn { grid-column:3 !important; grid-row:1 !important; }

.tm-app--chat .xtr-mchat-bottom-anchor {
  flex: 0 0 1px;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

body.xtr-mchat-keyboard-open .tm-app--chat .xtr-mchat-attachment-tray {
  padding-top: 6px !important;
}

@media (max-width:430px) {
  .tm-app--chat .xtr-mchat-attachment-tray {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
  .tm-app--chat .xtr-mchat-attachment-tray .xtr-mchat-pending-attachment {
    grid-template-columns: 42px minmax(0,1fr) 34px !important;
    gap: 2px 8px !important;
    padding: 7px 8px !important;
  }
  .tm-app--chat .chat-input-bar.xtr-mchat-composer-active {
    grid-template-columns: 42px minmax(0,1fr) 42px !important;
    grid-template-rows: 42px !important;
    column-gap: 7px !important;
  }
}


/* ==========================================================================
   1.9.7.16 — deterministic initial reveal repair
   Skeleton is visible during the real network request, not after it.
   ========================================================================== */
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-thread {
  position: relative;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-thread.is-preparing .xtr-mchat-messages {
  visibility: hidden !important;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-thread.is-preparing::after {
  content: none !important;
  display: none !important;
}

/* ========================================================================== 
   1.9.7.15 — post-send attachment alignment + conversation skeleton
   ========================================================================== */
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-thread.is-preparing::after {
  content: none !important;
  display: none !important;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-thread-skeleton {
  display: none;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-thread.is-preparing .xtr-mchat-thread-skeleton {
  position: absolute;
  top: var(--xtr-mchat-thread-head-height, 58px);
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 3;
  padding: 18px 14px 20px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 15px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(247,248,249,.98), rgba(244,246,247,.98));
  pointer-events: none;
  box-sizing: border-box;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-skel-row {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-skel-row.is-right { align-items: flex-end; }
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-skel-row.is-left { align-items: flex-start; }
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-skel-bubble,
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-skel-media,
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-skel-time {
  display: block;
  border-radius: 16px;
  background: linear-gradient(100deg,#e6e9ec 18%,#f7f8f9 38%,#e6e9ec 58%);
  background-size: 220% 100%;
  animation: xtrMchatSkeletonShimmer 1.15s linear infinite;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-skel-bubble {
  width: min(58vw, 220px);
  height: 54px;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-skel-bubble.is-wide { width: min(68vw, 260px); height: 68px; }
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-skel-bubble.is-short { width: min(42vw, 160px); height: 48px; }
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-skel-media {
  width: min(56vw, 220px);
  aspect-ratio: 4 / 3;
  border-radius: 17px;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-skel-time {
  width: 92px;
  height: 9px;
  border-radius: 999px;
}
@keyframes xtrMchatSkeletonShimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .tm-app--chat #xtrMobileChatRoot .xtr-mchat-skel-bubble,
  .tm-app--chat #xtrMobileChatRoot .xtr-mchat-skel-media,
  .tm-app--chat #xtrMobileChatRoot .xtr-mchat-skel-time { animation: none !important; }
}


/* ==========================================================================
   1.9.7.17 — guaranteed root-level conversation skeleton
   The loading skeleton is rendered as an overlay of the chat root, so it does
   not depend on the thread having already received a measurable height.
   ========================================================================== */
.tm-app--chat #xtrMobileChatRoot.xtr-mchat {
  position: relative;
}
.tm-app--chat #xtrMobileChatRoot > .xtr-mchat-root-skeleton {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 18px;
  background: linear-gradient(180deg,#f8f9fa 0%,#f2f4f6 100%);
  pointer-events: none;
  box-sizing: border-box;
}
.tm-app--chat #xtrMobileChatRoot > .xtr-mchat-root-skeleton[hidden] {
  display: none !important;
}
.tm-app--chat .xtr-mchat-root-skel-head {
  flex: 0 0 58px;
  min-height: 58px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-bottom: 1px solid #e7e9ec;
  background: rgba(255,255,255,.95);
  box-sizing: border-box;
}
.tm-app--chat .xtr-mchat-root-skel-head > i {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 13px;
}
.tm-app--chat .xtr-mchat-root-skel-head > span {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.tm-app--chat .xtr-mchat-root-skel-head b { width: min(52vw,220px); height: 15px; border-radius: 999px; }
.tm-app--chat .xtr-mchat-root-skel-head em { width: min(28vw,120px); height: 10px; border-radius: 999px; }
.tm-app--chat .xtr-mchat-root-skel-head > i,
.tm-app--chat .xtr-mchat-root-skel-head b,
.tm-app--chat .xtr-mchat-root-skel-head em,
.tm-app--chat .xtr-mchat-root-skeleton .xtr-mchat-skel-bubble,
.tm-app--chat .xtr-mchat-root-skeleton .xtr-mchat-skel-media,
.tm-app--chat .xtr-mchat-root-skeleton .xtr-mchat-skel-time {
  display: block;
  background: linear-gradient(100deg,#e2e5e8 18%,#f8f9fa 38%,#e2e5e8 58%);
  background-size: 220% 100%;
  animation: xtrMchatSkeletonShimmer 1.1s linear infinite;
}
.tm-app--chat .xtr-mchat-root-skel-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 18px 14px 20px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 15px;
  box-sizing: border-box;
}
@media (max-width:430px) {
  .tm-app--chat #xtrMobileChatRoot > .xtr-mchat-root-skeleton { border-radius: 16px; }
  .tm-app--chat .xtr-mchat-root-skel-head { min-height:54px; flex-basis:54px; padding:6px 8px; }
  .tm-app--chat .xtr-mchat-root-skel-body { padding:14px 10px 16px; gap:12px; }
}
@media (prefers-reduced-motion: reduce) {
  .tm-app--chat .xtr-mchat-root-skel-head > i,
  .tm-app--chat .xtr-mchat-root-skel-head b,
  .tm-app--chat .xtr-mchat-root-skel-head em,
  .tm-app--chat .xtr-mchat-root-skeleton .xtr-mchat-skel-bubble,
  .tm-app--chat .xtr-mchat-root-skeleton .xtr-mchat-skel-media,
  .tm-app--chat .xtr-mchat-root-skeleton .xtr-mchat-skel-time { animation:none !important; }
}

/* ========================================================================== 
   1.9.7.18 — perceptible skeleton + stable media geometry
   Keep chat opening visually calm even with many historical images/files.
   ========================================================================== */
.tm-app--chat #xtrMobileChatRoot > .xtr-mchat-root-skeleton {
  opacity: 1;
  visibility: visible;
  contain: layout paint;
  will-change: opacity;
}

/* Reserve media geometry before the image bytes arrive. This prevents old
   attachments from changing scrollHeight while the conversation is opening. */
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-image {
  position: relative;
  width: min(72vw, 280px);
  aspect-ratio: 4 / 3;
  max-width: 100%;
  max-height: none;
  display: block;
  overflow: hidden;
  background: #e8ebee;
  contain: layout paint;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-image img {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: contain;
  opacity: 1;
  transition: opacity .16s ease;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-image.is-loading::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(100deg,#e1e4e7 18%,#f8f9fa 38%,#e1e4e7 58%);
  background-size: 220% 100%;
  animation: xtrMchatSkeletonShimmer 1.05s linear infinite;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-image.is-loading img {
  opacity: 0;
}

@media (max-width:430px) {
  .tm-app--chat #xtrMobileChatRoot .xtr-mchat-image {
    width: min(76vw, 260px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tm-app--chat #xtrMobileChatRoot .xtr-mchat-image.is-loading::before {
    animation: none !important;
  }
}

/* 1.9.7.31 — media pipeline + conversation windowing */
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-history-more {
  display:block;
  margin:10px auto 14px;
  padding:9px 14px;
  border:1px solid rgba(122,128,136,.22);
  border-radius:999px;
  background:rgba(255,255,255,.92);
  color:#5f6670;
  font:600 12px/1.2 inherit;
  cursor:pointer;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-history-more:disabled { opacity:.55; cursor:default; }
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-image { position:relative; background:#eef0f2; }
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-image .xtr-mchat-image-fallback {
  position:absolute; inset:0; display:none; place-items:center; align-content:center; gap:4px;
  padding:18px; text-align:center; color:#666d76; background:#f1f3f5; z-index:2;
}
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-image .xtr-mchat-image-fallback b { font-size:13px; }
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-image .xtr-mchat-image-fallback small { font-size:11px; opacity:.8; }
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-image.is-error .xtr-mchat-image-fallback { display:grid; }
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-image.is-error img { opacity:0; }
.tm-app--chat #xtrMobileChatRoot .xtr-mchat-image.is-loaded img { opacity:1; }
