/* yh-ai-assistant — theme-agnostic chat widget */

.yh-ai-floating-backdrop {
  position: fixed;
  inset: 0;
  z-index: 8999;
  background: rgba(15, 23, 42, 0.38);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.28s ease;
  pointer-events: none;
}

.yh-ai-floating-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.yh-ai-floating-wrap {
  --yh-ai-accent: #2563eb;
  --yh-ai-panel-bg: #ffffff;
  --yh-ai-panel-text: #0f172a;
  --yh-ai-panel-muted: #64748b;
  --yh-ai-header-bg: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  --yh-ai-header-text: #ffffff;
  --yh-ai-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
  --yh-ai-radius: 16px;
  position: fixed;
  z-index: 9000;
  bottom: calc(var(--yh-fab-edge, 1rem) + var(--yh-dock-bottom, 0px) + var(--yh-ai-fab-offset, 0px));
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.yh-ai-floating-wrap.yh-ai-pos-right { right: 1.25rem; left: auto; }
.yh-ai-floating-wrap.yh-ai-pos-left { left: 1.25rem; right: auto; }

.yh-ai-theme-light { --yh-ai-accent: #409eff; --yh-ai-header-bg: #f8fafc; --yh-ai-header-text: #0f172a; }
.yh-ai-theme-brand { --yh-ai-accent: #2563eb; }
.yh-ai-theme-dark {
  --yh-ai-accent: #38bdf8;
  --yh-ai-panel-bg: #1e293b;
  --yh-ai-panel-text: #f1f5f9;
  --yh-ai-header-bg: linear-gradient(135deg, #334155 0%, #0f172a 100%);
}
.yh-ai-theme-minimal { --yh-ai-accent: #18181b; --yh-ai-header-bg: #fff; --yh-ai-header-text: #18181b; }
.yh-ai-theme-warm { --yh-ai-accent: #ea580c; --yh-ai-header-bg: linear-gradient(135deg, #fb923c 0%, #ea580c 100%); }
.yh-ai-theme-zen {
  --yh-ai-accent: #78716c;
  --yh-ai-header-bg: linear-gradient(135deg, #a8a29e 0%, #57534e 100%);
  --yh-ai-header-text: #fafaf9;
}

.yh-ai-floating-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  cursor: pointer;
  font: inherit;
  color: #fff;
  background: var(--yh-ai-accent);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--yh-ai-accent) 45%, transparent);
  transition: transform 0.2s ease;
}

.yh-ai-floating-btn--pill { padding: 0.72rem 1.15rem; border-radius: 999px; font-weight: 600; }
.yh-ai-floating-btn--circle { width: 3.5rem; height: 3.5rem; border-radius: 50%; padding: 0; }
.yh-ai-floating-btn-img { display: block; width: 100%; height: 100%; border-radius: 50%; background-size: cover; background-position: center; }

.yh-ai-floating-panel {
  position: absolute;
  bottom: calc(100% + 0.85rem);
  width: min(400px, calc(100vw - 2rem));
  max-height: min(78vh, 640px);
  display: flex;
  flex-direction: column;
  background: var(--yh-ai-panel-bg);
  color: var(--yh-ai-panel-text);
  border-radius: var(--yh-ai-radius);
  box-shadow: var(--yh-ai-shadow);
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.yh-ai-pos-right .yh-ai-floating-panel { right: 0; transform-origin: bottom right; }
.yh-ai-pos-left .yh-ai-floating-panel { left: 0; transform-origin: bottom left; }
.yh-ai-floating-panel.is-open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.yh-ai-floating-panel[hidden] { display: flex !important; }

.yh-ai-floating-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  background: var(--yh-ai-header-bg);
  color: var(--yh-ai-header-text);
}

.yh-ai-chat-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  background-color: rgba(255,255,255,0.2);
}

.yh-ai-chat-avatar--icon { display: flex; align-items: center; justify-content: center; font-size: 1.25rem; }

.yh-ai-floating-head-text { flex: 1; min-width: 0; }
.yh-ai-floating-head-text strong { display: block; font-size: 1rem; }
.yh-ai-floating-head-text span { display: block; font-size: 0.8rem; opacity: 0.9; margin-top: 0.2rem; }

.yh-ai-floating-close {
  border: none;
  background: rgba(255,255,255,0.15);
  color: inherit;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  cursor: pointer;
}

.yh-ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 200px;
  max-height: 360px;
}

.yh-ai-msg { display: flex; }
.yh-ai-msg--user { justify-content: flex-end; }
.yh-ai-msg--bot { justify-content: flex-start; }

.yh-ai-msg-bubble {
  max-width: 88%;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  line-height: 1.55;
  font-size: 0.92rem;
  word-break: break-word;
  white-space: pre-wrap;
}

.yh-ai-msg-bubble--md {
  white-space: normal;
}

.yh-ai-msg-bubble--md > :first-child { margin-top: 0; }
.yh-ai-msg-bubble--md > :last-child { margin-bottom: 0; }

.yh-ai-msg-bubble--md p,
.yh-ai-msg-bubble--md ul,
.yh-ai-msg-bubble--md ol,
.yh-ai-msg-bubble--md pre,
.yh-ai-msg-bubble--md blockquote {
  margin: 0 0 0.55em;
}

.yh-ai-msg-bubble--md h1,
.yh-ai-msg-bubble--md h2,
.yh-ai-msg-bubble--md h3,
.yh-ai-msg-bubble--md h4,
.yh-ai-msg-bubble--md h5,
.yh-ai-msg-bubble--md h6 {
  margin: 0 0 0.45em;
  font-size: 1em;
  font-weight: 700;
  line-height: 1.35;
}

.yh-ai-msg-bubble--md h1 { font-size: 1.08em; }
.yh-ai-msg-bubble--md h2 { font-size: 1.04em; }

.yh-ai-msg-bubble--md ul,
.yh-ai-msg-bubble--md ol {
  padding-left: 1.25em;
}

.yh-ai-msg-bubble--md li + li { margin-top: 0.2em; }

.yh-ai-msg-bubble--md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: color-mix(in srgb, var(--yh-ai-accent) 12%, transparent);
}

.yh-ai-msg-bubble--md pre {
  overflow-x: auto;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: color-mix(in srgb, var(--yh-ai-accent) 10%, #0f172a 4%);
}

.yh-ai-msg-bubble--md pre code {
  padding: 0;
  background: transparent;
  font-size: 0.84em;
  white-space: pre;
}

.yh-ai-msg-bubble--md blockquote {
  padding-left: 0.75rem;
  border-left: 3px solid color-mix(in srgb, var(--yh-ai-accent) 35%, #cbd5e1);
  color: var(--yh-ai-panel-muted);
}

.yh-ai-msg-bubble--md a {
  color: var(--yh-ai-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.yh-ai-msg-bubble--md a:hover { opacity: 0.85; }

.yh-ai-msg--user .yh-ai-msg-bubble {
  background: var(--yh-ai-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.yh-ai-msg--bot .yh-ai-msg-bubble {
  background: color-mix(in srgb, var(--yh-ai-accent) 8%, #f1f5f9);
  color: var(--yh-ai-panel-text);
  border-bottom-left-radius: 4px;
}

.yh-ai-msg--typing .yh-ai-msg-bubble { opacity: 0.7; font-style: italic; }

.yh-ai-chat-form {
  border-top: 1px solid rgba(0,0,0,0.06);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.yh-ai-chat-form textarea {
  width: 100%;
  border: 1px solid #dcdfe6;
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  font: inherit;
  resize: none;
  min-height: 3.5rem;
}

.yh-ai-chat-actions { display: flex; gap: 0.5rem; justify-content: flex-end; align-items: center; }

.yh-ai-send-btn, .yh-ai-handoff-btn {
  border: none;
  border-radius: 8px;
  padding: 0.5rem 0.85rem;
  font: inherit;
  cursor: pointer;
}

.yh-ai-send-btn { background: var(--yh-ai-accent); color: #fff; font-weight: 600; }
.yh-ai-handoff-btn { background: transparent; color: var(--yh-ai-panel-muted); border: 1px solid #dcdfe6; }

.yh-ai-handoff-dialog {
  position: fixed;
  inset: 0;
  z-index: 9100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.4);
}

.yh-ai-handoff-dialog-inner {
  background: #fff;
  border-radius: 12px;
  padding: 1.25rem;
  width: min(360px, 92vw);
}

.yh-ai-handoff-dialog-inner label { display: block; margin-bottom: 0.75rem; font-size: 0.9rem; }
.yh-ai-handoff-dialog-inner input, .yh-ai-handoff-dialog-inner textarea {
  width: 100%; margin-top: 0.25rem; padding: 0.5rem; border: 1px solid #dcdfe6; border-radius: 8px;
}

.yh-ai-floating-wrap.is-open .yh-ai-floating-btn { transform: scale(0.96); }

@media (max-width: 480px) {
  .yh-ai-floating-wrap.yh-ai-pos-right { right: 0.75rem; }
  .yh-ai-floating-panel { width: calc(100vw - 1.5rem); }
}
