/* Live support: the floating launcher, the panel, and the chat shared with the console. */

.support-launcher {
  position: fixed;
  right: var(--space-6);
  bottom: var(--space-6);
  z-index: 40;
  display: grid;
  place-items: center;
  width: var(--control-xl);
  height: var(--control-xl);
  padding: 0;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 8px 24px rgb(0 0 0 / calc(0.4 * var(--shade)));
  cursor: pointer;
}

.support-launcher:hover {
  filter: brightness(1.1);
}

.support-launcher__dot {
  position: absolute;
  top: 4px;
  right: 4px;
  display: none;
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent);
  border-radius: var(--radius-full);
  background: var(--win);
}

.support-launcher.has-unread .support-launcher__dot {
  display: block;
}

.support-panel {
  position: fixed;
  right: var(--space-6);
  bottom: calc(var(--space-6) + var(--control-xl) + var(--space-3));
  z-index: 40;
  display: flex;
  flex-direction: column;
  width: 380px;
  height: min(640px, 100dvh - 140px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-0);
  box-shadow: 0 24px 64px rgb(0 0 0 / calc(0.5 * var(--shade)));
}

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

.support-panel__head {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
  background: var(--surface-1);
}

.support-panel__avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--surface-0);
}

.support-panel__avatar img {
  width: 26px;
  height: 26px;
}

.support-panel__heading {
  flex: 1;
  min-width: 0;
}

.support-panel__heading h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.3;
}

.support-panel__heading p {
  margin: 0;
  color: var(--ink-muted);
  font-size: 12px;
  line-height: 1.4;
}

.support-panel__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

/* Chat */
.chat {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.chat__log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 0;
  padding: var(--space-4);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat__messages {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.message {
  display: flex;
  flex-direction: column;
  align-self: flex-start;
  align-items: flex-start;
  gap: 2px;
  max-width: 82%;
}

.message__body {
  margin: 0;
  padding: 10px 14px;
  border-radius: 16px 16px 16px 4px;
  background: var(--surface-2);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat[data-viewer="visitor"] .message--visitor,
.chat[data-viewer="agent"] .message--agent {
  align-self: flex-end;
  align-items: flex-end;
}

.chat[data-viewer="visitor"] .message--visitor .message__body,
.chat[data-viewer="agent"] .message--agent .message__body {
  border-radius: 16px 16px 4px;
  background: var(--accent);
  color: var(--on-accent);
}

.message__time {
  padding: 0 var(--space-1);
  color: var(--ink-muted);
  font-size: 11px;
}

.chat__resolved {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) 0;
  color: var(--ink-muted);
  font-size: 13px;
  text-align: center;
}

.chat__resolved p {
  margin: 0;
}

.chat[data-viewer="visitor"]:has(.chat__status[data-status="resolved"]) .chat__resolved {
  display: flex;
}

.chat[data-viewer="visitor"]:has(.chat__status[data-status="resolved"]) .composer {
  display: none;
}

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

.composer__input {
  flex: 1;
  min-width: 0;
  min-height: var(--control-md);
  max-height: 128px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  outline: none;
  background: var(--surface-0);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  resize: none;
}

.composer__input:focus {
  border-color: var(--focus);
}

.composer__input::placeholder {
  color: var(--ink-muted);
}

.composer__send {
  display: grid;
  flex: none;
  place-items: center;
  width: var(--control-md);
  height: var(--control-md);
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}

.composer:has(.composer__input:placeholder-shown) .composer__send,
.composer[aria-busy="true"] .composer__send {
  opacity: 0.5;
  pointer-events: none;
}

/* Phone: no launcher (support sits in the menu) and the panel takes the whole screen. */
@media (max-width: 767px) {
  .support-launcher {
    display: none;
  }

  .support-panel {
    inset: 0;
    z-index: 50;
    width: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .support-panel__head {
    padding-top: max(var(--space-3), env(safe-area-inset-top));
  }

  .composer {
    padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
  }

  body:has(.support-panel:not([hidden])) {
    overflow: hidden;
  }
}
