/* ─────────────────────────────────────────────────────────────
   Виджет чат-бота МФЦ «Мои Документы» Воронеж
   Все классы с префиксом .mfc- чтобы не конфликтовать со стилями сайта.
   Визуальный стиль: TypeUI «Professional» (business-ready, доверие).
   Шрифт Poppins не содержит кириллицы → используем Montserrat (геометрический, с кириллицей).
   Montserrat НЕ подгружается извне (Google Fonts ненадёжен в РФ и блокирует рендер):
   стоит первым в стеке и применяется, только если сайт сам его подключит/самохостит;
   иначе — системный шрифт без внешних запросов.
   ───────────────────────────────────────────────────────────── */
.mfc-widget {
  --mfc-primary: #fece14;       /* жёлтый акцент — главные действия */
  --mfc-primary-dark: #e6b800;  /* hover/active */
  --mfc-ink: #111827;           /* тёмный: текст, шапка, пузырь пользователя */
  --mfc-bg: #ffffff;
  --mfc-bot-bubble: #f3f4f6;
  --mfc-text: #111827;
  --mfc-muted: #6b7280;
  --mfc-border: #e5e7eb;
  --mfc-shadow: 0 10px 34px rgba(17, 24, 39, 0.16);
  --mfc-radius: 12px;
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 2147483000;
  font-family: "Montserrat", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--mfc-text);
}

/* Кнопка запуска */
.mfc-launcher {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--mfc-primary);
  box-shadow: var(--mfc-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.15s ease;
}
.mfc-launcher:hover { transform: translateY(-2px) scale(1.04); background: var(--mfc-primary-dark); }
.mfc-launcher svg { width: 30px; height: 30px; fill: var(--mfc-ink); }
.mfc-launcher.mfc-hidden { display: none; }

/* Панель */
.mfc-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 384px;
  max-width: calc(100vw - 32px);
  height: 620px;
  max-height: calc(100vh - 48px);
  background: var(--mfc-bg);
  border-radius: var(--mfc-radius);
  box-shadow: var(--mfc-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.mfc-panel.mfc-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Шапка */
.mfc-header {
  background: var(--mfc-ink);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.mfc-header .mfc-avatar {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: var(--mfc-primary);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.mfc-header .mfc-avatar svg { width: 22px; height: 22px; fill: var(--mfc-ink); }
.mfc-header .mfc-titles { flex: 1; min-width: 0; }
.mfc-header .mfc-title { font-weight: 600; font-size: 15px; }
.mfc-header .mfc-subtitle { font-size: 12px; opacity: 0.85; display: flex; align-items: center; gap: 6px; }
.mfc-header .mfc-dot { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; display: inline-block; }
.mfc-close {
  background: none; border: none; color: #fff; cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px; opacity: 0.85;
  display: flex; align-items: center; justify-content: center;
}
.mfc-close:hover { background: rgba(255,255,255,0.15); opacity: 1; }
.mfc-close svg { width: 18px; height: 18px; fill: #fff; }

/* Лента сообщений */
.mfc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fbfcfe;
}
.mfc-msg { display: flex; max-width: 88%; }
.mfc-msg.mfc-user { align-self: flex-end; }
.mfc-msg.mfc-bot { align-self: flex-start; }
.mfc-bubble {
  padding: 10px 14px;
  border-radius: 10px;
  white-space: normal;
  word-wrap: break-word;
}
.mfc-user .mfc-bubble {
  background: var(--mfc-ink);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.mfc-bot .mfc-bubble {
  background: var(--mfc-bot-bubble);
  color: var(--mfc-text);
  border-bottom-left-radius: 4px;
}
.mfc-bubble p { margin: 0 0 8px; }
.mfc-bubble p:last-child { margin-bottom: 0; }
.mfc-bubble ul, .mfc-bubble ol { margin: 6px 0; padding-left: 20px; }
.mfc-bubble li { margin: 2px 0; }
.mfc-bubble strong { font-weight: 600; }

/* Источники под ответом */
.mfc-sources {
  align-self: flex-start;
  max-width: 88%;
  font-size: 11px;
  color: var(--mfc-muted);
  margin-top: -4px;
  padding-left: 4px;
}
.mfc-sources b { color: var(--mfc-text); font-weight: 600; }
.mfc-sources a { color: var(--mfc-ink); text-decoration: underline; }
.mfc-sources a:hover { color: #000; }
.mfc-sources br { line-height: 1.9; }

/* Метка типа/достоверности ответа */
.mfc-kind {
  display: inline-block;
  font-weight: 600;
  font-size: 10.5px;
  line-height: 1.4;
  padding: 1px 8px;
  border-radius: 999px;
  margin-bottom: 3px;
  background: var(--mfc-bot-bubble);
  color: var(--mfc-text);
  border: 1px solid var(--mfc-border);
}
.mfc-kind-faq { background: #e7f6ec; color: #1a7f3c; border-color: #bfe6cd; }
.mfc-kind-generate,
.mfc-kind-general { background: #eef2ff; color: #3949ab; border-color: #d3dbff; }
.mfc-kind-unverified { background: #fff6e9; color: #9a6700; border-color: #f3d9a8; }
.mfc-kind-offtopic,
.mfc-kind-error { background: #f3f4f6; color: var(--mfc-muted); border-color: var(--mfc-border); }
.mfc-match { font-style: italic; }
.mfc-note { color: var(--mfc-muted); }

/* Предупреждение о ПДн */
.mfc-warning {
  align-self: center;
  max-width: 95%;
  background: #fff6e9;
  border: 1px solid #ffd9a8;
  color: #8a5200;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 10px;
}

/* Индикатор набора */
.mfc-typing { display: flex; gap: 4px; padding: 4px 2px; }
.mfc-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--mfc-muted);
  animation: mfc-bounce 1.2s infinite ease-in-out;
}
.mfc-typing span:nth-child(2) { animation-delay: 0.15s; }
.mfc-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes mfc-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Быстрые подсказки */
.mfc-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 2px; }
.mfc-chip {
  background: #fff;
  border: 1px solid var(--mfc-border);
  color: var(--mfc-ink);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.mfc-chip:hover { background: #fffbe6; border-color: var(--mfc-ink); }

/* Поле ввода */
.mfc-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--mfc-border);
  background: #fff;
}
.mfc-input {
  flex: 1;
  border: 1px solid var(--mfc-border);
  border-radius: 8px;
  padding: 11px 12px;
  font-family: inherit;
  font-size: 16px; /* >=16px — иначе iOS Safari зумит поле при фокусе */
  resize: none;
  max-height: 120px;
  outline: none;
  transition: border-color 0.15s ease;
}
.mfc-input:focus { border-color: var(--mfc-ink); }
.mfc-send {
  width: 42px; height: 42px;
  border: none; border-radius: 8px;
  background: var(--mfc-primary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.mfc-send:hover { background: var(--mfc-primary-dark); }
.mfc-send:disabled { background: #e5e7eb; cursor: default; }
.mfc-send svg { width: 20px; height: 20px; fill: var(--mfc-ink); }
.mfc-send.mfc-stop { background: #374151; }
.mfc-send.mfc-stop:hover { background: #1f2937; }
.mfc-send.mfc-stop svg { fill: #fff; }

/* ── Состояния клавиатурного фокуса (WCAG 2.2: видимый фокус) ── */
.mfc-launcher:focus-visible,
.mfc-send:focus-visible,
.mfc-chip:focus-visible {
  outline: 3px solid var(--mfc-ink);
  outline-offset: 2px;
}
.mfc-close:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

/* ── Нажатие (active) ── */
.mfc-launcher:active { transform: translateY(0) scale(0.95); }
.mfc-send:active:not(:disabled) { transform: scale(0.93); }
.mfc-chip:active { transform: scale(0.97); }

.mfc-footnote {
  text-align: center;
  font-size: 10.5px;
  color: var(--mfc-muted);
  padding: 0 12px 10px;
  background: #fff;
}

/* Мобильные устройства — на весь экран */
@media (max-width: 480px) {
  .mfc-widget { right: 16px; bottom: 16px; }
  .mfc-panel {
    width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh;
    right: -16px; bottom: -16px; border-radius: 0;
  }
}

/* ── Доступность: только для скринридеров ── */
.mfc-sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ── Уважение к prefers-reduced-motion ── */
@media (prefers-reduced-motion: reduce) {
  .mfc-widget *,
  .mfc-widget *::before,
  .mfc-widget *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
