/*
 * support_chat.css — the support conversation view (support_thread.html,
 * driven by static/js/controllers/esm/support_chat_controller.js).
 *
 * Bubbles, composer and buttons are the shared widget chrome (.pchat-msg--user
 * for my side, .pchat-msg--assistant for the other, .pchat-input-row,
 * .pchat-mic, .pchat-send in public_chat.css); this file only arranges them
 * into a Messenger-style thread: sender runs, day separators, system lines,
 * photos, Seen and typing lines. Colours come from the .pchat tokens
 * (ai_chat.css); no literal colours here.
 */

.support-thread [hidden] { display: none; }

/* ---------- Alerts (support_alerts_controller.js) ---------- */
/* Unread count on the closed launcher's top-right corner. */
.pchat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 16px;
  text-align: center;
  background: var(--danger-color);
  color: var(--white);
  pointer-events: none;
}
.pchat-badge[hidden],
.pchat--open .pchat-badge { display: none; }

/* The preview of an unread message: a card above the closed launcher, its
   right edge on the launcher's. As wide as a phone allows (the widget sits
   20px in from the right, so the same gutter is kept on the left). */
.support-card {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  width: min(320px, calc(100vw - 40px));
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(26, 26, 26, 0.12);
}
.support-card[hidden],
.pchat--open .support-card { display: none; }
.support-card-open {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 10px;
  row-gap: 2px;
  width: 100%;
  /* Right padding clears the close button in the corner. */
  padding: 12px 40px 10px 12px;
  font: inherit;
  text-align: left;
  color: var(--black);
  background: none;
  border: none;
  border-radius: inherit;
  cursor: pointer;
}
.support-card-open:hover { background: var(--sandstone); }
/* Two classes: the thread's .support-initial, further down, sets the small size. */
.support-card .support-card-initial {
  grid-row: 1 / span 2;
  width: 32px;
  height: 32px;
  font-size: 14px;
}
.support-card-name { font-size: 14px; line-height: 1.3; }
.support-card-text {
  grid-column: 2;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--text-2);
  overflow-wrap: break-word;
}
.support-card-reply {
  grid-column: 2;
  justify-self: end;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--orange-deep);
}
.support-card-dismiss {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 12px;
  color: var(--text-2);
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}
.support-card-dismiss:hover { background: var(--sandstone); color: var(--black); }
/* Pop-in: rises out of the launcher below it. */
.support-card--show {
  transform-origin: bottom right;
  animation: support-card-pop 0.28s var(--ease-overshoot) both;
}
@keyframes support-card-pop {
  0% { opacity: 0; transform: translateY(8px) scale(0.9); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .support-card--show { animation: none; }
}

.support-actions .support-mute { margin-left: auto; color: var(--text-2); }

.support-home,
.support-region,
.support-thread {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.support-region[hidden] { display: none; }

/* ---------- Loading placeholders ---------- */
/* Grey bubble shapes instead of an empty pane: .support-skeleton while
   support-inbox waits on GET /api/support/me, and a thread's empty message
   list on its first open (support-messages--loading, support_chat_controller.js). */
.support-skeleton {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
}
.support-skeleton[hidden] { display: none; }
.support-skeleton span,
.support-messages--loading:empty::before,
.support-messages--loading:empty::after {
  display: block;
  height: 38px;
  border-radius: 16px;
  background: linear-gradient(90deg, var(--border) 0%, var(--white) 50%, var(--border) 100%)
    0 0 / 200% 100%;
  animation: support-shimmer 1.1s linear infinite;
}
.support-skeleton span:nth-child(1) { width: 62%; }
.support-skeleton span:nth-child(2) { width: 44%; align-self: flex-end; }
.support-skeleton span:nth-child(3) { width: 70%; }
.support-messages--loading:empty {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.support-messages--loading:empty::before { content: ""; width: 58%; }
.support-messages--loading:empty::after { content: ""; width: 42%; align-self: flex-end; }
@keyframes support-shimmer {
  to { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .support-skeleton span,
  .support-messages--loading:empty::before,
  .support-messages--loading:empty::after { animation: none; }
}

/* ---------- Staff: inbox and thread header (support_inbox_controller.js) ---------- */
.support-staff-bar,
.support-staff-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}
.support-staff-bar strong { flex: 1; font-size: 14px; }
.support-staff-bar .support-mute {
  padding: 4px 8px;
  color: var(--text-2);
  background: none;
  border: none;
}
.support-staff-who {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  font-size: 13.5px;
}
.support-staff-who span {
  font-size: 12px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.support-claim {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-2);
}
/* Tickets raised from the thread: one line each, a few lines at most. */
.support-staff-tickets {
  max-height: 66px;
  overflow-y: auto;
  padding: 4px 12px;
  font-size: 12.5px;
  background: var(--sandstone);
  border-bottom: 1px solid var(--border);
}
.support-ticket {
  display: flex;
  gap: 6px;
  line-height: 1.6;
  white-space: nowrap;
}
.support-ticket a { flex-shrink: 0; color: var(--orange-deep); }
.support-ticket-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.support-ticket-status { flex-shrink: 0; color: var(--text-2); }

.support-inbox-actions,
.support-inbox-filters { flex-direction: row; flex-wrap: wrap; }
.support-inbox-filters button[aria-pressed="true"] {
  border-color: var(--orange);
  color: var(--orange-deep);
}
.support-inbox-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.support-inbox-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  text-align: left;
  color: var(--black);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
}
.support-inbox-row:hover,
.support-inbox-row.is-current { border-color: var(--orange); }
.support-inbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.support-inbox-line strong { flex: 1; font-size: 14px; }
.support-inbox-business { font-size: 12px; color: var(--text-2); }
.support-inbox-preview {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.support-inbox-wait { font-size: 12px; color: var(--orange-deep); }
.support-inbox-unread {
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  background: var(--danger-color);
  color: var(--white);
}
.support-inbox-empty { margin: 8px 0; font-size: 13.5px; color: var(--text-2); }

/* New conversation: the customer search that replaces the list; its results
   are .support-inbox-row buttons. */
.support-customer-search-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
}
.support-customer-search-bar input { flex: 1; min-width: 0; }

/* ---------- Admin support page (templates/admin/support_inbox.html) ---------- */
/* The list beside the thread at full height; on a phone one at a time, as in
   the widget (support-thread-open is set by support-inbox). */
.support-admin [hidden] { display: none; }
/* One row the height of the box, so each column scrolls inside it. */
.support-admin-inbox {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  grid-template-rows: minmax(0, 1fr);
  height: calc(100vh - 240px);
  min-height: 520px;
  overflow: hidden;
  background: var(--sandstone);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.support-admin-list { border-right: 1px solid var(--border); }
.support-admin-thread { min-width: 0; }
.support-admin-placeholder { margin: auto; color: var(--text-2); }
.support-admin-sent { margin: 0; padding: 6px 12px; font-size: 13px; }

@media (min-width: 992px) {
  .support-admin .support-back { display: none; }
}
@media (max-width: 991.98px) {
  .support-admin-inbox { grid-template-columns: 1fr; }
  .support-admin-inbox.support-thread-open .support-admin-list,
  .support-admin-inbox:not(.support-thread-open) .support-admin-thread { display: none; }
  /* An open thread is the screen, from the top down to the bottom nav, as the
     widget's sheet is: the reply box is always in view. The message area keeps
     its scroll to itself (.pchat-body, overscroll-behavior: contain), so a box
     taller than the screen could never be dragged into view. Below the nav's
     layer (1000), and down to the screen's edge while the keyboard has the nav
     off-screen. */
  .support-admin-inbox.support-thread-open {
    position: fixed;
    inset: 0 0 calc(var(--mobile-nav-height) + var(--mobile-nav-safe-bottom)) 0;
    z-index: 990;
    height: auto;
    min-height: 0;
    padding-top: env(safe-area-inset-top);
    border: none;
    border-radius: 0;
  }
  body[data-keyboard-open] .support-admin-inbox.support-thread-open { bottom: 0; }
  /* The closed Chip launcher floats where the reply box's Send button is. */
  body:has(.support-admin-inbox.support-thread-open) .pchat--app:not(.pchat--open) { display: none; }
}


/* ---------- Messages ---------- */
.support-messages {
  display: flex;
  flex-direction: column;
}
.support-run {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 10px;
}
.support-run--own { align-items: flex-end; }
.support-run--other { align-items: flex-start; }

.support-bubble-row {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 88%;
}
.support-run--own .support-bubble-row { flex-direction: row-reverse; }
.support-bubble-row .support-msg { max-width: 100%; }

.support-sender {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
  font-size: 12px;
  color: var(--text-2);
}
.support-initial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 600;
  background: var(--green);
  color: var(--white);
}

.support-img {
  display: block;
  width: 100%;
  max-width: 220px;
  border-radius: 8px;
}
.support-msg a + div { margin-top: 6px; }
/* A photo with no caption is shown bare, not inside a bubble. */
.support-msg--photo {
  padding: 0;
  background: none;
  border: none;
}

.support-day,
.support-system {
  align-self: center;
  max-width: 88%;
  margin: 6px 0 10px;
  font-size: 12px;
  color: var(--text-2);
  text-align: center;
}
.support-system { font-size: 12.5px; font-style: italic; }

.support-seen,
.support-typing {
  font-size: 11.5px;
  color: var(--text-2);
}
.support-typing { margin: 0 0 4px; font-style: italic; }

.support-retry {
  display: block;
  margin-top: 4px;
  padding: 0;
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  color: inherit;
  text-decoration: underline;
  background: none;
  border: none;
  cursor: pointer;
}

/* The action bar of a message (time, React, Edit, Raise a ticket; or the
   emoji to pick from): a pill over the message's top corner on its own side.
   Shown on hover where there is one, while a button in it has focus, and on
   the tapped message (.is-active, support_chat_controller.js). */
.support-bubble-row { position: relative; }
.support-msg-actions {
  position: absolute;
  bottom: calc(100% - 6px);
  left: 0;
  z-index: 1;
  display: none;
  align-items: center;
  gap: 2px;
  padding: 2px 6px;
  white-space: nowrap;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(26, 26, 26, 0.12);
}
.support-run--own .support-msg-actions { right: 0; left: auto; }
.support-bubble-row.is-active .support-msg-actions,
.support-bubble-row:focus-within .support-msg-actions { display: flex; }
@media (hover: hover) {
  .support-bubble-row:hover .support-msg-actions { display: flex; }
}
.support-time {
  padding: 0 4px;
  font-size: 11.5px;
  color: var(--text-2);
}
.support-msg-action {
  min-width: 28px;
  height: 28px;
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
  color: var(--text-2);
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}
.support-msg-action:hover,
.support-msg-action:focus-visible { background: var(--sandstone); color: var(--black); }

/* Under a message: "edited" and its reactions. */
.support-msg-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.support-edited { font-size: 11.5px; color: var(--text-2); }
.support-reaction {
  padding: 1px 8px;
  font: inherit;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--black);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.support-reaction.is-mine { border-color: var(--orange); }

/* A link to an app page in a staff message. Inherits the bubble's text colour
   so it reads on either side's bubble. */
.support-link {
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- Composer ---------- */
.support-composer { position: relative; align-items: flex-end; }

/* Staff "Link a page" search, opening above the composer row. */
.support-link-picker {
  position: absolute;
  right: 8px;
  bottom: calc(100% + 4px);
  left: 8px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  padding: 8px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(26, 26, 26, 0.12);
}
.support-link-picker[hidden] { display: none; }
.support-link-query { flex: none; border-radius: 8px; }
.support-link-results { overflow-y: auto; }
.support-link-result {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 6px 8px;
  text-align: left;
  background: none;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.support-link-result:hover,
.support-link-result:focus-visible { background: var(--sandstone); }
.support-link-result small,
.support-link-empty {
  font-size: 12px;
  color: var(--text-2);
}
.support-link-empty { margin: 4px 8px; }
.support-preview {
  position: relative;
  padding: 8px 12px 0;
  background: var(--white);
  border-top: 1px solid var(--border);
}
/* "Editing message" over the composer while a sent message is being changed. */
.support-editing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--text-2);
  background: var(--white);
  border-top: 1px solid var(--border);
}
.support-editing span { flex: 1; min-width: 0; }
.support-editing-cancel {
  padding: 2px 6px;
  color: var(--text-2);
  background: none;
  border: none;
  cursor: pointer;
}
.support-preview img {
  display: block;
  max-height: 80px;
  border-radius: 8px;
}
.support-preview-remove {
  position: absolute;
  top: 12px;
  left: 16px;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 11px;
  border-radius: 50%;
  border: none;
  background: var(--black);
  color: var(--white);
  cursor: pointer;
}
