/* AI-помощник — виджет чата */
.ai-chat-fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 900;
  width: 62px;
  height: 62px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(145deg, #0E6B5C, #0a5247);
  box-shadow: 0 8px 28px rgba(14, 107, 92, 0.45);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s, box-shadow .2s;
}
.ai-chat-fab:hover { transform: scale(1.06); box-shadow: 0 12px 32px rgba(14, 107, 92, 0.5); }
.ai-chat-fab.open { transform: scale(0.95); }

.ai-robot {
  width: 38px;
  height: 38px;
  position: relative;
}
.ai-robot-head {
  width: 30px; height: 26px;
  background: #fff;
  border-radius: 10px 10px 8px 8px;
  margin: 0 auto;
  position: relative;
  animation: aiRobotBob 2.4s ease-in-out infinite;
}
.ai-robot-eye {
  position: absolute; top: 9px;
  width: 5px; height: 5px;
  background: #0E6B5C; border-radius: 50%;
  animation: aiRobotBlink 4s infinite;
}
.ai-robot-eye.left { left: 7px; }
.ai-robot-eye.right { right: 7px; }
.ai-robot-antenna {
  position: absolute; top: -8px; left: 50%;
  transform: translateX(-50%);
  width: 2px; height: 8px; background: #fff;
}
.ai-robot-antenna::after {
  content: ''; position: absolute; top: -4px; left: -3px;
  width: 8px; height: 8px; border-radius: 50%;
  background: #7ee8d8;
  animation: aiAntennaPulse 1.5s ease infinite;
}
@keyframes aiRobotBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
@keyframes aiRobotBlink {
  0%, 96%, 100% { transform: scaleY(1); }
  98% { transform: scaleY(0.1); }
}
@keyframes aiAntennaPulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.2); }
}

.ai-chat-panel {
  position: fixed;
  right: 18px;
  bottom: 92px;
  z-index: 899;
  width: min(380px, calc(100vw - 24px));
  max-height: min(560px, calc(100vh - 120px));
  background: var(--card, #fff);
  border: 1px solid var(--line, #e5e2d8);
  border-radius: 22px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.98);
  transition: opacity .22s, transform .22s, visibility .22s;
}
.ai-chat-panel.open {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.ai-chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #0E6B5C, #12806d);
  color: #fff;
}
.ai-chat-head-icon { font-size: 1.4em; }
.ai-chat-head-text { flex: 1; }
.ai-chat-head-title { font-weight: 800; font-size: 0.95em; font-family: var(--font-display, Manrope, sans-serif); }
.ai-chat-head-sub { font-size: 0.75em; opacity: 0.85; margin-top: 2px; }
.ai-chat-close {
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: rgba(255,255,255,0.15);
  color: #fff; cursor: pointer; font-size: 1em;
}

.ai-chat-messages {
  flex: 1; overflow-y: auto;
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
  min-height: 200px; max-height: 340px;
  background: var(--bg-soft, #f7f4ec);
}
.ai-msg {
  max-width: 92%; padding: 10px 13px;
  border-radius: 16px; font-size: 0.88em; line-height: 1.5;
  word-break: break-word;
}
.ai-msg-bot.ai-msg-results { max-width: 96%; }
.ai-msg-bot {
  align-self: flex-start;
  background: var(--card, #fff);
  border: 1px solid var(--line, #e5e2d8);
  border-bottom-left-radius: 4px;
}
.ai-msg-user {
  align-self: flex-end;
  background: #0E6B5C; color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg-typing { color: var(--muted, #888); font-style: italic; }

.ai-msg-bot .ai-result-intro {
  font-weight: 700;
  margin-bottom: 8px;
}

.ai-result-card {
  background: var(--bg-soft, #f7f4ec);
  border: 1px solid var(--line, #e5e2d8);
  border-radius: 12px;
  padding: 9px 11px;
  margin-bottom: 8px;
}
.ai-result-card:last-child { margin-bottom: 0; }

.ai-result-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  color: #0E6B5C;
  font-weight: 700;
  text-decoration: none;
  line-height: 1.35;
}
.ai-result-title:hover { text-decoration: underline; }

.ai-result-num {
  flex-shrink: 0;
  font-weight: 700;
  font-size: 0.85em;
  opacity: 0.7;
}

.ai-result-crumb {
  font-size: 0.78em;
  color: var(--muted, #888);
  margin-top: 2px;
  margin-bottom: 6px;
}

.ai-result-snippet {
  font-size: 0.93em;
  line-height: 1.5;
  color: var(--text, #1c2321);
}

body.theme-dark .ai-result-card { background: #0F1413; border-color: #333; }

.ai-answer-text {
  font-size: 0.93em;
  line-height: 1.55;
}

.ai-sources {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line, #e5e2d8);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.ai-sources-label {
  font-size: 0.75em;
  color: var(--muted, #888);
  margin-right: 2px;
}
.ai-source-pill {
  display: inline-block;
  font-size: 0.78em;
  color: #0E6B5C;
  background: var(--bg-soft, #f7f4ec);
  border: 1px solid var(--line, #e5e2d8);
  border-radius: 999px;
  padding: 3px 10px;
  text-decoration: none;
  font-weight: 600;
}
.ai-source-pill:hover { text-decoration: underline; background: var(--accent-soft, #e1f0ec); }

.ai-fallback-notice {
  font-size: 0.78em;
  color: var(--muted, #888);
  font-style: italic;
  margin-bottom: 8px;
}

body.theme-dark .ai-source-pill { background: #0F1413; border-color: #333; }

.ai-chat-input-row {
  display: flex; gap: 8px; padding: 12px;
  border-top: 1px solid var(--line, #e5e2d8);
  background: var(--card, #fff);
}
.ai-chat-input {
  flex: 1; border: 1px solid var(--line, #e5e2d8);
  border-radius: 999px; padding: 10px 14px;
  font-size: 0.88em; font-family: inherit;
  background: var(--bg-soft, #f7f4ec);
  outline: none;
}
.ai-chat-input:focus { border-color: #0E6B5C; }
.ai-chat-send {
  width: 42px; height: 42px; border-radius: 50%;
  border: none; background: #0E6B5C; color: #fff;
  cursor: pointer; font-size: 1.1em; flex-shrink: 0;
}
.ai-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Онбординг */
.ai-onboard-overlay {
  position: fixed; inset: 0; z-index: 950;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  opacity: 0; visibility: hidden;
  transition: opacity .25s, visibility .25s;
}
.ai-onboard-overlay.open { opacity: 1; visibility: visible; }
.ai-onboard-card {
  background: var(--card, #fff);
  border-radius: 24px; padding: 24px 22px;
  max-width: 400px; width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  text-align: center;
}
.ai-onboard-robot { font-size: 3em; margin-bottom: 8px; }
.ai-onboard-title {
  font-family: var(--font-display, Manrope, sans-serif);
  font-weight: 800; font-size: 1.15em; margin: 0 0 8px;
}
.ai-onboard-text {
  font-size: 0.9em; color: var(--muted, #666);
  line-height: 1.5; margin: 0 0 14px; text-align: left;
}
.ai-onboard-example {
  background: var(--bg-soft, #f7f4ec);
  border-radius: 12px; padding: 12px 14px;
  font-size: 0.85em; text-align: left; margin-bottom: 14px;
  border: 1px solid var(--line, #e5e2d8);
}
.ai-onboard-check {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.82em; color: var(--muted, #666);
  margin-bottom: 14px; cursor: pointer; text-align: left;
}
.ai-onboard-check input { accent-color: #0E6B5C; }
.ai-onboard-btn {
  width: 100%; padding: 12px;
  border: none; border-radius: 999px;
  background: #0E6B5C; color: #fff;
  font-weight: 700; font-size: 0.92em; cursor: pointer;
}

body.theme-dark .ai-chat-panel { background: #1A1D1C; border-color: #333; }
body.theme-dark .ai-chat-messages { background: #0F1413; }
body.theme-dark .ai-msg-bot { background: #1A1D1C; border-color: #333; }
body.theme-dark .ai-onboard-card { background: #1A1D1C; }

@media (max-width: 480px) {
  .ai-chat-panel { right: 8px; bottom: 84px; width: calc(100vw - 16px); }
  .ai-chat-fab { right: 12px; bottom: 12px; }
}

/* Цитаты [1] в тексте ответа */
.ai-cite {
  display: inline-block;
  color: #0E6B5C;
  font-weight: 700;
  font-size: 0.82em;
  vertical-align: super;
  text-decoration: none;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 3px;
  transition: background 0.15s;
}
.ai-cite:hover { background: rgba(14,107,92,0.12); }

/* Спойлер источников */
.ai-sources-spoiler {
  margin-top: 10px;
  border-radius: 8px;
  border: 1px solid rgba(14,107,92,0.2);
  overflow: hidden;
}
.ai-sources-summary {
  padding: 7px 12px;
  font-size: 0.82em;
  font-weight: 600;
  color: #0E6B5C;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.ai-sources-summary::-webkit-details-marker { display: none; }
.ai-sources-summary::before { content: '▶ '; font-size: 0.7em; }
details[open] .ai-sources-summary::before { content: '▼ '; }
.ai-sources-spoiler .ai-sources {
  padding: 6px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
body.theme-dark .ai-sources-spoiler { border-color: rgba(14,107,92,0.3); }