* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #f8f9fa;
  --bg-secondary: #ffffff;
  --bg-sidebar: #1a1a2e;
  --bg-sidebar-hover: #16213e;
  --bg-sidebar-active: #0f3460;
  --text-primary: #1a1a2e;
  --text-secondary: #6c757d;
  --text-sidebar: #e0e0e0;
  --text-sidebar-dim: #8892a0;
  --accent: #4361ee;
  --accent-hover: #3a56d4;
  --user-bubble: #4361ee;
  --user-text: #ffffff;
  --assistant-bubble: #ffffff;
  --assistant-text: #1a1a2e;
  --border: #e9ecef;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --radius: 12px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Боковая панель */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-header h2 {
  color: var(--text-sidebar);
  font-size: 16px;
  font-weight: 600;
}

.btn-new-chat {
  background: var(--accent);
  color: white;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-new-chat:hover {
  background: var(--accent-hover);
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conversation-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-sidebar-dim);
  font-size: 13px;
  transition: all 0.15s;
  margin-bottom: 2px;
  position: relative;
}

.conversation-item:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-sidebar);
}

.conversation-item.active {
  background: var(--bg-sidebar-active);
  color: var(--text-sidebar);
}

.conversation-item .conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item .btn-delete {
  opacity: 0;
  background: none;
  border: none;
  color: #ff6b6b;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: opacity 0.15s;
}

.conversation-item:hover .btn-delete {
  opacity: 1;
}

/* Основная область */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.btn-menu {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

.btn-menu:hover {
  background: var(--border);
}

.chat-title h1 {
  font-size: 16px;
  font-weight: 600;
}

.chat-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Сообщения */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  gap: 12px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: var(--accent);
  color: white;
}

.message.assistant .message-avatar {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
}

.message-content {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.6;
  max-width: 85%;
}

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

.message.assistant .message-content {
  background: var(--assistant-bubble);
  color: var(--assistant-text);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}

.message-content p {
  margin-bottom: 8px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content strong {
  font-weight: 600;
}

.message-content em {
  font-style: italic;
}

.message-content ul, .message-content ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-content li {
  margin-bottom: 4px;
}

.message-content h1, .message-content h2, .message-content h3 {
  margin: 12px 0 6px;
  font-weight: 600;
}

.message-content h1 { font-size: 1.3em; }
.message-content h2 { font-size: 1.15em; }
.message-content h3 { font-size: 1.05em; }

.message-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.message-content code {
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

.message-content pre {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 12px 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-content pre code {
  background: none;
  padding: 0;
  color: inherit;
}

/* Индикатор набора */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}

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

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

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Экран приветствия */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  margin: auto;
  max-width: 600px;
}

.welcome-icon {
  font-size: 48px;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-screen h2 {
  font-size: 22px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.welcome-screen p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 14px;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.quick-action {
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  text-align: left;
  transition: all 0.2s;
  font-family: inherit;
}

.quick-action:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(67, 97, 238, 0.15);
}

/* Область ввода */
.input-area {
  padding: 12px 20px 16px;
  background: var(--bg-primary);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 800px;
  margin: 0 auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}

textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  background: transparent;
  max-height: 150px;
  padding: 4px 0;
}

textarea::placeholder {
  color: var(--text-secondary);
}

.btn-send {
  background: var(--accent);
  color: white;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-send:hover {
  background: var(--accent-hover);
}

.btn-send:disabled {
  background: var(--border);
  cursor: not-allowed;
}

.input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 6px;
  opacity: 0.7;
}

/* Мобильная адаптация */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
  }

  .btn-menu {
    display: flex;
  }

  .quick-actions {
    grid-template-columns: 1fr;
  }

  .message-content {
    max-width: 90%;
  }
}

/* Оверлей при открытом меню */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
}

.sidebar-overlay.active {
  display: block;
}

/* Скроллбар */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

.conversations-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
}
