<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Support</title>
    <meta name="description"
        content="Contact support. We will respond by email. Обращение в поддержку. Ответ будет направлен на указанный адрес.">
    <style>
        :root {
            --bg: #ececef;
            --surface: #fff;
            --text: #0a0a0b;
            --muted: #5c5c66;
            --border: rgba(0, 0, 0, 0.08);
            --accent: #2563eb;
            --accent-hover: #1d4ed8;
            --danger: #dc2626;
            --ok-bg: #ecfdf5;
            --ok-text: #047857;
            --ok-border: rgba(4, 120, 87, 0.2);
            --radius: 12px;
            --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
        }

        * {
            box-sizing: border-box;
        }

        html,
        body {
            margin: 0;
            min-height: 100%;
            background: var(--bg);
            color: var(--text);
            font-family: var(--font);
            font-size: 15px;
            line-height: 1.5;
            -webkit-font-smoothing: antialiased;
        }

        body {
            padding: min(6vw, 48px) 16px;
        }

        .page {
            max-width: 440px;
            margin: 0 auto;
        }

        .card {
            background: var(--surface);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
            padding: 28px 24px 24px;
        }

        h1 {
            margin: 0 0 6px;
            font-size: 1.35rem;
            font-weight: 650;
            letter-spacing: -0.03em;
            line-height: 1.2;
        }

        .lead {
            margin: 0 0 22px;
            font-size: 0.9rem;
            color: var(--muted);
        }

        .locale {
            display: block;
        }

        .locale+.locale {
            margin-top: 2px;
        }

        .locale.ru {
            font-size: 0.88em;
            opacity: 0.88;
        }

        .field {
            margin-bottom: 16px;
        }

        .field:last-of-type {
            margin-bottom: 0;
        }

        label {
            display: block;
            font-size: 0.78rem;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.04em;
            color: var(--muted);
            margin-bottom: 6px;
        }

        label .locale.ru {
            font-size: inherit;
            text-transform: none;
            letter-spacing: 0;
            font-weight: 500;
        }

        input[type="email"],
        textarea {
            width: 100%;
            border: 1px solid var(--border);
            border-radius: 10px;
            padding: 11px 12px;
            font: inherit;
            color: var(--text);
            background: #fafafa;
            transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
        }

        textarea {
            min-height: 120px;
            resize: vertical;
            line-height: 1.45;
        }

        input:focus,
        textarea:focus {
            outline: none;
            border-color: rgba(37, 99, 235, 0.45);
            background: var(--surface);
            box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
        }

        .row-actions {
            margin-top: 20px;
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .btn {
            appearance: none;
            border: 0;
            border-radius: 10px;
            padding: 12px 16px;
            font: inherit;
            font-weight: 600;
            font-size: 0.92rem;
            color: #fff;
            background: var(--accent);
            cursor: pointer;
            transition: background 0.15s, opacity 0.15s;
        }

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

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

        .btn .locale {
            display: inline;
        }

        .btn .locale.ru::before {
            content: " · ";
            opacity: 0.7;
            font-weight: 500;
        }

        .status {
            font-size: 0.85rem;
            color: var(--muted);
            min-height: 1.25em;
        }

        .status.error {
            color: var(--danger);
        }

        .toast {
            display: none;
            margin-top: 16px;
            padding: 12px 14px;
            border-radius: 10px;
            font-size: 0.88rem;
            background: var(--ok-bg);
            color: var(--ok-text);
            border: 1px solid var(--ok-border);
        }

        .toast.is-visible {
            display: block;
        }

        .toast .locale+.locale {
            margin-top: 4px;
        }
    </style>
</head>

<body>
    <main class="page">
        <div class="card">
            <h1 id="page-title">
                <span class="locale en">Support</span>
                <span class="locale ru">Поддержка</span>
            </h1>
            <p class="lead">
                <span class="locale en">Please enter your email address and message. We will send our response to the
                    email address you provide.</span>
                <span class="locale ru">Укажите адрес электронной почты и текст сообщения. Ответ будет направлен на
                    указанный адрес.</span>
            </p>

            <form id="support-form" method="post" action="" novalidate aria-labelledby="page-title">
                <div class="field">
                    <label for="email">
                        <span class="locale en">Email</span>
                        <span class="locale ru">Почта</span>
                    </label>
                    <input id="email" name="email" type="email" autocomplete="email" placeholder="you@example.com"
                        required>
                </div>

                <div class="field">
                    <label for="message">
                        <span class="locale en">Message</span>
                        <span class="locale ru">Сообщение</span>
                    </label>
                    <textarea id="message" name="message" required maxlength="8000" placeholder="…"></textarea>
                </div>

                <div class="row-actions">
                    <button id="submit-button" class="btn" type="submit" disabled>
                        <span class="locale en">Submit</span><span class="locale ru">Отправить</span>
                    </button>
                    <div id="status" class="status" aria-live="polite"></div>
                </div>
            </form>

            <div id="success-message" class="toast" aria-live="polite">
                <span class="locale en">Thank you. Your message has been received. We will respond to the email address
                    you provided.</span>
                <span class="locale ru">Благодарим за обращение. Ваше сообщение получено. Ответ будет направлен на
                    указанный адрес электронной почты.</span>
            </div>
        </div>
    </main>

    <script>
        (function () {
            var form = document.getElementById('support-form');
            var emailInput = document.getElementById('email');
            var messageInput = document.getElementById('message');
            var submitButton = document.getElementById('submit-button');
            var status = document.getElementById('status');
            var successMessage = document.getElementById('success-message');
            var isSubmitting = false;

            function isValidEmail(value) {
                var trimmed = value.trim();
                return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(trimmed);
            }

            function updateButtonState() {
                var hasMessage = messageInput.value.trim().length >= 3;
                submitButton.disabled = isSubmitting || !hasMessage || !isValidEmail(emailInput.value);
            }

            function setStatus(message, isError) {
                status.textContent = message;
                status.className = isError ? 'status error' : 'status';
            }

            emailInput.addEventListener('input', function () {
                emailInput.setCustomValidity('');
                successMessage.classList.remove('is-visible');
                setStatus('', false);
                updateButtonState();
            });

            messageInput.addEventListener('input', function () {
                successMessage.classList.remove('is-visible');
                setStatus('', false);
                updateButtonState();
            });

            form.addEventListener('submit', function (event) {
                event.preventDefault();
                successMessage.classList.remove('is-visible');

                if (!isValidEmail(emailInput.value)) {
                    emailInput.setCustomValidity('Invalid email.');
                    emailInput.reportValidity();
                    setStatus('Please enter a valid email address. / Укажите корректный адрес электронной почты.', true);
                    return;
                }

                if (messageInput.value.trim().length < 3) {
                    setStatus('Please enter a more detailed message. / Введите более подробное сообщение.', true);
                    return;
                }

                emailInput.setCustomValidity('');
                setStatus('Submitting… / Отправка…', false);
                isSubmitting = true;
                updateButtonState();

                var body = 'email=' + encodeURIComponent(emailInput.value.trim())
                    + '&message=' + encodeURIComponent(messageInput.value.trim());

                window.fetch(window.location.href, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
                    },
                    body: body,
                    credentials: 'same-origin'
                }).then(function (response) {
                    if (response.status !== 200) {
                        throw new Error('Request failed');
                    }
                    setStatus('', false);
                    successMessage.classList.add('is-visible');
                    isSubmitting = false;
                    messageInput.value = '';
                    emailInput.value = '';
                    updateButtonState();
                }).catch(function () {
                    isSubmitting = false;
                    setStatus('Your request could not be sent. Please try again later. / Запрос не удалось отправить. Повторите попытку позже.', true);
                    updateButtonState();
                }).then(function () {
                    updateButtonState();
                });
            });

            updateButtonState();
        }());
    </script>
</body>

</html>
