/* === Общие стили === */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f1117;
  --bg-surface: #1a1d27;
  --bg-card: #232734;
  --accent: #4CAF50;
  --accent-hover: #66BB6A;
  --text: #e4e6eb;
  --text-muted: #8b8fa3;
  --border: #2d3142;
  --error: #ef5350;
  --success: #4CAF50;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* === Чат === */
.app {
  max-width: 800px;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  padding: 20px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-size: 1.4rem;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.back-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.85rem;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  max-width: 85%;
}

.message.user {
  align-self: flex-end;
}

.message.bot {
  align-self: flex-start;
}

.message-content {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.5;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.user .message-content {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.bot .message-content {
  background: var(--bg-card);
  border-bottom-left-radius: 4px;
}

.message .sources {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.message .sources a {
  font-size: 0.8rem;
}

.message .source-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  margin-top: 6px;
}

.source-badge.database { background: #1b5e20; color: #a5d6a7; }
.source-badge.web { background: #0d47a1; color: #90caf9; }

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-8px); }
}

/* === Ввод === */
.input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.input-area form {
  display: flex;
  gap: 8px;
}

.input-area input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.input-area input:focus {
  border-color: var(--accent);
}

.input-area button {
  padding: 12px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.input-area button:hover {
  background: var(--accent-hover);
}

.input-area button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === Админ === */
.admin-app {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-top: 20px;
}

.card h2 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

/* Статистика */
.stats {
  display: flex;
  gap: 24px;
  justify-content: center;
}

.stat-item {
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Формы загрузки */
.learn-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.learn-form input,
.learn-form textarea {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
  resize: vertical;
}

.learn-form input:focus,
.learn-form textarea:focus {
  border-color: var(--accent);
}

.learn-form button {
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}

.learn-form button:hover { background: var(--accent-hover); }
.learn-form button:disabled { opacity: 0.5; cursor: not-allowed; }

.result-message {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  display: none;
}

.result-message.success {
  display: block;
  background: #1b5e20;
  color: #a5d6a7;
}

.result-message.error {
  display: block;
  background: #b71c1c;
  color: #ef9a9a;
}

/* Список источников */
.sources-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.source-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: 8px;
  gap: 12px;
}

.source-info {
  flex: 1;
  min-width: 0;
}

.source-info strong {
  display: block;
  margin-bottom: 4px;
}

.source-url {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 8px;
  border-radius: 6px;
  transition: background 0.2s;
}

.delete-btn:hover {
  background: rgba(239, 83, 80, 0.2);
}

.loading, .empty, .error {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
}

/* === Мобильная адаптация === */
@media (max-width: 600px) {
  .header h1 { font-size: 1.2rem; }
  .message { max-width: 95%; }
  .stats { flex-direction: column; gap: 12px; }
  .stat-value { font-size: 1.5rem; }
}
