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

.wfai-root {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 2147483000;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  color: var(--wf-ui-text, #0f172a);
  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: 56px;
  height: 56px;
  margin-left: auto;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(135deg, #0ea5e9 0%, #0f766e 100%);
  box-shadow:
    0 12px 32px 0 rgba(15, 118, 110, 0.38),
    inset 0 1.5px 1px 0 rgba(255, 255, 255, 0.6);
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  pointer-events: auto;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  transition: transform 200ms var(--wf-spring, ease), box-shadow 200ms ease, filter 200ms ease;
}

.wfai-launcher::after {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.6);
  content: "";
}

.wfai-launcher:hover {
  filter: brightness(1.08);
  box-shadow:
    0 16px 36px 0 rgba(15, 118, 110, 0.45),
    inset 0 1.5px 1px 0 rgba(255, 255, 255, 0.8);
  transform: translateY(-2.5px) scale(1.04);
}

.wfai-launcher:active {
  transform: scale(0.94);
}

.wfai-launcher:focus-visible,
.wfai-icon-button:focus-visible,
.wfai-send:focus-visible,
.wfai-input:focus-visible {
  outline: 3px solid rgba(14, 165, 233, 0.4);
  outline-offset: 2px;
}

.wfai-panel {
  position: absolute;
  right: 0;
  bottom: 72px;
  display: grid;
  width: min(390px, calc(100vw - 32px));
  height: min(600px, calc(100vh - 110px));
  min-height: 400px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: var(--wf-radius-xl, 20px);
  background: rgba(255, 255, 255, 0.82);
  box-shadow:
    0 24px 64px 0 rgba(15, 23, 42, 0.16),
    0 8px 24px 0 rgba(15, 23, 42, 0.08),
    inset 0 1.5px 1.5px 0 rgba(255, 255, 255, 0.95);
  -webkit-backdrop-filter: blur(36px) saturate(200%);
  backdrop-filter: blur(36px) saturate(200%);
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px) scale(0.96);
  transform-origin: bottom right;
  visibility: hidden;
  transition: opacity 220ms ease, transform 240ms var(--wf-spring, ease), visibility 220ms ease;
}

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

.wfai-header {
  display: flex;
  min-height: 66px;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 12px 18px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.7);
  background: rgba(255, 255, 255, 0.65);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

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

.wfai-title {
  margin: 0;
  color: var(--wf-ui-text, #0f172a);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.wfai-context {
  margin: 3px 0 0;
  overflow: hidden;
  color: var(--wf-ui-muted, #64748b);
  font-size: 11.5px;
  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: 32px;
  height: 32px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  color: var(--wf-ui-muted, #64748b);
  background: rgba(255, 255, 255, 0.5);
  font: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.wfai-icon-button:hover {
  color: var(--wf-ui-primary, #0f766e);
  background: rgba(240, 249, 248, 0.9);
  transform: scale(1.05);
}

.wfai-messages {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 16px 14px;
  scroll-behavior: smooth;
}

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

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

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

.wfai-message-assistant .wfai-bubble {
  border: 1px solid rgba(255, 255, 255, 0.85);
  color: var(--wf-ui-text, #0f172a);
  background: rgba(255, 255, 255, 0.78);
  box-shadow:
    0 4px 14px 0 rgba(15, 23, 42, 0.04),
    inset 0 1px 1px rgba(255, 255, 255, 0.9);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.wfai-message-user .wfai-bubble {
  color: #fff;
  background: linear-gradient(135deg, #0ea5e9 0%, #0f766e 100%);
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow:
    0 4px 14px 0 rgba(15, 118, 110, 0.25),
    inset 0 1px 0.5px rgba(255, 255, 255, 0.4);
}

.wfai-message-error .wfai-bubble {
  border-color: rgba(239, 68, 68, 0.3);
  color: #b91c1c;
  background: rgba(254, 242, 242, 0.85);
}

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

.wfai-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--wf-ui-primary, #0f766e);
  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 12px;
  border-top: 1px solid rgba(226, 232, 240, 0.7);
  background: rgba(255, 255, 255, 0.65);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.wfai-input {
  width: 100%;
  min-height: 42px;
  max-height: 116px;
  resize: none;
  flex: 1;
  padding: 9px 12px;
  overflow-y: auto;
  border: 1px solid rgba(203, 213, 225, 0.8);
  border-radius: var(--wf-radius-md, 12px);
  color: var(--wf-ui-text, #0f172a);
  background: rgba(255, 255, 255, 0.85);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: border-color 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}

.wfai-input::placeholder {
  color: var(--wf-ui-muted, #94a3b8);
}

.wfai-input:focus {
  border-color: var(--wf-ui-primary, #0f766e);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

.wfai-send {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: var(--wf-radius-md, 12px);
  color: #fff;
  background: linear-gradient(180deg, #0f766e 0%, #0d645e 100%);
  font: inherit;
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.25), inset 0 1px 0.5px rgba(255, 255, 255, 0.4);
  transition: transform 160ms var(--wf-spring, ease), filter 160ms ease;
}

.wfai-send:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1.5px);
}

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

@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(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .wfai-panel {
    width: calc(100vw - 24px);
    height: min(74vh, 620px);
    min-height: 360px;
    bottom: 68px;
  }

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

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