/* Shared conversation workspace contract. The legacy selectors remain in
   design-system.css; this file is loaded last so both portals share the same
   responsive behavior while their display data stays portal-specific. */
.plumber-inbox-app,
.plumber-inbox-board,
.plumber-inbox-panel,
.plumber-thread-list,
.plumber-thread-stage,
.plumber-thread-mobile-page,
.conversation-detail-shell,
.conversation-detail-surface {
  min-width: 0;
}

/* Customer pages do not inherit the plumber page's global min-width reset.
   Apply the same constraint to the mobile conversation route so a child
   bubble/composer cannot widen the page beyond the viewport. */
#main-content .customer-page--mobile-chat,
#main-content .customer-page--mobile-chat .customer-section-stack--mobile-chat {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow-x: clip;
}

#main-content .customer-page--mobile-chat .conversation-detail-shell,
#main-content .customer-page--mobile-chat .conversation-detail-shell > .chat-thread-header,
#main-content .customer-page--mobile-chat .conversation-detail-shell > .chat-thread-feed-shell,
#main-content .customer-page--mobile-chat .conversation-detail-shell > .chat-composer,
#main-content .customer-page--mobile-chat .conversation-detail-shell .chat-thread-feed {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.conversation-detail-shell,
.conversation-detail-surface,
.conversation-detail-shell .chat-thread-feed-shell,
.conversation-detail-surface .chat-thread-feed-shell {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.conversation-detail-shell .chat-thread-feed,
.conversation-detail-surface .chat-thread-feed {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.conversation-detail-shell .chat-message,
.conversation-detail-surface .chat-message {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.conversation-detail-shell .chat-message__bubble,
.conversation-detail-surface .chat-message__bubble,
.conversation-detail-shell .chat-message__gallery,
.conversation-detail-surface .chat-message__gallery,
.conversation-detail-shell .chat-message__image,
.conversation-detail-surface .chat-message__image {
  min-width: 0;
  max-width: 100%;
}

.plumber-inbox-board {
  height: clamp(36rem, calc(100dvh - 13rem), 52rem);
  min-height: 36rem;
  width: 100%;
  max-width: 100%;
  grid-template-columns: minmax(18rem, 21rem) minmax(0, 1fr);
  gap: 1rem;
}

/* Notifications use the full workspace width and grow with the document. */
.notification-centre .plumber-inbox-board,
.plumber-inbox-board--notifications {
  grid-template-columns: minmax(0, 1fr);
}

.notification-centre .plumber-inbox-panel--notifications {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.notification-centre .plumber-inbox-app__header > form {
  flex: 0 0 auto;
  margin-left: auto;
}

.notification-centre .notification-feed,
.notification-centre .plumber-notification-feed {
  flex: 0 0 auto;
  min-width: 0;
  min-height: 0;
  max-height: none !important;
  overflow: visible !important;
}

.notification-centre .plumber-inbox-panel--notifications > .notification-empty {
  flex: 1 1 auto;
  min-height: 0;
}

.notification-centre__table-head {
  display: grid;
  grid-template-columns: 2.6rem minmax(0, 1fr) 9rem 5rem;
  align-items: center;
  gap: .9rem;
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-surface-muted, #f8fafc);
  color: var(--color-text-secondary, #64748b);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.notification-centre__table-head span:first-child {
  grid-column: 1 / span 2;
  margin-left: 0;
}

.notification-centre__table-head span:nth-child(2) {
  grid-column: 3;
}

.notification-centre__table-head span:nth-child(3) {
  grid-column: 4;
}

.notification-centre__pagination {
  flex: 0 0 auto;
}

.mobile-infinite-status {
  display: none;
}

@media (min-width: 768px) {
  /* Desktop notification history is a normal page section. Let the document
     grow and scroll rather than trapping the user in a narrow inner feed. */
  .notification-centre .plumber-inbox-board {
    width: 100%;
    max-width: 100%;
    margin-inline: 0;
    height: auto;
    min-height: 0;
  }

  .notification-centre .plumber-inbox-panel--notifications {
    width: 100%;
    max-width: 100%;
    min-height: 32rem;
    overflow: visible;
  }

  .notification-centre .notification-feed,
  .notification-centre .plumber-notification-feed {
    flex: 0 0 auto;
    overflow: visible;
  }
}

.notification-centre .plumber-notification-row {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  text-decoration: none;
}

.notification-centre .plumber-notification-row__copy,
.notification-centre .plumber-notification-row__topline,
.notification-centre .plumber-notification-row__topline h2,
.notification-centre .plumber-notification-row__copy p {
  min-width: 0;
  max-width: 100%;
}

.notification-centre .plumber-notification-row__actions span {
  color: var(--color-primary, #2563eb);
  font-weight: 700;
}

.notification-centre .plumber-notification-row__date {
  color: var(--color-text-secondary, #64748b);
  font-size: .76rem;
  white-space: nowrap;
}

@media (min-width: 768px) {
  .notification-centre .plumber-notification-row {
    grid-template-columns: 2.6rem minmax(0, 1fr) 9rem 5rem;
    align-items: center;
  }

  .notification-centre .plumber-notification-row__topline time {
    display: none;
  }

  .notification-centre .plumber-notification-row__topline {
    justify-content: flex-start;
  }
}

/* Chat-only filter surface. It intentionally does not inherit the generic
   listing grid: search stays on its own lane and chips stay together below it
   at every breakpoint. */
.conversation-filter-panel {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-surface, #fff);
}

.conversation-filter-form {
  display: flex;
  flex-direction: column;
  gap: .7rem;
  width: 100%;
  min-width: 0;
  padding: 1rem;
  box-sizing: border-box;
}

.conversation-filter__search,
.conversation-filter__chips {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  min-width: 0;
}

.conversation-filter__field-label {
  color: var(--color-text-secondary, #475569);
  font-size: .72rem;
  font-weight: 700;
  line-height: 1.2;
}

.conversation-filter__search .list-search-field {
  min-width: 0;
  width: 100%;
}

.conversation-filter__search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: .5rem;
  min-width: 0;
}

.conversation-filter__toggle {
  display: none;
  width: 2.75rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border, #dbe4f0);
  border-radius: .7rem;
  background: var(--color-surface, #fff);
  color: var(--color-text-secondary, #475569);
}

.conversation-filter__toggle svg {
  width: 1rem;
  height: 1rem;
}

.conversation-filter__search .form-input {
  min-height: 2.75rem;
  border-radius: .7rem;
  background: var(--color-surface-muted, #f8fafc);
}

.conversation-filter__chips .plumber-inbox-chipbar {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  min-width: 0;
  padding: 0;
}

.conversation-filter__chips .plumber-inbox-chip {
  min-height: 2.35rem;
  padding-inline: .75rem;
  white-space: nowrap;
}

.plumber-inbox-panel--thread,
.plumber-inbox-panel--thread > *,
.plumber-inbox-panel--thread .plumber-thread-stage,
.plumber-inbox-panel--thread .plumber-inbox-empty {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.plumber-inbox-panel--thread .plumber-thread-stage {
  flex: 1 1 auto;
  overflow: hidden;
}

/* The customer CTA belongs to the inbox header, not the page content flow.
   Keep it at the top-right on desktop and right-align it on phones. */
.plumber-inbox-app__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  min-width: 0;
}

.plumber-inbox-app__header > div:first-child {
  min-width: 0;
}

.plumber-inbox-app__header > div:nth-child(2) {
  flex: 0 0 auto;
  margin-left: auto;
  justify-content: flex-end;
}

.plumber-inbox-app__header > div:nth-child(2) .btn {
  white-space: nowrap;
}

.conversation-inbox__actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

.plumber-inbox-panel--list {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Keep the scrollbar on the list itself so rows reach the panel edge. */
}

.plumber-thread-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}

.plumber-thread-list::-webkit-scrollbar { display: none; }

.plumber-inbox-panel--thread {
  min-width: 0;
}

.plumber-thread-row {
  min-width: 0;
  min-height: 4.5rem;
  align-items: center;
}

.plumber-thread-row__copy,
.plumber-thread-row__topline,
.plumber-thread-row__subtitle,
.plumber-thread-row__preview,
.plumber-thread-row__meta {
  min-width: 0;
}

.plumber-thread-row__topline strong,
.plumber-thread-row__subtitle,
.plumber-thread-row__preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plumber-thread-row__preview {
  display: block;
}

/* Mobile conversation pages use a labelled back action so users always have
   an obvious way to return to the inbox list. */
.plumber-thread-mobile-page__back {
  width: auto;
  min-width: 2.75rem;
  min-height: 2.75rem;
  gap: .35rem;
  padding-inline: .55rem;
  border-radius: .75rem;
  white-space: nowrap;
}

.plumber-thread-mobile-page__back span {
  font-size: .78rem;
  font-weight: 700;
}

.chat-thread-header__back span {
  display: none;
}

.plumber-thread-row:focus-visible,
.plumber-inbox-chip:focus-visible,
.conversation-filter-panel input:focus-visible,
.conversation-filter-panel a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .25);
}

.plumber-thread-stage,
.plumber-thread-mobile-page {
  min-width: 0;
}

.plumber-thread-stage__messages,
.plumber-thread-mobile-page__messages {
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

@media (max-width: 1023px) {
  .plumber-inbox-board {
    height: auto;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
  }

  .plumber-inbox-panel--list {
    max-height: none;
    overflow: visible;
  }

  .plumber-thread-list {
    overflow: visible;
  }

  .plumber-thread-row__topline strong,
  .plumber-thread-row__subtitle,
  .plumber-thread-row__preview {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .plumber-thread-row__preview {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .plumber-inbox-board {
    min-height: calc(100dvh - 10rem);
  }

  .plumber-inbox-panel--list {
    min-height: calc(100dvh - 12rem);
  }
}

@media (max-width: 767px) {
  /* Inbox lists are app surfaces: let them use the full phone width rather
     than inheriting the dashboard content gutter on one side. */
  #main-content .app-content:has(.notification-centre) {
    padding-bottom: 0;
  }

  .portal-page:has(.notification-centre),
  .plumber-page:has(.notification-centre),
  .customer-page:has(.notification-centre) {
    /* app-content already reserves the bottom-nav safe area; the page-level
       padding duplicated it and left a blank band after the final row. */
    padding-bottom: 0;
  }

  #main-content .app-content:has(.plumber-inbox-app),
  .plumber-page:has(.plumber-inbox-app) {
    padding-bottom: 0;
  }

  .plumber-inbox-app {
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: 0;
    min-width: 0;
  }

  .plumber-inbox-app__header {
    padding-inline: 1rem;
    flex-direction: column;
    align-items: stretch;
    gap: .65rem;
  }

  .plumber-inbox-app__header > div:nth-child(2) {
    align-self: flex-end;
    width: auto;
    max-width: 100%;
  }

  .conversation-inbox__actions {
    align-self: flex-end;
    width: auto;
    max-width: 100%;
  }

  .plumber-inbox-app__header > div:nth-child(2) .btn {
    min-height: 2.75rem;
  }

  .plumber-inbox-app__header > div:nth-child(2) .btn-danger {
    padding-inline: 1rem;
  }

  .notification-centre .plumber-inbox-app__header > form {
    align-self: flex-end;
    max-width: 100%;
  }

  .plumber-inbox-board {
    width: 100%;
    margin-inline: 0;
    gap: .75rem;
    height: auto;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
    overflow-x: clip;
  }

  .notification-centre .plumber-inbox-board {
    width: 100%;
    max-width: 100%;
    margin-inline: 0;
    height: auto;
    min-height: 0;
  }

  .notification-centre .plumber-inbox-panel--notifications {
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
  }

  .plumber-inbox-app .plumber-inbox-panel--list {
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
  }

  .plumber-inbox-app .plumber-thread-list {
    height: auto;
    min-height: 0;
    max-height: none !important;
    overflow: visible !important;
  }

  .notification-centre__table-head {
    display: none;
  }

  .notification-centre__pagination {
    display: none;
  }

  .plumber-inbox__pagination {
    display: none;
  }

  .mobile-infinite-status {
    display: block;
    margin: .65rem 1rem .85rem;
    color: var(--color-text-secondary, #64748b);
    font-size: .7rem;
    text-align: center;
  }

  .notification-centre .notification-feed,
  .notification-centre .plumber-notification-feed {
    max-height: none !important;
    overflow: visible !important;
  }

  .notification-centre .plumber-notification-row {
    width: 100%;
    grid-template-columns: 2.6rem minmax(0, 1fr) !important;
    align-items: start;
    padding: .85rem .75rem;
    gap: .65rem;
  }

  .notification-centre .plumber-notification-row__date {
    display: none;
  }

  .notification-centre .plumber-notification-row__topline {
    align-items: flex-start;
    gap: .5rem;
  }

  .notification-centre .plumber-notification-row__topline h2 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
  }

  .notification-centre .plumber-notification-row__topline time {
    flex: 0 0 auto;
    margin-top: .15rem;
    font-size: .65rem;
    white-space: nowrap;
  }

  .notification-centre .plumber-notification-row__copy p {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
    white-space: normal;
  }

  .notification-centre .plumber-notification-row__actions {
    grid-column: 2;
    min-width: 0;
    justify-content: space-between;
    margin-top: -.15rem;
  }

  .plumber-inbox-panel--list,
  .plumber-thread-list {
    width: 100%;
    max-width: none;
    box-sizing: border-box;
  }

  .plumber-inbox-panel--list {
    height: max(22rem, calc(100dvh - var(--app-header-height, 4rem) - var(--mobile-bottom-nav-space, 5.75rem) - 1.25rem));
    min-height: max(22rem, calc(100dvh - var(--app-header-height, 4rem) - var(--mobile-bottom-nav-space, 5.75rem) - 1.25rem));
    max-height: max(22rem, calc(100dvh - var(--app-header-height, 4rem) - var(--mobile-bottom-nav-space, 5.75rem) - 1.25rem));
    overflow: hidden;
  }

  .plumber-thread-list {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .plumber-inbox-panel--list > .plumber-inbox-empty {
    flex: 1 1 auto;
    min-height: 0;
  }

  .plumber-inbox-panel,
  .plumber-thread-mobile-page {
    border: 1px solid var(--color-border, #e2e8f0) !important;
    border-radius: 1rem !important;
    box-shadow: var(--shadow-sm, 0 8px 24px rgba(15, 23, 42, .06)) !important;
  }

  .conversation-filter-form {
    gap: .55rem;
    padding: .75rem;
  }

  .conversation-filter__field-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .conversation-filter__toggle {
    display: inline-flex;
  }

  .conversation-filter__chips .plumber-inbox-chipbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0;
    scrollbar-width: none;
  }

  .conversation-filter__chips .plumber-inbox-chipbar.is-collapsed-mobile {
    display: none;
  }

  .conversation-filter__chips .plumber-inbox-chipbar::-webkit-scrollbar {
    display: none;
  }

  .conversation-filter__chips .plumber-inbox-chip {
    flex: 0 0 auto;
    min-height: 2.45rem;
  }

  .plumber-thread-stage__icon,
  .plumber-thread-mobile-page__icon {
    width: 2.75rem;
    height: 2.75rem;
    flex: 0 0 2.75rem;
    border-radius: .75rem;
  }

  .plumber-inbox-chipbar {
    padding: .5rem .75rem .75rem;
    gap: .4rem;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  .plumber-inbox-chipbar::-webkit-scrollbar {
    display: none;
  }

  .plumber-inbox-chip {
    min-height: 2.5rem;
    flex: 0 0 auto;
    padding-inline: .75rem;
  }

  .plumber-thread-row,
  .plumber-notification-row {
    padding: .85rem .75rem;
    gap: .65rem;
  }

  .plumber-thread-row {
    grid-template-columns: 2.5rem minmax(0, 1fr) auto;
  }

  .plumber-thread-row__topline {
    gap: .4rem;
  }

  .plumber-thread-row__topline strong,
  .plumber-thread-row__subtitle {
    font-size: .8rem;
  }

  .plumber-thread-row__preview {
    font-size: .74rem;
    line-height: 1.35;
  }

  .plumber-thread-row__meta {
    align-self: start;
  }

  .plumber-thread-mobile-page {
    height: 100%;
    min-height: 0;
    margin-inline: 0;
  }

  /* Compact mobile detail header: participant and job context stay readable,
     while the global dashboard bar is intentionally removed for this focused
     conversation route. */
  .plumber-thread-mobile-page__header,
  .chat-thread-header--mobile {
    min-height: 3.75rem;
    padding: .5rem .65rem;
    gap: .45rem;
  }

  .plumber-thread-mobile-page__back span,
  .chat-thread-header__back span {
    display: none;
  }

  .plumber-thread-mobile-page__back,
  .plumber-thread-mobile-page__icon,
  .chat-thread-header__back,
  .chat-thread-header__icon {
    width: 2.35rem;
    min-width: 2.35rem;
    height: 2.35rem;
    min-height: 2.35rem;
    padding: 0;
    border-radius: .65rem;
  }

  .plumber-thread-mobile-page__header .chat-thread-header__avatar,
  .chat-thread-header--mobile .chat-thread-header__avatar {
    width: 2.15rem;
    height: 2.15rem;
  }

  .plumber-thread-mobile-page__header .chat-thread-header__copy h1,
  .chat-thread-header--mobile .chat-thread-header__copy h1,
  .chat-thread-header--mobile .chat-thread-header__copy h2 {
    font-size: .82rem;
    line-height: 1.2;
  }

  .plumber-thread-mobile-page__header .chat-thread-header__copy p,
  .chat-thread-header--mobile .chat-thread-header__copy p {
    font-size: .68rem;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .plumber-thread-mobile-page__header .chat-thread-header__copy > span,
  .chat-thread-header--mobile .chat-thread-header__copy > span {
    display: none;
  }

  .plumber-thread-mobile-page__composer,
  .plumber-thread-composer {
    padding: .75rem;
    padding-bottom: calc(.75rem + env(safe-area-inset-bottom));
  }

  .plumber-thread-mobile-page__composer textarea,
  .plumber-thread-composer textarea {
    min-height: 2.9rem;
    max-height: 9rem;
  }

  .chat-surface--conversation {
    min-height: 0;
    height: 100%;
  }

  .plumber-chat-bubble__content {
    max-width: min(88%, 28rem);
    overflow-wrap: anywhere;
  }

  .chat-thread-header__back {
    width: auto;
    min-width: 2.75rem;
    padding-inline: .55rem;
    gap: .35rem;
    white-space: nowrap;
  }

  .chat-thread-header__back span {
    display: none;
  }
}

@media (max-width: 767px) {
  /* mobile_chat_mode removes the fixed dashboard header, so the conversation
     surface can occupy the complete viewport instead of losing 4rem above. */
  .app-shell--mobile-chat {
    padding-top: 0 !important;
  }

  .app-shell--mobile-detail #main-content.app-main--mobile-chat,
  #main-content.app-main--mobile-chat {
    height: 100dvh;
    min-height: 100dvh;
  }

  #main-content.app-main--mobile-chat .plumber-page--mobile-chat .plumber-thread-mobile-page,
  #main-content.app-main--mobile-chat .customer-page--mobile-chat .plumber-thread-mobile-page {
    width: 100%;
    max-width: 100%;
    margin-inline: 0;
    box-sizing: border-box;
    height: 100%;
    min-height: 0;
  }

  #main-content.app-main--mobile-chat .customer-page--mobile-chat .customer-section-stack--mobile-chat,
  #main-content.app-main--mobile-chat .plumber-page--mobile-chat .section-stack--mobile-chat {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
}

html.dark .plumber-inbox-panel,
html.dark .plumber-thread-mobile-page {
  border-color: var(--color-border, #334155) !important;
}

/* Shared Flowbite-style message primitives.  The same structure is used for
   text, single-image, and gallery messages in both portals. */
.conversation-detail-shell .chat-message,
.conversation-detail-surface .chat-message {
  align-items: flex-start;
  position: relative;
}

.conversation-detail-shell .chat-message__stack,
.conversation-detail-surface .chat-message__stack {
  display: flex;
  flex: 0 1 auto;
  width: fit-content;
  min-width: 0;
  max-width: min(38rem, 84%);
  flex-direction: column;
  gap: .28rem;
  position: relative;
}

.chat-message__content-row {
  display: flex;
  align-items: center;
  gap: .35rem;
  min-width: 0;
  max-width: 100%;
}

.chat-message__content-row.is-own {
  justify-content: flex-end;
}

/* Keep actions beside the bubble: own-message actions sit on the bubble's
   left, while incoming actions sit on its right. */
.conversation-detail-shell .chat-message:not(.is-own) .chat-message__actions,
.conversation-detail-surface .chat-message:not(.is-own) .chat-message__actions {
  order: 2;
}

.conversation-detail-shell .chat-message:not(.is-own) .chat-message__stack,
.conversation-detail-surface .chat-message:not(.is-own) .chat-message__stack {
  order: 1;
}

.conversation-detail-shell .chat-message.is-own .chat-message__stack,
.conversation-detail-surface .chat-message.is-own .chat-message__stack {
  order: 2;
}

.conversation-detail-shell .chat-message.is-own .chat-message__actions,
.conversation-detail-surface .chat-message.is-own .chat-message__actions {
  order: -1;
}

.conversation-detail-shell .chat-message.is-own .chat-message__stack,
.conversation-detail-surface .chat-message.is-own .chat-message__stack {
  align-items: flex-end;
}

.conversation-detail-shell .chat-message__bubble,
.conversation-detail-surface .chat-message__bubble {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: visible;
}

/* Message variants keep their content-sized shape instead of inheriting the
   full stack width. Attachments remain wide enough for previews, while plain
   text stays readable without looking like an empty panel. */
.conversation-detail-shell .chat-message__bubble.is-text-only,
.conversation-detail-surface .chat-message__bubble.is-text-only {
  width: auto;
  max-width: min(32rem, 100%);
  align-self: flex-start;
}

.conversation-detail-shell .chat-message.is-own .chat-message__bubble.is-text-only,
.conversation-detail-surface .chat-message.is-own .chat-message__bubble.is-text-only {
  align-self: flex-end;
}

.conversation-detail-shell .chat-message__bubble.is-media-only,
.conversation-detail-surface .chat-message__bubble.is-media-only {
  width: min(28rem, 100%);
  max-width: min(28rem, 100%);
}

.conversation-detail-shell .chat-message__bubble.is-text-with-media,
.conversation-detail-surface .chat-message__bubble.is-text-with-media {
  width: min(28rem, 100%);
  max-width: min(28rem, 100%);
}

.conversation-detail-shell .chat-message__bubble p,
.conversation-detail-surface .chat-message__bubble p {
  overflow-wrap: anywhere;
}

.chat-message__topline {
  display: flex;
  align-items: center;
  gap: .45rem;
  min-height: 1.05rem;
  padding-inline: .2rem;
  color: #64748b;
  font-size: .7rem;
  line-height: 1.2;
}

.chat-message__sender {
  color: #334155;
  font-weight: 700;
}

.chat-message__topline time {
  white-space: nowrap;
}

.conversation-detail-shell .chat-message__meta,
.conversation-detail-surface .chat-message__meta {
  min-height: .9rem;
  width: 100%;
  padding-inline: .2rem;
  justify-content: flex-start;
  font-size: .68rem;
  font-weight: 600;
}

.conversation-detail-shell .chat-message.is-own .chat-message__meta,
.conversation-detail-surface .chat-message.is-own .chat-message__meta {
  justify-content: flex-end;
}

.chat-message__actions {
  position: relative;
  flex: 0 0 auto;
  align-self: center;
  margin-top: 1.25rem;
}

.conversation-detail-shell .chat-message__actions,
.conversation-detail-surface .chat-message__actions {
  position: relative;
  inset: auto;
  z-index: 3;
  margin: 0;
  align-self: center;
}

.conversation-detail-shell .chat-message.is-own .chat-message__actions,
.conversation-detail-surface .chat-message.is-own .chat-message__actions {
  inset: auto;
}

.chat-message__menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: .55rem;
  background: transparent;
  color: #64748b;
  box-shadow: none;
  visibility: visible;
  opacity: 1 !important;
  pointer-events: auto;
  transition: opacity .15s ease, background-color .15s ease, color .15s ease;
}

.chat-message__menu-dots {
  display: inline-block;
  color: currentColor;
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1;
  transform: translateY(-.08rem);
}

.chat-message__menu-toggle:hover,
.chat-message__menu-toggle:focus-visible,
.chat-message__actions.is-open .chat-message__menu-toggle {
  background: transparent;
  color: #334155;
  outline: none;
}

.chat-message:hover .chat-message__menu-toggle,
.chat-message:focus-within .chat-message__menu-toggle,
.chat-message__actions.is-open .chat-message__menu-toggle {
  opacity: 1;
}

.chat-message__menu-toggle svg,
.chat-message__menu-item svg {
  width: 1rem;
  height: 1rem;
  flex: 0 0 auto;
}

.chat-message__menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + .3rem);
  right: 0;
  width: 8.75rem;
  padding: .3rem;
  border: 1px solid #e2e8f0;
  border-radius: .7rem;
  background: #fff;
  box-shadow: 0 14px 30px -20px rgba(15, 23, 42, .55);
}

.conversation-detail-shell .chat-message:not(.is-own) .chat-message__menu,
.conversation-detail-surface .chat-message:not(.is-own) .chat-message__menu {
  left: calc(100% + .3rem);
  right: auto;
}

.conversation-detail-shell .chat-message.is-own .chat-message__menu,
.conversation-detail-surface .chat-message.is-own .chat-message__menu {
  left: auto;
  right: calc(100% + .3rem);
}

.chat-message.is-own .chat-message__menu {
  right: 0;
}

.chat-message__menu-item {
  display: flex;
  align-items: center;
  gap: .55rem;
  width: 100%;
  padding: .5rem .55rem;
  border: 0;
  border-radius: .45rem;
  background: transparent;
  color: #334155;
  font-size: .74rem;
  font-weight: 600;
  text-align: left;
}

.chat-message__menu-item:hover,
.chat-message__menu-item:focus-visible {
  background: #eff6ff;
  color: #1d4ed8;
  outline: none;
}

.chat-message__image-wrap {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border-radius: 1rem;
}

.chat-message__image-wrap .chat-message__image {
  display: block;
  width: 100%;
  height: 100%;
}

html.dark .chat-message__sender,
html.dark .chat-message__menu-item {
  color: #e2e8f0;
}

html.dark .chat-message__menu {
  border-color: #334155;
  background: #0f172a;
}

html.dark .chat-message__menu-item:hover,
html.dark .chat-message__menu-item:focus-visible,
html.dark .chat-message__menu-toggle:hover,
html.dark .chat-message__menu-toggle:focus-visible {
  background: transparent;
  color: #dbeafe;
}

@media (max-width: 767px) {
  .conversation-detail-shell .chat-message__stack,
  .conversation-detail-surface .chat-message__stack {
    flex-basis: min(100%, calc(100% - 2.55rem));
    max-width: min(100%, calc(100% - 2.55rem));
  }

  /* Keep mobile bubbles compact and predictable. Media should never take
     the full conversation width, while text can still grow naturally. */
  .conversation-detail-shell .chat-message__bubble.is-media-only,
  .conversation-detail-surface .chat-message__bubble.is-media-only {
    width: min(14rem, 82vw);
    max-width: min(14rem, 82vw);
    padding: .45rem;
  }

  .conversation-detail-shell .chat-message__bubble.is-text-only,
  .conversation-detail-surface .chat-message__bubble.is-text-only {
    width: auto;
    max-width: min(18rem, 78vw);
    padding-inline: .8rem;
  }

  .conversation-detail-shell .chat-message__bubble.is-text-with-media,
  .conversation-detail-surface .chat-message__bubble.is-text-with-media {
    width: min(18rem, 82vw);
    max-width: min(18rem, 82vw);
  }

  .conversation-detail-shell .chat-message__gallery,
  .conversation-detail-surface .chat-message__gallery {
    width: min(100%, 14rem);
    max-width: 100%;
    gap: .4rem;
  }

  .conversation-detail-shell .chat-message__gallery.is-single,
  .conversation-detail-surface .chat-message__gallery.is-single {
    width: min(12.5rem, 74vw);
    max-width: 100%;
  }

  .conversation-detail-shell .chat-message__gallery.is-single .chat-message__image img,
  .conversation-detail-surface .chat-message__gallery.is-single .chat-message__image img {
    max-height: 10.5rem;
    aspect-ratio: 4 / 5;
  }

  .chat-message__topline {
    font-size: .64rem;
  }

  .chat-message__menu-toggle {
    opacity: 1;
  }

  .chat-message__actions {
    margin: 0;
  }

  .chat-message__menu {
    right: 0;
    width: 8.25rem;
  }
}
