Improve this code significantly. Add features.

from flask import Flask, render_template_string, redirect, url_for, session, flash, request
from flask_sqlalchemy import SQLAlchemy
from flask_mail import Mail, Message
from werkzeug.security import generate_password_hash, check_password_hash
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, TextAreaField
from wtforms.validators import DataRequired, Length, EqualTo
import os
import secrets

app = Flask(__name__)
app.config['SECRET_KEY'] = 'your_secret_key'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['MAIL_SERVER'] = 'smtp.example.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = 'your_email@example.com'
app.config['MAIL_PASSWORD'] = 'your_password'
db = SQLAlchemy(app)
mail = Mail(app)

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(150), unique=True, nullable=False)
    password = db.Column(db.String(256), nullable=False)

class Item(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(150), nullable=False)
    description = db.Column(db.String(300), nullable=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

class RegistrationForm(FlaskForm):
    username = StringField('Username', validators=[DataRequired(), Length(min=3, max=150)])
    password = PasswordField('Password', validators=[DataRequired()])
    confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), EqualTo('password')])
    submit = SubmitField('Register')

class LoginForm(FlaskForm):
    username = StringField('Username', validators=[DataRequired()])
    password = PasswordField('Password', validators=[DataRequired()])
    submit = SubmitField('Login')

class ItemForm(FlaskForm):
    name = StringField('Item Name', validators=[DataRequired()])
    description = TextAreaField('Description')
    submit = SubmitField('Add Item')

class ResetPasswordForm(FlaskForm):
    username = StringField('Username', validators=[DataRequired()])
    new_password = PasswordField('New Password', validators=[DataRequired()])
    confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), EqualTo('new_password')])
    submit = SubmitField('Reset Password')

@app.route('/')
def home():
    items = Item.query.all()
    return render_template_string('''<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"><title>eBay Demand Assessment</title></head><body><nav class="navbar navbar-expand-lg navbar-light bg-light"><a class="navbar-brand" href="{{ url_for('home') }}">eBay Demand Assessment</a><div class="collapse navbar-collapse"><ul class="navbar-nav ml-auto">{% if 'username' in session %}<li class="nav-item"><a class="nav-link" href="{{ url_for('logout') }}">Logout</a></li><li class="nav-item"><a class="nav-link" href="{{ url_for('profile') }}">Profile</a></li>{% else %}<li class="nav-item"><a class="nav-link" href="{{ url_for('login') }}">Login</a></li><li class="nav-item"><a class="nav-link" href="{{ url_for('register') }}">Register</a></li>{% endif %}</ul></div></nav><div class="container mt-4">{% with messages = get_flashed_messages(with_categories=true) %}{% if messages %}{% for category, message in messages %}<div class="alert alert-{{ category }}">{{ message }}</div>{% endfor %}{% endif %}{% endwith %}<h1>Items</h1><form method="GET" action="{{ url_for('search_items') }}"><input type="text" name="search" placeholder="Search items"><button type="submit" class="btn btn-secondary">Search</button></form><ul class="list-group mb-4">{% for item in items %}<li class="list-group-item"><a href="{{ url_for('item_detail', item_id=item.id) }}">{{ item.name }}</a> <form method="POST" action="{{ url_for('delete_item', item_id=item.id) }}" style="display:inline;"><button type="submit" class="btn btn-danger btn-sm">Delete</button></form></li>{% endfor %}</ul><form method="POST" action="{{ url_for('add_item') }}"><input type="text" name="item_name" required placeholder="Item name"><textarea name="item_description" placeholder="Description"></textarea><button type="submit" class="btn btn-primary">List Item</button></form></div></body></html>''', items=items)

@app.route('/item/<int:item_id>')
def item_detail(item_id):
    item = Item.query.get_or_404(item_id)
    return render_template_string('''<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"><title>{{ item.name }}</title></head><body><div class="container mt-5"><h1>{{ item.name }}</h1><p>{{ item.description }}</p><a href="{{ url_for('home') }}" class="btn btn-secondary">Back</a></div></body></html>''', item=item)

@app.route('/register', methods=['GET', 'POST'])
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        if User.query.filter_by(username=form.username.data).first():
            flash('Username already exists.', 'danger')
            return redirect(url_for('register'))
        hashed_password = generate_password_hash(form.password.data)
        new_user = User(username=form.username.data, password=hashed_password)
        db.session.add(new_user)
        db.session.commit()
        flash('Registration successful! Please log in.', 'success')
        return redirect(url_for('login'))
    return render_template_string('''<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"><title>Register</title></head><body><div class="container mt-5"><h2>Register</h2><form method="POST">{{ form.hidden_tag() }}<div class="form-group">{{ form.username.label(class="form-label") }}{{ form.username(class="form-control", placeholder="Username") }}</div><div class="form-group">{{ form.password.label(class="form-label") }}{{ form.password(class="form-control", placeholder="Password") }}</div><div class="form-group">{{ form.confirm_password.label(class="form-label") }}{{ form.confirm_password(class="form-control", placeholder="Confirm Password") }}</div>{{ form.submit(class="btn btn-primary") }}</form></div></body></html>''', form=form)

@app.route('/login', methods=['GET', 'POST'])
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user and check_password_hash(user.password, form.password.data):
            session['username'] = user.username
            flash('Logged in successfully.', 'success')
            return redirect(url_for('home'))
        flash('Invalid credentials.', 'danger')
    return render_template_string('''<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"><title>Login</title></head><body><div class="container mt-5"><h2>Login</h2><form method="POST">{{ form.hidden_tag() }}<div class="form-group">{{ form.username.label(class="form-label") }}{{ form.username(class="form-control", placeholder="Username") }}</div><div class="form-group">{{ form.password.label(class="form-label") }}{{ form.password(class="form-control", placeholder="Password") }}</div>{{ form.submit(class="btn btn-primary") }}</form></div></body></html>''', form=form)

@app.route('/add_item', methods=['POST'])
def add_item():
    if 'username' not in session:
        flash('You must be logged in to