<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Change Password - MySQL to Sheets Sync</title>
    <style>
        :root {
            --primary: #2563eb;
            --primary-hover: #1d4ed8;
            --success: #16a34a;
            --error: #dc2626;
            --warning: #d97706;
            --bg: #f8fafc;
            --card-bg: #ffffff;
            --border: #e2e8f0;
            --text: #1e293b;
            --text-muted: #64748b;
        }

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

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: var(--bg);
            color: var(--text);
            line-height: 1.5;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 1rem;
        }

        .container {
            width: 100%;
            max-width: 400px;
        }

        .logo {
            text-align: center;
            margin-bottom: 2rem;
        }

        .logo h1 {
            font-size: 1.5rem;
            font-weight: 600;
            margin-bottom: 0.5rem;
        }

        .logo p {
            color: var(--text-muted);
            font-size: 0.875rem;
        }

        .card {
            background: var(--card-bg);
            border: 1px solid var(--border);
            border-radius: 0.5rem;
            padding: 2rem;
        }

        .warning-banner {
            background: #fffbeb;
            border: 1px solid #fde68a;
            color: var(--warning);
            padding: 1rem;
            border-radius: 0.375rem;
            margin-bottom: 1.5rem;
            font-size: 0.875rem;
        }

        .warning-banner strong {
            display: block;
            margin-bottom: 0.25rem;
        }

        .form-group {
            margin-bottom: 1.25rem;
        }

        label {
            display: block;
            font-size: 0.875rem;
            font-weight: 500;
            margin-bottom: 0.375rem;
        }

        input[type="password"] {
            width: 100%;
            padding: 0.625rem 0.875rem;
            border: 1px solid var(--border);
            border-radius: 0.375rem;
            font-size: 0.9375rem;
            font-family: inherit;
            transition: border-color 0.15s, box-shadow 0.15s;
        }

        input:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
        }

        .btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 0.625rem 1.25rem;
            border: none;
            border-radius: 0.375rem;
            font-size: 0.9375rem;
            font-weight: 500;
            cursor: pointer;
            transition: background-color 0.15s;
            text-decoration: none;
        }

        .btn-primary {
            width: 100%;
            background: var(--primary);
            color: white;
        }

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

        .btn-primary:disabled {
            opacity: 0.7;
            cursor: not-allowed;
        }

        .error-message {
            background: #fef2f2;
            border: 1px solid #fecaca;
            color: var(--error);
            padding: 0.75rem 1rem;
            border-radius: 0.375rem;
            margin-bottom: 1.25rem;
            font-size: 0.875rem;
        }

        .error-list {
            margin-top: 0.5rem;
            padding-left: 1.25rem;
            list-style: disc;
        }

        .error-list li {
            margin-bottom: 0.25rem;
        }

        .password-requirements {
            margin-top: 0.5rem;
            font-size: 0.75rem;
            color: var(--text-muted);
        }

        .password-requirements ul {
            margin-top: 0.25rem;
            padding-left: 1.25rem;
        }

        .password-requirements li {
            margin-bottom: 0.125rem;
        }

        .version {
            text-align: center;
            margin-top: 2rem;
            font-size: 0.75rem;
            color: var(--text-muted);
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="logo">
            <h1>MySQL to Sheets Sync</h1>
            <p>Change Your Password</p>
        </div>

        <div class="card">
            {% if is_forced %}
            <div class="warning-banner">
                <strong>Password Change Required</strong>
                For security, you must change your password before continuing.
                This is required for all new accounts with generated passwords.
            </div>
            {% endif %}

            {% if error %}
            <div class="error-message">
                {{ error }}
                {% if errors %}
                <ul class="error-list">
                    {% for err in errors %}
                    <li>{{ err }}</li>
                    {% endfor %}
                </ul>
                {% endif %}
            </div>
            {% endif %}

            <form method="POST" action="{{ url_for('auth.change_password') }}" id="changePasswordForm">
                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">

                {% if not is_forced %}
                <div class="form-group">
                    <label for="current_password">Current Password</label>
                    <input type="password" id="current_password" name="current_password"
                           placeholder="Enter your current password" required>
                </div>
                {% endif %}

                <div class="form-group">
                    <label for="new_password">New Password</label>
                    <input type="password" id="new_password" name="new_password"
                           placeholder="Enter a new password" required>
                    <div class="password-requirements">
                        Password requirements:
                        <ul>
                            <li>At least 8 characters</li>
                            <li>At least one uppercase letter</li>
                            <li>At least one lowercase letter</li>
                            <li>At least one number</li>
                        </ul>
                    </div>
                </div>

                <div class="form-group">
                    <label for="confirm_password">Confirm New Password</label>
                    <input type="password" id="confirm_password" name="confirm_password"
                           placeholder="Confirm your new password" required>
                </div>

                <button type="submit" class="btn btn-primary" id="submitBtn">
                    Change Password
                </button>
            </form>
        </div>

        <div class="version">
            v{{ version }}
        </div>
    </div>

    <script>
        document.getElementById('changePasswordForm').addEventListener('submit', function(e) {
            const newPwd = document.getElementById('new_password').value;
            const confirmPwd = document.getElementById('confirm_password').value;

            if (newPwd !== confirmPwd) {
                e.preventDefault();
                alert('New passwords do not match');
                return;
            }

            const btn = document.getElementById('submitBtn');
            btn.disabled = true;
            btn.textContent = 'Changing password...';
        });
    </script>
</body>
</html>
