/* ─── Кнопка AI в хедере ─────────────────────────────────────── */
.icon-btn.ai-header-btn {
  position: relative;
  background: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
  color: #fff !important;
  box-shadow: 0 2px 8px rgba(168, 85, 247, .35);
  transition: transform .15s ease, box-shadow .15s ease;
}
.icon-btn.ai-header-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(168, 85, 247, .55);
}
.icon-btn.ai-header-btn::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  background: linear-gradient(135deg, #6366f1, #a855f7, #ec4899);
  filter: blur(8px);
  opacity: .35;
  z-index: -1;
  animation: ai-pulse 3s ease-in-out infinite;
}
@keyframes ai-pulse {
  0%, 100% { opacity: .25; }
  50%      { opacity: .55; }
}
.icon-btn.ai-header-btn svg { stroke: #fff; }

/* ─── Floating-окно чата ─────────────────────────────────────── */
.ai-panel {
  position: fixed;
  right: 24px; bottom: 24px;
  width: 420px; height: 620px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  background: var(--bg, #0f172a);
  color: var(--text, #e2e8f0);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.3);
  display: none;
  flex-direction: column;
  z-index: 9999;
  overflow: hidden;
  animation: ai-rise .22s ease;
}
.ai-panel.open { display: flex; }
@keyframes ai-rise {
  from { opacity: 0; transform: translateY(20px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ai-panel-head {
  padding: 14px 16px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  color: #fff;
  display: flex; align-items: center; gap: 10px;
  cursor: grab;
}
.ai-panel-head:active { cursor: grabbing; }
.ai-head-title { font-weight: 700; font-size: 15px; flex: 1; display:flex; align-items:center; gap:8px; }
.ai-head-title .ai-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #10b981; box-shadow: 0 0 8px #10b981;
}
.ai-head-btn {
  width: 28px; height: 28px; border-radius: 8px;
  display:flex; align-items:center; justify-content:center;
  cursor: pointer; opacity: .85; transition: background .15s;
  background: rgba(255,255,255,.08); color: #fff;
}
.ai-head-btn:hover { background: rgba(255,255,255,.18); opacity: 1; }

/* ─── Список сообщений ──────────────────────────────────────── */
.ai-msgs {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}
.ai-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px; line-height: 1.5;
  word-wrap: break-word; word-break: break-word;
}
.ai-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg.bot {
  align-self: flex-start;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  border-bottom-left-radius: 4px;
}
.ai-msg.bot.streaming::after {
  content: '▌'; opacity: .6;
  animation: ai-blink 1s steps(2) infinite;
}
@keyframes ai-blink { 50% { opacity: 0; } }
.ai-msg.bot p:first-child { margin-top: 0; }
.ai-msg.bot p:last-child  { margin-bottom: 0; }
.ai-msg.bot ul, .ai-msg.bot ol { margin: 6px 0 6px 18px; padding: 0; }
.ai-msg.bot li { margin: 2px 0; }
.ai-msg.bot code {
  background: rgba(0,0,0,.4); padding: 1px 6px;
  border-radius: 4px; font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 12.5px;
}
.ai-msg.bot pre {
  background: rgba(0,0,0,.45); padding: 10px 12px;
  border-radius: 8px; overflow-x: auto; margin: 8px 0;
}
.ai-msg.bot pre code { background: transparent; padding: 0; }
.ai-msg.bot a { color: #a5b4fc; }

/* ─── Welcome / suggestions ─────────────────────────────────── */
.ai-welcome {
  padding: 12px 16px;
  background: rgba(99,102,241,.08);
  border: 1px solid rgba(99,102,241,.2);
  border-radius: 14px;
  font-size: 14px; line-height: 1.5;
}
.ai-suggestions {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 0 16px 12px;
}
.ai-suggestion {
  font-size: 12.5px;
  padding: 7px 12px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.ai-suggestion:hover {
  background: rgba(168,85,247,.15);
  border-color: rgba(168,85,247,.45);
}

/* ─── Composer ──────────────────────────────────────────────── */
.ai-composer {
  border-top: 1px solid rgba(255,255,255,.08);
  padding: 12px 12px 10px;
}
.ai-composer-row {
  display: flex; gap: 8px; align-items: flex-end;
}
.ai-input {
  flex: 1; resize: none;
  min-height: 38px; max-height: 140px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(255,255,255,.04);
  color: var(--text, #e2e8f0);
  font-size: 14px; font-family: inherit;
  line-height: 1.4;
}
.ai-input:focus {
  outline: none;
  border-color: rgba(168,85,247,.55);
  background: rgba(255,255,255,.06);
}
.ai-send-btn {
  width: 38px; height: 38px;
  border-radius: 10px; border: 0; cursor: pointer;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, transform .15s;
}
.ai-send-btn:hover { transform: translateY(-1px); }
.ai-send-btn:disabled { opacity: .4; cursor: not-allowed; transform:none; }
.ai-meta {
  font-size: 11.5px; color: var(--text3, #94a3b8);
  padding: 6px 4px 0; text-align: right;
}
.ai-meta .ai-low { color: #fb923c; }
.ai-meta .ai-out { color: #f87171; }

/* ─── Sidebar истории ───────────────────────────────────────── */
.ai-history-overlay {
  position: absolute; inset: 0;
  background: var(--bg, #0f172a);
  display: none; flex-direction: column;
}
.ai-history-overlay.open { display: flex; }
.ai-hist-head {
  padding: 14px 16px;
  display:flex; align-items:center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  font-weight: 600;
}
.ai-hist-list { flex: 1; overflow-y: auto; padding: 8px; }
.ai-hist-item {
  padding: 10px 12px; border-radius: 10px;
  cursor: pointer; transition: background .15s;
  display: flex; align-items: center; gap: 8px;
}
.ai-hist-item:hover { background: rgba(255,255,255,.05); }
.ai-hist-title { flex: 1; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-hist-del {
  opacity: 0; transition: opacity .15s;
  font-size: 12px; padding: 4px 8px;
  border-radius: 6px;
  background: rgba(248,113,113,.15); color: #fca5a5;
  cursor: pointer;
}
.ai-hist-item:hover .ai-hist-del { opacity: 1; }
.ai-hist-empty { padding: 40px 20px; text-align: center; color: var(--text3); font-size: 13px; }

/* ─── Состояние "не активирован" ────────────────────────────── */
.ai-locked {
  flex: 1; display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  text-align: center; padding: 32px 24px; gap: 16px;
}
.ai-locked h3 { margin: 0; font-size: 18px; font-weight: 700; }
.ai-locked p { margin: 0; font-size: 13.5px; color: var(--text3); line-height: 1.5; }
.ai-locked-btn {
  padding: 10px 22px; border-radius: 10px; border: 0; cursor: pointer;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  color: #fff; font-weight: 600; font-size: 14px;
}

/* ─── Адаптив ──────────────────────────────────────────────── */
@media (max-width: 640px) {
  .ai-panel {
    right: 0; bottom: 0; left: 0; top: 0;
    width: 100%; height: 100%;
    max-width: none; max-height: none;
    border-radius: 0;
  }
}
