/**
 * AI Search Widget + Chat Assistant — ai-search.css  v3
 */

/* ===== ПОШУК: ОВЕРЛЕЙ ===== */
#ai-search-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 99999;
  align-items: flex-start;
  justify-content: center;
  padding: 64px 16px 0;
  box-sizing: border-box;
}
#ai-search-overlay.active {
  display: flex;
  animation: ai-overlay-in 0.15s ease;
}
@keyframes ai-overlay-in {
  from { opacity:0; } to { opacity:1; }
}

/* ===== ПОШУК: МОДАЛЬНЕ ВІКНО ===== */
#ai-search-modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 660px;
  max-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,0.22);
  animation: ai-modal-in 0.2s ease;
}
@keyframes ai-modal-in {
  from { opacity:0; transform:translateY(-10px) scale(0.98); }
  to   { opacity:1; transform:translateY(0) scale(1); }
}

/* ===== ПОШУК: ШАПКА ===== */
#ai-search-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: #f7f8fa;
  border-bottom: 1px solid #e4e6ea;
  flex-shrink: 0;
}
#ai-search-icon { width:18px; height:18px; color:#6b7280; flex-shrink:0; }
#ai-search-input {
  flex: 1;
  border: none; outline: none;
  background: transparent;
  font-size: 17px; color: #111827;
  font-family: inherit; min-width: 0;
}
#ai-search-input::placeholder { color: #9ca3af; }
#ai-search-input::-webkit-search-cancel-button { display:none; }
#ai-search-close {
  background: transparent; border: none; cursor: pointer;
  padding: 5px; color: #9ca3af;
  display: flex; align-items: center;
  border-radius: 7px;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
#ai-search-close:hover { background:#e5e7eb; color:#374151; }
#ai-search-close svg { width:17px; height:17px; }

/* ===== ПОШУК: ТІЛО ===== */
#ai-search-body { overflow-y: auto; flex: 1; }

/* Порожній / немає результатів */
#ai-search-empty,
#ai-search-no-results {
  flex-direction: column;
  align-items: center; justify-content: center;
  padding: 44px 20px; gap: 8px;
}
#ai-search-empty svg, #ai-search-no-results svg { width:42px; height:42px; color:#d1d5db; margin-bottom:4px; }
#ai-search-empty p, #ai-search-no-results p { font-size:15px; color:#4b5563; margin:0; }
#ai-search-empty .hint, #ai-search-no-results .hint { font-size:13px; color:#9ca3af; }
#ai-search-no-results .hint a { color:#3b82f6; text-decoration:none; }
#ai-search-no-results .hint a:hover { text-decoration:underline; }

/* Завантаження */
#ai-search-loading {
  flex-direction: column; align-items:center;
  justify-content:center; padding:44px 20px; gap:14px;
}
#ai-search-loading p { font-size:14px; color:#9ca3af; margin:0; }
.ai-search-spinner { display:flex; gap:6px; align-items:center; }
.ai-search-spinner span {
  width:8px; height:8px; border-radius:50%;
  background:#3b82f6;
  animation:ai-bounce 1.2s infinite ease-in-out both;
}
.ai-search-spinner span:nth-child(1) { animation-delay:-0.32s; }
.ai-search-spinner span:nth-child(2) { animation-delay:-0.16s; }
@keyframes ai-bounce {
  0%,80%,100% { transform:scale(0.65); opacity:0.45; }
  40%          { transform:scale(1.1);  opacity:1; }
}

/* Результати */
#ai-search-results { padding:16px 18px; }
#ai-answer-block {
  background:#eff6ff; border-radius:10px;
  padding:13px 15px; margin-bottom:18px;
  border-left:3px solid #3b82f6;
}
#ai-answer-label {
  display:flex; align-items:center; gap:5px;
  font-size:11px; font-weight:600; color:#1d4ed8;
  text-transform:uppercase; letter-spacing:0.4px; margin-bottom:7px;
}
#ai-answer-label svg { width:13px; height:13px; color:#f59e0b; }
#ai-answer-text { font-size:15px; color:#1e3a5f; line-height:1.65; margin:0; }
#ai-results-label {
  font-size:11px; font-weight:600; color:#9ca3af;
  text-transform:uppercase; letter-spacing:0.5px; margin-bottom:10px;
}
#ai-results-list { list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:6px; }
.ai-result-item {
  display:flex; flex-direction:column; gap:4px;
  padding:12px 14px; border-radius:10px;
  text-decoration:none; background:#fff;
  border:1px solid #e5e7eb;
  transition:border-color 0.15s, background 0.15s;
}
.ai-result-item:hover { border-color:#93c5fd; background:#f0f7ff; }
.ai-result-meta { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.ai-result-tag {
  font-size:11px; font-weight:600;
  padding:2px 8px; border-radius:20px; white-space:nowrap;
}
.ai-result-tag--news { background:#dbeafe; color:#1e40af; }
.ai-result-tag--doc  { background:#d1fae5; color:#065f46; }
.ai-result-tag--page { background:#fef3c7; color:#92400e; }
.ai-result-date { font-size:12px; color:#9ca3af; white-space:nowrap; }
.ai-result-title { font-size:15px; font-weight:600; color:#111827; line-height:1.4; }
.ai-result-snippet { font-size:13px; color:#6b7280; line-height:1.55; }

/* Підвал пошуку */
#ai-search-footer {
  padding:9px 18px; border-top:1px solid #f3f4f6;
  font-size:11px; color:#9ca3af;
  display:flex; align-items:center; gap:5px;
  flex-shrink:0; background:#fafafa;
}
.ai-badge {
  background:#2563eb; color:#fff;
  font-size:10px; font-weight:700;
  padding:1px 6px; border-radius:5px;
}
kbd {
  background:#f3f4f6; border:1px solid #e5e7eb;
  border-radius:4px; padding:1px 5px;
  font-size:11px; color:#6b7280; font-family:inherit;
}

/* ===== КНОПКА ПОШУКУ В ШАПЦІ ===== */
#ai-search-trigger {
  display:inline-flex; align-items:center; gap:6px;
  background:transparent; border:none; cursor:pointer;
  text-decoration:none; color:inherit;
  font-size:14px; padding:6px 10px; border-radius:8px;
  opacity:0.85; transition:opacity 0.15s, background 0.15s;
}
#ai-search-trigger:hover { opacity:1; background:rgba(255,255,255,0.12); }
#ai-search-trigger svg { width:17px; height:17px; flex-shrink:0; }
#ai-search-trigger .ai-badge { font-size:9px; padding:1px 5px; opacity:0.9; }

/* ============================================================
   ЧАТ АСИСТЕНТ
   ============================================================ */

/* Кнопка-тригер чату (фіксована, права сторона) */
#ai-chat-trigger {
  position: fixed;
  bottom: 28px;
  right: 24px;
  z-index: 99990;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 28px;
  padding: 12px 20px 12px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(37,99,235,0.42);
  transition: transform 0.2s, box-shadow 0.2s, background 0.15s;
}
#ai-chat-trigger:hover {
  background: #1d4ed8;
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(37,99,235,0.48);
}
#ai-chat-trigger svg { width:20px; height:20px; flex-shrink:0; }
#ai-chat-trigger-label { white-space:nowrap; }

/* Оверлей (мобільний) */
#ai-chat-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99991;
}
#ai-chat-overlay.active { display: block; }

/* Панель чату */
#ai-chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  max-width: 100vw;
  background: #fff;
  z-index: 99992;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 40px rgba(0,0,0,0.14);
  transform: translateX(110%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  overflow: hidden;
  box-sizing: border-box;
}
#ai-chat-panel.active { transform: translateX(0); }

/* Шапка чату */
#ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: linear-gradient(135deg, #1e40af 0%, #2563eb 100%);
  color: #fff;
  flex-shrink: 0;
}
#ai-chat-title { display:flex; align-items:center; gap:12px; }
#ai-chat-avatar {
  width: 40px; height: 40px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
#ai-chat-avatar svg { width:20px; height:20px; color:#fbbf24; }
#ai-chat-name { font-size:15px; font-weight:700; }
#ai-chat-status { display:flex; align-items:center; gap:5px; font-size:12px; opacity:0.85; margin-top:2px; }
#ai-chat-dot {
  width: 7px; height: 7px;
  background: #4ade80; border-radius: 50%;
  display: inline-block;
}
#ai-chat-dot.busy {
  background: #fbbf24;
  animation: ai-pulse 1s infinite;
}
@keyframes ai-pulse {
  0%,100% { opacity:1; } 50% { opacity:0.4; }
}
#ai-chat-close {
  background: rgba(255,255,255,0.15);
  border: none; cursor: pointer;
  padding: 8px; border-radius: 8px; color: #fff;
  display:flex; align-items:center;
  transition: background 0.15s;
}
#ai-chat-close:hover { background: rgba(255,255,255,0.25); }
#ai-chat-close svg { width:18px; height:18px; }

/* Повідомлення */
#ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
}
.ai-chat-msg { display:flex; flex-direction:column; max-width:88%; min-width: 0; }
.ai-chat-msg--bot  { align-self: flex-start; }
.ai-chat-msg--user { align-self: flex-end; }

.ai-chat-bubble {
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  overflow-wrap: break-word;
}
.ai-chat-msg--bot .ai-chat-bubble {
  background: #fff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.ai-chat-msg--user .ai-chat-bubble {
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Анімація "друкує" */
.ai-chat-typing {
  display:flex; gap:5px; align-items:center; padding:14px 16px !important;
}
.ai-chat-typing span {
  width:7px; height:7px; background:#9ca3af; border-radius:50%;
  animation:ai-bounce 1.2s infinite ease-in-out both;
}
.ai-chat-typing span:nth-child(1) { animation-delay:-0.32s; }
.ai-chat-typing span:nth-child(2) { animation-delay:-0.16s; }

/* Джерела */
.ai-chat-sources {
  margin-top: 7px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ai-chat-source-link {
  font-size: 12px;
  color: #2563eb;
  text-decoration: none;
  padding: 4px 8px;
  background: #eff6ff;
  border-radius: 6px;
  border: 1px solid #bfdbfe;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  box-sizing: border-box;
  transition: background 0.1s;
}
.ai-chat-source-link:hover { background:#dbeafe; }

/* Підказки */
#ai-chat-suggestions {
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  border-top: 1px solid #f0f0f0;
  background: #fff;
  flex-shrink: 0;
}
.ai-chat-suggest {
  font-size: 12px;
  padding: 5px 11px;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.ai-chat-suggest:hover { background:#dbeafe; border-color:#93c5fd; }

/* Поле вводу */
#ai-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  flex-shrink: 0;
}
#ai-chat-input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  padding: 9px 13px;
  font-size: 14px;
  font-family: inherit;
  color: #111827;
  resize: none;
  outline: none;
  min-height: 38px;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
  transition: border-color 0.15s;
}
#ai-chat-input:focus { border-color:#3b82f6; }
#ai-chat-input::placeholder { color:#9ca3af; }
#ai-chat-send {
  width: 38px; height: 38px;
  background: #2563eb;
  color: #fff; border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items:center; justify-content:center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
#ai-chat-send:hover { background:#1d4ed8; transform:scale(1.06); }
#ai-chat-send svg { width:16px; height:16px; }

/* ===== АДАПТИВ ===== */
@media (max-width: 600px) {
  #ai-search-overlay { padding:0; align-items:flex-end; }
  #ai-search-modal { border-radius:18px 18px 0 0; max-height:90vh; max-width:100%; }
  .ai-result-date { display:none; }
  #ai-search-input { font-size:16px; }

  #ai-chat-panel { width:100%; border-radius:18px 18px 0 0; top:auto; height:90vh; }
  #ai-chat-trigger { bottom:20px; right:16px; padding:11px 16px 11px 14px; }
  #ai-chat-trigger-label { display:none; }
  #ai-chat-trigger { border-radius:50%; width:52px; height:52px; padding:0; justify-content:center; }
}
