/* =========================================================
   CHAT UI — Consolidated Stylesheet
   Notes:
   - Theme differences live in body theme variables below
   - Layout / components organized top-to-bottom
   - Mobile “stability patches” consolidated at end of mobile section
   ========================================================= */

/* =========================================================
   THEME TOKENS (light / dark)
   ========================================================= */

body:not(.theme-dark){
  --chat-bg: #f6f8fb;
  --chat-ink: #0f172a;
  --chat-ink-soft: #5b6474;
  --chat-border: rgba(148, 163, 184, 0.30);
  --chat-divider: rgba(148, 163, 184, 0.22);

  --chat-card: rgba(255, 255, 255, 0.92);
  --chat-card-solid: #ffffff;

  --chat-pill: rgba(24, 178, 107, 0.10);
  --chat-accent: #18b26b;
  --chat-accent-soft: rgba(24, 178, 107, 0.12);

  --chat-shadow: 0 18px 40px rgba(15, 23, 42, 0.10);
  --chat-shadow-strong: 0 30px 60px rgba(15, 23, 42, 0.14);

  --chat-bubble: rgba(255, 255, 255, 0.96);
  --chat-bubble-border: rgba(148, 163, 184, 0.22);

  --chat-input-surface: rgba(255, 255, 255, 0.92);
  --chat-input-text: #0f172a;

  --chat-field-bg: rgba(249, 250, 251, 0.75);
  --chat-field-border: rgba(148, 163, 184, 0.38);

  --chat-thread-bg:
    radial-gradient(circle at 18% 12%, rgba(24, 178, 107, 0.05), transparent 40%),
    radial-gradient(circle at 82% 22%, rgba(56, 189, 248, 0.06), transparent 45%),
    rgba(251, 252, 254, 0.88);

  --chat-page-bg:
    radial-gradient(circle at 12% 10%, rgba(56, 189, 248, 0.07), transparent 46%),
    radial-gradient(circle at 90% 20%, rgba(34, 197, 94, 0.08), transparent 52%),
    #f6f8fb;

  --chat-chip-bg: rgba(255, 255, 255, 0.60);

  --chat-knob: rgba(255, 255, 255, 0.95);
  --chat-knob-shadow: 0 6px 14px rgba(15, 23, 42, 0.12);

  --chat-bubble-shadow: 0 10px 22px rgba(15, 23, 42, 0.06);
  --chat-compose-shadow: 0 12px 26px rgba(15, 23, 42, 0.08);

  --chat-avatar-bg: rgba(24,178,107,0.12);
  --chat-avatar-border: rgba(24,178,107,0.22);
  --chat-avatar-ink: var(--chat-ink);

  --chat-icon-btn-bg: rgba(255,255,255,0.55);

  --chat-badge-border: rgba(148, 163, 184, 0.45);
  --chat-badge-bg: rgba(148, 163, 184, 0.06);

  --chat-toggle-border: rgba(148, 163, 184, 0.55);
  --chat-toggle-bg: rgba(148, 163, 184, 0.16);
  --chat-toggle-checked-bg: rgba(24, 178, 107, 0.18);
  --chat-toggle-checked-border: rgba(24, 178, 107, 0.45);

  --chat-placeholder: rgba(91, 100, 116, 0.85);
  --chat-focus-ring: 0 0 0 4px rgba(24, 178, 107, 0.10);

  --chat-user-bg: rgba(15, 23,  42, 0.03);
  --chat-user-border: rgba(148, 163, 184, 0.22);
  --chat-user-active-bg: rgba(24, 178, 107, 0.10);
  --chat-user-active-border: rgba(24, 178, 107, 0.35);

  --chat-user-status-border: rgba(148, 163, 184, 0.30);

  --chat-e2e-bg: rgba(148,163,184,0.08);

  --chat-menu-bg: var(--chat-card-solid);
  --chat-menu-item-hover: rgba(24,178,107,0.10);

  --chat-replybar-bg: rgba(24,178,107,0.08);
  --chat-replybar-x-bg: rgba(255,255,255,0.55);
  --chat-reply-snippet-bar: rgba(24,178,107,0.55);

  --chat-alert-border: rgba(239, 68, 68, 0.35);
  --chat-alert-bg: rgba(239, 68, 68, 0.08);

  --chat-recents-bg: rgba(255,255,255,0.35);
  --chat-recent-bg: rgba(255,255,255,0.50);

  --chat-skeleton-a: rgba(148,163,184,0.10);
  --chat-skeleton-b: rgba(148,163,184,0.22);

  --chat-mobile-header-bg: var(--chat-card-solid);

  --vh: 1vh;

  /* outgoing bubbles: calm single-surface token */
  --chat-bubble-me-surface: color-mix(in srgb, var(--chat-accent) 14%, white);

  /* mobile minimum bubble widths */
  --chat-bubble-min-mobile-them: 58px;
  --chat-bubble-min-mobile-me: 75px;
}

body.theme-dark{
  --chat-bg: #070b12;
  --chat-ink: #eaf2ff;
  --chat-ink-soft: rgba(234, 242, 255, 0.70);
  --chat-border: rgba(148, 163, 184, 0.16);
  --chat-divider: rgba(148, 163, 184, 0.14);

  --chat-card: rgba(16, 22, 33, 0.80);
  --chat-card-solid: #101621;

  --chat-pill: rgba(24, 178, 107, 0.10);
  --chat-accent: #18b26b;
  --chat-accent-soft: rgba(24, 178, 107, 0.12);

  --chat-field-bg: rgba(10, 14, 22, 0.55);
  --chat-field-border: rgba(148, 163, 184, 0.18);

  --chat-bubble: rgba(18, 24, 36, 0.92);
  --chat-bubble-border: rgba(148, 163, 184, 0.14);

  --chat-input-surface: rgba(16, 22, 33, 0.92);
  --chat-input-text: #eaf2ff;

  --chat-thread-bg:
    radial-gradient(circle at 18% 12%, rgba(24, 178, 107, 0.10), transparent 44%),
    radial-gradient(circle at 82% 22%, rgba(56, 189, 248, 0.10), transparent 52%),
    rgba(16, 22, 33, 0.78);

  --chat-page-bg:
    radial-gradient(circle at 14% 12%, rgba(56, 189, 248, 0.12), transparent 50%),
    radial-gradient(circle at 88% 22%, rgba(34, 197, 94, 0.12), transparent 55%),
    #070b12;

  --chat-chip-bg: rgba(10,14,22,0.35);

  --chat-knob: rgba(234, 242, 255, 0.92);
  --chat-knob-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);

  --chat-shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
  --chat-shadow-strong: 0 30px 60px rgba(0, 0, 0, 0.42);

  --chat-bubble-shadow: 0 14px 28px rgba(0, 0, 0, 0.30);
  --chat-compose-shadow: 0 12px 26px rgba(0, 0, 0, 0.34);

  --chat-avatar-bg: rgba(24,178,107,0.16);
  --chat-avatar-border: rgba(24,178,107,0.26);
  --chat-avatar-ink: rgba(234,242,255,0.95);

  --chat-icon-btn-bg: rgba(10, 14, 22, 0.35);

  --chat-badge-border: rgba(148, 163, 184, 0.35);
  --chat-badge-bg: rgba(10, 14, 22, 0.55);

  --chat-toggle-border: rgba(148, 163, 184, 0.55);
  --chat-toggle-bg: rgba(148, 163, 184, 0.16);
  --chat-toggle-checked-bg: rgba(24, 178, 107, 0.18);
  --chat-toggle-checked-border: rgba(24, 178, 107, 0.45);

  --chat-placeholder: rgba(234, 242, 255, 0.55);
  --chat-focus-ring: 0 0 0 4px rgba(24, 178, 107, 0.14);

  --chat-user-bg: rgba(255,255,255,0.03);
  --chat-user-border: rgba(148, 163, 184, 0.12);
  --chat-user-active-bg: rgba(24, 178, 107, 0.10);
  --chat-user-active-border: rgba(24, 178, 107, 0.35);

  --chat-user-status-border: rgba(148, 163, 184, 0.25);

  --chat-e2e-bg: rgba(10,14,22,0.45);

  --chat-menu-bg: rgba(12, 16, 24, 0.96);
  --chat-menu-item-hover: rgba(24,178,107,0.10);

  --chat-replybar-bg: rgba(24,178,107,0.14);
  --chat-replybar-x-bg: rgba(10,14,22,0.35);
  --chat-reply-snippet-bar: rgba(24,178,107,0.55);

  --chat-alert-border: rgba(239, 68, 68, 0.35);
  --chat-alert-bg: rgba(239, 68, 68, 0.08);

  --chat-recents-bg: rgba(10,14,22,0.22);
  --chat-recent-bg: rgba(255,255,255,0.04);

  --chat-skeleton-a: rgba(255,255,255,0.06);
  --chat-skeleton-b: rgba(255,255,255,0.12);

  --chat-mobile-header-bg: rgba(12, 16, 24, 0.92);

  /* outgoing bubbles: calm surface in dark */
  --chat-bubble-me-surface: color-mix(in srgb, var(--chat-accent) 18%, #101621);

  /* mobile minimum bubble widths */
  --chat-bubble-min-mobile-them: 92px;
  --chat-bubble-min-mobile-me: 112px;

  color-scheme: dark;
}

/* =========================================================
   MODAL SCROLL LOCK
   ========================================================= */

body.chat-modal-open{
  overflow: hidden !important;
  position: fixed !important;
  width: 100% !important;
  left: 0;
  right: 0;
  top: 0;
}

/* CSS-only safety if backdrop exists */
html:has(.chat-modal-backdrop),
body:has(.chat-modal-backdrop){
  overflow: hidden !important;
  height: 100% !important;
  overscroll-behavior: contain;
  touch-action: auto;
}

.chat-modal-backdrop{ pointer-events: auto; }
.chat-modal-backdrop *{ pointer-events: auto; }

/* =========================================================
   VISIBILITY UTILITIES
   ========================================================= */

.chat-desktop-only{ display:block; }
@media (max-width: 980px){
  .chat-desktop-only{ display:none !important; }
}

/* Force hidden everywhere */
.chat-back{ display:none !important; }

/* =========================================================
   PAGE SHELL + LAYOUT
   ========================================================= */

.chat-shell{
  position: relative;
  padding: 1.2rem 1.2rem 3.2rem;
  background: transparent;
}
.chat-shell::before{
  content:"";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--chat-page-bg);
}

@supports (height: 100dvh){
  .chat-shell{ min-height: calc(100dvh - 180px); }
}
@supports not (height: 100dvh){
  .chat-shell{ min-height: calc(var(--vh) * 100 - 180px); }
}

.chat-layout{
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 1.2rem;
  align-items: stretch;
}

.people-panel,
.convo-panel{
  height: auto;
  max-height: calc(100vh - 190px);
  min-height: 640px;
}

/* =========================================================
   CARD + HEADER
   ========================================================= */

.chat-card{
  border-radius: 1.35rem;
  border: 1px solid var(--chat-border);
  background: var(--chat-card);
  box-shadow: var(--chat-shadow-strong);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  color: var(--chat-ink);
}

.chat-card-header{
  padding: 0.85rem 0.95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: transparent;
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--chat-ink);
}

.chat-card-body{
  padding: 0.85rem 0.95rem 1rem;
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 0.75rem;
  min-height: 0;
}

/* =========================================================
   TOPBAR (WhatsApp-ish)
   ========================================================= */

.chat-topbar-left{
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.chat-panel-title{
  display: grid;
  gap: 0.1rem;
}

.chat-panel-title-main{
  font-size: 1.05rem;
  font-weight: 950;
  letter-spacing: 0.2px;
}

.chat-panel-title-sub{
  font-size: 0.82rem;
  color: var(--chat-ink-soft);
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  max-width: none;
  line-height: 1.2;
}

.chat-avatar{
  width: 38px;
  height: 38px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 950;
  letter-spacing: 0.3px;
  background: var(--chat-avatar-bg);
  border: 1px solid var(--chat-avatar-border);
  color: var(--chat-avatar-ink);
  flex: 0 0 auto;
}

.chat-avatar-sm{
  width: 30px;
  height: 30px;
  font-size: 0.78rem;
}

.chat-peer-lines{
  display: grid;
  gap: 0.1rem;
  min-width: 0;
}

.chat-peer-name{
  font-size: 0.98rem;
  font-weight: 950;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  max-width: none;
  line-height: 1.15;
  word-break: break-word;
}

.chat-peer-sub{
  font-size: 0.78rem;
  color: var(--chat-ink-soft);
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  max-width: none;
  line-height: 1.15;
  word-break: break-word;
}

/* =========================================================
   HEADER ACTIONS + ICON BUTTONS
   ========================================================= */

.chat-header-actions{
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.chat-icon-btn{
  border: 1px solid var(--chat-divider);
  background: var(--chat-icon-btn-bg);
  color: var(--chat-ink);
  border-radius: 0.95rem;
  padding: 0.36rem 0.58rem;
  font-weight: 950;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.chat-icon-btn:hover{ transform: translateY(-1px); }

/* 3-dot menu button */
#chat-thread-menu-btn{
  width: 42px;
  height: 42px;
  padding: 0 !important;
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  letter-spacing: 0;
  border-radius: 1.05rem;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

/* =========================================================
   PILLS + BADGES
   ========================================================= */

.chat-pill{
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid rgba(24, 178, 107, 0.35);
  background: var(--chat-pill);
  color: var(--chat-accent);
  font-size: 0.72rem;
  font-weight: 900;
  padding: 0.26rem 0.62rem;
}

.chat-badge{
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.24rem 0.6rem;
  font-size: 0.74rem;
  border-radius: 999px;
  border: 1px solid var(--chat-badge-border);
  color: var(--chat-ink-soft);
  background: var(--chat-badge-bg);
}

/* =========================================================
   TOGGLE
   ========================================================= */

.chat-visibility{ margin-top: 0.1rem; }

.toggle-pill{
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.84rem;
  color: var(--chat-ink-soft);
}
.toggle-pill input{ display:none; }

.toggle-ui{
  width: 40px;
  height: 20px;
  border-radius: 999px;
  border: 1px solid var(--chat-toggle-border);
  background: var(--chat-toggle-bg);
  position: relative;
  transition: 0.2s ease;
}

.toggle-ui::after{
  content:"";
  position:absolute;
  top:3px;
  left:3px;
  width:12px;
  height:12px;
  border-radius:999px;
  background: var(--chat-knob);
  box-shadow: var(--chat-knob-shadow);
  transition: 0.2s ease;
}

.toggle-pill input:checked + .toggle-ui{
  background: var(--chat-toggle-checked-bg);
  border-color: var(--chat-toggle-checked-border);
}
.toggle-pill input:checked + .toggle-ui::after{
  transform: translateX(18px);
  background: var(--chat-accent);
}

.chat-visibility-note{
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--chat-ink-soft);
  opacity: 0.9;
}

/* =========================================================
   PEOPLE SEARCH + LIST
   ========================================================= */

.chat-search input{
  width: 100%;
  border-radius: 1rem;
  border: 1px solid var(--chat-field-border);
  padding: 0.6rem 0.85rem;
  font-size: 0.92rem;
  background: var(--chat-field-bg);
  color: var(--chat-ink);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.chat-search input::placeholder{ color: var(--chat-placeholder); }
.chat-search input:focus{
  border-color: rgba(24, 178, 107, 0.45);
  box-shadow: var(--chat-focus-ring);
}

.chat-users{
  display: grid;
  gap: 0.5rem;
  overflow: auto;
  padding-right: 0.15rem;
  flex: 1;
  align-content: start;
  grid-auto-rows: max-content;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

/* Keep "no results" near search: collapse list when it has no rows */
.chat-users:empty{
  display: block;
  flex: 0 0 auto;
  min-height: 0;
  max-height: 0;
  overflow: hidden;
  padding-right: 0;
}

.chat-user{
  width: 100%;
  min-height: 56px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.6rem;
  border-radius: 0.85rem;
  border: 1px solid var(--chat-user-border);
  background: var(--chat-user-bg);
  cursor: pointer;
  transition: 0.18s ease;
  text-align: left;
}
.chat-user:hover{ transform: translateY(-1px); }

.chat-user.active{
  border-color: var(--chat-user-active-border);
  background: var(--chat-user-active-bg);
}

.chat-user-mid{
  display: grid;
  gap: 0.15rem;
  min-width: 0;
}

.chat-user-name{
  font-weight: 950;
  font-size: 0.9rem;
  color: var(--chat-ink);
  letter-spacing: 0.15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-user-sub{
  font-size: 0.74rem;
  color: var(--chat-ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-user-status{
  font-size: 0.68rem;
  color: var(--chat-ink-soft);
  border: 1px solid var(--chat-user-status-border);
  padding: 0.12rem 0.42rem;
  border-radius: 999px;
  background: var(--chat-chip-bg);
  opacity: 0.95;
}

/* =========================================================
   THREAD AREA
   ========================================================= */

.chat-thread{
  display:flex;
  flex-direction: column;
  gap: 0.65rem;
  flex: 1;
  min-height: 0;
  position: relative;
}

.chat-e2e-banner{
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  border-radius: 0.95rem;
  border: 1px solid var(--chat-divider);
  background: var(--chat-e2e-bg);
  color: var(--chat-ink-soft);
  font-size: 0.82rem;
}

@media (max-width: 980px){
  .chat-e2e-banner{
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: start;
    column-gap: 0.48rem;
    row-gap: 0;
    padding: 0.48rem 0.62rem;
    border-radius: 0.9rem;
    font-size: 0.79rem;
    line-height: 1.28;
  }

  .chat-e2e-banner .lock{
    line-height: 1;
    margin-top: 0.06rem;
    opacity: 0.88;
  }

  .chat-e2e-banner span:last-child{
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
  }
}

@media (min-width: 981px){
  .chat-e2e-banner{
    justify-content: center;
    text-align: center;
    width: fit-content;
    max-width: min(100%, 760px);
    margin: 0.2rem auto 0.25rem;
    padding: 0.56rem 0.9rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--chat-e2e-bg) 88%, var(--chat-card-solid));
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
  }

  .chat-e2e-banner .lock{
    flex: 0 0 auto;
    opacity: 0.9;
  }

  .chat-e2e-banner span:last-child{
    line-height: 1.3;
  }
}

.chat-messages{
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  overflow: auto;
  padding: 0.95rem 0.65rem 1.15rem;
  border-radius: 1.1rem;
  background: var(--chat-thread-bg);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.chat-scroll-date-pill{
  position: absolute;
  left: 50%;
  transform: translate(-50%, -8px);
  z-index: 9;
  pointer-events: none;
  padding: 0.26rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--chat-divider);
  background: color-mix(in srgb, var(--chat-card-solid) 88%, rgba(15,23,42,0.08));
  color: var(--chat-ink-soft);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  opacity: 0;
  transition: opacity 140ms ease, transform 140ms ease;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.12);
}
.chat-scroll-date-pill.is-visible{
  opacity: 1;
  transform: translate(-50%, 0);
}
body.theme-dark .chat-scroll-date-pill{
  background: color-mix(in srgb, var(--chat-card-solid) 78%, rgba(148,163,184,0.22));
}

#chat-empty{
  position: absolute;
  inset: 120px 0 110px 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1rem;
  pointer-events: none;
  z-index: 2;
  color: var(--chat-ink-soft);
  font-size: 0.95rem;
  opacity: 0.88;
}
#chat-empty::before{
  content: "💬";
  display:block;
  font-size: 2.1rem;
  margin-bottom: 0.6rem;
  opacity: 0.65;
}

.chat-msg{
  display: grid;
  gap: 0.22rem;
  justify-items: start;
  width: 100%;
}
.chat-msg.me{ justify-items: end; }

/* =========================================================
   META (timestamp + ticks)
   Mobile default below bubble + Desktop override inside bubble
   ========================================================= */

.chat-meta{
  font-size: 0.72rem;
  color: var(--chat-ink-soft);
  opacity: 0.85;

  display: inline-flex;
  align-items: center;
  gap: 6px;

  width: max-content;
  max-width: min(78%, 560px);

  margin-top: -4px; /* sits just under bubble */
  justify-self: start;
  align-self: start;
  margin-left: 6px;
  margin-right: 0;

  white-space: nowrap;
}

.chat-msg.me .chat-meta{
  justify-self: end;
  justify-content: flex-end;
  margin-left: 0;
  margin-right: 6px;
}

/* SVG ticks */
.chat-ticks{
  display: inline-flex;
  align-items: center;
  gap: 0;
  line-height: 1;
  opacity: 0.85;
  vertical-align: middle;
}
.chat-ticks svg{
  display: block;
  width: 18px;
  height: 18px;
}
.chat-ticks.is-pending { opacity: 0.60; }
.chat-ticks.is-sent { opacity: 0.78; }
.chat-ticks.is-delivered { opacity: 0.90; }
.chat-ticks.is-read { opacity: 1; }
.chat-ticks.is-failed { opacity: 1; }

.chat-msg.compact .chat-meta{ display: inline-flex; }

/* =========================================================
   BUBBLES
   ========================================================= */

.chat-bubble{
  position: relative;
  display: inline-block;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  border-radius: 1.1rem;
  border: 1px solid var(--chat-bubble-border);
  background: var(--chat-bubble);
  padding: 0.65rem 0.85rem;
  max-width: min(70%, 560px);
  line-height: 1.55;
  font-size: 0.96rem;
  box-shadow: var(--chat-bubble-shadow);
  color: var(--chat-ink);
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: box-shadow 420ms cubic-bezier(0.22, 0.61, 0.36, 1), transform 420ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* Prevent long LaTeX from blowing up bubbles (MathJax v3) */
.chat-bubble mjx-container{ max-width: 100%; }
.chat-bubble mjx-container[display="true"]{
  display: block;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding-bottom: 2px;
}
.chat-bubble mjx-container svg{
  max-width: 100%;
  height: auto;
}

/* Mobile swipe priority: equations should not steal horizontal drag from bubble swipe-to-reply */
@media (hover: none) and (pointer: coarse){
  .chat-bubble mjx-container,
  .chat-bubble mjx-container *{
    touch-action: pan-y !important;
    pointer-events: none !important;
  }
}

/* Avoid page-wide horizontal scroll due to long tokens */
.chat-messages,
.chat-thread,
.convo-panel{ overflow-x: hidden; }

/* Tail: incoming default */
.chat-bubble::after{
  content:"";
  position: absolute;
  bottom: 6px;
  left: -7px;
  width: 16px;
  height: 16px;
  background: var(--chat-bubble);
  border-left: 1px solid var(--chat-bubble-border);
  border-bottom: 1px solid var(--chat-bubble-border);
  transform: rotate(45deg);
  border-bottom-left-radius: 7px;
}
.chat-bubble::before{
  content:"";
  position: absolute;
  bottom: 3px;
  left: -2px;
  width: 12px;
  height: 12px;
  background: var(--chat-bubble);
  border-radius: 999px;
}

/* Reply snippet (rendered as <button>) */
.chat-bubble .chat-reply-snippet{
  display:block;
  position: relative;
  width: 100%;
  text-align: left;
  border-left: 0;
  padding-left: 0.65rem;
  margin-bottom: 0.35rem;
  opacity: 0.9;
  font-size: 0.84rem;
  color: var(--chat-ink-soft);

  border: 0;
  background: transparent;
  cursor: pointer;

  border-radius: 0.55rem;
  padding-top: 0.08rem;
  padding-bottom: 0.08rem;
}
.chat-bubble .chat-reply-snippet::before{
  content: "";
  position: absolute;
  left: 0.08rem;
  top: 0.12rem;
  bottom: 0.12rem;
  width: 3px;
  border-radius: 999px;
  background: var(--chat-reply-snippet-bar);
  opacity: 0.95;
}
.chat-bubble .chat-reply-snippet:hover,
.chat-bubble .chat-reply-snippet:active{
  background: color-mix(in srgb, var(--chat-replybar-bg) 70%, transparent);
}
.chat-bubble .chat-reply-snippet:focus{
  outline: none;
  box-shadow: var(--chat-focus-ring);
}

/* Jump highlight */
.chat-msg.chat-jump-highlight .chat-bubble{
  animation: chatJumpGlow 1.45s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

@keyframes chatJumpGlow{
  0%{
    box-shadow: var(--chat-bubble-shadow);
    transform: translateY(0);
  }
  18%{
    box-shadow: 0 0 0 5px rgba(24, 178, 107, 0.16), 0 0 0 10px rgba(24, 178, 107, 0.06), var(--chat-bubble-shadow);
    transform: translateY(-1px);
  }
  56%{
    box-shadow: 0 0 0 2px rgba(24, 178, 107, 0.10), 0 0 0 5px rgba(24, 178, 107, 0.04), var(--chat-bubble-shadow);
    transform: translateY(0);
  }
  100%{
    box-shadow: var(--chat-bubble-shadow);
    transform: translateY(0);
  }
}

/* Outgoing bubble: continuous surface */
.chat-msg.me .chat-bubble,
.chat-bubble.me{
  margin-left: auto;
  background: var(--chat-bubble-me-surface) !important;
  border: 0 !important;
  background-image: none !important;
  padding-right: 1.15rem;
  position: relative;
  isolation: isolate;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.08) !important;
}
body.theme-dark .chat-msg.me .chat-bubble,
body.theme-dark .chat-bubble.me{
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.28) !important;
}

.chat-msg.me .chat-bubble::after,
.chat-bubble.me::after{
  content: "";
  left: auto !important;
  right: -4px !important;
  bottom: 7px !important;
  width: 16px;
  height: 16px;
  background: var(--chat-bubble-me-surface) !important;
  border: 0 !important;
  background-image: none !important;
  transform: rotate(45deg);
  border-bottom-left-radius: 7px;
  z-index: 0 !important;
  pointer-events: none;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.06);
}
body.theme-dark .chat-msg.me .chat-bubble::after,
body.theme-dark .chat-bubble.me::after{
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.24);
}

.chat-msg.me .chat-bubble::before,
.chat-bubble.me::before{
  content: "";
  left: auto !important;
  right: 7px !important;
  bottom: 3px !important;
  width: 18px !important;
  height: 18px !important;
  background: var(--chat-bubble-me-surface) !important;
  border: 0 !important;
  background-image: none !important;
  border-radius: 999px;
  z-index: -1 !important;
  pointer-events: none;
}

/* =========================================================
   DESKTOP META INSIDE BUBBLE
   ========================================================= */

@media (min-width: 981px){
  /* Reserve “meta strip” inside the bubble */
  body:has(.chat-shell) .chat-bubble{ padding-bottom: 1.35rem; }

  /* Ensure short messages still fit time + ticks */
  body:has(.chat-shell) .chat-msg:not(.me) .chat-bubble{ min-width: 60px; }
  body:has(.chat-shell) .chat-msg.me .chat-bubble{ min-width: 85px; }

  /* Pull meta up into reserved padding */
  body:has(.chat-shell) .chat-meta{
    margin-top: -54px;
    margin-left: 12px;
    max-width: min(72%, 620px);
    gap: 8px;
    opacity: 0.70;
    font-size: 0.70rem;
    pointer-events: none;
  }
  body:has(.chat-shell) .chat-msg.me .chat-meta{
    margin-left: 0;
    margin-right: 12px;
  }

  body:has(.chat-shell) .chat-ticks{ margin-left: 2px; }

  /* Desktop: convo header single row with tidy ellipsis */
  .chat-card-header.convo-header{
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.6rem;
  }
  .chat-card-header.convo-header .chat-peer-name,
  .chat-card-header.convo-header .chat-peer-sub{
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* =========================================================
   COMPOSER
   ========================================================= */

.chat-compose{
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.6rem;
  align-items: end;
  background: var(--chat-input-surface);
  border-radius: 1.2rem;
  padding: 0.6rem;
  box-shadow: var(--chat-compose-shadow);
  color: var(--chat-ink);
}

.chat-input{
  width: 100%;
  min-height: 44px;
  border-radius: 0.95rem;
  border: none;
  padding: 0.65rem 0.75rem;
  background: transparent;
  color: var(--chat-input-text);
  font-size: 0.95rem;
  resize: none;
  outline: none;
}
.chat-input::placeholder{ color: var(--chat-placeholder); }

.chat-btn{
  border-radius: 0.95rem;
  border: none;
  background: var(--chat-accent);
  color: #fff;
  font-weight: 950;
  padding: 0.64rem 1.05rem;
  cursor: pointer;
  box-shadow: var(--chat-accent-shadow, 0 10px 18px rgba(24, 178, 107, 0.20));
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}
.chat-btn:hover{
  transform: translateY(-1px);
  box-shadow: var(--chat-accent-shadow-hover, 0 14px 24px rgba(24, 178, 107, 0.24));
}

.chat-hint{
  font-size: 0.82rem;
  color: var(--chat-ink-soft);
  opacity: 0.9;
}

.chat-alert{
  border-radius: 0.9rem;
  border: 1px solid var(--chat-alert-border);
  background: var(--chat-alert-bg);
  color: var(--chat-ink);
  padding: 0.6rem 0.75rem;
  font-size: 0.86rem;
  opacity: 0;
  transform: translateY(-5px);
  transition: opacity 180ms ease, transform 180ms ease;
}
.chat-alert.is-visible{
  opacity: 1;
  transform: translateY(0);
}
.chat-alert.is-leaving{
  opacity: 0;
  transform: translateY(-5px);
}

.chat-input:disabled,
.chat-btn:disabled{
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

/* =========================================================
   RECENTS
   ========================================================= */

.chat-recents{
  border: 1px solid var(--chat-divider);
  border-radius: 1rem;
  padding: 0.7rem 0.7rem;
  background: var(--chat-recents-bg);
}

.chat-recents-title{
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.2px;
  color: var(--chat-ink-soft);
  margin-bottom: 0.5rem;
}

.chat-recents-list{ display: grid; gap: 0.45rem; }

.chat-recent{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 0.6rem;
  border-radius: 0.9rem;
  border: 1px solid var(--chat-divider);
  padding: 0.55rem 0.65rem;
  background: var(--chat-recent-bg);
  cursor: pointer;
}

.chat-recent-left{
  display:flex;
  align-items:center;
  gap: 0.55rem;
  min-width: 0;
}

.chat-recent-name{
  font-weight: 950;
  font-size: 0.9rem;
  color: var(--chat-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-recent-time{
  font-size: 0.74rem;
  color: var(--chat-ink-soft);
}

/* =========================================================
   MENUS (thread menu + floating menu)
   ========================================================= */

.chat-menu{
  position: absolute;
  top: 58px;
  right: 14px;
  z-index: 5;
  border: 1px solid var(--chat-divider);
  border-radius: 1rem;
  background: var(--chat-menu-bg);
  box-shadow: var(--chat-shadow);
  overflow: hidden;
}

.chat-menu-item{
  width: 100%;
  text-align: left;
  padding: 0.75rem 0.85rem;
  background: transparent;
  border: none;
  cursor: pointer;
  font-weight: 900;
  color: var(--chat-ink);
}
.chat-menu-item:hover,
.chat-menu-item:active{ background: var(--chat-menu-item-hover); }

/* Mobile "finger-hover" */
.chat-menu-item.is-hot{ background: rgba(24, 178, 107, 0.12); }

/* Only "Clear chat" is destructive */
#chat-thread-menu #chat-clear-chat{ color: #b91c1c; }
#chat-thread-menu #chat-clear-chat:hover,
#chat-thread-menu #chat-clear-chat:active{ background: rgba(239, 68, 68, 0.12); }

/* Thread menu: shrink-to-fit */
#chat-thread-menu.chat-menu{
  min-width: unset !important;
  width: fit-content !important;
  max-width: 240px !important;
  border-radius: 1rem;
  box-shadow: var(--chat-shadow-strong);
}
#chat-thread-menu.chat-menu .chat-menu-item{
  padding: 0.72rem 0.95rem !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Floating message-action menu: neutral & tight */
.chat-float-menu{
  display: inline-block !important;
  width: fit-content !important;
  max-width: min(300px, calc(100vw - 24px));
  min-width: unset !important;
  border-radius: 0.9rem;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.18);
  overflow: hidden;
}
.chat-float-menu .chat-menu-item{
  display: block;
  width: 100%;
  font-size: 0.95rem;
  padding: 0.58rem 0.82rem !important;
  white-space: nowrap;
}
/* =========================================================
   MOBILE: Thread menu (Clear/Export) should feel like a sheet
   (This was in the old stable file; add it back.)
   ========================================================= */
@media (max-width: 980px){

  /* Thread menu only (does NOT affect the floating message menu) */
  #chat-thread-menu.chat-menu{
    top: 64px;
    left: 12px;
    right: 12px;

    width: auto !important;
    max-width: none !important;
    min-width: 0 !important;

    border-radius: 1.2rem;
    padding: 0.3rem 0;

    transform: none !important;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.22);

    /* Helps on iOS if anything weird overlaps */
    z-index: 25000 !important;
  }

  #chat-thread-menu .chat-menu-item{
    padding: 0.95rem 1.1rem !important;
    font-size: 0.98rem;
    font-weight: 800;
    line-height: 1.25;

    /* keep labels tidy */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Divider between items (mobile sheet look) */
  #chat-thread-menu .chat-menu-item + .chat-menu-item{
    border-top: 1px solid var(--chat-divider);
  }
}


/* =========================================================
   CLEAR CHAT CONFIRM MODAL + TOAST
   ========================================================= */

.chat-modal-backdrop{
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10000;
  display: grid;
  place-items: center;
  overscroll-behavior: contain;
}

.chat-modal{
  width: min(92vw, 380px);
  background: var(--chat-card-solid);
  border-radius: 1.2rem;
  box-shadow: var(--chat-shadow-strong);
  padding: 1rem 1rem 0.9rem;
  color: var(--chat-ink);
  border: 1px solid var(--chat-divider);
}

.chat-modal-title{
  font-weight: 950;
  font-size: 1rem;
  margin-bottom: 0.4rem;
}

.chat-modal-text{
  font-size: 0.9rem;
  color: var(--chat-ink-soft);
  margin-bottom: 0.9rem;
}

.chat-modal-actions{ display: grid; gap: 0.55rem; }

.chat-modal-btn{
  width: 100%;
  padding: 0.72rem 0.95rem;
  border-radius: 0.95rem;
  border: 1px solid var(--chat-divider);
  background: transparent;
  font-weight: 950;
  cursor: pointer;
}
.chat-modal-btn:active{ transform: translateY(1px); }

.chat-modal-btn.primary{
  background: var(--chat-accent);
  color: #fff;
  border-color: transparent;
}

.chat-modal-btn.danger{
  background: rgba(239, 68, 68, 0.10);
  color: #b91c1c;
  border-color: rgba(239, 68, 68, 0.25);
}

.chat-toast{
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--chat-card-solid);
  color: var(--chat-ink);
  border: 1px solid var(--chat-divider);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 800;
  box-shadow: var(--chat-shadow);
  z-index: 11000;
}

/* =========================================================
   REPLY BAR (WhatsApp-ish)
   ========================================================= */

.chat-replybar{
  display:flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.62rem;
  border-radius: 0.9rem;
  padding: 0.48rem 0.56rem 0.5rem;
  border: 1px solid var(--chat-divider);
  background: var(--chat-replybar-bg);
  box-shadow: inset 0 0 0 1px rgba(24, 178, 107, 0.05);
  position: relative;
}

.chat-replybar::before{
  content: "";
  position: absolute;
  left: 0.38rem;
  top: 0.38rem;
  bottom: 0.38rem;
  width: 3px;
  border-radius: 999px;
  background: var(--chat-reply-snippet-bar);
  opacity: 0.95;
}

.chat-replybar-left{
  flex: 1 1 auto;
  min-width: 0;
  padding-left: 0.48rem;
}

.chat-replybar-label{
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.25px;
  text-transform: uppercase;
  color: var(--chat-ink-soft);
}

.chat-replybar-text{
  margin-top: 0.08rem;
  font-size: 0.84rem;
  font-weight: 820;
  color: var(--chat-ink);

  white-space: normal;
  overflow: hidden;

  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  line-height: 1.15;

  flex: 1 1 auto;
  min-width: 0;
}

.chat-replybar-x{
  width: 34px;
  height: 34px;
  border-radius: 0.72rem;
  border: 1px solid var(--chat-divider);
  background: var(--chat-replybar-x-bg);
  cursor: pointer;
  font-weight: 900;
  font-size: 1rem;
  line-height: 1;
  color: var(--chat-ink);

  display: grid;
  place-items: center;

  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  position: relative;
  transition: transform 0.12s ease, background-color 0.14s ease, border-color 0.14s ease;
}
.chat-replybar-x:hover{
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--chat-divider) 50%, var(--chat-accent) 50%);
}
.chat-replybar-x:active{
  transform: translateY(0);
}
.chat-replybar-x::before{
  content:"";
  position:absolute;
  inset:-10px;
}

/* =========================================================
   SKELETON LOADING
   ========================================================= */

.chat-skeleton{ width: 100%; display: grid; gap: 0.65rem; padding: 0.2rem 0; }
.sk-row{ display:flex; justify-content: flex-start; }
.sk-row.me{ justify-content: flex-end; }

.sk-bubble{
  width: min(72%, 520px);
  height: 44px;
  border-radius: 1.05rem;
  border: 1px solid var(--chat-bubble-border);
  background: linear-gradient(90deg, var(--chat-skeleton-a), var(--chat-skeleton-b), var(--chat-skeleton-a));
  background-size: 240% 100%;
  animation: chatShimmer 1.2s ease-in-out infinite;
}

@keyframes chatShimmer{
  0%{ background-position: 0% 0; }
  100%{ background-position: 100% 0; }
}

/* Users/Recents loading skeletons */
.chat-skel-row{
  pointer-events: none;
}
.chat-skel-mid{
  flex: 1 1 auto;
  min-width: 0;
}
.chat-skel-block{
  background: linear-gradient(90deg, var(--chat-skeleton-a), var(--chat-skeleton-b), var(--chat-skeleton-a));
  background-size: 240% 100%;
  animation: chatShimmer 1.2s ease-in-out infinite;
  border: 1px solid var(--chat-divider);
}
.chat-skel-avatar{
  border-radius: 999px;
}
.chat-skel-line{
  border-radius: 0.55rem;
}
.chat-skel-line-a{
  height: 14px;
  width: clamp(96px, 44%, 190px);
  margin-top: 2px;
}
.chat-skel-recent-title{
  height: 14px;
  width: clamp(120px, 46%, 240px);
  margin-top: 0;
}
.chat-skel-line-b{
  height: 11px;
  width: clamp(70px, 30%, 130px);
  margin-top: 6px;
}
.chat-skel-pill{
  height: 24px;
  width: 48px;
  border-radius: 999px;
}
.chat-skel-recent-time{
  height: 20px;
  width: 64px;
  border-radius: 999px;
}

/* =========================================================
   SCROLL HINTS
   ========================================================= */

.chat-scroll-hint{ display:none; }

@media (min-width: 981px){
  .chat-scroll-hint-users{
    display: block;
    margin-top: 0.35rem;
    padding-left: 0.2rem;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.25px;
    text-align: left;
    color: var(--chat-ink-soft);
    opacity: 0.6;
    pointer-events: none;
    user-select: none;
  }
}

@media (max-width: 980px){
  .chat-scroll-hint{
    display: block;
    margin-top: 0.2rem;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.2px;
    color: var(--chat-ink-soft);
    opacity: 0.65;
  }
  .chat-scroll-hint-users{ margin-top: 0.25rem; }
}

/* =========================================================
   FOOTER SPACING (chat page only)
   ========================================================= */

.chat-shell + .site-footer{ margin-top: 2.2rem; }
.site-footer a:visited{ color: inherit; }

/* =========================================================
   UNDER-BUBBLE REPLY BUTTON (desktop hover / long-hover)
   Consolidated: keep the newer animation-based behavior.
   ========================================================= */

.chat-under-actions{
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0 0.25rem;
  opacity: 0;
  transform: translateY(-2px);
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
}

.chat-under-actions.them{ justify-content: flex-start; }
.chat-under-actions.me{ justify-content: flex-end; }

.chat-reply-under{
  border: 1px solid var(--chat-divider);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  background: var(--chat-icon-btn-bg);
  color: var(--chat-ink);
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) and (pointer: fine){
  :root{
    --reply-delay: 1.4s;
    --reply-visible: 5s;
    --reply-fade: 0.6s;
  }

  .chat-msg:hover .chat-under-actions{
    animation: replyPeek calc(var(--reply-visible) + var(--reply-fade)) ease forwards;
    animation-delay: var(--reply-delay);
  }

  @keyframes replyPeek{
    0%{ opacity: 1; transform: translateY(0); pointer-events: auto; }
    70%{ opacity: 1; transform: translateY(0); }
    100%{ opacity: 0; transform: translateY(-2px); pointer-events: none; }
  }

  .chat-reply-under:hover{ transform: translateY(-1px); }
  .chat-reply-under:focus{
    box-shadow: var(--chat-focus-ring);
    outline: none;
  }
}

@media (max-width: 520px){
  .chat-under-actions{ display:none; }
}

/* Hide manual refresh button (auto-refresh timer stays) */
#chat-refresh-users{ display: none !important; }

/* =========================================================
   MOBILE + RESPONSIVE
   ========================================================= */

@media (max-width: 980px){
  .chat-shell{ padding: 0.4rem 0.35rem 2rem; }
  .chat-shell::before{ position: absolute; }

  .chat-layout{
    grid-template-columns: minmax(0, 1fr);
    gap: 0.7rem;
  }

  .people-panel,
  .convo-panel{
    height: auto;
    max-height: none;
    min-height: 0;
  }

  .chat-card{ border-radius: 1rem; }

  .chat-card-header{
    padding: 0.7rem 0.8rem;
    background: var(--chat-mobile-header-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--chat-divider);
    align-items: flex-start;
  }

  .chat-card-body{ padding: 0.75rem 0.8rem 0.9rem; }

  /* Conversation header breathing (2 rows) */
  .chat-card-header.convo-header{
    flex-wrap: wrap;
    row-gap: 0.45rem;
  }
  .chat-card-header.convo-header .chat-topbar-left{
    flex: 1 1 100%;
    min-width: 0;
  }
  .chat-card-header.convo-header .chat-header-actions{
    flex: 0 0 100%;
    justify-content: flex-end;
    gap: 0.45rem;
  }

  .chat-messages{ padding: 0.8rem 0.95rem 1rem; }
  .chat-bubble{ max-width: min(78%, 560px); }

  /* Minimum bubble widths on mobile */
  .chat-msg:not(.me) .chat-bubble{ min-width: var(--chat-bubble-min-mobile-them); }
  .chat-msg.me .chat-bubble{ min-width: var(--chat-bubble-min-mobile-me); }

  .chat-compose{
    position: sticky;
    bottom: 0;
    z-index: 3;
    background: var(--chat-input-surface);
  }

  #chat-empty{ inset: 90px 0 130px 0; }

  .chat-recents-list{
    max-height: calc(4 * 56px + 3 * 0.45rem);
    overflow: auto;
    padding-right: 0.15rem;
  }

  .chat-users{
    max-height: calc(4 * 62px + 3 * 0.5rem);
  }

  /* Reply bar mobile: 2 lines */
  .chat-replybar{
    align-items: flex-start;
    gap: 0.5rem;
    border-radius: 0.82rem;
    padding: 0.44rem 0.5rem 0.46rem;
  }
  .chat-replybar::before{
    left: 0.33rem;
    top: 0.33rem;
    bottom: 0.33rem;
  }
  .chat-replybar-left{ padding-left: 0.44rem; }
  .chat-replybar-text{
    -webkit-line-clamp: 2;
    font-size: 0.83rem;
  }
  .chat-replybar-x{
    width: 32px;
    height: 32px;
    border-radius: 0.65rem;
  }

  /* Modal mobile: bottom sheet */
  .chat-modal-backdrop{ place-items: end center; }
  .chat-modal{
    width: 100%;
    border-radius: 1.2rem 1.2rem 0 0;
    padding-bottom: calc(0.9rem + env(safe-area-inset-bottom, 0px));
    position: relative;
  }
  .chat-modal::before{
    content:"";
    position:absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 44px;
    height: 4px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--chat-divider) 85%, transparent);
    opacity: 0.9;
  }
}

/* flattened (was nested) */
@media (max-width: 980px) and (max-width: 380px){
  .chat-badge{ font-size: 0.7rem; padding: 0.2rem 0.5rem; }
}

/* =========================================================
   DESKTOP CHAT WIDTH (match Problems page) + taller panels
   ========================================================= */

@media (min-width: 981px){
  body:has(.chat-shell) main{
    max-width: var(--max-width) !important;
    width: 100% !important;
  }

  body:has(.chat-shell) .chat-layout{
    grid-template-columns: minmax(340px, 420px) minmax(0, 1fr) !important;
    gap: 1.1rem !important;
  }

  body:has(.chat-shell) .chat-bubble,
  body:has(.chat-shell) .chat-bubble.me{
    max-width: min(72%, 620px);
  }

  .chat-shell{
    min-height: calc(100vh - 24px) !important;
    padding-bottom: 0.25rem !important;
  }

  .people-panel,
  .convo-panel{
    max-height: calc(100vh - 36px) !important;
    min-height: calc(100vh - 48px) !important;
  }

  .chat-card{ height: 100% !important; }

  .chat-card-body,
  .chat-thread,
  .chat-messages{
    flex: 1 1 auto;
    min-height: 0;
  }

  #chat-thread-menu.chat-menu{ max-width: 260px !important; transform: translateX(12px); }
  #chat-thread-menu.chat-menu .chat-menu-item{
    font-size: 1.02rem;
    padding: 0.85rem 1.1rem !important;
  }
}

/* =========================================================
   MOBILE: FULLSCREEN CONVERSATION (WhatsApp-ish)
   Toggle via: body.chat-convo-fullscreen
   ========================================================= */

#chat-expand-convo{
  display: none;
  width: 42px;
  height: 42px;
  padding: 0 !important;
  border-radius: 1.05rem;
  line-height: 1;
  font-size: 1.2rem;
  place-items: center;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 980px){
  #chat-expand-convo{ display: grid; }
}

body.chat-convo-fullscreen{
  overflow: hidden !important;
  height: 100% !important;

  /* slightly taller (not full 100vh) */
  --chat-fullscreen-extra: 56px;
}

html:has(body.chat-convo-fullscreen){
  overflow: hidden !important;
  height: 100% !important;
}

body.chat-convo-fullscreen .people-panel{ display: none !important; }

body.chat-convo-fullscreen .convo-panel{
  position: fixed !important;
  inset: 0 !important;
  z-index: 20000 !important;

  width: 100% !important;
  height: 100dvh !important;

  max-height: none !important;
  min-height: 0 !important;

  margin: 0 !important;
}

body.chat-convo-fullscreen .convo-panel .chat-card{
  border-radius: 0 !important;
  height: 100% !important;
}

body.chat-convo-fullscreen .convo-panel .chat-card-body,
body.chat-convo-fullscreen .convo-panel .chat-thread,
body.chat-convo-fullscreen .convo-panel .chat-messages{
  min-height: 0 !important;
}

/* Optional: tighten outer padding so it feels like a real app screen */
@media (max-width: 980px){
  body.chat-convo-fullscreen .chat-shell{ padding: 0 !important; }
}

/* Hide export hint in full-screen */
body.chat-convo-fullscreen .chat-export-hint{ display: none !important; }

/* Make sure the convo column truly occupies full height */
body.chat-convo-fullscreen .chat-convo{
  height: calc(var(--vh, 1vh) * 100);
}

/* Let messages expand */
body.chat-convo-fullscreen .chat-messages{
  flex: 1 1 auto;
  min-height: 0;
}

/* Slightly taller “maximised panel” height tweak */
body.chat-convo-fullscreen :is(.chat-shell, .chat-wrap, .chat-layout, .chat-main, .chat-right, .chat-convo, .chat-panel){
  height: calc(100% + var(--chat-fullscreen-extra)) !important;
  max-height: none !important;
  min-height: 0 !important;
}
body.chat-convo-fullscreen :is(#chat-messages, .chat-messages){
  min-height: 0 !important;
  flex: 1 1 auto !important;
  overflow: auto !important;
  -webkit-overflow-scrolling: touch;
}

/* =========================================================
   EXPORT HINT SHRINK
   ========================================================= */

.chat-export-hint,
.chat-export-note,
.chat-footer-hint{
  font-size: 13px !important;
  line-height: 1.25 !important;
  padding: 8px 12px !important;
  margin: 6px 12px 10px !important;
  border-radius: 12px !important;
  opacity: 0.75;
}
.chat-export-hint{
  background: rgba(0,0,0,0.03) !important;
}

/* =========================================================
   MOBILE HEIGHT STABILITY PATCH (consolidated)
   - neutralize dvh resizing
   - keep messages as the internal scroller
   - idle state + JS class body.chat-has-convo sizing
   ========================================================= */

@media (max-width: 980px){

  /* Core stability: let flex drive the layout */
  .chat-thread{
    min-height: 0 !important;
    height: auto !important;
  }

  .convo-panel .chat-card-body{
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
  }

  .chat-thread{
    flex: 1 1 auto !important;
    min-height: 0 !important;
  }

  .chat-messages{
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: 1px !important; /* prevents page stretch */
    max-height: none !important;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .chat-compose{
    position: sticky !important;
    bottom: 0 !important;
  }

  /* Prevent empty overlay from covering composer */
  #chat-empty{
    position: static !important;
    inset: auto !important;
    margin: 1.5rem 0 0.5rem;
  }

  /* Convo panel height depends on whether a chat is open (body.chat-has-convo set by JS) */
  body:not(.chat-convo-fullscreen):not(.chat-has-convo) .convo-panel{
    height: 78svh !important;
    max-height: 78svh !important;
    min-height: 520px !important;
  }

  body:not(.chat-convo-fullscreen).chat-has-convo .convo-panel{
    height: 110svh !important;
    max-height: 110svh !important;
    min-height: 520px !important;
  }

  body:not(.chat-convo-fullscreen) .convo-panel .chat-card{
    height: 100% !important;
  }

  /* Idle (no convo): stop big blank slab */
  body:not(.chat-convo-fullscreen):not(.chat-has-convo) .chat-messages{
    flex: 0 0 auto !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    padding-top: 0.25rem !important;
    padding-bottom: 0.25rem !important;
    background: transparent !important;
  }

  body:not(.chat-convo-fullscreen):not(.chat-has-convo) .chat-thread{
    min-height: 0 !important;
    height: auto !important;
    flex: 0 0 auto !important;
  }
}

/* =========================================================
   NO CHAT — manual spacing
   ========================================================= */

body:not(.chat-has-convo) .chat-compose{
  margin-top: 60px !important;
  margin-bottom: 22px !important;
}
body:not(.chat-has-convo) .chat-export-hint{
  margin-top: -18px !important;
}
/* Users-panel swipe hint: JS controls visibility */
.chat-scroll-hint-users{
  display: none;
  margin-top: 0.25rem;
  padding-left: 0.2rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.25px;
  text-align: left;
  color: var(--chat-ink-soft);
  opacity: 0.6;
  pointer-events: none;
  user-select: none;
}

/* When JS decides it's useful */
.chat-scroll-hint-users.is-on{
  display: block;
}

/* =========================================================
   DESKTOP: cap Recents + Members list to ~4 items, then scroll
   ========================================================= */
@media (min-width: 981px){

  /* Recents list: show ~4 then scroll */
  .chat-recents-list{
    max-height: calc(4 * 56px + 3 * 0.45rem);
    overflow: auto;
    padding-right: 0.15rem;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Members list: show ~4 then scroll */
  .chat-users{
    max-height: calc(4 * 62px + 3 * 0.5rem);
    overflow: auto;
    padding-right: 0.15rem;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
}
/* Users-panel swipe hint: JS toggles .is-on */
.chat-scroll-hint-users{
  display: none !important;
}

.chat-scroll-hint-users.is-on{
  display: inline-flex !important;

  /* look + feel */
  align-items: center;
  justify-content: center;
  gap: 0.35rem;

  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.15px;

  color: color-mix(in srgb, var(--chat-ink-soft) 85%, transparent);
  background: color-mix(in srgb, var(--chat-card-solid) 85%, transparent);

  border: 1px solid var(--chat-divider);
  border-radius: 999px;

  padding: 0.38rem 0.65rem;

  /* placement: subtle floating chip */
  width: fit-content;
  margin: 0.35rem auto 0.1rem;  /* centers under list */
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);

  user-select: none;
  pointer-events: none;
}
/* =========================================
   Users swipe hint — clean, sharp, no icon
   JS toggles .is-on
   ========================================= */

.chat-scroll-hint-users{
  display: none !important;
}

.chat-scroll-hint-users.is-on{
  display: inline-flex !important;

  align-items: center;
  justify-content: center;

  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.15px;

  /* crisp rendering */
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;

  color: var(--chat-ink-soft);
  background: var(--chat-card-solid);

  border: 1px solid rgba(148,163,184,.35);
  border-radius: 999px;

  padding: 0.38rem 0.65rem;

  width: fit-content;
  margin: 0.35rem auto 0.1rem;

  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.10);

  user-select: none;
  pointer-events: none;

  /* prevent iOS blur artifacts */
  transform: translateZ(0);
}

/* Slight mobile tuning */
@media (max-width: 980px){
  .chat-scroll-hint-users.is-on{
    border-color: rgba(148,163,184,.42);
    box-shadow: 0 5px 12px rgba(15, 23, 42, 0.12);
  }
}
/* =========================================================
   FINAL — crisp chip styling (Swipe hint + Export hint)
   No extra tokens, uses existing theme variables
   ========================================================= */

/* ===== Swipe hint (Users panel) ===== */
.chat-scroll-hint-users{ display:none !important; }

.chat-scroll-hint-users.is-on{
  display: inline-flex !important;
  align-items: center;
  justify-content: center;

  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.15px;

  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;

  color: var(--chat-ink-soft);
  background: var(--chat-card-solid);

  border: 1px solid var(--chat-divider);
  border-radius: 999px;

  padding: 0.38rem 0.65rem;
  width: fit-content;
  margin: 0.35rem auto 0.1rem;

  box-shadow: 0 6px 14px rgba(15,23,42,.10);

  user-select: none;
  pointer-events: none;

  transform: translateZ(0);
}

/* kill any legacy pseudo icons */
.chat-scroll-hint-users::before,
.chat-scroll-hint-users::after{
  content:none !important;
  display:none !important;
}

@media (max-width: 980px){
  .chat-scroll-hint-users.is-on{
    border-color: rgba(148,163,184,.42);
    box-shadow: 0 5px 12px rgba(15,23,42,.12);
  }
}

/* ===== Export hint — same chip style ===== */
.chat-export-hint,
.chat-export-note,
.chat-footer-hint{
  display: inline-flex !important;
  align-items: center;
  justify-content: center;

  font-size: 0.72rem !important;
  font-weight: 800 !important;
  letter-spacing: 0.15px;

  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;

  color: var(--chat-ink-soft) !important;
  background: var(--chat-card-solid) !important;

  border: 1px solid var(--chat-divider) !important;
  border-radius: 999px !important;

  padding: 0.38rem 0.65rem !important;
  width: fit-content !important;
  margin: 0.45rem auto 0.2rem !important;

  box-shadow: 0 6px 14px rgba(15,23,42,.10) !important;

  user-select: none;
  transform: translateZ(0);
}
/* =========================================================
   DESKTOP: make the tint run all the way down to the composer
   by moving the tint to .chat-thread (parent)
   ========================================================= */
@media (min-width: 981px){

  /* Paint the tint on the whole thread column */
  body:has(.chat-shell) .convo-panel .chat-thread{
    background: var(--chat-thread-bg) !important;
    border-radius: 1.1rem !important;

    /* match your messages padding so it looks identical */
    padding: 0.95rem 0.65rem 1.15rem !important;

    /* so the tint doesn't bleed outside rounding */
    overflow: hidden !important;
  }

  /* Messages area becomes transparent so tint looks continuous */
  body:has(.chat-shell) .convo-panel .chat-messages{
    background: transparent !important;
    padding: 0 0.45rem !important;  /* avoid bubble-tail clipping at edges */
    border-radius: 0 !important;
  }

  /* Optional: keep the e2e banner sitting nicely on the tint */
  body:has(.chat-shell) .convo-panel .chat-e2e-banner{
    background: color-mix(in srgb, var(--chat-e2e-bg) 85%, transparent) !important;
  }
}
/* =========================================================
   APPEND — make chat tint as smooth as the rest (no radials)
   ========================================================= */

/* Light: essentially a clean card-like wash */
body:not(.theme-dark){
  --chat-thread-bg:
    linear-gradient(
      180deg,
      rgba(255,255,255,0.92),
      rgba(248,250,252,0.92)
    );
}

/* Dark: same idea, slightly deeper */
body.theme-dark{
  --chat-thread-bg:
    linear-gradient(
      180deg,
      rgba(12,16,24,0.86),
      rgba(8,11,17,0.86)
    );
}
/* =========================================================
   Expand / Exit fullscreen icon (desktop + mobile)
   ========================================================= */

#chat-expand-convo{
  position: relative;
  font-size: 0;
  display: grid;
  place-items: center;
}

/* Slightly tighter on desktop so header stays balanced */
@media (min-width: 981px){
  #chat-expand-convo{
    width: 40px;
    height: 40px;
  }
}

/* default: expand (keep your nice emoji) */
#chat-expand-convo::before{
  content: "⛶";
  font-size: 1.2rem;
  line-height: 1;
}

/* active: exit fullscreen — clean glyph */
body.chat-convo-fullscreen #chat-expand-convo::before{
  content: "×";   /* simple, universal close/exit symbol */
}
/* =========================================================
   LEFT PANEL — desktop-only dynamic recents/users sizing
   ========================================================= */

@media (min-width: 981px){

  /* Make the PEOPLE card body a flex column */
  .people-panel .chat-card-body{
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
  }

  /* Recents takes natural height */
  #chat-recents{
    flex: 0 0 auto !important;
  }

  /* Users fills remaining space */
  #chat-users{
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow-y: auto !important;
  }

}
/* Search affordances */
.chat-search-wrap{
  position: relative;
}

.chat-search-clear{
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--chat-divider);
  background: var(--chat-card-solid);
  color: var(--chat-ink);
  display: grid;
  place-items: center;
  cursor: pointer;
}

/* Loading feel: subtle shimmer / spinner without extra assets */
#chat-search.is-loading{
  background-image: linear-gradient(90deg,
    transparent, rgba(24,178,107,0.10), transparent);
  background-size: 200% 100%;
  animation: chatSearchGlow 1.0s ease-in-out infinite;
}
@keyframes chatSearchGlow{
  0%{ background-position: 0% 0; }
  100%{ background-position: 200% 0; }
}

.chat-search-meta{
  font-size: 0.78rem;
  color: var(--chat-ink-soft);
  margin-top: -0.3rem;
  padding: 0 0.2rem;
  opacity: 0.9;
}
.chat-search-meta.ok{ color: color-mix(in srgb, var(--chat-accent) 70%, var(--chat-ink-soft)); }
.chat-search-meta.bad{ color: #b91c1c; }
.chat-search-meta.hint{ color: var(--chat-ink-soft); }

/* Better empty state */
#chat-users-empty{
  border: 1px dashed var(--chat-divider);
  border-radius: 1rem;
  padding: 0.9rem;
  background: color-mix(in srgb, var(--chat-card-solid) 70%, transparent);
  margin-top: 0.38rem;
  margin-bottom: 0.25rem;
}

.chat-empty-action{
  margin-top: 0.6rem;
  border-radius: 0.9rem;
  border: 1px solid var(--chat-divider);
  background: var(--chat-card-solid);
  padding: 0.55rem 0.8rem;
  font-weight: 900;
  cursor: pointer;
}
/* =========================================================
   FIX (mobile): Export hint pill looks attached/odd
   - remove negative margin hacks
   - keep it centered, not stretched, with sane spacing
   ========================================================= */

@media (max-width: 980px){

  /* Kill the old “pull it up” hack */
  body:not(.chat-has-convo) .chat-export-hint{
    margin-top: 0 !important;
  }

  /* Give composer + hint a clean, consistent gap */
  body:not(.chat-has-convo) .chat-compose{
    margin-top: 1.2rem !important;
    margin-bottom: 0.6rem !important;
  }

  /* Make the hint behave like a centered chip, never full-width */
  .chat-export-hint,
  .chat-export-note,
  .chat-footer-hint{
    align-self: center !important;
    justify-self: center !important;

    width: fit-content !important;
    max-width: calc(100% - 24px) !important;

    text-align: center !important;
    white-space: normal !important;   /* allow wrap */
    word-break: break-word !important;

    margin: 0.45rem auto 0.25rem !important;
  }
}
/* =========================================================
   FIX — Mobile fullscreen bottom area (composer feels “off”)
   - remove extra height stretching
   - make composer flush + safe-area correct (iOS)
   ========================================================= */
@media (max-width: 980px){

  /* Cancel the earlier "taller than screen" hack in fullscreen */
  body.chat-convo-fullscreen{
    --chat-fullscreen-extra: 0px !important;
  }
  body.chat-convo-fullscreen :is(.chat-shell, .chat-wrap, .chat-layout, .chat-main, .chat-right, .chat-convo, .chat-panel){
    height: 100% !important;
    max-height: none !important;
  }

  /* Let the card body go edge-to-edge, no bottom padding gap */
  body.chat-convo-fullscreen .convo-panel .chat-card-body{
    padding: 0.75rem 0.8rem 0 !important;
  }

  /* Messages should not leave a “mystery gap” under them */
  body.chat-convo-fullscreen .chat-messages{
    padding-bottom: 0.9rem !important;
  }

  /* Make the composer feel like an app bar stuck to the bottom */
  body.chat-convo-fullscreen .chat-compose{
    position: sticky !important;
    bottom: 0 !important;

    /* safe area for iPhone home indicator */
    padding-bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px)) !important;

    /* remove the “floating card” look */
    border-radius: 0 !important;
    margin: 0 !important;

    /* keep it visually anchored */
    box-shadow: 0 -10px 24px rgba(15, 23, 42, 0.06) !important;
  }
}
/* =========================================================
   FIX — Fullscreen: menus must not be clipped by card overflow
   (In fullscreen you already have border-radius:0, so safe.)
   ========================================================= */
@media (max-width: 980px){
  body.chat-convo-fullscreen .convo-panel .chat-card{
    overflow: visible !important;
  }

  /* Also let header be a positioning context that won’t clip */
  body.chat-convo-fullscreen .convo-panel .chat-card-header{
    overflow: visible !important;
  }
}

/* =========================================================
   FIX — Swipe feel: allow horizontal gesture without fighting scroll
   (JS will decide when to preventDefault; CSS just avoids weirdness)
   ========================================================= */
@media (max-width: 980px){
  .chat-bubble{
    /* keep vertical scroll natural; JS will “take over” on true horizontal swipe */
    touch-action: pan-y !important;
    will-change: transform;
  }
}

/* =========================================================
   FINAL LAYOUT STABILITY (desktop + mobile + iOS Safari)
   - removes over-tall chat panels
   - keeps messages as internal scroller
   - preserves fullscreen mode behavior
   ========================================================= */
:root{
  --chat-panel-h-desktop: clamp(560px, calc(100dvh - 230px), 760px);
  --chat-panel-h-mobile-open: 82svh;
  --chat-panel-h-mobile-idle: 72svh;
}
@supports not (height: 100dvh){
  :root{
    --chat-panel-h-desktop: clamp(560px, calc(var(--vh, 1vh) * 100 - 230px), 760px);
  }
}

/* undo old large idle spacing */
body:not(.chat-convo-fullscreen):not(.chat-has-convo) .chat-compose{
  margin-top: 0.7rem !important;
  margin-bottom: 0.45rem !important;
}
body:not(.chat-convo-fullscreen):not(.chat-has-convo) .chat-export-hint{
  margin-top: 0.25rem !important;
}

.chat-shell{
  min-height: 0 !important;
}

@media (min-width: 981px){
  .chat-shell{
    min-height: 0 !important;
    padding-bottom: 1rem !important;
  }

  .people-panel,
  .convo-panel{
    min-height: var(--chat-panel-h-desktop) !important;
    max-height: var(--chat-panel-h-desktop) !important;
  }

  .convo-panel .chat-card-body,
  .convo-panel .chat-thread,
  .convo-panel .chat-messages{
    min-height: 0 !important;
    height: auto !important;
  }
}

@media (max-width: 980px){
  .chat-shell{
    padding: 0.45rem 0.35rem 1rem !important;
    min-height: 0 !important;
  }
  .chat-shell + .site-footer{
    margin-top: 1rem !important;
  }

  .people-panel{
    min-height: 0 !important;
    max-height: none !important;
  }

  body:not(.chat-convo-fullscreen) .convo-panel{
    height: var(--chat-panel-h-mobile-open-px, var(--chat-panel-h-mobile-open)) !important;
    max-height: var(--chat-panel-h-mobile-open-px, var(--chat-panel-h-mobile-open)) !important;
    min-height: 600px !important;
  }
  body:not(.chat-convo-fullscreen).chat-has-convo .convo-panel{
    height: var(--chat-panel-h-mobile-open-px, var(--chat-panel-h-mobile-open)) !important;
    max-height: var(--chat-panel-h-mobile-open-px, var(--chat-panel-h-mobile-open)) !important;
    min-height: 600px !important;
  }
  body:not(.chat-convo-fullscreen):not(.chat-has-convo) .convo-panel{
    height: var(--chat-panel-h-mobile-idle-px, var(--chat-panel-h-mobile-idle)) !important;
    max-height: var(--chat-panel-h-mobile-idle-px, var(--chat-panel-h-mobile-idle)) !important;
    min-height: 560px !important;
  }

  body:not(.chat-convo-fullscreen) .convo-panel .chat-card{
    height: 100% !important;
  }
  body:not(.chat-convo-fullscreen) .convo-panel .chat-card-body{
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
    padding: 0.72rem 0.78rem 0.72rem !important;
  }
  body:not(.chat-convo-fullscreen) .chat-thread{
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
  }
  body:not(.chat-convo-fullscreen) .chat-messages{
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    padding: 0.78rem 0.88rem 0.9rem !important;
  }
  body:not(.chat-convo-fullscreen):not(.chat-has-convo) .chat-messages{
    padding-bottom: 0.35rem !important;
  }

  body:not(.chat-convo-fullscreen) #chat-empty{
    inset: 88px 0 106px 0 !important;
  }
  body:not(.chat-convo-fullscreen):not(.chat-has-convo) #chat-empty{
    position: absolute !important;
    inset: 72px 0 200px 0 !important;
    margin: 0 !important;
    place-items: center !important;
    display: grid !important;
  }
  body:not(.chat-convo-fullscreen).chat-has-convo #chat-empty{
    position: absolute !important;
    inset: 96px 0 188px 0 !important;
    margin: 0 !important;
    place-items: center !important;
  }

  /* Remove empty-state "shadow slab" above composer after clear-chat */
  body:not(.chat-convo-fullscreen) .chat-messages.is-empty{
    background: transparent !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }
  body:not(.chat-convo-fullscreen).chat-has-convo .chat-messages:not(.is-empty) + #chat-empty:not(.force-empty-visible){
    display: none !important;
  }
  body:not(.chat-convo-fullscreen).chat-has-convo .chat-messages.is-empty + #chat-empty,
  body:not(.chat-convo-fullscreen).chat-has-convo #chat-empty.force-empty-visible{
    display: grid !important;
  }

  body:not(.chat-convo-fullscreen) .chat-compose{
    position: sticky !important;
    bottom: 0 !important;
    margin: 0.55rem 0 0.25rem !important;
  }
  body:not(.chat-convo-fullscreen) .chat-export-hint{
    margin: 0.3rem auto 0.1rem !important;
    max-width: calc(100% - 20px) !important;
  }

  /* No-conversation layout: keep composer + hint visually at panel bottom */
  body:not(.chat-convo-fullscreen):not(.chat-has-convo) .chat-thread{
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
  }
  body:not(.chat-convo-fullscreen):not(.chat-has-convo) .chat-messages{
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
  }
  body:not(.chat-convo-fullscreen):not(.chat-has-convo) .chat-compose{
    margin-top: auto !important;
    margin-bottom: 0.3rem !important;
  }
  body:not(.chat-convo-fullscreen):not(.chat-has-convo) .chat-export-hint{
    margin: 0.3rem auto 0.2rem !important;
  }
}

/* =========================================================
   DESKTOP STANDARD MODE (final)
   - larger, app-like chat workspace
   - users list remains visible and scrollable
   - removes mobile-only hint noise on desktop
   ========================================================= */
@media (min-width: 981px){
  :root{
    --chat-panel-h-desktop: clamp(760px, calc(100dvh - 130px), 980px);
  }
  @supports not (height: 100dvh){
    :root{
      --chat-panel-h-desktop: clamp(760px, calc(var(--vh, 1vh) * 100 - 130px), 980px);
    }
  }

  .chat-shell{
    padding-top: 0.7rem !important;
    padding-bottom: 0.8rem !important;
  }

  .chat-shell .section-heading{
    margin-bottom: 0.75rem !important;
  }

  .chat-layout{
    grid-template-columns: minmax(360px, 430px) minmax(0, 1fr) !important;
    gap: 1rem !important;
  }

  .people-panel,
  .convo-panel{
    min-height: var(--chat-panel-h-desktop) !important;
    max-height: var(--chat-panel-h-desktop) !important;
  }

  .people-panel .chat-card-body{
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
    gap: 0.48rem !important;
  }

  .chat-visibility{
    margin-top: 0 !important;
  }

  .toggle-pill{
    gap: 0.48rem;
    font-size: 0.8rem;
  }

  .chat-visibility-note{
    margin-top: 0.14rem;
    font-size: 0.72rem;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #chat-recents-list{
    max-height: 138px !important;
    gap: 0.28rem !important;
  }

  #chat-users{
    flex: 1 1 auto !important;
    min-height: 340px !important;
    max-height: none !important;
    overflow-y: auto !important;
  }

  .chat-scroll-hint-users,
  .chat-scroll-hint-users.is-on{
    display: none !important;
  }

  .convo-panel .chat-thread{
    padding: 0.72rem 0.62rem 0.8rem !important;
  }
  .convo-panel .chat-messages{
    padding: 0.25rem 0.45rem 0.55rem !important;
  }

  .convo-panel .chat-compose{
    margin-top: 0.35rem !important;
    margin-bottom: 0.15rem !important;
    padding: 0.28rem 0.42rem !important;
  }

  .convo-panel .chat-export-hint{
    margin: 0.2rem auto 0.05rem !important;
  }

  body:not(.chat-convo-fullscreen):not(.chat-has-convo) #chat-empty{
    inset: 92px 0 196px 0 !important;
    display: grid !important;
    place-items: center !important;
    text-align: center !important;
  }
}

/* =========================================================
   FINAL HINT POLICY
   - desktop: never show swipe hint chip
   - both: use subtle bottom fade for overflow lists
   ========================================================= */
@media (min-width: 981px){
  .chat-scroll-hint-users,
  .chat-scroll-hint-users.is-on{
    display: none !important;
  }
}

#chat-users.chat-has-overflow,
#chat-recents-list.chat-has-overflow{
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 86%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 86%, transparent 100%);
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
}

/* =========================================================
   DESKTOP FULLSCREEN POLISH
   - center chat content (less edge-to-edge emptiness)
   - keep composer and thread aligned to same rail
   - remove horizontal overflow bar
   ========================================================= */
@media (min-width: 981px){
  body.chat-convo-fullscreen .convo-panel,
  body.chat-convo-fullscreen .convo-panel .chat-card,
  body.chat-convo-fullscreen .convo-panel .chat-thread,
  body.chat-convo-fullscreen .convo-panel .chat-messages{
    overflow-x: hidden !important;
  }

  body.chat-convo-fullscreen .convo-panel .chat-card-body{
    overflow: hidden !important;
  }

  body.chat-convo-fullscreen .convo-panel .chat-card-header{
    width: var(--chat-fs-rail-width) !important;
    max-width: 100% !important;
    margin-inline: auto !important;
    padding-inline: 0.25rem !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    align-items: center !important;
    column-gap: clamp(0.45rem, 1.2vw, 1rem) !important;
    justify-content: normal !important;
  }

  body.chat-convo-fullscreen .convo-panel .chat-card-header .chat-topbar-left{
    min-width: 0 !important;
  }

  body.chat-convo-fullscreen .convo-panel .chat-card-header .chat-header-actions{
    margin-left: 0 !important;
  }

  body.chat-convo-fullscreen .convo-panel .chat-thread{
    padding: 0.9rem 0.85rem 0.85rem !important;
    gap: 0.55rem !important;
    overflow: hidden !important;
  }

  body.chat-convo-fullscreen{
    --chat-fs-rail-width: min(1024px, calc(100vw - clamp(30px, 4vw, 74px)));
  }

  body.chat-convo-fullscreen .convo-panel .chat-e2e-banner,
  body.chat-convo-fullscreen .convo-panel .chat-messages,
  body.chat-convo-fullscreen .convo-panel .chat-replybar,
  body.chat-convo-fullscreen .convo-panel .chat-compose{
    width: var(--chat-fs-rail-width) !important;
    max-width: 100% !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  body.chat-convo-fullscreen .convo-panel .chat-messages{
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    scrollbar-gutter: stable both-edges;
    padding: 0.35rem 0.9rem 0.7rem !important;
  }

  body.chat-convo-fullscreen .convo-panel .chat-compose{
    margin-top: 0.35rem !important;
    margin-bottom: 0.1rem !important;
  }

  body.chat-convo-fullscreen .convo-panel .chat-replybar{
    margin-top: 0.2rem !important;
    margin-bottom: 0.25rem !important;
    padding: 0.5rem 0.62rem !important;
  }

  body.chat-convo-fullscreen .convo-panel .chat-replybar-x{
    width: 38px !important;
    height: 38px !important;
    border-radius: 0.8rem !important;
  }

  body.chat-convo-fullscreen .convo-panel .chat-e2e-banner{
    width: fit-content !important;
    max-width: var(--chat-fs-rail-width) !important;
    margin: 0.2rem auto 0.25rem !important;
  }
}
