/* ══ Neural canvas ══ */
#neural-canvas {
  position: fixed; top: 0; left: 0;
  width: 100vw; height: 100vh;
  pointer-events: none;
  opacity: 0; transition: opacity 0.6s ease;
  z-index: 999;
}
#neural-canvas.active { opacity: 1; }

/* ══ AI Button ══ */
#ai-btn {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 48px; height: 48px;
  border: none; background: transparent;
  cursor: pointer; z-index: 20;
  flex-shrink: 0;
}
.ai-btn-inner {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--bg-sidebar);
  border: 1.5px solid var(--border-color);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.3s, border-color 0.3s, box-shadow 0.2s, color 0.3s, transform 0.15s;
  position: relative; z-index: 20;
}
#ai-btn:hover .ai-btn-inner {
  border-color: var(--accent-color);
  background: rgba(var(--accent-color-rgb, 59,130,246), 0.12);
  box-shadow: 0 2px 10px rgba(var(--accent-color-rgb, 59,130,246), 0.3);
  transform: scale(1.06);
}
#ai-btn.active .ai-btn-inner {
  background: var(--accent-color);
  border-color: var(--accent-color);
  box-shadow: 0 2px 14px rgba(var(--accent-color-rgb, 59,130,246), 0.5);
}
/* На тёмных темах с очень светлым акцентом — иконка тёмная для контраста */
body.theme-twilight  #ai-btn.active .ai-btn-inner svg,
body.theme-glacier   #ai-btn.active .ai-btn-inner svg,
body.theme-cosmos    #ai-btn.active .ai-btn-inner svg,
body.theme-amethyst  #ai-btn.active .ai-btn-inner svg {
  color: #1a1625;
}
#ai-btn .ai-btn-inner svg {
  color: var(--text-muted);
  transition: color 0.3s, transform 0.3s;
}
#ai-btn:hover .ai-btn-inner svg {
  color: var(--accent-color);
  transform: rotate(15deg);
}
#ai-btn.active .ai-btn-inner svg {
  color: #ffffff;
  transform: rotate(20deg);
}

/* ══ Pulse rings — theme-aware ══ */
.pulse-ring {
  position: absolute; width: 44px; height: 44px;
  border-radius: 50%;
  border: 1.5px solid rgba(var(--accent-color-rgb, 59,130,246), 0.55);
  opacity: 0; pointer-events: none; z-index: 19;
}
#ai-btn.active .pulse-ring { animation: neural-pulse 2s ease-out infinite; }
#ai-btn.active .pulse-ring:nth-child(2) { animation-delay: 0.65s; }
#ai-btn.active .pulse-ring:nth-child(3) { animation-delay: 1.3s; }
@keyframes neural-pulse {
  0%   { transform: scale(1);   opacity: 0.65; }
  100% { transform: scale(3.2); opacity: 0; }
}

/* ══ AI Actions Row — встроена в строку ввода ══ */
.ai-actions-row {
  position: relative;
  display: grid;
  grid-template-rows: 1fr;
  /* НЕТ overflow:hidden — иначе пикер обрезается */
  transition: grid-template-rows 0.28s cubic-bezier(0.4,0,0.2,1),
  opacity 0.22s ease,
  margin-bottom 0.28s cubic-bezier(0.4,0,0.2,1);
  opacity: 1;
  margin-bottom: 8px;
}
.ai-actions-row.ai-actions-hidden {
  grid-template-rows: 0fr;
  opacity: 0;
  margin-bottom: 0;
  pointer-events: none;
}
/* Обёртка для grid-анимации — overflow:hidden здесь, не на row */
.ai-actions-clip {
  min-height: 0;
  overflow: hidden;
}
.ai-actions-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-bottom: 2px;
  padding-top: 2px;
}
.ai-actions-inner::-webkit-scrollbar { display: none; }
.ai-actions-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent-color);
  opacity: 0.8;
  white-space: nowrap;
  margin-right: 2px;
}

/* Результат и загрузка — под кнопками */
.ai-inline-result {
  font-size: 0.8rem;
  color: var(--text-main);
  background: rgba(var(--accent-color-rgb, 59,130,246), 0.08);
  border: 1px solid rgba(var(--accent-color-rgb, 59,130,246), 0.2);
  border-radius: 10px;
  padding: 6px 10px;
  margin-top: 6px;
  line-height: 1.45;
}
.ai-inline-loading {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-top: 6px;
  padding: 2px 4px;
}
.ai-loading-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent-color);
  opacity: 0.7;
  animation: ai-dot-pulse 1.2s ease-in-out infinite;
}
.ai-loading-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-loading-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-dot-pulse {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* ══ AI action buttons ══ */
.ai-action-btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  border-radius: 0.75rem;
  transition: all 0.2s;
  cursor: pointer;
  border: none;
}
.ai-action-primary {
  background: var(--accent-color);
  color: white;
}
.ai-action-primary:hover {
  filter: brightness(1.1);
}
.ai-action-secondary {
  background: transparent;
  color: var(--accent-color);
  border: 1.5px solid rgba(var(--accent-color-rgb, 59,130,246), 0.35);
}
.ai-action-secondary:hover {
  background: rgba(var(--accent-color-rgb, 59,130,246), 0.1);
}
.ai-action-apply { background: #059669; color: white; }
.ai-action-apply:hover { background: #047857; }
.ai-action-reply {
  background: transparent;
  color: var(--accent-color);
  border: 1.5px solid rgba(var(--accent-color-rgb, 59,130,246), 0.35);
  white-space: nowrap;
}
.ai-action-reply:hover {
  background: rgba(var(--accent-color-rgb, 59,130,246), 0.1);
}
/* ═══ Agent label button ════════════════════════════════════════════════════ */
.ai-agent-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1.5px solid rgba(var(--accent-color-rgb, 59,130,246), 0.3);
  background: rgba(var(--accent-color-rgb, 59,130,246), 0.06);
  color: var(--accent-color);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
  position: relative;
}
.ai-agent-label:hover {
  background: rgba(var(--accent-color-rgb, 59,130,246), 0.14);
  border-color: var(--accent-color);
}
.ai-agent-icon {
  font-size: 0.75rem;
  line-height: 1;
}

/* ═══ Agent picker dropdown ════════════════════════════════════════════════ */
.ai-agent-picker {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  min-width: 240px;
  background: var(--bg-main);
  border: 1.5px solid rgba(var(--accent-color-rgb, 59,130,246), 0.25);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  overflow: hidden;
  z-index: 100;
  animation: ai-panel-in 0.18s cubic-bezier(0.34,1.56,0.64,1) both;
}
.ai-agent-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s;
  text-align: left;
}
.ai-agent-option:hover {
  background: rgba(var(--accent-color-rgb, 59,130,246), 0.08);
}
.ai-agent-option.active {
  background: rgba(var(--accent-color-rgb, 59,130,246), 0.1);
}
.ai-agent-opt-icon {
  font-size: 1rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}
.ai-agent-opt-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.ai-agent-opt-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
}
.ai-agent-opt-desc {
  font-size: 0.67rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-agent-opt-free {
  font-size: 0.6rem;
  font-weight: 700;
  color: #16a34a;
  background: rgba(22,163,74,0.12);
  border: 1px solid rgba(22,163,74,0.3);
  border-radius: 4px;
  padding: 1px 5px;
  flex-shrink: 0;
}
.ai-agent-opt-check {
  color: var(--accent-color);
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}