/* Chat widget embedded on other sites, so every value is scoped to the
   widget's own elements. Styled like Messages; follows the OS light/dark
   setting; the panel grows out of the button that opens it. */
.pipeline-widget-toggle,
.pipeline-widget-panel {
  --pw-bg: #ffffff;
  --pw-bar: rgba(249, 249, 251, .82);
  --pw-bubble: #e9e9eb;
  --pw-field: #ffffff;
  --pw-border: rgba(60, 60, 67, .16);
  --pw-text: #1d1d1f;
  --pw-muted: #6e6e73;
  --pw-accent: #007aff;
  --pw-accent-h: #0066d6;
  --pw-green: #248a3d;
  --pw-shadow: 0 12px 40px rgba(0, 0, 0, .18), 0 2px 8px rgba(0, 0, 0, .06);
  --pw-font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI Variable Text', 'Segoe UI', system-ui, sans-serif;
  /* Critically damped spring (damping 1.0, response 0.2s). */
  --pw-spring: linear(0, 0.118, 0.329, 0.527, 0.682, 0.793, 0.868, 0.917, 0.949, 0.969, 0.981, 0.989, 0.993, 0.996, 0.998, 0.999, 1);
  --pw-spring-dur: 300ms;
}

@media (prefers-color-scheme: dark) {
  .pipeline-widget-toggle,
  .pipeline-widget-panel {
    --pw-bg: #000000;
    --pw-bar: rgba(28, 28, 30, .82);
    --pw-bubble: #26252a;
    --pw-field: #1c1c1e;
    --pw-border: rgba(255, 255, 255, .1);
    --pw-text: #f5f5f7;
    --pw-muted: #98989d;
    --pw-accent: #0a84ff;
    --pw-accent-h: #409cff;
    --pw-green: #30d158;
    --pw-shadow: 0 16px 48px rgba(0, 0, 0, .55), 0 0 0 .5px rgba(255, 255, 255, .1);
  }
}

.pipeline-widget-toggle {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  border: none;
  background: var(--pw-accent);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--pw-accent) 40%, transparent);
  transition: transform var(--pw-spring-dur) var(--pw-spring), background-color .2s ease;
}

.pipeline-widget-toggle:active {
  transform: scale(.9);
  transition-duration: 120ms;
}

.pipeline-widget-toggle svg {
  width: 1.5rem;
  height: 1.5rem;
}

/* Opens and closes along the same path, anchored to the toggle's corner. */
.pipeline-widget-panel {
  position: fixed;
  bottom: 5.5rem;
  right: 1.5rem;
  z-index: 1000;
  width: min(380px, calc(100vw - 2rem));
  height: min(560px, calc(100vh - 7rem));
  background: var(--pw-bg);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--pw-shadow);
  font-family: var(--pw-font);
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
  opacity: 0;
  transform: scale(.6);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity .25s ease, transform var(--pw-spring-dur) var(--pw-spring);
}

.pipeline-widget-panel.open {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.pipeline-widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1rem;
  background: var(--pw-bar);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: .5px solid var(--pw-border);
}

.pipeline-widget-header-info {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.pipeline-widget-avatar {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: color-mix(in srgb, var(--pw-accent) 14%, transparent);
  color: var(--pw-accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.pipeline-widget-title {
  font-family: var(--pw-font);
  font-size: .9375rem;
  font-weight: 600;
  color: var(--pw-text);
  margin: 0;
}

.pipeline-widget-status {
  font-family: var(--pw-font);
  font-size: .75rem;
  color: var(--pw-green);
  margin: 0;
}

.pipeline-widget-close {
  background: color-mix(in srgb, var(--pw-muted) 16%, transparent);
  border: none;
  color: var(--pw-muted);
  cursor: pointer;
  padding: .3rem;
  border-radius: 50%;
  display: flex;
  transition: color .2s ease, background-color .2s ease, transform var(--pw-spring-dur) var(--pw-spring);
}

.pipeline-widget-close:active {
  transform: scale(.88);
  transition-duration: 120ms;
}

.pipeline-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem .875rem;
  display: flex;
  flex-direction: column;
  gap: .375rem;
}

.pipeline-widget-messages::-webkit-scrollbar {
  width: 6px;
}

.pipeline-widget-messages::-webkit-scrollbar-thumb {
  background: var(--pw-border);
  border-radius: 6px;
}

.pipeline-msg {
  max-width: 80%;
  padding: .5rem .875rem;
  border-radius: 18px;
  font-family: var(--pw-font);
  font-size: .9375rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  animation: pipeline-bubble-in var(--pw-spring-dur) var(--pw-spring) both;
}

.pipeline-msg-bot {
  align-self: flex-start;
  background: var(--pw-bubble);
  color: var(--pw-text);
  border-bottom-left-radius: 6px;
  transform-origin: bottom left;
}

.pipeline-msg-user {
  align-self: flex-end;
  background: var(--pw-accent);
  color: #fff;
  border-bottom-right-radius: 6px;
  transform-origin: bottom right;
}

.pipeline-msg-bot + .pipeline-msg-user,
.pipeline-msg-user + .pipeline-msg-bot,
.pipeline-msg-user + .pipeline-msg-typing {
  margin-top: .5rem;
}

.pipeline-msg-typing {
  align-self: flex-start;
  background: var(--pw-bubble);
  color: var(--pw-muted);
  border-bottom-left-radius: 6px;
  transform-origin: bottom left;
  padding: .75rem 1rem;
}

.pipeline-msg-typing span {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: var(--pw-muted);
  border-radius: 50%;
  margin: 0 2px;
  animation: pipeline-bounce 1.2s infinite;
}

.pipeline-msg-typing span:nth-child(2) { animation-delay: .15s; }
.pipeline-msg-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes pipeline-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-3px); opacity: 1; }
}

@keyframes pipeline-bubble-in {
  from { opacity: 0; transform: scale(.85); }
}

.pipeline-widget-input-area {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: .625rem .75rem .75rem;
  padding: 4px 4px 4px 14px;
  background: var(--pw-field);
  border: 1px solid var(--pw-border);
  border-radius: 22px;
  transition: border-color .2s ease, box-shadow .2s ease;
}

.pipeline-widget-input-area:focus-within {
  border-color: var(--pw-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--pw-accent) 22%, transparent);
}

.pipeline-widget-input {
  flex: 1;
  min-width: 0;
  padding: .375rem 0;
  background: transparent;
  border: none;
  color: var(--pw-text);
  font-family: var(--pw-font);
  font-size: 1rem; /* 16px: iOS zooms into smaller fields */
  outline: none;
}

.pipeline-widget-input::placeholder {
  color: var(--pw-muted);
  opacity: .7;
}

.pipeline-widget-send {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: none;
  background: var(--pw-accent);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color .2s ease, opacity .2s ease, transform var(--pw-spring-dur) var(--pw-spring);
}

.pipeline-widget-send svg {
  width: 1rem;
  height: 1rem;
}

.pipeline-widget-send:active:not(:disabled) {
  transform: scale(.88);
  transition-duration: 120ms;
}

.pipeline-widget-send:disabled {
  opacity: .35;
  cursor: not-allowed;
}

@media (hover: hover) {
  .pipeline-widget-toggle:hover { background: var(--pw-accent-h); }
  .pipeline-widget-close:hover { color: var(--pw-text); }
  .pipeline-widget-send:hover:not(:disabled) { background: var(--pw-accent-h); }
}

@media (max-width: 480px) {
  /* On a phone the chat takes the whole screen. */
  .pipeline-widget-panel {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
  }

  .pipeline-widget-toggle {
    bottom: 1rem;
    right: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pipeline-widget-panel { transform: none; transition: opacity .2s ease; }
  .pipeline-msg { animation: none; }
  .pipeline-msg-typing span { animation: none; }
  .pipeline-widget-toggle:active,
  .pipeline-widget-close:active,
  .pipeline-widget-send:active:not(:disabled) { transform: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .pipeline-widget-header {
    background: var(--pw-bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  .pipeline-widget-panel { border: 1px solid rgba(127, 127, 127, .6); }
  .pipeline-msg-bot, .pipeline-msg-typing { border: 1px solid rgba(127, 127, 127, .6); }
}
