<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Dashboard - ChatBot</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Inter', sans-serif;
        }

        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }

        .dashboard-container {
            max-width: 1200px;
            margin: 0 auto;
        }

        .header {
            background: white;
            padding: 20px 30px;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            margin-bottom: 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .welcome-message {
            color: #333;
        }

        .welcome-message h1 {
            font-size: 28px;
            font-weight: 600;
            margin-bottom: 5px;
        }

        .welcome-message p {
            color: #666;
            font-size: 16px;
        }

        .user-actions {
            display: flex;
            gap: 15px;
            align-items: center;
        }

        .user-info {
            background: #f8f9fa;
            padding: 10px 15px;
            border-radius: 10px;
            font-size: 14px;
            color: #555;
        }

        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            transition: all 0.3s ease;
        }

        .btn-primary {
            background: #667eea;
            color: white;
        }

        .btn-primary:hover {
            background: #5a67d8;
            transform: translateY(-1px);
        }

        .btn-secondary {
            background: #e2e8f0;
            color: #4a5568;
        }

        .btn-secondary:hover {
            background: #cbd5e0;
        }

        .btn-danger {
            background: #e53e3e;
            color: white;
        }

        .btn-danger:hover {
            background: #c53030;
            transform: translateY(-1px);
        }

        .dashboard-content {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 30px;
            margin-bottom: 30px;
        }

        .card {
            background: white;
            padding: 25px;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            transition: transform 0.3s ease;
        }

        .card:hover {
            transform: translateY(-5px);
        }

        .card h3 {
            color: #333;
            font-size: 20px;
            font-weight: 600;
            margin-bottom: 15px;
        }

        .card p {
            color: #666;
            line-height: 1.6;
            margin-bottom: 15px;
        }

        .stats {
            display: flex;
            justify-content: space-between;
            margin: 15px 0;
        }

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

        .stat-value {
            font-size: 24px;
            font-weight: 700;
            color: #667eea;
        }

        .stat-label {
            font-size: 12px;
            color: #666;
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        .alert {
            padding: 15px 20px;
            margin: 20px 0;
            border-radius: 10px;
            font-weight: 500;
        }

        .alert-success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .alert-error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }

        .alert-warning {
            background: #fff3cd;
            color: #856404;
            border: 1px solid #ffeaa7;
        }

        .alert-info {
            background: #cce7ff;
            color: #004085;
            border: 1px solid #b8daff;
        }

        .quick-actions {
            background: white;
            padding: 25px;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            grid-column: 1 / -1;
        }

        .quick-actions h3 {
            margin-bottom: 20px;
            color: #333;
        }

        .action-buttons {
            display: flex;
            gap: 15px;
            flex-wrap: wrap;
        }

        @media (max-width: 768px) {
            .header {
                flex-direction: column;
                gap: 20px;
                text-align: center;
            }

            .user-actions {
                flex-direction: column;
                width: 100%;
            }

            .dashboard-content {
                grid-template-columns: 1fr;
            }

            .action-buttons {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
    <div class="dashboard-container">
        <!-- Flash Messages -->
        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="alert alert-{{ 'error' if category == 'error' else category }}">
                        {{ message }}
                    </div>
                {% endfor %}
            {% endif %}
        {% endwith %}

        <!-- Header -->
        <div class="header">
            <div class="welcome-message">
                <h1>Welcome, {{ user.username }}! 👋</h1>
                <p>Here's your ChatBot dashboard overview</p>
            </div>
            <div class="user-actions">
                <div class="user-info">
                    Logged in as: <strong>{{ user.email }}</strong>
                </div>
                <a href="{{ url_for('profile') }}" class="btn btn-secondary">Profile</a>
                <a href="{{ url_for('logout') }}" class="btn btn-danger"
                   onclick="return confirm('Are you sure you want to log out?')">
                    Logout
                </a>
            </div>
        </div>

        <!-- Dashboard Content -->
        <div class="dashboard-content">
            <div class="card">
                <h3>Account Information</h3>
                <p><strong>Username:</strong> {{ user.username }}</p>
                <p><strong>Email:</strong> {{ user.email }}</p>
                <p><strong>User ID:</strong> #{{ user.id }}</p>
                <p><strong>Last Login:</strong> {{ dashboard_data.last_login[:19] if dashboard_data.last_login != 'Unknown' else 'Unknown' }}</p>
                <a href="{{ url_for('change_password') }}" class="btn btn-primary">Change Password</a>
            </div>

            <div class="card">
                <h3>Session Information</h3>
                <p><strong>Session Status:</strong> Active</p>
                <p><strong>Session Type:</strong> {{ 'Persistent' if session.permanent else 'Temporary' }}</p>
                <p><strong>Expires:</strong> {{ dashboard_data.session_expires }}</p>
                <div class="stats">
                    <div class="stat-item">
                        <div class="stat-value">{{ user.id }}</div>
                        <div class="stat-label">User ID</div>
                    </div>
                </div>
            </div>

            <div class="card">
                <h3>ChatBot Status</h3>
                <p>Your personal chatbot is ready to help you.</p>
                <p><strong>Status:</strong> <span style="color: #28a745;">Active</span></p>
                <p><strong>Total Users:</strong> {{ dashboard_data.total_users }}</p>
                <a href="#" class="btn btn-primary">Start Chat</a>
            </div>

            <!-- Quick Actions -->
            <div class="quick-actions">
                <h3>Quick Actions</h3>
                <div class="action-buttons">
                    <a href="#" class="btn btn-primary">Start New Conversation</a>
                    <a href="{{ url_for('profile') }}" class="btn btn-secondary">View Profile</a>
                    <a href="{{ url_for('change_password') }}" class="btn btn-secondary">Change Password</a>
                    <a href="#" class="btn btn-secondary">Settings</a>
                </div>
            </div>
        </div>
    </div>
</body>
</html>