.sitehix-messenger {
  --msg-bg: #f6f0e7;
  --msg-line: #e4e7ec;
  --msg-muted: #667085;
  --msg-green: #d9fdd3;
  --msg-accent: #2454d6;
  height: calc(100dvh - 156px);
  min-height: 0;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--msg-line);
  border-radius: 8px;
  box-shadow: 0 18px 55px rgba(16, 24, 40, .1);
}

body.sitehix-messages-page,
body:has(.sitehix-messenger) {
  overflow: hidden;
}

body.sitehix-messages-page .section,
body:has(.sitehix-messenger) .section {
  padding: 28px 0;
}

body.sitehix-messages-page.admin-bar .sitehix-messenger,
body.admin-bar .sitehix-messenger {
  height: calc(100dvh - 188px);
}

.messenger-sidebar {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  border-right: 1px solid var(--msg-line);
  background: #fbfcfe;
}

.messenger-topbar,
.messenger-chat-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: #fff;
  border-bottom: 1px solid var(--msg-line);
}

.messenger-topbar {
  justify-content: space-between;
}

.messenger-kicker {
  display: block;
  color: var(--msg-muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.messenger-topbar h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.messenger-icon-btn,
.messenger-avatar {
  position: relative;
  overflow: hidden;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #2454d6, #12805c);
  color: #fff;
  font-weight: 900;
}

.messenger-avatar > span {
  position: relative;
  z-index: 1;
}

.messenger-avatar img {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  background: #fff;
}

.messenger-avatar.is-online::after {
  content: "";
  position: absolute;
  right: 1px;
  bottom: 1px;
  z-index: 3;
  width: 11px;
  height: 11px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #16a34a;
}

.messenger-search {
  margin: 12px;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: #eef2f7;
  color: var(--msg-muted);
  font-size: 13px;
  font-weight: 750;
}

.messenger-search input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  color: #111827;
}

.messenger-tabs {
  display: flex;
  gap: 8px;
  padding: 0 12px 12px;
}

.messenger-tabs button {
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid var(--msg-line);
  border-radius: 999px;
  background: #fff;
  color: #344054;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.messenger-tabs button.is-active {
  background: #e8f7f0;
  color: #12805c;
  border-color: #b9e7d2;
}

.messenger-contact-list {
  min-height: 0;
  overflow-y: auto;
  padding: 0 8px 12px;
}

.messenger-contact {
  width: 100%;
  min-height: 74px;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.messenger-contact:hover,
.messenger-contact.is-active {
  background: #eef2f7;
}

.messenger-contact-main {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 3px;
}

.messenger-contact-title,
.messenger-contact-sub {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.messenger-contact-title strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}

.messenger-contact-title em {
  flex: 0 0 auto;
  color: var(--msg-muted);
  font-size: 12px;
  font-style: normal;
}

.messenger-contact-sub span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--msg-muted);
  font-size: 13px;
}

.messenger-contact-sub b {
  min-width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #12805c;
  color: #fff;
  font-size: 12px;
}

.messenger-presence {
  display: block;
  color: var(--msg-muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
}
.messenger-presence.is-online { color: #12805c; }

.messenger-chat {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    linear-gradient(rgba(246, 240, 231, .92), rgba(246, 240, 231, .92)),
    radial-gradient(circle at 20% 20%, rgba(36, 84, 214, .08) 0 2px, transparent 3px),
    radial-gradient(circle at 80% 30%, rgba(18, 128, 92, .1) 0 2px, transparent 3px);
  background-size: auto, 54px 54px, 72px 72px;
}

.messenger-chat-header strong,
.messenger-chat-header span {
  display: block;
}

.messenger-chat-header span {
  color: var(--msg-muted);
  font-size: 13px;
  text-transform: capitalize;
}

.messenger-thread {
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
}

.message-row {
  display: flex;
  margin: 6px 0;
}

.message-row.is-mine {
  justify-content: flex-end;
}

.message-bubble {
  max-width: min(620px, 74%);
  padding: 9px 11px 6px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 1px rgba(16, 24, 40, .08);
}

.message-row.is-mine .message-bubble {
  background: var(--msg-green);
}

.message-bubble p {
  margin: 0;
  color: #111827;
  overflow-wrap: anywhere;
}

.message-bubble span {
  display: block;
  margin-top: 2px;
  color: var(--msg-muted);
  font-size: 11px;
  text-align: right;
}

.messenger-compose {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: 42px 1fr 54px;
  gap: 10px;
  align-items: end;
  padding: 12px;
  background: #fff;
  border-top: 1px solid var(--msg-line);
}

.messenger-compose textarea {
  width: 100%;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  border: 1px solid var(--msg-line);
  border-radius: 8px;
  padding: 11px 13px;
  outline: 0;
  font: inherit;
  line-height: 1.35;
}

.messenger-compose textarea:focus {
  border-color: var(--msg-accent);
  box-shadow: 0 0 0 3px rgba(36, 84, 214, .12);
}

.messenger-compose-icon,
.messenger-send {
  height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
}

.messenger-compose-icon {
  background: #eef2f7;
  color: #344054;
  font-size: 22px;
}

.messenger-send {
  background: #12805c;
  color: #fff;
  font-size: 12px;
}

.messenger-send:disabled,
.messenger-compose textarea:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.messenger-empty,
.messenger-loading,
.sitehix-message-login {
  min-height: 220px;
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 24px;
  color: var(--msg-muted);
  text-align: center;
}

.messenger-empty strong,
.sitehix-message-login h2 {
  display: block;
  margin: 0;
  color: #111827;
}

.messenger-empty span,
.sitehix-message-login p {
  display: block;
  margin: 4px 0 0;
}

.sitehix-message-login {
  min-height: 360px;
  background: #fff;
  border: 1px solid #e4e7ec;
  border-radius: 8px;
  box-shadow: 0 18px 55px rgba(16, 24, 40, .1);
}

.message-login-icon {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2454d6, #12805c);
  color: #fff;
  font-weight: 900;
  font-size: 26px;
}

@media (max-width: 920px) {
  .sitehix-messenger {
    height: calc(100dvh - 128px);
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: 320px minmax(0, 1fr);
  }

  body.sitehix-messages-page.admin-bar .sitehix-messenger,
  body.admin-bar .sitehix-messenger {
    height: calc(100dvh - 160px);
  }

  .messenger-sidebar {
    min-height: 0;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--msg-line);
  }

  .messenger-thread {
    padding: 16px;
  }

  .message-bubble {
    max-width: 86%;
  }
}

@media (max-width: 640px) {
  .sitehix-messenger {
    height: calc(100dvh - 96px);
    margin: -16px -12px 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  body.sitehix-messages-page.admin-bar .sitehix-messenger,
  body.admin-bar .sitehix-messenger {
    height: calc(100dvh - 142px);
  }

  .messenger-compose {
    grid-template-columns: 38px 1fr 50px;
    gap: 8px;
  }
}
