/* ============================================================
   KLIRR TECH — public documentation chat widget
   Reuses styles.css design tokens; falls back to the docs pages'
   --ds-* tokens where present so it matches either surface.
   ============================================================ */
.klirr-chat {
  position: fixed;
  right: clamp(14px, 3vw, 28px);
  bottom: clamp(14px, 3vw, 28px);
  z-index: 2000;
  font-family: var(--font, 'Manrope', 'Inter', system-ui, sans-serif);
  max-width: 100vw;
}

.klirr-chat__launcher {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: var(
    --grad-brand-soft,
    linear-gradient(120deg, #3b82f6 0%, #22d3ee 100%)
  );
  box-shadow: var(
    --ds-shadow-md,
    var(--shadow-lg, 0 24px 60px rgba(16, 27, 51, 0.14))
  );
  cursor: pointer;
  transition: transform 0.2s ease;
}
.klirr-chat__launcher:hover {
  transform: translateY(-2px) scale(1.04);
}
.klirr-chat__launcher--hidden {
  display: none;
}

.klirr-chat__panel {
  position: fixed;
  right: clamp(14px, 3vw, 28px);
  bottom: clamp(80px, 12vw, 100px);
  width: min(380px, calc(100vw - 28px));
  height: min(560px, calc(100dvh - 120px));
  max-width: calc(100vw - 28px);
  max-height: calc(100dvh - 120px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--ds-surface, var(--white, #fff));
  border: 1px solid var(--ds-border, var(--line-strong, #cbd5e6));
  border-radius: var(--ds-radius-lg, var(--r-lg, 20px));
  box-shadow: var(
    --ds-shadow-md,
    var(--shadow-lg, 0 24px 60px rgba(16, 27, 51, 0.14))
  );
}
.klirr-chat__panel[hidden] {
  display: none;
}

.klirr-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--ds-border, var(--line, #e2e8f2));
  flex-shrink: 0;
  min-width: 0;
}
.klirr-chat__title {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}
.klirr-chat__title strong {
  font-size: 0.95rem;
  color: var(--ds-text, var(--ink-900, #0b1220));
}
.klirr-chat__subtitle {
  font-size: 0.72rem;
  color: var(--ds-muted, var(--ink-500, #5a6a86));
}

.klirr-chat__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ds-muted, var(--ink-500, #5a6a86));
  cursor: pointer;
}
.klirr-chat__close:hover {
  background: var(--ds-hover, var(--paper-2, #eef2f9));
}

.klirr-chat__thread {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-width: 0;
  overscroll-behavior: contain;
}

.klirr-chat__empty {
  padding: 1.5rem 0.25rem;
  text-align: center;
}
.klirr-chat__empty-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ds-text, var(--ink-900, #0b1220));
  margin-bottom: 0.3rem;
}
.klirr-chat__empty-body {
  font-size: 0.8rem;
  color: var(--ds-muted, var(--ink-500, #5a6a86));
  line-height: 1.5;
}

.klirr-chat__message {
  display: flex;
  min-width: 0;
}
.klirr-chat__message--user {
  justify-content: flex-end;
}
.klirr-chat__message--assistant {
  justify-content: flex-start;
}
.klirr-chat__thinking-row {
  align-items: flex-end;
  gap: 0.4rem;
}

.klirr-chat__bubble-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  flex: 0 0 1.75rem;
  border-radius: 999px;
  color: var(--ds-accent, var(--blue, #3b82f6));
  background: color-mix(
    in srgb,
    var(--ds-accent, var(--blue, #3b82f6)) 14%,
    transparent
  );
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.klirr-chat__bubble {
  min-width: 0;
  max-width: 92%;
  padding: 0.55rem 0.75rem;
  border-radius: 0.9rem;
  font-size: 0.85rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.klirr-chat__message--user .klirr-chat__bubble {
  background: var(
    --grad-brand-soft,
    linear-gradient(120deg, #3b82f6 0%, #22d3ee 100%)
  );
  color: #fff;
  border-bottom-right-radius: 0.25rem;
}
.klirr-chat__message--assistant .klirr-chat__bubble {
  background: var(--ds-hover, var(--paper-2, #eef2f9));
  color: var(--ds-text, var(--ink-900, #0b1220));
  border-bottom-left-radius: 0.25rem;
}

.klirr-chat__user-text,
.klirr-chat__answer p {
  margin: 0;
}
.klirr-chat__user-text {
  white-space: pre-wrap;
}
.klirr-chat__answer {
  display: grid;
  gap: 0.55rem;
  overflow-wrap: anywhere;
}
.klirr-chat__answer-heading {
  font-weight: 750;
  line-height: 1.3;
}
.klirr-chat__answer-list-item {
  display: grid;
  grid-template-columns: 1.05rem minmax(0, 1fr);
  gap: 0.35rem;
  align-items: start;
}
.klirr-chat__answer-marker {
  color: var(--ds-accent, var(--blue, #3b82f6));
  font-weight: 750;
  text-align: right;
}
.klirr-chat__answer-item-text {
  min-width: 0;
}
.klirr-chat__answer-link {
  color: var(--ds-accent, var(--blue, #3b82f6));
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 0.16em;
  overflow-wrap: anywhere;
}
.klirr-chat__answer-code {
  border-radius: 0.25rem;
  background: color-mix(in srgb, currentColor 9%, transparent);
  padding: 0.08rem 0.28rem;
  font:
    0.9em/1.4 ui-monospace,
    SFMono-Regular,
    Menlo,
    Consolas,
    monospace;
}

.klirr-chat__typewriter-cursor {
  display: inline-block;
  width: 0.12rem;
  height: 1em;
  margin-left: 0.08rem;
  vertical-align: -0.12em;
  border-radius: 1px;
  background: currentColor;
  animation: klirr-chat-cursor 0.8s steps(1) infinite;
}

@keyframes klirr-chat-cursor {
  50% {
    opacity: 0;
  }
}

.klirr-chat__typing {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 3rem;
}
.klirr-chat__typing span {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 999px;
  background: var(--ds-muted, var(--ink-500, #5a6a86));
  animation: klirr-chat-bounce 1.2s infinite ease-in-out;
}
.klirr-chat__typing span:nth-child(2) {
  animation-delay: 0.15s;
}
.klirr-chat__typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes klirr-chat-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-0.25rem);
    opacity: 1;
  }
}

.klirr-chat__notice {
  margin-top: 0.45rem;
  padding: 0.4rem 0.5rem;
  border-radius: 0.5rem;
  font-size: 0.72rem;
  background: rgba(245, 158, 11, 0.14);
  color: var(--ds-text, var(--ink-900, #0b1220));
}

.klirr-chat__sources {
  margin-top: 0.5rem;
}
.klirr-chat__sources-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ds-muted, var(--ink-500, #5a6a86));
  margin-bottom: 0.2rem;
}
.klirr-chat__sources ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.klirr-chat__sources a {
  font-size: 0.76rem;
  color: var(--ds-accent, var(--blue, #3b82f6));
  text-decoration: underline;
  overflow-wrap: anywhere;
}

.klirr-chat__confirm {
  align-self: stretch;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--ds-border, var(--line, #e2e8f2));
  border-radius: 0.85rem;
  background: var(--ds-bg, var(--paper, #f6f8fc));
}
.klirr-chat__confirm-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ds-text, var(--ink-900, #0b1220));
  margin-bottom: 0.25rem;
}
.klirr-chat__confirm-body {
  font-size: 0.78rem;
  color: var(--ds-muted, var(--ink-500, #5a6a86));
  line-height: 1.4;
}

.klirr-chat__confirm-email {
  display: block;
  width: 100%;
  margin-top: 0.6rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--ds-border, var(--line-strong, #cbd5e6));
  border-radius: 0.6rem;
  font: inherit;
  font-size: 0.82rem;
  background: var(--ds-surface, var(--white, #fff));
  color: var(--ds-text, var(--ink-900, #0b1220));
}

.klirr-chat__confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.7rem;
}
.klirr-chat__confirm-actions button {
  flex: 1 1 auto;
  min-height: 2.1rem;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.klirr-chat__confirm-actions button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.klirr-chat__confirm-yes {
  border: 0;
  color: #fff;
  background: var(
    --grad-brand-soft,
    linear-gradient(120deg, #3b82f6 0%, #22d3ee 100%)
  );
}
.klirr-chat__confirm-cancel {
  border: 1px solid var(--ds-border, var(--line-strong, #cbd5e6));
  background: transparent;
  color: var(--ds-text, var(--ink-900, #0b1220));
}

.klirr-chat__composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--ds-border, var(--line, #e2e8f2));
  flex-shrink: 0;
  min-width: 0;
}
.klirr-chat__input {
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  max-height: 8rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--ds-border, var(--line-strong, #cbd5e6));
  border-radius: 0.7rem;
  font: inherit;
  font-size: 0.85rem;
  background: var(--ds-bg, var(--paper, #f6f8fc));
  color: var(--ds-text, var(--ink-900, #0b1220));
}
.klirr-chat__send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.3rem;
  height: 2.3rem;
  flex-shrink: 0;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: var(
    --grad-brand-soft,
    linear-gradient(120deg, #3b82f6 0%, #22d3ee 100%)
  );
  cursor: pointer;
}
.klirr-chat__input:disabled,
.klirr-chat__send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Match the TAM portal agent: same fixed placement, compact launcher, and
   neutral conversation panel. Klirr keeps only its identity text. */
.klirr-chat {
  --tam-agent-primary: var(--ds-accent, var(--blue));
  --tam-agent-on-primary: var(--ds-on-accent, var(--white));
  --tam-agent-surface: var(--ds-surface, var(--white));
  --tam-agent-surface-soft: var(--ds-hover, var(--paper-2));
  --tam-agent-text: var(--ds-text, var(--ink-900));
  --tam-agent-muted: var(--ds-muted, var(--ink-500));
  --tam-agent-outline: var(--ds-border, var(--line));
  --tam-agent-outline-strong: var(--ds-border, var(--line-strong));
  right: 1.5rem;
  bottom: 1.5rem;
}
.klirr-chat__launcher {
  width: 3.25rem;
  height: 3.25rem;
  padding: 0;
  border-radius: 999px;
  color: var(--tam-agent-on-primary);
  background: var(--tam-agent-primary);
  box-shadow: 0 8px 24px
    color-mix(in srgb, var(--tam-agent-text) 28%, transparent);
  font: inherit;
  font-weight: 600;
}
.klirr-chat__launcher:hover {
  transform: none;
  filter: brightness(0.92);
}
.klirr-chat__launcher:focus-visible {
  outline: 3px solid var(--tam-agent-primary);
  outline-offset: 3px;
}
.klirr-chat__launcher svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: currentColor;
  stroke: none;
}
.klirr-chat__panel {
  right: 1.5rem;
  bottom: 1.5rem;
  width: min(24rem, calc(100vw - 2rem));
  height: min(31rem, calc(100dvh - 2rem));
  max-width: none;
  max-height: none;
  border-color: var(--tam-agent-outline);
  background: var(--tam-agent-surface);
  color: var(--tam-agent-text);
  border-radius: 0.75rem;
  box-shadow: 0 12px 36px
    color-mix(in srgb, var(--tam-agent-text) 20%, transparent);
}
.klirr-chat__header,
.klirr-chat__composer {
  padding: 0.7rem;
}
.klirr-chat__header {
  border-color: var(--tam-agent-outline);
}
.klirr-chat__composer {
  border-color: var(--tam-agent-outline);
}
.klirr-chat__send {
  width: auto;
  height: auto;
  padding: 0.45rem 0.65rem;
  border-radius: 0.4rem;
  color: var(--tam-agent-on-primary);
  background: var(--tam-agent-primary);
  font: inherit;
  font-size: 0.8rem;
}
.klirr-chat__input {
  border-color: var(--tam-agent-outline-strong);
  border-radius: 0.4rem;
  background: var(--tam-agent-surface);
  color: var(--tam-agent-text);
}
.klirr-chat__title strong {
  font-size: 0.95rem;
}
.klirr-chat__title span {
  color: var(--tam-agent-muted);
  font-size: 0.72rem;
}
.klirr-chat__thread {
  gap: 0.6rem;
  padding: 0.9rem 1rem;
}
.klirr-chat__empty {
  padding: 1.5rem 0.25rem;
}
.klirr-chat__empty-title {
  margin-bottom: 0.3rem;
  color: var(--tam-agent-text);
  font-size: 0.9rem;
}
.klirr-chat__empty-body {
  color: var(--tam-agent-muted);
  font-size: 0.8rem;
}
.klirr-chat__bubble {
  max-width: 92%;
  padding: 0.55rem 0.75rem;
  border-radius: 0.9rem;
  border-bottom-left-radius: 0.25rem;
  background: var(--tam-agent-surface-soft);
  color: var(--tam-agent-text);
  font-size: 0.85rem;
  line-height: 1.45;
}
.klirr-chat__message--user .klirr-chat__bubble {
  border-bottom-right-radius: 0.25rem;
  border-bottom-left-radius: 0.9rem;
  background: var(--tam-agent-primary);
  color: var(--tam-agent-on-primary);
}
.klirr-chat__message--assistant .klirr-chat__bubble {
  background: var(--tam-agent-surface-soft);
  color: var(--tam-agent-text);
}
.klirr-chat__composer {
  padding: 0.7rem;
}
.klirr-chat__input {
  min-height: 2.4rem;
  padding: 0.55rem 0.7rem;
}

@media (prefers-reduced-motion: reduce) {
  .klirr-chat__typing span,
  .klirr-chat__typewriter-cursor {
    animation: none;
    opacity: 0.7;
  }
}

@media (max-width: 640px) {
  .klirr-chat {
    right: auto;
    left: max(14px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
  }

  .klirr-chat__panel {
    top: calc(
      var(--klirr-viewport-top, 0px) + max(8px, env(safe-area-inset-top))
    );
    right: max(8px, env(safe-area-inset-right));
    bottom: auto;
    left: max(8px, env(safe-area-inset-left));
    width: auto;
    height: calc(
      var(--klirr-viewport-height, 100dvh) -
        max(8px, env(safe-area-inset-top)) -
        max(8px, env(safe-area-inset-bottom)) - 16px
    );
    max-width: none;
    max-height: none;
    border-radius: 16px;
  }

  .klirr-chat__thread {
    padding: 0.75rem;
  }
  .klirr-chat__composer {
    padding: 0.625rem;
  }
  .klirr-chat__input,
  .klirr-chat__confirm-email {
    font-size: 16px;
  }
}
