/* ==========================================================================
   Chat (My Account → Messaging)
   Markup: modules/messaging/messaging.php · Behaviour: assets/messaging.js

   Everything is scoped under .qs-chat and driven by the variables below.
   --qs-accent is set inline from Settings → Styling (main skin colour).
   Theme button / heading / form styles are reset inside the component, which
   is why some declarations carry !important.
   ========================================================================== */

.qs-chat {
  --qs-accent: #ed147d;
  --qs-accent-soft: color-mix(in srgb, var(--qs-accent) 10%, #ffffff);
  --qs-accent-text: var(--qs-accent);
  --qs-surface: #ffffff;
  --qs-surface-2: #f6f6f8;
  --qs-hover: #f3f3f6;
  --qs-line: #e9e9ee;
  --qs-text: #17171c;
  --qs-muted: #6d6d7a;
  --qs-bubble-in: #ffffff;
  --qs-bubble-out: var(--qs-accent);
  --qs-bubble-out-text: #ffffff;
  --qs-online: #1faa59;
  --qs-danger: #cf222e;
  --qs-warn-bg: #fff8e1;
  --qs-warn-text: #7a5200;
  --qs-chat-height: 640px;

  display: flex;
  height: var(--qs-chat-height);
  min-height: 420px;
  background: var(--qs-surface);
  border: 1px solid var(--qs-line);
  border-radius: 18px;
  overflow: hidden;
  color: var(--qs-text);
  font-size: 15px;
  line-height: 1.45;
  box-shadow: 0 10px 30px rgba(20, 20, 40, 0.05);
  text-align: left;
}

body.qiupidsaas-dark-mode .qs-chat {
  --qs-accent-soft: color-mix(in srgb, var(--qs-accent) 22%, #1b1b22);
  --qs-accent-text: color-mix(in srgb, var(--qs-accent) 55%, #ffffff);
  --qs-surface: #1b1b22;
  --qs-surface-2: #131318;
  --qs-hover: #25252e;
  --qs-line: #2e2e39;
  --qs-text: #f1f1f4;
  --qs-muted: #a2a2b0;
  --qs-bubble-in: #2a2a34;
  --qs-warn-bg: #3a3016;
  --qs-warn-text: #ffd978;
  box-shadow: none;
}

.qs-chat *,
.qs-chat *::before,
.qs-chat *::after {
  box-sizing: border-box;
}

.qs-chat [hidden] {
  display: none !important;
}

/* The account page gives its content 50px of padding; the chat wants the room. */
html body.woocommerce-account .woocommerce .woocommerce-MyAccount-content:has(> .qs-chat) {
  padding: 24px 24px 0 !important;
}

/* --- resets against theme styles ---------------------------------------- */

.qs-chat button {
  margin: 0;
  font: inherit;
  letter-spacing: normal;
  text-transform: none;
  box-shadow: none !important;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.qs-chat a {
  text-decoration: none;
  box-shadow: none;
}

.qs-chat h2,
.qs-chat h3,
.qs-chat p {
  margin: 0;
  padding: 0;
  color: inherit;
}

.qs-chat :focus-visible {
  outline: 2px solid var(--qs-accent);
  outline-offset: 2px;
}

/* --- avatar --------------------------------------------------------------- */

.qs-avatar {
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  display: inline-block;
}

.qs-avatar img {
  width: 100% !important;
  height: 100% !important;
  max-width: none;
  border-radius: 50% !important;
  object-fit: cover;
  display: block;
  background: var(--qs-surface-2);
}

.qs-avatar__dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--qs-online);
  border: 2px solid var(--qs-surface);
}

.qs-avatar--lg {
  width: 84px;
  height: 84px;
}

/* --- sidebar -------------------------------------------------------------- */

.qs-chat__sidebar {
  flex: 0 0 340px;
  width: 340px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--qs-line);
  background: var(--qs-surface);
}

.qs-chat__sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 20px 20px 12px;
}

.qs-chat .qs-chat__title {
  font-size: 22px !important;
  font-weight: 700 !important;
  line-height: 1.2 !important;
  letter-spacing: -0.01em;
}

.qs-chat__credits {
  flex: 0 0 auto;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--qs-accent-soft);
  color: var(--qs-accent-text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.qs-chat__credits.is-empty {
  background: var(--qs-warn-bg);
  color: var(--qs-warn-text);
}

.qs-chat .qs-chat__search {
  position: relative;
  display: block;
  flex: 0 0 auto;
  width: auto;
  max-width: none;
  margin: 0 16px 10px;
  padding: 0;
  float: none;
}

.qs-chat__search i,
.qs-chat__search svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--qs-muted);
  font-size: 13px;
  pointer-events: none;
}

.qs-chat .qs-chat__search-input {
  width: 100%;
  height: 42px !important;
  margin: 0 !important;
  padding: 0 14px 0 38px !important;
  border: 1px solid transparent !important;
  border-radius: 999px !important;
  background: var(--qs-surface-2) !important;
  color: var(--qs-text) !important;
  font-size: 14px !important;
  line-height: 1.4;
  box-shadow: none !important;
  outline: none;
}

.qs-chat .qs-chat__search-input::placeholder {
  color: var(--qs-muted);
}

.qs-chat .qs-chat__search-input:focus {
  border-color: var(--qs-accent) !important;
  background: var(--qs-surface) !important;
}

.qs-chat__list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 8px 8px;
  overscroll-behavior: contain;
}

.qs-chat .qs-chat__item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px !important;
  border: 0 !important;
  border-radius: 14px !important;
  background: transparent !important;
  color: var(--qs-text) !important;
  text-align: left;
  height: auto;
  min-height: 0;
  line-height: 1.35;
  transition: background-color 0.15s ease;
}

.qs-chat .qs-chat__item:hover {
  background: var(--qs-hover) !important;
}

.qs-chat .qs-chat__item.is-active {
  background: var(--qs-accent-soft) !important;
}

.qs-chat__item-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.qs-chat__item-top,
.qs-chat__item-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.qs-chat__item-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 600;
}

.qs-chat__item-time {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--qs-muted);
}

.qs-chat__item-preview {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--qs-muted);
}

.qs-chat__item.is-unread .qs-chat__item-name {
  font-weight: 700;
}

.qs-chat__item.is-unread .qs-chat__item-preview {
  color: var(--qs-text);
  font-weight: 600;
}

.qs-chat__item.is-unread .qs-chat__item-time {
  color: var(--qs-accent-text);
  font-weight: 600;
}

.qs-chat__badge {
  flex: 0 0 auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--qs-accent);
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}

.qs-chat__list-empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--qs-muted);
  font-size: 14px;
}

.qs-chat__list-empty strong {
  display: block;
  margin-bottom: 4px;
  color: var(--qs-text);
  font-size: 15px;
}

.qs-chat .qs-chat__find {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 8px 16px 16px;
  padding: 11px 16px;
  border: 1px solid var(--qs-line);
  border-radius: 999px;
  color: var(--qs-text);
  font-size: 14px;
  font-weight: 600;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.qs-chat .qs-chat__find:hover {
  border-color: var(--qs-accent);
  color: var(--qs-accent);
}

/* --- main column ---------------------------------------------------------- */

.qs-chat__main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--qs-surface-2);
}

.qs-chat__empty {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 24px;
  text-align: center;
}

.qs-chat__empty-icon {
  width: 76px;
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--qs-accent-soft);
  color: var(--qs-accent);
  font-size: 30px;
  margin-bottom: 6px;
}

.qs-chat .qs-chat__empty h3 {
  font-size: 20px !important;
  font-weight: 700 !important;
  line-height: 1.3 !important;
}

.qs-chat__empty p {
  max-width: 360px;
  color: var(--qs-muted);
}

.qs-chat .qs-chat__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  padding: 11px 24px;
  border-radius: 999px;
  background: var(--qs-accent);
  color: #ffffff !important;
  font-size: 14px;
  font-weight: 600;
  transition: filter 0.15s ease;
}

.qs-chat .qs-chat__cta:hover {
  filter: brightness(0.92);
}

.qs-chat .qs-chat__cta--small {
  margin-top: 0;
  padding: 7px 16px;
  font-size: 13px;
}

.qs-chat--blank {
  height: auto;
  min-height: 420px;
}

.qs-chat--blank .qs-chat__empty {
  background: var(--qs-surface-2);
}

/* --- thread --------------------------------------------------------------- */

.qs-chat__thread {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.qs-chat__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: var(--qs-surface);
  border-bottom: 1px solid var(--qs-line);
}

.qs-chat .qs-chat__peer {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--qs-text);
}

.qs-chat .qs-chat__peer.is-static {
  cursor: default;
}

.qs-chat__peer-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.qs-chat__peer-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
}

.qs-chat__peer-status {
  font-size: 12.5px;
  color: var(--qs-muted);
  line-height: 1.3;
}

.qs-chat__peer-status.is-online {
  color: var(--qs-online);
  font-weight: 600;
}

.qs-chat__head-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.qs-chat .qs-chat__icon-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  min-height: 0;
  padding: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0 !important;
  border-radius: 50% !important;
  background: transparent !important;
  color: var(--qs-muted) !important;
  font-size: 16px;
  line-height: 1;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.qs-chat .qs-chat__icon-btn:hover {
  background: var(--qs-hover) !important;
  color: var(--qs-text) !important;
}

.qs-chat .qiupidsaas-chat-block-btn:hover {
  color: var(--qs-danger) !important;
}

.qs-chat .qs-chat__back {
  display: none;
  margin-left: -8px;
}

.qs-chat__body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.qs-chat__messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 22px 10px;
  display: flex;
  flex-direction: column;
  overscroll-behavior: contain;
}

/* Keeps a short conversation at the bottom, next to the message box. */
.qs-chat__messages > :first-child {
  margin-top: auto;
}

.qs-chat__day {
  align-self: center;
  margin: 14px 0 10px;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--qs-surface);
  border: 1px solid var(--qs-line);
  color: var(--qs-muted);
  font-size: 12px;
  font-weight: 600;
}

.qs-msg {
  max-width: min(72%, 560px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  align-self: flex-start;
  margin-top: 10px;
}

.qs-msg.joins-previous {
  margin-top: 2px;
}

.qs-msg.is-mine {
  align-items: flex-end;
  align-self: flex-end;
}

.qs-msg__bubble {
  padding: 9px 14px;
  border-radius: 20px;
  background: var(--qs-bubble-in);
  color: var(--qs-text);
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 1px rgba(20, 20, 40, 0.06);
}

.qs-msg.is-mine .qs-msg__bubble {
  background: var(--qs-bubble-out);
  color: var(--qs-bubble-out-text);
  box-shadow: none;
}

/* Bubbles of one group share a flat inner edge. */
.qs-msg.is-theirs.joins-previous .qs-msg__bubble { border-top-left-radius: 6px; }
.qs-msg.is-theirs.joins-next .qs-msg__bubble { border-bottom-left-radius: 6px; }
.qs-msg.is-mine.joins-previous .qs-msg__bubble { border-top-right-radius: 6px; }
.qs-msg.is-mine.joins-next .qs-msg__bubble { border-bottom-right-radius: 6px; }

.qs-msg__meta {
  margin: 3px 6px 0;
  font-size: 11.5px;
  color: var(--qs-muted);
}

.qs-msg.is-failed {
  cursor: pointer;
}

.qs-msg.is-failed .qs-msg__bubble {
  opacity: 0.6;
}

.qs-msg.is-failed .qs-msg__meta {
  color: var(--qs-danger);
  font-weight: 600;
}

.qs-msg.is-new {
  animation: qs-chat-in 0.18s ease-out;
}

@keyframes qs-chat-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.qs-chat__hello {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
}

.qs-chat__hello strong {
  margin-top: 8px;
  font-size: 18px;
}

.qs-chat__hello p {
  max-width: 320px;
  color: var(--qs-muted);
  font-size: 14px;
}

.qs-chat__loading {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.qs-chat__skeleton {
  width: 42%;
  height: 38px;
  border-radius: 20px;
  background: var(--qs-surface);
  opacity: 0.8;
  animation: qs-chat-pulse 1.1s ease-in-out infinite;
}

.qs-chat__skeleton.is-mine {
  width: 30%;
  align-self: flex-end;
}

@keyframes qs-chat-pulse {
  50% { opacity: 0.35; }
}

.qs-chat .qs-chat__jump {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px !important;
  border: 0 !important;
  border-radius: 999px !important;
  background: var(--qs-accent) !important;
  color: #ffffff !important;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18) !important;
}

/* --- notice and composer -------------------------------------------------- */

.qs-chat__notice {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin: 10px 18px 16px;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--qs-warn-bg);
  color: var(--qs-warn-text);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}

.qs-chat__composer {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0;
  padding: 12px 16px 16px;
  background: var(--qs-surface-2);
}

.qs-chat__field {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  border: 1px solid var(--qs-line);
  border-radius: 22px;
  background: var(--qs-surface);
  transition: border-color 0.15s ease;
}

.qs-chat__field:focus-within {
  border-color: var(--qs-accent);
}

.qs-chat .qs-chat__input {
  display: block;
  width: 100%;
  height: 42px;
  min-height: 42px !important;
  max-height: 132px;
  margin: 0 !important;
  padding: 10px 16px !important;
  border: 0 !important;
  border-radius: 22px !important;
  background: transparent !important;
  color: var(--qs-text) !important;
  font: inherit;
  font-size: 15px !important;
  line-height: 22px !important;
  resize: none;
  outline: none !important;
  box-shadow: none !important;
  overflow-y: auto;
}

.qs-chat .qs-chat__input::placeholder {
  color: var(--qs-muted);
  font-size: 15px;
}

.qs-chat__counter {
  align-self: flex-end;
  padding: 0 14px 11px 0;
  font-size: 11.5px;
  color: var(--qs-muted);
  white-space: nowrap;
}

.qs-chat__counter.is-max {
  color: var(--qs-danger);
  font-weight: 600;
}

.qs-chat .qs-chat__emoji-btn {
  width: 44px;
  height: 44px;
  font-size: 20px;
}

.qs-chat .qs-chat__send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  min-height: 0;
  padding: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0 !important;
  border-radius: 50% !important;
  background: var(--qs-accent) !important;
  color: #ffffff !important;
  font-size: 16px;
  line-height: 1;
  transition: filter 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
}

.qs-chat .qs-chat__send:hover:not(:disabled) {
  filter: brightness(0.92);
}

.qs-chat .qs-chat__send:active:not(:disabled) {
  transform: scale(0.94);
}

.qs-chat .qs-chat__send:disabled {
  opacity: 0.35;
  cursor: default;
}

.qs-chat__emoji-panel {
  position: absolute;
  left: 12px;
  bottom: calc(100% - 4px);
  z-index: 5;
  width: min(304px, calc(100% - 24px));
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  padding: 8px;
  border: 1px solid var(--qs-line);
  border-radius: 16px;
  background: var(--qs-surface);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
}

.qs-chat .qs-chat__emoji {
  height: 42px;
  min-height: 0;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 10px !important;
  background: transparent !important;
  color: inherit !important;
  font-size: 22px;
  line-height: 1;
}

.qs-chat .qs-chat__emoji:hover {
  background: var(--qs-hover) !important;
}

/* --- small screens: one pane at a time ------------------------------------ */

@media (max-width: 860px) {
  html body.woocommerce-account .woocommerce .woocommerce-MyAccount-content:has(> .qs-chat) {
    padding: 0 !important;
  }

  .qs-chat {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }

  .qs-chat__sidebar {
    flex: 1 1 auto;
    width: 100%;
    border-right: 0;
  }

  .qs-chat[data-view="list"] .qs-chat__main,
  .qs-chat[data-view="thread"] .qs-chat__sidebar {
    display: none;
  }

  .qs-chat .qs-chat__back {
    display: inline-flex;
  }

  .qs-chat__head {
    padding: 10px 12px;
  }

  .qs-chat__messages {
    padding: 14px 12px 8px;
  }

  .qs-msg {
    max-width: 84%;
  }

  .qs-chat__composer {
    padding: 10px 10px 12px;
    gap: 6px;
  }

  /* 16px keeps iOS from zooming the page when the field is focused. */
  .qs-chat .qs-chat__input,
  .qs-chat .qs-chat__search-input {
    font-size: 16px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .qs-msg.is-new,
  .qs-chat__skeleton {
    animation: none;
  }
}

/* --- unread notice on the dashboard --------------------------------------- */

#qiupidsaas_unread_messages_notice {
  margin: 16px 0;
  padding: 16px;
  border-radius: 15px;
  background-color: #ee137d;
  color: #ffffff;
  font-size: 30px;
  font-weight: 600;
  text-align: center;
}
#qiupidsaas_unread_messages_notice > a {
  padding: 4px 10px;
  border: 2px solid #ffffff;
  border-radius: inherit;
  color: inherit;
  background-color: transparent;
  transition: all 350ms ease-in-out;
}
#qiupidsaas_unread_messages_notice > a:hover {
  color: #ee137d;
  background-color: #ffffff;
}

/* --- page chrome around the chat ------------------------------------------ */

/* Normalize styles give search inputs content-box sizing, which made the field overflow. */
.qs-chat .qs-chat__search-input,
.qs-chat .qs-chat__input {
  box-sizing: border-box !important;
  min-width: 0;
  max-width: 100%;
}

/* The chat uses the full height of the screen, so the floating bottom navigation is hidden on
   this page (messaging.js fit() then gives its space to the chat). */
body:has(.qs-chat) .qiupidsaas-footer-mobile-sticky-nav-group {
  display: none !important;
}

/* With the chat reaching the bottom of the screen, the floating dark-mode button would sit on
   top of the send button. It stays available on every other page. */
body:has(.qs-chat) .qiupidsaas-dark-mode-button {
  display: none !important;
}
