/* ============================================================
   HEALTHY STANDARDS — Messenger widget component
   Scope: .hs-messenger (the popover shell rendered by ChatIcon)
   Load: after /hs-design/styles.css
   Tokens: semantic only — never raw ramp hex.
   ============================================================ */

/* ── Shell root ─────────────────────────────────────────────── */
.hs-messenger {
  --surface-raised: var(--surface-muted);

  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--surface);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

/* ── Header strip (list + thread share this) ────────────────── */
.hs-messenger__head {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0 var(--space-2);
  min-height: 52px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
  flex-shrink: 0;
}

.hs-messenger__head-ico {
  font-size: var(--fs-sm);
  color: var(--accent);
  flex-shrink: 0;
  margin-right: var(--space-1);
}

/* Avatar shown in thread header */
.hs-messenger__head-avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: var(--fs-micro);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  user-select: none;
  background: var(--surface-sunken);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.hs-messenger__head-avatar.hs-conv__avatar--group {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--info-border);
}

.hs-messenger__title {
  flex: 1;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.hs-messenger__head-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
  margin-left: var(--space-1);
}

/* ── Conversation list scroll area ─────────────────────────── */
.hs-messenger__list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* User picker (new-DM panel) */
.hs-messenger__picker {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
}

.hs-messenger__picker-search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  color: var(--text-muted);
  font-size: var(--fs-caption);
}
.hs-messenger__picker-search .form-control {
  flex: 1;
  font-size: var(--fs-sm);
  padding-top: 3px;
  padding-bottom: 3px;
}

.hs-messenger__picker-label {
  font-size: var(--fs-micro);
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}
.hs-picker__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-1) var(--space-1);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard);
}
.hs-picker__row:hover:not(:disabled) { background: var(--surface-sunken); }
.hs-picker__row:disabled { opacity: 0.6; cursor: default; }

/* [WA] Picker avatar — colored circles */
.hs-picker__avatar {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: var(--fw-semibold);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: var(--ls-wide);
  line-height: 1;
  user-select: none;
}
.hs-picker__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Conversation row ───────────────────────────────────────── */
.hs-conv {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: none;
  border-bottom: 1px solid var(--border-muted);
  background: transparent;
  cursor: pointer;
  text-align: left;
  color: inherit;
  transition: background var(--dur-fast) var(--ease-standard);
  min-height: 64px;
}
.hs-conv:hover    { background: var(--surface-sunken); }
.hs-conv.is-unread { background: var(--accent-soft); }
.hs-conv.is-unread:hover { background: var(--surface-tint); }
.hs-conv.is-active {
  background: var(--surface-tint);
  box-shadow: inset 3px 0 0 var(--accent);
}

/* [WA] Avatar — 40px colored circles */
.hs-conv__avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: var(--fs-caption);
  font-weight: var(--fw-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--ls-wide);
  line-height: 1;
  user-select: none;
}
.hs-conv__avatar--group {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--info-border);
}

.hs-conv__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.hs-conv__name {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: var(--lh-snug);
}
.hs-conv.is-unread .hs-conv__name { font-weight: var(--fw-semibold); }
.hs-conv__preview {
  font-size: var(--fs-caption);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: var(--lh-snug);
}
.hs-conv.is-unread .hs-conv__preview { color: var(--text-secondary); }

.hs-conv__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.hs-conv__time {
  font-size: var(--fs-micro);
  color: var(--text-muted);
  white-space: nowrap;
}
.hs-conv.is-unread .hs-conv__time { color: var(--success); }

/* [WA] Unread badge — green like WhatsApp */
.hs-conv__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  border-radius: var(--radius-pill);
  background: var(--success);
  color: #fff;
  font-size: var(--fs-micro);
  font-weight: var(--fw-bold);
  padding: 0 var(--space-1);
  line-height: 1;
}

/* ── Thread: messages area ──────────────────────────────────── */
/* [WA] Tinted background like WhatsApp */
.hs-thread__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) var(--space-3);
  min-height: 0;
  background: var(--surface-sunken);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, black 20px);
  mask-image: linear-gradient(to bottom, transparent 0, black 20px);
}

.hs-thread__older {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 auto var(--space-2);
  padding: var(--space-1) var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  font-size: var(--fs-micro);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-standard), background var(--dur-fast) var(--ease-standard);
  box-shadow: var(--shadow-sm);
}
.hs-thread__older:hover:not(:disabled) { color: var(--text-secondary); background: var(--surface-muted); }
.hs-thread__older:disabled { cursor: default; opacity: 0.6; }
.hs-thread__older-wrap { display: flex; justify-content: center; padding-bottom: var(--space-2); }

/* ── Message rows ───────────────────────────────────────────── */
.hs-msg {
  display: flex;
  margin-bottom: var(--space-2);
}
.hs-msg.is-grouped { margin-bottom: 2px; }
.hs-msg.is-grouped .hs-msg__sender { display: none; }
.hs-msg--in  { justify-content: flex-start; }
.hs-msg--out { justify-content: flex-end; }

.hs-msg__inner {
  max-width: 78%;
  display: flex;
  flex-direction: column;
}
.hs-msg--in  .hs-msg__inner { align-items: flex-start; }
.hs-msg--out .hs-msg__inner { align-items: flex-end; }

.hs-msg__sender {
  font-size: var(--fs-micro);
  font-weight: var(--fw-semibold);
  color: var(--accent);
  margin-bottom: 2px;
  padding-left: 10px;
}

.hs-msg__quote {
  border-left: 3px solid var(--accent);
  padding-left: var(--space-2);
  margin-bottom: var(--space-1);
  font-size: var(--fs-micro);
  color: var(--text-muted);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* [WA] Bubbles — no border, soft shadow, WhatsApp-style tails */
.hs-msg__bubble {
  position: relative;
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-sm);
  word-break: break-word;
  line-height: var(--lh-base);
}

/* Incoming bubble */
.hs-msg--in .hs-msg__bubble {
  background: var(--surface);
  color: var(--text-primary);
  border-radius: 0 var(--radius-lg) var(--radius-lg) var(--radius-lg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.10);
}

/* Incoming tail — points left at top-left corner */
.hs-msg--in:not(.is-grouped) .hs-msg__bubble::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  width: 0;
  height: 0;
  border-right: 8px solid var(--surface);
  border-bottom: 8px solid transparent;
}

/* Grouped incoming: full rounded corners, no tail */
.hs-msg--in.is-grouped .hs-msg__bubble {
  border-radius: var(--radius-md) var(--radius-lg) var(--radius-lg) var(--radius-md);
}

/* Outgoing bubble */
.hs-msg--out .hs-msg__bubble {
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: var(--radius-lg) 0 var(--radius-lg) var(--radius-lg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* Outgoing tail — points right at top-right corner */
.hs-msg--out:not(.is-grouped) .hs-msg__bubble::before {
  content: '';
  position: absolute;
  top: 0;
  right: -8px;
  width: 0;
  height: 0;
  border-left: 8px solid var(--accent);
  border-bottom: 8px solid transparent;
}

/* Grouped outgoing: full rounded corners, no tail */
.hs-msg--out.is-grouped .hs-msg__bubble {
  border-radius: var(--radius-lg) var(--radius-md) var(--radius-md) var(--radius-lg);
}

.hs-msg__bubble.is-deleted {
  opacity: 0.55;
  font-style: italic;
  box-shadow: none;
}

/* Timestamp + hover-action row */
.hs-msg__time {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: 3px;
  padding: 0 2px;
  font-size: var(--fs-micro);
  color: var(--text-muted);
}
.hs-msg--out .hs-msg__time { justify-content: flex-end; }

.hs-msg__actions {
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  transition: opacity 140ms var(--ease-standard);
}
.hs-msg:hover .hs-msg__actions,
.hs-msg:focus-within .hs-msg__actions { opacity: 1; }
.hs-msg__actions.is-open { opacity: 1; }

.hs-messenger .hs-btn-icon-sm {
  width: 22px;
  height: 22px;
  font-size: var(--fs-micro);
}
.hs-msg__confirm {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-micro);
  color: var(--text-muted);
}
.hs-msg__confirm button {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: var(--fs-micro);
  color: var(--text-muted);
}
.hs-msg__confirm button.is-danger { color: var(--danger); font-weight: var(--fw-semibold); }

/* ── Reply preview bar ──────────────────────────────────────── */
.hs-reply-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
  font-size: var(--fs-micro);
  color: var(--text-muted);
  flex-shrink: 0;
}
.hs-reply-bar__ico { color: var(--accent); flex-shrink: 0; }
.hs-reply-bar__text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hs-reply-bar__name { color: var(--text-primary); font-weight: var(--fw-semibold); }
.hs-reply-bar__body { font-style: italic; }

/* ── Composer ───────────────────────────────────────────────── */
.hs-composer {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
  flex-shrink: 0;
}
.hs-composer--replying { border-top: none; }

/* [WA] Pill-shaped input */
.hs-composer .form-control {
  flex: 1;
  resize: none;
  font-size: var(--fs-sm);
  max-height: 80px;
  overflow-y: auto;
  border-radius: 20px;
  padding-left: var(--space-3);
  padding-right: var(--space-3);
  line-height: 1.5;
}

/* [WA] Round accent send button */
.hs-composer__send {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard), transform var(--dur-fast) var(--ease-standard);
}
.hs-composer__send:hover:not(:disabled)  { background: var(--accent-hover); transform: scale(1.06); }
.hs-composer__send:active:not(:disabled) { background: var(--accent-active); transform: scale(0.96); }
.hs-composer__send:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.hs-composer__send:disabled {
  background: var(--surface-sunken);
  color: var(--text-muted);
  cursor: default;
  transform: none;
}

/* ── Presence dot ───────────────────────────────────────────── */
.hs-presence {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--text-muted);
  flex-shrink: 0;
}
.hs-presence.is-online { background: var(--success); }

/* ── Motion guard ───────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .hs-conv { transition: none; }
  .hs-msg__actions { transition: none; }
  .hs-composer__send { transition: none; }
}
