/* Hamrah Group 7 — critical messaging UI repair */
:root {
  --device-accent: #168fd0;
  --device-gradient: linear-gradient(135deg,#137fd2,#18b8ad);
  --g7-safe-bottom: max(12px, env(safe-area-inset-bottom));
}

body.chat-open #newChatFab,
.group7-selecting #newChatFab {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

#newChatFab[aria-hidden="true"] { display: none !important; }
#newChatFab {
  background: var(--device-gradient) !important;
  bottom: calc(92px + var(--g7-safe-bottom)) !important;
}

.bottom-nav button.active,
.bottom-nav button.active small,
.setting-row input:checked + .switch,
.send-btn,
.primary,
.g7-selection-toolbar button,
.group7-selection-toolbar button {
  --primary: var(--device-accent);
}

.bottom-nav button.active .nav-icon,
.send-btn,
.primary,
.g7-action-icon {
  background: var(--device-gradient) !important;
}

.g7-message {
  position: relative;
  margin-block: 4px 12px;
  transform: translateX(var(--g7-swipe, 0px));
  transition: transform 160ms cubic-bezier(.2,.8,.2,1), margin 160ms ease;
  touch-action: pan-y;
}
.g7-message.grouped { margin-block-start: 1px; margin-block-end: 8px; }
.g7-message:not(.grouped) + .g7-message { margin-block-start: 5px; }


.g7-message.g7-swipe-ready { transition-duration: 80ms; }
.g7-swipe-reply-icon {
  position: absolute;
  inset-inline-start: -42px;
  top: 50%;
  width: 34px;
  height: 34px;
  transform: translateY(-50%) scale(.75);
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--device-accent);
  opacity: clamp(0, calc(var(--g7-swipe, 0px) / 68px), 1);
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  pointer-events: none;
}
.g7-message.g7-swipe-ready .g7-swipe-reply-icon { transform: translateY(-50%) scale(1); }

/* Group 7 keeps reactions and reply previews outside the bubble flow, so the
 * legacy outgoing-message shine must be disabled instead of relying on clipping. */
.g7-message.message-new-out > .g7-bubble::after,
.g7-message.message-new-out > .bubble::after {
  content: none !important;
  display: none !important;
  animation: none !important;
}

.g7-bubble {
  display: flex !important;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  min-width: 92px;
  max-width: min(80vw, 520px) !important;
  height: auto !important;
  min-height: 0 !important;
  padding: 11px 13px 7px !important;
  overflow: visible !important;
}

.g7-bubble .message-text {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.72;
}

.g7-forward-label {
  align-self: flex-start;
  font-size: .74rem;
  font-weight: 800;
  color: color-mix(in srgb, var(--device-accent) 74%, white);
}

.g7-reply-preview {
  appearance: none;
  width: 100%;
  border: 0;
  border-inline-start: 3px solid var(--device-accent);
  border-radius: 9px;
  background: rgba(255,255,255,.055);
  color: inherit;
  padding: 7px 9px;
  text-align: start;
  display: grid;
  gap: 2px;
  cursor: pointer;
}
.g7-reply-preview b { color: color-mix(in srgb, var(--device-accent) 72%, white); font-size: .78rem; }
.g7-reply-preview span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .78rem; opacity: .82; }
.g7-reply-preview.unavailable { opacity: .65; cursor: default; }

.g7-message-meta {
  min-height: 19px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  flex-wrap: nowrap;
  direction: rtl;
  font-size: .66rem;
  line-height: 1;
  opacity: .76;
  margin-top: 1px;
  padding-inline-start: 6px;
}
.g7-message-meta time,
.g7-message-meta .g7-edited { white-space: nowrap; }
.g7-message-meta .g7-edited { font-size: .62rem; }

.g7-receipt {
  min-width: 22px;
  height: 19px;
  padding: 0 2px;
  border: 0;
  display: inline-grid;
  place-items: center;
  background: transparent;
  color: var(--status-delivered, #83a8bd);
  font-size: .76rem;
  font-weight: 900;
  letter-spacing: -4px;
  line-height: 1;
  cursor: pointer;
  transform-origin: center;
  animation: g104ReceiptResolve .22s cubic-bezier(.2,.9,.2,1) both;
}
.g7-receipt.g7-read { color: var(--status-read, #29aef4); }
.g7-receipt.g7-sent { letter-spacing: -1px; }
.g7-receipt.g7-pending { color: var(--status-pending, #a7b0bd); letter-spacing: 0; animation: none; }
.g7-pending-clock {
  position: relative;
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 1.6px solid currentColor;
  border-radius: 50%;
  opacity: .92;
  animation: g104PendingBreathe 1.35s ease-in-out infinite;
}
.g7-pending-clock::before,
.g7-pending-clock::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1.5px;
  border-radius: 2px;
  background: currentColor;
  transform-origin: 50% 100%;
}
.g7-pending-clock::before { height: 3.8px; transform: translate(-50%,-100%) rotate(0deg); }
.g7-pending-clock::after { height: 3px; transform: translate(-50%,-100%) rotate(118deg); }

.g7-receipt.g7-failed {
  letter-spacing: 0;
  color: #ff6b75;
  border: 1px solid currentColor;
  border-radius: 50%;
  width: 18px;
  min-width: 18px;
  height: 18px;
}

.message-actions-trigger {
  top: 8px !important;
  inset-inline-end: 8px !important;
  width: 28px !important;
  height: 28px !important;
  font-size: 14px;
  opacity: .45;
}

.g7-reactions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 2px;
}
.g7-reaction-chip {
  min-height: 28px;
  padding: 3px 8px;
  border: 1px solid rgba(130,170,200,.22);
  border-radius: 999px;
  background: rgba(7,22,42,.46);
  color: #eaf7ff;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .82rem;
}
.g7-reaction-chip.mine {
  border-color: color-mix(in srgb, var(--device-accent) 70%, white);
  background: color-mix(in srgb, var(--device-accent) 22%, transparent);
}
.g7-reaction-chip span { font-size: .68rem; }

.g7-jump-highlight .bubble {
  animation: g7Jump 1.2s ease;
}
@keyframes g7Jump {
  0%,100% { box-shadow: inherit; }
  35% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--device-accent) 55%, transparent), 0 0 30px color-mix(in srgb, var(--device-accent) 45%, transparent); }
}

.group7-selection-toolbar {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 40;
  min-height: 76px;
  padding: max(12px, env(safe-area-inset-top)) 14px 10px;
  display: grid;
  grid-template-columns: 42px auto 1fr auto auto auto;
  align-items: center;
  gap: 8px;
  color: #fff;
  background: rgba(9,25,46,.97);
  border-bottom: 1px solid rgba(128,179,214,.18);
  backdrop-filter: blur(20px);
}
.group7-selection-toolbar.hidden { display: none !important; }
.group7-selection-toolbar button {
  border: 0;
  min-height: 38px;
  padding: 7px 10px;
  border-radius: 12px;
  background: rgba(255,255,255,.08);
  color: #eef8ff;
}
.group7-selecting .chat-header { visibility: hidden; }
.g7-message.selected .bubble {
  outline: 2px solid var(--device-accent);
  background: color-mix(in srgb, var(--device-accent) 22%, #13243b) !important;
}

.group7-sheet { z-index: 180 !important; }
.group7-sheet-card {
  max-height: min(86dvh, 760px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.group7-sheet-content {
  overflow: auto;
  padding: 4px 4px calc(14px + env(safe-area-inset-bottom));
}
.g7-loading,
.g7-error,
.empty.compact {
  padding: 22px 14px;
  text-align: center;
  color: #9fb0c6;
}
.g7-error { color: #ff8791; }

.g7-reaction-picker {
  display: grid;
  grid-template-columns: repeat(6, minmax(44px, 1fr));
  gap: 8px;
  padding: 10px 2px 18px;
}
.g7-reaction-picker button {
  min-height: 52px;
  border: 1px solid rgba(129,177,211,.2);
  border-radius: 16px;
  background: rgba(20,38,61,.92);
  font-size: 1.6rem;
  transition: transform 140ms ease, background 140ms ease;
}
.g7-reaction-picker button:active { transform: scale(.86); background: var(--device-accent); }

.g7-user-row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 58px;
  padding: 7px 5px;
  border-bottom: 1px solid rgba(130,170,200,.11);
}
.g7-user-row .avatar { width: 40px; height: 40px; }
.g7-user-row span { display: grid; gap: 3px; }
.g7-user-row small { color: #91a4bb; font-size: .72rem; }
.g7-user-row strong { color: #29aef4; }
.g7-receipt-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-radius: 14px;
  background: rgba(26,54,82,.56);
  margin-bottom: 14px;
}
.group7-sheet-content h3 { margin: 14px 4px 6px; font-size: .86rem; color: #afc4d7; }

.g7-action-icon { display: grid !important; place-items: center; color: #fff; font-size: 1.1rem; }
.g7-secondary-action {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(126,180,216,.25);
  border-radius: 14px;
  background: rgba(18,41,67,.72);
  color: #dceeff;
  padding: 10px 14px;
}

.g7-search-input {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 7px;
  min-height: 50px;
  border: 1px solid rgba(125,176,210,.2);
  background: rgba(13,31,53,.86);
  border-radius: 17px;
  padding: 0 12px;
  margin: 2px 0 10px;
}
.g7-search-input input {
  width: 100%;
  border: 0;
  background: transparent;
  color: #eef7ff;
  outline: 0;
  font: inherit;
}
.g7-search-filters,
.g7-tabs {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 0 10px;
}
.g7-search-filters button,
.g7-tabs button {
  white-space: nowrap;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid rgba(125,176,210,.18);
  border-radius: 999px;
  background: rgba(17,36,59,.76);
  color: #9eb2c7;
}
.g7-search-filters button.active,
.g7-tabs button.active { color: #fff; background: var(--device-accent); border-color: var(--device-accent); }

.g7-search-result,
.g7-room-row,
.g7-file-card {
  width: 100%;
  display: grid;
  grid-template-columns: 46px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 4px;
  border: 0;
  border-bottom: 1px solid rgba(123,169,202,.11);
  background: transparent;
  color: #eaf5ff;
  text-align: start;
}
.g7-search-result > span:nth-child(2),
.g7-room-row > span:nth-child(2),
.g7-file-card > span:nth-child(2) { min-width: 0; display: grid; gap: 3px; }
.g7-search-result small,
.g7-room-row small,
.g7-file-card small { color: #8fa5ba; font-size: .7rem; }
.g7-search-result em { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-style: normal; color: #c3d2df; }

.g7-shared-results.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}
.g7-media-card {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  padding: 0;
  background: #13253a;
}
.g7-media-card img { width: 100%; height: 100%; object-fit: cover; }
.g7-media-card small { position: absolute; bottom: 4px; inset-inline-end: 4px; padding: 2px 5px; border-radius: 6px; color: #fff; background: rgba(0,0,0,.55); }

/* Voice messages: compact, truthful and fully contained */
.g7-voice-host,
.voice-player.voice-core-host,
.voice-player[data-audio-player] {
  /* Reset the legacy .voice-player grid. The Group 7 player is a single
   * self-contained component, not a grid item inside the old three-column UI. */
  display: block !important;
  grid-template-columns: none !important;
  align-items: initial !important;
  gap: 0 !important;
  box-sizing: border-box !important;
  position: relative !important;
  width: min(292px, 70vw) !important;
  min-width: 232px !important;
  max-width: 100% !important;
  min-height: 0 !important;
  height: auto !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: visible !important;
  background: transparent !important;
}
.voice-core-ui {
  box-sizing: border-box !important;
  width: 100% !important;
  min-width: 0 !important;
  min-height: 60px !important;
  height: auto !important;
  display: grid !important;
  grid-template-columns: 44px minmax(0,1fr) 36px !important;
  align-items: center !important;
  gap: 8px !important;
  padding: 5px 0 4px !important;
  overflow: visible !important;
}
.voice-core-play {
  position: static !important;
  width: 44px !important;
  height: 44px !important;
  min-width: 44px !important;
  border-radius: 50% !important;
  transform: none !important;
  overflow: hidden;
}
.voice-core-main { min-width: 0 !important; }
.voice-core-wave {
  position: relative;
  width: 100% !important;
  height: 28px !important;
  min-height: 28px !important;
  overflow: hidden;
}
.voice-core-meta {
  min-height: 17px;
  display: flex !important;
  justify-content: space-between;
  gap: 8px;
  font-size: .67rem !important;
}
.voice-core-rate {
  position: static !important;
  width: 38px !important;
  min-width: 38px !important;
  height: 32px !important;
  border-radius: 10px !important;
}
.voice-core-audio { display: none !important; }
.g7-bubble:has(.g7-voice-host) { min-width: 0 !important; width: fit-content; max-width: min(84vw, 340px) !important; }

@media (max-width: 420px) {
  .g7-bubble { max-width: 84vw !important; }
  .g7-voice-host, .voice-player.voice-core-host, .voice-player[data-audio-player] { width: min(270px, 74vw) !important; min-width: 214px !important; }
  .group7-selection-toolbar { grid-template-columns: 36px auto 1fr auto auto; }
  .group7-selection-toolbar [data-g7-selection="copy"] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .g7-message,
  .g7-reaction-picker button,
  .g7-jump-highlight .bubble { transition: none !important; animation: none !important; }
}

.g7-pin-order {
  position: absolute;
  inset-inline-start: 8px;
  bottom: 5px;
  display: inline-flex;
  gap: 3px;
  opacity: .55;
}
.room-shell { position: relative; }
.g7-pin-order button {
  width: 25px;
  height: 25px;
  border: 1px solid rgba(125,176,210,.16);
  border-radius: 8px;
  background: rgba(12,29,50,.75);
  color: #b8c9d8;
  padding: 0;
}
.g7-pin-order button:active { background: var(--device-accent); color: #fff; }

/* Advanced search filters and honest pagination */
.g7-search-advanced {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0 12px;
}
.g7-search-advanced label {
  display: grid;
  gap: 5px;
  font-size: .78rem;
  color: var(--muted);
}
.g7-search-advanced select,
.g7-search-advanced input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2, rgba(255,255,255,.045));
  color: inherit;
  padding: 8px 10px;
  font: inherit;
}
.g7-load-more {
  width: 100%;
  margin-top: 10px;
}
@media (max-width: 540px) {
  .g7-search-advanced { grid-template-columns: 1fr 1fr; }
  .g7-search-advanced label:first-child { grid-column: 1 / -1; }
}

/* Group 7.2 restores the original compact gradient palette as the sole device-theme owner. */
#themeChoices.theme-choices { display:grid !important; }
#legacyThemeChoices { display:none !important; }
.profile-form.profile-saving { opacity:.78; pointer-events:none; }
.profile-form.profile-save-error { animation: g72ProfileError .28s ease; }
@keyframes g72ProfileError { 35% { transform:translateX(5px); } 70% { transform:translateX(-5px); } }

/* Group 10.4 UI polish: coherent active control states and truthful receipt motion. */
.segmented button.active,
.g7-tabs button.active,
.g7-search-filters button.active,
.filter-chip.active,
.icon-btn.active,
button[aria-pressed="true"]:not(.g7-receipt) {
  border-color: var(--interactive-active-border, var(--device-accent));
  background: var(--interactive-active-soft, color-mix(in srgb,var(--device-accent) 18%,var(--surface))) !important;
  color: var(--interactive-active-strong, var(--device-accent)) !important;
  box-shadow: var(--interactive-active-glow, 0 8px 24px color-mix(in srgb,var(--device-accent) 24%,transparent));
}
@keyframes g104ReceiptResolve { from { opacity: .2; transform: translateY(1px) scale(.68); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes g104PendingBreathe { 0%,100% { opacity: .62; transform: scale(.94); } 50% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) {
  .g7-receipt, .g7-pending-clock { animation: none !important; }
}

/* UX2 — Message Surface Simplification R1 */
.g7-message{margin-block:2px 8px}
.g7-message.grouped{margin-block-start:1px;margin-block-end:4px}
.g7-bubble{
  gap:4px;
  min-width:76px;
  max-width:min(76vw,500px)!important;
  padding:8px 10px 6px!important;
  border-radius:16px 16px 16px 5px!important;
  border-color:color-mix(in srgb,var(--line) 58%,transparent)!important;
  box-shadow:none!important;
}
.g7-message.mine .g7-bubble,.message.mine .g7-bubble{
  border-radius:16px 16px 5px 16px!important;
}
.g7-bubble .message-text{line-height:1.64;font-size:.8rem}
.g7-message-meta{min-height:16px;gap:4px;font-size:.61rem;opacity:.7;margin-top:0;padding-inline-start:3px}
.g7-message-meta .g7-edited{font-size:.57rem}
.message-actions-trigger{top:5px!important;inset-inline-end:5px!important;width:26px!important;height:26px!important;border-radius:8px!important}
.g7-reply-preview{border-radius:8px;padding:5px 7px;background:color-mix(in srgb,var(--primary) 6%,transparent)}
.g7-reply-preview b,.g7-reply-preview span{font-size:.72rem}
.g7-reactions{gap:4px;margin-top:1px}
.g7-reaction-chip{min-height:26px;padding:2px 7px;border-color:color-mix(in srgb,var(--line) 80%,transparent);background:color-mix(in srgb,var(--surface-2) 72%,transparent)}
.g7-forward-label{font-size:.68rem}
.g7-swipe-reply-icon{width:34px;height:34px;box-shadow:none;background:var(--primary);border-color:transparent}

/* System call messages stay informative but stop looking like mini dashboards. */
.g9-system-call-bubble{
  min-width:0!important;
  max-width:min(76vw,360px)!important;
  gap:8px!important;
}
.g9-system-call-bubble::before{width:32px!important;height:32px!important;border-radius:10px!important;font-size:16px!important}

@media(max-width:420px){
  .g7-bubble{max-width:82vw!important}
  .g7-message-meta{font-size:.59rem}
}


/* E4 UI Consistency — date separators stay in normal flow; no compositor pile-up */
#chatScreen .messages > .date-chip{
  position:relative!important;
  inset:auto!important;
  z-index:2!important;
  flex:0 0 auto!important;
  transform:none!important;
  translate:none!important;
  animation:none!important;
  isolation:isolate;
  clear:both;
}
#chatScreen .messages > .date-chip + .date-chip{margin-block-start:0!important}

/* ==========================================================================
 * E5 Chat Scroll Performance Hotfix2
 * Keep the idle chat tree cheap: no transform stacking-context on every
 * message, isolate layout, and only promote the one message being swiped.
 * ========================================================================== */
#chatScreen #messageList.messages{
  contain:layout paint style;
  scroll-behavior:auto!important;
  overscroll-behavior:contain;
}

#chatScreen #messageList.messages>.g7-message{
  transform:none!important;
  transition:none!important;
  contain:layout style;
}

#chatScreen #messageList.messages>.g7-message.g7-swipe-active{
  transform:translate3d(var(--g7-swipe,0px),0,0)!important;
  transition:transform 120ms cubic-bezier(.2,.8,.2,1)!important;
  will-change:transform;
}
#chatScreen #messageList.messages>.g7-message.g7-swipe-active.g7-swipe-ready{
  transition-duration:80ms!important;
}

#chatScreen #messageList.messages>.g7-message>.g7-swipe-reply-icon{
  opacity:0!important;
}
#chatScreen #messageList.messages>.g7-message.g7-swipe-active>.g7-swipe-reply-icon{
  opacity:clamp(0,calc(var(--g7-swipe,0px)/68px),1)!important;
}

/* The E4 wallpaper layer is already outside the scrolling DOM. Built-in
   procedural wallpapers do not benefit from a full-viewport blur/overscan.
   Keep user-photo blur intact. */
body[data-g114-wallpaper="plain"] #chatScreen .g114-chat-wallpaper::before,
body[data-g114-wallpaper="dots"] #chatScreen .g114-chat-wallpaper::before,
body[data-g114-wallpaper="aurora"] #chatScreen .g114-chat-wallpaper::before,
body[data-g114-wallpaper="flow"] #chatScreen .g114-chat-wallpaper::before,
body[data-g114-wallpaper="grid"] #chatScreen .g114-chat-wallpaper::before{
  inset:0!important;
  filter:none!important;
  transform:none!important;
}
#chatScreen .g114-chat-wallpaper{
  contain:strict!important;
}

/* Desktop scroll paint: the late Windows layer used to re-add a shadow to
   every text bubble. Two IDs make this intentional performance override win
   without touching the frozen Desktop architecture. */
html[data-hamrah-desktop="windows"] body #chatScreen #messageList.messages>
.g7-message:not(.g119b-r82-album-item)>.g7-bubble{
  box-shadow:none!important;
}

/* While the scroll compositor is active, suppress hover-action churn under
   the stationary desktop pointer and remove non-essential paint effects.
   Everything restores shortly after scrolling stops. */
html[data-hamrah-desktop="windows"].g117a-frame-active #chatScreen #messageList .message-actions-trigger{
  opacity:0!important;
  transition:none!important;
  pointer-events:none!important;
}
html.g117a-frame-active #chatScreen #messageList .g7-bubble,
html.g117a-frame-active #chatScreen #messageList .g7-reaction-chip,
html.g117a-frame-active #chatScreen #messageList .attachment-file{
  box-shadow:none!important;
  transition:none!important;
}

/* ==========================================================================
 * E5 Viewport Virtualization + Lazy Voice Hotfix3
 * ========================================================================== */
@supports (content-visibility:auto){
  #chatScreen #messageList.messages>.g7-message{
    content-visibility:auto;
    contain-intrinsic-size:auto var(--g7-virtual-size,84px);
  }

  #chatScreen #messageList.messages>.g7-message.search-hit,
  #chatScreen #messageList.messages>.g7-message.selected,
  #chatScreen #messageList.messages>.g7-message.g7-swipe-active,
  #chatScreen #messageList.messages>.g7-message.message-pin-focus{
    content-visibility:visible;
  }

  /* Hotfix5: Windows now mounts only a bounded multi-screen DOM window.
     Mounted rows stay fully visible; Android keeps browser-native skipping. */
  html[data-hamrah-desktop="windows"] #chatScreen #messageList.messages[data-g7-windowed="1"]>.g7-message{
    content-visibility:visible;
    contain-intrinsic-size:none;
  }
}

/* Telegram-style bounded desktop message window. Spacer blocks preserve the
   scroll range while only the multi-screen working set exists in the DOM. */
#chatScreen #messageList.messages>.g7-virtual-spacer{
  display:block!important;
  flex:0 0 auto!important;
  inline-size:1px!important;
  min-block-size:0!important;
  margin:0!important;
  padding:0!important;
  border:0!important;
  pointer-events:none!important;
  contain:strict!important;
}
html[data-hamrah-desktop="windows"] #chatScreen #messageList.messages[data-g7-windowed="1"]{
  overflow-anchor:none;
}

#chatScreen .g7-voice-host[data-voice-viewport-queued="1"]:not([data-voice-core-mounted]){
  min-block-size:46px;
}
/* R5_SHARED_CHAT_HEADER_PIN_ARROW_CLEANUP_HF1
   Defensive shared cleanup: the legacy pinned-room reorder controls are not
   part of the conversation-list presentation on Windows or Android.
*/
#roomList .g7-pin-order,
#roomList [data-g7-pin-up],
#roomList [data-g7-pin-down] {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* R9_CHAT_STABLE_FIRST_COMPOSITE_HF17
 * The message model is already bounded by Group 7's virtual window. Running
 * browser content-visibility virtualization on that same 50-60 row window
 * makes Android replace intrinsic row sizes after reveal. Keep mounted rows
 * measurable from the prelayout pass on every deterministic native shell. */
@supports (content-visibility:auto){
  #chatScreen #messageList.messages[data-g7-windowed="1"]>.g7-message{
    content-visibility:visible;
    contain-intrinsic-size:none;
  }
}

/* Group 11.7A classifies buttons during idle time. Author names are inline
 * bubble metadata, not standalone controls; a delayed 44px touch minimum here
 * changed every group-message height after the viewport anchor was measured. */
#chatScreen #messageList .g7-message>.g7-bubble>.author[data-g117a-control]{
  min-block-size:0!important;
  padding-inline:0!important;
  border-radius:0!important;
}

/* R9_CHAT_CONTINUOUS_SURFACE_HF21
 * A room switch keeps the already-painted message viewport above the target
 * renderer until its saved anchor is committed. This is a non-interactive,
 * bounded clone of the existing virtual window, not another message owner. */
#chatScreen > [data-r9-chat-transition-freeze="true"]{
  position:absolute!important;
  inset:0!important;
  z-index:40!important;
  margin:0!important;
  visibility:visible!important;
  opacity:1!important;
  transform:none!important;
  pointer-events:none!important;
  contain:layout style paint!important;
  animation:none!important;
  transition:none!important;
}
#chatScreen > [data-r9-chat-transition-freeze="true"] > [data-r9-chat-transition-part="true"]{
  position:absolute!important;
  inset-inline:auto!important;
  inset-block:auto!important;
  flex:none!important;
  margin:0!important;
  visibility:visible!important;
  opacity:1!important;
  transform:none!important;
}
#chatScreen > [data-r9-chat-transition-freeze="true"] .messages{
  overflow:hidden!important;
  scrollbar-width:none!important;
}
#chatScreen > [data-r9-chat-transition-freeze="true"] .messages::-webkit-scrollbar{
  display:none!important;
}
#chatScreen > [data-r9-chat-transition-freeze="true"] *,
#chatScreen > [data-r9-chat-transition-freeze="true"] *::before,
#chatScreen > [data-r9-chat-transition-freeze="true"] *::after{
  animation:none!important;
  transition:none!important;
  pointer-events:none!important;
}

/* R9_ANDROID_TELEGRAM_ENTRY_HF24
 * Android owns one compositor-only chat-surface transition in Group 7. The
 * legacy 400ms page animation and delayed per-header-child entrances made the
 * WebView restart several animations while it was binding a cached timeline. */
html[data-hamrah-profile-platform="android"] .chat-screen.opening {
  animation: none !important;
}
html[data-hamrah-profile-platform="android"] .chat-screen.opening .chat-header > *,
html[data-hamrah-profile-platform="android"] #chatScreen[data-r9-android-entry-motion="true"] .chat-header > * {
  animation: none !important;
  transition: none !important;
}
html[data-hamrah-profile-platform="android"] #chatScreen[data-r9-android-entry-motion="true"] {
  backface-visibility: hidden;
  isolation: isolate;
}

/* R9_ANDROID_ENTRY_REENTRANCY_HF26
 * HF5's CSS keyframe and Group7's WAAPI both wrote transform on the same
 * Android surface. Keep WAAPI as the sole entry/exit owner. A logically hidden
 * chat remains painted only for the 148ms native Back exit, so Android can
 * verify it closed synchronously while the user sees a composited transition. */
html[data-hamrah-profile-platform="android"] #chatScreen.r9-hf5-entry-ready {
  animation: none !important;
}
html[data-hamrah-profile-platform="android"] #chatScreen.hidden[data-r9-android-exit-motion="true"] {
  display: flex !important;
  pointer-events: none !important;
  backface-visibility: hidden;
  isolation: isolate;
  contain: layout style paint;
}
html[data-hamrah-profile-platform="android"] #chatScreen.hidden[data-r9-android-exit-motion="true"] > .composer {
  display: grid !important;
}
/* HF30: Android navigation uses a physical forward axis even when message
 * content is RTL. The incoming/outgoing chat therefore owns the physical
 * left seam while the existing source surface parallaxes underneath it. */
html[data-hamrah-profile-platform="android"] #chatScreen:is([data-r9-android-entry-motion="true"],[data-r9-android-exit-motion="true"])::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inline-size: 14px;
  z-index: 90;
  pointer-events: none;
  inset-inline-start: auto;
  left: 0;
  right: auto;
  background: linear-gradient(90deg,rgba(0,0,0,.22),transparent);
}
html[data-hamrah-profile-platform="android"][data-r9-android-source-parallax] #app > :not(#chatScreen) {
  backface-visibility: hidden;
}
/* R9_ANDROID_TELEGRAM_SHARED_AXIS_HF28
 * Keep the single destination surface laid out and compositor-ready just
 * outside the viewport while the room list owns the screen. This preserves
 * the previous chat DOM after Back and avoids allocating a full-screen layer
 * on the first animation frame of the next entry. Logical visibility remains
 * owned by the existing .hidden class in JavaScript. */
@media (max-width: 767px) {
  html[data-hamrah-profile-platform="android"] #app:not(.hidden) > #chatScreen {
    backface-visibility: hidden;
    contain: layout style paint;
  }
  html[data-hamrah-profile-platform="android"] #app:not(.hidden) > #chatScreen.hidden:not([data-r9-android-exit-motion="true"]) {
    display: flex !important;
    pointer-events: none !important;
    transform: translate3d(101%,0,0) !important;
    will-change: transform;
  }
}
html[data-hamrah-profile-platform="android"][data-r9-android-room-open-guard="true"] #roomList .room-open {
  pointer-events: none !important;
}

/* R9_ANDROID_INSTANT_ENTRY_HF35
 * A hidden conversation no longer remains mounted as a permanent off-screen
 * full-viewport layer. The tap path lays it out once, invisibly, then Group 7
 * owns the only compositor transform. This lowers WebView layer memory and
 * prevents legacy opening/closing keyframes from competing with WAAPI. */
html[data-hamrah-profile-platform="android"][data-r9-android-entry-hf35="true"] #app:not(.hidden) > #chatScreen.hidden:not([data-r9-android-exit-motion="true"]) {
  display: none !important;
  transform: none !important;
  will-change: auto !important;
}
html[data-hamrah-profile-platform="android"][data-r9-android-entry-hf35="true"] #chatScreen:is(.opening,.closing,.r9-hf5-entry-ready) {
  animation: none !important;
}
html[data-hamrah-profile-platform="android"][data-r9-android-entry-hf35="true"] #chatScreen:is([data-r9-entry-prelayout="true"],[data-r9-android-entry-motion="true"],[data-r9-android-exit-motion="true"]) {
  backface-visibility: hidden;
  contain: layout style paint;
}

/* R9_ANDROID_VIDEO_TELEGRAM_ENTRY_HF25
 * The physical recording exposed a black frame between chat layout and the
 * first pseudo-wallpaper raster. While Android prelays out or composites the
 * destination surface, paint an equivalent fallback directly on the stable
 * viewport and keep the canonical wallpaper on its own promoted layer. */
html[data-hamrah-profile-platform="android"] #chatScreen[data-r9-entry-prelayout="true"] .g114-message-viewport,
html[data-hamrah-profile-platform="android"] #chatScreen[data-r9-android-entry-motion="true"] .g114-message-viewport {
  background-color: color-mix(in srgb,var(--bg) 96%,var(--primary) 4%) !important;
  background-position: center !important;
  background-repeat: no-repeat !important;
}
html[data-hamrah-profile-platform="android"] #chatScreen[data-r9-entry-prelayout="true"] .g114-chat-wallpaper,
html[data-hamrah-profile-platform="android"] #chatScreen[data-r9-android-entry-motion="true"] .g114-chat-wallpaper {
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}
html[data-hamrah-profile-platform="android"] body[data-g114-wallpaper="plain"] #chatScreen:is([data-r9-entry-prelayout="true"],[data-r9-android-entry-motion="true"]) .g114-message-viewport {
  background-image: radial-gradient(circle at 18% 16%,color-mix(in srgb,var(--primary) 8%,transparent) 0 1px,transparent 1.35px),radial-gradient(circle at 76% 72%,color-mix(in srgb,var(--primary-2) 6%,transparent) 0 1px,transparent 1.3px) !important;
  background-size: 46px 46px,56px 56px !important;
  background-position: 0 0,19px 17px !important;
  background-repeat: repeat !important;
}
html[data-hamrah-profile-platform="android"] body[data-g114-wallpaper="dots"] #chatScreen:is([data-r9-entry-prelayout="true"],[data-r9-android-entry-motion="true"]) .g114-message-viewport {
  background-image: radial-gradient(circle at 2px 2px,color-mix(in srgb,var(--primary) 14%,transparent) 1px,transparent 1.5px) !important;
  background-size: 20px 20px !important;
  background-repeat: repeat !important;
}
html[data-hamrah-profile-platform="android"] body[data-g114-wallpaper="aurora"] #chatScreen:is([data-r9-entry-prelayout="true"],[data-r9-android-entry-motion="true"]) .g114-message-viewport {
  background-image: radial-gradient(circle at 10% 20%,color-mix(in srgb,var(--primary) 28%,transparent),transparent 38%),radial-gradient(circle at 90% 80%,color-mix(in srgb,var(--primary-2) 24%,transparent),transparent 42%) !important;
  background-size: cover !important;
}
html[data-hamrah-profile-platform="android"] body[data-g114-wallpaper="flow"] #chatScreen:is([data-r9-entry-prelayout="true"],[data-r9-android-entry-motion="true"]) .g114-message-viewport {
  background-image: linear-gradient(135deg,color-mix(in srgb,var(--primary) 16%,transparent),transparent 45%),linear-gradient(315deg,color-mix(in srgb,var(--primary-2) 18%,transparent),transparent 52%) !important;
  background-size: cover !important;
}
html[data-hamrah-profile-platform="android"] body[data-g114-wallpaper="grid"] #chatScreen:is([data-r9-entry-prelayout="true"],[data-r9-android-entry-motion="true"]) .g114-message-viewport {
  background-image: linear-gradient(color-mix(in srgb,var(--primary) 10%,transparent) 1px,transparent 1px),linear-gradient(90deg,color-mix(in srgb,var(--primary-2) 10%,transparent) 1px,transparent 1px) !important;
  background-size: 26px 26px !important;
  background-repeat: repeat !important;
}
html[data-hamrah-profile-platform="android"] body[data-g114-wallpaper="personal"] #chatScreen:is([data-r9-entry-prelayout="true"],[data-r9-android-entry-motion="true"]) .g114-message-viewport {
  background-image: var(--g114-personal-wallpaper) !important;
  background-size: cover !important;
}

@media (prefers-reduced-motion: reduce) {
  html[data-hamrah-profile-platform="android"] #chatScreen[data-r9-android-entry-motion="true"] {
    transform: none !important;
  }
  html[data-hamrah-profile-platform="android"] #chatScreen::before {
    display: none !important;
  }
}
