/**
 * Floating Team Messages popup — FAB + two-panel modal (portal overlay).
 */

:root {
  --jp-tm-accent: #912061;
  --jp-tm-accent-hover: #a52974;
  --jp-tm-accent-deep: #6d1849;
  --jp-tm-sent-bg: #1e1e2e;
  --jp-tm-received-bg: #f1f5f9;
  --jp-tm-row-active: #ebe8f9;
  --jp-tm-dot: #e11d74;
}

.jp-global-chat-fab.jp-tm-popup__fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10001;
  width: 56px;
  height: 56px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 50%;
  background: var(--jp-tm-accent);
  box-shadow:
    0 8px 24px rgba(145, 32, 97, 0.42),
    inset 0 -3px 0 rgba(109, 24, 73, 0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.jp-global-chat-fab.jp-tm-popup__fab:hover {
  transform: scale(1.06);
  box-shadow:
    0 12px 32px rgba(145, 32, 97, 0.5),
    inset 0 -3px 0 rgba(109, 24, 73, 0.38);
}

.jp-global-chat-fab.jp-tm-popup__fab:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.jp-tm-popup__fab-icon {
  display: block;
  width: 26px;
  height: 26px;
}

.jp-tm-popup__fab-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  box-sizing: border-box;
  border-radius: 999px;
  background: var(--jp-tm-dot);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  pointer-events: none;
  z-index: 2;
}

.jp-tm-popup__fab-badge[hidden] {
  display: none !important;
}

.jp-tm-popup[hidden] {
  display: none !important;
}

.jp-tm-popup {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 10000;
  width: min(624px, calc(100vw - 48px));
  height: min(682px, calc((100vh - 140px) * 1.3));
  max-height: min(calc((100vh - 140px) * 1.3), calc(100vh - 72px));
  box-sizing: border-box;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18), 0 4px 12px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--jp-font-sans, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
  color: #0f172a;
}

.jp-tm-popup__chrome {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.jp-tm-popup__topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid #e8ecf2;
}

.jp-tm-popup__topbar-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #0f172a;
}

.jp-tm-popup__close {
  margin: 0;
  padding: 4px 10px;
  border: none;
  background: transparent;
  font-size: 1.35rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  border-radius: 8px;
}

.jp-tm-popup__close:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.jp-tm-popup__panels {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-height: 0;
}

.jp-tm-popup__sidebar {
  width: 38%;
  min-width: 160px;
  max-width: 200px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #e8ecf2;
  background: #fafbfc;
  min-height: 0;
}

.jp-tm-popup__sidebar-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
  border-bottom: 1px solid #e8ecf2;
}

.jp-tm-popup__sidebar-head-text {
  min-width: 0;
  flex: 1;
}

.jp-tm-popup__sidebar-collapse-btn {
  flex-shrink: 0;
  margin: 0;
  padding: 4px;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.jp-tm-popup__sidebar-collapse-btn:hover {
  background: rgba(15, 23, 42, 0.06);
  color: #0f172a;
}

.jp-tm-popup__sidebar-collapse-icon {
  display: block;
  transition: transform 0.18s ease;
}

.jp-tm-popup__sidebar-collapsible {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.jp-tm-popup__sidebar--collapsed {
  width: 44px;
  min-width: 44px;
  max-width: 44px;
}

.jp-tm-popup__sidebar--collapsed .jp-tm-popup__sidebar-collapsible {
  display: none;
}

.jp-tm-popup__sidebar--collapsed .jp-tm-popup__sidebar-head-text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.jp-tm-popup__sidebar--collapsed .jp-tm-popup__sidebar-head {
  justify-content: center;
  position: relative;
}

.jp-tm-popup__sidebar--collapsed .jp-tm-popup__sidebar-collapse-icon {
  transform: rotate(180deg);
}

.jp-tm-popup__conv-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.jp-tm-popup__conv-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.jp-tm-popup__conv-item {
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 8px 8px;
  cursor: pointer;
  border-bottom: 1px solid #eef1f5;
  background: transparent;
  border-left: 3px solid transparent;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  font: inherit;
  color: inherit;
}

.jp-tm-popup__conv-item:hover {
  background: rgba(15, 23, 42, 0.04);
}

.jp-tm-popup__conv-item--active {
  background: var(--jp-tm-row-active);
  border-left-color: var(--jp-tm-accent);
}

.jp-tm-popup__conv-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.jp-tm-popup__conv-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.jp-tm-popup__conv-avatar--ph {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
}

.jp-tm-popup__conv-avatar--tone-0 { background: var(--jp-tm-accent); }
.jp-tm-popup__conv-avatar--tone-1 { background: #2563eb; }
.jp-tm-popup__conv-avatar--tone-2 { background: #0891b2; }
.jp-tm-popup__conv-avatar--tone-3 { background: #7c3aed; }
.jp-tm-popup__conv-avatar--tone-4 { background: #db2777; }
.jp-tm-popup__conv-avatar--tone-5 { background: #0d9488; }

.jp-tm-popup__conv-unread-dot {
  position: absolute;
  top: -1px;
  right: -1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--jp-tm-dot);
  border: 2px solid #fafbfc;
}

.jp-tm-popup__conv-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.jp-tm-popup__conv-row1 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.jp-tm-popup__conv-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.jp-tm-popup__conv-time {
  flex-shrink: 0;
  font-size: 0.68rem;
  color: #94a3b8;
  max-width: 44px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.jp-tm-popup__conv-preview {
  font-size: 0.72rem;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.jp-tm-popup__empty-list {
  padding: 12px 10px;
  margin: 0;
  font-size: 0.8rem;
}

.jp-tm-popup__sidebar-foot {
  flex-shrink: 0;
  padding: 8px;
  border-top: 1px solid #e8ecf2;
  background: #fff;
}

.jp-tm-popup__btn-new {
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  border-bottom: 2px solid var(--jp-tm-accent-deep);
  box-sizing: border-box;
  background: var(--jp-tm-accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}

.jp-tm-popup__btn-new:hover {
  background: var(--jp-tm-accent-hover);
}

.jp-tm-popup__new-panel {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed #e2e8f0;
}

.jp-tm-popup__new-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: #475569;
}

.jp-tm-popup__new-select {
  width: 100%;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  font-size: 0.78rem;
  box-sizing: border-box;
}

.jp-tm-popup__new-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

.jp-tm-popup__btn-primary,
.jp-tm-popup__btn-secondary {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
}

.jp-tm-popup__btn-primary {
  background: var(--jp-tm-accent);
  color: #fff;
}

.jp-tm-popup__btn-secondary {
  background: #f1f5f9;
  color: #334155;
}

.jp-tm-popup__divider {
  width: 1px;
  background: #e8ecf2;
  flex-shrink: 0;
}

.jp-tm-popup__main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.jp-tm-popup__chat-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid #e8ecf2;
}



.jp-tm-popup__peer-avatar-slot {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.jp-tm-popup__chat-head-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.jp-tm-popup__peer-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}

.jp-tm-popup__peer-avatar--ph {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
}

.jp-tm-popup__peer-text {
  min-width: 0;
}

.jp-tm-popup__peer-name {
  font-size: 0.88rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.jp-tm-popup__peer-sub {
  font-size: 0.68rem;
}

.jp-tm-popup__chat-head-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.jp-tm-popup__icon-btn {
  border: none;
  background: transparent;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  color: #64748b;
  line-height: 1;
  font-size: 1.1rem;
}

.jp-tm-popup__icon-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.jp-tm-popup__menu {
  position: relative;
}

.jp-tm-popup__dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  min-width: 180px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.12);
  z-index: 5;
  padding: 4px 0;
}

.jp-tm-popup__dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  text-align: left;
  font-size: 0.82rem;
  cursor: pointer;
  color: #334155;
}

.jp-tm-popup__dropdown-item:hover {
  background: #f8fafc;
}

.jp-tm-popup__dropdown-item--danger {
  color: #b91c1c;
}

.jp-tm-popup__thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 12px 22px;
  background: #fff;
}

.jp-tm-popup__thread-placeholder {
  font-size: 0.82rem;
  padding: 24px 8px;
  text-align: center;
}

.jp-tm-popup__messages {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.jp-tm-popup .jp-msg-row {
  max-width: 100%;
  overflow: visible;
  margin-bottom: 22px;
}

/* Stack: message card + optional attachment strip (reactions anchor on card OR strip) */
.jp-tm-popup-msg-unit {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  max-width: 92%;
}

.jp-tm-popup .jp-msg-bubble.jp-tm-popup-msg-bubble.jp-tm-popup-msg-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: visible;
  width: 100%;
  max-width: none;
  padding: 8px 10px 12px;
  box-sizing: border-box;
}

.jp-tm-popup-msg-unit--has-attach .jp-msg-bubble.jp-tm-popup-msg-card {
  padding-bottom: 8px;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.jp-tm-popup-attach-slot {
  position: relative;
  width: 100%;
  margin-top: -1px;
  padding-bottom: 0;
  box-sizing: border-box;
  overflow: visible;
}

/* Incoming sender: compact avatar (photo or initials), not display name */
.jp-tm-popup-msg-avatar-wrap {
  flex-shrink: 0;
  align-self: flex-start;
}

.jp-tm-popup-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.jp-tm-popup-msg-avatar.jp-tm-popup-msg-avatar--ph {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  font-weight: 700;
  color: #fff;
}

.jp-tm-popup-msg-content-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  width: 100%;
}

.jp-tm-popup-msg-main {
  flex: 1 1 0%;
  min-width: 0;
}

.jp-tm-popup .jp-msg-body-txt {
  font-size: 0.875rem;
  line-height: 1.45;
  word-break: normal;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  max-width: 100%;
}

.jp-tm-popup-msg-time-wrap {
  flex-shrink: 0;
  line-height: 1.35;
}

.jp-tm-popup-msg-time {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--jp-text-muted, #64748b);
  white-space: nowrap;
}

/* Attachment strip sits below message card (flush seam) */
.jp-tm-popup-attach-slot .jp-msg-attach-banner.jp-msg-attach-banner--thread.jp-tm-popup-thread-attach {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 8px 10px 14px;
  border: 1px solid #34d399;
  border-radius: 0 0 10px 10px;
  background: linear-gradient(180deg, #ecfdf5 0%, #d1fae5 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

/* Reactions: bottom-left, half on / half off (Instagram-style straddle) */
.jp-tm-popup-msg-unit .jp-msg-reactions {
  position: absolute;
  left: 10px;
  bottom: 0;
  transform: translateY(50%);
  margin-top: 0;
  z-index: 3;
  display: flex;
  flex-wrap: wrap-reverse;
  justify-content: flex-start;
  align-items: center;
  gap: 4px;
  max-width: calc(100% - 20px);
  pointer-events: auto;
}

.jp-tm-popup .jp-msg-reaction-chip {
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.jp-tm-popup .jp-msg-reaction-chip:hover {
  background: rgba(30, 41, 59, 0.96);
}

.jp-tm-popup .jp-msg-reaction-chip--mine {
  border-color: rgba(145, 32, 97, 0.55);
  background: rgba(72, 18, 50, 0.95);
}

.jp-tm-popup .jp-msg-reaction-count {
  color: rgba(248, 250, 252, 0.88);
}

.jp-tm-popup .jp-msg-reaction-chip:focus-visible {
  outline: 2px solid var(--jp-tm-accent, #912061);
  outline-offset: 2px;
}

/* Compose attach banner: full filename wraps (narrow popup). */
.jp-tm-popup .jp-msg-attach-banner {
  align-items: flex-start;
}

.jp-tm-popup .jp-msg-attach-banner-name {
  flex: 1 1 0;
  min-width: 0;
  white-space: normal;
  word-break: break-word;
  overflow: visible;
  text-overflow: unset;
}

.jp-tm-popup .jp-msg-thread-attach-link {
  display: block;
  width: 100%;
  box-sizing: border-box;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
  overflow: visible;
  text-overflow: unset;
}

.jp-tm-popup__compose-foot.jp-msg-compose {
  flex-shrink: 0;
  padding: 10px 12px;
}

.jp-tm-popup__compose-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.jp-tm-popup__compose-form--disabled .jp-msg-attach-btn {
  pointer-events: none;
  opacity: 0.45;
}

.jp-tm-popup .jp-msg-compose-field {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
}

.jp-tm-popup .jp-msg-compose textarea {
  min-height: 52px;
  max-height: 96px;
}

.jp-tm-popup__send {
  flex-shrink: 0;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  border-bottom: 2px solid var(--jp-tm-accent-deep);
  box-sizing: border-box;
  background: var(--jp-tm-accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}

.jp-tm-popup__send:hover {
  background: var(--jp-tm-accent-hover);
}

.jp-tm-popup__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.jp-tm-popup__compose-err {
  color: #b91c1c;
}

.jp-msg-muted {
  color: #64748b;
}

@media (max-width: 520px) {
  .jp-tm-popup__panels {
    flex-direction: column;
  }
  .jp-tm-popup__sidebar {
    width: 100%;
    max-width: none;
    border-right: none;
    border-bottom: 1px solid #e8ecf2;
    max-height: 38%;
  }
  .jp-tm-popup__sidebar.jp-tm-popup__sidebar--collapsed {
    width: 100%;
    max-width: none;
    max-height: 52px;
    flex-shrink: 0;
    min-width: 0;
  }
  .jp-tm-popup__divider {
    display: none;
  }
}

.jp-tm-popup__icon-btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}
