/* IAM.Docs landing chat widget — vanilla CSS, dark theme aligned with landing */

.iam-chat {
  --iam-chat-bg: #0e1218;
  --iam-chat-surface: #161b24;
  --iam-chat-surface-2: #1f2632;
  --iam-chat-border: rgba(255, 255, 255, 0.08);
  --iam-chat-text: #edf5fc;
  --iam-chat-text-dim: rgba(237, 245, 252, 0.65);
  --iam-chat-text-faint: rgba(237, 245, 252, 0.45);
  --iam-chat-accent: #5b8def;
  --iam-chat-accent-strong: #3d6dd8;
  --iam-chat-bot-bg: #1f2632;
  --iam-chat-user-bg: linear-gradient(135deg, #4a7adf 0%, #3d6dd8 100%);
  --iam-chat-shadow: 0 12px 32px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
  --iam-chat-radius: 16px;
  --iam-chat-z: 2147483640;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--iam-chat-text);
}

/* ── Floating button ── */
.iam-chat__fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #5b8def 0%, #3d6dd8 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--iam-chat-shadow);
  z-index: var(--iam-chat-z);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
  padding: 0;
}

.iam-chat__fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 40px rgba(91, 141, 239, 0.35), 0 2px 6px rgba(0, 0, 0, 0.3);
}

.iam-chat__fab:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.iam-chat__fab-icon {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 120ms ease;
}

.iam-chat__fab[aria-expanded="true"] .iam-chat__fab-icon--chat { opacity: 0; }
.iam-chat__fab[aria-expanded="false"] .iam-chat__fab-icon--close { opacity: 0; }
.iam-chat__fab-icon--close { position: absolute; }

.iam-chat__fab-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ── Chat panel ── */
.iam-chat__panel {
  position: fixed;
  right: 24px;
  bottom: 100px;
  width: 380px;
  height: min(620px, calc(100vh - 140px));
  background: var(--iam-chat-bg);
  border: 1px solid var(--iam-chat-border);
  border-radius: var(--iam-chat-radius);
  box-shadow: var(--iam-chat-shadow);
  z-index: var(--iam-chat-z);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: translateY(12px) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: transform 200ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 200ms ease;
}

.iam-chat__panel[data-open="true"] {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 540px) {
  .iam-chat__panel {
    right: 12px;
    left: 12px;
    bottom: 92px;
    width: auto;
    height: calc(100vh - 110px);
    max-height: none;
  }
  .iam-chat__fab {
    right: 16px;
    bottom: 16px;
  }
}

/* ── Header ── */
.iam-chat__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--iam-chat-surface);
  border-bottom: 1px solid var(--iam-chat-border);
}

.iam-chat__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5b8def 0%, #3d6dd8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.iam-chat__title {
  flex: 1;
  min-width: 0;
}

.iam-chat__title-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--iam-chat-text);
}

.iam-chat__title-status {
  font-size: 12px;
  color: var(--iam-chat-text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.iam-chat__title-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}

.iam-chat__title-dot[data-state="connecting"] { background: #f59e0b; animation: iam-chat-pulse 1.4s ease-in-out infinite; }
.iam-chat__title-dot[data-state="offline"] { background: #ef4444; }

@keyframes iam-chat-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.iam-chat__close {
  background: transparent;
  border: none;
  color: var(--iam-chat-text-dim);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms ease, color 120ms ease;
}

.iam-chat__close:hover {
  background: var(--iam-chat-surface-2);
  color: var(--iam-chat-text);
}

/* ── Messages ── */
.iam-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--iam-chat-surface-2) transparent;
}

.iam-chat__messages::-webkit-scrollbar { width: 6px; }
.iam-chat__messages::-webkit-scrollbar-thumb {
  background: var(--iam-chat-surface-2);
  border-radius: 3px;
}

.iam-chat__msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  animation: iam-chat-fade-in 180ms ease;
}

@keyframes iam-chat-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

.iam-chat__msg--bot {
  background: var(--iam-chat-bot-bg);
  color: var(--iam-chat-text);
  border-top-left-radius: 4px;
  align-self: flex-start;
}

.iam-chat__msg--user {
  background: var(--iam-chat-user-bg);
  color: #fff;
  border-top-right-radius: 4px;
  align-self: flex-end;
}

.iam-chat__msg--system {
  align-self: center;
  background: transparent;
  color: var(--iam-chat-text-faint);
  font-size: 12px;
  padding: 4px 10px;
  text-align: center;
  max-width: 100%;
}

.iam-chat__msg a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.iam-chat__msg strong { font-weight: 600; }

.iam-chat__typing {
  align-self: flex-start;
  background: var(--iam-chat-bot-bg);
  border-top-left-radius: 4px;
  border-radius: 14px;
  padding: 12px 14px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.iam-chat__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--iam-chat-text-dim);
  animation: iam-chat-typing 1.2s ease-in-out infinite;
}

.iam-chat__typing span:nth-child(2) { animation-delay: 0.15s; }
.iam-chat__typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes iam-chat-typing {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── CTA chip after lead capture ── */
.iam-chat__cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 4px 0;
}

.iam-chat__cta {
  border: 1px solid var(--iam-chat-border);
  background: var(--iam-chat-surface);
  color: var(--iam-chat-text);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.iam-chat__cta:hover {
  background: var(--iam-chat-surface-2);
  border-color: var(--iam-chat-accent);
}

/* ── Input ── */
.iam-chat__form {
  border-top: 1px solid var(--iam-chat-border);
  padding: 12px 12px 12px 16px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--iam-chat-surface);
}

.iam-chat__textarea {
  flex: 1;
  background: var(--iam-chat-bg);
  border: 1px solid var(--iam-chat-border);
  border-radius: 12px;
  color: var(--iam-chat-text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  padding: 10px 12px;
  max-height: 140px;
  min-height: 40px;
  resize: none;
  outline: none;
  transition: border-color 120ms ease;
}

.iam-chat__textarea:focus {
  border-color: var(--iam-chat-accent);
}

.iam-chat__textarea::placeholder {
  color: var(--iam-chat-text-faint);
}

.iam-chat__send {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: var(--iam-chat-accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 120ms ease, transform 120ms ease;
}

.iam-chat__send:hover { background: var(--iam-chat-accent-strong); }
.iam-chat__send:disabled {
  background: var(--iam-chat-surface-2);
  color: var(--iam-chat-text-faint);
  cursor: not-allowed;
}

.iam-chat__send svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.iam-chat__footer {
  padding: 0 16px 10px;
  background: var(--iam-chat-surface);
  font-size: 11px;
  color: var(--iam-chat-text-faint);
  text-align: center;
}

/* ── Lead form (inline, after CTA "оставить контакт") ── */
.iam-chat__leadform {
  align-self: stretch;
  background: var(--iam-chat-bot-bg);
  border: 1px solid var(--iam-chat-border);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.iam-chat__leadform input,
.iam-chat__leadform textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--iam-chat-bg);
  border: 1px solid var(--iam-chat-border);
  border-radius: 8px;
  color: var(--iam-chat-text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

.iam-chat__leadform-actions {
  display: flex;
  gap: 8px;
}

.iam-chat__leadform-submit {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 8px;
  background: var(--iam-chat-accent);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.iam-chat__leadform-cancel {
  padding: 8px 12px;
  border: 1px solid var(--iam-chat-border);
  background: transparent;
  color: var(--iam-chat-text-dim);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
