/**
 * Chat styles — экран чата (ROADMAP 3.3)
 * Mobile-first, Telegram-like bubbles
 */

/* --- Sidebar --- */

.sidebar-header {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  margin-right: auto;
  min-width: 0;
}

.sidebar-brand h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.sidebar-brand .balance-badge {
  font-size: 11px;
  padding: 0;
  line-height: 1.2;
  text-align: left;
}

.sidebar-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.sidebar-actions button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}

.sidebar-actions button:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.sidebar-actions button svg {
  width: 20px;
  height: 20px;
}

.sidebar-actions button {
  position: relative;
}

.access-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  background: var(--danger, #e53e3e);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}

/* Заявки на доступ */
.access-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.access-card:last-child {
  border-bottom: none;
}

.access-info {
  flex: 1;
}

.access-user {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 14px;
}

.access-agent {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 2px;
}

.access-agent svg {
  width: 14px;
  height: 14px;
}

.access-date {
  color: var(--text-tertiary);
  font-size: 12px;
  margin-top: 2px;
}

.access-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-approve, .btn-deny {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.15s;
}

.btn-approve {
  background: var(--success, #38a169);
  color: #fff;
  border-color: var(--success, #38a169);
}

.btn-approve:hover {
  opacity: 0.9;
}

.btn-approve svg {
  width: 14px;
  height: 14px;
}

.btn-deny {
  background: transparent;
  color: var(--danger, #e53e3e);
  border-color: var(--danger, #e53e3e);
}

.btn-deny:hover {
  background: var(--danger, #e53e3e);
  color: #fff;
}

.btn-deny svg {
  width: 14px;
  height: 14px;
}

/* Каталог агентов */
.catalog-section {
  margin-bottom: 16px;
}

.catalog-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 8px 0 4px;
  letter-spacing: 0.5px;
}

.catalog-agent {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.catalog-agent:last-child {
  border-bottom: none;
}

.catalog-agent-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.catalog-agent-icon svg {
  width: 18px;
  height: 18px;
}

.catalog-agent-info {
  flex: 1;
  min-width: 0;
}

.catalog-agent-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

.catalog-agent-desc {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.catalog-agent-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.catalog-agent-status.pending {
  background: var(--warning-bg, #fff3cd);
  color: var(--warning, #f59e0b);
}

.catalog-agent-status.denied {
  background: var(--danger-bg, #fee);
  color: var(--danger, #e53e3e);
}

.catalog-agent-btn {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  flex-shrink: 0;
}

.catalog-agent-btn.primary {
  background: var(--accent);
  color: #fff;
}

.catalog-agent-btn.primary:hover {
  opacity: 0.9;
}

.catalog-agent-btn.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.catalog-agent-btn.secondary:hover {
  background: var(--accent);
  color: #fff;
}

/* Профиль */
.profile-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.profile-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.profile-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
  flex: 1;
  min-width: 0;
}

.profile-input:focus {
  border-color: var(--accent);
}

.profile-btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: var(--accent);
  color: #fff;
  white-space: nowrap;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.profile-btn:hover { opacity: 0.9; }
.profile-btn:disabled { opacity: 0.5; cursor: default; }

.profile-btn-outline {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
  white-space: nowrap;
  transition: all 0.15s;
  flex-shrink: 0;
}

.profile-btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Поиск */
.sidebar-search {
  padding: 8px 16px;
  flex-shrink: 0;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg-secondary);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
}

.sidebar-search input:focus {
  border-color: var(--accent);
}

.sidebar-search input::placeholder {
  color: var(--text-secondary);
}

/* Список стримов */
.stream-list {
  flex: 1;
  overflow-y: auto;
}

.stream-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
}

.stream-item:hover {
  background: var(--sidebar-hover);
}

.stream-item.active {
  background: var(--sidebar-active);
}

.stream-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  flex-shrink: 0;
}

.stream-info {
  flex: 1;
  overflow: hidden;
}

.stream-info-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.stream-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stream-time {
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
  margin-left: 8px;
}

.stream-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 1px;
}

.stream-agent-name {
  font-size: 11px;
  color: var(--accent);
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stream-cost {
  font-size: 10px;
  color: var(--text-secondary);
  opacity: 0.6;
  white-space: nowrap;
  margin-left: auto;
}

.stream-last-msg {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* Кнопка удаления стрима */
.stream-delete-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}
.stream-delete-btn:hover {
  background: var(--danger, #DE350B);
  color: #fff;
}
.stream-item:hover .stream-delete-btn {
  display: flex;
}

/* Пустой sidebar */
.stream-list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-secondary);
  text-align: center;
  flex: 1;
}

.stream-list-empty svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.stream-list-empty p {
  font-size: 14px;
  margin-top: 8px;
}

/* --- Chat area --- */

.chat-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header .btn-back {
  display: flex;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text-secondary);
}

.chat-header .btn-back:hover {
  background: var(--bg-secondary);
}

.chat-header .btn-back svg {
  width: 20px;
  height: 20px;
}

/* Планшет+ — скрываем кнопку "назад" */
@media (min-width: 768px) {
  .chat-header .btn-back { display: none; }
}

.chat-header-info {
  flex: 1;
  overflow: hidden;
  cursor: pointer;
}

.chat-header-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-sub {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Пустое состояние чата (десктоп, ничего не выбрано) */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  text-align: center;
  padding: 40px;
}

.chat-empty svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.3;
}

.chat-empty p {
  font-size: 15px;
}

/* Сообщения */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg {
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Markdown внутри сообщений */
.msg p { margin: 0 0 8px 0; }
.msg p:last-child { margin-bottom: 0; }
.msg code {
  background: #2d2d2d;
  color: #e6edf3;
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
}
.msg pre {
  background: #0d1117;
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  border: 1px solid #30363d;
}
.msg pre code {
  background: none;
  padding: 0;
  color: #e6edf3;
  font-size: 13px;
  line-height: 1.5;
}
.msg ul, .msg ol { padding-left: 18px; }

/* User bubble (справа) */
.msg.user {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
}

.msg.user code { background: rgba(0,0,0,0.3); color: #fff; }
.msg.user pre { background: #0d1117; border-color: #30363d; }

/* Agent bubble (слева) */
.msg.agent {
  background: var(--bubble-agent);
  color: var(--bubble-agent-text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Sender name (для мультиюзер / агентов) */
.msg-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

/* Other user bubble */
.msg.other-user {
  background: var(--bubble-other);
  color: var(--bubble-other-text);
  border-bottom-left-radius: 4px;
}

/* System message */
.msg.system {
  align-self: center;
  background: var(--bubble-system-bg);
  color: var(--bubble-system-text);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 12px;
  max-width: 90%;
}

/* Tool use message — эталон Agent_manager */
.msg-tool {
  background: var(--bg-secondary, #F1F5F9);
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 8px;
  padding: 0;
  font-size: 13px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}
.msg-tool-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  color: var(--text-secondary, #6B778C);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.msg-tool-header:hover {
  background: rgba(0,0,0,0.02);
}
.msg-tool-icon {
  font-size: 16px;
  flex-shrink: 0;
  opacity: 0.6;
}
.msg-tool-label {
  font-weight: 400;
  color: var(--text-secondary, #6B778C);
}
.msg-tool-name {
  font-weight: 600;
  color: var(--accent, #0066FF);
}
.msg-tool-hint {
  color: var(--text-secondary, #94A3B8);
  font-size: 12px;
  font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
  margin-left: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.msg-tool-time {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-secondary, #94A3B8);
  flex-shrink: 0;
}
.msg-tool-content {
  border-top: 1px solid var(--border, #E2E8F0);
  padding: 10px 14px;
  background: var(--bg-primary, #FFFFFF);
}
.msg-tool-content pre {
  margin: 0;
  padding: 8px 12px;
  background: rgba(0,0,0,0.03);
  border-radius: 6px;
  font-size: 12px;
  font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
  line-height: 1.5;
  overflow-x: auto;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary, #1E293B);
}
.msg-tool-result {
  border-top: 1px solid var(--border, #E2E8F0);
  padding: 10px 14px;
  background: rgba(0,136,90,0.04);
}
.msg-tool-result.tool-error {
  background: rgba(222,53,11,0.06);
}
.msg-tool-result pre {
  margin: 0;
  padding: 8px 12px;
  font-size: 12px;
  font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary, #6B778C);
}
.msg-tool-result.tool-error pre {
  color: var(--danger, #DE350B);
}
.msg-tool-result-standalone {
  background: var(--bg-secondary, #F1F5F9);
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  width: 100%;
  max-width: 100%;
}
.msg-tool-result-standalone pre {
  margin: 0;
  font-size: 12px;
  font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Thinking message */
.msg-thinking {
  background: rgba(255,139,0,0.05);
  border: 1px dashed rgba(255,139,0,0.25);
  border-radius: 8px;
  padding: 0;
  font-size: 13px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}
.msg-thinking-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-weight: 500;
  color: var(--warning, #FF8B00);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.msg-thinking-header:hover {
  background: rgba(255,139,0,0.03);
}
.msg-thinking-icon {
  font-size: 16px;
}
.msg-thinking-content {
  border-top: 1px dashed rgba(255,139,0,0.2);
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary, #6B778C);
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* Display grid (reuses tool switch styles) */
.sf-display-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
}

/* === Статус-панель обработки === */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: linear-gradient(90deg, #FF9800 0%, #FFB74D 50%, #FF9800 100%);
  background-size: 200% 100%;
  animation: statusShimmer 2.5s ease infinite;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
  min-height: 42px;
  gap: 12px;
  box-shadow: 0 -2px 8px rgba(255,152,0,0.2);
}
@keyframes statusShimmer {
  0% { background-position: 100% 0; }
  50% { background-position: 0 0; }
  100% { background-position: 100% 0; }
}
.status-bar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.status-bar-spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-bar-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-bar-abort {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.4);
  color: #fff;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.status-bar-abort:hover {
  background: rgba(255,255,255,0.35);
}

/* === Кнопка прокрутки вниз (внутри #chatView) === */
#chatView { position: relative; }
.scroll-down-btn {
  position: absolute;
  bottom: 120px;
  right: 20px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent, #0066FF);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  z-index: 10;
  transition: transform 0.15s, opacity 0.15s;
}
.scroll-down-btn:hover {
  transform: scale(1.1);
}

/* === Кнопка "к началу сообщения" для длинных баблов === */
.msg-scroll-top-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 4px 10px;
  background: rgba(0,102,255,0.08);
  border: 1px solid rgba(0,102,255,0.2);
  border-radius: 12px;
  color: var(--accent, #0066FF);
  font-size: 11px;
  cursor: pointer;
  width: fit-content;
}
.msg-scroll-top-btn:hover {
  background: rgba(0,102,255,0.15);
}
.msg-scroll-top-btn svg {
  width: 12px;
  height: 12px;
}

/* === Метка времени и отправитель над сообщением === */
.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px 0 4px;
  font-size: 11px;
  line-height: 1;
  color: var(--text-secondary, #6B778C);
}
.msg-meta-sender {
  font-weight: 600;
  color: var(--text-primary, #1E293B);
  font-size: 12px;
}
.msg-meta-time {
  color: var(--text-secondary, #94A3B8);
  font-size: 11px;
}

/* === Кнопки на блоках кода === */
.code-block-wrapper {
  position: relative;
}
.code-block-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}
.code-block-wrapper:hover .code-block-actions {
  opacity: 1;
}
.code-btn {
  background: none;
  border: none;
  color: #8b949e;
  padding: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 0.12s, background 0.12s;
}
.code-btn:hover {
  color: #e6edf3;
  background: rgba(255,255,255,0.1);
}
.code-btn.copied {
  color: #3fb950;
}
.code-btn svg {
  width: 16px;
  height: 16px;
}

/* === Fullscreen модалка для кода === */
.code-fullscreen-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #1a1a2e;
  z-index: 10000;
  display: flex;
  flex-direction: column;
}
.code-fullscreen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: #16213e;
  border-bottom: 1px solid #2a2a4a;
  flex-shrink: 0;
}
.code-fullscreen-header span {
  color: #8be9fd;
  font-size: 14px;
  font-weight: 600;
  font-family: 'SF Mono', 'Consolas', monospace;
  margin-right: auto;
}
.code-fullscreen-btn {
  background: #2a2a4a;
  border: 1px solid #3a3a5a;
  color: #e2e8f0;
  border-radius: 6px;
  padding: 7px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
}
.code-fullscreen-btn:hover {
  background: #3a3a5a;
}
.code-fullscreen-btn.btn-copy {
  color: #8be9fd;
}
.code-fullscreen-btn.btn-copy.copied {
  background: #00875A;
  color: #fff;
  border-color: #00875A;
}
.code-fullscreen-btn.btn-close {
  color: #ff6b6b;
  border-color: #ff6b6b44;
}
.code-fullscreen-btn.btn-close:hover {
  background: #ff6b6b22;
}
.code-fullscreen-body {
  flex: 1;
  overflow: auto;
  padding: 20px 24px;
  background: #0d1117;
}
.code-fullscreen-body pre {
  margin: 0;
  color: #e6edf3;
  font-size: 14px;
  line-height: 1.6;
  font-family: 'SF Mono', 'Consolas', 'Monaco', 'Courier New', monospace;
  white-space: pre;
  tab-size: 2;
}

/* === HTML Preview (iframe) === */
.html-preview-wrapper {
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 8px;
  overflow: hidden;
  margin: 8px 0;
}
.html-preview-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--bg-secondary, #F1F5F9);
  font-size: 12px;
  color: var(--text-secondary, #6B778C);
  border-bottom: 1px solid var(--border, #E2E8F0);
}
.html-preview-iframe {
  width: 100%;
  min-height: 200px;
  border: none;
  background: #fff;
}

/* === Кнопка скачивания файла [FILE:...] === */
.file-download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-secondary, #F1F5F9);
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 6px;
  color: var(--accent, #0066FF);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  margin: 4px 0;
}
.file-download-btn:hover {
  background: var(--primary-light, #E6F0FF);
}

/* Input bar */
.input-bar {
  padding: 8px 16px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
}

.input-bar textarea {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 16px; /* vision.md: минимум 16px для iOS */
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  outline: none;
  max-height: 120px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: border-color 0.15s;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-all;
}

.input-bar textarea:focus {
  border-color: var(--accent);
}

.input-bar textarea::placeholder {
  color: var(--text-secondary);
}

.input-bar .btn-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  flex-shrink: 0;
  transition: background 0.15s;
}

.input-bar .btn-send:hover {
  background: var(--accent-hover);
}

.input-bar .btn-send svg {
  width: 20px;
  height: 20px;
}

.input-bar .btn-send.btn-abort {
  background: var(--danger, #DE350B);
}

.input-bar .btn-send.btn-abort:hover {
  background: #bf2e09;
}

/* Typing indicator */
.typing-indicator {
  align-self: flex-start;
  padding: 8px 14px;
  background: var(--bubble-agent);
  border: 1px solid var(--border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  display: none;
}

.typing-indicator.active {
  display: block;
}

/* Status bar (online/offline) */
.status-badge {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  margin-right: 4px;
}

.status-badge.online {
  background: var(--success);
}

/* --- Active UI компоненты в сообщениях агента (3.5) --- */

.active-ui {
  margin-top: 8px;
}

/* Кнопки */
.active-ui-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.active-ui-buttons .aui-btn {
  padding: 8px 16px;
  border: 1px solid var(--accent);
  border-radius: 18px;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  min-height: 36px;
}

.active-ui-buttons .aui-btn:hover {
  background: var(--accent);
  color: #fff;
}

.active-ui-buttons .aui-btn.selected {
  background: var(--accent);
  color: #fff;
  pointer-events: none;
  opacity: 0.8;
}

.active-ui-buttons .aui-btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Select */
.active-ui-select {
  margin-top: 8px;
}

.active-ui-select select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
}

.active-ui-select select:focus {
  border-color: var(--accent);
}

.active-ui-select .aui-select-confirm {
  margin-top: 6px;
  padding: 6px 14px;
  border: none;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

/* Checkboxes */
.active-ui-checkboxes {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.active-ui-checkboxes label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px 0;
}

.active-ui-checkboxes input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.active-ui-checkboxes .aui-check-confirm {
  margin-top: 6px;
  padding: 6px 14px;
  border: none;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

/* Confirm dialog */
.active-ui-confirm {
  margin-top: 8px;
}

.active-ui-confirm .aui-confirm-text {
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.active-ui-confirm .aui-confirm-actions {
  display: flex;
  gap: 6px;
}

.active-ui-confirm .aui-confirm-yes {
  padding: 8px 20px;
  border: none;
  border-radius: 18px;
  background: var(--danger);
  color: #fff;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}

.active-ui-confirm .aui-confirm-no {
  padding: 8px 20px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}

/* Disabled state после ответа */
.active-ui.responded {
  opacity: 0.6;
  pointer-events: none;
}

/* --- Файлы в чате (3.6) --- */

.msg-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-top: 6px;
  cursor: pointer;
  transition: background 0.15s;
  max-width: 280px;
}

.msg-file:hover {
  background: var(--bg-tertiary);
}

.msg-file-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.msg-file-info {
  flex: 1;
  overflow: hidden;
}

.msg-file-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-file-size {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Image preview */
.msg-image {
  margin-top: 6px;
  border-radius: 10px;
  overflow: hidden;
  max-width: 300px;
}

.msg-image img {
  width: 100%;
  display: block;
  border-radius: 10px;
  cursor: pointer;
}

/* Attached files preview (перед отправкой) */
.attached-files {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
}

.attached-files.active {
  display: flex;
}

.file-preview {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 180px;
}

.file-preview .file-thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.file-preview .file-thumb-icon {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.file-preview .file-meta {
  flex: 1;
  min-width: 0;
}

.file-preview .file-meta-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-preview .file-meta-size {
  font-size: 11px;
  color: var(--text-secondary);
}

.file-preview .file-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: 2px solid var(--bg-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  min-height: 20px;
  min-width: 20px;
  padding: 0;
}

.file-preview .file-remove:hover {
  background: #c62828;
}

/* Upload area */
.input-bar .btn-attach {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.input-bar .btn-attach:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.input-bar .btn-attach svg {
  width: 20px;
  height: 20px;
}

/* Drag overlay */
.drag-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 102, 255, 0.08);
  border: 3px dashed var(--accent);
  z-index: 99;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--accent);
  font-weight: 500;
}

.drag-overlay.active {
  display: flex;
}

/* Upload progress */
.upload-progress {
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: none;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

.upload-progress.active {
  display: flex;
}

.upload-progress-bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.upload-progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.2s;
  width: 0%;
}

/* --- Reply-to-message (3.7) --- */

.reply-preview {
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: none;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.reply-preview.active {
  display: flex;
}

.reply-preview-bar {
  width: 3px;
  height: 32px;
  background: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
}

.reply-preview-content {
  flex: 1;
  overflow: hidden;
}

.reply-preview-sender {
  font-weight: 600;
  color: var(--accent);
  font-size: 12px;
}

.reply-preview-text {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-preview-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--text-secondary);
  flex-shrink: 0;
  cursor: pointer;
}

.reply-preview-close:hover {
  background: var(--bg-tertiary);
}

/* Quote in message */
.msg-quote {
  padding: 4px 8px;
  border-left: 3px solid var(--accent);
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.04);
  border-radius: 0 6px 6px 0;
}

[data-theme="dark"] .msg-quote {
  background: rgba(255, 255, 255, 0.05);
}

/* Quote inside user bubble — white bg for contrast */
.msg.user .msg-quote {
  background: rgba(255, 255, 255, 0.85);
  border-left-color: #0052CC;
  color: #6B778C;
}

[data-theme="dark"] .msg.user .msg-quote {
  background: rgba(255, 255, 255, 0.9);
  color: #6B778C;
}

.msg.user .msg-quote-sender {
  color: #0052CC;
}

.msg-quote-sender {
  font-weight: 600;
  color: var(--accent);
}

/* Reply button on hover */
.msg-wrapper {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 100%;
  gap: 2px;
}

/* User messages — справа */
.msg-wrapper.wrapper-user {
  align-self: flex-end;
  align-items: flex-end;
}

/* Agent / other — слева */
.msg-wrapper.wrapper-left {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-wrapper .msg {
  min-width: 0; /* позволяет shrink для длинного текста */
}

.msg-actions {
  opacity: 0;
  transition: opacity 0.15s;
  flex-shrink: 0;
  padding-top: 4px;
}

.msg-wrapper:hover .msg-actions {
  opacity: 1;
}

.msg-actions button {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  min-height: 28px;
  min-width: 28px;
}

.msg-actions button:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* --- Voice recording (Phase 6) — professional inline UI --- */

/* Mic button — обычное состояние */
.input-bar .btn-mic {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: color 0.2s, background 0.2s;
}

.input-bar .btn-mic:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.input-bar .btn-mic svg {
  width: 20px;
  height: 20px;
}

/* Mic button — во время записи: красная пульсация + иконка stop */
.input-bar.recording .btn-mic {
  color: #fff;
  background: var(--danger);
  animation: mic-pulse 1.5s ease-in-out infinite;
}

.input-bar.recording .btn-mic:hover {
  background: #c62828;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(222, 53, 11, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(222, 53, 11, 0); }
}

/* Voice-rec — inline блок, скрыт по умолчанию, показан при recording */
.voice-rec {
  display: none;
  flex: 1;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--danger);
  border-radius: 20px;
}

.input-bar.recording .voice-rec {
  display: flex;
}

/* При записи скрываем textarea и attach */
.input-bar.recording #msgInput,
.input-bar.recording .btn-attach {
  display: none;
}

/* Кнопка отмены записи (X) */
.voice-rec-cancel {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.voice-rec-cancel:hover {
  background: rgba(222, 53, 11, 0.1);
  color: var(--danger);
}

/* Визуализация waveform */
.voice-rec-viz {
  flex: 1;
  height: 36px;
  min-width: 0;
  overflow: hidden;
}

.voice-rec-viz canvas {
  display: block;
  width: 100%;
  height: 36px;
}

/* Таймер записи */
.voice-rec-time {
  font-size: 13px;
  font-weight: 600;
  color: var(--danger);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  text-align: right;
  flex-shrink: 0;
}

/* --- Recognizing state: графическая анимация --- */

/* Скрываем textarea и attach при распознавании */
.input-bar.recognizing #msgInput,
.input-bar.recognizing .btn-attach {
  display: none;
}

/* Показываем блок распознавания */
.voice-recog {
  display: none;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 0;
  height: 42px;
  padding: 0 16px;
  background: linear-gradient(135deg, #0066ff0f, #0066ff1f);
  border: 1px solid #0066ff40;
  border-radius: 20px;
  overflow: hidden;
}

.input-bar.recognizing .voice-recog {
  display: flex;
}

.voice-recog-cancel {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: var(--text-secondary);
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  transition: background 0.15s, color 0.15s;
}

.voice-recog-cancel:hover {
  background: rgba(222, 53, 11, 0.15);
  color: var(--danger);
}

/* Mic button: фиолетовый спиннер при распознавании */
.input-bar.recognizing .btn-mic {
  color: var(--accent);
  animation: recog-spin 2s linear infinite;
  pointer-events: none;
}

@keyframes recog-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Пульсирующие точки — как эквалайзер */
.voice-recog-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 24px;
}

.voice-recog-dots span {
  display: block;
  width: 4px;
  border-radius: 2px;
  background: var(--accent);
  animation: recog-bar 1.2s ease-in-out infinite;
}

.voice-recog-dots span:nth-child(1) { animation-delay: 0s;    height: 8px; }
.voice-recog-dots span:nth-child(2) { animation-delay: 0.15s; height: 14px; }
.voice-recog-dots span:nth-child(3) { animation-delay: 0.3s;  height: 20px; }
.voice-recog-dots span:nth-child(4) { animation-delay: 0.45s; height: 14px; }
.voice-recog-dots span:nth-child(5) { animation-delay: 0.6s;  height: 8px; }

@keyframes recog-bar {
  0%, 100% {
    transform: scaleY(0.4);
    opacity: 0.4;
  }
  50% {
    transform: scaleY(1);
    opacity: 1;
  }
}

/* Надпись "Распознавание" */
.voice-recog-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.voice-recog-label::after {
  content: '';
  animation: recog-ellipsis 1.5s steps(3, end) infinite;
}

@keyframes recog-ellipsis {
  0%   { content: ''; }
  33%  { content: '.'; }
  66%  { content: '..'; }
  100% { content: '...'; }
}

/* TTS play button in agent messages */
.msg-tts-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  margin-top: 4px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
  padding: 0;
}

.msg-tts-btn:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.msg-tts-btn svg {
  width: 16px;
  height: 16px;
}

.msg-tts-btn.playing {
  color: var(--accent);
  background: var(--accent-light);
}

/* Settings toggle (TTS on/off) */
.settings-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
