/* ─── Page & wrap ────────────────────────────────────────────────────── */
#page-agent { padding: 0 !important; }
.agent-wrap {
  max-width: 100% !important;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
/* Empty state: center the input zone vertically */
.agent-wrap:not(.has-messages) {
  justify-content: center;
}
/* Active: top-align */
.agent-wrap.has-messages {
  justify-content: flex-start;
}

/* ─── Messages list ──────────────────────────────────────────────────── */
.agent-history {
  flex: 1 1 0%;
  min-height: 0;
  max-height: none !important;
  overflow-y: auto !important;
  padding: 24px 0 12px !important;
  gap: 0 !important;
  display: flex;
  flex-direction: column;
}

/* ─── Message bubbles ────────────────────────────────────────────────── */
.agent-msg {
  gap: 0 !important;
  padding: 16px 20px !important;
  align-items: flex-start;
  max-width: 100%;
}
/* User messages — right-aligned bubble */
.agent-msg-user {
  flex-direction: row-reverse;
  justify-content: flex-start;
  padding: 8px 20px !important;
}
.agent-msg-user .agent-msg-content {
  flex: 0 1 auto !important;
  max-width: 70% !important;
  background: rgba(255,255,255,0.09) !important;
  border: 1px solid rgba(255,255,255,0.12) !important;
  border-radius: 18px 18px 4px 18px !important;
  padding: 10px 16px !important;
  font-size: 14px !important;
  box-shadow: none;
}
/* Assistant messages — no border, more open */
.agent-msg-assistant .agent-msg-content,
.agent-block .agent-msg-content {
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  padding: 4px 0 !important;
}
.agent-msg-avatar {
  display: none !important; /* cleaner without avatars in plain mode */
}
.agent-msg-body { gap: 4px !important; }
.agent-msg-label {
  font-size: 11px !important; font-weight: 700 !important;
  letter-spacing: 0.6px !important; opacity: 0.55;
  margin-bottom: 2px;
}
.agent-msg-content {
  font-size: 14px !important; line-height: 1.65 !important;
  color: rgba(255,255,255,0.88) !important;
  padding: 0 !important; border: none !important;
  background: transparent !important;
}

/* Per-agent label colours */
.agent-block.agent-manager    .agent-msg-label { color: #a8b3c7; }
.agent-block.agent-audit      .agent-msg-label { color: #5b8dee; }
.agent-block.agent-speed      .agent-msg-label { color: #ff9500; }
.agent-block.agent-analytics  .agent-msg-label { color: #30d158; }
.agent-block.agent-benchmark  .agent-msg-label { color: #ffcc00; }
.agent-block.agent-copywriter .agent-msg-label { color: #f59e0b; }

/* ─── Tool rows ──────────────────────────────────────────────────────── */
.agent-tool-row {
  border-radius: 8px !important; background: rgba(0,0,0,0.22) !important;
  border: 1px solid rgba(255,255,255,0.05);
}
.agent-tool-row.running { border-left: 2px solid #f59e0b !important; background: rgba(245,158,11,0.06) !important; }
.agent-tool-row.done    { border-left: 2px solid #30d158 !important; }
.agent-tool-row.error   { border-left: 2px solid #ff453a !important; }

/* ─── Input zone (centred empty / pinned bottom active) ──────────────── */
.agent-input-zone {
  flex-shrink: 0;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: padding 0.3s;
}
/* Empty state: no extra padding (flex centering handles vertical position) */
.agent-wrap:not(.has-messages) .agent-input-zone {
  padding-top: 0;
}
/* Active: small gap from last message */
.agent-wrap.has-messages .agent-input-zone {
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.05);
}

/* ─── Welcome heading ────────────────────────────────────────────────── */
.agent-welcome {
  text-align: center;
  padding-bottom: 8px;
  transition: opacity 0.3s;
}
.agent-wrap.has-messages .agent-welcome { display: none; }
.agent-welcome-title {
  font-size: 26px;
  font-weight: 700;
  color: rgba(255,255,255,0.90);
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}
.agent-welcome-sub {
  font-size: 13px;
  color: rgba(255,255,255,0.35);
}

/* ─── Project row ────────────────────────────────────────────────────── */
.agent-project-row {
  display: flex; align-items: center; gap: 8px;
}
.agent-project-label {
  font-size: 11.5px; color: rgba(255,255,255,0.32);
  white-space: nowrap;
}
/* agent-project-sel styled via .cs-trigger (CustomSelect component) */
.agent-project-row .cs-wrap { flex: 1; min-width: 0; }
.agent-project-row .cs-trigger { font-size: 12.5px; padding: 6px 10px; }

/* ─── Input box (borderless, floating) ──────────────────────────────── */
.agent-input-wrap {
  display: flex !important;
  align-items: flex-end !important;
  gap: 10px !important;
  background: transparent !important;
  border: none !important;
  border-radius: 0 !important;
  padding: 4px 0 !important;
  transition: none !important;
}
#agent-input {
  flex: 1;
  background: rgba(255,255,255,0.06) !important;
  border: 1px solid rgba(255,255,255,0.10) !important;
  border-radius: 14px !important;
  outline: none !important; resize: none;
  color: rgba(255,255,255,0.90) !important;
  font-size: 15px !important; line-height: 1.5;
  min-height: 24px; max-height: 160px; overflow-y: auto;
  padding: 10px 16px !important;
  transition: border-color 0.15s !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05) !important;
}
#agent-input:focus {
  border-color: rgba(245,158,11,0.40) !important;
  box-shadow: 0 0 0 3px rgba(245,158,11,0.10), inset 0 1px 0 rgba(255,255,255,0.05) !important;
}
#agent-input::placeholder { color: rgba(255,255,255,0.22) !important; }

#agent-send {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 50% !important;
  background: linear-gradient(145deg, #f59e0b, #d97706) !important;
  border: none !important;
  color: #1a0800 !important;
  font-size: 16px !important;
  font-weight: 800 !important;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s !important;
  box-shadow: 0 2px 10px rgba(245,158,11,0.45), inset 0 1px 0 rgba(255,255,255,0.30);
}
#agent-send:hover { transform: scale(1.08); box-shadow: 0 4px 16px rgba(245,158,11,0.55) !important; }
#agent-send:active { transform: scale(0.96); }

/* ─── Stop button ────────────────────────────────────────────────────── */
#agent-stop-btn {
  display: flex; align-items: center; justify-content: center;
  gap: 6px; padding: 8px 20px;
  background: rgba(255,255,255,0.06) !important;
  border: 1px solid rgba(255,255,255,0.12) !important;
  border-radius: 20px !important;
  color: rgba(255,255,255,0.80) !important;
  font-size: 13px !important; font-weight: 500 !important;
  cursor: pointer; transition: background 0.15s !important;
}
#agent-stop-btn:hover { background: rgba(255,69,58,0.15) !important; color: #ff6b6b !important; border-color: rgba(255,69,58,0.3) !important; }
#agent-stop-row { display: flex; justify-content: center; padding: 4px 0 8px; }

/* ─── Action chips ───────────────────────────────────────────────────── */
.agent-chips {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center;
}
.agent-wrap.has-messages .agent-chips { display: none; }
.agent-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  background: rgba(255,255,255,0.05) !important;
  border: 1px solid rgba(255,255,255,0.12) !important;
  border-radius: 20px !important;
  color: rgba(255,255,255,0.70) !important;
  font-size: 13px !important; font-weight: 500 !important;
  cursor: pointer;
  transition: all 0.15s !important;
  white-space: nowrap;
}
.agent-chip:hover {
  background: rgba(255,255,255,0.10) !important;
  border-color: rgba(255,255,255,0.22) !important;
  color: rgba(255,255,255,0.95) !important;
}

/* ─── Session stats ──────────────────────────────────────────────────── */
.agent-session-stats {
  background: rgba(255,255,255,0.03) !important;
  border: 1px solid rgba(255,255,255,0.06) !important;
  border-radius: 10px !important; font-size: 11px !important;
}

/* ─── Streaming cursor ───────────────────────────────────────────────── */
#agent-history.streaming::after {
  background: rgba(255,255,255,0.7) !important;
  border-radius: 2px;
  animation: blink-cursor 1s step-end infinite !important;
}
@keyframes blink-cursor { 50% { opacity: 0; } }

/* ─── Audit panels ───────────────────────────────────────────────────── */
.audit-done-panel {
  background: rgba(48,209,88,0.05) !important;
  border: 1px solid rgba(48,209,88,0.20) !important;
  border-radius: 12px !important;
}
.audit-action-panel {
  background: rgba(255,255,255,0.03) !important;
  border: 1px solid rgba(255,255,255,0.09) !important;
  border-radius: 12px !important;
}
.audit-done-btn { border-radius: 10px !important; font-size: 12px !important; transition: all 0.15s !important; }
.audit-btn-all {
  background: linear-gradient(135deg, #30d158, #27b348) !important;
  border-radius: 10px !important; transition: all 0.15s !important;
}
.audit-btn-all:hover { filter: brightness(1.1); }
.agent-suggestion-chip {
  background: rgba(255,255,255,0.04) !important;
  border: 1px solid rgba(255,255,255,0.09) !important;
  border-radius: 20px !important; transition: all 0.15s !important;
}
.agent-suggestion-chip:hover { background: rgba(255,255,255,0.09) !important; }

/* ═══════════════════════════════════════════════════════════════════════ */

/* ── AI persona / memory / image attachments ───────────────────────── */
.ai-persona-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; margin-bottom: 10px;
  background: var(--glass-input); border: 1px solid var(--border-dim);
  border-radius: 10px;
}
.ai-persona-lbl { font-size: 11.5px; color: var(--muted); }
.ai-persona-sel { width: auto; min-width: 220px; font-size: 12px; padding: 5px 26px 5px 10px; }
.ai-memory-hint {
  margin-left: auto; font-size: 11px; color: var(--muted);
  display: inline-flex; align-items: center; gap: 4px;
}
.ai-memory-hint.has-memory { color: var(--success, #30d158); }

.audit-attach-preview {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 6px 0;
}
.audit-attach-thumb {
  position: relative; width: 64px; height: 64px;
  border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border-dim);
  background: var(--glass-dark);
}
.audit-attach-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.audit-attach-thumb .remove {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0,0,0,.65); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; cursor: pointer; border: none; line-height: 1;
}
.audit-attach-btn { padding: 0 12px; font-size: 16px; flex-shrink: 0; }

.audit-msg-images {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-top: 6px;
}
.audit-msg-images img {
  max-width: 200px; max-height: 160px;
  border-radius: 8px; border: 1px solid var(--border-dim);
  object-fit: cover;
}

.audit-msg-actions {
  display: flex; gap: 4px; margin-top: 4px; opacity: .7;
  transition: opacity .15s;
}
.audit-msg:hover .audit-msg-actions { opacity: 1; }
.audit-msg-action {
  font-size: 11px; padding: 2px 8px; border-radius: 4px;
  border: 1px solid var(--border-dim); background: transparent;
  color: var(--muted-hi); cursor: pointer;
}
.audit-msg-action:hover { background: var(--glass-input); color: var(--text); }

/* ── Multi-select для отправки в Telegram ──────────────────────────── */
.audit-msg-select {
  display: flex; align-items: flex-start; padding-top: 8px;
  flex-shrink: 0; opacity: .35; transition: opacity .15s; cursor: pointer;
}
.audit-msg:hover .audit-msg-select { opacity: 1; }
.audit-msg--selected .audit-msg-select { opacity: 1; }
.audit-msg-select input { width: 16px; height: 16px; cursor: pointer; accent-color: #5b8dee; }
.audit-msg--selected { background: rgba(91,141,238,.06); border-radius: 8px; padding: 4px; margin: -4px 0; }
.audit-msg--selected .audit-msg-content { border-left: 2px solid #5b8dee; padding-left: 10px; }

.audit-selection-bar {
  position: sticky; bottom: 0; z-index: 20;
  margin-top: 8px; padding: 10px 14px;
  background: rgba(20,15,40,.92); backdrop-filter: blur(10px);
  border: 1px solid #5b8dee; border-radius: 10px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  box-shadow: 0 4px 16px rgba(91,141,238,.20);
}
.audit-selection-bar .audit-selection-count { font-size: 13px; color: var(--text); }
.audit-selection-bar .audit-selection-count strong { color: #5b8dee; font-size: 15px; margin-left: 4px; }

.personas-list {
  display: flex; flex-direction: column; gap: 8px;
}
.persona-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--glass-input);
  border: 1px solid var(--border-dim); border-radius: 10px;
}
.persona-item-icon {
  font-size: 20px; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--glass-dark); border-radius: 8px; flex-shrink: 0;
}
.persona-item-name { font-size: 13px; font-weight: 600; color: var(--text); }
.persona-item-prompt {
  font-size: 11.5px; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.persona-item-body { flex: 1; min-width: 0; }
.persona-item-badge {
  font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: rgba(91,141,238,.16); color: #5b8dee;
}

/* ── Audit chat ─────────────────────────────────────────────────────── */
.audit-chat-history {
  display: flex; flex-direction: column; gap: 12px;
  max-height: 540px; overflow-y: auto;
  padding: 4px 2px;
  margin-bottom: 12px;
  scrollbar-width: thin;
}
.audit-chat-history:empty::before {
  content: "Задайте первый вопрос — диалог появится здесь.";
  display: block; color: var(--muted); font-size: 13px;
  padding: 20px; text-align: center; font-style: italic;
}
.audit-msg {
  display: flex; gap: 10px;
  animation: fadeMsg .25s ease;
}
@keyframes fadeMsg { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }
.audit-msg-avatar {
  flex-shrink: 0; width: 28px; height: 28px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600;
}
.audit-msg-user .audit-msg-avatar    { background: var(--accent-btn); color: #fff; }
.audit-msg-assistant .audit-msg-avatar { background: rgba(48,209,88,.18); color: #30d158; border: 1px solid rgba(48,209,88,.30); }
.audit-msg-content {
  flex: 1; min-width: 0;
  background: var(--glass-input);
  border: 1px solid var(--border-dim);
  border-radius: 14px; padding: 10px 14px;
  font-size: 13.5px; line-height: 1.55;
  color: var(--text);
  word-wrap: break-word;
}
.audit-msg-user .audit-msg-content { background: rgba(91,141,238,.12); border-color: rgba(91,141,238,.28); }
.audit-msg-content h2 { font-size: 14.5px; margin-top: 12px; margin-bottom: 6px; color: var(--text); font-weight: 700; }
.audit-msg-content h3 { font-size: 13.5px; margin-top: 10px; margin-bottom: 5px; color: var(--text2); font-weight: 600; }
.audit-msg-content table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 12px; }
.audit-msg-content table th, .audit-msg-content table td { padding: 6px 8px; border: 1px solid var(--border-dim); text-align: left; }
.audit-msg-content table th { background: var(--glass-dark); font-weight: 600; }
.audit-msg-content code { background: rgba(0,0,0,.18); padding: 1px 5px; border-radius: 4px; font-size: 12px; font-family: 'SF Mono', Menlo, monospace; }
.audit-msg-content pre { background: rgba(0,0,0,.18); padding: 8px 10px; border-radius: 6px; font-size: 12px; overflow-x: auto; margin: 6px 0; }
.audit-msg-content strong { color: var(--text); font-weight: 600; }

.audit-chat-input-wrap {
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--glass-input);
  border: 1px solid var(--border-std);
  border-radius: 14px;
  padding: 8px 10px;
  transition: border-color .15s, box-shadow .15s;
}
.audit-chat-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.audit-chat-input {
  flex: 1; min-width: 0;
  background: transparent !important;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  resize: vertical;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  min-height: 36px; max-height: 200px;
  padding: 6px 4px !important;
}
.audit-chat-input::placeholder { color: var(--muted); }
#audit-chat-send {
  flex-shrink: 0; align-self: flex-end;
  padding: 8px 18px; font-size: 13px;
}

.audit-chat-quick {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 10px; align-items: center;
}
.audit-chat-chip {
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 16px;
  background: var(--glass-input);
  border: 1px solid var(--border-std);
  color: var(--text2);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.audit-chat-chip:hover {
  background: var(--glass-hover);
  border-color: var(--accent);
  color: var(--text);
}

.audit-msg-thinking {
  display: inline-flex; gap: 4px; padding: 12px 14px;
}
.audit-msg-thinking span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted-hi);
  animation: dot 1.4s ease-in-out infinite;
}
.audit-msg-thinking span:nth-child(2) { animation-delay: .2s; }
.audit-msg-thinking span:nth-child(3) { animation-delay: .4s; }
@keyframes dot {
  0%, 60%, 100% { opacity: .3; transform: scale(.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* TopVisor positions card */
.audit-tv-row {
  display: flex; gap: 10px; align-items: center;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-dim);
  font-size: 12.5px;
}
.audit-tv-row:last-child { border-bottom: none; }
.audit-tv-pos {
  flex-shrink: 0; min-width: 28px;
  font-weight: 700; font-size: 14px;
  text-align: center;
  padding: 2px 5px; border-radius: 5px;
}
.audit-tv-row .audit-tv-kw { flex: 1; color: var(--text); }
.audit-tv-row .audit-tv-freq { color: var(--muted); font-size: 11px; min-width: 60px; text-align: right; }

