/**
 * Site chat (modules/webchat). The round launcher keeps the place and size of the old WhatsApp button.
 * Launcher shapes come from the widget root classes (Webchat::launcherClasses): wc-circle (default), wc-square,
 * wc-bubble, wc-pill, wc-bar and wc-side, plus wc-left (left corner), wc-sm / wc-lg (size) and wc-pulse.
 */
.webchat {
  --wc-accent: var(--wc-color, var(--primary, #25d366));
  /* Text on the accent color (header, own messages, send): dark when the chosen color is light. */
  --wc-size: 54px;
  --wc-gap: 16px;
  position: fixed;
  right: var(--wc-gap);
  bottom: var(--wc-gap);
  z-index: 1030;
  font-size: 0.875rem;
}

.webchat.wc-sm {
  --wc-size: 46px;
}

.webchat.wc-lg {
  --wc-size: 64px;
}

.webchat.wc-left {
  right: auto;
  left: var(--wc-gap);
}

.webchat-launcher {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: var(--wc-size);
  height: var(--wc-size);
  padding: 0;
  border: 0;
  border-radius: 50%;
  font: inherit;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  /* Button color from Atendimento > Configurações (--wc-launcher); empty follows the window color. */
  color: var(--wc-launcher-fg, #fff);
  background: var(--wc-launcher, var(--wc-accent));
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: transform 0.15s ease-in-out;
}

.webchat-launcher:hover,
.webchat-launcher:focus {
  transform: scale(1.08);
  outline: none;
}

.webchat-launcher-open,
.webchat-launcher-close {
  display: inline-flex;
}

.webchat-launcher-close,
.webchat.is-open .webchat-launcher-open,
.webchat-launcher-label {
  display: none;
}

.webchat.is-open .webchat-launcher-close {
  display: inline-flex;
}

/* ---------- Launcher shapes ---------- */

.webchat.wc-square .webchat-launcher {
  border-radius: calc(var(--wc-size) * 0.28);
}

/* Speech bubble: the tail corner points to the corner of the screen. */
.webchat.wc-bubble .webchat-launcher {
  border-radius: 50% 50% 6px 50%;
}

.webchat.wc-bubble.wc-left .webchat-launcher {
  border-radius: 50% 50% 50% 6px;
}

/* Shapes with text (pill, bar, side): icon and label side by side. */
.webchat.wc-pill .webchat-launcher-label,
.webchat.wc-bar .webchat-launcher-label,
.webchat.wc-side .webchat-launcher-label {
  display: inline;
}

.webchat.wc-pill .webchat-launcher {
  width: auto;
  padding: 0 calc(var(--wc-size) * 0.42) 0 calc(var(--wc-size) * 0.32);
  border-radius: var(--wc-size);
}

/* Bar glued to the bottom edge of the screen; the window opens right on top of it. */
.webchat.wc-bar {
  right: 24px;
  bottom: 0;
}

.webchat.wc-bar.wc-left {
  right: auto;
  left: 24px;
}

.webchat.wc-bar .webchat-launcher {
  width: auto;
  height: calc(var(--wc-size) * 0.8);
  padding: 0 20px;
  border-radius: 10px 10px 0 0;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.18);
}

.webchat.wc-bar .webchat-launcher:hover,
.webchat.wc-bar .webchat-launcher:focus {
  transform: none;
}

.webchat.wc-bar .webchat-launcher svg {
  width: 20px;
  height: 20px;
}

/* Side tab glued to the right (or left) edge, vertically centered, text reading bottom to top. */
.webchat.wc-side {
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  pointer-events: none;
}

.webchat.wc-side.wc-left {
  right: auto;
  left: 0;
}

.webchat.wc-side > * {
  pointer-events: auto;
}

.webchat.wc-side .webchat-launcher,
.webchat.wc-side .webchat-launcher:hover,
.webchat.wc-side .webchat-launcher:focus {
  transform: rotate(180deg);
}

.webchat.wc-side .webchat-launcher {
  width: calc(var(--wc-size) * 0.75);
  height: auto;
  padding: 18px 0;
  border-radius: 0 10px 10px 0;
  box-shadow: -2px 0 12px rgba(0, 0, 0, 0.18);
  writing-mode: vertical-rl;
}

.webchat.wc-side.wc-left .webchat-launcher {
  border-radius: 10px 0 0 10px;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.18);
}

/* The tab is turned upside down: the icon and the badge turn back. */
.webchat.wc-side .webchat-launcher svg,
.webchat.wc-side .webchat-badge {
  transform: rotate(180deg);
}

.webchat.wc-side .webchat-launcher svg {
  width: 20px;
  height: 20px;
}

/* Badge on the inner top corner (coordinates are upside down because of the rotation). */
.webchat.wc-side .webchat-badge {
  top: auto;
  right: -6px;
  bottom: -6px;
  left: auto;
  writing-mode: horizontal-tb;
}

.webchat.wc-side.wc-left .webchat-badge {
  right: auto;
  left: -6px;
}

/* Side tab at the top (below a fixed site header) or at the bottom of the edge; the window and the teaser follow. */
.webchat.wc-side.wc-align-top {
  align-items: flex-start;
  padding-top: var(--wc-side-top, 120px);
}

.webchat.wc-side.wc-align-bottom {
  align-items: flex-end;
  padding-bottom: var(--wc-side-bottom, 24px);
}

.webchat.wc-side.wc-align-top .webchat-panel,
.webchat.wc-side.wc-align-top .webchat-teaser {
  top: var(--wc-side-top, 120px);
  transform: none;
}

/* The window starts at the tab and must still fit on the screen. */
.webchat.wc-side.wc-align-top .webchat-panel {
  height: min(560px, calc(100vh - var(--wc-side-top, 120px) - 16px));
}

.webchat.wc-side.wc-align-bottom .webchat-panel {
  height: min(560px, calc(100vh - var(--wc-side-bottom, 24px) - 16px));
}

.webchat.wc-side.wc-align-bottom .webchat-panel,
.webchat.wc-side.wc-align-bottom .webchat-teaser {
  top: auto;
  bottom: var(--wc-side-bottom, 24px);
  transform: none;
}

/* Pulse: a ring grows around the closed launcher to draw attention. */
.webchat-launcher::after {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  content: '';
}

.webchat.wc-pulse:not(.is-open) .webchat-launcher::after {
  animation: webchat-pulse 2.4s ease-out infinite;
}

@keyframes webchat-pulse {
  0% {
    box-shadow: 0 0 0 0 var(--wc-launcher, var(--wc-accent));
    opacity: 0.6;
  }

  80%,
  100% {
    box-shadow: 0 0 0 14px var(--wc-launcher, var(--wc-accent));
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .webchat.wc-pulse:not(.is-open) .webchat-launcher::after {
    animation: none;
  }
}

/* ---------- Teaser: short message next to the launcher, once per visit ---------- */

.webchat-teaser {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  display: flex;
  align-items: flex-start;
  gap: 4px;
  width: max-content;
  max-width: 260px;
  padding: 10px 6px 10px 14px;
  border-radius: 12px;
  color: #344050;
  background: #fff;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  animation: webchat-teaser-in 0.25s ease-out;
}

.webchat-teaser[hidden],
.webchat.is-open .webchat-teaser {
  display: none;
}

.webchat.wc-left .webchat-teaser {
  right: auto;
  left: 0;
}

.webchat.wc-side .webchat-teaser {
  top: 50%;
  right: calc(100% + 12px);
  bottom: auto;
  transform: translateY(-50%);
  animation: none;
}

.webchat.wc-side.wc-left .webchat-teaser {
  right: auto;
  left: calc(100% + 12px);
}

.webchat-teaser-text {
  padding: 0;
  border: 0;
  font: inherit;
  color: inherit;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.webchat-teaser-close {
  display: inline-flex;
  flex: 0 0 auto;
  padding: 2px;
  border: 0;
  color: #8a94a3;
  background: transparent;
  cursor: pointer;
}

@keyframes webchat-teaser-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.webchat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 20px;
  color: #fff;
  background: #e63757;
}

.webchat-badge[hidden] {
  display: none;
}

.webchat-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  display: flex;
  flex-direction: column;
  width: 360px;
  height: min(560px, calc(100vh - 100px));
  overflow: hidden;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

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

.webchat.wc-left .webchat-panel {
  right: auto;
  left: 0;
}

/* Bar: the window sits on the bar, without a gap. */
.webchat.wc-bar .webchat-panel {
  bottom: 100%;
  border-radius: 12px 12px 0 0;
}

.webchat.wc-side .webchat-panel {
  top: 50%;
  right: calc(100% + 12px);
  bottom: auto;
  transform: translateY(-50%);
}

.webchat.wc-side.wc-left .webchat-panel {
  right: auto;
  left: calc(100% + 12px);
}

.webchat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 12px 16px;
  color: var(--wc-on-accent, #fff);
  background: var(--wc-accent);
}

.webchat-header-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.webchat-header-text strong {
  font-size: 1rem;
}

.webchat-header-text small {
  opacity: 0.9;
}

.webchat-header-text small::before {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: #7ef0a6;
  content: '';
}

.webchat.is-offline .webchat-header-text small::before {
  background: #ffd666;
}

.webchat-close {
  display: inline-flex;
  padding: 4px;
  border: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
}

.webchat-end {
  margin-left: auto;
  margin-right: 4px;
  padding: 3px 10px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 14px;
  font-size: 0.75rem;
  color: inherit;
  background: transparent;
  cursor: pointer;
}

.webchat-end:hover,
.webchat-end:focus {
  background: rgba(255, 255, 255, 0.15);
  outline: none;
}

.webchat-end[hidden],
.webchat-confirm[hidden] {
  display: none;
}

.webchat-confirm {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid #e3e6ea;
  background: #fff8e6;
}

.webchat-confirm span {
  flex: 1 1 auto;
}

.webchat-confirm button {
  padding: 4px 10px;
  border: 1px solid #d8e2ef;
  border-radius: 14px;
  font-size: 0.8125rem;
  background: #fff;
  cursor: pointer;
}

.webchat-confirm .webchat-confirm-yes {
  border-color: #e63757;
  color: #fff;
  background: #e63757;
}

.webchat-body {
  flex: 1 1 auto;
  padding: 12px;
  overflow-y: auto;
  background: #f5f6f8;
}

.webchat-intro {
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 10px;
  color: #4d5969;
  background: #fff;
}

.webchat-day {
  margin: 10px 0 6px;
  font-size: 0.75rem;
  color: #8a94a3;
  text-align: center;
}

.webchat-day span {
  padding: 2px 10px;
  border-radius: 10px;
  background: #e8eaee;
}

.webchat-author {
  margin: 6px 0 2px 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #5e6e82;
}

.webchat-msg {
  position: relative;
  max-width: 82%;
  padding: 7px 10px 18px;
  margin-bottom: 4px;
  border-radius: 10px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.webchat-msg.is-theirs {
  color: #344050;
  background: #fff;
  border-top-left-radius: 2px;
}

.webchat-msg.is-mine {
  margin-left: auto;
  color: var(--wc-on-accent, #fff);
  background: var(--wc-accent);
  border-top-right-radius: 2px;
}

.webchat-msg.is-mine a {
  color: inherit;
  text-decoration: underline;
}

/* Robot menu options */
.webchat-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 4px;
}

.webchat-option {
  padding: 6px 12px;
  border: 1px solid var(--wc-accent);
  border-radius: 16px;
  color: var(--wc-accent);
  background: #fff;
  cursor: pointer;
  text-align: left;
}

.webchat-option:hover,
.webchat-option:focus {
  color: var(--wc-on-accent, #fff);
  background: var(--wc-accent);
  outline: none;
}

/** Robot link button inside the message (e.g. "Criar minha conta"). */
.webchat-link {
  display: inline-block;
  margin-top: 6px;
  text-decoration: none;
}

.webchat-option:disabled {
  opacity: 0.6;
  cursor: default;
}

.webchat-time {
  position: absolute;
  right: 8px;
  bottom: 3px;
  font-size: 0.6875rem;
  opacity: 0.7;
}

.webchat-media img,
.webchat-media video {
  display: block;
  max-width: 100%;
  border-radius: 6px;
}

.webchat-media audio {
  max-width: 100%;
}

.webchat-media + .webchat-text {
  margin-top: 4px;
}

.webchat-file::before {
  content: '\1F4CE  ';
}

.webchat-form {
  padding: 8px;
  border-top: 1px solid #e3e6ea;
  background: #fff;
}

.webchat-form.is-sending {
  opacity: 0.7;
}

.webchat-identify {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

/** Name and mobile phone side by side, e-mail on its own line below. */
.webchat-identify input {
  flex: 1 1 40%;
  min-width: 0;
}

.webchat-identify input[name='email'] {
  flex-basis: 100%;
}

.webchat-identify[hidden],
.webchat-error[hidden] {
  display: none;
}

.webchat-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
}

.webchat-error {
  margin-bottom: 6px;
  font-size: 0.8125rem;
  color: #e63757;
}

.webchat-composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.webchat-composer textarea {
  flex: 1 1 auto;
  max-height: 120px;
  padding: 7px 10px;
  border: 1px solid #d8e2ef;
  border-radius: 18px;
  resize: none;
  outline: none;
}

.webchat-composer textarea:focus {
  border-color: var(--wc-accent);
}

.webchat-send {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--wc-on-accent, #fff);
  background: var(--wc-accent);
  cursor: pointer;
}

/* Phone: full screen window, the launcher hides while it is open. */
@media (max-width: 575.98px) {
  .webchat-panel,
  .webchat.wc-bar .webchat-panel,
  .webchat.wc-side .webchat-panel {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    border-radius: 0;
    transform: none;
  }

  /* Side tab at the top or bottom: the full screen window ignores the tab height. */
  .webchat.wc-side.wc-align-top .webchat-panel,
  .webchat.wc-side.wc-align-bottom .webchat-panel {
    top: 0;
    bottom: 0;
    height: auto;
  }

  .webchat-teaser {
    max-width: calc(100vw - 2 * var(--wc-gap));
  }

  .webchat.is-open .webchat-launcher {
    display: none;
  }

  .webchat-identify {
    flex-direction: column;
  }

  .webchat-composer textarea {
    font-size: 16px; /* avoids the iOS auto zoom */
  }
}
