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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: #0a0a0a;
  color: #e0e0e0;
  min-height: 100vh;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.header {
  background: #0f0f0f;
  color: #e0e0e0;
  padding: 20px 24px;
  border-bottom: 1px solid #2a2a2a;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header h1 {
  font-size: 20px;
  margin-bottom: 2px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: #00ff88;
}

.subtitle {
  font-size: 12px;
  color: #666;
  font-weight: 400;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: transparent;
  color: #555;
  border: 1px solid #222;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.new-chat-btn:hover {
  background: #111;
  color: #00ff88;
  border-color: #00ff8844;
}

.back-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  color: #555;
  border: 1px solid #222;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
  transition: all 0.15s;
}

.back-link:hover {
  background: #111;
  color: #00ff88;
  border-color: #00ff8844;
}

.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #0a0a0a;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 85%;
  padding: 14px 18px;
  border-radius: 8px;
  line-height: 1.5;
  animation: fadeIn 0.2s ease;
}

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

.message.user {
  align-self: flex-end;
  background: #00ff88;
  color: #0a0a0a;
  border-bottom-right-radius: 2px;
  font-weight: 500;
}

.message.assistant {
  align-self: flex-start;
  background: #1a1a1a;
  color: #d0d0d0;
  border-bottom-left-radius: 2px;
  border: 1px solid #2a2a2a;
}

.message.welcome {
  align-self: center;
  background: #151515;
  border: 1px solid #2a2a2a;
  color: #777;
  text-align: center;
  max-width: 85%;
}

.message.error {
  background: #1a0f0f;
  color: #ff4444;
  border: 1px solid #3a1515;
}

.message p {
  margin-bottom: 6px;
  font-size: 14px;
}

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

.message ul {
  margin-left: 16px;
  margin-bottom: 6px;
  font-size: 14px;
}

.message ol {
  margin-left: 16px;
  margin-bottom: 6px;
  font-size: 14px;
}

.markdown-body {
  font-size: 14px;
  line-height: 1.6;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin-top: 12px;
  margin-bottom: 6px;
  font-weight: 600;
  color: #e0e0e0;
}

.markdown-body h2 {
  font-size: 16px;
}

.markdown-body h3 {
  font-size: 15px;
}

.markdown-body p {
  margin-bottom: 8px;
}

.markdown-body p:last-child {
  margin-bottom: 0;
}

.markdown-body strong {
  font-weight: 600;
  color: #00ff88;
}

.markdown-body ul,
.markdown-body ol {
  margin-left: 20px;
  margin-bottom: 8px;
}

.markdown-body li {
  margin-bottom: 4px;
}

.markdown-body code {
  background: #1a1a1a;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 13px;
  color: #00ff88;
}

.markdown-body pre {
  background: #0f0f0f;
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin-bottom: 8px;
  font-size: 13px;
  border: 1px solid #1a1a1a;
}

.markdown-body pre code {
  background: none;
  padding: 0;
  color: #c0c0c0;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid #1a1a1a;
  margin: 10px 0;
}

.source-count {
  font-size: 11px;
  color: #333;
  margin-top: 10px;
  font-style: italic;
}

.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  color: #555;
  font-size: 13px;
}

.loading.hidden {
  display: none;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #1a1a1a;
  border-top-color: #00ff88;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.input-area {
  padding: 16px 20px;
  background: #0f0f0f;
  border-top: 1px solid #2a2a2a;
}

#chat-form {
  display: flex;
  gap: 8px;
}

#message-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  transition: all 0.15s;
  background: #151515;
  color: #e0e0e0;
}

#message-input:focus {
  border-color: #00ff88;
  background: #1a1a1a;
}

#message-input::placeholder {
  color: #555;
}

#send-btn {
  padding: 12px 20px;
  background: #00ff88;
  color: #0a0a0a;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

#send-btn:hover {
  background: #33ffaa;
}

#send-btn:active {
  background: #00cc6a;
}

#send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  background: #00ff88;
}

.char-counter {
  text-align: right;
  font-size: 10px;
  color: #333;
  margin-top: 4px;
}

@media (max-width: 600px) {
  .header h1 {
    font-size: 18px;
  }

  .header {
    padding: 16px;
  }

  .message {
    max-width: 90%;
    padding: 12px 14px;
  }

  .chat-container {
    padding: 12px;
  }

  #chat-form {
    flex-direction: column;
    gap: 6px;
  }

  #send-btn {
    width: 100%;
    justify-content: center;
    padding: 12px;
  }

  .input-area {
    padding: 12px;
  }
}
