/* Global messages widget — sits beside AI FAB */

/* Shared dimmer (also defined in ai/chat.css for pages without messages CSS order) */
.hmj-chat-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1388;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.hmj-chat-backdrop.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

body.hmj-chat-overlay-open {
  overflow: hidden;
}

.hmj-msg {
  --msg-accent: var(--hmj-primary, #0F9F8A);
  --msg-accent-dark: var(--hmj-primary-dark, #087F70);
  --msg-fab: 3.5rem;
  --msg-z: 1395;
  --msg-gap: 0.65rem;
  position: relative;
  z-index: var(--msg-z);
  pointer-events: none;
  font-family: inherit;
}

.hmj-msg>* {
  pointer-events: auto;
}

.hmj-msg__launcher {
  position: fixed;
  /* beside AI: AI at inline-end, messages one FAB to the center */
  inset-inline-end: calc(1.15rem + var(--msg-fab) + var(--msg-gap));
  bottom: 1.15rem;
  width: var(--msg-fab);
  height: var(--msg-fab);
  border: 0;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--msg-accent), var(--msg-accent-dark));
  color: #fff;
  box-shadow: 0 10px 28px rgba(18, 140, 126, 0.4), 0 2px 8px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: calc(var(--msg-z) + 2);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.28s ease;
}

body.has-bottom-nav .hmj-msg__launcher {
  bottom: var(--hmj-fab-bottom, 1.15rem);
}

/* when AI is hidden, messages takes primary FAB spot */
body.has-hidden-ai .hmj-msg__launcher {
  inset-inline-end: 1.15rem;
}

.hmj-msg__launcher:hover {
  transform: translateY(-2px) scale(1.04);
}

.hmj-msg__launcher-icon {
  position: absolute;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  transition: opacity 0.2s ease, transform 0.28s ease;
}

.hmj-msg__launcher-icon--close {
  opacity: 0;
  transform: rotate(-40deg) scale(0.6);
}

.hmj-msg.is-open .hmj-msg__launcher-icon--open {
  opacity: 0;
  transform: rotate(40deg) scale(0.6);
}

.hmj-msg.is-open .hmj-msg__launcher-icon--close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

.hmj-msg__badge {
  position: absolute;
  top: -2px;
  inset-inline-start: -2px;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: #e11d48;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 8px rgba(225, 29, 72, 0.45);
  line-height: 1;
}

.hmj-msg__badge[hidden] {
  display: none !important;
}

.hmj-msg__panel {
  position: fixed;
  inset-inline-end: 1rem;
  bottom: calc(1.15rem + var(--msg-fab) + 0.75rem);
  width: min(400px, calc(100vw - 1.5rem));
  height: min(620px, calc(100dvh - 6.5rem));
  max-height: calc(100dvh - 5.5rem);
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 22px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
  overflow: hidden;
  z-index: calc(var(--msg-z) + 1);
  transform-origin: bottom center;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), visibility 0.28s;
}

body.has-bottom-nav .hmj-msg__panel {
  bottom: calc(var(--hmj-fab-bottom, 1.15rem) + var(--msg-fab) + 0.75rem);
  max-height: calc(100dvh - var(--hmj-fab-bottom, 1.15rem) - 8rem);
}

.hmj-msg.is-open .hmj-msg__panel {
  opacity: 1;
  transform: none;
  pointer-events: auto;
  visibility: visible;
}

.hmj-msg__head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 0.95rem;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  background: linear-gradient(165deg, #f0fdfa, #fff 70%);
  flex-shrink: 0;
}

.hmj-msg__brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  flex: 1;
}

.hmj-msg__avatar {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(18, 140, 126, 0.12);
  color: var(--msg-accent);
  flex-shrink: 0;
}

.hmj-msg__eyebrow {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  color: #64748b;
  letter-spacing: 0.02em;
}

.hmj-msg__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hmj-msg__icon-btn {
  width: 2.1rem;
  height: 2.1rem;
  border: 0;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.05);
  color: #475569;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.hmj-msg__icon-btn:hover {
  background: rgba(15, 23, 42, 0.1);
}

.hmj-msg__head-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.hmj-msg__icon-btn[hidden],
.hmj-msg__back[hidden] {
  display: none !important;
}

/* Inbox rows — same pattern as AI history items */
.hmj-msg__conv-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 0.5rem;
  align-items: start;
  margin: 0.35rem 0.65rem;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: #fff;
  border-radius: 12px;
  padding: 0.55rem 0.6rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.hmj-msg__conv-wrap:hover,
.hmj-msg__conv-wrap:focus-within {
  border-color: color-mix(in srgb, var(--msg-accent) 45%, rgba(15, 23, 42, 0.08));
  background: color-mix(in srgb, var(--msg-accent) 6%, #fff);
}

.hmj-msg__conv-wrap.is-unread {
  background: color-mix(in srgb, var(--msg-accent) 8%, #fff);
  border-color: color-mix(in srgb, var(--msg-accent) 30%, rgba(15, 23, 42, 0.08));
}

.hmj-msg__conv {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  width: 100%;
  min-width: 0;
  padding: 0.15rem 0.1rem;
  border: 0;
  background: transparent;
  text-align: start;
  cursor: pointer;
  color: inherit;
}

.hmj-msg__conv-del {
  width: 1.7rem;
  height: 1.7rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #b42318;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 0.72rem;
  opacity: 0.65;
  flex-shrink: 0;
  margin-top: 0.15rem;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.hmj-msg__conv-del:hover {
  background: #fde8e8;
  opacity: 1;
}

.hmj-msg__guest {
  padding: 2rem 1.25rem;
  text-align: center;
  color: #64748b;
}

.hmj-msg__login {
  display: inline-flex;
  margin-top: 0.75rem;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  background: var(--msg-accent);
  color: #fff !important;
  font-weight: 700;
  text-decoration: none !important;
}

.hmj-msg__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.hmj-msg__inbox,
.hmj-msg__thread {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.hmj-msg__inbox[hidden],
.hmj-msg__thread[hidden] {
  display: none !important;
}

.hmj-msg__inbox-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.35rem 0 0.75rem;
}

.hmj-msg__empty {
  margin: 2rem 1rem;
  text-align: center;
  color: #94a3b8;
  font-size: 0.9rem;
}

.hmj-msg__conv-icon {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 12px;
  background: #ecfdf5;
  color: var(--msg-accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 0.95rem;
}

.hmj-msg__conv-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.hmj-msg__conv-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
}

.hmj-msg__conv-name {
  font-weight: 800;
  font-size: 0.85rem;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hmj-msg__conv-time {
  font-size: 0.68rem;
  color: #94a3b8;
  flex-shrink: 0;
}

.hmj-msg__conv-place {
  font-size: 0.72rem;
  color: var(--msg-accent);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hmj-msg__conv-preview {
  font-size: 0.75rem;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hmj-msg__conv-badge {
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.28rem;
  border-radius: 999px;
  background: #e11d48;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-top: 0.2rem;
}

.hmj-msg__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.9rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  background:
    radial-gradient(500px 180px at 100% 0%, color-mix(in srgb, var(--msg-accent) 8%, transparent), transparent 70%),
    #fafbfb;
  scroll-behavior: smooth;
}

.hmj-msg__bubble {
  position: relative;
  max-width: 92%;
  padding: 0.7rem 0.85rem;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
  animation: hmj-msg-bubble-in 0.28s ease;
}

@keyframes hmj-msg-bubble-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

/* Match AI chat: own messages at end, peer at start */
.hmj-msg__bubble--mine {
  align-self: flex-end;
  background: var(--msg-accent);
  color: #fff;
  border-bottom-left-radius: 5px;
}

.hmj-msg__bubble--theirs {
  align-self: flex-start;
  background: #f1f5f4;
  color: #0f172a;
  border: 0;
  border-bottom-right-radius: 5px;
}

.hmj-msg__bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.hmj-msg__bubble--theirs .hmj-msg__bubble-meta {
  justify-content: flex-start;
}

.hmj-msg__bubble time {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
  font-size: 0.68rem;
  opacity: 0.75;
  line-height: 1;
}

.hmj-msg__bubble--masked {
  opacity: 0.85;
  font-style: italic;
  letter-spacing: 0.04em;
}

.hmj-msg__receipt {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  line-height: 1;
  opacity: 0.85;
}

.hmj-msg__receipt.is-read {
  opacity: 1;
}

/* Delete message — sits in meta row, not over text */
.hmj-msg__bubble-del {
  width: auto;
  height: auto;
  min-width: 0;
  padding: 0.1rem 0.35rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  opacity: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.hmj-msg__bubble-del i {
  font-size: 0.65rem;
}

.hmj-msg__bubble--mine:hover .hmj-msg__bubble-del,
.hmj-msg__bubble--mine:focus-within .hmj-msg__bubble-del,
.hmj-msg__bubble--mine.is-actions-open .hmj-msg__bubble-del {
  opacity: 0.9;
}

.hmj-msg__bubble--mine .hmj-msg__bubble-del:hover {
  background: rgba(255, 255, 255, 0.18);
  opacity: 1;
}

@media (hover: none) {
  .hmj-msg__bubble--mine .hmj-msg__bubble-del {
    opacity: 0.75;
  }
}

.hmj-msg__composer {
  display: flex;
  gap: 0.45rem;
  align-items: flex-end;
  padding: 0.7rem 0.75rem 0.85rem;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  background: #fff;
  flex-shrink: 0;
}

.hmj-msg__input {
  flex: 1;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 14px;
  padding: .5rem .5rem;
  resize: none;
  font: inherit;
  font-size: inherit;
  max-height: 100px;
  outline: none;
  background: #f8fafc;
  overflow: clip;
  font-size: .85rem;
}

.hmj-msg__input:focus {
  border-color: rgba(18, 140, 126, 0.45);
  box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.12);
  background: #fff;
}

.hmj-msg__send {
  width: 2.6rem;
  height: 2.6rem;
  border: 0;
  border-radius: 14px;
  background: var(--msg-accent);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.15s ease;
}

.hmj-msg__send:hover {
  background: var(--msg-accent-dark);
}

.hmj-msg__send:active {
  transform: scale(0.96);
}

.hmj-msg__place-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  margin: 0.5rem 0.65rem 0.25rem;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--msg-accent) 35%, rgba(15, 23, 42, 0.08));
  background: color-mix(in srgb, var(--msg-accent) 8%, #fff);
  color: var(--msg-accent-dark);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s ease;
}

.hmj-msg__place-cta:hover {
  background: color-mix(in srgb, var(--msg-accent) 14%, #fff);
}

.hmj-msg__empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2.2rem 1.25rem;
  gap: 0.5rem;
}

.hmj-msg__empty-icon {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background: color-mix(in srgb, var(--msg-accent) 12%, #fff);
  color: var(--msg-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  margin-bottom: 0.35rem;
}

.hmj-msg__empty-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #1e293b;
}

.hmj-msg__empty-desc {
  font-size: 0.82rem;
  color: #64748b;
  line-height: 1.6;
  margin: 0;
}

.hmj-msg__empty-note {
  margin-top: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  font-size: 0.76rem;
  color: #475569;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  line-height: 1.4;
  text-align: right;
  direction: rtl;
}

.hmj-msg__empty-tip {
  margin-top: 0.4rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: #fffbeb;
  border: 1px solid #fef3c7;
  font-size: 0.74rem;
  color: #b45309;
  line-height: 1.4;
  text-align: right;
  direction: rtl;
}

@media (max-width: 575.98px) {
  .hmj-msg__panel {
    inset-inline: 0.5rem;
    width: auto;
    bottom: calc(1.15rem + var(--msg-fab) + 0.55rem);

    max-height: unset !important;
    height: 90vh;
    bottom: 5px !important;
  }
}
.hmj-msg__composer .form-loading-overlay {
  display: none !important;
}

.hmj-msg__send.is-sending {
  opacity: 0.6;
  pointer-events: none;
}