.wfai-root,
.wfai-root * {
  box-sizing: border-box;
  letter-spacing: 0;
}

.wfai-root {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 2147483000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #183230;
  pointer-events: none;
}

body:has(.modal-mask.show) .wfai-root,
body:has(.reader-mask.show) .wfai-root {
  visibility: hidden;
  opacity: 0;
}

.wfai-launcher {
  position: relative;
  display: grid;
  width: 54px;
  height: 54px;
  margin-left: auto;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.76);
  border-radius: 50%;
  color: #fff;
  background: #0f766e;
  box-shadow: 0 12px 28px rgba(19, 78, 74, 0.3);
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}

.wfai-launcher::after {
  position: absolute;
  top: 5px;
  right: 4px;
  width: 9px;
  height: 9px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #f59e0b;
  content: "";
}

.wfai-launcher:hover {
  background: #0b5f59;
  box-shadow: 0 14px 32px rgba(19, 78, 74, 0.36);
  transform: translateY(-2px);
}

.wfai-launcher:focus-visible,
.wfai-icon-button:focus-visible,
.wfai-send:focus-visible,
.wfai-input:focus-visible {
  outline: 3px solid rgba(20, 184, 166, 0.32);
  outline-offset: 2px;
}

.wfai-panel {
  position: absolute;
  right: 0;
  bottom: 68px;
  display: grid;
  width: min(380px, calc(100vw - 32px));
  height: min(590px, calc(100vh - 108px));
  min-height: 390px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid rgba(15, 118, 110, 0.2);
  border-radius: 8px;
  background: #f8fbfa;
  box-shadow: 0 24px 64px rgba(23, 52, 49, 0.24);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(0.98);
  transform-origin: bottom right;
  visibility: hidden;
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
}

.wfai-root.wfai-open .wfai-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  visibility: visible;
}

.wfai-root.wfai-open .wfai-launcher {
  background: #164e49;
}

.wfai-header {
  display: flex;
  min-height: 68px;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 16px;
  border-bottom: 1px solid #dbe8e5;
  background: #fff;
}

.wfai-heading {
  min-width: 0;
  flex: 1;
}

.wfai-title {
  margin: 0;
  color: #163e3a;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
}

.wfai-context {
  margin: 3px 0 0;
  overflow: hidden;
  color: #64807c;
  font-size: 11px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wfai-header-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 4px;
}

.wfai-icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 6px;
  color: #45635f;
  background: transparent;
  font: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: color 160ms ease, background-color 160ms ease;
}

.wfai-icon-button:hover {
  color: #0f766e;
  background: #edf6f4;
}

.wfai-messages {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 18px 14px;
  scroll-behavior: smooth;
  scrollbar-color: #b8ccc8 transparent;
  scrollbar-width: thin;
}

.wfai-message {
  display: flex;
  width: 100%;
  margin: 0 0 12px;
}

.wfai-message-user {
  justify-content: flex-end;
}

.wfai-bubble {
  max-width: 86%;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.62;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.wfai-message-assistant .wfai-bubble {
  border: 1px solid #dce9e6;
  color: #284743;
  background: #fff;
}

.wfai-message-user .wfai-bubble {
  color: #fff;
  background: #0f766e;
}

.wfai-message-error .wfai-bubble {
  border-color: #f2c7c0;
  color: #8c2d20;
  background: #fff7f5;
}

.wfai-typing {
  display: inline-flex;
  min-width: 54px;
  align-items: center;
  gap: 5px;
}

.wfai-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #5d817c;
  animation: wfai-pulse 1.1s infinite ease-in-out;
}

.wfai-typing span:nth-child(2) {
  animation-delay: 130ms;
}

.wfai-typing span:nth-child(3) {
  animation-delay: 260ms;
}

.wfai-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #dbe8e5;
  background: #fff;
}

.wfai-input {
  width: 100%;
  min-height: 42px;
  max-height: 116px;
  resize: none;
  flex: 1;
  padding: 10px 11px;
  overflow-y: auto;
  border: 1px solid #cbdcd8;
  border-radius: 7px;
  color: #183230;
  background: #fbfdfd;
  font: inherit;
  font-size: 14px;
  line-height: 1.45;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.wfai-input::placeholder {
  color: #7d9591;
}

.wfai-input:focus {
  border-color: #0f766e;
  background: #fff;
}

.wfai-send {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 7px;
  color: #fff;
  background: #0f766e;
  font: inherit;
  font-size: 21px;
  font-weight: 800;
  cursor: pointer;
  transition: background-color 160ms ease, transform 160ms ease;
}

.wfai-send:hover:not(:disabled) {
  background: #0b5f59;
  transform: translateY(-1px);
}

.wfai-send:disabled,
.wfai-input:disabled {
  cursor: wait;
  opacity: 0.58;
}

@keyframes wfai-pulse {
  0%,
  60%,
  100% {
    opacity: 0.34;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

@media (max-width: 560px) {
  .wfai-root {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
  }

  .wfai-panel {
    width: calc(100vw - 20px);
    height: min(72vh, 610px);
    min-height: 360px;
    bottom: 64px;
  }

  .wfai-launcher {
    width: 52px;
    height: 52px;
  }

  .wfai-header {
    min-height: 64px;
  }

  .wfai-messages {
    padding: 14px 11px;
  }

  .wfai-bubble {
    max-width: 90%;
    font-size: 13px;
  }
}

@media (max-height: 560px) {
  .wfai-panel {
    height: calc(100vh - 84px);
    min-height: 300px;
    bottom: 62px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .wfai-root *,
  .wfai-root *::before,
  .wfai-root *::after {
    animation: none !important;
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
