/* Agent recovery opens over the login page, with no background artwork. */
#agentForgotDialog {
    position: fixed; inset: 0; width: 100%; height: 100vh; height: 100dvh;
    max-width: none; max-height: none; margin: 0; border: 0; background: transparent;
    padding: 40px 16px;
    padding: max(40px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(40px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    overflow-y: auto; font-family: Roboto, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    letter-spacing: .2px;
}
#agentForgotDialog:not([open]) { display: none; }
#agentForgotDialog[open] { display: flex; align-items: center; justify-content: center; }
#agentForgotDialog::backdrop { background: rgba(0, 0, 0, .5); }
#agentForgotDialog, #agentForgotDialog *, #agentForgotDialog *::before, #agentForgotDialog *::after { box-sizing: border-box; }
#agentForgotDialog input, #agentForgotDialog button { letter-spacing: inherit; }
#agentForgotDialog .popup-header { padding-right: 0; }
#agentForgotDialog .popup-title { margin: 0 0 8px; line-height: 1.2; }
#agentForgotDialog .popup-icon { flex-shrink: 0; }
#agentForgotDialog .form-input { height: auto; line-height: 1.5; color: #333; background: #fff; box-shadow: none; }
#agentForgotDialog .popup-description { margin: 0; font-weight: 400; }
#agentForgotDialog .back-to-login button { padding: 0; border: 0; background: none; color: #667eea; font: inherit; font-weight: 600; cursor: pointer; }
#agentForgotDialog .back-to-login button:hover { text-decoration: underline; }
#agentForgotDialog .success-message:empty { display: none; }
#agentForgotDialog .success-message:not(:empty) { display: block; }
#agentForgotDialog .success-message.fail { background: #fdecea; border-color: #f5c2c0; color: #a12622; }
#agentForgotDialog .success-message:not(.ok):not(.fail) { background: #f7f9fb; border-color: #e0e0e0; color: #666; }
body.agent-reset-open { overflow: hidden; }
        #agentForgotDialog .popup {
            background: #fff;
            border-radius: 16px;
            padding: clamp(24px, 5vw, 40px);
            width: 100%;
            max-width: 450px;
            margin: auto;
            box-shadow: 0 20px 60px rgba(40, 58, 90, 0.32);
            position: relative;
            animation: agentResetSlideUp 0.3s ease;
        }

        #agentForgotDialog .close-btn {
            position: absolute;
            top: 12px;
            right: 12px;
            width: 40px;
            height: 40px;
            border: none;
            background: #f0f0f0;
            border-radius: 50%;
            font-size: 24px;
            line-height: 1;
            color: #666;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            text-decoration: none;
            transition: background 0.2s, color 0.2s;
            -webkit-tap-highlight-color: transparent;
        }

        #agentForgotDialog .close-btn:hover,
        #agentForgotDialog .close-btn:focus-visible {
            background: #e0e0e0;
            color: #333;
            outline: none;
        }

        #agentForgotDialog .popup-header {
            text-align: center;
            margin-bottom: clamp(18px, 4vw, 24px);
        }

        #agentForgotDialog .popup-icon {
            width: clamp(52px, 12vw, 60px);
            height: clamp(52px, 12vw, 60px);
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 16px;
            font-size: clamp(24px, 6vw, 28px);
        }

        #agentForgotDialog .popup-title {
            font-size: clamp(20px, 5vw, 24px);
            font-weight: 700;
            color: #333;
            margin-bottom: 8px;
        }

        #agentForgotDialog .popup-description {
            font-size: clamp(13px, 3.4vw, 14px);
            color: #666;
            line-height: 1.5;
        }

        #agentForgotDialog .form-group {
            margin-bottom: clamp(18px, 4vw, 24px);
        }

        #agentForgotDialog .form-label {
            display: block;
            font-size: 14px;
            font-weight: 600;
            color: #333;
            margin-bottom: 8px;
        }

        #agentForgotDialog .form-input {
            width: 100%;
            padding: 14px 16px;
            font-size: 16px; /* 16px prevents iOS zoom-on-focus */
            font-family: inherit;
            border: 2px solid #e0e0e0;
            border-radius: 8px;
            transition: border-color 0.2s;
            outline: none;
        }

        #agentForgotDialog .form-input:focus {
            border-color: #667eea;
        }

        #agentForgotDialog .submit-btn {
            width: 100%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: #fff;
            border: none;
            padding: 14px;
            min-height: 48px;
            font-size: 16px;
            font-family: inherit;
            font-weight: 600;
            border-radius: 8px;
            cursor: pointer;
            transition: transform 0.2s, box-shadow 0.2s;
            -webkit-tap-highlight-color: transparent;
        }

        #agentForgotDialog .submit-btn:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
        }

        #agentForgotDialog .submit-btn:active {
            transform: translateY(0);
        }

        #agentForgotDialog .back-to-login {
            text-align: center;
            margin-top: 20px;
            font-size: 14px;
            color: #666;
        }

        #agentForgotDialog .back-to-login a {
            color: #667eea;
            text-decoration: none;
            font-weight: 600;
        }

        #agentForgotDialog .back-to-login a:hover {
            text-decoration: underline;
        }

        #agentForgotDialog .success-message {
            display: none;
            text-align: center;
            padding: 16px;
            background: #d4edda;
            border: 1px solid #c3e6cb;
            border-radius: 8px;
            color: #155724;
            font-size: 14px;
            margin-bottom: 20px;
        }

        #agentForgotDialog .success-message.show {
            display: block;
        }

        /* The same box, in red: an address that is not registered, a link that
           could not be sent. */
        #agentForgotDialog .success-message.is-error {
            background: #fdecea;
            border-color: #f5c2c0;
            color: #a12622;
        }

        #agentForgotDialog .form-input.is-invalid {
            border-color: #d9534f;
        }

        #agentForgotDialog .submit-btn:disabled {
            opacity: 0.65;
            cursor: default;
            transform: none;
            box-shadow: none;
        }

        /* --- Small phones --- */
        @media (max-width: 400px) {
            #agentForgotDialog .popup {
                border-radius: 12px;
            }
            #agentForgotDialog .close-btn {
                top: 8px;
                right: 8px;
            }
            #agentForgotDialog .popup-header {
                padding-top: 8px;
            }
        }

        /* --- Tablets and up: a touch more breathing room --- */
        @media (min-width: 768px) {
            #agentForgotDialog .popup {
                max-width: 480px;
            }
        }

        /* --- Large desktop --- */
        @media (min-width: 1440px) {
            #agentForgotDialog .popup {
                max-width: 520px;
            }
        }

        /* --- Landscape phones / short viewports: scroll instead of clipping --- */
        @media (max-height: 600px) {
            .overlay {
                align-items: flex-start;
            }
            #agentForgotDialog .popup {
                padding-top: 28px;
                padding-bottom: 28px;
            }
            #agentForgotDialog .popup-icon {
                width: 44px;
                height: 44px;
                font-size: 22px;
                margin-bottom: 10px;
            }
        }

        /* --- Touch devices: drop hover transforms --- */
        @media (hover: none) {
            #agentForgotDialog .submit-btn:hover {
                transform: none;
                box-shadow: none;
            }
        }

        @media (prefers-reduced-motion: reduce) {
            #agentForgotDialog *, #agentForgotDialog *::before, #agentForgotDialog *::after {
                animation: none !important;
                transition: none !important;
            }
        }

        @keyframes agentResetFadeIn {
            from { opacity: 0; }
            to   { opacity: 1; }
        }

        @keyframes agentResetSlideUp {
            from { transform: translateY(30px); opacity: 0; }
            to   { transform: translateY(0); opacity: 1; }
        }
    
