/* Native live chat — platform vs shop chrome */

html.paper-chat-open {
  overflow: hidden;
}

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

.paper-chat {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 1rem;
  background: rgba(15, 18, 22, 0.28);
}

.paper-chat__sheet {
  width: min(100%, 24rem);
  height: min(36rem, calc(100dvh - 2rem));
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg, 20px);
  overflow: hidden;
  background: var(--card, #fff);
  border: 1px solid var(--pop-rim, rgba(15, 20, 40, 0.08));
  box-shadow: var(--pop-lift-modal, 0 24px 48px -16px rgba(15, 20, 40, 0.26)),
    var(--pop-shine, inset 0 1px 0 rgba(255, 255, 255, 0.95));
}

.paper-chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 0.9rem;
  background: var(--card, #fff);
  color: var(--foreground, #1d1d1f);
  border-bottom: 1px solid var(--border, #e1e4ea);
}

.paper-chat--platform .paper-chat__head {
  box-shadow: inset 3px 0 0 #1f2933;
}

.paper-chat--shop .paper-chat__head {
  box-shadow: inset 3px 0 0 #0f3d2e;
}

.paper-chat__identity {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
  flex: 1 1 auto;
}

.paper-chat__media {
  flex: 0 0 auto;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.7rem;
  overflow: hidden;
  background: var(--pop-well, #eef0f3);
  border: 1px solid rgba(15, 18, 22, 0.08);
}

.paper-chat__media[hidden] {
  display: none !important;
}

.paper-chat__media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.paper-chat__titles {
  min-width: 0;
  flex: 1 1 auto;
}

.paper-chat__title {
  display: block;
  font-size: 0.95rem;
  font-weight: 650;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.paper-chat__subtitle {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.75rem;
  color: var(--muted-foreground, #6e6e73);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.paper-chat__close {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--muted-foreground, #6e6e73);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.25rem;
  border-radius: var(--radius-sm, 10px);
}

.paper-chat__close:hover,
.paper-chat__close:focus-visible {
  color: var(--foreground, #1d1d1f);
  background: rgba(15, 18, 22, 0.05);
  outline: none;
}

.paper-chat__messages {
  flex: 1;
  overflow: auto;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  background: var(--pop-well, #eef0f3);
}

.paper-chat--shop .paper-chat__messages {
  background: #f3f6f4;
}

.chat-bubble {
  box-sizing: border-box;
  display: block;
  flex: 0 0 auto;
  width: fit-content;
  max-width: min(85%, 22rem);
  height: auto;
  min-height: 0;
  padding: 0.35rem 0.6rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
  word-break: break-word;
  /* Do NOT set white-space:pre-wrap here — template indentation becomes
     visible blank space inside the bubble. Keep it on __body only. */
}

.chat-bubble--visitor,
.chat-bubble--user {
  align-self: flex-end;
  background: #1f2933;
  color: #fff;
}

.paper-chat--shop .chat-bubble--visitor,
.paper-chat--shop .chat-bubble--user {
  background: #0f3d2e;
}

.chat-bubble--agent {
  align-self: flex-start;
  background: #fff;
  border: 1px solid rgba(15, 18, 22, 0.08);
  color: #1f2933;
}

.chat-bubble--system {
  align-self: center;
  max-width: 92%;
  background: transparent;
  border: 0;
  color: #64748b;
  text-align: center;
  padding: 0.15rem 0.35rem;
  font-size: 0.78rem;
}

.chat-bubble--system .chat-bubble__meta {
  display: none;
}

.chat-bubble--system .chat-bubble__body {
  white-space: normal;
}

.chat-product-card {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  margin: 0.55rem 0 0.75rem;
  padding: 0.15rem 0.5rem 0.35rem;
  text-align: center;
}

.chat-product-card__rule {
  width: min(100%, 14rem);
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(15, 18, 22, 0.18) 18%,
    rgba(15, 18, 22, 0.18) 82%,
    transparent
  );
}

.chat-product-card__media-wrap {
  position: relative;
  width: 7.25rem;
  height: 7.25rem;
  flex: 0 0 auto;
}

.chat-product-card__media {
  margin: 0;
  width: 100%;
  height: 100%;
  border-radius: 0.95rem;
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(15, 18, 22, 0.08);
  box-shadow: 0 6px 18px rgba(15, 18, 22, 0.06);
}

.chat-product-card__media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-product-card__media--empty {
  background:
    linear-gradient(145deg, rgba(15, 18, 22, 0.04), rgba(15, 18, 22, 0.08));
}

.chat-product-card__info {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  z-index: 1;
}

.chat-product-card__info .product-info-btn {
  width: 1.55rem;
  height: 1.55rem;
  min-width: 1.55rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(15, 18, 22, 0.1);
  box-shadow: 0 2px 8px rgba(15, 18, 22, 0.16);
}

.chat-product-card__info .product-info-btn .icon {
  width: 0.95rem;
  height: 0.95rem;
}

/* Match stock-table package icon weight (not the default 2px stroke). */
.chat-product-card__info .product-info-btn svg {
  stroke-width: 1.15;
}

.chat-product-card__footer {
  display: block;
  max-width: min(100%, 20rem);
}

.chat-product-card__label {
  margin: 0;
  color: #64748b;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
}

.chat-bubble__meta {
  display: block;
  font-size: 0.65rem;
  opacity: 0.65;
  margin: 0 0 0.1rem;
  line-height: 1.2;
  white-space: nowrap;
}

.chat-bubble__body {
  display: block;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Sidebar Chat inbox unread */
.sidebar-settings-link[data-chat-inbox-nav] {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-nav-badge {
  margin-left: auto;
  min-width: 1.35rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: #c2410c;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 650;
  line-height: 1.2;
  text-align: center;
}

/* Agent inbox */
.chat-inbox {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  /* Keep the pane in the viewport so the thread scrolls instead of growing the page. */
  height: calc(100dvh - 7.5rem);
  min-height: 22rem;
  max-height: calc(100dvh - 7.5rem);
}

.chat-inbox > .page-header,
.chat-inbox > .chat-inbox__page-back {
  flex: 0 0 auto;
}

.chat-inbox__page-back {
  align-self: flex-start;
  margin: 0 0 0.15rem;
}

/* Single card: conversation list, or open thread (WhatsApp-style). */
.chat-inbox__pane {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  border: 1px solid rgba(15, 18, 22, 0.1);
  border-radius: 0.85rem;
  background: #fff;
  overflow: hidden;
  box-shadow: var(--pop-lift-sm, 0 1px 2px rgba(15, 20, 40, 0.05)),
    var(--pop-shine, inset 0 1px 0 rgba(255, 255, 255, 0.95));
}

.chat-inbox__list {
  flex: 1 1 auto;
  overflow: auto;
  background: #fff;
  min-height: 0;
}

.chat-inbox__pane.is-thread .chat-inbox__list,
.chat-inbox__list[hidden] {
  display: none !important;
}

.chat-inbox__pane.is-list .chat-inbox__thread,
.chat-inbox__thread[hidden] {
  display: none !important;
}

.chat-inbox__row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem 0.85rem;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid rgba(15, 18, 22, 0.06);
  min-width: 0;
}

.chat-inbox__row.is-active,
.chat-inbox__row:hover {
  background: rgba(15, 18, 22, 0.04);
}

.chat-inbox--platform .chat-inbox__row.is-active {
  box-shadow: inset 3px 0 0 #1f2933;
}

.chat-inbox--shop .chat-inbox__row.is-active {
  box-shadow: inset 3px 0 0 #0f3d2e;
}

.chat-inbox__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  min-width: 2.25rem;
  max-width: 2.25rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted-foreground, #6b7280) 12%, transparent);
  color: var(--muted-foreground, #6b7280);
  flex-shrink: 0;
  overflow: hidden;
}

.chat-inbox__avatar .icon {
  --icon-size: 1.15rem;
  width: var(--icon-size);
  height: var(--icon-size);
  min-width: var(--icon-size);
  min-height: var(--icon-size);
}

.chat-inbox__row-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  text-align: left;
}

.chat-inbox__row-title {
  font-weight: 600;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-inbox__row-preview {
  font-size: 0.8rem;
  color: rgba(15, 18, 22, 0.62);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-inbox__badge {
  flex: 0 0 auto;
  align-self: center;
  min-width: 1.35rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: #1f2933;
  color: #fff;
  font-size: 0.72rem;
  text-align: center;
}

.chat-inbox--shop .chat-inbox__badge {
  background: #0f3d2e;
}

.chat-inbox__thread {
  flex: 1 1 auto;
  background: #fff;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.chat-inbox__thread-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid rgba(15, 18, 22, 0.08);
}

.chat-inbox__thread-meta {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  min-width: 0;
  flex: 1 1 auto;
}

.chat-inbox__thread-meta strong {
  font-size: 0.95rem;
  line-height: 1.25;
}

.chat-inbox__thread-meta .muted {
  font-size: 0.78rem;
}

.chat-inbox__note-open {
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 0.82rem;
  padding: 0.35rem 0.7rem;
}

.chat-inbox__note-open.has-note {
  box-shadow: inset 0 0 0 1px rgba(15, 61, 46, 0.22);
}

.chat-thread__messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 0.4rem;
  background: #f7f8fa;
}

.chat-note-modal__hint {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
}

.chat-note-modal__form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-note-modal__form textarea {
  width: 100%;
  resize: vertical;
  min-height: 8rem;
  max-height: 18rem;
  border: 1px solid rgba(15, 18, 22, 0.12);
  border-radius: 0.65rem;
  padding: 0.65rem 0.75rem;
  font: inherit;
  font-size: 0.92rem;
  background: #fff;
}

.chat-note-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.chat-composer,
.paper-chat__composer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-top: 1px solid rgba(15, 18, 22, 0.08);
  background: #fff;
}

.chat-composer textarea,
.paper-chat__composer textarea {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  resize: none;
  min-height: 2.5rem;
  max-height: 6rem;
  border: 1px solid rgba(15, 18, 22, 0.12);
  border-radius: 0.65rem;
  padding: 0.5rem 0.65rem;
  font: inherit;
  line-height: 1.35;
}

/* Circular send: keep .btn.btn-primary colors/shadow, force equal box. */
.btn.chat-send-btn {
  flex: 0 0 auto;
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
  gap: 0;
  line-height: 0;
  border-radius: 999px;
}

.btn.chat-send-btn .icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  line-height: 0;
}

.btn.chat-send-btn svg {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  stroke: currentColor;
  stroke-width: 1.75;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  /* Optical center for the asymmetric paper-plane glyph. */
  transform: translate(0.06rem, -0.04rem);
}

.paper-chat--shop .btn.chat-send-btn {
  background: #0f3d2e;
  color: #fff;
  border-color: color-mix(in srgb, #0f3d2e 70%, var(--pop-rim));
}

.paper-chat--shop .btn.chat-send-btn:hover {
  background: #145c44;
  border-color: color-mix(in srgb, #145c44 70%, var(--pop-rim));
  color: #fff;
}

.chat-inbox__tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.chat-inbox__empty {
  padding: 1.5rem;
  margin: 0;
}

@media (max-width: 800px) {
  .chat-inbox {
    /* Account for mobile topbar + bottom nav. */
    height: calc(100dvh - 8.75rem);
    max-height: calc(100dvh - 8.75rem);
    min-height: 0;
  }

  .paper-chat {
    padding: 0;
    align-items: stretch;
  }

  .paper-chat__sheet {
    width: 100%;
    height: 100%;
    border-radius: 0;
  }
}

/* Reuse agent-reply notice classes from tokens.css (solid in-app notice). */
.paper-chat-notice--shop.chatwoot-agent-notice {
  border-color: #0f3d2e;
}
