/* AI Interpreter Widget — ai-interpreter.css
   Дизайн 1-в-1 по макету Figma «Chromlab / ИИ-виджет».
   Палитра и типографика из дизайн-токенов Figma. */

.ai-widget-overlay {
  --ai-ink:        #2a2c36;  /* основной текст (черн) */
  --ai-ink-2:      #222222;
  --ai-card:       #fafafa;  /* карточка */
  --ai-box:        #f4f5f9;  /* блок результата (серый 2) */
  --ai-accent:     #868fdd;  /* акцент 2-1 */
  --ai-accent-bg:  #e4e6f8;  /* бэк кнопок */
  --ai-border:     #e0e0e0;
  --ai-font: "Futura PT", "Futura", "Century Gothic", "Trebuchet MS",
             -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;

  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(34, 34, 34, 0.8);          /* #222 @ 80% */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  font-family: var(--ai-font);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
  -webkit-font-smoothing: antialiased;
}
.ai-widget-overlay.active { opacity: 1; visibility: visible; }

/* ── Shell (карточка + кнопка закрытия над ней) ── */
.ai-widget-shell {
  position: relative;
  width: 840px;
  max-width: 100%;
  transform: translateY(16px) scale(0.98);
  transition: transform 0.22s ease;
}
.ai-widget-overlay.active .ai-widget-shell { transform: none; }

.ai-widget-close {
  position: absolute;
  top: -46px;
  right: 0;
  width: 28px;
  height: 28px;
  padding: 6px;
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.9;
  transition: opacity 0.15s;
}
.ai-widget-close:hover { opacity: 1; }
.ai-widget-close svg { width: 100%; height: 100%; display: block; }

/* ── Карточка ── */
.ai-widget-container {
  background: var(--ai-card);
  border-radius: 30px;
  padding: 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  /* Фиксированная высота карточки (как в макете): блок результата flex:1
     заполняет её и скроллится внутри. Без явной высоты flex-область
     схлопывается в ноль и результат не виден. */
  height: min(88vh, 720px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

/* ── Заголовок ── */
.ai-widget-title {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-shrink: 0;
}
.ai-widget-title-info { flex: 1 0 0; min-width: 0; }
.ai-widget-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ai-widget-title-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}
.ai-widget-title-icon img,
.ai-widget-title-icon svg { width: 100%; height: 100%; display: block; }
.ai-widget-title-text {
  margin: 0;
  font-weight: 400;               /* Futura PT Book */
  font-size: 30px;
  line-height: 1.05;
  color: var(--ai-ink);
  word-break: break-word;
}
.ai-widget-title-order {
  margin: 2px 0 0;
  padding-left: 40px;
  font-weight: 400;
  font-size: 16px;
  line-height: 1.2;
  color: var(--ai-ink);
  opacity: 0.5;
}

/* ── Бейдж токенов / ПРО ── */
.ai-widget-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 40px;
  padding: 0 12px;
  border: none;
  border-radius: 5px;
  font-family: var(--ai-font);
  font-size: 16px;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  background: var(--ai-ink);
  color: var(--ai-card);
  transition: filter 0.15s;
}
.ai-widget-badge:hover { filter: brightness(1.12); }
.ai-widget-badge .b-main { font-weight: 500; }         /* Medium */
.ai-widget-badge .b-sub  { font-weight: 400; opacity: 0.5; }
.ai-widget-badge.danger  { background: #c0392b; }
.ai-widget-badge.warning { background: #b5732a; }

/* ПРО-версия */
.ai-widget-badge.pro {
  background: var(--ai-accent-bg);
  color: var(--ai-ink);
  cursor: default;
}
.ai-widget-badge.pro:hover { filter: none; }
.ai-widget-badge.pro .b-ico { width: 20px; height: 20px; display: block; }
.ai-widget-badge.pro .b-main { font-weight: 500; }

/* Счётчик запросов (без кнопки покупки) */
.ai-widget-badge.counter {
  background: var(--ai-accent-bg);
  color: var(--ai-ink);
  cursor: default;
}
.ai-widget-badge.counter:hover { filter: none; }
.ai-widget-badge.counter .b-sub { opacity: 1; font-weight: 500; }

/* ── Область результата ── */
.ai-widget-results {
  flex: 1 0 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-widget-results-box {
  position: relative;
  flex: 1 0 0;
  min-height: 0;
  background: var(--ai-box);
  border-radius: 30px;
  overflow: hidden;
}
.ai-widget-messages {
  height: 100%;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
.ai-widget-messages::-webkit-scrollbar { width: 5px; }
.ai-widget-messages::-webkit-scrollbar-track { background: transparent; }
.ai-widget-messages::-webkit-scrollbar-thumb { background: #d5d8e6; border-radius: 3px; }

/* Затухание снизу (blur) */
.ai-widget-results-fade {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 120px;
  border-radius: 0 0 30px 30px;
  background: linear-gradient(to bottom, rgba(244, 245, 249, 0), var(--ai-box) 90%);
  pointer-events: none;
}

/* ── Кнопка «Скачать результаты» ── */
.ai-widget-download {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 12px 0 8px;
  border: none;
  border-radius: 10px;
  background: var(--ai-accent-bg);
  color: var(--ai-accent);
  font-family: var(--ai-font);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: filter 0.15s, opacity 0.15s;
}
.ai-widget-download:hover:not(:disabled) { filter: brightness(0.97); }
.ai-widget-download:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-widget-download img,
.ai-widget-download svg { width: 20px; height: 20px; display: block; }

/* ── Инпут ── */
.ai-widget-input {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  min-height: 40px;
  padding: 0 6px 0 12px;
  border: 1px solid var(--ai-border);
  border-radius: 24px;
  background: var(--ai-card);
  transition: border-color 0.15s;
}
.ai-widget-input:focus-within { border-color: var(--ai-accent); }

.ai-widget-info {
  flex-shrink: 0;
  width: 20px;
  height: 40px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
  transition: opacity 0.15s;
}
.ai-widget-info:hover:not(:disabled) { opacity: 1; }
.ai-widget-info:disabled { opacity: 0.4; cursor: not-allowed; }
.ai-widget-info svg { width: 20px; height: 20px; display: block; }

.ai-widget-textarea {
  flex: 1 0 0;
  min-width: 0;
  border: none;
  outline: none;
  background: none;
  resize: none;
  font-family: var(--ai-font);
  font-size: 16px;
  line-height: 1.3;
  color: var(--ai-ink);
  padding: 9px 0;
  min-height: 40px;
  max-height: 120px;
}
.ai-widget-textarea::placeholder { color: var(--ai-ink); opacity: 0.5; }
.ai-widget-textarea:disabled { cursor: not-allowed; opacity: 0.6; }

.ai-widget-send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--ai-accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.13s, transform 0.09s;
}
.ai-widget-send:hover:not(:disabled) { filter: brightness(1.08); }
.ai-widget-send:active:not(:disabled) { transform: scale(0.93); }
.ai-widget-send:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-widget-send img,
.ai-widget-send svg { width: 20px; height: 20px; display: block; }

/* ── Результат ИИ: блоки ── */
.ai-response-blocks {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}
.ai-response-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--ai-ink);
  font-size: 18px;
  line-height: 1.3;
}
.ai-response-block-title {
  font-weight: 600;                /* Futura PT Demi */
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.ai-response-block-content { font-weight: 400; }
.ai-response-block-content p { margin: 0 0 4px; }
.ai-response-block-content p:last-child { margin-bottom: 0; }
.ai-response-block-content ul,
.ai-response-block-content ol { margin: 2px 0; padding-left: 27px; }
.ai-response-block-content li { margin-bottom: 2px; }
.ai-response-block-content strong { font-weight: 600; }
.ai-response-block-content em { font-style: italic; }

/* ── Стартовое состояние / загрузка ── */
.ai-widget-welcome {
  margin: auto;
  text-align: center;
  color: var(--ai-ink);
}
.ai-widget-welcome-icon { width: 48px; height: 48px; margin: 0 auto 14px; }
.ai-widget-welcome-icon img,
.ai-widget-welcome-icon svg { width: 100%; height: 100%; }
.ai-widget-welcome h3 { margin: 0 0 8px; font-weight: 500; font-size: 18px; }
.ai-widget-welcome p  { margin: 0; font-size: 15px; line-height: 1.5; opacity: 0.6; }

/* Индикатор набора */
.ai-widget-typing {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  color: var(--ai-ink);
  opacity: 0.75;
}
.ai-widget-typing-dots { display: flex; gap: 4px; }
.ai-widget-typing-dots span {
  width: 7px; height: 7px;
  background: var(--ai-accent);
  border-radius: 50%;
  animation: aiTypingDot 1.35s infinite ease-in-out both;
}
.ai-widget-typing-dots span:nth-child(1) { animation-delay: -0.30s; }
.ai-widget-typing-dots span:nth-child(2) { animation-delay: -0.15s; }
@keyframes aiTypingDot {
  0%, 80%, 100% { transform: scale(0.5); opacity: 0.35; }
  40% { transform: scale(1); opacity: 1; }
}

/* Сообщение врача */
.ai-widget-message.user {
  align-self: flex-end;
  max-width: 80%;
  background: var(--ai-accent-bg);
  color: var(--ai-ink);
  padding: 10px 16px;
  border-radius: 16px 16px 4px 16px;
  font-size: 16px;
  line-height: 1.4;
  word-break: break-word;
}
.ai-widget-message.user .ai-file-list {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(42, 44, 54, 0.15);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ai-widget-message.ai { width: 100%; }

/* Ошибка */
.ai-widget-error-msg {
  background: #fdecec;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  color: #c0392b;
  line-height: 1.4;
}
/* Лимит */
.ai-widget-limit-notice {
  background: #fff6e5;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  color: #8a5a00;
  line-height: 1.45;
}

/* ── Дисклеймер ── */
.ai-disclaimer-overlay {
  --ai-ink:        #2a2c36;
  --ai-card:       #fafafa;
  --ai-accent:     #868fdd;
  --ai-accent-bg:  #e4e6f8;
  --ai-font: "Futura PT", "Futura", "Century Gothic", "Trebuchet MS",
             -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;

  position: fixed;
  inset: 0;
  z-index: 100000;
  background: rgba(34, 34, 34, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  font-family: var(--ai-font);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}
.ai-disclaimer-overlay.active { opacity: 1; visibility: visible; }

.ai-disclaimer-dialog {
  width: min(640px, 100%);
  max-height: min(88vh, 720px);
  overflow: auto;
  background: var(--ai-card);
  border-radius: 20px;
  padding: 28px 32px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
  color: var(--ai-ink);
}

.ai-disclaimer-body {
  font-size: 15px;
  line-height: 1.55;
}
.ai-disclaimer-lead { margin: 0 0 14px; }
.ai-disclaimer-list {
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-disclaimer-list li { padding-left: 4px; }

.ai-disclaimer-footer {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ai-disclaimer-ack {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 15px;
  line-height: 1.35;
  cursor: pointer;
  user-select: none;
}
.ai-disclaimer-checkbox {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--ai-accent);
}

.ai-disclaimer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.ai-disclaimer-btn {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-family: var(--ai-font);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: filter 0.15s, opacity 0.15s;
}
.ai-disclaimer-btn.primary {
  background: var(--ai-accent);
  color: #fff;
}
.ai-disclaimer-btn.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.ai-disclaimer-btn.secondary {
  background: var(--ai-accent-bg);
  color: var(--ai-ink);
}
.ai-disclaimer-btn:hover:not(:disabled) { filter: brightness(1.05); }

@media (max-width: 640px) {
  .ai-disclaimer-overlay { padding: 16px; }
  .ai-disclaimer-dialog { padding: 20px; border-radius: 16px; }
  .ai-disclaimer-body { font-size: 14px; }
}

/* ── Прикреплённые файлы ── */
.ai-widget-attachments {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ai-widget-attachment-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--ai-accent-bg);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 14px;
  color: var(--ai-ink);
  max-width: 220px;
}
.ai-widget-attachment-chip span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ai-widget-attachment-chip button {
  background: none; border: none; cursor: pointer;
  color: var(--ai-ink); opacity: 0.6; font-size: 16px; line-height: 1;
  padding: 0; flex-shrink: 0;
}
.ai-widget-attachment-chip button:hover { opacity: 1; color: #c0392b; }

/* ── Статус извлечения текста из файла ── */
.ai-widget-attachment-chip .ai-chip-state {
  overflow: visible;
  flex-shrink: 0;
  font-size: 13px;
  line-height: 1;
}
.ai-widget-attachment-chip.is-extracting { opacity: 0.9; }
.ai-widget-attachment-chip.is-extracting .ai-chip-state {
  animation: ai-chip-pulse 1.1s ease-in-out infinite;
}
.ai-widget-attachment-chip.is-done  { box-shadow: inset 0 0 0 1px rgba(46, 125, 91, 0.35); }
.ai-widget-attachment-chip.is-error { box-shadow: inset 0 0 0 1px rgba(192, 57, 43, 0.35); }
@keyframes ai-chip-pulse {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 1; }
}

/* ── Drag & drop ── */
.ai-widget-dropzone {
  position: absolute;
  inset: 0;
  background: rgba(134, 143, 221, 0.08);
  border: 2.5px dashed var(--ai-accent);
  border-radius: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.14s;
}
.ai-widget-dropzone.active { opacity: 1; }
.ai-widget-dropzone-inner { text-align: center; color: var(--ai-accent); }
.ai-widget-dropzone-inner svg { width: 44px; height: 44px; margin-bottom: 8px; }
.ai-widget-dropzone-inner p { font-size: 16px; font-weight: 500; margin: 0; }

.ai-widget-file-input { display: none; }

/* ── Toast ── */
.ai-widget-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ai-ink, #2a2c36);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-family: var(--ai-font, sans-serif);
  font-size: 14px;
  z-index: 999999;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  animation: aiToastIn 0.18s ease;
}
@keyframes aiToastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Мобильный (по фрейму 380px) ── */
@media (max-width: 640px) {
  .ai-widget-overlay { padding: 0; align-items: stretch; }
  .ai-widget-shell {
    width: 100%;
    height: 100%;
  }
  .ai-widget-container {
    height: 100%;
    max-height: none;
    border-radius: 0;
    padding: 70px 20px 24px;
    gap: 16px;
  }
  .ai-widget-close { position: fixed; top: 20px; right: 20px; z-index: 100001; width: 32px; height: 32px; padding: 8px; }
  .ai-widget-title-icon { width: 24px; height: 24px; }
  .ai-widget-title-text { font-size: 22px; }
  .ai-widget-title-order { font-size: 14px; padding-left: 32px; }
  .ai-widget-badge { height: 32px; font-size: 14px; padding: 0 8px; }
  .ai-widget-results-box { border-radius: 20px; }
  .ai-widget-results-fade { border-radius: 0 0 20px 20px; }
  .ai-widget-messages { padding: 16px; gap: 14px; }
  .ai-response-block { font-size: 16px; }
  .ai-widget-dropzone { border-radius: 20px; }
  .ai-widget-textarea { font-size: 14px; }
  .ai-widget-textarea::placeholder { font-size: 13px; }
}

/* ── Кнопка «Интерпретация анализов» на странице заявки ─────────────────────
   Разметка в ЛК:
     <button class="lk-result-action-link ai-interpreter-trigger"
             style="background:none;border:none;cursor:pointer;padding:0;">
       <span class="lk-result-action-text">🧠 Интерпретация анализов</span>
     </button>
   Инлайн-стиль обнуляет фон/рамку/паддинги — кнопка превращается в голый текст,
   который сливается с фоном (особенно на мобильных: видно только эмодзи).
   Инлайн-стиль перебивает обычные селекторы, поэтому здесь нужен !important.
   :not(.ai-list-btn) — чтобы не задеть кнопки в списке заявок: их виджет
   заменяет на пассивный статус .ai-list-status. */
.ai-interpreter-trigger:not(.ai-list-btn) {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 14px 18px !important;
  background: #e4e6f8 !important;      /* --ai-accent-bg */
  border: 1.5px solid #868fdd !important; /* --ai-accent */
  border-radius: 100px !important;
  cursor: pointer !important;
  font-family: "Futura PT", "Century Gothic", "Trebuchet MS",
               -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.2;
  color: #2a2c36 !important;           /* --ai-ink: контрастный текст */
  text-align: center;
  transition: background 0.18s, color 0.18s;
}
.ai-interpreter-trigger:not(.ai-list-btn):hover {
  background: #868fdd !important;
  color: #fff !important;
}
/* Текст внутри: гарантируем видимость независимо от темы ЛК */
.ai-interpreter-trigger:not(.ai-list-btn) .lk-result-action-text {
  color: inherit !important;
  opacity: 1 !important;
  font-size: inherit;
  white-space: normal;
}

@media (max-width: 640px) {
  .ai-interpreter-trigger:not(.ai-list-btn) {
    padding: 13px 14px !important;
    font-size: 14px;
  }
}

/* ── Пассивный статус интерпретации в списке заявок ─────────────────────────
   Заменяет кнопку .ai-list-btn. Самодостаточно (вне .ai-widget-overlay,
   поэтому CSS-переменные виджета здесь недоступны). */
.ai-list-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: "Futura PT", "Century Gothic", "Trebuchet MS",
               -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
  cursor: default;
  user-select: none;
}
.ai-list-status--done {
  color: #2e7d5b;   /* зелёный «выполнено» */
  font-weight: 600;
}
/* Интерпретация не выполнена — ничего не показываем. Элемент остаётся в DOM
   (пустой, скрытый): ЛК ориентируется на него, чтобы не вставлять кнопку заново. */
.ai-list-status--none {
  display: none;
}

/* На мобильной вёрстке ЛК сворачивает таблицу до 2 колонок (номер + статус),
   и полный текст не помещается рядом с пилюлей «готов» — переносится на вторую
   строку. Центрируем текст под пилюлей и резервируем место под вторую строку
   у ВСЕХ заявок (не только выполненных), чтобы карточки в списке были одной
   высоты, а не «прыгали» из-за одной лишней строки у части заявок. */
@media (max-width: 640px) {
  .ai-list-status {
    display: flex;
    justify-content: center;
    width: 100%;
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.3;
    white-space: normal;
    text-align: center;
  }
  .ai-list-status--none {
    display: flex;
    visibility: hidden;
  }
}
